@@ -2099,38 +2099,81 @@ class VPHeaderPHIRecipe : public VPSingleDefRecipe {
2099
2099
}
2100
2100
};
2101
2101
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
+
2102
2147
// / A recipe for handling phi nodes of integer and floating-point inductions,
2103
2148
// / producing their vector values.
2104
- class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
2105
- PHINode *IV;
2149
+ class VPWidenIntOrFpInductionRecipe : public VPWidenInductionRecipe {
2106
2150
TruncInst *Trunc;
2107
- const InductionDescriptor &IndDesc;
2108
2151
2109
2152
public:
2110
2153
VPWidenIntOrFpInductionRecipe (PHINode *IV, VPValue *Start, VPValue *Step,
2111
2154
VPValue *VF, const InductionDescriptor &IndDesc,
2112
2155
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 ) {
2116
2159
addOperand (VF);
2117
2160
}
2118
2161
2119
2162
VPWidenIntOrFpInductionRecipe (PHINode *IV, VPValue *Start, VPValue *Step,
2120
2163
VPValue *VF, const InductionDescriptor &IndDesc,
2121
2164
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) {
2125
2168
addOperand (VF);
2126
2169
}
2127
2170
2128
2171
~VPWidenIntOrFpInductionRecipe () override = default ;
2129
2172
2130
2173
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 ());
2134
2177
}
2135
2178
2136
2179
VP_CLASSOF_IMPL (VPDef::VPWidenIntOrFpInductionSC)
@@ -2145,24 +2188,6 @@ class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
2145
2188
VPSlotTracker &SlotTracker) const override ;
2146
2189
#endif
2147
2190
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
-
2166
2191
VPValue *getVFValue () { return getOperand (2 ); }
2167
2192
const VPValue *getVFValue () const { return getOperand (2 ); }
2168
2193
@@ -2177,19 +2202,14 @@ class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
2177
2202
TruncInst *getTruncInst () { return Trunc; }
2178
2203
const TruncInst *getTruncInst () const { return Trunc; }
2179
2204
2180
- PHINode *getPHINode () { return IV; }
2181
-
2182
- // / Returns the induction descriptor for the recipe.
2183
- const InductionDescriptor &getInductionDescriptor () const { return IndDesc; }
2184
-
2185
2205
// / Returns true if the induction is canonical, i.e. starting at 0 and
2186
2206
// / incremented by UF * VF (= the original IV is incremented by 1) and has the
2187
2207
// / same type as the canonical induction.
2188
2208
bool isCanonical () const ;
2189
2209
2190
2210
// / Returns the scalar type of the induction.
2191
2211
Type *getScalarType () const {
2192
- return Trunc ? Trunc->getType () : IV ->getType ();
2212
+ return Trunc ? Trunc->getType () : getPHINode () ->getType ();
2193
2213
}
2194
2214
2195
2215
// / Returns the VPValue representing the value of this induction at
@@ -2200,10 +2220,8 @@ class VPWidenIntOrFpInductionRecipe : public VPHeaderPHIRecipe {
2200
2220
}
2201
2221
};
2202
2222
2203
- class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe ,
2223
+ class VPWidenPointerInductionRecipe : public VPWidenInductionRecipe ,
2204
2224
public VPUnrollPartAccessor<3 > {
2205
- const InductionDescriptor &IndDesc;
2206
-
2207
2225
bool IsScalarAfterVectorization;
2208
2226
2209
2227
public:
@@ -2212,19 +2230,16 @@ class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe,
2212
2230
VPWidenPointerInductionRecipe (PHINode *Phi, VPValue *Start, VPValue *Step,
2213
2231
const InductionDescriptor &IndDesc,
2214
2232
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) {}
2221
2236
2222
2237
~VPWidenPointerInductionRecipe () override = default ;
2223
2238
2224
2239
VPWidenPointerInductionRecipe *clone () override {
2225
2240
return new VPWidenPointerInductionRecipe (
2226
2241
cast<PHINode>(getUnderlyingInstr ()), getOperand (0 ), getOperand (1 ),
2227
- IndDesc , IsScalarAfterVectorization, getDebugLoc ());
2242
+ getInductionDescriptor () , IsScalarAfterVectorization, getDebugLoc ());
2228
2243
}
2229
2244
2230
2245
VP_CLASSOF_IMPL (VPDef::VPWidenPointerInductionSC)
@@ -2235,9 +2250,6 @@ class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe,
2235
2250
// / Returns true if only scalar values will be generated.
2236
2251
bool onlyScalarsGenerated (bool IsScalable);
2237
2252
2238
- // / Returns the induction descriptor for the recipe.
2239
- const InductionDescriptor &getInductionDescriptor () const { return IndDesc; }
2240
-
2241
2253
// / Returns the VPValue representing the value of this induction at
2242
2254
// / the first unrolled part, if it exists. Returns itself if unrolling did not
2243
2255
// / take place.
0 commit comments