[llvm-commits] CVS: llvm/lib/VMCore/AsmWriter.cpp

LLVM llvm at cs.uiuc.edu
Sat Jul 17 16:45:33 PDT 2004



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.147 -> 1.148

---
Log message:

bug 122: http://llvm.cs.uiuc.edu/PR122 :
- Replace ConstantPointerRef usage with GlobalValue usage
- Minimize redundant isa<GlobalValue> usage
- Correct isa<Constant> for GlobalValue subclass


---
Diffs of the changes:  (+19 -23)

Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.147 llvm/lib/VMCore/AsmWriter.cpp:1.148
--- llvm/lib/VMCore/AsmWriter.cpp:1.147	Wed Jul 14 21:51:31 2004
+++ llvm/lib/VMCore/AsmWriter.cpp	Sat Jul 17 18:45:23 2004
@@ -381,6 +381,7 @@
   }
 }
 
+/// @brief Internal constant writer. 
 static void WriteConstantInt(std::ostream &Out, const Constant *CV, 
                              bool PrintName,
                              std::map<const Type *, std::string> &TypeTable,
@@ -493,9 +494,6 @@
   } else if (isa<ConstantPointerNull>(CV)) {
     Out << "null";
 
-  } else if (const ConstantPointerRef *PR = dyn_cast<ConstantPointerRef>(CV)) {
-    WriteAsOperandInternal(Out, PR->getValue(), true, TypeTable, Machine);
-
   } else if (const ConstantExpr *CE = dyn_cast<ConstantExpr>(CV)) {
     Out << CE->getOpcodeName() << " (";
     
@@ -527,12 +525,13 @@
                                   std::map<const Type*, std::string> &TypeTable,
                                    SlotMachine *Machine) {
   Out << ' ';
-  if (PrintName && V->hasName()) {
+  if ((PrintName || isa<GlobalValue>(V)) && V->hasName())
     Out << getLLVMName(V->getName());
-  } else {
-    if (const Constant *CV = dyn_cast<Constant>(V)) {
+  else {
+    const Constant *CV = dyn_cast<Constant>(V);
+    if (CV && !isa<GlobalValue>(CV))
       WriteConstantInt(Out, CV, PrintName, TypeTable, Machine);
-    } else {
+    else {
       int Slot;
       if (Machine) {
         Slot = Machine->getSlot(V);
@@ -764,8 +763,14 @@
   Out << (GV->isConstant() ? "constant " : "global ");
   printType(GV->getType()->getElementType());
 
-  if (GV->hasInitializer())
-    writeOperand(GV->getInitializer(), false, false);
+  if (GV->hasInitializer()) {
+    Constant* C = cast<Constant>(GV->getInitializer());
+    assert(C &&  "GlobalVar initializer isn't constant?");
+    if (isa<GlobalValue>(C))
+      writeOperand(GV->getInitializer(), false, true);
+    else
+      writeOperand(GV->getInitializer(), false, false);
+  }
 
   printInfoComment(*GV);
   Out << "\n";
@@ -794,8 +799,9 @@
     SymbolTable::value_const_iterator VE = ST.value_end(PI->first);
 
     for (; VI != VE; ++VI) {
-      const Value *V = VI->second;
-      if (const Constant *CPV = dyn_cast<Constant>(V)) {
+      const Value* V = VI->second;
+      const Constant *CPV = dyn_cast<Constant>(V) ;
+      if (CPV && !isa<GlobalValue>(V)) {
         printConstant(CPV);
       }
     }
@@ -1162,12 +1168,6 @@
 void Constant::print(std::ostream &o) const {
   if (this == 0) { o << "<null> constant value\n"; return; }
 
-  // Handle CPR's special, because they have context information...
-  if (const ConstantPointerRef *CPR = dyn_cast<ConstantPointerRef>(this)) {
-    CPR->getValue()->print(o);  // Print as a global value, with context info.
-    return;
-  }
-
   o << ' ' << getType()->getDescription() << ' ';
 
   std::map<const Type *, std::string> TypeTable;
@@ -1347,10 +1347,6 @@
   // Check for uninitialized state and do lazy initialization
   this->initialize();
 
-  // Do not number CPR's at all. They are an abomination
-  if ( const ConstantPointerRef* CPR = dyn_cast<ConstantPointerRef>(V) )
-    V = CPR->getValue() ;
-
   // Get the type of the value
   const Type* VTy = V->getType();
 
@@ -1593,8 +1589,8 @@
   SC_DEBUG("  Inserting value [" << VTy << "] = " << V << " slot=" << 
            DestSlot << " [");
   // G = Global, C = Constant, T = Type, F = Function, o = other
-  SC_DEBUG((isa<GlobalVariable>(V) ? 'G' : (isa<Constant>(V) ? 'C' : 
-           (isa<Function>(V) ? 'F' : 'o'))));
+  SC_DEBUG((isa<GlobalVariable>(V) ? 'G' : (isa<Function>(V) ? 'F' : 
+           (isa<Constant>(V) ? 'C' : 'o'))));
   SC_DEBUG("]\n");
   return DestSlot;
 }





More information about the llvm-commits mailing list