From 546ea7ea88965166e6d756c2012ede522bf12682 Mon Sep 17 00:00:00 2001 From: Anton Korobeynikov Date: Sun, 29 Apr 2007 18:02:48 +0000 Subject: Implement review feedback llvm-svn: 36564 --- llvm/lib/CodeGen/AsmPrinter.cpp | 15 +++------------ llvm/lib/Transforms/IPO/GlobalDCE.cpp | 2 +- llvm/lib/VMCore/AsmWriter.cpp | 3 +-- llvm/lib/VMCore/Globals.cpp | 33 +++++++++++++++++++++++++++------ llvm/lib/VMCore/Verifier.cpp | 3 ++- 5 files changed, 34 insertions(+), 22 deletions(-) (limited to 'llvm/lib') diff --git a/llvm/lib/CodeGen/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter.cpp index f7571831a34..eb0f2f1b367 100644 --- a/llvm/lib/CodeGen/AsmPrinter.cpp +++ b/llvm/lib/CodeGen/AsmPrinter.cpp @@ -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(I->getAliasee()); - assert(Aliasee && "Aliasee cannot be null"); - std::string Name = Mang->getValueName(I); std::string Target; - if (const GlobalValue *GV = dyn_cast(Aliasee)) + if (const GlobalValue *GV = I->getAliasedGlobal()) Target = Mang->getValueName(GV); - else { - const ConstantExpr *CE = 0; - if ((CE = dyn_cast(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/llvm/lib/Transforms/IPO/GlobalDCE.cpp b/llvm/lib/Transforms/IPO/GlobalDCE.cpp index 90150689cc8..56879e2b136 100644 --- a/llvm/lib/Transforms/IPO/GlobalDCE.cpp +++ b/llvm/lib/Transforms/IPO/GlobalDCE.cpp @@ -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(I->getAliasee())); + MarkUsedGlobalsAsNeeded(I->getAliasee()); } // Now that all globals which are needed are in the AliveGlobals set, we loop diff --git a/llvm/lib/VMCore/AsmWriter.cpp b/llvm/lib/VMCore/AsmWriter.cpp index 656a7bed74e..ac68e8d32fb 100644 --- a/llvm/lib/VMCore/AsmWriter.cpp +++ b/llvm/lib/VMCore/AsmWriter.cpp @@ -926,8 +926,7 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) { assert(0 && "Invalid alias linkage"); } - const Constant *Aliasee = dyn_cast_or_null(GA->getAliasee()); - assert(Aliasee && "Aliasee cannot be null"); + const Constant *Aliasee = GA->getAliasee(); if (const GlobalVariable *GV = dyn_cast(Aliasee)) { printType(GV->getType()); diff --git a/llvm/lib/VMCore/Globals.cpp b/llvm/lib/VMCore/Globals.cpp index 88a8c0b2a7a..aeb34f43715 100644 --- a/llvm/lib/VMCore/Globals.cpp +++ b/llvm/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 @@ void GlobalAlias::eraseFromParent() { } bool GlobalAlias::isDeclaration() const { - const GlobalValue* AV = dyn_cast_or_null(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(C)) + return GV; + else { + const ConstantExpr *CE = 0; + if ((CE = dyn_cast(Aliasee)) && + (CE->getOpcode() == Instruction::BitCast)) + return cast(CE->getOperand(0)); + else + assert(0 && "Unsupported aliasee"); + } + } else + return 0; } diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp index c580e70d84e..8e632e2f8da 100644 --- a/llvm/lib/VMCore/Verifier.cpp +++ b/llvm/lib/VMCore/Verifier.cpp @@ -321,7 +321,8 @@ void Verifier::visitGlobalAlias(GlobalAlias &GA) { if (!isa(GA.getAliasee())) { const ConstantExpr *CE = dyn_cast(GA.getAliasee()); - Assert1(CE && CE->getOpcode() == Instruction::BitCast, + Assert1(CE && CE->getOpcode() == Instruction::BitCast && + isa(CE->getOperand(0)), "Aliasee should be either GlobalValue or bitcast of GlobalValue", &GA); } -- cgit v1.2.3