This is an archive of the discontinued LLVM Phabricator instance.

[Linker] Remove warning when linking ARM and Thumb IR modules.
ClosedPublic

Authored by fhahn on May 17 2017, 9:16 AM.

Details

Summary

This patch updates Triple::isCompatibleWith to make armxx and thumbxx
triples compatible, as long as the subarch, vendor, os, envorionment and
object format match. Thumb/ARM code generation should be controlled
using the thumb-mode per-function target feature rather than by the
triple to allow mixing Thumb and ARM functions.

D33448 updates Clang's codegen to add thumb-mode for all functions with
armxx or thumbxx triples.

Diff Detail

Event Timeline

fhahn created this revision.May 17 2017, 9:16 AM
echristo edited edge metadata.May 17 2017, 8:10 PM

I'm not even really sure that +thumb_mode works in all cases. Why not just have a single TargetMachine at that rate for the ARM back end?

pcc added subscribers: pcc, eugenis.May 17 2017, 8:41 PM
tejohnson added inline comments.May 18 2017, 5:57 AM
lib/Linker/IRMover.cpp
1275

If we're going to do this in the IRMover, it would probably be more efficient to do this once over the whole source module, not just the symbols being linked in one by one, so that the checking etc only needs to be done once per module. Just walk over all the src module functions and apply the attribute.

I guess this is needed because it looks like thumb-mode is typically added in the MC time, but that is too late since these modules are already combined, right?

Is there a drawback to always adding the +/-thumb-mode attribute to thumb/arm modules earlier, like during clang CodeGen?

fhahn added a comment.May 18 2017, 6:53 AM

@echristo I've created a separate review to remove the Thumb target machines (D33318)

Are there any cases in particular you are worried about when it comes to Thumb/ARM code generation in the same compilation unit? I was thinking about compiling and running a big set of tests with a version of clang that randomly adds +thumb-mode to some functions. This should help increasing the confidence in mixing Thumb/ARM code generation in the same compilation unit.

@tejohnson as far as I am aware of, one (probably minor) drawback of doing it in clang would be that other frontends might also need to add +-thumb-mode in case they want to link ARM and Thumb modules. Also, when it comes to the warning about incompatible triples from the linker, we would have to trust clang to add the +thumb-mode feature in order to silence the message for armxx and thumbxx triples.

fhahn added a comment.May 23 2017, 4:17 AM

@echristo I've uncovered a bug causing BL being used to call internal ARM functions from Thumb functions and have put up a patch for that problem: D33436

With this patch, multiple runs of the LNT test suite pass built for ARM using a version of clang that randomly adds +thumb-mode to functions.

fhahn updated this revision to Diff 100054.May 24 2017, 2:27 AM
fhahn retitled this revision from [Linker] Add support for linking ARM and Thumb IR modules. to [Linker] Remove warning when linking ARM and Thumb IR modules..
fhahn edited the summary of this revision. (Show Details)

Rebased and removed code that adds thumb-mode from the linker, as the thumb-mode feature should be added at an earlier stage.

This patch now only removes the warning when linking ARM and Thumb IR modules.

tejohnson added inline comments.May 24 2017, 8:18 AM
lib/Support/Triple.cpp
1482 ↗(On Diff #100054)

Formatting seems off - can you run clang-format?

1486 ↗(On Diff #100054)

What happens if the above 2 checks are run for Apple?

fhahn updated this revision to Diff 100123.May 24 2017, 10:04 AM
fhahn updated this revision to Diff 100126.May 24 2017, 10:16 AM
fhahn marked an inline comment as done.

added missing triples, fixed formatting

lib/Support/Triple.cpp
1486 ↗(On Diff #100054)

isCompatibleWith treats apple triples in a special way and I tried to match the check below for armxx and thumbxx triples

rinon added a subscriber: rinon.May 24 2017, 1:30 PM
tejohnson accepted this revision.May 25 2017, 6:05 AM

LGTM

Probably only need the llvm-link test though.

This revision is now accepted and ready to land.May 25 2017, 6:05 AM
fhahn added a comment.May 26 2017, 1:10 AM

I think the LTO test is slightly different from the linker test, it ensures that a function from a Thumb module can be inlined in a ARM function and that ARM code is generated for that function. I'll remove it if you think it does not add value to the test suite.

I think the LTO test is slightly different from the linker test, it ensures that a function from a Thumb module can be inlined in a ARM function and that ARM code is generated for that function.

Ah ok, that does seem valuable. Please add a comment to that effect to the test.

fhahn updated this revision to Diff 100410.May 26 2017, 7:51 AM

Added comment to LTO test case.

fhahn added a comment.May 26 2017, 7:52 AM

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

fhahn closed this revision.Jun 7 2017, 2:17 AM