42 #include <system_error>
46 #define DEBUG_TYPE "ir"
68 *Major = LLVM_VERSION_MAJOR;
70 *Minor = LLVM_VERSION_MINOR;
72 *Patch = LLVM_VERSION_PATCH;
78 return strdup(Message);
101 void *DiagnosticContext) {
102 unwrap(
C)->setDiagnosticHandlerCallBack(
110 unwrap(
C)->getDiagnosticHandlerCallBack());
114 return unwrap(
C)->getDiagnosticContext();
118 void *OpaqueHandle) {
121 unwrap(
C)->setYieldCallback(YieldCallback, OpaqueHandle);
125 return unwrap(
C)->shouldDiscardValueNames();
129 unwrap(
C)->setDiscardValueNames(Discard);
150 return Attribute::AttrKind::EndAttrKinds;
166 if (Attr.isEnumAttribute())
168 return Attr.getValueAsInt();
180 return wrap(Attr.getValueAsType());
184 const char *K,
unsigned KLength,
185 const char *V,
unsigned VLength) {
206 return Attr.isEnumAttribute() || Attr.isIntAttribute();
218 std::string MsgStorage;
231 switch(
unwrap(DI)->getSeverity()) {
265 auto &Str =
unwrap(
M)->getModuleIdentifier();
275 auto &Str =
unwrap(
M)->getSourceFileName();
286 return unwrap(
M)->getDataLayoutStr().c_str();
294 unwrap(
M)->setDataLayout(DataLayoutStr);
299 return unwrap(
M)->getTargetTriple().c_str();
320 return Module::ModFlagBehavior::Warning;
322 return Module::ModFlagBehavior::Require;
324 return Module::ModFlagBehavior::Override;
326 return Module::ModFlagBehavior::Append;
328 return Module::ModFlagBehavior::AppendUnique;
338 case Module::ModFlagBehavior::Warning:
340 case Module::ModFlagBehavior::Require:
342 case Module::ModFlagBehavior::Override:
344 case Module::ModFlagBehavior::Append:
346 case Module::ModFlagBehavior::AppendUnique:
355 unwrap(
M)->getModuleFlagsMetadata(MFEs);
359 for (
unsigned i = 0;
i < MFEs.size(); ++
i) {
360 const auto &ModuleFlag = MFEs[
i];
362 Result[
i].Key = ModuleFlag.Key->getString().data();
363 Result[
i].KeyLen = ModuleFlag.Key->getString().size();
364 Result[
i].Metadata =
wrap(ModuleFlag.Val);
383 unsigned Index,
size_t *Len) {
398 const char *
Key,
size_t KeyLen) {
403 const char *
Key,
size_t KeyLen,
417 char **ErrorMessage) {
421 *ErrorMessage = strdup(EC.message().c_str());
425 unwrap(
M)->print(dest,
nullptr);
430 std::string
E =
"Error printing to file: " + dest.
error().message();
431 *ErrorMessage = strdup(
E.c_str());
445 return strdup(buf.c_str());
462 auto &Str =
unwrap(
M)->getModuleInlineAsm();
468 size_t AsmStringSize,
char *Constraints,
469 size_t ConstraintsSize,
LLVMBool HasSideEffects,
484 HasSideEffects, IsAlignStack, AD, CanThrow));
549 return unwrap(Ty)->isSized();
567 os <<
"Printing <null> Type";
571 return strdup(buf.c_str());
621 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
692 return unwrap<FunctionType>(FunctionTy)->isVarArg();
696 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
700 return unwrap<FunctionType>(FunctionTy)->getNumParams();
731 if (!
Type->hasName())
733 return Type->getName().data();
739 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
743 return unwrap<StructType>(StructTy)->getNumElements();
747 StructType *Ty = unwrap<StructType>(StructTy);
753 StructType *Ty = unwrap<StructType>(StructTy);
758 return unwrap<StructType>(StructTy)->isPacked();
762 return unwrap<StructType>(StructTy)->isOpaque();
766 return unwrap<StructType>(StructTy)->isLiteral();
781 for (
auto *
T :
unwrap(Tp)->subtypes()) {
796 return unwrap(Ty)->isOpaquePointerTy();
809 auto *Ty =
unwrap(WrappedTy);
810 if (
auto *PTy = dyn_cast<PointerType>(Ty))
811 return wrap(PTy->getNonOpaquePointerElementType());
812 if (
auto *ATy = dyn_cast<ArrayType>(Ty))
813 return wrap(ATy->getElementType());
814 return wrap(cast<VectorType>(Ty)->getElementType());
818 return unwrap(Tp)->getNumContainedTypes();
822 return unwrap<ArrayType>(ArrayTy)->getNumElements();
826 return unwrap<PointerType>(
PointerTy)->getAddressSpace();
830 return unwrap<VectorType>(VectorTy)->getElementCount().getKnownMinValue();
861 unsigned TypeParamCount,
863 unsigned IntParamCount) {
879 switch(
unwrap(Val)->getValueID()) {
881 #define HANDLE_VALUE(Name) \
882 case Value::Name##Val: \
883 return LLVM##Name##ValueKind;
884 #include "llvm/IR/Value.def"
892 *
Length = V->getName().size();
893 return V->getName().data();
901 return unwrap(Val)->getName().data();
905 unwrap(Val)->setName(Name);
919 os <<
"Printing <null> Value";
923 return strdup(buf.c_str());
931 return unwrap<Instruction>(Inst)->hasMetadata();
935 auto *
I = unwrap<Instruction>(Inst);
936 assert(
I &&
"Expected instruction");
937 if (
auto *MD =
I->getMetadata(KindID))
947 assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
948 "Expected a metadata node or a canonicalized constant");
950 if (
MDNode *
N = dyn_cast<MDNode>(MD))
959 unwrap<Instruction>(Inst)->setMetadata(KindID,
N);
977 for (
unsigned i = 0;
i < MVEs.size(); ++
i) {
978 const auto &ModuleFlag = MVEs[
i];
979 Result[
i].Kind = ModuleFlag.first;
980 Result[
i].Metadata =
wrap(ModuleFlag.second);
982 *NumEntries = MVEs.size();
988 size_t *NumEntries) {
991 unwrap<Instruction>(
Value)->getAllMetadata(Entries);
997 #define LLVM_DEFINE_VALUE_CAST(name) \
998 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
999 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
1005 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1006 if (isa<MDNode>(MD->getMetadata()) ||
1007 isa<ValueAsMetadata>(MD->getMetadata()))
1013 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1014 if (isa<MDString>(MD->getMetadata()))
1050 if (
auto *
C = dyn_cast<ConstantAsMetadata>(
Op))
1051 return wrap(
C->getValue());
1057 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
1058 if (
auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1059 assert(
Index == 0 &&
"Function-local metadata can only have one operand");
1060 return wrap(L->getValue());
1063 cast<MDNode>(MD->getMetadata()),
Index);
1066 return wrap(cast<User>(V)->getOperand(
Index));
1071 return wrap(&cast<User>(V)->getOperandUse(
Index));
1080 if (isa<MetadataAsValue>(V))
1083 return cast<User>(V)->getNumOperands();
1105 return isa<Constant>(
unwrap(Ty));
1110 return C->isNullValue();
1115 return isa<UndefValue>(
unwrap(Val));
1119 return isa<PoisonValue>(
unwrap(Val));
1153 for (
auto *OV :
ArrayRef(Vals, Count)) {
1158 else if (
auto *
C = dyn_cast<Constant>(V))
1160 else if (
auto *MDV = dyn_cast<MetadataAsValue>(V)) {
1161 MD = MDV->getMetadata();
1162 assert(!isa<LocalAsMetadata>(MD) &&
"Unexpected function-local metadata "
1163 "outside of direct argument to call");
1167 "Expected only one operand to function-local metadata");
1186 if (
auto *
C = dyn_cast<Constant>(V))
1188 if (
auto *MAV = dyn_cast<MetadataAsValue>(V))
1189 return wrap(MAV->getMetadata());
1194 if (
const auto *MD = dyn_cast<MetadataAsValue>(
unwrap(V)))
1195 if (
const MDString *
S = dyn_cast<MDString>(MD->getMetadata())) {
1196 *
Length =
S->getString().size();
1197 return S->getString().data();
1204 auto *MD = unwrap<MetadataAsValue>(V);
1205 if (isa<ValueAsMetadata>(MD->getMetadata()))
1207 return cast<MDNode>(MD->getMetadata())->getNumOperands();
1243 const char *Name,
size_t NameLen) {
1248 const char *Name,
size_t NameLen) {
1249 return wrap(
unwrap(
M)->getOrInsertNamedMetadata({Name, NameLen}));
1259 auto *MD = unwrap<MetadataAsValue>(V);
1260 if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1261 *Dest =
wrap(MDV->getValue());
1264 const auto *
N = cast<MDNode>(MD->getMetadata());
1265 const unsigned numOperands =
N->getNumOperands();
1267 for (
unsigned i = 0;
i < numOperands;
i++)
1273 return N->getNumOperands();
1284 for (
unsigned i=0;
i<
N->getNumOperands();
i++)
1299 if (!
Length)
return nullptr;
1301 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1302 if (
const auto &
DL =
I->getDebugLoc()) {
1303 S =
DL->getDirectory();
1305 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1307 GV->getDebugInfo(GVEs);
1310 S = DGV->getDirectory();
1311 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1313 S = DSP->getDirectory();
1315 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1323 if (!
Length)
return nullptr;
1325 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1326 if (
const auto &
DL =
I->getDebugLoc()) {
1327 S =
DL->getFilename();
1329 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1331 GV->getDebugInfo(GVEs);
1334 S = DGV->getFilename();
1335 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1337 S = DSP->getFilename();
1339 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1348 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1349 if (
const auto &
DL =
I->getDebugLoc()) {
1352 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1354 GV->getDebugInfo(GVEs);
1358 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1362 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1370 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val)))
1371 if (
const auto &
DL =
I->getDebugLoc())
1372 C =
DL->getColumn();
1398 unsigned SLen, uint8_t Radix) {
1417 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
1421 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
1425 ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
1437 *LosesInfo = APFLosesInfo;
1449 DontNullTerminate == 0));
1459 return wrap(unwrap<Constant>(
C)->getAggregateElement(Idx));
1463 return wrap(unwrap<ConstantDataSequential>(
C)->getElementAsConstant(idx));
1467 return unwrap<ConstantDataSequential>(
C)->isString();
1471 StringRef Str = unwrap<ConstantDataSequential>(
C)->getAsString();
1485 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1499 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1500 StructType *Ty = unwrap<StructType>(StructTy);
1507 ArrayRef(unwrap<Constant>(ScalarConstantVals, Size), Size)));
1516 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1517 #include "llvm/IR/Instruction.def"
1525 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1526 #include "llvm/IR/Instruction.def"
1565 unwrap<Constant>(RHSConstant)));
1571 unwrap<Constant>(RHSConstant)));
1577 unwrap<Constant>(RHSConstant)));
1582 unwrap<Constant>(RHSConstant)));
1588 unwrap<Constant>(RHSConstant)));
1594 unwrap<Constant>(RHSConstant)));
1599 unwrap<Constant>(RHSConstant)));
1605 unwrap<Constant>(RHSConstant)));
1611 unwrap<Constant>(RHSConstant)));
1616 unwrap<Constant>(RHSConstant)));
1621 unwrap<Constant>(RHSConstant)));
1626 unwrap<Constant>(RHSConstant)));
1632 unwrap<Constant>(LHSConstant),
1633 unwrap<Constant>(RHSConstant)));
1639 unwrap<Constant>(LHSConstant),
1640 unwrap<Constant>(RHSConstant)));
1645 unwrap<Constant>(RHSConstant)));
1650 unwrap<Constant>(RHSConstant)));
1655 unwrap<Constant>(RHSConstant)));
1662 Constant *Val = unwrap<Constant>(ConstantVal);
1668 unsigned NumIndices) {
1671 Constant *Val = unwrap<Constant>(ConstantVal);
1780 unwrap<Constant>(ConstantIfTrue),
1781 unwrap<Constant>(ConstantIfFalse)));
1787 unwrap<Constant>(IndexConstant)));
1794 unwrap<Constant>(ElementValueConstant),
1795 unwrap<Constant>(IndexConstant)));
1804 unwrap<Constant>(VectorBConstant),
1809 const char *Constraints,
1813 Constraints, HasSideEffects, IsAlignStack));
1827 return unwrap<GlobalValue>(Global)->isDeclaration();
1831 switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1877 errs() <<
"LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1878 "longer supported.");
1904 <<
"LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1909 <<
"LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1916 errs() <<
"LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1927 return unwrap<GlobalValue>(Global)->getSection().data();
1931 unwrap<GlobalObject>(Global)->setSection(Section);
1936 unwrap<GlobalValue>(Global)->getVisibility());
1940 unwrap<GlobalValue>(Global)
1946 unwrap<GlobalValue>(Global)->getDLLStorageClass());
1950 unwrap<GlobalValue>(Global)->setDLLStorageClass(
1955 switch (unwrap<GlobalValue>(Global)->getUnnamedAddr()) {
1969 switch (UnnamedAddr) {
1980 return unwrap<GlobalValue>(Global)->hasGlobalUnnamedAddr();
1984 unwrap<GlobalValue>(Global)->setUnnamedAddr(
1990 return wrap(unwrap<GlobalValue>(Global)->getValueType());
1998 return GV->getAlign() ? GV->getAlign()->value() : 0;
2000 return AI->getAlign().value();
2001 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2002 return LI->getAlign().value();
2004 return SI->getAlign().value();
2006 return RMWI->getAlign().value();
2008 return CXI->getAlign().value();
2011 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, "
2012 "and AtomicCmpXchgInst have alignment");
2019 else if (
AllocaInst *AI = dyn_cast<AllocaInst>(
P))
2020 AI->setAlignment(
Align(Bytes));
2021 else if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2022 LI->setAlignment(
Align(Bytes));
2024 SI->setAlignment(
Align(Bytes));
2026 RMWI->setAlignment(
Align(Bytes));
2028 CXI->setAlignment(
Align(Bytes));
2031 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, and "
2032 "and AtomicCmpXchgInst have alignment");
2036 size_t *NumEntries) {
2040 Instr->getAllMetadata(Entries);
2042 unwrap<GlobalObject>(
Value)->getAllMetadata(Entries);
2068 unwrap<GlobalObject>(Global)->setMetadata(Kind, unwrap<MDNode>(MD));
2072 unwrap<GlobalObject>(Global)->eraseMetadata(Kind);
2076 unwrap<GlobalObject>(Global)->clearMetadata();
2132 unwrap<GlobalVariable>(
GlobalVar)->eraseFromParent();
2144 ->setInitializer(unwrap<Constant>(ConstantVal));
2148 return unwrap<GlobalVariable>(
GlobalVar)->isThreadLocal();
2152 unwrap<GlobalVariable>(
GlobalVar)->setThreadLocal(IsThreadLocal != 0);
2156 return unwrap<GlobalVariable>(
GlobalVar)->isConstant();
2160 unwrap<GlobalVariable>(
GlobalVar)->setConstant(IsConstant != 0);
2164 switch (unwrap<GlobalVariable>(
GlobalVar)->getThreadLocalMode()) {
2203 return unwrap<GlobalVariable>(
GlobalVar)->isExternallyInitialized();
2207 unwrap<GlobalVariable>(
GlobalVar)->setExternallyInitialized(IsExtInit);
2217 unwrap<Constant>(Aliasee),
unwrap(
M)));
2221 const char *Name,
size_t NameLen) {
2258 return wrap(unwrap<GlobalAlias>(Alias)->getAliasee());
2262 unwrap<GlobalAlias>(Alias)->setAliasee(unwrap<Constant>(Aliasee));
2294 Function *Func = unwrap<Function>(Fn);
2296 if (++
I == Func->getParent()->end())
2302 Function *Func = unwrap<Function>(Fn);
2304 if (
I == Func->getParent()->begin())
2310 unwrap<Function>(Fn)->eraseFromParent();
2314 return unwrap<Function>(Fn)->hasPersonalityFn();
2318 return wrap(unwrap<Function>(Fn)->getPersonalityFn());
2322 unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
2327 return F->getIntrinsicID();
2332 assert(
ID < llvm::Intrinsic::num_intrinsics &&
"Intrinsic ID out of range");
2339 size_t ParamCount) {
2348 *NameLength = Str.size();
2362 size_t *NameLength) {
2366 *NameLength = Str.length();
2367 return strdup(Str.c_str());
2373 size_t *NameLength) {
2377 *NameLength = Str.length();
2378 return strdup(Str.c_str());
2391 return unwrap<Function>(Fn)->getCallingConv();
2395 return unwrap<Function>(Fn)->setCallingConv(
2401 return F->hasGC()?
F->getGC().c_str() :
nullptr;
2414 unwrap<Function>(
F)->addAttributeAtIndex(Idx,
unwrap(A));
2418 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(Idx);
2419 return AS.getNumAttributes();
2424 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(Idx);
2432 return wrap(unwrap<Function>(
F)->getAttributeAtIndex(
2438 const char *K,
unsigned KLen) {
2440 unwrap<Function>(
F)->getAttributeAtIndex(Idx,
StringRef(K, KLen)));
2449 const char *K,
unsigned KLen) {
2450 unwrap<Function>(
F)->removeAttributeAtIndex(Idx,
StringRef(K, KLen));
2455 Function *Func = unwrap<Function>(Fn);
2457 Func->addFnAttr(Attr);
2465 return unwrap<Function>(FnRef)->arg_size();
2469 Function *Fn = unwrap<Function>(FnRef);
2471 *ParamRefs++ =
wrap(&A);
2475 Function *Fn = unwrap<Function>(FnRef);
2484 Function *Func = unwrap<Function>(Fn);
2486 if (
I == Func->arg_end())
2492 Function *Func = unwrap<Function>(Fn);
2494 if (
I == Func->arg_begin())
2502 if (A->getArgNo() + 1 >= Fn->
arg_size())
2509 if (A->getArgNo() == 0)
2511 return wrap(&A->getParent()->arg_begin()[A->getArgNo() - 1]);
2522 const char *Name,
size_t NameLen,
2532 const char *Name,
size_t NameLen) {
2569 return wrap(unwrap<GlobalIFunc>(IFunc)->getResolver());
2573 unwrap<GlobalIFunc>(IFunc)->setResolver(unwrap<Constant>(
Resolver));
2577 unwrap<GlobalIFunc>(IFunc)->eraseFromParent();
2581 unwrap<GlobalIFunc>(IFunc)->removeFromParent();
2591 return isa<BasicBlock>(
unwrap(Val));
2595 return wrap(unwrap<BasicBlock>(Val));
2599 return unwrap(
BB)->getName().data();
2611 return unwrap<Function>(FnRef)->size();
2615 Function *Fn = unwrap<Function>(FnRef);
2617 *BasicBlocksRefs++ =
wrap(&
BB);
2621 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
2625 Function *Func = unwrap<Function>(Fn);
2627 if (
I == Func->end())
2633 Function *Func = unwrap<Function>(Fn);
2635 if (
I == Func->begin())
2643 if (++
I == Block->getParent()->end())
2651 if (
I == Block->getParent()->begin())
2665 assert(CurBB &&
"current insertion point is invalid!");
2671 unwrap<Function>(Fn)->insert(unwrap<Function>(Fn)->
end(),
unwrap(
BB));
2697 unwrap(BBRef)->eraseFromParent();
2701 unwrap(BBRef)->removeFromParent();
2721 if (
I == Block->end())
2729 if (
I == Block->begin())
2751 unwrap<Instruction>(Inst)->removeFromParent();
2755 unwrap<Instruction>(Inst)->eraseFromParent();
2759 unwrap<Instruction>(Inst)->deleteValue();
2766 if (CE->getOpcode() == Instruction::ICmp)
2775 if (CE->getOpcode() == Instruction::FCmp)
2788 return wrap(
C->clone());
2794 return (
I &&
I->isTerminator()) ?
wrap(
I) :
nullptr;
2799 return FPI->arg_size();
2801 return unwrap<CallBase>(Instr)->arg_size();
2807 return unwrap<CallBase>(Instr)->getCallingConv();
2811 return unwrap<CallBase>(Instr)->setCallingConv(
2817 auto *Call = unwrap<CallBase>(Instr);
2820 Call->addAttributeAtIndex(Idx, AlignAttr);
2825 unwrap<CallBase>(
C)->addAttributeAtIndex(Idx,
unwrap(A));
2830 auto *Call = unwrap<CallBase>(
C);
2831 auto AS = Call->getAttributes().getAttributes(Idx);
2832 return AS.getNumAttributes();
2837 auto *Call = unwrap<CallBase>(
C);
2838 auto AS = Call->getAttributes().getAttributes(Idx);
2846 return wrap(unwrap<CallBase>(
C)->getAttributeAtIndex(
2852 const char *K,
unsigned KLen) {
2854 unwrap<CallBase>(
C)->getAttributeAtIndex(Idx,
StringRef(K, KLen)));
2863 const char *K,
unsigned KLen) {
2864 unwrap<CallBase>(
C)->removeAttributeAtIndex(Idx,
StringRef(K, KLen));
2868 return wrap(unwrap<CallBase>(Instr)->getCalledOperand());
2872 return wrap(unwrap<CallBase>(Instr)->getFunctionType());
2878 return unwrap<CallInst>(Call)->isTailCall();
2882 unwrap<CallInst>(Call)->setTailCall(isTailCall);
2888 return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
2893 return wrap(CRI->getUnwindDest());
2895 return wrap(CSI->getUnwindDest());
2897 return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
2901 unwrap<InvokeInst>(Invoke)->setNormalDest(
unwrap(
B));
2906 return CRI->setUnwindDest(
unwrap(
B));
2908 return CSI->setUnwindDest(
unwrap(
B));
2910 unwrap<InvokeInst>(Invoke)->setUnwindDest(
unwrap(
B));
2916 return unwrap<Instruction>(
Term)->getNumSuccessors();
2920 return wrap(unwrap<Instruction>(
Term)->getSuccessor(
i));
2930 return unwrap<BranchInst>(
Branch)->isConditional();
2934 return wrap(unwrap<BranchInst>(
Branch)->getCondition());
2944 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
2950 return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
2956 return unwrap<GEPOperator>(
GEP)->isInBounds();
2960 return unwrap<GetElementPtrInst>(
GEP)->setIsInBounds(InBounds);
2964 return wrap(unwrap<GEPOperator>(
GEP)->getSourceElementType());
2971 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
2972 for (
unsigned I = 0;
I != Count; ++
I)
2977 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
2981 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(
Index));
2985 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(
Index));
2992 if (
auto *
GEP = dyn_cast<GEPOperator>(
I))
2993 return GEP->getNumIndices();
2994 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
2995 return EV->getNumIndices();
2996 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
2997 return IV->getNumIndices();
2999 "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
3004 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3005 return EV->getIndices().data();
3006 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3007 return IV->getIndices().data();
3009 "LLVMGetIndices applies only to extractvalue and insertvalue!");
3026 auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() :
BB->end();
3076 L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) :
nullptr;
3087 unwrap(
Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
3091 unwrap(
Builder)->AddMetadataToInst(unwrap<Instruction>(Inst));
3098 ? unwrap<MDNode>(FPMathTag)
3136 unsigned NumDests) {
3156 unwrap(
B)->GetInsertBlock()->getParent()->setPersonalityFn(
3157 unwrap<Function>(PersFn));
3171 if (ParentPad ==
nullptr) {
3185 unsigned NumHandlers,
const char *Name) {
3186 if (ParentPad ==
nullptr) {
3191 NumHandlers, Name));
3196 return wrap(
unwrap(
B)->CreateCatchRet(unwrap<CatchPadInst>(CatchPad),
3202 return wrap(
unwrap(
B)->CreateCleanupRet(unwrap<CleanupPadInst>(CatchPad),
3212 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal),
unwrap(Dest));
3216 unwrap<IndirectBrInst>(IndirectBr)->addDestination(
unwrap(Dest));
3220 return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
3224 return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(Idx));
3228 unwrap<LandingPadInst>(LandingPad)->addClause(unwrap<Constant>(
ClauseVal));
3232 return unwrap<LandingPadInst>(LandingPad)->isCleanup();
3236 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
3240 unwrap<CatchSwitchInst>(CatchSwitch)->addHandler(
unwrap(Dest));
3244 return unwrap<CatchSwitchInst>(CatchSwitch)->getNumHandlers();
3250 *Handlers++ =
wrap(
H);
3254 return wrap(unwrap<CatchPadInst>(CatchPad)->getCatchSwitch());
3258 unwrap<CatchPadInst>(CatchPad)
3259 ->setCatchSwitch(unwrap<CatchSwitchInst>(CatchSwitch));
3265 return wrap(unwrap<FuncletPadInst>(Funclet)->getArgOperand(
i));
3269 unwrap<FuncletPadInst>(Funclet)->setArgOperand(
i,
unwrap(value));
3441 ITy,
unwrap(Ty), AllocSize,
3442 nullptr,
nullptr,
"");
3452 ITy,
unwrap(Ty), AllocSize,
3453 unwrap(Val),
nullptr,
"");
3587 LLVMBool isSingleThread,
const char *Name) {
3597 unsigned NumIndices,
const char *Name) {
3604 unsigned NumIndices,
const char *Name) {
3619 return wrap(
unwrap(
B)->CreateGlobalString(Str, Name));
3624 return wrap(
unwrap(
B)->CreateGlobalStringPtr(Str, Name));
3629 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3630 return LI->isVolatile();
3632 return SI->isVolatile();
3634 return AI->isVolatile();
3635 return cast<AtomicCmpXchgInst>(
P)->isVolatile();
3640 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3641 return LI->setVolatile(isVolatile);
3643 return SI->setVolatile(isVolatile);
3645 return AI->setVolatile(isVolatile);
3646 return cast<AtomicCmpXchgInst>(
P)->setVolatile(isVolatile);
3650 return unwrap<AtomicCmpXchgInst>(CmpXchgInst)->isWeak();
3654 return unwrap<AtomicCmpXchgInst>(CmpXchgInst)->setWeak(isWeak);
3660 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3661 O = LI->getOrdering();
3663 O =
SI->getOrdering();
3665 O = cast<AtomicRMWInst>(
P)->getOrdering();
3673 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3674 return LI->setOrdering(
O);
3675 return cast<StoreInst>(
P)->setOrdering(
O);
3803 unwrap(Src), SrcIsSigned,
unwrap(DestTy), DestIsSigned));
3869 unsigned Index,
const char *Name) {