-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[VPlan] Manage instruction metadata in VPlan. #135272
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3760c4f
d3edd89
980a939
7ad19f7
f9d1fb5
6c8ef1f
ef9bcc9
681bb63
14ee2b1
923336d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -290,13 +290,6 @@ struct VPTransformState { | |
/// vector loop. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is the above description still accurate? Would be good to clarify when State.addNewMetadata(To, Orig) needs to complement applyMetadata(To). Will possibly be handled by #136450 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is still accurate; applyMetadata in this patch applies metadata already on |
||
void addNewMetadata(Instruction *To, const Instruction *Orig); | ||
|
||
/// Add metadata from one instruction to another. | ||
/// | ||
/// This includes both the original MDs from \p From and additional ones (\see | ||
/// addNewMetadata). Use this for *newly created* instructions in the vector | ||
/// loop. | ||
void addMetadata(Value *To, Instruction *From); | ||
|
||
/// Set the debug location in the builder using the debug location \p DL. | ||
void setDebugLocFrom(DebugLoc DL); | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -1205,6 +1205,11 @@ void VPIRPhi::print(raw_ostream &O, const Twine &Indent, | |||||||||||||||
} | ||||||||||||||||
#endif | ||||||||||||||||
|
||||||||||||||||
void VPIRMetadata::applyMetadata(Instruction &I) const { | ||||||||||||||||
for (const auto &[Kind, Node] : Metadata) | ||||||||||||||||
I.setMetadata(Kind, Node); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
void VPWidenCallRecipe::execute(VPTransformState &State) { | ||||||||||||||||
assert(State.VF.isVector() && "not widening"); | ||||||||||||||||
assert(Variant != nullptr && "Can't create vector function."); | ||||||||||||||||
|
@@ -1231,11 +1236,11 @@ void VPWidenCallRecipe::execute(VPTransformState &State) { | |||||||||||||||
|
||||||||||||||||
CallInst *V = State.Builder.CreateCall(Variant, Args, OpBundles); | ||||||||||||||||
applyFlags(*V); | ||||||||||||||||
applyMetadata(*V); | ||||||||||||||||
V->setCallingConv(Variant->getCallingConv()); | ||||||||||||||||
|
||||||||||||||||
if (!V->getType()->isVoidTy()) | ||||||||||||||||
State.set(this, V); | ||||||||||||||||
Comment on lines
1241
to
1243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: good to place setMetadata() next to setFlags() in general, here and below.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done thanks |
||||||||||||||||
State.addMetadata(V, CI); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
InstructionCost VPWidenCallRecipe::computeCost(ElementCount VF, | ||||||||||||||||
|
@@ -1311,10 +1316,10 @@ void VPWidenIntrinsicRecipe::execute(VPTransformState &State) { | |||||||||||||||
CallInst *V = State.Builder.CreateCall(VectorF, Args, OpBundles); | ||||||||||||||||
|
||||||||||||||||
applyFlags(*V); | ||||||||||||||||
applyMetadata(*V); | ||||||||||||||||
|
||||||||||||||||
if (!V->getType()->isVoidTy()) | ||||||||||||||||
State.set(this, V); | ||||||||||||||||
State.addMetadata(V, CI); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
InstructionCost VPWidenIntrinsicRecipe::computeCost(ElementCount VF, | ||||||||||||||||
|
@@ -1509,9 +1514,11 @@ void VPWidenSelectRecipe::execute(VPTransformState &State) { | |||||||||||||||
Value *Op1 = State.get(getOperand(2)); | ||||||||||||||||
Value *Sel = State.Builder.CreateSelect(Cond, Op0, Op1); | ||||||||||||||||
State.set(this, Sel); | ||||||||||||||||
if (isa<FPMathOperator>(Sel)) | ||||||||||||||||
applyFlags(*cast<Instruction>(Sel)); | ||||||||||||||||
State.addMetadata(Sel, dyn_cast_or_null<Instruction>(getUnderlyingValue())); | ||||||||||||||||
if (auto *I = dyn_cast<Instruction>(Sel)) { | ||||||||||||||||
if (isa<FPMathOperator>(I)) | ||||||||||||||||
applyFlags(*I); | ||||||||||||||||
applyMetadata(*I); | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
+1517
to
+1521
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent, consistency nit: good to keep State.set() as the last operation of execute(), after fully finishing to build the new instruction/value, including applying its flags/metadata. Conceptually, flags and metadata could be folded into Builder.CreateSelect(). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can do separately, thanks. |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
InstructionCost VPWidenSelectRecipe::computeCost(ElementCount VF, | ||||||||||||||||
|
@@ -1642,12 +1649,13 @@ void VPWidenRecipe::execute(VPTransformState &State) { | |||||||||||||||
|
||||||||||||||||
Value *V = Builder.CreateNAryOp(Opcode, Ops); | ||||||||||||||||
|
||||||||||||||||
if (auto *VecOp = dyn_cast<Instruction>(V)) | ||||||||||||||||
if (auto *VecOp = dyn_cast<Instruction>(V)) { | ||||||||||||||||
applyFlags(*VecOp); | ||||||||||||||||
applyMetadata(*VecOp); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here setFlags() is already applied under dyn_cast to Instruction. Place setMetadata() here as well, or rather applyMetadata(Instruction*)? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done, thanks |
||||||||||||||||
// Use this vector value for all users of the original instruction. | ||||||||||||||||
State.set(this, V); | ||||||||||||||||
State.addMetadata(V, dyn_cast_or_null<Instruction>(getUnderlyingValue())); | ||||||||||||||||
break; | ||||||||||||||||
} | ||||||||||||||||
case Instruction::ExtractValue: { | ||||||||||||||||
|
@@ -1679,8 +1687,9 @@ void VPWidenRecipe::execute(VPTransformState &State) { | |||||||||||||||
} else { | ||||||||||||||||
C = Builder.CreateICmp(getPredicate(), A, B); | ||||||||||||||||
} | ||||||||||||||||
if (auto *I = dyn_cast<Instruction>(C)) | ||||||||||||||||
applyMetadata(*I); | ||||||||||||||||
State.set(this, C); | ||||||||||||||||
State.addMetadata(C, dyn_cast_or_null<Instruction>(getUnderlyingValue())); | ||||||||||||||||
break; | ||||||||||||||||
} | ||||||||||||||||
default: | ||||||||||||||||
|
@@ -1796,9 +1805,10 @@ void VPWidenCastRecipe::execute(VPTransformState &State) { | |||||||||||||||
Value *A = State.get(Op); | ||||||||||||||||
Value *Cast = Builder.CreateCast(Instruction::CastOps(Opcode), A, DestTy); | ||||||||||||||||
State.set(this, Cast); | ||||||||||||||||
State.addMetadata(Cast, cast_or_null<Instruction>(getUnderlyingValue())); | ||||||||||||||||
if (auto *CastOp = dyn_cast<Instruction>(Cast)) | ||||||||||||||||
if (auto *CastOp = dyn_cast<Instruction>(Cast)) { | ||||||||||||||||
applyFlags(*CastOp); | ||||||||||||||||
applyMetadata(*CastOp); | ||||||||||||||||
} | ||||||||||||||||
Comment on lines
-1800
to
+1811
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same independent consistency nit. |
||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
InstructionCost VPWidenCastRecipe::computeCost(ElementCount VF, | ||||||||||||||||
|
@@ -2750,8 +2760,10 @@ void VPWidenLoadRecipe::execute(VPTransformState &State) { | |||||||||||||||
} else { | ||||||||||||||||
NewLI = Builder.CreateAlignedLoad(DataTy, Addr, Alignment, "wide.load"); | ||||||||||||||||
} | ||||||||||||||||
// Add metadata to the load, but setVectorValue to the reverse shuffle. | ||||||||||||||||
State.addMetadata(NewLI, cast<LoadInst>(&Ingredient)); | ||||||||||||||||
// Add metadata to the load, but set the result to the reverse shuffle, if | ||||||||||||||||
// needed. | ||||||||||||||||
State.addNewMetadata(cast<Instruction>(NewLI), &Ingredient); | ||||||||||||||||
applyMetadata(*cast<Instruction>(NewLI)); | ||||||||||||||||
if (Reverse) | ||||||||||||||||
NewLI = Builder.CreateVectorReverse(NewLI, "reverse"); | ||||||||||||||||
State.set(this, NewLI); | ||||||||||||||||
|
@@ -2810,7 +2822,8 @@ void VPWidenLoadEVLRecipe::execute(VPTransformState &State) { | |||||||||||||||
} | ||||||||||||||||
NewLI->addParamAttr( | ||||||||||||||||
0, Attribute::getWithAlignment(NewLI->getContext(), Alignment)); | ||||||||||||||||
State.addMetadata(NewLI, cast<LoadInst>(&Ingredient)); | ||||||||||||||||
State.addNewMetadata(NewLI, &Ingredient); | ||||||||||||||||
applyMetadata(*NewLI); | ||||||||||||||||
Instruction *Res = NewLI; | ||||||||||||||||
if (isReverse()) | ||||||||||||||||
Res = createReverseEVL(Builder, Res, EVL, "vp.reverse"); | ||||||||||||||||
|
@@ -2884,7 +2897,8 @@ void VPWidenStoreRecipe::execute(VPTransformState &State) { | |||||||||||||||
NewSI = Builder.CreateMaskedStore(StoredVal, Addr, Alignment, Mask); | ||||||||||||||||
else | ||||||||||||||||
NewSI = Builder.CreateAlignedStore(StoredVal, Addr, Alignment); | ||||||||||||||||
State.addMetadata(NewSI, cast<StoreInst>(&Ingredient)); | ||||||||||||||||
State.addNewMetadata(NewSI, &Ingredient); | ||||||||||||||||
applyMetadata(*NewSI); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) | ||||||||||||||||
|
@@ -2930,7 +2944,8 @@ void VPWidenStoreEVLRecipe::execute(VPTransformState &State) { | |||||||||||||||
} | ||||||||||||||||
NewSI->addParamAttr( | ||||||||||||||||
1, Attribute::getWithAlignment(NewSI->getContext(), Alignment)); | ||||||||||||||||
State.addMetadata(NewSI, cast<StoreInst>(&Ingredient)); | ||||||||||||||||
State.addNewMetadata(NewSI, &Ingredient); | ||||||||||||||||
applyMetadata(*NewSI); | ||||||||||||||||
} | ||||||||||||||||
|
||||||||||||||||
InstructionCost VPWidenStoreEVLRecipe::computeCost(ElementCount VF, | ||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this way of initializing
VPIRMetadata(I)
be applied to all recipe constructors that receive their underlying instructionI
as parameter? This seems like a natural default behavior, could be followed by an update if some other exceptional metadata is desired.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated for now, although it might be good to encourage avoidance of relying on underlying instructions on construction ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Certainly, by all means!
Any recipe that can be constructed w/o an underlying instruction should be; at that point its metadata can be passed instead of the instruction itself.