1987463af301f7f3ebfcaf6a9c6282b66882bb6b
[oota-llvm.git] / lib / VMCore / LLVMContext.cpp
1 //===-- LLVMContext.cpp - Implement LLVMContext -----------------------===//
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 implements LLVMContext, as a wrapper around the opaque
11 // class LLVMContextImpl.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "llvm/LLVMContext.h"
16 #include "llvm/Constants.h"
17 #include "llvm/DerivedTypes.h"
18 #include "llvm/Support/ManagedStatic.h"
19 #include "LLVMContextImpl.h"
20
21 using namespace llvm;
22
23 static ManagedStatic<LLVMContext> GlobalContext;
24
25 LLVMContext& llvm::getGlobalContext() {
26   return *GlobalContext;
27 }
28
29 LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl()) { }
30 LLVMContext::~LLVMContext() { delete pImpl; }
31
32 // Constant accessors
33 Constant* LLVMContext::getNullValue(const Type* Ty) {
34   return Constant::getNullValue(Ty);
35 }
36
37 Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
38   return Constant::getAllOnesValue(Ty);
39 }
40
41 // UndefValue accessors.
42 UndefValue* LLVMContext::getUndef(const Type* Ty) {
43   return UndefValue::get(Ty);
44 }
45
46 // ConstantInt accessors.
47 ConstantInt* LLVMContext::getConstantIntTrue() {
48   return ConstantInt::getTrue();
49 }
50
51 ConstantInt* LLVMContext::getConstantIntFalse() {
52   return ConstantInt::getFalse();
53 }
54
55 ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V,
56                                          bool isSigned) {
57   return ConstantInt::get(Ty, V, isSigned);
58 }
59
60 ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty,
61                                                int64_t V) {
62   return ConstantInt::getSigned(Ty, V);
63 }
64
65 ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
66   return ConstantInt::get(V);
67 }
68
69 Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
70   return ConstantInt::get(Ty, V);
71 }
72
73 ConstantInt* LLVMContext::getAllOnesConstantInt(const Type* Ty) {
74   return ConstantInt::getAllOnesValue(Ty);
75 }
76
77
78 // ConstantPointerNull accessors.
79 ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
80   return ConstantPointerNull::get(T);
81 }
82
83
84 // ConstantStruct accessors.
85 Constant* LLVMContext::getConstantStruct(const StructType* T,
86                                          const std::vector<Constant*>& V) {
87   return ConstantStruct::get(T, V);
88 }
89
90 Constant* LLVMContext::getConstantStruct(const std::vector<Constant*>& V,
91                                          bool Packed) {
92   return ConstantStruct::get(V, Packed);
93 }
94
95 Constant* LLVMContext::getConstantStruct(Constant* const *Vals,
96                                          unsigned NumVals, bool Packed) {
97   return ConstantStruct::get(Vals, NumVals, Packed);
98 }
99
100
101 // ConstantAggregateZero accessors.
102 ConstantAggregateZero* LLVMContext::getConstantAggregateZero(const Type* Ty) {
103   return ConstantAggregateZero::get(Ty);
104 }
105
106
107 // ConstantArray accessors.
108 Constant* LLVMContext::getConstantArray(const ArrayType* T,
109                                         const std::vector<Constant*>& V) {
110   return ConstantArray::get(T, V);
111 }
112
113 Constant* LLVMContext::getConstantArray(const ArrayType* T,
114                                         Constant* const* Vals,
115                                         unsigned NumVals) {
116   return ConstantArray::get(T, Vals, NumVals);
117 }
118
119 Constant* LLVMContext::getConstantArray(const std::string& Initializer,
120                                         bool AddNull) {
121   return ConstantArray::get(Initializer, AddNull);
122 }
123
124
125 // ConstantExpr accessors.
126 Constant* LLVMContext::getConstantExpr(unsigned Opcode, Constant* C1,
127                                        Constant* C2) {
128   return ConstantExpr::get(Opcode, C1, C2);
129 }
130
131 Constant* LLVMContext::getConstantExprTrunc(Constant* C, const Type* Ty) {
132   return ConstantExpr::getTrunc(C, Ty);
133 }
134
135 Constant* LLVMContext::getConstantExprSExt(Constant* C, const Type* Ty) {
136   return ConstantExpr::getSExt(C, Ty);
137 }
138
139 Constant* LLVMContext::getConstantExprZExt(Constant* C, const Type* Ty) {
140   return ConstantExpr::getZExt(C, Ty);  
141 }
142
143 Constant* LLVMContext::getConstantExprFPTrunc(Constant* C, const Type* Ty) {
144   return ConstantExpr::getFPTrunc(C, Ty);
145 }
146
147 Constant* LLVMContext::getConstantExprFPExtend(Constant* C, const Type* Ty) {
148   return ConstantExpr::getFPExtend(C, Ty);
149 }
150
151 Constant* LLVMContext::getConstantExprUIToFP(Constant* C, const Type* Ty) {
152   return ConstantExpr::getUIToFP(C, Ty);
153 }
154
155 Constant* LLVMContext::getConstantExprSIToFP(Constant* C, const Type* Ty) {
156   return ConstantExpr::getSIToFP(C, Ty);
157 }
158
159 Constant* LLVMContext::getConstantExprFPToUI(Constant* C, const Type* Ty) {
160   return ConstantExpr::getFPToUI(C, Ty);
161 }
162
163 Constant* LLVMContext::getConstantExprFPToSI(Constant* C, const Type* Ty) {
164   return ConstantExpr::getFPToSI(C, Ty);
165 }
166
167 Constant* LLVMContext::getConstantExprPtrToInt(Constant* C, const Type* Ty) {
168   return ConstantExpr::getPtrToInt(C, Ty);
169 }
170
171 Constant* LLVMContext::getConstantExprIntToPtr(Constant* C, const Type* Ty) {
172   return ConstantExpr::getIntToPtr(C, Ty);
173 }
174
175 Constant* LLVMContext::getConstantExprBitCast(Constant* C, const Type* Ty) {
176   return ConstantExpr::getBitCast(C, Ty);
177 }
178
179 Constant* LLVMContext::getConstantExprCast(unsigned ops, Constant* C,
180                                            const Type* Ty) {
181   return ConstantExpr::getCast(ops, C, Ty);
182 }
183
184 Constant* LLVMContext::getConstantExprZExtOrBitCast(Constant* C,
185                                                     const Type* Ty) {
186   return ConstantExpr::getZExtOrBitCast(C, Ty);
187 }
188
189 Constant* LLVMContext::getConstantExprSExtOrBitCast(Constant* C,
190                                                     const Type* Ty) {
191   return ConstantExpr::getSExtOrBitCast(C, Ty);
192 }
193
194 Constant* LLVMContext::getConstantExprTruncOrBitCast(Constant* C,
195                                                      const Type* Ty) {
196   return ConstantExpr::getTruncOrBitCast(C, Ty);  
197 }
198
199 Constant* LLVMContext::getConstantExprPointerCast(Constant* C, const Type* Ty) {
200   return ConstantExpr::getPointerCast(C, Ty);
201 }
202
203 Constant* LLVMContext::getConstantExprIntegerCast(Constant* C, const Type* Ty,
204                                                   bool isSigned) {
205   return ConstantExpr::getIntegerCast(C, Ty, isSigned);
206 }
207
208 Constant* LLVMContext::getConstantExprFPCast(Constant* C, const Type* Ty) {
209   return ConstantExpr::getFPCast(C, Ty);
210 }
211
212 Constant* LLVMContext::getConstantExprSelect(Constant* C, Constant* V1,
213                                              Constant* V2) {
214   return ConstantExpr::getSelect(C, V1, V2);
215 }
216
217 Constant* LLVMContext::getConstantExprAlignOf(const Type* Ty) {
218   return ConstantExpr::getAlignOf(Ty);
219 }
220
221 Constant* LLVMContext::getConstantExprCompare(unsigned short pred,
222                                  Constant* C1, Constant* C2) {
223   return ConstantExpr::getCompare(pred, C1, C2);
224 }
225
226 Constant* LLVMContext::getConstantExprNeg(Constant* C) {
227   return ConstantExpr::getNeg(C);
228 }
229
230 Constant* LLVMContext::getConstantExprFNeg(Constant* C) {
231   return ConstantExpr::getFNeg(C);
232 }
233
234 Constant* LLVMContext::getConstantExprNot(Constant* C) {
235   return ConstantExpr::getNot(C);
236 }
237
238 Constant* LLVMContext::getConstantExprAdd(Constant* C1, Constant* C2) {
239   return ConstantExpr::getAdd(C1, C2);
240 }
241
242 Constant* LLVMContext::getConstantExprFAdd(Constant* C1, Constant* C2) {
243   return ConstantExpr::getFAdd(C1, C2);
244 }
245
246 Constant* LLVMContext::getConstantExprSub(Constant* C1, Constant* C2) {
247   return ConstantExpr::getSub(C1, C2);
248 }
249
250 Constant* LLVMContext::getConstantExprFSub(Constant* C1, Constant* C2) {
251   return ConstantExpr::getFSub(C1, C2);
252 }
253
254 Constant* LLVMContext::getConstantExprMul(Constant* C1, Constant* C2) {
255   return ConstantExpr::getMul(C1, C2);
256 }
257
258 Constant* LLVMContext::getConstantExprFMul(Constant* C1, Constant* C2) {
259   return ConstantExpr::getFMul(C1, C2);
260 }
261
262 Constant* LLVMContext::getConstantExprUDiv(Constant* C1, Constant* C2) {
263   return ConstantExpr::getUDiv(C1, C2);
264 }
265
266 Constant* LLVMContext::getConstantExprSDiv(Constant* C1, Constant* C2) {
267   return ConstantExpr::getSDiv(C1, C2);
268 }
269
270 Constant* LLVMContext::getConstantExprFDiv(Constant* C1, Constant* C2) {
271   return ConstantExpr::getFDiv(C1, C2);
272 }
273
274 Constant* LLVMContext::getConstantExprURem(Constant* C1, Constant* C2) {
275   return ConstantExpr::getURem(C1, C2);
276 }
277
278 Constant* LLVMContext::getConstantExprSRem(Constant* C1, Constant* C2) {
279   return ConstantExpr::getSRem(C1, C2);
280 }
281
282 Constant* LLVMContext::getConstantExprFRem(Constant* C1, Constant* C2) {
283   return ConstantExpr::getFRem(C1, C2);
284 }
285
286 Constant* LLVMContext::getConstantExprAnd(Constant* C1, Constant* C2) {
287   return ConstantExpr::getAnd(C1, C2);
288 }
289
290 Constant* LLVMContext::getConstantExprOr(Constant* C1, Constant* C2) {
291   return ConstantExpr::getOr(C1, C2);
292 }
293
294 Constant* LLVMContext::getConstantExprXor(Constant* C1, Constant* C2) {
295   return ConstantExpr::getXor(C1, C2);
296 }
297
298 Constant* LLVMContext::getConstantExprICmp(unsigned short pred, Constant* LHS,
299                               Constant* RHS) {
300   return ConstantExpr::getICmp(pred, LHS, RHS);
301 }
302
303 Constant* LLVMContext::getConstantExprFCmp(unsigned short pred, Constant* LHS,
304                               Constant* RHS) {
305   return ConstantExpr::getFCmp(pred, LHS, RHS);
306 }
307
308 Constant* LLVMContext::getConstantExprVICmp(unsigned short pred, Constant* LHS,
309                                Constant* RHS) {
310   return ConstantExpr::getVICmp(pred, LHS, RHS);
311 }
312
313 Constant* LLVMContext::getConstantExprVFCmp(unsigned short pred, Constant* LHS,
314                                Constant* RHS) {
315   return ConstantExpr::getVFCmp(pred, LHS, RHS);
316 }
317
318 Constant* LLVMContext::getConstantExprShl(Constant* C1, Constant* C2) {
319   return ConstantExpr::getShl(C1, C2);
320 }
321
322 Constant* LLVMContext::getConstantExprLShr(Constant* C1, Constant* C2) {
323   return ConstantExpr::getLShr(C1, C2);
324 }
325
326 Constant* LLVMContext::getConstantExprAShr(Constant* C1, Constant* C2) {
327   return ConstantExpr::getAShr(C1, C2);
328 }
329
330 Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
331                                                     Constant* const* IdxList, 
332                                                     unsigned NumIdx) {
333   return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
334 }
335
336 Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
337                                                     Value* const* IdxList, 
338                                                     unsigned NumIdx) {
339   return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
340 }
341
342 Constant* LLVMContext::getConstantExprExtractElement(Constant* Vec,
343                                                      Constant* Idx) {
344   return ConstantExpr::getExtractElement(Vec, Idx);
345 }
346
347 Constant* LLVMContext::getConstantExprInsertElement(Constant* Vec,
348                                                     Constant* Elt,
349                                                     Constant* Idx) {
350   return ConstantExpr::getInsertElement(Vec, Elt, Idx);
351 }
352
353 Constant* LLVMContext::getConstantExprShuffleVector(Constant* V1, Constant* V2,
354                                                     Constant* Mask) {
355   return ConstantExpr::getShuffleVector(V1, V2, Mask);
356 }
357
358 Constant* LLVMContext::getConstantExprExtractValue(Constant* Agg,
359                                                    const unsigned* IdxList, 
360                                                    unsigned NumIdx) {
361   return ConstantExpr::getExtractValue(Agg, IdxList, NumIdx);
362 }
363
364 Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val,
365                                                   const unsigned* IdxList,
366                                                   unsigned NumIdx) {
367   return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
368 }
369
370 Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
371   return ConstantExpr::getZeroValueForNegationExpr(Ty);
372 }
373
374
375 // ConstantFP accessors.
376 ConstantFP* LLVMContext::getConstantFP(const APFloat& V) {
377   return ConstantFP::get(V);
378 }
379
380 Constant* LLVMContext::getConstantFP(const Type* Ty, double V) {
381   return ConstantFP::get(Ty, V);
382 }
383
384 ConstantFP* LLVMContext::getConstantFPNegativeZero(const Type* Ty) {
385   return ConstantFP::getNegativeZero(Ty);
386 }
387
388
389 // ConstantVector accessors.
390 Constant* LLVMContext::getConstantVector(const VectorType* T,
391                             const std::vector<Constant*>& V) {
392   return ConstantVector::get(T, V);
393 }
394
395 Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& V) {
396   return ConstantVector::get(V);
397 }
398
399 Constant* LLVMContext::getConstantVector(Constant* const* Vals,
400                                          unsigned NumVals) {
401   return ConstantVector::get(Vals, NumVals);
402 }
403
404 ConstantVector* LLVMContext::getConstantVectorAllOnes(const VectorType* Ty) {
405   return ConstantVector::getAllOnesValue(Ty);
406 }
407
408 // FunctionType accessors
409 FunctionType* LLVMContext::getFunctionType(const Type* Result,
410                                          const std::vector<const Type*>& Params,
411                                          bool isVarArg) {
412   return FunctionType::get(Result, Params, isVarArg);
413 }
414                                 
415 // IntegerType accessors
416 const IntegerType* LLVMContext::getIntegerType(unsigned NumBits) {
417   return IntegerType::get(NumBits);
418 }
419   
420 // OpaqueType accessors
421 OpaqueType* LLVMContext::getOpaqueType() {
422   return OpaqueType::get();
423 }
424
425 // StructType accessors
426 StructType* LLVMContext::getStructType(bool isPacked) {
427   return StructType::get(isPacked);
428 }
429
430 StructType* LLVMContext::getStructType(const std::vector<const Type*>& Params,
431                                        bool isPacked) {
432   return StructType::get(Params, isPacked);
433 }
434
435 // ArrayType accessors
436 ArrayType* LLVMContext::getArrayType(const Type* ElementType,
437                                      uint64_t NumElements) {
438   return ArrayType::get(ElementType, NumElements);
439 }
440   
441 // PointerType accessors
442 PointerType* LLVMContext::getPointerType(const Type* ElementType,
443                                          unsigned AddressSpace) {
444   return PointerType::get(ElementType, AddressSpace);
445 }
446
447 PointerType* LLVMContext::getPointerTypeUnqual(const Type* ElementType) {
448   return PointerType::getUnqual(ElementType);
449 }
450   
451 // VectorType accessors
452 VectorType* LLVMContext::getVectorType(const Type* ElementType,
453                                        unsigned NumElements) {
454   return VectorType::get(ElementType, NumElements);
455 }
456
457 VectorType* LLVMContext::getVectorTypeInteger(const VectorType* VTy) {
458   return VectorType::getInteger(VTy);  
459 }
460
461 VectorType* LLVMContext::getVectorTypeExtendedElement(const VectorType* VTy) {
462   return VectorType::getExtendedElementVectorType(VTy);
463 }
464
465 VectorType* LLVMContext::getVectorTypeTruncatedElement(const VectorType* VTy) {
466   return VectorType::getTruncatedElementVectorType(VTy);
467 }