[clang] [CIR] Only scan globals and constants for block addresses in GotoSolver (PR #232870)

Bruno Cardoso Lopes via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 16 19:03:03 PDT 2026


================
@@ -115,27 +115,33 @@ static void process(cir::FuncOp func,
 void GotoSolverPass::runOnOperation() {
   llvm::TimeTraceScope scope("Goto Solver");
 
-  // Block addresses can also appear in attributes outside of any function body,
-  // such as global variable initializers.  Collect, per target function and in
-  // initializer order, the labels referenced this way so their LabelOps survive
-  // and join the indirect branch's successors.  A SetVector keeps the first
-  // occurrence in order: a label named more than once across initializers needs
-  // to be a successor only once.
+  // Block addresses also appear in attributes: global initializers and
+  // cir.const values. Collect, per target function and in walk order, the
+  // labels referenced this way so their LabelOps survive and join the
+  // indirect branch's successors. A SetVector keeps the first occurrence
+  // in order: a label named more than once is a successor only once.
+  //
+  // process() collects cir.block_address ops; scan just globals and
+  // constants for the rest.
   llvm::StringMap<llvm::SmallSetVector<StringRef, 4>> globalBlockAddrLabels;
-  getOperation()->walk([&](mlir::Operation *op) {
+  mlir::ModuleOp module = mlir::cast<mlir::ModuleOp>(getOperation());
+  module.walk([&](mlir::Operation *op) {
+    if (!mlir::isa<cir::GlobalOp, cir::ConstantOp>(op))
----------------
bcardosolopes wrote:

Improved the comment to explain it

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


More information about the cfe-commits mailing list