Skip to content

Commit 8910c1a

Browse files
committed
!fixup address comments, more uniform constructors.
1 parent 89483ac commit 8910c1a

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(unsigned Opcode,
@@ -191,13 +192,14 @@ class VPBuilder {
191192
VPInstruction *createNot(VPValue *Operand,
192193
DebugLoc DL = DebugLoc::getUnknown(),
193194
const Twine &Name = "") {
194-
return createInstruction(VPInstruction::Not, {Operand}, DL, Name);
195+
return createInstruction(VPInstruction::Not, {Operand}, {}, DL, Name);
195196
}
196197

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

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

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

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

314314
VPValue *createScalarZExtOrTrunc(VPValue *Op, Type *ResultTy, Type *SrcTy,
@@ -330,7 +330,7 @@ class VPBuilder {
330330
else if (Opcode == Instruction::ZExt)
331331
Flags = VPIRFlags::NonNegFlagsTy(false);
332332
return tryInsertInstruction(
333-
new VPWidenCastRecipe(Opcode, Op, ResultTy, nullptr, Flags));
333+
new VPWidenCastRecipe(Opcode, Op, ResultTy, Flags));
334334
}
335335

336336
VPScalarIVStepsRecipe *

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp

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

82278227
if (VPI->getOpcode() == Instruction::Select)
8228-
return new VPWidenSelectRecipe(*cast<SelectInst>(Instr), R->operands());
8228+
return new VPWidenSelectRecipe(*cast<SelectInst>(Instr), R->operands(),
8229+
*VPI);
82298230

82308231
if (Instruction::isCast(VPI->getOpcode())) {
82318232
auto *CastR = cast<VPInstructionWithType>(R);
82328233
auto *CI = cast<CastInst>(Instr);
82338234
return new VPWidenCastRecipe(CI->getOpcode(), VPI->getOperand(0),
8234-
CastR->getResultType(), CI, *VPI, *VPI);
8235+
CastR->getResultType(), *CI, *VPI);
82358236
}
82368237

82378238
return tryToWiden(VPI);

llvm/lib/Transforms/Vectorize/VPlan.h

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

11051105
public:
11061106
VPInstruction(unsigned Opcode, ArrayRef<VPValue *> Operands,
1107-
const VPIRFlags &Flags, const VPIRMetadata &MD = {},
1107+
const VPIRFlags &Flags = {}, const VPIRMetadata &MD = {},
11081108
DebugLoc DL = DebugLoc::getUnknown(), const Twine &Name = "");
11091109

11101110
VP_CLASSOF_IMPL(VPDef::VPInstructionSC)
@@ -1191,14 +1191,10 @@ class VPInstructionWithType : public VPInstruction {
11911191

11921192
public:
11931193
VPInstructionWithType(unsigned Opcode, ArrayRef<VPValue *> Operands,
1194-
Type *ResultTy, const VPIRFlags &Flags, DebugLoc DL,
1194+
Type *ResultTy, const VPIRFlags &Flags = {},
1195+
const VPIRMetadata &Metadata = {},
1196+
DebugLoc DL = DebugLoc::getUnknown(),
11951197
const Twine &Name = "")
1196-
: VPInstruction(Opcode, Operands, Flags, {}, DL, Name),
1197-
ResultTy(ResultTy) {}
1198-
1199-
VPInstructionWithType(unsigned Opcode, ArrayRef<VPValue *> Operands,
1200-
Type *ResultTy, DebugLoc DL, const VPIRFlags &Flags,
1201-
const VPIRMetadata &Metadata, const Twine &Name = "")
12021198
: VPInstruction(Opcode, Operands, Flags, Metadata, DL, Name),
12031199
ResultTy(ResultTy) {}
12041200

@@ -1227,7 +1223,7 @@ class VPInstructionWithType : public VPInstruction {
12271223
VPInstruction *clone() override {
12281224
auto *New =
12291225
new VPInstructionWithType(getOpcode(), operands(), getResultType(),
1230-
*this, getDebugLoc(), getName());
1226+
*this, *this, getDebugLoc(), getName());
12311227
New->setUnderlyingValue(getUnderlyingValue());
12321228
return New;
12331229
}
@@ -1310,7 +1306,7 @@ class VPPhiAccessors {
13101306

13111307
struct LLVM_ABI_FOR_TEST VPPhi : public VPInstruction, public VPPhiAccessors {
13121308
VPPhi(ArrayRef<VPValue *> Operands, DebugLoc DL, const Twine &Name = "")
1313-
: VPInstruction(Instruction::PHI, Operands, {}, DL, Name) {}
1309+
: VPInstruction(Instruction::PHI, Operands, {}, {}, DL, Name) {}
13141310

13151311
static inline bool classof(const VPUser *U) {
13161312
auto *VPI = dyn_cast<VPInstruction>(U);
@@ -1455,10 +1451,8 @@ class LLVM_ABI_FOR_TEST VPWidenRecipe : public VPRecipeWithIRFlags,
14551451

14561452
VPWidenRecipe(Instruction &I, ArrayRef<VPValue *> Operands,
14571453
const VPIRMetadata &Metadata, DebugLoc DL)
1458-
: VPRecipeWithIRFlags(VPDef::VPWidenSC, Operands, VPIRFlags(I), DL),
1459-
VPIRMetadata(Metadata), Opcode(I.getOpcode()) {
1460-
setUnderlyingValue(&I);
1461-
}
1454+
: VPRecipeWithIRFlags(VPDef::VPWidenSC, Operands, I),
1455+
VPIRMetadata(Metadata), Opcode(I.getOpcode()) {}
14621456

14631457
~VPWidenRecipe() override = default;
14641458

@@ -1498,26 +1492,30 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
14981492

14991493
public:
15001494
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
1501-
CastInst *UI = nullptr, const VPIRFlags &Flags = {},
1495+
CastInst &UI, const VPIRMetadata &Metadata)
1496+
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, UI),
1497+
VPIRMetadata(Metadata), Opcode(Opcode), ResultTy(ResultTy) {
1498+
assert(UI.getOpcode() == Opcode &&
1499+
"opcode of underlying cast doesn't match");
1500+
}
1501+
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
1502+
const VPIRFlags &Flags = {},
15021503
const VPIRMetadata &Metadata = {},
15031504
DebugLoc DL = DebugLoc::getUnknown())
1504-
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op,
1505-
UI ? VPIRFlags(*UI) : Flags,
1506-
UI ? UI->getDebugLoc() : DL),
1505+
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, Flags, DL),
15071506
VPIRMetadata(Metadata), Opcode(Opcode), ResultTy(ResultTy) {
15081507
assert(flagsValidForOpcode(Opcode) &&
15091508
"Set flags not supported for the provided opcode");
1510-
assert((!UI || UI->getOpcode() == Opcode) &&
1511-
"opcode of underlying cast doesn't match");
1512-
setUnderlyingValue(UI);
15131509
}
15141510

15151511
~VPWidenCastRecipe() override = default;
15161512

15171513
VPWidenCastRecipe *clone() override {
1518-
return new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy,
1519-
cast_or_null<CastInst>(getUnderlyingValue()),
1520-
*this, *this, getDebugLoc());
1514+
auto *New = new VPWidenCastRecipe(Opcode, getOperand(0), ResultTy, *this,
1515+
*this, getDebugLoc());
1516+
if (auto *UV = getUnderlyingValue())
1517+
New->setUnderlyingValue(UV);
1518+
return New;
15211519
}
15221520

15231521
VP_CLASSOF_IMPL(VPDef::VPWidenCastSC)
@@ -1571,9 +1569,13 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
15711569

15721570
VPWidenIntrinsicRecipe(Intrinsic::ID VectorIntrinsicID,
15731571
ArrayRef<VPValue *> CallArguments, Type *Ty,
1572+
const VPIRFlags &Flags = {},
1573+
const VPIRMetadata &Metadata = {},
15741574
DebugLoc DL = DebugLoc::getUnknown())
1575-
: VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, DL),
1576-
VPIRMetadata(), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty) {
1575+
: VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, Flags,
1576+
DL),
1577+
VPIRMetadata(Metadata), VectorIntrinsicID(VectorIntrinsicID),
1578+
ResultTy(Ty) {
15771579
LLVMContext &Ctx = Ty->getContext();
15781580
AttributeSet Attrs = Intrinsic::getFnAttributes(Ctx, VectorIntrinsicID);
15791581
MemoryEffects ME = Attrs.getMemoryEffects();
@@ -1592,7 +1594,7 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
15921594
operands(), ResultTy, *this,
15931595
getDebugLoc());
15941596
return new VPWidenIntrinsicRecipe(VectorIntrinsicID, operands(), ResultTy,
1595-
getDebugLoc());
1597+
*this, *this, getDebugLoc());
15961598
}
15971599

15981600
VP_CLASSOF_IMPL(VPDef::VPWidenIntrinsicSC)
@@ -1730,15 +1732,16 @@ class VPHistogramRecipe : public VPRecipeBase {
17301732
/// instruction.
17311733
struct LLVM_ABI_FOR_TEST VPWidenSelectRecipe : public VPRecipeWithIRFlags,
17321734
public VPIRMetadata {
1733-
VPWidenSelectRecipe(SelectInst &I, ArrayRef<VPValue *> Operands)
1735+
VPWidenSelectRecipe(SelectInst &I, ArrayRef<VPValue *> Operands,
1736+
VPIRMetadata &MD)
17341737
: VPRecipeWithIRFlags(VPDef::VPWidenSelectSC, Operands, I),
1735-
VPIRMetadata(I) {}
1738+
VPIRMetadata(MD) {}
17361739

17371740
~VPWidenSelectRecipe() override = default;
17381741

17391742
VPWidenSelectRecipe *clone() override {
17401743
return new VPWidenSelectRecipe(*cast<SelectInst>(getUnderlyingInstr()),
1741-
operands());
1744+
operands(), *this);
17421745
}
17431746

17441747
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
@@ -104,11 +104,11 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
104104
drop_end(Ingredient.operands()), CI->getType(), *VPI,
105105
CI->getDebugLoc());
106106
} else if (SelectInst *SI = dyn_cast<SelectInst>(Inst)) {
107-
NewRecipe = new VPWidenSelectRecipe(*SI, Ingredient.operands());
107+
NewRecipe = new VPWidenSelectRecipe(*SI, Ingredient.operands(), *VPI);
108108
} else if (auto *CI = dyn_cast<CastInst>(Inst)) {
109109
NewRecipe =
110110
new VPWidenCastRecipe(CI->getOpcode(), Ingredient.getOperand(0),
111-
CI->getType(), CI, {}, *VPI);
111+
CI->getType(), *CI, *VPI);
112112
} else {
113113
NewRecipe = new VPWidenRecipe(*Inst, Ingredient.operands(), *VPI,
114114
Ingredient.getDebugLoc());
@@ -1696,8 +1696,9 @@ static bool tryToReplaceALMWithWideALM(VPlan &Plan, ElementCount VF,
16961696
Ops.append({ALM, Plan.getOrAddLiveIn(
16971697
ConstantInt::get(IntegerType::getInt64Ty(Ctx),
16981698
VF.getKnownMinValue() * Part))});
1699-
auto *Ext = new VPWidenIntrinsicRecipe(Intrinsic::vector_extract, Ops,
1700-
IntegerType::getInt1Ty(Ctx), DL);
1699+
auto *Ext =
1700+
new VPWidenIntrinsicRecipe(Intrinsic::vector_extract, Ops,
1701+
IntegerType::getInt1Ty(Ctx), {}, {}, DL);
17011702
Extracts[Part] = Ext;
17021703
Ext->insertAfter(ALM);
17031704
}
@@ -1836,7 +1837,7 @@ static bool simplifyBranchConditionForVFAndUF(VPlan &Plan, ElementCount BestVF,
18361837
// The vector region contains header phis for which we cannot remove the
18371838
// loop region yet.
18381839
auto *BOC = new VPInstruction(VPInstruction::BranchOnCond, {Plan.getTrue()},
1839-
{}, Term->getDebugLoc());
1840+
{}, {}, Term->getDebugLoc());
18401841
ExitingVPBB->appendRecipe(BOC);
18411842
}
18421843

@@ -2672,13 +2673,13 @@ static VPRecipeBase *optimizeMaskToEVL(VPValue *HeaderMask,
26722673
m_Select(m_Specific(HeaderMask), m_VPValue(LHS), m_VPValue(RHS))))
26732674
return new VPWidenIntrinsicRecipe(
26742675
Intrinsic::vp_merge, {Plan->getTrue(), LHS, RHS, &EVL},
2675-
TypeInfo.inferScalarType(LHS), CurRecipe.getDebugLoc());
2676+
TypeInfo.inferScalarType(LHS), {}, {}, CurRecipe.getDebugLoc());
26762677

26772678
if (match(&CurRecipe, m_Select(m_RemoveMask(HeaderMask, Mask), m_VPValue(LHS),
26782679
m_VPValue(RHS))))
26792680
return new VPWidenIntrinsicRecipe(
26802681
Intrinsic::vp_merge, {Mask, LHS, RHS, &EVL},
2681-
TypeInfo.inferScalarType(LHS), CurRecipe.getDebugLoc());
2682+
TypeInfo.inferScalarType(LHS), {}, {}, CurRecipe.getDebugLoc());
26822683

26832684
return nullptr;
26842685
}
@@ -2746,7 +2747,8 @@ static void transformRecipestoEVLRecipes(VPlan &Plan, VPValue &EVL) {
27462747
VPWidenIntrinsicRecipe *VPSplice = new VPWidenIntrinsicRecipe(
27472748
Intrinsic::experimental_vp_splice,
27482749
{V1, V2, Imm, Plan.getTrue(), PrevEVL, &EVL},
2749-
TypeInfo.inferScalarType(R.getVPSingleValue()), R.getDebugLoc());
2750+
TypeInfo.inferScalarType(R.getVPSingleValue()), {}, {},
2751+
R.getDebugLoc());
27502752
VPSplice->insertBefore(&R);
27512753
R.getVPSingleValue()->replaceAllUsesWith(VPSplice);
27522754
ToErase.push_back(&R);
@@ -3811,15 +3813,15 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
38113813
Ext0->getOpcode() == Ext1->getOpcode() &&
38123814
IsMulAccValidAndClampRange(Mul, Ext0, Ext1, Ext) && Mul->hasOneUse()) {
38133815
auto *NewExt0 = new VPWidenCastRecipe(
3814-
Ext0->getOpcode(), Ext0->getOperand(0), Ext->getResultType(), nullptr,
3815-
*Ext0, *Ext0, Ext0->getDebugLoc());
3816+
Ext0->getOpcode(), Ext0->getOperand(0), Ext->getResultType(), *Ext0,
3817+
*Ext0, Ext0->getDebugLoc());
38163818
NewExt0->insertBefore(Ext0);
38173819

38183820
VPWidenCastRecipe *NewExt1 = NewExt0;
38193821
if (Ext0 != Ext1) {
38203822
NewExt1 = new VPWidenCastRecipe(Ext1->getOpcode(), Ext1->getOperand(0),
3821-
Ext->getResultType(), nullptr, *Ext1,
3822-
*Ext1, Ext1->getDebugLoc());
3823+
Ext->getResultType(), *Ext1, *Ext1,
3824+
Ext1->getDebugLoc());
38233825
NewExt1->insertBefore(Ext1);
38243826
}
38253827
Mul->setOperand(0, NewExt0);

0 commit comments

Comments
 (0)