[PATCH] D139565: [IR] add new callbrpad instruction

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 8 13:30:19 PST 2022


efriedma added a comment.

In D139565#3980574 <https://reviews.llvm.org/D139565#3980574>, @nickdesaulniers wrote:

> Ok, new idea for an approach based on feedback thus far (comments welcome and appreciated):
>
> 1. allow the use of `callbr` values along ANY edge; direct or indirect. i.e. restore https://reviews.llvm.org/D135997.

Right.

> 2. Create a new function pass (as part of `TargetPassConfig::addISelPasses` so it runs before isel on LLVM IR) that:

If it isn't practical to lower correctly in SelectionDAG without mutating the IR, that's fine.  I suspect GlobalISel doesn't want an IR pass, though; it's probably more straightforward there to lower callbr directly to a G_CALLBR instruction, then do the lowering directly on MIR .  So making it part of SelectionDAG isel might be better?  I guess GlobalISel can just ignore the intrinsic if it wants, though, so maybe a separate pass is fine.  (We can add a flag to dump the IR after the transform if you're worried about testing.)

If you do make it a separate pass, you probably want it pretty close to isel so other transforms don't get confused.

> 1. for each basic block terminator if it's a callbr that has outputs that have uses:
>   1. splits indirect edges that happen to also be critical edges (if any) (akin to https://reviews.llvm.org/D138078, but in a dedicated pass, not during ISEL but just before as part of the `TargetPassConfig::addISelPasses` pipeline)

Right, you need to split to insert the copies in the right place, in general.

> 3. Replaces the uses dominated by the indirect edge to use the newly created value.  We might need to insert phis where previously there were none (perhaps the SSA construction @efriedma refers to?).

Right, this is what I was referring to when I mentioned SSA construction.  (You'd probably use the llvm::SSAUpdater utility on IR.)

> 3. Add a mapping from CallBrInst to either INLINEASM_BR MachineInstr or first defined virtreg (not sure yet), probably in SelectionDAGBuilder's FunctionLoweringInfo instance member. Create an entry in this mapping when lowering a callbr or inlineasm.  Consume this mapping info when visiting the "new value" created from 2.A.b above to insert COPYs as necessary.

Not sure you're guaranteed to visit the callbr before its successors?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139565/new/

https://reviews.llvm.org/D139565



More information about the llvm-commits mailing list