This is an archive of the discontinued LLVM Phabricator instance.

[Driver][ARM] For assembler files recognize -Xassembler or -Wa, -mthumb
ClosedPublic

Authored by peter.smith on Nov 16 2017, 6:50 AM.

Details

Summary

The Unified Arm Assembler Language is designed so that the majority of assembler files can be assembled for both Arm and Thumb with the choice made as a compilation option. The way this is done in gcc is to pass -mthumb to the assembler with either -Wa,-mthumb or -Xassembler -mthumb. This change adds support for these options to clang. There is no assembler equivalent of -mno-thumb, -marm or -mno-arm so we don't need to recognize these.

Ideally we would do all of the processing in CollectArgsForIntegratedAssembler(). Unfortunately we need to change the triple and at that point it is too late. Instead we look for the option earlier in ComputeLLVMTriple().

Fixes PR34519

Diff Detail

Repository
rL LLVM

Event Timeline

peter.smith created this revision.Nov 16 2017, 6:50 AM
compnerd added inline comments.Nov 16 2017, 10:21 PM
lib/Driver/ToolChain.cpp
549–556 ↗(On Diff #123174)

Why not write this as:

const auto &Values = Args.filtered(options::OPT_Wa_COMMA, options::OPT_Xassembler);
bool IsIntegratedAssemblerThumb =
    std::any_of(std::begin(A->getValues()),
                std::end(A->getValues()),
                [](StringRef Arg) { return Arg == "-mthumb"});
560–564 ↗(On Diff #123174)

This is horribly complicated to read. Can we just split this out of the condition and create a variable?

peter.smith added inline comments.Nov 17 2017, 3:09 AM
lib/Driver/ToolChain.cpp
549–556 ↗(On Diff #123174)

I gave it a try and I don't think it can be done simply as there are two loops and not one. There could be two Args, one for Wa_COMMA and one for X_Assembler. Unless there is a way of combining the iterator ranges into one I don't think this can be done without nested loops. I checked the other uses of Args.filtered and I couldn't find any of use outside of the range for. Please do let me know if I'm missing something though as I'm happy to change it if there is something better.

560–564 ↗(On Diff #123174)

Agreed. I'll post an alternative that attempts to evaluate -mthumb before the boolean expression.

Updated diff with an attempt to simplify the check for filetype and mthumb. I've left the existing Args.filtered in expression for now as I couldn't make a better alternative with std::for_any.

compnerd accepted this revision.Nov 18 2017, 6:32 PM

Would be nice to rename the variable prior to commit.

lib/Driver/ToolChain.cpp
547 ↗(On Diff #123310)

I think that this should be IsThumb. The -m is just an indicator that this is a machine flag.

549–556 ↗(On Diff #123174)

I should've hoisted the ->getValues(), but I suspect that would work. But that is a slight tweak, not anything to hold this up on.

This revision is now accepted and ready to land.Nov 18 2017, 6:32 PM

Would be nice to rename the variable prior to commit.

Thanks for the review, I've renamed the variable as suggested.

This revision was automatically updated to reflect the committed changes.