-
Notifications
You must be signed in to change notification settings - Fork 0
[DebugLocCov] Plumbing to enable detailed and accurate tracking of DebugLocs #4
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
base: main
Are you sure you want to change the base?
Changes from 8 commits
91061aa
3068f5b
604afeb
9475fa6
9b8189c
0818d38
f23826d
39df02f
f61843f
93ec698
052d724
513a7ec
c9862be
1be10f6
72906cd
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 |
---|---|---|
|
@@ -93,9 +93,15 @@ class IRBuilderBase { | |
/// created instructions, like !dbg metadata. | ||
SmallVector<std::pair<unsigned, MDNode *>, 2> MetadataToCopy; | ||
|
||
DebugLoc StoredDL; | ||
|
||
/// Add or update the an entry (Kind, MD) to MetadataToCopy, if \p MD is not | ||
/// null. If \p MD is null, remove the entry with \p Kind. | ||
void AddOrRemoveMetadataToCopy(unsigned Kind, MDNode *MD) { | ||
if (Kind == LLVMContext::MD_dbg) { | ||
StoredDL = DebugLoc(MD); | ||
} | ||
|
||
if (!MD) { | ||
erase_if(MetadataToCopy, [Kind](const std::pair<unsigned, MDNode *> &KV) { | ||
return KV.first == Kind; | ||
|
@@ -216,6 +222,10 @@ class IRBuilderBase { | |
/// Set location information used by debugging information. | ||
void SetCurrentDebugLocation(DebugLoc L) { | ||
AddOrRemoveMetadataToCopy(LLVMContext::MD_dbg, L.getAsMDNode()); | ||
// Although we set StoredDL in the above call, we prefer to use the exact | ||
// DebugLoc we were given, so overwrite it here; the call is only needed to | ||
// update the entry in MetadataToCopy. | ||
StoredDL = std::move(L); | ||
} | ||
|
||
/// Set nosanitize metadata. | ||
|
@@ -229,8 +239,11 @@ class IRBuilderBase { | |
/// not on \p Src will be dropped from MetadataToCopy. | ||
void CollectMetadataToCopy(Instruction *Src, | ||
ArrayRef<unsigned> MetadataKinds) { | ||
for (unsigned K : MetadataKinds) | ||
for (unsigned K : MetadataKinds) { | ||
AddOrRemoveMetadataToCopy(K, Src->getMetadata(K)); | ||
if (K == LLVMContext::MD_dbg) | ||
SetCurrentDebugLocation(Src->getDebugLoc()); | ||
} | ||
} | ||
|
||
/// Get location information used by debugging information. | ||
|
@@ -242,8 +255,21 @@ class IRBuilderBase { | |
|
||
/// Add all entries in MetadataToCopy to \p I. | ||
void AddMetadataToInst(Instruction *I) const { | ||
for (const auto &KV : MetadataToCopy) | ||
for (const auto &KV : MetadataToCopy) { | ||
if (KV.first == LLVMContext::MD_dbg) { | ||
// If `!I->getDebugLoc()` then we will call this below anyway, so skip | ||
// a duplicate call here. | ||
if (I->getDebugLoc()) | ||
I->setDebugLoc(StoredDL.getCopied()); | ||
continue; | ||
} | ||
I->setMetadata(KV.first, KV.second); | ||
} | ||
// If I does not have an existing DebugLoc and no DebugLoc has been set | ||
// here, we copy our DebugLoc to I anyway, because more likely than not I | ||
// is a new instruction whose DL should originate from this builder. | ||
if (!I->getDebugLoc()) | ||
I->setDebugLoc(StoredDL.getCopied()); | ||
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. Would these things not more naturally be placed in 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. "these things" meaning the |
||
} | ||
|
||
/// Get the return type of the current function that we're emitting | ||
|
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.
Why this?
Uh oh!
There was an error while loading. Please reload this page.
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.
AddOrRemoveMetadataToCopy
only takes theMDNode*
as an argument, so we can't capture the metadata from the source DebugLoc. We still callAddOrRemoveMetadataToCopy
because this whole bit in IRBuilder is a bit messy; we wantMD_dbg
to still appear in theMetadataToCopy
map because otherwise we won't know that we need to copy the stored debugloc to any inserted instruction. I've sprinkled comments around the place to explain parts of this piecemeal, but before submitting this to a real review it probably needs to be rewritten more intuitively.