@@ -1171,6 +1171,28 @@ class VPIRInstruction : public VPRecipeBase {
11711171 void extractLastLaneOfFirstOperand (VPBuilder &Builder);
11721172};
11731173
1174+ // / Helper type to provide functions to access incoming values and blocks for
1175+ // / phi-like recipes.
1176+ class VPPhiAccessors {
1177+ protected:
1178+ // / Return a VPRecipeBase* to the current object.
1179+ virtual const VPRecipeBase *getAsRecipe () const = 0;
1180+
1181+ public:
1182+ virtual ~VPPhiAccessors () = default ;
1183+
1184+ // / Returns the incoming VPValue with index \p Idx.
1185+ VPValue *getIncomingValue (unsigned Idx) const {
1186+ return getAsRecipe ()->getOperand (Idx);
1187+ }
1188+
1189+ // / Returns the incoming block with index \p Idx.
1190+ const VPBasicBlock *getIncomingBlock (unsigned Idx) const ;
1191+
1192+ // / Returns the number of incoming values, also number of incoming blocks.
1193+ unsigned getNumIncoming () const { return getAsRecipe ()->getNumOperands (); }
1194+ };
1195+
11741196// / An overlay for VPIRInstructions wrapping PHI nodes enabling convenient use
11751197// / cast/dyn_cast/isa and execute() implementation. A single VPValue operand is
11761198// / allowed, and it is used to add a new incoming value for the single
@@ -1974,10 +1996,13 @@ class VPWidenPointerInductionRecipe : public VPWidenInductionRecipe,
19741996// / recipe is placed in an entry block to a (non-replicate) region, it must have
19751997// / exactly 2 incoming values, the first from the predecessor of the region and
19761998// / the second from the exiting block of the region.
1977- class VPWidenPHIRecipe : public VPSingleDefRecipe {
1999+ class VPWidenPHIRecipe : public VPSingleDefRecipe , public VPPhiAccessors {
19782000 // / Name to use for the generated IR instruction for the widened phi.
19792001 std::string Name;
19802002
2003+ protected:
2004+ const VPRecipeBase *getAsRecipe () const override { return this ; }
2005+
19812006public:
19822007 // / Create a new VPWidenPHIRecipe for \p Phi with start value \p Start and
19832008 // / debug location \p DL.
@@ -2005,12 +2030,6 @@ class VPWidenPHIRecipe : public VPSingleDefRecipe {
20052030 void print (raw_ostream &O, const Twine &Indent,
20062031 VPSlotTracker &SlotTracker) const override ;
20072032#endif
2008-
2009- // / Returns the \p I th incoming VPBasicBlock.
2010- VPBasicBlock *getIncomingBlock (unsigned I);
2011-
2012- // / Returns the \p I th incoming VPValue.
2013- VPValue *getIncomingValue (unsigned I) { return getOperand (I); }
20142033};
20152034
20162035// / A recipe for handling first-order recurrence phis. The start value is the
@@ -3329,6 +3348,12 @@ class VPBasicBlock : public VPBlockBase {
33293348 // / the cloned recipes.
33303349 VPBasicBlock *clone () override ;
33313350
3351+ // / Returns the predecessor block at index \p Idx with the predecessors as per
3352+ // / the corresponding plain CFG. If the block is an entry block to a region,
3353+ // / the first predecessor is the single predecessor of a region, and the
3354+ // / second predecessor is the exiting block of the region.
3355+ const VPBasicBlock *getCFGPredecessor (unsigned Idx) const ;
3356+
33323357protected:
33333358 // / Execute the recipes in the IR basic block \p BB.
33343359 void executeRecipes (VPTransformState *State, BasicBlock *BB);
@@ -3343,6 +3368,11 @@ class VPBasicBlock : public VPBlockBase {
33433368 BasicBlock *createEmptyBasicBlock (VPTransformState &State);
33443369};
33453370
3371+ inline const VPBasicBlock *
3372+ VPPhiAccessors::getIncomingBlock (unsigned Idx) const {
3373+ return getAsRecipe ()->getParent ()->getCFGPredecessor (Idx);
3374+ }
3375+
33463376// / A special type of VPBasicBlock that wraps an existing IR basic block.
33473377// / Recipes of the block get added before the first non-phi instruction in the
33483378// / wrapped block.
0 commit comments