bug 122:
- Replace ConstantPointerRef usage with GlobalValue usage
- Minimize redundant isa<GlobalValue> usage
- Correct isa<Constant> for GlobalValue subclass


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@14942 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/BasicAliasAnalysis.cpp b/lib/Analysis/BasicAliasAnalysis.cpp
index c533f6d..f95adb3 100644
--- a/lib/Analysis/BasicAliasAnalysis.cpp
+++ b/lib/Analysis/BasicAliasAnalysis.cpp
@@ -143,8 +143,8 @@
     if (CE->getOpcode() == Instruction::Cast ||
         CE->getOpcode() == Instruction::GetElementPtr)
       return getUnderlyingObject(CE->getOperand(0));
-  } else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V)) {
-    return CPR->getValue();
+  } else if (const GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
+    return GV;
   }
   return 0;
 }
@@ -166,7 +166,7 @@
   V = cast<User>(V)->getOperand(0);
 
   while (const User *G = isGEP(V)) {
-    if (!isa<Constant>(GEPOps[0]) ||
+    if (!isa<Constant>(GEPOps[0]) || isa<GlobalValue>(GEPOps[0]) ||
         !cast<Constant>(GEPOps[0])->isNullValue())
       break;  // Don't handle folding arbitrary pointer offsets yet...
     GEPOps.erase(GEPOps.begin());   // Drop the zero index
@@ -217,7 +217,7 @@
 //
 AliasAnalysis::ModRefResult
 BasicAliasAnalysis::getModRefInfo(CallSite CS, Value *P, unsigned Size) {
-  if (!isa<Constant>(P) && !isa<GlobalValue>(P))
+  if (!isa<Constant>(P))
     if (const AllocationInst *AI =
                   dyn_cast_or_null<AllocationInst>(getUnderlyingObject(P))) {
       // Okay, the pointer is to a stack allocated object.  If we can prove that
@@ -246,12 +246,6 @@
     if (CE->getOpcode() == Instruction::Cast)
       V2 = CE->getOperand(0);
 
-  // Strip off constant pointer refs if they exist
-  if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V1))
-    V1 = CPR->getValue();
-  if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V2))
-    V2 = CPR->getValue();
-
   // Are we checking for alias of the same value?
   if (V1 == V2) return MustAlias;
 
@@ -380,7 +374,7 @@
           // the arguments provided, except substitute 0's for any variable
           // indexes we find...
           for (unsigned i = 0; i != GEPOperands.size(); ++i)
-            if (!isa<Constant>(GEPOperands[i]) ||
+            if (!isa<Constant>(GEPOperands[i]) || isa<GlobalValue>(GEPOperands[i]) ||
                 isa<ConstantExpr>(GEPOperands[i]))
               GEPOperands[i] =Constant::getNullValue(GEPOperands[i]->getType());
           int64_t Offset = getTargetData().getIndexedOffset(BasePtr->getType(),
@@ -453,7 +447,7 @@
     
     bool AllAreZeros = true;
     for (unsigned i = UnequalOper; i != MaxOperands; ++i)
-      if (!isa<Constant>(GEP1Ops[i]) ||
+      if (!isa<Constant>(GEP1Ops[i]) || 
           !cast<Constant>(GEP1Ops[i])->isNullValue()) {
         AllAreZeros = false;
         break;
diff --git a/lib/Analysis/DataStructure/DataStructureStats.cpp b/lib/Analysis/DataStructure/DataStructureStats.cpp
index 4a3e385..18e97cb 100644
--- a/lib/Analysis/DataStructure/DataStructureStats.cpp
+++ b/lib/Analysis/DataStructure/DataStructureStats.cpp
@@ -102,7 +102,7 @@
 
 DSNode *DSGraphStats::getNodeForValue(Value *V) {
   const DSGraph *G = TDGraph;
-  if (isa<GlobalValue>(V) || isa<Constant>(V))
+  if (isa<Constant>(V))
     G = TDGraph->getGlobalsGraph();
 
   const DSGraph::ScalarMapTy &ScalarMap = G->getScalarMap();
diff --git a/lib/Analysis/DataStructure/Local.cpp b/lib/Analysis/DataStructure/Local.cpp
index 865c144..7836555 100644
--- a/lib/Analysis/DataStructure/Local.cpp
+++ b/lib/Analysis/DataStructure/Local.cpp
@@ -220,10 +220,13 @@
   // Otherwise we need to create a new node to point to.
   // Check first for constant expressions that must be traversed to
   // extract the actual value.
-  if (Constant *C = dyn_cast<Constant>(V))
-    if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C)) {
-      return NH = getValueDest(*CPR->getValue());
-    } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
+  DSNode* N;
+  if (GlobalValue* GV = dyn_cast<GlobalValue>(V)) {
+    // Create a new global node for this global variable...
+    N = createNode(GV->getType()->getElementType());
+    N->addGlobal(GV);
+  } else if (Constant *C = dyn_cast<Constant>(V)) {
+    if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
       if (CE->getOpcode() == Instruction::Cast)
         NH = getValueDest(*CE->getOperand(0));
       else if (CE->getOpcode() == Instruction::GetElementPtr) {
@@ -247,13 +250,7 @@
     } else {
       assert(0 && "Unknown constant type!");
     }
-
-  // Otherwise we need to create a new node to point to...
-  DSNode *N;
-  if (GlobalValue *GV = dyn_cast<GlobalValue>(V)) {
-    // Create a new global node for this global variable...
-    N = createNode(GV->getType()->getElementType());
-    N->addGlobal(GV);
+    N = createNode(); // just create a shadow node
   } else {
     // Otherwise just create a shadow node
     N = createNode();
@@ -491,8 +488,6 @@
 
 void GraphBuilder::visitCallSite(CallSite CS) {
   Value *Callee = CS.getCalledValue();
-  if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Callee))
-    Callee = CPR->getValue();
 
   // Special case handling of certain libc allocation functions here.
   if (Function *F = dyn_cast<Function>(Callee))
diff --git a/lib/Analysis/DataStructure/Printer.cpp b/lib/Analysis/DataStructure/Printer.cpp
index 87d6bbc..24bf768 100644
--- a/lib/Analysis/DataStructure/Printer.cpp
+++ b/lib/Analysis/DataStructure/Printer.cpp
@@ -138,7 +138,7 @@
     // Add scalar nodes to the graph...
     const DSGraph::ScalarMapTy &VM = G->getScalarMap();
     for (DSGraph::ScalarMapTy::const_iterator I = VM.begin(); I != VM.end();++I)
-      if (!isa<GlobalValue>(I->first) && !isa<ConstantPointerRef>(I->first)) {
+      if (!isa<GlobalValue>(I->first)) {
         std::stringstream OS;
         WriteAsOperand(OS, I->first, false, true, CurMod);
         GW.emitSimpleNode(I->first, "", OS.str());
diff --git a/lib/Analysis/IPA/Andersens.cpp b/lib/Analysis/IPA/Andersens.cpp
index 6b24a12..12f0fc3 100644
--- a/lib/Analysis/IPA/Andersens.cpp
+++ b/lib/Analysis/IPA/Andersens.cpp
@@ -479,8 +479,8 @@
 
   if (isa<ConstantPointerNull>(C))
     return &GraphNodes[NullPtr];
-  else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C))
-    return getNode(CPR->getValue());
+  else if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
+    return getNode(GV);
   else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
     switch (CE->getOpcode()) {
     case Instruction::GetElementPtr:
@@ -507,8 +507,8 @@
 
   if (isa<ConstantPointerNull>(C))
     return &GraphNodes[NullObject];
-  else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(C))
-    return getObject(CPR->getValue());
+  else if (GlobalValue *GV = dyn_cast<GlobalValue>(C))
+    return getObject(GV);
   else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(C)) {
     switch (CE->getOpcode()) {
     case Instruction::GetElementPtr:
diff --git a/lib/Analysis/IPA/CallGraph.cpp b/lib/Analysis/IPA/CallGraph.cpp
index 70bf2c4..72b4bdb 100644
--- a/lib/Analysis/IPA/CallGraph.cpp
+++ b/lib/Analysis/IPA/CallGraph.cpp
@@ -73,10 +73,8 @@
         getNodeFor(Inst->getParent()->getParent())->addCalledFunction(Node);
       else
         isUsedExternally = true;
-    } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(*I)) {
-      // THIS IS A DISGUSTING HACK.  Brought to you by the power of
-      // ConstantPointerRefs!
-      for (Value::use_iterator I = CPR->use_begin(), E = CPR->use_end();
+    } else if (GlobalValue *GV = dyn_cast<GlobalValue>(*I)) {
+      for (Value::use_iterator I = GV->use_begin(), E = GV->use_end();
            I != E; ++I)
         if (Instruction *Inst = dyn_cast<Instruction>(*I)) {
           if (isOnlyADirectCall(F, CallSite::get(Inst)))
diff --git a/lib/Analysis/IPA/FindUsedTypes.cpp b/lib/Analysis/IPA/FindUsedTypes.cpp
index a852777..1f127fe 100644
--- a/lib/Analysis/IPA/FindUsedTypes.cpp
+++ b/lib/Analysis/IPA/FindUsedTypes.cpp
@@ -48,9 +48,10 @@
   
   // If this is a constant, it could be using other types...
   if (const Constant *C = dyn_cast<Constant>(V)) {
-    for (User::const_op_iterator OI = C->op_begin(), OE = C->op_end();
-         OI != OE; ++OI)
-      IncorporateValue(*OI);
+    if (!isa<GlobalValue>(C))
+      for (User::const_op_iterator OI = C->op_begin(), OE = C->op_end();
+	   OI != OE; ++OI)
+	IncorporateValue(*OI);
   }
 }
 
diff --git a/lib/Analysis/IPA/GlobalsModRef.cpp b/lib/Analysis/IPA/GlobalsModRef.cpp
index c3f6ba9..cb1d360 100644
--- a/lib/Analysis/IPA/GlobalsModRef.cpp
+++ b/lib/Analysis/IPA/GlobalsModRef.cpp
@@ -165,8 +165,8 @@
       } else {
         return true;
       }        
-    } else if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(*UI)) {
-      if (AnalyzeUsesOfGlobal(CPR, Readers, Writers)) return true;
+    } else if (GlobalValue *GV = dyn_cast<GlobalValue>(*UI)) {
+      if (AnalyzeUsesOfGlobal(GV, Readers, Writers)) return true;
     } else {
       return true;
     }
@@ -257,8 +257,6 @@
     if (CE->getOpcode() == Instruction::Cast ||
         CE->getOpcode() == Instruction::GetElementPtr)
       return getUnderlyingObject(CE->getOperand(0));
-  } else if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(V)) {
-    return CPR->getValue();
   }
   return 0;
 }
diff --git a/lib/Analysis/ScalarEvolution.cpp b/lib/Analysis/ScalarEvolution.cpp
index 257fc0d..cac3b50 100644
--- a/lib/Analysis/ScalarEvolution.cpp
+++ b/lib/Analysis/ScalarEvolution.cpp
@@ -1498,9 +1498,9 @@
   case Instruction::Select:
     return ConstantExpr::getSelect(Operands[0], Operands[1], Operands[2]);
   case Instruction::Call:
-    if (ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(Operands[0])) {
+    if (Function *GV = dyn_cast<Function>(Operands[0])) {
       Operands.erase(Operands.begin());
-      return ConstantFoldCall(cast<Function>(CPR->getValue()), Operands);
+      return ConstantFoldCall(cast<Function>(GV), Operands);
     }
 
     return 0;
@@ -1560,9 +1560,9 @@
 /// reason, return null.
 static Constant *EvaluateExpression(Value *V, Constant *PHIVal) {
   if (isa<PHINode>(V)) return PHIVal;
-  if (Constant *C = dyn_cast<Constant>(V)) return C;
   if (GlobalValue *GV = dyn_cast<GlobalValue>(V))
-    return ConstantPointerRef::get(GV);
+    return GV;
+  if (Constant *C = dyn_cast<Constant>(V)) return C;
   Instruction *I = cast<Instruction>(V);
 
   std::vector<Constant*> Operands;
@@ -1718,8 +1718,6 @@
           Value *Op = I->getOperand(i);
           if (Constant *C = dyn_cast<Constant>(Op)) {
             Operands.push_back(C);
-          } else if (GlobalValue *GV = dyn_cast<GlobalValue>(Op)) {
-            Operands.push_back(ConstantPointerRef::get(GV));
           } else {
             SCEVHandle OpV = getSCEVAtScope(getSCEV(Op), L);
             if (SCEVConstant *SC = dyn_cast<SCEVConstant>(OpV))