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