Add accessor for MDNode.
[oota-llvm.git] / include / llvm / LLVMContext.h
1 //===-- llvm/LLVMContext.h - Class for managing "global" state --*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares LLVMContext, a container of "global" state in LLVM, such
11 // as the global type and constant uniquing tables.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_LLVMCONTEXT_H
16 #define LLVM_LLVMCONTEXT_H
17
18 #include "llvm/Support/DataTypes.h"
19 #include <vector>
20 #include <string>
21
22 namespace llvm {
23
24 class LLVMContextImpl;
25 class Constant;
26 class ConstantInt;
27 class ConstantPointerNull;
28 class ConstantStruct;
29 class ConstantAggregateZero;
30 class ConstantArray;
31 class ConstantFP;
32 class ConstantVector;
33 class UndefValue;
34 class MDNode;
35 class IntegerType;
36 class PointerType;
37 class StructType;
38 class ArrayType;
39 class VectorType;
40 class OpaqueType;
41 class FunctionType;
42 class Type;
43 class APInt;
44 class APFloat;
45 class Value;
46
47 /// This is an important class for using LLVM in a threaded context.  It
48 /// (opaquely) owns and manages the core "global" data of LLVM's core 
49 /// infrastructure, including the type and constant uniquing tables.
50 /// LLVMContext itself provides no locking guarantees, so you should be careful
51 /// to have one context per thread.
52 class LLVMContext {
53   LLVMContextImpl* pImpl;
54 public:
55   LLVMContext();
56   ~LLVMContext();
57   
58   // Constant accessors
59   Constant* getNullValue(const Type* Ty);
60   Constant* getAllOnesValue(const Type* Ty);
61   
62   // UndefValue accessors
63   UndefValue* getUndef(const Type* Ty);
64   
65   // ConstantInt accessors
66   ConstantInt* getConstantIntTrue();
67   ConstantInt* getConstantIntFalse();
68   ConstantInt* getConstantInt(const IntegerType* Ty, uint64_t V,
69                               bool isSigned = false);
70   ConstantInt* getConstantIntSigned(const IntegerType* Ty, int64_t V);
71   ConstantInt* getConstantInt(const APInt& V);
72   Constant* getConstantInt(const Type* Ty, const APInt& V);
73   ConstantInt* getAllOnesConstantInt(const Type* Ty);
74   
75   // ConstantPointerNull accessors
76   ConstantPointerNull* getConstantPointerNull(const PointerType* T);
77   
78   // ConstantStruct accessors
79   Constant* getConstantStruct(const StructType* T,
80                               const std::vector<Constant*>& V);
81   Constant* getConstantStruct(const std::vector<Constant*>& V,
82                               bool Packed = false);
83   Constant* getConstantStruct(Constant* const *Vals, unsigned NumVals,
84                               bool Packed = false);
85                               
86   // ConstantAggregateZero accessors
87   ConstantAggregateZero* getConstantAggregateZero(const Type* Ty);
88   
89   // ConstantArray accessors
90   Constant* getConstantArray(const ArrayType* T,
91                              const std::vector<Constant*>& V);
92   Constant* getConstantArray(const ArrayType* T, Constant* const* Vals,
93                              unsigned NumVals);
94   Constant* getConstantArray(const std::string& Initializer,
95                              bool AddNull = false);
96                              
97   // ConstantExpr accessors
98   Constant* getConstantExpr(unsigned Opcode, Constant* C1, Constant* C2);
99   Constant* getConstantExprTrunc(Constant* C, const Type* Ty);
100   Constant* getConstantExprSExt(Constant* C, const Type* Ty);
101   Constant* getConstantExprZExt(Constant* C, const Type* Ty);
102   Constant* getConstantExprFPTrunc(Constant* C, const Type* Ty);
103   Constant* getConstantExprFPExtend(Constant* C, const Type* Ty);
104   Constant* getConstantExprUIToFP(Constant* C, const Type* Ty);
105   Constant* getConstantExprSIToFP(Constant* C, const Type* Ty);
106   Constant* getConstantExprFPToUI(Constant* C, const Type* Ty);
107   Constant* getConstantExprFPToSI(Constant* C, const Type* Ty);
108   Constant* getConstantExprPtrToInt(Constant* C, const Type* Ty);
109   Constant* getConstantExprIntToPtr(Constant* C, const Type* Ty);
110   Constant* getConstantExprBitCast(Constant* C, const Type* Ty);
111   Constant* getConstantExprCast(unsigned ops, Constant* C, const Type* Ty);
112   Constant* getConstantExprZExtOrBitCast(Constant* C, const Type* Ty);
113   Constant* getConstantExprSExtOrBitCast(Constant* C, const Type* Ty);
114   Constant* getConstantExprTruncOrBitCast(Constant* C, const Type* Ty);
115   Constant* getConstantExprPointerCast(Constant* C, const Type* Ty);
116   Constant* getConstantExprIntegerCast(Constant* C, const Type* Ty,
117                                        bool isSigned);
118   Constant* getConstantExprFPCast(Constant* C, const Type* Ty);
119   Constant* getConstantExprSelect(Constant* C, Constant* V1, Constant* V2);
120   Constant* getConstantExprAlignOf(const Type* Ty);
121   Constant* getConstantExprCompare(unsigned short pred,
122                                    Constant* C1, Constant* C2);
123   Constant* getConstantExprNeg(Constant* C);
124   Constant* getConstantExprFNeg(Constant* C);
125   Constant* getConstantExprNot(Constant* C);
126   Constant* getConstantExprAdd(Constant* C1, Constant* C2);
127   Constant* getConstantExprFAdd(Constant* C1, Constant* C2);
128   Constant* getConstantExprSub(Constant* C1, Constant* C2);
129   Constant* getConstantExprFSub(Constant* C1, Constant* C2);
130   Constant* getConstantExprMul(Constant* C1, Constant* C2);
131   Constant* getConstantExprFMul(Constant* C1, Constant* C2);
132   Constant* getConstantExprUDiv(Constant* C1, Constant* C2);
133   Constant* getConstantExprSDiv(Constant* C1, Constant* C2);
134   Constant* getConstantExprFDiv(Constant* C1, Constant* C2);
135   Constant* getConstantExprURem(Constant* C1, Constant* C2);
136   Constant* getConstantExprSRem(Constant* C1, Constant* C2);
137   Constant* getConstantExprFRem(Constant* C1, Constant* C2);
138   Constant* getConstantExprAnd(Constant* C1, Constant* C2);
139   Constant* getConstantExprOr(Constant* C1, Constant* C2);
140   Constant* getConstantExprXor(Constant* C1, Constant* C2);
141   Constant* getConstantExprICmp(unsigned short pred, Constant* LHS,
142                                 Constant* RHS);
143   Constant* getConstantExprFCmp(unsigned short pred, Constant* LHS,
144                                 Constant* RHS);
145   Constant* getConstantExprVICmp(unsigned short pred, Constant* LHS,
146                                  Constant* RHS);
147   Constant* getConstantExprVFCmp(unsigned short pred, Constant* LHS,
148                                  Constant* RHS);
149   Constant* getConstantExprShl(Constant* C1, Constant* C2);
150   Constant* getConstantExprLShr(Constant* C1, Constant* C2);
151   Constant* getConstantExprAShr(Constant* C1, Constant* C2);
152   Constant* getConstantExprGetElementPtr(Constant* C, Constant* const* IdxList, 
153                                          unsigned NumIdx);
154   Constant* getConstantExprGetElementPtr(Constant* C, Value* const* IdxList, 
155                                           unsigned NumIdx);
156   Constant* getConstantExprExtractElement(Constant* Vec, Constant* Idx);
157   Constant* getConstantExprInsertElement(Constant* Vec, Constant* Elt,
158                                          Constant* Idx);
159   Constant* getConstantExprShuffleVector(Constant* V1, Constant* V2,
160                                          Constant* Mask);
161   Constant* getConstantExprExtractValue(Constant* Agg, const unsigned* IdxList, 
162                                         unsigned NumIdx);
163   Constant* getConstantExprInsertValue(Constant* Agg, Constant* Val,
164                                        const unsigned* IdxList,
165                                        unsigned NumIdx);
166   Constant* getZeroValueForNegation(const Type* Ty);
167   
168   // ConstantFP accessors
169   ConstantFP* getConstantFP(const APFloat& V);
170   Constant* getConstantFP(const Type* Ty, double V);
171   ConstantFP* getConstantFPNegativeZero(const Type* Ty);
172   
173   // ConstantVector accessors
174   Constant* getConstantVector(const VectorType* T,
175                               const std::vector<Constant*>& V);
176   Constant* getConstantVector(const std::vector<Constant*>& V);
177   Constant* getConstantVector(Constant* const* Vals, unsigned NumVals);
178   ConstantVector* getConstantVectorAllOnes(const VectorType* Ty);
179   
180   // MDNode accessors
181   MDNode* getMDNode(Value* const* Vals, unsigned NumVals);
182   
183   // FunctionType accessors
184   FunctionType* getFunctionType(const Type* Result,
185                                 const std::vector<const Type*>& Params,
186                                 bool isVarArg);
187                                 
188   // IntegerType accessors
189   const IntegerType* getIntegerType(unsigned NumBits);
190   
191   // OpaqueType accessors
192   OpaqueType* getOpaqueType();
193   
194   // StructType accessors
195   StructType* getStructType(bool isPacked=false);
196   StructType* getStructType(const std::vector<const Type*>& Params,
197                             bool isPacked = false);
198   
199   // ArrayType accessors
200   ArrayType* getArrayType(const Type* ElementType, uint64_t NumElements);
201   
202   // PointerType accessors
203   PointerType* getPointerType(const Type* ElementType, unsigned AddressSpace);
204   PointerType* getPointerTypeUnqual(const Type* ElementType);
205   
206   // VectorType accessors
207   VectorType* getVectorType(const Type* ElementType, unsigned NumElements);
208   VectorType* getVectorTypeInteger(const VectorType* VTy);
209   VectorType* getVectorTypeExtendedElement(const VectorType* VTy);
210   VectorType* getVectorTypeTruncatedElement(const VectorType* VTy);
211 };
212
213 /// FOR BACKWARDS COMPATIBILITY - Returns a global context.
214 extern LLVMContext& getGlobalContext();
215
216 }
217
218 #endif