correct the type of two intrinsics, add int_ppc_altivec_vmladduhm
[oota-llvm.git] / include / llvm / GlobalVariable.h
1 //===-- llvm/GlobalVariable.h - GlobalVariable class ------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
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.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file contains the declaration of the GlobalVariable class, which
11 // represents a single global variable (or constant) in the VM.
12 //
13 // Global variables are constant pointers that refer to hunks of space that are
14 // allocated by either the VM, or by the linker in a static compiler.  A global
15 // variable may have an intial value, which is copied into the executables .data
16 // area.  Global Constants are required to have initializers.
17 //
18 //===----------------------------------------------------------------------===//
19
20 #ifndef LLVM_GLOBAL_VARIABLE_H
21 #define LLVM_GLOBAL_VARIABLE_H
22
23 #include "llvm/GlobalValue.h"
24
25 namespace llvm {
26
27 class Module;
28 class Constant;
29 class PointerType;
30 template<typename SC> struct ilist_traits;
31 template<typename ValueSubClass, typename ItemParentClass, typename SymTabClass,
32          typename SubClass> class SymbolTableListTraits;
33
34 class GlobalVariable : public GlobalValue {
35   friend class SymbolTableListTraits<GlobalVariable, Module, Module,
36                                      ilist_traits<GlobalVariable> >;
37   void operator=(const GlobalVariable &);     // Do not implement
38   GlobalVariable(const GlobalVariable &);     // Do not implement
39
40   void setParent(Module *parent);
41
42   GlobalVariable *Prev, *Next;
43   void setNext(GlobalVariable *N) { Next = N; }
44   void setPrev(GlobalVariable *N) { Prev = N; }
45
46   bool isConstantGlobal;               // Is this a global constant?
47   Use Initializer;
48
49 public:
50   /// GlobalVariable ctor - If a parent module is specified, the global is
51   /// automatically inserted into the end of the specified modules global list.
52   ///
53   GlobalVariable(const Type *Ty, bool isConstant, LinkageTypes Linkage,
54                  Constant *Initializer = 0, const std::string &Name = "",
55                  Module *Parent = 0);
56
57   /// isExternal - Is this global variable lacking an initializer?  If so, the
58   /// global variable is defined in some other translation unit, and is thus
59   /// externally defined here.
60   ///
61   virtual bool isExternal() const { return getNumOperands() == 0; }
62
63   /// hasInitializer - Unless a global variable isExternal(), it has an
64   /// initializer.  The initializer for the global variable/constant is held by
65   /// Initializer if an initializer is specified.
66   ///
67   inline bool hasInitializer() const { return !isExternal(); }
68
69   /// getInitializer - Return the initializer for this global variable.  It is
70   /// illegal to call this method if the global is external, because we cannot
71   /// tell what the value is initialized to!
72   ///
73   inline Constant *getInitializer() const {
74     assert(hasInitializer() && "GV doesn't have initializer!");
75     return reinterpret_cast<Constant*>(Initializer.get());
76   }
77   inline Constant *getInitializer() {
78     assert(hasInitializer() && "GV doesn't have initializer!");
79     return reinterpret_cast<Constant*>(Initializer.get());
80   }
81   inline void setInitializer(Constant *CPV) {
82     if (CPV == 0) {
83       if (hasInitializer()) {
84         Initializer.set(0);
85         NumOperands = 0;
86       }
87     } else {
88       if (!hasInitializer())
89         NumOperands = 1;
90       Initializer.set(CPV);
91     }
92   }
93
94   // getNext/Prev - Return the next or previous global variable in the list.
95         GlobalVariable *getNext()       { return Next; }
96   const GlobalVariable *getNext() const { return Next; }
97         GlobalVariable *getPrev()       { return Prev; }
98   const GlobalVariable *getPrev() const { return Prev; }
99
100   /// If the value is a global constant, its value is immutable throughout the
101   /// runtime execution of the program.  Assigning a value into the constant
102   /// leads to undefined behavior.
103   ///
104   bool isConstant() const { return isConstantGlobal; }
105   void setConstant(bool Value) { isConstantGlobal = Value; }
106
107   /// removeFromParent - This method unlinks 'this' from the containing module,
108   /// but does not delete it.
109   ///
110   void removeFromParent();
111
112   /// eraseFromParent - This method unlinks 'this' from the containing module
113   /// and deletes it.
114   ///
115   void eraseFromParent();
116
117   /// Override Constant's implementation of this method so we can
118   /// replace constant initializers.
119   virtual void replaceUsesOfWithOnConstant(Value *From, Value *To, Use *U);
120
121   virtual void print(std::ostream &OS) const;
122
123   // Methods for support type inquiry through isa, cast, and dyn_cast:
124   static inline bool classof(const GlobalVariable *) { return true; }
125   static inline bool classof(const Value *V) {
126     return V->getValueType() == Value::GlobalVariableVal;
127   }
128 };
129
130 } // End llvm namespace
131
132 #endif