Command line -mcpu= and -march=

Hi

I'm doing a port of Clang/LLVM - purely for the educational value - to the MC6809 (and HD6309 as a dub target) processors. I'll also want to eventually provide direct support for the AM9511 floating-point coprocessor as an option. I'm working with bleeding-edge code from the Git mirror.

I've made some pretty decent progress; I copied the llvm/lib/Targets/MSP430 Target to llvm/lib/targets/MC6809, changed all references to MSP430 to MC6809 ones, and went through the rest of the code mechanically creating MC6809 entries wherever there was an MSP430 one. Similarly in llvm/tools/clang/...

I then butchered the MC6809.td file, the register description .td file, made a new machine description string, and fixed the compilation problems that arose. This gives me a FrankenComopiler that generates MSP430 instructions using MC6809 registers in MC6809 memory layout. So far so good. I'm leaving the fun bit - doing all the instructions/assembly/output file generation - for last.

What I can't figure out is how to the -mcpu=foo and/or -march=bar to work. The documentation implies that you get these for free by setting up the processor and subtarget features in the MC6809.td file, but try as I might I can't get it to work, and it doesn't work for the MSP430 either.

No matter what I do,

$ clang --target=mc6809-elf -march=foo -S ~/test.c -o test1.s

... gets me a response of

clang-8: warning: argument unused during compilation: '-march=foo' [-Wunused-command-line-argument]

... even for MSP430 ...

$ clang --target=msp430-elf -march=baz -S ~/test.c -o test1.s
clang-8: warning: argument unused during compilation: '-march=baz' [-Wunused-command-line-argument]

I'm concluding that I need to write a "consumer" of the -march and/or -mcpu options myself, but I can't find a canonical example of this anywhere. I've played with RegisterTarget, but the documentation is a bit too densely packed for me. Other CPUs like ARM and AArch64 work, and I can't figure out why.

Can anyone please point me at how to canonically add a -march= or -mcpu= option to MSP430? I can take it from there.

Thank you!

M

Hi Mark,

What I can't figure out is how to the -mcpu=foo and/or -march=bar to work. The documentation implies that you get these for free by setting up the processor and subtarget features in the MC6809.td file, but try as I might I can't get it to work, and it doesn't work for the MSP430 either.

This probably applies to the developer tools (llc, opt etc), but Clang
needs a bit of attention since it often tries to present a sanitized
view of those internals to end users.

... even for MSP430 ...

MSP430 is a fairly bare-bones target, I'm not entirely surprised
no-one has done the work there.

I'm concluding that I need to write a "consumer" of the -march and/or -mcpu options myself, but I can't find a canonical example of this anywhere. I've played with RegisterTarget, but the documentation is a bit too densely packed for me. Other CPUs like ARM and AArch64 work, and I can't figure out why.

I think the top-level code you want is in (under clang)
lib/Driver/ToolChains/Clang.cpp (a bunch of getTargetFeature stuff)
and lib/Driver/ToolChains/CommonArgs.cpp (getCPUName especially).
These defer to target-specific .cpp files in the more complete targets
(lib/Driver/ToolChains/Arch/XYZ.cpp).

Cheers.

Tim.

Hi Mark,

Hi Tim,

I think the top-level code you want is in (under clang)
lib/Driver/ToolChains/Clang.cpp (a bunch of getTargetFeature stuff)
and lib/Driver/ToolChains/CommonArgs.cpp (getCPUName especially).
These defer to target-specific .cpp files in the more complete targets
(lib/Driver/ToolChains/Arch/XYZ.cpp).

Spot on! Thank you!

I got it working now :slight_smile:

M