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

Anton Korobeynikov asl at math.spbu.ru
Sat Apr 28 06:45:51 PDT 2007



Changes in directory llvm/lib/VMCore:

AsmWriter.cpp updated: 1.276 -> 1.277
Globals.cpp updated: 1.20 -> 1.21
Module.cpp updated: 1.81 -> 1.82
Verifier.cpp updated: 1.206 -> 1.207
---
Log message:

Implement review feedback. Aliasees can be either GlobalValue's or 
bitcasts of them.


---
Diffs of the changes:  (+30 -12)

 AsmWriter.cpp |   14 ++++++++++----
 Globals.cpp   |   21 ++++++++++++++-------
 Module.cpp    |    3 +++
 Verifier.cpp  |    4 +++-
 4 files changed, 30 insertions(+), 12 deletions(-)


Index: llvm/lib/VMCore/AsmWriter.cpp
diff -u llvm/lib/VMCore/AsmWriter.cpp:1.276 llvm/lib/VMCore/AsmWriter.cpp:1.277
--- llvm/lib/VMCore/AsmWriter.cpp:1.276	Wed Apr 25 21:24:10 2007
+++ llvm/lib/VMCore/AsmWriter.cpp	Sat Apr 28 08:44:59 2007
@@ -926,7 +926,7 @@
    assert(0 && "Invalid alias linkage");
   }
   
-  const GlobalValue *Aliasee = GA->getAliasee();
+  const Constant *Aliasee = dyn_cast_or_null<Constant>(GA->getAliasee());
   assert(Aliasee && "Aliasee cannot be null");
     
   if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Aliasee)) {
@@ -940,9 +940,15 @@
       Out << getLLVMName(F->getName(), GlobalPrefix);
     else
       Out << "@\"\"";
-  } else
-    assert(0 && "Unsupported aliasee");
-
+  } else {
+    const ConstantExpr *CE = 0;
+    if ((CE = dyn_cast<ConstantExpr>(Aliasee)) &&
+        (CE->getOpcode() == Instruction::BitCast)) {
+      writeOperand(CE, false);    
+    } else
+      assert(0 && "Unsupported aliasee");
+  }
+  
   printInfoComment(*GA);
   Out << "\n";
 }


Index: llvm/lib/VMCore/Globals.cpp
diff -u llvm/lib/VMCore/Globals.cpp:1.20 llvm/lib/VMCore/Globals.cpp:1.21
--- llvm/lib/VMCore/Globals.cpp:1.20	Wed Apr 25 09:27:10 2007
+++ llvm/lib/VMCore/Globals.cpp	Sat Apr 28 08:44:59 2007
@@ -163,12 +163,15 @@
 //===----------------------------------------------------------------------===//
 
 GlobalAlias::GlobalAlias(const Type *Ty, LinkageTypes Link,
-                         const std::string &Name, const GlobalValue* aliasee,
+                         const std::string &Name, Constant* aliasee,
                          Module *ParentModule)
-  : GlobalValue(Ty, Value::GlobalAliasVal, 0, 0,
-                Link, Name), Aliasee(aliasee) {
+  : GlobalValue(Ty, Value::GlobalAliasVal, &Aliasee, 1, Link, Name) {
   LeakDetector::addGarbageObject(this);
 
+  if (aliasee)
+    assert(aliasee->getType() == Ty && "Alias and aliasee types should match!");
+  Aliasee.init(aliasee, this);
+
   if (ParentModule)
     ParentModule->getAliasList().push_back(this);
 }
@@ -190,12 +193,16 @@
 }
 
 bool GlobalAlias::isDeclaration() const {
-  return (Aliasee && Aliasee->isDeclaration());
+  const GlobalValue* AV = dyn_cast_or_null<const GlobalValue>(getAliasee());
+  return (AV && AV->isDeclaration());
 }
 
-void GlobalAlias::setAliasee(const GlobalValue *GV) 
+void GlobalAlias::setAliasee(Constant *Aliasee) 
 {
-  // FIXME: Some checks?
-  Aliasee = GV;
+  if (Aliasee) {
+    assert(Aliasee->getType() == getType() && 
+           "Alias and aliasee types should match!");
+    setOperand(0, Aliasee);
+  }
 }
 


Index: llvm/lib/VMCore/Module.cpp
diff -u llvm/lib/VMCore/Module.cpp:1.81 llvm/lib/VMCore/Module.cpp:1.82
--- llvm/lib/VMCore/Module.cpp:1.81	Wed Apr 25 09:27:10 2007
+++ llvm/lib/VMCore/Module.cpp	Sat Apr 28 08:45:00 2007
@@ -298,6 +298,9 @@
 
   for(Module::global_iterator I = global_begin(), E = global_end(); I != E; ++I)
     I->dropAllReferences();
+
+  for(Module::alias_iterator I = alias_begin(), E = alias_end(); I != E; ++I)
+    I->dropAllReferences();
 }
 
 void Module::addLibrary(const std::string& Lib) {


Index: llvm/lib/VMCore/Verifier.cpp
diff -u llvm/lib/VMCore/Verifier.cpp:1.206 llvm/lib/VMCore/Verifier.cpp:1.207
--- llvm/lib/VMCore/Verifier.cpp:1.206	Wed Apr 25 09:27:10 2007
+++ llvm/lib/VMCore/Verifier.cpp	Sat Apr 28 08:45:00 2007
@@ -316,7 +316,9 @@
   Assert1(GA.hasExternalLinkage() || GA.hasInternalLinkage() ||
           GA.hasWeakLinkage(),
           "Alias should have external or external weak linkage!", &GA);
-
+  Assert1(GA.getType() == GA.getAliasee()->getType(),
+          "Alias and aliasee types should match!", &GA);
+  
   visitGlobalValue(GA);
 }
 






More information about the llvm-commits mailing list