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