Skip to content

Commit f2e62cf

Browse files
authored
[VPlan] Add VPPhi subclass for VPInstruction with PHI opcodes.(NFC) (#139151)
Similarly to VPInstructionWithType and VPIRPhi, add VPPhi as a subclass for VPInstruction. This allows implementing the VPPhiAccessors trait, making available helpers for generic printing of incoming values / blocks and accessors for incoming blocks and values. It will also allow properly verifying def-uses for values used by VPInstructions with PHI opcodes via #124838. PR: #139151
1 parent fe56c8f commit f2e62cf

File tree

3 files changed

+30
-12
lines changed

3 files changed

+30
-12
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,7 @@ class VPBuilder {
252252

253253
VPInstruction *createScalarPhi(ArrayRef<VPValue *> IncomingValues,
254254
DebugLoc DL, const Twine &Name = "") {
255-
return tryInsertInstruction(
256-
new VPInstruction(Instruction::PHI, IncomingValues, DL, Name));
255+
return tryInsertInstruction(new VPPhi(IncomingValues, DL, Name));
257256
}
258257

259258
/// Convert the input value \p Current to the corresponding value of an

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,21 @@ class VPPhiAccessors {
11431143
#endif
11441144
};
11451145

1146+
struct VPPhi : public VPInstruction, public VPPhiAccessors {
1147+
VPPhi(ArrayRef<VPValue *> Operands, DebugLoc DL, const Twine &Name = "")
1148+
: VPInstruction(Instruction::PHI, Operands, DL, Name) {}
1149+
1150+
static inline bool classof(const VPRecipeBase *U) {
1151+
auto *R = dyn_cast<VPInstruction>(U);
1152+
return R && R->getOpcode() == Instruction::PHI;
1153+
}
1154+
1155+
void execute(VPTransformState &State) override;
1156+
1157+
protected:
1158+
const VPRecipeBase *getAsRecipe() const override { return this; }
1159+
};
1160+
11461161
/// A recipe to wrap on original IR instruction not to be modified during
11471162
/// execution, except for PHIs. PHIs are modeled via the VPIRPhi subclass.
11481163
/// Expect PHIs, VPIRInstructions cannot have any operands.

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -492,16 +492,7 @@ Value *VPInstruction::generate(VPTransformState &State) {
492492
return Builder.CreateCmp(getPredicate(), A, B, Name);
493493
}
494494
case Instruction::PHI: {
495-
assert(getParent() ==
496-
getParent()->getPlan()->getVectorLoopRegion()->getEntry() &&
497-
"VPInstructions with PHI opcodes must be used for header phis only "
498-
"at the moment");
499-
BasicBlock *VectorPH =
500-
State.CFG.VPBB2IRBB.at(getParent()->getCFGPredecessor(0));
501-
Value *Start = State.get(getOperand(0), VPLane(0));
502-
PHINode *Phi = State.Builder.CreatePHI(Start->getType(), 2, Name);
503-
Phi->addIncoming(Start, VectorPH);
504-
return Phi;
495+
llvm_unreachable("should be handled by VPPhi::execute");
505496
}
506497
case Instruction::Select: {
507498
bool OnlyFirstLaneUsed = vputils::onlyFirstLaneUsed(this);
@@ -1131,6 +1122,19 @@ void VPInstructionWithType::print(raw_ostream &O, const Twine &Indent,
11311122
}
11321123
#endif
11331124

1125+
void VPPhi::execute(VPTransformState &State) {
1126+
State.setDebugLocFrom(getDebugLoc());
1127+
assert(getParent() ==
1128+
getParent()->getPlan()->getVectorLoopRegion()->getEntry() &&
1129+
"VPInstructions with PHI opcodes must be used for header phis only "
1130+
"at the moment");
1131+
BasicBlock *VectorPH = State.CFG.VPBB2IRBB.at(getIncomingBlock(0));
1132+
Value *Start = State.get(getIncomingValue(0), VPLane(0));
1133+
PHINode *Phi = State.Builder.CreatePHI(Start->getType(), 2, getName());
1134+
Phi->addIncoming(Start, VectorPH);
1135+
State.set(this, Phi, VPLane(0));
1136+
}
1137+
11341138
VPIRInstruction *VPIRInstruction ::create(Instruction &I) {
11351139
if (auto *Phi = dyn_cast<PHINode>(&I))
11361140
return new VPIRPhi(*Phi);

0 commit comments

Comments
 (0)