[llvm] 65cd9e4 - [VPlan] Make VPValue constructors protected. (NFC)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 17 14:17:58 PST 2025
Author: Florian Hahn
Date: 2025-01-17T22:17:12Z
New Revision: 65cd9e4c2f85bd119eb039df1c90e8c97cbffb0c
URL: https://github.com/llvm/llvm-project/commit/65cd9e4c2f85bd119eb039df1c90e8c97cbffb0c
DIFF: https://github.com/llvm/llvm-project/commit/65cd9e4c2f85bd119eb039df1c90e8c97cbffb0c.diff
LOG: [VPlan] Make VPValue constructors protected. (NFC)
Tighten access to constructors similar to ef1260acc0. VPValues should
either be constructed by constructors of recipes defining them or should
be live-ins created by VPlan (via getOrAddLiveIn).
Added:
Modified:
llvm/lib/Transforms/Vectorize/VPlanValue.h
llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/VPlanValue.h b/llvm/lib/Transforms/Vectorize/VPlanValue.h
index 7aaf4002b8b3e7..23e39ce89a3a42 100644
--- a/llvm/lib/Transforms/Vectorize/VPlanValue.h
+++ b/llvm/lib/Transforms/Vectorize/VPlanValue.h
@@ -33,9 +33,11 @@ namespace llvm {
class raw_ostream;
class Value;
class VPDef;
+struct VPDoubleValueDef;
class VPSlotTracker;
class VPUser;
class VPRecipeBase;
+class VPInterleaveRecipe;
// This is the base class of the VPlan Def/Use graph, used for modeling the data
// flow into, within and out of the VPlan. VPValues can stand for live-ins
@@ -44,12 +46,15 @@ class VPRecipeBase;
class VPValue {
friend class VPBuilder;
friend class VPDef;
+ friend struct VPDoubleValueDef;
friend class VPInstruction;
+ friend class VPInterleaveRecipe;
friend struct VPlanTransforms;
friend class VPBasicBlock;
friend class VPInterleavedAccessInfo;
friend class VPSlotTracker;
friend class VPRecipeBase;
+ friend class VPlan;
const unsigned char SubclassID; ///< Subclass identifier (for isa/dyn_cast).
@@ -65,6 +70,13 @@ class VPValue {
VPValue(const unsigned char SC, Value *UV = nullptr, VPDef *Def = nullptr);
+ /// Create a live-in VPValue.
+ VPValue(Value *UV = nullptr) : VPValue(VPValueSC, UV, nullptr) {}
+ /// Create a VPValue for a \p Def which is a subclass of VPValue.
+ VPValue(VPDef *Def, Value *UV = nullptr) : VPValue(VPVRecipeSC, UV, Def) {}
+ /// Create a VPValue for a \p Def which defines multiple values.
+ VPValue(Value *UV, VPDef *Def) : VPValue(VPValueSC, UV, Def) {}
+
// DESIGN PRINCIPLE: Access to the underlying IR must be strictly limited to
// the front-end and back-end of VPlan so that the middle-end is as
// independent as possible of the underlying IR. We grant access to the
@@ -84,12 +96,6 @@ class VPValue {
VPVRecipeSC /// A VPValue sub-class that is a VPRecipeBase.
};
- /// Create a live-in VPValue.
- VPValue(Value *UV = nullptr) : VPValue(VPValueSC, UV, nullptr) {}
- /// Create a VPValue for a \p Def which is a subclass of VPValue.
- VPValue(VPDef *Def, Value *UV = nullptr) : VPValue(VPVRecipeSC, UV, Def) {}
- /// Create a VPValue for a \p Def which defines multiple values.
- VPValue(Value *UV, VPDef *Def) : VPValue(VPValueSC, UV, Def) {}
VPValue(const VPValue &) = delete;
VPValue &operator=(const VPValue &) = delete;
diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
index 92a0ffd000e541..73dde0af8afdd7 100644
--- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
+++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp
@@ -19,6 +19,7 @@
#include <string>
namespace llvm {
+
namespace {
#define CHECK_ITERATOR(Range1, ...) \
@@ -131,8 +132,9 @@ TEST_F(VPInstructionTest, moveBefore) {
}
TEST_F(VPInstructionTest, setOperand) {
- VPValue *VPV1 = new VPValue();
- VPValue *VPV2 = new VPValue();
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPValue *VPV1 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *VPV2 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 2));
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});
EXPECT_EQ(1u, VPV1->getNumUsers());
EXPECT_EQ(I1, *VPV1->user_begin());
@@ -140,7 +142,7 @@ TEST_F(VPInstructionTest, setOperand) {
EXPECT_EQ(I1, *VPV2->user_begin());
// Replace operand 0 (VPV1) with VPV3.
- VPValue *VPV3 = new VPValue();
+ VPValue *VPV3 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 3));
I1->setOperand(0, VPV3);
EXPECT_EQ(0u, VPV1->getNumUsers());
EXPECT_EQ(1u, VPV2->getNumUsers());
@@ -157,7 +159,7 @@ TEST_F(VPInstructionTest, setOperand) {
EXPECT_EQ(I1, *std::next(VPV3->user_begin()));
// Replace operand 0 (VPV3) with VPV4.
- VPValue *VPV4 = new VPValue();
+ VPValue *VPV4 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 4));
I1->setOperand(0, VPV4);
EXPECT_EQ(1u, VPV3->getNumUsers());
EXPECT_EQ(I1, *VPV3->user_begin());
@@ -170,19 +172,16 @@ TEST_F(VPInstructionTest, setOperand) {
EXPECT_EQ(I1, *std::next(VPV4->user_begin()));
delete I1;
- delete VPV1;
- delete VPV2;
- delete VPV3;
- delete VPV4;
}
TEST_F(VPInstructionTest, replaceAllUsesWith) {
- VPValue *VPV1 = new VPValue();
- VPValue *VPV2 = new VPValue();
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPValue *VPV1 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *VPV2 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 2));
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});
// Replace all uses of VPV1 with VPV3.
- VPValue *VPV3 = new VPValue();
+ VPValue *VPV3 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 3));
VPV1->replaceAllUsesWith(VPV3);
EXPECT_EQ(VPV3, I1->getOperand(0));
EXPECT_EQ(VPV2, I1->getOperand(1));
@@ -217,14 +216,12 @@ TEST_F(VPInstructionTest, replaceAllUsesWith) {
delete I1;
delete I2;
- delete VPV1;
- delete VPV2;
- delete VPV3;
}
TEST_F(VPInstructionTest, releaseOperandsAtDeletion) {
- VPValue *VPV1 = new VPValue();
- VPValue *VPV2 = new VPValue();
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPValue *VPV1 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *VPV2 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
VPInstruction *I1 = new VPInstruction(0, {VPV1, VPV2});
EXPECT_EQ(1u, VPV1->getNumUsers());
@@ -236,9 +233,6 @@ TEST_F(VPInstructionTest, releaseOperandsAtDeletion) {
EXPECT_EQ(0u, VPV1->getNumUsers());
EXPECT_EQ(0u, VPV2->getNumUsers());
-
- delete VPV1;
- delete VPV2;
}
using VPBasicBlockTest = VPlanTestBase;
@@ -869,9 +863,11 @@ No successors
using VPRecipeTest = VPlanTestBase;
TEST_F(VPRecipeTest, CastVPInstructionToVPUser) {
- VPValue Op1;
- VPValue Op2;
- VPInstruction Recipe(Instruction::Add, {&Op1, &Op2});
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPlan &Plan = getPlan();
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPInstruction Recipe(Instruction::Add, {Op1, Op2});
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
@@ -879,14 +875,15 @@ TEST_F(VPRecipeTest, CastVPInstructionToVPUser) {
}
TEST_F(VPRecipeTest, CastVPWidenRecipeToVPUser) {
+ VPlan &Plan = getPlan();
IntegerType *Int32 = IntegerType::get(C, 32);
auto *AI = BinaryOperator::CreateAdd(PoisonValue::get(Int32),
PoisonValue::get(Int32));
- VPValue Op1;
- VPValue Op2;
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
SmallVector<VPValue *, 2> Args;
- Args.push_back(&Op1);
- Args.push_back(&Op1);
+ Args.push_back(Op1);
+ Args.push_back(Op2);
VPWidenRecipe WidenR(*AI, make_range(Args.begin(), Args.end()));
EXPECT_TRUE(isa<VPUser>(&WidenR));
VPRecipeBase *WidenRBase = &WidenR;
@@ -896,17 +893,18 @@ TEST_F(VPRecipeTest, CastVPWidenRecipeToVPUser) {
}
TEST_F(VPRecipeTest, CastVPWidenCallRecipeToVPUserAndVPDef) {
+ VPlan &Plan = getPlan();
IntegerType *Int32 = IntegerType::get(C, 32);
FunctionType *FTy = FunctionType::get(Int32, false);
Function *Fn = Function::Create(FTy, GlobalValue::ExternalLinkage, 0);
auto *Call = CallInst::Create(FTy, Fn);
- VPValue Op1;
- VPValue Op2;
- VPValue CalledFn(Call->getCalledFunction());
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *CalledFn = Plan.getOrAddLiveIn(Call->getCalledFunction());
SmallVector<VPValue *, 2> Args;
- Args.push_back(&Op1);
- Args.push_back(&Op2);
- Args.push_back(&CalledFn);
+ Args.push_back(Op1);
+ Args.push_back(Op2);
+ Args.push_back(CalledFn);
VPWidenCallRecipe Recipe(Call, Fn, Args);
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
@@ -922,17 +920,18 @@ TEST_F(VPRecipeTest, CastVPWidenCallRecipeToVPUserAndVPDef) {
}
TEST_F(VPRecipeTest, CastVPWidenSelectRecipeToVPUserAndVPDef) {
+ VPlan &Plan = getPlan();
IntegerType *Int1 = IntegerType::get(C, 1);
IntegerType *Int32 = IntegerType::get(C, 32);
auto *SelectI = SelectInst::Create(
PoisonValue::get(Int1), PoisonValue::get(Int32), PoisonValue::get(Int32));
- VPValue Op1;
- VPValue Op2;
- VPValue Op3;
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *Op3 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 3));
SmallVector<VPValue *, 4> Args;
- Args.push_back(&Op1);
- Args.push_back(&Op2);
- Args.push_back(&Op3);
+ Args.push_back(Op1);
+ Args.push_back(Op2);
+ Args.push_back(Op3);
VPWidenSelectRecipe WidenSelectR(*SelectI,
make_range(Args.begin(), Args.end()));
EXPECT_TRUE(isa<VPUser>(&WidenSelectR));
@@ -948,15 +947,16 @@ TEST_F(VPRecipeTest, CastVPWidenSelectRecipeToVPUserAndVPDef) {
}
TEST_F(VPRecipeTest, CastVPWidenGEPRecipeToVPUserAndVPDef) {
+ VPlan &Plan = getPlan();
IntegerType *Int32 = IntegerType::get(C, 32);
PointerType *Int32Ptr = PointerType::get(Int32, 0);
auto *GEP = GetElementPtrInst::Create(Int32, PoisonValue::get(Int32Ptr),
PoisonValue::get(Int32));
- VPValue Op1;
- VPValue Op2;
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
SmallVector<VPValue *, 4> Args;
- Args.push_back(&Op1);
- Args.push_back(&Op2);
+ Args.push_back(Op1);
+ Args.push_back(Op2);
VPWidenGEPRecipe Recipe(GEP, make_range(Args.begin(), Args.end()));
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
@@ -971,15 +971,17 @@ TEST_F(VPRecipeTest, CastVPWidenGEPRecipeToVPUserAndVPDef) {
}
TEST_F(VPRecipeTest, CastVPBlendRecipeToVPUser) {
+ VPlan &Plan = getPlan();
IntegerType *Int32 = IntegerType::get(C, 32);
auto *Phi = PHINode::Create(Int32, 1);
- VPValue I1;
- VPValue I2;
- VPValue M2;
+
+ VPValue *I1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *I2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *M2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 3));
SmallVector<VPValue *, 4> Args;
- Args.push_back(&I1);
- Args.push_back(&I2);
- Args.push_back(&M2);
+ Args.push_back(I1);
+ Args.push_back(I2);
+ Args.push_back(M2);
VPBlendRecipe Recipe(Phi, Args);
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
@@ -988,10 +990,12 @@ TEST_F(VPRecipeTest, CastVPBlendRecipeToVPUser) {
}
TEST_F(VPRecipeTest, CastVPInterleaveRecipeToVPUser) {
- VPValue Addr;
- VPValue Mask;
+ VPlan &Plan = getPlan();
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPValue *Addr = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
InterleaveGroup<Instruction> IG(4, false, Align(4));
- VPInterleaveRecipe Recipe(&IG, &Addr, {}, &Mask, false);
+ VPInterleaveRecipe Recipe(&IG, Addr, {}, Mask, false);
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
@@ -999,13 +1003,14 @@ TEST_F(VPRecipeTest, CastVPInterleaveRecipeToVPUser) {
}
TEST_F(VPRecipeTest, CastVPReplicateRecipeToVPUser) {
- VPValue Op1;
- VPValue Op2;
+ VPlan &Plan = getPlan();
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
SmallVector<VPValue *, 4> Args;
- Args.push_back(&Op1);
- Args.push_back(&Op2);
+ Args.push_back(Op1);
+ Args.push_back(Op2);
- IntegerType *Int32 = IntegerType::get(C, 32);
FunctionType *FTy = FunctionType::get(Int32, false);
auto *Call = CallInst::Create(FTy, PoisonValue::get(FTy));
VPReplicateRecipe Recipe(Call, make_range(Args.begin(), Args.end()), true);
@@ -1016,8 +1021,10 @@ TEST_F(VPRecipeTest, CastVPReplicateRecipeToVPUser) {
}
TEST_F(VPRecipeTest, CastVPBranchOnMaskRecipeToVPUser) {
- VPValue Mask;
- VPBranchOnMaskRecipe Recipe(&Mask);
+ VPlan &Plan = getPlan();
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPBranchOnMaskRecipe Recipe(Mask);
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
@@ -1025,13 +1032,14 @@ TEST_F(VPRecipeTest, CastVPBranchOnMaskRecipeToVPUser) {
}
TEST_F(VPRecipeTest, CastVPWidenMemoryRecipeToVPUserAndVPDef) {
+ VPlan &Plan = getPlan();
IntegerType *Int32 = IntegerType::get(C, 32);
PointerType *Int32Ptr = PointerType::get(Int32, 0);
auto *Load =
new LoadInst(Int32, PoisonValue::get(Int32Ptr), "", false, Align(1));
- VPValue Addr;
- VPValue Mask;
- VPWidenLoadRecipe Recipe(*Load, &Addr, &Mask, true, false, {});
+ VPValue *Addr = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPWidenLoadRecipe Recipe(*Load, Addr, Mask, true, false, {});
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
@@ -1048,15 +1056,16 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
IntegerType *Int1 = IntegerType::get(C, 1);
IntegerType *Int32 = IntegerType::get(C, 32);
PointerType *Int32Ptr = PointerType::get(Int32, 0);
+ VPlan &Plan = getPlan();
{
auto *AI = BinaryOperator::CreateAdd(PoisonValue::get(Int32),
PoisonValue::get(Int32));
- VPValue Op1;
- VPValue Op2;
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
SmallVector<VPValue *, 2> Args;
- Args.push_back(&Op1);
- Args.push_back(&Op1);
+ Args.push_back(Op1);
+ Args.push_back(Op2);
VPWidenRecipe Recipe(*AI, make_range(Args.begin(), Args.end()));
EXPECT_FALSE(Recipe.mayHaveSideEffects());
EXPECT_FALSE(Recipe.mayReadFromMemory());
@@ -1069,13 +1078,13 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
auto *SelectI =
SelectInst::Create(PoisonValue::get(Int1), PoisonValue::get(Int32),
PoisonValue::get(Int32));
- VPValue Op1;
- VPValue Op2;
- VPValue Op3;
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *Op3 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 3));
SmallVector<VPValue *, 4> Args;
- Args.push_back(&Op1);
- Args.push_back(&Op2);
- Args.push_back(&Op3);
+ Args.push_back(Op1);
+ Args.push_back(Op2);
+ Args.push_back(Op3);
VPWidenSelectRecipe Recipe(*SelectI, make_range(Args.begin(), Args.end()));
EXPECT_FALSE(Recipe.mayHaveSideEffects());
EXPECT_FALSE(Recipe.mayReadFromMemory());
@@ -1087,11 +1096,11 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
{
auto *GEP = GetElementPtrInst::Create(Int32, PoisonValue::get(Int32Ptr),
PoisonValue::get(Int32));
- VPValue Op1;
- VPValue Op2;
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
SmallVector<VPValue *, 4> Args;
- Args.push_back(&Op1);
- Args.push_back(&Op2);
+ Args.push_back(Op1);
+ Args.push_back(Op2);
VPWidenGEPRecipe Recipe(GEP, make_range(Args.begin(), Args.end()));
EXPECT_FALSE(Recipe.mayHaveSideEffects());
EXPECT_FALSE(Recipe.mayReadFromMemory());
@@ -1101,8 +1110,9 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
}
{
- VPValue Mask;
- VPBranchOnMaskRecipe Recipe(&Mask);
+ VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+
+ VPBranchOnMaskRecipe Recipe(Mask);
EXPECT_TRUE(Recipe.mayHaveSideEffects());
EXPECT_FALSE(Recipe.mayReadFromMemory());
EXPECT_FALSE(Recipe.mayWriteToMemory());
@@ -1110,11 +1120,11 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
}
{
- VPValue ChainOp;
- VPValue VecOp;
- VPValue CondOp;
- VPReductionRecipe Recipe(RecurrenceDescriptor(), nullptr, &ChainOp, &CondOp,
- &VecOp, false);
+ VPValue *ChainOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *VecOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *CondOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 3));
+ VPReductionRecipe Recipe(RecurrenceDescriptor(), nullptr, ChainOp, CondOp,
+ VecOp, false);
EXPECT_FALSE(Recipe.mayHaveSideEffects());
EXPECT_FALSE(Recipe.mayReadFromMemory());
EXPECT_FALSE(Recipe.mayWriteToMemory());
@@ -1122,13 +1132,13 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
}
{
- VPValue ChainOp;
- VPValue VecOp;
- VPValue CondOp;
- VPReductionRecipe Recipe(RecurrenceDescriptor(), nullptr, &ChainOp, &CondOp,
- &VecOp, false);
- VPValue EVL;
- VPReductionEVLRecipe EVLRecipe(Recipe, EVL, &CondOp);
+ VPValue *ChainOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *VecOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *CondOp = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 3));
+ VPReductionRecipe Recipe(RecurrenceDescriptor(), nullptr, ChainOp, CondOp,
+ VecOp, false);
+ VPValue *EVL = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 4));
+ VPReductionEVLRecipe EVLRecipe(Recipe, *EVL, CondOp);
EXPECT_FALSE(EVLRecipe.mayHaveSideEffects());
EXPECT_FALSE(EVLRecipe.mayReadFromMemory());
EXPECT_FALSE(EVLRecipe.mayWriteToMemory());
@@ -1138,9 +1148,9 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
{
auto *Load =
new LoadInst(Int32, PoisonValue::get(Int32Ptr), "", false, Align(1));
- VPValue Addr;
- VPValue Mask;
- VPWidenLoadRecipe Recipe(*Load, &Addr, &Mask, true, false, {});
+ VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Addr = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPWidenLoadRecipe Recipe(*Load, Addr, Mask, true, false, {});
EXPECT_FALSE(Recipe.mayHaveSideEffects());
EXPECT_TRUE(Recipe.mayReadFromMemory());
EXPECT_FALSE(Recipe.mayWriteToMemory());
@@ -1151,10 +1161,10 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
{
auto *Store = new StoreInst(PoisonValue::get(Int32),
PoisonValue::get(Int32Ptr), false, Align(1));
- VPValue Addr;
- VPValue Mask;
- VPValue StoredV;
- VPWidenStoreRecipe Recipe(*Store, &Addr, &StoredV, &Mask, false, false, {});
+ VPValue *Mask = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Addr = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *StoredV = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 3));
+ VPWidenStoreRecipe Recipe(*Store, Addr, StoredV, Mask, false, false, {});
EXPECT_TRUE(Recipe.mayHaveSideEffects());
EXPECT_FALSE(Recipe.mayReadFromMemory());
EXPECT_TRUE(Recipe.mayWriteToMemory());
@@ -1166,13 +1176,13 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
FunctionType *FTy = FunctionType::get(Int32, false);
Function *Fn = Function::Create(FTy, GlobalValue::ExternalLinkage, 0);
auto *Call = CallInst::Create(FTy, Fn);
- VPValue Op1;
- VPValue Op2;
- VPValue CalledFn(Call->getCalledFunction());
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *CalledFn = Plan.getOrAddLiveIn(Call->getCalledFunction());
SmallVector<VPValue *, 3> Args;
- Args.push_back(&Op1);
- Args.push_back(&Op2);
- Args.push_back(&CalledFn);
+ Args.push_back(Op1);
+ Args.push_back(Op2);
+ Args.push_back(CalledFn);
VPWidenCallRecipe Recipe(Call, Fn, Args);
EXPECT_TRUE(Recipe.mayHaveSideEffects());
EXPECT_TRUE(Recipe.mayReadFromMemory());
@@ -1189,13 +1199,13 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
Intrinsic::getOrInsertDeclaration(&M, Intrinsic::thread_pointer);
auto *Call = CallInst::Create(TheFn->getFunctionType(), TheFn);
- VPValue Op1;
- VPValue Op2;
- VPValue CalledFn(TheFn);
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *CalledFn = Plan.getOrAddLiveIn(Call->getCalledFunction());
SmallVector<VPValue *, 3> Args;
- Args.push_back(&Op1);
- Args.push_back(&Op2);
- Args.push_back(&CalledFn);
+ Args.push_back(Op1);
+ Args.push_back(Op2);
+ Args.push_back(CalledFn);
VPWidenCallRecipe Recipe(Call, TheFn, Args);
EXPECT_FALSE(Recipe.mayHaveSideEffects());
EXPECT_FALSE(Recipe.mayReadFromMemory());
@@ -1205,21 +1215,20 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
}
{
- VPValue Op1;
- VPValue Op2;
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
InductionDescriptor IndDesc;
- VPScalarIVStepsRecipe Recipe(IndDesc, &Op1, &Op2);
+ VPScalarIVStepsRecipe Recipe(IndDesc, Op1, Op2);
EXPECT_FALSE(Recipe.mayHaveSideEffects());
EXPECT_FALSE(Recipe.mayReadFromMemory());
EXPECT_FALSE(Recipe.mayWriteToMemory());
EXPECT_FALSE(Recipe.mayReadOrWriteMemory());
}
- // The initial implementation is conservative with respect to VPInstructions.
{
- VPValue Op1;
- VPValue Op2;
- VPInstruction VPInst(Instruction::Add, {&Op1, &Op2});
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *Op2 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPInstruction VPInst(Instruction::Add, {Op1, Op2});
VPRecipeBase &Recipe = VPInst;
EXPECT_FALSE(Recipe.mayHaveSideEffects());
EXPECT_FALSE(Recipe.mayReadFromMemory());
@@ -1227,8 +1236,8 @@ TEST_F(VPRecipeTest, MayHaveSideEffectsAndMayReadWriteMemory) {
EXPECT_FALSE(Recipe.mayReadOrWriteMemory());
}
{
- VPValue Op1;
- VPPredInstPHIRecipe Recipe(&Op1, {});
+ VPValue *Op1 = Plan.getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPPredInstPHIRecipe Recipe(Op1, {});
EXPECT_FALSE(Recipe.mayHaveSideEffects());
EXPECT_FALSE(Recipe.mayReadFromMemory());
EXPECT_FALSE(Recipe.mayWriteToMemory());
@@ -1397,8 +1406,8 @@ TEST_F(VPRecipeTest, dumpRecipeUnnamedVPValuesNotInPlanOrBlock) {
auto *AI = BinaryOperator::CreateAdd(PoisonValue::get(Int32),
PoisonValue::get(Int32));
AI->setName("a");
- VPValue *ExtVPV1 = new VPValue(ConstantInt::get(Int32, 1));
- VPValue *ExtVPV2 = new VPValue(AI);
+ VPValue *ExtVPV1 = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *ExtVPV2 = getPlan().getOrAddLiveIn(AI);
VPInstruction *I1 = new VPInstruction(Instruction::Add, {ExtVPV1, ExtVPV2});
VPInstruction *I2 = new VPInstruction(Instruction::Mul, {I1, I1});
@@ -1468,36 +1477,37 @@ TEST_F(VPRecipeTest, dumpRecipeUnnamedVPValuesNotInPlanOrBlock) {
delete I2;
delete I1;
- delete ExtVPV2;
- delete ExtVPV1;
delete AI;
}
#endif
TEST_F(VPRecipeTest, CastVPReductionRecipeToVPUser) {
- VPValue ChainOp;
- VPValue VecOp;
- VPValue CondOp;
- VPReductionRecipe Recipe(RecurrenceDescriptor(), nullptr, &ChainOp, &CondOp,
- &VecOp, false);
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPValue *ChainOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *VecOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *CondOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 3));
+ VPReductionRecipe Recipe(RecurrenceDescriptor(), nullptr, ChainOp, CondOp,
+ VecOp, false);
EXPECT_TRUE(isa<VPUser>(&Recipe));
VPRecipeBase *BaseR = &Recipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
}
TEST_F(VPRecipeTest, CastVPReductionEVLRecipeToVPUser) {
- VPValue ChainOp;
- VPValue VecOp;
- VPValue CondOp;
- VPReductionRecipe Recipe(RecurrenceDescriptor(), nullptr, &ChainOp, &CondOp,
- &VecOp, false);
- VPValue EVL;
- VPReductionEVLRecipe EVLRecipe(Recipe, EVL, &CondOp);
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPValue *ChainOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 1));
+ VPValue *VecOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 2));
+ VPValue *CondOp = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 3));
+ VPReductionRecipe Recipe(RecurrenceDescriptor(), nullptr, ChainOp, CondOp,
+ VecOp, false);
+ VPValue *EVL = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 0));
+ VPReductionEVLRecipe EVLRecipe(Recipe, *EVL, CondOp);
EXPECT_TRUE(isa<VPUser>(&EVLRecipe));
VPRecipeBase *BaseR = &EVLRecipe;
EXPECT_TRUE(isa<VPUser>(BaseR));
}
+} // namespace
struct VPDoubleValueDef : public VPRecipeBase {
VPDoubleValueDef(ArrayRef<VPValue *> Operands) : VPRecipeBase(99, Operands) {
@@ -1514,6 +1524,8 @@ struct VPDoubleValueDef : public VPRecipeBase {
#endif
};
+namespace {
+
TEST(VPDoubleValueDefTest, traverseUseLists) {
// Check that the def-use chains of a multi-def can be traversed in both
// directions.
@@ -1559,8 +1571,9 @@ TEST(VPDoubleValueDefTest, traverseUseLists) {
}
TEST_F(VPRecipeTest, CastToVPSingleDefRecipe) {
- VPValue Start;
- VPEVLBasedIVPHIRecipe R(&Start, {});
+ IntegerType *Int32 = IntegerType::get(C, 32);
+ VPValue *Start = getPlan().getOrAddLiveIn(ConstantInt::get(Int32, 0));
+ VPEVLBasedIVPHIRecipe R(Start, {});
VPRecipeBase *B = &R;
EXPECT_TRUE(isa<VPSingleDefRecipe>(B));
// TODO: check other VPSingleDefRecipes.
More information about the llvm-commits
mailing list