X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=lib%2FCodeGen%2FLexicalScopes.cpp;h=f7ba12539ec52e77c77880215c3399135eef12e1;hb=71857ccdb83b6374f7a791c2dae45ce9934a85af;hp=ae06a40703772b4ccbceedca8201b91db2b0bf48;hpb=2e85b1bfa7412577dd61f21ea10a686d3685144b;p=oota-llvm.git diff --git a/lib/CodeGen/LexicalScopes.cpp b/lib/CodeGen/LexicalScopes.cpp index ae06a407037..f7ba12539ec 100644 --- a/lib/CodeGen/LexicalScopes.cpp +++ b/lib/CodeGen/LexicalScopes.cpp @@ -16,10 +16,10 @@ #define DEBUG_TYPE "lexicalscopes" #include "llvm/CodeGen/LexicalScopes.h" -#include "llvm/Function.h" -#include "llvm/Analysis/DebugInfo.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineInstr.h" +#include "llvm/DebugInfo.h" +#include "llvm/IR/Function.h" #include "llvm/Support/Debug.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/FormattedStream.h" @@ -118,9 +118,16 @@ LexicalScope *LexicalScopes::findLexicalScope(DebugLoc DL) { MDNode *IA = NULL; DL.getScopeAndInlinedAt(Scope, IA, MF->getFunction()->getContext()); if (!Scope) return NULL; + + // The scope that we were created with could have an extra file - which + // isn't what we care about in this case. + DIDescriptor D = DIDescriptor(Scope); + if (D.isLexicalBlockFile()) + Scope = DILexicalBlockFile(Scope).getScope(); + if (IA) return InlinedLexicalScopeMap.lookup(DebugLoc::getFromDILocation(IA)); - return LexicalScopeMap.lookup(DL.getScope(Scope->getContext())); + return LexicalScopeMap.lookup(Scope); } /// getOrCreateLexicalScope - Find lexical scope for the given DebugLoc. If @@ -129,6 +136,7 @@ LexicalScope *LexicalScopes::getOrCreateLexicalScope(DebugLoc DL) { MDNode *Scope = NULL; MDNode *InlinedAt = NULL; DL.getScopeAndInlinedAt(Scope, InlinedAt, MF->getFunction()->getContext()); + if (InlinedAt) { // Create an abstract scope for inlined function. getOrCreateAbstractScope(Scope); @@ -141,12 +149,18 @@ LexicalScope *LexicalScopes::getOrCreateLexicalScope(DebugLoc DL) { /// getOrCreateRegularScope - Find or create a regular lexical scope. LexicalScope *LexicalScopes::getOrCreateRegularScope(MDNode *Scope) { + DIDescriptor D = DIDescriptor(Scope); + if (D.isLexicalBlockFile()) { + Scope = DILexicalBlockFile(Scope).getScope(); + D = DIDescriptor(Scope); + } + LexicalScope *WScope = LexicalScopeMap.lookup(Scope); if (WScope) return WScope; LexicalScope *Parent = NULL; - if (DIDescriptor(Scope).isLexicalBlock()) + if (D.isLexicalBlock()) Parent = getOrCreateLexicalScope(DebugLoc::getFromDILexicalBlock(Scope)); WScope = new LexicalScope(Parent, DIDescriptor(Scope), NULL, false); LexicalScopeMap.insert(std::make_pair(Scope, WScope)); @@ -176,12 +190,14 @@ LexicalScope *LexicalScopes::getOrCreateInlinedScope(MDNode *Scope, LexicalScope *LexicalScopes::getOrCreateAbstractScope(const MDNode *N) { assert(N && "Invalid Scope encoding!"); + DIDescriptor Scope(N); + if (Scope.isLexicalBlockFile()) + Scope = DILexicalBlockFile(Scope).getScope(); LexicalScope *AScope = AbstractScopeMap.lookup(N); if (AScope) return AScope; LexicalScope *Parent = NULL; - DIDescriptor Scope(N); if (Scope.isLexicalBlock()) { DILexicalBlock DB(N); DIDescriptor ParentDesc = DB.getContext(); @@ -202,9 +218,9 @@ void LexicalScopes::constructScopeNest(LexicalScope *Scope) { unsigned Counter = 0; while (!WorkStack.empty()) { LexicalScope *WS = WorkStack.back(); - const SmallVector &Children = WS->getChildren(); + const SmallVectorImpl &Children = WS->getChildren(); bool visitedChildren = false; - for (SmallVector::const_iterator SI = Children.begin(), + for (SmallVectorImpl::const_iterator SI = Children.begin(), SE = Children.end(); SI != SE; ++SI) { LexicalScope *ChildScope = *SI; if (!ChildScope->getDFSOut()) { @@ -263,8 +279,8 @@ getMachineBasicBlocks(DebugLoc DL, return; } - SmallVector &InsnRanges = Scope->getRanges(); - for (SmallVector::iterator I = InsnRanges.begin(), + SmallVectorImpl &InsnRanges = Scope->getRanges(); + for (SmallVectorImpl::iterator I = InsnRanges.begin(), E = InsnRanges.end(); I != E; ++I) { InsnRange &R = *I; MBBs.insert(R.first->getParent()); @@ -295,25 +311,25 @@ bool LexicalScopes::dominates(DebugLoc DL, MachineBasicBlock *MBB) { return Result; } +void LexicalScope::anchor() { } + /// dump - Print data structures. -void LexicalScope::dump() const { +void LexicalScope::dump(unsigned Indent) const { #ifndef NDEBUG raw_ostream &err = dbgs(); - err.indent(IndentLevel); + err.indent(Indent); err << "DFSIn: " << DFSIn << " DFSOut: " << DFSOut << "\n"; const MDNode *N = Desc; + err.indent(Indent); N->dump(); if (AbstractScope) - err << "Abstract Scope\n"; + err << std::string(Indent, ' ') << "Abstract Scope\n"; - IndentLevel += 2; if (!Children.empty()) - err << "Children ...\n"; + err << std::string(Indent + 2, ' ') << "Children ...\n"; for (unsigned i = 0, e = Children.size(); i != e; ++i) if (Children[i] != this) - Children[i]->dump(); - - IndentLevel -= 2; + Children[i]->dump(Indent + 2); #endif }