[PATCH] D82731: [X86] Move frontend CPU feature initialization to a look up table based implementation.

Craig Topper via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jun 28 16:06:27 PDT 2020


craig.topper created this revision.
craig.topper added reviewers: RKSimon, spatel, LuoYuanke, LiuChen3, echristo, FreddyYe.
Herald added subscribers: jfb, hiraditya.
Herald added projects: clang, LLVM.
craig.topper added a reviewer: erichkeane.

This replaces the switch statement implementation in the clang's
X86.cpp with a lookup table X86TargetParser.cpp.

I've used constexpr and copy of the FeatureBitset from
SubtargetFeature.h to store the features in a lookup table.
After the lookup the bitset is translated into strings for use
by the rest of the frontend code.

I had to modify the implementation of the FeatureBitset to avoid
bugs in libgcc's constexpr handling. It seems to not like the
same array entry to be used on the left side and right hand side
of an assignment or &= or |=. I've also used uint32_t instead of
uint64_t and sized based on the X86::CPU_FEATURE_MAX.

I've initialized the features for different CPUs outside of the
table so that they can be inherited from to express inheritance in
an adhoc way. This was one of the big limitations of the switch
where had resorted to labels and gotos.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82731

Files:
  clang/lib/Basic/Targets/X86.cpp
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/Preprocessor/predefined-arch-macros.c
  llvm/include/llvm/Support/X86TargetParser.def
  llvm/include/llvm/Support/X86TargetParser.h
  llvm/lib/Support/X86TargetParser.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D82731.273979.patch
Type: text/x-patch
Size: 48048 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200628/531206e4/attachment-0001.bin>


More information about the cfe-commits mailing list