[flang-commits] [flang] [flang][debug] Only import debug info for specified renamed variables (PR #194926)

Abid Qadeer via flang-commits flang-commits at lists.llvm.org
Tue May 5 10:05:55 PDT 2026


================
@@ -823,10 +823,30 @@ void AddDebugInfoPass::handleOnlyClause(
     fir::UseStmtOp useOp, mlir::LLVM::DISubprogramAttr spAttr,
     mlir::LLVM::DIFileAttr fileAttr, mlir::SymbolTable *symbolTable,
     llvm::DenseSet<mlir::LLVM::DIImportedEntityAttr> &importedModules) {
+
+  auto onlySymbols = useOp.getOnlySymbols();
+  auto renames = useOp.getRenames();
+
   // Process ONLY symbols (without renames)
-  if (auto onlySymbols = useOp.getOnlySymbols()) {
+  if (onlySymbols) {
     for (mlir::Attribute attr : *onlySymbols) {
       auto symbolRef = mlir::cast<mlir::FlatSymbolRefAttr>(attr);
+
+      // Check if this symbol is also in renames, if so skip it
+      bool isInRenames = false;
+      if (renames) {
+        for (auto renameAttr : *renames) {
+          auto rename = mlir::cast<fir::UseRenameAttr>(renameAttr);
+          if (rename.getSymbol().getValue() == symbolRef.getValue()) {
+            isInRenames = true;
+            break;
+          }
+        }
+      }
+
+      if (isInRenames)
+        continue;
+
----------------
abidh wrote:

We are introducing a quadratic behavior here where we will run rename loop on all symbols in only list. I wonder if we can do better. Perhaps run the rename thing first and add the symbols during the loop into a set. Then only loop runs after that and uses that set instead of running a 2nd loop.

https://github.com/llvm/llvm-project/pull/194926


More information about the flang-commits mailing list