From 6cb7d5650054ca5e7d9886e0788ed94db99fafaf Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Wed, 29 Jun 2016 15:57:47 -0700 Subject: [PATCH] Cache the previous result of IRGenDebugInfo::createInlinedAt(). This saves ~4 seconds of a -r --no-assertions stdlib build and lowers the contribution of llvm::SourceMgr::getLineAndColumn() to the total runtime from 6% to 2%. --- lib/IRGen/IRGenDebugInfo.cpp | 17 ++++++++++++++++- lib/IRGen/IRGenDebugInfo.h | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/IRGen/IRGenDebugInfo.cpp b/lib/IRGen/IRGenDebugInfo.cpp index b328c6deb5e58..3d84b716daab8 100644 --- a/lib/IRGen/IRGenDebugInfo.cpp +++ b/lib/IRGen/IRGenDebugInfo.cpp @@ -243,7 +243,19 @@ 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. @@ -251,6 +263,9 @@ llvm::MDNode *IRGenDebugInfo::createInlinedAt(const SILDebugScope *DS) { 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; diff --git a/lib/IRGen/IRGenDebugInfo.h b/lib/IRGen/IRGenDebugInfo.h index 465721a13cca6..0841a745d457d 100644 --- a/lib/IRGen/IRGenDebugInfo.h +++ b/lib/IRGen/IRGenDebugInfo.h @@ -67,6 +67,8 @@ class IRGenDebugInfo { llvm::DenseMap DITypeCache; llvm::StringMap DIModuleCache; TrackingDIRefMap DIRefMap; + std::vector> + LastInlineChain; llvm::BumpPtrAllocator DebugInfoNames; StringRef CWDName; /// The current working directory.