[llvm] [BOLT][NFC] Simplify instruction iteration. (PR #174898)
Anatoly Trosinenko via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 12 06:44:33 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)) {
----------------
atrosinenko wrote:
At first, I thought that calling `computeAddress` here would be too expensive (and would have other undesired properties), but then I realized it is always `O(1)` here because `Point` always stores an `(offset, instruction)` pair in this function. I wonder if `instr_iterator_impl::getOffset()` would be more straightforward to use here.
https://github.com/llvm/llvm-project/pull/174898
More information about the llvm-commits
mailing list