This is an archive of the discontinued LLVM Phabricator instance.

[AVR] Add -mmcu option to the driver
ClosedPublic

Authored by Lekensteyn on Feb 10 2017, 7:49 AM.

Details

Summary

Add the AVR-specific -mmcu option for compatibility with GCC (GCC does not use
-mcpu nor -march for AVR). This option is needed to inform the frontend to
define some macros (for example) and the inform the assembler of the allowed
features, so add a test to check that.

Fixes PR#31569

Diff Detail

Repository
rL LLVM

Event Timeline

Lekensteyn created this revision.Feb 10 2017, 7:49 AM
jroelofs added inline comments.Feb 10 2017, 8:45 AM
include/clang/Driver/Options.td
1613 ↗(On Diff #87992)

Would it make sense to have mcu be an alias for mcpu instead?

Lekensteyn added inline comments.Feb 10 2017, 9:47 AM
include/clang/Driver/Options.td
1613 ↗(On Diff #87992)

That would deviate from the GCC interface, so I have chosen for the current situation:

$ avr-gcc -mmcu=avr2 -o /dev/null x.c
$ avr-gcc -mcpu=avr2 -o /dev/null x.c
avr-gcc: error: unrecognized command line option '-mcpu=avr2'
$ avr-gcc -march=avr2 -o /dev/null x.c
avr-gcc: error: unrecognized command line option '-march=avr2'
$ avr-gcc -v
...
gcc version 6.3.0 (GCC)
dylanmckay added inline comments.
include/clang/Driver/Options.td
1613 ↗(On Diff #87992)

I think @jroelofs means that it is possible to make mmcu an alias of mmcu internally. This would mean we wouldn't need to add AVR-specific getCPUName handling.

Lekensteyn added inline comments.Feb 10 2017, 2:16 PM
include/clang/Driver/Options.td
1613 ↗(On Diff #87992)

If mmcu is made an alias of mcpu, wouldn't that mean that both -mcpu and -mmcu would be accepted by driver (undesirable)?
As far as I can see, -target-cpu must be passed to the frontend and assembler, -mcpu= is not recognized as option. And ensuring that getCPUName returns a non-empty string ensures that -target-cpu is passed.

I am quite new to the internals, so please let me know if I misunderstood something :-)

jroelofs accepted this revision.Apr 17 2017, 7:45 AM

LGTM

include/clang/Driver/Options.td
1613 ↗(On Diff #87992)

-mmcu= is the right thing to do, without the alias (I was wrong).

This revision is now accepted and ready to land.Apr 17 2017, 7:45 AM
xiangzhai added a comment.EditedApr 19 2017, 1:33 AM

Hi Peter,

Please rebase your patch!

David has already changed the structure of lib/Driver/Tools.cpp in D30372
so it is better to add case llvm::Triple::avr to lib/Driver/ToolChains/CommonArgs.cpp? please point out my fault, thanks!

Regards,
Leslie Zhai

xiangzhai requested changes to this revision.Apr 19 2017, 1:48 AM
This revision now requires changes to proceed.Apr 19 2017, 1:48 AM
xiangzhai set the repository for this revision to rL LLVM.Apr 19 2017, 1:50 AM
xiangzhai edited subscribers, added: dlj; removed: xiangzhai.
Lekensteyn updated this revision to Diff 95707.EditedApr 19 2017, 4:31 AM
Lekensteyn edited edge metadata.

v2: rebase on commit ad25f8b712f1ef99020fcb7b5e31dd95b39c6112 (trunk@300661)

Based on the context, the change from lib/Driver/Tools.cpp -> lib/Driver/ToolChains/CommonArgs.cpp seems most appropriate (Gnu.cpp seems to be about mapping LLVM options to GCC?)

And please do commit on my behalf, I haven't requested an account yet. Thanks!

xiangzhai accepted this revision.Apr 19 2017, 7:11 AM

Hi Peter,

Thanks for your rebase! LGTM!

Based on the context, the change from lib/Driver/Tools.cpp -> lib/Driver/ToolChains/CommonArgs.cpp seems most appropriate (Gnu.cpp seems to be about mapping LLVM options to GCC?)

Sorry for my mistake! yes, I am maintaining similar patch for GCC toolchain triples :) also rebased to lib/Driver/ToolChains/CommonArgs.cpp for packaging llvm-4.0.0.

And please do commit on my behalf, I haven't requested an account yet. Thanks!

I will commit it for you tomorrow if no Need Review!

Regards,
Leslie Zhai

This revision is now accepted and ready to land.Apr 19 2017, 7:11 AM
This revision was automatically updated to reflect the committed changes.