Index: include/llvm/CodeGen/LexicalScopes.h =================================================================== --- include/llvm/CodeGen/LexicalScopes.h +++ include/llvm/CodeGen/LexicalScopes.h @@ -45,14 +45,11 @@ class LexicalScope { public: - LexicalScope(LexicalScope *P, const DILocalScope *D, const DILocation *I, - bool A) - : Parent(P), Desc(D), InlinedAtLocation(I), AbstractScope(A), + LexicalScope(const DILocalScope *D, const DILocation *I, bool A) + : Parent(nullptr), Desc(D), InlinedAtLocation(I), AbstractScope(A), LastInsn(nullptr), FirstInsn(nullptr), DFSIn(0), DFSOut(0) { assert((!D || D->isResolved()) && "Expected resolved node"); assert((!I || I->isResolved()) && "Expected resolved node"); - if (Parent) - Parent->addChild(this); } // Accessors. @@ -67,6 +64,15 @@ /// addChild - Add a child scope. void addChild(LexicalScope *S) { Children.push_back(S); } + /// setParent - Make the scope a child of another. + void setParent(LexicalScope *P) { + assert(!Parent && "Cannot change parent"); + if (P) { + P->addChild(this); + Parent = P; + } + } + /// openInsnRange - This scope covers instruction range starting from MI. void openInsnRange(const MachineInstr *MI) { if (!FirstInsn) Index: lib/CodeGen/LexicalScopes.cpp =================================================================== --- lib/CodeGen/LexicalScopes.cpp +++ lib/CodeGen/LexicalScopes.cpp @@ -150,10 +150,14 @@ LexicalScope *Parent = nullptr; if (auto *Block = dyn_cast(Scope)) Parent = getOrCreateLexicalScope(Block->getScope()); - I = LexicalScopeMap.emplace(std::piecewise_construct, - std::forward_as_tuple(Scope), - std::forward_as_tuple(Parent, Scope, nullptr, - false)).first; + + I = LexicalScopeMap.find(Scope); + if (I == LexicalScopeMap.end()) { + I = LexicalScopeMap + .insert(std::make_pair(Scope, LexicalScope(Scope, nullptr, false))) + .first; + I->second.setParent(Parent); + } if (!Parent) { assert(cast(Scope)->describes(MF->getFunction())); @@ -181,11 +185,14 @@ else Parent = getOrCreateLexicalScope(InlinedAt); - I = InlinedLexicalScopeMap.emplace(std::piecewise_construct, - std::forward_as_tuple(P), - std::forward_as_tuple(Parent, Scope, - InlinedAt, false)) - .first; + I = InlinedLexicalScopeMap.find(P); + if (I == InlinedLexicalScopeMap.end()) { + I = InlinedLexicalScopeMap + .insert(std::make_pair(P, LexicalScope(Scope, InlinedAt, false))) + .first; + I->second.setParent(Parent); + } + return &I->second; } @@ -203,10 +210,14 @@ if (auto *Block = dyn_cast(Scope)) Parent = getOrCreateAbstractScope(Block->getScope()); - I = AbstractScopeMap.emplace(std::piecewise_construct, - std::forward_as_tuple(Scope), - std::forward_as_tuple(Parent, Scope, - nullptr, true)).first; + I = AbstractScopeMap.find(Scope); + if (I == AbstractScopeMap.end()) { + I = AbstractScopeMap + .insert(std::make_pair(Scope, LexicalScope(Scope, nullptr, true))) + .first; + I->second.setParent(Parent); + } + if (isa(Scope)) AbstractScopesList.push_back(&I->second); return &I->second; Index: lib/CodeGen/RegAllocPBQP.cpp =================================================================== --- lib/CodeGen/RegAllocPBQP.cpp +++ lib/CodeGen/RegAllocPBQP.cpp @@ -305,7 +305,7 @@ unsigned VReg = G.getNodeMetadata(NId).getVReg(); LiveInterval &LI = LIS.getInterval(VReg); assert(!LI.empty() && "PBQP graph contains node for empty interval"); - Inactive.push(std::make_tuple(&LI, 0, NId)); + Inactive.push(std::make_tuple(&LI, size_t(0), NId)); } while (!Inactive.empty()) {