Delete PHI nodes that are not dead but are locked in a cycle of single
[oota-llvm.git] / lib / Debugger / ProgramInfo.cpp
index a3e55a3aef162c5115795a78f8006e8c1964f028..17175c4e4cf1beafc5de4076d365dcb7992695d8 100644 (file)
 #include "llvm/Constants.h"
 #include "llvm/DerivedTypes.h"
 #include "llvm/Intrinsics.h"
-#include "llvm/iOther.h"
+#include "llvm/Instructions.h"
 #include "llvm/Module.h"
 #include "llvm/Debugger/SourceFile.h"
 #include "llvm/Debugger/SourceLanguage.h"
-#include "Support/FileUtilities.h"
-#include "Support/SlowOperationInformer.h"
-#include "Support/STLExtras.h"
+#include "llvm/Support/SlowOperationInformer.h"
+#include "llvm/ADT/STLExtras.h"
 #include <iostream>
 
 using namespace llvm;
@@ -61,8 +60,8 @@ static std::string getStringValue(Value *V, unsigned Offset = 0) {
       }
     }
   } else if (Constant *C = dyn_cast<Constant>(V)) {
-    if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C))
-      return getStringValue(CPR->getValue(), Offset);
+    if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
+      return getStringValue(GV, Offset);
     else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
       if (CE->getOpcode() == Instruction::GetElementPtr) {
         // Turn a gep into the specified offset.
@@ -108,8 +107,6 @@ static const GlobalVariable *getNextStopPoint(const Value *V, unsigned &LineNo,
           if (const ConstantInt *C = dyn_cast<ConstantInt>(CI->getOperand(3)))
             CurColNo = C->getRawValue();
           const Value *Op = CI->getOperand(4);
-          if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Op))
-            Op = CPR->getValue();
           
           if ((CurDesc = dyn_cast<GlobalVariable>(Op)) &&
               (LineNo < LastLineNo ||
@@ -172,11 +169,16 @@ SourceFileInfo::~SourceFileInfo() {
 
 SourceFile &SourceFileInfo::getSourceText() const {
   // FIXME: this should take into account the source search directories!
-  if (SourceText == 0)  // Read the file in if we haven't already.
-    if (!Directory.empty() && FileOpenable(Directory+"/"+BaseName))
-      SourceText = new SourceFile(Directory+"/"+BaseName, Descriptor);
+  if (SourceText == 0) { // Read the file in if we haven't already.
+    sys::Path tmpPath;
+    if (!Directory.empty())
+      tmpPath.setDirectory(Directory);
+    tmpPath.appendFile(BaseName);
+    if (tmpPath.readable())
+      SourceText = new SourceFile(tmpPath.toString(), Descriptor);
     else
       SourceText = new SourceFile(BaseName, Descriptor);
+  }
   return *SourceText;
 }
 
@@ -192,11 +194,9 @@ SourceFunctionInfo::SourceFunctionInfo(ProgramInfo &PI,
     if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
       if (CS->getNumOperands() > 2) {
         // Entry #1 is the file descriptor.
-        if (const ConstantPointerRef *CPR =
-            dyn_cast<ConstantPointerRef>(CS->getOperand(1)))
-          if (const GlobalVariable *GV =
-              dyn_cast<GlobalVariable>(CPR->getValue()))
-            SourceFile = &PI.getSourceFile(GV);
+        if (const GlobalVariable *GV = 
+            dyn_cast<GlobalVariable>(CS->getOperand(1)))
+          SourceFile = &PI.getSourceFile(GV);
 
         // Entry #2 is the function name.
         Name = getStringValue(CS->getOperand(2));
@@ -235,9 +235,10 @@ void SourceFunctionInfo::getSourceLocation(unsigned &RetLineNo,
 // ProgramInfo implementation
 //
 
-ProgramInfo::ProgramInfo(Module *m) : M(m) {
+ProgramInfo::ProgramInfo(Module *m) : M(m), ProgramTimeStamp(0,0) {
   assert(M && "Cannot create program information with a null module!");
-  ProgramTimeStamp = getFileTimestamp(M->getModuleIdentifier());
+  sys::Path modulePath(M->getModuleIdentifier());
+  ProgramTimeStamp = modulePath.getTimestamp();
 
   SourceFilesIsComplete = false;
   SourceFunctionsIsComplete = false;
@@ -366,9 +367,9 @@ ProgramInfo::getFunction(const GlobalVariable *Desc) {
   if (Desc && Desc->hasInitializer())
     if (ConstantStruct *CS = dyn_cast<ConstantStruct>(Desc->getInitializer()))
       if (CS->getNumOperands() > 0)
-        if (const ConstantPointerRef *CPR =
-            dyn_cast<ConstantPointerRef>(CS->getOperand(1)))
-          SourceFileDesc = dyn_cast<GlobalVariable>(CPR->getValue());
+        if (const GlobalVariable *GV =
+            dyn_cast<GlobalVariable>(CS->getOperand(1)))
+          SourceFileDesc = GV;
 
   const SourceLanguage &Lang = getSourceFile(SourceFileDesc).getLanguage();
   return *(Result = Lang.createSourceFunctionInfo(Desc, *this));