@@ -1171,6 +1171,28 @@ class VPIRInstruction : public VPRecipeBase {
1171
1171
void extractLastLaneOfFirstOperand (VPBuilder &Builder);
1172
1172
};
1173
1173
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
+
1174
1196
// / An overlay for VPIRInstructions wrapping PHI nodes enabling convenient use
1175
1197
// / cast/dyn_cast/isa and execute() implementation. A single VPValue operand is
1176
1198
// / allowed, and it is used to add a new incoming value for the single
@@ -1974,10 +1996,13 @@ class VPWidenPointerInductionRecipe : public VPWidenInductionRecipe,
1974
1996
// / recipe is placed in an entry block to a (non-replicate) region, it must have
1975
1997
// / exactly 2 incoming values, the first from the predecessor of the region and
1976
1998
// / the second from the exiting block of the region.
1977
- class VPWidenPHIRecipe : public VPSingleDefRecipe {
1999
+ class VPWidenPHIRecipe : public VPSingleDefRecipe , public VPPhiAccessors {
1978
2000
// / Name to use for the generated IR instruction for the widened phi.
1979
2001
std::string Name;
1980
2002
2003
+ protected:
2004
+ const VPRecipeBase *getAsRecipe () const override { return this ; }
2005
+
1981
2006
public:
1982
2007
// / Create a new VPWidenPHIRecipe for \p Phi with start value \p Start and
1983
2008
// / debug location \p DL.
@@ -2005,12 +2030,6 @@ class VPWidenPHIRecipe : public VPSingleDefRecipe {
2005
2030
void print (raw_ostream &O, const Twine &Indent,
2006
2031
VPSlotTracker &SlotTracker) const override ;
2007
2032
#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); }
2014
2033
};
2015
2034
2016
2035
// / A recipe for handling first-order recurrence phis. The start value is the
@@ -3329,6 +3348,12 @@ class VPBasicBlock : public VPBlockBase {
3329
3348
// / the cloned recipes.
3330
3349
VPBasicBlock *clone () override ;
3331
3350
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
+
3332
3357
protected:
3333
3358
// / Execute the recipes in the IR basic block \p BB.
3334
3359
void executeRecipes (VPTransformState *State, BasicBlock *BB);
@@ -3343,6 +3368,11 @@ class VPBasicBlock : public VPBlockBase {
3343
3368
BasicBlock *createEmptyBasicBlock (VPTransformState &State);
3344
3369
};
3345
3370
3371
+ inline const VPBasicBlock *
3372
+ VPPhiAccessors::getIncomingBlock (unsigned Idx) const {
3373
+ return getAsRecipe ()->getParent ()->getCFGPredecessor (Idx);
3374
+ }
3375
+
3346
3376
// / A special type of VPBasicBlock that wraps an existing IR basic block.
3347
3377
// / Recipes of the block get added before the first non-phi instruction in the
3348
3378
// / wrapped block.
0 commit comments