2
2
// RUN: FileCheck %s --check-prefix=ENCODER
3
3
// RUN: llvm-tblgen -gen-disassembler -I %p/../../include %s | \
4
4
// RUN: FileCheck %s --check-prefix=DECODER
5
- // RUN: llvm-tblgen -gen-disassembler --suppress-per-hwmode-duplicates -I \
6
- // RUN: %p/../../include %s | FileCheck %s --check-prefix=DECODER-SUPPRESS
7
5
8
6
include "llvm/Target/Target.td"
9
7
@@ -20,8 +18,8 @@ def Myi32 : Operand<i32> {
20
18
def HasA : Predicate<"Subtarget->hasA()">;
21
19
def HasB : Predicate<"Subtarget->hasB()">;
22
20
23
- def ModeA : HwMode<"+a", [HasA]>;
24
- def ModeB : HwMode<"+b", [HasB]>;
21
+ def ModeA : HwMode<"+a", [HasA]>; // hwmode ID 1
22
+ def ModeB : HwMode<"+b", [HasB]>; // hwmode ID 2
25
23
26
24
27
25
def fooTypeEncDefault : InstructionEncoding {
@@ -98,17 +96,24 @@ def unrelated: Instruction {
98
96
let AsmString = "unrelated $factor";
99
97
}
100
98
99
+ // DecoderTable64 is assigned with 'DefaultMode',
100
+ // the table name should remain the same as before.
101
+ // DECODER-LABEL: DecoderTable64[] =
102
+ // DECODER-DAG: Opcode: fooTypeEncDefault:foo
101
103
102
- // DECODER-LABEL: DecoderTableAlt_DefaultMode32[] =
103
- // DECODER-DAG: Opcode: unrelated
104
- // DECODER-LABEL: DecoderTableAlt_ModeA32[] =
105
- // DECODER-DAG: Opcode: unrelated
106
- // DECODER-LABEL: DecoderTableAlt_ModeB32[] =
104
+ // DecoderTable without any valid HwModes
105
+ // should not have any suffix in table name.
106
+ // The table should remain the same as before.
107
+ // DECODER-LABEL: DecoderTableAlt32[] =
107
108
// DECODER-DAG: Opcode: unrelated
108
- // DECODER-LABEL: DecoderTable_DefaultMode32[] =
109
- // DECODER-DAG: Opcode: bar
110
- // DECODER-LABEL: DecoderTable_DefaultMode64[] =
111
- // DECODER-DAG: Opcode: fooTypeEncDefault:foo
109
+ // DECODER-NOT: DecoderTableAlt_ModeA32[]
110
+ // DECODER-NOT: DecoderTableAlt_ModeB32[]
111
+
112
+ // The DecoderTable32 contains two valid hwmodes, we will
113
+ // generate two tables corresponding to these hwmodes.
114
+ // Still want to say we didn't assign 'DefaultMode' to DecoderTable32,
115
+ // instead we assign 'DefaultMode' to DecoderTable64, so
116
+ // DecoderTable32 won't appear here.
112
117
// DECODER-LABEL: DecoderTable_ModeA32[] =
113
118
// DECODER-DAG: Opcode: fooTypeEncA:foo
114
119
// DECODER-DAG: Opcode: bar
@@ -118,30 +123,24 @@ def unrelated: Instruction {
118
123
// DECODER-DAG: Opcode: bar
119
124
120
125
121
- // DECODER-SUPPRESS-LABEL: DecoderTableAlt_AllModes32[] =
122
- // DECODER-SUPPRESS-DAG: Opcode: unrelated
123
- // DECODER-SUPPRESS-LABEL: DecoderTable_AllModes32[] =
124
- // DECODER-SUPPRESS-DAG: Opcode: bar
125
- // DECODER-SUPPRESS-LABEL: DecoderTable_DefaultMode64[] =
126
- // DECODER-SUPPRESS-NOT: Opcode: bar
127
- // DECODER-SUPPRESS-DAG: Opcode: fooTypeEncDefault:foo
128
- // DECODER-SUPPRESS-LABEL: DecoderTable_ModeA32[] =
129
- // DECODER-SUPPRESS-DAG: Opcode: fooTypeEncA:foo
130
- // DECODER-SUPPRESS-NOT: Opcode: bar
131
- // DECODER-SUPPRESS-LABEL: DecoderTable_ModeB32[] =
132
- // DECODER-SUPPRESS-DAG: Opcode: fooTypeEncB:foo
133
- // DECODER-SUPPRESS-DAG: Opcode: fooTypeEncA:baz
134
- // DECODER-SUPPRESS-NOT: Opcode: bar
135
-
136
- // ENCODER-LABEL: static const uint64_t InstBits_DefaultMode[] = {
126
+ // For 'bar' and 'unrelated', we didn't assign any hwmodes for them,
127
+ // they should keep the same in the following three tables.
128
+ // For 'foo' we assigned three hwmodes(includes 'DefaultMode')
129
+ // it's encodings should be different in the following three tables.
130
+ // For 'baz' we only assigned ModeB for it, to avoid empty encoding
131
+ // we assigned the encoding of ModeB to ModeA and DefaultMode(Even though
132
+ // they will not be used).
133
+ // ENCODER-LABEL: static const uint64_t InstBits[] = {
137
134
// ENCODER: UINT64_C(2), // bar
138
- // ENCODER: UINT64_C(0), // baz
135
+ // To avoid empty encoding, we choose the encoding of ModeB for baz here
136
+ // ENCODER: UINT64_C(12), // baz
139
137
// ENCODER: UINT64_C(8), // foo
140
138
// ENCODER: UINT64_C(2), // unrelated
141
139
142
140
// ENCODER-LABEL: static const uint64_t InstBits_ModeA[] = {
143
141
// ENCODER: UINT64_C(2), // bar
144
- // ENCODER: UINT64_C(0), // baz
142
+ // To avoid empty encoding, we choose the encoding of ModeB for baz here
143
+ // ENCODER: UINT64_C(12), // baz
145
144
// ENCODER: UINT64_C(12), // foo
146
145
// ENCODER: UINT64_C(2), // unrelated
147
146
@@ -151,18 +150,39 @@ def unrelated: Instruction {
151
150
// ENCODER: UINT64_C(3), // foo
152
151
// ENCODER: UINT64_C(2), // unrelated
153
152
153
+ // Sink the logic of hwmodes selection to per instruction level.
154
+ // ENCODER-LABEL: case ::bar:
155
+ // ENCODER: op = getMachineOpValue
156
+ // ENCODER-LABEL: case ::baz: {
157
+ // ENCODER: unsigned HwMode = STI.getHwMode();
158
+ // ENCODER: HwMode &= 2;
159
+ // ENCODER: switch (HwMode) {
160
+ // ENCODER: default: llvm_unreachable("Unknown hardware mode!"); break;
161
+ // ENCODER: case 2: InstBitsByHw = InstBits_ModeB; break;
162
+ // ENCODER: };
163
+ // ENCODER: Value = InstBitsByHw[opcode];
164
+ // ENCODER: switch (HwMode) {
165
+ // ENCODER: default: llvm_unreachable("Unhandled HwMode");
166
+ // ENCODER: case 2: {
167
+ // ENCODER: op = getMachineOpValue
168
+ // ENCODER-LABEL: case ::foo: {
154
169
// ENCODER: unsigned HwMode = STI.getHwMode();
170
+ // ENCODER: HwMode &= 3;
155
171
// ENCODER: switch (HwMode) {
156
172
// ENCODER: default: llvm_unreachable("Unknown hardware mode!"); break;
157
- // ENCODER: case 0: InstBits = InstBits_DefaultMode ; break;
158
- // ENCODER: case 1: InstBits = InstBits_ModeA; break;
159
- // ENCODER: case 2: InstBits = InstBits_ModeB; break;
173
+ // ENCODER: case 0: InstBitsByHw = InstBits ; break;
174
+ // ENCODER: case 1: InstBitsByHw = InstBits_ModeA; break;
175
+ // ENCODER: case 2: InstBitsByHw = InstBits_ModeB; break;
160
176
// ENCODER: };
177
+ // ENCODER: Value = InstBitsByHw[opcode];
178
+ // ENCODER: switch (HwMode) {
179
+ // ENCODER: default: llvm_unreachable("Unhandled HwMode");
180
+ // ENCODER: case 0: {
181
+ // ENCODER: op = getMachineOpValue
182
+ // ENCODER: case 1: {
183
+ // ENCODER: op = getMachineOpValue
184
+ // ENCODER: case 2: {
185
+ // ENCODER: op = getMachineOpValue
186
+
161
187
162
- // ENCODER: case ::foo: {
163
- // ENCODER: switch (HwMode) {
164
- // ENCODER: default: llvm_unreachable("Unhandled HwMode");
165
- // ENCODER: case 0: {
166
- // ENCODER: case 1: {
167
- // ENCODER: case 2: {
168
188
0 commit comments