Skip to content

Commit ea4325f

Browse files
authored
[TableGen][DecoderEmitter] Improve conflicts dump (#154001)
* Print filter stack in non-reversed order. * Print encoding name to the right of encoding bits to deal with alignment issues. * Use the correct bit width when printing encoding bits. Example of old output: ``` 01000100........ 01000........... 0100............ ................ tADDhirr 000000000000000001000100________ tADDrSP 000000000000000001000100_1101___ tADDspr 0000000000000000010001001____101 ``` New output: ``` ................ 0100............ 01000........... 01000100........ 01000100________ tADDhirr 01000100_1101___ tADDrSP 010001001____101 tADDspr ```
1 parent 05f1673 commit ea4325f

File tree

2 files changed

+32
-33
lines changed

2 files changed

+32
-33
lines changed

llvm/test/TableGen/FixedLenDecoderEmitter/conflict.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def B : I<(outs GPR32:$dst), (ins GPR32:$src1), []> {
2929
}
3030

3131
// CHECK: Decoding Conflict:
32-
// CHECK: 00000000000000000000000000000000
33-
// CHECK: ................................
34-
// CHECK: A 00000000000000000000000000000000
35-
// CHECK: B 00000000000000000000000000000000
32+
// CHECK: ................................
33+
// CHECK: 00000000000000000000000000000000
34+
// CHECK: 00000000000000000000000000000000 A
35+
// CHECK: 00000000000000000000000000000000 B

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ static raw_ostream &operator<<(raw_ostream &OS, const EncodingAndInst &Value) {
319319
}
320320

321321
// Prints the bit value for each position.
322-
static void dumpBits(raw_ostream &OS, const BitsInit &Bits) {
323-
for (const Init *Bit : reverse(Bits.getBits()))
322+
static void dumpBits(raw_ostream &OS, const BitsInit &Bits, unsigned BitWidth) {
323+
for (const Init *Bit : reverse(Bits.getBits().take_front(BitWidth)))
324324
OS << BitValue(Bit);
325325
}
326326

@@ -389,16 +389,16 @@ class FilterChooser;
389389
///
390390
/// An example of a conflict is
391391
///
392-
/// Conflict:
393-
/// 111101000.00........00010000....
394-
/// 111101000.00........0001........
395-
/// 1111010...00........0001........
396-
/// 1111010...00....................
397-
/// 1111010.........................
398-
/// 1111............................
399-
/// ................................
400-
/// VST4q8a 111101000_00________00010000____
401-
/// VST4q8b 111101000_00________00010000____
392+
/// Decoding Conflict:
393+
/// ................................
394+
/// 1111............................
395+
/// 1111010.........................
396+
/// 1111010...00....................
397+
/// 1111010...00........0001........
398+
/// 111101000.00........0001........
399+
/// 111101000.00........00010000....
400+
/// 111101000_00________00010000____ VST4q8a
401+
/// 111101000_00________00010000____ VST4q8b
402402
///
403403
/// The Debug output shows the path that the decoding tree follows to reach the
404404
/// the conclusion that there is a conflict. VST4q8a is a vst4 to double-spaced
@@ -582,7 +582,7 @@ class FilterChooser {
582582

583583
/// dumpStack - dumpStack traverses the filter chooser chain and calls
584584
/// dumpFilterArray on each filter chooser up to the top level one.
585-
void dumpStack(raw_ostream &OS, const char *prefix) const;
585+
void dumpStack(raw_ostream &OS, indent Indent) const;
586586

587587
bool PositionFiltered(unsigned Idx) const {
588588
return FilterBitValues[Idx].isSet();
@@ -701,9 +701,8 @@ void Filter::recurse() {
701701
std::vector<BitValue> BitValueArray(Owner.FilterBitValues);
702702

703703
if (!VariableInstructions.empty()) {
704-
// Conservatively marks each segment position as BIT_UNSET.
705704
for (unsigned bitIndex = 0; bitIndex < NumBits; ++bitIndex)
706-
BitValueArray[StartBit + bitIndex] = BitValue::BIT_UNSET;
705+
BitValueArray[StartBit + bitIndex] = BitValue::BIT_UNFILTERED;
707706

708707
// Delegates to an inferior filter chooser for further processing on this
709708
// group of instructions whose segment values are variable.
@@ -1118,15 +1117,12 @@ void FilterChooser::dumpFilterArray(raw_ostream &OS,
11181117

11191118
/// dumpStack - dumpStack traverses the filter chooser chain and calls
11201119
/// dumpFilterArray on each filter chooser up to the top level one.
1121-
void FilterChooser::dumpStack(raw_ostream &OS, const char *prefix) const {
1122-
const FilterChooser *current = this;
1123-
1124-
while (current) {
1125-
OS << prefix;
1126-
dumpFilterArray(OS, current->FilterBitValues);
1127-
OS << '\n';
1128-
current = current->Parent;
1129-
}
1120+
void FilterChooser::dumpStack(raw_ostream &OS, indent Indent) const {
1121+
if (Parent)
1122+
Parent->dumpStack(OS, Indent);
1123+
OS << Indent;
1124+
dumpFilterArray(OS, FilterBitValues);
1125+
OS << '\n';
11301126
}
11311127

11321128
// Calculates the island(s) needed to decode the instruction.
@@ -1765,13 +1761,16 @@ void FilterChooser::doFilter() {
17651761
// Print out useful conflict information for postmortem analysis.
17661762
errs() << "Decoding Conflict:\n";
17671763

1768-
dumpStack(errs(), "\t\t");
1764+
// Dump filters.
1765+
indent Indent(4);
1766+
dumpStack(errs(), Indent);
17691767

1770-
for (auto Opcode : Opcodes) {
1768+
// Dump encodings.
1769+
for (EncodingIDAndOpcode Opcode : Opcodes) {
17711770
const EncodingAndInst &Enc = AllInstructions[Opcode.EncodingID];
1772-
errs() << '\t' << Enc << ' ';
1773-
dumpBits(errs(), getBitsField(*Enc.EncodingDef, "Inst"));
1774-
errs() << '\n';
1771+
errs() << Indent;
1772+
dumpBits(errs(), getBitsField(*Enc.EncodingDef, "Inst"), BitWidth);
1773+
errs() << " " << Enc << '\n';
17751774
}
17761775
PrintFatalError("Decoding conflict encountered");
17771776
}

0 commit comments

Comments
 (0)