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;
139 case Type::FloatTyID:
140 return LLVMFloatTypeKind;
141 case Type::DoubleTyID:
142 return LLVMDoubleTypeKind;
143 case Type::X86_FP80TyID:
144 return LLVMX86_FP80TypeKind;
145 case Type::FP128TyID:
146 return LLVMFP128TypeKind;
147 case Type::PPC_FP128TyID:
148 return LLVMPPC_FP128TypeKind;
149 case Type::LabelTyID:
150 return LLVMLabelTypeKind;
151 case Type::MetadataTyID:
152 return LLVMMetadataTypeKind;
153 case Type::IntegerTyID:
154 return LLVMIntegerTypeKind;
155 case Type::FunctionTyID:
156 return LLVMFunctionTypeKind;
157 case Type::StructTyID:
158 return LLVMStructTypeKind;
159 case Type::ArrayTyID:
160 return LLVMArrayTypeKind;
161 case Type::PointerTyID:
162 return LLVMPointerTypeKind;
163 case Type::VectorTyID:
164 return LLVMVectorTypeKind;
165 case Type::X86_MMXTyID:
166 return LLVMX86_MMXTypeKind;
170 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty)
172 return unwrap(Ty)->isSized();
175 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty) {
176 return wrap(&unwrap(Ty)->getContext());
179 /*--.. Operations on integer types .........................................--*/
181 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C) {
182 return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
184 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C) {
185 return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
187 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C) {
188 return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
190 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C) {
191 return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
193 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C) {
194 return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
196 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits) {
197 return wrap(IntegerType::get(*unwrap(C), NumBits));
200 LLVMTypeRef LLVMInt1Type(void) {
201 return LLVMInt1TypeInContext(LLVMGetGlobalContext());
203 LLVMTypeRef LLVMInt8Type(void) {
204 return LLVMInt8TypeInContext(LLVMGetGlobalContext());
206 LLVMTypeRef LLVMInt16Type(void) {
207 return LLVMInt16TypeInContext(LLVMGetGlobalContext());
209 LLVMTypeRef LLVMInt32Type(void) {
210 return LLVMInt32TypeInContext(LLVMGetGlobalContext());
212 LLVMTypeRef LLVMInt64Type(void) {
213 return LLVMInt64TypeInContext(LLVMGetGlobalContext());
215 LLVMTypeRef LLVMIntType(unsigned NumBits) {
216 return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
219 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
220 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
223 /*--.. Operations on real types ............................................--*/
225 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C) {
226 return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
228 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C) {
229 return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
231 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C) {
232 return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
234 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C) {
235 return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
237 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C) {
238 return (LLVMTypeRef) Type::getPPC_FP128Ty(*unwrap(C));
240 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C) {
241 return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
244 LLVMTypeRef LLVMFloatType(void) {
245 return LLVMFloatTypeInContext(LLVMGetGlobalContext());
247 LLVMTypeRef LLVMDoubleType(void) {
248 return LLVMDoubleTypeInContext(LLVMGetGlobalContext());
250 LLVMTypeRef LLVMX86FP80Type(void) {
251 return LLVMX86FP80TypeInContext(LLVMGetGlobalContext());
253 LLVMTypeRef LLVMFP128Type(void) {
254 return LLVMFP128TypeInContext(LLVMGetGlobalContext());
256 LLVMTypeRef LLVMPPCFP128Type(void) {
257 return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
259 LLVMTypeRef LLVMX86MMXType(void) {
260 return LLVMX86MMXTypeInContext(LLVMGetGlobalContext());
263 /*--.. Operations on function types ........................................--*/
265 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
266 LLVMTypeRef *ParamTypes, unsigned ParamCount,
268 ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
269 return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
272 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
273 return unwrap<FunctionType>(FunctionTy)->isVarArg();
276 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy) {
277 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
280 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
281 return unwrap<FunctionType>(FunctionTy)->getNumParams();
284 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
285 FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
286 for (FunctionType::param_iterator I = Ty->param_begin(),
287 E = Ty->param_end(); I != E; ++I)
291 /*--.. Operations on struct types ..........................................--*/
293 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
294 unsigned ElementCount, LLVMBool Packed) {
295 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
296 return wrap(StructType::get(*unwrap(C), Tys, Packed != 0));
299 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
300 unsigned ElementCount, LLVMBool Packed) {
301 return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
302 ElementCount, Packed);
305 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name)
307 return wrap(StructType::create(*unwrap(C), Name));
310 const char *LLVMGetStructName(LLVMTypeRef Ty)
312 StructType *Type = unwrap<StructType>(Ty);
313 if (!Type->hasName())
315 return Type->getName().data();
318 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
319 unsigned ElementCount, LLVMBool Packed) {
320 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
321 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
324 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
325 return unwrap<StructType>(StructTy)->getNumElements();
328 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest) {
329 StructType *Ty = unwrap<StructType>(StructTy);
330 for (StructType::element_iterator I = Ty->element_begin(),
331 E = Ty->element_end(); I != E; ++I)
335 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy) {
336 return unwrap<StructType>(StructTy)->isPacked();
339 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy) {
340 return unwrap<StructType>(StructTy)->isOpaque();
343 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) {
344 return wrap(unwrap(M)->getTypeByName(Name));
347 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
349 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
350 return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
353 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
354 return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
357 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
358 return wrap(VectorType::get(unwrap(ElementType), ElementCount));
361 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) {
362 return wrap(unwrap<SequentialType>(Ty)->getElementType());
365 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
366 return unwrap<ArrayType>(ArrayTy)->getNumElements();
369 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) {
370 return unwrap<PointerType>(PointerTy)->getAddressSpace();
373 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
374 return unwrap<VectorType>(VectorTy)->getNumElements();
377 /*--.. Operations on other types ...........................................--*/
379 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C) {
380 return wrap(Type::getVoidTy(*unwrap(C)));
382 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C) {
383 return wrap(Type::getLabelTy(*unwrap(C)));
386 LLVMTypeRef LLVMVoidType(void) {
387 return LLVMVoidTypeInContext(LLVMGetGlobalContext());
389 LLVMTypeRef LLVMLabelType(void) {
390 return LLVMLabelTypeInContext(LLVMGetGlobalContext());
393 /*===-- Operations on values ----------------------------------------------===*/
395 /*--.. Operations on all values ............................................--*/
397 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) {
398 return wrap(unwrap(Val)->getType());
401 const char *LLVMGetValueName(LLVMValueRef Val) {
402 return unwrap(Val)->getName().data();
405 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
406 unwrap(Val)->setName(Name);
409 void LLVMDumpValue(LLVMValueRef Val) {
413 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
414 unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
417 int LLVMHasMetadata(LLVMValueRef Inst) {
418 return unwrap<Instruction>(Inst)->hasMetadata();
421 LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID) {
422 return wrap(unwrap<Instruction>(Inst)->getMetadata(KindID));
425 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef MD) {
426 unwrap<Instruction>(Inst)->setMetadata(KindID, MD? unwrap<MDNode>(MD) : NULL);
429 /*--.. Conversion functions ................................................--*/
431 #define LLVM_DEFINE_VALUE_CAST(name) \
432 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
433 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
436 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST)
438 /*--.. Operations on Uses ..................................................--*/
439 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val) {
440 Value *V = unwrap(Val);
441 Value::use_iterator I = V->use_begin();
442 if (I == V->use_end())
444 return wrap(&(I.getUse()));
447 LLVMUseRef LLVMGetNextUse(LLVMUseRef U) {
448 Use *Next = unwrap(U)->getNext();
454 LLVMValueRef LLVMGetUser(LLVMUseRef U) {
455 return wrap(unwrap(U)->getUser());
458 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U) {
459 return wrap(unwrap(U)->get());
462 /*--.. Operations on Users .................................................--*/
463 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) {
464 Value *V = unwrap(Val);
465 if (MDNode *MD = dyn_cast<MDNode>(V))
466 return wrap(MD->getOperand(Index));
467 return wrap(cast<User>(V)->getOperand(Index));
470 void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
471 unwrap<User>(Val)->setOperand(Index, unwrap(Op));
474 int LLVMGetNumOperands(LLVMValueRef Val) {
475 Value *V = unwrap(Val);
476 if (MDNode *MD = dyn_cast<MDNode>(V))
477 return MD->getNumOperands();
478 return cast<User>(V)->getNumOperands();
481 /*--.. Operations on constants of any type .................................--*/
483 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
484 return wrap(Constant::getNullValue(unwrap(Ty)));
487 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) {
488 return wrap(Constant::getAllOnesValue(unwrap(Ty)));
491 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
492 return wrap(UndefValue::get(unwrap(Ty)));
495 LLVMBool LLVMIsConstant(LLVMValueRef Ty) {
496 return isa<Constant>(unwrap(Ty));
499 LLVMBool LLVMIsNull(LLVMValueRef Val) {
500 if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
501 return C->isNullValue();
505 LLVMBool LLVMIsUndef(LLVMValueRef Val) {
506 return isa<UndefValue>(unwrap(Val));
509 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) {
511 wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
514 /*--.. Operations on metadata nodes ........................................--*/
516 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
518 return wrap(MDString::get(*unwrap(C), StringRef(Str, SLen)));
521 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen) {
522 return LLVMMDStringInContext(LLVMGetGlobalContext(), Str, SLen);
525 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
527 return wrap(MDNode::get(*unwrap(C),
528 makeArrayRef(unwrap<Value>(Vals, Count), Count)));
531 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
532 return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
535 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len) {
536 if (const MDString *S = dyn_cast<MDString>(unwrap(V))) {
537 *Len = S->getString().size();
538 return S->getString().data();
544 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name)
546 if (NamedMDNode *N = unwrap(M)->getNamedMetadata(name)) {
547 return N->getNumOperands();
552 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest)
554 NamedMDNode *N = unwrap(M)->getNamedMetadata(name);
557 for (unsigned i=0;i<N->getNumOperands();i++)
558 Dest[i] = wrap(N->getOperand(i));
561 /*--.. Operations on scalar constants ......................................--*/
563 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
564 LLVMBool SignExtend) {
565 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
568 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
570 const uint64_t Words[]) {
571 IntegerType *Ty = unwrap<IntegerType>(IntTy);
572 return wrap(ConstantInt::get(Ty->getContext(),
573 APInt(Ty->getBitWidth(),
574 makeArrayRef(Words, NumWords))));
577 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[],
579 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str),
583 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char Str[],
584 unsigned SLen, uint8_t Radix) {
585 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen),
589 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
590 return wrap(ConstantFP::get(unwrap(RealTy), N));
593 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
594 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text)));
597 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[],
599 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
602 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
603 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
606 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
607 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
610 /*--.. Operations on composite constants ...................................--*/
612 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
614 LLVMBool DontNullTerminate) {
615 /* Inverted the sense of AddNull because ', 0)' is a
616 better mnemonic for null termination than ', 1)'. */
617 return wrap(ConstantArray::get(*unwrap(C), StringRef(Str, Length),
618 DontNullTerminate == 0));
620 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
621 LLVMValueRef *ConstantVals,
622 unsigned Count, LLVMBool Packed) {
623 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
624 return wrap(ConstantStruct::getAnon(*unwrap(C), makeArrayRef(Elements, Count),
628 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
629 LLVMBool DontNullTerminate) {
630 return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
633 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
634 LLVMValueRef *ConstantVals, unsigned Length) {
635 ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
636 return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
638 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
640 return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
644 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
645 LLVMValueRef *ConstantVals,
647 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
648 StructType *Ty = cast<StructType>(unwrap(StructTy));
650 return wrap(ConstantStruct::get(Ty, makeArrayRef(Elements, Count)));
653 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
654 return wrap(ConstantVector::get(makeArrayRef(
655 unwrap<Constant>(ScalarConstantVals, Size), Size)));
658 /*-- Opcode mapping */
660 static LLVMOpcode map_to_llvmopcode(int opcode)
663 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
664 #include "llvm/Instruction.def"
667 assert(false && "Unhandled Opcode.");
669 return static_cast<LLVMOpcode>(0);
672 static int map_from_llvmopcode(LLVMOpcode code)
675 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
676 #include "llvm/Instruction.def"
679 assert(false && "Unhandled Opcode.");
684 /*--.. Constant expressions ................................................--*/
686 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal) {
687 return map_to_llvmopcode(unwrap<ConstantExpr>(ConstantVal)->getOpcode());
690 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) {
691 return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
694 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) {
695 return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
698 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) {
699 return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
702 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal) {
703 return wrap(ConstantExpr::getNSWNeg(unwrap<Constant>(ConstantVal)));
706 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal) {
707 return wrap(ConstantExpr::getNUWNeg(unwrap<Constant>(ConstantVal)));
711 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal) {
712 return wrap(ConstantExpr::getFNeg(unwrap<Constant>(ConstantVal)));
715 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) {
716 return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
719 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
720 return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
721 unwrap<Constant>(RHSConstant)));
724 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant,
725 LLVMValueRef RHSConstant) {
726 return wrap(ConstantExpr::getNSWAdd(unwrap<Constant>(LHSConstant),
727 unwrap<Constant>(RHSConstant)));
730 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant,
731 LLVMValueRef RHSConstant) {
732 return wrap(ConstantExpr::getNUWAdd(unwrap<Constant>(LHSConstant),
733 unwrap<Constant>(RHSConstant)));
736 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
737 return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant),
738 unwrap<Constant>(RHSConstant)));
741 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
742 return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
743 unwrap<Constant>(RHSConstant)));
746 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant,
747 LLVMValueRef RHSConstant) {
748 return wrap(ConstantExpr::getNSWSub(unwrap<Constant>(LHSConstant),
749 unwrap<Constant>(RHSConstant)));
752 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant,
753 LLVMValueRef RHSConstant) {
754 return wrap(ConstantExpr::getNUWSub(unwrap<Constant>(LHSConstant),
755 unwrap<Constant>(RHSConstant)));
758 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
759 return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant),
760 unwrap<Constant>(RHSConstant)));
763 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
764 return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
765 unwrap<Constant>(RHSConstant)));
768 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant,
769 LLVMValueRef RHSConstant) {
770 return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
771 unwrap<Constant>(RHSConstant)));
774 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant,
775 LLVMValueRef RHSConstant) {
776 return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
777 unwrap<Constant>(RHSConstant)));
780 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
781 return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant),
782 unwrap<Constant>(RHSConstant)));
785 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
786 return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
787 unwrap<Constant>(RHSConstant)));
790 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
791 return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
792 unwrap<Constant>(RHSConstant)));
795 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant,
796 LLVMValueRef RHSConstant) {
797 return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant),
798 unwrap<Constant>(RHSConstant)));
801 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
802 return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
803 unwrap<Constant>(RHSConstant)));
806 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
807 return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
808 unwrap<Constant>(RHSConstant)));
811 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
812 return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
813 unwrap<Constant>(RHSConstant)));
816 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
817 return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
818 unwrap<Constant>(RHSConstant)));
821 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
822 return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
823 unwrap<Constant>(RHSConstant)));
826 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
827 return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
828 unwrap<Constant>(RHSConstant)));
831 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
832 return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
833 unwrap<Constant>(RHSConstant)));
836 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
837 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
838 return wrap(ConstantExpr::getICmp(Predicate,
839 unwrap<Constant>(LHSConstant),
840 unwrap<Constant>(RHSConstant)));
843 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
844 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
845 return wrap(ConstantExpr::getFCmp(Predicate,
846 unwrap<Constant>(LHSConstant),
847 unwrap<Constant>(RHSConstant)));
850 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
851 return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
852 unwrap<Constant>(RHSConstant)));
855 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
856 return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
857 unwrap<Constant>(RHSConstant)));
860 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
861 return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
862 unwrap<Constant>(RHSConstant)));
865 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
866 LLVMValueRef *ConstantIndices, unsigned NumIndices) {
867 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
869 return wrap(ConstantExpr::getGetElementPtr(unwrap<Constant>(ConstantVal),
873 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
874 LLVMValueRef *ConstantIndices,
875 unsigned NumIndices) {
876 Constant* Val = unwrap<Constant>(ConstantVal);
877 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
879 return wrap(ConstantExpr::getInBoundsGetElementPtr(Val, IdxList));
882 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
883 return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
887 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
888 return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
892 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
893 return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
897 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
898 return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
902 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
903 return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
907 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
908 return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
912 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
913 return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
917 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
918 return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
922 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
923 return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
927 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
928 return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
932 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
933 return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
937 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
938 return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
942 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
943 LLVMTypeRef ToType) {
944 return wrap(ConstantExpr::getZExtOrBitCast(unwrap<Constant>(ConstantVal),
948 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
949 LLVMTypeRef ToType) {
950 return wrap(ConstantExpr::getSExtOrBitCast(unwrap<Constant>(ConstantVal),
954 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
955 LLVMTypeRef ToType) {
956 return wrap(ConstantExpr::getTruncOrBitCast(unwrap<Constant>(ConstantVal),
960 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
961 LLVMTypeRef ToType) {
962 return wrap(ConstantExpr::getPointerCast(unwrap<Constant>(ConstantVal),
966 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
968 return wrap(ConstantExpr::getIntegerCast(unwrap<Constant>(ConstantVal),
969 unwrap(ToType), isSigned));
972 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
973 return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal),
977 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
978 LLVMValueRef ConstantIfTrue,
979 LLVMValueRef ConstantIfFalse) {
980 return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
981 unwrap<Constant>(ConstantIfTrue),
982 unwrap<Constant>(ConstantIfFalse)));
985 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
986 LLVMValueRef IndexConstant) {
987 return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
988 unwrap<Constant>(IndexConstant)));
991 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
992 LLVMValueRef ElementValueConstant,
993 LLVMValueRef IndexConstant) {
994 return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
995 unwrap<Constant>(ElementValueConstant),
996 unwrap<Constant>(IndexConstant)));
999 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1000 LLVMValueRef VectorBConstant,
1001 LLVMValueRef MaskConstant) {
1002 return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
1003 unwrap<Constant>(VectorBConstant),
1004 unwrap<Constant>(MaskConstant)));
1007 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1009 return wrap(ConstantExpr::getExtractValue(unwrap<Constant>(AggConstant),
1010 makeArrayRef(IdxList, NumIdx)));
1013 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1014 LLVMValueRef ElementValueConstant,
1015 unsigned *IdxList, unsigned NumIdx) {
1016 return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant),
1017 unwrap<Constant>(ElementValueConstant),
1018 makeArrayRef(IdxList, NumIdx)));
1021 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
1022 const char *Constraints,
1023 LLVMBool HasSideEffects,
1024 LLVMBool IsAlignStack) {
1025 return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
1026 Constraints, HasSideEffects, IsAlignStack));
1029 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB) {
1030 return wrap(BlockAddress::get(unwrap<Function>(F), unwrap(BB)));
1033 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1035 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) {
1036 return wrap(unwrap<GlobalValue>(Global)->getParent());
1039 LLVMBool LLVMIsDeclaration(LLVMValueRef Global) {
1040 return unwrap<GlobalValue>(Global)->isDeclaration();
1043 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) {
1044 switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1046 assert(false && "Unhandled Linkage Type.");
1047 case GlobalValue::ExternalLinkage:
1048 return LLVMExternalLinkage;
1049 case GlobalValue::AvailableExternallyLinkage:
1050 return LLVMAvailableExternallyLinkage;
1051 case GlobalValue::LinkOnceAnyLinkage:
1052 return LLVMLinkOnceAnyLinkage;
1053 case GlobalValue::LinkOnceODRLinkage:
1054 return LLVMLinkOnceODRLinkage;
1055 case GlobalValue::WeakAnyLinkage:
1056 return LLVMWeakAnyLinkage;
1057 case GlobalValue::WeakODRLinkage:
1058 return LLVMWeakODRLinkage;
1059 case GlobalValue::AppendingLinkage:
1060 return LLVMAppendingLinkage;
1061 case GlobalValue::InternalLinkage:
1062 return LLVMInternalLinkage;
1063 case GlobalValue::PrivateLinkage:
1064 return LLVMPrivateLinkage;
1065 case GlobalValue::LinkerPrivateLinkage:
1066 return LLVMLinkerPrivateLinkage;
1067 case GlobalValue::LinkerPrivateWeakLinkage:
1068 return LLVMLinkerPrivateWeakLinkage;
1069 case GlobalValue::LinkerPrivateWeakDefAutoLinkage:
1070 return LLVMLinkerPrivateWeakDefAutoLinkage;
1071 case GlobalValue::DLLImportLinkage:
1072 return LLVMDLLImportLinkage;
1073 case GlobalValue::DLLExportLinkage:
1074 return LLVMDLLExportLinkage;
1075 case GlobalValue::ExternalWeakLinkage:
1076 return LLVMExternalWeakLinkage;
1077 case GlobalValue::CommonLinkage:
1078 return LLVMCommonLinkage;
1081 // Should never get here.
1082 return static_cast<LLVMLinkage>(0);
1085 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
1086 GlobalValue *GV = unwrap<GlobalValue>(Global);
1090 assert(false && "Unhandled Linkage Type.");
1091 case LLVMExternalLinkage:
1092 GV->setLinkage(GlobalValue::ExternalLinkage);
1094 case LLVMAvailableExternallyLinkage:
1095 GV->setLinkage(GlobalValue::AvailableExternallyLinkage);
1097 case LLVMLinkOnceAnyLinkage:
1098 GV->setLinkage(GlobalValue::LinkOnceAnyLinkage);
1100 case LLVMLinkOnceODRLinkage:
1101 GV->setLinkage(GlobalValue::LinkOnceODRLinkage);
1103 case LLVMWeakAnyLinkage:
1104 GV->setLinkage(GlobalValue::WeakAnyLinkage);
1106 case LLVMWeakODRLinkage:
1107 GV->setLinkage(GlobalValue::WeakODRLinkage);
1109 case LLVMAppendingLinkage:
1110 GV->setLinkage(GlobalValue::AppendingLinkage);
1112 case LLVMInternalLinkage:
1113 GV->setLinkage(GlobalValue::InternalLinkage);
1115 case LLVMPrivateLinkage:
1116 GV->setLinkage(GlobalValue::PrivateLinkage);
1118 case LLVMLinkerPrivateLinkage:
1119 GV->setLinkage(GlobalValue::LinkerPrivateLinkage);
1121 case LLVMLinkerPrivateWeakLinkage:
1122 GV->setLinkage(GlobalValue::LinkerPrivateWeakLinkage);
1124 case LLVMLinkerPrivateWeakDefAutoLinkage:
1125 GV->setLinkage(GlobalValue::LinkerPrivateWeakDefAutoLinkage);
1127 case LLVMDLLImportLinkage:
1128 GV->setLinkage(GlobalValue::DLLImportLinkage);
1130 case LLVMDLLExportLinkage:
1131 GV->setLinkage(GlobalValue::DLLExportLinkage);
1133 case LLVMExternalWeakLinkage:
1134 GV->setLinkage(GlobalValue::ExternalWeakLinkage);
1136 case LLVMGhostLinkage:
1138 << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1140 case LLVMCommonLinkage:
1141 GV->setLinkage(GlobalValue::CommonLinkage);
1146 const char *LLVMGetSection(LLVMValueRef Global) {
1147 return unwrap<GlobalValue>(Global)->getSection().c_str();
1150 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
1151 unwrap<GlobalValue>(Global)->setSection(Section);
1154 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
1155 return static_cast<LLVMVisibility>(
1156 unwrap<GlobalValue>(Global)->getVisibility());
1159 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) {
1160 unwrap<GlobalValue>(Global)
1161 ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
1164 unsigned LLVMGetAlignment(LLVMValueRef Global) {
1165 return unwrap<GlobalValue>(Global)->getAlignment();
1168 void LLVMSetAlignment(LLVMValueRef Global, unsigned Bytes) {
1169 unwrap<GlobalValue>(Global)->setAlignment(Bytes);
1172 /*--.. Operations on global variables ......................................--*/
1174 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
1175 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1176 GlobalValue::ExternalLinkage, 0, Name));
1179 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1181 unsigned AddressSpace) {
1182 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1183 GlobalValue::ExternalLinkage, 0, Name, 0,
1184 false, AddressSpace));
1187 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {
1188 return wrap(unwrap(M)->getNamedGlobal(Name));
1191 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) {
1192 Module *Mod = unwrap(M);
1193 Module::global_iterator I = Mod->global_begin();
1194 if (I == Mod->global_end())
1199 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) {
1200 Module *Mod = unwrap(M);
1201 Module::global_iterator I = Mod->global_end();
1202 if (I == Mod->global_begin())
1207 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) {
1208 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1209 Module::global_iterator I = GV;
1210 if (++I == GV->getParent()->global_end())
1215 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) {
1216 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1217 Module::global_iterator I = GV;
1218 if (I == GV->getParent()->global_begin())
1223 void LLVMDeleteGlobal(LLVMValueRef GlobalVar) {
1224 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
1227 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) {
1228 GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
1229 if ( !GV->hasInitializer() )
1231 return wrap(GV->getInitializer());
1234 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
1235 unwrap<GlobalVariable>(GlobalVar)
1236 ->setInitializer(unwrap<Constant>(ConstantVal));
1239 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
1240 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
1243 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal) {
1244 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
1247 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
1248 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
1251 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant) {
1252 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
1255 /*--.. Operations on aliases ......................................--*/
1257 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1259 return wrap(new GlobalAlias(unwrap(Ty), GlobalValue::ExternalLinkage, Name,
1260 unwrap<Constant>(Aliasee), unwrap (M)));
1263 /*--.. Operations on functions .............................................--*/
1265 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1266 LLVMTypeRef FunctionTy) {
1267 return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
1268 GlobalValue::ExternalLinkage, Name, unwrap(M)));
1271 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
1272 return wrap(unwrap(M)->getFunction(Name));
1275 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) {
1276 Module *Mod = unwrap(M);
1277 Module::iterator I = Mod->begin();
1278 if (I == Mod->end())
1283 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) {
1284 Module *Mod = unwrap(M);
1285 Module::iterator I = Mod->end();
1286 if (I == Mod->begin())
1291 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) {
1292 Function *Func = unwrap<Function>(Fn);
1293 Module::iterator I = Func;
1294 if (++I == Func->getParent()->end())
1299 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) {
1300 Function *Func = unwrap<Function>(Fn);
1301 Module::iterator I = Func;
1302 if (I == Func->getParent()->begin())
1307 void LLVMDeleteFunction(LLVMValueRef Fn) {
1308 unwrap<Function>(Fn)->eraseFromParent();
1311 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) {
1312 if (Function *F = dyn_cast<Function>(unwrap(Fn)))
1313 return F->getIntrinsicID();
1317 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) {
1318 return unwrap<Function>(Fn)->getCallingConv();
1321 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
1322 return unwrap<Function>(Fn)->setCallingConv(
1323 static_cast<CallingConv::ID>(CC));
1326 const char *LLVMGetGC(LLVMValueRef Fn) {
1327 Function *F = unwrap<Function>(Fn);
1328 return F->hasGC()? F->getGC() : 0;
1331 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
1332 Function *F = unwrap<Function>(Fn);
1339 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1340 Function *Func = unwrap<Function>(Fn);
1341 const AttrListPtr PAL = Func->getAttributes();
1342 const AttrListPtr PALnew = PAL.addAttr(~0U, PA);
1343 Func->setAttributes(PALnew);
1346 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1347 Function *Func = unwrap<Function>(Fn);
1348 const AttrListPtr PAL = Func->getAttributes();
1349 const AttrListPtr PALnew = PAL.removeAttr(~0U, PA);
1350 Func->setAttributes(PALnew);
1353 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) {
1354 Function *Func = unwrap<Function>(Fn);
1355 const AttrListPtr PAL = Func->getAttributes();
1356 Attributes attr = PAL.getFnAttributes();
1357 return (LLVMAttribute)attr;
1360 /*--.. Operations on parameters ............................................--*/
1362 unsigned LLVMCountParams(LLVMValueRef FnRef) {
1363 // This function is strictly redundant to
1364 // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1365 return unwrap<Function>(FnRef)->arg_size();
1368 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
1369 Function *Fn = unwrap<Function>(FnRef);
1370 for (Function::arg_iterator I = Fn->arg_begin(),
1371 E = Fn->arg_end(); I != E; I++)
1372 *ParamRefs++ = wrap(I);
1375 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
1376 Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
1382 LLVMValueRef LLVMGetParamParent(LLVMValueRef V) {
1383 return wrap(unwrap<Argument>(V)->getParent());
1386 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn) {
1387 Function *Func = unwrap<Function>(Fn);
1388 Function::arg_iterator I = Func->arg_begin();
1389 if (I == Func->arg_end())
1394 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) {
1395 Function *Func = unwrap<Function>(Fn);
1396 Function::arg_iterator I = Func->arg_end();
1397 if (I == Func->arg_begin())
1402 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) {
1403 Argument *A = unwrap<Argument>(Arg);
1404 Function::arg_iterator I = A;
1405 if (++I == A->getParent()->arg_end())
1410 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
1411 Argument *A = unwrap<Argument>(Arg);
1412 Function::arg_iterator I = A;
1413 if (I == A->getParent()->arg_begin())
1418 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1419 unwrap<Argument>(Arg)->addAttr(PA);
1422 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1423 unwrap<Argument>(Arg)->removeAttr(PA);
1426 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) {
1427 Argument *A = unwrap<Argument>(Arg);
1428 Attributes attr = A->getParent()->getAttributes().getParamAttributes(
1430 return (LLVMAttribute)attr;
1434 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
1435 unwrap<Argument>(Arg)->addAttr(
1436 Attribute::constructAlignmentFromInt(align));
1439 /*--.. Operations on basic blocks ..........................................--*/
1441 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) {
1442 return wrap(static_cast<Value*>(unwrap(BB)));
1445 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val) {
1446 return isa<BasicBlock>(unwrap(Val));
1449 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) {
1450 return wrap(unwrap<BasicBlock>(Val));
1453 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB) {
1454 return wrap(unwrap(BB)->getParent());
1457 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB) {
1458 return wrap(unwrap(BB)->getTerminator());
1461 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
1462 return unwrap<Function>(FnRef)->size();
1465 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
1466 Function *Fn = unwrap<Function>(FnRef);
1467 for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
1468 *BasicBlocksRefs++ = wrap(I);
1471 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
1472 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
1475 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn) {
1476 Function *Func = unwrap<Function>(Fn);
1477 Function::iterator I = Func->begin();
1478 if (I == Func->end())
1483 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) {
1484 Function *Func = unwrap<Function>(Fn);
1485 Function::iterator I = Func->end();
1486 if (I == Func->begin())
1491 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) {
1492 BasicBlock *Block = unwrap(BB);
1493 Function::iterator I = Block;
1494 if (++I == Block->getParent()->end())
1499 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
1500 BasicBlock *Block = unwrap(BB);
1501 Function::iterator I = Block;
1502 if (I == Block->getParent()->begin())
1507 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1510 return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
1513 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
1514 return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
1517 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1518 LLVMBasicBlockRef BBRef,
1520 BasicBlock *BB = unwrap(BBRef);
1521 return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
1524 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef,
1526 return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
1529 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {
1530 unwrap(BBRef)->eraseFromParent();
1533 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BBRef) {
1534 unwrap(BBRef)->removeFromParent();
1537 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1538 unwrap(BB)->moveBefore(unwrap(MovePos));
1541 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1542 unwrap(BB)->moveAfter(unwrap(MovePos));
1545 /*--.. Operations on instructions ..........................................--*/
1547 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) {
1548 return wrap(unwrap<Instruction>(Inst)->getParent());
1551 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB) {
1552 BasicBlock *Block = unwrap(BB);
1553 BasicBlock::iterator I = Block->begin();
1554 if (I == Block->end())
1559 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) {
1560 BasicBlock *Block = unwrap(BB);
1561 BasicBlock::iterator I = Block->end();
1562 if (I == Block->begin())
1567 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) {
1568 Instruction *Instr = unwrap<Instruction>(Inst);
1569 BasicBlock::iterator I = Instr;
1570 if (++I == Instr->getParent()->end())
1575 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) {
1576 Instruction *Instr = unwrap<Instruction>(Inst);
1577 BasicBlock::iterator I = Instr;
1578 if (I == Instr->getParent()->begin())
1583 void LLVMInstructionEraseFromParent(LLVMValueRef Inst) {
1584 unwrap<Instruction>(Inst)->eraseFromParent();
1587 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) {
1588 if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
1589 return (LLVMIntPredicate)I->getPredicate();
1590 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
1591 if (CE->getOpcode() == Instruction::ICmp)
1592 return (LLVMIntPredicate)CE->getPredicate();
1593 return (LLVMIntPredicate)0;
1596 /*--.. Call and invoke instructions ........................................--*/
1598 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
1599 Value *V = unwrap(Instr);
1600 if (CallInst *CI = dyn_cast<CallInst>(V))
1601 return CI->getCallingConv();
1602 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
1603 return II->getCallingConv();
1604 llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
1608 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
1609 Value *V = unwrap(Instr);
1610 if (CallInst *CI = dyn_cast<CallInst>(V))
1611 return CI->setCallingConv(static_cast<CallingConv::ID>(CC));
1612 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
1613 return II->setCallingConv(static_cast<CallingConv::ID>(CC));
1614 llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
1617 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
1619 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1621 Call.getAttributes().addAttr(index, PA));
1624 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
1626 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1628 Call.getAttributes().removeAttr(index, PA));
1631 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
1633 CallSite Call = CallSite(unwrap<Instruction>(Instr));
1635 Call.getAttributes().addAttr(index,
1636 Attribute::constructAlignmentFromInt(align)));
1639 /*--.. Operations on call instructions (only) ..............................--*/
1641 LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
1642 return unwrap<CallInst>(Call)->isTailCall();
1645 void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
1646 unwrap<CallInst>(Call)->setTailCall(isTailCall);
1649 /*--.. Operations on switch instructions (only) ............................--*/
1651 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch) {
1652 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
1655 /*--.. Operations on phi nodes .............................................--*/
1657 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
1658 LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
1659 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
1660 for (unsigned I = 0; I != Count; ++I)
1661 PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
1664 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
1665 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
1668 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index) {
1669 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
1672 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) {
1673 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
1677 /*===-- Instruction builders ----------------------------------------------===*/
1679 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C) {
1680 return wrap(new IRBuilder<>(*unwrap(C)));
1683 LLVMBuilderRef LLVMCreateBuilder(void) {
1684 return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
1687 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
1688 LLVMValueRef Instr) {
1689 BasicBlock *BB = unwrap(Block);
1690 Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end();
1691 unwrap(Builder)->SetInsertPoint(BB, I);
1694 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
1695 Instruction *I = unwrap<Instruction>(Instr);
1696 unwrap(Builder)->SetInsertPoint(I->getParent(), I);
1699 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
1700 BasicBlock *BB = unwrap(Block);
1701 unwrap(Builder)->SetInsertPoint(BB);
1704 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder) {
1705 return wrap(unwrap(Builder)->GetInsertBlock());
1708 void LLVMClearInsertionPosition(LLVMBuilderRef Builder) {
1709 unwrap(Builder)->ClearInsertionPoint();
1712 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr) {
1713 unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
1716 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
1718 unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name);
1721 void LLVMDisposeBuilder(LLVMBuilderRef Builder) {
1722 delete unwrap(Builder);
1725 /*--.. Metadata builders ...................................................--*/
1727 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) {
1728 MDNode *Loc = L ? unwrap<MDNode>(L) : NULL;
1729 unwrap(Builder)->SetCurrentDebugLocation(DebugLoc::getFromDILocation(Loc));
1732 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder) {
1733 return wrap(unwrap(Builder)->getCurrentDebugLocation()
1734 .getAsMDNode(unwrap(Builder)->getContext()));
1737 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst) {
1738 unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
1742 /*--.. Instruction builders ................................................--*/
1744 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {
1745 return wrap(unwrap(B)->CreateRetVoid());
1748 LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) {
1749 return wrap(unwrap(B)->CreateRet(unwrap(V)));
1752 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals,
1754 return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
1757 LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) {
1758 return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
1761 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If,
1762 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
1763 return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
1766 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V,
1767 LLVMBasicBlockRef Else, unsigned NumCases) {
1768 return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
1771 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
1772 unsigned NumDests) {
1773 return wrap(unwrap(B)->CreateIndirectBr(unwrap(Addr), NumDests));
1776 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,
1777 LLVMValueRef *Args, unsigned NumArgs,
1778 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
1780 return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
1781 makeArrayRef(unwrap(Args), NumArgs),
1785 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
1786 LLVMValueRef PersFn, unsigned NumClauses,
1788 return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty),
1789 cast<Function>(unwrap(PersFn)),
1793 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn) {
1794 return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
1797 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
1798 return wrap(unwrap(B)->CreateUnreachable());
1801 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
1802 LLVMBasicBlockRef Dest) {
1803 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
1806 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest) {
1807 unwrap<IndirectBrInst>(IndirectBr)->addDestination(unwrap(Dest));
1810 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal) {
1811 unwrap<LandingPadInst>(LandingPad)->
1812 addClause(cast<Constant>(unwrap(ClauseVal)));
1815 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
1816 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
1819 /*--.. Arithmetic ..........................................................--*/
1821 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1823 return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
1826 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1828 return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
1831 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1833 return wrap(unwrap(B)->CreateNUWAdd(unwrap(LHS), unwrap(RHS), Name));
1836 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1838 return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
1841 LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1843 return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
1846 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1848 return wrap(unwrap(B)->CreateNSWSub(unwrap(LHS), unwrap(RHS), Name));
1851 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1853 return wrap(unwrap(B)->CreateNUWSub(unwrap(LHS), unwrap(RHS), Name));
1856 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1858 return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
1861 LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1863 return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
1866 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1868 return wrap(unwrap(B)->CreateNSWMul(unwrap(LHS), unwrap(RHS), Name));
1871 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1873 return wrap(unwrap(B)->CreateNUWMul(unwrap(LHS), unwrap(RHS), Name));
1876 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1878 return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
1881 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1883 return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
1886 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1888 return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
1891 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS,
1892 LLVMValueRef RHS, const char *Name) {
1893 return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
1896 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1898 return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
1901 LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1903 return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
1906 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1908 return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
1911 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1913 return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
1916 LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1918 return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
1921 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1923 return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
1926 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1928 return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
1931 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1933 return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
1936 LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1938 return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
1941 LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
1943 return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
1946 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
1947 LLVMValueRef LHS, LLVMValueRef RHS,
1949 return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
1950 unwrap(RHS), Name));
1953 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1954 return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
1957 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
1959 return wrap(unwrap(B)->CreateNSWNeg(unwrap(V), Name));
1962 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
1964 return wrap(unwrap(B)->CreateNUWNeg(unwrap(V), Name));
1967 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1968 return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name));
1971 LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
1972 return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
1975 /*--.. Memory ..............................................................--*/
1977 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
1979 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
1980 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
1981 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
1982 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
1983 ITy, unwrap(Ty), AllocSize,
1985 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
1988 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
1989 LLVMValueRef Val, const char *Name) {
1990 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
1991 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
1992 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
1993 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
1994 ITy, unwrap(Ty), AllocSize,
1995 unwrap(Val), 0, "");
1996 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
1999 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2001 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), 0, Name));
2004 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2005 LLVMValueRef Val, const char *Name) {
2006 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
2009 LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {
2010 return wrap(unwrap(B)->Insert(
2011 CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
2015 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
2017 return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
2020 LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val,
2021 LLVMValueRef PointerVal) {
2022 return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
2025 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2026 LLVMValueRef *Indices, unsigned NumIndices,
2028 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2029 return wrap(unwrap(B)->CreateGEP(unwrap(Pointer), IdxList, Name));
2032 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2033 LLVMValueRef *Indices, unsigned NumIndices,
2035 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2036 return wrap(unwrap(B)->CreateInBoundsGEP(unwrap(Pointer), IdxList, Name));
2039 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2040 unsigned Idx, const char *Name) {
2041 return wrap(unwrap(B)->CreateStructGEP(unwrap(Pointer), Idx, Name));
2044 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2046 return wrap(unwrap(B)->CreateGlobalString(Str, Name));
2049 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2051 return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
2054 /*--.. Casts ...............................................................--*/
2056 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2057 LLVMTypeRef DestTy, const char *Name) {
2058 return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
2061 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val,
2062 LLVMTypeRef DestTy, const char *Name) {
2063 return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
2066 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val,
2067 LLVMTypeRef DestTy, const char *Name) {
2068 return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
2071 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val,
2072 LLVMTypeRef DestTy, const char *Name) {
2073 return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
2076 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val,
2077 LLVMTypeRef DestTy, const char *Name) {
2078 return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
2081 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2082 LLVMTypeRef DestTy, const char *Name) {
2083 return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
2086 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2087 LLVMTypeRef DestTy, const char *Name) {
2088 return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
2091 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2092 LLVMTypeRef DestTy, const char *Name) {
2093 return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
2096 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val,
2097 LLVMTypeRef DestTy, const char *Name) {
2098 return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
2101 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val,
2102 LLVMTypeRef DestTy, const char *Name) {
2103 return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
2106 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val,
2107 LLVMTypeRef DestTy, const char *Name) {
2108 return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
2111 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2112 LLVMTypeRef DestTy, const char *Name) {
2113 return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
2116 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2117 LLVMTypeRef DestTy, const char *Name) {
2118 return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
2122 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2123 LLVMTypeRef DestTy, const char *Name) {
2124 return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
2128 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2129 LLVMTypeRef DestTy, const char *Name) {
2130 return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
2134 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2135 LLVMTypeRef DestTy, const char *Name) {
2136 return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
2137 unwrap(DestTy), Name));
2140 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val,
2141 LLVMTypeRef DestTy, const char *Name) {
2142 return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
2145 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val,
2146 LLVMTypeRef DestTy, const char *Name) {
2147 return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy),
2148 /*isSigned*/true, Name));
2151 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef B, LLVMValueRef Val,
2152 LLVMTypeRef DestTy, const char *Name) {
2153 return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
2156 /*--.. Comparisons .........................................................--*/
2158 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
2159 LLVMValueRef LHS, LLVMValueRef RHS,
2161 return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
2162 unwrap(LHS), unwrap(RHS), Name));
2165 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
2166 LLVMValueRef LHS, LLVMValueRef RHS,
2168 return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
2169 unwrap(LHS), unwrap(RHS), Name));
2172 /*--.. Miscellaneous instructions ..........................................--*/
2174 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {
2175 return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
2178 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
2179 LLVMValueRef *Args, unsigned NumArgs,
2181 return wrap(unwrap(B)->CreateCall(unwrap(Fn),
2182 makeArrayRef(unwrap(Args), NumArgs),
2186 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
2187 LLVMValueRef Then, LLVMValueRef Else,
2189 return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
2193 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List,
2194 LLVMTypeRef Ty, const char *Name) {
2195 return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
2198 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2199 LLVMValueRef Index, const char *Name) {
2200 return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
2204 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2205 LLVMValueRef EltVal, LLVMValueRef Index,
2207 return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
2208 unwrap(Index), Name));
2211 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1,
2212 LLVMValueRef V2, LLVMValueRef Mask,
2214 return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
2215 unwrap(Mask), Name));
2218 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2219 unsigned Index, const char *Name) {
2220 return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
2223 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2224 LLVMValueRef EltVal, unsigned Index,
2226 return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
2230 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val,
2232 return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
2235 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef B, LLVMValueRef Val,
2237 return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
2240 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS,
2241 LLVMValueRef RHS, const char *Name) {
2242 return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
2246 /*===-- Module providers --------------------------------------------------===*/
2248 LLVMModuleProviderRef
2249 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) {
2250 return reinterpret_cast<LLVMModuleProviderRef>(M);
2253 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) {
2258 /*===-- Memory buffers ----------------------------------------------------===*/
2260 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(
2262 LLVMMemoryBufferRef *OutMemBuf,
2263 char **OutMessage) {
2265 OwningPtr<MemoryBuffer> MB;
2267 if (!(ec = MemoryBuffer::getFile(Path, MB))) {
2268 *OutMemBuf = wrap(MB.take());
2272 *OutMessage = strdup(ec.message().c_str());
2276 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2277 char **OutMessage) {
2278 OwningPtr<MemoryBuffer> MB;
2280 if (!(ec = MemoryBuffer::getSTDIN(MB))) {
2281 *OutMemBuf = wrap(MB.take());
2285 *OutMessage = strdup(ec.message().c_str());
2289 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) {
2290 delete unwrap(MemBuf);
2293 /*===-- Pass Registry -----------------------------------------------------===*/
2295 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void) {
2296 return wrap(PassRegistry::getPassRegistry());
2299 /*===-- Pass Manager ------------------------------------------------------===*/
2301 LLVMPassManagerRef LLVMCreatePassManager() {
2302 return wrap(new PassManager());
2305 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M) {
2306 return wrap(new FunctionPassManager(unwrap(M)));
2309 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) {
2310 return LLVMCreateFunctionPassManagerForModule(
2311 reinterpret_cast<LLVMModuleRef>(P));
2314 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
2315 return unwrap<PassManager>(PM)->run(*unwrap(M));
2318 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM) {
2319 return unwrap<FunctionPassManager>(FPM)->doInitialization();
2322 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F) {
2323 return unwrap<FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
2326 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM) {
2327 return unwrap<FunctionPassManager>(FPM)->doFinalization();
2330 void LLVMDisposePassManager(LLVMPassManagerRef PM) {