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