Page MenuHomePhabricator

[CodeGen] Add thumb-mode to target-features for arm/thumb triples.
ClosedPublic

Authored by fhahn on May 23 2017, 9:44 AM.

Details

Summary

The thumb-mode target feature is used to force Thumb or ARM code
generation on a per-function basis. Explicitly adding +thumb-mode to
functions for thumbxx triples enables mixed ARM/Thumb code generation in
places where compilation units with thumbxx and armxx triples are merged
together (e.g. the IR linker or LTO).

For armxx triples, -thumb-mode is added in a similar fashion.

Diff Detail

Event Timeline

fhahn created this revision.May 23 2017, 9:44 AM
echristo requested changes to this revision.May 23 2017, 12:12 PM

I probably would have added this as a feature in ARMTargetInfo similar to CRC/soft-float/etc.

Thoughts?

-eric

This revision now requires changes to proceed.May 23 2017, 12:12 PM
fhahn added a comment.May 24 2017, 8:59 AM

I probably would have added this as a feature in ARMTargetInfo similar to CRC/soft-float/etc.

Thoughts?

Do you mean ARMTargetMachine::getSubtargetImpl (https://github.com/llvm-mirror/llvm/blob/master/lib/Target/ARM/ARMTargetMachine.cpp#L305) ?

It seems like that function is only used by llc (and not llvm-as for example) and at that stage it is too late to add thumb-mode, because llc operates on a single module with a single target triple.

I probably would have added this as a feature in ARMTargetInfo similar to CRC/soft-float/etc.

Thoughts?

Do you mean ARMTargetMachine::getSubtargetImpl (https://github.com/llvm-mirror/llvm/blob/master/lib/Target/ARM/ARMTargetMachine.cpp#L305) ?

It seems like that function is only used by llc (and not llvm-as for example) and at that stage it is too late to add thumb-mode, because llc operates on a single module with a single target triple.

No, I meant somewhere around here: https://github.com/llvm-mirror/clang/blob/master/lib/Basic/Targets.cpp#L5058 to define it and then in CGCall.cpp it'll get added along with the other target-features.

I think that'll enable you to handle -mthumb and -target in a fairly unified way?

rinon added a subscriber: rinon.May 24 2017, 1:30 PM
fhahn updated this revision to Diff 100222.May 25 2017, 3:52 AM
fhahn edited edge metadata.
fhahn retitled this revision from [CodeGen] Add thumb-mode to function target-features for arm/thumb triples. to [CodeGen] Add thumb-mode to target-features for arm/thumb triples..
fhahn edited the summary of this revision. (Show Details)

Move code to lib/Basic/Targets.cpp

fhahn added a comment.May 25 2017, 3:53 AM

@echristo lib/Basic/Targets.cpp is indeed a much better place to add thumb-mode to the target features, thanks for pointing me in the right direction!

echristo accepted this revision.May 25 2017, 5:58 PM

One minor nit and LGTM.

Thanks!

-eric

lib/Basic/Targets.cpp
5441

Minor nit: comments are full sentences.

This revision is now accepted and ready to land.May 25 2017, 5:58 PM
fhahn updated this revision to Diff 100371.May 26 2017, 1:03 AM

Updated the comment, thanks for the reviewing this patch!

fhahn marked an inline comment as done.May 26 2017, 1:03 AM
fhahn added a comment.May 26 2017, 7:53 AM

I'll hold off merging this patch until D33436 lands, which fixes a problem with mixed ARM/Thumb codegen

I'll hold off merging this patch until D33436 lands, which fixes a problem with mixed ARM/Thumb codegen

OK. Commit at will :)

-eric

fhahn added a comment.Jun 5 2017, 10:01 AM

I've discovered another problem while doing an ARM bootstrap build with mixed ARM/Thumb codegen. With D33898 , the bootstrap build with mixed ARM/Thumb code works properly. After that's in I'll finally commit this patch.

fhahn updated this revision to Diff 101687.Jun 7 2017, 3:59 AM

rebased

fhahn closed this revision.Jun 7 2017, 4:51 AM