Skip to content

Commit 7e0cb43

Browse files
committed
Review feedback
1 parent eea9dbc commit 7e0cb43

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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);
@@ -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)