diff options
author | Orlando Cazalet-Hyams <orlando.hyams@sony.com> | 2024-05-13 12:49:42 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-13 12:49:42 +0100 |
commit | 91d7ca904c601d181c431bffbf2773165de2fabd (patch) | |
tree | 5e05b5d86efd01fa1286b45af7fefdebcf4b2b7c /llvm/lib/IR/DebugInfo.cpp | |
parent | c5b0da9d83971d94d3b26105b1e42d3a3826ef1e (diff) | |
download | llvm-91d7ca904c601d181c431bffbf2773165de2fabd.zip llvm-91d7ca904c601d181c431bffbf2773165de2fabd.tar.gz llvm-91d7ca904c601d181c431bffbf2773165de2fabd.tar.bz2 |
[DebugInfo] Remap extracted DIAssignIDs in hotcoldsplit (#91940)
Fix #91814
When instructions are extracted into a new function the `DIAssignID` metadata
uses and attachments need to be remapped so that the stores and assignment
markers don't link to stores and assignment markers in the original function.
This matches existing inlining behaviour for DIAssignIDs.
Diffstat (limited to 'llvm/lib/IR/DebugInfo.cpp')
-rw-r--r-- | llvm/lib/IR/DebugInfo.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/llvm/lib/IR/DebugInfo.cpp b/llvm/lib/IR/DebugInfo.cpp index 7976904..4c3f37c 100644 --- a/llvm/lib/IR/DebugInfo.cpp +++ b/llvm/lib/IR/DebugInfo.cpp @@ -2130,6 +2130,30 @@ bool at::calculateFragmentIntersect( SliceSizeInBits, DVRAssign, Result); } +/// Update inlined instructions' DIAssignID metadata. We need to do this +/// otherwise a function inlined more than once into the same function +/// will cause DIAssignID to be shared by many instructions. +void at::remapAssignID(DenseMap<DIAssignID *, DIAssignID *> &Map, + Instruction &I) { + auto GetNewID = [&Map](Metadata *Old) { + DIAssignID *OldID = cast<DIAssignID>(Old); + if (DIAssignID *NewID = Map.lookup(OldID)) + return NewID; + DIAssignID *NewID = DIAssignID::getDistinct(OldID->getContext()); + Map[OldID] = NewID; + return NewID; + }; + // If we find a DIAssignID attachment or use, replace it with a new version. + for (DbgVariableRecord &DVR : filterDbgVars(I.getDbgRecordRange())) { + if (DVR.isDbgAssign()) + DVR.setAssignId(GetNewID(DVR.getAssignID())); + } + if (auto *ID = I.getMetadata(LLVMContext::MD_DIAssignID)) + I.setMetadata(LLVMContext::MD_DIAssignID, GetNewID(ID)); + else if (auto *DAI = dyn_cast<DbgAssignIntrinsic>(&I)) + DAI->setAssignId(GetNewID(DAI->getAssignID())); +} + /// Collect constant properies (base, size, offset) of \p StoreDest. /// Return std::nullopt if any properties are not constants or the /// offset from the base pointer is negative. |