1 //===-- llvm/GlobalValue.h - Class to represent a global value --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a common base class of all globally definable objects. As such,
11 // it is subclassed by GlobalVariable and by Function. This is used because you
12 // can do certain things with these global objects that you can't do to anything
13 // else. For example, use the address of one as a constant.
15 //===----------------------------------------------------------------------===//
17 #ifndef LLVM_GLOBALVALUE_H
18 #define LLVM_GLOBALVALUE_H
20 #include "llvm/Constant.h"
27 class GlobalValue : public Constant {
28 GlobalValue(const GlobalValue &); // do not implement
31 ExternalLinkage, // Externally visible function
32 LinkOnceLinkage, // Keep one copy of named function when linking (inline)
33 WeakLinkage, // Keep one copy of named function when linking (weak)
34 AppendingLinkage, // Special purpose, only applies to global arrays
35 InternalLinkage // Rename collisions when linking (static functions)
38 GlobalValue(const Type *Ty, ValueTy vty, LinkageTypes linkage,
39 const std::string &name = "")
40 : Constant(Ty, vty, name), Linkage(linkage), Parent(0) { }
42 LinkageTypes Linkage; // The linkage of this global
45 virtual ~GlobalValue();
47 /// If the usage is empty (except transitively dead constants), then this
48 /// global value can can be safely deleted since the destructor will
49 /// delete the dead constants as well.
50 /// @brief Determine if the usage of this global value is empty except
51 /// for transitively dead constants.
52 bool use_empty_except_constants();
54 /// getType - Global values are always pointers.
55 inline const PointerType *getType() const {
56 return reinterpret_cast<const PointerType*>(User::getType());
59 bool hasExternalLinkage() const { return Linkage == ExternalLinkage; }
60 bool hasLinkOnceLinkage() const { return Linkage == LinkOnceLinkage; }
61 bool hasWeakLinkage() const { return Linkage == WeakLinkage; }
62 bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
63 bool hasInternalLinkage() const { return Linkage == InternalLinkage; }
64 void setLinkage(LinkageTypes LT) { Linkage = LT; }
65 LinkageTypes getLinkage() const { return Linkage; }
67 /// Override from Constant class. No GlobalValue's have null values so
68 /// this always returns false.
69 virtual bool isNullValue() const { return false; }
71 /// Override from Constant class.
72 virtual void destroyConstant();
74 /// isExternal - Return true if the primary definition of this global value is
75 /// outside of the current translation unit...
76 virtual bool isExternal() const = 0;
78 /// getParent - Get the module that this global value is contained inside
80 inline Module *getParent() { return Parent; }
81 inline const Module *getParent() const { return Parent; }
83 /// removeDeadConstantUsers - If there are any dead constant users dangling
84 /// off of this global value, remove them. This method is useful for clients
85 /// that want to check to see if a global is unused, but don't want to deal
86 /// with potentially dead constants hanging off of the globals.
88 /// This function returns true if the global value is now dead. If all
89 /// users of this global are not dead, this method may return false and
90 /// leave some of them around.
91 bool removeDeadConstantUsers();
93 // Methods for support type inquiry through isa, cast, and dyn_cast:
94 static inline bool classof(const GlobalValue *T) { return true; }
95 static inline bool classof(const Value *V) {
96 return V->getValueType() == Value::FunctionVal ||
97 V->getValueType() == Value::GlobalVariableVal;
101 } // End llvm namespace