[PATCH] D158814: [X86] Merge FeatureInfos_WithPLUS and FeatureInfos. NFC
Craig Topper via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 24 22:06:56 PDT 2023
craig.topper created this revision.
craig.topper added reviewers: RKSimon, pengfei, FreddyYe.
Herald added a subscriber: hiraditya.
Herald added a project: All.
craig.topper requested review of this revision.
Herald added a project: LLVM.
Store the string with the '+' in FeatureInfos. Drop the '+'
at runtime for the users that don't want it.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D158814
Files:
llvm/include/llvm/TargetParser/X86TargetParser.h
llvm/lib/TargetParser/X86TargetParser.cpp
Index: llvm/lib/TargetParser/X86TargetParser.cpp
===================================================================
--- llvm/lib/TargetParser/X86TargetParser.cpp
+++ llvm/lib/TargetParser/X86TargetParser.cpp
@@ -32,8 +32,14 @@
};
struct FeatureInfo {
- StringLiteral Name;
+ StringLiteral NameWithPlus;
FeatureBitset ImpliedFeatures;
+
+ StringRef getName(bool WithPlus = false) const {
+ if (WithPlus)
+ return NameWithPlus;
+ return NameWithPlus.drop_front();
+ }
};
} // end anonymous namespace
@@ -603,18 +609,13 @@
constexpr FeatureBitset ImpliedFeaturesAVXVNNI = FeatureAVX2;
constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = {
-#define X86_FEATURE(ENUM, STR) {{STR}, ImpliedFeatures##ENUM},
-#include "llvm/TargetParser/X86TargetParser.def"
-};
-
-constexpr FeatureInfo FeatureInfos_WithPLUS[X86::CPU_FEATURE_MAX] = {
#define X86_FEATURE(ENUM, STR) {{"+" STR}, ImpliedFeatures##ENUM},
#include "llvm/TargetParser/X86TargetParser.def"
};
void llvm::X86::getFeaturesForCPU(StringRef CPU,
SmallVectorImpl<StringRef> &EnabledFeatures,
- bool IfNeedPlus) {
+ bool NeedPlus) {
auto I = llvm::find_if(Processors,
[&](const ProcInfo &P) { return P.Name == CPU; });
assert(I != std::end(Processors) && "Processor not found!");
@@ -627,11 +628,8 @@
// Add the string version of all set bits.
for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
- if (Bits[i] && !FeatureInfos[i].Name.empty() &&
- !FeatureInfos_WithPLUS[i].Name.empty()){
- EnabledFeatures.push_back(IfNeedPlus ? FeatureInfos_WithPLUS[i].Name
- : FeatureInfos[i].Name);
- }
+ if (Bits[i] && !FeatureInfos[i].getName(NeedPlus).empty())
+ EnabledFeatures.push_back(FeatureInfos[i].getName(NeedPlus));
}
// For each feature that is (transitively) implied by this feature, set it.
@@ -668,8 +666,9 @@
void llvm::X86::updateImpliedFeatures(
StringRef Feature, bool Enabled,
StringMap<bool> &Features) {
- auto I = llvm::find_if(
- FeatureInfos, [&](const FeatureInfo &FI) { return FI.Name == Feature; });
+ auto I = llvm::find_if(FeatureInfos, [&](const FeatureInfo &FI) {
+ return FI.getName() == Feature;
+ });
if (I == std::end(FeatureInfos)) {
// FIXME: This shouldn't happen, but may not have all features in the table
// yet.
@@ -685,8 +684,8 @@
// Update the map entry for all implied features.
for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
- if (ImpliedBits[i] && !FeatureInfos[i].Name.empty())
- Features[FeatureInfos[i].Name] = Enabled;
+ if (ImpliedBits[i] && !FeatureInfos[i].getName().empty())
+ Features[FeatureInfos[i].getName()] = Enabled;
}
char llvm::X86::getCPUDispatchMangling(StringRef CPU) {
Index: llvm/include/llvm/TargetParser/X86TargetParser.h
===================================================================
--- llvm/include/llvm/TargetParser/X86TargetParser.h
+++ llvm/include/llvm/TargetParser/X86TargetParser.h
@@ -160,9 +160,9 @@
ProcessorFeatures getKeyFeature(CPUKind Kind);
/// Fill in the features that \p CPU supports into \p Features.
-/// "+" will be append in front of each feature if IfNeedPlus is true.
+/// "+" will be append in front of each feature if NeedPlus is true.
void getFeaturesForCPU(StringRef CPU, SmallVectorImpl<StringRef> &Features,
- bool IfNeedPlus = false);
+ bool NeedPlus = false);
/// Set or clear entries in \p Features that are implied to be enabled/disabled
/// by the provided \p Feature.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158814.553353.patch
Type: text/x-patch
Size: 3689 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230825/1d159f65/attachment.bin>
More information about the llvm-commits
mailing list