42 #include <system_error>
46 #define DEBUG_TYPE "ir"
67 return strdup(Message);
87 void *DiagnosticContext) {
88 unwrap(
C)->setDiagnosticHandlerCallBack(
96 unwrap(
C)->getDiagnosticHandlerCallBack());
100 return unwrap(
C)->getDiagnosticContext();
104 void *OpaqueHandle) {
107 unwrap(
C)->setYieldCallback(YieldCallback, OpaqueHandle);
111 return unwrap(
C)->shouldDiscardValueNames();
115 unwrap(
C)->setDiscardValueNames(Discard);
119 unwrap(
C)->setOpaquePointers(OpaquePointers);
140 return Attribute::AttrKind::EndAttrKinds;
148 if (AttrKind == Attribute::AttrKind::ByVal) {
154 if (AttrKind == Attribute::AttrKind::StructRet) {
168 if (Attr.isEnumAttribute())
170 return Attr.getValueAsInt();
182 return wrap(Attr.getValueAsType());
186 const char *K,
unsigned KLength,
187 const char *V,
unsigned VLength) {
208 return Attr.isEnumAttribute() || Attr.isIntAttribute();
220 std::string MsgStorage;
233 switch(
unwrap(DI)->getSeverity()) {
267 auto &Str =
unwrap(
M)->getModuleIdentifier();
277 auto &Str =
unwrap(
M)->getSourceFileName();
288 return unwrap(
M)->getDataLayoutStr().c_str();
296 unwrap(
M)->setDataLayout(DataLayoutStr);
301 return unwrap(
M)->getTargetTriple().c_str();
322 return Module::ModFlagBehavior::Warning;
324 return Module::ModFlagBehavior::Require;
326 return Module::ModFlagBehavior::Override;
328 return Module::ModFlagBehavior::Append;
330 return Module::ModFlagBehavior::AppendUnique;
340 case Module::ModFlagBehavior::Warning:
342 case Module::ModFlagBehavior::Require:
344 case Module::ModFlagBehavior::Override:
346 case Module::ModFlagBehavior::Append:
348 case Module::ModFlagBehavior::AppendUnique:
357 unwrap(
M)->getModuleFlagsMetadata(MFEs);
361 for (
unsigned i = 0;
i < MFEs.size(); ++
i) {
362 const auto &ModuleFlag = MFEs[
i];
364 Result[
i].Key = ModuleFlag.Key->getString().data();
365 Result[
i].KeyLen = ModuleFlag.Key->getString().size();
366 Result[
i].Metadata =
wrap(ModuleFlag.Val);
385 unsigned Index,
size_t *Len) {
400 const char *
Key,
size_t KeyLen) {
405 const char *
Key,
size_t KeyLen,
419 char **ErrorMessage) {
423 *ErrorMessage = strdup(EC.message().c_str());
427 unwrap(
M)->print(dest,
nullptr);
432 std::string
E =
"Error printing to file: " + dest.
error().message();
433 *ErrorMessage = strdup(
E.c_str());
447 return strdup(buf.c_str());
464 auto &Str =
unwrap(
M)->getModuleInlineAsm();
470 size_t AsmStringSize,
char *Constraints,
471 size_t ConstraintsSize,
LLVMBool HasSideEffects,
486 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<Type>(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();
868 switch(
unwrap(Val)->getValueID()) {
870 #define HANDLE_VALUE(Name) \
871 case Value::Name##Val: \
872 return LLVM##Name##ValueKind;
873 #include "llvm/IR/Value.def"
881 *Length = V->getName().size();
882 return V->getName().data();
890 return unwrap(Val)->getName().data();
908 os <<
"Printing <null> Value";
912 return strdup(buf.c_str());
920 return unwrap<Instruction>(Inst)->hasMetadata();
924 auto *
I = unwrap<Instruction>(Inst);
925 assert(
I &&
"Expected instruction");
926 if (
auto *MD =
I->getMetadata(KindID))
936 assert((isa<MDNode>(MD) || isa<ConstantAsMetadata>(MD)) &&
937 "Expected a metadata node or a canonicalized constant");
939 if (
MDNode *
N = dyn_cast<MDNode>(MD))
948 unwrap<Instruction>(Inst)->setMetadata(KindID,
N);
966 for (
unsigned i = 0;
i < MVEs.size(); ++
i) {
967 const auto &ModuleFlag = MVEs[
i];
968 Result[
i].Kind = ModuleFlag.first;
969 Result[
i].Metadata =
wrap(ModuleFlag.second);
971 *NumEntries = MVEs.size();
977 size_t *NumEntries) {
980 unwrap<Instruction>(
Value)->getAllMetadata(Entries);
986 #define LLVM_DEFINE_VALUE_CAST(name) \
987 LLVMValueRef LLVMIsA##name(LLVMValueRef Val) { \
988 return wrap(static_cast<Value*>(dyn_cast_or_null<name>(unwrap(Val)))); \
994 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
995 if (isa<MDNode>(MD->getMetadata()) ||
996 isa<ValueAsMetadata>(MD->getMetadata()))
1002 if (
auto *MD = dyn_cast_or_null<MetadataAsValue>(
unwrap(Val)))
1003 if (isa<MDString>(MD->getMetadata()))
1039 if (
auto *
C = dyn_cast<ConstantAsMetadata>(
Op))
1040 return wrap(
C->getValue());
1046 if (
auto *MD = dyn_cast<MetadataAsValue>(V)) {
1047 if (
auto *L = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1048 assert(Index == 0 &&
"Function-local metadata can only have one operand");
1049 return wrap(L->getValue());
1052 cast<MDNode>(MD->getMetadata()), Index);
1055 return wrap(cast<User>(V)->getOperand(Index));
1060 return wrap(&cast<User>(V)->getOperandUse(Index));
1064 unwrap<User>(Val)->setOperand(Index,
unwrap(
Op));
1069 if (isa<MetadataAsValue>(V))
1072 return cast<User>(V)->getNumOperands();
1094 return isa<Constant>(
unwrap(Ty));
1099 return C->isNullValue();
1104 return isa<UndefValue>(
unwrap(Val));
1108 return isa<PoisonValue>(
unwrap(Val));
1147 else if (
auto *
C = dyn_cast<Constant>(V))
1149 else if (
auto *MDV = dyn_cast<MetadataAsValue>(V)) {
1150 MD = MDV->getMetadata();
1151 assert(!isa<LocalAsMetadata>(MD) &&
"Unexpected function-local metadata "
1152 "outside of direct argument to call");
1156 "Expected only one operand to function-local metadata");
1175 if (
auto *
C = dyn_cast<Constant>(V))
1177 if (
auto *MAV = dyn_cast<MetadataAsValue>(V))
1178 return wrap(MAV->getMetadata());
1183 if (
const auto *MD = dyn_cast<MetadataAsValue>(
unwrap(V)))
1184 if (
const MDString *
S = dyn_cast<MDString>(MD->getMetadata())) {
1185 *Length =
S->getString().size();
1186 return S->getString().data();
1193 auto *MD = cast<MetadataAsValue>(
unwrap(V));
1194 if (isa<ValueAsMetadata>(MD->getMetadata()))
1196 return cast<MDNode>(MD->getMetadata())->getNumOperands();
1216 NamedMDNode *NamedNode = unwrap<NamedMDNode>(NMD);
1224 NamedMDNode *NamedNode = unwrap<NamedMDNode>(NMD);
1232 const char *
Name,
size_t NameLen) {
1237 const char *
Name,
size_t NameLen) {
1242 NamedMDNode *NamedNode = unwrap<NamedMDNode>(NMD);
1248 auto *MD = cast<MetadataAsValue>(
unwrap(V));
1249 if (
auto *MDV = dyn_cast<ValueAsMetadata>(MD->getMetadata())) {
1250 *Dest =
wrap(MDV->getValue());
1253 const auto *
N = cast<MDNode>(MD->getMetadata());
1254 const unsigned numOperands =
N->getNumOperands();
1256 for (
unsigned i = 0;
i < numOperands;
i++)
1262 return N->getNumOperands();
1273 for (
unsigned i=0;
i<
N->getNumOperands();
i++)
1288 if (!Length)
return nullptr;
1290 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1291 if (
const auto &
DL =
I->getDebugLoc()) {
1292 S =
DL->getDirectory();
1294 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1296 GV->getDebugInfo(GVEs);
1299 S = DGV->getDirectory();
1300 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1302 S = DSP->getDirectory();
1304 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1312 if (!Length)
return nullptr;
1314 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1315 if (
const auto &
DL =
I->getDebugLoc()) {
1316 S =
DL->getFilename();
1318 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1320 GV->getDebugInfo(GVEs);
1323 S = DGV->getFilename();
1324 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1326 S = DSP->getFilename();
1328 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1337 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val))) {
1338 if (
const auto &
DL =
I->getDebugLoc()) {
1341 }
else if (
const auto *GV = dyn_cast<GlobalVariable>(
unwrap(Val))) {
1343 GV->getDebugInfo(GVEs);
1347 }
else if (
const auto *
F = dyn_cast<Function>(
unwrap(Val))) {
1351 assert(0 &&
"Expected Instruction, GlobalVariable or Function");
1359 if (
const auto *
I = dyn_cast<Instruction>(
unwrap(Val)))
1360 if (
const auto &
DL =
I->getDebugLoc())
1361 C =
DL->getColumn();
1388 unsigned SLen, uint8_t Radix) {
1407 return unwrap<ConstantInt>(ConstantVal)->getZExtValue();
1411 return unwrap<ConstantInt>(ConstantVal)->getSExtValue();
1415 ConstantFP *cFP = unwrap<ConstantFP>(ConstantVal) ;
1427 *LosesInfo = APFLosesInfo;
1439 DontNullTerminate == 0));
1449 return wrap(unwrap<ConstantDataSequential>(
C)->getElementAsConstant(idx));
1453 return unwrap<ConstantDataSequential>(
C)->isString();
1457 StringRef Str = unwrap<ConstantDataSequential>(
C)->getAsString();
1458 *Length = Str.size();
1471 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1485 Constant **Elements = unwrap<Constant>(ConstantVals, Count);
1493 unwrap<Constant>(ScalarConstantVals, Size), Size)));
1502 #define HANDLE_INST(num, opc, clas) case num: return LLVM##opc;
1503 #include "llvm/IR/Instruction.def"
1511 #define HANDLE_INST(num, opc, clas) case LLVM##opc: return num;
1512 #include "llvm/IR/Instruction.def"
1555 unwrap<Constant>(RHSConstant)));
1561 unwrap<Constant>(RHSConstant)));
1567 unwrap<Constant>(RHSConstant)));
1572 unwrap<Constant>(RHSConstant)));
1577 unwrap<Constant>(RHSConstant)));
1583 unwrap<Constant>(RHSConstant)));
1589 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)));
1627 unwrap<Constant>(RHSConstant)));
1632 unwrap<Constant>(RHSConstant)));
1638 unwrap<Constant>(RHSConstant)));
1643 unwrap<Constant>(RHSConstant)));
1648 unwrap<Constant>(RHSConstant)));
1653 unwrap<Constant>(RHSConstant)));
1658 unwrap<Constant>(RHSConstant)));
1663 unwrap<Constant>(RHSConstant)));
1668 unwrap<Constant>(RHSConstant)));
1673 unwrap<Constant>(RHSConstant)));
1679 unwrap<Constant>(LHSConstant),
1680 unwrap<Constant>(RHSConstant)));
1686 unwrap<Constant>(LHSConstant),
1687 unwrap<Constant>(RHSConstant)));
1692 unwrap<Constant>(RHSConstant)));
1697 unwrap<Constant>(RHSConstant)));
1702 unwrap<Constant>(RHSConstant)));
1709 Constant *Val = unwrap<Constant>(ConstantVal);
1718 Constant *Val = unwrap<Constant>(ConstantVal);
1724 unsigned NumIndices) {
1727 Constant *Val = unwrap<Constant>(ConstantVal);
1734 unsigned NumIndices) {
1737 Constant *Val = unwrap<Constant>(ConstantVal);
1834 unwrap(ToType), isSigned));
1846 unwrap<Constant>(ConstantIfTrue),
1847 unwrap<Constant>(ConstantIfFalse)));
1853 unwrap<Constant>(IndexConstant)));
1860 unwrap<Constant>(ElementValueConstant),
1861 unwrap<Constant>(IndexConstant)));
1870 unwrap<Constant>(VectorBConstant),
1882 unsigned *IdxList,
unsigned NumIdx) {
1884 unwrap<Constant>(ElementValueConstant),
1889 const char *Constraints,
1893 Constraints, HasSideEffects, IsAlignStack));
1907 return unwrap<GlobalValue>(Global)->isDeclaration();
1911 switch (unwrap<GlobalValue>(Global)->getLinkage()) {
1957 errs() <<
"LLVMSetLinkage(): LLVMLinkOnceODRAutoHideLinkage is no "
1958 "longer supported.");
1984 <<
"LLVMSetLinkage(): LLVMDLLImportLinkage is no longer supported.");
1989 <<
"LLVMSetLinkage(): LLVMDLLExportLinkage is no longer supported.");
1996 errs() <<
"LLVMSetLinkage(): LLVMGhostLinkage is no longer supported.");
2007 return unwrap<GlobalValue>(Global)->getSection().data();
2011 unwrap<GlobalObject>(Global)->setSection(Section);
2016 unwrap<GlobalValue>(Global)->getVisibility());
2020 unwrap<GlobalValue>(Global)
2026 unwrap<GlobalValue>(Global)->getDLLStorageClass());
2030 unwrap<GlobalValue>(Global)->setDLLStorageClass(
2035 switch (unwrap<GlobalValue>(Global)->getUnnamedAddr()) {
2049 switch (UnnamedAddr) {
2060 return unwrap<GlobalValue>(Global)->hasGlobalUnnamedAddr();
2064 unwrap<GlobalValue>(Global)->setUnnamedAddr(
2070 return wrap(unwrap<GlobalValue>(Global)->getValueType());
2076 Value *
P = unwrap<Value>(V);
2078 return GV->getAlignment();
2080 return AI->getAlignment();
2081 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2082 return LI->getAlignment();
2084 return SI->getAlignment();
2086 return RMWI->getAlign().value();
2088 return CXI->getAlign().value();
2091 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, "
2092 "and AtomicCmpXchgInst have alignment");
2096 Value *
P = unwrap<Value>(V);
2099 else if (
AllocaInst *AI = dyn_cast<AllocaInst>(
P))
2100 AI->setAlignment(
Align(Bytes));
2101 else if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
2102 LI->setAlignment(
Align(Bytes));
2104 SI->setAlignment(
Align(Bytes));
2106 RMWI->setAlignment(
Align(Bytes));
2108 CXI->setAlignment(
Align(Bytes));
2111 "only GlobalValue, AllocaInst, LoadInst, StoreInst, AtomicRMWInst, and "
2112 "and AtomicCmpXchgInst have alignment");
2116 size_t *NumEntries) {
2120 Instr->getAllMetadata(Entries);
2122 unwrap<GlobalObject>(
Value)->getAllMetadata(Entries);
2148 unwrap<GlobalObject>(Global)->setMetadata(
Kind, unwrap<MDNode>(MD));
2152 unwrap<GlobalObject>(Global)->eraseMetadata(
Kind);
2156 unwrap<GlobalObject>(Global)->clearMetadata();
2212 unwrap<GlobalVariable>(
GlobalVar)->eraseFromParent();
2224 ->setInitializer(unwrap<Constant>(ConstantVal));
2228 return unwrap<GlobalVariable>(
GlobalVar)->isThreadLocal();
2232 unwrap<GlobalVariable>(
GlobalVar)->setThreadLocal(IsThreadLocal != 0);
2236 return unwrap<GlobalVariable>(
GlobalVar)->isConstant();
2240 unwrap<GlobalVariable>(
GlobalVar)->setConstant(IsConstant != 0);
2244 switch (unwrap<GlobalVariable>(
GlobalVar)->getThreadLocalMode()) {
2283 return unwrap<GlobalVariable>(
GlobalVar)->isExternallyInitialized();
2287 unwrap<GlobalVariable>(
GlobalVar)->setExternallyInitialized(IsExtInit);
2294 auto *PTy = cast<PointerType>(
unwrap(Ty));
2296 PTy->getAddressSpace(),
2298 unwrap<Constant>(Aliasee),
unwrap(
M)));
2306 unwrap<Constant>(Aliasee),
unwrap(
M)));
2310 const char *
Name,
size_t NameLen) {
2347 return wrap(unwrap<GlobalAlias>(Alias)->getAliasee());
2351 unwrap<GlobalAlias>(Alias)->setAliasee(unwrap<Constant>(Aliasee));
2383 Function *Func = unwrap<Function>(Fn);
2385 if (++
I == Func->getParent()->end())
2391 Function *Func = unwrap<Function>(Fn);
2393 if (
I == Func->getParent()->begin())
2399 unwrap<Function>(Fn)->eraseFromParent();
2403 return unwrap<Function>(Fn)->hasPersonalityFn();
2407 return wrap(unwrap<Function>(Fn)->getPersonalityFn());
2411 unwrap<Function>(Fn)->setPersonalityFn(unwrap<Constant>(PersonalityFn));
2416 return F->getIntrinsicID();
2421 assert(
ID < llvm::Intrinsic::num_intrinsics &&
"Intrinsic ID out of range");
2428 size_t ParamCount) {
2456 return strdup(Str.c_str());
2467 return strdup(Str.c_str());
2480 return unwrap<Function>(Fn)->getCallingConv();
2484 return unwrap<Function>(Fn)->setCallingConv(
2490 return F->hasGC()?
F->getGC().c_str() :
nullptr;
2503 unwrap<Function>(
F)->addAttributeAtIndex(Idx,
unwrap(A));
2507 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(Idx);
2508 return AS.getNumAttributes();
2513 auto AS = unwrap<Function>(
F)->getAttributes().getAttributes(Idx);
2521 return wrap(unwrap<Function>(
F)->getAttributeAtIndex(
2527 const char *K,
unsigned KLen) {
2529 unwrap<Function>(
F)->getAttributeAtIndex(Idx,
StringRef(K, KLen)));
2538 const char *K,
unsigned KLen) {
2539 unwrap<Function>(
F)->removeAttributeAtIndex(Idx,
StringRef(K, KLen));
2544 Function *Func = unwrap<Function>(Fn);
2546 Func->addFnAttr(Attr);
2554 return unwrap<Function>(FnRef)->arg_size();
2558 Function *Fn = unwrap<Function>(FnRef);
2560 *ParamRefs++ =
wrap(&A);
2564 Function *Fn = unwrap<Function>(FnRef);
2573 Function *Func = unwrap<Function>(Fn);
2575 if (
I == Func->arg_end())
2581 Function *Func = unwrap<Function>(Fn);
2583 if (
I == Func->arg_begin())
2591 if (A->getArgNo() + 1 >= Fn->
arg_size())
2598 if (A->getArgNo() == 0)
2600 return wrap(&A->getParent()->arg_begin()[A->getArgNo() - 1]);
2611 const char *
Name,
size_t NameLen,
2621 const char *
Name,
size_t NameLen) {
2658 return wrap(unwrap<GlobalIFunc>(IFunc)->getResolver());
2662 unwrap<GlobalIFunc>(IFunc)->setResolver(unwrap<Constant>(
Resolver));
2666 unwrap<GlobalIFunc>(IFunc)->eraseFromParent();
2670 unwrap<GlobalIFunc>(IFunc)->removeFromParent();
2680 return isa<BasicBlock>(
unwrap(Val));
2684 return wrap(unwrap<BasicBlock>(Val));
2688 return unwrap(
BB)->getName().data();
2700 return unwrap<Function>(FnRef)->size();
2704 Function *Fn = unwrap<Function>(FnRef);
2706 *BasicBlocksRefs++ =
wrap(&
BB);
2710 return wrap(&unwrap<Function>(Fn)->getEntryBlock());
2714 Function *Func = unwrap<Function>(Fn);
2716 if (
I == Func->end())
2722 Function *Func = unwrap<Function>(Fn);
2724 if (
I == Func->begin())
2732 if (++
I == Block->getParent()->end())
2740 if (
I == Block->getParent()->begin())
2754 assert(CurBB &&
"current insertion point is invalid!");
2761 unwrap<Function>(Fn)->getBasicBlockList().push_back(
unwrap(
BB));
2787 unwrap(BBRef)->eraseFromParent();
2791 unwrap(BBRef)->removeFromParent();
2811 if (
I == Block->end())
2819 if (
I == Block->begin())
2841 unwrap<Instruction>(Inst)->removeFromParent();
2845 unwrap<Instruction>(Inst)->eraseFromParent();
2852 if (CE->getOpcode() == Instruction::ICmp)
2861 if (CE->getOpcode() == Instruction::FCmp)
2874 return wrap(
C->clone());
2880 return (
I &&
I->isTerminator()) ?
wrap(
I) :
nullptr;
2885 return FPI->getNumArgOperands();
2887 return unwrap<CallBase>(Instr)->arg_size();
2893 return unwrap<CallBase>(Instr)->getCallingConv();
2897 return unwrap<CallBase>(Instr)->setCallingConv(
2903 auto *Call = unwrap<CallBase>(Instr);
2906 Call->addAttributeAtIndex(Idx, AlignAttr);
2911 unwrap<CallBase>(
C)->addAttributeAtIndex(Idx,
unwrap(A));
2916 auto *Call = unwrap<CallBase>(
C);
2917 auto AS = Call->getAttributes().getAttributes(Idx);
2918 return AS.getNumAttributes();
2923 auto *Call = unwrap<CallBase>(
C);
2924 auto AS = Call->getAttributes().getAttributes(Idx);
2932 return wrap(unwrap<CallBase>(
C)->getAttributeAtIndex(
2938 const char *K,
unsigned KLen) {
2940 unwrap<CallBase>(
C)->getAttributeAtIndex(Idx,
StringRef(K, KLen)));
2949 const char *K,
unsigned KLen) {
2950 unwrap<CallBase>(
C)->removeAttributeAtIndex(Idx,
StringRef(K, KLen));
2954 return wrap(unwrap<CallBase>(Instr)->getCalledOperand());
2958 return wrap(unwrap<CallBase>(Instr)->getFunctionType());
2964 return unwrap<CallInst>(Call)->isTailCall();
2968 unwrap<CallInst>(Call)->setTailCall(isTailCall);
2974 return wrap(unwrap<InvokeInst>(Invoke)->getNormalDest());
2979 return wrap(CRI->getUnwindDest());
2981 return wrap(CSI->getUnwindDest());
2983 return wrap(unwrap<InvokeInst>(Invoke)->getUnwindDest());
2987 unwrap<InvokeInst>(Invoke)->setNormalDest(
unwrap(
B));
2992 return CRI->setUnwindDest(
unwrap(
B));
2994 return CSI->setUnwindDest(
unwrap(
B));
2996 unwrap<InvokeInst>(Invoke)->setUnwindDest(
unwrap(
B));
3002 return unwrap<Instruction>(
Term)->getNumSuccessors();
3006 return wrap(unwrap<Instruction>(
Term)->getSuccessor(
i));
3016 return unwrap<BranchInst>(
Branch)->isConditional();
3020 return wrap(unwrap<BranchInst>(
Branch)->getCondition());
3030 return wrap(unwrap<SwitchInst>(Switch)->getDefaultDest());
3036 return wrap(unwrap<AllocaInst>(Alloca)->getAllocatedType());
3042 return unwrap<GEPOperator>(
GEP)->isInBounds();
3046 return unwrap<GetElementPtrInst>(
GEP)->setIsInBounds(InBounds);
3050 return wrap(unwrap<GEPOperator>(
GEP)->getSourceElementType());
3057 PHINode *PhiVal = unwrap<PHINode>(PhiNode);
3058 for (
unsigned I = 0;
I != Count; ++
I)
3063 return unwrap<PHINode>(PhiNode)->getNumIncomingValues();
3067 return wrap(unwrap<PHINode>(PhiNode)->getIncomingValue(Index));
3071 return wrap(unwrap<PHINode>(PhiNode)->getIncomingBlock(Index));
3078 if (
auto *
GEP = dyn_cast<GEPOperator>(
I))
3079 return GEP->getNumIndices();
3080 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3081 return EV->getNumIndices();
3082 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3083 return IV->getNumIndices();
3084 if (
auto *CE = dyn_cast<ConstantExpr>(
I))
3085 return CE->getIndices().size();
3087 "LLVMGetNumIndices applies only to extractvalue and insertvalue!");
3092 if (
auto *EV = dyn_cast<ExtractValueInst>(
I))
3093 return EV->getIndices().data();
3094 if (
auto *
IV = dyn_cast<InsertValueInst>(
I))
3095 return IV->getIndices().data();
3096 if (
auto *CE = dyn_cast<ConstantExpr>(
I))
3097 return CE->getIndices().data();
3099 "LLVMGetIndices applies only to extractvalue and insertvalue!");
3116 auto I = Instr ? unwrap<Instruction>(Instr)->getIterator() :
BB->end();
3166 L ? cast<MDNode>(unwrap<MetadataAsValue>(L)->getMetadata()) :
nullptr;
3177 unwrap(
Builder)->SetInstDebugLocation(unwrap<Instruction>(Inst));
3181 unwrap(
Builder)->AddMetadataToInst(unwrap<Instruction>(Inst));
3188 ? unwrap<MDNode>(FPMathTag)
3226 unsigned NumDests) {
3259 unwrap(
B)->GetInsertBlock()->getParent()->setPersonalityFn(
3260 cast<Function>(
unwrap(PersFn)));
3275 if (ParentPad ==
nullptr) {
3290 unsigned NumHandlers,
const char *
Name) {
3291 if (ParentPad ==
nullptr) {
3296 NumHandlers,
Name));
3301 return wrap(
unwrap(
B)->CreateCatchRet(unwrap<CatchPadInst>(CatchPad),
3307 return wrap(
unwrap(
B)->CreateCleanupRet(unwrap<CleanupPadInst>(CatchPad),
3317 unwrap<SwitchInst>(Switch)->addCase(unwrap<ConstantInt>(OnVal),
unwrap(Dest));
3321 unwrap<IndirectBrInst>(IndirectBr)->addDestination(
unwrap(Dest));
3325 return unwrap<LandingPadInst>(LandingPad)->getNumClauses();
3329 return wrap(unwrap<LandingPadInst>(LandingPad)->getClause(Idx));
3333 unwrap<LandingPadInst>(LandingPad)->
3338 return unwrap<LandingPadInst>(LandingPad)->isCleanup();
3342 unwrap<LandingPadInst>(LandingPad)->setCleanup(Val);
3346 unwrap<CatchSwitchInst>(CatchSwitch)->addHandler(
unwrap(Dest));
3350 return unwrap<CatchSwitchInst>(CatchSwitch)->getNumHandlers();
3356 *Handlers++ =
wrap(
H);
3360 return wrap(unwrap<CatchPadInst>(CatchPad)->getCatchSwitch());
3364 unwrap<CatchPadInst>(CatchPad)
3365 ->setCatchSwitch(unwrap<CatchSwitchInst>(CatchSwitch));
3371 return wrap(unwrap<FuncletPadInst>(Funclet)->getArgOperand(
i));
3375 unwrap<FuncletPadInst>(Funclet)->setArgOperand(
i,
unwrap(value));
3547 ITy,
unwrap(Ty), AllocSize,
3548 nullptr,
nullptr,
"");
3558 ITy,
unwrap(Ty), AllocSize,
3559 unwrap(Val),
nullptr,
"");
3717 unsigned NumIndices,
const char *
Name) {
3733 unsigned NumIndices,
const char *
Name) {
3740 unsigned Idx,
const char *
Name) {
3764 Value *
P = unwrap<Value>(MemAccessInst);
3765 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3766 return LI->isVolatile();
3768 return SI->isVolatile();
3770 return AI->isVolatile();
3771 return cast<AtomicCmpXchgInst>(
P)->isVolatile();
3775 Value *
P = unwrap<Value>(MemAccessInst);
3776 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3777 return LI->setVolatile(isVolatile);
3779 return SI->setVolatile(isVolatile);
3781 return AI->setVolatile(isVolatile);
3782 return cast<AtomicCmpXchgInst>(
P)->setVolatile(isVolatile);
3786 return unwrap<AtomicCmpXchgInst>(CmpXchgInst)->isWeak();
3790 return unwrap<AtomicCmpXchgInst>(CmpXchgInst)->setWeak(isWeak);
3794 Value *
P = unwrap<Value>(MemAccessInst);
3796 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3797 O = LI->getOrdering();
3799 O =
SI->getOrdering();
3801 O = cast<AtomicRMWInst>(
P)->getOrdering();
3806 Value *
P = unwrap<Value>(MemAccessInst);
3809 if (
LoadInst *LI = dyn_cast<LoadInst>(
P))
3810 return LI->setOrdering(
O);
3811 return cast<StoreInst>(
P)->setOrdering(
O);