Move the ConstantStruct factory methods over to LLVMContext.
[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()) { }
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 ConstantInt::get(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       ConstantVector::get(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   return ConstantArray::get(T, Vals, NumVals);
180 }
181
182 /// ConstantArray::get(const string&) - Return an array that is initialized to
183 /// contain the specified string.  If length is zero then a null terminator is 
184 /// added to the specified string so that it may be used in a natural way. 
185 /// Otherwise, the length parameter specifies how much of the string to use 
186 /// and it won't be null terminated.
187 ///
188 Constant* LLVMContext::getConstantArray(const std::string& Str,
189                                         bool AddNull) {
190   std::vector<Constant*> ElementVals;
191   for (unsigned i = 0; i < Str.length(); ++i)
192     ElementVals.push_back(getConstantInt(Type::Int8Ty, Str[i]));
193
194   // Add a null terminator to the string...
195   if (AddNull) {
196     ElementVals.push_back(getConstantInt(Type::Int8Ty, 0));
197   }
198
199   ArrayType *ATy = getArrayType(Type::Int8Ty, ElementVals.size());
200   return getConstantArray(ATy, ElementVals);
201 }
202
203
204 // ConstantExpr accessors.
205 Constant* LLVMContext::getConstantExpr(unsigned Opcode, Constant* C1,
206                                        Constant* C2) {
207   return ConstantExpr::get(Opcode, C1, C2);
208 }
209
210 Constant* LLVMContext::getConstantExprTrunc(Constant* C, const Type* Ty) {
211   return ConstantExpr::getTrunc(C, Ty);
212 }
213
214 Constant* LLVMContext::getConstantExprSExt(Constant* C, const Type* Ty) {
215   return ConstantExpr::getSExt(C, Ty);
216 }
217
218 Constant* LLVMContext::getConstantExprZExt(Constant* C, const Type* Ty) {
219   return ConstantExpr::getZExt(C, Ty);  
220 }
221
222 Constant* LLVMContext::getConstantExprFPTrunc(Constant* C, const Type* Ty) {
223   return ConstantExpr::getFPTrunc(C, Ty);
224 }
225
226 Constant* LLVMContext::getConstantExprFPExtend(Constant* C, const Type* Ty) {
227   return ConstantExpr::getFPExtend(C, Ty);
228 }
229
230 Constant* LLVMContext::getConstantExprUIToFP(Constant* C, const Type* Ty) {
231   return ConstantExpr::getUIToFP(C, Ty);
232 }
233
234 Constant* LLVMContext::getConstantExprSIToFP(Constant* C, const Type* Ty) {
235   return ConstantExpr::getSIToFP(C, Ty);
236 }
237
238 Constant* LLVMContext::getConstantExprFPToUI(Constant* C, const Type* Ty) {
239   return ConstantExpr::getFPToUI(C, Ty);
240 }
241
242 Constant* LLVMContext::getConstantExprFPToSI(Constant* C, const Type* Ty) {
243   return ConstantExpr::getFPToSI(C, Ty);
244 }
245
246 Constant* LLVMContext::getConstantExprPtrToInt(Constant* C, const Type* Ty) {
247   return ConstantExpr::getPtrToInt(C, Ty);
248 }
249
250 Constant* LLVMContext::getConstantExprIntToPtr(Constant* C, const Type* Ty) {
251   return ConstantExpr::getIntToPtr(C, Ty);
252 }
253
254 Constant* LLVMContext::getConstantExprBitCast(Constant* C, const Type* Ty) {
255   return ConstantExpr::getBitCast(C, Ty);
256 }
257
258 Constant* LLVMContext::getConstantExprCast(unsigned ops, Constant* C,
259                                            const Type* Ty) {
260   return ConstantExpr::getCast(ops, C, Ty);
261 }
262
263 Constant* LLVMContext::getConstantExprZExtOrBitCast(Constant* C,
264                                                     const Type* Ty) {
265   return ConstantExpr::getZExtOrBitCast(C, Ty);
266 }
267
268 Constant* LLVMContext::getConstantExprSExtOrBitCast(Constant* C,
269                                                     const Type* Ty) {
270   return ConstantExpr::getSExtOrBitCast(C, Ty);
271 }
272
273 Constant* LLVMContext::getConstantExprTruncOrBitCast(Constant* C,
274                                                      const Type* Ty) {
275   return ConstantExpr::getTruncOrBitCast(C, Ty);  
276 }
277
278 Constant* LLVMContext::getConstantExprPointerCast(Constant* C, const Type* Ty) {
279   return ConstantExpr::getPointerCast(C, Ty);
280 }
281
282 Constant* LLVMContext::getConstantExprIntegerCast(Constant* C, const Type* Ty,
283                                                   bool isSigned) {
284   return ConstantExpr::getIntegerCast(C, Ty, isSigned);
285 }
286
287 Constant* LLVMContext::getConstantExprFPCast(Constant* C, const Type* Ty) {
288   return ConstantExpr::getFPCast(C, Ty);
289 }
290
291 Constant* LLVMContext::getConstantExprSelect(Constant* C, Constant* V1,
292                                              Constant* V2) {
293   return ConstantExpr::getSelect(C, V1, V2);
294 }
295
296 Constant* LLVMContext::getConstantExprAlignOf(const Type* Ty) {
297   // alignof is implemented as: (i64) gep ({i8,Ty}*)null, 0, 1
298   const Type *AligningTy = getStructType(Type::Int8Ty, Ty, NULL);
299   Constant *NullPtr = getNullValue(AligningTy->getPointerTo());
300   Constant *Zero = getConstantInt(Type::Int32Ty, 0);
301   Constant *One = getConstantInt(Type::Int32Ty, 1);
302   Constant *Indices[2] = { Zero, One };
303   Constant *GEP = getConstantExprGetElementPtr(NullPtr, Indices, 2);
304   return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int32Ty);
305 }
306
307 Constant* LLVMContext::getConstantExprCompare(unsigned short pred,
308                                  Constant* C1, Constant* C2) {
309   return ConstantExpr::getCompare(pred, C1, C2);
310 }
311
312 Constant* LLVMContext::getConstantExprNeg(Constant* C) {
313   // API compatibility: Adjust integer opcodes to floating-point opcodes.
314   if (C->getType()->isFPOrFPVector())
315     return getConstantExprFNeg(C);
316   assert(C->getType()->isIntOrIntVector() &&
317          "Cannot NEG a nonintegral value!");
318   return getConstantExpr(Instruction::Sub,
319              getZeroValueForNegation(C->getType()),
320              C);
321 }
322
323 Constant* LLVMContext::getConstantExprFNeg(Constant* C) {
324   assert(C->getType()->isFPOrFPVector() &&
325          "Cannot FNEG a non-floating-point value!");
326   return getConstantExpr(Instruction::FSub,
327              getZeroValueForNegation(C->getType()),
328              C);
329 }
330
331 Constant* LLVMContext::getConstantExprNot(Constant* C) {
332   assert(C->getType()->isIntOrIntVector() &&
333          "Cannot NOT a nonintegral value!");
334   return getConstantExpr(Instruction::Xor, C, getAllOnesValue(C->getType()));
335 }
336
337 Constant* LLVMContext::getConstantExprAdd(Constant* C1, Constant* C2) {
338   return getConstantExpr(Instruction::Add, C1, C2);
339 }
340
341 Constant* LLVMContext::getConstantExprFAdd(Constant* C1, Constant* C2) {
342   return getConstantExpr(Instruction::FAdd, C1, C2);
343 }
344
345 Constant* LLVMContext::getConstantExprSub(Constant* C1, Constant* C2) {
346   return getConstantExpr(Instruction::Sub, C1, C2);
347 }
348
349 Constant* LLVMContext::getConstantExprFSub(Constant* C1, Constant* C2) {
350   return getConstantExpr(Instruction::FSub, C1, C2);
351 }
352
353 Constant* LLVMContext::getConstantExprMul(Constant* C1, Constant* C2) {
354   return getConstantExpr(Instruction::Mul, C1, C2);
355 }
356
357 Constant* LLVMContext::getConstantExprFMul(Constant* C1, Constant* C2) {
358   return getConstantExpr(Instruction::FMul, C1, C2);
359 }
360
361 Constant* LLVMContext::getConstantExprUDiv(Constant* C1, Constant* C2) {
362   return getConstantExpr(Instruction::UDiv, C1, C2);
363 }
364
365 Constant* LLVMContext::getConstantExprSDiv(Constant* C1, Constant* C2) {
366   return getConstantExpr(Instruction::SDiv, C1, C2);
367 }
368
369 Constant* LLVMContext::getConstantExprFDiv(Constant* C1, Constant* C2) {
370   return getConstantExpr(Instruction::FDiv, C1, C2);
371 }
372
373 Constant* LLVMContext::getConstantExprURem(Constant* C1, Constant* C2) {
374   return getConstantExpr(Instruction::URem, C1, C2);
375 }
376
377 Constant* LLVMContext::getConstantExprSRem(Constant* C1, Constant* C2) {
378   return getConstantExpr(Instruction::SRem, C1, C2);
379 }
380
381 Constant* LLVMContext::getConstantExprFRem(Constant* C1, Constant* C2) {
382   return getConstantExpr(Instruction::FRem, C1, C2);
383 }
384
385 Constant* LLVMContext::getConstantExprAnd(Constant* C1, Constant* C2) {
386   return getConstantExpr(Instruction::And, C1, C2);
387 }
388
389 Constant* LLVMContext::getConstantExprOr(Constant* C1, Constant* C2) {
390   return getConstantExpr(Instruction::Or, C1, C2);
391 }
392
393 Constant* LLVMContext::getConstantExprXor(Constant* C1, Constant* C2) {
394   return getConstantExpr(Instruction::Xor, C1, C2);
395 }
396
397 Constant* LLVMContext::getConstantExprICmp(unsigned short pred, Constant* LHS,
398                               Constant* RHS) {
399   return ConstantExpr::getICmp(pred, LHS, RHS);
400 }
401
402 Constant* LLVMContext::getConstantExprFCmp(unsigned short pred, Constant* LHS,
403                               Constant* RHS) {
404   return ConstantExpr::getFCmp(pred, LHS, RHS);
405 }
406
407 Constant* LLVMContext::getConstantExprShl(Constant* C1, Constant* C2) {
408   return getConstantExpr(Instruction::Shl, C1, C2);
409 }
410
411 Constant* LLVMContext::getConstantExprLShr(Constant* C1, Constant* C2) {
412   return getConstantExpr(Instruction::LShr, C1, C2);
413 }
414
415 Constant* LLVMContext::getConstantExprAShr(Constant* C1, Constant* C2) {
416   return getConstantExpr(Instruction::AShr, C1, C2);
417 }
418
419 Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
420                                                     Constant* const* IdxList, 
421                                                     unsigned NumIdx) {
422   return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
423 }
424
425 Constant* LLVMContext::getConstantExprGetElementPtr(Constant* C,
426                                                     Value* const* IdxList, 
427                                                     unsigned NumIdx) {
428   return ConstantExpr::getGetElementPtr(C, IdxList, NumIdx);
429 }
430
431 Constant* LLVMContext::getConstantExprExtractElement(Constant* Vec,
432                                                      Constant* Idx) {
433   return ConstantExpr::getExtractElement(Vec, Idx);
434 }
435
436 Constant* LLVMContext::getConstantExprInsertElement(Constant* Vec,
437                                                     Constant* Elt,
438                                                     Constant* Idx) {
439   return ConstantExpr::getInsertElement(Vec, Elt, Idx);
440 }
441
442 Constant* LLVMContext::getConstantExprShuffleVector(Constant* V1, Constant* V2,
443                                                     Constant* Mask) {
444   return ConstantExpr::getShuffleVector(V1, V2, Mask);
445 }
446
447 Constant* LLVMContext::getConstantExprExtractValue(Constant* Agg,
448                                                    const unsigned* IdxList, 
449                                                    unsigned NumIdx) {
450   return ConstantExpr::getExtractValue(Agg, IdxList, NumIdx);
451 }
452
453 Constant* LLVMContext::getConstantExprInsertValue(Constant* Agg, Constant* Val,
454                                                   const unsigned* IdxList,
455                                                   unsigned NumIdx) {
456   return ConstantExpr::getInsertValue(Agg, Val, IdxList, NumIdx);
457 }
458
459 Constant* LLVMContext::getConstantExprSizeOf(const Type* Ty) {
460   // sizeof is implemented as: (i64) gep (Ty*)null, 1
461   Constant *GEPIdx = getConstantInt(Type::Int32Ty, 1);
462   Constant *GEP = getConstantExprGetElementPtr(
463                             getNullValue(getPointerTypeUnqual(Ty)), &GEPIdx, 1);
464   return getConstantExprCast(Instruction::PtrToInt, GEP, Type::Int64Ty);
465 }
466
467 Constant* LLVMContext::getZeroValueForNegation(const Type* Ty) {
468   if (const VectorType *PTy = dyn_cast<VectorType>(Ty))
469     if (PTy->getElementType()->isFloatingPoint()) {
470       std::vector<Constant*> zeros(PTy->getNumElements(),
471                            getConstantFPNegativeZero(PTy->getElementType()));
472       return getConstantVector(PTy, zeros);
473     }
474
475   if (Ty->isFloatingPoint()) 
476     return getConstantFPNegativeZero(Ty);
477
478   return getNullValue(Ty);
479 }
480
481
482 // ConstantFP accessors.
483 ConstantFP* LLVMContext::getConstantFP(const APFloat& V) {
484   return ConstantFP::get(V);
485 }
486
487 static const fltSemantics *TypeToFloatSemantics(const Type *Ty) {
488   if (Ty == Type::FloatTy)
489     return &APFloat::IEEEsingle;
490   if (Ty == Type::DoubleTy)
491     return &APFloat::IEEEdouble;
492   if (Ty == Type::X86_FP80Ty)
493     return &APFloat::x87DoubleExtended;
494   else if (Ty == Type::FP128Ty)
495     return &APFloat::IEEEquad;
496   
497   assert(Ty == Type::PPC_FP128Ty && "Unknown FP format");
498   return &APFloat::PPCDoubleDouble;
499 }
500
501 /// get() - This returns a constant fp for the specified value in the
502 /// specified type.  This should only be used for simple constant values like
503 /// 2.0/1.0 etc, that are known-valid both as double and as the target format.
504 Constant* LLVMContext::getConstantFP(const Type* Ty, double V) {
505   APFloat FV(V);
506   bool ignored;
507   FV.convert(*TypeToFloatSemantics(Ty->getScalarType()),
508              APFloat::rmNearestTiesToEven, &ignored);
509   Constant *C = getConstantFP(FV);
510
511   // For vectors, broadcast the value.
512   if (const VectorType *VTy = dyn_cast<VectorType>(Ty))
513     return
514       getConstantVector(std::vector<Constant *>(VTy->getNumElements(), C));
515
516   return C;
517 }
518
519 ConstantFP* LLVMContext::getConstantFPNegativeZero(const Type* Ty) {
520   APFloat apf = cast <ConstantFP>(getNullValue(Ty))->getValueAPF();
521   apf.changeSign();
522   return getConstantFP(apf);
523 }
524
525
526 // ConstantVector accessors.
527 Constant* LLVMContext::getConstantVector(const VectorType* T,
528                             const std::vector<Constant*>& V) {
529   return ConstantVector::get(T, V);
530 }
531
532 Constant* LLVMContext::getConstantVector(const std::vector<Constant*>& V) {
533   return ConstantVector::get(V);
534 }
535
536 Constant* LLVMContext::getConstantVector(Constant* const* Vals,
537                                          unsigned NumVals) {
538   return ConstantVector::get(Vals, NumVals);
539 }
540
541 // MDNode accessors
542 MDNode* LLVMContext::getMDNode(Value* const* Vals, unsigned NumVals) {
543   return MDNode::get(Vals, NumVals);
544 }
545
546 // MDString accessors
547 MDString* LLVMContext::getMDString(const char *StrBegin, const char *StrEnd) {
548   return MDString::get(StrBegin, StrEnd);
549 }
550
551 MDString* LLVMContext::getMDString(const std::string &Str) {
552   return MDString::get(Str);
553 }
554
555 // FunctionType accessors
556 FunctionType* LLVMContext::getFunctionType(const Type* Result, bool isVarArg) {
557   return FunctionType::get(Result, isVarArg);
558 }
559
560 FunctionType* LLVMContext::getFunctionType(const Type* Result,
561                                          const std::vector<const Type*>& Params,
562                                          bool isVarArg) {
563   return FunctionType::get(Result, Params, isVarArg);
564 }
565                                 
566 // IntegerType accessors
567 const IntegerType* LLVMContext::getIntegerType(unsigned NumBits) {
568   return IntegerType::get(NumBits);
569 }
570   
571 // OpaqueType accessors
572 OpaqueType* LLVMContext::getOpaqueType() {
573   return OpaqueType::get();
574 }
575
576 // StructType accessors
577 StructType* LLVMContext::getStructType(bool isPacked) {
578   return StructType::get(isPacked);
579 }
580
581 StructType* LLVMContext::getStructType(const std::vector<const Type*>& Params,
582                                        bool isPacked) {
583   return StructType::get(Params, isPacked);
584 }
585
586 StructType *LLVMContext::getStructType(const Type *type, ...) {
587   va_list ap;
588   std::vector<const llvm::Type*> StructFields;
589   va_start(ap, type);
590   while (type) {
591     StructFields.push_back(type);
592     type = va_arg(ap, llvm::Type*);
593   }
594   return StructType::get(StructFields);
595 }
596
597 // ArrayType accessors
598 ArrayType* LLVMContext::getArrayType(const Type* ElementType,
599                                      uint64_t NumElements) {
600   return ArrayType::get(ElementType, NumElements);
601 }
602   
603 // PointerType accessors
604 PointerType* LLVMContext::getPointerType(const Type* ElementType,
605                                          unsigned AddressSpace) {
606   return PointerType::get(ElementType, AddressSpace);
607 }
608
609 PointerType* LLVMContext::getPointerTypeUnqual(const Type* ElementType) {
610   return PointerType::getUnqual(ElementType);
611 }
612   
613 // VectorType accessors
614 VectorType* LLVMContext::getVectorType(const Type* ElementType,
615                                        unsigned NumElements) {
616   return VectorType::get(ElementType, NumElements);
617 }
618
619 VectorType* LLVMContext::getVectorTypeInteger(const VectorType* VTy) {
620   return VectorType::getInteger(VTy);  
621 }
622
623 VectorType* LLVMContext::getVectorTypeExtendedElement(const VectorType* VTy) {
624   return VectorType::getExtendedElementVectorType(VTy);
625 }
626
627 VectorType* LLVMContext::getVectorTypeTruncatedElement(const VectorType* VTy) {
628   return VectorType::getTruncatedElementVectorType(VTy);
629 }
630
631 const Type* LLVMContext::makeCmpResultType(const Type* opnd_type) {
632   if (const VectorType* vt = dyn_cast<const VectorType>(opnd_type)) {
633     return getVectorType(Type::Int1Ty, vt->getNumElements());
634   }
635   return Type::Int1Ty;
636 }