[llvm] [VPlan] Type VP(Recipe|Block)Ty SubclassID (NFC) (PR #209132)
Ramkumar Ramachandra via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 23:54:46 PDT 2026
https://github.com/artagnon updated https://github.com/llvm/llvm-project/pull/209132
>From 689a1decfdcc4b949b3269eb97e05d057dba726c Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Mon, 13 Jul 2026 11:29:04 +0100
Subject: [PATCH 1/3] [VPlan] Type VP(Recipe|Block)Ty SubclassID (NFC)
With the advantage that switching over the SubclassID would give better
compile-time diagnostics.
Co-authored-by: Luke Lau <luke at igalia.com>
---
llvm/lib/Transforms/Vectorize/VPlan.h | 59 +++++++++----------
.../Transforms/Vectorize/VPlanTest.cpp | 2 +-
2 files changed, 30 insertions(+), 31 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index 46e2ad4716323..e5ca9ab3aa81f 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -94,8 +94,6 @@ enum class UncountableExitStyle {
class LLVM_ABI_FOR_TEST VPBlockBase {
friend class VPBlockUtils;
- const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).
-
/// An optional name for the block.
std::string Name;
@@ -159,10 +157,6 @@ class LLVM_ABI_FOR_TEST VPBlockBase {
*I = New;
}
-protected:
- VPBlockBase(const unsigned char SC, const std::string &N)
- : SubclassID(SC), Name(N) {}
-
public:
/// An enumeration for keeping track of the concrete subclass of VPBlockBase
/// that are actually instantiated. Values of this enumeration are kept in the
@@ -383,6 +377,13 @@ class LLVM_ABI_FOR_TEST VPBlockBase {
/// the cloned recipes, including all blocks in the single-entry single-exit
/// region for VPRegionBlocks.
virtual VPBlockBase *clone() = 0;
+
+private:
+ const VPBlockTy SubclassID; ///< Subclass identifier (for isa/dyn_cast).
+
+protected:
+ VPBlockBase(const VPBlockTy SC, const std::string &N)
+ : Name(N), SubclassID(SC) {}
};
/// VPRecipeBase is a base class modeling a sequence of one or more output IR
@@ -397,9 +398,6 @@ class LLVM_ABI_FOR_TEST VPRecipeBase
friend VPBasicBlock;
friend class VPBlockUtils;
- /// Subclass identifier (for isa/dyn_cast).
- const unsigned char SubclassID;
-
/// Each VPRecipe belongs to a single VPBasicBlock.
VPBasicBlock *Parent = nullptr;
@@ -458,9 +456,9 @@ class LLVM_ABI_FOR_TEST VPRecipeBase
VPLastPHISC = VPReductionPHISC,
};
- VPRecipeBase(const unsigned char SC, ArrayRef<VPValue *> Operands,
+ VPRecipeBase(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
DebugLoc DL = DebugLoc::getUnknown())
- : VPDef(), VPUser(Operands), SubclassID(SC), DL(DL) {}
+ : VPDef(), VPUser(Operands), DL(DL), SubclassID(SC) {}
~VPRecipeBase() override = default;
@@ -514,7 +512,7 @@ class LLVM_ABI_FOR_TEST VPRecipeBase
iplist<VPRecipeBase>::iterator eraseFromParent();
/// \return an ID for the concrete type of this object.
- unsigned getVPRecipeID() const { return SubclassID; }
+ VPRecipeTy getVPRecipeID() const { return SubclassID; }
/// Method to support type inquiry through isa, cast, and dyn_cast.
static inline bool classof(const VPDef *D) {
@@ -560,6 +558,10 @@ class LLVM_ABI_FOR_TEST VPRecipeBase
VPSlotTracker &SlotTracker) const;
#endif
+private:
+ /// Subclass identifier (for isa/dyn_cast).
+ const VPRecipeTy SubclassID;
+
protected:
/// Compute the cost of this recipe either using a recipe's specialized
/// implementation or using the legacy cost model and the underlying
@@ -602,15 +604,15 @@ LLVM_ABI Type *computeScalarTypeForInstruction(unsigned Opcode,
class LLVM_ABI_FOR_TEST VPSingleDefRecipe : public VPRecipeBase,
public VPSingleDefValue {
public:
- VPSingleDefRecipe(const unsigned char SC, ArrayRef<VPValue *> Operands,
+ VPSingleDefRecipe(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
DebugLoc DL = DebugLoc::getUnknown())
: VPRecipeBase(SC, Operands, DL), VPSingleDefValue(this) {}
- VPSingleDefRecipe(const unsigned char SC, ArrayRef<VPValue *> Operands,
+ VPSingleDefRecipe(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
Value *UV, DebugLoc DL = DebugLoc::getUnknown())
: VPRecipeBase(SC, Operands, DL), VPSingleDefValue(this, UV) {}
- VPSingleDefRecipe(const unsigned char SC, ArrayRef<VPValue *> Operands,
+ VPSingleDefRecipe(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
Type *ResultTy, Value *UV = nullptr,
DebugLoc DL = DebugLoc::getUnknown())
: VPRecipeBase(SC, Operands, DL), VPSingleDefValue(this, UV, ResultTy) {}
@@ -1106,12 +1108,12 @@ static_assert(sizeof(VPIRFlags) <= 3, "VPIRFlags should not grow");
/// A pure-virtual common base class for recipes defining a single VPValue and
/// using IR flags.
struct VPRecipeWithIRFlags : public VPSingleDefRecipe, public VPIRFlags {
- VPRecipeWithIRFlags(const unsigned char SC, ArrayRef<VPValue *> Operands,
+ VPRecipeWithIRFlags(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
const VPIRFlags &Flags,
DebugLoc DL = DebugLoc::getUnknown())
: VPSingleDefRecipe(SC, Operands, DL), VPIRFlags(Flags) {}
- VPRecipeWithIRFlags(const unsigned char SC, ArrayRef<VPValue *> Operands,
+ VPRecipeWithIRFlags(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
Type *ResultTy, const VPIRFlags &Flags,
DebugLoc DL = DebugLoc::getUnknown())
: VPSingleDefRecipe(SC, Operands, ResultTy, /*UV=*/nullptr, DL),
@@ -1927,8 +1929,7 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
bool MayHaveSideEffects;
protected:
- VPWidenIntrinsicRecipe(const unsigned char SC,
- Intrinsic::ID VectorIntrinsicID,
+ VPWidenIntrinsicRecipe(const VPRecipeTy SC, Intrinsic::ID VectorIntrinsicID,
ArrayRef<VPValue *> CallArguments, Type *Ty,
const VPIRFlags &Flags = {},
const VPIRMetadata &MD = {},
@@ -2426,12 +2427,12 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags {
class LLVM_ABI_FOR_TEST VPHeaderPHIRecipe : public VPSingleDefRecipe,
public VPPhiAccessors {
protected:
- VPHeaderPHIRecipe(unsigned char VPRecipeID, Instruction *UnderlyingInstr,
+ VPHeaderPHIRecipe(const VPRecipeTy VPRecipeID, Instruction *UnderlyingInstr,
VPValue *Start, DebugLoc DL = DebugLoc::getUnknown())
: VPHeaderPHIRecipe(VPRecipeID, UnderlyingInstr, Start,
Start->getScalarType(), DL) {}
- VPHeaderPHIRecipe(unsigned char VPRecipeID, Instruction *UnderlyingInstr,
+ VPHeaderPHIRecipe(const VPRecipeTy VPRecipeID, Instruction *UnderlyingInstr,
VPValue *Start, Type *ResultTy, DebugLoc DL)
: VPSingleDefRecipe(VPRecipeID, Start, ResultTy, UnderlyingInstr, DL) {}
@@ -2502,13 +2503,13 @@ class VPWidenInductionRecipe : public VPHeaderPHIRecipe {
InductionDescriptor IndDesc;
public:
- VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start,
+ VPWidenInductionRecipe(const VPRecipeTy Kind, PHINode *IV, VPValue *Start,
VPValue *Step, const InductionDescriptor &IndDesc,
DebugLoc DL)
: VPWidenInductionRecipe(Kind, IV, Start, Step, IndDesc,
Start->getScalarType(), DL) {}
- VPWidenInductionRecipe(unsigned char Kind, PHINode *IV, VPValue *Start,
+ VPWidenInductionRecipe(const VPRecipeTy Kind, PHINode *IV, VPValue *Start,
VPValue *Step, const InductionDescriptor &IndDesc,
Type *ResultTy, DebugLoc DL)
: VPHeaderPHIRecipe(Kind, IV, Start, ResultTy, DL), IndDesc(IndDesc) {
@@ -3028,8 +3029,7 @@ class LLVM_ABI_FOR_TEST VPInterleaveBase : public VPRecipeBase,
bool NeedsMaskForGaps = false;
protected:
- VPInterleaveBase(const unsigned char SC,
- const InterleaveGroup<Instruction> *IG,
+ VPInterleaveBase(const VPRecipeTy SC, const InterleaveGroup<Instruction> *IG,
ArrayRef<VPValue *> Operands,
ArrayRef<VPValue *> StoredValues, VPValue *Mask,
bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
@@ -3214,10 +3214,9 @@ class LLVM_ABI_FOR_TEST VPReductionRecipe : public VPRecipeWithIRFlags {
ReductionStyle Style;
protected:
- VPReductionRecipe(const unsigned char SC, RecurKind RdxKind,
- FastMathFlags FMFs, Instruction *I,
- ArrayRef<VPValue *> Operands, VPValue *CondOp,
- ReductionStyle Style, DebugLoc DL)
+ VPReductionRecipe(const VPRecipeTy SC, RecurKind RdxKind, FastMathFlags FMFs,
+ Instruction *I, ArrayRef<VPValue *> Operands,
+ VPValue *CondOp, ReductionStyle Style, DebugLoc DL)
: VPRecipeWithIRFlags(SC, Operands, Operands[0]->getScalarType(), FMFs,
DL),
RdxKind(RdxKind), Style(Style) {
@@ -4371,7 +4370,7 @@ class LLVM_ABI_FOR_TEST VPBasicBlock : public VPBlockBase {
/// The VPRecipes held in the order of output instructions to generate.
RecipeListTy Recipes;
- VPBasicBlock(const unsigned char BlockSC, const Twine &Name = "")
+ VPBasicBlock(const VPBlockTy BlockSC, const Twine &Name = "")
: VPBlockBase(BlockSC, Name.str()) {}
public:
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index f3e90bb805b27..f10435dfb2da6 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -1762,7 +1762,7 @@ TEST_F(VPRecipeTest, CastVPReductionEVLRecipeToVPUser) {
struct VPDoubleValueDef : public VPRecipeBase {
VPDoubleValueDef(ArrayRef<VPValue *> Operands, Type *Ty)
- : VPRecipeBase(99, Operands) {
+ : VPRecipeBase(VPRecipeBase::VPInterleaveSC, Operands) {
new VPMultiDefValue(this, /*UV=*/nullptr, Ty);
new VPMultiDefValue(this, /*UV=*/nullptr, Ty);
}
>From f1c5a821ca1c17e84715211458f93f8d278ddcf5 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Mon, 13 Jul 2026 12:35:58 +0100
Subject: [PATCH 2/3] [VPlan] Drop const in constructor args
---
llvm/lib/Transforms/Vectorize/VPlan.h | 36 +++++++++++++--------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index e5ca9ab3aa81f..a1822c0f5e017 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -382,8 +382,7 @@ class LLVM_ABI_FOR_TEST VPBlockBase {
const VPBlockTy SubclassID; ///< Subclass identifier (for isa/dyn_cast).
protected:
- VPBlockBase(const VPBlockTy SC, const std::string &N)
- : Name(N), SubclassID(SC) {}
+ VPBlockBase(VPBlockTy SC, const std::string &N) : Name(N), SubclassID(SC) {}
};
/// VPRecipeBase is a base class modeling a sequence of one or more output IR
@@ -456,7 +455,7 @@ class LLVM_ABI_FOR_TEST VPRecipeBase
VPLastPHISC = VPReductionPHISC,
};
- VPRecipeBase(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
+ VPRecipeBase(VPRecipeTy SC, ArrayRef<VPValue *> Operands,
DebugLoc DL = DebugLoc::getUnknown())
: VPDef(), VPUser(Operands), DL(DL), SubclassID(SC) {}
@@ -604,17 +603,16 @@ LLVM_ABI Type *computeScalarTypeForInstruction(unsigned Opcode,
class LLVM_ABI_FOR_TEST VPSingleDefRecipe : public VPRecipeBase,
public VPSingleDefValue {
public:
- VPSingleDefRecipe(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
+ VPSingleDefRecipe(VPRecipeTy SC, ArrayRef<VPValue *> Operands,
DebugLoc DL = DebugLoc::getUnknown())
: VPRecipeBase(SC, Operands, DL), VPSingleDefValue(this) {}
- VPSingleDefRecipe(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
- Value *UV, DebugLoc DL = DebugLoc::getUnknown())
+ VPSingleDefRecipe(VPRecipeTy SC, ArrayRef<VPValue *> Operands, Value *UV,
+ DebugLoc DL = DebugLoc::getUnknown())
: VPRecipeBase(SC, Operands, DL), VPSingleDefValue(this, UV) {}
- VPSingleDefRecipe(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
- Type *ResultTy, Value *UV = nullptr,
- DebugLoc DL = DebugLoc::getUnknown())
+ VPSingleDefRecipe(VPRecipeTy SC, ArrayRef<VPValue *> Operands, Type *ResultTy,
+ Value *UV = nullptr, DebugLoc DL = DebugLoc::getUnknown())
: VPRecipeBase(SC, Operands, DL), VPSingleDefValue(this, UV, ResultTy) {}
static inline bool classof(const VPRecipeBase *R) {
@@ -1108,12 +1106,12 @@ static_assert(sizeof(VPIRFlags) <= 3, "VPIRFlags should not grow");
/// A pure-virtual common base class for recipes defining a single VPValue and
/// using IR flags.
struct VPRecipeWithIRFlags : public VPSingleDefRecipe, public VPIRFlags {
- VPRecipeWithIRFlags(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
+ VPRecipeWithIRFlags(VPRecipeTy SC, ArrayRef<VPValue *> Operands,
const VPIRFlags &Flags,
DebugLoc DL = DebugLoc::getUnknown())
: VPSingleDefRecipe(SC, Operands, DL), VPIRFlags(Flags) {}
- VPRecipeWithIRFlags(const VPRecipeTy SC, ArrayRef<VPValue *> Operands,
+ VPRecipeWithIRFlags(VPRecipeTy SC, ArrayRef<VPValue *> Operands,
Type *ResultTy, const VPIRFlags &Flags,
DebugLoc DL = DebugLoc::getUnknown())
: VPSingleDefRecipe(SC, Operands, ResultTy, /*UV=*/nullptr, DL),
@@ -1929,7 +1927,7 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
bool MayHaveSideEffects;
protected:
- VPWidenIntrinsicRecipe(const VPRecipeTy SC, Intrinsic::ID VectorIntrinsicID,
+ VPWidenIntrinsicRecipe(VPRecipeTy SC, Intrinsic::ID VectorIntrinsicID,
ArrayRef<VPValue *> CallArguments, Type *Ty,
const VPIRFlags &Flags = {},
const VPIRMetadata &MD = {},
@@ -2427,12 +2425,12 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags {
class LLVM_ABI_FOR_TEST VPHeaderPHIRecipe : public VPSingleDefRecipe,
public VPPhiAccessors {
protected:
- VPHeaderPHIRecipe(const VPRecipeTy VPRecipeID, Instruction *UnderlyingInstr,
+ VPHeaderPHIRecipe(VPRecipeTy VPRecipeID, Instruction *UnderlyingInstr,
VPValue *Start, DebugLoc DL = DebugLoc::getUnknown())
: VPHeaderPHIRecipe(VPRecipeID, UnderlyingInstr, Start,
Start->getScalarType(), DL) {}
- VPHeaderPHIRecipe(const VPRecipeTy VPRecipeID, Instruction *UnderlyingInstr,
+ VPHeaderPHIRecipe(VPRecipeTy VPRecipeID, Instruction *UnderlyingInstr,
VPValue *Start, Type *ResultTy, DebugLoc DL)
: VPSingleDefRecipe(VPRecipeID, Start, ResultTy, UnderlyingInstr, DL) {}
@@ -2503,13 +2501,13 @@ class VPWidenInductionRecipe : public VPHeaderPHIRecipe {
InductionDescriptor IndDesc;
public:
- VPWidenInductionRecipe(const VPRecipeTy Kind, PHINode *IV, VPValue *Start,
+ VPWidenInductionRecipe(VPRecipeTy Kind, PHINode *IV, VPValue *Start,
VPValue *Step, const InductionDescriptor &IndDesc,
DebugLoc DL)
: VPWidenInductionRecipe(Kind, IV, Start, Step, IndDesc,
Start->getScalarType(), DL) {}
- VPWidenInductionRecipe(const VPRecipeTy Kind, PHINode *IV, VPValue *Start,
+ VPWidenInductionRecipe(VPRecipeTy Kind, PHINode *IV, VPValue *Start,
VPValue *Step, const InductionDescriptor &IndDesc,
Type *ResultTy, DebugLoc DL)
: VPHeaderPHIRecipe(Kind, IV, Start, ResultTy, DL), IndDesc(IndDesc) {
@@ -3029,7 +3027,7 @@ class LLVM_ABI_FOR_TEST VPInterleaveBase : public VPRecipeBase,
bool NeedsMaskForGaps = false;
protected:
- VPInterleaveBase(const VPRecipeTy SC, const InterleaveGroup<Instruction> *IG,
+ VPInterleaveBase(VPRecipeTy SC, const InterleaveGroup<Instruction> *IG,
ArrayRef<VPValue *> Operands,
ArrayRef<VPValue *> StoredValues, VPValue *Mask,
bool NeedsMaskForGaps, const VPIRMetadata &MD, DebugLoc DL)
@@ -3214,7 +3212,7 @@ class LLVM_ABI_FOR_TEST VPReductionRecipe : public VPRecipeWithIRFlags {
ReductionStyle Style;
protected:
- VPReductionRecipe(const VPRecipeTy SC, RecurKind RdxKind, FastMathFlags FMFs,
+ VPReductionRecipe(VPRecipeTy SC, RecurKind RdxKind, FastMathFlags FMFs,
Instruction *I, ArrayRef<VPValue *> Operands,
VPValue *CondOp, ReductionStyle Style, DebugLoc DL)
: VPRecipeWithIRFlags(SC, Operands, Operands[0]->getScalarType(), FMFs,
@@ -4370,7 +4368,7 @@ class LLVM_ABI_FOR_TEST VPBasicBlock : public VPBlockBase {
/// The VPRecipes held in the order of output instructions to generate.
RecipeListTy Recipes;
- VPBasicBlock(const VPBlockTy BlockSC, const Twine &Name = "")
+ VPBasicBlock(VPBlockTy BlockSC, const Twine &Name = "")
: VPBlockBase(BlockSC, Name.str()) {}
public:
>From 39e668a730b4968059a7e43daf4697b217607262 Mon Sep 17 00:00:00 2001
From: Ramkumar Ramachandra <artagnon at tenstorrent.com>
Date: Tue, 14 Jul 2026 07:53:30 +0100
Subject: [PATCH 3/3] [VPlan] Missed change: enum inherits from unsigned char
---
llvm/lib/Transforms/Vectorize/VPlan.h | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h
index a1822c0f5e017..47c34157533e4 100644
--- a/llvm/lib/Transforms/Vectorize/VPlan.h
+++ b/llvm/lib/Transforms/Vectorize/VPlan.h
@@ -162,7 +162,11 @@ class LLVM_ABI_FOR_TEST VPBlockBase {
/// that are actually instantiated. Values of this enumeration are kept in the
/// SubclassID field of the VPBlockBase objects. They are used for concrete
/// type identification.
- using VPBlockTy = enum { VPRegionBlockSC, VPBasicBlockSC, VPIRBasicBlockSC };
+ using VPBlockTy = enum : unsigned char {
+ VPRegionBlockSC,
+ VPBasicBlockSC,
+ VPIRBasicBlockSC
+ };
using VPBlocksTy = SmallVectorImpl<VPBlockBase *>;
@@ -408,7 +412,7 @@ class LLVM_ABI_FOR_TEST VPRecipeBase
/// that is actually instantiated. Values of this enumeration are kept in the
/// SubclassID field of the VPRecipeBase objects. They are used for concrete
/// type identification.
- using VPRecipeTy = enum {
+ using VPRecipeTy = enum : unsigned char {
VPBranchOnMaskSC,
VPDerivedIVSC,
VPExpandSCEVSC,
More information about the llvm-commits
mailing list