From b5b0db911b4a0ec23cc71009c64da392e0ab4e85 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Wed, 30 Apr 2014 23:40:59 +0000 Subject: LexicalScopes: use unique_ptr to own LexicalScope objects. Ownership of abstract scopes coming soon. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207724 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/LexicalScopes.h | 6 ++++-- lib/CodeGen/LexicalScopes.cpp | 32 ++++++++++++++++---------------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/include/llvm/CodeGen/LexicalScopes.h b/include/llvm/CodeGen/LexicalScopes.h index d6468bd75c..8ce280e35a 100644 --- a/include/llvm/CodeGen/LexicalScopes.h +++ b/include/llvm/CodeGen/LexicalScopes.h @@ -25,6 +25,7 @@ #include "llvm/IR/Metadata.h" #include "llvm/IR/ValueHandle.h" #include +#include namespace llvm { class MachineInstr; @@ -100,7 +101,8 @@ public: /// findLexicalScope - Find regular lexical scope or return NULL. LexicalScope *findLexicalScope(const MDNode *N) { - return LexicalScopeMap.lookup(N); + auto I = LexicalScopeMap.find(N); + return I != LexicalScopeMap.end() ? I->second.get() : nullptr; } /// dump - Print data structures to dbgs(). @@ -134,7 +136,7 @@ private: /// LexicalScopeMap - Tracks the scopes in the current function. Owns the /// contained LexicalScope*s. - DenseMap LexicalScopeMap; + DenseMap> LexicalScopeMap; /// InlinedLexicalScopeMap - Tracks inlined function scopes in current /// function. diff --git a/lib/CodeGen/LexicalScopes.cpp b/lib/CodeGen/LexicalScopes.cpp index f01dec28e5..8a7151dcf1 100644 --- a/lib/CodeGen/LexicalScopes.cpp +++ b/lib/CodeGen/LexicalScopes.cpp @@ -33,7 +33,6 @@ LexicalScopes::~LexicalScopes() { reset(); } void LexicalScopes::reset() { MF = nullptr; CurrentFnLexicalScope = nullptr; - DeleteContainerSeconds(LexicalScopeMap); DeleteContainerSeconds(AbstractScopeMap); InlinedLexicalScopeMap.clear(); AbstractScopesList.clear(); @@ -124,7 +123,8 @@ LexicalScope *LexicalScopes::findLexicalScope(DebugLoc DL) { if (IA) return InlinedLexicalScopeMap.lookup(DebugLoc::getFromDILocation(IA)); - return LexicalScopeMap.lookup(Scope); + auto I = LexicalScopeMap.find(Scope); + return I != LexicalScopeMap.end() ? I->second.get() : nullptr; } /// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If @@ -152,35 +152,35 @@ LexicalScope *LexicalScopes::getOrCreateRegularScope(MDNode *Scope) { D = DIDescriptor(Scope); } - LexicalScope *WScope = LexicalScopeMap.lookup(Scope); - if (WScope) - return WScope; + auto IterBool = LexicalScopeMap.insert(std::make_pair(Scope, std::unique_ptr())); + auto &MapValue = *IterBool.first; + if (!IterBool.second) + return MapValue.second.get(); LexicalScope *Parent = nullptr; if (D.isLexicalBlock()) Parent = getOrCreateLexicalScope(DebugLoc::getFromDILexicalBlock(Scope)); - WScope = new LexicalScope(Parent, DIDescriptor(Scope), nullptr, false); - LexicalScopeMap.insert(std::make_pair(Scope, WScope)); + MapValue.second = make_unique(Parent, DIDescriptor(Scope), nullptr, false); if (!Parent && DIDescriptor(Scope).isSubprogram() && DISubprogram(Scope).describes(MF->getFunction())) - CurrentFnLexicalScope = WScope; + CurrentFnLexicalScope = MapValue.second.get(); - return WScope; + return MapValue.second.get(); } /// getOrCreateInlinedScope - Find or create an inlined lexical scope. LexicalScope *LexicalScopes::getOrCreateInlinedScope(MDNode *Scope, MDNode *InlinedAt) { - LexicalScope *InlinedScope = LexicalScopeMap.lookup(InlinedAt); - if (InlinedScope) - return InlinedScope; + auto IterBool = LexicalScopeMap.insert(std::make_pair(InlinedAt, std::unique_ptr())); + auto &MapValue = *IterBool.first; + if (!IterBool.second) + return MapValue.second.get(); DebugLoc InlinedLoc = DebugLoc::getFromDILocation(InlinedAt); - InlinedScope = new LexicalScope(getOrCreateLexicalScope(InlinedLoc), + MapValue.second = make_unique(getOrCreateLexicalScope(InlinedLoc), DIDescriptor(Scope), InlinedAt, false); - InlinedLexicalScopeMap[InlinedLoc] = InlinedScope; - LexicalScopeMap[InlinedAt] = InlinedScope; - return InlinedScope; + InlinedLexicalScopeMap[InlinedLoc] = MapValue.second.get(); + return MapValue.second.get(); } /// getOrCreateAbstractScope - Find or create an abstract lexical scope. -- cgit v1.2.3