[llvm-dev] Command line -mcpu= and -march=

Mark R V Murray via llvm-dev llvm-dev at lists.llvm.org
Wed Dec 19 02:23:15 PST 2018


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!

Mark R V Murray

More information about the llvm-dev mailing list