1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419
|
//===-- M68kInstrControl.td - Control Flow Instructions ----*- tablegen -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
///
/// \file
/// This file describes the M68k jump, return, call, and related instructions.
/// Here is the current status of the file:
///
/// Machine:
///
/// BRA [x] BSR [~] Bcc [~] DBcc [ ] FBcc [ ]
/// FDBcc [ ] FNOP [ ] FPn [ ] FScc [ ] FTST [ ]
/// JMP [~] JSR [x] NOP [x] RTD [!] RTR [ ]
/// RTS [x] Scc [~] TST [ ]
///
/// Pseudo:
///
/// RET [x]
/// TCRETURNj [x] TCRETURNq [x]
/// TAILJMPj [x] TAILJMPq [x]
///
/// Map:
///
/// [ ] - was not touched at all
/// [!] - requires extarnal stuff implemented
/// [~] - in progress but usable
/// [x] - done
///
///
/// NOTE
/// Though branch and jump instructions are using memory operands they
/// DO NOT read the jump address from memory, they just calculate EA
/// and jump there.
///
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
// NOP
//===----------------------------------------------------------------------===//
let hasSideEffects = 0 in {
def NOP : MxInst<(outs), (ins), "nop", []> {
let Inst = (descend 0b0100, 0b1110, 0b0111, 0b0001);
}
}
//===----------------------------------------------------------------------===//
// Conditions
//===----------------------------------------------------------------------===//
/// CC—Carry clear GE—Greater than or equal
/// LS—Lower or same PL—Plus
/// CS—Carry set GT—Greater than
/// LT—Less than T—Always true*
/// EQ—Equal HI—Higher
/// MI—Minus VC—Overflow clear
/// F—Never true* LE—Less than or equal
/// NE—Not equal VS—Overflow set
///
/// *Not applicable to the Bcc instructions.
class MxEncCondOp<bits<4> cond> {
dag Value = (descend cond);
}
def MxCCt : MxEncCondOp<0b0000>;
def MxCCf : MxEncCondOp<0b0001>;
def MxCChi : MxEncCondOp<0b0010>;
def MxCCls : MxEncCondOp<0b0011>;
def MxCCcc : MxEncCondOp<0b0100>;
def MxCCcs : MxEncCondOp<0b0101>;
def MxCCne : MxEncCondOp<0b0110>;
def MxCCeq : MxEncCondOp<0b0111>;
def MxCCvc : MxEncCondOp<0b1000>;
def MxCCvs : MxEncCondOp<0b1001>;
def MxCCpl : MxEncCondOp<0b1010>;
def MxCCmi : MxEncCondOp<0b1011>;
def MxCCge : MxEncCondOp<0b1100>;
def MxCClt : MxEncCondOp<0b1101>;
def MxCCgt : MxEncCondOp<0b1110>;
def MxCCle : MxEncCondOp<0b1111>;
/// --------------------------------+---------+---------
/// F E D C | B A 9 8 | 7 6 | 5 4 3 | 2 1 0
/// --------------------------------+---------+---------
/// 0 1 0 1 | CONDITION | 1 1 | MODE | REG
/// ----------------------------------------------------
let Uses = [CCR] in {
class MxSccR<string CC>
: MxInst<(outs MxDRD8:$dst), (ins), "s"#CC#"\t$dst",
[(set i8:$dst, (MxSetCC !cast<PatLeaf>("MxCOND"#CC), CCR))]> {
let Inst = (descend 0b0101, !cast<MxEncCondOp>("MxCC"#CC).Value, 0b11,
/*MODE without last bit*/0b00,
/*REGISTER prefixed with D/A bit*/(operand "$dst", 4));
}
class MxSccM<string CC, MxOperand MEMOpd, ComplexPattern MEMPat, MxEncMemOp DST_ENC>
: MxInst<(outs), (ins MEMOpd:$dst), "s"#CC#"\t$dst",
[(store (MxSetCC !cast<PatLeaf>("MxCOND"#CC), CCR), MEMPat:$dst)]> {
let Inst =
(ascend
(descend 0b0101, !cast<MxEncCondOp>("MxCC"#CC).Value, 0b11, DST_ENC.EA),
DST_ENC.Supplement
);
}
}
foreach cc = [ "cc", "ls", "lt", "eq", "mi", "f", "ne", "ge",
"cs", "pl", "gt", "t", "hi", "vc", "le", "vs"] in {
def SET#"d8"#cc : MxSccR<cc>;
def SET#"j8"#cc : MxSccM<cc, MxType8.JOp, MxType8.JPat, MxEncAddrMode_j<"dst">>;
def SET#"p8"#cc : MxSccM<cc, MxType8.POp, MxType8.PPat, MxEncAddrMode_p<"dst">>;
}
//===----------------------------------------------------------------------===//
// Jumps
//===----------------------------------------------------------------------===//
///------------------------------+---------+---------
/// F E D C B A 9 8 7 6 | 5 4 3 | 2 1 0
///------------------------------+---------+---------
/// 0 1 0 0 1 1 1 0 1 1 | MODE | REG
///------------------------------+---------+---------
let isBranch = 1, isTerminator = 1, isBarrier = 1, isIndirectBranch = 1 in
class MxJMP<MxOperand LOCOp, MxEncMemOp DST_ENC>
: MxInst<(outs), (ins LOCOp:$dst), "jmp\t$dst", [(brind iPTR:$dst)]> {
let Inst =
(ascend
(descend 0b0100, 0b1110, 0b11, DST_ENC.EA),
DST_ENC.Supplement
);
}
def JMP32j : MxJMP<MxARI32, MxEncAddrMode_j<"dst">>;
// FIXME Support 16 bit indirect jump.
// Currently M68k does not allow 16 bit indirect jumps use sext operands
// def JMP16r : MxInst<(outs), (ins M68k_ARI16:$dst),
// "jmp\t$dst",
// [(brind AR16:$dst)]>;
//===----------------------------------------------------------------------===//
// Branches
//===----------------------------------------------------------------------===//
/// --------------------------------------------------
/// F E D C | B A 9 8 | 7 6 5 4 3 2 1 0
/// --------------------------------------------------
/// 0 1 1 0 | CONDITION | 8-BIT DISPLACEMENT
/// --------------------------------------------------
/// 16-BIT DISPLACEMENT IF 8-BIT DISPLACEMENT = $00
/// --------------------------------------------------
/// 32-BIT DISPLACEMENT IF 8-BIT DISPLACEMENT = $FF
/// --------------------------------------------------
let isBranch = 1, isTerminator = 1, Uses = [CCR] in
class MxBcc<string cc, Operand TARGET, dag disp_8, dag disp_16_32>
: MxInst<(outs), (ins TARGET:$dst), "b"#cc#"\t$dst", []> {
// FIXME: If we want to avoid supplying disp_16_32 with empty
// (ascend) for 16/32 bits variants, we can use conditional
// bang operator like this:
// ```
// class MxBcc<string cc, Operand TARGET, int SIZE>
// ...
// let Inst = !cond(
// !eq(SIZE, 8): /* encoding for Bcc8 */
// !eq(SIZE, 16): /* encoding for Bcc16 */
// !eq(SIZE, 32): /* encoding for Bcc32 */
// );
let Inst =
(ascend
(descend 0b0110, !cast<MxEncCondOp>("MxCC"#cc).Value, disp_8),
disp_16_32
);
}
foreach cc = [ "cc", "ls", "lt", "eq", "mi", "ne", "ge",
"cs", "pl", "gt", "hi", "vc", "le", "vs"] in {
def B#cc#"8"
: MxBcc<cc, MxBrTarget8,
(operand "$dst", 8, (encoder "encodePCRelImm<8>")), (ascend)>;
def B#cc#"16"
: MxBcc<cc, MxBrTarget16, (descend 0b0000, 0b0000),
(operand "$dst", 16, (encoder "encodePCRelImm<16>"))>;
}
foreach cc = [ "cc", "ls", "lt", "eq", "mi", "ne", "ge",
"cs", "pl", "gt", "hi", "vc", "le", "vs"] in {
def : Pat<(MxBrCond bb:$target, !cast<PatLeaf>("MxCOND"#cc), CCR),
(!cast<Instruction>("B"#cc#"8") MxBrTarget8:$target)>;
}
/// -------------------------------------------------
/// F E D C B A 9 8 | 7 6 5 4 3 2 1 0
/// -------------------------------------------------
/// 0 1 1 0 0 0 0 0 | 8-BIT DISPLACEMENT
/// -------------------------------------------------
/// 16-BIT DISPLACEMENT IF 8-BIT DISPLACEMENT = $00
/// -------------------------------------------------
/// 32-BIT DISPLACEMENT IF 8-BIT DISPLACEMENT = $FF
/// -------------------------------------------------
let isBranch = 1, isTerminator = 1, isBarrier = 1 in
class MxBra<Operand TARGET, dag disp_8, dag disp_16_32>
: MxInst<(outs), (ins TARGET:$dst), "bra\t$dst", []> {
let Inst =
(ascend
(descend 0b0110, 0b0000, disp_8),
disp_16_32
);
}
def BRA8 : MxBra<MxBrTarget8,
(operand "$dst", 8, (encoder "encodePCRelImm<8>")), (ascend)>;
def BRA16 : MxBra<MxBrTarget16, (descend 0b0000, 0b0000),
(operand "$dst", 16, (encoder "encodePCRelImm<16>"))>;
def : Pat<(br bb:$target), (BRA8 MxBrTarget8:$target)>;
/// -------------------------------------------------
/// F E D C B A 9 8 | 7 6 5 4 3 2 1 0
/// -------------------------------------------------
/// 0 1 1 0 0 0 0 1 | 8-BIT DISPLACEMENT
/// -------------------------------------------------
/// 16-BIT DISPLACEMENT IF 8-BIT DISPLACEMENT = $00
/// -------------------------------------------------
/// 32-BIT DISPLACEMENT IF 8-BIT DISPLACEMENT = $FF
/// -------------------------------------------------
let isBranch = 1, isTerminator = 1 in
class MxBsr<Operand TARGET, MxType TYPE, dag disp_8, dag disp_16_32>
: MxInst<(outs), (ins TARGET:$dst), "bsr."#TYPE.Prefix#"\t$dst"> {
let Inst = (ascend
(descend 0b0110, 0b0001, disp_8),
disp_16_32
);
}
def BSR8 : MxBsr<MxBrTarget8, MxType8,
(operand "$dst", 8, (encoder "encodePCRelImm<8>")), (ascend)>;
def BSR16 : MxBsr<MxBrTarget16, MxType16, (descend 0b0000, 0b0000),
(operand "$dst", 16, (encoder "encodePCRelImm<16>"))>;
def BSR32 : MxBsr<MxBrTarget32, MxType32, (descend 0b1111, 0b1111),
(operand "$dst", 32, (encoder "encodePCRelImm<32>"),
(decoder "DecodeImm32"))>;
//===----------------------------------------------------------------------===//
// Call
//===----------------------------------------------------------------------===//
// All calls clobber the non-callee saved registers. %SP is marked as
// a use to prevent stack-pointer assignments that appear immediately
// before calls from potentially appearing dead. Uses for argument
// registers are added manually.
let Uses = [SP] in
let isCall = 1 in
///------------------------------+---------+---------
/// F E D C B A 9 8 7 6 | 5 4 3 | 2 1 0
///------------------------------+---------+---------
/// 0 1 0 0 1 1 1 0 1 0 | MODE | REG
///------------------------------+---------+---------
class MxCall<MxOperand LOCOp, MxEncMemOp DST_ENC>
: MxInst<(outs), (ins LOCOp:$dst), "jsr\t$dst", []> {
let Inst =
(ascend
(descend 0b0100, 0b1110, 0b10, DST_ENC.EA),
DST_ENC.Supplement
);
}
def CALLk : MxCall<MxPCI32, MxEncAddrMode_k<"dst">>;
def CALLq : MxCall<MxPCD32, MxEncAddrMode_q<"dst">>;
def CALLb : MxCall<MxAL32, MxEncAddrMode_abs<"dst", true>>;
def CALLj : MxCall<MxARI32, MxEncAddrMode_j<"dst">>;
multiclass CallPat<MxCall callOp, Predicate pred> {
let Predicates = [pred] in {
def : Pat<(MxCall (i32 tglobaladdr:$dst)), (callOp tglobaladdr:$dst)>;
def : Pat<(MxCall (i32 texternalsym:$dst)), (callOp texternalsym:$dst)>;
def : Pat<(MxCall (i32 imm:$dst)), (callOp imm:$dst)>;
}
}
defm : CallPat<CALLq, IsPIC>;
defm : CallPat<CALLb, IsNotPIC>;
def : Pat<(MxCall iPTR:$dst), (CALLj MxARI32:$dst)>;
//===----------------------------------------------------------------------===//
// Tail Call
//===----------------------------------------------------------------------===//
let isCodeGenOnly = 1 in {
let Uses = [SP] in {
let isCall = 1, isTerminator = 1, isBarrier = 1 in {
let isReturn = 1 in
def TCRETURNq : MxPseudo<(outs), (ins MxPCD32:$dst, i32imm:$adj)>;
def TAILJMPq : MxPseudo<(outs), (ins MxPCD32:$dst)>;
// NOTE j does not mean load and jump M68k jmp just calculates EA and jumps
// and it is using Mem form like (An) thus j letter.
let isReturn = 1 in
def TCRETURNj : MxPseudo<(outs), (ins MxARI32_TC:$dst, i32imm:$adj)>;
def TAILJMPj : MxPseudo<(outs), (ins MxARI32_TC:$dst)>;
} // isCall = 1, isTerminator = 1, isBarrier = 1
} // Uses = [SP]
} // isCodeGenOnly = 1
//===----------------------------------------------------------------------===//
// Return
//===----------------------------------------------------------------------===//
let isTerminator = 1, isReturn = 1, isBarrier = 1, hasCtrlDep = 1 in {
def RTS : MxInst<(outs), (ins), "rts", []> {
let Inst = (descend 0b0100, 0b1110, 0b0111, 0b0101);
}
let isCodeGenOnly = 1 in
def RET : MxPseudo<(outs), (ins i32imm:$adj, variable_ops),
[(MxRet timm:$adj)]>;
} // isTerminator = 1, isReturn = 1, isBarrier = 1, hasCtrlDep = 1
//===----------------------------------------------------------------------===//
// SETCC_C Patterns
//===----------------------------------------------------------------------===//
// Use subx to materialize carry bit.
let Uses = [CCR], Defs = [CCR], isPseudo = 1 in {
// FIXME These are pseudo ops that should be replaced with Pat<> patterns.
// However, Pat<> can't replicate the destination reg into the inputs of the
// result.
def SETCS_C8d : MxPseudo<(outs MxDRD8:$dst), (ins),
[(set MxDRD8:$dst, (MxSetCC_C MxCONDcs, CCR))]>;
def SETCS_C16d : MxPseudo<(outs MxDRD16:$dst), (ins),
[(set MxDRD16:$dst, (MxSetCC_C MxCONDcs, CCR))]>;
def SETCS_C32d : MxPseudo<(outs MxXRD32:$dst), (ins),
[(set MxXRD32:$dst, (MxSetCC_C MxCONDcs, CCR))]>;
} // Uses = [CCR], Defs = [CCR], isPseudo = 1
def : Pat<(i16 (anyext (i8 (MxSetCC_C MxCONDcs, CCR)))), (SETCS_C16d)>;
def : Pat<(i32 (anyext (i8 (MxSetCC_C MxCONDcs, CCR)))), (SETCS_C32d)>;
def : Pat<(i16 (sext (i8 (MxSetCC_C MxCONDcs, CCR)))), (SETCS_C16d)>;
def : Pat<(i32 (sext (i8 (MxSetCC_C MxCONDcs, CCR)))), (SETCS_C32d)>;
// We canonicalize 'scs' to "(and (subx reg,reg), 1)" on the hope that the and
// will be eliminated and that the subx can be extended up to a wider type. When
// this happens, it is great. However, if we are left with an 8-bit subx and an
// and, we might as well just match it as a setb.
def : Pat<(and (i8 (MxSetCC_C MxCONDcs, CCR)), 1), (SETd8cs)>;
// (add OP, SETB) -> (addx OP, (move 0))
def : Pat<(add (and (i8 (MxSetCC_C MxCONDcs, CCR)), 1), MxDRD8:$op),
(ADDX8dd MxDRD8:$op, (MOV8di 0))>;
def : Pat<(add (and (i32 (MxSetCC_C MxCONDcs, CCR)), 1), MxXRD32:$op),
(ADDX32dd MxDRD32:$op, (MOV32ri 0))>;
// (sub OP, SETB) -> (subx OP, (move 0))
def : Pat<(sub MxDRD8:$op, (and (i8 (MxSetCC_C MxCONDcs, CCR)), 1)),
(SUBX8dd MxDRD8:$op, (MOV8di 0))>;
def : Pat<(sub MxXRD32:$op, (and (i32 (MxSetCC_C MxCONDcs, CCR)), 1)),
(SUBX32dd MxDRD32:$op, (MOV32ri 0))>;
// (sub OP, SETCC_CARRY) -> (addx OP, (move 0))
def : Pat<(sub MxDRD8:$op, (i8 (MxSetCC_C MxCONDcs, CCR))),
(ADDX8dd MxDRD8:$op, (MOV8di 0))>;
def : Pat<(sub MxXRD32:$op, (i32 (MxSetCC_C MxCONDcs, CCR))),
(ADDX32dd MxDRD32:$op, (MOV32ri 0))>;
//===------------===//
// Trap / Breakpoint
//===------------===//
let RenderMethod = "addImmOperands", ParserMethod = "parseImm" in {
def MxTrapImm : AsmOperandClass {
let Name = "MxTrapImm";
let PredicateMethod = "isTrapImm";
}
def MxBkptImm : AsmOperandClass {
let Name = "MxBkptImm";
let PredicateMethod = "isBkptImm";
}
}
let ParserMatchClass = MxTrapImm in
def MxTrapimm : MxOp<i8, MxSize8, "i">;
let ParserMatchClass = MxBkptImm in
def MxBkptimm : MxOp<i8, MxSize8, "i">;
def TRAP : MxInst<(outs), (ins MxTrapimm:$vect), "trap\t$vect", []> {
let Inst = (descend 0b0100, 0b1110, 0b0100, (operand "$vect", 4));
}
def TRAPV : MxInst<(outs), (ins), "trapv", []> {
let Inst = (descend 0b0100, 0b1110, 0b0111, 0b0110);
}
def BKPT : MxInst<(outs), (ins MxBkptimm:$vect), "bkpt\t$vect", []> {
let Inst = (descend 0b0100, 0b1000, 0b0100, 0b1 , (operand "$vect", 3));
}
def ILLEGAL : MxInst<(outs), (ins), "illegal", []> {
let Inst = (descend 0b0100, 0b1010, 0b1111, 0b1100);
}
|