Skip to content

Commit d3edd89

Browse files
committed
!fixup address latest comments, thanks
1 parent 3760c4f commit d3edd89

File tree

4 files changed

+35
-47
lines changed

4 files changed

+35
-47
lines changed

llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class VPRecipeBuilder {
236236

237237
/// Returns the metatadata that can be preserved from the original instruction
238238
/// \p I, including noalias metadata guaranteed by runtime checks.
239-
SmallVector<std::pair<unsigned, MDNode *>>
239+
static SmallVector<std::pair<unsigned, MDNode *>>
240240
getMetadataToPropagate(Instruction *I);
241241
};
242242
} // end namespace llvm

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1194,39 +1194,33 @@ using MDArrayRef = ArrayRef<std::pair<unsigned, MDNode *>>;
11941194

11951195
/// Helper to manage IR metadata for recipes. It filters out metadata that
11961196
/// cannot be proagated.
1197-
class VPWithIRMetadata {
1197+
class VPIRMetadata {
11981198
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
11991199

12001200
protected:
1201-
VPWithIRMetadata() {}
1202-
VPWithIRMetadata(MDArrayRef Metadata) : Metadata(Metadata) {}
1203-
1204-
void addMetadata(MDArrayRef Metadata) {
1205-
append_range(this->Metadata, Metadata);
1206-
}
1201+
VPIRMetadata(MDArrayRef Metadata) : Metadata(Metadata) {}
12071202

12081203
public:
12091204
/// Add all metadata to \p V if it is an instruction.
1210-
void setMetadata(Value *V) const;
1211-
1212-
void addMetadata(unsigned Kind, MDNode *N) { Metadata.emplace_back(Kind, N); }
1205+
void applyMetadata(Value *V) const;
12131206

1207+
/// Return the IR metadata.
12141208
MDArrayRef getMetadata() const { return Metadata; }
12151209
};
12161210

12171211
/// VPWidenRecipe is a recipe for producing a widened instruction using the
12181212
/// opcode and operands of the recipe. This recipe covers most of the
12191213
/// traditional vectorization cases where each recipe transforms into a
12201214
/// vectorized version of itself.
1221-
class VPWidenRecipe : public VPRecipeWithIRFlags, public VPWithIRMetadata {
1215+
class VPWidenRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
12221216
unsigned Opcode;
12231217

12241218
protected:
12251219
template <typename IterT>
12261220
VPWidenRecipe(unsigned VPDefOpcode, Instruction &I,
12271221
iterator_range<IterT> Operands, MDArrayRef Metadata)
1228-
: VPRecipeWithIRFlags(VPDefOpcode, Operands, I),
1229-
VPWithIRMetadata(Metadata), Opcode(I.getOpcode()) {}
1222+
: VPRecipeWithIRFlags(VPDefOpcode, Operands, I), VPIRMetadata(Metadata),
1223+
Opcode(I.getOpcode()) {}
12301224

12311225
public:
12321226
template <typename IterT>
@@ -1263,7 +1257,7 @@ class VPWidenRecipe : public VPRecipeWithIRFlags, public VPWithIRMetadata {
12631257
};
12641258

12651259
/// VPWidenCastRecipe is a recipe to create vector cast instructions.
1266-
class VPWidenCastRecipe : public VPRecipeWithIRFlags, public VPWithIRMetadata {
1260+
class VPWidenCastRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
12671261
/// Cast instruction opcode.
12681262
Instruction::CastOps Opcode;
12691263

@@ -1274,13 +1268,13 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags, public VPWithIRMetadata {
12741268
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
12751269
CastInst &UI, MDArrayRef Metadata)
12761270
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, UI),
1277-
VPWithIRMetadata(Metadata), Opcode(Opcode), ResultTy(ResultTy) {
1271+
VPIRMetadata(Metadata), Opcode(Opcode), ResultTy(ResultTy) {
12781272
assert(UI.getOpcode() == Opcode &&
12791273
"opcode of underlying cast doesn't match");
12801274
}
12811275

12821276
VPWidenCastRecipe(Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy)
1283-
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op), VPWithIRMetadata(),
1277+
: VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op), VPIRMetadata({}),
12841278
Opcode(Opcode), ResultTy(ResultTy) {}
12851279

12861280
~VPWidenCastRecipe() override = default;
@@ -1315,8 +1309,7 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags, public VPWithIRMetadata {
13151309
};
13161310

13171311
/// A recipe for widening vector intrinsics.
1318-
class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags,
1319-
public VPWithIRMetadata {
1312+
class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
13201313
/// ID of the vector intrinsic to widen.
13211314
Intrinsic::ID VectorIntrinsicID;
13221315

@@ -1337,7 +1330,7 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags,
13371330
ArrayRef<VPValue *> CallArguments, Type *Ty,
13381331
MDArrayRef Metadata, DebugLoc DL = {})
13391332
: VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, CI),
1340-
VPWithIRMetadata(Metadata), VectorIntrinsicID(VectorIntrinsicID),
1333+
VPIRMetadata(Metadata), VectorIntrinsicID(VectorIntrinsicID),
13411334
ResultTy(Ty), MayReadFromMemory(CI.mayReadFromMemory()),
13421335
MayWriteToMemory(CI.mayWriteToMemory()),
13431336
MayHaveSideEffects(CI.mayHaveSideEffects()) {}
@@ -1346,7 +1339,7 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags,
13461339
ArrayRef<VPValue *> CallArguments, Type *Ty,
13471340
MDArrayRef Metadata, DebugLoc DL = {})
13481341
: VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, DL),
1349-
VPWithIRMetadata(Metadata), VectorIntrinsicID(VectorIntrinsicID),
1342+
VPIRMetadata(Metadata), VectorIntrinsicID(VectorIntrinsicID),
13501343
ResultTy(Ty) {
13511344
LLVMContext &Ctx = Ty->getContext();
13521345
AttributeSet Attrs = Intrinsic::getFnAttributes(Ctx, VectorIntrinsicID);
@@ -1403,7 +1396,7 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags,
14031396
};
14041397

14051398
/// A recipe for widening Call instructions using library calls.
1406-
class VPWidenCallRecipe : public VPRecipeWithIRFlags, public VPWithIRMetadata {
1399+
class VPWidenCallRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
14071400
/// Variant stores a pointer to the chosen function. There is a 1:1 mapping
14081401
/// between a given VF and the chosen vectorized variant, so there will be a
14091402
/// different VPlan for each VF with a valid variant.
@@ -1415,7 +1408,7 @@ class VPWidenCallRecipe : public VPRecipeWithIRFlags, public VPWithIRMetadata {
14151408
DebugLoc DL = {})
14161409
: VPRecipeWithIRFlags(VPDef::VPWidenCallSC, CallArguments,
14171410
*cast<Instruction>(UV)),
1418-
VPWithIRMetadata(Metadata), Variant(Variant) {
1411+
VPIRMetadata(Metadata), Variant(Variant) {
14191412
assert(
14201413
isa<Function>(getOperand(getNumOperands() - 1)->getLiveInIRValue()) &&
14211414
"last operand must be the called function");
@@ -1502,13 +1495,12 @@ class VPHistogramRecipe : public VPRecipeBase {
15021495
};
15031496

15041497
/// A recipe for widening select instructions.
1505-
struct VPWidenSelectRecipe : public VPRecipeWithIRFlags,
1506-
public VPWithIRMetadata {
1498+
struct VPWidenSelectRecipe : public VPRecipeWithIRFlags, public VPIRMetadata {
15071499
template <typename IterT>
15081500
VPWidenSelectRecipe(SelectInst &I, iterator_range<IterT> Operands,
15091501
MDArrayRef Metadata)
15101502
: VPRecipeWithIRFlags(VPDef::VPWidenSelectSC, Operands, I),
1511-
VPWithIRMetadata(Metadata) {}
1503+
VPIRMetadata(Metadata) {}
15121504

15131505
~VPWidenSelectRecipe() override = default;
15141506

@@ -2636,7 +2628,7 @@ class VPPredInstPHIRecipe : public VPSingleDefRecipe {
26362628

26372629
/// A common base class for widening memory operations. An optional mask can be
26382630
/// provided as the last operand.
2639-
class VPWidenMemoryRecipe : public VPRecipeBase, public VPWithIRMetadata {
2631+
class VPWidenMemoryRecipe : public VPRecipeBase, public VPIRMetadata {
26402632
protected:
26412633
Instruction &Ingredient;
26422634

@@ -2661,8 +2653,8 @@ class VPWidenMemoryRecipe : public VPRecipeBase, public VPWithIRMetadata {
26612653
std::initializer_list<VPValue *> Operands,
26622654
bool Consecutive, bool Reverse, MDArrayRef Metadata,
26632655
DebugLoc DL)
2664-
: VPRecipeBase(SC, Operands, DL), VPWithIRMetadata(Metadata),
2665-
Ingredient(I), Consecutive(Consecutive), Reverse(Reverse) {
2656+
: VPRecipeBase(SC, Operands, DL), VPIRMetadata(Metadata), Ingredient(I),
2657+
Consecutive(Consecutive), Reverse(Reverse) {
26662658
assert((Consecutive || !Reverse) && "Reverse implies consecutive");
26672659
}
26682660

@@ -2731,7 +2723,6 @@ struct VPWidenLoadRecipe final : public VPWidenMemoryRecipe, public VPValue {
27312723
auto *Copy = new VPWidenLoadRecipe(cast<LoadInst>(Ingredient), getAddr(),
27322724
getMask(), Consecutive, Reverse,
27332725
getMetadata(), getDebugLoc());
2734-
Copy->addMetadata(getMetadata());
27352726
return Copy;
27362727
}
27372728

@@ -2766,7 +2757,6 @@ struct VPWidenLoadEVLRecipe final : public VPWidenMemoryRecipe, public VPValue {
27662757
L.isReverse(), L.getMetadata(), L.getDebugLoc()),
27672758
VPValue(this, &getIngredient()) {
27682759
setMask(Mask);
2769-
addMetadata(L.getMetadata());
27702760
}
27712761

27722762
VP_CLASSOF_IMPL(VPDef::VPWidenLoadEVLSC)
@@ -2812,7 +2802,6 @@ struct VPWidenStoreRecipe final : public VPWidenMemoryRecipe {
28122802
auto *Copy = new VPWidenStoreRecipe(
28132803
cast<StoreInst>(Ingredient), getAddr(), getStoredValue(), getMask(),
28142804
Consecutive, Reverse, getMetadata(), getDebugLoc());
2815-
Copy->addMetadata(getMetadata());
28162805
return Copy;
28172806
}
28182807

@@ -2850,7 +2839,6 @@ struct VPWidenStoreEVLRecipe final : public VPWidenMemoryRecipe {
28502839
S.isConsecutive(), S.isReverse(), S.getMetadata(),
28512840
S.getDebugLoc()) {
28522841
setMask(Mask);
2853-
addMetadata(S.getMetadata());
28542842
}
28552843

28562844
VP_CLASSOF_IMPL(VPDef::VPWidenStoreEVLSC)

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,7 @@ void VPIRPhi::print(raw_ostream &O, const Twine &Indent,
12041204
}
12051205
#endif
12061206

1207-
void VPWithIRMetadata::setMetadata(Value *V) const {
1207+
void VPIRMetadata::applyMetadata(Value *V) const {
12081208
auto *I = dyn_cast<Instruction>(V);
12091209
if (!I)
12101210
return;
@@ -1239,10 +1239,10 @@ void VPWidenCallRecipe::execute(VPTransformState &State) {
12391239

12401240
CallInst *V = State.Builder.CreateCall(Variant, Args, OpBundles);
12411241
setFlags(V);
1242+
applyMetadata(V);
12421243

12431244
if (!V->getType()->isVoidTy())
12441245
State.set(this, V);
1245-
setMetadata(V);
12461246
}
12471247

12481248
InstructionCost VPWidenCallRecipe::computeCost(ElementCount VF,
@@ -1318,10 +1318,10 @@ void VPWidenIntrinsicRecipe::execute(VPTransformState &State) {
13181318
CallInst *V = State.Builder.CreateCall(VectorF, Args, OpBundles);
13191319

13201320
setFlags(V);
1321+
applyMetadata(V);
13211322

13221323
if (!V->getType()->isVoidTy())
13231324
State.set(this, V);
1324-
setMetadata(V);
13251325
}
13261326

13271327
InstructionCost VPWidenIntrinsicRecipe::computeCost(ElementCount VF,
@@ -1518,7 +1518,7 @@ void VPWidenSelectRecipe::execute(VPTransformState &State) {
15181518
State.set(this, Sel);
15191519
if (isa<FPMathOperator>(Sel))
15201520
setFlags(cast<Instruction>(Sel));
1521-
setMetadata(Sel);
1521+
applyMetadata(Sel);
15221522
}
15231523

15241524
InstructionCost VPWidenSelectRecipe::computeCost(ElementCount VF,
@@ -1649,12 +1649,13 @@ void VPWidenRecipe::execute(VPTransformState &State) {
16491649

16501650
Value *V = Builder.CreateNAryOp(Opcode, Ops);
16511651

1652-
if (auto *VecOp = dyn_cast<Instruction>(V))
1652+
if (auto *VecOp = dyn_cast<Instruction>(V)) {
16531653
setFlags(VecOp);
1654+
applyMetadata(V);
1655+
}
16541656

16551657
// Use this vector value for all users of the original instruction.
16561658
State.set(this, V);
1657-
setMetadata(V);
16581659
break;
16591660
}
16601661
case Instruction::ExtractValue: {
@@ -1686,8 +1687,8 @@ void VPWidenRecipe::execute(VPTransformState &State) {
16861687
} else {
16871688
C = Builder.CreateICmp(getPredicate(), A, B);
16881689
}
1690+
applyMetadata(C);
16891691
State.set(this, C);
1690-
setMetadata(C);
16911692
break;
16921693
}
16931694
default:
@@ -1805,7 +1806,7 @@ void VPWidenCastRecipe::execute(VPTransformState &State) {
18051806
State.set(this, Cast);
18061807
if (auto *CastOp = dyn_cast<Instruction>(Cast)) {
18071808
setFlags(CastOp);
1808-
setMetadata(CastOp);
1809+
applyMetadata(CastOp);
18091810
}
18101811
}
18111812

@@ -2759,7 +2760,7 @@ void VPWidenLoadRecipe::execute(VPTransformState &State) {
27592760
}
27602761
// Add metadata to the load, but setVectorValue to the reverse shuffle.
27612762
State.addNewMetadata(NewLI, LI);
2762-
setMetadata(NewLI);
2763+
applyMetadata(NewLI);
27632764
if (Reverse)
27642765
NewLI = Builder.CreateVectorReverse(NewLI, "reverse");
27652766
State.set(this, NewLI);
@@ -2820,7 +2821,7 @@ void VPWidenLoadEVLRecipe::execute(VPTransformState &State) {
28202821
NewLI->addParamAttr(
28212822
0, Attribute::getWithAlignment(NewLI->getContext(), Alignment));
28222823
State.addNewMetadata(NewLI, LI);
2823-
setMetadata(NewLI);
2824+
applyMetadata(NewLI);
28242825
Instruction *Res = NewLI;
28252826
if (isReverse())
28262827
Res = createReverseEVL(Builder, Res, EVL, "vp.reverse");
@@ -2897,7 +2898,7 @@ void VPWidenStoreRecipe::execute(VPTransformState &State) {
28972898
else
28982899
NewSI = Builder.CreateAlignedStore(StoredVal, Addr, Alignment);
28992900
State.addNewMetadata(NewSI, SI);
2900-
setMetadata(NewSI);
2901+
applyMetadata(NewSI);
29012902
}
29022903

29032904
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
@@ -2945,7 +2946,7 @@ void VPWidenStoreEVLRecipe::execute(VPTransformState &State) {
29452946
NewSI->addParamAttr(
29462947
1, Attribute::getWithAlignment(NewSI->getContext(), Alignment));
29472948
State.addNewMetadata(NewSI, SI);
2948-
setMetadata(NewSI);
2949+
applyMetadata(NewSI);
29492950
}
29502951

29512952
InstructionCost VPWidenStoreEVLRecipe::computeCost(ElementCount VF,

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ bool VPlanTransforms::tryToConvertVPInstructionsToVPRecipes(
7070
NewRecipe = new VPWidenIntOrFpInductionRecipe(
7171
Phi, Start, Step, &Plan->getVF(), *II, Ingredient.getDebugLoc());
7272
} else {
73-
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
74-
getMetadataToPropagate(Inst, Metadata);
73+
auto Metadata = VPRecipeBuilder::getMetadataToPropagate(Inst);
7574
assert(isa<VPInstruction>(&Ingredient) &&
7675
"only VPInstructions expected here");
7776
assert(!isa<PHINode>(Inst) && "phis should be handled above");

0 commit comments

Comments
 (0)