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