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"
27 class GlobalValue : public User {
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 : User(Ty, vty, name), Linkage(linkage), Parent(0) {}
42 LinkageTypes Linkage; // The linkage of this global
47 /// getType - Global values are always pointers.
48 inline const PointerType *getType() const {
49 return reinterpret_cast<const PointerType*>(User::getType());
52 bool hasExternalLinkage() const { return Linkage == ExternalLinkage; }
53 bool hasLinkOnceLinkage() const { return Linkage == LinkOnceLinkage; }
54 bool hasWeakLinkage() const { return Linkage == WeakLinkage; }
55 bool hasAppendingLinkage() const { return Linkage == AppendingLinkage; }
56 bool hasInternalLinkage() const { return Linkage == InternalLinkage; }
57 void setLinkage(LinkageTypes LT) { Linkage = LT; }
58 LinkageTypes getLinkage() const { return Linkage; }
60 /// isExternal - Return true if the primary definition of this global value is
61 /// outside of the current translation unit...
62 virtual bool isExternal() const = 0;
64 /// getParent - Get the module that this global value is contained inside
66 inline Module *getParent() { return Parent; }
67 inline const Module *getParent() const { return Parent; }
69 // Methods for support type inquiry through isa, cast, and dyn_cast:
70 static inline bool classof(const GlobalValue *T) { return true; }
71 static inline bool classof(const Value *V) {
72 return V->getValueType() == Value::FunctionVal ||
73 V->getValueType() == Value::GlobalVariableVal;
77 } // End llvm namespace