42#include <system_error>
46#define DEBUG_TYPE "ir"
64 *Major = LLVM_VERSION_MAJOR;
66 *Minor = LLVM_VERSION_MINOR;
68 *Patch = LLVM_VERSION_PATCH;
74 return strdup(Message);
97 void *DiagnosticContext) {
98 unwrap(
C)->setDiagnosticHandlerCallBack(
106 unwrap(
C)->getDiagnosticHandlerCallBack());
110 return unwrap(
C)->getDiagnosticContext();
114 void *OpaqueHandle) {
117 unwrap(
C)->setYieldCallback(YieldCallback, OpaqueHandle);
121 return unwrap(
C)->shouldDiscardValueNames();
125 unwrap(
C)->setDiscardValueNames(Discard);
146 return Attribute::AttrKind::EndAttrKinds;
162 if (Attr.isEnumAttribute())
164 return Attr.getValueAsInt();
176 return wrap(Attr.getValueAsType());
180 const char *K,
unsigned KLength,
181 const char *V,
unsigned VLength) {
202 return Attr.isEnumAttribute() || Attr.isIntAttribute();
214 std::string MsgStorage;
227 switch(
unwrap(DI)->getSeverity()) {
261 auto &Str =
unwrap(M)->getModuleIdentifier();
271 auto &Str =
unwrap(M)->getSourceFileName();
282 return unwrap(M)->getDataLayoutStr().c_str();
290 unwrap(M)->setDataLayout(DataLayoutStr);
295 return unwrap(M)->getTargetTriple().c_str();
314 return Module::ModFlagBehavior::Error;
316 return Module::ModFlagBehavior::Warning;
318 return Module::ModFlagBehavior::Require;
320 return Module::ModFlagBehavior::Override;
322 return Module::ModFlagBehavior::Append;
324 return Module::ModFlagBehavior::AppendUnique;
332 case Module::ModFlagBehavior::Error:
334 case Module::ModFlagBehavior::Warning:
336 case Module::ModFlagBehavior::Require:
338 case Module::ModFlagBehavior::Override:
340 case Module::ModFlagBehavior::Append:
342 case Module::ModFlagBehavior::AppendUnique:
351 unwrap(M)->getModuleFlagsMetadata(MFEs);
355 for (
unsigned i = 0; i < MFEs.
size(); ++i) {
356 const auto &ModuleFlag = MFEs[i];
358 Result[i].Key = ModuleFlag.Key->getString().data();
359 Result[i].KeyLen = ModuleFlag.Key->getString().size();
360 Result[i].Metadata =
wrap(ModuleFlag.Val);
379 unsigned Index,
size_t *Len) {
394 const char *Key,
size_t KeyLen) {
395 return wrap(
unwrap(M)->getModuleFlag({Key, KeyLen}));
399 const char *Key,
size_t KeyLen,
402 {Key, KeyLen},
unwrap(Val));
413 char **ErrorMessage) {
417 *ErrorMessage = strdup(EC.message().c_str());
421 unwrap(M)->print(dest,
nullptr);
426 std::string
E =
"Error printing to file: " + dest.
error().message();
427 *ErrorMessage = strdup(
E.c_str());
438 unwrap(M)->print(os,
nullptr);
441 return strdup(buf.c_str());
458 auto &Str =
unwrap(M)->getModuleInlineAsm();
464 size_t AsmStringSize,
const char *Constraints,
465 size_t ConstraintsSize,
LLVMBool HasSideEffects,
480 HasSideEffects, IsAlignStack, AD, CanThrow));
485 Value *Val = unwrap<Value>(InlineAsmVal);
486 const std::string &AsmString = cast<InlineAsm>(Val)->getAsmString();
488 *Len = AsmString.length();
489 return AsmString.c_str();
494 Value *Val = unwrap<Value>(InlineAsmVal);
495 const std::string &ConstraintString =
496 cast<InlineAsm>(Val)->getConstraintString();
498 *Len = ConstraintString.length();
499 return ConstraintString.c_str();
504 Value *Val = unwrap<Value>(InlineAsmVal);
519 Value *Val = unwrap<Value>(InlineAsmVal);
520 return (
LLVMTypeRef)cast<InlineAsm>(Val)->getFunctionType();
524 Value *Val = unwrap<Value>(InlineAsmVal);
525 return cast<InlineAsm>(Val)->hasSideEffects();
529 Value *Val = unwrap<Value>(InlineAsmVal);
530 return cast<InlineAsm>(Val)->isAlignStack();
534 Value *Val = unwrap<Value>(InlineAsmVal);
535 return cast<InlineAsm>(Val)->canThrow();
600 return unwrap(Ty)->isSized();
618 os <<
"Printing <null> Type";
622 return strdup(buf.c_str());
672 return unwrap<IntegerType>(IntegerTy)->getBitWidth();
739 return wrap(FunctionType::get(
unwrap(ReturnType), Tys, IsVarArg != 0));
743 return unwrap<FunctionType>(FunctionTy)->isVarArg();
747 return wrap(unwrap<FunctionType>(FunctionTy)->getReturnType());
751 return unwrap<FunctionType>(FunctionTy)->getNumParams();
756 for (
Type *
T : Ty->params())
782 if (!
Type->hasName())
784 return Type->getName().data();
790 unwrap<StructType>(StructTy)->setBody(Tys, Packed != 0);
794 return unwrap<StructType>(StructTy)->getNumElements();
798 StructType *Ty = unwrap<StructType>(StructTy);
804 StructType *Ty = unwrap<StructType>(StructTy);
809 return unwrap<StructType>(StructTy)->isPacked();
813 return unwrap<StructType>(StructTy)->isOpaque();
817 return unwrap<StructType>(StructTy)->isLiteral();
832 for (
auto *
T :
unwrap(Tp)->subtypes()) {
864 auto *Ty =
unwrap(WrappedTy);
865 if (
auto *ATy = dyn_cast<ArrayType>(Ty))
866 return wrap(ATy->getElementType());
867 return wrap(cast<VectorType>(Ty)->getElementType());
871 return unwrap(Tp)->getNumContainedTypes();
875 return unwrap<ArrayType>(ArrayTy)->getNumElements();
879 return unwrap<ArrayType>(ArrayTy)->getNumElements();
883 return unwrap<PointerType>(
PointerTy)->getAddressSpace();
887 return unwrap<VectorType>(VectorTy)->getElementCount().getKnownMinValue();
918 unsigned TypeParamCount,
920 unsigned IntParamCount) {
936 switch(
unwrap(Val)->getValueID()) {
938#define HANDLE_VALUE(Name) \
939 case Value::Name##Val: \
940 return LLVM##Name##ValueKind;
941#include "llvm/IR/Value.def"
949 *
Length = V->getName().size();
950 return V->getName().data();
958 return unwrap(Val)->getName().data();
976 os <<
"Printing <null> Value";
980 return strdup(buf.c_str());
988 return unwrap<Instruction>(Inst)->hasMetadata();
992 auto *
I = unwrap<Instruction>(Inst);
993 assert(
I &&
"Expected instruction");
994 if (
auto *MD =
I->getMetadata(KindID))
1004 assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
1005 "Expected a metadata node or a canonicalized constant");
1007 if (
MDNode *
N = dyn_cast<MDNode>(MD))
1016 unwrap<Instruction>(Inst)->setMetadata(KindID,
N);
1034 for (
unsigned i = 0; i < MVEs.
size(); ++i) {
1035 const auto &ModuleFlag = MVEs[i];
1036 Result[i].Kind = ModuleFlag.first;
1037 Result[i].Metadata =
wrap(ModuleFlag.second);
1039 *NumEntries = MVEs.
size();
1045 size_t *NumEntries) {
1048 unwrap<Instruction>(
Value)->getAllMetadata(Entries);
1054#define LLVM_DEFINE_VALUE_CAST(name) \
1055 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
1056 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
1062 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1063 if (isa<MDNode>(MD->getMetadata()) ||
1064 isa<ValueAsMetadata>(MD->getMetadata()))
1070 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1071 if (isa<ValueAsMetadata>(MD->getMetadata()))
1077 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1078 if (isa<MDString>(MD->getMetadata()))
1087 if (
I == V->use_end())
1114 if (
auto *
C = dyn_cast<ConstantAsMetadata>(
Op))
1115 return wrap(
C->getValue());
1121 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
1122 if (
auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1123 assert(
Index == 0 &&
"Function-local metadata can only have one operand");
1124 return wrap(L->getValue());
1127 cast<MDNode>(MD->getMetadata()),
Index);
1130 return wrap(cast<User>(V)->getOperand(
Index));
1135 return wrap(&cast<User>(V)->getOperandUse(
Index));
1144 if (isa<MetadataAsValue>(V))
1147 return cast<User>(V)->getNumOperands();
1169 return isa<Constant>(
unwrap(Ty));
1174 return C->isNullValue();
1179 return isa<UndefValue>(
unwrap(Val));
1183 return isa<PoisonValue>(
unwrap(Val));
1217 for (
auto *OV :
ArrayRef(Vals, Count)) {
1222 else if (
auto *
C = dyn_cast<Constant>(V))
1224 else if (
auto *MDV = dyn_cast<MetadataAsValue>(V)) {
1225 MD = MDV->getMetadata();
1226 assert(!isa<LocalAsMetadata>(MD) &&
"Unexpected function-local metadata "
1227 "outside of direct argument to call");
1231 "Expected only one operand to function-local metadata");
1250 if (
auto *
C = dyn_cast<Constant>(V))
1252 if (
auto *MAV = dyn_cast<MetadataAsValue>(V))
1253 return wrap(MAV->getMetadata());
1258 if (
const auto *MD = dyn_cast<MetadataAsValue>(
unwrap(V)))
1259 if (
const MDString *S = dyn_cast<MDString>(MD->getMetadata())) {
1260 *
Length = S->getString().size();
1261 return S->getString().data();
1268 auto *MD = unwrap<MetadataAsValue>(V);
1269 if (isa<ValueAsMetadata>(MD->getMetadata()))
1271 return cast<MDNode>(MD->getMetadata())->getNumOperands();
1307 const char *
Name,
size_t NameLen) {
1312 const char *
Name,
size_t NameLen) {
1313 return wrap(
unwrap(M)->getOrInsertNamedMetadata({
Name, NameLen}));
1323 auto *MD = unwrap<MetadataAsValue>(V);
1324 if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1325 *Dest =
wrap(MDV->getValue());
1328 const auto *
N = cast<MDNode>(MD->getMetadata());
1329 const unsigned numOperands =
N->getNumOperands();
1331 for (
unsigned i = 0; i < numOperands; i++)
1337 auto *MD = cast<MetadataAsValue>(
unwrap(V));
1338 auto *
N = cast<MDNode>(MD->getMetadata());
1339 N->replaceOperandWith(
Index, unwrap<Metadata>(Replacement));
1344 return N->getNumOperands();
1355 for (
unsigned i=0;i<
N->getNumOperands();i++)
1370 if (!
Length)
return nullptr;
1372 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1373 if (
const auto &
DL =
I->getDebugLoc()) {
1374 S =
DL->getDirectory();
1376 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1378 GV->getDebugInfo(GVEs);
1381 S = DGV->getDirectory();
1382 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1384 S = DSP->getDirectory();
1386 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1394 if (!
Length)
return nullptr;
1396 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1397 if (
const auto &
DL =
I->getDebugLoc()) {
1398 S =
DL->getFilename();
1400 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1402 GV->getDebugInfo(GVEs);
1405 S = DGV->getFilename();
1406 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1408 S = DSP->getFilename();
1410 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1419 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1420 if (
const auto &
DL =
I->getDebugLoc()) {
1423 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1425 GV->getDebugInfo(GVEs);
1429 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1433 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1441 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val)))
1442 if (
const auto &
DL =
I->getDebugLoc())
1443 C =
DL->getColumn();
1469 unsigned SLen, uint8_t Radix) {
1488 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
1492 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
1496 ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
1507 APF.
convert(APFloat::IEEEdouble(), APFloat::rmNearestTiesToEven, &APFLosesInfo);
1508 *LosesInfo = APFLosesInfo;
1520 DontNullTerminate == 0));
1530 return wrap(unwrap<Constant>(
C)->getAggregateElement(
Idx));
1534 return wrap(unwrap<ConstantDataSequential>(
C)->getElementAsConstant(idx));
1538 return unwrap<ConstantDataSequential>(
C)->isString();
1542 StringRef Str = unwrap<ConstantDataSequential>(
C)->getAsString();
1562 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1576 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1577 StructType *Ty = unwrap<StructType>(StructTy);
1593#define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1594#include "llvm/IR/Instruction.def"
1602#define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1603#include "llvm/IR/Instruction.def"
1642 unwrap<Constant>(RHSConstant)));
1648 unwrap<Constant>(RHSConstant)));
1654 unwrap<Constant>(RHSConstant)));
1659 unwrap<Constant>(RHSConstant)));
1665 unwrap<Constant>(RHSConstant)));
1671 unwrap<Constant>(RHSConstant)));
1676 unwrap<Constant>(RHSConstant)));
1682 unwrap<Constant>(RHSConstant)));
1688 unwrap<Constant>(RHSConstant)));
1693 unwrap<Constant>(RHSConstant)));
1699 unwrap<Constant>(LHSConstant),
1700 unwrap<Constant>(RHSConstant)));
1706 unwrap<Constant>(LHSConstant),
1707 unwrap<Constant>(RHSConstant)));
1712 unwrap<Constant>(RHSConstant)));
1717 unwrap<Constant>(RHSConstant)));
1722 unwrap<Constant>(RHSConstant)));
1729 Constant *Val = unwrap<Constant>(ConstantVal);
1735 unsigned NumIndices) {
1738 Constant *Val = unwrap<Constant>(ConstantVal);
1846 unwrap<Constant>(IndexConstant)));
1853 unwrap<Constant>(ElementValueConstant),
1854 unwrap<Constant>(IndexConstant)));
1863 unwrap<Constant>(VectorBConstant),
1868 const char *Constraints,
1872 Constraints, HasSideEffects, IsAlignStack));
1886 return unwrap<GlobalValue>(
Global)->isDeclaration();
1890 switch (unwrap<GlobalValue>(
Global)->getLinkage()) {
1936 errs() <<
"LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1937 "longer supported.");
1963 <<
"LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1968 <<
"LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1975 errs() <<
"LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
1986 return unwrap<GlobalValue>(
Global)->getSection().data();
1990 unwrap<GlobalObject>(
Global)->setSection(Section);
1995 unwrap<GlobalValue>(
Global)->getVisibility());
1999 unwrap<GlobalValue>(
Global)
2005 unwrap<GlobalValue>(
Global)->getDLLStorageClass());
2009 unwrap<GlobalValue>(
Global)->setDLLStorageClass(
2014 switch (unwrap<GlobalValue>(
Global)->getUnnamedAddr()) {
2015 case GlobalVariable::UnnamedAddr::None:
2017 case GlobalVariable::UnnamedAddr::Local:
2019 case GlobalVariable::UnnamedAddr::Global:
2028 switch (UnnamedAddr) {
2039 return unwrap<GlobalValue>(
Global)->hasGlobalUnnamedAddr();
2043 unwrap<GlobalValue>(
Global)->setUnnamedAddr(
2044 HasUnnamedAddr ? GlobalValue::UnnamedAddr::Global
2045 : GlobalValue::UnnamedAddr::None);
2049 return wrap(unwrap<GlobalValue>(
Global)->getValueType());
2057 return GV->getAlign() ? GV->getAlign()->value() : 0;
2059 return AI->getAlign().value();
2060 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2061 return LI->getAlign().value();
2063 return SI->getAlign().value();
2065 return RMWI->getAlign().value();
2067 return CXI->getAlign().value();
2070 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, "
2071 "and AtomicCmpXchgInst have alignment");
2078 else if (
AllocaInst *AI = dyn_cast<AllocaInst>(
P))
2079 AI->setAlignment(
Align(Bytes));
2080 else if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2081 LI->setAlignment(
Align(Bytes));
2082 else if (
StoreInst *SI = dyn_cast<StoreInst>(
P))
2083 SI->setAlignment(
Align(Bytes));
2085 RMWI->setAlignment(
Align(Bytes));
2087 CXI->setAlignment(
Align(Bytes));
2090 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, and "
2091 "and AtomicCmpXchgInst have alignment");
2095 size_t *NumEntries) {
2099 Instr->getAllMetadata(Entries);
2101 unwrap<GlobalObject>(
Value)->getAllMetadata(Entries);
2127 unwrap<GlobalObject>(
Global)->setMetadata(Kind, unwrap<MDNode>(MD));
2131 unwrap<GlobalObject>(
Global)->eraseMetadata(Kind);
2135 unwrap<GlobalObject>(
Global)->clearMetadata();
2150 nullptr, GlobalVariable::NotThreadLocal,
2191 unwrap<GlobalVariable>(GlobalVar)->eraseFromParent();
2202 unwrap<GlobalVariable>(GlobalVar)
2203 ->setInitializer(unwrap<Constant>(ConstantVal));
2207 return unwrap<GlobalVariable>(GlobalVar)->isThreadLocal();
2211 unwrap<GlobalVariable>(GlobalVar)->setThreadLocal(IsThreadLocal != 0);
2215 return unwrap<GlobalVariable>(GlobalVar)->isConstant();
2219 unwrap<GlobalVariable>(GlobalVar)->setConstant(IsConstant != 0);
2223 switch (unwrap<GlobalVariable>(GlobalVar)->getThreadLocalMode()) {
2224 case GlobalVariable::NotThreadLocal:
2226 case GlobalVariable::GeneralDynamicTLSModel:
2228 case GlobalVariable::LocalDynamicTLSModel:
2230 case GlobalVariable::InitialExecTLSModel:
2232 case GlobalVariable::LocalExecTLSModel:
2262 return unwrap<GlobalVariable>(GlobalVar)->isExternallyInitialized();
2266 unwrap<GlobalVariable>(GlobalVar)->setExternallyInitialized(IsExtInit);
2276 unwrap<Constant>(Aliasee),
unwrap(M)));
2280 const char *
Name,
size_t NameLen) {
2317 return wrap(unwrap<GlobalAlias>(Alias)->getAliasee());
2321 unwrap<GlobalAlias>(Alias)->setAliasee(unwrap<Constant>(Aliasee));
2353 Function *Func = unwrap<Function>(Fn);
2355 if (++
I == Func->getParent()->end())
2361 Function *Func = unwrap<Function>(Fn);
2363 if (
I == Func->getParent()->begin())
2369 unwrap<Function>(Fn)->eraseFromParent();
2373 return unwrap<Function>(Fn)->hasPersonalityFn();
2377 return wrap(unwrap<Function>(Fn)->getPersonalityFn());
2381 unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
2386 return F->getIntrinsicID();
2391 assert(
ID < llvm::Intrinsic::num_intrinsics &&
"Intrinsic ID out of range");
2398 size_t ParamCount) {
2407 *NameLength = Str.size();
2421 size_t *NameLength) {
2425 *NameLength = Str.length();
2426 return strdup(Str.c_str());
2432 size_t *NameLength) {
2436 *NameLength = Str.length();
2437 return strdup(Str.c_str());
2450 return unwrap<Function>(Fn)->getCallingConv();
2454 return unwrap<Function>(Fn)->setCallingConv(
2460 return F->hasGC()?
F->getGC().c_str() :
nullptr;
2473 unwrap<Function>(
F)->addAttributeAtIndex(
Idx,
unwrap(
A));
2477 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(
Idx);
2478 return AS.getNumAttributes();
2483 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(
Idx);
2491 return wrap(unwrap<Function>(
F)->getAttributeAtIndex(
2497 const char *K,
unsigned KLen) {
2499 unwrap<Function>(
F)->getAttributeAtIndex(
Idx,
StringRef(K, KLen)));
2508 const char *K,
unsigned KLen) {
2509 unwrap<Function>(
F)->removeAttributeAtIndex(
Idx,
StringRef(K, KLen));
2514 Function *Func = unwrap<Function>(Fn);
2516 Func->addFnAttr(Attr);
2524 return unwrap<Function>(FnRef)->arg_size();
2528 Function *Fn = unwrap<Function>(FnRef);
2530 *ParamRefs++ =
wrap(&
A);
2534 Function *Fn = unwrap<Function>(FnRef);
2543 Function *Func = unwrap<Function>(Fn);
2545 if (
I == Func->arg_end())
2551 Function *Func = unwrap<Function>(Fn);
2553 if (
I == Func->arg_begin())
2561 if (
A->getArgNo() + 1 >= Fn->
arg_size())
2568 if (
A->getArgNo() == 0)
2570 return wrap(&
A->getParent()->arg_begin()[
A->getArgNo() - 1]);
2581 const char *
Name,
size_t NameLen,
2591 const char *
Name,
size_t NameLen) {
2628 return wrap(unwrap<GlobalIFunc>(IFunc)->getResolver());
2632 unwrap<GlobalIFunc>(IFunc)->setResolver(unwrap<Constant>(
Resolver));
2636 unwrap<GlobalIFunc>(IFunc)->eraseFromParent();
2640 unwrap<GlobalIFunc>(IFunc)->removeFromParent();
2650 return isa<BasicBlock>(
unwrap(Val));
2654 return wrap(unwrap<BasicBlock>(Val));
2658 return unwrap(BB)->getName().data();
2670 return unwrap<Function>(FnRef)->size();
2674 Function *Fn = unwrap<Function>(FnRef);
2676 *BasicBlocksRefs++ =
wrap(&BB);
2680 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
2684 Function *Func = unwrap<Function>(Fn);
2686 if (
I == Func->end())
2692 Function *Func = unwrap<Function>(Fn);
2694 if (
I == Func->begin())
2702 if (++
I ==
Block->getParent()->end())
2710 if (
I ==
Block->getParent()->begin())
2724 assert(CurBB &&
"current insertion point is invalid!");
2730 unwrap<Function>(Fn)->insert(unwrap<Function>(Fn)->end(),
unwrap(BB));
2756 unwrap(BBRef)->eraseFromParent();
2760 unwrap(BBRef)->removeFromParent();
2796 if (++
I == Instr->getParent()->end())
2804 if (
I == Instr->getParent()->begin())
2810 unwrap<Instruction>(Inst)->removeFromParent();
2814 unwrap<Instruction>(Inst)->eraseFromParent();
2818 unwrap<Instruction>(Inst)->deleteValue();
2825 if (CE->getOpcode() == Instruction::ICmp)
2834 if (CE->getOpcode() == Instruction::FCmp)
2847 return wrap(
C->clone());
2853 return (
I &&
I->isTerminator()) ?
wrap(
I) :
nullptr;
2858 return FPI->arg_size();
2860 return unwrap<CallBase>(Instr)->arg_size();
2866 return unwrap<CallBase>(Instr)->getCallingConv();
2870 return unwrap<CallBase>(Instr)->setCallingConv(
2876 auto *Call = unwrap<CallBase>(Instr);
2879 Call->addAttributeAtIndex(
Idx, AlignAttr);
2884 unwrap<CallBase>(
C)->addAttributeAtIndex(
Idx,
unwrap(
A));
2889 auto *Call = unwrap<CallBase>(
C);
2890 auto AS = Call->getAttributes().getAttributes(
Idx);
2891 return AS.getNumAttributes();
2896 auto *Call = unwrap<CallBase>(
C);
2897 auto AS = Call->getAttributes().getAttributes(
Idx);
2905 return wrap(unwrap<CallBase>(
C)->getAttributeAtIndex(
2911 const char *K,
unsigned KLen) {
2913 unwrap<CallBase>(
C)->getAttributeAtIndex(
Idx,
StringRef(K, KLen)));
2922 const char *K,
unsigned KLen) {
2923 unwrap<CallBase>(
C)->removeAttributeAtIndex(
Idx,
StringRef(K, KLen));
2927 return wrap(unwrap<CallBase>(Instr)->getCalledOperand());
2931 return wrap(unwrap<CallBase>(Instr)->getFunctionType());
2937 return unwrap<CallInst>(Call)->isTailCall();
2941 unwrap<CallInst>(Call)->setTailCall(isTailCall);
2955 return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
2960 return wrap(CRI->getUnwindDest());
2962 return wrap(CSI->getUnwindDest());
2964 return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
2968 unwrap<InvokeInst>(Invoke)->setNormalDest(
unwrap(
B));
2973 return CRI->setUnwindDest(
unwrap(
B));
2975 return CSI->setUnwindDest(
unwrap(
B));
2977 unwrap<InvokeInst>(Invoke)->setUnwindDest(
unwrap(
B));
2983 return unwrap<Instruction>(Term)->getNumSuccessors();
2987 return wrap(unwrap<Instruction>(Term)->getSuccessor(i));
2991 return unwrap<Instruction>(Term)->setSuccessor(i,
unwrap(
block));
2997 return unwrap<BranchInst>(Branch)->isConditional();
3001 return wrap(unwrap<BranchInst>(Branch)->getCondition());
3005 return unwrap<BranchInst>(Branch)->setCondition(
unwrap(
Cond));
3011 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
3017 return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
3023 return unwrap<GEPOperator>(
GEP)->isInBounds();
3027 return unwrap<GetElementPtrInst>(
GEP)->setIsInBounds(InBounds);
3031 return wrap(unwrap<GEPOperator>(
GEP)->getSourceElementType());
3038 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
3039 for (
unsigned I = 0;
I != Count; ++
I)
3044 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
3048 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(
Index));
3052 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(
Index));
3059 if (
auto *
GEP = dyn_cast<GEPOperator>(
I))
3060 return GEP->getNumIndices();
3061 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3062 return EV->getNumIndices();
3063 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3064 return IV->getNumIndices();
3066 "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
3071 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3072 return EV->getIndices().data();
3073 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3074 return IV->getIndices().data();
3076 "LLVMGetIndices applies only to extractvalue and insertvalue!");
3093 auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() : BB->
end();
3143 L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) :
nullptr;
3154 unwrap(
Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
3158 unwrap(
Builder)->AddMetadataToInst(unwrap<Instruction>(Inst));
3165 ? unwrap<MDNode>(FPMathTag)
3203 unsigned NumDests) {
3223 unwrap(
B)->GetInsertBlock()->getParent()->setPersonalityFn(
3224 unwrap<Function>(PersFn));
3238 if (ParentPad ==
nullptr) {
3252 unsigned NumHandlers,
const char *
Name) {
3253 if (ParentPad ==
nullptr) {
3258 NumHandlers,
Name));
3263 return wrap(
unwrap(
B)->CreateCatchRet(unwrap<CatchPadInst>(CatchPad),
3269 return wrap(
unwrap(
B)->CreateCleanupRet(unwrap<CleanupPadInst>(CatchPad),
3279 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal),
unwrap(Dest));
3283 unwrap<IndirectBrInst>(IndirectBr)->addDestination(
unwrap(Dest));
3287 return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
3291 return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(
Idx));
3295 unwrap<LandingPadInst>(LandingPad)->addClause(unwrap<Constant>(
ClauseVal));
3299 return unwrap<LandingPadInst>(LandingPad)->isCleanup();
3303 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
3307 unwrap<CatchSwitchInst>(CatchSwitch)->addHandler(
unwrap(Dest));
3311 return unwrap<CatchSwitchInst>(CatchSwitch)->getNumHandlers();
3317 *Handlers++ =
wrap(
H);
3321 return wrap(unwrap<CatchPadInst>(CatchPad)->getCatchSwitch());
3325 unwrap<CatchPadInst>(CatchPad)
3326 ->setCatchSwitch(unwrap<CatchSwitchInst>(CatchSwitch));
3332 return wrap(unwrap<FuncletPadInst>(Funclet)->getArgOperand(i));
3336 unwrap<FuncletPadInst>(Funclet)->setArgOperand(i,
unwrap(
value));
3501 Value *
P = unwrap<Value>(ArithInst);
3502 return cast<Instruction>(
P)->hasNoUnsignedWrap();
3506 Value *
P = unwrap<Value>(ArithInst);
3507 cast<Instruction>(
P)->setHasNoUnsignedWrap(HasNUW);
3511 Value *
P = unwrap<Value>(ArithInst);
3512 return cast<Instruction>(
P)->hasNoSignedWrap();
3516 Value *
P = unwrap<Value>(ArithInst);
3517 cast<Instruction>(
P)->setHasNoSignedWrap(HasNSW);
3521 Value *
P = unwrap<Value>(DivOrShrInst);
3522 return cast<Instruction>(
P)->isExact();
3526 Value *
P = unwrap<Value>(DivOrShrInst);
3527 cast<Instruction>(
P)->setIsExact(IsExact);
3607 return AtomicOrdering::AcquireRelease;
3609 return AtomicOrdering::SequentiallyConsistent;
3622 case AtomicOrdering::AcquireRelease:
3624 case AtomicOrdering::SequentiallyConsistent:
3689 unsigned NumIndices,
const char *
Name) {
3696 unsigned NumIndices,
const char *
Name) {