Skip to content

Cache the previous result of IRGenDebugInfo::createInlinedAt(). #3265

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

Merged
merged 1 commit into from
Jun 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/IRGen/IRGenDebugInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,29 @@ static bool isAbstractClosure(const SILLocation &Loc) {
llvm::MDNode *IRGenDebugInfo::createInlinedAt(const SILDebugScope *DS) {
llvm::MDNode *InlinedAt = nullptr;
if (DS) {
for (auto *CS : DS->flattenedInlineTree()) {
// The inlined-at chain, starting with the innermost (noninlined) scope.
auto Scopes = DS->flattenedInlineTree();

// See if we share a common prefix with the last chain of inline scopes.
unsigned N = 0;
while (N < LastInlineChain.size() && N < Scopes.size() &&
LastInlineChain[N].first == Scopes[N])
InlinedAt = LastInlineChain[N++].second;
LastInlineChain.resize(N);

// Construct the new suffix.
for (; N < Scopes.size(); ++N) {
auto *CS = Scopes[N];
// In SIL the inlined-at information is part of the scopes, in
// LLVM IR it is part of the location. Transforming the inlined-at
// SIL scope to a location means skipping the inlined-at scope.
auto *Parent = CS->Parent.get<const SILDebugScope *>();
auto *ParentScope = getOrCreateScope(Parent);
auto L = CS->Loc.decodeDebugLoc(SM);
InlinedAt = llvm::DebugLoc::get(L.Line, L.Column, ParentScope, InlinedAt);

// Cache the suffix.
LastInlineChain.push_back({CS, llvm::TrackingMDNodeRef(InlinedAt)});
}
}
return InlinedAt;
Expand Down
2 changes: 2 additions & 0 deletions lib/IRGen/IRGenDebugInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class IRGenDebugInfo {
llvm::DenseMap<TypeBase *, llvm::TrackingMDNodeRef> DITypeCache;
llvm::StringMap<llvm::TrackingMDNodeRef> DIModuleCache;
TrackingDIRefMap DIRefMap;
std::vector<std::pair<const SILDebugScope *, llvm::TrackingMDNodeRef>>
LastInlineChain;

llvm::BumpPtrAllocator DebugInfoNames;
StringRef CWDName; /// The current working directory.
Expand Down