aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/IR
diff options
context:
space:
mode:
authorQuinton Miller <nicetas.c@gmail.com>2023-12-11 16:47:33 +0800
committerGitHub <noreply@github.com>2023-12-11 09:47:33 +0100
commit86763a8cc499baa0328ea485d3823875946de023 (patch)
tree13f7bb1f2596b75bda39c6bbcddbb4658f1273da /llvm/lib/IR
parentbd3e8eb6e325081bf7cfbe93652aa825de3170e5 (diff)
downloadllvm-86763a8cc499baa0328ea485d3823875946de023.zip
llvm-86763a8cc499baa0328ea485d3823875946de023.tar.gz
llvm-86763a8cc499baa0328ea485d3823875946de023.tar.bz2
[LLVM-C] Support operand bundles (#73914)
Added the following functions for manipulating operand bundles, as well as building ``call`` and ``invoke`` instructions that use operand bundles: * LLVMBuildCallWithOperandBundles * LLVMBuildInvokeWithOperandBundles * LLVMCreateOperandBundle * LLVMDisposeOperandBundle * LLVMGetNumOperandBundles * LLVMGetOperandBundleAtIndex * LLVMGetNumOperandBundleArgs * LLVMGetOperandBundleArgAtIndex * LLVMGetOperandBundleTag Fixes #71873.
Diffstat (limited to 'llvm/lib/IR')
-rw-r--r--llvm/lib/IR/Core.cpp69
1 files changed, 69 insertions, 0 deletions
diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp
index 7832028..96629de 100644
--- a/llvm/lib/IR/Core.cpp
+++ b/llvm/lib/IR/Core.cpp
@@ -43,6 +43,8 @@
using namespace llvm;
+DEFINE_SIMPLE_CONVERSION_FUNCTIONS(OperandBundleDef, LLVMOperandBundleRef)
+
#define DEBUG_TYPE "ir"
void llvm::initializeCore(PassRegistry &Registry) {
@@ -2567,6 +2569,34 @@ void LLVMRemoveGlobalIFunc(LLVMValueRef IFunc) {
unwrap<GlobalIFunc>(IFunc)->removeFromParent();
}
+/*--.. Operations on operand bundles........................................--*/
+
+LLVMOperandBundleRef LLVMCreateOperandBundle(const char *Tag, size_t TagLen,
+ LLVMValueRef *Args,
+ unsigned NumArgs) {
+ return wrap(new OperandBundleDef(std::string(Tag, TagLen),
+ ArrayRef(unwrap(Args), NumArgs)));
+}
+
+void LLVMDisposeOperandBundle(LLVMOperandBundleRef Bundle) {
+ delete unwrap(Bundle);
+}
+
+const char *LLVMGetOperandBundleTag(LLVMOperandBundleRef Bundle, size_t *Len) {
+ StringRef Str = unwrap(Bundle)->getTag();
+ *Len = Str.size();
+ return Str.data();
+}
+
+unsigned LLVMGetNumOperandBundleArgs(LLVMOperandBundleRef Bundle) {
+ return unwrap(Bundle)->inputs().size();
+}
+
+LLVMValueRef LLVMGetOperandBundleArgAtIndex(LLVMOperandBundleRef Bundle,
+ unsigned Index) {
+ return wrap(unwrap(Bundle)->inputs()[Index]);
+}
+
/*--.. Operations on basic blocks ..........................................--*/
LLVMValueRef LLVMBasicBlockAsValue(LLVMBasicBlockRef BB) {
@@ -2858,6 +2888,16 @@ LLVMTypeRef LLVMGetCalledFunctionType(LLVMValueRef Instr) {
return wrap(unwrap<CallBase>(Instr)->getFunctionType());
}
+unsigned LLVMGetNumOperandBundles(LLVMValueRef C) {
+ return unwrap<CallBase>(C)->getNumOperandBundles();
+}
+
+LLVMOperandBundleRef LLVMGetOperandBundleAtIndex(LLVMValueRef C,
+ unsigned Index) {
+ return wrap(
+ new OperandBundleDef(unwrap<CallBase>(C)->getOperandBundleAt(Index)));
+}
+
/*--.. Operations on call instructions (only) ..............................--*/
LLVMBool LLVMIsTailCall(LLVMValueRef Call) {
@@ -3140,6 +3180,20 @@ LLVMValueRef LLVMBuildInvoke2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn,
ArrayRef(unwrap(Args), NumArgs), Name));
}
+LLVMValueRef LLVMBuildInvokeWithOperandBundles(
+ LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef *Args,
+ unsigned NumArgs, LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
+ LLVMOperandBundleRef *Bundles, unsigned NumBundles, const char *Name) {
+ SmallVector<OperandBundleDef, 8> OBs;
+ for (auto *Bundle : ArrayRef(Bundles, NumBundles)) {
+ OperandBundleDef *OB = unwrap(Bundle);
+ OBs.push_back(*OB);
+ }
+ return wrap(unwrap(B)->CreateInvoke(
+ unwrap<FunctionType>(Ty), unwrap(Fn), unwrap(Then), unwrap(Catch),
+ ArrayRef(unwrap(Args), NumArgs), OBs, Name));
+}
+
LLVMValueRef LLVMBuildLandingPad(LLVMBuilderRef B, LLVMTypeRef Ty,
LLVMValueRef PersFn, unsigned NumClauses,
const char *Name) {
@@ -3878,6 +3932,21 @@ LLVMValueRef LLVMBuildCall2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn,
ArrayRef(unwrap(Args), NumArgs), Name));
}
+LLVMValueRef
+LLVMBuildCallWithOperandBundles(LLVMBuilderRef B, LLVMTypeRef Ty,
+ LLVMValueRef Fn, LLVMValueRef *Args,
+ unsigned NumArgs, LLVMOperandBundleRef *Bundles,
+ unsigned NumBundles, const char *Name) {
+ FunctionType *FTy = unwrap<FunctionType>(Ty);
+ SmallVector<OperandBundleDef, 8> OBs;
+ for (auto *Bundle : ArrayRef(Bundles, NumBundles)) {
+ OperandBundleDef *OB = unwrap(Bundle);
+ OBs.push_back(*OB);
+ }
+ return wrap(unwrap(B)->CreateCall(
+ FTy, unwrap(Fn), ArrayRef(unwrap(Args), NumArgs), OBs, Name));
+}
+
LLVMValueRef LLVMBuildSelect(LLVMBuilderRef B, LLVMValueRef If,
LLVMValueRef Then, LLVMValueRef Else,
const char *Name) {