Wrap long lines
[oota-llvm.git] / include / llvm / GlobalValue.h
index f2349bc3cbb6073a1d3e8dfd5a5396b2dca41350..12863a2c139efb401f4c06588de4b85699279e5c 100644 (file)
 #ifndef LLVM_GLOBALVALUE_H
 #define LLVM_GLOBALVALUE_H
 
-#include "llvm/User.h"
+#include "llvm/Constant.h"
+
+namespace llvm {
+
 class PointerType;
 class Module;
 
-class GlobalValue : public User {
+class GlobalValue : public Constant {
   GlobalValue(const GlobalValue &);             // do not implement
 public:
   enum LinkageTypes {
@@ -29,21 +32,31 @@ public:
     LinkOnceLinkage,   // Keep one copy of named function when linking (inline)
     WeakLinkage,       // Keep one copy of named function when linking (weak)
     AppendingLinkage,  // Special purpose, only applies to global arrays
-    InternalLinkage    // Rename collisions when linking (static functions)
+    InternalLinkage,   // Rename collisions when linking (static functions)
+    GhostLinkage       // Stand-in functions for streaming fns from BC files
   };
 protected:
   GlobalValue(const Type *Ty, ValueTy vty, LinkageTypes linkage,
              const std::string &name = "")
-    : User(Ty, vty, name), Linkage(linkage), Parent(0) {}
+    : Constant(Ty, vty, name), Linkage(linkage), Parent(0) { }
 
   LinkageTypes Linkage;   // The linkage of this global
   Module *Parent;
 public:
-  ~GlobalValue() {}
+  ~GlobalValue() {
+    removeDeadConstantUsers();   // remove any dead constants using this.
+  }
+
+  /// If the usage is empty (except transitively dead constants), then this
+  /// global value can can be safely deleted since the destructor will 
+  /// delete the dead constants as well.
+  /// @brief Determine if the usage of this global value is empty except 
+  /// for transitively dead constants.
+  bool use_empty_except_constants();
 
   /// getType - Global values are always pointers.
   inline const PointerType *getType() const {
-    return (const PointerType*)User::getType();
+    return reinterpret_cast<const PointerType*>(User::getType());
   }
 
   bool hasExternalLinkage()  const { return Linkage == ExternalLinkage; }
@@ -54,6 +67,20 @@ public:
   void setLinkage(LinkageTypes LT) { Linkage = LT; }
   LinkageTypes getLinkage() const { return Linkage; }
 
+  /// hasNotBeenReadFromBytecode - If a module provider is being used to lazily
+  /// stream in functions from disk, this method can be used to check to see if
+  /// the function has been read in yet or not.  Unless you are working on the
+  /// JIT or something else that streams stuff in lazily, you don't need to
+  /// worry about this.
+  bool hasNotBeenReadFromBytecode() const { return Linkage == GhostLinkage; }
+
+  /// Override from Constant class. No GlobalValue's are null values so this
+  /// always returns false.
+  virtual bool isNullValue() const { return false; }
+
+  /// Override from Constant class.
+  virtual void destroyConstant();
+
   /// isExternal - Return true if the primary definition of this global value is
   /// outside of the current translation unit...
   virtual bool isExternal() const = 0;
@@ -63,6 +90,16 @@ public:
   inline Module *getParent() { return Parent; }
   inline const Module *getParent() const { return Parent; }
 
+  /// removeDeadConstantUsers - If there are any dead constant users dangling
+  /// off of this global value, remove them.  This method is useful for clients
+  /// that want to check to see if a global is unused, but don't want to deal
+  /// with potentially dead constants hanging off of the globals.
+  ///
+  /// This method tries to make the global dead.  If it detects a user that
+  /// would prevent it from becoming completely dead, it gives up early,
+  /// potentially leaving some dead constant users around.
+  void removeDeadConstantUsers();
+
   // Methods for support type inquiry through isa, cast, and dyn_cast:
   static inline bool classof(const GlobalValue *T) { return true; }
   static inline bool classof(const Value *V) {
@@ -71,4 +108,6 @@ public:
   }
 };
 
+} // End llvm namespace
+
 #endif