Search code examples
llvm

What's LLVMBlockAddress() first argument?


I'm playing a bit with LLVM C-API and I'm somehow stuck with LLVMBuildIndirectBr(), or more exactly with LLVMBlockAddress() because I have no idea what its first argument is and more importantly how can I create it. It's a LLVMValueRef which is supposed to represent 'the function' but the documentation I found doesn't tell more.


Solution

  • According to its code, this function is just a C wrapper for BlockAddress::get(). So, the first argument is the Function that contains the BB, I presume.

    There is no C API for BlockAddress::get() overload taking only BB argument, so you have to call LLVMGetBasicBlockParent() on that BB first to obtain a reference to the Function it belongs to, and then pass it as first parameter to LLVMBlockAddress().

    As a rule of thumb in such situations, try to figure out "native" C++ method you are using, and then look for its documentation.