Delete PHI nodes that are not dead but are locked in a cycle of single
[oota-llvm.git] / lib / Debugger / ProgramInfo.cpp
index 46584a942c9c8e5ad4de2815ebd1641e1d75471a..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;
 
 /// getGlobalVariablesUsing - Return all of the global variables which have the
@@ -44,8 +45,7 @@ static std::string getStringValue(Value *V, unsigned Offset = 0) {
   if (GlobalVariable *GV = dyn_cast<GlobalVariable>(V)) {
     if (GV->hasInitializer() && isa<ConstantArray>(GV->getInitializer())) {
       ConstantArray *Init = cast<ConstantArray>(GV->getInitializer());
-      if (Init->getType()->getElementType() == Type::SByteTy ||
-          Init->getType()->getElementType() == Type::UByteTy) {
+      if (Init->isString()) {
         std::string Result = Init->getAsString();
         if (Offset < Result.size()) {
           // If we are pointing INTO The string, erase the beginning...
@@ -60,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.
@@ -107,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 ||
@@ -171,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;
 }
 
@@ -191,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));
@@ -234,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;
@@ -365,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));