This is an archive of the discontinued LLVM Phabricator instance.

[NFC][clang] Use X86 Features declaration from X86TargetParser
ClosedPublic

Authored by a.elovikov on Aug 16 2021, 11:58 AM.

Details

Summary

...instead of redeclaring them in clang's own X86Target.def. They were already
required to be in sync (IIUC), so no reason to maintain two identical lists.

Diff Detail

Unit TestsFailed

Event Timeline

a.elovikov created this revision.Aug 16 2021, 11:58 AM
a.elovikov requested review of this revision.Aug 16 2021, 11:59 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2021, 11:59 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Are these in the same order in X86TargetParser.Def? Can we make some comment in that file to make sure that we keep them in the order (see comment in original x86Target.def)?

The order in X86Parser.def is determined by how bits are allocated in to feature vector in libgcc. They're not in any priority order that I know of.

a.elovikov planned changes to this revision.Aug 16 2021, 1:42 PM

Another version. My main goal here is to gradually move more stuff from clang/
to llvm/ so I'm open to other suggestions in doing so.

Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2021, 4:06 PM
craig.topper added inline comments.Aug 19 2021, 7:39 AM
clang/lib/Basic/Targets/X86.cpp
1060–1062

priorites -> priorities

1064

Maybe just wrap this all in #ifndef NDEBUG?

1066

array_lengthof(Priorities) - 1

erichkeane added inline comments.Aug 19 2021, 7:44 AM
clang/lib/Basic/Targets/X86.cpp
1068

If all you care about is whether they are a consecutive range, why not just use std::is_sorted?

craig.topper added inline comments.Aug 19 2021, 7:48 AM
clang/lib/Basic/Targets/X86.cpp
1068

The Priorities array isn't sorted. It's just whatever order the X86_FEATURE_COMPAT lists them.

The values need to be unique and in a contiguous range.

erichkeane added inline comments.Aug 19 2021, 8:15 AM
clang/lib/Basic/Targets/X86.cpp
1068

Then I'd suggest something like: llvm::sort, then assert *(end - 1) - *begin == std::distance(begin, end) && llvm::adjacent_find or something.

I definitely didn't get that point out of this odd for-loop and is_contained. There is perhaps at trick with std::min and std::max too. Though, it looks like this is perhaps trying to prove that the range is 0 to the the array size, right? In that case, perhaps there is something easier.

Also a nit, it is consecutive in that case.

erichkeane added inline comments.Aug 19 2021, 8:18 AM
clang/lib/Basic/Targets/X86.cpp
1068

Actually...

std::array<unsigned, array_lengthof(Priorities) -1> HelperList;
std::iota(HelperList.begin(), HelperList.end());
std::is_permutation(HelperList.begin(), HelperList.end(),  
        std::begin(Priorities), std::end(Priorities));

Apply reviewers' suggestions. Thanks!

a.elovikov marked 3 inline comments as done.Aug 19 2021, 3:56 PM
a.elovikov added inline comments.
clang/lib/Basic/Targets/X86.cpp
1068

I thought about std::sort + std::iota + std::equal but wasn't sure how readable that would be with the extra helper object (range version isn't available in C++14) and hoped my version would be more compact.

Since it wasn't obvious what it does I shamelessly copied your suggestion (and learnt about std::is_permutation and array_lengthof when doing it).

Thanks!

a.elovikov marked an inline comment as done.Aug 23 2021, 9:26 AM

Hi guys, do you want me to fix anything else? I think I've addressed what I could.

erichkeane accepted this revision.Aug 23 2021, 9:31 AM

2 nits, give Craig a day or two to =1 as well please, particularly since he's the code-owner here.

clang/lib/Basic/Targets/X86.cpp
1061

Just a nit, I would like a better description here of the constraint we're trying to enforce. I can imagine someone in the future failing this, and not getting the context without a few sentences of how no duplicates are allowed, and it must be all numbers from 0 to the-max-number.

1069
This revision is now accepted and ready to land.Aug 23 2021, 9:31 AM

Address Erich's comments

erichkeane accepted this revision.Aug 23 2021, 11:54 AM
This revision was landed with ongoing or failed builds.Aug 23 2021, 12:30 PM
This revision was automatically updated to reflect the committed changes.