[llvm] InstrProfiling.cpp: Let lowerIntrinsics() able to insert BBs. (PR #95585)

NAKAMURA Takumi via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 18 05:25:19 PDT 2024


chapuni wrote:

@ornata `MadeChange` is a just trigger to the posprocess `promoteCounterLoadStores(F)`.
All intrinsics was replaced within BB Insts in the current impl.

I would like to introduce BB change to insert conditional store. This makes `for (BB)` harder and redoing the loop is required.
This is the reason why I introduce `IsBBChanged`.

Do you have any better idea for redoing if BB is added by `SplitBlockAndInsertIfThen()`?
Rather redoing the loop, could we record IntrinsicInsts at 1st loop and procees marked Insts in 2nd loop? For example,

```
  SmallVector<IntrinsicInst*> InstrsLowered;
  for (BB: *F)
    for (Instr: BB)
      if (isa<IntrinsicInst>(Instr) && (isCounterBase(Instr) || isMCDCBase(Instr))
        InstrsLowered.push_back(Instr);

  // This can replace MadeChange.
  if (InstrsLowered.empty()) return false;

  for (Instr : InstrLowered)
    if (auto *IPFOO == dyn_cast<InstrProfFOO>(Instr)
      lowerFOO(IPFOO);
    else if ...

promoteCounterLoadStores(F);
return true;  
```

This will avoid flags and redoing.


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


More information about the llvm-commits mailing list