Skip to content

Commit 4939125

Browse files
committed
[VPlan] Use VPPhiAccessors for VPIRPhi.
1 parent 5df36e4 commit 4939125

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1146,7 +1146,7 @@ template <typename RecipeTy> class VPPhiAccessors {
11461146

11471147
/// An overlay for VPIRInstructions wrapping PHI nodes enabling convenient use
11481148
/// cast/dyn_cast/isa and execute() implementation.
1149-
struct VPIRPhi : public VPIRInstruction {
1149+
struct VPIRPhi : public VPIRInstruction, public VPPhiAccessors<VPIRPhi> {
11501150
VPIRPhi(PHINode &PN) : VPIRInstruction(PN) {}
11511151

11521152
static inline bool classof(const VPRecipeBase *U) {

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,16 +1028,19 @@ static const VPBasicBlock *getIncomingBlockForRecipe(const VPRecipeBase *R,
10281028
return Pred->getExitingBasicBlock();
10291029
}
10301030

1031+
template <>
1032+
const VPBasicBlock *
1033+
VPPhiAccessors<VPIRPhi>::getIncomingBlock(unsigned Idx) const {
1034+
return getIncomingBlockForRecipe(getAsRecipe(), Idx);
1035+
}
1036+
10311037
void VPIRPhi::execute(VPTransformState &State) {
10321038
PHINode *Phi = &getIRPhi();
1033-
for (const auto &[Idx, Op] : enumerate(operands())) {
1034-
VPValue *ExitValue = Op;
1039+
for (const auto &[ExitValue, IncVPBB] : incoming_values_and_blocks()) {
10351040
auto Lane = vputils::isUniformAfterVectorization(ExitValue)
10361041
? VPLane::getFirstLane()
10371042
: VPLane::getLastLaneForVF(State.VF);
1038-
VPBlockBase *Pred = getParent()->getPredecessors()[Idx];
1039-
auto *PredVPBB = Pred->getExitingBasicBlock();
1040-
BasicBlock *PredBB = State.CFG.VPBB2IRBB[PredVPBB];
1043+
BasicBlock *PredBB = State.CFG.VPBB2IRBB[IncVPBB];
10411044
// Set insertion point in PredBB in case an extract needs to be generated.
10421045
// TODO: Model extracts explicitly.
10431046
State.Builder.SetInsertPoint(PredBB, PredBB->getFirstNonPHIIt());
@@ -1062,12 +1065,11 @@ void VPIRPhi::print(raw_ostream &O, const Twine &Indent,
10621065

10631066
if (getNumOperands() != 0) {
10641067
O << " (extra operand" << (getNumOperands() > 1 ? "s" : "") << ": ";
1065-
interleaveComma(
1066-
enumerate(operands()), O, [this, &O, &SlotTracker](auto Op) {
1067-
Op.value()->printAsOperand(O, SlotTracker);
1068-
O << " from ";
1069-
getParent()->getPredecessors()[Op.index()]->printAsOperand(O);
1070-
});
1068+
interleaveComma(incoming_values_and_blocks(), O, [&O, &SlotTracker](auto Op) {
1069+
std::get<0>(Op)->printAsOperand(O, SlotTracker);
1070+
O << " from ";
1071+
std::get<1>(Op)->printAsOperand(O);
1072+
});
10711073
O << ")";
10721074
}
10731075
}

0 commit comments

Comments
 (0)