47#include <system_error>
57#define DEBUG_TYPE "ir"
75 *Major = LLVM_VERSION_MAJOR;
77 *Minor = LLVM_VERSION_MINOR;
79 *Patch = LLVM_VERSION_PATCH;
85 return strdup(Message);
108 void *DiagnosticContext) {
109 unwrap(
C)->setDiagnosticHandlerCallBack(
117 unwrap(
C)->getDiagnosticHandlerCallBack());
121 return unwrap(
C)->getDiagnosticContext();
125 void *OpaqueHandle) {
128 unwrap(
C)->setYieldCallback(YieldCallback, OpaqueHandle);
132 return unwrap(
C)->shouldDiscardValueNames();
136 unwrap(
C)->setDiscardValueNames(Discard);
161 return Attribute::AttrKind::EndAttrKinds;
172 return unwrap(
A).getKindAsEnum();
177 if (Attr.isEnumAttribute())
179 return Attr.getValueAsInt();
191 return wrap(Attr.getValueAsType());
209 const char *K,
unsigned KLength,
210 const char *V,
unsigned VLength) {
217 auto S =
unwrap(
A).getKindAsString();
224 auto S =
unwrap(
A).getValueAsString();
231 return Attr.isEnumAttribute() || Attr.isIntAttribute();
235 return unwrap(
A).isStringAttribute();
239 return unwrap(
A).isTypeAttribute();
243 std::string MsgStorage;
256 switch(
unwrap(DI)->getSeverity()) {
290 auto &Str =
unwrap(M)->getModuleIdentifier();
300 auto &Str =
unwrap(M)->getSourceFileName();
311 return unwrap(M)->getDataLayoutStr().c_str();
319 unwrap(M)->setDataLayout(DataLayoutStr);
324 return unwrap(M)->getTargetTriple().c_str();
343 return Module::ModFlagBehavior::Error;
345 return Module::ModFlagBehavior::Warning;
347 return Module::ModFlagBehavior::Require;
349 return Module::ModFlagBehavior::Override;
351 return Module::ModFlagBehavior::Append;
353 return Module::ModFlagBehavior::AppendUnique;
361 case Module::ModFlagBehavior::Error:
363 case Module::ModFlagBehavior::Warning:
365 case Module::ModFlagBehavior::Require:
367 case Module::ModFlagBehavior::Override:
369 case Module::ModFlagBehavior::Append:
371 case Module::ModFlagBehavior::AppendUnique:
380 unwrap(M)->getModuleFlagsMetadata(MFEs);
384 for (
unsigned i = 0; i < MFEs.
size(); ++i) {
385 const auto &ModuleFlag = MFEs[i];
387 Result[i].Key = ModuleFlag.Key->getString().data();
388 Result[i].KeyLen = ModuleFlag.Key->getString().size();
389 Result[i].Metadata =
wrap(ModuleFlag.Val);
408 unsigned Index,
size_t *Len) {
423 const char *Key,
size_t KeyLen) {
424 return wrap(
unwrap(M)->getModuleFlag({Key, KeyLen}));
428 const char *Key,
size_t KeyLen,
431 {Key, KeyLen},
unwrap(Val));
450 char **ErrorMessage) {
454 *ErrorMessage = strdup(EC.message().c_str());
463 std::string E =
"Error printing to file: " + dest.
error().message();
464 *ErrorMessage = strdup(E.c_str());
478 return strdup(buf.c_str());
495 auto &Str =
unwrap(M)->getModuleInlineAsm();
501 size_t AsmStringSize,
const char *Constraints,
502 size_t ConstraintsSize,
LLVMBool HasSideEffects,
517 HasSideEffects, IsAlignStack, AD, CanThrow));
522 Value *Val = unwrap<Value>(InlineAsmVal);
523 const std::string &AsmString = cast<InlineAsm>(Val)->getAsmString();
525 *Len = AsmString.length();
526 return AsmString.c_str();
531 Value *Val = unwrap<Value>(InlineAsmVal);
532 const std::string &ConstraintString =
533 cast<InlineAsm>(Val)->getConstraintString();
535 *Len = ConstraintString.length();
536 return ConstraintString.c_str();
541 Value *Val = unwrap<Value>(InlineAsmVal);
556 Value *Val = unwrap<Value>(InlineAsmVal);
557 return (
LLVMTypeRef)cast<InlineAsm>(Val)->getFunctionType();
561 Value *Val = unwrap<Value>(InlineAsmVal);
562 return cast<InlineAsm>(Val)->hasSideEffects();
566 Value *Val = unwrap<Value>(InlineAsmVal);
567 return cast<InlineAsm>(Val)->isAlignStack();
571 Value *Val = unwrap<Value>(InlineAsmVal);
572 return cast<InlineAsm>(Val)->canThrow();
635 return unwrap(Ty)->isSized();
653 os <<
"Printing <null> Type";
657 return strdup(buf.c_str());
707 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
768 return wrap(FunctionType::get(
unwrap(ReturnType), Tys, IsVarArg != 0));
772 return unwrap<FunctionType>(FunctionTy)->isVarArg();
776 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
780 return unwrap<FunctionType>(FunctionTy)->getNumParams();
785 for (
Type *
T : Ty->params())
811 if (!
Type->hasName())
813 return Type->getName().data();
819 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
823 return unwrap<StructType>(StructTy)->getNumElements();
827 StructType *Ty = unwrap<StructType>(StructTy);
833 StructType *Ty = unwrap<StructType>(StructTy);
838 return unwrap<StructType>(StructTy)->isPacked();
842 return unwrap<StructType>(StructTy)->isOpaque();
846 return unwrap<StructType>(StructTy)->isLiteral();
861 for (
auto *
T :
unwrap(Tp)->subtypes()) {
893 auto *Ty =
unwrap(WrappedTy);
894 if (
auto *ATy = dyn_cast<ArrayType>(Ty))
895 return wrap(ATy->getElementType());
896 return wrap(cast<VectorType>(Ty)->getElementType());
900 return unwrap(Tp)->getNumContainedTypes();
904 return unwrap<ArrayType>(ArrayTy)->getNumElements();
908 return unwrap<ArrayType>(ArrayTy)->getNumElements();
912 return unwrap<PointerType>(
PointerTy)->getAddressSpace();
916 return unwrap<VectorType>(VectorTy)->getElementCount().getKnownMinValue();
920 return wrap(unwrap<ConstantPtrAuth>(PtrAuth)->getPointer());
924 return wrap(unwrap<ConstantPtrAuth>(PtrAuth)->getKey());
928 return wrap(unwrap<ConstantPtrAuth>(PtrAuth)->getDiscriminator());
932 return wrap(unwrap<ConstantPtrAuth>(PtrAuth)->getAddrDiscriminator());
963 unsigned TypeParamCount,
965 unsigned IntParamCount) {
974 return Type->getName().data();
979 return Type->getNumTypeParameters();
990 return Type->getNumIntParameters();
995 return Type->getIntParameter(
Idx);
1007 switch(
unwrap(Val)->getValueID()) {
1009#define HANDLE_VALUE(Name) \
1010 case Value::Name##Val: \
1011 return LLVM##Name##ValueKind;
1012#include "llvm/IR/Value.def"
1020 *
Length = V->getName().size();
1021 return V->getName().data();
1047 os <<
"Printing <null> Value";
1051 return strdup(buf.c_str());
1065 os <<
"Printing <null> DbgRecord";
1069 return strdup(buf.c_str());
1077 return unwrap<Instruction>(Inst)->hasMetadata();
1081 auto *
I = unwrap<Instruction>(Inst);
1082 assert(
I &&
"Expected instruction");
1083 if (
auto *MD =
I->getMetadata(KindID))
1093 assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
1094 "Expected a metadata node or a canonicalized constant");
1096 if (
MDNode *
N = dyn_cast<MDNode>(MD))
1105 unwrap<Instruction>(Inst)->setMetadata(KindID,
N);
1123 for (
unsigned i = 0; i < MVEs.
size(); ++i) {
1124 const auto &ModuleFlag = MVEs[i];
1125 Result[i].Kind = ModuleFlag.first;
1126 Result[i].Metadata =
wrap(ModuleFlag.second);
1128 *NumEntries = MVEs.
size();
1134 size_t *NumEntries) {
1137 unwrap<Instruction>(
Value)->getAllMetadata(Entries);
1143#define LLVM_DEFINE_VALUE_CAST(name) \
1144 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
1145 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
1151 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1152 if (isa<MDNode>(MD->getMetadata()) ||
1153 isa<ValueAsMetadata>(MD->getMetadata()))
1159 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1160 if (isa<ValueAsMetadata>(MD->getMetadata()))
1166 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1167 if (isa<MDString>(MD->getMetadata()))
1176 if (
I == V->use_end())
1203 if (
auto *
C = dyn_cast<ConstantAsMetadata>(
Op))
1204 return wrap(
C->getValue());
1210 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
1211 if (
auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1212 assert(Index == 0 &&
"Function-local metadata can only have one operand");
1213 return wrap(L->getValue());
1216 cast<MDNode>(MD->getMetadata()), Index);
1219 return wrap(cast<User>(V)->getOperand(Index));
1224 return wrap(&cast<User>(V)->getOperandUse(Index));
1228 unwrap<User>(Val)->setOperand(Index,
unwrap(
Op));
1233 if (isa<MetadataAsValue>(V))
1236 return cast<User>(V)->getNumOperands();
1258 return isa<Constant>(
unwrap(Ty));
1263 return C->isNullValue();
1268 return isa<UndefValue>(
unwrap(Val));
1272 return isa<PoisonValue>(
unwrap(Val));
1306 for (
auto *OV :
ArrayRef(Vals, Count)) {
1311 else if (
auto *
C = dyn_cast<Constant>(V))
1313 else if (
auto *MDV = dyn_cast<MetadataAsValue>(V)) {
1314 MD = MDV->getMetadata();
1315 assert(!isa<LocalAsMetadata>(MD) &&
"Unexpected function-local metadata "
1316 "outside of direct argument to call");
1320 "Expected only one operand to function-local metadata");
1339 if (
auto *
C = dyn_cast<Constant>(V))
1341 if (
auto *MAV = dyn_cast<MetadataAsValue>(V))
1342 return wrap(MAV->getMetadata());
1347 if (
const auto *MD = dyn_cast<MetadataAsValue>(
unwrap(V)))
1348 if (
const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
1349 *
Length = S->getString().size();
1350 return S->getString().data();
1357 auto *MD = unwrap<MetadataAsValue>(V);
1358 if (isa<ValueAsMetadata>(MD->getMetadata()))
1360 return cast<MDNode>(MD->getMetadata())->getNumOperands();
1366 if (
I ==
Mod->named_metadata_end())
1374 if (
I ==
Mod->named_metadata_begin())
1396 const char *
Name,
size_t NameLen) {
1401 const char *
Name,
size_t NameLen) {
1402 return wrap(
unwrap(M)->getOrInsertNamedMetadata({
Name, NameLen}));
1412 auto *MD = unwrap<MetadataAsValue>(V);
1413 if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1414 *Dest =
wrap(MDV->getValue());
1417 const auto *
N = cast<MDNode>(MD->getMetadata());
1418 const unsigned numOperands =
N->getNumOperands();
1420 for (
unsigned i = 0; i < numOperands; i++)
1426 auto *MD = cast<MetadataAsValue>(
unwrap(V));
1427 auto *
N = cast<MDNode>(MD->getMetadata());
1428 N->replaceOperandWith(Index, unwrap<Metadata>(Replacement));
1433 return N->getNumOperands();
1444 for (
unsigned i=0;i<
N->getNumOperands();i++)
1459 if (!
Length)
return nullptr;
1461 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1462 if (
const auto &
DL =
I->getDebugLoc()) {
1463 S =
DL->getDirectory();
1465 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1467 GV->getDebugInfo(GVEs);
1470 S = DGV->getDirectory();
1471 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1473 S = DSP->getDirectory();
1475 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1483 if (!
Length)
return nullptr;
1485 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1486 if (
const auto &
DL =
I->getDebugLoc()) {
1487 S =
DL->getFilename();
1489 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1491 GV->getDebugInfo(GVEs);
1494 S = DGV->getFilename();
1495 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1497 S = DSP->getFilename();
1499 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1508 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1509 if (
const auto &
DL =
I->getDebugLoc()) {
1512 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1514 GV->getDebugInfo(GVEs);
1518 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1522 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1530 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val)))
1531 if (
const auto &
DL =
I->getDebugLoc())
1532 C =
DL->getColumn();
1540 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy),
N, SignExtend != 0));
1547 return wrap(ConstantInt::get(
1553 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy),
StringRef(Str),
1558 unsigned SLen,
uint8_t Radix) {
1559 return wrap(ConstantInt::get(unwrap<IntegerType>(IntTy),
StringRef(Str, SLen),
1577 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
1581 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
1585 ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
1596 APF.
convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &APFLosesInfo);
1597 *LosesInfo = APFLosesInfo;
1609 DontNullTerminate == 0));
1618 DontNullTerminate == 0));
1628 return wrap(unwrap<Constant>(
C)->getAggregateElement(
Idx));
1632 return wrap(unwrap<ConstantDataSequential>(
C)->getElementAsConstant(idx));
1636 return unwrap<ConstantDataSequential>(
C)->isString();
1640 StringRef Str = unwrap<ConstantDataSequential>(
C)->getAsString();
1660 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1674 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1675 StructType *Ty = unwrap<StructType>(StructTy);
1688 unwrap<Constant>(
Ptr), unwrap<ConstantInt>(Key),
1689 unwrap<ConstantInt>(Disc), unwrap<Constant>(AddrDisc)));
1698#define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1699#include "llvm/IR/Instruction.def"
1707#define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1708#include "llvm/IR/Instruction.def"
1773 unwrap<Constant>(RHSConstant)));
1779 unwrap<Constant>(RHSConstant)));
1785 unwrap<Constant>(RHSConstant)));
1790 unwrap<Constant>(RHSConstant)));
1796 unwrap<Constant>(RHSConstant)));
1802 unwrap<Constant>(RHSConstant)));
1807 unwrap<Constant>(RHSConstant)));
1813 unwrap<Constant>(RHSConstant)));
1819 unwrap<Constant>(RHSConstant)));
1824 unwrap<Constant>(RHSConstant)));
1831 Constant *Val = unwrap<Constant>(ConstantVal);
1837 unsigned NumIndices) {
1840 Constant *Val = unwrap<Constant>(ConstantVal);
1847 unsigned NumIndices,
1851 Constant *Val = unwrap<Constant>(ConstantVal);
1897 unwrap<Constant>(IndexConstant)));
1904 unwrap<Constant>(ElementValueConstant),
1905 unwrap<Constant>(IndexConstant)));
1914 unwrap<Constant>(VectorBConstant),
1919 const char *Constraints,
1923 Constraints, HasSideEffects, IsAlignStack));
1935 return wrap(unwrap<BlockAddress>(BlockAddr)->getBasicBlock());
1945 return unwrap<GlobalValue>(
Global)->isDeclaration();
1949 switch (unwrap<GlobalValue>(
Global)->getLinkage()) {
1995 errs() <<
"LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1996 "longer supported.");
2022 <<
"LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
2027 <<
"LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
2034 errs() <<
"LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
2045 return unwrap<GlobalValue>(
Global)->getSection().data();
2049 unwrap<GlobalObject>(
Global)->setSection(Section);
2054 unwrap<GlobalValue>(
Global)->getVisibility());
2058 unwrap<GlobalValue>(
Global)
2064 unwrap<GlobalValue>(
Global)->getDLLStorageClass());
2068 unwrap<GlobalValue>(
Global)->setDLLStorageClass(
2073 switch (unwrap<GlobalValue>(
Global)->getUnnamedAddr()) {
2074 case GlobalVariable::UnnamedAddr::None:
2076 case GlobalVariable::UnnamedAddr::Local:
2078 case GlobalVariable::UnnamedAddr::Global:
2087 switch (UnnamedAddr) {
2098 return unwrap<GlobalValue>(
Global)->hasGlobalUnnamedAddr();
2102 unwrap<GlobalValue>(
Global)->setUnnamedAddr(
2103 HasUnnamedAddr ? GlobalValue::UnnamedAddr::Global
2104 : GlobalValue::UnnamedAddr::None);
2116 return GV->getAlign() ? GV->getAlign()->value() : 0;
2118 return AI->getAlign().value();
2119 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2120 return LI->getAlign().value();
2122 return SI->getAlign().value();
2124 return RMWI->getAlign().value();
2126 return CXI->getAlign().value();
2129 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, "
2130 "and AtomicCmpXchgInst have alignment");
2137 else if (
AllocaInst *AI = dyn_cast<AllocaInst>(
P))
2138 AI->setAlignment(
Align(Bytes));
2139 else if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2140 LI->setAlignment(
Align(Bytes));
2141 else if (
StoreInst *SI = dyn_cast<StoreInst>(
P))
2142 SI->setAlignment(
Align(Bytes));
2144 RMWI->setAlignment(
Align(Bytes));
2146 CXI->setAlignment(
Align(Bytes));
2149 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, and "
2150 "and AtomicCmpXchgInst have alignment");
2154 size_t *NumEntries) {
2158 Instr->getAllMetadata(Entries);
2160 unwrap<GlobalObject>(
Value)->getAllMetadata(Entries);
2186 unwrap<GlobalObject>(
Global)->setMetadata(Kind, unwrap<MDNode>(MD));
2190 unwrap<GlobalObject>(
Global)->eraseMetadata(Kind);
2194 unwrap<GlobalObject>(
Global)->clearMetadata();
2209 nullptr, GlobalVariable::NotThreadLocal,
2225 if (
I ==
Mod->global_end())
2233 if (
I ==
Mod->global_begin())
2255 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
2266 unwrap<GlobalVariable>(GlobalVar)->setInitializer(
2267 ConstantVal ? unwrap<Constant>(ConstantVal) :
nullptr);
2271 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
2275 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
2279 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
2283 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
2287 switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
2288 case GlobalVariable::NotThreadLocal:
2290 case GlobalVariable::GeneralDynamicTLSModel:
2292 case GlobalVariable::LocalDynamicTLSModel:
2294 case GlobalVariable::InitialExecTLSModel:
2296 case GlobalVariable::LocalExecTLSModel:
2326 return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
2330 unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
2340 unwrap<Constant>(Aliasee),
unwrap(M)));
2344 const char *
Name,
size_t NameLen) {
2351 if (
I ==
Mod->alias_end())
2359 if (
I ==
Mod->alias_begin())
2381 return wrap(unwrap<GlobalAlias>(Alias)->getAliasee());
2385 unwrap<GlobalAlias>(Alias)->setAliasee(unwrap<Constant>(Aliasee));
2408 if (
I ==
Mod->end())
2416 if (
I ==
Mod->begin())
2422 Function *Func = unwrap<Function>(Fn);
2424 if (++
I == Func->getParent()->end())
2430 Function *Func = unwrap<Function>(Fn);
2432 if (
I == Func->getParent()->begin())
2438 unwrap<Function>(Fn)->eraseFromParent();
2442 return unwrap<Function>(Fn)->hasPersonalityFn();
2446 return wrap(unwrap<Function>(Fn)->getPersonalityFn());
2450 unwrap<Function>(Fn)->setPersonalityFn(
2451 PersonalityFn ? unwrap<Constant>(PersonalityFn) :
nullptr);
2456 return F->getIntrinsicID();
2461 assert(
ID < llvm::Intrinsic::num_intrinsics &&
"Intrinsic ID out of range");
2468 size_t ParamCount) {
2477 *NameLength = Str.size();
2489 size_t ParamCount,
size_t *NameLength) {
2493 *NameLength = Str.length();
2494 return strdup(Str.c_str());
2499 size_t ParamCount,
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();
2767 return wrap(
unwrap(Bundle)->inputs()[Index]);
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 auto I = Instr->DebugMarker->StoredDbgRecords.begin();
2980 if (
I == Instr->DebugMarker->StoredDbgRecords.end())
2987 auto I = Instr->DebugMarker->StoredDbgRecords.rbegin();
2988 if (
I == Instr->DebugMarker->StoredDbgRecords.rend())
2996 if (++
I ==
Record->getInstruction()->DebugMarker->StoredDbgRecords.end())
3004 if (
I ==
Record->getInstruction()->DebugMarker->StoredDbgRecords.begin())
3011 return FPI->arg_size();
3013 return unwrap<CallBase>(Instr)->arg_size();
3019 return unwrap<CallBase>(Instr)->getCallingConv();
3023 return unwrap<CallBase>(Instr)->setCallingConv(
3029 auto *Call = unwrap<CallBase>(Instr);
3032 Call->addAttributeAtIndex(
Idx, AlignAttr);
3037 unwrap<CallBase>(
C)->addAttributeAtIndex(
Idx,
unwrap(
A));
3042 auto *Call = unwrap<CallBase>(
C);
3043 auto AS = Call->getAttributes().getAttributes(
Idx);
3044 return AS.getNumAttributes();
3049 auto *Call = unwrap<CallBase>(
C);
3050 auto AS = Call->getAttributes().getAttributes(
Idx);
3058 return wrap(unwrap<CallBase>(
C)->getAttributeAtIndex(
3064 const char *K,
unsigned KLen) {
3066 unwrap<CallBase>(
C)->getAttributeAtIndex(
Idx,
StringRef(K, KLen)));
3075 const char *K,
unsigned KLen) {
3076 unwrap<CallBase>(
C)->removeAttributeAtIndex(
Idx,
StringRef(K, KLen));
3080 return wrap(unwrap<CallBase>(Instr)->getCalledOperand());
3084 return wrap(unwrap<CallBase>(Instr)->getFunctionType());
3088 return unwrap<CallBase>(
C)->getNumOperandBundles();
3100 return unwrap<CallInst>(Call)->isTailCall();
3104 unwrap<CallInst>(Call)->setTailCall(isTailCall);
3118 return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
3123 return wrap(CRI->getUnwindDest());
3125 return wrap(CSI->getUnwindDest());
3127 return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
3131 unwrap<InvokeInst>(Invoke)->setNormalDest(
unwrap(
B));
3136 return CRI->setUnwindDest(
unwrap(
B));
3138 return CSI->setUnwindDest(
unwrap(
B));
3140 unwrap<InvokeInst>(Invoke)->setUnwindDest(
unwrap(
B));
3144 return wrap(unwrap<CallBrInst>(CallBr)->getDefaultDest());
3148 return unwrap<CallBrInst>(CallBr)->getNumIndirectDests();
3152 return wrap(unwrap<CallBrInst>(CallBr)->getIndirectDest(
Idx));
3158 return unwrap<Instruction>(Term)->getNumSuccessors();
3162 return wrap(unwrap<Instruction>(Term)->getSuccessor(i));
3166 return unwrap<Instruction>(Term)->setSuccessor(i,
unwrap(
block));
3172 return unwrap<BranchInst>(Branch)->isConditional();
3176 return wrap(unwrap<BranchInst>(Branch)->getCondition());
3180 return unwrap<BranchInst>(Branch)->setCondition(
unwrap(
Cond));
3186 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
3192 return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
3198 return unwrap<GEPOperator>(
GEP)->isInBounds();
3202 return unwrap<GetElementPtrInst>(
GEP)->setIsInBounds(InBounds);
3206 return wrap(unwrap<GEPOperator>(
GEP)->getSourceElementType());
3223 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
3224 for (
unsigned I = 0;
I != Count; ++
I)
3229 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
3233 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
3237 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
3244 if (
auto *
GEP = dyn_cast<GEPOperator>(
I))
3245 return GEP->getNumIndices();
3246 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3247 return EV->getNumIndices();
3248 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3249 return IV->getNumIndices();
3251 "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
3256 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3257 return EV->getIndices().data();
3258 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3259 return IV->getIndices().data();
3261 "LLVMGetIndices applies only to extractvalue and insertvalue!");
3278 I.setHeadBit(BeforeDbgRecords);
3285 unwrap<Instruction>(Instr),
false);
3292 unwrap<Instruction>(Instr),
true);
3308 unwrap(Builder)->SetInsertPoint(BB);
3312 return wrap(
unwrap(Builder)->GetInsertBlock());
3316 unwrap(Builder)->ClearInsertionPoint();
3320 unwrap(Builder)->Insert(unwrap<Instruction>(Instr));
3325 unwrap(Builder)->Insert(unwrap<Instruction>(Instr),
Name);
3335 return wrap(
unwrap(Builder)->getCurrentDebugLocation().getAsMDNode());
3340 unwrap(Builder)->SetCurrentDebugLocation(
DebugLoc(unwrap<MDNode>(Loc)));
3347 L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) :
nullptr;
3354 Context,
unwrap(Builder)->getCurrentDebugLocation().getAsMDNode()));
3358 unwrap(Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
3362 unwrap(Builder)->AddMetadataToInst(unwrap<Instruction>(Inst));
3368 unwrap(Builder)->setDefaultFPMathTag(FPMathTag
3369 ? unwrap<MDNode>(FPMathTag)
3378 return wrap(
unwrap(Builder)->getDefaultFPMathTag());
3411 unsigned NumDests) {
3420 unsigned NumBundles,
const char *
Name) {
3423 for (
auto *Bundle :
ArrayRef(Bundles, NumBundles)) {
3429 unwrap<FunctionType>(Ty),
unwrap(Fn),
unwrap(DefaultDest),
3448 for (
auto *Bundle :
ArrayRef(Bundles, NumBundles)) {
3465 unwrap<Function>(PersFn));
3479 if (ParentPad ==
nullptr) {
3493 unsigned NumHandlers,
const char *
Name) {
3494 if (ParentPad ==
nullptr) {
3499 NumHandlers,
Name));
3504 return wrap(
unwrap(
B)->CreateCatchRet(unwrap<CatchPadInst>(CatchPad),
3510 return wrap(
unwrap(
B)->CreateCleanupRet(unwrap<CleanupPadInst>(CatchPad),
3520 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal),
unwrap(Dest));
3524 unwrap<IndirectBrInst>(IndirectBr)->addDestination(
unwrap(Dest));
3528 return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
3532 return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(
Idx));
3536 unwrap<LandingPadInst>(LandingPad)->addClause(unwrap<Constant>(
ClauseVal));
3540 return unwrap<LandingPadInst>(LandingPad)->isCleanup();
3544 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
3548 unwrap<CatchSwitchInst>(CatchSwitch)->addHandler(
unwrap(Dest));
3552 return unwrap<CatchSwitchInst>(CatchSwitch)->getNumHandlers();
3558 *Handlers++ =
wrap(
H);
3562 return wrap(unwrap<CatchPadInst>(CatchPad)->getCatchSwitch());
3566 unwrap<CatchPadInst>(CatchPad)
3567 ->setCatchSwitch(unwrap<CatchSwitchInst>(CatchSwitch));
3573 return wrap(unwrap<FuncletPadInst>(Funclet)->getArgOperand(i));
3577 unwrap<FuncletPadInst>(Funclet)->setArgOperand(i,
unwrap(
value));
3764 if (
auto *
I = dyn_cast<BinaryOperator>(Neg))
3765 I->setHasNoUnsignedWrap();
3778 Value *
P = unwrap<Value>(ArithInst);
3779 return cast<Instruction>(
P)->hasNoUnsignedWrap();
3783 Value *
P = unwrap<Value>(ArithInst);
3784 cast<Instruction>(
P)->setHasNoUnsignedWrap(HasNUW);