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