@@ -2099,38 +2099,81 @@ class VPHeaderPHIRecipe : public VPSingleDefRecipe {
20992099 }
21002100};
21012101
2102+ // / Base class for widened induction (VPWidenIntOrFpInductionRecipe and
2103+ // / VPWidenPointerInductionRecipe), providing shared functionality, including
2104+ // / retrieving the step value, induction descriptor and original phi node.
2105+ class VPWidenInductionRecipe : public VPHeaderPHIRecipe {
2106+ const InductionDescriptor &IndDesc;
2107+
2108+ public:
2109+ VPWidenInductionRecipe (unsigned char Kind, PHINode *IV, VPValue *Start,
2110+ VPValue *Step, const InductionDescriptor &IndDesc,
2111+ DebugLoc DL)
2112+ : VPHeaderPHIRecipe(Kind, IV, Start, DL), IndDesc(IndDesc) {
2113+ addOperand (Step);
2114+ }
2115+
2116+ static inline bool classof (const VPRecipeBase *R) {
2117+ return R->getVPDefID () == VPDef::VPWidenIntOrFpInductionSC ||
2118+ R->getVPDefID () == VPDef::VPWidenPointerInductionSC;
2119+ }
2120+
2121+ virtual void execute (VPTransformState &State) override = 0;
2122+
2123+ // / Returns the step value of the induction.
2124+ VPValue *getStepValue () { return getOperand (1 ); }
2125+ const VPValue *getStepValue () const { return getOperand (1 ); }
2126+
2127+ PHINode *getPHINode () const { return cast<PHINode>(getUnderlyingValue ()); }
2128+
2129+ // / Returns the induction descriptor for the recipe.
2130+ const InductionDescriptor &getInductionDescriptor () const { return IndDesc; }
2131+
2132+ VPValue *getBackedgeValue () override {
2133+ // TODO: All operands of base recipe must exist and be at same index in
2134+ // derived recipe.
2135+ llvm_unreachable (
2136+ " VPWidenIntOrFpInductionRecipe generates its own backedge value" );
2137+ }
2138+
2139+ VPRecipeBase &getBackedgeRecipe () override {
2140+ // TODO: All operands of base recipe must exist and be at same index in
2141+ // derived recipe.
2142+ llvm_unreachable (
2143+ " VPWidenIntOrFpInductionRecipe generates its own backedge value" );
2144+ }
2145+ };
2146+
21022147// / A recipe for handling phi nodes of integer and floating-point inductions,
21032148// / producing their vector values.
2104- class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
2105- PHINode *IV;
2149+ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
21062150 TruncInst *Trunc;
2107- const InductionDescriptor &IndDesc;
21082151
21092152public:
21102153 VPWidenIntOrFpInductionRecipe (PHINode *IV, VPValue *Start, VPValue *Step,
21112154 VPValue *VF, const InductionDescriptor &IndDesc,
21122155 DebugLoc DL)
2113- : VPHeaderPHIRecipe (VPDef::VPWidenIntOrFpInductionSC, IV, Start, DL) ,
2114- IV (IV), Trunc( nullptr ) , IndDesc(IndDesc) {
2115- addOperand (Step);
2156+ : VPWidenInductionRecipe (VPDef::VPWidenIntOrFpInductionSC, IV, Start,
2157+ Step , IndDesc, DL),
2158+ Trunc ( nullptr ) {
21162159 addOperand (VF);
21172160 }
21182161
21192162 VPWidenIntOrFpInductionRecipe (PHINode *IV, VPValue *Start, VPValue *Step,
21202163 VPValue *VF, const InductionDescriptor &IndDesc,
21212164 TruncInst *Trunc, DebugLoc DL)
2122- : VPHeaderPHIRecipe (VPDef::VPWidenIntOrFpInductionSC, Trunc , Start, DL) ,
2123- IV(IV), Trunc(Trunc) , IndDesc(IndDesc) {
2124- addOperand (Step);
2165+ : VPWidenInductionRecipe (VPDef::VPWidenIntOrFpInductionSC, IV , Start,
2166+ Step , IndDesc, DL),
2167+ Trunc(Trunc) {
21252168 addOperand (VF);
21262169 }
21272170
21282171 ~VPWidenIntOrFpInductionRecipe () override = default ;
21292172
21302173 VPWidenIntOrFpInductionRecipe *clone () override {
2131- return new VPWidenIntOrFpInductionRecipe (IV, getStartValue (),
2132- getStepValue (), getVFValue (),
2133- IndDesc , Trunc, getDebugLoc ());
2174+ return new VPWidenIntOrFpInductionRecipe (
2175+ getPHINode (), getStartValue (), getStepValue (), getVFValue (),
2176+ getInductionDescriptor () , Trunc, getDebugLoc ());
21342177 }
21352178
21362179 VP_CLASSOF_IMPL (VPDef::VPWidenIntOrFpInductionSC)
@@ -2145,24 +2188,6 @@ class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
21452188 VPSlotTracker &SlotTracker) const override ;
21462189#endif
21472190
2148- VPValue *getBackedgeValue () override {
2149- // TODO: All operands of base recipe must exist and be at same index in
2150- // derived recipe.
2151- llvm_unreachable (
2152- " VPWidenIntOrFpInductionRecipe generates its own backedge value" );
2153- }
2154-
2155- VPRecipeBase &getBackedgeRecipe () override {
2156- // TODO: All operands of base recipe must exist and be at same index in
2157- // derived recipe.
2158- llvm_unreachable (
2159- " VPWidenIntOrFpInductionRecipe generates its own backedge value" );
2160- }
2161-
2162- // / Returns the step value of the induction.
2163- VPValue *getStepValue () { return getOperand (1 ); }
2164- const VPValue *getStepValue () const { return getOperand (1 ); }
2165-
21662191 VPValue *getVFValue () { return getOperand (2 ); }
21672192 const VPValue *getVFValue () const { return getOperand (2 ); }
21682193
@@ -2177,19 +2202,14 @@ class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
21772202 TruncInst *getTruncInst () { return Trunc; }
21782203 const TruncInst *getTruncInst () const { return Trunc; }
21792204
2180- PHINode *getPHINode () { return IV; }
2181-
2182- // / Returns the induction descriptor for the recipe.
2183- const InductionDescriptor &getInductionDescriptor () const { return IndDesc; }
2184-
21852205 // / Returns true if the induction is canonical, i.e. starting at 0 and
21862206 // / incremented by UF * VF (= the original IV is incremented by 1) and has the
21872207 // / same type as the canonical induction.
21882208 bool isCanonical () const ;
21892209
21902210 // / Returns the scalar type of the induction.
21912211 Type *getScalarType () const {
2192- return Trunc ? Trunc->getType () : IV ->getType ();
2212+ return Trunc ? Trunc->getType () : getPHINode () ->getType ();
21932213 }
21942214
21952215 // / Returns the VPValue representing the value of this induction at
@@ -2200,10 +2220,8 @@ class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
22002220 }
22012221};
22022222
2203- class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe ,
2223+ class VPWidenPointerInductionRecipe : public VPWidenInductionRecipe ,
22042224 public VPUnrollPartAccessor<3 > {
2205- const InductionDescriptor &IndDesc;
2206-
22072225 bool IsScalarAfterVectorization;
22082226
22092227public:
@@ -2212,19 +2230,16 @@ class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe,
22122230 VPWidenPointerInductionRecipe (PHINode *Phi, VPValue *Start, VPValue *Step,
22132231 const InductionDescriptor &IndDesc,
22142232 bool IsScalarAfterVectorization, DebugLoc DL)
2215- : VPHeaderPHIRecipe(VPDef::VPWidenPointerInductionSC, Phi, nullptr , DL),
2216- IndDesc (IndDesc),
2217- IsScalarAfterVectorization(IsScalarAfterVectorization) {
2218- addOperand (Start);
2219- addOperand (Step);
2220- }
2233+ : VPWidenInductionRecipe(VPDef::VPWidenPointerInductionSC, Phi, Start,
2234+ Step, IndDesc, DL),
2235+ IsScalarAfterVectorization (IsScalarAfterVectorization) {}
22212236
22222237 ~VPWidenPointerInductionRecipe () override = default ;
22232238
22242239 VPWidenPointerInductionRecipe *clone () override {
22252240 return new VPWidenPointerInductionRecipe (
22262241 cast<PHINode>(getUnderlyingInstr ()), getOperand (0 ), getOperand (1 ),
2227- IndDesc , IsScalarAfterVectorization, getDebugLoc ());
2242+ getInductionDescriptor () , IsScalarAfterVectorization, getDebugLoc ());
22282243 }
22292244
22302245 VP_CLASSOF_IMPL (VPDef::VPWidenPointerInductionSC)
@@ -2235,9 +2250,6 @@ class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe,
22352250 // / Returns true if only scalar values will be generated.
22362251 bool onlyScalarsGenerated (bool IsScalable);
22372252
2238- // / Returns the induction descriptor for the recipe.
2239- const InductionDescriptor &getInductionDescriptor () const { return IndDesc; }
2240-
22412253 // / Returns the VPValue representing the value of this induction at
22422254 // / the first unrolled part, if it exists. Returns itself if unrolling did not
22432255 // / take place.
0 commit comments