This is an archive of the discontinued LLVM Phabricator instance.

[X86] Implement __builtin_cpu_is
ClosedPublic

Authored by craig.topper on Jul 14 2017, 10:42 PM.

Details

Summary

This patch adds support for __builtin_cpu_is. I've tried to match the strings supported to the latest version of gcc.

I've only tested this on my Macbook so far so I'd appreciate if others would test it. An AMD system would be great.

Diff Detail

Repository
rL LLVM

Event Timeline

craig.topper created this revision.Jul 14 2017, 10:42 PM
RKSimon edited edge metadata.Jul 15 2017, 12:21 PM

I don't have much experience with this builtin - does gcc use it for anything but x86? google didn't turn up much.

I think gcc supports builtin_cpu_supports and builtin_cpu_is for non-x86. We already have an x86 only implementation of __builtin_cpu_supports so I did the same here.

I'm considering making validateCpuIs return a std::pair with the appropriate value and a tag that indicates invalid/vendor/type/subtype. This way we can remove the target based string decoding from CodeGen by reusing the validate function(with a better name). Sema can look for the invalid tag for its error.

We could also make validateCpuSupports return the feature bit number for __builtin_cpu_supports and reuse it in CodeGen.

echristo edited edge metadata.Jul 18 2017, 8:55 AM
echristo added a subscriber: erichkeane.

Adding Erich Keane here on this since he's working on something similar for the target attribute.

-eric

From my perspective here once you and Erich get some agreement on the checking between your two bits I'm fine :)

-eric

FWIW the duplication in CGCall.cpp of the enum set is painful if you can come up with anything else it'd be awesome. I don't have any good ideas, just a fond wish :)

@erichkeane are you ok with this code for now? I think validateCPUIs gives you what you need at least for Sema support for target attribute. You'll probably need to refactor the CG code to make your ifunc resolver. But I think you need to do that for the existing feature code that's similar anyway. And from our side conversation it sounds like you're not ready for that yet.

erichkeane edited edge metadata.Jul 31 2017, 11:57 AM

@erichkeane are you ok with this code for now? I think validateCPUIs gives you what you need at least for Sema support for target attribute. You'll probably need to refactor the CG code to make your ifunc resolver. But I think you need to do that for the existing feature code that's similar anyway. And from our side conversation it sounds like you're not ready for that yet.

Thats correct. I think this is right based on what I currently understand, though you/I will likely need to make some additional modifications to support my features.

echristo accepted this revision.Aug 10 2017, 3:23 AM

SGTM.

-eric

This revision is now accepted and ready to land.Aug 10 2017, 3:23 AM
This revision was automatically updated to reflect the committed changes.