[llvm] [VPlan] Add VPIRInstruction, use for exit block live-outs. (PR #100735)

Florian Hahn via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 13 13:58:40 PDT 2024


================
@@ -867,6 +867,43 @@ void VPInstruction::print(raw_ostream &O, const Twine &Indent,
 }
 #endif
 
+void VPIRInstruction::execute(VPTransformState &State) {
+  assert(isa<VPIRBasicBlock>(getParent()) &&
+         "VPIRInstructions can only be placed in VPIRBasicBlocks");
+
+  assert((isa<PHINode>(&I) || getNumOperands() == 0) &&
+         "Only PHINodes can have extra operands");
+  if (getNumOperands() == 1) {
+    VPValue *ExitValue = getOperand(0);
+    auto Lane = vputils::isUniformAfterVectorization(ExitValue)
+                    ? VPLane::getFirstLane()
+                    : VPLane::getLastLaneForVF(State.VF);
+    auto *PredVPBB = cast<VPBasicBlock>(getParent()->getSinglePredecessor());
+    BasicBlock *PredBB = State.CFG.VPBB2IRBB[PredVPBB];
+    // Set insertion point in PredBB in case an extract needs to be generated.
+    // TODO: Model extracts explicitly.
+    State.Builder.SetInsertPoint(PredBB, PredBB->getFirstNonPHIIt());
+    Value *V = State.get(ExitValue, VPIteration(State.UF - 1, Lane));
+    auto *Phi = cast<PHINode>(&I);
+    Phi->addIncoming(V, PredBB);
+  }
+
+  State.Builder.SetInsertPoint(I.getParent(), std::next(I.getIterator()));
----------------
fhahn wrote:

Added a comment, thanks!

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


More information about the llvm-commits mailing list