Skip to content

Commit 329bc34

Browse files
committed
[VPlan] Use VPPhiAccessors for VPIRPhi.
1 parent c606923 commit 329bc34

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
@@ -1147,7 +1147,7 @@ template <typename RecipeTy> class VPPhiAccessors {
11471147

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

11531153
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
@@ -1039,16 +1039,19 @@ static const VPBasicBlock *getIncomingBlockForRecipe(const VPRecipeBase *R,
10391039
return Pred->getExitingBasicBlock();
10401040
}
10411041

1042+
template <>
1043+
const VPBasicBlock *
1044+
VPPhiAccessors<VPIRPhi>::getIncomingBlock(unsigned Idx) const {
1045+
return getIncomingBlockForRecipe(getAsRecipe(), Idx);
1046+
}
1047+
10421048
void VPIRPhi::execute(VPTransformState &State) {
10431049
PHINode *Phi = &getIRPhi();
1044-
for (const auto &[Idx, Op] : enumerate(operands())) {
1045-
VPValue *ExitValue = Op;
1050+
for (const auto &[ExitValue, IncVPBB] : incoming_values_and_blocks()) {
10461051
auto Lane = vputils::isUniformAfterVectorization(ExitValue)
10471052
? VPLane::getFirstLane()
10481053
: VPLane::getLastLaneForVF(State.VF);
1049-
VPBlockBase *Pred = getParent()->getPredecessors()[Idx];
1050-
auto *PredVPBB = Pred->getExitingBasicBlock();
1051-
BasicBlock *PredBB = State.CFG.VPBB2IRBB[PredVPBB];
1054+
BasicBlock *PredBB = State.CFG.VPBB2IRBB[IncVPBB];
10521055
// Set insertion point in PredBB in case an extract needs to be generated.
10531056
// TODO: Model extracts explicitly.
10541057
State.Builder.SetInsertPoint(PredBB, PredBB->getFirstNonPHIIt());
@@ -1073,12 +1076,11 @@ void VPIRPhi::print(raw_ostream &O, const Twine &Indent,
10731076

10741077
if (getNumOperands() != 0) {
10751078
O << " (extra operand" << (getNumOperands() > 1 ? "s" : "") << ": ";
1076-
interleaveComma(
1077-
enumerate(operands()), O, [this, &O, &SlotTracker](auto Op) {
1078-
Op.value()->printAsOperand(O, SlotTracker);
1079-
O << " from ";
1080-
getParent()->getPredecessors()[Op.index()]->printAsOperand(O);
1081-
});
1079+
interleaveComma(incoming_values_and_blocks(), O, [&O, &SlotTracker](auto Op) {
1080+
std::get<0>(Op)->printAsOperand(O, SlotTracker);
1081+
O << " from ";
1082+
std::get<1>(Op)->printAsOperand(O);
1083+
});
10821084
O << ")";
10831085
}
10841086
}

0 commit comments

Comments
 (0)