Skip to content

Commit 428a769

Browse files
nikicfrederik-h
authored andcommitted
[MC] Speed up checkFeatures() (NFCI) (llvm#130936)
checkFeatures() currently goes through ApplyFeatureFlag(), which will also handle implied features. This is very slow -- just querying every feature once takes up 10% of a Rust hello world compile. However, if we only want to query whether certain features are set/unset, we can do so directly -- implied features have already been handled when the FeatureBitset was constructed.
1 parent d1d9a8f commit 428a769

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

llvm/lib/MC/MCSubtargetInfo.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -317,14 +317,18 @@ FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) {
317317

318318
bool MCSubtargetInfo::checkFeatures(StringRef FS) const {
319319
SubtargetFeatures T(FS);
320-
FeatureBitset Set, All;
321-
for (std::string F : T.getFeatures()) {
322-
::ApplyFeatureFlag(Set, F, ProcFeatures);
323-
if (F[0] == '-')
324-
F[0] = '+';
325-
::ApplyFeatureFlag(All, F, ProcFeatures);
326-
}
327-
return (FeatureBits & All) == Set;
320+
return all_of(T.getFeatures(), [this](const std::string &F) {
321+
assert(SubtargetFeatures::hasFlag(F) &&
322+
"Feature flags should start with '+' or '-'");
323+
const SubtargetFeatureKV *FeatureEntry =
324+
Find(SubtargetFeatures::StripFlag(F), ProcFeatures);
325+
if (!FeatureEntry)
326+
report_fatal_error(Twine("'") + F +
327+
"' is not a recognized feature for this target");
328+
329+
return FeatureBits.test(FeatureEntry->Value) ==
330+
SubtargetFeatures::isEnabled(F);
331+
});
328332
}
329333

330334
const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {

0 commit comments

Comments
 (0)