Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[llvm-c] Operand bundle API #71873

Closed
HertzDevil opened this issue Nov 9, 2023 · 0 comments · Fixed by #73914
Closed

[llvm-c] Operand bundle API #71873

HertzDevil opened this issue Nov 9, 2023 · 0 comments · Fixed by #73914
Labels
llvm Umbrella label for LLVM issues

Comments

@HertzDevil
Copy link
Contributor

Currently it seems there is no way to attach operand bundles to call or invoke instructions via the C API, which are needed for Windows SEH, among other things. It would be great if LLVM frontends don't have to write their own wrapper functions for this. I was thinking of something like:

typedef struct LLVMOpaqueOperandBundle *LLVMOperandBundleRef;

LLVMOperandBundleRef LLVMCreateOperandBundle(
  const char *Name, size_t SLen, LLVMValueRef *Args, unsigned NumArgs);
void LLVMDisposeOperandBundle(
  LLVMOperandBundleRef Bundle);
const char *LLVMGetOperandBundleTag(
  LLVMOperandBundleRef Bundle, size_t *Len);
unsigned LLVMGetNumOperandBundleArgs(
  LLVMOperandBundleRef Bundle);
void LLVMGetOperandBundleArgs(
  LLVMOperandBundleRef Bundle, LLVMValueRef *Dest);
LLVMValueRef LLVMGetOperandBundleArgAtIndex(
  LLVMOperandBundleRef Bundle, unsigned Index);

/* `Instr` must be a CallInst or InvokeInst */
unsigned LLVMGetNumOperandBundles(
  LLVMValueRef Instr);
void LLVMGetOperandBundles(
  LLVMValueRef Instr, LLVMOperandBundleRef *Dest);
LLVMOperandBundleRef LLVMGetOperandBundleAtIndex(
  LLVMValueRef Instr, unsigned Index);

LLVMValueRef LLVMBuildCall3(
  LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs,
  LLVMOperandBundleRef *Bundles, unsigned NumBundles,
  const char *Name);
LLVMValueRef LLVMBuildInvoke3(
  LLVMBuilderRef B, LLVMTypeRef Ty, LLVMValueRef Fn, LLVMValueRef *Args, unsigned NumArgs,
  LLVMBasicBlockRef Then, LLVMBasicBlockRef Catch,
  LLVMOperandBundleRef *Bundles, unsigned NumBundles,
  const char *Name);

However I had a few questions while working on this myself:

  • The names LLVMBuildCall3 and LLVMBuildInvoke3 would suggest that the 2 variants are deprecated, perhaps better names should be chosen.
  • I had LLVMCreateOperandBundle call new llvm::OperandBundleDef(...). Bundles created this way need to be disposed later. Is this an appropriate representation for LLVMOperandBundleRef?
  • In my WIP LLVMGetOperandBundles and LLVMGetOperandBundleAtIndex copy the bundles to the heap, and they too need to be disposed. This looks rather unnatural to me. Is it safe to wrap the bundles' addresses directly instead?

See also: #30133, https://discourse.llvm.org/t/setting-funclet-operand-bundles/44113

@EugeneZelenko EugeneZelenko added llvm Umbrella label for LLVM issues and removed new issue labels Nov 9, 2023
nikic pushed a commit that referenced this issue Dec 11, 2023
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm Umbrella label for LLVM issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants