This patch corrects logic in PPCFrameLowering for save and restore of
[oota-llvm.git] / lib / CodeGen / LexicalScopes.cpp
index 2276004af224b51fbe22beff403696d993faf486..6b6b9d084e1f9d93d8898aecfa78caa976a34ab9 100644 (file)
@@ -16,8 +16,8 @@
 
 #define DEBUG_TYPE "lexicalscopes"
 #include "llvm/CodeGen/LexicalScopes.h"
+#include "llvm/DebugInfo.h"
 #include "llvm/Function.h"
-#include "llvm/Analysis/DebugInfo.h"
 #include "llvm/CodeGen/MachineFunction.h"
 #include "llvm/CodeGen/MachineInstr.h"
 #include "llvm/Support/Debug.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();
@@ -221,11 +237,12 @@ void LexicalScopes::constructScopeNest(LexicalScope *Scope) {
   }
 }
 
-/// assignInstructionRanges - Find ranges of instructions covered by each lexical 
-/// scope.
+/// assignInstructionRanges - Find ranges of instructions covered by each
+/// lexical scope.
 void LexicalScopes::
 assignInstructionRanges(SmallVectorImpl<InsnRange> &MIRanges,
-                    DenseMap<const MachineInstr *, LexicalScope *> &MI2ScopeMap) {
+                    DenseMap<const MachineInstr *, LexicalScope *> &MI2ScopeMap)
+{
   
   LexicalScope *PrevLexicalScope = NULL;
   for (SmallVectorImpl<InsnRange>::const_iterator RI = MIRanges.begin(),
@@ -248,12 +265,20 @@ assignInstructionRanges(SmallVectorImpl<InsnRange> &MIRanges,
 /// have machine instructions that belong to lexical scope identified by 
 /// DebugLoc.
 void LexicalScopes::
-getMachineBasicBlocks(DebugLoc DL, SmallPtrSet<const MachineBasicBlock*, 4> &MBBs) {
+getMachineBasicBlocks(DebugLoc DL, 
+                      SmallPtrSet<const MachineBasicBlock*, 4> &MBBs) {
   MBBs.clear();
   LexicalScope *Scope = getOrCreateLexicalScope(DL);
   if (!Scope)
     return;
   
+  if (Scope == CurrentFnLexicalScope) {
+    for (MachineFunction::const_iterator I = MF->begin(), E = MF->end();
+         I != E; ++I)
+      MBBs.insert(I);
+    return;
+  }
+
   SmallVector<InsnRange, 4> &InsnRanges = Scope->getRanges();
   for (SmallVector<InsnRange, 4>::iterator I = InsnRanges.begin(),
          E = InsnRanges.end(); I != E; ++I) {
@@ -268,6 +293,11 @@ bool LexicalScopes::dominates(DebugLoc DL, MachineBasicBlock *MBB) {
   LexicalScope *Scope = getOrCreateLexicalScope(DL);
   if (!Scope)
     return false;
+
+  // Current function scope covers all basic blocks in the function.
+  if (Scope == CurrentFnLexicalScope && MBB->getParent() == MF)
+    return true;
+
   bool Result = false;
   for (MachineBasicBlock::iterator I = MBB->begin(), E = MBB->end();
        I != E; ++I) {
@@ -281,6 +311,8 @@ bool LexicalScopes::dominates(DebugLoc DL, MachineBasicBlock *MBB) {
   return Result;
 }
 
+void LexicalScope::anchor() { }
+
 /// dump - Print data structures.
 void LexicalScope::dump() const {
 #ifndef NDEBUG