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/User.h"
24 class GlobalValue : public User {
25 GlobalValue(const GlobalValue &); // do not implement
28 ExternalLinkage, // Externally visible function
29 LinkOnceLinkage, // Keep one copy of named function when linking (inline)
30 WeakLinkage, // Keep one copy of named function when linking (weak)
31 AppendingLinkage, // Special purpose, only applies to global arrays
32 InternalLinkage // Rename collisions when linking (static functions)
35 GlobalValue(const Type *Ty, ValueTy vty, LinkageTypes linkage,
36 const std::string &name = "")
37 : User(Ty, vty, name), Linkage(linkage), Parent(0) {}
39 LinkageTypes Linkage; // The linkage of this global
44 /// getType - Global values are always pointers.
45 inline const PointerType *getType() const {
46 return (const PointerType*)User::getType();
49 bool hasExternalLinkage() const { return Linkage == ExternalLinkage; }
50 bool hasLinkOnceLinkage() const { return Linkage == LinkOnceLinkage; }
51 bool hasWeakLinkage() const { return Linkage == WeakLinkage; }
52 bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
53 bool hasInternalLinkage() const { return Linkage == InternalLinkage; }
54 void setLinkage(LinkageTypes LT) { Linkage = LT; }
55 LinkageTypes getLinkage() const { return Linkage; }
57 /// isExternal - Return true if the primary definition of this global value is
58 /// outside of the current translation unit...
59 virtual bool isExternal() const = 0;
61 /// getParent - Get the module that this global value is contained inside
63 inline Module *getParent() { return Parent; }
64 inline const Module *getParent() const { return Parent; }
66 // Methods for support type inquiry through isa, cast, and dyn_cast:
67 static inline bool classof(const GlobalValue *T) { return true; }
68 static inline bool classof(const Value *V) {
69 return V->getValueType() == Value::FunctionVal ||
70 V->getValueType() == Value::GlobalVariableVal;