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