Skip to content

Commit 3036d96

Browse files
committed
Move/update comments, minor refactoring
1 parent 8d903db commit 3036d96

File tree

1 file changed

+34
-43
lines changed

1 file changed

+34
-43
lines changed

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 34 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,6 @@ class DecoderEmitter {
167167

168168
const CodeGenTarget &getTarget() const { return Target; }
169169

170-
// Emit the decoder state machine table.
171-
void emitTable(formatted_raw_ostream &OS, DecoderTableInfo &TableInfo,
172-
StringRef Namespace, unsigned HwModeID, unsigned BitWidth,
173-
const DecoderTreeNode *Tree) const;
174170
void emitInstrLenTable(formatted_raw_ostream &OS,
175171
ArrayRef<unsigned> InstrLen) const;
176172
void emitPredicateFunction(formatted_raw_ostream &OS,
@@ -1189,9 +1185,7 @@ class DecoderTreeBuilder {
11891185
ArrayRef<InstructionEncoding> Encodings)
11901186
: Target(Target), Encodings(Encodings) {}
11911187

1192-
std::unique_ptr<DecoderTreeNode> buildTree(const FilterChooser &FC) {
1193-
return convertFilterChooser(&FC);
1194-
}
1188+
std::unique_ptr<DecoderTreeNode> buildTree(ArrayRef<unsigned> EncodingIDs);
11951189

11961190
private:
11971191
std::unique_ptr<DecoderTreeNode>
@@ -1271,6 +1265,14 @@ DecoderTreeBuilder::convertFilterChooser(const FilterChooser *FC) {
12711265
return N;
12721266
}
12731267

1268+
std::unique_ptr<DecoderTreeNode>
1269+
DecoderTreeBuilder::buildTree(ArrayRef<unsigned> EncodingIDs) {
1270+
FilterChooser FC(Encodings, EncodingIDs);
1271+
if (FC.hasConflict())
1272+
return nullptr;
1273+
return convertFilterChooser(&FC);
1274+
}
1275+
12741276
/// Collects all HwModes referenced by the target for encoding purposes.
12751277
void DecoderEmitter::collectHwModesReferencedForEncodings(
12761278
std::vector<unsigned> &HwModeIDs,
@@ -1438,22 +1440,6 @@ DecoderEmitter::DecoderEmitter(const RecordKeeper &RK)
14381440
parseInstructionEncodings();
14391441
}
14401442

1441-
// Emit the decoder state machine table.
1442-
void DecoderEmitter::emitTable(formatted_raw_ostream &OS,
1443-
DecoderTableInfo &TableInfo, StringRef Namespace,
1444-
unsigned HwModeID, unsigned BitWidth,
1445-
const DecoderTreeNode *Tree) const {
1446-
SmallString<32> TableName("DecoderTable");
1447-
TableName.append(Namespace);
1448-
if (HwModeID != DefaultMode)
1449-
TableName.append({"_", Target.getHwModes().getModeName(HwModeID)});
1450-
TableName.append(utostr(BitWidth));
1451-
1452-
DecoderTableEmitter TableEmitter(TableInfo, OS);
1453-
TableEmitter.emitTable(TableName,
1454-
SpecializeDecodersPerBitwidth ? BitWidth : 0, Tree);
1455-
}
1456-
14571443
// Emits disassembler code for instruction decoding.
14581444
void DecoderEmitter::run(raw_ostream &o) const {
14591445
formatted_raw_ostream OS(o);
@@ -1522,35 +1508,40 @@ template <typename T> constexpr uint32_t InsnBitWidth = 0;
15221508
PrintFatalError(
15231509
"Cannot specialize decoders for variable length instuctions");
15241510

1525-
// Entries in `EncMap` are already sorted by bitwidth. So bucketing per
1526-
// bitwidth can be done on-the-fly as we iterate over the map.
15271511
DecoderTableInfo TableInfo{};
1512+
DecoderTreeBuilder TreeBuilder(Target, Encodings);
1513+
DecoderTableEmitter TableEmitter(TableInfo, OS);
15281514

1515+
// Emit a table for each (namespace, hwmode, bitwidth) combination.
1516+
// Predicates and decoders are shared across the tables to provide more
1517+
// opportunities for uniqueness. If SpecializeDecodersPerBitwidth is enabled,
1518+
// decoders are shared across all tables for a given bitwidth, else they are
1519+
// shared across all tables. Predicates are always shared across all tables.
1520+
//
1521+
// Entries in `EncMap` are already sorted by bitwidth. So bucketing per
1522+
// bitwidth can be done on-the-fly as we iterate over the map.
15291523
bool HasConflict = false;
15301524
for (const auto &[BitWidth, BWMap] : EncMap) {
15311525
for (const auto &[Key, EncodingIDs] : BWMap) {
15321526
auto [DecoderNamespace, HwModeID] = Key;
15331527

1534-
// Emit the decoder for this (namespace, hwmode, width) combination.
1535-
FilterChooser FC(Encodings, EncodingIDs);
1536-
HasConflict |= FC.hasConflict();
1537-
// Skip emitting table entries if a conflict has been detected.
1538-
if (HasConflict)
1528+
std::unique_ptr<DecoderTreeNode> Tree =
1529+
TreeBuilder.buildTree(EncodingIDs);
1530+
1531+
// Skip emitting the table if a conflict has been detected.
1532+
if (!Tree) {
1533+
HasConflict = true;
15391534
continue;
1535+
}
1536+
1537+
// Form the table name.
1538+
SmallString<32> TableName({"DecoderTable", DecoderNamespace});
1539+
if (HwModeID != DefaultMode)
1540+
TableName.append({"_", Target.getHwModes().getModeName(HwModeID)});
1541+
TableName.append(utostr(BitWidth));
15401542

1541-
DecoderTreeBuilder TreeBuilder(Target, Encodings);
1542-
std::unique_ptr<DecoderTreeNode> Tree = TreeBuilder.buildTree(FC);
1543-
1544-
// The decode table is cleared for each top level decoder function. The
1545-
// predicates and decoders themselves, however, are shared across
1546-
// different decoders to give more opportunities for uniqueing.
1547-
// - If `SpecializeDecodersPerBitwidth` is enabled, decoders are shared
1548-
// across all decoder tables for a given bitwidth, else they are shared
1549-
// across all decoder tables.
1550-
// - predicates are shared across all decoder tables.
1551-
// Print the table to the output stream.
1552-
emitTable(OS, TableInfo, DecoderNamespace, HwModeID, BitWidth,
1553-
Tree.get());
1543+
TableEmitter.emitTable(
1544+
TableName, SpecializeDecodersPerBitwidth ? BitWidth : 0, Tree.get());
15541545
}
15551546

15561547
// Each BitWidth get's its own decoders and decoder function if

0 commit comments

Comments
 (0)