42#include <system_error>
46#define DEBUG_TYPE "ir"
64 *Major = LLVM_VERSION_MAJOR;
66 *Minor = LLVM_VERSION_MINOR;
68 *Patch = LLVM_VERSION_PATCH;
74 return strdup(Message);
97 void *DiagnosticContext) {
98 unwrap(
C)->setDiagnosticHandlerCallBack(
106 unwrap(
C)->getDiagnosticHandlerCallBack());
110 return unwrap(
C)->getDiagnosticContext();
114 void *OpaqueHandle) {
117 unwrap(
C)->setYieldCallback(YieldCallback, OpaqueHandle);
121 return unwrap(
C)->shouldDiscardValueNames();
125 unwrap(
C)->setDiscardValueNames(Discard);
146 return Attribute::AttrKind::EndAttrKinds;
162 if (Attr.isEnumAttribute())
164 return Attr.getValueAsInt();
176 return wrap(Attr.getValueAsType());
180 const char *K,
unsigned KLength,
181 const char *V,
unsigned VLength) {
202 return Attr.isEnumAttribute() || Attr.isIntAttribute();
214 std::string MsgStorage;
227 switch(
unwrap(DI)->getSeverity()) {
261 auto &Str =
unwrap(M)->getModuleIdentifier();
271 auto &Str =
unwrap(M)->getSourceFileName();
282 return unwrap(M)->getDataLayoutStr().c_str();
290 unwrap(M)->setDataLayout(DataLayoutStr);
295 return unwrap(M)->getTargetTriple().c_str();
314 return Module::ModFlagBehavior::Error;
316 return Module::ModFlagBehavior::Warning;
318 return Module::ModFlagBehavior::Require;
320 return Module::ModFlagBehavior::Override;
322 return Module::ModFlagBehavior::Append;
324 return Module::ModFlagBehavior::AppendUnique;
332 case Module::ModFlagBehavior::Error:
334 case Module::ModFlagBehavior::Warning:
336 case Module::ModFlagBehavior::Require:
338 case Module::ModFlagBehavior::Override:
340 case Module::ModFlagBehavior::Append:
342 case Module::ModFlagBehavior::AppendUnique:
351 unwrap(M)->getModuleFlagsMetadata(MFEs);
355 for (
unsigned i = 0; i < MFEs.
size(); ++i) {
356 const auto &ModuleFlag = MFEs[i];
358 Result[i].Key = ModuleFlag.Key->getString().data();
359 Result[i].KeyLen = ModuleFlag.Key->getString().size();
360 Result[i].Metadata =
wrap(ModuleFlag.Val);
379 unsigned Index,
size_t *Len) {
394 const char *Key,
size_t KeyLen) {
395 return wrap(
unwrap(M)->getModuleFlag({Key, KeyLen}));
399 const char *Key,
size_t KeyLen,
402 {Key, KeyLen},
unwrap(Val));
413 char **ErrorMessage) {
417 *ErrorMessage = strdup(EC.message().c_str());
421 unwrap(M)->print(dest,
nullptr);
426 std::string
E =
"Error printing to file: " + dest.
error().message();
427 *ErrorMessage = strdup(
E.c_str());
438 unwrap(M)->print(os,
nullptr);
441 return strdup(buf.c_str());
458 auto &Str =
unwrap(M)->getModuleInlineAsm();
464 size_t AsmStringSize,
const char *Constraints,
465 size_t ConstraintsSize,
LLVMBool HasSideEffects,
480 HasSideEffects, IsAlignStack, AD, CanThrow));
485 Value *Val = unwrap<Value>(InlineAsmVal);
486 const std::string &AsmString = cast<InlineAsm>(Val)->getAsmString();
488 *Len = AsmString.length();
489 return AsmString.c_str();
494 Value *Val = unwrap<Value>(InlineAsmVal);
495 const std::string &ConstraintString =
496 cast<InlineAsm>(Val)->getConstraintString();
498 *Len = ConstraintString.length();
499 return ConstraintString.c_str();
504 Value *Val = unwrap<Value>(InlineAsmVal);
519 Value *Val = unwrap<Value>(InlineAsmVal);
520 return (
LLVMTypeRef)cast<InlineAsm>(Val)->getFunctionType();
524 Value *Val = unwrap<Value>(InlineAsmVal);
525 return cast<InlineAsm>(Val)->hasSideEffects();
529 Value *Val = unwrap<Value>(InlineAsmVal);
530 return cast<InlineAsm>(Val)->isAlignStack();
534 Value *Val = unwrap<Value>(InlineAsmVal);
535 return cast<InlineAsm>(Val)->canThrow();
600 return unwrap(Ty)->isSized();
618 os <<
"Printing <null> Type";
622 return strdup(buf.c_str());
672 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
739 return wrap(FunctionType::get(
unwrap(ReturnType), Tys, IsVarArg != 0));
743 return unwrap<FunctionType>(FunctionTy)->isVarArg();
747 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
751 return unwrap<FunctionType>(FunctionTy)->getNumParams();
756 for (
Type *
T : Ty->params())
782 if (!
Type->hasName())
784 return Type->getName().data();
790 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
794 return unwrap<StructType>(StructTy)->getNumElements();
798 StructType *Ty = unwrap<StructType>(StructTy);
804 StructType *Ty = unwrap<StructType>(StructTy);
809 return unwrap<StructType>(StructTy)->isPacked();
813 return unwrap<StructType>(StructTy)->isOpaque();
817 return unwrap<StructType>(StructTy)->isLiteral();
832 for (
auto *
T :
unwrap(Tp)->subtypes()) {
864 auto *Ty =
unwrap(WrappedTy);
865 if (
auto *ATy = dyn_cast<ArrayType>(Ty))
866 return wrap(ATy->getElementType());
867 return wrap(cast<VectorType>(Ty)->getElementType());
871 return unwrap(Tp)->getNumContainedTypes();
875 return unwrap<ArrayType>(ArrayTy)->getNumElements();
879 return unwrap<ArrayType>(ArrayTy)->getNumElements();
883 return unwrap<PointerType>(
PointerTy)->getAddressSpace();
887 return unwrap<VectorType>(VectorTy)->getElementCount().getKnownMinValue();
918 unsigned TypeParamCount,
920 unsigned IntParamCount) {
936 switch(
unwrap(Val)->getValueID()) {
938#define HANDLE_VALUE(Name) \
939 case Value::Name##Val: \
940 return LLVM##Name##ValueKind;
941#include "llvm/IR/Value.def"
949 *
Length = V->getName().size();
950 return V->getName().data();
958 return unwrap(Val)->getName().data();
976 os <<
"Printing <null> Value";
980 return strdup(buf.c_str());
988 return unwrap<Instruction>(Inst)->hasMetadata();
992 auto *
I = unwrap<Instruction>(Inst);
993 assert(
I &&
"Expected instruction");
994 if (
auto *MD =
I->getMetadata(KindID))
1004 assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
1005 "Expected a metadata node or a canonicalized constant");
1007 if (
MDNode *
N = dyn_cast<MDNode>(MD))
1016 unwrap<Instruction>(Inst)->setMetadata(KindID,
N);
1034 for (
unsigned i = 0; i < MVEs.
size(); ++i) {
1035 const auto &ModuleFlag = MVEs[i];
1036 Result[i].Kind = ModuleFlag.first;
1037 Result[i].Metadata =
wrap(ModuleFlag.second);
1039 *NumEntries = MVEs.
size();
1045 size_t *NumEntries) {
1048 unwrap<Instruction>(
Value)->getAllMetadata(Entries);
1054#define LLVM_DEFINE_VALUE_CAST(name) \
1055 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
1056 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
1062 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1063 if (isa<MDNode>(MD->getMetadata()) ||
1064 isa<ValueAsMetadata>(MD->getMetadata()))
1070 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1071 if (isa<ValueAsMetadata>(MD->getMetadata()))
1077 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1078 if (isa<MDString>(MD->getMetadata()))
1087 if (
I == V->use_end())
1114 if (
auto *
C = dyn_cast<ConstantAsMetadata>(
Op))
1115 return wrap(
C->getValue());
1121 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
1122 if (
auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1123 assert(
Index == 0 &&
"Function-local metadata can only have one operand");
1124 return wrap(L->getValue());
1127 cast<MDNode>(MD->getMetadata()),
Index);
1130 return wrap(cast<User>(V)->getOperand(
Index));
1135 return wrap(&cast<User>(V)->getOperandUse(
Index));
1144 if (isa<MetadataAsValue>(V))
1147 return cast<User>(V)->getNumOperands();
1169 return isa<Constant>(
unwrap(Ty));
1174 return C->isNullValue();
1179 return isa<UndefValue>(
unwrap(Val));
1183 return isa<PoisonValue>(
unwrap(Val));
1217 for (
auto *OV :
ArrayRef(Vals, Count)) {
1222 else if (
auto *
C = dyn_cast<Constant>(V))
1224 else if (
auto *MDV = dyn_cast<MetadataAsValue>(V)) {
1225 MD = MDV->getMetadata();
1226 assert(!isa<LocalAsMetadata>(MD) &&
"Unexpected function-local metadata "
1227 "outside of direct argument to call");
1231 "Expected only one operand to function-local metadata");
1250 if (
auto *
C = dyn_cast<Constant>(V))
1252 if (
auto *MAV = dyn_cast<MetadataAsValue>(V))
1253 return wrap(MAV->getMetadata());
1258 if (
const auto *MD = dyn_cast<MetadataAsValue>(
unwrap(V)))
1259 if (
const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
1260 *
Length = S->getString().size();
1261 return S->getString().data();
1268 auto *MD = unwrap<MetadataAsValue>(V);
1269 if (isa<ValueAsMetadata>(MD->getMetadata()))
1271 return cast<MDNode>(MD->getMetadata())->getNumOperands();
1307 const char *
Name,
size_t NameLen) {
1312 const char *
Name,
size_t NameLen) {
1313 return wrap(
unwrap(M)->getOrInsertNamedMetadata({
Name, NameLen}));
1323 auto *MD = unwrap<MetadataAsValue>(V);
1324 if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1325 *Dest =
wrap(MDV->getValue());
1328 const auto *
N = cast<MDNode>(MD->getMetadata());
1329 const unsigned numOperands =
N->getNumOperands();
1331 for (
unsigned i = 0; i < numOperands; i++)
1337 auto *MD = cast<MetadataAsValue>(
unwrap(V));
1338 auto *
N = cast<MDNode>(MD->getMetadata());
1339 N->replaceOperandWith(
Index, unwrap<Metadata>(Replacement));
1344 return N->getNumOperands();
1355 for (
unsigned i=0;i<
N->getNumOperands();i++)
1370 if (!
Length)
return nullptr;
1372 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1373 if (
const auto &
DL =
I->getDebugLoc()) {
1374 S =
DL->getDirectory();
1376 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1378 GV->getDebugInfo(GVEs);
1381 S = DGV->getDirectory();
1382 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1384 S = DSP->getDirectory();
1386 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1394 if (!
Length)
return nullptr;
1396 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1397 if (
const auto &
DL =
I->getDebugLoc()) {
1398 S =
DL->getFilename();
1400 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1402 GV->getDebugInfo(GVEs);
1405 S = DGV->getFilename();
1406 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1408 S = DSP->getFilename();
1410 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1419 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1420 if (
const auto &
DL =
I->getDebugLoc()) {
1423 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1425 GV->getDebugInfo(GVEs);
1429 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1433 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1441 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val)))
1442 if (
const auto &
DL =
I->getDebugLoc())
1443 C =
DL->getColumn();
1469 unsigned SLen, uint8_t Radix) {
1488 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
1492 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
1496 ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
1507 APF.
convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &APFLosesInfo);
1508 *LosesInfo = APFLosesInfo;
1520 DontNullTerminate == 0));
1530 return wrap(unwrap<Constant>(
C)->getAggregateElement(
Idx));
1534 return wrap(unwrap<ConstantDataSequential>(
C)->getElementAsConstant(idx));
1538 return unwrap<ConstantDataSequential>(
C)->isString();
1542 StringRef Str = unwrap<ConstantDataSequential>(
C)->getAsString();
1562 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1576 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1577 StructType *Ty = unwrap<StructType>(StructTy);
1593#define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1594#include "llvm/IR/Instruction.def"
1602#define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1603#include "llvm/IR/Instruction.def"
1642 unwrap<Constant>(RHSConstant)));
1648 unwrap<Constant>(RHSConstant)));
1654 unwrap<Constant>(RHSConstant)));
1659 unwrap<Constant>(RHSConstant)));
1665 unwrap<Constant>(RHSConstant)));
1671 unwrap<Constant>(RHSConstant)));
1676 unwrap<Constant>(RHSConstant)));
1682 unwrap<Constant>(RHSConstant)));
1688 unwrap<Constant>(RHSConstant)));
1693 unwrap<Constant>(RHSConstant)));
1699 unwrap<Constant>(LHSConstant),
1700 unwrap<Constant>(RHSConstant)));
1706 unwrap<Constant>(LHSConstant),
1707 unwrap<Constant>(RHSConstant)));
1712 unwrap<Constant>(RHSConstant)));
1719 Constant *Val = unwrap<Constant>(ConstantVal);
1725 unsigned NumIndices) {
1728 Constant *Val = unwrap<Constant>(ConstantVal);
1773 unwrap<Constant>(IndexConstant)));
1780 unwrap<Constant>(ElementValueConstant),
1781 unwrap<Constant>(IndexConstant)));
1790 unwrap<Constant>(VectorBConstant),
1795 const char *Constraints,
1799 Constraints, HasSideEffects, IsAlignStack));
1813 return unwrap<GlobalValue>(
Global)->isDeclaration();
1817 switch (unwrap<GlobalValue>(
Global)->getLinkage()) {
1863 errs() <<
"LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1864 "longer supported.");
1890 <<
"LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1895 <<
"LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1902 errs() <<
"LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1913 return unwrap<GlobalValue>(
Global)->getSection().data();
1917 unwrap<GlobalObject>(
Global)->setSection(Section);
1922 unwrap<GlobalValue>(
Global)->getVisibility());
1926 unwrap<GlobalValue>(
Global)
1932 unwrap<GlobalValue>(
Global)->getDLLStorageClass());
1936 unwrap<GlobalValue>(
Global)->setDLLStorageClass(
1941 switch (unwrap<GlobalValue>(
Global)->getUnnamedAddr()) {
1942 case GlobalVariable::UnnamedAddr::None:
1944 case GlobalVariable::UnnamedAddr::Local:
1946 case GlobalVariable::UnnamedAddr::Global:
1955 switch (UnnamedAddr) {
1966 return unwrap<GlobalValue>(
Global)->hasGlobalUnnamedAddr();
1970 unwrap<GlobalValue>(
Global)->setUnnamedAddr(
1971 HasUnnamedAddr ? GlobalValue::UnnamedAddr::Global
1972 : GlobalValue::UnnamedAddr::None);
1976 return wrap(unwrap<GlobalValue>(
Global)->getValueType());
1984 return GV->getAlign() ? GV->getAlign()->value() : 0;
1986 return AI->getAlign().value();
1987 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
1988 return LI->getAlign().value();
1990 return SI->getAlign().value();
1992 return RMWI->getAlign().value();
1994 return CXI->getAlign().value();
1997 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, "
1998 "and AtomicCmpXchgInst have alignment");
2005 else if (
AllocaInst *AI = dyn_cast<AllocaInst>(
P))
2006 AI->setAlignment(
Align(Bytes));
2007 else if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2008 LI->setAlignment(
Align(Bytes));
2009 else if (
StoreInst *SI = dyn_cast<StoreInst>(
P))
2010 SI->setAlignment(
Align(Bytes));
2012 RMWI->setAlignment(
Align(Bytes));
2014 CXI->setAlignment(
Align(Bytes));
2017 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, and "
2018 "and AtomicCmpXchgInst have alignment");
2022 size_t *NumEntries) {
2026 Instr->getAllMetadata(Entries);
2028 unwrap<GlobalObject>(
Value)->getAllMetadata(Entries);
2054 unwrap<GlobalObject>(
Global)->setMetadata(Kind, unwrap<MDNode>(MD));
2058 unwrap<GlobalObject>(
Global)->eraseMetadata(Kind);
2062 unwrap<GlobalObject>(
Global)->clearMetadata();
2077 nullptr, GlobalVariable::NotThreadLocal,
2118 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
2129 unwrap<GlobalVariable>(GlobalVar)
2130 ->setInitializer(unwrap<Constant>(ConstantVal));
2134 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
2138 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
2142 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
2146 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
2150 switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
2151 case GlobalVariable::NotThreadLocal:
2153 case GlobalVariable::GeneralDynamicTLSModel:
2155 case GlobalVariable::LocalDynamicTLSModel:
2157 case GlobalVariable::InitialExecTLSModel:
2159 case GlobalVariable::LocalExecTLSModel:
2189 return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
2193 unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
2203 unwrap<Constant>(Aliasee),
unwrap(M)));
2207 const char *
Name,
size_t NameLen) {
2244 return wrap(unwrap<GlobalAlias>(Alias)->getAliasee());
2248 unwrap<GlobalAlias>(Alias)->setAliasee(unwrap<Constant>(Aliasee));
2280 Function *Func = unwrap<Function>(Fn);
2282 if (++
I == Func->getParent()->end())
2288 Function *Func = unwrap<Function>(Fn);
2290 if (
I == Func->getParent()->begin())
2296 unwrap<Function>(Fn)->eraseFromParent();
2300 return unwrap<Function>(Fn)->hasPersonalityFn();
2304 return wrap(unwrap<Function>(Fn)->getPersonalityFn());
2308 unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
2313 return F->getIntrinsicID();
2318 assert(
ID < llvm::Intrinsic::num_intrinsics &&
"Intrinsic ID out of range");
2325 size_t ParamCount) {
2334 *NameLength = Str.size();
2348 size_t *NameLength) {
2352 *NameLength = Str.length();
2353 return strdup(Str.c_str());
2359 size_t *NameLength) {
2363 *NameLength = Str.length();
2364 return strdup(Str.c_str());
2377 return unwrap<Function>(Fn)->getCallingConv();
2381 return unwrap<Function>(Fn)->setCallingConv(
2387 return F->hasGC()?
F->getGC().c_str() :
nullptr;
2400 unwrap<Function>(
F)->addAttributeAtIndex(
Idx,
unwrap(
A));
2404 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(
Idx);
2405 return AS.getNumAttributes();
2410 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(
Idx);
2418 return wrap(unwrap<Function>(
F)->getAttributeAtIndex(
2424 const char *K,
unsigned KLen) {
2426 unwrap<Function>(
F)->getAttributeAtIndex(
Idx,
StringRef(K, KLen)));
2435 const char *K,
unsigned KLen) {
2436 unwrap<Function>(
F)->removeAttributeAtIndex(
Idx,
StringRef(K, KLen));
2441 Function *Func = unwrap<Function>(Fn);
2443 Func->addFnAttr(Attr);
2451 return unwrap<Function>(FnRef)->arg_size();
2455 Function *Fn = unwrap<Function>(FnRef);
2457 *ParamRefs++ =
wrap(&
A);
2461 Function *Fn = unwrap<Function>(FnRef);
2470 Function *Func = unwrap<Function>(Fn);
2472 if (
I == Func->arg_end())
2478 Function *Func = unwrap<Function>(Fn);
2480 if (
I == Func->arg_begin())
2488 if (
A->getArgNo() + 1 >= Fn->
arg_size())
2495 if (
A->getArgNo() == 0)
2497 return wrap(&
A->getParent()->arg_begin()[
A->getArgNo() - 1]);
2508 const char *
Name,
size_t NameLen,
2518 const char *
Name,
size_t NameLen) {
2555 return wrap(unwrap<GlobalIFunc>(IFunc)->getResolver());
2559 unwrap<GlobalIFunc>(IFunc)->setResolver(unwrap<Constant>(
Resolver));
2563 unwrap<GlobalIFunc>(IFunc)->eraseFromParent();
2567 unwrap<GlobalIFunc>(IFunc)->removeFromParent();
2577 return isa<BasicBlock>(
unwrap(Val));
2581 return wrap(unwrap<BasicBlock>(Val));
2585 return unwrap(BB)->getName().data();
2597 return unwrap<Function>(FnRef)->size();
2601 Function *Fn = unwrap<Function>(FnRef);
2603 *BasicBlocksRefs++ =
wrap(&BB);
2607 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
2611 Function *Func = unwrap<Function>(Fn);
2613 if (
I == Func->end())
2619 Function *Func = unwrap<Function>(Fn);
2621 if (
I == Func->begin())
2629 if (++
I ==
Block->getParent()->end())
2637 if (
I ==
Block->getParent()->begin())
2651 assert(CurBB &&
"current insertion point is invalid!");
2657 unwrap<Function>(Fn)->insert(unwrap<Function>(Fn)->end(),
unwrap(BB));
2683 unwrap(BBRef)->eraseFromParent();
2687 unwrap(BBRef)->removeFromParent();
2723 if (++
I == Instr->getParent()->end())
2731 if (
I == Instr->getParent()->begin())
2737 unwrap<Instruction>(Inst)->removeFromParent();
2741 unwrap<Instruction>(Inst)->eraseFromParent();
2745 unwrap<Instruction>(Inst)->deleteValue();
2752 if (CE->getOpcode() == Instruction::ICmp)
2761 if (CE->getOpcode() == Instruction::FCmp)
2774 return wrap(
C->clone());
2780 return (
I &&
I->isTerminator()) ?
wrap(
I) :
nullptr;
2785 return FPI->arg_size();
2787 return unwrap<CallBase>(Instr)->arg_size();
2793 return unwrap<CallBase>(Instr)->getCallingConv();
2797 return unwrap<CallBase>(Instr)->setCallingConv(
2803 auto *Call = unwrap<CallBase>(Instr);
2806 Call->addAttributeAtIndex(
Idx, AlignAttr);
2811 unwrap<CallBase>(
C)->addAttributeAtIndex(
Idx,
unwrap(
A));
2816 auto *Call = unwrap<CallBase>(
C);
2817 auto AS = Call->getAttributes().getAttributes(
Idx);
2818 return AS.getNumAttributes();
2823 auto *Call = unwrap<CallBase>(
C);
2824 auto AS = Call->getAttributes().getAttributes(
Idx);
2832 return wrap(unwrap<CallBase>(
C)->getAttributeAtIndex(
2838 const char *K,
unsigned KLen) {
2840 unwrap<CallBase>(
C)->getAttributeAtIndex(
Idx,
StringRef(K, KLen)));
2849 const char *K,
unsigned KLen) {
2850 unwrap<CallBase>(
C)->removeAttributeAtIndex(
Idx,
StringRef(K, KLen));
2854 return wrap(unwrap<CallBase>(Instr)->getCalledOperand());
2858 return wrap(unwrap<CallBase>(Instr)->getFunctionType());
2864 return unwrap<CallInst>(Call)->isTailCall();
2868 unwrap<CallInst>(Call)->setTailCall(isTailCall);
2882 return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
2887 return wrap(CRI->getUnwindDest());
2889 return wrap(CSI->getUnwindDest());
2891 return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
2895 unwrap<InvokeInst>(Invoke)->setNormalDest(
unwrap(
B));
2900 return CRI->setUnwindDest(
unwrap(
B));
2902 return CSI->setUnwindDest(
unwrap(
B));
2904 unwrap<InvokeInst>(Invoke)->setUnwindDest(
unwrap(
B));
2910 return unwrap<Instruction>(Term)->getNumSuccessors();
2914 return wrap(unwrap<Instruction>(Term)->getSuccessor(i));
2918 return unwrap<Instruction>(Term)->setSuccessor(i,
unwrap(
block));
2924 return unwrap<BranchInst>(Branch)->isConditional();
2928 return wrap(unwrap<BranchInst>(Branch)->getCondition());
2932 return unwrap<BranchInst>(Branch)->setCondition(
unwrap(
Cond));
2938 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
2944 return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
2950 return unwrap<GEPOperator>(
GEP)->isInBounds();
2954 return unwrap<GetElementPtrInst>(
GEP)->setIsInBounds(InBounds);
2958 return wrap(unwrap<GEPOperator>(
GEP)->getSourceElementType());
2965 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
2966 for (
unsigned I = 0;
I != Count; ++
I)
2971 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
2975 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(
Index));
2979 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(
Index));
2986 if (
auto *
GEP = dyn_cast<GEPOperator>(
I))
2987 return GEP->getNumIndices();
2988 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
2989 return EV->getNumIndices();
2990 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
2991 return IV->getNumIndices();
2993 "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
2998 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
2999 return EV->getIndices().data();
3000 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3001 return IV->getIndices().data();
3003 "LLVMGetIndices applies only to extractvalue and insertvalue!");
3020 auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->
end();
3021 unwrap(Builder)->SetInsertPoint(BB,
I);
3026 unwrap(Builder)->SetInsertPoint(
I->getParent(),
I->getIterator());
3031 unwrap(Builder)->SetInsertPoint(BB);
3035 return wrap(
unwrap(Builder)->GetInsertBlock());
3039 unwrap(Builder)->ClearInsertionPoint();
3043 unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
3048 unwrap(Builder)->Insert(unwrap<Instruction>(Instr),
Name);
3058 return wrap(
unwrap(Builder)->getCurrentDebugLocation().getAsMDNode());
3063 unwrap(Builder)->SetCurrentDebugLocation(
DebugLoc(unwrap<MDNode>(Loc)));
3070 L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) :
nullptr;
3077 Context,
unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()));
3081 unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
3085 unwrap(Builder)->AddMetadataToInst(unwrap<Instruction>(Inst));
3091 unwrap(Builder)->setDefaultFPMathTag(FPMathTag
3092 ? unwrap<MDNode>(FPMathTag)
3097 return wrap(
unwrap(Builder)->getDefaultFPMathTag());
3130 unsigned NumDests) {
3150 unwrap(
B)->GetInsertBlock()->getParent()->setPersonalityFn(
3151 unwrap<Function>(PersFn));
3165 if (ParentPad ==
nullptr) {
3179 unsigned NumHandlers,
const char *
Name) {
3180 if (ParentPad ==
nullptr) {
3185 NumHandlers,
Name));
3190 return wrap(
unwrap(
B)->CreateCatchRet(unwrap<CatchPadInst>(CatchPad),
3196 return wrap(
unwrap(
B)->CreateCleanupRet(unwrap<CleanupPadInst>(CatchPad),
3206 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal),
unwrap(Dest));
3210 unwrap<IndirectBrInst>(IndirectBr)->addDestination(
unwrap(Dest));
3214 return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
3218 return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(
Idx));
3222 unwrap<LandingPadInst>(LandingPad)->addClause(unwrap<Constant>(
ClauseVal));
3226 return unwrap<LandingPadInst>(LandingPad)->isCleanup();
3230 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
3234 unwrap<CatchSwitchInst>(CatchSwitch)->addHandler(
unwrap(Dest));
3238 return unwrap<CatchSwitchInst>(CatchSwitch)->getNumHandlers();
3244 *Handlers++ =
wrap(
H);
3248 return wrap(unwrap<CatchPadInst>(CatchPad)->getCatchSwitch());
3252 unwrap<CatchPadInst>(CatchPad)
3253 ->setCatchSwitch(unwrap<CatchSwitchInst>(CatchSwitch));
3259 return wrap(unwrap<FuncletPadInst>(Funclet)->getArgOperand(i));
3263 unwrap<FuncletPadInst>(Funclet)->setArgOperand(i,
unwrap(
value));
3428 Value *
P = unwrap<Value>(ArithInst);
3429 return cast<Instruction>(
P)->hasNoUnsignedWrap();
3433 Value *
P = unwrap<Value>(ArithInst);
3434 cast<Instruction>(
P)->setHasNoUnsignedWrap(HasNUW);
3438 Value *
P = unwrap<Value>(ArithInst);
3439 return cast<Instruction>(
P)->hasNoSignedWrap();
3443 Value *
P = unwrap<Value>(ArithInst);
3444 cast<Instruction>(
P)->setHasNoSignedWrap(HasNSW);
3448 Value *
P = unwrap<Value>(DivOrShrInst);
3449 return cast<Instruction>(
P)->isExact();
3453 Value *
P = unwrap<Value>(DivOrShrInst);
3454 cast<Instruction>(
P)->setIsExact(IsExact);
3458 Value *
P = unwrap<Value>(NonNegInst);
3459 return cast<Instruction>(
P)->hasNonNeg();
3463 Value *
P = unwrap<Value>(NonNegInst);
3464 cast<Instruction>(
P)->setNonNeg(IsNonNeg);
3544 return AtomicOrdering::AcquireRelease;
3546 return AtomicOrdering::SequentiallyConsistent;
3559 case AtomicOrdering::AcquireRelease:
3561 case AtomicOrdering::SequentiallyConsistent:
3626 unsigned NumIndices,
const char *
Name) {
3633 unsigned NumIndices,
const char *
Name) {
3658 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3659 return LI->isVolatile();
3661 return SI->isVolatile();
3663 return AI->isVolatile();
3664 return cast<AtomicCmpXchgInst>(
P)->isVolatile();
3669 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3670 return LI->setVolatile(isVolatile);
3672 return SI->setVolatile(isVolatile);
3674 return AI->setVolatile(isVolatile);
3675 return cast<AtomicCmpXchgInst>(
P)->setVolatile(isVolatile);
3679 return unwrap<AtomicCmpXchgInst>(CmpXchgInst)->isWeak();
3683 return unwrap<AtomicCmpXchgInst>(CmpXchgInst)->setWeak(isWeak);
3689 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3690 O = LI->getOrdering();
3691 else if (
StoreInst *SI = dyn_cast<StoreInst>(
P))
3692 O = SI->getOrdering();
3693 else if (
FenceInst *FI = dyn_cast<FenceInst>(
P))
3694 O = FI->getOrdering();
3696 O = cast<AtomicRMWInst>(
P)->getOrdering();
3704 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3705 return LI->setOrdering(O);
3706 else if (
FenceInst *FI = dyn_cast<FenceInst>(
P))
3707 return FI->setOrdering(O);
3709 return ARWI->setOrdering(O);
3710 return cast<StoreInst>(
P)->setOrdering(O);