[llvm-dev] How to get generic datalayout and "target-cpu" attribute

Mehdi Amini via llvm-dev
Fri, 15 Jan 2016 01:52:18 -0000

Hi,

It seems that you may want to have a look at
http://llvm.org/docs/doxygen/html/Host_8h_source.html

Also, your compiler could easily just produce the final object file directly
instead of calling opt/llc (mimic opt.cpp and llc.cpp for instance, or what
clang is doing).

—
Mehdi

> On Jan 14, 2016, at 5:31 PM, Manuel Jacob via llvm-dev <llvm-dev at
lists.llvm.org> wrote:
>
> Hi,
>
> My compiler emits LLVM IR in text form and passes it to the opt and llc
executables.
>
> The datalayout and triple are currently determined by running "clang
-x c /dev/null -emit-llvm -S -o -" and parsing the output.  This works fine
because clang seems to choose a generic version of the CPU it is running on, and
this is exactly what we want.  Still this solution is hacky and I'd like to
know whether there is a cleaner way to achieve this.
>
> The "target-cpu" attribute is not set at all by my compiler.
I'm concerned that this limits the effectiveness of certain optimization
passes.  I don't understand when the triple is used and when the
"target-cpu" attribute is used.
>
> The compiler links some other IR, which is generated by clang, into the
main IR output of the compiler before optimization.  The functions pulled in
from the clang outputs have the "target-cpu" attribute set.  On X86,
the inliner refuses to inline these functions because the features of the CPU
model set on the callee are a superset of those of the caller.
>
> It is of course possible to compile a short C function with clang and fish
the "target-cpu" attribute out of the IR.  However, I don't want
to introduce another hack.
>
> Can someone recommend a cleaner way to get the datalayout and
"target-cpu" attribute for a generic model of the CPU we're
compiling on?
>
> -Manuel
> _______________________________________________
> LLVM Developers mailing list
> llvm-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev