Skip to content

Commit d7f7e1d

Browse files
committed
[M68k] Fix requirements and operands for MOVE from/to CCR/SR
This fixes the defined CPU feature requirements for some of the MOVE from/to CCR/SR instructions. Specifically, MOVE to CCR and MOVE from SR are available to the whole 68000 family, except MOVE from SR requires supervisor mode on 68010+. On 68000, MOVE from SR is used instead of MOVE from CCR to move the condition bits. A new feature predicate IsM68000 is added for any lowering that needs to make this choice. The operands on these instructions are also adjusted to not take a destination for MOVE to CCR/SR (because the destination is invariable) and to not take a source for MOVE from CCR/SR (because the source is invariable).
1 parent 607ac48 commit d7f7e1d

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

llvm/lib/Target/M68k/M68kInstrData.td

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,15 +374,15 @@ def MOVM32mp_P : MxMOVEM_RM_Pseudo<MxType32r, MxType32.POp>;
374374
/// --------------------------------------------------
375375
let Defs = [CCR] in {
376376
class MxMoveToCCR<MxOperand MEMOp, MxEncMemOp SRC_ENC>
377-
: MxInst<(outs CCRC:$dst), (ins MEMOp:$src), "move.w\t$src, $dst", []> {
377+
: MxInst<(outs), (ins MEMOp:$src), "move.w\t$src, %ccr", []> {
378378
let Inst = (ascend
379379
(descend 0b0100010011, SRC_ENC.EA),
380380
SRC_ENC.Supplement
381381
);
382382
}
383383

384384
class MxMoveToCCRPseudo<MxOperand MEMOp>
385-
: MxPseudo<(outs CCRC:$dst), (ins MEMOp:$src)>;
385+
: MxPseudo<(outs), (ins MEMOp:$src)>;
386386
} // let Defs = [CCR]
387387

388388
let mayLoad = 1 in
@@ -405,13 +405,13 @@ def MOV8cd : MxMoveToCCRPseudo<MxOp8AddrMode_d.Op>;
405405
/// --------------------------------------------------
406406
let Uses = [CCR] in {
407407
class MxMoveFromCCR_R
408-
: MxInst<(outs MxDRD16:$dst), (ins CCRC:$src), "move.w\t$src, $dst", []>,
408+
: MxInst<(outs MxDRD16:$dst), (ins), "move.w\t%ccr, $dst", []>,
409409
Requires<[ AtLeastM68010 ]> {
410410
let Inst = (descend 0b0100001011, MxEncAddrMode_d<"dst">.EA);
411411
}
412412

413413
class MxMoveFromCCR_M<MxOperand MEMOp, MxEncMemOp DST_ENC>
414-
: MxInst<(outs), (ins MEMOp:$dst, CCRC:$src), "move.w\t$src, $dst", []>,
414+
: MxInst<(outs), (ins MEMOp:$dst), "move.w\t%ccr, $dst", []>,
415415
Requires<[ AtLeastM68010 ]> {
416416
let Inst = (ascend
417417
(descend 0b0100001011, DST_ENC.EA),
@@ -420,9 +420,9 @@ class MxMoveFromCCR_M<MxOperand MEMOp, MxEncMemOp DST_ENC>
420420
}
421421

422422
class MxMoveFromCCRPseudo<MxOperand MEMOp>
423-
: MxPseudo<(outs), (ins MEMOp:$dst, CCRC:$src)>;
423+
: MxPseudo<(outs), (ins MEMOp:$dst)>;
424424
class MxMoveFromCCR_RPseudo<MxOperand MEMOp>
425-
: MxPseudo<(outs MEMOp:$dst), (ins CCRC:$src)>;
425+
: MxPseudo<(outs MEMOp:$dst), (ins)>;
426426
} // let Uses = [CCR]
427427

428428
let mayStore = 1 in
@@ -447,7 +447,7 @@ def MOV8dc : MxMoveFromCCR_RPseudo<MxOp8AddrMode_d.Op>;
447447
/// --------------------------------------------------
448448
let Defs = [SR] in {
449449
class MxMoveToSR<MxOperand MEMOp, MxEncMemOp SRC_ENC>
450-
: MxInst<(outs SRC:$dst), (ins MEMOp:$src), "move.w\t$src, $dst", []> {
450+
: MxInst<(outs), (ins MEMOp:$src), "move.w\t$src, %sr", []> {
451451
let Inst = (ascend
452452
(descend 0b0100011011, SRC_ENC.EA),
453453
SRC_ENC.Supplement
@@ -470,16 +470,17 @@ def MOV16sd : MxMoveToSR<MxOp16AddrMode_d.Op, MxMoveSrcOpEnc_d>;
470470
/// | EFFECTIVE ADDRESS
471471
/// 0 1 0 0 0 0 0 0 1 1 | MODE | REG
472472
/// --------------------------------------------------
473+
474+
// MoveFromSR works on 68010+ but it causes an exception unless in
475+
// supervisor mode. But on 68000, MoveFromSR is the *only* way to move CCR.
473476
let Uses = [SR] in {
474477
class MxMoveFromSR_R
475-
: MxInst<(outs MxDRD16:$dst), (ins SRC:$src), "move.w\t$src, $dst", []>,
476-
Requires<[ AtLeastM68010 ]> {
478+
: MxInst<(outs MxDRD16:$dst), (ins), "move.w\t%sr, $dst", []> {
477479
let Inst = (descend 0b0100000011, MxEncAddrMode_d<"dst">.EA);
478480
}
479481

480482
class MxMoveFromSR_M<MxOperand MEMOp, MxEncMemOp DST_ENC>
481-
: MxInst<(outs), (ins MEMOp:$dst, SRC:$src), "move.w\t$src, $dst", []>,
482-
Requires<[ AtLeastM68010 ]> {
483+
: MxInst<(outs), (ins MEMOp:$dst), "move.w\t%sr, $dst", []> {
483484
let Inst = (ascend
484485
(descend 0b0100000011, DST_ENC.EA),
485486
DST_ENC.Supplement

llvm/lib/Target/M68k/M68kInstrInfo.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,9 @@ def IsPIC : Predicate<"TM.isPositionIndependent()">;
465465
def IsNotPIC : Predicate<"!TM.isPositionIndependent()">;
466466

467467
// ISA versions
468+
def IsM68000 : Predicate<"Subtarget->isM68000()">,
469+
AssemblerPredicate<(all_of FeatureISA00)>;
470+
468471
foreach i = [0,1,2,4,6] in
469472
def AtLeastM680 # i # "0" : Predicate<"Subtarget->atLeastM680"#i#"0()">,
470473
AssemblerPredicate<(all_of

llvm/lib/Target/M68k/M68kSubtarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class M68kSubtarget : public M68kGenSubtargetInfo {
8484
/// of function is auto generated by tblgen.
8585
void ParseSubtargetFeatures(StringRef CPU, StringRef TuneCPU, StringRef FS);
8686

87+
bool isM68000() const { return SubtargetKind == M00; }
8788
bool atLeastM68000() const { return SubtargetKind >= M00; }
8889
bool atLeastM68010() const { return SubtargetKind >= M10; }
8990
bool atLeastM68020() const { return SubtargetKind >= M20; }

0 commit comments

Comments
 (0)