Skip to content

Commit 680c908

Browse files
authored
Merge pull request #3265 from adrian-prantl/27016577
2 parents eb84b7d + 6cb7d56 commit 680c908

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,14 +243,29 @@ static bool isAbstractClosure(const SILLocation &Loc) {
243243
llvm::MDNode *IRGenDebugInfo::createInlinedAt(const SILDebugScope *DS) {
244244
llvm::MDNode *InlinedAt = nullptr;
245245
if (DS) {
246-
for (auto *CS : DS->flattenedInlineTree()) {
246+
// The inlined-at chain, starting with the innermost (noninlined) scope.
247+
auto Scopes = DS->flattenedInlineTree();
248+
249+
// See if we share a common prefix with the last chain of inline scopes.
250+
unsigned N = 0;
251+
while (N < LastInlineChain.size() && N < Scopes.size() &&
252+
LastInlineChain[N].first == Scopes[N])
253+
InlinedAt = LastInlineChain[N++].second;
254+
LastInlineChain.resize(N);
255+
256+
// Construct the new suffix.
257+
for (; N < Scopes.size(); ++N) {
258+
auto *CS = Scopes[N];
247259
// In SIL the inlined-at information is part of the scopes, in
248260
// LLVM IR it is part of the location. Transforming the inlined-at
249261
// SIL scope to a location means skipping the inlined-at scope.
250262
auto *Parent = CS->Parent.get<const SILDebugScope *>();
251263
auto *ParentScope = getOrCreateScope(Parent);
252264
auto L = CS->Loc.decodeDebugLoc(SM);
253265
InlinedAt = llvm::DebugLoc::get(L.Line, L.Column, ParentScope, InlinedAt);
266+
267+
// Cache the suffix.
268+
LastInlineChain.push_back({CS, llvm::TrackingMDNodeRef(InlinedAt)});
254269
}
255270
}
256271
return InlinedAt;

lib/IRGen/IRGenDebugInfo.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class IRGenDebugInfo {
6767
llvm::DenseMap<TypeBase *, llvm::TrackingMDNodeRef> DITypeCache;
6868
llvm::StringMap<llvm::TrackingMDNodeRef> DIModuleCache;
6969
TrackingDIRefMap DIRefMap;
70+
std::vector<std::pair<const SILDebugScope *, llvm::TrackingMDNodeRef>>
71+
LastInlineChain;
7072

7173
llvm::BumpPtrAllocator DebugInfoNames;
7274
StringRef CWDName; /// The current working directory.

0 commit comments

Comments
 (0)