1 //===-- Core.cpp ----------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements the common infrastructure (including the C bindings)
11 // for libLLVMCore.a, which implements the LLVM intermediate representation.
13 //===----------------------------------------------------------------------===//
15 #include "llvm-c/Core.h"
16 #include "llvm/Bitcode/ReaderWriter.h"
17 #include "llvm/Constants.h"
18 #include "llvm/DerivedTypes.h"
19 #include "llvm/GlobalVariable.h"
20 #include "llvm/GlobalAlias.h"
21 #include "llvm/LLVMContext.h"
22 #include "llvm/InlineAsm.h"
23 #include "llvm/IntrinsicInst.h"
24 #include "llvm/PassManager.h"
25 #include "llvm/Support/CallSite.h"
26 #include "llvm/Support/Debug.h"
27 #include "llvm/Support/ErrorHandling.h"
28 #include "llvm/Support/MemoryBuffer.h"
29 #include "llvm/Support/raw_ostream.h"
30 #include "llvm/Support/system_error.h"
37 void llvm::initializeCore(PassRegistry &Registry) {
38 initializeDominatorTreePass(Registry);
39 initializePrintModulePassPass(Registry);
40 initializePrintFunctionPassPass(Registry);
41 initializeVerifierPass(Registry);
42 initializePreVerifierPass(Registry);
45 void LLVMInitializeCore(LLVMPassRegistryRef R) {
46 initializeCore(*unwrap(R));
49 /*===-- Error handling ----------------------------------------------------===*/
51 void LLVMDisposeMessage(char *Message) {
56 /*===-- Operations on contexts --------------------------------------------===*/
58 LLVMContextRef LLVMContextCreate() {
59 return wrap(new LLVMContext());
62 LLVMContextRef LLVMGetGlobalContext() {
63 return wrap(&getGlobalContext());
66 void LLVMContextDispose(LLVMContextRef C) {
70 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
72 return unwrap(C)->getMDKindID(StringRef(Name, SLen));
75 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen) {
76 return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);
80 /*===-- Operations on modules ---------------------------------------------===*/
82 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
83 return wrap(new Module(ModuleID, getGlobalContext()));
86 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
88 return wrap(new Module(ModuleID, *unwrap(C)));
91 void LLVMDisposeModule(LLVMModuleRef M) {
95 /*--.. Data layout .........................................................--*/
96 const char * LLVMGetDataLayout(LLVMModuleRef M) {
97 return unwrap(M)->getDataLayout().c_str();
100 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple) {
101 unwrap(M)->setDataLayout(Triple);
104 /*--.. Target triple .......................................................--*/
105 const char * LLVMGetTarget(LLVMModuleRef M) {
106 return unwrap(M)->getTargetTriple().c_str();
109 void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
110 unwrap(M)->setTargetTriple(Triple);
113 void LLVMDumpModule(LLVMModuleRef M) {
117 /*--.. Operations on inline assembler ......................................--*/
118 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) {
119 unwrap(M)->setModuleInlineAsm(StringRef(Asm));
123 /*--.. Operations on module contexts ......................................--*/
124 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M) {
125 return wrap(&unwrap(M)->getContext());
129 /*===-- Operations on types -----------------------------------------------===*/
131 /*--.. Operations on all types (mostly) ....................................--*/
133 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) {
134 switch (unwrap(Ty)->getTypeID()) {
136 assert(false && "Unhandled TypeID.");
138 return LLVMVoidTypeKind;
140 return LLVMHalfTypeKind;
141 case Type::FloatTyID:
142 return LLVMFloatTypeKind;
143 case Type::DoubleTyID:
144 return LLVMDoubleTypeKind;
145 case Type::X86_FP80TyID:
146 return LLVMX86_FP80TypeKind;
147 case Type::FP128TyID:
148 return LLVMFP128TypeKind;
149 case Type::PPC_FP128TyID:
150 return LLVMPPC_FP128TypeKind;
151 case Type::LabelTyID:
152 return LLVMLabelTypeKind;
153 case Type::MetadataTyID:
154 return LLVMMetadataTypeKind;
155 case Type::IntegerTyID:
156 return LLVMIntegerTypeKind;
157 case Type::FunctionTyID:
158 return LLVMFunctionTypeKind;
159 case Type::StructTyID:
160 return LLVMStructTypeKind;
161 case Type::ArrayTyID:
162 return LLVMArrayTypeKind;
163 case Type::PointerTyID:
164 return LLVMPointerTypeKind;
165 case Type::VectorTyID:
166 return LLVMVectorTypeKind;
167 case Type::X86_MMXTyID:
168 return LLVMX86_MMXTypeKind;
172 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty)
174 return unwrap(Ty)->isSized();
177 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty) {
178 return wrap(&unwrap(Ty)->getContext());
181 /*--.. Operations on integer types .........................................--*/
183 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C) {
184 return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
186 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C) {
187 return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
189 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C) {
190 return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
192 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C) {
193 return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
195 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C) {
196 return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
198 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits) {
199 return wrap(IntegerType::get(*unwrap(C), NumBits));
202 LLVMTypeRef LLVMInt1Type(void) {
203 return LLVMInt1TypeInContext(LLVMGetGlobalContext());
205 LLVMTypeRef LLVMInt8Type(void) {
206 return LLVMInt8TypeInContext(LLVMGetGlobalContext());
208 LLVMTypeRef LLVMInt16Type(void) {
209 return LLVMInt16TypeInContext(LLVMGetGlobalContext());
211 LLVMTypeRef LLVMInt32Type(void) {
212 return LLVMInt32TypeInContext(LLVMGetGlobalContext());
214 LLVMTypeRef LLVMInt64Type(void) {
215 return LLVMInt64TypeInContext(LLVMGetGlobalContext());
217 LLVMTypeRef LLVMIntType(unsigned NumBits) {
218 return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
221 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
222 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
225 /*--.. Operations on real types ............................................--*/
227 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C) {
228 return (LLVMTypeRef) Type::getHalfTy(*unwrap(C));
230 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C) {
231 return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
233 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C) {
234 return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
236 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C) {
237 return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
239 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C) {
240 return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
242 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C) {
243 return (LLVMTypeRef) Type::getPPC_FP128Ty(*unwrap(C));
245 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C) {
246 return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
249 LLVMTypeRef LLVMHalfType(void) {
250 return LLVMHalfTypeInContext(LLVMGetGlobalContext());
252 LLVMTypeRef LLVMFloatType(void) {
253 return LLVMFloatTypeInContext(LLVMGetGlobalContext());
255 LLVMTypeRef LLVMDoubleType(void) {
256 return LLVMDoubleTypeInContext(LLVMGetGlobalContext());
258 LLVMTypeRef LLVMX86FP80Type(void) {
259 return LLVMX86FP80TypeInContext(LLVMGetGlobalContext());
261 LLVMTypeRef LLVMFP128Type(void) {
262 return LLVMFP128TypeInContext(LLVMGetGlobalContext());
264 LLVMTypeRef LLVMPPCFP128Type(void) {
265 return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
267 LLVMTypeRef LLVMX86MMXType(void) {
268 return LLVMX86MMXTypeInContext(LLVMGetGlobalContext());
271 /*--.. Operations on function types ........................................--*/
273 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
274 LLVMTypeRef *ParamTypes, unsigned ParamCount,
276 ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
277 return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
280 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
281 return unwrap<FunctionType>(FunctionTy)->isVarArg();
284 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy) {
285 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
288 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
289 return unwrap<FunctionType>(FunctionTy)->getNumParams();
292 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
293 FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
294 for (FunctionType::param_iterator I = Ty->param_begin(),
295 E = Ty->param_end(); I != E; ++I)
299 /*--.. Operations on struct types ..........................................--*/
301 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
302 unsigned ElementCount, LLVMBool Packed) {
303 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
304 return wrap(StructType::get(*unwrap(C), Tys, Packed != 0));
307 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
308 unsigned ElementCount, LLVMBool Packed) {
309 return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
310 ElementCount, Packed);
313 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name)
315 return wrap(StructType::create(*unwrap(C), Name));
318 const char *LLVMGetStructName(LLVMTypeRef Ty)
320 StructType *Type = unwrap<StructType>(Ty);
321 if (!Type->hasName())
323 return Type->getName().data();
326 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
327 unsigned ElementCount, LLVMBool Packed) {
328 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
329 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
332 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
333 return unwrap<StructType>(StructTy)->getNumElements();
336 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest) {
337 StructType *Ty = unwrap<StructType>(StructTy);
338 for (StructType::element_iterator I = Ty->element_begin(),
339 E = Ty->element_end(); I != E; ++I)
343 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy) {
344 return unwrap<StructType>(StructTy)->isPacked();
347 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy) {
348 return unwrap<StructType>(StructTy)->isOpaque();
351 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) {
352 return wrap(unwrap(M)->getTypeByName(Name));
355 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
357 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
358 return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
361 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
362 return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
365 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
366 return wrap(VectorType::get(unwrap(ElementType), ElementCount));
369 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) {
370 return wrap(unwrap<SequentialType>(Ty)->getElementType());
373 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
374 return unwrap<ArrayType>(ArrayTy)->getNumElements();
377 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) {
378 return unwrap<PointerType>(PointerTy)->getAddressSpace();
381 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
382 return unwrap<VectorType>(VectorTy)->getNumElements();
385 /*--.. Operations on other types ...........................................--*/
387 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C) {
388 return wrap(Type::getVoidTy(*unwrap(C)));
390 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C) {
391 return wrap(Type::getLabelTy(*unwrap(C)));
394 LLVMTypeRef LLVMVoidType(void) {
395 return LLVMVoidTypeInContext(LLVMGetGlobalContext());
397 LLVMTypeRef LLVMLabelType(void) {
398 return LLVMLabelTypeInContext(LLVMGetGlobalContext());
401 /*===-- Operations on values ----------------------------------------------===*/
403 /*--.. Operations on all values ............................................--*/
405 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) {
406 return wrap(unwrap(Val)->getType());
409 const char *LLVMGetValueName(LLVMValueRef Val) {
410 return unwrap(Val)->getName().data();
413 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
414 unwrap(Val)->setName(Name);
417 void LLVMDumpValue(LLVMValueRef Val) {
421 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
422 unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
425 int LLVMHasMetadata(LLVMValueRef Inst) {
426 return unwrap<Instruction>(Inst)->hasMetadata();
429 LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID) {
430 return wrap(unwrap<Instruction>(Inst)->getMetadata(KindID));
433 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef MD) {
434 unwrap<Instruction>(Inst)->setMetadata(KindID, MD? unwrap<MDNode>(MD) : NULL);
437 /*--.. Conversion functions ................................................--*/
439 #define LLVM_DEFINE_VALUE_CAST(name) \
440 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
441 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
444 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST)
446 /*--.. Operations on Uses ..................................................--*/
447 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val) {
448 Value *V = unwrap(Val);
449 Value::use_iterator I = V->use_begin();
450 if (I == V->use_end())
452 return wrap(&(I.getUse()));
455 LLVMUseRef LLVMGetNextUse(LLVMUseRef U) {
456 Use *Next = unwrap(U)->getNext();
462 LLVMValueRef LLVMGetUser(LLVMUseRef U) {
463 return wrap(unwrap(U)->getUser());
466 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U) {
467 return wrap(unwrap(U)->get());
470 /*--.. Operations on Users .................................................--*/
471 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) {
472 Value *V = unwrap(Val);
473 if (MDNode *MD = dyn_cast<MDNode>(V))
474 return wrap(MD->getOperand(Index));
475 return wrap(cast<User>(V)->getOperand(Index));
478 void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
479 unwrap<User>(Val)->setOperand(Index, unwrap(Op));
482 int LLVMGetNumOperands(LLVMValueRef Val) {
483 Value *V = unwrap(Val);
484 if (MDNode *MD = dyn_cast<MDNode>(V))
485 return MD->getNumOperands();
486 return cast<User>(V)->getNumOperands();
489 /*--.. Operations on constants of any type .................................--*/
491 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
492 return wrap(Constant::getNullValue(unwrap(Ty)));
495 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) {
496 return wrap(Constant::getAllOnesValue(unwrap(Ty)));
499 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
500 return wrap(UndefValue::get(unwrap(Ty)));
503 LLVMBool LLVMIsConstant(LLVMValueRef Ty) {
504 return isa<Constant>(unwrap(Ty));
507 LLVMBool LLVMIsNull(LLVMValueRef Val) {
508 if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
509 return C->isNullValue();
513 LLVMBool LLVMIsUndef(LLVMValueRef Val) {
514 return isa<UndefValue>(unwrap(Val));
517 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) {
519 wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
522 /*--.. Operations on metadata nodes ........................................--*/
524 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
526 return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen)));
529 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen) {
530 return LLVMMDStringInContext(LLVMGetGlobalContext(), Str, SLen);
533 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
535 return wrap(MDNode::get(*unwrap(C),
536 makeArrayRef(unwrap<Value>(Vals, Count), Count)));
539 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
540 return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
543 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len) {
544 if (const MDString *S = dyn_cast<MDString>(unwrap(V))) {
545 *Len = S->getString().size();
546 return S->getString().data();
552 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name)
554 if (NamedMDNode *N = unwrap(M)->getNamedMetadata(name)) {
555 return N->getNumOperands();
560 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest)
562 NamedMDNode *N = unwrap(M)->getNamedMetadata(name);
565 for (unsigned i=0;i<N->getNumOperands();i++)
566 Dest[i] = wrap(N->getOperand(i));
569 /*--.. Operations on scalar constants ......................................--*/
571 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
572 LLVMBool SignExtend) {
573 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
576 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
578 const uint64_t Words[]) {
579 IntegerType *Ty = unwrap<IntegerType>(IntTy);
580 return wrap(ConstantInt::get(Ty->getContext(),
581 APInt(Ty->getBitWidth(),
582 makeArrayRef(Words, NumWords))));
585 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[],
587 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str),
591 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char Str[],
592 unsigned SLen, uint8_t Radix) {
593 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen),
597 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
598 return wrap(ConstantFP::get(unwrap(RealTy), N));
601 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
602 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text)));
605 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[],
607 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
610 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
611 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
614 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
615 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
618 /*--.. Operations on composite constants ...................................--*/
620 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
622 LLVMBool DontNullTerminate) {
623 /* Inverted the sense of AddNull because ', 0)' is a
624 better mnemonic for null termination than ', 1)'. */
625 return wrap(ConstantArray::get(*unwrap(C), StringRef(Str, Length),
626 DontNullTerminate == 0));
628 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
629 LLVMValueRef *ConstantVals,
630 unsigned Count, LLVMBool Packed) {
631 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
632 return wrap(ConstantStruct::getAnon(*unwrap(C), makeArrayRef(Elements, Count),
636 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
637 LLVMBool DontNullTerminate) {
638 return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
641 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
642 LLVMValueRef *ConstantVals, unsigned Length) {
643 ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
644 return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
646 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
648 return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
652 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
653 LLVMValueRef *ConstantVals,
655 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
656 StructType *Ty = cast<StructType>(unwrap(StructTy));
658 return wrap(ConstantStruct::get(Ty, makeArrayRef(Elements, Count)));
661 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
662 return wrap(ConstantVector::get(makeArrayRef(
663 unwrap<Constant>(ScalarConstantVals, Size), Size)));
666 /*-- Opcode mapping */
668 static LLVMOpcode map_to_llvmopcode(int opcode)
672 assert(0 && "Unhandled Opcode.");
673 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
674 #include "llvm/Instruction.def"
679 static int map_from_llvmopcode(LLVMOpcode code)
683 assert(0 && "Unhandled Opcode.");
684 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
685 #include "llvm/Instruction.def"
690 /*--.. Constant expressions ................................................--*/
692 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal) {
693 return map_to_llvmopcode(unwrap<ConstantExpr>(ConstantVal)->getOpcode());
696 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) {
697 return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
700 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) {
701 return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
704 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) {
705 return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
708 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal) {
709 return wrap(ConstantExpr::getNSWNeg(unwrap<Constant>(ConstantVal)));
712 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal) {
713 return wrap(ConstantExpr::getNUWNeg(unwrap<Constant>(ConstantVal)));
717 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal) {
718 return wrap(ConstantExpr::getFNeg(unwrap<Constant>(ConstantVal)));
721 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) {
722 return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
725 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
726 return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
727 unwrap<Constant>(RHSConstant)));
730 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant,
731 LLVMValueRef RHSConstant) {
732 return wrap(ConstantExpr::getNSWAdd(unwrap<Constant>(LHSConstant),
733 unwrap<Constant>(RHSConstant)));
736 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant,
737 LLVMValueRef RHSConstant) {
738 return wrap(ConstantExpr::getNUWAdd(unwrap<Constant>(LHSConstant),
739 unwrap<Constant>(RHSConstant)));
742 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
743 return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant),
744 unwrap<Constant>(RHSConstant)));
747 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
748 return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
749 unwrap<Constant>(RHSConstant)));
752 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant,
753 LLVMValueRef RHSConstant) {
754 return wrap(ConstantExpr::getNSWSub(unwrap<Constant>(LHSConstant),
755 unwrap<Constant>(RHSConstant)));
758 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant,
759 LLVMValueRef RHSConstant) {
760 return wrap(ConstantExpr::getNUWSub(unwrap<Constant>(LHSConstant),
761 unwrap<Constant>(RHSConstant)));
764 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
765 return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant),
766 unwrap<Constant>(RHSConstant)));
769 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
770 return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
771 unwrap<Constant>(RHSConstant)));
774 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant,
775 LLVMValueRef RHSConstant) {
776 return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
777 unwrap<Constant>(RHSConstant)));
780 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant,
781 LLVMValueRef RHSConstant) {
782 return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
783 unwrap<Constant>(RHSConstant)));
786 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
787 return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant),
788 unwrap<Constant>(RHSConstant)));
791 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
792 return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
793 unwrap<Constant>(RHSConstant)));
796 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
797 return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
798 unwrap<Constant>(RHSConstant)));
801 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant,
802 LLVMValueRef RHSConstant) {
803 return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant),
804 unwrap<Constant>(RHSConstant)));
807 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
808 return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
809 unwrap<Constant>(RHSConstant)));
812 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
813 return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
814 unwrap<Constant>(RHSConstant)));
817 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
818 return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
819 unwrap<Constant>(RHSConstant)));
822 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
823 return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
824 unwrap<Constant>(RHSConstant)));
827 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
828 return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
829 unwrap<Constant>(RHSConstant)));
832 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
833 return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
834 unwrap<Constant>(RHSConstant)));
837 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
838 return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
839 unwrap<Constant>(RHSConstant)));
842 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
843 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
844 return wrap(ConstantExpr::getICmp(Predicate,
845 unwrap<Constant>(LHSConstant),
846 unwrap<Constant>(RHSConstant)));
849 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
850 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
851 return wrap(ConstantExpr::getFCmp(Predicate,
852 unwrap<Constant>(LHSConstant),
853 unwrap<Constant>(RHSConstant)));
856 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
857 return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
858 unwrap<Constant>(RHSConstant)));
861 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
862 return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
863 unwrap<Constant>(RHSConstant)));
866 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
867 return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
868 unwrap<Constant>(RHSConstant)));
871 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
872 LLVMValueRef *ConstantIndices, unsigned NumIndices) {
873 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
875 return wrap(ConstantExpr::getGetElementPtr(unwrap<Constant>(ConstantVal),
879 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
880 LLVMValueRef *ConstantIndices,
881 unsigned NumIndices) {
882 Constant* Val = unwrap<Constant>(ConstantVal);
883 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
885 return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, IdxList));
888 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
889 return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
893 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
894 return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
898 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
899 return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
903 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
904 return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
908 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
909 return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
913 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
914 return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
918 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
919 return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
923 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
924 return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
928 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
929 return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
933 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
934 return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
938 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
939 return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
943 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
944 return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
948 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
949 LLVMTypeRef ToType) {
950 return wrap(ConstantExpr::getZExtOrBitCast(unwrap<Constant>(ConstantVal),
954 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
955 LLVMTypeRef ToType) {
956 return wrap(ConstantExpr::getSExtOrBitCast(unwrap<Constant>(ConstantVal),
960 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
961 LLVMTypeRef ToType) {
962 return wrap(ConstantExpr::getTruncOrBitCast(unwrap<Constant>(ConstantVal),
966 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
967 LLVMTypeRef ToType) {
968 return wrap(ConstantExpr::getPointerCast(unwrap<Constant>(ConstantVal),
972 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
974 return wrap(ConstantExpr::getIntegerCast(unwrap<Constant>(ConstantVal),
975 unwrap(ToType), isSigned));
978 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
979 return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal),
983 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
984 LLVMValueRef ConstantIfTrue,
985 LLVMValueRef ConstantIfFalse) {
986 return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
987 unwrap<Constant>(ConstantIfTrue),
988 unwrap<Constant>(ConstantIfFalse)));
991 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
992 LLVMValueRef IndexConstant) {
993 return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
994 unwrap<Constant>(IndexConstant)));
997 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
998 LLVMValueRef ElementValueConstant,
999 LLVMValueRef IndexConstant) {
1000 return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
1001 unwrap<Constant>(ElementValueConstant),
1002 unwrap<Constant>(IndexConstant)));
1005 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1006 LLVMValueRef VectorBConstant,
1007 LLVMValueRef MaskConstant) {
1008 return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
1009 unwrap<Constant>(VectorBConstant),
1010 unwrap<Constant>(MaskConstant)));
1013 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1015 return wrap(ConstantExpr::getExtractValue(unwrap<Constant>(AggConstant),
1016 makeArrayRef(IdxList, NumIdx)));
1019 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1020 LLVMValueRef ElementValueConstant,
1021 unsigned *IdxList, unsigned NumIdx) {
1022 return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant),
1023 unwrap<Constant>(ElementValueConstant),
1024 makeArrayRef(IdxList, NumIdx)));
1027 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
1028 const char *Constraints,
1029 LLVMBool HasSideEffects,
1030 LLVMBool IsAlignStack) {
1031 return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
1032 Constraints, HasSideEffects, IsAlignStack));
1035 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB) {
1036 return wrap(BlockAddress::get(unwrap<Function>(F), unwrap(BB)));
1039 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1041 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) {
1042 return wrap(unwrap<GlobalValue>(Global)->getParent());
1045 LLVMBool LLVMIsDeclaration(LLVMValueRef Global) {
1046 return unwrap<GlobalValue>(Global)->isDeclaration();
1049 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) {
1050 switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1052 assert(false && "Unhandled Linkage Type.");
1053 case GlobalValue::ExternalLinkage:
1054 return LLVMExternalLinkage;
1055 case GlobalValue::AvailableExternallyLinkage:
1056 return LLVMAvailableExternallyLinkage;
1057 case GlobalValue::LinkOnceAnyLinkage:
1058 return LLVMLinkOnceAnyLinkage;
1059 case GlobalValue::LinkOnceODRLinkage:
1060 return LLVMLinkOnceODRLinkage;
1061 case GlobalValue::WeakAnyLinkage:
1062 return LLVMWeakAnyLinkage;
1063 case GlobalValue::WeakODRLinkage:
1064 return LLVMWeakODRLinkage;
1065 case GlobalValue::AppendingLinkage:
1066 return LLVMAppendingLinkage;
1067 case GlobalValue::InternalLinkage:
1068 return LLVMInternalLinkage;
1069 case GlobalValue::PrivateLinkage:
1070 return LLVMPrivateLinkage;
1071 case GlobalValue::LinkerPrivateLinkage:
1072 return LLVMLinkerPrivateLinkage;
1073 case GlobalValue::LinkerPrivateWeakLinkage:
1074 return LLVMLinkerPrivateWeakLinkage;
1075 case GlobalValue::LinkerPrivateWeakDefAutoLinkage:
1076 return LLVMLinkerPrivateWeakDefAutoLinkage;
1077 case GlobalValue::DLLImportLinkage:
1078 return LLVMDLLImportLinkage;
1079 case GlobalValue::DLLExportLinkage:
1080 return LLVMDLLExportLinkage;
1081 case GlobalValue::ExternalWeakLinkage:
1082 return LLVMExternalWeakLinkage;
1083 case GlobalValue::CommonLinkage:
1084 return LLVMCommonLinkage;
1087 // Should never get here.
1088 return static_cast<LLVMLinkage>(0);
1091 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
1092 GlobalValue *GV = unwrap<GlobalValue>(Global);
1096 assert(false && "Unhandled Linkage Type.");
1097 case LLVMExternalLinkage:
1098 GV->setLinkage(GlobalValue::ExternalLinkage);
1100 case LLVMAvailableExternallyLinkage:
1101 GV->setLinkage(GlobalValue::AvailableExternallyLinkage);
1103 case LLVMLinkOnceAnyLinkage:
1104 GV->setLinkage(GlobalValue::LinkOnceAnyLinkage);
1106 case LLVMLinkOnceODRLinkage:
1107 GV->setLinkage(GlobalValue::LinkOnceODRLinkage);
1109 case LLVMWeakAnyLinkage:
1110 GV->setLinkage(GlobalValue::WeakAnyLinkage);
1112 case LLVMWeakODRLinkage:
1113 GV->setLinkage(GlobalValue::WeakODRLinkage);
1115 case LLVMAppendingLinkage:
1116 GV->setLinkage(GlobalValue::AppendingLinkage);
1118 case LLVMInternalLinkage:
1119 GV->setLinkage(GlobalValue::InternalLinkage);
1121 case LLVMPrivateLinkage:
1122 GV->setLinkage(GlobalValue::PrivateLinkage);
1124 case LLVMLinkerPrivateLinkage:
1125 GV->setLinkage(GlobalValue::LinkerPrivateLinkage);
1127 case LLVMLinkerPrivateWeakLinkage:
1128 GV->setLinkage(GlobalValue::LinkerPrivateWeakLinkage);
1130 case LLVMLinkerPrivateWeakDefAutoLinkage:
1131 GV->setLinkage(GlobalValue::LinkerPrivateWeakDefAutoLinkage);
1133 case LLVMDLLImportLinkage:
1134 GV->setLinkage(GlobalValue::DLLImportLinkage);
1136 case LLVMDLLExportLinkage:
1137 GV->setLinkage(GlobalValue::DLLExportLinkage);
1139 case LLVMExternalWeakLinkage:
1140 GV->setLinkage(GlobalValue::ExternalWeakLinkage);
1142 case LLVMGhostLinkage:
1144 << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1146 case LLVMCommonLinkage:
1147 GV->setLinkage(GlobalValue::CommonLinkage);
1152 const char *LLVMGetSection(LLVMValueRef Global) {
1153 return unwrap<GlobalValue>(Global)->getSection().c_str();
1156 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
1157 unwrap<GlobalValue>(Global)->setSection(Section);
1160 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
1161 return static_cast<LLVMVisibility>(
1162 unwrap<GlobalValue>(Global)->getVisibility());
1165 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) {
1166 unwrap<GlobalValue>(Global)
1167 ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
1170 unsigned LLVMGetAlignment(LLVMValueRef Global) {
1171 return unwrap<GlobalValue>(Global)->getAlignment();
1174 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) {
1175 unwrap<GlobalValue>(Global)->setAlignment(Bytes);
1178 /*--.. Operations on global variables ......................................--*/
1180 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
1181 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1182 GlobalValue::ExternalLinkage, 0, Name));
1185 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1187 unsigned AddressSpace) {
1188 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1189 GlobalValue::ExternalLinkage, 0, Name, 0,
1190 false, AddressSpace));
1193 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {
1194 return wrap(unwrap(M)->getNamedGlobal(Name));
1197 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) {
1198 Module *Mod = unwrap(M);
1199 Module::global_iterator I = Mod->global_begin();
1200 if (I == Mod->global_end())
1205 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) {
1206 Module *Mod = unwrap(M);
1207 Module::global_iterator I = Mod->global_end();
1208 if (I == Mod->global_begin())
1213 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) {
1214 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1215 Module::global_iterator I = GV;
1216 if (++I == GV->getParent()->global_end())
1221 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) {
1222 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1223 Module::global_iterator I = GV;
1224 if (I == GV->getParent()->global_begin())
1229 void LLVMDeleteGlobal(LLVMValueRef GlobalVar) {
1230 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
1233 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) {
1234 GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
1235 if ( !GV->hasInitializer() )
1237 return wrap(GV->getInitializer());
1240 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
1241 unwrap<GlobalVariable>(GlobalVar)
1242 ->setInitializer(unwrap<Constant>(ConstantVal));
1245 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
1246 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
1249 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal) {
1250 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
1253 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
1254 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
1257 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant) {
1258 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
1261 /*--.. Operations on aliases ......................................--*/
1263 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1265 return wrap(new GlobalAlias(unwrap(Ty), GlobalValue::ExternalLinkage, Name,
1266 unwrap<Constant>(Aliasee), unwrap (M)));
1269 /*--.. Operations on functions .............................................--*/
1271 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1272 LLVMTypeRef FunctionTy) {
1273 return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
1274 GlobalValue::ExternalLinkage, Name, unwrap(M)));
1277 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
1278 return wrap(unwrap(M)->getFunction(Name));
1281 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) {
1282 Module *Mod = unwrap(M);
1283 Module::iterator I = Mod->begin();
1284 if (I == Mod->end())
1289 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) {
1290 Module *Mod = unwrap(M);
1291 Module::iterator I = Mod->end();
1292 if (I == Mod->begin())
1297 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) {
1298 Function *Func = unwrap<Function>(Fn);
1299 Module::iterator I = Func;
1300 if (++I == Func->getParent()->end())
1305 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) {
1306 Function *Func = unwrap<Function>(Fn);
1307 Module::iterator I = Func;
1308 if (I == Func->getParent()->begin())
1313 void LLVMDeleteFunction(LLVMValueRef Fn) {
1314 unwrap<Function>(Fn)->eraseFromParent();
1317 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) {
1318 if (Function *F = dyn_cast<Function>(unwrap(Fn)))
1319 return F->getIntrinsicID();
1323 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) {
1324 return unwrap<Function>(Fn)->getCallingConv();
1327 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
1328 return unwrap<Function>(Fn)->setCallingConv(
1329 static_cast<CallingConv::ID>(CC));
1332 const char *LLVMGetGC(LLVMValueRef Fn) {
1333 Function *F = unwrap<Function>(Fn);
1334 return F->hasGC()? F->getGC() : 0;
1337 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
1338 Function *F = unwrap<Function>(Fn);
1345 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1346 Function *Func = unwrap<Function>(Fn);
1347 const AttrListPtr PAL = Func->getAttributes();
1348 const AttrListPtr PALnew = PAL.addAttr(~0U, PA);
1349 Func->setAttributes(PALnew);
1352 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1353 Function *Func = unwrap<Function>(Fn);
1354 const AttrListPtr PAL = Func->getAttributes();
1355 const AttrListPtr PALnew = PAL.removeAttr(~0U, PA);
1356 Func->setAttributes(PALnew);
1359 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) {
1360 Function *Func = unwrap<Function>(Fn);
1361 const AttrListPtr PAL = Func->getAttributes();
1362 Attributes attr = PAL.getFnAttributes();
1363 return (LLVMAttribute)attr;
1366 /*--.. Operations on parameters ............................................--*/
1368 unsigned LLVMCountParams(LLVMValueRef FnRef) {
1369 // This function is strictly redundant to
1370 // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1371 return unwrap<Function>(FnRef)->arg_size();
1374 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
1375 Function *Fn = unwrap<Function>(FnRef);
1376 for (Function::arg_iterator I = Fn->arg_begin(),
1377 E = Fn->arg_end(); I != E; I++)
1378 *ParamRefs++ = wrap(I);
1381 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
1382 Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
1388 LLVMValueRef LLVMGetParamParent(LLVMValueRef V) {
1389 return wrap(unwrap<Argument>(V)->getParent());
1392 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn) {
1393 Function *Func = unwrap<Function>(Fn);
1394 Function::arg_iterator I = Func->arg_begin();
1395 if (I == Func->arg_end())
1400 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) {
1401 Function *Func = unwrap<Function>(Fn);
1402 Function::arg_iterator I = Func->arg_end();
1403 if (I == Func->arg_begin())
1408 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) {
1409 Argument *A = unwrap<Argument>(Arg);
1410 Function::arg_iterator I = A;
1411 if (++I == A->getParent()->arg_end())
1416 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
1417 Argument *A = unwrap<Argument>(Arg);
1418 Function::arg_iterator I = A;
1419 if (I == A->getParent()->arg_begin())
1424 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1425 unwrap<Argument>(Arg)->addAttr(PA);
1428 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1429 unwrap<Argument>(Arg)->removeAttr(PA);
1432 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) {
1433 Argument *A = unwrap<Argument>(Arg);
1434 Attributes attr = A->getParent()->getAttributes().getParamAttributes(
1436 return (LLVMAttribute)attr;
1440 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
1441 unwrap<Argument>(Arg)->addAttr(
1442 Attribute::constructAlignmentFromInt(align));
1445 /*--.. Operations on basic blocks ..........................................--*/
1447 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) {
1448 return wrap(static_cast<Value*>(unwrap(BB)));
1451 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val) {
1452 return isa<BasicBlock>(unwrap(Val));
1455 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) {
1456 return wrap(unwrap<BasicBlock>(Val));
1459 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB) {
1460 return wrap(unwrap(BB)->getParent());
1463 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB) {
1464 return wrap(unwrap(BB)->getTerminator());
1467 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
1468 return unwrap<Function>(FnRef)->size();
1471 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
1472 Function *Fn = unwrap<Function>(FnRef);
1473 for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
1474 *BasicBlocksRefs++ = wrap(I);
1477 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
1478 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
1481 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn) {
1482 Function *Func = unwrap<Function>(Fn);
1483 Function::iterator I = Func->begin();
1484 if (I == Func->end())
1489 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) {
1490 Function *Func = unwrap<Function>(Fn);
1491 Function::iterator I = Func->end();
1492 if (I == Func->begin())
1497 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) {
1498 BasicBlock *Block = unwrap(BB);
1499 Function::iterator I = Block;
1500 if (++I == Block->getParent()->end())
1505 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
1506 BasicBlock *Block = unwrap(BB);
1507 Function::iterator I = Block;
1508 if (I == Block->getParent()->begin())
1513 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1516 return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
1519 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
1520 return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
1523 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1524 LLVMBasicBlockRef BBRef,
1526 BasicBlock *BB = unwrap(BBRef);
1527 return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
1530 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef,
1532 return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
1535 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {
1536 unwrap(BBRef)->eraseFromParent();
1539 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BBRef) {
1540 unwrap(BBRef)->removeFromParent();
1543 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1544 unwrap(BB)->moveBefore(unwrap(MovePos));
1547 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1548 unwrap(BB)->moveAfter(unwrap(MovePos));
1551 /*--.. Operations on instructions ..........................................--*/
1553 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) {
1554 return wrap(unwrap<Instruction>(Inst)->getParent());
1557 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB) {
1558 BasicBlock *Block = unwrap(BB);
1559 BasicBlock::iterator I = Block->begin();
1560 if (I == Block->end())
1565 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) {
1566 BasicBlock *Block = unwrap(BB);
1567 BasicBlock::iterator I = Block->end();
1568 if (I == Block->begin())
1573 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) {
1574 Instruction *Instr = unwrap<Instruction>(Inst);
1575 BasicBlock::iterator I = Instr;
1576 if (++I == Instr->getParent()->end())
1581 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) {
1582 Instruction *Instr = unwrap<Instruction>(Inst);
1583 BasicBlock::iterator I = Instr;
1584 if (I == Instr->getParent()->begin())
1589 void LLVMInstructionEraseFromParent(LLVMValueRef Inst) {
1590 unwrap<Instruction>(Inst)->eraseFromParent();
1593 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) {
1594 if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
1595 return (LLVMIntPredicate)I->getPredicate();
1596 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
1597 if (CE->getOpcode() == Instruction::ICmp)
1598 return (LLVMIntPredicate)CE->getPredicate();
1599 return (LLVMIntPredicate)0;
1602 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst) {
1603 if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
1604 return map_to_llvmopcode(C->getOpcode());
1605 return (LLVMOpcode)0;
1608 /*--.. Call and invoke instructions ........................................--*/
1610 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
1611 Value *V = unwrap(Instr);
1612 if (CallInst *CI = dyn_cast<CallInst>(V))
1613 return CI->getCallingConv();
1614 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
1615 return II->getCallingConv();
1616 llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
1620 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
1621 Value *V = unwrap(Instr);
1622 if (CallInst *CI = dyn_cast<CallInst>(V))
1623 return CI->setCallingConv(static_cast<CallingConv::ID>(CC));
1624 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
1625 return II->setCallingConv(static_cast<CallingConv::ID>(CC));
1626 llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
1629 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
1631 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1633 Call.getAttributes().addAttr(index, PA));
1636 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
1638 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1640 Call.getAttributes().removeAttr(index, PA));
1643 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
1645 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1647 Call.getAttributes().addAttr(index,
1648 Attribute::constructAlignmentFromInt(align)));
1651 /*--.. Operations on call instructions (only) ..............................--*/
1653 LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
1654 return unwrap<CallInst>(Call)->isTailCall();
1657 void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
1658 unwrap<CallInst>(Call)->setTailCall(isTailCall);
1661 /*--.. Operations on switch instructions (only) ............................--*/
1663 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch) {
1664 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
1667 /*--.. Operations on phi nodes .............................................--*/
1669 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
1670 LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
1671 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
1672 for (unsigned I = 0; I != Count; ++I)
1673 PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
1676 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
1677 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
1680 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index) {
1681 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
1684 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) {
1685 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
1689 /*===-- Instruction builders ----------------------------------------------===*/
1691 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C) {
1692 return wrap(new IRBuilder<>(*unwrap(C)));
1695 LLVMBuilderRef LLVMCreateBuilder(void) {
1696 return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
1699 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
1700 LLVMValueRef Instr) {
1701 BasicBlock *BB = unwrap(Block);
1702 Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end();
1703 unwrap(Builder)->SetInsertPoint(BB, I);
1706 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
1707 Instruction *I = unwrap<Instruction>(Instr);
1708 unwrap(Builder)->SetInsertPoint(I->getParent(), I);
1711 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
1712 BasicBlock *BB = unwrap(Block);
1713 unwrap(Builder)->SetInsertPoint(BB);
1716 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder) {
1717 return wrap(unwrap(Builder)->GetInsertBlock());
1720 void LLVMClearInsertionPosition(LLVMBuilderRef Builder) {
1721 unwrap(Builder)->ClearInsertionPoint();
1724 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr) {
1725 unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
1728 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
1730 unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name);
1733 void LLVMDisposeBuilder(LLVMBuilderRef Builder) {
1734 delete unwrap(Builder);
1737 /*--.. Metadata builders ...................................................--*/
1739 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) {
1740 MDNode *Loc = L ? unwrap<MDNode>(L) : NULL;
1741 unwrap(Builder)->SetCurrentDebugLocation(DebugLoc::getFromDILocation(Loc));
1744 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder) {
1745 return wrap(unwrap(Builder)->getCurrentDebugLocation()
1746 .getAsMDNode(unwrap(Builder)->getContext()));
1749 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst) {
1750 unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
1754 /*--.. Instruction builders ................................................--*/
1756 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {
1757 return wrap(unwrap(B)->CreateRetVoid());
1760 LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) {
1761 return wrap(unwrap(B)->CreateRet(unwrap(V)));
1764 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals,
1766 return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
1769 LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) {
1770 return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
1773 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If,
1774 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
1775 return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
1778 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V,
1779 LLVMBasicBlockRef Else, unsigned NumCases) {
1780 return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
1783 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
1784 unsigned NumDests) {
1785 return wrap(unwrap(B)->CreateIndirectBr(unwrap(Addr), NumDests));
1788 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,
1789 LLVMValueRef *Args, unsigned NumArgs,
1790 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
1792 return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
1793 makeArrayRef(unwrap(Args), NumArgs),
1797 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
1798 LLVMValueRef PersFn, unsigned NumClauses,
1800 return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty),
1801 cast<Function>(unwrap(PersFn)),
1805 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn) {
1806 return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
1809 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
1810 return wrap(unwrap(B)->CreateUnreachable());
1813 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
1814 LLVMBasicBlockRef Dest) {
1815 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
1818 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest) {
1819 unwrap<IndirectBrInst>(IndirectBr)->addDestination(unwrap(Dest));
1822 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal) {
1823 unwrap<LandingPadInst>(LandingPad)->
1824 addClause(cast<Constant>(unwrap(ClauseVal)));
1827 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
1828 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
1831 /*--.. Arithmetic ..........................................................--*/
1833 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1835 return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
1838 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1840 return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
1843 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1845 return wrap(unwrap(B)->CreateNUWAdd(unwrap(LHS), unwrap(RHS), Name));
1848 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1850 return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
1853 LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1855 return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
1858 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1860 return wrap(unwrap(B)->CreateNSWSub(unwrap(LHS), unwrap(RHS), Name));
1863 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1865 return wrap(unwrap(B)->CreateNUWSub(unwrap(LHS), unwrap(RHS), Name));
1868 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1870 return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
1873 LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1875 return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
1878 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1880 return wrap(unwrap(B)->CreateNSWMul(unwrap(LHS), unwrap(RHS), Name));
1883 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1885 return wrap(unwrap(B)->CreateNUWMul(unwrap(LHS), unwrap(RHS), Name));
1888 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1890 return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
1893 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1895 return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
1898 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1900 return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
1903 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS,
1904 LLVMValueRef RHS, const char *Name) {
1905 return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
1908 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1910 return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
1913 LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1915 return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
1918 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1920 return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
1923 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1925 return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
1928 LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1930 return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
1933 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1935 return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
1938 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1940 return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
1943 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1945 return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
1948 LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1950 return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
1953 LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1955 return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
1958 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
1959 LLVMValueRef LHS, LLVMValueRef RHS,
1961 return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
1962 unwrap(RHS), Name));
1965 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1966 return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
1969 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
1971 return wrap(unwrap(B)->CreateNSWNeg(unwrap(V), Name));
1974 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
1976 return wrap(unwrap(B)->CreateNUWNeg(unwrap(V), Name));
1979 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1980 return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name));
1983 LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1984 return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
1987 /*--.. Memory ..............................................................--*/
1989 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
1991 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
1992 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
1993 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
1994 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
1995 ITy, unwrap(Ty), AllocSize,
1997 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2000 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
2001 LLVMValueRef Val, const char *Name) {
2002 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2003 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2004 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2005 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2006 ITy, unwrap(Ty), AllocSize,
2007 unwrap(Val), 0, "");
2008 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2011 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2013 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), 0, Name));
2016 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2017 LLVMValueRef Val, const char *Name) {
2018 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
2021 LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {
2022 return wrap(unwrap(B)->Insert(
2023 CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
2027 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
2029 return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
2032 LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val,
2033 LLVMValueRef PointerVal) {
2034 return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
2037 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2038 LLVMValueRef *Indices, unsigned NumIndices,
2040 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2041 return wrap(unwrap(B)->CreateGEP(unwrap(Pointer), IdxList, Name));
2044 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2045 LLVMValueRef *Indices, unsigned NumIndices,
2047 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2048 return wrap(unwrap(B)->CreateInBoundsGEP(unwrap(Pointer), IdxList, Name));
2051 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2052 unsigned Idx, const char *Name) {
2053 return wrap(unwrap(B)->CreateStructGEP(unwrap(Pointer), Idx, Name));
2056 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2058 return wrap(unwrap(B)->CreateGlobalString(Str, Name));
2061 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2063 return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
2066 /*--.. Casts ...............................................................--*/
2068 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2069 LLVMTypeRef DestTy, const char *Name) {
2070 return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
2073 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val,
2074 LLVMTypeRef DestTy, const char *Name) {
2075 return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
2078 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val,
2079 LLVMTypeRef DestTy, const char *Name) {
2080 return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
2083 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val,
2084 LLVMTypeRef DestTy, const char *Name) {
2085 return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
2088 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val,
2089 LLVMTypeRef DestTy, const char *Name) {
2090 return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
2093 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2094 LLVMTypeRef DestTy, const char *Name) {
2095 return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
2098 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2099 LLVMTypeRef DestTy, const char *Name) {
2100 return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
2103 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2104 LLVMTypeRef DestTy, const char *Name) {
2105 return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
2108 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val,
2109 LLVMTypeRef DestTy, const char *Name) {
2110 return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
2113 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val,
2114 LLVMTypeRef DestTy, const char *Name) {
2115 return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
2118 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val,
2119 LLVMTypeRef DestTy, const char *Name) {
2120 return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
2123 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2124 LLVMTypeRef DestTy, const char *Name) {
2125 return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
2128 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2129 LLVMTypeRef DestTy, const char *Name) {
2130 return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
2134 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2135 LLVMTypeRef DestTy, const char *Name) {
2136 return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
2140 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2141 LLVMTypeRef DestTy, const char *Name) {
2142 return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
2146 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2147 LLVMTypeRef DestTy, const char *Name) {
2148 return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
2149 unwrap(DestTy), Name));
2152 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val,
2153 LLVMTypeRef DestTy, const char *Name) {
2154 return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
2157 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val,
2158 LLVMTypeRef DestTy, const char *Name) {
2159 return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy),
2160 /*isSigned*/true, Name));
2163 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef B, LLVMValueRef Val,
2164 LLVMTypeRef DestTy, const char *Name) {
2165 return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
2168 /*--.. Comparisons .........................................................--*/
2170 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
2171 LLVMValueRef LHS, LLVMValueRef RHS,
2173 return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
2174 unwrap(LHS), unwrap(RHS), Name));
2177 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
2178 LLVMValueRef LHS, LLVMValueRef RHS,
2180 return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
2181 unwrap(LHS), unwrap(RHS), Name));
2184 /*--.. Miscellaneous instructions ..........................................--*/
2186 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {
2187 return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
2190 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
2191 LLVMValueRef *Args, unsigned NumArgs,
2193 return wrap(unwrap(B)->CreateCall(unwrap(Fn),
2194 makeArrayRef(unwrap(Args), NumArgs),
2198 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
2199 LLVMValueRef Then, LLVMValueRef Else,
2201 return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
2205 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List,
2206 LLVMTypeRef Ty, const char *Name) {
2207 return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
2210 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2211 LLVMValueRef Index, const char *Name) {
2212 return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
2216 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2217 LLVMValueRef EltVal, LLVMValueRef Index,
2219 return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
2220 unwrap(Index), Name));
2223 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1,
2224 LLVMValueRef V2, LLVMValueRef Mask,
2226 return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
2227 unwrap(Mask), Name));
2230 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2231 unsigned Index, const char *Name) {
2232 return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
2235 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2236 LLVMValueRef EltVal, unsigned Index,
2238 return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
2242 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val,
2244 return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
2247 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef B, LLVMValueRef Val,
2249 return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
2252 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS,
2253 LLVMValueRef RHS, const char *Name) {
2254 return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
2258 /*===-- Module providers --------------------------------------------------===*/
2260 LLVMModuleProviderRef
2261 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) {
2262 return reinterpret_cast<LLVMModuleProviderRef>(M);
2265 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) {
2270 /*===-- Memory buffers ----------------------------------------------------===*/
2272 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(
2274 LLVMMemoryBufferRef *OutMemBuf,
2275 char **OutMessage) {
2277 OwningPtr<MemoryBuffer> MB;
2279 if (!(ec = MemoryBuffer::getFile(Path, MB))) {
2280 *OutMemBuf = wrap(MB.take());
2284 *OutMessage = strdup(ec.message().c_str());
2288 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2289 char **OutMessage) {
2290 OwningPtr<MemoryBuffer> MB;
2292 if (!(ec = MemoryBuffer::getSTDIN(MB))) {
2293 *OutMemBuf = wrap(MB.take());
2297 *OutMessage = strdup(ec.message().c_str());
2301 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) {
2302 delete unwrap(MemBuf);
2305 /*===-- Pass Registry -----------------------------------------------------===*/
2307 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void) {
2308 return wrap(PassRegistry::getPassRegistry());
2311 /*===-- Pass Manager ------------------------------------------------------===*/
2313 LLVMPassManagerRef LLVMCreatePassManager() {
2314 return wrap(new PassManager());
2317 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M) {
2318 return wrap(new FunctionPassManager(unwrap(M)));
2321 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) {
2322 return LLVMCreateFunctionPassManagerForModule(
2323 reinterpret_cast<LLVMModuleRef>(P));
2326 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
2327 return unwrap<PassManager>(PM)->run(*unwrap(M));
2330 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM) {
2331 return unwrap<FunctionPassManager>(FPM)->doInitialization();
2334 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F) {
2335 return unwrap<FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
2338 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM) {
2339 return unwrap<FunctionPassManager>(FPM)->doFinalization();
2342 void LLVMDisposePassManager(LLVMPassManagerRef PM) {