[llvm] [BOLT][NFC] Simplify instruction iteration. (PR #174898)

Harald van Dijk via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 12 08:30:23 PST 2026


================
@@ -804,16 +788,18 @@ class CFGUnawareSrcSafetyAnalysis : public SrcSafetyAnalysis,
   void run() override {
     const SrcState DefaultState = computePessimisticState(BF);
     SrcState S = createEntryState();
-    for (auto &I : BF.instrs()) {
-      MCInst &Inst = I.second;
+    for (auto It = BF.instr_begin(), End = BF.instr_end(); It != End; ++It) {
+      MCInstReference Point(It);
+      MCInst &Inst = *It;
       if (BC.MIB->isCFI(Inst))
         continue;
 
       // If there is a label before this instruction, it is possible that it
       // can be jumped-to, thus conservatively resetting S. As an exception,
       // let's ignore any labels at the beginning of the function, as at least
       // one label is expected there.
-      if (BF.hasLabelAt(I.first) && &Inst != &BF.instrs().begin()->second) {
+      unsigned Offset = Point.computeAddress() - BF.getAddress();
+      if (Offset && BF.hasLabelAt(Offset)) {
----------------
hvdijk wrote:

That would work in this version but one of the goals of this PR is to allow `CFGUnawareSrcSafetyAnalysis` to be used with functions where we did construct a CFG, but we know the CFG is bad (`BF.hasCFG() && !BF.isSimple()`). I don't think we can avoid it in that case.

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


More information about the llvm-commits mailing list