[llvm-commits] [llvm] r135163 - in /llvm/trunk: include/llvm/Function.h include/llvm/GlobalAlias.h include/llvm/GlobalValue.h include/llvm/GlobalVariable.h lib/VMCore/Globals.cpp

Chris Lattner sabre at nondot.org
Thu Jul 14 11:10:41 PDT 2011


Author: lattner
Date: Thu Jul 14 13:10:41 2011
New Revision: 135163

URL: http://llvm.org/viewvc/llvm-project?rev=135163&view=rev
Log:
consolidate GlobalValue::isDeclaration into one 
non-virtual function.

Modified:
    llvm/trunk/include/llvm/Function.h
    llvm/trunk/include/llvm/GlobalAlias.h
    llvm/trunk/include/llvm/GlobalValue.h
    llvm/trunk/include/llvm/GlobalVariable.h
    llvm/trunk/lib/VMCore/Globals.cpp

Modified: llvm/trunk/include/llvm/Function.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Function.h?rev=135163&r1=135162&r2=135163&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Function.h (original)
+++ llvm/trunk/include/llvm/Function.h Thu Jul 14 13:10:41 2011
@@ -139,12 +139,6 @@
   /// 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

Modified: llvm/trunk/include/llvm/GlobalAlias.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/GlobalAlias.h?rev=135163&r1=135162&r2=135163&view=diff
==============================================================================
--- llvm/trunk/include/llvm/GlobalAlias.h (original)
+++ llvm/trunk/include/llvm/GlobalAlias.h Thu Jul 14 13:10:41 2011
@@ -47,11 +47,6 @@
   /// 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.
   ///

Modified: llvm/trunk/include/llvm/GlobalValue.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/GlobalValue.h?rev=135163&r1=135162&r2=135163&view=diff
==============================================================================
--- llvm/trunk/include/llvm/GlobalValue.h (original)
+++ llvm/trunk/include/llvm/GlobalValue.h Thu Jul 14 13:10:41 2011
@@ -266,8 +266,8 @@
   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.

Modified: llvm/trunk/include/llvm/GlobalVariable.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/GlobalVariable.h?rev=135163&r1=135162&r2=135163&view=diff
==============================================================================
--- llvm/trunk/include/llvm/GlobalVariable.h (original)
+++ llvm/trunk/include/llvm/GlobalVariable.h Thu Jul 14 13:10:41 2011
@@ -68,11 +68,6 @@
   /// 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.

Modified: llvm/trunk/lib/VMCore/Globals.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Globals.cpp?rev=135163&r1=135162&r2=135163&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Globals.cpp (original)
+++ llvm/trunk/lib/VMCore/Globals.cpp Thu Jul 14 13:10:41 2011
@@ -61,6 +61,19 @@
   Alignment = Log2_32(Align) + 1;
   assert(getAlignment() == Align && "Alignment representation error!");
 }
+
+bool GlobalValue::isDeclaration() const {
+  if (const GlobalVariable *GV = dyn_cast<GlobalVariable>(this))
+    return GV->getNumOperands() == 0;
+
+  if (const Function *F = dyn_cast<Function>(this))
+    return F->empty();
+  
+  const GlobalAlias *GA = cast<GlobalAlias>(this);
+  if (const GlobalValue *AV = GA->getAliasedGlobal())
+    return AV->isDeclaration();
+  return false;
+}
   
 //===----------------------------------------------------------------------===//
 // GlobalVariable Implementation
@@ -202,14 +215,6 @@
   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!");





More information about the llvm-commits mailing list