Implement review feedback
authorAnton Korobeynikov <asl@math.spbu.ru>
Sun, 29 Apr 2007 18:02:48 +0000 (18:02 +0000)
committerAnton Korobeynikov <asl@math.spbu.ru>
Sun, 29 Apr 2007 18:02:48 +0000 (18:02 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36564 91177308-0d34-0410-b5e6-96231b3b80d8

docs/LangRef.html
include/llvm/Function.h
include/llvm/GlobalAlias.h
lib/CodeGen/AsmPrinter.cpp
lib/Transforms/IPO/GlobalDCE.cpp
lib/VMCore/AsmWriter.cpp
lib/VMCore/Globals.cpp
lib/VMCore/Verifier.cpp

index d74ef742dbcd21a7cfc476aee289a94329e36626..67a2fc8a4ddf924f6390daf4c72d90b7e406f49a 100644 (file)
@@ -24,7 +24,7 @@
       <li><a href="#callingconv">Calling Conventions</a></li>
       <li><a href="#globalvars">Global Variables</a></li>
       <li><a href="#functionstructure">Functions</a></li>
-      <li><a href="aliasstructure">Aliases</a>
+      <li><a href="#aliasstructure">Aliases</a>
       <li><a href="#paramattrs">Parameter Attributes</a></li>
       <li><a href="#moduleasm">Module-Level Inline Assembly</a></li>
       <li><a href="#datalayout">Data Layout</a></li>
index 71fb87ea6671bad175bd4ed1ea15127792e6fe2c..b3b9716d4dfdd741d1a2ffe00158b17db5168fab 100644 (file)
@@ -150,12 +150,12 @@ public:
   /// removeFromParent - This method unlinks 'this' from the containing module,
   /// but does not delete it.
   ///
-  virtual void removeFromParent();
+  void removeFromParent();
 
   /// eraseFromParent - This method unlinks 'this' from the containing module
   /// and deletes it.
   ///
-  virtual void eraseFromParent();
+  void eraseFromParent();
 
 
   /// Get the underlying elements of the Function... the basic block list is
index 04bd5fbd7fee3bc69adf0978c0caaad5a64b7c52..bbd19ba8816d802e8b382bdf462b93b949b31ec2 100644 (file)
@@ -75,7 +75,10 @@ public:
   Constant* getAliasee() {
     return cast_or_null<Constant>(getOperand(0));
   }
-
+  /// getAliasedGlobal() - Aliasee can be either global or bitcast of
+  /// global. This method retrives the global for both aliasee flavours.
+  const GlobalValue* getAliasedGlobal() const;
+    
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const GlobalAlias *) { return true; }
   static inline bool classof(const Value *V) {
index f7571831a344184a2163ce8f7dae88cc1ea8544b..eb0f2f1b36714cf20a6e50f04f72937dbc4f3942 100644 (file)
@@ -129,22 +129,13 @@ bool AsmPrinter::doFinalization(Module &M) {
     O << "\n";
     for (Module::const_alias_iterator I = M.alias_begin(), E = M.alias_end();
          I!=E; ++I) {
-      const Constant *Aliasee = dyn_cast_or_null<Constant>(I->getAliasee());
-      assert(Aliasee && "Aliasee cannot be null");
-
       std::string Name = Mang->getValueName(I);
       std::string Target;
       
-      if (const GlobalValue *GV = dyn_cast<GlobalValue>(Aliasee))
+      if (const GlobalValue *GV = I->getAliasedGlobal())
         Target = Mang->getValueName(GV);
-      else {
-        const ConstantExpr *CE = 0;
-        if ((CE = dyn_cast<ConstantExpr>(Aliasee)) &&
-            (CE->getOpcode() == Instruction::BitCast))
-          Target = Mang->getValueName(CE->getOperand(0));
-        else
-          assert(0 && "Unsupported aliasee");
-      }
+      else
+        assert(0 && "Unsupported aliasee");
       
       if (I->hasExternalLinkage())
         O << "\t.globl\t" << Name << "\n";
index 90150689cc87e107cada352fa453706c352bbe74..56879e2b1362e83e512d4f9ec6a67365327e214c 100644 (file)
@@ -76,7 +76,7 @@ bool GlobalDCE::runOnModule(Module &M) {
   for (Module::alias_iterator I = M.alias_begin(), E = M.alias_end();
        I != E; ++I) {
     // Aliases are always needed even if they are not used.
-    MarkUsedGlobalsAsNeeded(cast<Constant>(I->getAliasee()));
+    MarkUsedGlobalsAsNeeded(I->getAliasee());
   }
 
   // Now that all globals which are needed are in the AliveGlobals set, we loop
index 656a7bed74e2d46013cd1ce7273b93e162ea5fe4..ac68e8d32fb942e6c1a310cb695677d1a9680f8a 100644 (file)
@@ -926,8 +926,7 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) {
    assert(0 && "Invalid alias linkage");
   }
   
-  const Constant *Aliasee = dyn_cast_or_null<Constant>(GA->getAliasee());
-  assert(Aliasee && "Aliasee cannot be null");
+  const Constant *Aliasee = GA->getAliasee();
     
   if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(Aliasee)) {
     printType(GV->getType());
index 88a8c0b2a7ad7d4484456cfc524735a6d282321b..aeb34f43715d46aed6d8afe3286b33a63a5de72b 100644 (file)
@@ -12,6 +12,7 @@
 //
 //===----------------------------------------------------------------------===//
 
+#include "llvm/Constants.h"
 #include "llvm/GlobalVariable.h"
 #include "llvm/GlobalAlias.h"
 #include "llvm/DerivedTypes.h"
@@ -193,16 +194,36 @@ void GlobalAlias::eraseFromParent() {
 }
 
 bool GlobalAlias::isDeclaration() const {
-  const GlobalValue* AV = dyn_cast_or_null<const GlobalValue>(getAliasee());
-  return (AV && AV->isDeclaration());
+  const GlobalValue* AV = getAliasedGlobal();
+  if (AV)
+    return AV->isDeclaration();
+  else
+    return false;
 }
 
 void GlobalAlias::setAliasee(Constant *Aliasee) 
 {
-  if (Aliasee) {
-    assert(Aliasee->getType() == getType() && 
+  if (Aliasee)
+    assert(Aliasee->getType() == getType() &&
            "Alias and aliasee types should match!");
-    setOperand(0, Aliasee);
-  }
+  
+  setOperand(0, Aliasee);
+}
+
+const GlobalValue *GlobalAlias::getAliasedGlobal() const  {
+  const Constant *C = getAliasee();
+  if (C) {
+    if (const GlobalValue *GV = dyn_cast<GlobalValue>(C))
+      return GV;
+    else {
+      const ConstantExpr *CE = 0;
+      if ((CE = dyn_cast<ConstantExpr>(Aliasee)) &&
+          (CE->getOpcode() == Instruction::BitCast))
+        return cast<GlobalValue>(CE->getOperand(0));
+      else
+        assert(0 && "Unsupported aliasee");
+    }
+  } else
+    return 0;
 }
 
index c580e70d84eaabdba4577a669ec8b03a194b6162..8e632e2f8da0fa6f689da3066119b72b33b86542 100644 (file)
@@ -321,7 +321,8 @@ void Verifier::visitGlobalAlias(GlobalAlias &GA) {
   
   if (!isa<GlobalValue>(GA.getAliasee())) {
     const ConstantExpr *CE = dyn_cast<ConstantExpr>(GA.getAliasee());
-    Assert1(CE && CE->getOpcode() == Instruction::BitCast,
+    Assert1(CE && CE->getOpcode() == Instruction::BitCast &&
+            isa<GlobalValue>(CE->getOperand(0)),
             "Aliasee should be either GlobalValue or bitcast of GlobalValue",
             &GA);
   }