Skip to content

Commit ef6cf12

Browse files
toppercmemfrob
authored and
memfrob
committed
[X86] Rename X86::getImpliedFeatures to X86::updateImpliedFeatures and pass clang's StringMap directly to it.
No point in building a vector of StringRefs for clang to apply to the StringMap. Just pass the StringMap and modify it directly.
1 parent ef2e268 commit ef6cf12

File tree

3 files changed

+14
-21
lines changed

3 files changed

+14
-21
lines changed

clang/lib/Basic/Targets/X86.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,7 @@ void X86TargetInfo::setFeatureEnabled(llvm::StringMap<bool> &Features,
159159
}
160160

161161
Features[Name] = Enabled;
162-
163-
SmallVector<StringRef, 8> ImpliedFeatures;
164-
llvm::X86::getImpliedFeatures(Name, Enabled, ImpliedFeatures);
165-
for (const auto &F : ImpliedFeatures)
166-
Features[F] = Enabled;
162+
llvm::X86::updateImpliedFeatures(Name, Enabled, Features);
167163
}
168164

169165
/// handleTargetFeatures - Perform initialization based on the user

llvm/include/llvm/Support/X86TargetParser.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_SUPPORT_X86TARGETPARSERCOMMON_H
1515

1616
#include "llvm/ADT/SmallVector.h"
17+
#include "llvm/ADT/StringMap.h"
1718

1819
namespace llvm {
1920
class StringRef;
@@ -137,10 +138,10 @@ ProcessorFeatures getKeyFeature(CPUKind Kind);
137138
/// Fill in the features that \p CPU supports into \p Features.
138139
void getFeaturesForCPU(StringRef CPU, SmallVectorImpl<StringRef> &Features);
139140

140-
/// Fill \p Features with the features that are implied to be enabled/disabled
141+
/// Set or clear entries in \p Features that are implied to be enabled/disabled
141142
/// by the provided \p Feature.
142-
void getImpliedFeatures(StringRef Feature, bool Enabled,
143-
SmallVectorImpl<StringRef> &Features);
143+
void updateImpliedFeatures(StringRef Feature, bool Enabled,
144+
StringMap<bool> &Features);
144145

145146
} // namespace X86
146147
} // namespace llvm

llvm/lib/Support/X86TargetParser.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,6 @@ static constexpr FeatureInfo FeatureInfos[X86::CPU_FEATURE_MAX] = {
536536
#include "llvm/Support/X86TargetParser.def"
537537
};
538538

539-
// Convert the set bits in FeatureBitset to a list of strings.
540-
static void getFeatureBitsAsStrings(const FeatureBitset &Bits,
541-
SmallVectorImpl<StringRef> &Features) {
542-
for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
543-
if (Bits[i] && !FeatureInfos[i].Name.empty())
544-
Features.push_back(FeatureInfos[i].Name);
545-
}
546-
547539
void llvm::X86::getFeaturesForCPU(StringRef CPU,
548540
SmallVectorImpl<StringRef> &EnabledFeatures) {
549541
auto I = llvm::find_if(Processors,
@@ -557,7 +549,9 @@ void llvm::X86::getFeaturesForCPU(StringRef CPU,
557549
Bits &= ~Feature64BIT;
558550

559551
// Add the string version of all set bits.
560-
getFeatureBitsAsStrings(Bits, EnabledFeatures);
552+
for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
553+
if (Bits[i] && !FeatureInfos[i].Name.empty())
554+
EnabledFeatures.push_back(FeatureInfos[i].Name);
561555
}
562556

563557
// For each feature that is (transitively) implied by this feature, set it.
@@ -591,9 +585,9 @@ static void getImpliedDisabledFeatures(FeatureBitset &Bits, unsigned Value) {
591585
} while (Prev != Bits);
592586
}
593587

594-
void llvm::X86::getImpliedFeatures(
588+
void llvm::X86::updateImpliedFeatures(
595589
StringRef Feature, bool Enabled,
596-
SmallVectorImpl<StringRef> &ImpliedFeatures) {
590+
StringMap<bool> &Features) {
597591
auto I = llvm::find_if(
598592
FeatureInfos, [&](const FeatureInfo &FI) { return FI.Name == Feature; });
599593
if (I == std::end(FeatureInfos)) {
@@ -609,6 +603,8 @@ void llvm::X86::getImpliedFeatures(
609603
getImpliedDisabledFeatures(ImpliedBits,
610604
std::distance(std::begin(FeatureInfos), I));
611605

612-
// Convert all the found bits into strings.
613-
getFeatureBitsAsStrings(ImpliedBits, ImpliedFeatures);
606+
// Update the map entry for all implied features.
607+
for (unsigned i = 0; i != CPU_FEATURE_MAX; ++i)
608+
if (ImpliedBits[i] && !FeatureInfos[i].Name.empty())
609+
Features[FeatureInfos[i].Name] = Enabled;
614610
}

0 commit comments

Comments
 (0)