Skip to content

[MC] Speed up checkFeatures() (NFCI) #130936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions llvm/lib/MC/MCSubtargetInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,14 +317,18 @@ FeatureBitset MCSubtargetInfo::ApplyFeatureFlag(StringRef FS) {

bool MCSubtargetInfo::checkFeatures(StringRef FS) const {
SubtargetFeatures T(FS);
FeatureBitset Set, All;
for (std::string F : T.getFeatures()) {
::ApplyFeatureFlag(Set, F, ProcFeatures);
if (F[0] == '-')
F[0] = '+';
::ApplyFeatureFlag(All, F, ProcFeatures);
}
return (FeatureBits & All) == Set;
return all_of(T.getFeatures(), [this](const std::string &F) {
assert(SubtargetFeatures::hasFlag(F) &&
"Feature flags should start with '+' or '-'");
const SubtargetFeatureKV *FeatureEntry =
Find(SubtargetFeatures::StripFlag(F), ProcFeatures);
if (!FeatureEntry)
report_fatal_error(Twine("'") + F +
"' is not a recognized feature for this target");

return FeatureBits.test(FeatureEntry->Value) ==
SubtargetFeatures::isEnabled(F);
});
}

const MCSchedModel &MCSubtargetInfo::getSchedModelForCPU(StringRef CPU) const {
Expand Down