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/IR/Attributes.h"
18 #include "llvm/IR/CallSite.h"
19 #include "llvm/IR/Constants.h"
20 #include "llvm/IR/DerivedTypes.h"
21 #include "llvm/IR/DiagnosticInfo.h"
22 #include "llvm/IR/DiagnosticPrinter.h"
23 #include "llvm/IR/GlobalAlias.h"
24 #include "llvm/IR/GlobalVariable.h"
25 #include "llvm/IR/IRBuilder.h"
26 #include "llvm/IR/InlineAsm.h"
27 #include "llvm/IR/IntrinsicInst.h"
28 #include "llvm/IR/LLVMContext.h"
29 #include "llvm/IR/LegacyPassManager.h"
30 #include "llvm/IR/Module.h"
31 #include "llvm/Support/Debug.h"
32 #include "llvm/Support/ErrorHandling.h"
33 #include "llvm/Support/FileSystem.h"
34 #include "llvm/Support/ManagedStatic.h"
35 #include "llvm/Support/MemoryBuffer.h"
36 #include "llvm/Support/Threading.h"
37 #include "llvm/Support/raw_ostream.h"
41 #include <system_error>
45 #define DEBUG_TYPE "ir"
47 void llvm::initializeCore(PassRegistry &Registry) {
48 initializeDominatorTreeWrapperPassPass(Registry);
49 initializePrintModulePassWrapperPass(Registry);
50 initializePrintFunctionPassWrapperPass(Registry);
51 initializePrintBasicBlockPassPass(Registry);
52 initializeVerifierLegacyPassPass(Registry);
55 void LLVMInitializeCore(LLVMPassRegistryRef R) {
56 initializeCore(*unwrap(R));
63 /*===-- Error handling ----------------------------------------------------===*/
65 char *LLVMCreateMessage(const char *Message) {
66 return strdup(Message);
69 void LLVMDisposeMessage(char *Message) {
74 /*===-- Operations on contexts --------------------------------------------===*/
76 LLVMContextRef LLVMContextCreate() {
77 return wrap(new LLVMContext());
80 LLVMContextRef LLVMGetGlobalContext() {
81 return wrap(&getGlobalContext());
84 void LLVMContextSetDiagnosticHandler(LLVMContextRef C,
85 LLVMDiagnosticHandler Handler,
86 void *DiagnosticContext) {
87 unwrap(C)->setDiagnosticHandler(
88 LLVM_EXTENSION reinterpret_cast<LLVMContext::DiagnosticHandlerTy>(Handler),
92 void LLVMContextSetYieldCallback(LLVMContextRef C, LLVMYieldCallback Callback,
95 LLVM_EXTENSION reinterpret_cast<LLVMContext::YieldCallbackTy>(Callback);
96 unwrap(C)->setYieldCallback(YieldCallback, OpaqueHandle);
99 void LLVMContextDispose(LLVMContextRef C) {
103 unsigned LLVMGetMDKindIDInContext(LLVMContextRef C, const char* Name,
105 return unwrap(C)->getMDKindID(StringRef(Name, SLen));
108 unsigned LLVMGetMDKindID(const char* Name, unsigned SLen) {
109 return LLVMGetMDKindIDInContext(LLVMGetGlobalContext(), Name, SLen);
112 char *LLVMGetDiagInfoDescription(LLVMDiagnosticInfoRef DI) {
113 std::string MsgStorage;
114 raw_string_ostream Stream(MsgStorage);
115 DiagnosticPrinterRawOStream DP(Stream);
117 unwrap(DI)->print(DP);
120 return LLVMCreateMessage(MsgStorage.c_str());
123 LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI){
124 LLVMDiagnosticSeverity severity;
126 switch(unwrap(DI)->getSeverity()) {
128 severity = LLVMDSError;
131 severity = LLVMDSWarning;
134 severity = LLVMDSRemark;
137 severity = LLVMDSNote;
147 /*===-- Operations on modules ---------------------------------------------===*/
149 LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) {
150 return wrap(new Module(ModuleID, getGlobalContext()));
153 LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID,
155 return wrap(new Module(ModuleID, *unwrap(C)));
158 void LLVMDisposeModule(LLVMModuleRef M) {
162 /*--.. Data layout .........................................................--*/
163 const char * LLVMGetDataLayout(LLVMModuleRef M) {
164 return unwrap(M)->getDataLayoutStr().c_str();
167 void LLVMSetDataLayout(LLVMModuleRef M, const char *Triple) {
168 unwrap(M)->setDataLayout(Triple);
171 /*--.. Target triple .......................................................--*/
172 const char * LLVMGetTarget(LLVMModuleRef M) {
173 return unwrap(M)->getTargetTriple().c_str();
176 void LLVMSetTarget(LLVMModuleRef M, const char *Triple) {
177 unwrap(M)->setTargetTriple(Triple);
180 void LLVMDumpModule(LLVMModuleRef M) {
184 LLVMBool LLVMPrintModuleToFile(LLVMModuleRef M, const char *Filename,
185 char **ErrorMessage) {
187 raw_fd_ostream dest(Filename, EC, sys::fs::F_Text);
189 *ErrorMessage = strdup(EC.message().c_str());
193 unwrap(M)->print(dest, nullptr);
197 if (dest.has_error()) {
198 *ErrorMessage = strdup("Error printing to file");
205 char *LLVMPrintModuleToString(LLVMModuleRef M) {
207 raw_string_ostream os(buf);
209 unwrap(M)->print(os, nullptr);
212 return strdup(buf.c_str());
215 /*--.. Operations on inline assembler ......................................--*/
216 void LLVMSetModuleInlineAsm(LLVMModuleRef M, const char *Asm) {
217 unwrap(M)->setModuleInlineAsm(StringRef(Asm));
221 /*--.. Operations on module contexts ......................................--*/
222 LLVMContextRef LLVMGetModuleContext(LLVMModuleRef M) {
223 return wrap(&unwrap(M)->getContext());
227 /*===-- Operations on types -----------------------------------------------===*/
229 /*--.. Operations on all types (mostly) ....................................--*/
231 LLVMTypeKind LLVMGetTypeKind(LLVMTypeRef Ty) {
232 switch (unwrap(Ty)->getTypeID()) {
234 return LLVMVoidTypeKind;
236 return LLVMHalfTypeKind;
237 case Type::FloatTyID:
238 return LLVMFloatTypeKind;
239 case Type::DoubleTyID:
240 return LLVMDoubleTypeKind;
241 case Type::X86_FP80TyID:
242 return LLVMX86_FP80TypeKind;
243 case Type::FP128TyID:
244 return LLVMFP128TypeKind;
245 case Type::PPC_FP128TyID:
246 return LLVMPPC_FP128TypeKind;
247 case Type::LabelTyID:
248 return LLVMLabelTypeKind;
249 case Type::MetadataTyID:
250 return LLVMMetadataTypeKind;
251 case Type::IntegerTyID:
252 return LLVMIntegerTypeKind;
253 case Type::FunctionTyID:
254 return LLVMFunctionTypeKind;
255 case Type::StructTyID:
256 return LLVMStructTypeKind;
257 case Type::ArrayTyID:
258 return LLVMArrayTypeKind;
259 case Type::PointerTyID:
260 return LLVMPointerTypeKind;
261 case Type::VectorTyID:
262 return LLVMVectorTypeKind;
263 case Type::X86_MMXTyID:
264 return LLVMX86_MMXTypeKind;
266 llvm_unreachable("Unhandled TypeID.");
269 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty)
271 return unwrap(Ty)->isSized();
274 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty) {
275 return wrap(&unwrap(Ty)->getContext());
278 void LLVMDumpType(LLVMTypeRef Ty) {
279 return unwrap(Ty)->dump();
282 char *LLVMPrintTypeToString(LLVMTypeRef Ty) {
284 raw_string_ostream os(buf);
287 unwrap(Ty)->print(os);
289 os << "Printing <null> Type";
293 return strdup(buf.c_str());
296 /*--.. Operations on integer types .........................................--*/
298 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C) {
299 return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
301 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C) {
302 return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
304 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C) {
305 return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
307 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C) {
308 return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
310 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C) {
311 return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
313 LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C) {
314 return (LLVMTypeRef) Type::getInt128Ty(*unwrap(C));
316 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits) {
317 return wrap(IntegerType::get(*unwrap(C), NumBits));
320 LLVMTypeRef LLVMInt1Type(void) {
321 return LLVMInt1TypeInContext(LLVMGetGlobalContext());
323 LLVMTypeRef LLVMInt8Type(void) {
324 return LLVMInt8TypeInContext(LLVMGetGlobalContext());
326 LLVMTypeRef LLVMInt16Type(void) {
327 return LLVMInt16TypeInContext(LLVMGetGlobalContext());
329 LLVMTypeRef LLVMInt32Type(void) {
330 return LLVMInt32TypeInContext(LLVMGetGlobalContext());
332 LLVMTypeRef LLVMInt64Type(void) {
333 return LLVMInt64TypeInContext(LLVMGetGlobalContext());
335 LLVMTypeRef LLVMInt128Type(void) {
336 return LLVMInt128TypeInContext(LLVMGetGlobalContext());
338 LLVMTypeRef LLVMIntType(unsigned NumBits) {
339 return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
342 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
343 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
346 /*--.. Operations on real types ............................................--*/
348 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C) {
349 return (LLVMTypeRef) Type::getHalfTy(*unwrap(C));
351 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C) {
352 return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
354 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C) {
355 return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
357 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C) {
358 return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
360 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C) {
361 return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
363 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C) {
364 return (LLVMTypeRef) Type::getPPC_FP128Ty(*unwrap(C));
366 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C) {
367 return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
370 LLVMTypeRef LLVMHalfType(void) {
371 return LLVMHalfTypeInContext(LLVMGetGlobalContext());
373 LLVMTypeRef LLVMFloatType(void) {
374 return LLVMFloatTypeInContext(LLVMGetGlobalContext());
376 LLVMTypeRef LLVMDoubleType(void) {
377 return LLVMDoubleTypeInContext(LLVMGetGlobalContext());
379 LLVMTypeRef LLVMX86FP80Type(void) {
380 return LLVMX86FP80TypeInContext(LLVMGetGlobalContext());
382 LLVMTypeRef LLVMFP128Type(void) {
383 return LLVMFP128TypeInContext(LLVMGetGlobalContext());
385 LLVMTypeRef LLVMPPCFP128Type(void) {
386 return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
388 LLVMTypeRef LLVMX86MMXType(void) {
389 return LLVMX86MMXTypeInContext(LLVMGetGlobalContext());
392 /*--.. Operations on function types ........................................--*/
394 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
395 LLVMTypeRef *ParamTypes, unsigned ParamCount,
397 ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
398 return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
401 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
402 return unwrap<FunctionType>(FunctionTy)->isVarArg();
405 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy) {
406 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
409 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
410 return unwrap<FunctionType>(FunctionTy)->getNumParams();
413 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
414 FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
415 for (FunctionType::param_iterator I = Ty->param_begin(),
416 E = Ty->param_end(); I != E; ++I)
420 /*--.. Operations on struct types ..........................................--*/
422 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
423 unsigned ElementCount, LLVMBool Packed) {
424 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
425 return wrap(StructType::get(*unwrap(C), Tys, Packed != 0));
428 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
429 unsigned ElementCount, LLVMBool Packed) {
430 return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
431 ElementCount, Packed);
434 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name)
436 return wrap(StructType::create(*unwrap(C), Name));
439 const char *LLVMGetStructName(LLVMTypeRef Ty)
441 StructType *Type = unwrap<StructType>(Ty);
442 if (!Type->hasName())
444 return Type->getName().data();
447 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
448 unsigned ElementCount, LLVMBool Packed) {
449 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
450 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
453 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
454 return unwrap<StructType>(StructTy)->getNumElements();
457 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest) {
458 StructType *Ty = unwrap<StructType>(StructTy);
459 for (StructType::element_iterator I = Ty->element_begin(),
460 E = Ty->element_end(); I != E; ++I)
464 LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i) {
465 StructType *Ty = unwrap<StructType>(StructTy);
466 return wrap(Ty->getTypeAtIndex(i));
469 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy) {
470 return unwrap<StructType>(StructTy)->isPacked();
473 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy) {
474 return unwrap<StructType>(StructTy)->isOpaque();
477 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) {
478 return wrap(unwrap(M)->getTypeByName(Name));
481 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
483 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
484 return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
487 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
488 return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
491 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
492 return wrap(VectorType::get(unwrap(ElementType), ElementCount));
495 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) {
496 return wrap(unwrap<SequentialType>(Ty)->getElementType());
499 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
500 return unwrap<ArrayType>(ArrayTy)->getNumElements();
503 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) {
504 return unwrap<PointerType>(PointerTy)->getAddressSpace();
507 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
508 return unwrap<VectorType>(VectorTy)->getNumElements();
511 /*--.. Operations on other types ...........................................--*/
513 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C) {
514 return wrap(Type::getVoidTy(*unwrap(C)));
516 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C) {
517 return wrap(Type::getLabelTy(*unwrap(C)));
520 LLVMTypeRef LLVMVoidType(void) {
521 return LLVMVoidTypeInContext(LLVMGetGlobalContext());
523 LLVMTypeRef LLVMLabelType(void) {
524 return LLVMLabelTypeInContext(LLVMGetGlobalContext());
527 /*===-- Operations on values ----------------------------------------------===*/
529 /*--.. Operations on all values ............................................--*/
531 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) {
532 return wrap(unwrap(Val)->getType());
535 const char *LLVMGetValueName(LLVMValueRef Val) {
536 return unwrap(Val)->getName().data();
539 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
540 unwrap(Val)->setName(Name);
543 void LLVMDumpValue(LLVMValueRef Val) {
547 char* LLVMPrintValueToString(LLVMValueRef Val) {
549 raw_string_ostream os(buf);
552 unwrap(Val)->print(os);
554 os << "Printing <null> Value";
558 return strdup(buf.c_str());
561 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
562 unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
565 int LLVMHasMetadata(LLVMValueRef Inst) {
566 return unwrap<Instruction>(Inst)->hasMetadata();
569 LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID) {
570 auto *I = unwrap<Instruction>(Inst);
571 assert(I && "Expected instruction");
572 if (auto *MD = I->getMetadata(KindID))
573 return wrap(MetadataAsValue::get(I->getContext(), MD));
577 // MetadataAsValue uses a canonical format which strips the actual MDNode for
578 // MDNode with just a single constant value, storing just a ConstantAsMetadata
579 // This undoes this canonicalization, reconstructing the MDNode.
580 static MDNode *extractMDNode(MetadataAsValue *MAV) {
581 Metadata *MD = MAV->getMetadata();
582 assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
583 "Expected a metadata node or a canonicalized constant");
585 if (MDNode *N = dyn_cast<MDNode>(MD))
588 return MDNode::get(MAV->getContext(), MD);
591 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef Val) {
592 MDNode *N = Val ? extractMDNode(unwrap<MetadataAsValue>(Val)) : nullptr;
594 unwrap<Instruction>(Inst)->setMetadata(KindID, N);
597 /*--.. Conversion functions ................................................--*/
599 #define LLVM_DEFINE_VALUE_CAST(name) \
600 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
601 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
604 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST)
606 LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val) {
607 if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
608 if (isa<MDNode>(MD->getMetadata()) ||
609 isa<ValueAsMetadata>(MD->getMetadata()))
614 LLVMValueRef LLVMIsAMDString(LLVMValueRef Val) {
615 if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
616 if (isa<MDString>(MD->getMetadata()))
621 /*--.. Operations on Uses ..................................................--*/
622 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val) {
623 Value *V = unwrap(Val);
624 Value::use_iterator I = V->use_begin();
625 if (I == V->use_end())
630 LLVMUseRef LLVMGetNextUse(LLVMUseRef U) {
631 Use *Next = unwrap(U)->getNext();
637 LLVMValueRef LLVMGetUser(LLVMUseRef U) {
638 return wrap(unwrap(U)->getUser());
641 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U) {
642 return wrap(unwrap(U)->get());
645 /*--.. Operations on Users .................................................--*/
647 static LLVMValueRef getMDNodeOperandImpl(LLVMContext &Context, const MDNode *N,
649 Metadata *Op = N->getOperand(Index);
652 if (auto *C = dyn_cast<ConstantAsMetadata>(Op))
653 return wrap(C->getValue());
654 return wrap(MetadataAsValue::get(Context, Op));
657 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) {
658 Value *V = unwrap(Val);
659 if (auto *MD = dyn_cast<MetadataAsValue>(V)) {
660 if (auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
661 assert(Index == 0 && "Function-local metadata can only have one operand");
662 return wrap(L->getValue());
664 return getMDNodeOperandImpl(V->getContext(),
665 cast<MDNode>(MD->getMetadata()), Index);
668 return wrap(cast<User>(V)->getOperand(Index));
671 LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index) {
672 Value *V = unwrap(Val);
673 return wrap(&cast<User>(V)->getOperandUse(Index));
676 void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
677 unwrap<User>(Val)->setOperand(Index, unwrap(Op));
680 int LLVMGetNumOperands(LLVMValueRef Val) {
681 Value *V = unwrap(Val);
682 if (isa<MetadataAsValue>(V))
683 return LLVMGetMDNodeNumOperands(Val);
685 return cast<User>(V)->getNumOperands();
688 /*--.. Operations on constants of any type .................................--*/
690 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
691 return wrap(Constant::getNullValue(unwrap(Ty)));
694 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) {
695 return wrap(Constant::getAllOnesValue(unwrap(Ty)));
698 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
699 return wrap(UndefValue::get(unwrap(Ty)));
702 LLVMBool LLVMIsConstant(LLVMValueRef Ty) {
703 return isa<Constant>(unwrap(Ty));
706 LLVMBool LLVMIsNull(LLVMValueRef Val) {
707 if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
708 return C->isNullValue();
712 LLVMBool LLVMIsUndef(LLVMValueRef Val) {
713 return isa<UndefValue>(unwrap(Val));
716 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) {
718 wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
721 /*--.. Operations on metadata nodes ........................................--*/
723 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
725 LLVMContext &Context = *unwrap(C);
726 return wrap(MetadataAsValue::get(
727 Context, MDString::get(Context, StringRef(Str, SLen))));
730 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen) {
731 return LLVMMDStringInContext(LLVMGetGlobalContext(), Str, SLen);
734 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
736 LLVMContext &Context = *unwrap(C);
737 SmallVector<Metadata *, 8> MDs;
738 for (auto *OV : makeArrayRef(Vals, Count)) {
739 Value *V = unwrap(OV);
743 else if (auto *C = dyn_cast<Constant>(V))
744 MD = ConstantAsMetadata::get(C);
745 else if (auto *MDV = dyn_cast<MetadataAsValue>(V)) {
746 MD = MDV->getMetadata();
747 assert(!isa<LocalAsMetadata>(MD) && "Unexpected function-local metadata "
748 "outside of direct argument to call");
750 // This is function-local metadata. Pretend to make an MDNode.
752 "Expected only one operand to function-local metadata");
753 return wrap(MetadataAsValue::get(Context, LocalAsMetadata::get(V)));
758 return wrap(MetadataAsValue::get(Context, MDNode::get(Context, MDs)));
761 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
762 return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
765 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len) {
766 if (const auto *MD = dyn_cast<MetadataAsValue>(unwrap(V)))
767 if (const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
768 *Len = S->getString().size();
769 return S->getString().data();
775 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V)
777 auto *MD = cast<MetadataAsValue>(unwrap(V));
778 if (isa<ValueAsMetadata>(MD->getMetadata()))
780 return cast<MDNode>(MD->getMetadata())->getNumOperands();
783 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest)
785 auto *MD = cast<MetadataAsValue>(unwrap(V));
786 if (auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
787 *Dest = wrap(MDV->getValue());
790 const auto *N = cast<MDNode>(MD->getMetadata());
791 const unsigned numOperands = N->getNumOperands();
792 LLVMContext &Context = unwrap(V)->getContext();
793 for (unsigned i = 0; i < numOperands; i++)
794 Dest[i] = getMDNodeOperandImpl(Context, N, i);
797 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name)
799 if (NamedMDNode *N = unwrap(M)->getNamedMetadata(name)) {
800 return N->getNumOperands();
805 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest)
807 NamedMDNode *N = unwrap(M)->getNamedMetadata(name);
810 LLVMContext &Context = unwrap(M)->getContext();
811 for (unsigned i=0;i<N->getNumOperands();i++)
812 Dest[i] = wrap(MetadataAsValue::get(Context, N->getOperand(i)));
815 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
818 NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
823 N->addOperand(extractMDNode(unwrap<MetadataAsValue>(Val)));
826 /*--.. Operations on scalar constants ......................................--*/
828 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
829 LLVMBool SignExtend) {
830 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
833 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
835 const uint64_t Words[]) {
836 IntegerType *Ty = unwrap<IntegerType>(IntTy);
837 return wrap(ConstantInt::get(Ty->getContext(),
838 APInt(Ty->getBitWidth(),
839 makeArrayRef(Words, NumWords))));
842 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[],
844 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str),
848 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char Str[],
849 unsigned SLen, uint8_t Radix) {
850 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen),
854 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
855 return wrap(ConstantFP::get(unwrap(RealTy), N));
858 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
859 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text)));
862 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[],
864 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
867 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
868 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
871 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
872 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
875 double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *LosesInfo) {
876 ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
877 Type *Ty = cFP->getType();
879 if (Ty->isFloatTy()) {
881 return cFP->getValueAPF().convertToFloat();
884 if (Ty->isDoubleTy()) {
886 return cFP->getValueAPF().convertToDouble();
890 APFloat APF = cFP->getValueAPF();
891 APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &APFLosesInfo);
892 *LosesInfo = APFLosesInfo;
893 return APF.convertToDouble();
896 /*--.. Operations on composite constants ...................................--*/
898 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
900 LLVMBool DontNullTerminate) {
901 /* Inverted the sense of AddNull because ', 0)' is a
902 better mnemonic for null termination than ', 1)'. */
903 return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length),
904 DontNullTerminate == 0));
906 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
907 LLVMValueRef *ConstantVals,
908 unsigned Count, LLVMBool Packed) {
909 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
910 return wrap(ConstantStruct::getAnon(*unwrap(C), makeArrayRef(Elements, Count),
914 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
915 LLVMBool DontNullTerminate) {
916 return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
920 LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx) {
921 return wrap(static_cast<ConstantDataSequential*>(unwrap(c))->getElementAsConstant(idx));
924 LLVMBool LLVMIsConstantString(LLVMValueRef c) {
925 return static_cast<ConstantDataSequential*>(unwrap(c))->isString();
928 const char *LLVMGetAsString(LLVMValueRef c, size_t* Length) {
929 StringRef str = static_cast<ConstantDataSequential*>(unwrap(c))->getAsString();
930 *Length = str.size();
934 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
935 LLVMValueRef *ConstantVals, unsigned Length) {
936 ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
937 return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
940 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
942 return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
946 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
947 LLVMValueRef *ConstantVals,
949 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
950 StructType *Ty = cast<StructType>(unwrap(StructTy));
952 return wrap(ConstantStruct::get(Ty, makeArrayRef(Elements, Count)));
955 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
956 return wrap(ConstantVector::get(makeArrayRef(
957 unwrap<Constant>(ScalarConstantVals, Size), Size)));
960 /*-- Opcode mapping */
962 static LLVMOpcode map_to_llvmopcode(int opcode)
965 default: llvm_unreachable("Unhandled Opcode.");
966 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
967 #include "llvm/IR/Instruction.def"
972 static int map_from_llvmopcode(LLVMOpcode code)
975 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
976 #include "llvm/IR/Instruction.def"
979 llvm_unreachable("Unhandled Opcode.");
982 /*--.. Constant expressions ................................................--*/
984 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal) {
985 return map_to_llvmopcode(unwrap<ConstantExpr>(ConstantVal)->getOpcode());
988 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) {
989 return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
992 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) {
993 return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
996 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) {
997 return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
1000 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal) {
1001 return wrap(ConstantExpr::getNSWNeg(unwrap<Constant>(ConstantVal)));
1004 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal) {
1005 return wrap(ConstantExpr::getNUWNeg(unwrap<Constant>(ConstantVal)));
1009 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal) {
1010 return wrap(ConstantExpr::getFNeg(unwrap<Constant>(ConstantVal)));
1013 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) {
1014 return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
1017 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1018 return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
1019 unwrap<Constant>(RHSConstant)));
1022 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant,
1023 LLVMValueRef RHSConstant) {
1024 return wrap(ConstantExpr::getNSWAdd(unwrap<Constant>(LHSConstant),
1025 unwrap<Constant>(RHSConstant)));
1028 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant,
1029 LLVMValueRef RHSConstant) {
1030 return wrap(ConstantExpr::getNUWAdd(unwrap<Constant>(LHSConstant),
1031 unwrap<Constant>(RHSConstant)));
1034 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1035 return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant),
1036 unwrap<Constant>(RHSConstant)));
1039 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1040 return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
1041 unwrap<Constant>(RHSConstant)));
1044 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant,
1045 LLVMValueRef RHSConstant) {
1046 return wrap(ConstantExpr::getNSWSub(unwrap<Constant>(LHSConstant),
1047 unwrap<Constant>(RHSConstant)));
1050 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant,
1051 LLVMValueRef RHSConstant) {
1052 return wrap(ConstantExpr::getNUWSub(unwrap<Constant>(LHSConstant),
1053 unwrap<Constant>(RHSConstant)));
1056 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1057 return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant),
1058 unwrap<Constant>(RHSConstant)));
1061 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1062 return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
1063 unwrap<Constant>(RHSConstant)));
1066 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant,
1067 LLVMValueRef RHSConstant) {
1068 return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
1069 unwrap<Constant>(RHSConstant)));
1072 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant,
1073 LLVMValueRef RHSConstant) {
1074 return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
1075 unwrap<Constant>(RHSConstant)));
1078 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1079 return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant),
1080 unwrap<Constant>(RHSConstant)));
1083 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1084 return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
1085 unwrap<Constant>(RHSConstant)));
1088 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1089 return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
1090 unwrap<Constant>(RHSConstant)));
1093 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant,
1094 LLVMValueRef RHSConstant) {
1095 return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant),
1096 unwrap<Constant>(RHSConstant)));
1099 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1100 return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
1101 unwrap<Constant>(RHSConstant)));
1104 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1105 return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
1106 unwrap<Constant>(RHSConstant)));
1109 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1110 return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
1111 unwrap<Constant>(RHSConstant)));
1114 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1115 return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
1116 unwrap<Constant>(RHSConstant)));
1119 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1120 return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
1121 unwrap<Constant>(RHSConstant)));
1124 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1125 return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
1126 unwrap<Constant>(RHSConstant)));
1129 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1130 return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
1131 unwrap<Constant>(RHSConstant)));
1134 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1135 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1136 return wrap(ConstantExpr::getICmp(Predicate,
1137 unwrap<Constant>(LHSConstant),
1138 unwrap<Constant>(RHSConstant)));
1141 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1142 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1143 return wrap(ConstantExpr::getFCmp(Predicate,
1144 unwrap<Constant>(LHSConstant),
1145 unwrap<Constant>(RHSConstant)));
1148 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1149 return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
1150 unwrap<Constant>(RHSConstant)));
1153 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1154 return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
1155 unwrap<Constant>(RHSConstant)));
1158 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1159 return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
1160 unwrap<Constant>(RHSConstant)));
1163 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1164 LLVMValueRef *ConstantIndices, unsigned NumIndices) {
1165 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1167 return wrap(ConstantExpr::getGetElementPtr(
1168 nullptr, unwrap<Constant>(ConstantVal), IdxList));
1171 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1172 LLVMValueRef *ConstantIndices,
1173 unsigned NumIndices) {
1174 Constant* Val = unwrap<Constant>(ConstantVal);
1175 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1177 return wrap(ConstantExpr::getInBoundsGetElementPtr(nullptr, Val, IdxList));
1180 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1181 return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
1185 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1186 return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
1190 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1191 return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
1195 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1196 return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
1200 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1201 return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
1205 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1206 return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
1210 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1211 return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
1215 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1216 return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
1220 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1221 return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
1225 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1226 return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
1230 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1231 return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
1235 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1236 return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
1240 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal,
1241 LLVMTypeRef ToType) {
1242 return wrap(ConstantExpr::getAddrSpaceCast(unwrap<Constant>(ConstantVal),
1246 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1247 LLVMTypeRef ToType) {
1248 return wrap(ConstantExpr::getZExtOrBitCast(unwrap<Constant>(ConstantVal),
1252 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1253 LLVMTypeRef ToType) {
1254 return wrap(ConstantExpr::getSExtOrBitCast(unwrap<Constant>(ConstantVal),
1258 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1259 LLVMTypeRef ToType) {
1260 return wrap(ConstantExpr::getTruncOrBitCast(unwrap<Constant>(ConstantVal),
1264 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1265 LLVMTypeRef ToType) {
1266 return wrap(ConstantExpr::getPointerCast(unwrap<Constant>(ConstantVal),
1270 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1271 LLVMBool isSigned) {
1272 return wrap(ConstantExpr::getIntegerCast(unwrap<Constant>(ConstantVal),
1273 unwrap(ToType), isSigned));
1276 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1277 return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal),
1281 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1282 LLVMValueRef ConstantIfTrue,
1283 LLVMValueRef ConstantIfFalse) {
1284 return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
1285 unwrap<Constant>(ConstantIfTrue),
1286 unwrap<Constant>(ConstantIfFalse)));
1289 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1290 LLVMValueRef IndexConstant) {
1291 return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
1292 unwrap<Constant>(IndexConstant)));
1295 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1296 LLVMValueRef ElementValueConstant,
1297 LLVMValueRef IndexConstant) {
1298 return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
1299 unwrap<Constant>(ElementValueConstant),
1300 unwrap<Constant>(IndexConstant)));
1303 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1304 LLVMValueRef VectorBConstant,
1305 LLVMValueRef MaskConstant) {
1306 return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
1307 unwrap<Constant>(VectorBConstant),
1308 unwrap<Constant>(MaskConstant)));
1311 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1313 return wrap(ConstantExpr::getExtractValue(unwrap<Constant>(AggConstant),
1314 makeArrayRef(IdxList, NumIdx)));
1317 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1318 LLVMValueRef ElementValueConstant,
1319 unsigned *IdxList, unsigned NumIdx) {
1320 return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant),
1321 unwrap<Constant>(ElementValueConstant),
1322 makeArrayRef(IdxList, NumIdx)));
1325 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
1326 const char *Constraints,
1327 LLVMBool HasSideEffects,
1328 LLVMBool IsAlignStack) {
1329 return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
1330 Constraints, HasSideEffects, IsAlignStack));
1333 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB) {
1334 return wrap(BlockAddress::get(unwrap<Function>(F), unwrap(BB)));
1337 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1339 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) {
1340 return wrap(unwrap<GlobalValue>(Global)->getParent());
1343 LLVMBool LLVMIsDeclaration(LLVMValueRef Global) {
1344 return unwrap<GlobalValue>(Global)->isDeclaration();
1347 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) {
1348 switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1349 case GlobalValue::ExternalLinkage:
1350 return LLVMExternalLinkage;
1351 case GlobalValue::AvailableExternallyLinkage:
1352 return LLVMAvailableExternallyLinkage;
1353 case GlobalValue::LinkOnceAnyLinkage:
1354 return LLVMLinkOnceAnyLinkage;
1355 case GlobalValue::LinkOnceODRLinkage:
1356 return LLVMLinkOnceODRLinkage;
1357 case GlobalValue::WeakAnyLinkage:
1358 return LLVMWeakAnyLinkage;
1359 case GlobalValue::WeakODRLinkage:
1360 return LLVMWeakODRLinkage;
1361 case GlobalValue::AppendingLinkage:
1362 return LLVMAppendingLinkage;
1363 case GlobalValue::InternalLinkage:
1364 return LLVMInternalLinkage;
1365 case GlobalValue::PrivateLinkage:
1366 return LLVMPrivateLinkage;
1367 case GlobalValue::ExternalWeakLinkage:
1368 return LLVMExternalWeakLinkage;
1369 case GlobalValue::CommonLinkage:
1370 return LLVMCommonLinkage;
1373 llvm_unreachable("Invalid GlobalValue linkage!");
1376 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
1377 GlobalValue *GV = unwrap<GlobalValue>(Global);
1380 case LLVMExternalLinkage:
1381 GV->setLinkage(GlobalValue::ExternalLinkage);
1383 case LLVMAvailableExternallyLinkage:
1384 GV->setLinkage(GlobalValue::AvailableExternallyLinkage);
1386 case LLVMLinkOnceAnyLinkage:
1387 GV->setLinkage(GlobalValue::LinkOnceAnyLinkage);
1389 case LLVMLinkOnceODRLinkage:
1390 GV->setLinkage(GlobalValue::LinkOnceODRLinkage);
1392 case LLVMLinkOnceODRAutoHideLinkage:
1393 DEBUG(errs() << "LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1394 "longer supported.");
1396 case LLVMWeakAnyLinkage:
1397 GV->setLinkage(GlobalValue::WeakAnyLinkage);
1399 case LLVMWeakODRLinkage:
1400 GV->setLinkage(GlobalValue::WeakODRLinkage);
1402 case LLVMAppendingLinkage:
1403 GV->setLinkage(GlobalValue::AppendingLinkage);
1405 case LLVMInternalLinkage:
1406 GV->setLinkage(GlobalValue::InternalLinkage);
1408 case LLVMPrivateLinkage:
1409 GV->setLinkage(GlobalValue::PrivateLinkage);
1411 case LLVMLinkerPrivateLinkage:
1412 GV->setLinkage(GlobalValue::PrivateLinkage);
1414 case LLVMLinkerPrivateWeakLinkage:
1415 GV->setLinkage(GlobalValue::PrivateLinkage);
1417 case LLVMDLLImportLinkage:
1419 << "LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1421 case LLVMDLLExportLinkage:
1423 << "LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1425 case LLVMExternalWeakLinkage:
1426 GV->setLinkage(GlobalValue::ExternalWeakLinkage);
1428 case LLVMGhostLinkage:
1430 << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1432 case LLVMCommonLinkage:
1433 GV->setLinkage(GlobalValue::CommonLinkage);
1438 const char *LLVMGetSection(LLVMValueRef Global) {
1439 return unwrap<GlobalValue>(Global)->getSection();
1442 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
1443 unwrap<GlobalObject>(Global)->setSection(Section);
1446 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
1447 return static_cast<LLVMVisibility>(
1448 unwrap<GlobalValue>(Global)->getVisibility());
1451 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) {
1452 unwrap<GlobalValue>(Global)
1453 ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
1456 LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global) {
1457 return static_cast<LLVMDLLStorageClass>(
1458 unwrap<GlobalValue>(Global)->getDLLStorageClass());
1461 void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class) {
1462 unwrap<GlobalValue>(Global)->setDLLStorageClass(
1463 static_cast<GlobalValue::DLLStorageClassTypes>(Class));
1466 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global) {
1467 return unwrap<GlobalValue>(Global)->hasUnnamedAddr();
1470 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr) {
1471 unwrap<GlobalValue>(Global)->setUnnamedAddr(HasUnnamedAddr);
1474 /*--.. Operations on global variables, load and store instructions .........--*/
1476 unsigned LLVMGetAlignment(LLVMValueRef V) {
1477 Value *P = unwrap<Value>(V);
1478 if (GlobalValue *GV = dyn_cast<GlobalValue>(P))
1479 return GV->getAlignment();
1480 if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1481 return AI->getAlignment();
1482 if (LoadInst *LI = dyn_cast<LoadInst>(P))
1483 return LI->getAlignment();
1484 if (StoreInst *SI = dyn_cast<StoreInst>(P))
1485 return SI->getAlignment();
1488 "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1491 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
1492 Value *P = unwrap<Value>(V);
1493 if (GlobalObject *GV = dyn_cast<GlobalObject>(P))
1494 GV->setAlignment(Bytes);
1495 else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1496 AI->setAlignment(Bytes);
1497 else if (LoadInst *LI = dyn_cast<LoadInst>(P))
1498 LI->setAlignment(Bytes);
1499 else if (StoreInst *SI = dyn_cast<StoreInst>(P))
1500 SI->setAlignment(Bytes);
1503 "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1506 /*--.. Operations on global variables ......................................--*/
1508 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
1509 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1510 GlobalValue::ExternalLinkage, nullptr, Name));
1513 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1515 unsigned AddressSpace) {
1516 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1517 GlobalValue::ExternalLinkage, nullptr, Name,
1518 nullptr, GlobalVariable::NotThreadLocal,
1522 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {
1523 return wrap(unwrap(M)->getNamedGlobal(Name));
1526 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) {
1527 Module *Mod = unwrap(M);
1528 Module::global_iterator I = Mod->global_begin();
1529 if (I == Mod->global_end())
1534 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) {
1535 Module *Mod = unwrap(M);
1536 Module::global_iterator I = Mod->global_end();
1537 if (I == Mod->global_begin())
1542 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) {
1543 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1544 Module::global_iterator I = GV;
1545 if (++I == GV->getParent()->global_end())
1550 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) {
1551 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1552 Module::global_iterator I = GV;
1553 if (I == GV->getParent()->global_begin())
1558 void LLVMDeleteGlobal(LLVMValueRef GlobalVar) {
1559 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
1562 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) {
1563 GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
1564 if ( !GV->hasInitializer() )
1566 return wrap(GV->getInitializer());
1569 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
1570 unwrap<GlobalVariable>(GlobalVar)
1571 ->setInitializer(unwrap<Constant>(ConstantVal));
1574 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
1575 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
1578 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal) {
1579 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
1582 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
1583 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
1586 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant) {
1587 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
1590 LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar) {
1591 switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
1592 case GlobalVariable::NotThreadLocal:
1593 return LLVMNotThreadLocal;
1594 case GlobalVariable::GeneralDynamicTLSModel:
1595 return LLVMGeneralDynamicTLSModel;
1596 case GlobalVariable::LocalDynamicTLSModel:
1597 return LLVMLocalDynamicTLSModel;
1598 case GlobalVariable::InitialExecTLSModel:
1599 return LLVMInitialExecTLSModel;
1600 case GlobalVariable::LocalExecTLSModel:
1601 return LLVMLocalExecTLSModel;
1604 llvm_unreachable("Invalid GlobalVariable thread local mode");
1607 void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode) {
1608 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1611 case LLVMNotThreadLocal:
1612 GV->setThreadLocalMode(GlobalVariable::NotThreadLocal);
1614 case LLVMGeneralDynamicTLSModel:
1615 GV->setThreadLocalMode(GlobalVariable::GeneralDynamicTLSModel);
1617 case LLVMLocalDynamicTLSModel:
1618 GV->setThreadLocalMode(GlobalVariable::LocalDynamicTLSModel);
1620 case LLVMInitialExecTLSModel:
1621 GV->setThreadLocalMode(GlobalVariable::InitialExecTLSModel);
1623 case LLVMLocalExecTLSModel:
1624 GV->setThreadLocalMode(GlobalVariable::LocalExecTLSModel);
1629 LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar) {
1630 return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
1633 void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit) {
1634 unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
1637 /*--.. Operations on aliases ......................................--*/
1639 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1641 auto *PTy = cast<PointerType>(unwrap(Ty));
1642 return wrap(GlobalAlias::create(PTy, GlobalValue::ExternalLinkage, Name,
1643 unwrap<Constant>(Aliasee), unwrap(M)));
1646 /*--.. Operations on functions .............................................--*/
1648 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1649 LLVMTypeRef FunctionTy) {
1650 return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
1651 GlobalValue::ExternalLinkage, Name, unwrap(M)));
1654 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
1655 return wrap(unwrap(M)->getFunction(Name));
1658 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) {
1659 Module *Mod = unwrap(M);
1660 Module::iterator I = Mod->begin();
1661 if (I == Mod->end())
1666 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) {
1667 Module *Mod = unwrap(M);
1668 Module::iterator I = Mod->end();
1669 if (I == Mod->begin())
1674 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) {
1675 Function *Func = unwrap<Function>(Fn);
1676 Module::iterator I = Func;
1677 if (++I == Func->getParent()->end())
1682 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) {
1683 Function *Func = unwrap<Function>(Fn);
1684 Module::iterator I = Func;
1685 if (I == Func->getParent()->begin())
1690 void LLVMDeleteFunction(LLVMValueRef Fn) {
1691 unwrap<Function>(Fn)->eraseFromParent();
1694 LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn) {
1695 return wrap(unwrap<Function>(Fn)->getPersonalityFn());
1698 void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn) {
1699 unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
1702 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) {
1703 if (Function *F = dyn_cast<Function>(unwrap(Fn)))
1704 return F->getIntrinsicID();
1708 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) {
1709 return unwrap<Function>(Fn)->getCallingConv();
1712 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
1713 return unwrap<Function>(Fn)->setCallingConv(
1714 static_cast<CallingConv::ID>(CC));
1717 const char *LLVMGetGC(LLVMValueRef Fn) {
1718 Function *F = unwrap<Function>(Fn);
1719 return F->hasGC()? F->getGC() : nullptr;
1722 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
1723 Function *F = unwrap<Function>(Fn);
1730 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1731 Function *Func = unwrap<Function>(Fn);
1732 const AttributeSet PAL = Func->getAttributes();
1734 const AttributeSet PALnew =
1735 PAL.addAttributes(Func->getContext(), AttributeSet::FunctionIndex,
1736 AttributeSet::get(Func->getContext(),
1737 AttributeSet::FunctionIndex, B));
1738 Func->setAttributes(PALnew);
1741 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1743 Function *Func = unwrap<Function>(Fn);
1744 AttributeSet::AttrIndex Idx =
1745 AttributeSet::AttrIndex(AttributeSet::FunctionIndex);
1748 B.addAttribute(A, V);
1749 AttributeSet Set = AttributeSet::get(Func->getContext(), Idx, B);
1750 Func->addAttributes(Idx, Set);
1753 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1754 Function *Func = unwrap<Function>(Fn);
1755 const AttributeSet PAL = Func->getAttributes();
1757 const AttributeSet PALnew =
1758 PAL.removeAttributes(Func->getContext(), AttributeSet::FunctionIndex,
1759 AttributeSet::get(Func->getContext(),
1760 AttributeSet::FunctionIndex, B));
1761 Func->setAttributes(PALnew);
1764 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) {
1765 Function *Func = unwrap<Function>(Fn);
1766 const AttributeSet PAL = Func->getAttributes();
1767 return (LLVMAttribute)PAL.Raw(AttributeSet::FunctionIndex);
1770 /*--.. Operations on parameters ............................................--*/
1772 unsigned LLVMCountParams(LLVMValueRef FnRef) {
1773 // This function is strictly redundant to
1774 // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1775 return unwrap<Function>(FnRef)->arg_size();
1778 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
1779 Function *Fn = unwrap<Function>(FnRef);
1780 for (Function::arg_iterator I = Fn->arg_begin(),
1781 E = Fn->arg_end(); I != E; I++)
1782 *ParamRefs++ = wrap(I);
1785 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
1786 Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
1792 LLVMValueRef LLVMGetParamParent(LLVMValueRef V) {
1793 return wrap(unwrap<Argument>(V)->getParent());
1796 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn) {
1797 Function *Func = unwrap<Function>(Fn);
1798 Function::arg_iterator I = Func->arg_begin();
1799 if (I == Func->arg_end())
1804 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) {
1805 Function *Func = unwrap<Function>(Fn);
1806 Function::arg_iterator I = Func->arg_end();
1807 if (I == Func->arg_begin())
1812 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) {
1813 Argument *A = unwrap<Argument>(Arg);
1814 Function::arg_iterator I = A;
1815 if (++I == A->getParent()->arg_end())
1820 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
1821 Argument *A = unwrap<Argument>(Arg);
1822 Function::arg_iterator I = A;
1823 if (I == A->getParent()->arg_begin())
1828 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1829 Argument *A = unwrap<Argument>(Arg);
1831 A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, B));
1834 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1835 Argument *A = unwrap<Argument>(Arg);
1837 A->removeAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, B));
1840 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) {
1841 Argument *A = unwrap<Argument>(Arg);
1842 return (LLVMAttribute)A->getParent()->getAttributes().
1843 Raw(A->getArgNo()+1);
1847 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
1848 Argument *A = unwrap<Argument>(Arg);
1850 B.addAlignmentAttr(align);
1851 A->addAttr(AttributeSet::get(A->getContext(),A->getArgNo() + 1, B));
1854 /*--.. Operations on basic blocks ..........................................--*/
1856 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) {
1857 return wrap(static_cast<Value*>(unwrap(BB)));
1860 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val) {
1861 return isa<BasicBlock>(unwrap(Val));
1864 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) {
1865 return wrap(unwrap<BasicBlock>(Val));
1868 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB) {
1869 return wrap(unwrap(BB)->getParent());
1872 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB) {
1873 return wrap(unwrap(BB)->getTerminator());
1876 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
1877 return unwrap<Function>(FnRef)->size();
1880 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
1881 Function *Fn = unwrap<Function>(FnRef);
1882 for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
1883 *BasicBlocksRefs++ = wrap(I);
1886 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
1887 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
1890 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn) {
1891 Function *Func = unwrap<Function>(Fn);
1892 Function::iterator I = Func->begin();
1893 if (I == Func->end())
1898 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) {
1899 Function *Func = unwrap<Function>(Fn);
1900 Function::iterator I = Func->end();
1901 if (I == Func->begin())
1906 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) {
1907 BasicBlock *Block = unwrap(BB);
1908 Function::iterator I = Block;
1909 if (++I == Block->getParent()->end())
1914 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
1915 BasicBlock *Block = unwrap(BB);
1916 Function::iterator I = Block;
1917 if (I == Block->getParent()->begin())
1922 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1925 return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
1928 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
1929 return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
1932 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1933 LLVMBasicBlockRef BBRef,
1935 BasicBlock *BB = unwrap(BBRef);
1936 return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
1939 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef,
1941 return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
1944 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {
1945 unwrap(BBRef)->eraseFromParent();
1948 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BBRef) {
1949 unwrap(BBRef)->removeFromParent();
1952 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1953 unwrap(BB)->moveBefore(unwrap(MovePos));
1956 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1957 unwrap(BB)->moveAfter(unwrap(MovePos));
1960 /*--.. Operations on instructions ..........................................--*/
1962 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) {
1963 return wrap(unwrap<Instruction>(Inst)->getParent());
1966 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB) {
1967 BasicBlock *Block = unwrap(BB);
1968 BasicBlock::iterator I = Block->begin();
1969 if (I == Block->end())
1974 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) {
1975 BasicBlock *Block = unwrap(BB);
1976 BasicBlock::iterator I = Block->end();
1977 if (I == Block->begin())
1982 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) {
1983 Instruction *Instr = unwrap<Instruction>(Inst);
1984 BasicBlock::iterator I = Instr;
1985 if (++I == Instr->getParent()->end())
1990 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) {
1991 Instruction *Instr = unwrap<Instruction>(Inst);
1992 BasicBlock::iterator I = Instr;
1993 if (I == Instr->getParent()->begin())
1998 void LLVMInstructionEraseFromParent(LLVMValueRef Inst) {
1999 unwrap<Instruction>(Inst)->eraseFromParent();
2002 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) {
2003 if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
2004 return (LLVMIntPredicate)I->getPredicate();
2005 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2006 if (CE->getOpcode() == Instruction::ICmp)
2007 return (LLVMIntPredicate)CE->getPredicate();
2008 return (LLVMIntPredicate)0;
2011 LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst) {
2012 if (FCmpInst *I = dyn_cast<FCmpInst>(unwrap(Inst)))
2013 return (LLVMRealPredicate)I->getPredicate();
2014 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2015 if (CE->getOpcode() == Instruction::FCmp)
2016 return (LLVMRealPredicate)CE->getPredicate();
2017 return (LLVMRealPredicate)0;
2020 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst) {
2021 if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2022 return map_to_llvmopcode(C->getOpcode());
2023 return (LLVMOpcode)0;
2026 LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst) {
2027 if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2028 return wrap(C->clone());
2032 /*--.. Call and invoke instructions ........................................--*/
2034 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
2035 Value *V = unwrap(Instr);
2036 if (CallInst *CI = dyn_cast<CallInst>(V))
2037 return CI->getCallingConv();
2038 if (InvokeInst *II = dyn_cast<InvokeInst>(V))
2039 return II->getCallingConv();
2040 llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
2043 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
2044 Value *V = unwrap(Instr);
2045 if (CallInst *CI = dyn_cast<CallInst>(V))
2046 return CI->setCallingConv(static_cast<CallingConv::ID>(CC));
2047 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
2048 return II->setCallingConv(static_cast<CallingConv::ID>(CC));
2049 llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
2052 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
2054 CallSite Call = CallSite(unwrap<Instruction>(Instr));
2057 Call.getAttributes().addAttributes(Call->getContext(), index,
2058 AttributeSet::get(Call->getContext(),
2062 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2064 CallSite Call = CallSite(unwrap<Instruction>(Instr));
2066 Call.setAttributes(Call.getAttributes()
2067 .removeAttributes(Call->getContext(), index,
2068 AttributeSet::get(Call->getContext(),
2072 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2074 CallSite Call = CallSite(unwrap<Instruction>(Instr));
2076 B.addAlignmentAttr(align);
2077 Call.setAttributes(Call.getAttributes()
2078 .addAttributes(Call->getContext(), index,
2079 AttributeSet::get(Call->getContext(),
2083 /*--.. Operations on call instructions (only) ..............................--*/
2085 LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
2086 return unwrap<CallInst>(Call)->isTailCall();
2089 void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
2090 unwrap<CallInst>(Call)->setTailCall(isTailCall);
2093 /*--.. Operations on terminators ...........................................--*/
2095 unsigned LLVMGetNumSuccessors(LLVMValueRef Term) {
2096 return unwrap<TerminatorInst>(Term)->getNumSuccessors();
2099 LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i) {
2100 return wrap(unwrap<TerminatorInst>(Term)->getSuccessor(i));
2103 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) {
2104 return unwrap<TerminatorInst>(Term)->setSuccessor(i,unwrap(block));
2107 /*--.. Operations on branch instructions (only) ............................--*/
2109 LLVMBool LLVMIsConditional(LLVMValueRef Branch) {
2110 return unwrap<BranchInst>(Branch)->isConditional();
2113 LLVMValueRef LLVMGetCondition(LLVMValueRef Branch) {
2114 return wrap(unwrap<BranchInst>(Branch)->getCondition());
2117 void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond) {
2118 return unwrap<BranchInst>(Branch)->setCondition(unwrap(Cond));
2121 /*--.. Operations on switch instructions (only) ............................--*/
2123 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch) {
2124 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
2127 /*--.. Operations on phi nodes .............................................--*/
2129 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2130 LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
2131 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
2132 for (unsigned I = 0; I != Count; ++I)
2133 PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
2136 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
2137 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
2140 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index) {
2141 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
2144 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) {
2145 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
2149 /*===-- Instruction builders ----------------------------------------------===*/
2151 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C) {
2152 return wrap(new IRBuilder<>(*unwrap(C)));
2155 LLVMBuilderRef LLVMCreateBuilder(void) {
2156 return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
2159 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2160 LLVMValueRef Instr) {
2161 BasicBlock *BB = unwrap(Block);
2162 Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end();
2163 unwrap(Builder)->SetInsertPoint(BB, I);
2166 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
2167 Instruction *I = unwrap<Instruction>(Instr);
2168 unwrap(Builder)->SetInsertPoint(I->getParent(), I);
2171 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
2172 BasicBlock *BB = unwrap(Block);
2173 unwrap(Builder)->SetInsertPoint(BB);
2176 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder) {
2177 return wrap(unwrap(Builder)->GetInsertBlock());
2180 void LLVMClearInsertionPosition(LLVMBuilderRef Builder) {
2181 unwrap(Builder)->ClearInsertionPoint();
2184 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr) {
2185 unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
2188 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2190 unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name);
2193 void LLVMDisposeBuilder(LLVMBuilderRef Builder) {
2194 delete unwrap(Builder);
2197 /*--.. Metadata builders ...................................................--*/
2199 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) {
2201 L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr;
2202 unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(Loc));
2205 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder) {
2206 LLVMContext &Context = unwrap(Builder)->getContext();
2207 return wrap(MetadataAsValue::get(
2208 Context, unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()));
2211 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst) {
2212 unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
2216 /*--.. Instruction builders ................................................--*/
2218 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {
2219 return wrap(unwrap(B)->CreateRetVoid());
2222 LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) {
2223 return wrap(unwrap(B)->CreateRet(unwrap(V)));
2226 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals,
2228 return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
2231 LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) {
2232 return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
2235 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If,
2236 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
2237 return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
2240 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V,
2241 LLVMBasicBlockRef Else, unsigned NumCases) {
2242 return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
2245 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2246 unsigned NumDests) {
2247 return wrap(unwrap(B)->CreateIndirectBr(unwrap(Addr), NumDests));
2250 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,
2251 LLVMValueRef *Args, unsigned NumArgs,
2252 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2254 return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
2255 makeArrayRef(unwrap(Args), NumArgs),
2259 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2260 LLVMValueRef PersFn, unsigned NumClauses,
2262 // The personality used to live on the landingpad instruction, but now it
2263 // lives on the parent function. For compatibility, take the provided
2264 // personality and put it on the parent function.
2266 unwrap(B)->GetInsertBlock()->getParent()->setPersonalityFn(
2267 cast<Function>(unwrap(PersFn)));
2268 return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty), NumClauses, Name));
2271 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn) {
2272 return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
2275 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
2276 return wrap(unwrap(B)->CreateUnreachable());
2279 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2280 LLVMBasicBlockRef Dest) {
2281 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
2284 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest) {
2285 unwrap<IndirectBrInst>(IndirectBr)->addDestination(unwrap(Dest));
2288 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal) {
2289 unwrap<LandingPadInst>(LandingPad)->
2290 addClause(cast<Constant>(unwrap(ClauseVal)));
2293 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
2294 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
2297 /*--.. Arithmetic ..........................................................--*/
2299 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2301 return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
2304 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2306 return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
2309 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2311 return wrap(unwrap(B)->CreateNUWAdd(unwrap(LHS), unwrap(RHS), Name));
2314 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2316 return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
2319 LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2321 return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
2324 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2326 return wrap(unwrap(B)->CreateNSWSub(unwrap(LHS), unwrap(RHS), Name));
2329 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2331 return wrap(unwrap(B)->CreateNUWSub(unwrap(LHS), unwrap(RHS), Name));
2334 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2336 return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
2339 LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2341 return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
2344 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2346 return wrap(unwrap(B)->CreateNSWMul(unwrap(LHS), unwrap(RHS), Name));
2349 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2351 return wrap(unwrap(B)->CreateNUWMul(unwrap(LHS), unwrap(RHS), Name));
2354 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2356 return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
2359 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2361 return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
2364 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2366 return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
2369 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS,
2370 LLVMValueRef RHS, const char *Name) {
2371 return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
2374 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2376 return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
2379 LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2381 return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
2384 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2386 return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
2389 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2391 return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
2394 LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2396 return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
2399 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2401 return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
2404 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2406 return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
2409 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2411 return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
2414 LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2416 return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
2419 LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2421 return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
2424 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2425 LLVMValueRef LHS, LLVMValueRef RHS,
2427 return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
2428 unwrap(RHS), Name));
2431 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
2432 return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
2435 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2437 return wrap(unwrap(B)->CreateNSWNeg(unwrap(V), Name));
2440 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2442 return wrap(unwrap(B)->CreateNUWNeg(unwrap(V), Name));
2445 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
2446 return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name));
2449 LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
2450 return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
2453 /*--.. Memory ..............................................................--*/
2455 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
2457 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2458 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2459 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2460 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2461 ITy, unwrap(Ty), AllocSize,
2462 nullptr, nullptr, "");
2463 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2466 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
2467 LLVMValueRef Val, const char *Name) {
2468 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2469 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2470 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2471 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2472 ITy, unwrap(Ty), AllocSize,
2473 unwrap(Val), nullptr, "");
2474 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2477 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2479 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), nullptr, Name));
2482 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2483 LLVMValueRef Val, const char *Name) {
2484 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
2487 LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {
2488 return wrap(unwrap(B)->Insert(
2489 CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
2492 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
2494 return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
2497 LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val,
2498 LLVMValueRef PointerVal) {
2499 return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
2502 static AtomicOrdering mapFromLLVMOrdering(LLVMAtomicOrdering Ordering) {
2504 case LLVMAtomicOrderingNotAtomic: return NotAtomic;
2505 case LLVMAtomicOrderingUnordered: return Unordered;
2506 case LLVMAtomicOrderingMonotonic: return Monotonic;
2507 case LLVMAtomicOrderingAcquire: return Acquire;
2508 case LLVMAtomicOrderingRelease: return Release;
2509 case LLVMAtomicOrderingAcquireRelease: return AcquireRelease;
2510 case LLVMAtomicOrderingSequentiallyConsistent:
2511 return SequentiallyConsistent;
2514 llvm_unreachable("Invalid LLVMAtomicOrdering value!");
2517 static LLVMAtomicOrdering mapToLLVMOrdering(AtomicOrdering Ordering) {
2519 case NotAtomic: return LLVMAtomicOrderingNotAtomic;
2520 case Unordered: return LLVMAtomicOrderingUnordered;
2521 case Monotonic: return LLVMAtomicOrderingMonotonic;
2522 case Acquire: return LLVMAtomicOrderingAcquire;
2523 case Release: return LLVMAtomicOrderingRelease;
2524 case AcquireRelease: return LLVMAtomicOrderingAcquireRelease;
2525 case SequentiallyConsistent:
2526 return LLVMAtomicOrderingSequentiallyConsistent;
2529 llvm_unreachable("Invalid AtomicOrdering value!");
2532 LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering Ordering,
2533 LLVMBool isSingleThread, const char *Name) {
2535 unwrap(B)->CreateFence(mapFromLLVMOrdering(Ordering),
2536 isSingleThread ? SingleThread : CrossThread,
2540 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2541 LLVMValueRef *Indices, unsigned NumIndices,
2543 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2544 return wrap(unwrap(B)->CreateGEP(nullptr, unwrap(Pointer), IdxList, Name));
2547 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2548 LLVMValueRef *Indices, unsigned NumIndices,
2550 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2552 unwrap(B)->CreateInBoundsGEP(nullptr, unwrap(Pointer), IdxList, Name));
2555 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2556 unsigned Idx, const char *Name) {
2557 return wrap(unwrap(B)->CreateStructGEP(nullptr, unwrap(Pointer), Idx, Name));
2560 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2562 return wrap(unwrap(B)->CreateGlobalString(Str, Name));
2565 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2567 return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
2570 LLVMBool LLVMGetVolatile(LLVMValueRef MemAccessInst) {
2571 Value *P = unwrap<Value>(MemAccessInst);
2572 if (LoadInst *LI = dyn_cast<LoadInst>(P))
2573 return LI->isVolatile();
2574 return cast<StoreInst>(P)->isVolatile();
2577 void LLVMSetVolatile(LLVMValueRef MemAccessInst, LLVMBool isVolatile) {
2578 Value *P = unwrap<Value>(MemAccessInst);
2579 if (LoadInst *LI = dyn_cast<LoadInst>(P))
2580 return LI->setVolatile(isVolatile);
2581 return cast<StoreInst>(P)->setVolatile(isVolatile);
2584 LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemAccessInst) {
2585 Value *P = unwrap<Value>(MemAccessInst);
2587 if (LoadInst *LI = dyn_cast<LoadInst>(P))
2588 O = LI->getOrdering();
2590 O = cast<StoreInst>(P)->getOrdering();
2591 return mapToLLVMOrdering(O);
2594 void LLVMSetOrdering(LLVMValueRef MemAccessInst, LLVMAtomicOrdering Ordering) {
2595 Value *P = unwrap<Value>(MemAccessInst);
2596 AtomicOrdering O = mapFromLLVMOrdering(Ordering);
2598 if (LoadInst *LI = dyn_cast<LoadInst>(P))
2599 return LI->setOrdering(O);
2600 return cast<StoreInst>(P)->setOrdering(O);
2603 /*--.. Casts ...............................................................--*/
2605 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2606 LLVMTypeRef DestTy, const char *Name) {
2607 return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
2610 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val,
2611 LLVMTypeRef DestTy, const char *Name) {
2612 return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
2615 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val,
2616 LLVMTypeRef DestTy, const char *Name) {
2617 return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
2620 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val,
2621 LLVMTypeRef DestTy, const char *Name) {
2622 return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
2625 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val,
2626 LLVMTypeRef DestTy, const char *Name) {
2627 return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
2630 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2631 LLVMTypeRef DestTy, const char *Name) {
2632 return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
2635 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2636 LLVMTypeRef DestTy, const char *Name) {
2637 return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
2640 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2641 LLVMTypeRef DestTy, const char *Name) {
2642 return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
2645 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val,
2646 LLVMTypeRef DestTy, const char *Name) {
2647 return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
2650 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val,
2651 LLVMTypeRef DestTy, const char *Name) {
2652 return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
2655 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val,
2656 LLVMTypeRef DestTy, const char *Name) {
2657 return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
2660 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2661 LLVMTypeRef DestTy, const char *Name) {
2662 return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
2665 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef B, LLVMValueRef Val,
2666 LLVMTypeRef DestTy, const char *Name) {
2667 return wrap(unwrap(B)->CreateAddrSpaceCast(unwrap(Val), unwrap(DestTy), Name));
2670 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2671 LLVMTypeRef DestTy, const char *Name) {
2672 return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
2676 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2677 LLVMTypeRef DestTy, const char *Name) {
2678 return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
2682 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2683 LLVMTypeRef DestTy, const char *Name) {
2684 return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
2688 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2689 LLVMTypeRef DestTy, const char *Name) {
2690 return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
2691 unwrap(DestTy), Name));
2694 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val,
2695 LLVMTypeRef DestTy, const char *Name) {
2696 return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
2699 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val,
2700 LLVMTypeRef DestTy, const char *Name) {
2701 return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy),
2702 /*isSigned*/true, Name));
2705 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef B, LLVMValueRef Val,
2706 LLVMTypeRef DestTy, const char *Name) {
2707 return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
2710 /*--.. Comparisons .........................................................--*/
2712 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
2713 LLVMValueRef LHS, LLVMValueRef RHS,
2715 return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
2716 unwrap(LHS), unwrap(RHS), Name));
2719 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
2720 LLVMValueRef LHS, LLVMValueRef RHS,
2722 return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
2723 unwrap(LHS), unwrap(RHS), Name));
2726 /*--.. Miscellaneous instructions ..........................................--*/
2728 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {
2729 return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
2732 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
2733 LLVMValueRef *Args, unsigned NumArgs,
2735 return wrap(unwrap(B)->CreateCall(unwrap(Fn),
2736 makeArrayRef(unwrap(Args), NumArgs),
2740 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
2741 LLVMValueRef Then, LLVMValueRef Else,
2743 return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
2747 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List,
2748 LLVMTypeRef Ty, const char *Name) {
2749 return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
2752 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2753 LLVMValueRef Index, const char *Name) {
2754 return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
2758 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2759 LLVMValueRef EltVal, LLVMValueRef Index,
2761 return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
2762 unwrap(Index), Name));
2765 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1,
2766 LLVMValueRef V2, LLVMValueRef Mask,
2768 return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
2769 unwrap(Mask), Name));
2772 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2773 unsigned Index, const char *Name) {
2774 return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
2777 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2778 LLVMValueRef EltVal, unsigned Index,
2780 return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
2784 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val,
2786 return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
2789 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef B, LLVMValueRef Val,
2791 return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
2794 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS,
2795 LLVMValueRef RHS, const char *Name) {
2796 return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
2799 LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B,LLVMAtomicRMWBinOp op,
2800 LLVMValueRef PTR, LLVMValueRef Val,
2801 LLVMAtomicOrdering ordering,
2802 LLVMBool singleThread) {
2803 AtomicRMWInst::BinOp intop;
2805 case LLVMAtomicRMWBinOpXchg: intop = AtomicRMWInst::Xchg; break;
2806 case LLVMAtomicRMWBinOpAdd: intop = AtomicRMWInst::Add; break;
2807 case LLVMAtomicRMWBinOpSub: intop = AtomicRMWInst::Sub; break;
2808 case LLVMAtomicRMWBinOpAnd: intop = AtomicRMWInst::And; break;
2809 case LLVMAtomicRMWBinOpNand: intop = AtomicRMWInst::Nand; break;
2810 case LLVMAtomicRMWBinOpOr: intop = AtomicRMWInst::Or; break;
2811 case LLVMAtomicRMWBinOpXor: intop = AtomicRMWInst::Xor; break;
2812 case LLVMAtomicRMWBinOpMax: intop = AtomicRMWInst::Max; break;
2813 case LLVMAtomicRMWBinOpMin: intop = AtomicRMWInst::Min; break;
2814 case LLVMAtomicRMWBinOpUMax: intop = AtomicRMWInst::UMax; break;
2815 case LLVMAtomicRMWBinOpUMin: intop = AtomicRMWInst::UMin; break;
2817 return wrap(unwrap(B)->CreateAtomicRMW(intop, unwrap(PTR), unwrap(Val),
2818 mapFromLLVMOrdering(ordering), singleThread ? SingleThread : CrossThread));
2822 /*===-- Module providers --------------------------------------------------===*/
2824 LLVMModuleProviderRef
2825 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) {
2826 return reinterpret_cast<LLVMModuleProviderRef>(M);
2829 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) {
2834 /*===-- Memory buffers ----------------------------------------------------===*/
2836 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(
2838 LLVMMemoryBufferRef *OutMemBuf,
2839 char **OutMessage) {
2841 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getFile(Path);
2842 if (std::error_code EC = MBOrErr.getError()) {
2843 *OutMessage = strdup(EC.message().c_str());
2846 *OutMemBuf = wrap(MBOrErr.get().release());
2850 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2851 char **OutMessage) {
2852 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getSTDIN();
2853 if (std::error_code EC = MBOrErr.getError()) {
2854 *OutMessage = strdup(EC.message().c_str());
2857 *OutMemBuf = wrap(MBOrErr.get().release());
2861 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(
2862 const char *InputData,
2863 size_t InputDataLength,
2864 const char *BufferName,
2865 LLVMBool RequiresNullTerminator) {
2867 return wrap(MemoryBuffer::getMemBuffer(StringRef(InputData, InputDataLength),
2868 StringRef(BufferName),
2869 RequiresNullTerminator).release());
2872 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(
2873 const char *InputData,
2874 size_t InputDataLength,
2875 const char *BufferName) {
2878 MemoryBuffer::getMemBufferCopy(StringRef(InputData, InputDataLength),
2879 StringRef(BufferName)).release());
2882 const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf) {
2883 return unwrap(MemBuf)->getBufferStart();
2886 size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf) {
2887 return unwrap(MemBuf)->getBufferSize();
2890 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) {
2891 delete unwrap(MemBuf);
2894 /*===-- Pass Registry -----------------------------------------------------===*/
2896 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void) {
2897 return wrap(PassRegistry::getPassRegistry());
2900 /*===-- Pass Manager ------------------------------------------------------===*/
2902 LLVMPassManagerRef LLVMCreatePassManager() {
2903 return wrap(new legacy::PassManager());
2906 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M) {
2907 return wrap(new legacy::FunctionPassManager(unwrap(M)));
2910 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) {
2911 return LLVMCreateFunctionPassManagerForModule(
2912 reinterpret_cast<LLVMModuleRef>(P));
2915 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
2916 return unwrap<legacy::PassManager>(PM)->run(*unwrap(M));
2919 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM) {
2920 return unwrap<legacy::FunctionPassManager>(FPM)->doInitialization();
2923 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F) {
2924 return unwrap<legacy::FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
2927 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM) {
2928 return unwrap<legacy::FunctionPassManager>(FPM)->doFinalization();
2931 void LLVMDisposePassManager(LLVMPassManagerRef PM) {
2935 /*===-- Threading ------------------------------------------------------===*/
2937 LLVMBool LLVMStartMultithreaded() {
2938 return LLVMIsMultithreaded();
2941 void LLVMStopMultithreaded() {
2944 LLVMBool LLVMIsMultithreaded() {
2945 return llvm_is_multithreaded();