Skip to content

Commit a67b932

Browse files
committed
[M68k][NFC] Refactoring memory operands of different sizes with foreach
I'm planning to add memory operands that produce floating point type. In order to prevent code bloating induced by memory operands of not just integer but floating point types, I factored the sizes from these operands with foreach loops.
1 parent 8d9cb6b commit a67b932

File tree

1 file changed

+51
-65
lines changed

1 file changed

+51
-65
lines changed

llvm/lib/Target/M68k/M68kInstrInfo.td

Lines changed: 51 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -200,32 +200,35 @@ class MxRegOp<ValueType vt,
200200

201201
// REGISTER DIRECT. The operand is in the data register specified by
202202
// the effective address register field.
203-
def MxXRD16 : MxRegOp<i16, XR16, MxSize16, "r">;
204-
def MxXRD32 : MxRegOp<i32, XR32, MxSize32, "r">;
205-
206-
def MxXRD16_TC : MxRegOp<i16, XR16_TC, MxSize16, "r">;
207-
def MxXRD32_TC : MxRegOp<i32, XR32_TC, MxSize32, "r">;
203+
foreach size = [16, 32] in {
204+
def MxXRD # size : MxRegOp<!cast<ValueType>("i"#size), !cast<MxRegClass>("XR"#size),
205+
!cast<MxSize>("MxSize"#size), "r">;
206+
def MxXRD # size # _TC : MxRegOp<!cast<ValueType>("i"#size), !cast<MxRegClass>("XR"#size#"_TC"),
207+
!cast<MxSize>("MxSize"#size), "r">;
208+
} // foreach size
208209

209210
// DATA REGISTER DIRECT. The operand is in the data register specified by
210211
// the effective address register field.
211212
let ParserMatchClass = MxDRegClass in {
212-
def MxDRD8 : MxRegOp<i8, DR8, MxSize8, "d">;
213-
def MxDRD16 : MxRegOp<i16, DR16, MxSize16, "d">;
214-
def MxDRD32 : MxRegOp<i32, DR32, MxSize32, "d">;
215-
216-
def MxDRD16_TC : MxRegOp<i16, DR16_TC, MxSize16, "d">;
217-
def MxDRD32_TC : MxRegOp<i32, DR32_TC, MxSize32, "d">;
218-
}
213+
foreach size = [8, 16, 32] in {
214+
def MxDRD # size : MxRegOp<!cast<ValueType>("i"#size), !cast<MxRegClass>("DR"#size),
215+
!cast<MxSize>("MxSize"#size), "d">;
216+
if !gt(size, 8) then
217+
def MxDRD # size # _TC : MxRegOp<!cast<ValueType>("i"#size), !cast<MxRegClass>("DR"#size#"_TC"),
218+
!cast<MxSize>("MxSize"#size), "d">;
219+
} // foreach size
220+
} // let ParserMatchClass
219221

220222
// ADDRESS REGISTER DIRECT. The operand is in the address register specified by
221223
// the effective address register field.
222224
let ParserMatchClass = MxARegClass in {
223-
def MxARD16 : MxRegOp<i16, AR16, MxSize16, "a">;
224-
def MxARD32 : MxRegOp<i32, AR32, MxSize32, "a">;
225-
226-
def MxARD16_TC : MxRegOp<i16, AR16_TC, MxSize16, "a">;
227-
def MxARD32_TC : MxRegOp<i32, AR32_TC, MxSize32, "a">;
228-
}
225+
foreach size = [16, 32] in {
226+
def MxARD # size : MxRegOp<!cast<ValueType>("i"#size), !cast<MxRegClass>("AR"#size),
227+
!cast<MxSize>("MxSize"#size), "a">;
228+
def MxARD # size # _TC : MxRegOp<!cast<ValueType>("i"#size), !cast<MxRegClass>("AR"#size#"_TC"),
229+
!cast<MxSize>("MxSize"#size), "a">;
230+
} // foreach size
231+
} // let ParserMatchClass
229232

230233
// FLOATING POINT DATA REGISTER.
231234
let ParserMatchClass = MxFPDRegClass in {
@@ -255,13 +258,11 @@ class MxMemOp<dag ops, MxSize size, string letter,
255258
// a data reference with the exception of the jump and jump-to-subroutine
256259
// instructions.
257260
def MxARI : MxOpClass<"ARI">;
258-
def MxARI8 : MxMemOp<(ops AR32), MxSize8, "j", "printARI8Mem", MxARI>;
259-
def MxARI16 : MxMemOp<(ops AR32), MxSize16, "j", "printARI16Mem", MxARI>;
260-
def MxARI32 : MxMemOp<(ops AR32), MxSize32, "j", "printARI32Mem", MxARI>;
261-
262-
def MxARI8_TC : MxMemOp<(ops AR32_TC), MxSize8, "j", "printARI8Mem", MxARI>;
263-
def MxARI16_TC : MxMemOp<(ops AR32_TC), MxSize16, "j", "printARI16Mem", MxARI>;
264-
def MxARI32_TC : MxMemOp<(ops AR32_TC), MxSize32, "j", "printARI32Mem", MxARI>;
261+
foreach size = ["8", "16", "32"] in {
262+
defvar ResSize = !cast<MxSize>("MxSize"#size);
263+
def MxARI # size : MxMemOp<(ops AR32), ResSize, "j", "printARI"#size#"Mem", MxARI>;
264+
def MxARI # size # _TC : MxMemOp<(ops AR32_TC), ResSize, "j", "printARI"#size#"Mem", MxARI>;
265+
} // foreach size
265266

266267
// ADDRESS REGISTER INDIRECT WITH POSTINCREMENT. The address of the operand is
267268
// in the address register specified by the register field. After the operand
@@ -271,13 +272,11 @@ def MxARI32_TC : MxMemOp<(ops AR32_TC), MxSize32, "j", "printARI32Mem", MxARI
271272
// by two rather than one to keep the stack pointer on a word boundary.
272273
// The reference is classified as a data reference.
273274
def MxARIPI : MxOpClass<"ARIPI">;
274-
def MxARIPI8 : MxMemOp<(ops AR32), MxSize8, "o", "printARIPI8Mem", MxARIPI>;
275-
def MxARIPI16 : MxMemOp<(ops AR32), MxSize16, "o", "printARIPI16Mem", MxARIPI>;
276-
def MxARIPI32 : MxMemOp<(ops AR32), MxSize32, "o", "printARIPI32Mem", MxARIPI>;
277-
278-
def MxARIPI8_TC : MxMemOp<(ops AR32_TC), MxSize8, "o", "printARIPI8Mem", MxARIPI>;
279-
def MxARIPI16_TC : MxMemOp<(ops AR32_TC), MxSize16, "o", "printARIPI16Mem", MxARIPI>;
280-
def MxARIPI32_TC : MxMemOp<(ops AR32_TC), MxSize32, "o", "printARIPI32Mem", MxARIPI>;
275+
foreach size = ["8", "16", "32"] in {
276+
defvar ResSize = !cast<MxSize>("MxSize"#size);
277+
def MxARIPI # size : MxMemOp<(ops AR32), ResSize, "o", "printARIPI"#size#"Mem", MxARIPI>;
278+
def MxARIPI # size # _TC : MxMemOp<(ops AR32_TC), ResSize, "o", "printARIPI"#size#"Mem", MxARIPI>;
279+
} // foreach size
281280

282281
// ADDRESS REGISTER INDIRECT WITH PREDECREMENT. The address of the operand is in
283282
// the address register specified by the register field. Before the operand
@@ -287,27 +286,23 @@ def MxARIPI32_TC : MxMemOp<(ops AR32_TC), MxSize32, "o", "printARIPI32Mem", MxA
287286
// two rather than one to keep the stack pointer on a word boundary.
288287
// The reference is classified as a data reference.
289288
def MxARIPD : MxOpClass<"ARIPD">;
290-
def MxARIPD8 : MxMemOp<(ops AR32), MxSize8, "e", "printARIPD8Mem", MxARIPD>;
291-
def MxARIPD16 : MxMemOp<(ops AR32), MxSize16, "e", "printARIPD16Mem", MxARIPD>;
292-
def MxARIPD32 : MxMemOp<(ops AR32), MxSize32, "e", "printARIPD32Mem", MxARIPD>;
293-
294-
def MxARIPD8_TC : MxMemOp<(ops AR32_TC), MxSize8, "e", "printARIPD8Mem", MxARIPD>;
295-
def MxARIPD16_TC : MxMemOp<(ops AR32_TC), MxSize16, "e", "printARIPD16Mem", MxARIPD>;
296-
def MxARIPD32_TC : MxMemOp<(ops AR32_TC), MxSize32, "e", "printARIPD32Mem", MxARIPD>;
289+
foreach size = ["8", "16", "32"] in {
290+
defvar ResSize = !cast<MxSize>("MxSize"#size);
291+
def MxARIPD # size : MxMemOp<(ops AR32), ResSize, "e", "printARIPD"#size#"Mem", MxARIPD>;
292+
def MxARIPD # size # _TC : MxMemOp<(ops AR32_TC), ResSize, "e", "printARIPD"#size#"Mem", MxARIPD>;
293+
} // foreach size
297294

298295
// ADDRESS REGISTER INDIRECT WITH DISPLACEMENT. This addressing mode requires one
299296
// word of extension. The address of the operand is the sum of the address in
300297
// the address register and the sign-extended 16-bit displacement integer in the
301298
// extension word. The reference is classified as a data reference with the
302299
// exception of the jump and jump-to-subroutine instructions.
303300
def MxARID : MxOpClass<"ARID">;
304-
def MxARID8 : MxMemOp<(ops i16imm:$disp, AR32:$reg), MxSize8, "p", "printARID8Mem", MxARID>;
305-
def MxARID16 : MxMemOp<(ops i16imm:$disp, AR32:$reg), MxSize16, "p", "printARID16Mem", MxARID>;
306-
def MxARID32 : MxMemOp<(ops i16imm:$disp, AR32:$reg), MxSize32, "p", "printARID32Mem", MxARID>;
307-
308-
def MxARID8_TC : MxMemOp<(ops i16imm:$disp, AR32_TC:$reg), MxSize8, "p", "printARID8Mem", MxARID>;
309-
def MxARID16_TC : MxMemOp<(ops i16imm:$disp, AR32_TC:$reg), MxSize16, "p", "printARID16Mem", MxARID>;
310-
def MxARID32_TC : MxMemOp<(ops i16imm:$disp, AR32_TC:$reg), MxSize32, "p", "printARID32Mem", MxARID>;
301+
foreach size = ["8", "16", "32"] in {
302+
defvar ResSize = !cast<MxSize>("MxSize"#size);
303+
def MxARID # size : MxMemOp<(ops i16imm:$disp, AR32:$reg), ResSize, "p", "printARID"#size#"Mem", MxARID>;
304+
def MxARID # size # _TC : MxMemOp<(ops i16imm:$disp, AR32_TC:$reg), ResSize, "p", "printARID"#size#"Mem", MxARID>;
305+
} // foreach size
311306

312307
// ADDRESS REGISTER INDIRECT WITH INDEX. This addressing mode requires one word
313308
// of extension. The address of the operand is the sum of the address in the
@@ -316,19 +311,11 @@ def MxARID32_TC : MxMemOp<(ops i16imm:$disp, AR32_TC:$reg), MxSize32, "p", "pr
316311
// The reference is classified as a data reference with the exception of the
317312
// jump and jump-to-subroutine instructions
318313
def MxARII : MxOpClass<"ARII">;
319-
def MxARII8 : MxMemOp<(ops i8imm:$disp, AR32:$reg, XR32:$index),
320-
MxSize8, "f", "printARII8Mem", MxARII>;
321-
def MxARII16 : MxMemOp<(ops i8imm:$disp, AR32:$reg, XR32:$index),
322-
MxSize16, "f", "printARII16Mem", MxARII>;
323-
def MxARII32 : MxMemOp<(ops i8imm:$disp, AR32:$reg, XR32:$index),
324-
MxSize32, "f", "printARII32Mem", MxARII>;
325-
326-
def MxARII8_TC : MxMemOp<(ops i8imm:$disp, AR32_TC:$reg, XR32_TC:$index),
327-
MxSize8, "f", "printARII8Mem", MxARII>;
328-
def MxARII16_TC : MxMemOp<(ops i8imm:$disp, AR32_TC:$reg, XR32_TC:$index),
329-
MxSize16, "f", "printARII16Mem", MxARII>;
330-
def MxARII32_TC : MxMemOp<(ops i8imm:$disp, AR32_TC:$reg, XR32_TC:$index),
331-
MxSize32, "f", "printARII32Mem", MxARII>;
314+
foreach size = ["8", "16", "32"] in {
315+
defvar ResSize = !cast<MxSize>("MxSize"#size);
316+
def MxARII # size : MxMemOp<(ops i8imm:$disp, AR32:$reg, XR32:$index), ResSize, "f", "printARII"#size#"Mem", MxARII>;
317+
def MxARII # size # _TC : MxMemOp<(ops i8imm:$disp, AR32_TC:$reg, XR32:$index), ResSize, "f", "printARII"#size#"Mem", MxARII>;
318+
} // foreach size
332319

333320
// ABSOLUTE SHORT ADDRESS. This addressing mode requires one word of extension.
334321
// The address of the operand is the extension word. The 16-bit address is sign
@@ -361,24 +348,23 @@ def MxPCD : MxOpClass<"PCD">;
361348
def MxPCI : MxOpClass<"PCI">;
362349

363350
let OperandType = "OPERAND_PCREL" in {
351+
foreach size = ["8", "16", "32"] in {
352+
defvar ResSize = !cast<MxSize>("MxSize"#size);
364353
// PROGRAM COUNTER WITH DISPLACEMENT. This addressing mode requires one word of
365354
// extension. The address of the operand is the sum of the address in the program
366355
// counter and the Sign-extended 16-bit displacement integer in the extension
367356
// word. The value in the program counter is the address of the extension word.
368357
// The reference is classified as a program reference.
369-
def MxPCD8 : MxMemOp<(ops i16imm), MxSize8, "q", "printPCD8Mem", MxPCD>;
370-
def MxPCD16 : MxMemOp<(ops i16imm), MxSize16, "q", "printPCD16Mem", MxPCD>;
371-
def MxPCD32 : MxMemOp<(ops i16imm), MxSize32, "q", "printPCD32Mem", MxPCD>;
358+
def MxPCD # size : MxMemOp<(ops i16imm), ResSize, "q", "printPCD"#size#"Mem", MxPCD>;
372359

373360
// PROGRAM COUNTER WITH INDEX. This addressing mode requires one word of
374361
// extension. The address is the sum of the address in the program counter, the
375362
// sign-extended displacement integer in the lower eight bits of the extension
376363
// word, and the contents of the index register. The value in the program
377364
// counter is the address of the extension word. This reference is classified as
378365
// a program reference.
379-
def MxPCI8 : MxMemOp<(ops i8imm:$disp, XR32:$index), MxSize8, "k", "printPCI8Mem", MxPCI>;
380-
def MxPCI16 : MxMemOp<(ops i8imm:$disp, XR32:$index), MxSize16, "k", "printPCI16Mem", MxPCI>;
381-
def MxPCI32 : MxMemOp<(ops i8imm:$disp, XR32:$index), MxSize32, "k", "printPCI32Mem", MxPCI>;
366+
def MxPCI # size : MxMemOp<(ops i8imm:$disp, XR32:$index), ResSize, "k", "printPCI"#size#"Mem", MxPCI>;
367+
} // foreach size
382368
} // OPERAND_PCREL
383369

384370
def MxImm : AsmOperandClass {

0 commit comments

Comments
 (0)