[llvm-dev] Generating C headers from LLVM

Michael Spencer via llvm-dev llvm-dev at lists.llvm.org
Fri Apr 12 10:19:52 PDT 2019


On Fri, Apr 12, 2019 at 3:53 AM Peter Lammich via llvm-dev <
llvm-dev at lists.llvm.org> wrote:

> Hi List,
>
> is there any way to generate proper C header files for functions that
> are defined in LLVM-IR. My current attempts fail when clang does some
> fancy transformations (to adhere to some ABIs ??), e.g., for returning
> a struct.
>
> For example the declaration
>
> typedef struct {int64_t a; int64_t b;int64_t c;} test;
> test create_test(void);yields the LLVM code
>
> %struct.test = type { i64, i64, i64 }
> declare void @create_test(%struct.test* sret) #1
>
> However, the function is defined in LLVM-IR as
> {i64,i64,i64} @create_test()
>

Where are you getting this definition from?  Clang outputs what is required
by the target backend to generate the correct ABI.  The mapping from C code
to llvm ir is always target dependent.

- Michael Spencer


>
> Questions:
> 1) Is there any way to convince clang to generate the "correct" output,
> that fits the given definition in LLVM-IR?
>
> 2) What other surprises to expect? Is there a "safe fragment" where the
>  obvious C code actually matches the obvious LLVM-IR?
>
> 3) If 1 does not exist, is there a way to generate "wrapper-functions"
> in LLVM-IR, that map the given functions to what clang expects?
>
>
> Thanks in advance for any help,
>   Peter
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190412/db27abce/attachment.html>


More information about the llvm-dev mailing list