45#include <system_error>
55#define DEBUG_TYPE "ir"
73 *Major = LLVM_VERSION_MAJOR;
75 *Minor = LLVM_VERSION_MINOR;
77 *Patch = LLVM_VERSION_PATCH;
83 return strdup(Message);
106 void *DiagnosticContext) {
107 unwrap(
C)->setDiagnosticHandlerCallBack(
115 unwrap(
C)->getDiagnosticHandlerCallBack());
119 return unwrap(
C)->getDiagnosticContext();
123 void *OpaqueHandle) {
126 unwrap(
C)->setYieldCallback(YieldCallback, OpaqueHandle);
130 return unwrap(
C)->shouldDiscardValueNames();
134 unwrap(
C)->setDiscardValueNames(Discard);
159 return Attribute::AttrKind::EndAttrKinds;
170 return unwrap(
A).getKindAsEnum();
175 if (Attr.isEnumAttribute())
177 return Attr.getValueAsInt();
189 return wrap(Attr.getValueAsType());
207 const char *K,
unsigned KLength,
208 const char *V,
unsigned VLength) {
215 auto S =
unwrap(
A).getKindAsString();
222 auto S =
unwrap(
A).getValueAsString();
229 return Attr.isEnumAttribute() || Attr.isIntAttribute();
233 return unwrap(
A).isStringAttribute();
237 return unwrap(
A).isTypeAttribute();
241 std::string MsgStorage;
254 switch(
unwrap(DI)->getSeverity()) {
288 auto &Str =
unwrap(M)->getModuleIdentifier();
298 auto &Str =
unwrap(M)->getSourceFileName();
309 return unwrap(M)->getDataLayoutStr().c_str();
317 unwrap(M)->setDataLayout(DataLayoutStr);
322 return unwrap(M)->getTargetTriple().c_str();
341 return Module::ModFlagBehavior::Error;
343 return Module::ModFlagBehavior::Warning;
345 return Module::ModFlagBehavior::Require;
347 return Module::ModFlagBehavior::Override;
349 return Module::ModFlagBehavior::Append;
351 return Module::ModFlagBehavior::AppendUnique;
359 case Module::ModFlagBehavior::Error:
361 case Module::ModFlagBehavior::Warning:
363 case Module::ModFlagBehavior::Require:
365 case Module::ModFlagBehavior::Override:
367 case Module::ModFlagBehavior::Append:
369 case Module::ModFlagBehavior::AppendUnique:
378 unwrap(M)->getModuleFlagsMetadata(MFEs);
382 for (
unsigned i = 0; i < MFEs.
size(); ++i) {
383 const auto &ModuleFlag = MFEs[i];
385 Result[i].Key = ModuleFlag.Key->getString().data();
386 Result[i].KeyLen = ModuleFlag.Key->getString().size();
387 Result[i].Metadata =
wrap(ModuleFlag.Val);
406 unsigned Index,
size_t *Len) {
421 const char *Key,
size_t KeyLen) {
422 return wrap(
unwrap(M)->getModuleFlag({Key, KeyLen}));
426 const char *Key,
size_t KeyLen,
429 {Key, KeyLen},
unwrap(Val));
448 char **ErrorMessage) {
452 *ErrorMessage = strdup(EC.message().c_str());
461 std::string E =
"Error printing to file: " + dest.
error().message();
462 *ErrorMessage = strdup(E.c_str());
476 return strdup(buf.c_str());
493 auto &Str =
unwrap(M)->getModuleInlineAsm();
499 size_t AsmStringSize,
const char *Constraints,
500 size_t ConstraintsSize,
LLVMBool HasSideEffects,
515 HasSideEffects, IsAlignStack, AD, CanThrow));
520 Value *Val = unwrap<Value>(InlineAsmVal);
521 const std::string &AsmString = cast<InlineAsm>(Val)->getAsmString();
523 *Len = AsmString.length();
524 return AsmString.c_str();
529 Value *Val = unwrap<Value>(InlineAsmVal);
530 const std::string &ConstraintString =
531 cast<InlineAsm>(Val)->getConstraintString();
533 *Len = ConstraintString.length();
534 return ConstraintString.c_str();
539 Value *Val = unwrap<Value>(InlineAsmVal);
554 Value *Val = unwrap<Value>(InlineAsmVal);
555 return (
LLVMTypeRef)cast<InlineAsm>(Val)->getFunctionType();
559 Value *Val = unwrap<Value>(InlineAsmVal);
560 return cast<InlineAsm>(Val)->hasSideEffects();
564 Value *Val = unwrap<Value>(InlineAsmVal);
565 return cast<InlineAsm>(Val)->isAlignStack();
569 Value *Val = unwrap<Value>(InlineAsmVal);
570 return cast<InlineAsm>(Val)->canThrow();
633 return unwrap(Ty)->isSized();
651 os <<
"Printing <null> Type";
655 return strdup(buf.c_str());
705 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
766 return wrap(FunctionType::get(
unwrap(ReturnType), Tys, IsVarArg != 0));
770 return unwrap<FunctionType>(FunctionTy)->isVarArg();
774 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
778 return unwrap<FunctionType>(FunctionTy)->getNumParams();
783 for (
Type *
T : Ty->params())
809 if (!
Type->hasName())
811 return Type->getName().data();
817 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
821 return unwrap<StructType>(StructTy)->getNumElements();
825 StructType *Ty = unwrap<StructType>(StructTy);
831 StructType *Ty = unwrap<StructType>(StructTy);
836 return unwrap<StructType>(StructTy)->isPacked();
840 return unwrap<StructType>(StructTy)->isOpaque();
844 return unwrap<StructType>(StructTy)->isLiteral();
859 for (
auto *
T :
unwrap(Tp)->subtypes()) {
891 auto *Ty =
unwrap(WrappedTy);
892 if (
auto *ATy = dyn_cast<ArrayType>(Ty))
893 return wrap(ATy->getElementType());
894 return wrap(cast<VectorType>(Ty)->getElementType());
898 return unwrap(Tp)->getNumContainedTypes();
902 return unwrap<ArrayType>(ArrayTy)->getNumElements();
906 return unwrap<ArrayType>(ArrayTy)->getNumElements();
910 return unwrap<PointerType>(
PointerTy)->getAddressSpace();
914 return unwrap<VectorType>(VectorTy)->getElementCount().getKnownMinValue();
918 return wrap(unwrap<ConstantPtrAuth>(PtrAuth)->getPointer());
922 return wrap(unwrap<ConstantPtrAuth>(PtrAuth)->getKey());
926 return wrap(unwrap<ConstantPtrAuth>(PtrAuth)->getDiscriminator());
930 return wrap(unwrap<ConstantPtrAuth>(PtrAuth)->getAddrDiscriminator());
961 unsigned TypeParamCount,
963 unsigned IntParamCount) {
972 return Type->getName().data();
977 return Type->getNumTypeParameters();
988 return Type->getNumIntParameters();
993 return Type->getIntParameter(
Idx);
1005 switch(
unwrap(Val)->getValueID()) {
1007#define HANDLE_VALUE(Name) \
1008 case Value::Name##Val: \
1009 return LLVM##Name##ValueKind;
1010#include "llvm/IR/Value.def"
1018 *
Length = V->getName().size();
1019 return V->getName().data();
1045 os <<
"Printing <null> Value";
1049 return strdup(buf.c_str());
1063 os <<
"Printing <null> DbgRecord";
1067 return strdup(buf.c_str());
1075 return unwrap<Instruction>(Inst)->hasMetadata();
1079 auto *
I = unwrap<Instruction>(Inst);
1080 assert(
I &&
"Expected instruction");
1081 if (
auto *MD =
I->getMetadata(KindID))
1091 assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
1092 "Expected a metadata node or a canonicalized constant");
1094 if (
MDNode *
N = dyn_cast<MDNode>(MD))
1103 unwrap<Instruction>(Inst)->setMetadata(KindID,
N);
1121 for (
unsigned i = 0; i < MVEs.
size(); ++i) {
1122 const auto &ModuleFlag = MVEs[i];
1123 Result[i].Kind = ModuleFlag.first;
1124 Result[i].Metadata =
wrap(ModuleFlag.second);
1126 *NumEntries = MVEs.
size();
1132 size_t *NumEntries) {
1135 unwrap<Instruction>(
Value)->getAllMetadata(Entries);
1141#define LLVM_DEFINE_VALUE_CAST(name) \
1142 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
1143 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
1149 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1150 if (isa<MDNode>(MD->getMetadata()) ||
1151 isa<ValueAsMetadata>(MD->getMetadata()))
1157 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1158 if (isa<ValueAsMetadata>(MD->getMetadata()))
1164 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1165 if (isa<MDString>(MD->getMetadata()))
1174 if (
I == V->use_end())
1201 if (
auto *
C = dyn_cast<ConstantAsMetadata>(
Op))
1202 return wrap(
C->getValue());
1208 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
1209 if (
auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1210 assert(
Index == 0 &&
"Function-local metadata can only have one operand");
1211 return wrap(L->getValue());
1214 cast<MDNode>(MD->getMetadata()),
Index);
1217 return wrap(cast<User>(V)->getOperand(
Index));
1222 return wrap(&cast<User>(V)->getOperandUse(
Index));
1231 if (isa<MetadataAsValue>(V))
1234 return cast<User>(V)->getNumOperands();
1256 return isa<Constant>(
unwrap(Ty));
1261 return C->isNullValue();
1266 return isa<UndefValue>(
unwrap(Val));
1270 return isa<PoisonValue>(
unwrap(Val));
1304 for (
auto *OV :
ArrayRef(Vals, Count)) {
1309 else if (
auto *
C = dyn_cast<Constant>(V))
1311 else if (
auto *MDV = dyn_cast<MetadataAsValue>(V)) {
1312 MD = MDV->getMetadata();
1313 assert(!isa<LocalAsMetadata>(MD) &&
"Unexpected function-local metadata "
1314 "outside of direct argument to call");
1318 "Expected only one operand to function-local metadata");
1337 if (
auto *
C = dyn_cast<Constant>(V))
1339 if (
auto *MAV = dyn_cast<MetadataAsValue>(V))
1340 return wrap(MAV->getMetadata());
1345 if (
const auto *MD = dyn_cast<MetadataAsValue>(
unwrap(V)))
1346 if (
const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
1347 *
Length = S->getString().size();
1348 return S->getString().data();
1355 auto *MD = unwrap<MetadataAsValue>(V);
1356 if (isa<ValueAsMetadata>(MD->getMetadata()))
1358 return cast<MDNode>(MD->getMetadata())->getNumOperands();
1364 if (
I ==
Mod->named_metadata_end())
1372 if (
I ==
Mod->named_metadata_begin())
1394 const char *
Name,
size_t NameLen) {
1399 const char *
Name,
size_t NameLen) {
1400 return wrap(
unwrap(M)->getOrInsertNamedMetadata({
Name, NameLen}));
1410 auto *MD = unwrap<MetadataAsValue>(V);
1411 if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1412 *Dest =
wrap(MDV->getValue());
1415 const auto *
N = cast<MDNode>(MD->getMetadata());
1416 const unsigned numOperands =
N->getNumOperands();
1418 for (
unsigned i = 0; i < numOperands; i++)
1424 auto *MD = cast<MetadataAsValue>(
unwrap(V));
1425 auto *
N = cast<MDNode>(MD->getMetadata());
1426 N->replaceOperandWith(
Index, unwrap<Metadata>(Replacement));
1431 return N->getNumOperands();
1442 for (
unsigned i=0;i<
N->getNumOperands();i++)
1457 if (!
Length)
return nullptr;
1459 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1460 if (
const auto &
DL =
I->getDebugLoc()) {
1461 S =
DL->getDirectory();
1463 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1465 GV->getDebugInfo(GVEs);
1468 S = DGV->getDirectory();
1469 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1471 S = DSP->getDirectory();
1473 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1481 if (!
Length)
return nullptr;
1483 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1484 if (
const auto &
DL =
I->getDebugLoc()) {
1485 S =
DL->getFilename();
1487 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1489 GV->getDebugInfo(GVEs);
1492 S = DGV->getFilename();
1493 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1495 S = DSP->getFilename();
1497 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1506 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1507 if (
const auto &
DL =
I->getDebugLoc()) {
1510 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1512 GV->getDebugInfo(GVEs);
1516 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1520 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1528 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val)))
1529 if (
const auto &
DL =
I->getDebugLoc())
1530 C =
DL->getColumn();
1538 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy),
N, SignExtend != 0));
1545 return wrap(ConstantInt::get(
1551 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy),
StringRef(Str),
1556 unsigned SLen, uint8_t Radix) {
1557 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy),
StringRef(Str, SLen),
1575 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
1579 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
1583 ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
1594 APF.
convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &APFLosesInfo);
1595 *LosesInfo = APFLosesInfo;
1607 DontNullTerminate == 0));
1616 DontNullTerminate == 0));
1626 return wrap(unwrap<Constant>(
C)->getAggregateElement(
Idx));
1630 return wrap(unwrap<ConstantDataSequential>(
C)->getElementAsConstant(idx));
1634 return unwrap<ConstantDataSequential>(
C)->isString();
1638 StringRef Str = unwrap<ConstantDataSequential>(
C)->getAsString();
1658 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1672 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1673 StructType *Ty = unwrap<StructType>(StructTy);
1686 unwrap<Constant>(
Ptr), unwrap<ConstantInt>(Key),
1687 unwrap<ConstantInt>(Disc), unwrap<Constant>(AddrDisc)));
1696#define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1697#include "llvm/IR/Instruction.def"
1705#define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1706#include "llvm/IR/Instruction.def"
1771 unwrap<Constant>(RHSConstant)));
1777 unwrap<Constant>(RHSConstant)));
1783 unwrap<Constant>(RHSConstant)));
1788 unwrap<Constant>(RHSConstant)));
1794 unwrap<Constant>(RHSConstant)));
1800 unwrap<Constant>(RHSConstant)));
1805 unwrap<Constant>(RHSConstant)));
1811 unwrap<Constant>(RHSConstant)));
1817 unwrap<Constant>(RHSConstant)));
1822 unwrap<Constant>(RHSConstant)));
1829 Constant *Val = unwrap<Constant>(ConstantVal);
1835 unsigned NumIndices) {
1838 Constant *Val = unwrap<Constant>(ConstantVal);
1845 unsigned NumIndices,
1849 Constant *Val = unwrap<Constant>(ConstantVal);
1895 unwrap<Constant>(IndexConstant)));
1902 unwrap<Constant>(ElementValueConstant),
1903 unwrap<Constant>(IndexConstant)));
1912 unwrap<Constant>(VectorBConstant),
1917 const char *Constraints,
1921 Constraints, HasSideEffects, IsAlignStack));
1933 return wrap(unwrap<BlockAddress>(BlockAddr)->getBasicBlock());
1943 return unwrap<GlobalValue>(
Global)->isDeclaration();
1947 switch (unwrap<GlobalValue>(
Global)->getLinkage()) {
1993 errs() <<
"LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1994 "longer supported.");
2020 <<
"LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
2025 <<
"LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
2032 errs() <<
"LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
2043 return unwrap<GlobalValue>(
Global)->getSection().data();
2047 unwrap<GlobalObject>(
Global)->setSection(Section);
2052 unwrap<GlobalValue>(
Global)->getVisibility());
2056 unwrap<GlobalValue>(
Global)
2062 unwrap<GlobalValue>(
Global)->getDLLStorageClass());
2066 unwrap<GlobalValue>(
Global)->setDLLStorageClass(
2071 switch (unwrap<GlobalValue>(
Global)->getUnnamedAddr()) {
2072 case GlobalVariable::UnnamedAddr::None:
2074 case GlobalVariable::UnnamedAddr::Local:
2076 case GlobalVariable::UnnamedAddr::Global:
2085 switch (UnnamedAddr) {
2096 return unwrap<GlobalValue>(
Global)->hasGlobalUnnamedAddr();
2100 unwrap<GlobalValue>(
Global)->setUnnamedAddr(
2101 HasUnnamedAddr ? GlobalValue::UnnamedAddr::Global
2102 : GlobalValue::UnnamedAddr::None);
2106 return wrap(unwrap<GlobalValue>(
Global)->getValueType());
2114 return GV->getAlign() ? GV->getAlign()->value() : 0;
2116 return AI->getAlign().value();
2117 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2118 return LI->getAlign().value();
2120 return SI->getAlign().value();
2122 return RMWI->getAlign().value();
2124 return CXI->getAlign().value();
2127 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, "
2128 "and AtomicCmpXchgInst have alignment");
2135 else if (
AllocaInst *AI = dyn_cast<AllocaInst>(
P))
2136 AI->setAlignment(
Align(Bytes));
2137 else if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2138 LI->setAlignment(
Align(Bytes));
2139 else if (
StoreInst *SI = dyn_cast<StoreInst>(
P))
2140 SI->setAlignment(
Align(Bytes));
2142 RMWI->setAlignment(
Align(Bytes));
2144 CXI->setAlignment(
Align(Bytes));
2147 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, and "
2148 "and AtomicCmpXchgInst have alignment");
2152 size_t *NumEntries) {
2156 Instr->getAllMetadata(Entries);
2158 unwrap<GlobalObject>(
Value)->getAllMetadata(Entries);
2184 unwrap<GlobalObject>(
Global)->setMetadata(Kind, unwrap<MDNode>(MD));
2188 unwrap<GlobalObject>(
Global)->eraseMetadata(Kind);
2192 unwrap<GlobalObject>(
Global)->clearMetadata();
2207 nullptr, GlobalVariable::NotThreadLocal,
2223 if (
I ==
Mod->global_end())
2231 if (
I ==
Mod->global_begin())
2253 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
2264 unwrap<GlobalVariable>(GlobalVar)
2265 ->setInitializer(unwrap<Constant>(ConstantVal));
2269 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
2273 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
2277 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
2281 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
2285 switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
2286 case GlobalVariable::NotThreadLocal:
2288 case GlobalVariable::GeneralDynamicTLSModel:
2290 case GlobalVariable::LocalDynamicTLSModel:
2292 case GlobalVariable::InitialExecTLSModel:
2294 case GlobalVariable::LocalExecTLSModel:
2324 return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
2328 unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
2338 unwrap<Constant>(Aliasee),
unwrap(M)));
2342 const char *
Name,
size_t NameLen) {
2349 if (
I ==
Mod->alias_end())
2357 if (
I ==
Mod->alias_begin())
2379 return wrap(unwrap<GlobalAlias>(Alias)->getAliasee());
2383 unwrap<GlobalAlias>(Alias)->setAliasee(unwrap<Constant>(Aliasee));
2406 if (
I ==
Mod->end())
2414 if (
I ==
Mod->begin())
2420 Function *Func = unwrap<Function>(Fn);
2422 if (++
I == Func->getParent()->end())
2428 Function *Func = unwrap<Function>(Fn);
2430 if (
I == Func->getParent()->begin())
2436 unwrap<Function>(Fn)->eraseFromParent();
2440 return unwrap<Function>(Fn)->hasPersonalityFn();
2444 return wrap(unwrap<Function>(Fn)->getPersonalityFn());
2448 unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
2453 return F->getIntrinsicID();
2458 assert(
ID < llvm::Intrinsic::num_intrinsics &&
"Intrinsic ID out of range");
2465 size_t ParamCount) {
2474 *NameLength = Str.size();
2488 size_t *NameLength) {
2492 *NameLength = Str.length();
2493 return strdup(Str.c_str());
2499 size_t *NameLength) {
2503 *NameLength = Str.length();
2504 return strdup(Str.c_str());
2517 return unwrap<Function>(Fn)->getCallingConv();
2521 return unwrap<Function>(Fn)->setCallingConv(
2527 return F->hasGC()?
F->getGC().c_str() :
nullptr;
2540 return wrap(
F->getPrefixData());
2545 return F->hasPrefixData();
2550 Constant *prefix = unwrap<Constant>(prefixData);
2551 F->setPrefixData(prefix);
2556 return wrap(
F->getPrologueData());
2561 return F->hasPrologueData();
2566 Constant *prologue = unwrap<Constant>(prologueData);
2567 F->setPrologueData(prologue);
2572 unwrap<Function>(
F)->addAttributeAtIndex(
Idx,
unwrap(
A));
2576 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(
Idx);
2577 return AS.getNumAttributes();
2582 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(
Idx);
2590 return wrap(unwrap<Function>(
F)->getAttributeAtIndex(
2596 const char *K,
unsigned KLen) {
2598 unwrap<Function>(
F)->getAttributeAtIndex(
Idx,
StringRef(K, KLen)));
2607 const char *K,
unsigned KLen) {
2608 unwrap<Function>(
F)->removeAttributeAtIndex(
Idx,
StringRef(K, KLen));
2613 Function *Func = unwrap<Function>(Fn);
2615 Func->addFnAttr(Attr);
2623 return unwrap<Function>(FnRef)->arg_size();
2627 Function *Fn = unwrap<Function>(FnRef);
2629 *ParamRefs++ =
wrap(&
A);
2633 Function *Fn = unwrap<Function>(FnRef);
2642 Function *Func = unwrap<Function>(Fn);
2644 if (
I == Func->arg_end())
2650 Function *Func = unwrap<Function>(Fn);
2652 if (
I == Func->arg_begin())
2660 if (
A->getArgNo() + 1 >= Fn->
arg_size())
2667 if (
A->getArgNo() == 0)
2669 return wrap(&
A->getParent()->arg_begin()[
A->getArgNo() - 1]);
2680 const char *
Name,
size_t NameLen,
2690 const char *
Name,
size_t NameLen) {
2697 if (
I ==
Mod->ifunc_end())
2705 if (
I ==
Mod->ifunc_begin())
2727 return wrap(unwrap<GlobalIFunc>(IFunc)->getResolver());
2731 unwrap<GlobalIFunc>(IFunc)->setResolver(unwrap<Constant>(
Resolver));
2735 unwrap<GlobalIFunc>(IFunc)->eraseFromParent();
2739 unwrap<GlobalIFunc>(IFunc)->removeFromParent();
2777 return isa<BasicBlock>(
unwrap(Val));
2781 return wrap(unwrap<BasicBlock>(Val));
2797 return unwrap<Function>(FnRef)->size();
2801 Function *Fn = unwrap<Function>(FnRef);
2803 *BasicBlocksRefs++ =
wrap(&BB);
2807 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
2811 Function *Func = unwrap<Function>(Fn);
2813 if (
I == Func->end())
2819 Function *Func = unwrap<Function>(Fn);
2821 if (
I == Func->begin())
2829 if (++
I ==
Block->getParent()->end())
2837 if (
I ==
Block->getParent()->begin())
2851 assert(CurBB &&
"current insertion point is invalid!");
2857 unwrap<Function>(Fn)->insert(unwrap<Function>(Fn)->end(),
unwrap(BB));
2923 if (++
I == Instr->getParent()->end())
2931 if (
I == Instr->getParent()->begin())
2937 unwrap<Instruction>(Inst)->removeFromParent();
2941 unwrap<Instruction>(Inst)->eraseFromParent();
2945 unwrap<Instruction>(Inst)->deleteValue();
2968 return wrap(
C->clone());
2974 return (
I &&
I->isTerminator()) ?
wrap(
I) :
nullptr;
2979 return FPI->arg_size();
2981 return unwrap<CallBase>(Instr)->arg_size();
2987 return unwrap<CallBase>(Instr)->getCallingConv();
2991 return unwrap<CallBase>(Instr)->setCallingConv(
2997 auto *Call = unwrap<CallBase>(Instr);
3000 Call->addAttributeAtIndex(
Idx, AlignAttr);
3005 unwrap<CallBase>(
C)->addAttributeAtIndex(
Idx,
unwrap(
A));
3010 auto *Call = unwrap<CallBase>(
C);
3011 auto AS = Call->getAttributes().getAttributes(
Idx);
3012 return AS.getNumAttributes();
3017 auto *Call = unwrap<CallBase>(
C);
3018 auto AS = Call->getAttributes().getAttributes(
Idx);
3026 return wrap(unwrap<CallBase>(
C)->getAttributeAtIndex(
3032 const char *K,
unsigned KLen) {
3034 unwrap<CallBase>(
C)->getAttributeAtIndex(
Idx,
StringRef(K, KLen)));
3043 const char *K,
unsigned KLen) {
3044 unwrap<CallBase>(
C)->removeAttributeAtIndex(
Idx,
StringRef(K, KLen));
3048 return wrap(unwrap<CallBase>(Instr)->getCalledOperand());
3052 return wrap(unwrap<CallBase>(Instr)->getFunctionType());
3056 return unwrap<CallBase>(
C)->getNumOperandBundles();
3068 return unwrap<CallInst>(Call)->isTailCall();
3072 unwrap<CallInst>(Call)->setTailCall(isTailCall);
3086 return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
3091 return wrap(CRI->getUnwindDest());
3093 return wrap(CSI->getUnwindDest());
3095 return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
3099 unwrap<InvokeInst>(Invoke)->setNormalDest(
unwrap(
B));
3104 return CRI->setUnwindDest(
unwrap(
B));
3106 return CSI->setUnwindDest(
unwrap(
B));
3108 unwrap<InvokeInst>(Invoke)->setUnwindDest(
unwrap(
B));
3112 return wrap(unwrap<CallBrInst>(CallBr)->getDefaultDest());
3116 return unwrap<CallBrInst>(CallBr)->getNumIndirectDests();
3120 return wrap(unwrap<CallBrInst>(CallBr)->getIndirectDest(
Idx));
3126 return unwrap<Instruction>(Term)->getNumSuccessors();
3130 return wrap(unwrap<Instruction>(Term)->getSuccessor(i));
3134 return unwrap<Instruction>(Term)->setSuccessor(i,
unwrap(
block));
3140 return unwrap<BranchInst>(Branch)->isConditional();
3144 return wrap(unwrap<BranchInst>(Branch)->getCondition());
3148 return unwrap<BranchInst>(Branch)->setCondition(
unwrap(
Cond));
3154 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
3160 return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
3166 return unwrap<GEPOperator>(
GEP)->isInBounds();
3170 return unwrap<GetElementPtrInst>(
GEP)->setIsInBounds(InBounds);
3174 return wrap(unwrap<GEPOperator>(
GEP)->getSourceElementType());
3191 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
3192 for (
unsigned I = 0;
I != Count; ++
I)
3197 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
3201 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(
Index));
3205 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(
Index));
3212 if (
auto *
GEP = dyn_cast<GEPOperator>(
I))
3213 return GEP->getNumIndices();
3214 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3215 return EV->getNumIndices();
3216 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3217 return IV->getNumIndices();
3219 "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
3224 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3225 return EV->getIndices().data();
3226 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3227 return IV->getIndices().data();
3229 "LLVMGetIndices applies only to extractvalue and insertvalue!");
3246 I.setHeadBit(BeforeDbgRecords);
3253 unwrap<Instruction>(Instr),
false);
3260 unwrap<Instruction>(Instr),
true);
3276 unwrap(Builder)->SetInsertPoint(BB);
3280 return wrap(
unwrap(Builder)->GetInsertBlock());
3284 unwrap(Builder)->ClearInsertionPoint();
3288 unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
3293 unwrap(Builder)->Insert(unwrap<Instruction>(Instr),
Name);
3303 return wrap(
unwrap(Builder)->getCurrentDebugLocation().getAsMDNode());
3308 unwrap(Builder)->SetCurrentDebugLocation(
DebugLoc(unwrap<MDNode>(Loc)));
3315 L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) :
nullptr;
3322 Context,
unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()));
3326 unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
3330 unwrap(Builder)->AddMetadataToInst(unwrap<Instruction>(Inst));
3336 unwrap(Builder)->setDefaultFPMathTag(FPMathTag
3337 ? unwrap<MDNode>(FPMathTag)
3346 return wrap(
unwrap(Builder)->getDefaultFPMathTag());
3379 unsigned NumDests) {
3388 unsigned NumBundles,
const char *
Name) {
3391 for (
auto *Bundle :
ArrayRef(Bundles, NumBundles)) {
3397 unwrap<FunctionType>(Ty),
unwrap(Fn),
unwrap(DefaultDest),
3416 for (
auto *Bundle :
ArrayRef(Bundles, NumBundles)) {
3433 unwrap<Function>(PersFn));
3447 if (ParentPad ==
nullptr) {
3461 unsigned NumHandlers,
const char *
Name) {
3462 if (ParentPad ==
nullptr) {
3467 NumHandlers,
Name));
3472 return wrap(
unwrap(
B)->CreateCatchRet(unwrap<CatchPadInst>(CatchPad),
3478 return wrap(
unwrap(
B)->CreateCleanupRet(unwrap<CleanupPadInst>(CatchPad),
3488 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal),
unwrap(Dest));
3492 unwrap<IndirectBrInst>(IndirectBr)->addDestination(
unwrap(Dest));
3496 return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
3500 return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(
Idx));
3504 unwrap<LandingPadInst>(LandingPad)->addClause(unwrap<Constant>(
ClauseVal));
3508 return unwrap<LandingPadInst>(LandingPad)->isCleanup();
3512 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
3516 unwrap<CatchSwitchInst>(CatchSwitch)->addHandler(
unwrap(Dest));
3520 return unwrap<CatchSwitchInst>(CatchSwitch)->getNumHandlers();
3526 *Handlers++ =
wrap(
H);
3530 return wrap(unwrap<CatchPadInst>(CatchPad)->getCatchSwitch());
3534 unwrap<CatchPadInst>(CatchPad)
3535 ->setCatchSwitch(unwrap<CatchSwitchInst>(CatchSwitch));
3541 return wrap(unwrap<FuncletPadInst>(Funclet)->getArgOperand(i));
3545 unwrap<FuncletPadInst>(Funclet)->setArgOperand(i,
unwrap(
value));
3732 if (
auto *
I = dyn_cast<BinaryOperator>(Neg))
3733 I->setHasNoUnsignedWrap();
3746 Value *
P = unwrap<Value>(ArithInst);
3747 return cast<Instruction>(
P)->hasNoUnsignedWrap();
3751 Value *
P = unwrap<Value>(ArithInst);
3752 cast<Instruction>(
P)->setHasNoUnsignedWrap(HasNUW);
3756 Value *
P = unwrap<Value>(ArithInst);
3757 return cast<Instruction>(
P)->hasNoSignedWrap();
3761 Value *
P = unwrap<Value>(ArithInst);
3762 cast<Instruction>(
P)->setHasNoSignedWrap(HasNSW);
3766 Value *
P = unwrap<Value>(DivOrShrInst);
3767 return cast<Instruction>(
P)->isExact();
3771 Value *
P = unwrap<Value>(DivOrShrInst);
3772 cast<Instruction>(
P)->setIsExact(IsExact);
3776 Value *
P = unwrap<Value>(NonNegInst);
3777 return cast<Instruction>(