bug 122:
- Replace ConstantPointerRef usage with GlobalValue usage


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14953 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Target/CBackend/CBackend.cpp b/lib/Target/CBackend/CBackend.cpp
index 139320f..c1cd657 100644
--- a/lib/Target/CBackend/CBackend.cpp
+++ b/lib/Target/CBackend/CBackend.cpp
@@ -620,8 +620,8 @@
       printType(Out, CPV->getType());
       Out << ")/*NULL*/0)";
       break;
-    } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CPV)) {
-      writeOperand(CPR->getValue());
+    } else if (GlobalValue *GV = dyn_cast<GlobalValue>(CPV)) {
+      writeOperand(GV);
       break;
     }
     // FALL THROUGH
@@ -641,7 +641,8 @@
       return;
     }
   
-  if (Constant *CPV = dyn_cast<Constant>(Operand)) {
+  Constant* CPV = dyn_cast<Constant>(Operand);
+  if (CPV && !isa<GlobalValue>(CPV)) {
     printConstant(CPV); 
   } else {
     Out << Mang->getValueName(Operand);
@@ -1412,9 +1413,6 @@
   // If accessing a global value with no indexing, avoid *(&GV) syndrome
   if (GlobalValue *V = dyn_cast<GlobalValue>(Ptr)) {
     HasImplicitAddress = true;
-  } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Ptr)) {
-    HasImplicitAddress = true;
-    Ptr = CPR->getValue();         // Get to the global...
   } else if (isDirectAlloca(Ptr)) {
     HasImplicitAddress = true;
   }
diff --git a/lib/Target/CBackend/Writer.cpp b/lib/Target/CBackend/Writer.cpp
index 139320f..c1cd657 100644
--- a/lib/Target/CBackend/Writer.cpp
+++ b/lib/Target/CBackend/Writer.cpp
@@ -620,8 +620,8 @@
       printType(Out, CPV->getType());
       Out << ")/*NULL*/0)";
       break;
-    } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CPV)) {
-      writeOperand(CPR->getValue());
+    } else if (GlobalValue *GV = dyn_cast<GlobalValue>(CPV)) {
+      writeOperand(GV);
       break;
     }
     // FALL THROUGH
@@ -641,7 +641,8 @@
       return;
     }
   
-  if (Constant *CPV = dyn_cast<Constant>(Operand)) {
+  Constant* CPV = dyn_cast<Constant>(Operand);
+  if (CPV && !isa<GlobalValue>(CPV)) {
     printConstant(CPV); 
   } else {
     Out << Mang->getValueName(Operand);
@@ -1412,9 +1413,6 @@
   // If accessing a global value with no indexing, avoid *(&GV) syndrome
   if (GlobalValue *V = dyn_cast<GlobalValue>(Ptr)) {
     HasImplicitAddress = true;
-  } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Ptr)) {
-    HasImplicitAddress = true;
-    Ptr = CPR->getValue();         // Get to the global...
   } else if (isDirectAlloca(Ptr)) {
     HasImplicitAddress = true;
   }
diff --git a/lib/Target/SparcV9/InternalGlobalMapper.cpp b/lib/Target/SparcV9/InternalGlobalMapper.cpp
index 7d4a40a..0cd2faa 100644
--- a/lib/Target/SparcV9/InternalGlobalMapper.cpp
+++ b/lib/Target/SparcV9/InternalGlobalMapper.cpp
@@ -42,7 +42,7 @@
   // add a null.
   if (GV.hasInternalLinkage () && GV.hasName ())
     Vector.push_back (ConstantExpr::getCast
-      (ConstantPointerRef::get (&GV), PointerType::get (Type::SByteTy)));
+      (&GV, PointerType::get (Type::SByteTy)));
   else
     Vector.push_back (ConstantPointerNull::get (PointerType::get
                                                 (Type::SByteTy)));
diff --git a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
index a153871..6aebcb5 100644
--- a/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
+++ b/lib/Target/SparcV9/RegAlloc/PhyRegAlloc.cpp
@@ -1289,7 +1289,7 @@
 
       // Have: { uint, [Size x { uint, int, uint, int }] } *
       // Cast it to: { uint, [0 x { uint, int, uint, int }] } *
-      Constant *CE = ConstantExpr::getCast (ConstantPointerRef::get (GV), PT);
+      Constant *CE = ConstantExpr::getCast (GV, PT);
       allstate.push_back (CE);
     }
   }
diff --git a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp
index aa18345..addcbdc 100644
--- a/lib/Target/SparcV9/SparcV9AsmPrinter.cpp
+++ b/lib/Target/SparcV9/SparcV9AsmPrinter.cpp
@@ -317,11 +317,8 @@
   
   toAsm << "\t" << TypeToDataDirective(CV->getType()) << "\t";
   
-  if (const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(CV)) {
-    // This is a constant address for a global variable or method.
-    // Use the name of the variable or method as the address value.
-    assert(isa<GlobalValue>(CPR->getValue()) && "Unexpected non-global");
-    toAsm << getID(CPR->getValue()) << "\n";
+  if (const GlobalValue* GV = dyn_cast<GlobalValue>(CV)) {
+    toAsm << getID(GV) << "\n";
   } else if (isa<ConstantPointerNull>(CV)) {
     // Null pointer value
     toAsm << "0\n";
@@ -480,7 +477,9 @@
                                         const TargetMachine& target) {
   std::string S;
   bool failed = false;
-  if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
+  if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
+    S += getID(GV);
+  } else if (const Constant* CV = dyn_cast<Constant>(V)) { // symbolic or known
     if (const ConstantBool *CB = dyn_cast<ConstantBool>(CV))
       S += std::string(CB == ConstantBool::True ? "1" : "0");
     else if (const ConstantSInt *CI = dyn_cast<ConstantSInt>(CV))
@@ -491,14 +490,10 @@
       S += ftostr(CFP->getValue());
     else if (isa<ConstantPointerNull>(CV))
       S += "0";
-    else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(CV))
-      S += valToExprString(CPR->getValue(), target);
     else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV))
       S += ConstantExprToString(CE, target);
     else
       failed = true;
-  } else if (const GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
-    S += getID(GV);
   } else
     failed = true;