[llvm] 08f16a8 - [VPlan] Use macro to define recipe classof implementation (NFC).
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 16 09:52:45 PST 2022
Author: Florian Hahn
Date: 2022-12-16T17:52:15Z
New Revision: 08f16a8217c1024e74c0af79120713f04af1230a
URL: https://github.com/llvm/llvm-project/commit/08f16a8217c1024e74c0af79120713f04af1230a
DIFF: https://github.com/llvm/llvm-project/commit/08f16a8217c1024e74c0af79120713f04af1230a.diff
LOG: [VPlan] Use macro to define recipe classof implementation (NFC).
Add a VP_CLASSOF_IMPL macro to define common classof implementations for
recipes. This reduces duplication and also adds missing implementations
to existing recipes.
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlan.h
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index be6b52430e36f..d4d5ace5773ef 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -767,6 +767,22 @@ inline bool VPUser::classof(const VPDef *Def) {
Def->getVPDefID() == VPRecipeBase::VPWidenMemoryInstructionSC;
}
+// Helper macro to define common classof implementations for recipes.
+#define VP_CLASSOF_IMPL(VPDefID, VPValueID) \
+ static inline bool classof(const VPDef *D) { \
+ return D->getVPDefID() == VPDefID; \
+ } \
+ static inline bool classof(const VPValue *V) { \
+ return V->getVPValueID() == VPValueID; \
+ } \
+ static inline bool classof(const VPUser *U) { \
+ auto *R = dyn_cast<VPRecipeBase>(U); \
+ return R && R->getVPDefID() == VPDefID; \
+ } \
+ static inline bool classof(const VPRecipeBase *R) { \
+ return R->getVPDefID() == VPDefID; \
+ }
+
/// This is a concrete Recipe that models a single VPlan-level instruction.
/// While as any Recipe it may generate a sequence of IR instructions when
/// executed, these instructions would always form a single-def expression as
@@ -822,31 +838,13 @@ class VPInstruction : public VPRecipeBase, public VPValue {
DebugLoc DL = {}, const Twine &Name = "")
: VPInstruction(Opcode, ArrayRef<VPValue *>(Operands), DL, Name) {}
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVInstructionSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPInstructionSC, VPValue::VPVInstructionSC)
VPInstruction *clone() const {
SmallVector<VPValue *, 2> Operands(operands());
return new VPInstruction(Opcode, Operands, DL, Name);
}
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *R) {
- return R->getVPDefID() == VPRecipeBase::VPInstructionSC;
- }
-
- /// Extra classof implementations to allow directly casting from VPUser ->
- /// VPInstruction.
- static inline bool classof(const VPUser *U) {
- auto *R = dyn_cast<VPRecipeBase>(U);
- return R && R->getVPDefID() == VPRecipeBase::VPInstructionSC;
- }
- static inline bool classof(const VPRecipeBase *R) {
- return R->getVPDefID() == VPRecipeBase::VPInstructionSC;
- }
-
unsigned getOpcode() const { return Opcode; }
/// Generate the instruction.
@@ -929,13 +927,7 @@ class VPWidenRecipe : public VPRecipeBase, public VPValue {
~VPWidenRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *D) {
- return D->getVPDefID() == VPRecipeBase::VPWidenSC;
- }
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVWidenSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPWidenSC, VPValue::VPVWidenSC)
/// Produce widened copies of all Ingredients.
void execute(VPTransformState &State) override;
@@ -963,10 +955,7 @@ class VPWidenCallRecipe : public VPRecipeBase, public VPValue {
~VPWidenCallRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *D) {
- return D->getVPDefID() == VPRecipeBase::VPWidenCallSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPWidenCallSC, VPValue::VPVWidenCallSC)
/// Produce a widened version of the call instruction.
void execute(VPTransformState &State) override;
@@ -994,10 +983,7 @@ class VPWidenSelectRecipe : public VPRecipeBase, public VPValue {
~VPWidenSelectRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *D) {
- return D->getVPDefID() == VPRecipeBase::VPWidenSelectSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPWidenSelectSC, VPValue::VPVWidenSelectSC)
/// Produce a widened version of the select instruction.
void execute(VPTransformState &State) override;
@@ -1034,10 +1020,7 @@ class VPWidenGEPRecipe : public VPRecipeBase, public VPValue {
}
~VPWidenGEPRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *D) {
- return D->getVPDefID() == VPRecipeBase::VPWidenGEPSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPWidenGEPSC, VPValue::VPVWidenGEPSC)
/// Generate the gep nodes.
void execute(VPTransformState &State) override;
@@ -1073,10 +1056,8 @@ class VPWidenIntOrFpInductionRecipe : public VPRecipeBase, public VPValue {
~VPWidenIntOrFpInductionRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *D) {
- return D->getVPDefID() == VPRecipeBase::VPWidenIntOrFpInductionSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPWidenIntOrFpInductionSC,
+ VPValue::VPVWidenIntOrFpInductionSC)
/// Generate the vectorized and scalarized versions of the phi node as
/// needed by their users.
@@ -1219,16 +1200,8 @@ class VPWidenPointerInductionRecipe : public VPHeaderPHIRecipe {
~VPWidenPointerInductionRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPRecipeBase *B) {
- return B->getVPDefID() == VPRecipeBase::VPWidenPointerInductionSC;
- }
- static inline bool classof(const VPHeaderPHIRecipe *R) {
- return R->getVPDefID() == VPRecipeBase::VPWidenPointerInductionSC;
- }
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVWidenPointerInductionSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPWidenPointerInductionSC,
+ VPValue::VPVWidenPointerInductionSC)
/// Generate vector values for the pointer induction.
void execute(VPTransformState &State) override;
@@ -1260,16 +1233,7 @@ class VPWidenPHIRecipe : public VPHeaderPHIRecipe {
~VPWidenPHIRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPRecipeBase *B) {
- return B->getVPDefID() == VPRecipeBase::VPWidenPHISC;
- }
- static inline bool classof(const VPHeaderPHIRecipe *R) {
- return R->getVPDefID() == VPRecipeBase::VPWidenPHISC;
- }
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVWidenPHISC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPWidenPHISC, VPValue::VPVWidenPHISC)
/// Generate the phi/select nodes.
void execute(VPTransformState &State) override;
@@ -1301,16 +1265,12 @@ struct VPFirstOrderRecurrencePHIRecipe : public VPHeaderPHIRecipe {
: VPHeaderPHIRecipe(VPVFirstOrderRecurrencePHISC,
VPFirstOrderRecurrencePHISC, Phi, &Start) {}
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPRecipeBase *R) {
- return R->getVPDefID() == VPRecipeBase::VPFirstOrderRecurrencePHISC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPFirstOrderRecurrencePHISC,
+ VPValue::VPVFirstOrderRecurrencePHISC)
+
static inline bool classof(const VPHeaderPHIRecipe *R) {
return R->getVPDefID() == VPRecipeBase::VPFirstOrderRecurrencePHISC;
}
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVFirstOrderRecurrencePHISC;
- }
void execute(VPTransformState &State) override;
@@ -1347,16 +1307,11 @@ class VPReductionPHIRecipe : public VPHeaderPHIRecipe {
~VPReductionPHIRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPRecipeBase *R) {
- return R->getVPDefID() == VPRecipeBase::VPReductionPHISC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPReductionPHISC, VPValue::VPVReductionPHISC)
+
static inline bool classof(const VPHeaderPHIRecipe *R) {
return R->getVPDefID() == VPRecipeBase::VPReductionPHISC;
}
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVReductionPHISC;
- }
/// Generate the phi/select nodes.
void execute(VPTransformState &State) override;
@@ -1396,10 +1351,7 @@ class VPBlendRecipe : public VPRecipeBase, public VPValue {
"of operands");
}
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *D) {
- return D->getVPDefID() == VPRecipeBase::VPBlendSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPBlendSC, VPValue::VPVBlendSC)
/// Return the number of incoming values, taking into account that a single
/// incoming value has no mask.
@@ -1460,7 +1412,6 @@ class VPInterleaveRecipe : public VPRecipeBase {
}
~VPInterleaveRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
static inline bool classof(const VPDef *D) {
return D->getVPDefID() == VPRecipeBase::VPInterleaveSC;
}
@@ -1532,10 +1483,7 @@ class VPReductionRecipe : public VPRecipeBase, public VPValue {
~VPReductionRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVReductionSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPReductionSC, VPValue::VPVReductionSC)
/// Generate the reduction in the loop
void execute(VPTransformState &State) override;
@@ -1586,14 +1534,7 @@ class VPReplicateRecipe : public VPRecipeBase, public VPValue {
~VPReplicateRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *D) {
- return D->getVPDefID() == VPRecipeBase::VPReplicateSC;
- }
-
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVReplicateSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPReplicateSC, VPValue::VPVReplicateSC)
/// Generate replicas of the desired Ingredient. Replicas will be generated
/// for all parts and lanes unless a specific part and lane are specified in
@@ -1856,16 +1797,12 @@ class VPCanonicalIVPHIRecipe : public VPHeaderPHIRecipe {
~VPCanonicalIVPHIRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *D) {
- return D->getVPDefID() == VPCanonicalIVPHISC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPCanonicalIVPHISC,
+ VPValue::VPVCanonicalIVPHISC)
+
static inline bool classof(const VPHeaderPHIRecipe *D) {
return D->getVPDefID() == VPCanonicalIVPHISC;
}
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVCanonicalIVPHISC;
- }
/// Generate the canonical scalar induction phi of the vector loop.
void execute(VPTransformState &State) override;
@@ -1908,16 +1845,12 @@ class VPActiveLaneMaskPHIRecipe : public VPHeaderPHIRecipe {
~VPActiveLaneMaskPHIRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *D) {
- return D->getVPDefID() == VPActiveLaneMaskPHISC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPActiveLaneMaskPHISC,
+ VPValue::VPVActiveLaneMaskPHISC)
+
static inline bool classof(const VPHeaderPHIRecipe *D) {
return D->getVPDefID() == VPActiveLaneMaskPHISC;
}
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVActiveLaneMaskPHISC;
- }
/// Generate the active lane mask phi of the vector loop.
void execute(VPTransformState &State) override;
@@ -1992,22 +1925,7 @@ class VPDerivedIVRecipe : public VPRecipeBase, public VPValue {
~VPDerivedIVRecipe() override = default;
- /// Method to support type inquiry through isa, cast, and dyn_cast.
- static inline bool classof(const VPDef *D) {
- return D->getVPDefID() == VPRecipeBase::VPDerivedIVSC;
- }
- /// Extra classof implementations to allow directly casting from VPUser ->
- /// VPDerivedIVRecipe.
- static inline bool classof(const VPUser *U) {
- auto *R = dyn_cast<VPRecipeBase>(U);
- return R && R->getVPDefID() == VPRecipeBase::VPDerivedIVSC;
- }
- static inline bool classof(const VPRecipeBase *R) {
- return R->getVPDefID() == VPRecipeBase::VPDerivedIVSC;
- }
- static inline bool classof(const VPValue *V) {
- return V->getVPValueID() == VPValue::VPVDerivedIVSC;
- }
+ VP_CLASSOF_IMPL(VPRecipeBase::VPDerivedIVSC, VPValue::VPVInstructionSC)
/// Generate the transformed value of the induction at offset StartValue (1.
/// operand) + IV (2. operand) * StepValue (3, operand).
More information about the llvm-commits
mailing list