From 6c48244973b3c3286af54dddb98412d2820b26b5 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Thu, 14 Jul 2011 18:10:41 +0000 Subject: [PATCH] consolidate GlobalValue::isDeclaration into one non-virtual function. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@135163 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/Function.h | 6 ------ include/llvm/GlobalAlias.h | 5 ----- include/llvm/GlobalValue.h | 4 ++-- include/llvm/GlobalVariable.h | 5 ----- lib/VMCore/Globals.cpp | 21 +++++++++++++-------- 5 files changed, 15 insertions(+), 26 deletions(-) diff --git a/include/llvm/Function.h b/include/llvm/Function.h index 093f8b5e8af..0aa5b2a9fa4 100644 --- a/include/llvm/Function.h +++ b/include/llvm/Function.h @@ -139,12 +139,6 @@ public: /// arguments. bool isVarArg() const; - /// isDeclaration - Is the body of this function unknown? (The basic block - /// list is empty if so.) This is true for function declarations, but not - /// true for function definitions. - /// - virtual bool isDeclaration() const { return BasicBlocks.empty(); } - /// getIntrinsicID - This method returns the ID number of the specified /// function, or Intrinsic::not_intrinsic if the function is not an /// instrinsic, or if the pointer is null. This value is always defined to be diff --git a/include/llvm/GlobalAlias.h b/include/llvm/GlobalAlias.h index 66eb11cfd32..c3d3c38bd34 100644 --- a/include/llvm/GlobalAlias.h +++ b/include/llvm/GlobalAlias.h @@ -47,11 +47,6 @@ public: /// Provide fast operand accessors DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); - /// isDeclaration - Is this global variable lacking an initializer? If so, - /// the global variable is defined in some other translation unit, and is thus - /// only a declaration here. - virtual bool isDeclaration() const; - /// removeFromParent - This method unlinks 'this' from the containing module, /// but does not delete it. /// diff --git a/include/llvm/GlobalValue.h b/include/llvm/GlobalValue.h index 69995e19caa..d77a4dbdb31 100644 --- a/include/llvm/GlobalValue.h +++ b/include/llvm/GlobalValue.h @@ -266,8 +266,8 @@ public: virtual void destroyConstant(); /// isDeclaration - Return true if the primary definition of this global - /// value is outside of the current translation unit... - virtual bool isDeclaration() const = 0; + /// value is outside of the current translation unit. + bool isDeclaration() const; /// removeFromParent - This method unlinks 'this' from the containing module, /// but does not delete it. diff --git a/include/llvm/GlobalVariable.h b/include/llvm/GlobalVariable.h index 0fe89934350..bbc09c177e2 100644 --- a/include/llvm/GlobalVariable.h +++ b/include/llvm/GlobalVariable.h @@ -68,11 +68,6 @@ public: /// Provide fast operand accessors DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); - /// isDeclaration - Is this global variable lacking an initializer? If so, - /// the global variable is defined in some other translation unit, and is thus - /// only a declaration here. - virtual bool isDeclaration() const { return getNumOperands() == 0; } - /// hasInitializer - Unless a global variable isExternal(), it has an /// initializer. The initializer for the global variable/constant is held by /// Initializer if an initializer is specified. diff --git a/lib/VMCore/Globals.cpp b/lib/VMCore/Globals.cpp index dfb88f49277..0e0d667392b 100644 --- a/lib/VMCore/Globals.cpp +++ b/lib/VMCore/Globals.cpp @@ -61,6 +61,19 @@ void GlobalValue::setAlignment(unsigned Align) { Alignment = Log2_32(Align) + 1; assert(getAlignment() == Align && "Alignment representation error!"); } + +bool GlobalValue::isDeclaration() const { + if (const GlobalVariable *GV = dyn_cast(this)) + return GV->getNumOperands() == 0; + + if (const Function *F = dyn_cast(this)) + return F->empty(); + + const GlobalAlias *GA = cast(this); + if (const GlobalValue *AV = GA->getAliasedGlobal()) + return AV->isDeclaration(); + return false; +} //===----------------------------------------------------------------------===// // GlobalVariable Implementation @@ -202,14 +215,6 @@ void GlobalAlias::eraseFromParent() { getParent()->getAliasList().erase(this); } -bool GlobalAlias::isDeclaration() const { - const GlobalValue* AV = getAliasedGlobal(); - if (AV) - return AV->isDeclaration(); - else - return false; -} - void GlobalAlias::setAliasee(Constant *Aliasee) { assert((!Aliasee || Aliasee->getType() == getType()) && "Alias and aliasee types should match!");