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;
265 case Type::TokenTyID:
266 return LLVMTokenTypeKind;
268 llvm_unreachable("Unhandled TypeID.");
271 LLVMBool LLVMTypeIsSized(LLVMTypeRef Ty)
273 return unwrap(Ty)->isSized();
276 LLVMContextRef LLVMGetTypeContext(LLVMTypeRef Ty) {
277 return wrap(&unwrap(Ty)->getContext());
280 void LLVMDumpType(LLVMTypeRef Ty) {
281 return unwrap(Ty)->dump();
284 char *LLVMPrintTypeToString(LLVMTypeRef Ty) {
286 raw_string_ostream os(buf);
289 unwrap(Ty)->print(os);
291 os << "Printing <null> Type";
295 return strdup(buf.c_str());
298 /*--.. Operations on integer types .........................................--*/
300 LLVMTypeRef LLVMInt1TypeInContext(LLVMContextRef C) {
301 return (LLVMTypeRef) Type::getInt1Ty(*unwrap(C));
303 LLVMTypeRef LLVMInt8TypeInContext(LLVMContextRef C) {
304 return (LLVMTypeRef) Type::getInt8Ty(*unwrap(C));
306 LLVMTypeRef LLVMInt16TypeInContext(LLVMContextRef C) {
307 return (LLVMTypeRef) Type::getInt16Ty(*unwrap(C));
309 LLVMTypeRef LLVMInt32TypeInContext(LLVMContextRef C) {
310 return (LLVMTypeRef) Type::getInt32Ty(*unwrap(C));
312 LLVMTypeRef LLVMInt64TypeInContext(LLVMContextRef C) {
313 return (LLVMTypeRef) Type::getInt64Ty(*unwrap(C));
315 LLVMTypeRef LLVMInt128TypeInContext(LLVMContextRef C) {
316 return (LLVMTypeRef) Type::getInt128Ty(*unwrap(C));
318 LLVMTypeRef LLVMIntTypeInContext(LLVMContextRef C, unsigned NumBits) {
319 return wrap(IntegerType::get(*unwrap(C), NumBits));
322 LLVMTypeRef LLVMInt1Type(void) {
323 return LLVMInt1TypeInContext(LLVMGetGlobalContext());
325 LLVMTypeRef LLVMInt8Type(void) {
326 return LLVMInt8TypeInContext(LLVMGetGlobalContext());
328 LLVMTypeRef LLVMInt16Type(void) {
329 return LLVMInt16TypeInContext(LLVMGetGlobalContext());
331 LLVMTypeRef LLVMInt32Type(void) {
332 return LLVMInt32TypeInContext(LLVMGetGlobalContext());
334 LLVMTypeRef LLVMInt64Type(void) {
335 return LLVMInt64TypeInContext(LLVMGetGlobalContext());
337 LLVMTypeRef LLVMInt128Type(void) {
338 return LLVMInt128TypeInContext(LLVMGetGlobalContext());
340 LLVMTypeRef LLVMIntType(unsigned NumBits) {
341 return LLVMIntTypeInContext(LLVMGetGlobalContext(), NumBits);
344 unsigned LLVMGetIntTypeWidth(LLVMTypeRef IntegerTy) {
345 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
348 /*--.. Operations on real types ............................................--*/
350 LLVMTypeRef LLVMHalfTypeInContext(LLVMContextRef C) {
351 return (LLVMTypeRef) Type::getHalfTy(*unwrap(C));
353 LLVMTypeRef LLVMFloatTypeInContext(LLVMContextRef C) {
354 return (LLVMTypeRef) Type::getFloatTy(*unwrap(C));
356 LLVMTypeRef LLVMDoubleTypeInContext(LLVMContextRef C) {
357 return (LLVMTypeRef) Type::getDoubleTy(*unwrap(C));
359 LLVMTypeRef LLVMX86FP80TypeInContext(LLVMContextRef C) {
360 return (LLVMTypeRef) Type::getX86_FP80Ty(*unwrap(C));
362 LLVMTypeRef LLVMFP128TypeInContext(LLVMContextRef C) {
363 return (LLVMTypeRef) Type::getFP128Ty(*unwrap(C));
365 LLVMTypeRef LLVMPPCFP128TypeInContext(LLVMContextRef C) {
366 return (LLVMTypeRef) Type::getPPC_FP128Ty(*unwrap(C));
368 LLVMTypeRef LLVMX86MMXTypeInContext(LLVMContextRef C) {
369 return (LLVMTypeRef) Type::getX86_MMXTy(*unwrap(C));
371 LLVMTypeRef LLVMTokenTypeInContext(LLVMContextRef C) {
372 return (LLVMTypeRef) Type::getTokenTy(*unwrap(C));
375 LLVMTypeRef LLVMHalfType(void) {
376 return LLVMHalfTypeInContext(LLVMGetGlobalContext());
378 LLVMTypeRef LLVMFloatType(void) {
379 return LLVMFloatTypeInContext(LLVMGetGlobalContext());
381 LLVMTypeRef LLVMDoubleType(void) {
382 return LLVMDoubleTypeInContext(LLVMGetGlobalContext());
384 LLVMTypeRef LLVMX86FP80Type(void) {
385 return LLVMX86FP80TypeInContext(LLVMGetGlobalContext());
387 LLVMTypeRef LLVMFP128Type(void) {
388 return LLVMFP128TypeInContext(LLVMGetGlobalContext());
390 LLVMTypeRef LLVMPPCFP128Type(void) {
391 return LLVMPPCFP128TypeInContext(LLVMGetGlobalContext());
393 LLVMTypeRef LLVMX86MMXType(void) {
394 return LLVMX86MMXTypeInContext(LLVMGetGlobalContext());
397 /*--.. Operations on function types ........................................--*/
399 LLVMTypeRef LLVMFunctionType(LLVMTypeRef ReturnType,
400 LLVMTypeRef *ParamTypes, unsigned ParamCount,
402 ArrayRef<Type*> Tys(unwrap(ParamTypes), ParamCount);
403 return wrap(FunctionType::get(unwrap(ReturnType), Tys, IsVarArg != 0));
406 LLVMBool LLVMIsFunctionVarArg(LLVMTypeRef FunctionTy) {
407 return unwrap<FunctionType>(FunctionTy)->isVarArg();
410 LLVMTypeRef LLVMGetReturnType(LLVMTypeRef FunctionTy) {
411 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
414 unsigned LLVMCountParamTypes(LLVMTypeRef FunctionTy) {
415 return unwrap<FunctionType>(FunctionTy)->getNumParams();
418 void LLVMGetParamTypes(LLVMTypeRef FunctionTy, LLVMTypeRef *Dest) {
419 FunctionType *Ty = unwrap<FunctionType>(FunctionTy);
420 for (FunctionType::param_iterator I = Ty->param_begin(),
421 E = Ty->param_end(); I != E; ++I)
425 /*--.. Operations on struct types ..........................................--*/
427 LLVMTypeRef LLVMStructTypeInContext(LLVMContextRef C, LLVMTypeRef *ElementTypes,
428 unsigned ElementCount, LLVMBool Packed) {
429 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
430 return wrap(StructType::get(*unwrap(C), Tys, Packed != 0));
433 LLVMTypeRef LLVMStructType(LLVMTypeRef *ElementTypes,
434 unsigned ElementCount, LLVMBool Packed) {
435 return LLVMStructTypeInContext(LLVMGetGlobalContext(), ElementTypes,
436 ElementCount, Packed);
439 LLVMTypeRef LLVMStructCreateNamed(LLVMContextRef C, const char *Name)
441 return wrap(StructType::create(*unwrap(C), Name));
444 const char *LLVMGetStructName(LLVMTypeRef Ty)
446 StructType *Type = unwrap<StructType>(Ty);
447 if (!Type->hasName())
449 return Type->getName().data();
452 void LLVMStructSetBody(LLVMTypeRef StructTy, LLVMTypeRef *ElementTypes,
453 unsigned ElementCount, LLVMBool Packed) {
454 ArrayRef<Type*> Tys(unwrap(ElementTypes), ElementCount);
455 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
458 unsigned LLVMCountStructElementTypes(LLVMTypeRef StructTy) {
459 return unwrap<StructType>(StructTy)->getNumElements();
462 void LLVMGetStructElementTypes(LLVMTypeRef StructTy, LLVMTypeRef *Dest) {
463 StructType *Ty = unwrap<StructType>(StructTy);
464 for (StructType::element_iterator I = Ty->element_begin(),
465 E = Ty->element_end(); I != E; ++I)
469 LLVMTypeRef LLVMStructGetTypeAtIndex(LLVMTypeRef StructTy, unsigned i) {
470 StructType *Ty = unwrap<StructType>(StructTy);
471 return wrap(Ty->getTypeAtIndex(i));
474 LLVMBool LLVMIsPackedStruct(LLVMTypeRef StructTy) {
475 return unwrap<StructType>(StructTy)->isPacked();
478 LLVMBool LLVMIsOpaqueStruct(LLVMTypeRef StructTy) {
479 return unwrap<StructType>(StructTy)->isOpaque();
482 LLVMTypeRef LLVMGetTypeByName(LLVMModuleRef M, const char *Name) {
483 return wrap(unwrap(M)->getTypeByName(Name));
486 /*--.. Operations on array, pointer, and vector types (sequence types) .....--*/
488 LLVMTypeRef LLVMArrayType(LLVMTypeRef ElementType, unsigned ElementCount) {
489 return wrap(ArrayType::get(unwrap(ElementType), ElementCount));
492 LLVMTypeRef LLVMPointerType(LLVMTypeRef ElementType, unsigned AddressSpace) {
493 return wrap(PointerType::get(unwrap(ElementType), AddressSpace));
496 LLVMTypeRef LLVMVectorType(LLVMTypeRef ElementType, unsigned ElementCount) {
497 return wrap(VectorType::get(unwrap(ElementType), ElementCount));
500 LLVMTypeRef LLVMGetElementType(LLVMTypeRef Ty) {
501 return wrap(unwrap<SequentialType>(Ty)->getElementType());
504 unsigned LLVMGetArrayLength(LLVMTypeRef ArrayTy) {
505 return unwrap<ArrayType>(ArrayTy)->getNumElements();
508 unsigned LLVMGetPointerAddressSpace(LLVMTypeRef PointerTy) {
509 return unwrap<PointerType>(PointerTy)->getAddressSpace();
512 unsigned LLVMGetVectorSize(LLVMTypeRef VectorTy) {
513 return unwrap<VectorType>(VectorTy)->getNumElements();
516 /*--.. Operations on other types ...........................................--*/
518 LLVMTypeRef LLVMVoidTypeInContext(LLVMContextRef C) {
519 return wrap(Type::getVoidTy(*unwrap(C)));
521 LLVMTypeRef LLVMLabelTypeInContext(LLVMContextRef C) {
522 return wrap(Type::getLabelTy(*unwrap(C)));
525 LLVMTypeRef LLVMVoidType(void) {
526 return LLVMVoidTypeInContext(LLVMGetGlobalContext());
528 LLVMTypeRef LLVMLabelType(void) {
529 return LLVMLabelTypeInContext(LLVMGetGlobalContext());
532 /*===-- Operations on values ----------------------------------------------===*/
534 /*--.. Operations on all values ............................................--*/
536 LLVMTypeRef LLVMTypeOf(LLVMValueRef Val) {
537 return wrap(unwrap(Val)->getType());
540 const char *LLVMGetValueName(LLVMValueRef Val) {
541 return unwrap(Val)->getName().data();
544 void LLVMSetValueName(LLVMValueRef Val, const char *Name) {
545 unwrap(Val)->setName(Name);
548 void LLVMDumpValue(LLVMValueRef Val) {
552 char* LLVMPrintValueToString(LLVMValueRef Val) {
554 raw_string_ostream os(buf);
557 unwrap(Val)->print(os);
559 os << "Printing <null> Value";
563 return strdup(buf.c_str());
566 void LLVMReplaceAllUsesWith(LLVMValueRef OldVal, LLVMValueRef NewVal) {
567 unwrap(OldVal)->replaceAllUsesWith(unwrap(NewVal));
570 int LLVMHasMetadata(LLVMValueRef Inst) {
571 return unwrap<Instruction>(Inst)->hasMetadata();
574 LLVMValueRef LLVMGetMetadata(LLVMValueRef Inst, unsigned KindID) {
575 auto *I = unwrap<Instruction>(Inst);
576 assert(I && "Expected instruction");
577 if (auto *MD = I->getMetadata(KindID))
578 return wrap(MetadataAsValue::get(I->getContext(), MD));
582 // MetadataAsValue uses a canonical format which strips the actual MDNode for
583 // MDNode with just a single constant value, storing just a ConstantAsMetadata
584 // This undoes this canonicalization, reconstructing the MDNode.
585 static MDNode *extractMDNode(MetadataAsValue *MAV) {
586 Metadata *MD = MAV->getMetadata();
587 assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
588 "Expected a metadata node or a canonicalized constant");
590 if (MDNode *N = dyn_cast<MDNode>(MD))
593 return MDNode::get(MAV->getContext(), MD);
596 void LLVMSetMetadata(LLVMValueRef Inst, unsigned KindID, LLVMValueRef Val) {
597 MDNode *N = Val ? extractMDNode(unwrap<MetadataAsValue>(Val)) : nullptr;
599 unwrap<Instruction>(Inst)->setMetadata(KindID, N);
602 /*--.. Conversion functions ................................................--*/
604 #define LLVM_DEFINE_VALUE_CAST(name) \
605 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
606 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
609 LLVM_FOR_EACH_VALUE_SUBCLASS(LLVM_DEFINE_VALUE_CAST)
611 LLVMValueRef LLVMIsAMDNode(LLVMValueRef Val) {
612 if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
613 if (isa<MDNode>(MD->getMetadata()) ||
614 isa<ValueAsMetadata>(MD->getMetadata()))
619 LLVMValueRef LLVMIsAMDString(LLVMValueRef Val) {
620 if (auto *MD = dyn_cast_or_null<MetadataAsValue>(unwrap(Val)))
621 if (isa<MDString>(MD->getMetadata()))
626 /*--.. Operations on Uses ..................................................--*/
627 LLVMUseRef LLVMGetFirstUse(LLVMValueRef Val) {
628 Value *V = unwrap(Val);
629 Value::use_iterator I = V->use_begin();
630 if (I == V->use_end())
635 LLVMUseRef LLVMGetNextUse(LLVMUseRef U) {
636 Use *Next = unwrap(U)->getNext();
642 LLVMValueRef LLVMGetUser(LLVMUseRef U) {
643 return wrap(unwrap(U)->getUser());
646 LLVMValueRef LLVMGetUsedValue(LLVMUseRef U) {
647 return wrap(unwrap(U)->get());
650 /*--.. Operations on Users .................................................--*/
652 static LLVMValueRef getMDNodeOperandImpl(LLVMContext &Context, const MDNode *N,
654 Metadata *Op = N->getOperand(Index);
657 if (auto *C = dyn_cast<ConstantAsMetadata>(Op))
658 return wrap(C->getValue());
659 return wrap(MetadataAsValue::get(Context, Op));
662 LLVMValueRef LLVMGetOperand(LLVMValueRef Val, unsigned Index) {
663 Value *V = unwrap(Val);
664 if (auto *MD = dyn_cast<MetadataAsValue>(V)) {
665 if (auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
666 assert(Index == 0 && "Function-local metadata can only have one operand");
667 return wrap(L->getValue());
669 return getMDNodeOperandImpl(V->getContext(),
670 cast<MDNode>(MD->getMetadata()), Index);
673 return wrap(cast<User>(V)->getOperand(Index));
676 LLVMUseRef LLVMGetOperandUse(LLVMValueRef Val, unsigned Index) {
677 Value *V = unwrap(Val);
678 return wrap(&cast<User>(V)->getOperandUse(Index));
681 void LLVMSetOperand(LLVMValueRef Val, unsigned Index, LLVMValueRef Op) {
682 unwrap<User>(Val)->setOperand(Index, unwrap(Op));
685 int LLVMGetNumOperands(LLVMValueRef Val) {
686 Value *V = unwrap(Val);
687 if (isa<MetadataAsValue>(V))
688 return LLVMGetMDNodeNumOperands(Val);
690 return cast<User>(V)->getNumOperands();
693 /*--.. Operations on constants of any type .................................--*/
695 LLVMValueRef LLVMConstNull(LLVMTypeRef Ty) {
696 return wrap(Constant::getNullValue(unwrap(Ty)));
699 LLVMValueRef LLVMConstAllOnes(LLVMTypeRef Ty) {
700 return wrap(Constant::getAllOnesValue(unwrap(Ty)));
703 LLVMValueRef LLVMGetUndef(LLVMTypeRef Ty) {
704 return wrap(UndefValue::get(unwrap(Ty)));
707 LLVMBool LLVMIsConstant(LLVMValueRef Ty) {
708 return isa<Constant>(unwrap(Ty));
711 LLVMBool LLVMIsNull(LLVMValueRef Val) {
712 if (Constant *C = dyn_cast<Constant>(unwrap(Val)))
713 return C->isNullValue();
717 LLVMBool LLVMIsUndef(LLVMValueRef Val) {
718 return isa<UndefValue>(unwrap(Val));
721 LLVMValueRef LLVMConstPointerNull(LLVMTypeRef Ty) {
723 wrap(ConstantPointerNull::get(unwrap<PointerType>(Ty)));
726 /*--.. Operations on metadata nodes ........................................--*/
728 LLVMValueRef LLVMMDStringInContext(LLVMContextRef C, const char *Str,
730 LLVMContext &Context = *unwrap(C);
731 return wrap(MetadataAsValue::get(
732 Context, MDString::get(Context, StringRef(Str, SLen))));
735 LLVMValueRef LLVMMDString(const char *Str, unsigned SLen) {
736 return LLVMMDStringInContext(LLVMGetGlobalContext(), Str, SLen);
739 LLVMValueRef LLVMMDNodeInContext(LLVMContextRef C, LLVMValueRef *Vals,
741 LLVMContext &Context = *unwrap(C);
742 SmallVector<Metadata *, 8> MDs;
743 for (auto *OV : makeArrayRef(Vals, Count)) {
744 Value *V = unwrap(OV);
748 else if (auto *C = dyn_cast<Constant>(V))
749 MD = ConstantAsMetadata::get(C);
750 else if (auto *MDV = dyn_cast<MetadataAsValue>(V)) {
751 MD = MDV->getMetadata();
752 assert(!isa<LocalAsMetadata>(MD) && "Unexpected function-local metadata "
753 "outside of direct argument to call");
755 // This is function-local metadata. Pretend to make an MDNode.
757 "Expected only one operand to function-local metadata");
758 return wrap(MetadataAsValue::get(Context, LocalAsMetadata::get(V)));
763 return wrap(MetadataAsValue::get(Context, MDNode::get(Context, MDs)));
766 LLVMValueRef LLVMMDNode(LLVMValueRef *Vals, unsigned Count) {
767 return LLVMMDNodeInContext(LLVMGetGlobalContext(), Vals, Count);
770 const char *LLVMGetMDString(LLVMValueRef V, unsigned* Len) {
771 if (const auto *MD = dyn_cast<MetadataAsValue>(unwrap(V)))
772 if (const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
773 *Len = S->getString().size();
774 return S->getString().data();
780 unsigned LLVMGetMDNodeNumOperands(LLVMValueRef V)
782 auto *MD = cast<MetadataAsValue>(unwrap(V));
783 if (isa<ValueAsMetadata>(MD->getMetadata()))
785 return cast<MDNode>(MD->getMetadata())->getNumOperands();
788 void LLVMGetMDNodeOperands(LLVMValueRef V, LLVMValueRef *Dest)
790 auto *MD = cast<MetadataAsValue>(unwrap(V));
791 if (auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
792 *Dest = wrap(MDV->getValue());
795 const auto *N = cast<MDNode>(MD->getMetadata());
796 const unsigned numOperands = N->getNumOperands();
797 LLVMContext &Context = unwrap(V)->getContext();
798 for (unsigned i = 0; i < numOperands; i++)
799 Dest[i] = getMDNodeOperandImpl(Context, N, i);
802 unsigned LLVMGetNamedMetadataNumOperands(LLVMModuleRef M, const char* name)
804 if (NamedMDNode *N = unwrap(M)->getNamedMetadata(name)) {
805 return N->getNumOperands();
810 void LLVMGetNamedMetadataOperands(LLVMModuleRef M, const char* name, LLVMValueRef *Dest)
812 NamedMDNode *N = unwrap(M)->getNamedMetadata(name);
815 LLVMContext &Context = unwrap(M)->getContext();
816 for (unsigned i=0;i<N->getNumOperands();i++)
817 Dest[i] = wrap(MetadataAsValue::get(Context, N->getOperand(i)));
820 void LLVMAddNamedMetadataOperand(LLVMModuleRef M, const char* name,
823 NamedMDNode *N = unwrap(M)->getOrInsertNamedMetadata(name);
828 N->addOperand(extractMDNode(unwrap<MetadataAsValue>(Val)));
831 /*--.. Operations on scalar constants ......................................--*/
833 LLVMValueRef LLVMConstInt(LLVMTypeRef IntTy, unsigned long long N,
834 LLVMBool SignExtend) {
835 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), N, SignExtend != 0));
838 LLVMValueRef LLVMConstIntOfArbitraryPrecision(LLVMTypeRef IntTy,
840 const uint64_t Words[]) {
841 IntegerType *Ty = unwrap<IntegerType>(IntTy);
842 return wrap(ConstantInt::get(Ty->getContext(),
843 APInt(Ty->getBitWidth(),
844 makeArrayRef(Words, NumWords))));
847 LLVMValueRef LLVMConstIntOfString(LLVMTypeRef IntTy, const char Str[],
849 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str),
853 LLVMValueRef LLVMConstIntOfStringAndSize(LLVMTypeRef IntTy, const char Str[],
854 unsigned SLen, uint8_t Radix) {
855 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy), StringRef(Str, SLen),
859 LLVMValueRef LLVMConstReal(LLVMTypeRef RealTy, double N) {
860 return wrap(ConstantFP::get(unwrap(RealTy), N));
863 LLVMValueRef LLVMConstRealOfString(LLVMTypeRef RealTy, const char *Text) {
864 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Text)));
867 LLVMValueRef LLVMConstRealOfStringAndSize(LLVMTypeRef RealTy, const char Str[],
869 return wrap(ConstantFP::get(unwrap(RealTy), StringRef(Str, SLen)));
872 unsigned long long LLVMConstIntGetZExtValue(LLVMValueRef ConstantVal) {
873 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
876 long long LLVMConstIntGetSExtValue(LLVMValueRef ConstantVal) {
877 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
880 double LLVMConstRealGetDouble(LLVMValueRef ConstantVal, LLVMBool *LosesInfo) {
881 ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
882 Type *Ty = cFP->getType();
884 if (Ty->isFloatTy()) {
886 return cFP->getValueAPF().convertToFloat();
889 if (Ty->isDoubleTy()) {
891 return cFP->getValueAPF().convertToDouble();
895 APFloat APF = cFP->getValueAPF();
896 APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &APFLosesInfo);
897 *LosesInfo = APFLosesInfo;
898 return APF.convertToDouble();
901 /*--.. Operations on composite constants ...................................--*/
903 LLVMValueRef LLVMConstStringInContext(LLVMContextRef C, const char *Str,
905 LLVMBool DontNullTerminate) {
906 /* Inverted the sense of AddNull because ', 0)' is a
907 better mnemonic for null termination than ', 1)'. */
908 return wrap(ConstantDataArray::getString(*unwrap(C), StringRef(Str, Length),
909 DontNullTerminate == 0));
911 LLVMValueRef LLVMConstStructInContext(LLVMContextRef C,
912 LLVMValueRef *ConstantVals,
913 unsigned Count, LLVMBool Packed) {
914 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
915 return wrap(ConstantStruct::getAnon(*unwrap(C), makeArrayRef(Elements, Count),
919 LLVMValueRef LLVMConstString(const char *Str, unsigned Length,
920 LLVMBool DontNullTerminate) {
921 return LLVMConstStringInContext(LLVMGetGlobalContext(), Str, Length,
925 LLVMValueRef LLVMGetElementAsConstant(LLVMValueRef c, unsigned idx) {
926 return wrap(static_cast<ConstantDataSequential*>(unwrap(c))->getElementAsConstant(idx));
929 LLVMBool LLVMIsConstantString(LLVMValueRef c) {
930 return static_cast<ConstantDataSequential*>(unwrap(c))->isString();
933 const char *LLVMGetAsString(LLVMValueRef c, size_t* Length) {
934 StringRef str = static_cast<ConstantDataSequential*>(unwrap(c))->getAsString();
935 *Length = str.size();
939 LLVMValueRef LLVMConstArray(LLVMTypeRef ElementTy,
940 LLVMValueRef *ConstantVals, unsigned Length) {
941 ArrayRef<Constant*> V(unwrap<Constant>(ConstantVals, Length), Length);
942 return wrap(ConstantArray::get(ArrayType::get(unwrap(ElementTy), Length), V));
945 LLVMValueRef LLVMConstStruct(LLVMValueRef *ConstantVals, unsigned Count,
947 return LLVMConstStructInContext(LLVMGetGlobalContext(), ConstantVals, Count,
951 LLVMValueRef LLVMConstNamedStruct(LLVMTypeRef StructTy,
952 LLVMValueRef *ConstantVals,
954 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
955 StructType *Ty = cast<StructType>(unwrap(StructTy));
957 return wrap(ConstantStruct::get(Ty, makeArrayRef(Elements, Count)));
960 LLVMValueRef LLVMConstVector(LLVMValueRef *ScalarConstantVals, unsigned Size) {
961 return wrap(ConstantVector::get(makeArrayRef(
962 unwrap<Constant>(ScalarConstantVals, Size), Size)));
965 /*-- Opcode mapping */
967 static LLVMOpcode map_to_llvmopcode(int opcode)
970 default: llvm_unreachable("Unhandled Opcode.");
971 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
972 #include "llvm/IR/Instruction.def"
977 static int map_from_llvmopcode(LLVMOpcode code)
980 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
981 #include "llvm/IR/Instruction.def"
984 llvm_unreachable("Unhandled Opcode.");
987 /*--.. Constant expressions ................................................--*/
989 LLVMOpcode LLVMGetConstOpcode(LLVMValueRef ConstantVal) {
990 return map_to_llvmopcode(unwrap<ConstantExpr>(ConstantVal)->getOpcode());
993 LLVMValueRef LLVMAlignOf(LLVMTypeRef Ty) {
994 return wrap(ConstantExpr::getAlignOf(unwrap(Ty)));
997 LLVMValueRef LLVMSizeOf(LLVMTypeRef Ty) {
998 return wrap(ConstantExpr::getSizeOf(unwrap(Ty)));
1001 LLVMValueRef LLVMConstNeg(LLVMValueRef ConstantVal) {
1002 return wrap(ConstantExpr::getNeg(unwrap<Constant>(ConstantVal)));
1005 LLVMValueRef LLVMConstNSWNeg(LLVMValueRef ConstantVal) {
1006 return wrap(ConstantExpr::getNSWNeg(unwrap<Constant>(ConstantVal)));
1009 LLVMValueRef LLVMConstNUWNeg(LLVMValueRef ConstantVal) {
1010 return wrap(ConstantExpr::getNUWNeg(unwrap<Constant>(ConstantVal)));
1014 LLVMValueRef LLVMConstFNeg(LLVMValueRef ConstantVal) {
1015 return wrap(ConstantExpr::getFNeg(unwrap<Constant>(ConstantVal)));
1018 LLVMValueRef LLVMConstNot(LLVMValueRef ConstantVal) {
1019 return wrap(ConstantExpr::getNot(unwrap<Constant>(ConstantVal)));
1022 LLVMValueRef LLVMConstAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1023 return wrap(ConstantExpr::getAdd(unwrap<Constant>(LHSConstant),
1024 unwrap<Constant>(RHSConstant)));
1027 LLVMValueRef LLVMConstNSWAdd(LLVMValueRef LHSConstant,
1028 LLVMValueRef RHSConstant) {
1029 return wrap(ConstantExpr::getNSWAdd(unwrap<Constant>(LHSConstant),
1030 unwrap<Constant>(RHSConstant)));
1033 LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant,
1034 LLVMValueRef RHSConstant) {
1035 return wrap(ConstantExpr::getNUWAdd(unwrap<Constant>(LHSConstant),
1036 unwrap<Constant>(RHSConstant)));
1039 LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1040 return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant),
1041 unwrap<Constant>(RHSConstant)));
1044 LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1045 return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant),
1046 unwrap<Constant>(RHSConstant)));
1049 LLVMValueRef LLVMConstNSWSub(LLVMValueRef LHSConstant,
1050 LLVMValueRef RHSConstant) {
1051 return wrap(ConstantExpr::getNSWSub(unwrap<Constant>(LHSConstant),
1052 unwrap<Constant>(RHSConstant)));
1055 LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant,
1056 LLVMValueRef RHSConstant) {
1057 return wrap(ConstantExpr::getNUWSub(unwrap<Constant>(LHSConstant),
1058 unwrap<Constant>(RHSConstant)));
1061 LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1062 return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant),
1063 unwrap<Constant>(RHSConstant)));
1066 LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1067 return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant),
1068 unwrap<Constant>(RHSConstant)));
1071 LLVMValueRef LLVMConstNSWMul(LLVMValueRef LHSConstant,
1072 LLVMValueRef RHSConstant) {
1073 return wrap(ConstantExpr::getNSWMul(unwrap<Constant>(LHSConstant),
1074 unwrap<Constant>(RHSConstant)));
1077 LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant,
1078 LLVMValueRef RHSConstant) {
1079 return wrap(ConstantExpr::getNUWMul(unwrap<Constant>(LHSConstant),
1080 unwrap<Constant>(RHSConstant)));
1083 LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1084 return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant),
1085 unwrap<Constant>(RHSConstant)));
1088 LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1089 return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant),
1090 unwrap<Constant>(RHSConstant)));
1093 LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1094 return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant),
1095 unwrap<Constant>(RHSConstant)));
1098 LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant,
1099 LLVMValueRef RHSConstant) {
1100 return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant),
1101 unwrap<Constant>(RHSConstant)));
1104 LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1105 return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant),
1106 unwrap<Constant>(RHSConstant)));
1109 LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1110 return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant),
1111 unwrap<Constant>(RHSConstant)));
1114 LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1115 return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant),
1116 unwrap<Constant>(RHSConstant)));
1119 LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1120 return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant),
1121 unwrap<Constant>(RHSConstant)));
1124 LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1125 return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant),
1126 unwrap<Constant>(RHSConstant)));
1129 LLVMValueRef LLVMConstOr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1130 return wrap(ConstantExpr::getOr(unwrap<Constant>(LHSConstant),
1131 unwrap<Constant>(RHSConstant)));
1134 LLVMValueRef LLVMConstXor(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1135 return wrap(ConstantExpr::getXor(unwrap<Constant>(LHSConstant),
1136 unwrap<Constant>(RHSConstant)));
1139 LLVMValueRef LLVMConstICmp(LLVMIntPredicate Predicate,
1140 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1141 return wrap(ConstantExpr::getICmp(Predicate,
1142 unwrap<Constant>(LHSConstant),
1143 unwrap<Constant>(RHSConstant)));
1146 LLVMValueRef LLVMConstFCmp(LLVMRealPredicate Predicate,
1147 LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1148 return wrap(ConstantExpr::getFCmp(Predicate,
1149 unwrap<Constant>(LHSConstant),
1150 unwrap<Constant>(RHSConstant)));
1153 LLVMValueRef LLVMConstShl(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1154 return wrap(ConstantExpr::getShl(unwrap<Constant>(LHSConstant),
1155 unwrap<Constant>(RHSConstant)));
1158 LLVMValueRef LLVMConstLShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1159 return wrap(ConstantExpr::getLShr(unwrap<Constant>(LHSConstant),
1160 unwrap<Constant>(RHSConstant)));
1163 LLVMValueRef LLVMConstAShr(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) {
1164 return wrap(ConstantExpr::getAShr(unwrap<Constant>(LHSConstant),
1165 unwrap<Constant>(RHSConstant)));
1168 LLVMValueRef LLVMConstGEP(LLVMValueRef ConstantVal,
1169 LLVMValueRef *ConstantIndices, unsigned NumIndices) {
1170 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1172 return wrap(ConstantExpr::getGetElementPtr(
1173 nullptr, unwrap<Constant>(ConstantVal), IdxList));
1176 LLVMValueRef LLVMConstInBoundsGEP(LLVMValueRef ConstantVal,
1177 LLVMValueRef *ConstantIndices,
1178 unsigned NumIndices) {
1179 Constant* Val = unwrap<Constant>(ConstantVal);
1180 ArrayRef<Constant *> IdxList(unwrap<Constant>(ConstantIndices, NumIndices),
1182 return wrap(ConstantExpr::getInBoundsGetElementPtr(nullptr, Val, IdxList));
1185 LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1186 return wrap(ConstantExpr::getTrunc(unwrap<Constant>(ConstantVal),
1190 LLVMValueRef LLVMConstSExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1191 return wrap(ConstantExpr::getSExt(unwrap<Constant>(ConstantVal),
1195 LLVMValueRef LLVMConstZExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1196 return wrap(ConstantExpr::getZExt(unwrap<Constant>(ConstantVal),
1200 LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1201 return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal),
1205 LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1206 return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal),
1210 LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1211 return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal),
1215 LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1216 return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal),
1220 LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1221 return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal),
1225 LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1226 return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal),
1230 LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1231 return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal),
1235 LLVMValueRef LLVMConstIntToPtr(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1236 return wrap(ConstantExpr::getIntToPtr(unwrap<Constant>(ConstantVal),
1240 LLVMValueRef LLVMConstBitCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1241 return wrap(ConstantExpr::getBitCast(unwrap<Constant>(ConstantVal),
1245 LLVMValueRef LLVMConstAddrSpaceCast(LLVMValueRef ConstantVal,
1246 LLVMTypeRef ToType) {
1247 return wrap(ConstantExpr::getAddrSpaceCast(unwrap<Constant>(ConstantVal),
1251 LLVMValueRef LLVMConstZExtOrBitCast(LLVMValueRef ConstantVal,
1252 LLVMTypeRef ToType) {
1253 return wrap(ConstantExpr::getZExtOrBitCast(unwrap<Constant>(ConstantVal),
1257 LLVMValueRef LLVMConstSExtOrBitCast(LLVMValueRef ConstantVal,
1258 LLVMTypeRef ToType) {
1259 return wrap(ConstantExpr::getSExtOrBitCast(unwrap<Constant>(ConstantVal),
1263 LLVMValueRef LLVMConstTruncOrBitCast(LLVMValueRef ConstantVal,
1264 LLVMTypeRef ToType) {
1265 return wrap(ConstantExpr::getTruncOrBitCast(unwrap<Constant>(ConstantVal),
1269 LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal,
1270 LLVMTypeRef ToType) {
1271 return wrap(ConstantExpr::getPointerCast(unwrap<Constant>(ConstantVal),
1275 LLVMValueRef LLVMConstIntCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType,
1276 LLVMBool isSigned) {
1277 return wrap(ConstantExpr::getIntegerCast(unwrap<Constant>(ConstantVal),
1278 unwrap(ToType), isSigned));
1281 LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) {
1282 return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal),
1286 LLVMValueRef LLVMConstSelect(LLVMValueRef ConstantCondition,
1287 LLVMValueRef ConstantIfTrue,
1288 LLVMValueRef ConstantIfFalse) {
1289 return wrap(ConstantExpr::getSelect(unwrap<Constant>(ConstantCondition),
1290 unwrap<Constant>(ConstantIfTrue),
1291 unwrap<Constant>(ConstantIfFalse)));
1294 LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant,
1295 LLVMValueRef IndexConstant) {
1296 return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant),
1297 unwrap<Constant>(IndexConstant)));
1300 LLVMValueRef LLVMConstInsertElement(LLVMValueRef VectorConstant,
1301 LLVMValueRef ElementValueConstant,
1302 LLVMValueRef IndexConstant) {
1303 return wrap(ConstantExpr::getInsertElement(unwrap<Constant>(VectorConstant),
1304 unwrap<Constant>(ElementValueConstant),
1305 unwrap<Constant>(IndexConstant)));
1308 LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant,
1309 LLVMValueRef VectorBConstant,
1310 LLVMValueRef MaskConstant) {
1311 return wrap(ConstantExpr::getShuffleVector(unwrap<Constant>(VectorAConstant),
1312 unwrap<Constant>(VectorBConstant),
1313 unwrap<Constant>(MaskConstant)));
1316 LLVMValueRef LLVMConstExtractValue(LLVMValueRef AggConstant, unsigned *IdxList,
1318 return wrap(ConstantExpr::getExtractValue(unwrap<Constant>(AggConstant),
1319 makeArrayRef(IdxList, NumIdx)));
1322 LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant,
1323 LLVMValueRef ElementValueConstant,
1324 unsigned *IdxList, unsigned NumIdx) {
1325 return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant),
1326 unwrap<Constant>(ElementValueConstant),
1327 makeArrayRef(IdxList, NumIdx)));
1330 LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString,
1331 const char *Constraints,
1332 LLVMBool HasSideEffects,
1333 LLVMBool IsAlignStack) {
1334 return wrap(InlineAsm::get(dyn_cast<FunctionType>(unwrap(Ty)), AsmString,
1335 Constraints, HasSideEffects, IsAlignStack));
1338 LLVMValueRef LLVMBlockAddress(LLVMValueRef F, LLVMBasicBlockRef BB) {
1339 return wrap(BlockAddress::get(unwrap<Function>(F), unwrap(BB)));
1342 /*--.. Operations on global variables, functions, and aliases (globals) ....--*/
1344 LLVMModuleRef LLVMGetGlobalParent(LLVMValueRef Global) {
1345 return wrap(unwrap<GlobalValue>(Global)->getParent());
1348 LLVMBool LLVMIsDeclaration(LLVMValueRef Global) {
1349 return unwrap<GlobalValue>(Global)->isDeclaration();
1352 LLVMLinkage LLVMGetLinkage(LLVMValueRef Global) {
1353 switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1354 case GlobalValue::ExternalLinkage:
1355 return LLVMExternalLinkage;
1356 case GlobalValue::AvailableExternallyLinkage:
1357 return LLVMAvailableExternallyLinkage;
1358 case GlobalValue::LinkOnceAnyLinkage:
1359 return LLVMLinkOnceAnyLinkage;
1360 case GlobalValue::LinkOnceODRLinkage:
1361 return LLVMLinkOnceODRLinkage;
1362 case GlobalValue::WeakAnyLinkage:
1363 return LLVMWeakAnyLinkage;
1364 case GlobalValue::WeakODRLinkage:
1365 return LLVMWeakODRLinkage;
1366 case GlobalValue::AppendingLinkage:
1367 return LLVMAppendingLinkage;
1368 case GlobalValue::InternalLinkage:
1369 return LLVMInternalLinkage;
1370 case GlobalValue::PrivateLinkage:
1371 return LLVMPrivateLinkage;
1372 case GlobalValue::ExternalWeakLinkage:
1373 return LLVMExternalWeakLinkage;
1374 case GlobalValue::CommonLinkage:
1375 return LLVMCommonLinkage;
1378 llvm_unreachable("Invalid GlobalValue linkage!");
1381 void LLVMSetLinkage(LLVMValueRef Global, LLVMLinkage Linkage) {
1382 GlobalValue *GV = unwrap<GlobalValue>(Global);
1385 case LLVMExternalLinkage:
1386 GV->setLinkage(GlobalValue::ExternalLinkage);
1388 case LLVMAvailableExternallyLinkage:
1389 GV->setLinkage(GlobalValue::AvailableExternallyLinkage);
1391 case LLVMLinkOnceAnyLinkage:
1392 GV->setLinkage(GlobalValue::LinkOnceAnyLinkage);
1394 case LLVMLinkOnceODRLinkage:
1395 GV->setLinkage(GlobalValue::LinkOnceODRLinkage);
1397 case LLVMLinkOnceODRAutoHideLinkage:
1398 DEBUG(errs() << "LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1399 "longer supported.");
1401 case LLVMWeakAnyLinkage:
1402 GV->setLinkage(GlobalValue::WeakAnyLinkage);
1404 case LLVMWeakODRLinkage:
1405 GV->setLinkage(GlobalValue::WeakODRLinkage);
1407 case LLVMAppendingLinkage:
1408 GV->setLinkage(GlobalValue::AppendingLinkage);
1410 case LLVMInternalLinkage:
1411 GV->setLinkage(GlobalValue::InternalLinkage);
1413 case LLVMPrivateLinkage:
1414 GV->setLinkage(GlobalValue::PrivateLinkage);
1416 case LLVMLinkerPrivateLinkage:
1417 GV->setLinkage(GlobalValue::PrivateLinkage);
1419 case LLVMLinkerPrivateWeakLinkage:
1420 GV->setLinkage(GlobalValue::PrivateLinkage);
1422 case LLVMDLLImportLinkage:
1424 << "LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1426 case LLVMDLLExportLinkage:
1428 << "LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1430 case LLVMExternalWeakLinkage:
1431 GV->setLinkage(GlobalValue::ExternalWeakLinkage);
1433 case LLVMGhostLinkage:
1435 << "LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1437 case LLVMCommonLinkage:
1438 GV->setLinkage(GlobalValue::CommonLinkage);
1443 const char *LLVMGetSection(LLVMValueRef Global) {
1444 return unwrap<GlobalValue>(Global)->getSection();
1447 void LLVMSetSection(LLVMValueRef Global, const char *Section) {
1448 unwrap<GlobalObject>(Global)->setSection(Section);
1451 LLVMVisibility LLVMGetVisibility(LLVMValueRef Global) {
1452 return static_cast<LLVMVisibility>(
1453 unwrap<GlobalValue>(Global)->getVisibility());
1456 void LLVMSetVisibility(LLVMValueRef Global, LLVMVisibility Viz) {
1457 unwrap<GlobalValue>(Global)
1458 ->setVisibility(static_cast<GlobalValue::VisibilityTypes>(Viz));
1461 LLVMDLLStorageClass LLVMGetDLLStorageClass(LLVMValueRef Global) {
1462 return static_cast<LLVMDLLStorageClass>(
1463 unwrap<GlobalValue>(Global)->getDLLStorageClass());
1466 void LLVMSetDLLStorageClass(LLVMValueRef Global, LLVMDLLStorageClass Class) {
1467 unwrap<GlobalValue>(Global)->setDLLStorageClass(
1468 static_cast<GlobalValue::DLLStorageClassTypes>(Class));
1471 LLVMBool LLVMHasUnnamedAddr(LLVMValueRef Global) {
1472 return unwrap<GlobalValue>(Global)->hasUnnamedAddr();
1475 void LLVMSetUnnamedAddr(LLVMValueRef Global, LLVMBool HasUnnamedAddr) {
1476 unwrap<GlobalValue>(Global)->setUnnamedAddr(HasUnnamedAddr);
1479 /*--.. Operations on global variables, load and store instructions .........--*/
1481 unsigned LLVMGetAlignment(LLVMValueRef V) {
1482 Value *P = unwrap<Value>(V);
1483 if (GlobalValue *GV = dyn_cast<GlobalValue>(P))
1484 return GV->getAlignment();
1485 if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1486 return AI->getAlignment();
1487 if (LoadInst *LI = dyn_cast<LoadInst>(P))
1488 return LI->getAlignment();
1489 if (StoreInst *SI = dyn_cast<StoreInst>(P))
1490 return SI->getAlignment();
1493 "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1496 void LLVMSetAlignment(LLVMValueRef V, unsigned Bytes) {
1497 Value *P = unwrap<Value>(V);
1498 if (GlobalObject *GV = dyn_cast<GlobalObject>(P))
1499 GV->setAlignment(Bytes);
1500 else if (AllocaInst *AI = dyn_cast<AllocaInst>(P))
1501 AI->setAlignment(Bytes);
1502 else if (LoadInst *LI = dyn_cast<LoadInst>(P))
1503 LI->setAlignment(Bytes);
1504 else if (StoreInst *SI = dyn_cast<StoreInst>(P))
1505 SI->setAlignment(Bytes);
1508 "only GlobalValue, AllocaInst, LoadInst and StoreInst have alignment");
1511 /*--.. Operations on global variables ......................................--*/
1513 LLVMValueRef LLVMAddGlobal(LLVMModuleRef M, LLVMTypeRef Ty, const char *Name) {
1514 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1515 GlobalValue::ExternalLinkage, nullptr, Name));
1518 LLVMValueRef LLVMAddGlobalInAddressSpace(LLVMModuleRef M, LLVMTypeRef Ty,
1520 unsigned AddressSpace) {
1521 return wrap(new GlobalVariable(*unwrap(M), unwrap(Ty), false,
1522 GlobalValue::ExternalLinkage, nullptr, Name,
1523 nullptr, GlobalVariable::NotThreadLocal,
1527 LLVMValueRef LLVMGetNamedGlobal(LLVMModuleRef M, const char *Name) {
1528 return wrap(unwrap(M)->getNamedGlobal(Name));
1531 LLVMValueRef LLVMGetFirstGlobal(LLVMModuleRef M) {
1532 Module *Mod = unwrap(M);
1533 Module::global_iterator I = Mod->global_begin();
1534 if (I == Mod->global_end())
1539 LLVMValueRef LLVMGetLastGlobal(LLVMModuleRef M) {
1540 Module *Mod = unwrap(M);
1541 Module::global_iterator I = Mod->global_end();
1542 if (I == Mod->global_begin())
1547 LLVMValueRef LLVMGetNextGlobal(LLVMValueRef GlobalVar) {
1548 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1549 Module::global_iterator I = GV;
1550 if (++I == GV->getParent()->global_end())
1555 LLVMValueRef LLVMGetPreviousGlobal(LLVMValueRef GlobalVar) {
1556 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1557 Module::global_iterator I = GV;
1558 if (I == GV->getParent()->global_begin())
1563 void LLVMDeleteGlobal(LLVMValueRef GlobalVar) {
1564 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
1567 LLVMValueRef LLVMGetInitializer(LLVMValueRef GlobalVar) {
1568 GlobalVariable* GV = unwrap<GlobalVariable>(GlobalVar);
1569 if ( !GV->hasInitializer() )
1571 return wrap(GV->getInitializer());
1574 void LLVMSetInitializer(LLVMValueRef GlobalVar, LLVMValueRef ConstantVal) {
1575 unwrap<GlobalVariable>(GlobalVar)
1576 ->setInitializer(unwrap<Constant>(ConstantVal));
1579 LLVMBool LLVMIsThreadLocal(LLVMValueRef GlobalVar) {
1580 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
1583 void LLVMSetThreadLocal(LLVMValueRef GlobalVar, LLVMBool IsThreadLocal) {
1584 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
1587 LLVMBool LLVMIsGlobalConstant(LLVMValueRef GlobalVar) {
1588 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
1591 void LLVMSetGlobalConstant(LLVMValueRef GlobalVar, LLVMBool IsConstant) {
1592 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
1595 LLVMThreadLocalMode LLVMGetThreadLocalMode(LLVMValueRef GlobalVar) {
1596 switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
1597 case GlobalVariable::NotThreadLocal:
1598 return LLVMNotThreadLocal;
1599 case GlobalVariable::GeneralDynamicTLSModel:
1600 return LLVMGeneralDynamicTLSModel;
1601 case GlobalVariable::LocalDynamicTLSModel:
1602 return LLVMLocalDynamicTLSModel;
1603 case GlobalVariable::InitialExecTLSModel:
1604 return LLVMInitialExecTLSModel;
1605 case GlobalVariable::LocalExecTLSModel:
1606 return LLVMLocalExecTLSModel;
1609 llvm_unreachable("Invalid GlobalVariable thread local mode");
1612 void LLVMSetThreadLocalMode(LLVMValueRef GlobalVar, LLVMThreadLocalMode Mode) {
1613 GlobalVariable *GV = unwrap<GlobalVariable>(GlobalVar);
1616 case LLVMNotThreadLocal:
1617 GV->setThreadLocalMode(GlobalVariable::NotThreadLocal);
1619 case LLVMGeneralDynamicTLSModel:
1620 GV->setThreadLocalMode(GlobalVariable::GeneralDynamicTLSModel);
1622 case LLVMLocalDynamicTLSModel:
1623 GV->setThreadLocalMode(GlobalVariable::LocalDynamicTLSModel);
1625 case LLVMInitialExecTLSModel:
1626 GV->setThreadLocalMode(GlobalVariable::InitialExecTLSModel);
1628 case LLVMLocalExecTLSModel:
1629 GV->setThreadLocalMode(GlobalVariable::LocalExecTLSModel);
1634 LLVMBool LLVMIsExternallyInitialized(LLVMValueRef GlobalVar) {
1635 return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
1638 void LLVMSetExternallyInitialized(LLVMValueRef GlobalVar, LLVMBool IsExtInit) {
1639 unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
1642 /*--.. Operations on aliases ......................................--*/
1644 LLVMValueRef LLVMAddAlias(LLVMModuleRef M, LLVMTypeRef Ty, LLVMValueRef Aliasee,
1646 auto *PTy = cast<PointerType>(unwrap(Ty));
1647 return wrap(GlobalAlias::create(PTy, GlobalValue::ExternalLinkage, Name,
1648 unwrap<Constant>(Aliasee), unwrap(M)));
1651 /*--.. Operations on functions .............................................--*/
1653 LLVMValueRef LLVMAddFunction(LLVMModuleRef M, const char *Name,
1654 LLVMTypeRef FunctionTy) {
1655 return wrap(Function::Create(unwrap<FunctionType>(FunctionTy),
1656 GlobalValue::ExternalLinkage, Name, unwrap(M)));
1659 LLVMValueRef LLVMGetNamedFunction(LLVMModuleRef M, const char *Name) {
1660 return wrap(unwrap(M)->getFunction(Name));
1663 LLVMValueRef LLVMGetFirstFunction(LLVMModuleRef M) {
1664 Module *Mod = unwrap(M);
1665 Module::iterator I = Mod->begin();
1666 if (I == Mod->end())
1671 LLVMValueRef LLVMGetLastFunction(LLVMModuleRef M) {
1672 Module *Mod = unwrap(M);
1673 Module::iterator I = Mod->end();
1674 if (I == Mod->begin())
1679 LLVMValueRef LLVMGetNextFunction(LLVMValueRef Fn) {
1680 Function *Func = unwrap<Function>(Fn);
1681 Module::iterator I = Func;
1682 if (++I == Func->getParent()->end())
1687 LLVMValueRef LLVMGetPreviousFunction(LLVMValueRef Fn) {
1688 Function *Func = unwrap<Function>(Fn);
1689 Module::iterator I = Func;
1690 if (I == Func->getParent()->begin())
1695 void LLVMDeleteFunction(LLVMValueRef Fn) {
1696 unwrap<Function>(Fn)->eraseFromParent();
1699 LLVMValueRef LLVMGetPersonalityFn(LLVMValueRef Fn) {
1700 return wrap(unwrap<Function>(Fn)->getPersonalityFn());
1703 void LLVMSetPersonalityFn(LLVMValueRef Fn, LLVMValueRef PersonalityFn) {
1704 unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
1707 unsigned LLVMGetIntrinsicID(LLVMValueRef Fn) {
1708 if (Function *F = dyn_cast<Function>(unwrap(Fn)))
1709 return F->getIntrinsicID();
1713 unsigned LLVMGetFunctionCallConv(LLVMValueRef Fn) {
1714 return unwrap<Function>(Fn)->getCallingConv();
1717 void LLVMSetFunctionCallConv(LLVMValueRef Fn, unsigned CC) {
1718 return unwrap<Function>(Fn)->setCallingConv(
1719 static_cast<CallingConv::ID>(CC));
1722 const char *LLVMGetGC(LLVMValueRef Fn) {
1723 Function *F = unwrap<Function>(Fn);
1724 return F->hasGC()? F->getGC() : nullptr;
1727 void LLVMSetGC(LLVMValueRef Fn, const char *GC) {
1728 Function *F = unwrap<Function>(Fn);
1735 void LLVMAddFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1736 Function *Func = unwrap<Function>(Fn);
1737 const AttributeSet PAL = Func->getAttributes();
1739 const AttributeSet PALnew =
1740 PAL.addAttributes(Func->getContext(), AttributeSet::FunctionIndex,
1741 AttributeSet::get(Func->getContext(),
1742 AttributeSet::FunctionIndex, B));
1743 Func->setAttributes(PALnew);
1746 void LLVMAddTargetDependentFunctionAttr(LLVMValueRef Fn, const char *A,
1748 Function *Func = unwrap<Function>(Fn);
1749 AttributeSet::AttrIndex Idx =
1750 AttributeSet::AttrIndex(AttributeSet::FunctionIndex);
1753 B.addAttribute(A, V);
1754 AttributeSet Set = AttributeSet::get(Func->getContext(), Idx, B);
1755 Func->addAttributes(Idx, Set);
1758 void LLVMRemoveFunctionAttr(LLVMValueRef Fn, LLVMAttribute PA) {
1759 Function *Func = unwrap<Function>(Fn);
1760 const AttributeSet PAL = Func->getAttributes();
1762 const AttributeSet PALnew =
1763 PAL.removeAttributes(Func->getContext(), AttributeSet::FunctionIndex,
1764 AttributeSet::get(Func->getContext(),
1765 AttributeSet::FunctionIndex, B));
1766 Func->setAttributes(PALnew);
1769 LLVMAttribute LLVMGetFunctionAttr(LLVMValueRef Fn) {
1770 Function *Func = unwrap<Function>(Fn);
1771 const AttributeSet PAL = Func->getAttributes();
1772 return (LLVMAttribute)PAL.Raw(AttributeSet::FunctionIndex);
1775 /*--.. Operations on parameters ............................................--*/
1777 unsigned LLVMCountParams(LLVMValueRef FnRef) {
1778 // This function is strictly redundant to
1779 // LLVMCountParamTypes(LLVMGetElementType(LLVMTypeOf(FnRef)))
1780 return unwrap<Function>(FnRef)->arg_size();
1783 void LLVMGetParams(LLVMValueRef FnRef, LLVMValueRef *ParamRefs) {
1784 Function *Fn = unwrap<Function>(FnRef);
1785 for (Function::arg_iterator I = Fn->arg_begin(),
1786 E = Fn->arg_end(); I != E; I++)
1787 *ParamRefs++ = wrap(I);
1790 LLVMValueRef LLVMGetParam(LLVMValueRef FnRef, unsigned index) {
1791 Function::arg_iterator AI = unwrap<Function>(FnRef)->arg_begin();
1797 LLVMValueRef LLVMGetParamParent(LLVMValueRef V) {
1798 return wrap(unwrap<Argument>(V)->getParent());
1801 LLVMValueRef LLVMGetFirstParam(LLVMValueRef Fn) {
1802 Function *Func = unwrap<Function>(Fn);
1803 Function::arg_iterator I = Func->arg_begin();
1804 if (I == Func->arg_end())
1809 LLVMValueRef LLVMGetLastParam(LLVMValueRef Fn) {
1810 Function *Func = unwrap<Function>(Fn);
1811 Function::arg_iterator I = Func->arg_end();
1812 if (I == Func->arg_begin())
1817 LLVMValueRef LLVMGetNextParam(LLVMValueRef Arg) {
1818 Argument *A = unwrap<Argument>(Arg);
1819 Function::arg_iterator I = A;
1820 if (++I == A->getParent()->arg_end())
1825 LLVMValueRef LLVMGetPreviousParam(LLVMValueRef Arg) {
1826 Argument *A = unwrap<Argument>(Arg);
1827 Function::arg_iterator I = A;
1828 if (I == A->getParent()->arg_begin())
1833 void LLVMAddAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1834 Argument *A = unwrap<Argument>(Arg);
1836 A->addAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, B));
1839 void LLVMRemoveAttribute(LLVMValueRef Arg, LLVMAttribute PA) {
1840 Argument *A = unwrap<Argument>(Arg);
1842 A->removeAttr(AttributeSet::get(A->getContext(), A->getArgNo() + 1, B));
1845 LLVMAttribute LLVMGetAttribute(LLVMValueRef Arg) {
1846 Argument *A = unwrap<Argument>(Arg);
1847 return (LLVMAttribute)A->getParent()->getAttributes().
1848 Raw(A->getArgNo()+1);
1852 void LLVMSetParamAlignment(LLVMValueRef Arg, unsigned align) {
1853 Argument *A = unwrap<Argument>(Arg);
1855 B.addAlignmentAttr(align);
1856 A->addAttr(AttributeSet::get(A->getContext(),A->getArgNo() + 1, B));
1859 /*--.. Operations on basic blocks ..........................................--*/
1861 LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) {
1862 return wrap(static_cast<Value*>(unwrap(BB)));
1865 LLVMBool LLVMValueIsBasicBlock(LLVMValueRef Val) {
1866 return isa<BasicBlock>(unwrap(Val));
1869 LLVMBasicBlockRef LLVMValueAsBasicBlock(LLVMValueRef Val) {
1870 return wrap(unwrap<BasicBlock>(Val));
1873 LLVMValueRef LLVMGetBasicBlockParent(LLVMBasicBlockRef BB) {
1874 return wrap(unwrap(BB)->getParent());
1877 LLVMValueRef LLVMGetBasicBlockTerminator(LLVMBasicBlockRef BB) {
1878 return wrap(unwrap(BB)->getTerminator());
1881 unsigned LLVMCountBasicBlocks(LLVMValueRef FnRef) {
1882 return unwrap<Function>(FnRef)->size();
1885 void LLVMGetBasicBlocks(LLVMValueRef FnRef, LLVMBasicBlockRef *BasicBlocksRefs){
1886 Function *Fn = unwrap<Function>(FnRef);
1887 for (Function::iterator I = Fn->begin(), E = Fn->end(); I != E; I++)
1888 *BasicBlocksRefs++ = wrap(I);
1891 LLVMBasicBlockRef LLVMGetEntryBasicBlock(LLVMValueRef Fn) {
1892 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
1895 LLVMBasicBlockRef LLVMGetFirstBasicBlock(LLVMValueRef Fn) {
1896 Function *Func = unwrap<Function>(Fn);
1897 Function::iterator I = Func->begin();
1898 if (I == Func->end())
1903 LLVMBasicBlockRef LLVMGetLastBasicBlock(LLVMValueRef Fn) {
1904 Function *Func = unwrap<Function>(Fn);
1905 Function::iterator I = Func->end();
1906 if (I == Func->begin())
1911 LLVMBasicBlockRef LLVMGetNextBasicBlock(LLVMBasicBlockRef BB) {
1912 BasicBlock *Block = unwrap(BB);
1913 Function::iterator I = Block;
1914 if (++I == Block->getParent()->end())
1919 LLVMBasicBlockRef LLVMGetPreviousBasicBlock(LLVMBasicBlockRef BB) {
1920 BasicBlock *Block = unwrap(BB);
1921 Function::iterator I = Block;
1922 if (I == Block->getParent()->begin())
1927 LLVMBasicBlockRef LLVMAppendBasicBlockInContext(LLVMContextRef C,
1930 return wrap(BasicBlock::Create(*unwrap(C), Name, unwrap<Function>(FnRef)));
1933 LLVMBasicBlockRef LLVMAppendBasicBlock(LLVMValueRef FnRef, const char *Name) {
1934 return LLVMAppendBasicBlockInContext(LLVMGetGlobalContext(), FnRef, Name);
1937 LLVMBasicBlockRef LLVMInsertBasicBlockInContext(LLVMContextRef C,
1938 LLVMBasicBlockRef BBRef,
1940 BasicBlock *BB = unwrap(BBRef);
1941 return wrap(BasicBlock::Create(*unwrap(C), Name, BB->getParent(), BB));
1944 LLVMBasicBlockRef LLVMInsertBasicBlock(LLVMBasicBlockRef BBRef,
1946 return LLVMInsertBasicBlockInContext(LLVMGetGlobalContext(), BBRef, Name);
1949 void LLVMDeleteBasicBlock(LLVMBasicBlockRef BBRef) {
1950 unwrap(BBRef)->eraseFromParent();
1953 void LLVMRemoveBasicBlockFromParent(LLVMBasicBlockRef BBRef) {
1954 unwrap(BBRef)->removeFromParent();
1957 void LLVMMoveBasicBlockBefore(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1958 unwrap(BB)->moveBefore(unwrap(MovePos));
1961 void LLVMMoveBasicBlockAfter(LLVMBasicBlockRef BB, LLVMBasicBlockRef MovePos) {
1962 unwrap(BB)->moveAfter(unwrap(MovePos));
1965 /*--.. Operations on instructions ..........................................--*/
1967 LLVMBasicBlockRef LLVMGetInstructionParent(LLVMValueRef Inst) {
1968 return wrap(unwrap<Instruction>(Inst)->getParent());
1971 LLVMValueRef LLVMGetFirstInstruction(LLVMBasicBlockRef BB) {
1972 BasicBlock *Block = unwrap(BB);
1973 BasicBlock::iterator I = Block->begin();
1974 if (I == Block->end())
1979 LLVMValueRef LLVMGetLastInstruction(LLVMBasicBlockRef BB) {
1980 BasicBlock *Block = unwrap(BB);
1981 BasicBlock::iterator I = Block->end();
1982 if (I == Block->begin())
1987 LLVMValueRef LLVMGetNextInstruction(LLVMValueRef Inst) {
1988 Instruction *Instr = unwrap<Instruction>(Inst);
1989 BasicBlock::iterator I = Instr;
1990 if (++I == Instr->getParent()->end())
1995 LLVMValueRef LLVMGetPreviousInstruction(LLVMValueRef Inst) {
1996 Instruction *Instr = unwrap<Instruction>(Inst);
1997 BasicBlock::iterator I = Instr;
1998 if (I == Instr->getParent()->begin())
2003 void LLVMInstructionEraseFromParent(LLVMValueRef Inst) {
2004 unwrap<Instruction>(Inst)->eraseFromParent();
2007 LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) {
2008 if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst)))
2009 return (LLVMIntPredicate)I->getPredicate();
2010 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2011 if (CE->getOpcode() == Instruction::ICmp)
2012 return (LLVMIntPredicate)CE->getPredicate();
2013 return (LLVMIntPredicate)0;
2016 LLVMRealPredicate LLVMGetFCmpPredicate(LLVMValueRef Inst) {
2017 if (FCmpInst *I = dyn_cast<FCmpInst>(unwrap(Inst)))
2018 return (LLVMRealPredicate)I->getPredicate();
2019 if (ConstantExpr *CE = dyn_cast<ConstantExpr>(unwrap(Inst)))
2020 if (CE->getOpcode() == Instruction::FCmp)
2021 return (LLVMRealPredicate)CE->getPredicate();
2022 return (LLVMRealPredicate)0;
2025 LLVMOpcode LLVMGetInstructionOpcode(LLVMValueRef Inst) {
2026 if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2027 return map_to_llvmopcode(C->getOpcode());
2028 return (LLVMOpcode)0;
2031 LLVMValueRef LLVMInstructionClone(LLVMValueRef Inst) {
2032 if (Instruction *C = dyn_cast<Instruction>(unwrap(Inst)))
2033 return wrap(C->clone());
2037 /*--.. Call and invoke instructions ........................................--*/
2039 unsigned LLVMGetInstructionCallConv(LLVMValueRef Instr) {
2040 Value *V = unwrap(Instr);
2041 if (CallInst *CI = dyn_cast<CallInst>(V))
2042 return CI->getCallingConv();
2043 if (InvokeInst *II = dyn_cast<InvokeInst>(V))
2044 return II->getCallingConv();
2045 llvm_unreachable("LLVMGetInstructionCallConv applies only to call and invoke!");
2048 void LLVMSetInstructionCallConv(LLVMValueRef Instr, unsigned CC) {
2049 Value *V = unwrap(Instr);
2050 if (CallInst *CI = dyn_cast<CallInst>(V))
2051 return CI->setCallingConv(static_cast<CallingConv::ID>(CC));
2052 else if (InvokeInst *II = dyn_cast<InvokeInst>(V))
2053 return II->setCallingConv(static_cast<CallingConv::ID>(CC));
2054 llvm_unreachable("LLVMSetInstructionCallConv applies only to call and invoke!");
2057 void LLVMAddInstrAttribute(LLVMValueRef Instr, unsigned index,
2059 CallSite Call = CallSite(unwrap<Instruction>(Instr));
2062 Call.getAttributes().addAttributes(Call->getContext(), index,
2063 AttributeSet::get(Call->getContext(),
2067 void LLVMRemoveInstrAttribute(LLVMValueRef Instr, unsigned index,
2069 CallSite Call = CallSite(unwrap<Instruction>(Instr));
2071 Call.setAttributes(Call.getAttributes()
2072 .removeAttributes(Call->getContext(), index,
2073 AttributeSet::get(Call->getContext(),
2077 void LLVMSetInstrParamAlignment(LLVMValueRef Instr, unsigned index,
2079 CallSite Call = CallSite(unwrap<Instruction>(Instr));
2081 B.addAlignmentAttr(align);
2082 Call.setAttributes(Call.getAttributes()
2083 .addAttributes(Call->getContext(), index,
2084 AttributeSet::get(Call->getContext(),
2088 /*--.. Operations on call instructions (only) ..............................--*/
2090 LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
2091 return unwrap<CallInst>(Call)->isTailCall();
2094 void LLVMSetTailCall(LLVMValueRef Call, LLVMBool isTailCall) {
2095 unwrap<CallInst>(Call)->setTailCall(isTailCall);
2098 /*--.. Operations on terminators ...........................................--*/
2100 unsigned LLVMGetNumSuccessors(LLVMValueRef Term) {
2101 return unwrap<TerminatorInst>(Term)->getNumSuccessors();
2104 LLVMBasicBlockRef LLVMGetSuccessor(LLVMValueRef Term, unsigned i) {
2105 return wrap(unwrap<TerminatorInst>(Term)->getSuccessor(i));
2108 void LLVMSetSuccessor(LLVMValueRef Term, unsigned i, LLVMBasicBlockRef block) {
2109 return unwrap<TerminatorInst>(Term)->setSuccessor(i,unwrap(block));
2112 /*--.. Operations on branch instructions (only) ............................--*/
2114 LLVMBool LLVMIsConditional(LLVMValueRef Branch) {
2115 return unwrap<BranchInst>(Branch)->isConditional();
2118 LLVMValueRef LLVMGetCondition(LLVMValueRef Branch) {
2119 return wrap(unwrap<BranchInst>(Branch)->getCondition());
2122 void LLVMSetCondition(LLVMValueRef Branch, LLVMValueRef Cond) {
2123 return unwrap<BranchInst>(Branch)->setCondition(unwrap(Cond));
2126 /*--.. Operations on switch instructions (only) ............................--*/
2128 LLVMBasicBlockRef LLVMGetSwitchDefaultDest(LLVMValueRef Switch) {
2129 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
2132 /*--.. Operations on phi nodes .............................................--*/
2134 void LLVMAddIncoming(LLVMValueRef PhiNode, LLVMValueRef *IncomingValues,
2135 LLVMBasicBlockRef *IncomingBlocks, unsigned Count) {
2136 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
2137 for (unsigned I = 0; I != Count; ++I)
2138 PhiVal->addIncoming(unwrap(IncomingValues[I]), unwrap(IncomingBlocks[I]));
2141 unsigned LLVMCountIncoming(LLVMValueRef PhiNode) {
2142 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
2145 LLVMValueRef LLVMGetIncomingValue(LLVMValueRef PhiNode, unsigned Index) {
2146 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
2149 LLVMBasicBlockRef LLVMGetIncomingBlock(LLVMValueRef PhiNode, unsigned Index) {
2150 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
2154 /*===-- Instruction builders ----------------------------------------------===*/
2156 LLVMBuilderRef LLVMCreateBuilderInContext(LLVMContextRef C) {
2157 return wrap(new IRBuilder<>(*unwrap(C)));
2160 LLVMBuilderRef LLVMCreateBuilder(void) {
2161 return LLVMCreateBuilderInContext(LLVMGetGlobalContext());
2164 void LLVMPositionBuilder(LLVMBuilderRef Builder, LLVMBasicBlockRef Block,
2165 LLVMValueRef Instr) {
2166 BasicBlock *BB = unwrap(Block);
2167 Instruction *I = Instr? unwrap<Instruction>(Instr) : (Instruction*) BB->end();
2168 unwrap(Builder)->SetInsertPoint(BB, I);
2171 void LLVMPositionBuilderBefore(LLVMBuilderRef Builder, LLVMValueRef Instr) {
2172 Instruction *I = unwrap<Instruction>(Instr);
2173 unwrap(Builder)->SetInsertPoint(I->getParent(), I);
2176 void LLVMPositionBuilderAtEnd(LLVMBuilderRef Builder, LLVMBasicBlockRef Block) {
2177 BasicBlock *BB = unwrap(Block);
2178 unwrap(Builder)->SetInsertPoint(BB);
2181 LLVMBasicBlockRef LLVMGetInsertBlock(LLVMBuilderRef Builder) {
2182 return wrap(unwrap(Builder)->GetInsertBlock());
2185 void LLVMClearInsertionPosition(LLVMBuilderRef Builder) {
2186 unwrap(Builder)->ClearInsertionPoint();
2189 void LLVMInsertIntoBuilder(LLVMBuilderRef Builder, LLVMValueRef Instr) {
2190 unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
2193 void LLVMInsertIntoBuilderWithName(LLVMBuilderRef Builder, LLVMValueRef Instr,
2195 unwrap(Builder)->Insert(unwrap<Instruction>(Instr), Name);
2198 void LLVMDisposeBuilder(LLVMBuilderRef Builder) {
2199 delete unwrap(Builder);
2202 /*--.. Metadata builders ...................................................--*/
2204 void LLVMSetCurrentDebugLocation(LLVMBuilderRef Builder, LLVMValueRef L) {
2206 L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) : nullptr;
2207 unwrap(Builder)->SetCurrentDebugLocation(DebugLoc(Loc));
2210 LLVMValueRef LLVMGetCurrentDebugLocation(LLVMBuilderRef Builder) {
2211 LLVMContext &Context = unwrap(Builder)->getContext();
2212 return wrap(MetadataAsValue::get(
2213 Context, unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()));
2216 void LLVMSetInstDebugLocation(LLVMBuilderRef Builder, LLVMValueRef Inst) {
2217 unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
2221 /*--.. Instruction builders ................................................--*/
2223 LLVMValueRef LLVMBuildRetVoid(LLVMBuilderRef B) {
2224 return wrap(unwrap(B)->CreateRetVoid());
2227 LLVMValueRef LLVMBuildRet(LLVMBuilderRef B, LLVMValueRef V) {
2228 return wrap(unwrap(B)->CreateRet(unwrap(V)));
2231 LLVMValueRef LLVMBuildAggregateRet(LLVMBuilderRef B, LLVMValueRef *RetVals,
2233 return wrap(unwrap(B)->CreateAggregateRet(unwrap(RetVals), N));
2236 LLVMValueRef LLVMBuildBr(LLVMBuilderRef B, LLVMBasicBlockRef Dest) {
2237 return wrap(unwrap(B)->CreateBr(unwrap(Dest)));
2240 LLVMValueRef LLVMBuildCondBr(LLVMBuilderRef B, LLVMValueRef If,
2241 LLVMBasicBlockRef Then, LLVMBasicBlockRef Else) {
2242 return wrap(unwrap(B)->CreateCondBr(unwrap(If), unwrap(Then), unwrap(Else)));
2245 LLVMValueRef LLVMBuildSwitch(LLVMBuilderRef B, LLVMValueRef V,
2246 LLVMBasicBlockRef Else, unsigned NumCases) {
2247 return wrap(unwrap(B)->CreateSwitch(unwrap(V), unwrap(Else), NumCases));
2250 LLVMValueRef LLVMBuildIndirectBr(LLVMBuilderRef B, LLVMValueRef Addr,
2251 unsigned NumDests) {
2252 return wrap(unwrap(B)->CreateIndirectBr(unwrap(Addr), NumDests));
2255 LLVMValueRef LLVMBuildInvoke(LLVMBuilderRef B, LLVMValueRef Fn,
2256 LLVMValueRef *Args, unsigned NumArgs,
2257 LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
2259 return wrap(unwrap(B)->CreateInvoke(unwrap(Fn), unwrap(Then), unwrap(Catch),
2260 makeArrayRef(unwrap(Args), NumArgs),
2264 LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
2265 LLVMValueRef PersFn, unsigned NumClauses,
2267 // The personality used to live on the landingpad instruction, but now it
2268 // lives on the parent function. For compatibility, take the provided
2269 // personality and put it on the parent function.
2271 unwrap(B)->GetInsertBlock()->getParent()->setPersonalityFn(
2272 cast<Function>(unwrap(PersFn)));
2273 return wrap(unwrap(B)->CreateLandingPad(unwrap(Ty), NumClauses, Name));
2276 LLVMValueRef LLVMBuildResume(LLVMBuilderRef B, LLVMValueRef Exn) {
2277 return wrap(unwrap(B)->CreateResume(unwrap(Exn)));
2280 LLVMValueRef LLVMBuildUnreachable(LLVMBuilderRef B) {
2281 return wrap(unwrap(B)->CreateUnreachable());
2284 void LLVMAddCase(LLVMValueRef Switch, LLVMValueRef OnVal,
2285 LLVMBasicBlockRef Dest) {
2286 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal), unwrap(Dest));
2289 void LLVMAddDestination(LLVMValueRef IndirectBr, LLVMBasicBlockRef Dest) {
2290 unwrap<IndirectBrInst>(IndirectBr)->addDestination(unwrap(Dest));
2293 void LLVMAddClause(LLVMValueRef LandingPad, LLVMValueRef ClauseVal) {
2294 unwrap<LandingPadInst>(LandingPad)->
2295 addClause(cast<Constant>(unwrap(ClauseVal)));
2298 void LLVMSetCleanup(LLVMValueRef LandingPad, LLVMBool Val) {
2299 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
2302 /*--.. Arithmetic ..........................................................--*/
2304 LLVMValueRef LLVMBuildAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2306 return wrap(unwrap(B)->CreateAdd(unwrap(LHS), unwrap(RHS), Name));
2309 LLVMValueRef LLVMBuildNSWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2311 return wrap(unwrap(B)->CreateNSWAdd(unwrap(LHS), unwrap(RHS), Name));
2314 LLVMValueRef LLVMBuildNUWAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2316 return wrap(unwrap(B)->CreateNUWAdd(unwrap(LHS), unwrap(RHS), Name));
2319 LLVMValueRef LLVMBuildFAdd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2321 return wrap(unwrap(B)->CreateFAdd(unwrap(LHS), unwrap(RHS), Name));
2324 LLVMValueRef LLVMBuildSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2326 return wrap(unwrap(B)->CreateSub(unwrap(LHS), unwrap(RHS), Name));
2329 LLVMValueRef LLVMBuildNSWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2331 return wrap(unwrap(B)->CreateNSWSub(unwrap(LHS), unwrap(RHS), Name));
2334 LLVMValueRef LLVMBuildNUWSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2336 return wrap(unwrap(B)->CreateNUWSub(unwrap(LHS), unwrap(RHS), Name));
2339 LLVMValueRef LLVMBuildFSub(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2341 return wrap(unwrap(B)->CreateFSub(unwrap(LHS), unwrap(RHS), Name));
2344 LLVMValueRef LLVMBuildMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2346 return wrap(unwrap(B)->CreateMul(unwrap(LHS), unwrap(RHS), Name));
2349 LLVMValueRef LLVMBuildNSWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2351 return wrap(unwrap(B)->CreateNSWMul(unwrap(LHS), unwrap(RHS), Name));
2354 LLVMValueRef LLVMBuildNUWMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2356 return wrap(unwrap(B)->CreateNUWMul(unwrap(LHS), unwrap(RHS), Name));
2359 LLVMValueRef LLVMBuildFMul(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2361 return wrap(unwrap(B)->CreateFMul(unwrap(LHS), unwrap(RHS), Name));
2364 LLVMValueRef LLVMBuildUDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2366 return wrap(unwrap(B)->CreateUDiv(unwrap(LHS), unwrap(RHS), Name));
2369 LLVMValueRef LLVMBuildSDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2371 return wrap(unwrap(B)->CreateSDiv(unwrap(LHS), unwrap(RHS), Name));
2374 LLVMValueRef LLVMBuildExactSDiv(LLVMBuilderRef B, LLVMValueRef LHS,
2375 LLVMValueRef RHS, const char *Name) {
2376 return wrap(unwrap(B)->CreateExactSDiv(unwrap(LHS), unwrap(RHS), Name));
2379 LLVMValueRef LLVMBuildFDiv(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2381 return wrap(unwrap(B)->CreateFDiv(unwrap(LHS), unwrap(RHS), Name));
2384 LLVMValueRef LLVMBuildURem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2386 return wrap(unwrap(B)->CreateURem(unwrap(LHS), unwrap(RHS), Name));
2389 LLVMValueRef LLVMBuildSRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2391 return wrap(unwrap(B)->CreateSRem(unwrap(LHS), unwrap(RHS), Name));
2394 LLVMValueRef LLVMBuildFRem(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2396 return wrap(unwrap(B)->CreateFRem(unwrap(LHS), unwrap(RHS), Name));
2399 LLVMValueRef LLVMBuildShl(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2401 return wrap(unwrap(B)->CreateShl(unwrap(LHS), unwrap(RHS), Name));
2404 LLVMValueRef LLVMBuildLShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2406 return wrap(unwrap(B)->CreateLShr(unwrap(LHS), unwrap(RHS), Name));
2409 LLVMValueRef LLVMBuildAShr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2411 return wrap(unwrap(B)->CreateAShr(unwrap(LHS), unwrap(RHS), Name));
2414 LLVMValueRef LLVMBuildAnd(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2416 return wrap(unwrap(B)->CreateAnd(unwrap(LHS), unwrap(RHS), Name));
2419 LLVMValueRef LLVMBuildOr(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2421 return wrap(unwrap(B)->CreateOr(unwrap(LHS), unwrap(RHS), Name));
2424 LLVMValueRef LLVMBuildXor(LLVMBuilderRef B, LLVMValueRef LHS, LLVMValueRef RHS,
2426 return wrap(unwrap(B)->CreateXor(unwrap(LHS), unwrap(RHS), Name));
2429 LLVMValueRef LLVMBuildBinOp(LLVMBuilderRef B, LLVMOpcode Op,
2430 LLVMValueRef LHS, LLVMValueRef RHS,
2432 return wrap(unwrap(B)->CreateBinOp(Instruction::BinaryOps(map_from_llvmopcode(Op)), unwrap(LHS),
2433 unwrap(RHS), Name));
2436 LLVMValueRef LLVMBuildNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
2437 return wrap(unwrap(B)->CreateNeg(unwrap(V), Name));
2440 LLVMValueRef LLVMBuildNSWNeg(LLVMBuilderRef B, LLVMValueRef V,
2442 return wrap(unwrap(B)->CreateNSWNeg(unwrap(V), Name));
2445 LLVMValueRef LLVMBuildNUWNeg(LLVMBuilderRef B, LLVMValueRef V,
2447 return wrap(unwrap(B)->CreateNUWNeg(unwrap(V), Name));
2450 LLVMValueRef LLVMBuildFNeg(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
2451 return wrap(unwrap(B)->CreateFNeg(unwrap(V), Name));
2454 LLVMValueRef LLVMBuildNot(LLVMBuilderRef B, LLVMValueRef V, const char *Name) {
2455 return wrap(unwrap(B)->CreateNot(unwrap(V), Name));
2458 /*--.. Memory ..............................................................--*/
2460 LLVMValueRef LLVMBuildMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
2462 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2463 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2464 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2465 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2466 ITy, unwrap(Ty), AllocSize,
2467 nullptr, nullptr, "");
2468 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2471 LLVMValueRef LLVMBuildArrayMalloc(LLVMBuilderRef B, LLVMTypeRef Ty,
2472 LLVMValueRef Val, const char *Name) {
2473 Type* ITy = Type::getInt32Ty(unwrap(B)->GetInsertBlock()->getContext());
2474 Constant* AllocSize = ConstantExpr::getSizeOf(unwrap(Ty));
2475 AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
2476 Instruction* Malloc = CallInst::CreateMalloc(unwrap(B)->GetInsertBlock(),
2477 ITy, unwrap(Ty), AllocSize,
2478 unwrap(Val), nullptr, "");
2479 return wrap(unwrap(B)->Insert(Malloc, Twine(Name)));
2482 LLVMValueRef LLVMBuildAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2484 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), nullptr, Name));
2487 LLVMValueRef LLVMBuildArrayAlloca(LLVMBuilderRef B, LLVMTypeRef Ty,
2488 LLVMValueRef Val, const char *Name) {
2489 return wrap(unwrap(B)->CreateAlloca(unwrap(Ty), unwrap(Val), Name));
2492 LLVMValueRef LLVMBuildFree(LLVMBuilderRef B, LLVMValueRef PointerVal) {
2493 return wrap(unwrap(B)->Insert(
2494 CallInst::CreateFree(unwrap(PointerVal), unwrap(B)->GetInsertBlock())));
2497 LLVMValueRef LLVMBuildLoad(LLVMBuilderRef B, LLVMValueRef PointerVal,
2499 return wrap(unwrap(B)->CreateLoad(unwrap(PointerVal), Name));
2502 LLVMValueRef LLVMBuildStore(LLVMBuilderRef B, LLVMValueRef Val,
2503 LLVMValueRef PointerVal) {
2504 return wrap(unwrap(B)->CreateStore(unwrap(Val), unwrap(PointerVal)));
2507 static AtomicOrdering mapFromLLVMOrdering(LLVMAtomicOrdering Ordering) {
2509 case LLVMAtomicOrderingNotAtomic: return NotAtomic;
2510 case LLVMAtomicOrderingUnordered: return Unordered;
2511 case LLVMAtomicOrderingMonotonic: return Monotonic;
2512 case LLVMAtomicOrderingAcquire: return Acquire;
2513 case LLVMAtomicOrderingRelease: return Release;
2514 case LLVMAtomicOrderingAcquireRelease: return AcquireRelease;
2515 case LLVMAtomicOrderingSequentiallyConsistent:
2516 return SequentiallyConsistent;
2519 llvm_unreachable("Invalid LLVMAtomicOrdering value!");
2522 static LLVMAtomicOrdering mapToLLVMOrdering(AtomicOrdering Ordering) {
2524 case NotAtomic: return LLVMAtomicOrderingNotAtomic;
2525 case Unordered: return LLVMAtomicOrderingUnordered;
2526 case Monotonic: return LLVMAtomicOrderingMonotonic;
2527 case Acquire: return LLVMAtomicOrderingAcquire;
2528 case Release: return LLVMAtomicOrderingRelease;
2529 case AcquireRelease: return LLVMAtomicOrderingAcquireRelease;
2530 case SequentiallyConsistent:
2531 return LLVMAtomicOrderingSequentiallyConsistent;
2534 llvm_unreachable("Invalid AtomicOrdering value!");
2537 LLVMValueRef LLVMBuildFence(LLVMBuilderRef B, LLVMAtomicOrdering Ordering,
2538 LLVMBool isSingleThread, const char *Name) {
2540 unwrap(B)->CreateFence(mapFromLLVMOrdering(Ordering),
2541 isSingleThread ? SingleThread : CrossThread,
2545 LLVMValueRef LLVMBuildGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2546 LLVMValueRef *Indices, unsigned NumIndices,
2548 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2549 return wrap(unwrap(B)->CreateGEP(nullptr, unwrap(Pointer), IdxList, Name));
2552 LLVMValueRef LLVMBuildInBoundsGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2553 LLVMValueRef *Indices, unsigned NumIndices,
2555 ArrayRef<Value *> IdxList(unwrap(Indices), NumIndices);
2557 unwrap(B)->CreateInBoundsGEP(nullptr, unwrap(Pointer), IdxList, Name));
2560 LLVMValueRef LLVMBuildStructGEP(LLVMBuilderRef B, LLVMValueRef Pointer,
2561 unsigned Idx, const char *Name) {
2562 return wrap(unwrap(B)->CreateStructGEP(nullptr, unwrap(Pointer), Idx, Name));
2565 LLVMValueRef LLVMBuildGlobalString(LLVMBuilderRef B, const char *Str,
2567 return wrap(unwrap(B)->CreateGlobalString(Str, Name));
2570 LLVMValueRef LLVMBuildGlobalStringPtr(LLVMBuilderRef B, const char *Str,
2572 return wrap(unwrap(B)->CreateGlobalStringPtr(Str, Name));
2575 LLVMBool LLVMGetVolatile(LLVMValueRef MemAccessInst) {
2576 Value *P = unwrap<Value>(MemAccessInst);
2577 if (LoadInst *LI = dyn_cast<LoadInst>(P))
2578 return LI->isVolatile();
2579 return cast<StoreInst>(P)->isVolatile();
2582 void LLVMSetVolatile(LLVMValueRef MemAccessInst, LLVMBool isVolatile) {
2583 Value *P = unwrap<Value>(MemAccessInst);
2584 if (LoadInst *LI = dyn_cast<LoadInst>(P))
2585 return LI->setVolatile(isVolatile);
2586 return cast<StoreInst>(P)->setVolatile(isVolatile);
2589 LLVMAtomicOrdering LLVMGetOrdering(LLVMValueRef MemAccessInst) {
2590 Value *P = unwrap<Value>(MemAccessInst);
2592 if (LoadInst *LI = dyn_cast<LoadInst>(P))
2593 O = LI->getOrdering();
2595 O = cast<StoreInst>(P)->getOrdering();
2596 return mapToLLVMOrdering(O);
2599 void LLVMSetOrdering(LLVMValueRef MemAccessInst, LLVMAtomicOrdering Ordering) {
2600 Value *P = unwrap<Value>(MemAccessInst);
2601 AtomicOrdering O = mapFromLLVMOrdering(Ordering);
2603 if (LoadInst *LI = dyn_cast<LoadInst>(P))
2604 return LI->setOrdering(O);
2605 return cast<StoreInst>(P)->setOrdering(O);
2608 /*--.. Casts ...............................................................--*/
2610 LLVMValueRef LLVMBuildTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2611 LLVMTypeRef DestTy, const char *Name) {
2612 return wrap(unwrap(B)->CreateTrunc(unwrap(Val), unwrap(DestTy), Name));
2615 LLVMValueRef LLVMBuildZExt(LLVMBuilderRef B, LLVMValueRef Val,
2616 LLVMTypeRef DestTy, const char *Name) {
2617 return wrap(unwrap(B)->CreateZExt(unwrap(Val), unwrap(DestTy), Name));
2620 LLVMValueRef LLVMBuildSExt(LLVMBuilderRef B, LLVMValueRef Val,
2621 LLVMTypeRef DestTy, const char *Name) {
2622 return wrap(unwrap(B)->CreateSExt(unwrap(Val), unwrap(DestTy), Name));
2625 LLVMValueRef LLVMBuildFPToUI(LLVMBuilderRef B, LLVMValueRef Val,
2626 LLVMTypeRef DestTy, const char *Name) {
2627 return wrap(unwrap(B)->CreateFPToUI(unwrap(Val), unwrap(DestTy), Name));
2630 LLVMValueRef LLVMBuildFPToSI(LLVMBuilderRef B, LLVMValueRef Val,
2631 LLVMTypeRef DestTy, const char *Name) {
2632 return wrap(unwrap(B)->CreateFPToSI(unwrap(Val), unwrap(DestTy), Name));
2635 LLVMValueRef LLVMBuildUIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2636 LLVMTypeRef DestTy, const char *Name) {
2637 return wrap(unwrap(B)->CreateUIToFP(unwrap(Val), unwrap(DestTy), Name));
2640 LLVMValueRef LLVMBuildSIToFP(LLVMBuilderRef B, LLVMValueRef Val,
2641 LLVMTypeRef DestTy, const char *Name) {
2642 return wrap(unwrap(B)->CreateSIToFP(unwrap(Val), unwrap(DestTy), Name));
2645 LLVMValueRef LLVMBuildFPTrunc(LLVMBuilderRef B, LLVMValueRef Val,
2646 LLVMTypeRef DestTy, const char *Name) {
2647 return wrap(unwrap(B)->CreateFPTrunc(unwrap(Val), unwrap(DestTy), Name));
2650 LLVMValueRef LLVMBuildFPExt(LLVMBuilderRef B, LLVMValueRef Val,
2651 LLVMTypeRef DestTy, const char *Name) {
2652 return wrap(unwrap(B)->CreateFPExt(unwrap(Val), unwrap(DestTy), Name));
2655 LLVMValueRef LLVMBuildPtrToInt(LLVMBuilderRef B, LLVMValueRef Val,
2656 LLVMTypeRef DestTy, const char *Name) {
2657 return wrap(unwrap(B)->CreatePtrToInt(unwrap(Val), unwrap(DestTy), Name));
2660 LLVMValueRef LLVMBuildIntToPtr(LLVMBuilderRef B, LLVMValueRef Val,
2661 LLVMTypeRef DestTy, const char *Name) {
2662 return wrap(unwrap(B)->CreateIntToPtr(unwrap(Val), unwrap(DestTy), Name));
2665 LLVMValueRef LLVMBuildBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2666 LLVMTypeRef DestTy, const char *Name) {
2667 return wrap(unwrap(B)->CreateBitCast(unwrap(Val), unwrap(DestTy), Name));
2670 LLVMValueRef LLVMBuildAddrSpaceCast(LLVMBuilderRef B, LLVMValueRef Val,
2671 LLVMTypeRef DestTy, const char *Name) {
2672 return wrap(unwrap(B)->CreateAddrSpaceCast(unwrap(Val), unwrap(DestTy), Name));
2675 LLVMValueRef LLVMBuildZExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2676 LLVMTypeRef DestTy, const char *Name) {
2677 return wrap(unwrap(B)->CreateZExtOrBitCast(unwrap(Val), unwrap(DestTy),
2681 LLVMValueRef LLVMBuildSExtOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2682 LLVMTypeRef DestTy, const char *Name) {
2683 return wrap(unwrap(B)->CreateSExtOrBitCast(unwrap(Val), unwrap(DestTy),
2687 LLVMValueRef LLVMBuildTruncOrBitCast(LLVMBuilderRef B, LLVMValueRef Val,
2688 LLVMTypeRef DestTy, const char *Name) {
2689 return wrap(unwrap(B)->CreateTruncOrBitCast(unwrap(Val), unwrap(DestTy),
2693 LLVMValueRef LLVMBuildCast(LLVMBuilderRef B, LLVMOpcode Op, LLVMValueRef Val,
2694 LLVMTypeRef DestTy, const char *Name) {
2695 return wrap(unwrap(B)->CreateCast(Instruction::CastOps(map_from_llvmopcode(Op)), unwrap(Val),
2696 unwrap(DestTy), Name));
2699 LLVMValueRef LLVMBuildPointerCast(LLVMBuilderRef B, LLVMValueRef Val,
2700 LLVMTypeRef DestTy, const char *Name) {
2701 return wrap(unwrap(B)->CreatePointerCast(unwrap(Val), unwrap(DestTy), Name));
2704 LLVMValueRef LLVMBuildIntCast(LLVMBuilderRef B, LLVMValueRef Val,
2705 LLVMTypeRef DestTy, const char *Name) {
2706 return wrap(unwrap(B)->CreateIntCast(unwrap(Val), unwrap(DestTy),
2707 /*isSigned*/true, Name));
2710 LLVMValueRef LLVMBuildFPCast(LLVMBuilderRef B, LLVMValueRef Val,
2711 LLVMTypeRef DestTy, const char *Name) {
2712 return wrap(unwrap(B)->CreateFPCast(unwrap(Val), unwrap(DestTy), Name));
2715 /*--.. Comparisons .........................................................--*/
2717 LLVMValueRef LLVMBuildICmp(LLVMBuilderRef B, LLVMIntPredicate Op,
2718 LLVMValueRef LHS, LLVMValueRef RHS,
2720 return wrap(unwrap(B)->CreateICmp(static_cast<ICmpInst::Predicate>(Op),
2721 unwrap(LHS), unwrap(RHS), Name));
2724 LLVMValueRef LLVMBuildFCmp(LLVMBuilderRef B, LLVMRealPredicate Op,
2725 LLVMValueRef LHS, LLVMValueRef RHS,
2727 return wrap(unwrap(B)->CreateFCmp(static_cast<FCmpInst::Predicate>(Op),
2728 unwrap(LHS), unwrap(RHS), Name));
2731 /*--.. Miscellaneous instructions ..........................................--*/
2733 LLVMValueRef LLVMBuildPhi(LLVMBuilderRef B, LLVMTypeRef Ty, const char *Name) {
2734 return wrap(unwrap(B)->CreatePHI(unwrap(Ty), 0, Name));
2737 LLVMValueRef LLVMBuildCall(LLVMBuilderRef B, LLVMValueRef Fn,
2738 LLVMValueRef *Args, unsigned NumArgs,
2740 return wrap(unwrap(B)->CreateCall(unwrap(Fn),
2741 makeArrayRef(unwrap(Args), NumArgs),
2745 LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
2746 LLVMValueRef Then, LLVMValueRef Else,
2748 return wrap(unwrap(B)->CreateSelect(unwrap(If), unwrap(Then), unwrap(Else),
2752 LLVMValueRef LLVMBuildVAArg(LLVMBuilderRef B, LLVMValueRef List,
2753 LLVMTypeRef Ty, const char *Name) {
2754 return wrap(unwrap(B)->CreateVAArg(unwrap(List), unwrap(Ty), Name));
2757 LLVMValueRef LLVMBuildExtractElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2758 LLVMValueRef Index, const char *Name) {
2759 return wrap(unwrap(B)->CreateExtractElement(unwrap(VecVal), unwrap(Index),
2763 LLVMValueRef LLVMBuildInsertElement(LLVMBuilderRef B, LLVMValueRef VecVal,
2764 LLVMValueRef EltVal, LLVMValueRef Index,
2766 return wrap(unwrap(B)->CreateInsertElement(unwrap(VecVal), unwrap(EltVal),
2767 unwrap(Index), Name));
2770 LLVMValueRef LLVMBuildShuffleVector(LLVMBuilderRef B, LLVMValueRef V1,
2771 LLVMValueRef V2, LLVMValueRef Mask,
2773 return wrap(unwrap(B)->CreateShuffleVector(unwrap(V1), unwrap(V2),
2774 unwrap(Mask), Name));
2777 LLVMValueRef LLVMBuildExtractValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2778 unsigned Index, const char *Name) {
2779 return wrap(unwrap(B)->CreateExtractValue(unwrap(AggVal), Index, Name));
2782 LLVMValueRef LLVMBuildInsertValue(LLVMBuilderRef B, LLVMValueRef AggVal,
2783 LLVMValueRef EltVal, unsigned Index,
2785 return wrap(unwrap(B)->CreateInsertValue(unwrap(AggVal), unwrap(EltVal),
2789 LLVMValueRef LLVMBuildIsNull(LLVMBuilderRef B, LLVMValueRef Val,
2791 return wrap(unwrap(B)->CreateIsNull(unwrap(Val), Name));
2794 LLVMValueRef LLVMBuildIsNotNull(LLVMBuilderRef B, LLVMValueRef Val,
2796 return wrap(unwrap(B)->CreateIsNotNull(unwrap(Val), Name));
2799 LLVMValueRef LLVMBuildPtrDiff(LLVMBuilderRef B, LLVMValueRef LHS,
2800 LLVMValueRef RHS, const char *Name) {
2801 return wrap(unwrap(B)->CreatePtrDiff(unwrap(LHS), unwrap(RHS), Name));
2804 LLVMValueRef LLVMBuildAtomicRMW(LLVMBuilderRef B,LLVMAtomicRMWBinOp op,
2805 LLVMValueRef PTR, LLVMValueRef Val,
2806 LLVMAtomicOrdering ordering,
2807 LLVMBool singleThread) {
2808 AtomicRMWInst::BinOp intop;
2810 case LLVMAtomicRMWBinOpXchg: intop = AtomicRMWInst::Xchg; break;
2811 case LLVMAtomicRMWBinOpAdd: intop = AtomicRMWInst::Add; break;
2812 case LLVMAtomicRMWBinOpSub: intop = AtomicRMWInst::Sub; break;
2813 case LLVMAtomicRMWBinOpAnd: intop = AtomicRMWInst::And; break;
2814 case LLVMAtomicRMWBinOpNand: intop = AtomicRMWInst::Nand; break;
2815 case LLVMAtomicRMWBinOpOr: intop = AtomicRMWInst::Or; break;
2816 case LLVMAtomicRMWBinOpXor: intop = AtomicRMWInst::Xor; break;
2817 case LLVMAtomicRMWBinOpMax: intop = AtomicRMWInst::Max; break;
2818 case LLVMAtomicRMWBinOpMin: intop = AtomicRMWInst::Min; break;
2819 case LLVMAtomicRMWBinOpUMax: intop = AtomicRMWInst::UMax; break;
2820 case LLVMAtomicRMWBinOpUMin: intop = AtomicRMWInst::UMin; break;
2822 return wrap(unwrap(B)->CreateAtomicRMW(intop, unwrap(PTR), unwrap(Val),
2823 mapFromLLVMOrdering(ordering), singleThread ? SingleThread : CrossThread));
2827 /*===-- Module providers --------------------------------------------------===*/
2829 LLVMModuleProviderRef
2830 LLVMCreateModuleProviderForExistingModule(LLVMModuleRef M) {
2831 return reinterpret_cast<LLVMModuleProviderRef>(M);
2834 void LLVMDisposeModuleProvider(LLVMModuleProviderRef MP) {
2839 /*===-- Memory buffers ----------------------------------------------------===*/
2841 LLVMBool LLVMCreateMemoryBufferWithContentsOfFile(
2843 LLVMMemoryBufferRef *OutMemBuf,
2844 char **OutMessage) {
2846 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getFile(Path);
2847 if (std::error_code EC = MBOrErr.getError()) {
2848 *OutMessage = strdup(EC.message().c_str());
2851 *OutMemBuf = wrap(MBOrErr.get().release());
2855 LLVMBool LLVMCreateMemoryBufferWithSTDIN(LLVMMemoryBufferRef *OutMemBuf,
2856 char **OutMessage) {
2857 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr = MemoryBuffer::getSTDIN();
2858 if (std::error_code EC = MBOrErr.getError()) {
2859 *OutMessage = strdup(EC.message().c_str());
2862 *OutMemBuf = wrap(MBOrErr.get().release());
2866 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRange(
2867 const char *InputData,
2868 size_t InputDataLength,
2869 const char *BufferName,
2870 LLVMBool RequiresNullTerminator) {
2872 return wrap(MemoryBuffer::getMemBuffer(StringRef(InputData, InputDataLength),
2873 StringRef(BufferName),
2874 RequiresNullTerminator).release());
2877 LLVMMemoryBufferRef LLVMCreateMemoryBufferWithMemoryRangeCopy(
2878 const char *InputData,
2879 size_t InputDataLength,
2880 const char *BufferName) {
2883 MemoryBuffer::getMemBufferCopy(StringRef(InputData, InputDataLength),
2884 StringRef(BufferName)).release());
2887 const char *LLVMGetBufferStart(LLVMMemoryBufferRef MemBuf) {
2888 return unwrap(MemBuf)->getBufferStart();
2891 size_t LLVMGetBufferSize(LLVMMemoryBufferRef MemBuf) {
2892 return unwrap(MemBuf)->getBufferSize();
2895 void LLVMDisposeMemoryBuffer(LLVMMemoryBufferRef MemBuf) {
2896 delete unwrap(MemBuf);
2899 /*===-- Pass Registry -----------------------------------------------------===*/
2901 LLVMPassRegistryRef LLVMGetGlobalPassRegistry(void) {
2902 return wrap(PassRegistry::getPassRegistry());
2905 /*===-- Pass Manager ------------------------------------------------------===*/
2907 LLVMPassManagerRef LLVMCreatePassManager() {
2908 return wrap(new legacy::PassManager());
2911 LLVMPassManagerRef LLVMCreateFunctionPassManagerForModule(LLVMModuleRef M) {
2912 return wrap(new legacy::FunctionPassManager(unwrap(M)));
2915 LLVMPassManagerRef LLVMCreateFunctionPassManager(LLVMModuleProviderRef P) {
2916 return LLVMCreateFunctionPassManagerForModule(
2917 reinterpret_cast<LLVMModuleRef>(P));
2920 LLVMBool LLVMRunPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
2921 return unwrap<legacy::PassManager>(PM)->run(*unwrap(M));
2924 LLVMBool LLVMInitializeFunctionPassManager(LLVMPassManagerRef FPM) {
2925 return unwrap<legacy::FunctionPassManager>(FPM)->doInitialization();
2928 LLVMBool LLVMRunFunctionPassManager(LLVMPassManagerRef FPM, LLVMValueRef F) {
2929 return unwrap<legacy::FunctionPassManager>(FPM)->run(*unwrap<Function>(F));
2932 LLVMBool LLVMFinalizeFunctionPassManager(LLVMPassManagerRef FPM) {
2933 return unwrap<legacy::FunctionPassManager>(FPM)->doFinalization();
2936 void LLVMDisposePassManager(LLVMPassManagerRef PM) {
2940 /*===-- Threading ------------------------------------------------------===*/
2942 LLVMBool LLVMStartMultithreaded() {
2943 return LLVMIsMultithreaded();
2946 void LLVMStopMultithreaded() {
2949 LLVMBool LLVMIsMultithreaded() {
2950 return llvm_is_multithreaded();