Fix "no newline at end of file" warning from gcc.
[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/Instruction.h"
19 #include "llvm/MDNode.h"
20 #include "llvm/Support/ManagedStatic.h"
21 #include "LLVMContextImpl.h"
22 #include <cstdarg>
23
24 using namespace llvm;
25
26 static ManagedStatic<LLVMContext> GlobalContext;
27
28 LLVMContext& llvm::getGlobalContext() {
29   return *GlobalContext;
30 }
31
32 LLVMContext::LLVMContext() : pImpl(new LLVMContextImpl(*this)) { }
33 LLVMContext::~LLVMContext() { delete pImpl; }
34
35 // Constant accessors
36
37 // Constructor to create a '0' constant of arbitrary type...
38 static const uint64_t zero[2] = {0, 0};
39 Constant* LLVMContext::getNullValue(const Type* Ty) {
40   switch (Ty->getTypeID()) {
41   case Type::IntegerTyID:
42     return getConstantInt(Ty, 0);
43   case Type::FloatTyID:
44     return getConstantFP(APFloat(APInt(32, 0)));
45   case Type::DoubleTyID:
46     return getConstantFP(APFloat(APInt(64, 0)));
47   case Type::X86_FP80TyID:
48     return getConstantFP(APFloat(APInt(80, 2, zero)));
49   case Type::FP128TyID:
50     return getConstantFP(APFloat(APInt(128, 2, zero), true));
51   case Type::PPC_FP128TyID:
52     return getConstantFP(APFloat(APInt(128, 2, zero)));
53   case Type::PointerTyID:
54     return getConstantPointerNull(cast<PointerType>(Ty));
55   case Type::StructTyID:
56   case Type::ArrayTyID:
57   case Type::VectorTyID:
58     return getConstantAggregateZero(Ty);
59   default:
60     // Function, Label, or Opaque type?
61     assert(!"Cannot create a null constant of that type!");
62     return 0;
63   }
64 }
65
66 Constant* LLVMContext::getAllOnesValue(const Type* Ty) {
67   if (const IntegerType* ITy = dyn_cast<IntegerType>(Ty))
68     return getConstantInt(APInt::getAllOnesValue(ITy->getBitWidth()));
69   
70   std::vector<Constant*> Elts;
71   const VectorType* VTy = cast<VectorType>(Ty);
72   Elts.resize(VTy->getNumElements(), getAllOnesValue(VTy->getElementType()));
73   assert(Elts[0] && "Not a vector integer type!");
74   return cast<ConstantVector>(getConstantVector(Elts));
75 }
76
77 // UndefValue accessors.
78 UndefValue* LLVMContext::getUndef(const Type* Ty) {
79   return UndefValue::get(Ty);
80 }
81
82 // ConstantInt accessors.
83 ConstantInt* LLVMContext::getConstantIntTrue() {
84   return ConstantInt::getTrue();
85 }
86
87 ConstantInt* LLVMContext::getConstantIntFalse() {
88   return ConstantInt::getFalse();
89 }
90
91 Constant* LLVMContext::getConstantInt(const Type* Ty, uint64_t V,
92                                          bool isSigned) {
93   Constant *C = getConstantInt(cast<IntegerType>(Ty->getScalarType()),
94                                V, isSigned);
95
96   // For vectors, broadcast the value.
97   if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
98     return
99       getConstantVector(std::vector<Constant *>(VTy->getNumElements(), C));
100
101   return C;
102 }
103
104
105 ConstantInt* LLVMContext::getConstantInt(const IntegerType* Ty, uint64_t V,
106                                          bool isSigned) {
107   return getConstantInt(APInt(Ty->getBitWidth(), V, isSigned));
108 }
109
110 ConstantInt* LLVMContext::getConstantIntSigned(const IntegerType* Ty,
111                                                int64_t V) {
112   return getConstantInt(Ty, V, true);
113 }
114
115 Constant *LLVMContext::getConstantIntSigned(const Type *Ty, int64_t V) {
116   return getConstantInt(Ty, V, true);
117 }
118
119 ConstantInt* LLVMContext::getConstantInt(const APInt& V) {
120   return pImpl->getConstantInt(V);
121 }
122
123 Constant* LLVMContext::getConstantInt(const Type* Ty, const APInt& V) {
124   ConstantInt *C = getConstantInt(V);
125   assert(C->getType() == Ty->getScalarType() &&
126          "ConstantInt type doesn't match the type implied by its value!");
127
128   // For vectors, broadcast the value.
129   if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
130     return
131       getConstantVector(std::vector<Constant *>(VTy->getNumElements(), C));
132
133   return C;
134 }
135
136 // ConstantPointerNull accessors.
137 ConstantPointerNull* LLVMContext::getConstantPointerNull(const PointerType* T) {
138   return ConstantPointerNull::get(T);
139 }
140
141
142 // ConstantStruct accessors.
143 Constant* LLVMContext::getConstantStruct(const StructType* T,
144                                          const std::vector<Constant*>& V) {
145   return ConstantStruct::get(T, V);
146 }
147
148 Constant* LLVMContext::getConstantStruct(const std::vector<Constant*>& V,
149                                          bool packed) {
150   std::vector<const Type*> StructEls;
151   StructEls.reserve(V.size());
152   for (unsigned i = 0, e = V.size(); i != e; ++i)
153     StructEls.push_back(V[i]->getType());
154   return getConstantStruct(getStructType(StructEls, packed), V);
155 }
156
157 Constant* LLVMContext::getConstantStruct(Constant* const *Vals,
158                                          unsigned NumVals, bool Packed) {
159   // FIXME: make this the primary ctor method.
160   return getConstantStruct(std::vector<Constant*>(Vals, Vals+NumVals), Packed);
161 }
162
163
164 // ConstantAggregateZero accessors.
165 ConstantAggregateZero* LLVMContext::getConstantAggregateZero(const Type* Ty) {
166   return ConstantAggregateZero::get(Ty);
167 }
168
169
170 // ConstantArray accessors.
171 Constant* LLVMContext::getConstantArray(const ArrayType* T,
172                                         const std::vector<Constant*>& V) {
173   return ConstantArray::get(T, V);
174 }
175
176 Constant* LLVMContext::getConstantArray(const ArrayType* T,
177                                         Constant* const* Vals,
178                                         unsigned NumVals) {
179   // FIXME: make this the primary ctor method.
180   return getConstantArray(T, std::vector<Constant*>(Vals, Vals+NumVals));
181 }
182
183 /// ConstantArray::get(const string&) - Return an array that is initialized to
184 /// contain the specified string.  If length is zero then a null terminator is 
185 /// added to the specified string so that it may be used in a natural way. 
186 /// Otherwise, the length parameter specifies how much of the string to use 
187 /// and it won't be null terminated.
188 ///
189 Constant* LLVMContext::getConstantArray(const std::string& Str,
190                                         bool AddNull) {
191   std::vector<Constant*> ElementVals;
192   for (unsigned i = 0; i < Str.length(); ++i)
193     ElementVals.push_back(getConstantInt(Type::Int8Ty, Str[i]));
194
195   // Add a null terminator to the string...
196   if (AddNull) {
197     ElementVals.push_back(getConstantInt(Type::Int8Ty, 0));
198   }
199
200   ArrayType *ATy = getArrayType(Type::Int8Ty, ElementVals.size());
201   return getConstantArray(ATy, ElementVals);
202 }
203
204
205 // ConstantExpr accessors.
206 Constant* LLVMContext::getConstantExpr(unsigned Opcode, Constant* C1,
207                                        Constant* C2) {
208   return ConstantExpr::get(Opcode, C1, C2);
209 }
210
211 Constant* LLVMContext::getConstantExprTrunc(Constant* C, const Type* Ty) {
212   return ConstantExpr::getTrunc(C, Ty);
213 }
214
215 Constant* LLVMContext::getConstantExprSExt(Constant* C, const Type* Ty) {
216   return ConstantExpr::getSExt(C, Ty);
217 }
218
219 Constant* LLVMContext::getConstantExprZExt(Constant* C, const Type* Ty) {
220   return ConstantExpr::getZExt(C, Ty);  
221 }
222
223 Constant* LLVMContext::getConstantExprFPTrunc(Constant* C, const Type* Ty) {
224   return ConstantExpr::getFPTrunc(C, Ty);
225 }
226
227 Constant* LLVMContext::getConstantExprFPExtend(Constant* C, const Type* Ty) {
228   return ConstantExpr::getFPExtend(C, Ty);
229 }
230
231 Constant* LLVMContext::getConstantExprUIToFP(Constant* C, const Type* Ty) {
232   return ConstantExpr::getUIToFP(C, Ty);
233 }
234
235 Constant* LLVMContext::getConstantExprSIToFP(Constant* C, const Type* Ty) {
236   return ConstantExpr::getSIToFP(C, Ty);
237 }
238
239 Constant* LLVMContext::getConstantExprFPToUI(Constant* C, const Type* Ty) {
240   return ConstantExpr::getFPToUI(C, Ty);
241 }
242
243 Constant* LLVMContext::getConstantExprFPToSI(Constant* C, const Type* Ty) {
244   return ConstantExpr::getFPToSI(C, Ty);
245 }
246
247 Constant* LLVMContext::getConstantExprPtrToInt(Constant* C, const Type* Ty) {
248   return ConstantExpr::getPtrToInt(C, Ty);
249 }
250
251 Constant* LLVMContext::getConstantExprIntToPtr(Constant* C, const Type* Ty) {
252   return ConstantExpr::getIntToPtr(C, Ty);
253 }
254
255 Constant* LLVMContext::getConstantExprBitCast(Constant* C, const Type* Ty) {
256   return ConstantExpr::getBitCast(C, Ty);
257 }
258
259 Constant* LLVMContext::getConstantExprCast(unsigned ops, Constant* C,
260                                            const Type* Ty) {
261   return ConstantExpr::getCast(ops, C, Ty);
262 }
263
264 Constant* LLVMContext::getConstantExprZExtOrBitCast(Constant* C,
265                                                     const Type* Ty) {
266   return ConstantExpr::getZExtOrBitCast(C, Ty);
267 }
268
269 Constant* LLVMContext::getConstantExprSExtOrBitCast(Constant* C,
270                                                     const Type* Ty) {
271   return ConstantExpr::getSExtOrBitCast(C, Ty);
272 }
273
274 Constant* LLVMContext::getConstantExprTruncOrBitCast(Constant* C,
275                                                      const Type* Ty) {
276   return ConstantExpr::getTruncOrBitCast(C, Ty);  
277 }
278
279 Constant* LLVMContext::getConstantExprPointerCast(Constant* C, const Type* Ty) {
280   return ConstantExpr::getPointerCast(C, Ty);
281 }
282
283 Constant* LLVMContext::getConstantExprIntegerCast(Constant* C, const Type* Ty,
284                                                   bool isSigned) {
285   return ConstantExpr::getIntegerCast(C, Ty, isSigned);
286 }
287
288 Constant* LLVMContext::getConstantExprFPCast(Constant* C, const Type* Ty) {
289   return ConstantExpr::getFPCast(C, Ty);
290 }
291
292 Constant* LLVMContext::getConstantExprSelect(Constant* C, Constant* V1,
293                                              Constant* V2) {
294   return ConstantExpr::getSelect(C, V1, V2);
295 }
296
297 Constant* LLVMContext::getConstantExprAlignOf(const Type* Ty) {
298   // alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1
299   const Type *AligningTy = getStructType(Type::Int8Ty, Ty, NULL);
300   Constant *NullPtr = getNullValue(AligningTy->getPointerTo());
301   Constant *Zero = getConstantInt(Type::Int32Ty, 0);
302   Constant *One = getConstantInt(Type::Int32Ty, 1);
303   Constant *Indices[2] = { Zero, One };
304   Constant *GEP = getConstantExprGetElementPtr(NullPtr, Indices, 2);
305   return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int32Ty);
306 }
307
308 Constant* LLVMContext::getConstantExprCompare(unsigned short pred,
309                                  Constant* C1, Constant* C2) {
310   return ConstantExpr::getCompare(pred, C1, C2);
311 }
312
313 Constant* LLVMContext::getConstantExprNeg(Constant* C) {
314   // API compatibility: Adjust integer opcodes to floating-point opcodes.
315   if (C->getType()->isFPOrFPVector())
316     return getConstantExprFNeg(C);
317   assert(C->getType()->isIntOrIntVector() &&
318          "Cannot NEG a nonintegral value!");
319   return getConstantExpr(Instruction::Sub,
320              getZeroValueForNegation(C->getType()),
321              C);
322 }
323
324 Constant* LLVMContext::getConstantExprFNeg(Constant* C) {
325   assert(C->getType()->isFPOrFPVector() &&
326          "Cannot FNEG a non-floating-point value!");
327   return getConstantExpr(Instruction::FSub,
328              getZeroValueForNegation(C->getType()),
329              C);
330 }
331
332 Constant* LLVMContext::getConstantExprNot(Constant* C) {
333   assert(C->getType()->isIntOrIntVector() &&
334          "Cannot NOT a nonintegral value!");
335   return getConstantExpr(Instruction::Xor, C, getAllOnesValue(C->getType()));
336 }
337
338 Constant* LLVMContext::getConstantExprAdd(Constant* C1, Constant* C2) {
339   return getConstantExpr(Instruction::Add, C1, C2);
340 }
341
342 Constant* LLVMContext::getConstantExprFAdd(Constant* C1, Constant* C2) {
343   return getConstantExpr(Instruction::FAdd, C1, C2);
344 }
345
346 Constant* LLVMContext::getConstantExprSub(Constant* C1, Constant* C2) {
347   return getConstantExpr(Instruction::Sub, C1, C2);
348 }
349
350 Constant* LLVMContext::getConstantExprFSub(Constant* C1, Constant* C2) {
351   return getConstantExpr(Instruction::FSub, C1, C2);
352 }
353
354 Constant* LLVMContext::getConstantExprMul(Constant* C1, Constant* C2) {
355   return getConstantExpr(Instruction::Mul, C1, C2);
356 }
357
358 Constant* LLVMContext::getConstantExprFMul(Constant* C1, Constant* C2) {
359   return getConstantExpr(Instruction::FMul, C1, C2);
360 }
361
362 Constant* LLVMContext::getConstantExprUDiv(Constant* C1, Constant* C2) {
363   return getConstantExpr(Instruction::UDiv, C1, C2);
364 }
365
366 Constant* LLVMContext::getConstantExprSDiv(Constant* C1, Constant* C2) {
367   return getConstantExpr(Instruction::SDiv, C1, C2);
368 }
369
370 Constant* LLVMContext::getConstantExprFDiv(Constant* C1, Constant* C2) {
371   return getConstantExpr(Instruction::FDiv, C1, C2);
372 }
373
374 Constant* LLVMContext::getConstantExprURem(Constant* C1, Constant* C2) {
375   return getConstantExpr(Instruction::URem, C1, C2);
376 }
377
378 Constant* LLVMContext::getConstantExprSRem(Constant* C1, Constant* C2) {
379   return getConstantExpr(Instruction::SRem, C1, C2);
380 }
381
382 Constant* LLVMContext::getConstantExprFRem(Constant* C1, Constant* C2) {
383   return getConstantExpr(Instruction::FRem, C1, C2);
384 }
385
386 Constant* LLVMContext::getConstantExprAnd(Constant* C1, Constant* C2) {
387   return getConstantExpr(Instruction::And, C1, C2);
388 }
389
390 Constant* LLVMContext::getConstantExprOr(Constant* C1, Constant* C2) {
391   return getConstantExpr(Instruction::Or, C1, C2);
392 }
393
394 Constant* LLVMContext::getConstantExprXor(Constant* C1, Constant* C2) {
395   return getConstantExpr(Instruction::Xor, C1, C2);
396 }
397
398 Constant* LLVMContext::getConstantExprICmp(unsigned short pred, Constant* LHS,
399                               Constant* RHS) {
400   return ConstantExpr::getICmp(pred, LHS, RHS);
401 }
402
403 Constant* LLVMContext::getConstantExprFCmp(unsigned short pred, Constant* LHS,
404                               Constant* RHS) {
405   return ConstantExpr::getFCmp(pred, LHS, RHS);
406 }
407
408 Constant* LLVMContext::getConstantExprShl(Constant* C1, Constant* C2) {
409   return getConstantExpr(Instruction::Shl, C1, C2);
410 }
411
412 Constant* LLVMContext::getConstantExprLShr(Constant* C1, Constant* C2) {
413   return getConstantExpr(Instruction::LShr, C1, C2);
414 }
415
416 Constant* LLVMContext::getConstantExprAShr(Constant* C1, Constant* C2) {
417   return getConstantExpr(Instruction::AShr, C1, C2);
418 }
419
420 Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
421                                                     Constant* const* IdxList, 
422                                                     unsigned NumIdx) {
423   return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
424 }
425
426 Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
427                                                     Value* const* IdxList, 
428                                                     unsigned NumIdx) {
429   return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
430 }
431
432 Constant* LLVMContext::getConstantExprExtractElement(Constant* Vec,
433                                                      Constant* Idx) {
434   return ConstantExpr::getExtractElement(Vec, Idx);
435 }
436
437 Constant* LLVMContext::getConstantExprInsertElement(Constant* Vec,
438                                                     Constant* Elt,
439                                                     Constant* Idx) {
440   return ConstantExpr::getInsertElement(Vec, Elt, Idx);
441 }
442
443 Constant* LLVMContext::getConstantExprShuffleVector(Constant* V1, Constant* V2,
444                                                     Constant* Mask) {
445   return ConstantExpr::getShuffleVector(V1, V2, Mask);
446 }
447
448 Constant* LLVMContext::getConstantExprExtractValue(Constant* Agg,
449                                                    const unsigned* IdxList, 
450                                                    unsigned NumIdx) {
451   return ConstantExpr::getExtractValue(Agg, IdxList, NumIdx);
452 }
453
454 Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val,
455                                                   const unsigned* IdxList,
456                                                   unsigned NumIdx) {
457   return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
458 }
459
460 Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) {
461   // sizeof is implemented as: (i64) gep (Ty*)null, 1
462   Constant *GEPIdx = getConstantInt(Type::Int32Ty, 1);
463   Constant *GEP = getConstantExprGetElementPtr(
464                             getNullValue(getPointerTypeUnqual(Ty)), &GEPIdx, 1);
465   return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
466 }
467
468 Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
469   if (const VectorType *PTy = dyn_cast<VectorType>(Ty))
470     if (PTy->getElementType()->isFloatingPoint()) {
471       std::vector<Constant*> zeros(PTy->getNumElements(),
472                            getConstantFPNegativeZero(PTy->getElementType()));
473       return getConstantVector(PTy, zeros);
474     }
475
476   if (Ty->isFloatingPoint()) 
477     return getConstantFPNegativeZero(Ty);
478
479   return getNullValue(Ty);
480 }
481
482
483 // ConstantFP accessors.
484 ConstantFP* LLVMContext::getConstantFP(const APFloat& V) {
485   return pImpl->getConstantFP(V);
486 }
487
488 static const fltSemantics *TypeToFloatSemantics(const Type *Ty) {
489   if (Ty == Type::FloatTy)
490     return &APFloat::IEEEsingle;
491   if (Ty == Type::DoubleTy)
492     return &APFloat::IEEEdouble;
493   if (Ty == Type::X86_FP80Ty)
494     return &APFloat::x87DoubleExtended;
495   else if (Ty == Type::FP128Ty)
496     return &APFloat::IEEEquad;
497   
498   assert(Ty == Type::PPC_FP128Ty && "Unknown FP format");
499   return &APFloat::PPCDoubleDouble;
500 }
501
502 /// get() - This returns a constant fp for the specified value in the
503 /// specified type.  This should only be used for simple constant values like
504 /// 2.0/1.0 etc, that are known-valid both as double and as the target format.
505 Constant* LLVMContext::getConstantFP(const Type* Ty, double V) {
506   APFloat FV(V);
507   bool ignored;
508   FV.convert(*TypeToFloatSemantics(Ty->getScalarType()),
509              APFloat::rmNearestTiesToEven, &ignored);
510   Constant *C = getConstantFP(FV);
511
512   // For vectors, broadcast the value.
513   if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
514     return
515       getConstantVector(std::vector<Constant *>(VTy->getNumElements(), C));
516
517   return C;
518 }
519
520 ConstantFP* LLVMContext::getConstantFPNegativeZero(const Type* Ty) {
521   APFloat apf = cast <ConstantFP>(getNullValue(Ty))->getValueAPF();
522   apf.changeSign();
523   return getConstantFP(apf);
524 }
525
526
527 // ConstantVector accessors.
528 Constant* LLVMContext::getConstantVector(const VectorType* T,
529                             const std::vector<Constant*>& V) {
530   return ConstantVector::get(T, V);
531 }
532
533 Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& V) {
534   assert(!V.empty() && "Cannot infer type if V is empty");
535   return getConstantVector(getVectorType(V.front()->getType(),V.size()), V);
536 }
537
538 Constant* LLVMContext::getConstantVector(Constant* const* Vals,
539                                          unsigned NumVals) {
540   // FIXME: make this the primary ctor method.
541   return getConstantVector(std::vector<Constant*>(Vals, Vals+NumVals));
542 }
543
544 // MDNode accessors
545 MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
546   return pImpl->getMDNode(Vals, NumVals);
547 }
548
549 // MDString accessors
550 MDString* LLVMContext::getMDString(const char *StrBegin, const char *StrEnd) {
551   return pImpl->getMDString(StrBegin, StrEnd);
552 }
553
554 MDString* LLVMContext::getMDString(const std::string &Str) {
555   return getMDString(Str.data(), Str.data()+Str.size());
556 }
557
558 // FunctionType accessors
559 FunctionType* LLVMContext::getFunctionType(const Type* Result, bool isVarArg) {
560   return FunctionType::get(Result, isVarArg);
561 }
562
563 FunctionType* LLVMContext::getFunctionType(const Type* Result,
564                                          const std::vector<const Type*>& Params,
565                                          bool isVarArg) {
566   return FunctionType::get(Result, Params, isVarArg);
567 }
568                                 
569 // IntegerType accessors
570 const IntegerType* LLVMContext::getIntegerType(unsigned NumBits) {
571   return IntegerType::get(NumBits);
572 }
573   
574 // OpaqueType accessors
575 OpaqueType* LLVMContext::getOpaqueType() {
576   return OpaqueType::get();
577 }
578
579 // StructType accessors
580 StructType* LLVMContext::getStructType(bool isPacked) {
581   return StructType::get(isPacked);
582 }
583
584 StructType* LLVMContext::getStructType(const std::vector<const Type*>& Params,
585                                        bool isPacked) {
586   return StructType::get(Params, isPacked);
587 }
588
589 StructType *LLVMContext::getStructType(const Type *type, ...) {
590   va_list ap;
591   std::vector<const llvm::Type*> StructFields;
592   va_start(ap, type);
593   while (type) {
594     StructFields.push_back(type);
595     type = va_arg(ap, llvm::Type*);
596   }
597   return StructType::get(StructFields);
598 }
599
600 // ArrayType accessors
601 ArrayType* LLVMContext::getArrayType(const Type* ElementType,
602                                      uint64_t NumElements) {
603   return ArrayType::get(ElementType, NumElements);
604 }
605   
606 // PointerType accessors
607 PointerType* LLVMContext::getPointerType(const Type* ElementType,
608                                          unsigned AddressSpace) {
609   return PointerType::get(ElementType, AddressSpace);
610 }
611
612 PointerType* LLVMContext::getPointerTypeUnqual(const Type* ElementType) {
613   return PointerType::getUnqual(ElementType);
614 }
615   
616 // VectorType accessors
617 VectorType* LLVMContext::getVectorType(const Type* ElementType,
618                                        unsigned NumElements) {
619   return VectorType::get(ElementType, NumElements);
620 }
621
622 VectorType* LLVMContext::getVectorTypeInteger(const VectorType* VTy) {
623   return VectorType::getInteger(VTy);  
624 }
625
626 VectorType* LLVMContext::getVectorTypeExtendedElement(const VectorType* VTy) {
627   return VectorType::getExtendedElementVectorType(VTy);
628 }
629
630 VectorType* LLVMContext::getVectorTypeTruncatedElement(const VectorType* VTy) {
631   return VectorType::getTruncatedElementVectorType(VTy);
632 }
633
634 const Type* LLVMContext::makeCmpResultType(const Type* opnd_type) {
635   if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) {
636     return getVectorType(Type::Int1Ty, vt->getNumElements());
637   }
638   return Type::Int1Ty;
639 }
640
641 void LLVMContext::erase(MDString *M) {
642   pImpl->erase(M);
643 }
644
645 void LLVMContext::erase(MDNode *M) {
646   pImpl->erase(M);
647 }