@@ -1190,18 +1190,33 @@ struct VPIRPhi : public VPIRInstruction {
11901190#endif
11911191};
11921192
1193+ // / Helper to manage IR metadata for recipes. It filters out metadata that
1194+ // / cannot be propagated.
1195+ class VPIRMetadata {
1196+ SmallVector<std::pair<unsigned , MDNode *>> Metadata;
1197+
1198+ protected:
1199+ VPIRMetadata () {}
1200+ VPIRMetadata (Instruction &I) { getMetadataToPropagate (&I, Metadata); }
1201+
1202+ public:
1203+ // / Add all metadata to \p I.
1204+ void applyMetadata (Instruction &I) const ;
1205+ };
1206+
11931207// / VPWidenRecipe is a recipe for producing a widened instruction using the
11941208// / opcode and operands of the recipe. This recipe covers most of the
11951209// / traditional vectorization cases where each recipe transforms into a
11961210// / vectorized version of itself.
1197- class VPWidenRecipe : public VPRecipeWithIRFlags {
1211+ class VPWidenRecipe : public VPRecipeWithIRFlags , public VPIRMetadata {
11981212 unsigned Opcode;
11991213
12001214protected:
12011215 template <typename IterT>
12021216 VPWidenRecipe (unsigned VPDefOpcode, Instruction &I,
12031217 iterator_range<IterT> Operands)
1204- : VPRecipeWithIRFlags(VPDefOpcode, Operands, I), Opcode(I.getOpcode()) {}
1218+ : VPRecipeWithIRFlags(VPDefOpcode, Operands, I), VPIRMetadata(I),
1219+ Opcode (I.getOpcode()) {}
12051220
12061221public:
12071222 template <typename IterT>
@@ -1236,7 +1251,7 @@ class VPWidenRecipe : public VPRecipeWithIRFlags {
12361251};
12371252
12381253// / VPWidenCastRecipe is a recipe to create vector cast instructions.
1239- class VPWidenCastRecipe : public VPRecipeWithIRFlags {
1254+ class VPWidenCastRecipe : public VPRecipeWithIRFlags , public VPIRMetadata {
12401255 // / Cast instruction opcode.
12411256 Instruction::CastOps Opcode;
12421257
@@ -1246,15 +1261,15 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags {
12461261public:
12471262 VPWidenCastRecipe (Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy,
12481263 CastInst &UI)
1249- : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, UI), Opcode(Opcode ),
1250- ResultTy (ResultTy) {
1264+ : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op, UI), VPIRMetadata(UI ),
1265+ Opcode (Opcode), ResultTy(ResultTy) {
12511266 assert (UI.getOpcode () == Opcode &&
12521267 " opcode of underlying cast doesn't match" );
12531268 }
12541269
12551270 VPWidenCastRecipe (Instruction::CastOps Opcode, VPValue *Op, Type *ResultTy)
1256- : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op), Opcode(Opcode ),
1257- ResultTy(ResultTy) {}
1271+ : VPRecipeWithIRFlags(VPDef::VPWidenCastSC, Op), VPIRMetadata( ),
1272+ Opcode(Opcode), ResultTy(ResultTy) {}
12581273
12591274 ~VPWidenCastRecipe () override = default ;
12601275
@@ -1288,7 +1303,7 @@ class VPWidenCastRecipe : public VPRecipeWithIRFlags {
12881303};
12891304
12901305// / A recipe for widening vector intrinsics.
1291- class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags {
1306+ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags , public VPIRMetadata {
12921307 // / ID of the vector intrinsic to widen.
12931308 Intrinsic::ID VectorIntrinsicID;
12941309
@@ -1309,7 +1324,7 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags {
13091324 ArrayRef<VPValue *> CallArguments, Type *Ty,
13101325 DebugLoc DL = {})
13111326 : VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, CI),
1312- VectorIntrinsicID (VectorIntrinsicID), ResultTy(Ty),
1327+ VPIRMetadata (CI), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty),
13131328 MayReadFromMemory(CI.mayReadFromMemory()),
13141329 MayWriteToMemory(CI.mayWriteToMemory()),
13151330 MayHaveSideEffects(CI.mayHaveSideEffects()) {}
@@ -1318,7 +1333,7 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags {
13181333 ArrayRef<VPValue *> CallArguments, Type *Ty,
13191334 DebugLoc DL = {})
13201335 : VPRecipeWithIRFlags(VPDef::VPWidenIntrinsicSC, CallArguments, DL),
1321- VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty) {
1336+ VPIRMetadata(), VectorIntrinsicID(VectorIntrinsicID), ResultTy(Ty) {
13221337 LLVMContext &Ctx = Ty->getContext ();
13231338 AttributeSet Attrs = Intrinsic::getFnAttributes (Ctx, VectorIntrinsicID);
13241339 MemoryEffects ME = Attrs.getMemoryEffects ();
@@ -1374,7 +1389,7 @@ class VPWidenIntrinsicRecipe : public VPRecipeWithIRFlags {
13741389};
13751390
13761391// / A recipe for widening Call instructions using library calls.
1377- class VPWidenCallRecipe : public VPRecipeWithIRFlags {
1392+ class VPWidenCallRecipe : public VPRecipeWithIRFlags , public VPIRMetadata {
13781393 // / Variant stores a pointer to the chosen function. There is a 1:1 mapping
13791394 // / between a given VF and the chosen vectorized variant, so there will be a
13801395 // / different VPlan for each VF with a valid variant.
@@ -1385,7 +1400,7 @@ class VPWidenCallRecipe : public VPRecipeWithIRFlags {
13851400 ArrayRef<VPValue *> CallArguments, DebugLoc DL = {})
13861401 : VPRecipeWithIRFlags(VPDef::VPWidenCallSC, CallArguments,
13871402 *cast<Instruction>(UV)),
1388- Variant (Variant) {
1403+ VPIRMetadata (*cast<Instruction>(UV)), Variant(Variant) {
13891404 assert (
13901405 isa<Function>(getOperand (getNumOperands () - 1 )->getLiveInIRValue ()) &&
13911406 " last operand must be the called function" );
@@ -1471,10 +1486,11 @@ class VPHistogramRecipe : public VPRecipeBase {
14711486};
14721487
14731488// / A recipe for widening select instructions.
1474- struct VPWidenSelectRecipe : public VPRecipeWithIRFlags {
1489+ struct VPWidenSelectRecipe : public VPRecipeWithIRFlags , public VPIRMetadata {
14751490 template <typename IterT>
14761491 VPWidenSelectRecipe (SelectInst &I, iterator_range<IterT> Operands)
1477- : VPRecipeWithIRFlags(VPDef::VPWidenSelectSC, Operands, I) {}
1492+ : VPRecipeWithIRFlags(VPDef::VPWidenSelectSC, Operands, I),
1493+ VPIRMetadata (I) {}
14781494
14791495 ~VPWidenSelectRecipe () override = default ;
14801496
@@ -2602,7 +2618,7 @@ class VPPredInstPHIRecipe : public VPSingleDefRecipe {
26022618
26032619// / A common base class for widening memory operations. An optional mask can be
26042620// / provided as the last operand.
2605- class VPWidenMemoryRecipe : public VPRecipeBase {
2621+ class VPWidenMemoryRecipe : public VPRecipeBase , public VPIRMetadata {
26062622protected:
26072623 Instruction &Ingredient;
26082624
@@ -2626,8 +2642,8 @@ class VPWidenMemoryRecipe : public VPRecipeBase {
26262642 VPWidenMemoryRecipe (const char unsigned SC, Instruction &I,
26272643 std::initializer_list<VPValue *> Operands,
26282644 bool Consecutive, bool Reverse, DebugLoc DL)
2629- : VPRecipeBase(SC, Operands, DL), Ingredient (I), Consecutive(Consecutive ),
2630- Reverse (Reverse) {
2645+ : VPRecipeBase(SC, Operands, DL), VPIRMetadata (I), Ingredient(I ),
2646+ Consecutive (Consecutive), Reverse(Reverse) {
26312647 assert ((Consecutive || !Reverse) && " Reverse implies consecutive" );
26322648 }
26332649
0 commit comments