Implement review feedback
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@36564 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/docs/LangRef.html b/docs/LangRef.html
index d74ef74..67a2fc8 100644
--- a/docs/LangRef.html
+++ b/docs/LangRef.html
@@ -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>
diff --git a/include/llvm/Function.h b/include/llvm/Function.h
index 71fb87e..b3b9716 100644
--- a/include/llvm/Function.h
+++ b/include/llvm/Function.h
@@ -150,12 +150,12 @@
/// 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
diff --git a/include/llvm/GlobalAlias.h b/include/llvm/GlobalAlias.h
index 04bd5fb..bbd19ba 100644
--- a/include/llvm/GlobalAlias.h
+++ b/include/llvm/GlobalAlias.h
@@ -75,7 +75,10 @@
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) {
diff --git a/lib/CodeGen/AsmPrinter.cpp b/lib/CodeGen/AsmPrinter.cpp
index f757183..eb0f2f1 100644
--- a/lib/CodeGen/AsmPrinter.cpp
+++ b/lib/CodeGen/AsmPrinter.cpp
@@ -129,22 +129,13 @@
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";
diff --git a/lib/Transforms/IPO/GlobalDCE.cpp b/lib/Transforms/IPO/GlobalDCE.cpp
index 9015068..56879e2 100644
--- a/lib/Transforms/IPO/GlobalDCE.cpp
+++ b/lib/Transforms/IPO/GlobalDCE.cpp
@@ -76,7 +76,7 @@
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
diff --git a/lib/VMCore/AsmWriter.cpp b/lib/VMCore/AsmWriter.cpp
index 656a7be..ac68e8d 100644
--- a/lib/VMCore/AsmWriter.cpp
+++ b/lib/VMCore/AsmWriter.cpp
@@ -926,8 +926,7 @@
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());
diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp
index 88a8c0b..aeb34f4 100644
--- a/lib/VMCore/Globals.cpp
+++ b/lib/VMCore/Globals.cpp
@@ -12,6 +12,7 @@
//
//===----------------------------------------------------------------------===//
+#include "llvm/Constants.h"
#include "llvm/GlobalVariable.h"
#include "llvm/GlobalAlias.h"
#include "llvm/DerivedTypes.h"
@@ -193,16 +194,36 @@
}
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;
}
diff --git a/lib/VMCore/Verifier.cpp b/lib/VMCore/Verifier.cpp
index c580e70..8e632e2 100644
--- a/lib/VMCore/Verifier.cpp
+++ b/lib/VMCore/Verifier.cpp
@@ -321,7 +321,8 @@
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);
}