From ec5af3d5cbbc025a7c5c3aa2cf6591a63c212256 Mon Sep 17 00:00:00 2001 From: Pietro Fezzardi Date: Mon, 8 Jun 2026 19:14:31 +0200 Subject: [PATCH] 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. --- .../ImportDescriptiveInfo.cpp | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/lib/CliftImportModel/ImportDescriptiveInfo.cpp b/lib/CliftImportModel/ImportDescriptiveInfo.cpp index cf27d8d85..bdc858319 100644 --- a/lib/CliftImportModel/ImportDescriptiveInfo.cpp +++ b/lib/CliftImportModel/ImportDescriptiveInfo.cpp @@ -253,6 +253,33 @@ public: if (auto S = mlir::dyn_cast(Op)) return visitStatementOp(S); + if (auto U = mlir::dyn_cast(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(); + revng_assert(Module); + + mlir::Operation *Target = // + mlir::SymbolTable::lookupSymbolIn(Module, Use.getSymbolNameAttr()); + + if (auto F = mlir::dyn_cast_or_null(Target)) + return recordFunctionOpName(F); + + if (auto G = mlir::dyn_cast_or_null(Target)) + return recordGlobalVariableOpName(G); + return mlir::success(); }