<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/71873>71873</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[llvm-c] Operand bundle API
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
HertzDevil
</td>
</tr>
</table>
<pre>
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:
```c
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
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzEVl1v2zoS_TX0yyCGTMVK_OAHx15vDXTbYhu0j4uxOLa4oUiVpKzr_vqLoRx_JelNHy4uEDgQyZk55_BjDoagt5ZoKsYPYrwYYBsr56cfyMefC9ppM1g7tZ_OW-_JRrMHHSEQ1QFiRZ5AB7AOOtxDdIAxYlmBa8ijVbBurTIUeKZEY8B50Hbnngi0DdG3ZdTOBthp5GQwh9mXlZBz6CpdVoCewBIpUrBxHr5rq1wX4Ou_PvAarJ3dgmMQECttt2EIqwida42CNcHWE0bQG_j48dt_YOOdjWRVAOWskHcRKtwRA-u8jsTltQfXWeg8Ng152LT2AI-Lx0pzfugwpGpPmotvILiaUnUw-olEPhPZQmTPv0XW_5X9d9w3pGgDPfUE7HODP1r63Ov1kOQCIWf91Nngf2kj8ofz5K8tSSnnTPwypZD3fRBA6WyIUFbouc4nrInFDPon_S_C149k-ZPTfEPTppxCzmZ-G3i8temsKPjU1v3Y5Ihq57RKgQsdGhfeAvAq7OdFp2yXMDno3xQv4h5x-86sR3qciQmeyhwJHSp8auuLND3Jo3jvBH-U4hrz76R7uQsLCvG8zMX8G-VmcWUV_fFupY6CHMImV6dOyKWQMxBFtuIbLIoM6jZEvnAIczSGh_mer9I9T19CprB3CR4ukR7p9dXeo_G1wNcp5q9L8Ia-r96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