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 AppendingLinkage, // Special purpose, only applies to global arrays
24 InternalLinkage // Rename collisions when linking (static functions)
27 GlobalValue(const Type *Ty, ValueTy vty, LinkageTypes linkage,
28 const std::string &name = "")
29 : User(Ty, vty, name), Linkage(linkage), Parent(0) {}
31 LinkageTypes Linkage; // The linkage of this global
36 /// getType - Global values are always pointers.
37 inline const PointerType *getType() const {
38 return (const PointerType*)User::getType();
41 bool hasExternalLinkage() const { return Linkage == ExternalLinkage; }
42 bool hasLinkOnceLinkage() const { return Linkage == LinkOnceLinkage; }
43 bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
44 bool hasInternalLinkage() const { return Linkage == InternalLinkage; }
45 void setLinkage(LinkageTypes LT) { Linkage = LT; }
46 LinkageTypes getLinkage() const { return Linkage; }
48 /// isExternal - Return true if the primary definition of this global value is
49 /// outside of the current translation unit...
50 virtual bool isExternal() const = 0;
52 /// getParent - Get the module that this global value is contained inside
54 inline Module *getParent() { return Parent; }
55 inline const Module *getParent() const { return Parent; }
57 // Methods for support type inquiry through isa, cast, and dyn_cast:
58 static inline bool classof(const GlobalValue *T) { return true; }
59 static inline bool classof(const Value *V) {
60 return V->getValueType() == Value::FunctionVal ||
61 V->getValueType() == Value::GlobalVariableVal;