xref: /freebsd/contrib/llvm-project/llvm/lib/Target/M68k/M68kInstrInfo.td (revision 924226fba12cc9a228c73b956e1b7fa24c60b055)
1//===-- M68kInstrInfo.td - Main M68k Instruction Definition -*- tablegen -*-==//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// This file describes the M68k instruction set, defining the instructions
11/// and properties of the instructions which are needed for code generation,
12/// machine code emission, and analysis.
13///
14//===----------------------------------------------------------------------===//
15
16include "M68kInstrFormats.td"
17
18//===----------------------------------------------------------------------===//
19// Profiles
20//===----------------------------------------------------------------------===//
21
22def MxSDT_CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
23def MxSDT_CallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
24
25def MxSDT_Call    : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
26
27def MxSDT_Ret     : SDTypeProfile<0, -1, [
28  /* ADJ */ SDTCisVT<0, i32>
29]>;
30
31def MxSDT_TCRet   : SDTypeProfile<0, 2, [SDTCisPtrTy<0>, SDTCisVT<1, i32>]>;
32
33def MxSDT_Wrapper : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
34
35def MxSDT_UnArithCCROut : SDTypeProfile<2, 1, [
36  /* RES */ SDTCisInt<0>,
37  /* CCR */ SDTCisVT<1, i8>,
38  /* OPD */ SDTCisSameAs<0, 2>
39]>;
40
41// RES, CCR <- op LHS, RHS
42def MxSDT_BiArithCCROut : SDTypeProfile<2, 2, [
43  /* RES */ SDTCisInt<0>,
44  /* CCR */ SDTCisVT<1, i8>,
45  /* LHS */ SDTCisSameAs<0, 2>,
46  /* RHS */ SDTCisSameAs<0, 3>
47]>;
48
49// RES, CCR <- op LHS, RHS, CCR
50def MxSDT_BiArithCCRInOut : SDTypeProfile<2, 3, [
51  /* RES 1 */ SDTCisInt<0>,
52  /*   CCR */ SDTCisVT<1, i8>,
53  /*   LHS */ SDTCisSameAs<0, 2>,
54  /*   RHS */ SDTCisSameAs<0, 3>,
55  /*   CCR */ SDTCisSameAs<1, 4>
56]>;
57
58// RES1, RES2, CCR <- op LHS, RHS
59def MxSDT_2BiArithCCROut : SDTypeProfile<3, 2, [
60  /* RES 1 */ SDTCisInt<0>,
61  /* RES 2 */ SDTCisSameAs<0, 1>,
62  /*   CCR */ SDTCisVT<1, i8>,
63  /*   LHS */ SDTCisSameAs<0, 2>,
64  /*   RHS */ SDTCisSameAs<0, 3>
65]>;
66
67def MxSDT_CmpTest : SDTypeProfile<1, 2, [
68   /* CCR */ SDTCisVT<0, i8>,
69   /* Ops */ SDTCisSameAs<1, 2>
70]>;
71
72def MxSDT_Cmov : SDTypeProfile<1, 4, [
73  /*  ARG */ SDTCisSameAs<0, 1>,
74  /*  ARG */ SDTCisSameAs<1, 2>,
75  /* Cond */ SDTCisVT<3, i8>,
76  /*  CCR */ SDTCisVT<4, i8>
77]>;
78
79def MxSDT_BrCond : SDTypeProfile<0, 3, [
80  /* Dest */ SDTCisVT<0, OtherVT>,
81  /* Cond */ SDTCisVT<1, i8>,
82  /*  CCR */ SDTCisVT<2, i8>
83]>;
84
85def MxSDT_SetCC : SDTypeProfile<1, 2, [
86  /* BOOL */ SDTCisVT<0, i8>,
87  /* Cond */ SDTCisVT<1, i8>,
88  /*  CCR */ SDTCisVT<2, i8>
89]>;
90
91def MxSDT_SetCC_C : SDTypeProfile<1, 2, [
92  /* BOOL */ SDTCisInt<0>,
93  /* Cond */ SDTCisVT<1, i8>,
94  /*  CCR */ SDTCisVT<2, i8>
95]>;
96
97
98def MxSDT_SEG_ALLOCA : SDTypeProfile<1, 1,[
99  /*  MEM */ SDTCisVT<0, iPTR>,
100  /* SIZE */ SDTCisVT<1, iPTR>
101]>;
102
103
104//===----------------------------------------------------------------------===//
105// Nodes
106//===----------------------------------------------------------------------===//
107
108def MxCallSeqStart : SDNode<"ISD::CALLSEQ_START", MxSDT_CallSeqStart,
109                            [SDNPHasChain, SDNPOutGlue]>;
110
111def MxCallSeqEnd   : SDNode<"ISD::CALLSEQ_END", MxSDT_CallSeqEnd,
112                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
113
114def MxCall         : SDNode<"M68kISD::CALL", MxSDT_Call,
115                            [SDNPHasChain, SDNPOutGlue,
116                             SDNPOptInGlue, SDNPVariadic]>;
117
118def MxRet   : SDNode<"M68kISD::RET", MxSDT_Ret,
119                     [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
120
121def MxTCRet : SDNode<"M68kISD::TC_RETURN", MxSDT_TCRet,
122                     [SDNPHasChain,  SDNPOptInGlue, SDNPVariadic]>;
123
124def MxWrapper   : SDNode<"M68kISD::Wrapper",   MxSDT_Wrapper>;
125def MxWrapperPC : SDNode<"M68kISD::WrapperPC", MxSDT_Wrapper>;
126
127def MxAdd  : SDNode<"M68kISD::ADD",  MxSDT_BiArithCCROut, [SDNPCommutative]>;
128def MxSub  : SDNode<"M68kISD::SUB",  MxSDT_BiArithCCROut>;
129def MxOr   : SDNode<"M68kISD::OR",   MxSDT_BiArithCCROut, [SDNPCommutative]>;
130def MxXor  : SDNode<"M68kISD::XOR",  MxSDT_BiArithCCROut, [SDNPCommutative]>;
131def MxAnd  : SDNode<"M68kISD::AND",  MxSDT_BiArithCCROut, [SDNPCommutative]>;
132
133def MxAddX : SDNode<"M68kISD::ADDX", MxSDT_BiArithCCRInOut>;
134def MxSubX : SDNode<"M68kISD::SUBX", MxSDT_BiArithCCRInOut>;
135
136def MxSMul : SDNode<"M68kISD::SMUL", MxSDT_BiArithCCROut, [SDNPCommutative]>;
137def MxUMul : SDNode<"M68kISD::UMUL", MxSDT_2BiArithCCROut, [SDNPCommutative]>;
138
139def MxCmp     : SDNode<"M68kISD::CMP", MxSDT_CmpTest>;
140def MxBtst    : SDNode<"M68kISD::BTST", MxSDT_CmpTest>;
141
142def MxCmov    : SDNode<"M68kISD::CMOV",        MxSDT_Cmov>;
143def MxBrCond  : SDNode<"M68kISD::BRCOND",      MxSDT_BrCond, [SDNPHasChain]>;
144def MxSetCC   : SDNode<"M68kISD::SETCC",       MxSDT_SetCC>;
145def MxSetCC_C : SDNode<"M68kISD::SETCC_CARRY", MxSDT_SetCC_C>;
146
147
148def MxSegAlloca : SDNode<"M68kISD::SEG_ALLOCA", MxSDT_SEG_ALLOCA,
149                         [SDNPHasChain]>;
150
151
152//===----------------------------------------------------------------------===//
153// Operands
154//===----------------------------------------------------------------------===//
155
156/// Size is the size of the data, either bits of a register or number of bits
157/// addressed in memory. Size id is a letter that identifies size.
158class MxSize<int num, string id, string full> {
159  int Num = num;
160  string Id = id;
161  string Full = full;
162}
163
164def MxSize8  : MxSize<8,  "b", "byte">;
165def MxSize16 : MxSize<16, "w", "word">;
166def MxSize32 : MxSize<32, "l", "long">;
167
168class MxOpClass<string name,
169                list<AsmOperandClass> superClasses = []> : AsmOperandClass {
170  let Name = name;
171  let ParserMethod = "parseMemOp";
172  let SuperClasses = superClasses;
173}
174
175def MxRegClass : MxOpClass<"Reg">;
176// Splitting asm register class to avoid ambiguous on operands'
177// MatchClassKind. For instance, without this separation,
178// both ADD32dd and ADD32dr has {MCK_RegClass, MCK_RegClass} for
179// their operands, which makes AsmParser unable to pick the correct
180// one in a deterministic way.
181let RenderMethod = "addRegOperands", SuperClasses = [MxRegClass]in {
182  def MxARegClass : MxOpClass<"AReg">;
183  def MxDRegClass : MxOpClass<"DReg">;
184}
185
186class MxOperand<ValueType vt, MxSize size, string letter, RegisterClass rc, dag pat = (null_frag)> {
187  ValueType VT = vt;
188  string Letter = letter;
189  MxSize Size = size;
190  RegisterClass RC = rc;
191  dag Pat = pat;
192}
193
194class MxRegOp<ValueType vt,
195              RegisterClass rc,
196              MxSize size,
197              string letter,
198              string pm = "printOperand">
199    : RegisterOperand<rc, pm>,
200      MxOperand<vt, size, letter, rc> {
201  let ParserMatchClass = MxRegClass;
202}
203
204// REGISTER DIRECT. The operand is in the data register specified by
205// the effective address register field.
206def MxXRD16 : MxRegOp<i16, XR16, MxSize16, "r">;
207def MxXRD32 : MxRegOp<i32, XR32, MxSize32, "r">;
208
209def MxXRD16_TC : MxRegOp<i16, XR16_TC, MxSize16, "r">;
210def MxXRD32_TC : MxRegOp<i32, XR32_TC, MxSize32, "r">;
211
212// DATA REGISTER DIRECT. The operand is in the data register specified by
213// the effective address register field.
214let ParserMatchClass = MxDRegClass in {
215  def MxDRD8  : MxRegOp<i8,  DR8,  MxSize8,  "d">;
216  def MxDRD16 : MxRegOp<i16, DR16, MxSize16, "d">;
217  def MxDRD32 : MxRegOp<i32, DR32, MxSize32, "d">;
218
219  def MxDRD16_TC : MxRegOp<i16, DR16_TC, MxSize16, "d">;
220  def MxDRD32_TC : MxRegOp<i32, DR32_TC, MxSize32, "d">;
221}
222
223// ADDRESS REGISTER DIRECT. The operand is in the address register specified by
224// the effective address register field.
225let ParserMatchClass = MxARegClass in {
226  def MxARD16 : MxRegOp<i16, AR16, MxSize16, "a">;
227  def MxARD32 : MxRegOp<i32, AR32, MxSize32, "a">;
228
229  def MxARD16_TC : MxRegOp<i16, AR16_TC, MxSize16, "a">;
230  def MxARD32_TC : MxRegOp<i32, AR32_TC, MxSize32, "a">;
231}
232
233class MxMemOp<dag ops, MxSize size, string letter,
234              string printMethod = "printOperand",
235              AsmOperandClass parserMatchClass = ImmAsmOperand>
236    : Operand<iPTR>, MxOperand<iPTR, size, letter, ?> {
237  let PrintMethod = printMethod;
238  let MIOperandInfo = ops;
239  let ParserMatchClass = parserMatchClass;
240  let OperandType = "OPERAND_MEMORY";
241}
242
243// ADDRESS REGISTER INDIRECT. The address of the operand is in the address
244// register specified by the register field. The reference is classified as
245// a data reference with the exception of the jump and jump-to-subroutine
246// instructions.
247def MxARI         : MxOpClass<"ARI">;
248def MxARI8        : MxMemOp<(ops AR32), MxSize8,  "j", "printARI8Mem", MxARI>;
249def MxARI16       : MxMemOp<(ops AR32), MxSize16, "j", "printARI16Mem", MxARI>;
250def MxARI32       : MxMemOp<(ops AR32), MxSize32, "j", "printARI32Mem", MxARI>;
251
252def MxARI8_TC     : MxMemOp<(ops AR32_TC), MxSize8,  "j", "printARI8Mem", MxARI>;
253def MxARI16_TC    : MxMemOp<(ops AR32_TC), MxSize16, "j", "printARI16Mem", MxARI>;
254def MxARI32_TC    : MxMemOp<(ops AR32_TC), MxSize32, "j", "printARI32Mem", MxARI>;
255
256// ADDRESS REGISTER INDIRECT WITH POSTINCREMENT. The address of the operand is
257// in the address register specified by the register field. After the operand
258// address is used, it is incremented by one, two, or four depending upon whether
259// the size of the operand is byte, word, or long word. If the address register
260// is the stack pointer and the operand size is byte, the address is incremented
261// by two rather than one to keep the stack pointer on a word boundary.
262// The reference is classified as a data reference.
263def MxARIPI       : MxOpClass<"ARIPI">;
264def MxARIPI8      : MxMemOp<(ops AR32), MxSize8,  "o", "printARIPI8Mem", MxARIPI>;
265def MxARIPI16     : MxMemOp<(ops AR32), MxSize16, "o", "printARIPI16Mem", MxARIPI>;
266def MxARIPI32     : MxMemOp<(ops AR32), MxSize32, "o", "printARIPI32Mem", MxARIPI>;
267
268def MxARIPI8_TC   : MxMemOp<(ops AR32_TC), MxSize8,  "o", "printARIPI8Mem", MxARIPI>;
269def MxARIPI16_TC  : MxMemOp<(ops AR32_TC), MxSize16, "o", "printARIPI16Mem", MxARIPI>;
270def MxARIPI32_TC  : MxMemOp<(ops AR32_TC), MxSize32, "o", "printARIPI32Mem", MxARIPI>;
271
272// ADDRESS REGISTER INDIRECT WITH PREDECREMENT. The address of the operand is in
273// the address register specified by the register field. Before the operand
274// address is used, it is decremented by one, two, or four depending upon whether
275// the operand size is byte, word, or long word. If the address register is
276// the stack pointer and the operand size is byte, the address is decremented by
277// two rather than one to keep the stack pointer on a word boundary.
278// The reference is classified as a data reference.
279def MxARIPD       : MxOpClass<"ARIPD">;
280def MxARIPD8      : MxMemOp<(ops AR32), MxSize8,  "e", "printARIPD8Mem", MxARIPD>;
281def MxARIPD16     : MxMemOp<(ops AR32), MxSize16, "e", "printARIPD16Mem", MxARIPD>;
282def MxARIPD32     : MxMemOp<(ops AR32), MxSize32, "e", "printARIPD32Mem", MxARIPD>;
283
284def MxARIPD8_TC   : MxMemOp<(ops AR32_TC), MxSize8,  "e", "printARIPD8Mem", MxARIPD>;
285def MxARIPD16_TC  : MxMemOp<(ops AR32_TC), MxSize16, "e", "printARIPD16Mem", MxARIPD>;
286def MxARIPD32_TC  : MxMemOp<(ops AR32_TC), MxSize32, "e", "printARIPD32Mem", MxARIPD>;
287
288// ADDRESS REGISTER INDIRECT WITH DISPLACEMENT. This addressing mode requires one
289// word of extension. The address of the operand is the sum of the address in
290// the address register and the sign-extended 16-bit displacement integer in the
291// extension word. The reference is classified as a data reference with the
292// exception of the jump and jump-to-subroutine instructions.
293def MxARID        : MxOpClass<"ARID">;
294def MxARID8       : MxMemOp<(ops i16imm, AR32), MxSize8,  "p", "printARID8Mem", MxARID>;
295def MxARID16      : MxMemOp<(ops i16imm, AR32), MxSize16, "p", "printARID16Mem", MxARID>;
296def MxARID32      : MxMemOp<(ops i16imm, AR32), MxSize32, "p", "printARID32Mem", MxARID>;
297
298def MxARID8_TC    : MxMemOp<(ops i16imm, AR32_TC), MxSize8,  "p", "printARID8Mem", MxARID>;
299def MxARID16_TC   : MxMemOp<(ops i16imm, AR32_TC), MxSize16, "p", "printARID16Mem", MxARID>;
300def MxARID32_TC   : MxMemOp<(ops i16imm, AR32_TC), MxSize32, "p", "printARID32Mem", MxARID>;
301
302// ADDRESS REGISTER INDIRECT WITH INDEX. This addressing mode requires one word
303// of extension. The address of the operand is the sum of the address in the
304// address register, the signextended displacement integer in the low order eight
305// bits of the extension word, and the contents of the index register.
306// The reference is classified as a data reference with the exception of the
307// jump and jump-to-subroutine instructions
308def MxARII       : MxOpClass<"ARII">;
309def MxARII8      : MxMemOp<(ops i8imm, AR32, XR32), MxSize8,  "f", "printARII8Mem", MxARII>;
310def MxARII16     : MxMemOp<(ops i8imm, AR32, XR32), MxSize16, "f", "printARII16Mem", MxARII>;
311def MxARII32     : MxMemOp<(ops i8imm, AR32, XR32), MxSize32, "f", "printARII32Mem", MxARII>;
312
313def MxARII8_TC   : MxMemOp<(ops i8imm, AR32_TC, XR32_TC), MxSize8,  "f", "printARII8Mem", MxARII>;
314def MxARII16_TC  : MxMemOp<(ops i8imm, AR32_TC, XR32_TC), MxSize16, "f", "printARII16Mem", MxARII>;
315def MxARII32_TC  : MxMemOp<(ops i8imm, AR32_TC, XR32_TC), MxSize32, "f", "printARII32Mem", MxARII>;
316
317// ABSOLUTE SHORT ADDRESS. This addressing mode requires one word of extension.
318// The address of the operand is the extension word. The 16-bit address is sign
319// extended before it is used.  The reference is classified as a data reference
320// with the exception of the jump and jump-tosubroutine instructions.
321def MxAddr     : MxOpClass<"Addr">;
322let RenderMethod = "addAddrOperands" in {
323  // This hierarchy ensures Addr8 will always be parsed
324  // before other larger-width variants.
325  def MxAddr32   : MxOpClass<"Addr32", [MxAddr]>;
326  def MxAddr16   : MxOpClass<"Addr16", [MxAddr32]>;
327  def MxAddr8    : MxOpClass<"Addr8",  [MxAddr16]>;
328}
329
330def MxAS8      : MxMemOp<(ops OtherVT), MxSize8,  "B", "printAS8Mem",  MxAddr8>;
331def MxAS16     : MxMemOp<(ops OtherVT), MxSize16, "B", "printAS16Mem", MxAddr16>;
332def MxAS32     : MxMemOp<(ops OtherVT), MxSize32, "B", "printAS32Mem", MxAddr32>;
333
334// ABSOLUTE LONG ADDRESS. This addressing mode requires two words of extension.
335// The address of the operand is developed by the concatenation of the extension
336// words. The high order part of the address is the first extension word; the low
337// order part of the address is the second extension word. The reference is
338// classified as a data reference with the exception of the jump and jump
339// to-subroutine instructions.
340def MxAL8      : MxMemOp<(ops OtherVT), MxSize8,  "b", "printAL8Mem",  MxAddr8>;
341def MxAL16     : MxMemOp<(ops OtherVT), MxSize16, "b", "printAL16Mem", MxAddr16>;
342def MxAL32     : MxMemOp<(ops OtherVT), MxSize32, "b", "printAL32Mem", MxAddr32>;
343
344def MxPCD : MxOpClass<"PCD">;
345def MxPCI : MxOpClass<"PCI">;
346
347let OperandType = "OPERAND_PCREL" in {
348// PROGRAM COUNTER WITH DISPLACEMENT. This addressing mode requires one word of
349// extension. The address of the operand is the sum of the address in the program
350// counter and the Sign-extended 16-bit displacement integer in the extension
351// word. The value in the program counter is the address of the extension word.
352// The reference is classified as a program reference.
353def MxPCD8     : MxMemOp<(ops i16imm), MxSize8,  "q", "printPCD8Mem", MxPCD>;
354def MxPCD16    : MxMemOp<(ops i16imm), MxSize16, "q", "printPCD16Mem", MxPCD>;
355def MxPCD32    : MxMemOp<(ops i16imm), MxSize32, "q", "printPCD32Mem", MxPCD>;
356
357// PROGRAM COUNTER WITH INDEX. This addressing mode requires one word of
358// extension. The address is the sum of the address in the program counter, the
359// sign-extended displacement integer in the lower eight bits of the extension
360// word, and the contents of the index register.  The value in the program
361// counter is the address of the extension word. This reference is classified as
362// a program reference.
363def MxPCI8   : MxMemOp<(ops i8imm, XR32), MxSize8,  "k", "printPCI8Mem", MxPCI>;
364def MxPCI16  : MxMemOp<(ops i8imm, XR32), MxSize16, "k", "printPCI16Mem", MxPCI>;
365def MxPCI32  : MxMemOp<(ops i8imm, XR32), MxSize32, "k", "printPCI32Mem", MxPCI>;
366} // OPERAND_PCREL
367
368def MxImm : AsmOperandClass {
369  let Name = "MxImm";
370  let PredicateMethod = "isImm";
371  let RenderMethod = "addImmOperands";
372  let ParserMethod = "parseImm";
373}
374
375class MxOp<ValueType vt, MxSize size, string letter>
376    : Operand<vt>,
377      MxOperand<vt, size, letter, ?> {
378  let ParserMatchClass = MxImm;
379}
380
381let OperandType = "OPERAND_IMMEDIATE",
382    PrintMethod = "printImmediate" in {
383// IMMEDIATE DATA. This addressing mode requires either one or two words of
384// extension depending on the size of the operation.
385//     Byte Operation - operand is low order byte of extension word
386//     Word Operation - operand is extension word
387//     Long Word Operation - operand is in the two extension words,
388//                           high order 16 bits are in the first
389//                           extension word, low order 16 bits are
390//                           in the second extension word.
391def Mxi8imm  : MxOp<i8,  MxSize8,  "i">;
392def Mxi16imm : MxOp<i16, MxSize16, "i">;
393def Mxi32imm : MxOp<i32, MxSize32, "i">;
394} // OPERAND_IMMEDIATE
395
396class MxBrTargetOperand<int N> : Operand<OtherVT> {
397  let OperandType = "OPERAND_PCREL";
398  let PrintMethod = "printPCRelImm";
399  let ParserMatchClass = !cast<AsmOperandClass>("MxAddr"#N);
400}
401// Branch targets have OtherVT type and print as pc-relative values.
402def MxBrTarget8  : MxBrTargetOperand<8>;
403def MxBrTarget16 : MxBrTargetOperand<16>;
404def MxBrTarget32 : MxBrTargetOperand<32>;
405
406// Used with MOVEM
407def MxMoveMaskClass : MxOpClass<"MoveMask">;
408def MxMoveMask : MxOp<i16, MxSize16, "m"> {
409  let OperandType = "OPERAND_IMMEDIATE";
410  let PrintMethod = "printMoveMask";
411  let ParserMatchClass = MxMoveMaskClass;
412}
413
414//===----------------------------------------------------------------------===//
415// Predicates
416//===----------------------------------------------------------------------===//
417
418def SmallCode    : Predicate<"TM.getCodeModel() == CodeModel::Small">;
419def KernelCode   : Predicate<"TM.getCodeModel() == CodeModel::Kernel">;
420def FarData      : Predicate<"TM.getCodeModel() != CodeModel::Small &&"
421                             "TM.getCodeModel() != CodeModel::Kernel">;
422def NearData     : Predicate<"TM.getCodeModel() == CodeModel::Small ||"
423                             "TM.getCodeModel() == CodeModel::Kernel">;
424def IsPIC        : Predicate<"TM.isPositionIndependent()">;
425def IsNotPIC     : Predicate<"!TM.isPositionIndependent()">;
426def IsM68000     : Predicate<"Subtarget.IsM68000()">;
427def IsM68010     : Predicate<"Subtarget.IsM68010()">;
428def IsM68020     : Predicate<"Subtarget.IsM68020()">;
429def IsM68030     : Predicate<"Subtarget.IsM68030()">;
430def IsM68040     : Predicate<"Subtarget.IsM68040()">;
431
432
433//===----------------------------------------------------------------------===//
434// Condition Codes
435//
436// These MUST be kept in sync with codes enum in M68kInstrInfo.h
437//===----------------------------------------------------------------------===//
438
439def MxCONDt   : PatLeaf<(i8 0)>;  // True
440def MxCONDf   : PatLeaf<(i8 1)>;  // False
441def MxCONDhi  : PatLeaf<(i8 2)>;  // High
442def MxCONDls  : PatLeaf<(i8 3)>;  // Less or Same
443def MxCONDcc  : PatLeaf<(i8 4)>;  // Carry Clear
444def MxCONDcs  : PatLeaf<(i8 5)>;  // Carry Set
445def MxCONDne  : PatLeaf<(i8 6)>;  // Not Equal
446def MxCONDeq  : PatLeaf<(i8 7)>;  // Equal
447def MxCONDvc  : PatLeaf<(i8 8)>;  // Overflow Clear
448def MxCONDvs  : PatLeaf<(i8 9)>;  // Overflow Set
449def MxCONDpl  : PatLeaf<(i8 10)>; // Plus
450def MxCONDmi  : PatLeaf<(i8 11)>; // Minus
451def MxCONDge  : PatLeaf<(i8 12)>; // Greater or Equal
452def MxCONDlt  : PatLeaf<(i8 13)>; // Less Than
453def MxCONDgt  : PatLeaf<(i8 14)>; // Greater Than
454def MxCONDle  : PatLeaf<(i8 15)>; // Less or Equal
455
456
457//===----------------------------------------------------------------------===//
458// Complex Patterns
459//===----------------------------------------------------------------------===//
460
461// NOTE Though this CP is not strictly necessarily it will simplify instruciton
462// definitions
463def MxCP_ARI   : ComplexPattern<iPTR, 1, "SelectARI",
464                                [], [SDNPWantParent]>;
465
466def MxCP_ARIPI : ComplexPattern<iPTR, 1, "SelectARIPI",
467                                [], [SDNPWantParent]>;
468
469def MxCP_ARIPD : ComplexPattern<iPTR, 1, "SelectARIPD",
470                                [], [SDNPWantParent]>;
471
472def MxCP_ARID  : ComplexPattern<iPTR, 2, "SelectARID",
473                                [add, sub, mul, or, shl, frameindex],
474                                [SDNPWantParent]>;
475
476def MxCP_ARII  : ComplexPattern<iPTR, 3, "SelectARII",
477                                [add, sub, mul, or, shl, frameindex],
478                                [SDNPWantParent]>;
479
480def MxCP_AL    : ComplexPattern<iPTR, 1, "SelectAL",
481                                [add, sub, mul, or, shl],
482                                [SDNPWantParent]>;
483
484def MxCP_PCD   : ComplexPattern<iPTR, 1, "SelectPCD",
485                                [add, sub, mul, or, shl],
486                                [SDNPWantParent]>;
487
488def MxCP_PCI   : ComplexPattern<iPTR, 2, "SelectPCI",
489                                [add, sub, mul, or, shl], [SDNPWantParent]>;
490
491
492//===----------------------------------------------------------------------===//
493// Pattern Fragments
494//===----------------------------------------------------------------------===//
495
496def MximmSExt8  : PatLeaf<(i8  imm)>;
497def MximmSExt16 : PatLeaf<(i16 imm)>;
498def MximmSExt32 : PatLeaf<(i32 imm)>;
499
500// Used for Shifts and Rotations, since M68k immediates in these instructions
501// are 1 <= i <= 8. Generally, if immediate is bigger than 8 it will be moved
502// to a register and then an operation is performed.
503//
504// TODO Need to evaluate whether splitting one big shift(or rotate)
505// into a few smaller is faster than doing a move, if so do custom lowering
506def Mximm8_1to8   : ImmLeaf<i8,  [{ return Imm >= 1 && Imm <= 8; }]>;
507def Mximm16_1to8  : ImmLeaf<i16, [{ return Imm >= 1 && Imm <= 8; }]>;
508def Mximm32_1to8  : ImmLeaf<i32, [{ return Imm >= 1 && Imm <= 8; }]>;
509
510// Helper fragments for loads.
511// It's always safe to treat a anyext i16 load as a i32 load if the i16 is
512// known to be 32-bit aligned or better. Ditto for i8 to i16.
513def Mxloadi16 : PatFrag<(ops node:$ptr), (i16 (unindexedload node:$ptr)), [{
514  LoadSDNode *LD = cast<LoadSDNode>(N);
515  ISD::LoadExtType ExtType = LD->getExtensionType();
516  if (ExtType == ISD::NON_EXTLOAD)
517    return true;
518  if (ExtType == ISD::EXTLOAD)
519    return LD->getAlignment() >= 2 && !LD->isSimple();
520  return false;
521}]>;
522
523def Mxloadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{
524  LoadSDNode *LD = cast<LoadSDNode>(N);
525  ISD::LoadExtType ExtType = LD->getExtensionType();
526  if (ExtType == ISD::NON_EXTLOAD)
527    return true;
528  if (ExtType == ISD::EXTLOAD)
529    return LD->getAlignment() >= 4 && !LD->isSimple();
530  return false;
531}]>;
532
533def Mxloadi8         : PatFrag<(ops node:$ptr), (i8  (load node:$ptr))>;
534
535def MxSExtLoadi16i8  : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>;
536def MxSExtLoadi32i8  : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>;
537def MxSExtLoadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>;
538
539def MxZExtLoadi8i1   : PatFrag<(ops node:$ptr), (i8  (zextloadi1 node:$ptr))>;
540def MxZExtLoadi16i1  : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>;
541def MxZExtLoadi32i1  : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>;
542def MxZExtLoadi16i8  : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
543def MxZExtLoadi32i8  : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>;
544def MxZExtLoadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>;
545
546def MxExtLoadi8i1    : PatFrag<(ops node:$ptr), (i8  (extloadi1 node:$ptr))>;
547def MxExtLoadi16i1   : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>;
548def MxExtLoadi32i1   : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>;
549def MxExtLoadi16i8   : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>;
550def MxExtLoadi32i8   : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>;
551def MxExtLoadi32i16  : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>;
552
553
554//===----------------------------------------------------------------------===//
555// Type Fixtures
556//
557// Type Fixtures are ValueType related information sets that usually go together
558//===----------------------------------------------------------------------===//
559
560// TODO make it folded like MxType8.F.Op nad MxType8.F.Pat
561// TODO move strings into META subclass
562// vt: Type of data this fixture refers to
563// prefix: Prefix used to identify type
564// postfix: Prefix used to qualify type
565class MxType<ValueType vt, string prefix, string postfix,
566             // rLet: Register letter
567             // rOp:  Supported any register operand
568             string rLet, MxOperand rOp,
569             // jOp:  Supported ARI operand
570             // jPat: What ARI pattern to use
571             MxOperand jOp, ComplexPattern jPat,
572             // oOp:  Supported ARIPI operand
573             // oPat: What ARIPI pattern is used
574             MxOperand oOp, ComplexPattern oPat,
575             // eOp:  Supported ARIPD operand
576             // ePat: What ARIPD pattern is used
577             MxOperand eOp, ComplexPattern ePat,
578             // pOp:  Supported ARID operand
579             // pPat: What ARID pattern is used
580             MxOperand pOp, ComplexPattern pPat,
581             // fOp:  Supported ARII operand
582             // fPat: What ARII pattern is used
583             MxOperand fOp, ComplexPattern fPat,
584             // bOp:  Supported absolute operand
585             // bPat: What absolute pattern is used
586             MxOperand bOp, ComplexPattern bPat,
587             // qOp:  Supported PCD operand
588             // qPat: What PCD pattern is used
589             MxOperand qOp, ComplexPattern qPat,
590             // kOp:  Supported PCI operand
591             // kPat: What PCI pattern is used
592             MxOperand kOp, ComplexPattern kPat,
593             // iOp:  Supported immediate operand
594             // iPat: What immediate pattern is used
595             MxOperand iOp, PatFrag iPat,
596             // load: What load operation is used with MEM
597             PatFrag load> {
598  int Size = vt.Size;
599  ValueType VT = vt;
600  string Prefix = prefix;
601  string Postfix = postfix;
602
603  string RLet = rLet;
604  MxOperand ROp = rOp;
605
606  MxOperand JOp = jOp;
607  ComplexPattern JPat = jPat;
608
609  MxOperand OOp = oOp;
610  ComplexPattern OPat = oPat;
611
612  MxOperand EOp = eOp;
613  ComplexPattern EPat = ePat;
614
615  MxOperand POp = pOp;
616  ComplexPattern PPat = pPat;
617
618  MxOperand FOp = fOp;
619  ComplexPattern FPat = fPat;
620
621  MxOperand BOp = bOp;
622  ComplexPattern BPat = bPat;
623
624  MxOperand QOp = qOp;
625  ComplexPattern QPat = qPat;
626
627  MxOperand KOp = kOp;
628  ComplexPattern KPat = kPat;
629
630  MxOperand IOp = iOp;
631  PatFrag IPat = iPat;
632
633  PatFrag Load = load;
634}
635
636class MxType8Class<string rLet, MxOperand reg>
637    : MxType<i8, "b", "", rLet, reg,
638             MxARI8,   MxCP_ARI,
639             MxARIPI8, MxCP_ARIPI,
640             MxARIPD8, MxCP_ARIPD,
641             MxARID8,  MxCP_ARID,
642             MxARII8,  MxCP_ARII,
643             MxAL8,    MxCP_AL,
644             MxPCD8,   MxCP_PCD,
645             MxPCI8,   MxCP_PCI,
646             Mxi8imm,  MximmSExt8,
647             Mxloadi8>;
648
649def MxType8 : MxType8Class<?,?>;
650
651class MxType16Class<string rLet, MxOperand reg>
652    : MxType<i16, "w", "", rLet, reg,
653             MxARI16,   MxCP_ARI,
654             MxARIPI16, MxCP_ARIPI,
655             MxARIPD16, MxCP_ARIPD,
656             MxARID16,  MxCP_ARID,
657             MxARII16,  MxCP_ARII,
658             MxAL16,    MxCP_AL,
659             MxPCD16,   MxCP_PCD,
660             MxPCI16,   MxCP_PCI,
661             Mxi16imm,  MximmSExt16,
662             Mxloadi16>;
663
664def MxType16 : MxType16Class<?,?>;
665
666class MxType32Class<string rLet, MxOperand reg>
667    : MxType<i32, "l", "", rLet, reg,
668             MxARI32,   MxCP_ARI,
669             MxARIPI32, MxCP_ARIPI,
670             MxARIPD32, MxCP_ARIPD,
671             MxARID32,  MxCP_ARID,
672             MxARII32,  MxCP_ARII,
673             MxAL32,    MxCP_AL,
674             MxPCD32,   MxCP_PCD,
675             MxPCI32,   MxCP_PCI,
676             Mxi32imm,  MximmSExt32,
677             Mxloadi32>;
678
679def MxType32 : MxType32Class<?,?>;
680
681
682def MxType8d : MxType8Class<"d", MxDRD8>;
683
684def MxType16d : MxType16Class<"d", MxDRD16>;
685def MxType16a : MxType16Class<"a", MxARD16>;
686def MxType16r : MxType16Class<"r", MxXRD16>;
687def MxType32d : MxType32Class<"d", MxDRD32>;
688def MxType32a : MxType32Class<"a", MxARD32>;
689def MxType32r : MxType32Class<"r", MxXRD32>;
690
691let Postfix = "_TC" in {
692def MxType16d_TC : MxType16Class<"d", MxDRD16_TC>;
693def MxType16a_TC : MxType16Class<"a", MxARD16_TC>;
694def MxType16r_TC : MxType16Class<"r", MxXRD16_TC>;
695def MxType32d_TC : MxType32Class<"d", MxDRD32_TC>;
696def MxType32a_TC : MxType32Class<"a", MxARD32_TC>;
697def MxType32r_TC : MxType32Class<"r", MxXRD32_TC>;
698}
699
700
701//===----------------------------------------------------------------------===//
702// Subsystems
703//===----------------------------------------------------------------------===//
704
705include "M68kInstrData.td"
706include "M68kInstrShiftRotate.td"
707include "M68kInstrBits.td"
708include "M68kInstrArithmetic.td"
709include "M68kInstrControl.td"
710
711include "M68kInstrCompiler.td"
712