This is an archive of the discontinued LLVM Phabricator instance.

[Bitcode] Add thumb-mode to target-features in metadata loader.
AbandonedPublic

Authored by fhahn on Jun 8 2017, 4:48 AM.

Details

Summary

The thumb-mode target feature is used to control mixed ARM/Thumb
code generation in a single compilation unit. D33287 adds thumb-mode to
target-features for arm/thumb triples.

David Blaikie also suggested that we might be able to get rid of the
thumb triples altogether after the bitcode reader. Currently there are
about 30 checks that use Triple::thumb/thumbeb in the LLVM source code.

I had a look at most of them and unfortunately it seems like replacing
most of them with ARMSubtarget::isThumb will be quite hard, because
either no TargetMachine instance (e.g. the uses in
lib/Transforms/IPO/LowerTypeTests.cpp) or no function is available (e.g.
when initializing global sections in lib/MC/MCObjectFileInfo.cpp or
printing model-level inline asm lib/Target/ARM/ARMAsmPrinter.cpp).

I would appreciate any thoughts on Triple::thumb uses. At the moment it
seems to me replacing the remaining uses requires quite a bit of work
for relatively little benefits.

Diff Detail

Event Timeline

fhahn created this revision.Jun 8 2017, 4:48 AM
javed.absar added inline comments.Jun 8 2017, 5:43 AM
lib/Bitcode/Reader/MetadataLoader.cpp
683

maybe you should add isARMorThumb to ADT/Triple.h and use it, much like isPS4(), isAndroid etc?

test/Bitcode/thumb-mode-upgrade-arm.ll
2

Could the same check be achieved using something like 'llvm-as < %s | llvm-dis ..."?

dblaikie added inline comments.Jun 8 2017, 9:55 AM
lib/Bitcode/Reader/MetadataLoader.cpp
688–689

Probably cheaper to get the attribute & test if it succeeded, than to test then get separately (one lookup rather than two). I'd check other API uses to see if there's a good idiom for a single query+test sort of thing as it's not readily apparent to me from the API (I'd expect Attribute to have an explicit operator bool, but it doesn't look like it has one)

690

Is this how other target features are tested for in other parts of the codebase? I'd be worried that 'thumb-mode' could appear as a substring of a target feature and cause this to have a false positive

690

So is the idea that all new bitcode for ARM targets will have explicit -thumb-mode or +thumb-mode, so you'll know when upgrading that you're not overriding a default (eg: if you see a thumb triple but none of the functions have thumb-mode that doesn't mean each function was attributed with "not thumb")?

pcc edited edge metadata.Jun 8 2017, 2:19 PM
pcc added a subscriber: eugenis.

either no TargetMachine instance (e.g. the uses in
lib/Transforms/IPO/LowerTypeTests.cpp)

I believe that the jump table entries created by this pass will want to have the same thumbness as the referenced function, but @eugenis may know more.

In D34028#776424, @pcc wrote:

either no TargetMachine instance (e.g. the uses in
lib/Transforms/IPO/LowerTypeTests.cpp)

I believe that the jump table entries created by this pass will want to have the same thumbness as the referenced function, but @eugenis may know more.

Right. And ARM for external functions (the same as PLT).

fhahn updated this revision to Diff 102041.Jun 9 2017, 9:15 AM

Address comments.

@ppc @eugenis it sounds like we should use the function target-features when determining the thumbness of the jump table entries, otherwise this could probably confuse the linker for mixed ARM/Thumb. codegen. I'll look into that!

lib/Bitcode/Reader/MetadataLoader.cpp
683

Maybe it would make sense to add an isThumb() and isARm() method to Triple. In particular, isThumb could be used at a couple of places. But ideally those checks should be replaced to use the ARMSubtargetFeatures.

688–689

There is no need to check if the feature is present, getFnAttribute returns an empty attribute in case the attribute does not exist.

690

No, AFAIK target features are only checked during CodeGen, using a TargetMachine or Subtarget instance. I think initializing an ARMSubtarget instance in this case would be overkill. I've strengthened the check though, so it should not match if thumb-mode appears in a substring.

Re your second comment: yes the idea is that code generated by clang now sets +/-thumb-mode for all functions. For functions without a thumb-mode target feature and a thumb triple, Thumb code should be generated, thus +thumb-mode is added.

test/Bitcode/thumb-mode-upgrade-arm.ll
2

I think the reason to include a bitcode file is to make sure older versions of the bitcode format are handled correctly going forward

mehdi_amini added inline comments.Jun 26 2017, 9:17 AM
lib/Bitcode/Reader/MetadataLoader.cpp
683

This will be done for each and every function in the module, while this check could be done at the module level once.
I kind of remember that building a Triple from a string isn't "free", but possible this is negligible in face of the cost of deserializing bitcode.

fhahn updated this revision to Diff 104140.Jun 27 2017, 4:52 AM
fhahn marked an inline comment as done.
fhahn added inline comments.
lib/Bitcode/Reader/MetadataLoader.cpp
683

@mehdi_amini I've updated the patch to only instantiate Triple once.

fhahn marked an inline comment as done.Jun 27 2017, 4:59 AM
fhahn added inline comments.
lib/Bitcode/Reader/MetadataLoader.cpp
683

@javed.absar I've opened D34682 which adds isThumb and isARM functions to the Triple class.

Should this be documented in the LLVM LangRef? (or elsewhere?)
(Otherwise I'd expect some documentation on the `upgradeThumbMode``` function at least)

(maybe it is already?)

fhahn abandoned this revision.Mar 9 2018, 6:55 AM

Sorry for the long delay! I am dropping this now, as I think it's not applicable or needed any more. Thanks for having a look