-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[DebugInfo][RemoveDIs] Don't allocate one DPMarker per instruction #79345
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
0620bf7
7c172df
ad1bc4e
f4d7242
3e4d83e
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 |
---|---|---|
|
@@ -111,11 +111,6 @@ void Instruction::insertAfter(Instruction *InsertPos) { | |
BasicBlock *DestParent = InsertPos->getParent(); | ||
|
||
DestParent->getInstList().insertAfter(InsertPos->getIterator(), this); | ||
|
||
// No need to manually update DPValues: if we insert after an instruction | ||
// position, then we can never have any DPValues on "this". | ||
if (DestParent->IsNewDbgInfoFormat) | ||
DestParent->createMarker(this); | ||
} | ||
|
||
BasicBlock::iterator Instruction::insertInto(BasicBlock *ParentBB, | ||
|
@@ -138,17 +133,15 @@ void Instruction::insertBefore(BasicBlock &BB, | |
if (!BB.IsNewDbgInfoFormat) | ||
return; | ||
|
||
BB.createMarker(this); | ||
|
||
// We've inserted "this": if InsertAtHead is set then it comes before any | ||
// DPValues attached to InsertPos. But if it's not set, then any DPValues | ||
// should now come before "this". | ||
bool InsertAtHead = InsertPos.getHeadBit(); | ||
if (!InsertAtHead) { | ||
DPMarker *SrcMarker = BB.getMarker(InsertPos); | ||
// If there's no source marker, InsertPos is very likely end(). | ||
if (SrcMarker) | ||
DbgMarker->absorbDebugValues(*SrcMarker, false); | ||
if (SrcMarker && !SrcMarker->empty()) { | ||
adoptDbgValues(&BB, InsertPos, false); | ||
} | ||
} | ||
|
||
// If we're inserting a terminator, check if we need to flush out | ||
|
@@ -212,14 +205,13 @@ void Instruction::moveBeforeImpl(BasicBlock &BB, InstListType::iterator I, | |
BB.getInstList().splice(I, getParent()->getInstList(), getIterator()); | ||
|
||
if (BB.IsNewDbgInfoFormat && !Preserve) { | ||
if (!DbgMarker) | ||
BB.createMarker(this); | ||
DPMarker *NextMarker = getParent()->getNextMarker(this); | ||
|
||
// If we're inserting at point I, and not in front of the DPValues attached | ||
// there, then we should absorb the DPValues attached to I. | ||
if (NextMarker && !InsertAtHead) | ||
DbgMarker->absorbDebugValues(*NextMarker, false); | ||
if (!InsertAtHead && NextMarker && !NextMarker->empty()) { | ||
adoptDbgValues(&BB, I, false); | ||
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. Given that (most? all?) other uses of Do we want to make +1 to what @SLTozer said:
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. Hmmm, I was going to say "because we never have trailing DPValues here" (i.e. ones hanging off the end of the block), but I'm now seeing various scenarios where moveBefore is called with the end() iterator. And the assertion on moveBeforeImpl's entry explicitly takes account of that. So this would need some cleanup. It's probably better to fold all that maintenance code into adoptDbgValues, I suppose I'll look at that next. |
||
} | ||
} | ||
|
||
if (isTerminator()) | ||
|
@@ -258,6 +250,48 @@ std::optional<DPValue::self_iterator> Instruction::getDbgReinsertionPosition() { | |
|
||
bool Instruction::hasDbgValues() const { return !getDbgValueRange().empty(); } | ||
|
||
void Instruction::adoptDbgValues(BasicBlock *BB, BasicBlock::iterator It, | ||
bool InsertAtHead) { | ||
DPMarker *SrcMarker = BB->getMarker(It); | ||
auto ReleaseTrailingDPValues = [BB, It, SrcMarker]() { | ||
if (BB->end() == It) { | ||
SrcMarker->eraseFromParent(); | ||
BB->deleteTrailingDPValues(); | ||
} | ||
}; | ||
|
||
if (!SrcMarker || SrcMarker->StoredDPValues.empty()) { | ||
ReleaseTrailingDPValues(); | ||
return; | ||
} | ||
|
||
// If we have DPMarkers attached to this instruction, we have to honour the | ||
// ordering of DPValues between this and the other marker. Fall back to just | ||
// absorbing from the source. | ||
if (DbgMarker || It == BB->end()) { | ||
// Ensure we _do_ have a marker. | ||
getParent()->createMarker(this); | ||
DbgMarker->absorbDebugValues(*SrcMarker, InsertAtHead); | ||
|
||
// Having transferred everything out of SrcMarker, we _could_ clean it up | ||
// and free the marker now. However, that's a lot of heap-accounting for a | ||
// small amount of memory with a good chance of re-use. Leave it for the | ||
// moment. It will be released when the Instruction is freed in the worst | ||
// case. | ||
// However: if we transferred from a trailing marker off the end of the | ||
// block, it's important to not leave the empty marker trailing. It will | ||
// give a misleading impression that some debug records have been left | ||
// trailing. | ||
ReleaseTrailingDPValues(); | ||
} else { | ||
// Optimisation: we're transferring all the DPValues from the source marker | ||
// onto this empty location: just adopt the other instructions marker. | ||
DbgMarker = SrcMarker; | ||
DbgMarker->MarkedInstr = this; | ||
It->DbgMarker = nullptr; | ||
} | ||
} | ||
|
||
void Instruction::dropDbgValues() { | ||
if (DbgMarker) | ||
DbgMarker->dropDPValues(); | ||
|
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't this whole if/else block be replaced by just
adoptDbgValues
?