Skip to content

Commit ac9133d

Browse files
committed
[RISCV] Use hasFeature instead of checkFeature in llvm-exegesis. NFC
Until recently checkFeature was quite slow. llvm#130936 I was curious where we use checkFeature and noticed these. I thought we could use hasFeature instead of going through strings.
1 parent 2490f7f commit ac9133d

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

llvm/tools/llvm-exegesis/lib/RISCV/Target.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,33 @@ template <class BaseT> class RISCVSnippetGenerator : public BaseT {
156156
// FIXME: We could have obtained these two constants from RISCVSubtarget
157157
// but in order to get that from TargetMachine, we need a Function.
158158
const MCSubtargetInfo &STI = State.getSubtargetInfo();
159-
ELEN = STI.checkFeatures("+zve64x") ? 64 : 32;
160-
161-
std::string ZvlQuery;
162-
for (unsigned Size = 32; Size <= 65536; Size *= 2) {
163-
ZvlQuery = "+zvl";
164-
raw_string_ostream SS(ZvlQuery);
165-
SS << Size << "b";
166-
if (STI.checkFeatures(SS.str()) && ZvlVLen < Size)
167-
ZvlVLen = Size;
159+
ELEN = STI.hasFeature(RISCV::FeatureStdExtZve64x) ? 64 : 32;
160+
161+
static_assert(RISCV::FeatureStdExtZvl64b == RISCV::FeatureStdExtZvl32b + 1);
162+
static_assert(RISCV::FeatureStdExtZvl128b ==
163+
RISCV::FeatureStdExtZvl32b + 2);
164+
static_assert(RISCV::FeatureStdExtZvl256b ==
165+
RISCV::FeatureStdExtZvl32b + 3);
166+
static_assert(RISCV::FeatureStdExtZvl512b ==
167+
RISCV::FeatureStdExtZvl32b + 4);
168+
static_assert(RISCV::FeatureStdExtZvl1024b ==
169+
RISCV::FeatureStdExtZvl32b + 5);
170+
static_assert(RISCV::FeatureStdExtZvl2048b ==
171+
RISCV::FeatureStdExtZvl32b + 6);
172+
static_assert(RISCV::FeatureStdExtZvl4096b ==
173+
RISCV::FeatureStdExtZvl32b + 7);
174+
static_assert(RISCV::FeatureStdExtZvl8192b ==
175+
RISCV::FeatureStdExtZvl32b + 8);
176+
static_assert(RISCV::FeatureStdExtZvl16384b ==
177+
RISCV::FeatureStdExtZvl32b + 9);
178+
static_assert(RISCV::FeatureStdExtZvl32768b ==
179+
RISCV::FeatureStdExtZvl32b + 10);
180+
static_assert(RISCV::FeatureStdExtZvl65536b ==
181+
RISCV::FeatureStdExtZvl32b + 11);
182+
for (unsigned Feature = RISCV::FeatureStdExtZvl32b, Size = 32;
183+
Size <= 65536; ++Feature, Size *= 2) {
184+
if (STI.hasFeature(Feature))
185+
ZvlVLen = std::max(ZvlVLen, Size);
168186
}
169187
}
170188

0 commit comments

Comments
 (0)