Skip to content

Commit 3034e99

Browse files
committed
!fixup address comments, more uniform constructors.
1 parent 033f430 commit 3034e99

File tree

5 files changed

+70
-64
lines changed

5 files changed

+70
-64
lines changed

llvm/lib/Transforms/Vectorize/LoopVectorizationPlanner.h

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ class VPBuilder {
6363
}
6464

6565
VPInstruction *createInstruction(unsigned Opcode,
66-
ArrayRef<VPValue *> Operands, DebugLoc DL,
66+
ArrayRef<VPValue *> Operands,
67+
const VPIRMetadata &MD, DebugLoc DL,
6768
const Twine &Name = "") {
6869
return tryInsertInstruction(
69-
new VPInstruction(Opcode, Operands, {}, DL, Name));
70+
new VPInstruction(Opcode, Operands, {}, MD, DL, Name));
7071
}
7172

7273
public:
@@ -154,14 +155,14 @@ class VPBuilder {
154155
const VPIRMetadata &MD = {},
155156
DebugLoc DL = DebugLoc::getUnknown(),
156157
const Twine &Name = "") {
157-
VPInstruction *NewVPInst =
158-
tryInsertInstruction(new VPInstruction(Opcode, Operands, MD, DL, Name));
158+
VPInstruction *NewVPInst = tryInsertInstruction(
159+
new VPInstruction(Opcode, Operands, {}, MD, DL, Name));
159160
NewVPInst->setUnderlyingValue(Inst);
160161
return NewVPInst;
161162
}
162163
VPInstruction *createNaryOp(unsigned Opcode, ArrayRef<VPValue *> Operands,
163164
DebugLoc DL, const Twine &Name = "") {
164-
return createInstruction(Opcode, Operands, DL, Name);
165+
return createInstruction(Opcode, Operands, {}, DL, Name);
165166
}
166167
VPInstruction *createNaryOp(unsigned Opcode, ArrayRef<VPValue *> Operands,
167168
const VPIRFlags &Flags,
@@ -175,8 +176,8 @@ class VPBuilder {
175176
Type *ResultTy, const VPIRFlags &Flags = {},
176177
DebugLoc DL = DebugLoc::getUnknown(),
177178
const Twine &Name = "") {
178-
return tryInsertInstruction(
179-
new VPInstructionWithType(Opcode, Operands, ResultTy, Flags, DL, Name));
179+
return tryInsertInstruction(new VPInstructionWithType(
180+
Opcode, Operands, ResultTy, Flags, {}, DL, Name));
180181
}
181182

182183
VPInstruction *createOverflowingOp(
@@ -190,13 +191,14 @@ class VPBuilder {
190191
VPInstruction *createNot(VPValue *Operand,
191192
DebugLoc DL = DebugLoc::getUnknown(),
192193
const Twine &Name = "") {
193-
return createInstruction(VPInstruction::Not, {Operand}, DL, Name);
194+
return createInstruction(VPInstruction::Not, {Operand}, {}, DL, Name);
194195
}
195196

196197
VPInstruction *createAnd(VPValue *LHS, VPValue *RHS,
197198
DebugLoc DL = DebugLoc::getUnknown(),
198199
const Twine &Name = "") {
199-
return createInstruction(Instruction::BinaryOps::And, {LHS, RHS}, DL, Name);
200+
return createInstruction(Instruction::BinaryOps::And, {LHS, RHS}, {}, DL,
201+
Name);
200202
}
201203

202204
VPInstruction *createOr(VPValue *LHS, VPValue *RHS,
@@ -211,20 +213,18 @@ class VPBuilder {
211213
VPInstruction *createLogicalAnd(VPValue *LHS, VPValue *RHS,
212214
DebugLoc DL = DebugLoc::getUnknown(),
213215
const Twine &Name = "") {
214-
return tryInsertInstruction(
215-
new VPInstruction(VPInstruction::LogicalAnd, {LHS, RHS}, {}, DL, Name));
216+
return createNaryOp(VPInstruction::LogicalAnd, {LHS, RHS}, DL, Name);
216217
}
217218

218219
VPInstruction *
219220
createSelect(VPValue *Cond, VPValue *TrueVal, VPValue *FalseVal,
220221
DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "",
221222
std::optional<FastMathFlags> FMFs = std::nullopt) {
222-
auto *Select =
223-
FMFs ? new VPInstruction(Instruction::Select, {Cond, TrueVal, FalseVal},
224-
*FMFs, {}, DL, Name)
225-
: new VPInstruction(Instruction::Select, {Cond, TrueVal, FalseVal},
226-
{}, DL, Name);
227-
return tryInsertInstruction(Select);
223+
if (!FMFs)
224+
return createNaryOp(Instruction::Select, {Cond, TrueVal, FalseVal}, DL,
225+
Name);
226+
return tryInsertInstruction(new VPInstruction(
227+
Instruction::Select, {Cond, TrueVal, FalseVal}, *FMFs, {}, DL, Name));
228228
}
229229

230230
/// Create a new ICmp VPInstruction with predicate \p Pred and operands \p A
@@ -307,7 +307,7 @@ class VPBuilder {
307307
const VPIRFlags &Flags = {},
308308
const VPIRMetadata &Metadata = {}) {
309309
return tryInsertInstruction(
310-
new VPInstructionWithType(Opcode, Op, ResultTy, DL, Flags, Metadata));
310+
new VPInstructionWithType(Opcode, Op, ResultTy, Flags, Metadata, DL));
311311
}
312312

313313
VPValue *createScalarZExtOrTrunc(VPValue *Op, Type *ResultTy, Type *SrcTy,
@@ -329,7 +329,7 @@ class VPBuilder {
329329
else if (Opcode == Instruction::ZExt)
330330
Flags = VPIRFlags::NonNegFlagsTy(false);
331331
return tryInsertInstruction(
332-
new VPWidenCastRecipe(Opcode, Op, ResultTy, nullptr, Flags));
332+
new VPWidenCastRecipe(Opcode, Op, ResultTy, Flags));
333333
}
334334

335335
VPScalarIVStepsRecipe *

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8234,13 +8234,14 @@ VPRecipeBase *VPRecipeBuilder::tryToCreateWidenRecipe(VPSingleDefRecipe *R,
82348234
return new VPWidenGEPRecipe(cast<GetElementPtrInst>(Instr), R->operands());
82358235

82368236
if (VPI->getOpcode() == Instruction::Select)
8237-
return new VPWidenSelectRecipe(*cast<SelectInst>(Instr), R->operands());
8237+
return new VPWidenSelectRecipe(*cast<SelectInst>(Instr), R->operands(),
8238+
*VPI);
82388239

82398240
if (Instruction::isCast(VPI->getOpcode())) {
82408241
auto *CastR = cast<VPInstructionWithType>(R);
82418242
auto *CI = cast<CastInst>(Instr);
82428243
return new VPWidenCastRecipe(CI->getOpcode(), VPI->getOperand(0),
8243-
CastR->getResultType(), CI, *VPI, *VPI);
8244+
CastR->getResultType(), *CI, *VPI);
82448245
}
82458246

82468247
return tryToWiden(VPI);

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ class LLVM_ABI_FOR_TEST VPInstruction : public VPRecipeWithIRFlags,
11201120

11211121
public:
11221122
VPInstruction(unsigned Opcode, ArrayRef<VPValue *> Operands,
1123-
const VPIRFlags &Flags, const VPIRMetadata &MD = {},
1123+
const VPIRFlags &Flags = {}, const VPIRMetadata &MD = {},
11241124
DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "");
11251125

11261126
VP_CLASSOF_IMPL(VPDef::VPInstructionSC)
@@ -1210,14 +1210,10 @@ class VPInstructionWithType : public VPInstruction {
12101210

12111211
public:
12121212
VPInstructionWithType(unsigned Opcode, ArrayRef<VPValue *> Operands,
1213-
Type *ResultTy, const VPIRFlags &Flags, DebugLoc DL,
1213+
Type *ResultTy, const VPIRFlags &Flags = {},
1214+
const VPIRMetadata &Metadata = {},
1215+
DebugLoc DL = DebugLoc::getUnknown(),
12141216
const Twine &Name = "")
1215-
: VPInstruction(Opcode, Operands, Flags, {}, DL, Name),
1216-
ResultTy(ResultTy) {}
1217-
1218-
VPInstructionWithType(unsigned Opcode, ArrayRef<VPValue *> Operands,
1219-
Type *ResultTy, DebugLoc DL, const VPIRFlags &Flags,
1220-
const VPIRMetadata &Metadata, const Twine &Name = "")
12211217
: VPInstruction(Opcode, Operands, Flags, Metadata, DL, Name),
12221218
ResultTy(ResultTy) {}
12231219

@@ -1246,7 +1242,7 @@ class VPInstructionWithType : public VPInstruction {
12461242
VPInstruction *clone() override {
12471243
auto *New =
12481244
new VPInstructionWithType(getOpcode(), operands(), getResultType(),
1249-
*this, getDebugLoc(), getName());
1245+
*this, *this, getDebugLoc(), getName());
12501246
New->setUnderlyingValue(getUnderlyingValue());
12511247
return New;
12521248
}
@@ -1330,7 +1326,7 @@ class VPPhiAccessors {
13301326

13311327
struct LLVM_ABI_FOR_TEST VPPhi : public VPInstruction, public VPPhiAccessors {
13321328
VPPhi(ArrayRef<VPValue *> Operands, DebugLoc DL, const Twine &Name = "")
1333-
: VPInstruction(Instruction::PHI, Operands, {}, DL, Name) {}
1329+
: VPInstruction(Instruction::PHI, Operands, {}, {}, DL, Name) {}
13341330

13351331
static inline bool classof(const VPUser *U) {
13361332
auto *VPI = dyn_cast<VPInstruction>(U);
@@ -1476,10 +1472,8 @@ class LLVM_ABI_FOR_TEST VPWidenRecipe : public VPRecipeWithIRFlags,
14761472

14771473
VPWidenRecipe(Instruction &I, ArrayRef<VPValue *> Operands,
14781474
const VPIRMetadata &Metadata, DebugLoc DL)
1479-
: VPRecipeWithIRFlags(VPDef::VPWidenSC, Operands, VPIRFlags(I), DL),
1480-
VPIRMetadata(Metadata), Opcode(I.getOpcode()) {
1481-
setUnderlyingValue(&I);
1482-
}
1475+
: VPRecipeWithIRFlags(VPDef::VPWidenSC, Operands, I),
1476+
VPIRMetadata(Metadata), Opcode(I.getOpcode()) {}
14831477

14841478
~VPWidenRecipe() override = default;
14851479

@@ -1520,26 +1514,30 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
15201514

15211515
public:
15221516
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
1523-
CastInst *UI = nullptr, const VPIRFlags &Flags = {},
1517+
CastInst &UI, const VPIRMetadata &Metadata)
1518+
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, UI),
1519+
VPIRMetadata(Metadata), Opcode(Opcode), ResultTy(ResultTy) {
1520+
assert(UI.getOpcode() == Opcode &&
1521+
"opcode of underlying cast doesn't match");
1522+
}
1523+
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
1524+
const VPIRFlags &Flags = {},
15241525
const VPIRMetadata &Metadata = {},
15251526
DebugLoc DL = DebugLoc::getUnknown())
1526-
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op,
1527-
UI ? VPIRFlags(*UI) : Flags,
1528-
UI ? UI->getDebugLoc() : DL),
1527+
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, Flags, DL),
15291528
VPIRMetadata(Metadata), Opcode(Opcode), ResultTy(ResultTy) {
15301529
assert(flagsValidForOpcode(Opcode) &&
15311530
"Set flags not supported for the provided opcode");
1532-
assert((!UI || UI->getOpcode() == Opcode) &&
1533-
"opcode of underlying cast doesn't match");
1534-
setUnderlyingValue(UI);
15351531
}
15361532

15371533
~VPWidenCastRecipe() override = default;
15381534

15391535
VPWidenCastRecipe *clone() override {
1540-
return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy,
1541-
cast_or_null<CastInst>(getUnderlyingValue()),
1542-
*this, *this, getDebugLoc());
1536+
auto *New = new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy, *this,
1537+
*this, getDebugLoc());
1538+
if (auto *UV = getUnderlyingValue())
1539+
New->setUnderlyingValue(UV);
1540+
return New;
15431541
}
15441542

15451543
VP_CLASSOF_IMPL(VPDef::VPWidenCastSC)
@@ -1594,9 +1592,13 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
15941592

15951593
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID,
15961594
ArrayRef<VPValue *> CallArguments, Type *Ty,
1595+
const VPIRFlags &Flags = {},
1596+
const VPIRMetadata &Metadata = {},
15971597
DebugLoc DL = DebugLoc::getUnknown())
1598-
: VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, DL),
1599-
VPIRMetadata(), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty) {
1598+
: VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, Flags,
1599+
DL),
1600+
VPIRMetadata(Metadata), VectorIntrinsicID(VectorIntrinsicID),
1601+
ResultTy(Ty) {
16001602
LLVMContext &Ctx = Ty->getContext();
16011603
AttributeSet Attrs = Intrinsic::getFnAttributes(Ctx, VectorIntrinsicID);
16021604
MemoryEffects ME = Attrs.getMemoryEffects();
@@ -1615,7 +1617,7 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
16151617
operands(), ResultTy, *this,
16161618
getDebugLoc());
16171619
return new VPWidenIntrinsicRecipe(VectorIntrinsicID, operands(), ResultTy,
1618-
getDebugLoc());
1620+
*this, *this, getDebugLoc());
16191621
}
16201622

16211623
VP_CLASSOF_IMPL(VPDef::VPWidenIntrinsicSC)
@@ -1756,15 +1758,16 @@ class VPHistogramRecipe : public VPRecipeBase {
17561758
/// instruction.
17571759
struct LLVM_ABI_FOR_TEST VPWidenSelectRecipe : public VPRecipeWithIRFlags,
17581760
public VPIRMetadata {
1759-
VPWidenSelectRecipe(SelectInst &I, ArrayRef<VPValue *> Operands)
1761+
VPWidenSelectRecipe(SelectInst &I, ArrayRef<VPValue *> Operands,
1762+
VPIRMetadata &MD)
17601763
: VPRecipeWithIRFlags(VPDef::VPWidenSelectSC, Operands, I),
1761-
VPIRMetadata(I) {}
1764+
VPIRMetadata(MD) {}
17621765

17631766
~VPWidenSelectRecipe() override = default;
17641767

17651768
VPWidenSelectRecipe *clone() override {
17661769
return new VPWidenSelectRecipe(*cast<SelectInst>(getUnderlyingInstr()),
1767-
operands());
1770+
operands(), *this);
17681771
}
17691772

17701773
VP_CLASSOF_IMPL(VPDef::VPWidenSelectSC)

llvm/lib/Transforms/Vectorize/VPlanSLP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ VPInstruction *VPlanSlp::buildGraph(ArrayRef<VPValue *> Values) {
518518
assert(CombinedOperands.size() > 0 && "Need more some operands");
519519
auto *Inst = cast<VPInstruction>(Values[0])->getUnderlyingInstr();
520520
auto *VPI =
521-
new VPInstruction(Opcode, CombinedOperands, {}, Inst->getDebugLoc());
521+
new VPInstruction(Opcode, CombinedOperands, {}, {}, Inst->getDebugLoc());
522522

523523
LLVM_DEBUG(dbgs() << "Create VPInstruction " << *VPI << " " << Values[0]
524524
<< "\n");

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,11 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
109109
drop_end(Ingredient.operands()), CI->getType(), *VPI,
110110
CI->getDebugLoc());
111111
} else if (SelectInst *SI = dyn_cast<SelectInst>(Inst)) {
112-
NewRecipe = new VPWidenSelectRecipe(*SI, Ingredient.operands());
112+
NewRecipe = new VPWidenSelectRecipe(*SI, Ingredient.operands(), *VPI);
113113
} else if (auto *CI = dyn_cast<CastInst>(Inst)) {
114114
NewRecipe =
115115
new VPWidenCastRecipe(CI->getOpcode(), Ingredient.getOperand(0),
116-
CI->getType(), CI, {}, *VPI);
116+
CI->getType(), *CI, *VPI);
117117
} else {
118118
NewRecipe = new VPWidenRecipe(*Inst, Ingredient.operands(), *VPI,
119119
Ingredient.getDebugLoc());
@@ -1706,8 +1706,9 @@ static bool tryToReplaceALMWithWideALM(VPlan &Plan, ElementCount VF,
17061706
Ops.append({ALM, Plan.getOrAddLiveIn(
17071707
ConstantInt::get(IntegerType::getInt64Ty(Ctx),
17081708
VF.getKnownMinValue() * Part))});
1709-
auto *Ext = new VPWidenIntrinsicRecipe(Intrinsic::vector_extract, Ops,
1710-
IntegerType::getInt1Ty(Ctx), DL);
1709+
auto *Ext =
1710+
new VPWidenIntrinsicRecipe(Intrinsic::vector_extract, Ops,
1711+
IntegerType::getInt1Ty(Ctx), {}, {}, DL);
17111712
Extracts[Part] = Ext;
17121713
Ext->insertAfter(ALM);
17131714
}
@@ -1846,7 +1847,7 @@ static bool simplifyBranchConditionForVFAndUF(VPlan &Plan, ElementCount BestVF,
18461847
// The vector region contains header phis for which we cannot remove the
18471848
// loop region yet.
18481849
auto *BOC = new VPInstruction(VPInstruction::BranchOnCond, {Plan.getTrue()},
1849-
{}, Term->getDebugLoc());
1850+
{}, {}, Term->getDebugLoc());
18501851
ExitingVPBB->appendRecipe(BOC);
18511852
}
18521853

@@ -2680,13 +2681,13 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
26802681
m_Select(m_Specific(HeaderMask), m_VPValue(LHS), m_VPValue(RHS))))
26812682
return new VPWidenIntrinsicRecipe(
26822683
Intrinsic::vp_merge, {Plan->getTrue(), LHS, RHS, &EVL},
2683-
TypeInfo.inferScalarType(LHS), CurRecipe.getDebugLoc());
2684+
TypeInfo.inferScalarType(LHS), {}, {}, CurRecipe.getDebugLoc());
26842685

26852686
if (match(&CurRecipe, m_Select(m_RemoveMask(HeaderMask, Mask), m_VPValue(LHS),
26862687
m_VPValue(RHS))))
26872688
return new VPWidenIntrinsicRecipe(
26882689
Intrinsic::vp_merge, {Mask, LHS, RHS, &EVL},
2689-
TypeInfo.inferScalarType(LHS), CurRecipe.getDebugLoc());
2690+
TypeInfo.inferScalarType(LHS), {}, {}, CurRecipe.getDebugLoc());
26902691

26912692
return nullptr;
26922693
}
@@ -2754,7 +2755,8 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
27542755
VPWidenIntrinsicRecipe *VPSplice = new VPWidenIntrinsicRecipe(
27552756
Intrinsic::experimental_vp_splice,
27562757
{V1, V2, Imm, Plan.getTrue(), PrevEVL, &EVL},
2757-
TypeInfo.inferScalarType(R.getVPSingleValue()), R.getDebugLoc());
2758+
TypeInfo.inferScalarType(R.getVPSingleValue()), {}, {},
2759+
R.getDebugLoc());
27582760
VPSplice->insertBefore(&R);
27592761
R.getVPSingleValue()->replaceAllUsesWith(VPSplice);
27602762
ToErase.push_back(&R);
@@ -3816,15 +3818,15 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
38163818
Ext0->getOpcode() == Ext1->getOpcode() &&
38173819
IsMulAccValidAndClampRange(Mul, Ext0, Ext1, Ext) && Mul->hasOneUse()) {
38183820
auto *NewExt0 = new VPWidenCastRecipe(
3819-
Ext0->getOpcode(), Ext0->getOperand(0), Ext->getResultType(), nullptr,
3820-
*Ext0, *Ext0, Ext0->getDebugLoc());
3821+
Ext0->getOpcode(), Ext0->getOperand(0), Ext->getResultType(), *Ext0,
3822+
*Ext0, Ext0->getDebugLoc());
38213823
NewExt0->insertBefore(Ext0);
38223824

38233825
VPWidenCastRecipe *NewExt1 = NewExt0;
38243826
if (Ext0 != Ext1) {
38253827
NewExt1 = new VPWidenCastRecipe(Ext1->getOpcode(), Ext1->getOperand(0),
3826-
Ext->getResultType(), nullptr, *Ext1,
3827-
*Ext1, Ext1->getDebugLoc());
3828+
Ext->getResultType(), *Ext1, *Ext1,
3829+
Ext1->getDebugLoc());
38283830
NewExt1->insertBefore(Ext1);
38293831
}
38303832
Mul->setOperand(0, NewExt0);

0 commit comments

Comments
 (0)