1 //===-- llvm/GlobalValue.h - Class to represent a global value --*- C++ -*-===//
3 // This file is a common base class of all globally definable objects. As such,
4 // it is subclassed by GlobalVariable and by Function. This is used because you
5 // can do certain things with these global objects that you can't do to anything
6 // else. For example, use the address of one as a constant.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_GLOBALVALUE_H
11 #define LLVM_GLOBALVALUE_H
13 #include "llvm/User.h"
17 class GlobalValue : public User {
18 GlobalValue(const GlobalValue &); // do not implement
21 ExternalLinkage, // Externally visible function
22 LinkOnceLinkage, // Keep one copy of named function when linking (inline)
23 WeakLinkage, // Keep one copy of named function when linking (weak)
24 AppendingLinkage, // Special purpose, only applies to global arrays
25 InternalLinkage // Rename collisions when linking (static functions)
28 GlobalValue(const Type *Ty, ValueTy vty, LinkageTypes linkage,
29 const std::string &name = "")
30 : User(Ty, vty, name), Linkage(linkage), Parent(0) {}
32 LinkageTypes Linkage; // The linkage of this global
37 /// getType - Global values are always pointers.
38 inline const PointerType *getType() const {
39 return (const PointerType*)User::getType();
42 bool hasExternalLinkage() const { return Linkage == ExternalLinkage; }
43 bool hasLinkOnceLinkage() const { return Linkage == LinkOnceLinkage; }
44 bool hasWeakLinkage() const { return Linkage == WeakLinkage; }
45 bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
46 bool hasInternalLinkage() const { return Linkage == InternalLinkage; }
47 void setLinkage(LinkageTypes LT) { Linkage = LT; }
48 LinkageTypes getLinkage() const { return Linkage; }
50 /// isExternal - Return true if the primary definition of this global value is
51 /// outside of the current translation unit...
52 virtual bool isExternal() const = 0;
54 /// getParent - Get the module that this global value is contained inside
56 inline Module *getParent() { return Parent; }
57 inline const Module *getParent() const { return Parent; }
59 // Methods for support type inquiry through isa, cast, and dyn_cast:
60 static inline bool classof(const GlobalValue *T) { return true; }
61 static inline bool classof(const Value *V) {
62 return V->getValueType() == Value::FunctionVal ||
63 V->getValueType() == Value::GlobalVariableVal;