Skip to content

Commit 98262e5

Browse files
authored
[TableGen][DecoderEmitter] Fix broken AdditionalEncoding support (#155057)
We didn't have tests for AdditionalEncoding and none of the in-tree targets use this functionality, so I inadvertently broke it in #154288.
1 parent 9697b3c commit 98262e5

File tree

2 files changed

+69
-0
lines changed

2 files changed

+69
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// RUN: llvm-tblgen -gen-disassembler -I %p/../../../include %s | FileCheck %s
2+
3+
include "llvm/Target/Target.td"
4+
5+
class Enc {
6+
int Size = 2;
7+
bits<16> Inst;
8+
}
9+
10+
class EncSHIFT<bits<2> opc> : Enc {
11+
bits<6> shamt;
12+
let Inst{15...14} = {0, 0};
13+
let Inst{13...12} = opc;
14+
let Inst{11...6} = shamt;
15+
}
16+
17+
class EncNOP<bits<2> opc> : Enc {
18+
let Inst{15...14} = {0, 0};
19+
let Inst{13...12} = opc;
20+
let Inst{11...6} = {0, 0, 0, 0, 0, 0};
21+
}
22+
23+
def ShAmtOp : Operand<i32> {
24+
let DecoderMethod = "decodeShAmt";
25+
let hasCompleteDecoder = false;
26+
}
27+
28+
class I<dag out_ops, dag in_ops> : Instruction {
29+
let InOperandList = in_ops;
30+
let OutOperandList = out_ops;
31+
}
32+
33+
// CHECK: /* 0 */ MCD::OPC_ExtractField, 12, 4, // Inst{15-12} ...
34+
// CHECK-NEXT: /* 3 */ MCD::OPC_FilterValue, 0, 14, 0, // Skip to: 21
35+
// CHECK-NEXT: /* 7 */ MCD::OPC_CheckField, 6, 6, 0, 4, 0, // Skip to: 17
36+
// CHECK-NEXT: /* 13 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP
37+
// CHECK-NEXT: /* 17 */ MCD::OPC_TryDecodeOrFail, {{[0-9]+}}, 2, 1,
38+
// CHECK-NEXT: /* 21 */ MCD::OPC_FilterValue, 1, 14, 0, // Skip to: 39
39+
// CHECK-NEXT: /* 25 */ MCD::OPC_CheckField, 6, 6, 0, 4, 0, // Skip to: 35
40+
// CHECK-NEXT: /* 31 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP
41+
// CHECK-NEXT: /* 35 */ MCD::OPC_TryDecodeOrFail, {{[0-9]+}}, 2, 1,
42+
// CHECK-NEXT: /* 39 */ MCD::OPC_FilterValue, 2, 14, 0, // Skip to: 57
43+
// CHECK-NEXT: /* 43 */ MCD::OPC_CheckField, 6, 6, 0, 4, 0, // Skip to: 53
44+
// CHECK-NEXT: /* 49 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP
45+
// CHECK-NEXT: /* 53 */ MCD::OPC_TryDecodeOrFail, {{[0-9]+}}, 2, 1,
46+
// CHECK-NEXT: /* 57 */ MCD::OPC_FilterValueOrFail, 3,
47+
// CHECK-NEXT: /* 59 */ MCD::OPC_CheckField, 6, 6, 0, 4, 0, // Skip to: 69
48+
// CHECK-NEXT: /* 65 */ MCD::OPC_Decode, {{[0-9]+}}, 2, 0, // Opcode: {{.*}}:NOP
49+
// CHECK-NEXT: /* 69 */ MCD::OPC_TryDecodeOrFail, {{[0-9]+}}, 2, 1,
50+
// CHECK-NEXT: /* 73 */ MCD::OPC_Fail,
51+
52+
class SHIFT<bits<2> opc> : I<(outs), (ins ShAmtOp:$shamt)>, EncSHIFT<opc>;
53+
def SHIFT0 : SHIFT<0>;
54+
def SHIFT1 : SHIFT<1>;
55+
def SHIFT2 : SHIFT<2>;
56+
def SHIFT3 : SHIFT<3>;
57+
58+
def NOP : I<(outs), (ins)>, EncNOP<0>;
59+
def : AdditionalEncoding<NOP>, EncNOP<1>;
60+
def : AdditionalEncoding<NOP>, EncNOP<2>;
61+
def : AdditionalEncoding<NOP>, EncNOP<3>;
62+
63+
def II : InstrInfo;
64+
65+
def MyTarget : Target {
66+
let InstructionSet = II;
67+
}

llvm/utils/TableGen/DecoderEmitter.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,9 @@ void DecoderEmitter::parseInstructionEncodings() {
24952495
++NumEncodingsOmitted;
24962496
continue;
24972497
}
2498+
unsigned EncodingID = Encodings.size();
24982499
Encodings.emplace_back(EncodingDef, &Target.getInstruction(InstDef));
2500+
EncodingIDsByHwMode[DefaultMode].push_back(EncodingID);
24992501
}
25002502

25012503
// Do some statistics.

0 commit comments

Comments
 (0)