[llvm] [NFC][MC][DecoderEmitter] Simplify loop to find the best filter (PR #156237)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Sun Aug 31 04:24:56 PDT 2025
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/156237
Eliminate `AllUseless` as that can be inferred as `BestScore == 0`. Track pointer instead of index for the best filter.
>From 98eabb8b0b7cea41b44358c42adcad6316114843 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Sat, 30 Aug 2025 16:33:48 -0700
Subject: [PATCH] [NFC][MC][DecoderEmitter] Simplify loop to find the best
filter
---
llvm/utils/TableGen/DecoderEmitter.cpp | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git a/llvm/utils/TableGen/DecoderEmitter.cpp b/llvm/utils/TableGen/DecoderEmitter.cpp
index 98569abfbb1a4..871e06a07a7b3 100644
--- a/llvm/utils/TableGen/DecoderEmitter.cpp
+++ b/llvm/utils/TableGen/DecoderEmitter.cpp
@@ -1473,26 +1473,21 @@ FilterChooser::findBestFilter(ArrayRef<bitAttr_t> BitAttrs, bool AllowMixed,
// We have finished with the filter processings. Now it's time to choose
// the best performing filter.
- unsigned BestIndex = 0;
- bool AllUseless = true;
+ std::unique_ptr<Filter> *BestFilter = nullptr;
unsigned BestScore = 0;
- for (const auto &[Idx, Filter] : enumerate(Filters)) {
+ for (std::unique_ptr<Filter> &Filter : Filters) {
unsigned Usefulness = Filter->usefulness();
-
- if (Usefulness)
- AllUseless = false;
-
if (Usefulness > BestScore) {
- BestIndex = Idx;
+ BestFilter = &Filter;
BestScore = Usefulness;
}
}
- if (AllUseless)
+ if (BestFilter == nullptr)
return nullptr;
- return std::move(Filters[BestIndex]);
+ return std::move(*BestFilter);
}
std::unique_ptr<Filter> FilterChooser::findBestFilter() const {
More information about the llvm-commits
mailing list