mirror of
https://github.com/revng/revng
synced 2026-06-21 14:07:57 +00:00
CliftImportModel: import symbol descriptive info
When importing descriptive info for a single function, the body walk now intercepts clift::UseOp operations and follows the symbol reference to find the target FunctionOp or GlobalVariableOp. Before this commit, the per-function overload of importDescriptiveInfo recorded the rename only for the current function (plus helpers and globals at module level, but not via UseOp). The deduplication logic makes it cheap and safe for a single FunctionOp or GlobalVariableOp to be used in many UseOps without importing descriptive info twice. The same holds if the FunctionOp is also visited at module level and not just via UseOp, as is the case for self-recursive functions.
This commit is contained in:
@@ -253,6 +253,33 @@ public:
|
||||
if (auto S = mlir::dyn_cast<clift::StatementOpInterface>(Op))
|
||||
return visitStatementOp(S);
|
||||
|
||||
if (auto U = mlir::dyn_cast<clift::UseOp>(Op))
|
||||
return visitUseOp(U);
|
||||
|
||||
return mlir::success();
|
||||
}
|
||||
|
||||
// Resolve the symbol referenced by `Use` to its definition in the
|
||||
// enclosing module and record the descriptive info for that target.
|
||||
//
|
||||
// This is what guarantees that a function whose body contains
|
||||
// references to other functions or to global variables also causes
|
||||
// those callees to be renamed by the SymbolRenamer at the end of
|
||||
// importDescriptiveInfo, without the per-function variant having to
|
||||
// pre-walk every sibling module-level op.
|
||||
mlir::LogicalResult visitUseOp(clift::UseOp Use) {
|
||||
auto Module = Use->getParentOfType<mlir::ModuleOp>();
|
||||
revng_assert(Module);
|
||||
|
||||
mlir::Operation *Target = //
|
||||
mlir::SymbolTable::lookupSymbolIn(Module, Use.getSymbolNameAttr());
|
||||
|
||||
if (auto F = mlir::dyn_cast_or_null<clift::FunctionOp>(Target))
|
||||
return recordFunctionOpName(F);
|
||||
|
||||
if (auto G = mlir::dyn_cast_or_null<clift::GlobalVariableOp>(Target))
|
||||
return recordGlobalVariableOpName(G);
|
||||
|
||||
return mlir::success();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user