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:$disp, AR32:$reg), MxSize8, "p", "printARID8Mem", MxARID>; 295def MxARID16 : MxMemOp<(ops i16imm:$disp, AR32:$reg), MxSize16, "p", "printARID16Mem", MxARID>; 296def MxARID32 : MxMemOp<(ops i16imm:$disp, AR32:$reg), MxSize32, "p", "printARID32Mem", MxARID>; 297 298def MxARID8_TC : MxMemOp<(ops i16imm:$disp, AR32_TC:$reg), MxSize8, "p", "printARID8Mem", MxARID>; 299def MxARID16_TC : MxMemOp<(ops i16imm:$disp, AR32_TC:$reg), MxSize16, "p", "printARID16Mem", MxARID>; 300def MxARID32_TC : MxMemOp<(ops i16imm:$disp, AR32_TC:$reg), 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:$disp, AR32:$reg, XR32:$index), 310 MxSize8, "f", "printARII8Mem", MxARII>; 311def MxARII16 : MxMemOp<(ops i8imm:$disp, AR32:$reg, XR32:$index), 312 MxSize16, "f", "printARII16Mem", MxARII>; 313def MxARII32 : MxMemOp<(ops i8imm:$disp, AR32:$reg, XR32:$index), 314 MxSize32, "f", "printARII32Mem", MxARII>; 315 316def MxARII8_TC : MxMemOp<(ops i8imm:$disp, AR32_TC:$reg, XR32_TC:$index), 317 MxSize8, "f", "printARII8Mem", MxARII>; 318def MxARII16_TC : MxMemOp<(ops i8imm:$disp, AR32_TC:$reg, XR32_TC:$index), 319 MxSize16, "f", "printARII16Mem", MxARII>; 320def MxARII32_TC : MxMemOp<(ops i8imm:$disp, AR32_TC:$reg, XR32_TC:$index), 321 MxSize32, "f", "printARII32Mem", MxARII>; 322 323// ABSOLUTE SHORT ADDRESS. This addressing mode requires one word of extension. 324// The address of the operand is the extension word. The 16-bit address is sign 325// extended before it is used. The reference is classified as a data reference 326// with the exception of the jump and jump-tosubroutine instructions. 327def MxAddr : MxOpClass<"Addr">; 328let RenderMethod = "addAddrOperands" in { 329 // This hierarchy ensures Addr8 will always be parsed 330 // before other larger-width variants. 331 def MxAddr32 : MxOpClass<"Addr32", [MxAddr]>; 332 def MxAddr16 : MxOpClass<"Addr16", [MxAddr32]>; 333 def MxAddr8 : MxOpClass<"Addr8", [MxAddr16]>; 334} 335 336def MxAS8 : MxMemOp<(ops OtherVT), MxSize8, "B", "printAS8Mem", MxAddr8>; 337def MxAS16 : MxMemOp<(ops OtherVT), MxSize16, "B", "printAS16Mem", MxAddr16>; 338def MxAS32 : MxMemOp<(ops OtherVT), MxSize32, "B", "printAS32Mem", MxAddr32>; 339 340// ABSOLUTE LONG ADDRESS. This addressing mode requires two words of extension. 341// The address of the operand is developed by the concatenation of the extension 342// words. The high order part of the address is the first extension word; the low 343// order part of the address is the second extension word. The reference is 344// classified as a data reference with the exception of the jump and jump 345// to-subroutine instructions. 346def MxAL8 : MxMemOp<(ops OtherVT), MxSize8, "b", "printAL8Mem", MxAddr8>; 347def MxAL16 : MxMemOp<(ops OtherVT), MxSize16, "b", "printAL16Mem", MxAddr16>; 348def MxAL32 : MxMemOp<(ops OtherVT), MxSize32, "b", "printAL32Mem", MxAddr32>; 349 350def MxPCD : MxOpClass<"PCD">; 351def MxPCI : MxOpClass<"PCI">; 352 353let OperandType = "OPERAND_PCREL" in { 354// PROGRAM COUNTER WITH DISPLACEMENT. This addressing mode requires one word of 355// extension. The address of the operand is the sum of the address in the program 356// counter and the Sign-extended 16-bit displacement integer in the extension 357// word. The value in the program counter is the address of the extension word. 358// The reference is classified as a program reference. 359def MxPCD8 : MxMemOp<(ops i16imm), MxSize8, "q", "printPCD8Mem", MxPCD>; 360def MxPCD16 : MxMemOp<(ops i16imm), MxSize16, "q", "printPCD16Mem", MxPCD>; 361def MxPCD32 : MxMemOp<(ops i16imm), MxSize32, "q", "printPCD32Mem", MxPCD>; 362 363// PROGRAM COUNTER WITH INDEX. This addressing mode requires one word of 364// extension. The address is the sum of the address in the program counter, the 365// sign-extended displacement integer in the lower eight bits of the extension 366// word, and the contents of the index register. The value in the program 367// counter is the address of the extension word. This reference is classified as 368// a program reference. 369def MxPCI8 : MxMemOp<(ops i8imm:$disp, XR32:$index), MxSize8, "k", "printPCI8Mem", MxPCI>; 370def MxPCI16 : MxMemOp<(ops i8imm:$disp, XR32:$index), MxSize16, "k", "printPCI16Mem", MxPCI>; 371def MxPCI32 : MxMemOp<(ops i8imm:$disp, XR32:$index), MxSize32, "k", "printPCI32Mem", MxPCI>; 372} // OPERAND_PCREL 373 374def MxImm : AsmOperandClass { 375 let Name = "MxImm"; 376 let PredicateMethod = "isImm"; 377 let RenderMethod = "addImmOperands"; 378 let ParserMethod = "parseImm"; 379} 380 381class MxOp<ValueType vt, MxSize size, string letter> 382 : Operand<vt>, 383 MxOperand<vt, size, letter, ?> { 384 let ParserMatchClass = MxImm; 385} 386 387let OperandType = "OPERAND_IMMEDIATE", 388 PrintMethod = "printImmediate" in { 389// IMMEDIATE DATA. This addressing mode requires either one or two words of 390// extension depending on the size of the operation. 391// Byte Operation - operand is low order byte of extension word 392// Word Operation - operand is extension word 393// Long Word Operation - operand is in the two extension words, 394// high order 16 bits are in the first 395// extension word, low order 16 bits are 396// in the second extension word. 397def Mxi8imm : MxOp<i8, MxSize8, "i">; 398def Mxi16imm : MxOp<i16, MxSize16, "i">; 399def Mxi32imm : MxOp<i32, MxSize32, "i">; 400} // OPERAND_IMMEDIATE 401 402class MxBrTargetOperand<int N> : Operand<OtherVT> { 403 let OperandType = "OPERAND_PCREL"; 404 let PrintMethod = "printPCRelImm"; 405 let ParserMatchClass = !cast<AsmOperandClass>("MxAddr"#N); 406} 407// Branch targets have OtherVT type and print as pc-relative values. 408def MxBrTarget8 : MxBrTargetOperand<8>; 409def MxBrTarget16 : MxBrTargetOperand<16>; 410def MxBrTarget32 : MxBrTargetOperand<32>; 411 412// Used with MOVEM 413def MxMoveMaskClass : MxOpClass<"MoveMask">; 414def MxMoveMask : MxOp<i16, MxSize16, "m"> { 415 let OperandType = "OPERAND_IMMEDIATE"; 416 let PrintMethod = "printMoveMask"; 417 let ParserMatchClass = MxMoveMaskClass; 418} 419 420//===----------------------------------------------------------------------===// 421// Predicates 422//===----------------------------------------------------------------------===// 423 424def SmallCode : Predicate<"TM.getCodeModel() == CodeModel::Small">; 425def KernelCode : Predicate<"TM.getCodeModel() == CodeModel::Kernel">; 426def FarData : Predicate<"TM.getCodeModel() != CodeModel::Small &&" 427 "TM.getCodeModel() != CodeModel::Kernel">; 428def NearData : Predicate<"TM.getCodeModel() == CodeModel::Small ||" 429 "TM.getCodeModel() == CodeModel::Kernel">; 430def IsPIC : Predicate<"TM.isPositionIndependent()">; 431def IsNotPIC : Predicate<"!TM.isPositionIndependent()">; 432 433def AtLeastM68000 : Predicate<"Subtarget->atLeastM68000()">; 434def AtLeastM68010 : Predicate<"Subtarget->atLeastM68010()">; 435def AtLeastM68020 : Predicate<"Subtarget->atLeastM68020()">; 436def AtLeastM68030 : Predicate<"Subtarget->atLeastM68030()">; 437def AtLeastM68040 : Predicate<"Subtarget->atLeastM68040()">; 438 439//===----------------------------------------------------------------------===// 440// Condition Codes 441// 442// These MUST be kept in sync with codes enum in M68kInstrInfo.h 443//===----------------------------------------------------------------------===// 444 445def MxCONDt : PatLeaf<(i8 0)>; // True 446def MxCONDf : PatLeaf<(i8 1)>; // False 447def MxCONDhi : PatLeaf<(i8 2)>; // High 448def MxCONDls : PatLeaf<(i8 3)>; // Less or Same 449def MxCONDcc : PatLeaf<(i8 4)>; // Carry Clear 450def MxCONDcs : PatLeaf<(i8 5)>; // Carry Set 451def MxCONDne : PatLeaf<(i8 6)>; // Not Equal 452def MxCONDeq : PatLeaf<(i8 7)>; // Equal 453def MxCONDvc : PatLeaf<(i8 8)>; // Overflow Clear 454def MxCONDvs : PatLeaf<(i8 9)>; // Overflow Set 455def MxCONDpl : PatLeaf<(i8 10)>; // Plus 456def MxCONDmi : PatLeaf<(i8 11)>; // Minus 457def MxCONDge : PatLeaf<(i8 12)>; // Greater or Equal 458def MxCONDlt : PatLeaf<(i8 13)>; // Less Than 459def MxCONDgt : PatLeaf<(i8 14)>; // Greater Than 460def MxCONDle : PatLeaf<(i8 15)>; // Less or Equal 461 462 463//===----------------------------------------------------------------------===// 464// Complex Patterns 465//===----------------------------------------------------------------------===// 466 467// NOTE Though this CP is not strictly necessarily it will simplify instruciton 468// definitions 469def MxCP_ARI : ComplexPattern<iPTR, 1, "SelectARI", 470 [], [SDNPWantParent]>; 471 472def MxCP_ARIPI : ComplexPattern<iPTR, 1, "SelectARIPI", 473 [], [SDNPWantParent]>; 474 475def MxCP_ARIPD : ComplexPattern<iPTR, 1, "SelectARIPD", 476 [], [SDNPWantParent]>; 477 478def MxCP_ARID : ComplexPattern<iPTR, 2, "SelectARID", 479 [add, sub, mul, or, shl, frameindex], 480 [SDNPWantParent]>; 481 482def MxCP_ARII : ComplexPattern<iPTR, 3, "SelectARII", 483 [add, sub, mul, or, shl, frameindex], 484 [SDNPWantParent]>; 485 486def MxCP_AL : ComplexPattern<iPTR, 1, "SelectAL", 487 [add, sub, mul, or, shl], 488 [SDNPWantParent]>; 489 490def MxCP_PCD : ComplexPattern<iPTR, 1, "SelectPCD", 491 [add, sub, mul, or, shl], 492 [SDNPWantParent]>; 493 494def MxCP_PCI : ComplexPattern<iPTR, 2, "SelectPCI", 495 [add, sub, mul, or, shl], [SDNPWantParent]>; 496 497 498//===----------------------------------------------------------------------===// 499// Pattern Fragments 500//===----------------------------------------------------------------------===// 501 502def MximmSExt8 : PatLeaf<(i8 imm)>; 503def MximmSExt16 : PatLeaf<(i16 imm)>; 504def MximmSExt32 : PatLeaf<(i32 imm)>; 505 506// Used for Shifts and Rotations, since M68k immediates in these instructions 507// are 1 <= i <= 8. Generally, if immediate is bigger than 8 it will be moved 508// to a register and then an operation is performed. 509// 510// TODO Need to evaluate whether splitting one big shift(or rotate) 511// into a few smaller is faster than doing a move, if so do custom lowering 512def Mximm8_1to8 : ImmLeaf<i8, [{ return Imm >= 1 && Imm <= 8; }]>; 513def Mximm16_1to8 : ImmLeaf<i16, [{ return Imm >= 1 && Imm <= 8; }]>; 514def Mximm32_1to8 : ImmLeaf<i32, [{ return Imm >= 1 && Imm <= 8; }]>; 515 516// Helper fragments for loads. 517// It's always safe to treat a anyext i16 load as a i32 load if the i16 is 518// known to be 32-bit aligned or better. Ditto for i8 to i16. 519def Mxloadi16 : PatFrag<(ops node:$ptr), (i16 (unindexedload node:$ptr)), [{ 520 LoadSDNode *LD = cast<LoadSDNode>(N); 521 ISD::LoadExtType ExtType = LD->getExtensionType(); 522 if (ExtType == ISD::NON_EXTLOAD) 523 return true; 524 if (ExtType == ISD::EXTLOAD) 525 return LD->getAlign() >= 2 && !LD->isSimple(); 526 return false; 527}]>; 528 529def Mxloadi32 : PatFrag<(ops node:$ptr), (i32 (unindexedload node:$ptr)), [{ 530 LoadSDNode *LD = cast<LoadSDNode>(N); 531 ISD::LoadExtType ExtType = LD->getExtensionType(); 532 if (ExtType == ISD::NON_EXTLOAD) 533 return true; 534 if (ExtType == ISD::EXTLOAD) 535 return LD->getAlign() >= 4 && !LD->isSimple(); 536 return false; 537}]>; 538 539def Mxloadi8 : PatFrag<(ops node:$ptr), (i8 (load node:$ptr))>; 540 541def MxSExtLoadi16i8 : PatFrag<(ops node:$ptr), (i16 (sextloadi8 node:$ptr))>; 542def MxSExtLoadi32i8 : PatFrag<(ops node:$ptr), (i32 (sextloadi8 node:$ptr))>; 543def MxSExtLoadi32i16 : PatFrag<(ops node:$ptr), (i32 (sextloadi16 node:$ptr))>; 544 545def MxZExtLoadi8i1 : PatFrag<(ops node:$ptr), (i8 (zextloadi1 node:$ptr))>; 546def MxZExtLoadi16i1 : PatFrag<(ops node:$ptr), (i16 (zextloadi1 node:$ptr))>; 547def MxZExtLoadi32i1 : PatFrag<(ops node:$ptr), (i32 (zextloadi1 node:$ptr))>; 548def MxZExtLoadi16i8 : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>; 549def MxZExtLoadi32i8 : PatFrag<(ops node:$ptr), (i32 (zextloadi8 node:$ptr))>; 550def MxZExtLoadi32i16 : PatFrag<(ops node:$ptr), (i32 (zextloadi16 node:$ptr))>; 551 552def MxExtLoadi8i1 : PatFrag<(ops node:$ptr), (i8 (extloadi1 node:$ptr))>; 553def MxExtLoadi16i1 : PatFrag<(ops node:$ptr), (i16 (extloadi1 node:$ptr))>; 554def MxExtLoadi32i1 : PatFrag<(ops node:$ptr), (i32 (extloadi1 node:$ptr))>; 555def MxExtLoadi16i8 : PatFrag<(ops node:$ptr), (i16 (extloadi8 node:$ptr))>; 556def MxExtLoadi32i8 : PatFrag<(ops node:$ptr), (i32 (extloadi8 node:$ptr))>; 557def MxExtLoadi32i16 : PatFrag<(ops node:$ptr), (i32 (extloadi16 node:$ptr))>; 558 559 560//===----------------------------------------------------------------------===// 561// Type Fixtures 562// 563// Type Fixtures are ValueType related information sets that usually go together 564//===----------------------------------------------------------------------===// 565 566// TODO make it folded like MxType8.F.Op nad MxType8.F.Pat 567// TODO move strings into META subclass 568// vt: Type of data this fixture refers to 569// prefix: Prefix used to identify type 570// postfix: Prefix used to qualify type 571class MxType<ValueType vt, string prefix, string postfix, 572 // rLet: Register letter 573 // rOp: Supported any register operand 574 string rLet, MxOperand rOp, 575 // jOp: Supported ARI operand 576 // jPat: What ARI pattern to use 577 MxOperand jOp, ComplexPattern jPat, 578 // oOp: Supported ARIPI operand 579 // oPat: What ARIPI pattern is used 580 MxOperand oOp, ComplexPattern oPat, 581 // eOp: Supported ARIPD operand 582 // ePat: What ARIPD pattern is used 583 MxOperand eOp, ComplexPattern ePat, 584 // pOp: Supported ARID operand 585 // pPat: What ARID pattern is used 586 MxOperand pOp, ComplexPattern pPat, 587 // fOp: Supported ARII operand 588 // fPat: What ARII pattern is used 589 MxOperand fOp, ComplexPattern fPat, 590 // bOp: Supported absolute operand 591 // bPat: What absolute pattern is used 592 MxOperand bOp, ComplexPattern bPat, 593 // qOp: Supported PCD operand 594 // qPat: What PCD pattern is used 595 MxOperand qOp, ComplexPattern qPat, 596 // kOp: Supported PCI operand 597 // kPat: What PCI pattern is used 598 MxOperand kOp, ComplexPattern kPat, 599 // iOp: Supported immediate operand 600 // iPat: What immediate pattern is used 601 MxOperand iOp, PatFrag iPat, 602 // load: What load operation is used with MEM 603 PatFrag load> { 604 int Size = vt.Size; 605 ValueType VT = vt; 606 string Prefix = prefix; 607 string Postfix = postfix; 608 609 string RLet = rLet; 610 MxOperand ROp = rOp; 611 612 MxOperand JOp = jOp; 613 ComplexPattern JPat = jPat; 614 615 MxOperand OOp = oOp; 616 ComplexPattern OPat = oPat; 617 618 MxOperand EOp = eOp; 619 ComplexPattern EPat = ePat; 620 621 MxOperand POp = pOp; 622 ComplexPattern PPat = pPat; 623 624 MxOperand FOp = fOp; 625 ComplexPattern FPat = fPat; 626 627 MxOperand BOp = bOp; 628 ComplexPattern BPat = bPat; 629 630 MxOperand QOp = qOp; 631 ComplexPattern QPat = qPat; 632 633 MxOperand KOp = kOp; 634 ComplexPattern KPat = kPat; 635 636 MxOperand IOp = iOp; 637 PatFrag IPat = iPat; 638 639 PatFrag Load = load; 640} 641 642// Provides an alternative way to access the MxOperand and 643// patterns w.r.t a specific addressing mode. 644class MxOpBundle<int size, MxOperand op, ComplexPattern pat> { 645 int Size = size; 646 MxOperand Op = op; 647 ComplexPattern Pat = pat; 648} 649 650class MxImmOpBundle<int size, MxOperand op, PatFrag pat> 651 : MxOpBundle<size, op, ?> { 652 PatFrag ImmPat = pat; 653} 654 655// TODO: We can use MxOp<S>AddrMode_<AM> in more places to 656// replace MxType-based operand factoring. 657foreach size = [8, 16, 32] in { 658 // Dn 659 def MxOp#size#AddrMode_d 660 : MxOpBundle<size, !cast<MxOperand>("MxDRD"#size), ?>; 661 662 // (An) 663 def MxOp#size#AddrMode_j 664 : MxOpBundle<size, !cast<MxOperand>("MxARI"#size), MxCP_ARI>; 665 666 // (An)+ 667 def MxOp#size#AddrMode_o 668 : MxOpBundle<size, !cast<MxOperand>("MxARIPI"#size), MxCP_ARIPI>; 669 670 // -(An) 671 def MxOp#size#AddrMode_e 672 : MxOpBundle<size, !cast<MxOperand>("MxARIPD"#size), MxCP_ARIPD>; 673 674 // (i,An) 675 def MxOp#size#AddrMode_p 676 : MxOpBundle<size, !cast<MxOperand>("MxARID"#size), MxCP_ARID>; 677 678 // (i,An,Xn) 679 def MxOp#size#AddrMode_f 680 : MxOpBundle<size, !cast<MxOperand>("MxARII"#size), MxCP_ARII>; 681 682 // (ABS).L 683 def MxOp#size#AddrMode_b 684 : MxOpBundle<size, !cast<MxOperand>("MxAL"#size), MxCP_AL>; 685 686 // (i,PC) 687 def MxOp#size#AddrMode_q 688 : MxOpBundle<size, !cast<MxOperand>("MxPCD"#size), MxCP_PCD>; 689 690 // (i,PC,Xn) 691 def MxOp#size#AddrMode_k 692 : MxOpBundle<size, !cast<MxOperand>("MxPCI"#size), MxCP_PCI>; 693 694 // #imm 695 def MxOp#size#AddrMode_i 696 : MxImmOpBundle<size, !cast<MxOperand>("Mxi"#size#"imm"), 697 !cast<PatFrag>("MximmSExt"#size)>; 698} // foreach size = [8, 16, 32] 699 700foreach size = [16, 32] in { 701 // An 702 def MxOp#size#AddrMode_a 703 : MxOpBundle<size, !cast<MxOperand>("MxARD"#size), ?>; 704 705 // Xn 706 def MxOp#size#AddrMode_r 707 : MxOpBundle<size, !cast<MxOperand>("MxXRD"#size), ?>; 708} // foreach size = [16, 32] 709 710class MxType8Class<string rLet, MxOperand reg> 711 : MxType<i8, "b", "", rLet, reg, 712 MxARI8, MxCP_ARI, 713 MxARIPI8, MxCP_ARIPI, 714 MxARIPD8, MxCP_ARIPD, 715 MxARID8, MxCP_ARID, 716 MxARII8, MxCP_ARII, 717 MxAL8, MxCP_AL, 718 MxPCD8, MxCP_PCD, 719 MxPCI8, MxCP_PCI, 720 Mxi8imm, MximmSExt8, 721 Mxloadi8>; 722 723def MxType8 : MxType8Class<?,?>; 724 725class MxType16Class<string rLet, MxOperand reg> 726 : MxType<i16, "w", "", rLet, reg, 727 MxARI16, MxCP_ARI, 728 MxARIPI16, MxCP_ARIPI, 729 MxARIPD16, MxCP_ARIPD, 730 MxARID16, MxCP_ARID, 731 MxARII16, MxCP_ARII, 732 MxAL16, MxCP_AL, 733 MxPCD16, MxCP_PCD, 734 MxPCI16, MxCP_PCI, 735 Mxi16imm, MximmSExt16, 736 Mxloadi16>; 737 738def MxType16 : MxType16Class<?,?>; 739 740class MxType32Class<string rLet, MxOperand reg> 741 : MxType<i32, "l", "", rLet, reg, 742 MxARI32, MxCP_ARI, 743 MxARIPI32, MxCP_ARIPI, 744 MxARIPD32, MxCP_ARIPD, 745 MxARID32, MxCP_ARID, 746 MxARII32, MxCP_ARII, 747 MxAL32, MxCP_AL, 748 MxPCD32, MxCP_PCD, 749 MxPCI32, MxCP_PCI, 750 Mxi32imm, MximmSExt32, 751 Mxloadi32>; 752 753def MxType32 : MxType32Class<?,?>; 754 755 756def MxType8d : MxType8Class<"d", MxDRD8>; 757 758def MxType16d : MxType16Class<"d", MxDRD16>; 759def MxType16a : MxType16Class<"a", MxARD16>; 760def MxType16r : MxType16Class<"r", MxXRD16>; 761def MxType32d : MxType32Class<"d", MxDRD32>; 762def MxType32a : MxType32Class<"a", MxARD32>; 763def MxType32r : MxType32Class<"r", MxXRD32>; 764 765let Postfix = "_TC" in { 766def MxType16d_TC : MxType16Class<"d", MxDRD16_TC>; 767def MxType16a_TC : MxType16Class<"a", MxARD16_TC>; 768def MxType16r_TC : MxType16Class<"r", MxXRD16_TC>; 769def MxType32d_TC : MxType32Class<"d", MxDRD32_TC>; 770def MxType32a_TC : MxType32Class<"a", MxARD32_TC>; 771def MxType32r_TC : MxType32Class<"r", MxXRD32_TC>; 772} 773 774 775//===----------------------------------------------------------------------===// 776// Subsystems 777//===----------------------------------------------------------------------===// 778 779include "M68kInstrData.td" 780include "M68kInstrShiftRotate.td" 781include "M68kInstrBits.td" 782include "M68kInstrArithmetic.td" 783include "M68kInstrControl.td" 784include "M68kInstrAtomics.td" 785 786include "M68kInstrCompiler.td" 787