Skip to content

Commit acea1f5

Browse files
authored
[LLVM][MC][CodeEmitterGen] Reduce various InstBits table sizes (#156213)
Change various `InstBits` tables have an entry only for non-pseudo target instructions and adjust the indexing into these tables accordingly. Some minor refactoring related to this: - Use early return after handling variable length encodings - Reduce the scope of anonymous namespace to just the class declaration. Example reductions in these table sizes for some targets: ``` Target FirstSupportedOpcode Reduction in size AMDGPU 10813 10813 * 16 = 168KB RISCV 12051 12051 * 8 = 94KB ```
1 parent 79e9317 commit acea1f5

File tree

3 files changed

+175
-167
lines changed

3 files changed

+175
-167
lines changed

llvm/test/TableGen/HwModeEncodeAPInt.td

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -114,32 +114,38 @@ def unrelated: Instruction {
114114
// For 'baz' we only assigned ModeB for it, so it will be presented
115115
// as '0' in the tables of ModeA, ModeC and Default Mode.
116116
// ENCODER-LABEL: static const uint64_t InstBits[] = {
117-
// ENCODER: UINT64_C(2), UINT64_C(0), // bar
118-
// ENCODER: UINT64_C(0), UINT64_C(0), // baz
119-
// ENCODER: UINT64_C(8), UINT64_C(0), // foo
120-
// ENCODER: UINT64_C(2), UINT64_C(0), // unrelated
117+
// ENCODER-NEXT: UINT64_C(2), UINT64_C(0), // bar
118+
// ENCODER-NEXT: UINT64_C(0), UINT64_C(0), // baz
119+
// ENCODER-NEXT: UINT64_C(8), UINT64_C(0), // foo
120+
// ENCODER-NEXT: UINT64_C(2), UINT64_C(0), // unrelated
121+
// ENCODER-NEXT: };
121122
// ENCODER-LABEL: static const uint64_t InstBits_ModeA[] = {
122-
// ENCODER: UINT64_C(2), UINT64_C(0), // bar
123-
// ENCODER: UINT64_C(0), UINT64_C(0), // baz
124-
// ENCODER: UINT64_C(12), UINT64_C(0), // foo
125-
// ENCODER: UINT64_C(2), UINT64_C(0), // unrelated
123+
// ENCODER-NEXT: UINT64_C(2), UINT64_C(0), // bar
124+
// ENCODER-NEXT: UINT64_C(0), UINT64_C(0), // baz
125+
// ENCODER-NEXT: UINT64_C(12), UINT64_C(0), // foo
126+
// ENCODER-NEXT: UINT64_C(2), UINT64_C(0), // unrelated
127+
// ENCODER-NEXT: };
126128
// ENCODER-LABEL: static const uint64_t InstBits_ModeB[] = {
127-
// ENCODER: UINT64_C(2), UINT64_C(0), // bar
128-
// ENCODER: UINT64_C(12), UINT64_C(0), // baz
129-
// ENCODER: UINT64_C(0), UINT64_C(211106232532992), // foo
130-
// ENCODER: UINT64_C(2), UINT64_C(0), // unrelated
129+
// ENCODER-NEXT: UINT64_C(2), UINT64_C(0), // bar
130+
// ENCODER-NEXT: UINT64_C(12), UINT64_C(0), // baz
131+
// ENCODER-NEXT: UINT64_C(0), UINT64_C(211106232532992), // foo
132+
// ENCODER-NEXT: UINT64_C(2), UINT64_C(0), // unrelated
133+
// ENCODER-NEXT: };
131134
// ENCODER-LABEL: static const uint64_t InstBits_ModeC[] = {
132-
// ENCODER: UINT64_C(2), UINT64_C(0), // bar
133-
// ENCODER: UINT64_C(0), UINT64_C(0), // baz
134-
// ENCODER: UINT64_C(12582915), UINT64_C(0), // foo
135-
// ENCODER: UINT64_C(2), UINT64_C(0), // unrelated
136-
135+
// ENCODER-NEXT: UINT64_C(2), UINT64_C(0), // bar
136+
// ENCODER-NEXT: UINT64_C(0), UINT64_C(0), // baz
137+
// ENCODER-NEXT: UINT64_C(12582915), UINT64_C(0), // foo
138+
// ENCODER-NEXT: UINT64_C(2), UINT64_C(0), // unrelated
139+
// ENCODER-NEXT: };
137140

138141
// ENCODER: const uint64_t *InstBitsByHw;
142+
// ENCODER: constexpr unsigned FirstSupportedOpcode
139143
// ENCODER: const unsigned opcode = MI.getOpcode();
144+
// ENCODER: if (opcode < FirstSupportedOpcode)
145+
// ENCODER: unsigned TableIndex = opcode - FirstSupportedOpcode
140146
// ENCODER: if (Scratch.getBitWidth() != 128)
141147
// ENCODER: Scratch = Scratch.zext(128);
142-
// ENCODER: Inst = APInt(128, ArrayRef(InstBits + opcode * 2, 2));
148+
// ENCODER: Inst = APInt(128, ArrayRef(InstBits + TableIndex * 2, 2));
143149
// ENCODER: APInt &Value = Inst;
144150
// ENCODER: APInt &op = Scratch;
145151
// ENCODER: switch (opcode) {
@@ -155,7 +161,7 @@ def unrelated: Instruction {
155161
// ENCODER: case 2: InstBitsByHw = InstBits_ModeB; break;
156162
// ENCODER: case 3: InstBitsByHw = InstBits_ModeC; break;
157163
// ENCODER: };
158-
// ENCODER: Inst = APInt(128, ArrayRef(InstBitsByHw + opcode * 2, 2));
164+
// ENCODER: Inst = APInt(128, ArrayRef(InstBitsByHw + TableIndex * 2, 2));
159165
// ENCODER: Value = Inst;
160166
// ENCODER: switch (HwMode) {
161167
// ENCODER: default: llvm_unreachable("Unhandled HwMode");
@@ -189,7 +195,7 @@ def unrelated: Instruction {
189195
// ENCODER: default: llvm_unreachable("Unknown hardware mode!"); break;
190196
// ENCODER: case 2: InstBitsByHw = InstBits_ModeB; break;
191197
// ENCODER: };
192-
// ENCODER: Inst = APInt(128, ArrayRef(InstBitsByHw + opcode * 2, 2));
198+
// ENCODER: Inst = APInt(128, ArrayRef(InstBitsByHw + TableIndex * 2, 2));
193199
// ENCODER: Value = Inst;
194200
// ENCODER: switch (HwMode) {
195201
// ENCODER: default: llvm_unreachable("Unhandled HwMode");

llvm/test/TableGen/HwModeEncodeDecode3.td

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,29 @@ def unrelated: Instruction {
189189
// For 'baz' we only assigned ModeB for it, so it will be presented
190190
// as '0' in the tables of ModeA, ModeC and Default Mode.
191191
// ENCODER-LABEL: static const uint64_t InstBits[] = {
192-
// ENCODER: UINT64_C(2), // bar
193-
// ENCODER: UINT64_C(0), // baz
194-
// ENCODER: UINT64_C(8), // foo
195-
// ENCODER: UINT64_C(2), // unrelated
192+
// ENCODER-NEXT: UINT64_C(2), // bar
193+
// ENCODER-NEXT: UINT64_C(0), // baz
194+
// ENCODER-NEXT: UINT64_C(8), // foo
195+
// ENCODER-NEXT: UINT64_C(2), // unrelated
196+
// ENCODER-NEXT: };
196197
// ENCODER-LABEL: static const uint64_t InstBits_ModeA[] = {
197-
// ENCODER: UINT64_C(2), // bar
198-
// ENCODER: UINT64_C(0), // baz
199-
// ENCODER: UINT64_C(12), // foo
200-
// ENCODER: UINT64_C(2), // unrelated
198+
// ENCODER-NEXT: UINT64_C(2), // bar
199+
// ENCODER-NEXT: UINT64_C(0), // baz
200+
// ENCODER-NEXT: UINT64_C(12), // foo
201+
// ENCODER-NEXT: UINT64_C(2), // unrelated
202+
// ENCODER-NEXT: };
201203
// ENCODER-LABEL: static const uint64_t InstBits_ModeB[] = {
202-
// ENCODER: UINT64_C(2), // bar
203-
// ENCODER: UINT64_C(12), // baz
204-
// ENCODER: UINT64_C(3), // foo
205-
// ENCODER: UINT64_C(2), // unrelated
204+
// ENCODER-NEXT: UINT64_C(2), // bar
205+
// ENCODER-NEXT: UINT64_C(12), // baz
206+
// ENCODER-NEXT: UINT64_C(3), // foo
207+
// ENCODER-NEXT: UINT64_C(2), // unrelated
208+
// ENCODER-NEXT: };
206209
// ENCODER-LABEL: static const uint64_t InstBits_ModeC[] = {
207-
// ENCODER: UINT64_C(2), // bar
208-
// ENCODER: UINT64_C(0), // baz
209-
// ENCODER: UINT64_C(12582915), // foo
210-
// ENCODER: UINT64_C(2), // unrelated
210+
// ENCODER-NEXT: UINT64_C(2), // bar
211+
// ENCODER-NEXT: UINT64_C(0), // baz
212+
// ENCODER-NEXT: UINT64_C(12582915), // foo
213+
// ENCODER-NEXT: UINT64_C(2), // unrelated
214+
// ENCODER-NEXT: };
211215

212216
// ENCODER-LABEL: case ::bar:
213217
// ENCODER-LABEL: case ::unrelated:
@@ -221,7 +225,7 @@ def unrelated: Instruction {
221225
// ENCODER: case 2: InstBitsByHw = InstBits_ModeB; break;
222226
// ENCODER: case 3: InstBitsByHw = InstBits_ModeC; break;
223227
// ENCODER: };
224-
// ENCODER: Value = InstBitsByHw[opcode];
228+
// ENCODER: Value = InstBitsByHw[TableIndex];
225229
// ENCODER: switch (HwMode) {
226230
// ENCODER: default: llvm_unreachable("Unhandled HwMode");
227231
// ENCODER: case 0: {
@@ -256,7 +260,7 @@ def unrelated: Instruction {
256260
// ENCODER: default: llvm_unreachable("Unknown hardware mode!"); break;
257261
// ENCODER: case 2: InstBitsByHw = InstBits_ModeB; break;
258262
// ENCODER: };
259-
// ENCODER: Value = InstBitsByHw[opcode];
263+
// ENCODER: Value = InstBitsByHw[TableIndex];
260264
// ENCODER: switch (HwMode) {
261265
// ENCODER: default: llvm_unreachable("Unhandled HwMode");
262266
// ENCODER: case 2: {

0 commit comments

Comments
 (0)