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,
char *Constraints,
465 size_t ConstraintsSize,
LLVMBool HasSideEffects,
480 HasSideEffects, IsAlignStack, AD, CanThrow));
545 return unwrap(Ty)->isSized();
563 os <<
"Printing <null> Type";
567 return strdup(buf.c_str());
617 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
684 return wrap(FunctionType::get(
unwrap(ReturnType), Tys, IsVarArg != 0));
688 return unwrap<FunctionType>(FunctionTy)->isVarArg();
692 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
696 return unwrap<FunctionType>(FunctionTy)->getNumParams();
701 for (
Type *
T : Ty->params())
727 if (!
Type->hasName())
729 return Type->getName().data();
735 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
739 return unwrap<StructType>(StructTy)->getNumElements();
743 StructType *Ty = unwrap<StructType>(StructTy);
749 StructType *Ty = unwrap<StructType>(StructTy);
754 return unwrap<StructType>(StructTy)->isPacked();
758 return unwrap<StructType>(StructTy)->isOpaque();
762 return unwrap<StructType>(StructTy)->isLiteral();
777 for (
auto *
T :
unwrap(Tp)->subtypes()) {
796 return unwrap(Ty)->isOpaquePointerTy();
809 auto *Ty =
unwrap(WrappedTy);
810 if (
auto *ATy = dyn_cast<ArrayType>(Ty))
811 return wrap(ATy->getElementType());
812 return wrap(cast<VectorType>(Ty)->getElementType());
816 return unwrap(Tp)->getNumContainedTypes();
820 return unwrap<ArrayType>(ArrayTy)->getNumElements();
824 return unwrap<ArrayType>(ArrayTy)->getNumElements();
828 return unwrap<PointerType>(
PointerTy)->getAddressSpace();
832 return unwrap<VectorType>(VectorTy)->getElementCount().getKnownMinValue();
863 unsigned TypeParamCount,
865 unsigned IntParamCount) {
881 switch(
unwrap(Val)->getValueID()) {
883#define HANDLE_VALUE(Name) \
884 case Value::Name##Val: \
885 return LLVM##Name##ValueKind;
886#include "llvm/IR/Value.def"
894 *
Length = V->getName().size();
895 return V->getName().data();
903 return unwrap(Val)->getName().data();
921 os <<
"Printing <null> Value";
925 return strdup(buf.c_str());
933 return unwrap<Instruction>(Inst)->hasMetadata();
937 auto *
I = unwrap<Instruction>(Inst);
938 assert(
I &&
"Expected instruction");
939 if (
auto *MD =
I->getMetadata(KindID))
949 assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
950 "Expected a metadata node or a canonicalized constant");
952 if (
MDNode *
N = dyn_cast<MDNode>(MD))
961 unwrap<Instruction>(Inst)->setMetadata(KindID,
N);
979 for (
unsigned i = 0; i < MVEs.
size(); ++i) {
980 const auto &ModuleFlag = MVEs[i];
981 Result[i].Kind = ModuleFlag.first;
982 Result[i].Metadata =
wrap(ModuleFlag.second);
984 *NumEntries = MVEs.
size();
990 size_t *NumEntries) {
993 unwrap<Instruction>(
Value)->getAllMetadata(Entries);
999#define LLVM_DEFINE_VALUE_CAST(name) \
1000 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
1001 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
1007 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1008 if (isa<MDNode>(MD->getMetadata()) ||
1009 isa<ValueAsMetadata>(MD->getMetadata()))
1015 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1016 if (isa<ValueAsMetadata>(MD->getMetadata()))
1022 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1023 if (isa<MDString>(MD->getMetadata()))
1032 if (
I == V->use_end())
1059 if (
auto *
C = dyn_cast<ConstantAsMetadata>(Op))
1060 return wrap(
C->getValue());
1066 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
1067 if (
auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1068 assert(
Index == 0 &&
"Function-local metadata can only have one operand");
1069 return wrap(L->getValue());
1072 cast<MDNode>(MD->getMetadata()),
Index);
1075 return wrap(cast<User>(V)->getOperand(
Index));
1080 return wrap(&cast<User>(V)->getOperandUse(
Index));
1089 if (isa<MetadataAsValue>(V))
1092 return cast<User>(V)->getNumOperands();
1114 return isa<Constant>(
unwrap(Ty));
1119 return C->isNullValue();
1124 return isa<UndefValue>(
unwrap(Val));
1128 return isa<PoisonValue>(
unwrap(Val));
1162 for (
auto *OV :
ArrayRef(Vals, Count)) {
1167 else if (
auto *
C = dyn_cast<Constant>(V))
1169 else if (
auto *MDV = dyn_cast<MetadataAsValue>(V)) {
1170 MD = MDV->getMetadata();
1171 assert(!isa<LocalAsMetadata>(MD) &&
"Unexpected function-local metadata "
1172 "outside of direct argument to call");
1176 "Expected only one operand to function-local metadata");
1195 if (
auto *
C = dyn_cast<Constant>(V))
1197 if (
auto *MAV = dyn_cast<MetadataAsValue>(V))
1198 return wrap(MAV->getMetadata());
1203 if (
const auto *MD = dyn_cast<MetadataAsValue>(
unwrap(V)))
1204 if (
const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
1205 *
Length = S->getString().size();
1206 return S->getString().data();
1213 auto *MD = unwrap<MetadataAsValue>(V);
1214 if (isa<ValueAsMetadata>(MD->getMetadata()))
1216 return cast<MDNode>(MD->getMetadata())->getNumOperands();
1252 const char *
Name,
size_t NameLen) {
1257 const char *
Name,
size_t NameLen) {
1258 return wrap(
unwrap(M)->getOrInsertNamedMetadata({
Name, NameLen}));
1268 auto *MD = unwrap<MetadataAsValue>(V);
1269 if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1270 *Dest =
wrap(MDV->getValue());
1273 const auto *
N = cast<MDNode>(MD->getMetadata());
1274 const unsigned numOperands =
N->getNumOperands();
1276 for (
unsigned i = 0; i < numOperands; i++)
1282 auto *MD = cast<MetadataAsValue>(
unwrap(V));
1283 auto *
N = cast<MDNode>(MD->getMetadata());
1284 N->replaceOperandWith(
Index, unwrap<Metadata>(Replacement));
1289 return N->getNumOperands();
1300 for (
unsigned i=0;i<
N->getNumOperands();i++)
1315 if (!
Length)
return nullptr;
1317 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1318 if (
const auto &
DL =
I->getDebugLoc()) {
1319 S =
DL->getDirectory();
1321 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1323 GV->getDebugInfo(GVEs);
1326 S = DGV->getDirectory();
1327 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1329 S = DSP->getDirectory();
1331 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1339 if (!
Length)
return nullptr;
1341 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1342 if (
const auto &
DL =
I->getDebugLoc()) {
1343 S =
DL->getFilename();
1345 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1347 GV->getDebugInfo(GVEs);
1350 S = DGV->getFilename();
1351 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1353 S = DSP->getFilename();
1355 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1364 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1365 if (
const auto &
DL =
I->getDebugLoc()) {
1368 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1370 GV->getDebugInfo(GVEs);
1374 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1378 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1386 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val)))
1387 if (
const auto &
DL =
I->getDebugLoc())
1388 C =
DL->getColumn();
1414 unsigned SLen, uint8_t Radix) {
1433 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
1437 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
1441 ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
1452 APF.
convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &APFLosesInfo);
1453 *LosesInfo = APFLosesInfo;
1465 DontNullTerminate == 0));
1475 return wrap(unwrap<Constant>(
C)->getAggregateElement(
Idx));
1479 return wrap(unwrap<ConstantDataSequential>(
C)->getElementAsConstant(idx));
1483 return unwrap<ConstantDataSequential>(
C)->isString();
1487 StringRef Str = unwrap<ConstantDataSequential>(
C)->getAsString();
1507 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1521 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1522 StructType *Ty = unwrap<StructType>(StructTy);
1538#define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1539#include "llvm/IR/Instruction.def"
1547#define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1548#include "llvm/IR/Instruction.def"
1587 unwrap<Constant>(RHSConstant)));
1593 unwrap<Constant>(RHSConstant)));
1599 unwrap<Constant>(RHSConstant)));
1604 unwrap<Constant>(RHSConstant)));
1610 unwrap<Constant>(RHSConstant)));
1616 unwrap<Constant>(RHSConstant)));
1621 unwrap<Constant>(RHSConstant)));
1627 unwrap<Constant>(RHSConstant)));
1633 unwrap<Constant>(RHSConstant)));
1638 unwrap<Constant>(RHSConstant)));
1643 unwrap<Constant>(RHSConstant)));
1648 unwrap<Constant>(RHSConstant)));
1654 unwrap<Constant>(LHSConstant),
1655 unwrap<Constant>(RHSConstant)));
1661 unwrap<Constant>(LHSConstant),
1662 unwrap<Constant>(RHSConstant)));
1667 unwrap<Constant>(RHSConstant)));
1672 unwrap<Constant>(RHSConstant)));
1677 unwrap<Constant>(RHSConstant)));
1684 Constant *Val = unwrap<Constant>(ConstantVal);
1690 unsigned NumIndices) {
1693 Constant *Val = unwrap<Constant>(ConstantVal);
1801 unwrap<Constant>(IndexConstant)));
1808 unwrap<Constant>(ElementValueConstant),
1809 unwrap<Constant>(IndexConstant)));
1818 unwrap<Constant>(VectorBConstant),
1823 const char *Constraints,
1827 Constraints, HasSideEffects, IsAlignStack));
1841 return unwrap<GlobalValue>(
Global)->isDeclaration();
1845 switch (unwrap<GlobalValue>(
Global)->getLinkage()) {
1891 errs() <<
"LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1892 "longer supported.");
1918 <<
"LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1923 <<
"LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1930 errs() <<
"LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1941 return unwrap<GlobalValue>(
Global)->getSection().data();
1945 unwrap<GlobalObject>(
Global)->setSection(Section);
1950 unwrap<GlobalValue>(
Global)->getVisibility());
1954 unwrap<GlobalValue>(
Global)
1960 unwrap<GlobalValue>(
Global)->getDLLStorageClass());
1964 unwrap<GlobalValue>(
Global)->setDLLStorageClass(
1969 switch (unwrap<GlobalValue>(
Global)->getUnnamedAddr()) {
1970 case GlobalVariable::UnnamedAddr::None:
1972 case GlobalVariable::UnnamedAddr::Local:
1974 case GlobalVariable::UnnamedAddr::Global:
1983 switch (UnnamedAddr) {
1994 return unwrap<GlobalValue>(
Global)->hasGlobalUnnamedAddr();
1998 unwrap<GlobalValue>(
Global)->setUnnamedAddr(
1999 HasUnnamedAddr ? GlobalValue::UnnamedAddr::Global
2000 : GlobalValue::UnnamedAddr::None);
2004 return wrap(unwrap<GlobalValue>(
Global)->getValueType());
2012 return GV->getAlign() ? GV->getAlign()->value() : 0;
2014 return AI->getAlign().value();
2015 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2016 return LI->getAlign().value();
2018 return SI->getAlign().value();
2020 return RMWI->getAlign().value();
2022 return CXI->getAlign().value();
2025 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, "
2026 "and AtomicCmpXchgInst have alignment");
2033 else if (
AllocaInst *AI = dyn_cast<AllocaInst>(
P))
2034 AI->setAlignment(
Align(Bytes));
2035 else if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2036 LI->setAlignment(
Align(Bytes));
2038 SI->setAlignment(
Align(Bytes));
2040 RMWI->setAlignment(
Align(Bytes));
2042 CXI->setAlignment(
Align(Bytes));
2045 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, and "
2046 "and AtomicCmpXchgInst have alignment");
2050 size_t *NumEntries) {
2054 Instr->getAllMetadata(Entries);
2056 unwrap<GlobalObject>(
Value)->getAllMetadata(Entries);
2082 unwrap<GlobalObject>(
Global)->setMetadata(Kind, unwrap<MDNode>(MD));
2086 unwrap<GlobalObject>(
Global)->eraseMetadata(Kind);
2090 unwrap<GlobalObject>(
Global)->clearMetadata();
2105 nullptr, GlobalVariable::NotThreadLocal,
2146 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
2157 unwrap<GlobalVariable>(GlobalVar)
2158 ->setInitializer(unwrap<Constant>(ConstantVal));
2162 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
2166 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
2170 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
2174 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
2178 switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
2179 case GlobalVariable::NotThreadLocal:
2181 case GlobalVariable::GeneralDynamicTLSModel:
2183 case GlobalVariable::LocalDynamicTLSModel:
2185 case GlobalVariable::InitialExecTLSModel:
2187 case GlobalVariable::LocalExecTLSModel:
2217 return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
2221 unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
2231 unwrap<Constant>(Aliasee),
unwrap(M)));
2235 const char *
Name,
size_t NameLen) {
2272 return wrap(unwrap<GlobalAlias>(Alias)->getAliasee());
2276 unwrap<GlobalAlias>(Alias)->setAliasee(unwrap<Constant>(Aliasee));
2308 Function *Func = unwrap<Function>(Fn);
2310 if (++
I == Func->getParent()->end())
2316 Function *Func = unwrap<Function>(Fn);
2318 if (
I == Func->getParent()->begin())
2324 unwrap<Function>(Fn)->eraseFromParent();
2328 return unwrap<Function>(Fn)->hasPersonalityFn();
2332 return wrap(unwrap<Function>(Fn)->getPersonalityFn());
2336 unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
2341 return F->getIntrinsicID();
2346 assert(
ID < llvm::Intrinsic::num_intrinsics &&
"Intrinsic ID out of range");
2353 size_t ParamCount) {
2362 *NameLength = Str.size();
2376 size_t *NameLength) {
2380 *NameLength = Str.length();
2381 return strdup(Str.c_str());
2387 size_t *NameLength) {
2391 *NameLength = Str.length();
2392 return strdup(Str.c_str());
2405 return unwrap<Function>(Fn)->getCallingConv();
2409 return unwrap<Function>(Fn)->setCallingConv(
2415 return F->hasGC()?
F->getGC().c_str() :
nullptr;
2428 unwrap<Function>(
F)->addAttributeAtIndex(
Idx,
unwrap(
A));
2432 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(
Idx);
2433 return AS.getNumAttributes();
2438 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(
Idx);
2446 return wrap(unwrap<Function>(
F)->getAttributeAtIndex(
2452 const char *K,
unsigned KLen) {
2454 unwrap<Function>(
F)->getAttributeAtIndex(
Idx,
StringRef(K, KLen)));
2463 const char *K,
unsigned KLen) {
2464 unwrap<Function>(
F)->removeAttributeAtIndex(
Idx,
StringRef(K, KLen));
2469 Function *Func = unwrap<Function>(Fn);
2471 Func->addFnAttr(Attr);
2479 return unwrap<Function>(FnRef)->arg_size();
2483 Function *Fn = unwrap<Function>(FnRef);
2485 *ParamRefs++ =
wrap(&
A);
2489 Function *Fn = unwrap<Function>(FnRef);
2498 Function *Func = unwrap<Function>(Fn);
2500 if (
I == Func->arg_end())
2506 Function *Func = unwrap<Function>(Fn);
2508 if (
I == Func->arg_begin())
2516 if (
A->getArgNo() + 1 >= Fn->
arg_size())
2523 if (
A->getArgNo() == 0)
2525 return wrap(&
A->getParent()->arg_begin()[
A->getArgNo() - 1]);
2536 const char *
Name,
size_t NameLen,
2546 const char *
Name,
size_t NameLen) {
2583 return wrap(unwrap<GlobalIFunc>(IFunc)->getResolver());
2587 unwrap<GlobalIFunc>(IFunc)->setResolver(unwrap<Constant>(
Resolver));
2591 unwrap<GlobalIFunc>(IFunc)->eraseFromParent();
2595 unwrap<GlobalIFunc>(IFunc)->removeFromParent();
2605 return isa<BasicBlock>(
unwrap(Val));
2609 return wrap(unwrap<BasicBlock>(Val));
2613 return unwrap(BB)->getName().data();
2625 return unwrap<Function>(FnRef)->size();
2629 Function *Fn = unwrap<Function>(FnRef);
2631 *BasicBlocksRefs++ =
wrap(&BB);
2635 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
2639 Function *Func = unwrap<Function>(Fn);
2641 if (
I == Func->end())
2647 Function *Func = unwrap<Function>(Fn);
2649 if (
I == Func->begin())
2657 if (++
I == Block->getParent()->end())
2665 if (
I == Block->getParent()->begin())
2679 assert(CurBB &&
"current insertion point is invalid!");
2685 unwrap<Function>(Fn)->insert(unwrap<Function>(Fn)->end(),
unwrap(BB));
2711 unwrap(BBRef)->eraseFromParent();
2715 unwrap(BBRef)->removeFromParent();
2735 if (
I == Block->end())
2743 if (
I == Block->begin())
2765 unwrap<Instruction>(Inst)->removeFromParent();
2769 unwrap<Instruction>(Inst)->eraseFromParent();
2773 unwrap<Instruction>(Inst)->deleteValue();
2780 if (CE->getOpcode() == Instruction::ICmp)
2789 if (CE->getOpcode() == Instruction::FCmp)
2802 return wrap(
C->clone());
2808 return (
I &&
I->isTerminator()) ?
wrap(
I) :
nullptr;
2813 return FPI->arg_size();
2815 return unwrap<CallBase>(Instr)->arg_size();
2821 return unwrap<CallBase>(Instr)->getCallingConv();
2825 return unwrap<CallBase>(Instr)->setCallingConv(
2831 auto *Call = unwrap<CallBase>(Instr);
2834 Call->addAttributeAtIndex(
Idx, AlignAttr);
2839 unwrap<CallBase>(
C)->addAttributeAtIndex(
Idx,
unwrap(
A));
2844 auto *Call = unwrap<CallBase>(
C);
2845 auto AS = Call->getAttributes().getAttributes(
Idx);
2846 return AS.getNumAttributes();
2851 auto *Call = unwrap<CallBase>(
C);
2852 auto AS = Call->getAttributes().getAttributes(
Idx);
2860 return wrap(unwrap<CallBase>(
C)->getAttributeAtIndex(
2866 const char *K,
unsigned KLen) {
2868 unwrap<CallBase>(
C)->getAttributeAtIndex(
Idx,
StringRef(K, KLen)));
2877 const char *K,
unsigned KLen) {
2878 unwrap<CallBase>(
C)->removeAttributeAtIndex(
Idx,
StringRef(K, KLen));
2882 return wrap(unwrap<CallBase>(Instr)->getCalledOperand());
2886 return wrap(unwrap<CallBase>(Instr)->getFunctionType());
2892 return unwrap<CallInst>(Call)->isTailCall();
2896 unwrap<CallInst>(Call)->setTailCall(isTailCall);
2902 return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
2907 return wrap(CRI->getUnwindDest());
2909 return wrap(CSI->getUnwindDest());
2911 return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
2915 unwrap<InvokeInst>(Invoke)->setNormalDest(
unwrap(
B));
2920 return CRI->setUnwindDest(
unwrap(
B));
2922 return CSI->setUnwindDest(
unwrap(
B));
2924 unwrap<InvokeInst>(Invoke)->setUnwindDest(
unwrap(
B));
2930 return unwrap<Instruction>(Term)->getNumSuccessors();
2934 return wrap(unwrap<Instruction>(Term)->getSuccessor(i));
2938 return unwrap<Instruction>(Term)->setSuccessor(i,
unwrap(
block));
2944 return unwrap<BranchInst>(Branch)->isConditional();
2948 return wrap(unwrap<BranchInst>(Branch)->getCondition());
2952 return unwrap<BranchInst>(Branch)->setCondition(
unwrap(
Cond));
2958 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
2964 return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
2970 return unwrap<GEPOperator>(
GEP)->isInBounds();
2974 return unwrap<GetElementPtrInst>(
GEP)->setIsInBounds(InBounds);
2978 return wrap(unwrap<GEPOperator>(
GEP)->getSourceElementType());
2985 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
2986 for (
unsigned I = 0;
I != Count; ++
I)
2991 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
2995 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(
Index));
2999 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(
Index));
3006 if (
auto *
GEP = dyn_cast<GEPOperator>(
I))
3007 return GEP->getNumIndices();
3008 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3009 return EV->getNumIndices();
3010 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3011 return IV->getNumIndices();
3013 "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
3018 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3019 return EV->getIndices().data();
3020 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3021 return IV->getIndices().data();
3023 "LLVMGetIndices applies only to extractvalue and insertvalue!");
3040 auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->
end();
3090 L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) :
nullptr;
3101 unwrap(
Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
3105 unwrap(
Builder)->AddMetadataToInst(unwrap<Instruction>(Inst));
3112 ? unwrap<MDNode>(FPMathTag)
3150 unsigned NumDests) {
3170 unwrap(
B)->GetInsertBlock()->getParent()->setPersonalityFn(
3171 unwrap<Function>(PersFn));
3185 if (ParentPad ==
nullptr) {
3199 unsigned NumHandlers,
const char *
Name) {
3200 if (ParentPad ==
nullptr) {
3205 NumHandlers,
Name));
3210 return wrap(
unwrap(
B)->CreateCatchRet(unwrap<CatchPadInst>(CatchPad),
3216 return wrap(
unwrap(
B)->CreateCleanupRet(unwrap<CleanupPadInst>(CatchPad),
3226 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal),
unwrap(Dest));
3230 unwrap<IndirectBrInst>(IndirectBr)->addDestination(
unwrap(Dest));
3234 return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
3238 return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(
Idx));
3242 unwrap<LandingPadInst>(LandingPad)->addClause(unwrap<Constant>(
ClauseVal));
3246 return unwrap<LandingPadInst>(LandingPad)->isCleanup();
3250 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
3254 unwrap<CatchSwitchInst>(CatchSwitch)->addHandler(
unwrap(Dest));
3258 return unwrap<CatchSwitchInst>(CatchSwitch)->getNumHandlers();
3264 *Handlers++ =
wrap(
H);
3268 return wrap(unwrap<CatchPadInst>(CatchPad)->getCatchSwitch());
3272 unwrap<CatchPadInst>(CatchPad)
3273 ->setCatchSwitch(unwrap<CatchSwitchInst>(CatchSwitch));
3279 return wrap(unwrap<FuncletPadInst>(Funclet)->getArgOperand(i));
3283 unwrap<FuncletPadInst>(Funclet)->setArgOperand(i,
unwrap(
value));
3455 ITy,
unwrap(Ty), AllocSize,
3456 nullptr,
nullptr,
"");
3466 ITy,
unwrap(Ty), AllocSize,
3467 unwrap(Val),
nullptr,
"");
3529 return AtomicOrdering::AcquireRelease;
3531 return AtomicOrdering::SequentiallyConsistent;
3544 case AtomicOrdering::AcquireRelease:
3546 case AtomicOrdering::SequentiallyConsistent:
3611 unsigned NumIndices,
const char *
Name) {
3618 unsigned NumIndices,
const char *
Name) {
3643 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3644 return LI->isVolatile();
3646 return SI->isVolatile();
3648 return AI->isVolatile();
3649 return cast<AtomicCmpXchgInst>(
P)->isVolatile();
3654 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3655 return LI->setVolatile(isVolatile);
3657 return SI->setVolatile(isVolatile);
3659 return AI->setVolatile(isVolatile);
3660 return cast<AtomicCmpXchgInst>(
P)->setVolatile(isVolatile);
3664 return unwrap<AtomicCmpXchgInst>(CmpXchgInst)->isWeak();
3668 return unwrap<AtomicCmpXchgInst>(CmpXchgInst)->setWeak(isWeak);
3674 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3675 O = LI->getOrdering();
3677 O =
SI->getOrdering();
3679 O = cast<AtomicRMWInst>(
P)->getOrdering();