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