[cfe-dev] How to add new target?

Daniel Dunbar daniel at zuster.org
Thu Mar 25 08:21:44 PDT 2010


On Thu, Mar 25, 2010 at 5:33 AM, Artur Pietrek <pietreka at gmail.com> wrote:
>> Hi Artur,
>
> Hi Daniel
>
>>
>> > Hi all,
>> > so after "greping" the code I was able to do (more or less) everything I
>> > wanted to do.
>>
>> As you have discovered, this stuff isn't very well documented yet. Do
>> you feel like writing up a blurb we could add to our Internals Manual
>> describing what you have discovered?
>
> I'll try when I'll make it work correct ;)
>
> BTW I've noticed strange behaviour. When I switched from llvm-gcc to clang,
> my benchmarks stopped working. When I compile simple code:
>
> char array[] =
> "+0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz";
>
> int main() {
>   return array[31];
> }
>
> like this:
> clang -ccc-host-triple mycpu -O0 -S hello.c -o hello.s
>
> The code is wrong, to be precise in one instruction I get
> lbs $r16 = 0[$r17] instead of lbs $r16 = 31[$r17]
>
> but the code is correct when I do it like this:
> clang -ccc-host-triple mycpu -O0 hello.c -c -emit-llvm -o hello.bc
> llc -march=mycpu hello.bc -o hello.s
>
>
> Am I missing something? Shouldn't these two be equivalent?

Unfortunately, no. The driver sets a variety of options in the LLVM
backend that you would need to pass to llc by hand. Try running
$ clang -ccc-host-triple mycpu -O0 hello.c -c -emit-llvm -o hello.bc -###
to see how clang is calling the compiler (clang -cc1), and look for -m
arguments. For example, -mcpu sets the CPU to target, and other -m
options do things like disable use of a frame pointer.

 - Daniel

> Thanks in advance.
>
> Artur
>




More information about the cfe-dev mailing list