Skip to content

Commit b8dc2db

Browse files
committed
Review feedback
1 parent eea9dbc commit b8dc2db

File tree

1 file changed

+27
-19
lines changed

1 file changed

+27
-19
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static cl::opt<bool> LargeTable(
8484
"in the table instead of the default 16 bits."),
8585
cl::init(false), cl::cat(DisassemblerEmitterCat));
8686

87-
static cl::opt<bool> UseFnTableInDecodeToMCInst(
87+
static cl::opt<bool> UseFnTableInDecodetoMCInst(
8888
"use-fn-table-in-decode-to-mcinst",
8989
cl::desc(
9090
"Use a table of function pointers instead of a switch case in the\n"
@@ -251,8 +251,7 @@ class DecoderEmitter {
251251
//
252252
// BIT_UNFILTERED is used as the init value for a filter position. It is used
253253
// only for filter processings.
254-
class BitValue {
255-
public:
254+
struct BitValue {
256255
enum bit_value_t : uint8_t {
257256
BIT_FALSE, // '0'
258257
BIT_TRUE, // '1'
@@ -261,25 +260,37 @@ class BitValue {
261260
};
262261

263262
BitValue(bit_value_t V) : V(V) {}
264-
BitValue(const Init *Init) {
265-
if (const BitInit *Bit = dyn_cast<BitInit>(Init))
263+
explicit BitValue(const Init *Init) {
264+
if (const auto *Bit = dyn_cast<BitInit>(Init))
266265
V = Bit->getValue() ? BIT_TRUE : BIT_FALSE;
267266
else
268267
V = BIT_UNSET;
269268
}
270269
BitValue(const BitsInit &Bits, unsigned Idx) : BitValue(Bits.getBit(Idx)) {}
271270

272-
bool isSet(void) const { return V == BIT_TRUE || V == BIT_FALSE; }
273-
bool isUnset(void) const { return V == BIT_UNSET; }
274-
std::optional<uint64_t> getValue(void) const {
271+
bool isSet() const { return V == BIT_TRUE || V == BIT_FALSE; }
272+
bool isUnset() const { return V == BIT_UNSET; }
273+
std::optional<uint64_t> getValue() const {
275274
if (isSet())
276275
return static_cast<uint64_t>(V);
277276
return std::nullopt;
278277
}
279278
bit_value_t getRawValue() const { return V; }
280279

281280
// For printing a bit value.
282-
operator StringRef() const { return StringRef("01_.").slice(V, V + 1); }
281+
operator StringRef() const {
282+
switch (V) {
283+
case BIT_FALSE:
284+
return "0";
285+
case BIT_TRUE:
286+
return "1";
287+
case BIT_UNSET:
288+
return "_";
289+
case BIT_UNFILTERED:
290+
return ".";
291+
}
292+
llvm_unreachable("Unknow bit value");
293+
}
283294

284295
bool operator==(bit_value_t Other) const { return Other == V; }
285296
bool operator!=(bit_value_t Other) const { return Other != V; }
@@ -318,7 +329,7 @@ static const BitsInit &getBitsField(const Record &Def, StringRef FieldName) {
318329
else if (const BitInit *BI = dyn_cast<BitInit>(SI.Value))
319330
Bits.push_back(BI);
320331
else
321-
Bits.insert(Bits.end(), SI.BitWidth, UnsetInit::get(Def.getRecords()));
332+
Bits.append(SI.BitWidth, UnsetInit::get(Def.getRecords()));
322333
}
323334

324335
return *BitsInit::get(Def.getRecords(), Bits);
@@ -1072,7 +1083,7 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
10721083
"DecodeStatus S, InsnType insn, MCInst &MI, uint64_t Address, const "
10731084
"MCDisassembler *Decoder, bool &DecodeComplete";
10741085

1075-
if (UseFnTableInDecodeToMCInst) {
1086+
if (UseFnTableInDecodetoMCInst) {
10761087
// Emit a function for each case first.
10771088
for (const auto &[Index, Decoder] : enumerate(Decoders)) {
10781089
OS << Indent << "template <typename InsnType>\n";
@@ -1095,7 +1106,7 @@ void DecoderEmitter::emitDecoderFunction(formatted_raw_ostream &OS,
10951106
Indent += 2;
10961107
OS << Indent << "DecodeComplete = true;\n";
10971108

1098-
if (UseFnTableInDecodeToMCInst) {
1109+
if (UseFnTableInDecodetoMCInst) {
10991110
// Build a table of function pointers.
11001111
OS << Indent << "using DecodeFnTy = DecodeStatus (*)(" << DecodeParams
11011112
<< ");\n";
@@ -1282,7 +1293,7 @@ std::pair<unsigned, bool> FilterChooser::getDecoderIndex(DecoderSet &Decoders,
12821293
// FIXME: emitDecoder() function can take a buffer directly rather than
12831294
// a stream.
12841295
raw_svector_ostream S(Decoder);
1285-
indent Indent(UseFnTableInDecodeToMCInst ? 2 : 4);
1296+
indent Indent(UseFnTableInDecodetoMCInst ? 2 : 4);
12861297
bool HasCompleteDecoder = emitDecoder(S, Indent, Opc);
12871298

12881299
// Using the full decoder string as the key value here is a bit
@@ -1430,16 +1441,13 @@ void FilterChooser::emitSoftFailTableEntry(DecoderTableInfo &TableInfo,
14301441
if (B != BitValue::BIT_TRUE)
14311442
continue;
14321443

1433-
switch (IB.getRawValue()) {
1434-
case BitValue::BIT_FALSE:
1444+
if (IB == BitValue::BIT_FALSE) {
14351445
// The bit is meant to be false, so emit a check to see if it is true.
14361446
PositiveMask.setBit(i);
1437-
break;
1438-
case BitValue::BIT_TRUE:
1447+
} else if (IB == BitValue::BIT_TRUE) {
14391448
// The bit is meant to be true, so emit a check to see if it is false.
14401449
NegativeMask.setBit(i);
1441-
break;
1442-
default:
1450+
} else {
14431451
// The bit is not set; this must be an error!
14441452
errs() << "SoftFail Conflict: bit SoftFail{" << i << "} in "
14451453
<< AllInstructions[Opc] << " is set but Inst{" << i

0 commit comments

Comments
 (0)