diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -603,47 +603,23 @@ }; /// VPRecipeBase is a base class modeling a sequence of one or more output IR -/// instructions. -class VPRecipeBase : public ilist_node_with_parent { +/// instructions. VPRecipeBase owns the the VPValues it defines through VPDef +/// and is responsible for deleting its defined values. Single-value +/// VPRecipeBases that also inherit from VPValue must make sure to inherit from +/// VPRecipeBase before VPValue. +class VPRecipeBase : public ilist_node_with_parent, + public VPDef { friend VPBasicBlock; friend class VPBlockUtils; - const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast). /// Each VPRecipe belongs to a single VPBasicBlock. VPBasicBlock *Parent = nullptr; public: - /// An enumeration for keeping track of the concrete subclass of 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 { - VPBlendSC, - VPBranchOnMaskSC, - VPInstructionSC, - VPInterleaveSC, - VPPredInstPHISC, - VPReductionSC, - VPReplicateSC, - VPWidenCallSC, - VPWidenCanonicalIVSC, - VPWidenGEPSC, - VPWidenIntOrFpInductionSC, - VPWidenMemoryInstructionSC, - VPWidenPHISC, - VPWidenSC, - VPWidenSelectSC - }; - - VPRecipeBase(const unsigned char SC) : SubclassID(SC) {} + VPRecipeBase(const unsigned char SC) : VPDef(SC) {} virtual ~VPRecipeBase() = default; - /// \return an ID for the concrete type of this object. - /// This is used to implement the classof checks. This should not be used - /// for any other purpose, as the values may change as LLVM evolves. - unsigned getVPRecipeID() const { return SubclassID; } - /// \return the VPBasicBlock which this VPRecipe belongs to. VPBasicBlock *getParent() { return Parent; } const VPBasicBlock *getParent() const { return Parent; } @@ -701,26 +677,32 @@ return cast_or_null(VPV->getUnderlyingValue()); return nullptr; } + + /// Method to support type inquiry through isa, cast, and dyn_cast. + static inline bool classof(const VPDef *D) { + // All VPDefs are also VPRecipeBases. + return true; + } }; -inline bool VPUser::classof(const VPRecipeBase *Recipe) { - return Recipe->getVPRecipeID() == VPRecipeBase::VPInstructionSC || - Recipe->getVPRecipeID() == VPRecipeBase::VPWidenSC || - Recipe->getVPRecipeID() == VPRecipeBase::VPWidenCallSC || - Recipe->getVPRecipeID() == VPRecipeBase::VPWidenSelectSC || - Recipe->getVPRecipeID() == VPRecipeBase::VPWidenGEPSC || - Recipe->getVPRecipeID() == VPRecipeBase::VPBlendSC || - Recipe->getVPRecipeID() == VPRecipeBase::VPInterleaveSC || - Recipe->getVPRecipeID() == VPRecipeBase::VPReplicateSC || - Recipe->getVPRecipeID() == VPRecipeBase::VPBranchOnMaskSC || - Recipe->getVPRecipeID() == VPRecipeBase::VPWidenMemoryInstructionSC; +inline bool VPUser::classof(const VPDef *Def) { + return Def->getVPDefID() == VPRecipeBase::VPInstructionSC || + Def->getVPDefID() == VPRecipeBase::VPWidenSC || + Def->getVPDefID() == VPRecipeBase::VPWidenCallSC || + Def->getVPDefID() == VPRecipeBase::VPWidenSelectSC || + Def->getVPDefID() == VPRecipeBase::VPWidenGEPSC || + Def->getVPDefID() == VPRecipeBase::VPBlendSC || + Def->getVPDefID() == VPRecipeBase::VPInterleaveSC || + Def->getVPDefID() == VPRecipeBase::VPReplicateSC || + Def->getVPDefID() == VPRecipeBase::VPBranchOnMaskSC || + Def->getVPDefID() == VPRecipeBase::VPWidenMemoryInstructionSC; } /// 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 /// the VPInstruction is also a single def-use vertex. -class VPInstruction : public VPUser, public VPValue, public VPRecipeBase { +class VPInstruction : public VPValue, public VPUser, public VPRecipeBase { friend class VPlanSlp; public: @@ -746,9 +728,16 @@ public: VPInstruction(unsigned Opcode, ArrayRef Operands) - : VPUser(Operands), VPValue(VPValue::VPInstructionSC), + : VPValue(VPValue::VPInstructionSC), VPUser(Operands), VPRecipeBase(VPRecipeBase::VPInstructionSC), Opcode(Opcode) {} + VPInstruction(unsigned Opcode, ArrayRef Operands) + : VPValue(VPValue::VPInstructionSC), VPUser({}), + VPRecipeBase(VPRecipeBase::VPInstructionSC), Opcode(Opcode) { + for (auto *I : Operands) + addOperand(I->getVPValue()); + } + VPInstruction(unsigned Opcode, std::initializer_list Operands) : VPInstruction(Opcode, ArrayRef(Operands)) {} @@ -763,8 +752,8 @@ } /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *R) { - return R->getVPRecipeID() == VPRecipeBase::VPInstructionSC; + static inline bool classof(const VPDef *R) { + return R->getVPDefID() == VPRecipeBase::VPInstructionSC; } unsigned getOpcode() const { return Opcode; } @@ -822,13 +811,13 @@ template VPWidenRecipe(Instruction &I, iterator_range Operands) : VPRecipeBase(VPWidenSC), VPUser(Operands), - VPValue(VPValue::VPVWidenSC, &I), Ingredient(I) {} + VPValue(VPValue::VPVWidenSC, &I, this), Ingredient(I) {} ~VPWidenRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPWidenSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPWidenSC; } static inline bool classof(const VPValue *V) { return V->getVPValueID() == VPValue::VPVWidenSC; @@ -843,10 +832,7 @@ }; /// A recipe for widening Call instructions. -class VPWidenCallRecipe : public VPRecipeBase, - public VPDef, - public VPUser, - public VPValue { +class VPWidenCallRecipe : public VPRecipeBase, public VPUser, public VPValue { public: template @@ -857,8 +843,8 @@ ~VPWidenCallRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPWidenCallSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPWidenCallSC; } /// Produce a widened version of the call instruction. @@ -870,10 +856,7 @@ }; /// A recipe for widening select instructions. -class VPWidenSelectRecipe : public VPRecipeBase, - public VPDef, - public VPUser, - public VPValue { +class VPWidenSelectRecipe : public VPRecipeBase, public VPUser, public VPValue { /// Is the condition of the select loop invariant? bool InvariantCond; @@ -889,8 +872,8 @@ ~VPWidenSelectRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPWidenSelectSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPWidenSelectSC; } /// Produce a widened version of the select instruction. @@ -903,7 +886,6 @@ /// A recipe for handling GEP instructions. class VPWidenGEPRecipe : public VPRecipeBase, - public VPDef, public VPUser, public VPValue { bool IsPtrLoopInvariant; @@ -930,8 +912,8 @@ ~VPWidenGEPRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPWidenGEPSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPWidenGEPSC; } /// Generate the gep nodes. @@ -950,12 +932,17 @@ public: VPWidenIntOrFpInductionRecipe(PHINode *IV, TruncInst *Trunc = nullptr) - : VPRecipeBase(VPWidenIntOrFpInductionSC), IV(IV), Trunc(Trunc) {} + : VPRecipeBase(VPWidenIntOrFpInductionSC), IV(IV), Trunc(Trunc) { + if (Trunc) + new VPValue(Trunc, this); + else + new VPValue(IV, this); + } ~VPWidenIntOrFpInductionRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPWidenIntOrFpInductionSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPWidenIntOrFpInductionSC; } /// Generate the vectorized and scalarized versions of the phi node as @@ -972,12 +959,14 @@ PHINode *Phi; public: - VPWidenPHIRecipe(PHINode *Phi) : VPRecipeBase(VPWidenPHISC), Phi(Phi) {} + VPWidenPHIRecipe(PHINode *Phi) : VPRecipeBase(VPWidenPHISC), Phi(Phi) { + new VPValue(Phi, this); + } ~VPWidenPHIRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPWidenPHISC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPWidenPHISC; } /// Generate the phi/select nodes. @@ -999,6 +988,7 @@ /// might be incoming with a full mask for which there is no VPValue. VPBlendRecipe(PHINode *Phi, ArrayRef Operands) : VPRecipeBase(VPBlendSC), VPUser(Operands), Phi(Phi) { + new VPValue(Phi, this); assert(Operands.size() > 0 && ((Operands.size() == 1) || (Operands.size() % 2 == 0)) && "Expected either a single incoming value or a positive even number " @@ -1006,8 +996,8 @@ } /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPBlendSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPBlendSC; } /// Return the number of incoming values, taking into account that a single @@ -1030,7 +1020,7 @@ /// VPInterleaveRecipe is a recipe for transforming an interleave group of load /// or stores into one wide load/store and shuffles. -class VPInterleaveRecipe : public VPRecipeBase, public VPDef, public VPUser { +class VPInterleaveRecipe : public VPRecipeBase, public VPUser { const InterleaveGroup *IG; public: @@ -1050,8 +1040,8 @@ ~VPInterleaveRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPInterleaveSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPInterleaveSC; } /// Return the address accessed by this recipe. @@ -1079,7 +1069,7 @@ /// A recipe to represent inloop reduction operations, performing a reduction on /// a vector operand into a scalar value, and adding the result to a chain. /// The Operands are {ChainOp, VecOp, [Condition]}. -class VPReductionRecipe : public VPRecipeBase, public VPValue, public VPUser { +class VPReductionRecipe : public VPRecipeBase, public VPUser, public VPValue { /// The recurrence decriptor for the reduction in question. RecurrenceDescriptor *RdxDesc; /// Fast math flags to use for the resulting reduction operation. @@ -1088,11 +1078,12 @@ const TargetTransformInfo *TTI; public: - VPReductionRecipe(RecurrenceDescriptor *R, Instruction *I, VPValue *ChainOp, - VPValue *VecOp, VPValue *CondOp, const TargetTransformInfo *TTI) - : VPRecipeBase(VPRecipeBase::VPReductionSC), - VPValue(VPValue::VPReductionSC, I), VPUser({ChainOp, VecOp}), - RdxDesc(R), NoNaN(false), TTI(TTI) { + VPReductionRecipe(RecurrenceDescriptor *R, Instruction *I, VPValue *ChainOp, + VPValue *VecOp, VPValue *CondOp, + const TargetTransformInfo *TTI) + : VPRecipeBase(VPRecipeBase::VPReductionSC), VPUser({ChainOp, VecOp}), + VPValue(VPValue::VPReductionSC, I, this), RdxDesc(R), NoNaN(false), + TTI(TTI) { if (CondOp) addOperand(CondOp); } @@ -1100,8 +1091,8 @@ ~VPReductionRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPReductionSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPReductionSC; } /// Generate the reduction in the loop @@ -1148,13 +1139,14 @@ // having predicated instructions also pack their values into a vector by // default unless they have a replicated user which uses their scalar value. AlsoPack = IsPredicated && !I->use_empty(); + new VPValue(I, this); } ~VPReplicateRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPReplicateSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPReplicateSC; } static inline bool classof(const VPValue *V) { @@ -1179,13 +1171,14 @@ class VPBranchOnMaskRecipe : public VPRecipeBase, public VPUser { public: VPBranchOnMaskRecipe(VPValue *BlockInMask) : VPRecipeBase(VPBranchOnMaskSC) { + new VPValue(nullptr, this); if (BlockInMask) // nullptr means all-one mask. addOperand(BlockInMask); } /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPBranchOnMaskSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPBranchOnMaskSC; } /// Generate the extraction of the appropriate bit from the block mask and the @@ -1224,12 +1217,14 @@ /// Construct a VPPredInstPHIRecipe given \p PredInst whose value needs a phi /// nodes after merging back from a Branch-on-Mask. VPPredInstPHIRecipe(Instruction *PredInst) - : VPRecipeBase(VPPredInstPHISC), PredInst(PredInst) {} + : VPRecipeBase(VPPredInstPHISC), PredInst(PredInst) { + new VPValue(PredInst, this); + } ~VPPredInstPHIRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPPredInstPHISC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPPredInstPHISC; } /// Generates phi nodes for live-outs as needed to retain SSA form. @@ -1247,7 +1242,6 @@ /// TODO: We currently execute only per-part unless a specific instance is /// provided. class VPWidenMemoryInstructionRecipe : public VPRecipeBase, - public VPDef, public VPUser, public VPValue { void setMask(VPValue *Mask) { @@ -1275,8 +1269,8 @@ } /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPWidenMemoryInstructionSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPWidenMemoryInstructionSC; } /// Return the address accessed by this recipe. @@ -1310,21 +1304,16 @@ /// A Recipe for widening the canonical induction variable of the vector loop. class VPWidenCanonicalIVRecipe : public VPRecipeBase { - /// A VPValue representing the canonical vector IV. - VPValue Val; - public: - VPWidenCanonicalIVRecipe() : VPRecipeBase(VPWidenCanonicalIVSC) {} - ~VPWidenCanonicalIVRecipe() override = default; + VPWidenCanonicalIVRecipe() : VPRecipeBase(VPWidenCanonicalIVSC) { + new VPValue(nullptr, this); + } - /// Return the VPValue representing the canonical vector induction variable of - /// the vector loop. - const VPValue *getVPValue() const { return &Val; } - VPValue *getVPValue() { return &Val; } + ~VPWidenCanonicalIVRecipe() override = default; /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *V) { - return V->getVPRecipeID() == VPRecipeBase::VPWidenCanonicalIVSC; + static inline bool classof(const VPDef *D) { + return D->getVPDefID() == VPRecipeBase::VPWidenCanonicalIVSC; } /// Generate a canonical vector induction variable of the vector loop, with diff --git a/llvm/lib/Transforms/Vectorize/VPlan.cpp b/llvm/lib/Transforms/Vectorize/VPlan.cpp --- a/llvm/lib/Transforms/Vectorize/VPlan.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlan.cpp @@ -115,42 +115,18 @@ } VPValue *VPRecipeBase::toVPValue() { + if (getNumDefinedValues() == 1) + return getVPValue(); if (auto *V = dyn_cast(this)) return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; return nullptr; } const VPValue *VPRecipeBase::toVPValue() const { + if (getNumDefinedValues() == 1) + return getVPValue(); if (auto *V = dyn_cast(this)) return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; - if (auto *V = dyn_cast(this)) - return V; return nullptr; } diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h --- a/llvm/lib/Transforms/Vectorize/VPlanValue.h +++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h @@ -43,6 +43,7 @@ class VPValue { friend class VPBuilder; friend class VPDef; + friend class VPInstruction; friend struct VPlanTransforms; friend class VPBasicBlock; friend class VPInterleavedAccessInfo; @@ -232,7 +233,7 @@ } /// Method to support type inquiry through isa, cast, and dyn_cast. - static inline bool classof(const VPRecipeBase *Recipe); + static inline bool classof(const VPDef *Recipe); }; /// This class augments a recipe with a set of VPValues defined by the recipe. @@ -243,6 +244,9 @@ class VPDef { friend class VPValue; + /// Subclass identifier (for isa/dyn_cast). + const unsigned char SubclassID; + /// The VPValues defined by this VPDef. TinyPtrVector DefinedValues; @@ -265,6 +269,30 @@ } public: + /// An enumeration for keeping track of the concrete subclass of 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 { + VPBlendSC, + VPBranchOnMaskSC, + VPInstructionSC, + VPInterleaveSC, + VPPredInstPHISC, + VPReductionSC, + VPReplicateSC, + VPWidenCallSC, + VPWidenCanonicalIVSC, + VPWidenGEPSC, + VPWidenIntOrFpInductionSC, + VPWidenMemoryInstructionSC, + VPWidenPHISC, + VPWidenSC, + VPWidenSelectSC + }; + + VPDef(const unsigned char SC) : SubclassID(SC) {} + virtual ~VPDef() { for (VPValue *D : make_early_inc_range(DefinedValues)) { assert(D->Def == this && @@ -291,6 +319,11 @@ /// Returns the number of values defined by the VPDef. unsigned getNumDefinedValues() const { return DefinedValues.size(); } + + /// \return an ID for the concrete type of this object. + /// This is used to implement the classof checks. This should not be used + /// for any other purpose, as the values may change as LLVM evolves. + unsigned getVPDefID() const { return SubclassID; } }; class VPlan; diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp --- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp @@ -365,7 +365,7 @@ EXPECT_TRUE(isa(&Recipe)); VPRecipeBase *BaseR = &Recipe; EXPECT_TRUE(isa(BaseR)); - EXPECT_EQ(&Recipe, BaseR->toVPUser()); + EXPECT_EQ(&Recipe, BaseR); } TEST(VPRecipeTest, CastVPWidenRecipeToVPUser) { @@ -383,11 +383,11 @@ EXPECT_TRUE(isa(&WidenR)); VPRecipeBase *WidenRBase = &WidenR; EXPECT_TRUE(isa(WidenRBase)); - EXPECT_EQ(&WidenR, WidenRBase->toVPUser()); + EXPECT_EQ(&WidenR, WidenRBase); delete AI; } -TEST(VPRecipeTest, CastVPWidenCallRecipeToVPUser) { +TEST(VPRecipeTest, CastVPWidenCallRecipeToVPUserAndVPDef) { LLVMContext C; IntegerType *Int32 = IntegerType::get(C, 32); @@ -402,11 +402,16 @@ EXPECT_TRUE(isa(&Recipe)); VPRecipeBase *BaseR = &Recipe; EXPECT_TRUE(isa(BaseR)); - EXPECT_EQ(&Recipe, BaseR->toVPUser()); + EXPECT_EQ(&Recipe, BaseR); + + VPValue *VPV = &Recipe; + EXPECT_TRUE(isa(VPV->getDef())); + EXPECT_EQ(&Recipe, dyn_cast(VPV->getDef())); + delete Call; } -TEST(VPRecipeTest, CastVPWidenSelectRecipeToVPUser) { +TEST(VPRecipeTest, CastVPWidenSelectRecipeToVPUserAndVPDef) { LLVMContext C; IntegerType *Int1 = IntegerType::get(C, 1); @@ -425,11 +430,16 @@ EXPECT_TRUE(isa(&WidenSelectR)); VPRecipeBase *BaseR = &WidenSelectR; EXPECT_TRUE(isa(BaseR)); - EXPECT_EQ(&WidenSelectR, BaseR->toVPUser()); + EXPECT_EQ(&WidenSelectR, BaseR); + + VPValue *VPV = &WidenSelectR; + EXPECT_TRUE(isa(VPV->getDef())); + EXPECT_EQ(&WidenSelectR, dyn_cast(VPV->getDef())); + delete SelectI; } -TEST(VPRecipeTest, CastVPWidenGEPRecipeToVPUser) { +TEST(VPRecipeTest, CastVPWidenGEPRecipeToVPUserAndVPDef) { LLVMContext C; IntegerType *Int32 = IntegerType::get(C, 32); @@ -445,7 +455,12 @@ EXPECT_TRUE(isa(&Recipe)); VPRecipeBase *BaseR = &Recipe; EXPECT_TRUE(isa(BaseR)); - EXPECT_EQ(&Recipe, BaseR->toVPUser()); + EXPECT_EQ(&Recipe, BaseR); + + VPValue *VPV = &Recipe; + EXPECT_TRUE(isa(VPV->getDef())); + EXPECT_EQ(&Recipe, dyn_cast(VPV->getDef())); + delete GEP; } @@ -476,7 +491,7 @@ EXPECT_TRUE(isa(&Recipe)); VPRecipeBase *BaseR = &Recipe; EXPECT_TRUE(isa(BaseR)); - EXPECT_EQ(&Recipe, BaseR->toVPUser()); + EXPECT_EQ(&Recipe, BaseR); } TEST(VPRecipeTest, CastVPReplicateRecipeToVPUser) { @@ -503,10 +518,10 @@ EXPECT_TRUE(isa(&Recipe)); VPRecipeBase *BaseR = &Recipe; EXPECT_TRUE(isa(BaseR)); - EXPECT_EQ(&Recipe, BaseR->toVPUser()); + EXPECT_EQ(&Recipe, BaseR); } -TEST(VPRecipeTest, CastVPWidenMemoryInstructionRecipeToVPUser) { +TEST(VPRecipeTest, CastVPWidenMemoryInstructionRecipeToVPUserAndVPDef) { LLVMContext C; IntegerType *Int32 = IntegerType::get(C, 32); @@ -519,15 +534,25 @@ EXPECT_TRUE(isa(&Recipe)); VPRecipeBase *BaseR = &Recipe; EXPECT_TRUE(isa(BaseR)); - EXPECT_EQ(&Recipe, BaseR->toVPUser()); + EXPECT_EQ(&Recipe, BaseR); + + VPValue *VPV = &Recipe; + EXPECT_TRUE(isa(VPV->getDef())); + EXPECT_EQ(&Recipe, dyn_cast(VPV->getDef())); + delete Load; } -struct VPDoubleValueDef : public VPUser, public VPDef { - VPDoubleValueDef(ArrayRef Operands) : VPUser(Operands), VPDef() { +struct VPDoubleValueDef : public VPRecipeBase, public VPUser { + VPDoubleValueDef(ArrayRef Operands) + : VPRecipeBase(99), VPUser(Operands) { new VPValue(nullptr, this); new VPValue(nullptr, this); } + + void execute(struct VPTransformState &State) override{}; + void print(raw_ostream &O, const Twine &Indent, + VPSlotTracker &SlotTracker) const override {} }; TEST(VPDoubleValueDefTest, traverseUseLists) {