Avoid duplicating loop header which leads to unnatural loops (and just seem like...
[oota-llvm.git] / lib / Debugger / ProgramInfo.cpp
index ebca794320f4f5b30edb5a8bc2d4eb946c011b3b..e4380ea42783e609bdd24c81ed8db4bd64dbdfb6 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                     The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Intrinsics.h"
+#include "llvm/IntrinsicInst.h"
 #include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/Debugger/SourceFile.h"
 #include "llvm/Debugger/SourceLanguage.h"
 #include "llvm/Support/SlowOperationInformer.h"
 #include "llvm/ADT/STLExtras.h"
-#include <iostream>
-
 using namespace llvm;
 
 /// getGlobalVariablesUsing - Return all of the global variables which have the
@@ -57,17 +56,15 @@ static const GlobalVariable *getNextStopPoint(const Value *V, unsigned &LineNo,
       // Infinite loops == bad, ignore PHI nodes.
       ShouldRecurse = false;
     } else if (const CallInst *CI = dyn_cast<CallInst>(*UI)) {
+      
       // If we found a stop point, check to see if it is earlier than what we
       // already have.  If so, remember it.
-      if (const Function *F = CI->getCalledFunction())
-        if (F->getIntrinsicID() == Intrinsic::dbg_stoppoint) {
-          unsigned CurLineNo = ~0, CurColNo = ~0;
+      if (CI->getCalledFunction())
+        if (const DbgStopPointInst *SPI = dyn_cast<DbgStopPointInst>(CI)) {
+          unsigned CurLineNo = SPI->getLine();
+          unsigned CurColNo = SPI->getColumn();
           const GlobalVariable *CurDesc = 0;
-          if (const ConstantInt *C = dyn_cast<ConstantInt>(CI->getOperand(2)))
-            CurLineNo = C->getRawValue();
-          if (const ConstantInt *C = dyn_cast<ConstantInt>(CI->getOperand(3)))
-            CurColNo = C->getRawValue();
-          const Value *Op = CI->getOperand(4);
+          const Value *Op = SPI->getContext();
 
           if ((CurDesc = dyn_cast<GlobalVariable>(Op)) &&
               (LineNo < LastLineNo ||
@@ -78,7 +75,6 @@ static const GlobalVariable *getNextStopPoint(const Value *V, unsigned &LineNo,
           }
           ShouldRecurse = false;
         }
-
     }
 
     // If this is not a phi node or a stopping point, recursively scan the users
@@ -116,8 +112,8 @@ SourceFileInfo::SourceFileInfo(const GlobalVariable *Desc,
   if (Desc && Desc->hasInitializer())
     if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
       if (CS->getNumOperands() > 4) {
-        if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(CS->getOperand(1)))
-          Version = CUI->getValue();
+        if (ConstantInt *CUI = dyn_cast<ConstantInt>(CS->getOperand(1)))
+          Version = CUI->getZExtValue();
 
         BaseName  = CS->getOperand(3)->getStringValue();
         Directory = CS->getOperand(4)->getStringValue();
@@ -183,8 +179,8 @@ void SourceFunctionInfo::getSourceLocation(unsigned &RetLineNo,
             if (SD) {             // We found the first stop point!
               // This is just a sanity check.
               if (getSourceFile().getDescriptor() != SD)
-                std::cout << "WARNING: first line of function is not in the"
-                  " file that the function descriptor claims it is in.\n";
+                cout << "WARNING: first line of function is not in the"
+                     << " file that the function descriptor claims it is in.\n";
               break;
             }
           }
@@ -198,8 +194,10 @@ void SourceFunctionInfo::getSourceLocation(unsigned &RetLineNo,
 
 ProgramInfo::ProgramInfo(Module *m) : M(m), ProgramTimeStamp(0,0) {
   assert(M && "Cannot create program information with a null module!");
-  sys::Path modulePath(M->getModuleIdentifier());
-  ProgramTimeStamp = modulePath.getTimestamp();
+  sys::PathWithStatus ModPath(M->getModuleIdentifier());
+  const sys::FileStatus *Stat = ModPath.getFileStatus();
+  if (Stat)
+    ProgramTimeStamp = Stat->getTimestamp();
 
   SourceFilesIsComplete = false;
   SourceFunctionsIsComplete = false;
@@ -238,8 +236,8 @@ ProgramInfo::getSourceFile(const GlobalVariable *Desc) {
   if (Desc && Desc->hasInitializer())
     if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
       if (CS->getNumOperands() > 2)
-        if (ConstantUInt *CUI = dyn_cast<ConstantUInt>(CS->getOperand(2)))
-          LangID = CUI->getValue();
+        if (ConstantInt *CUI = dyn_cast<ConstantInt>(CS->getOperand(2)))
+          LangID = CUI->getZExtValue();
 
   const SourceLanguage &Lang = SourceLanguage::get(LangID);
   SourceFileInfo *New = Lang.createSourceFileInfo(Desc, *this);
@@ -282,7 +280,8 @@ ProgramInfo::getSourceFiles(bool RequiresCompleteMap) {
   // mapping.
   for (unsigned i = 0, e = TranslationUnits.size(); i != e; ++i) {
     getSourceFile(TranslationUnits[i]);
-    SOI.progress(i+1, e);
+    if (SOI.progress(i+1, e))
+      throw "While building source files index, operation cancelled.";
   }
 
   // Ok, if we got this far, then we indexed the whole program.
@@ -363,7 +362,8 @@ ProgramInfo::getSourceFunctions(bool RequiresCompleteMap) {
   // Loop over all of the functions found, building the SourceFunctions mapping.
   for (unsigned i = 0, e = Functions.size(); i != e; ++i) {
     getFunction(Functions[i]);
-    SOI.progress(i+1, e);
+    if (SOI.progress(i+1, e))
+      throw "While functions index, operation cancelled.";
   }
 
   // Ok, if we got this far, then we indexed the whole program.