2008-11-19 19:00:54 +08:00
|
|
|
//===- PIC16InstrInfo.td - PIC16 Instruction defs -------------*- tblgen-*-===//
|
2008-05-13 17:02:57 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-19 19:00:54 +08:00
|
|
|
//
|
2009-01-30 17:01:44 +08:00
|
|
|
// This file describes the PIC16 instructions in TableGen format.
|
2008-11-19 19:00:54 +08:00
|
|
|
//
|
2008-05-13 17:02:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-19 19:00:54 +08:00
|
|
|
// PIC16 Specific Type Constraints.
|
2008-05-13 17:02:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-19 19:00:54 +08:00
|
|
|
class SDTCisI8<int OpNum> : SDTCisVT<OpNum, i8>;
|
|
|
|
class SDTCisI16<int OpNum> : SDTCisVT<OpNum, i16>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-19 19:00:54 +08:00
|
|
|
// PIC16 Specific Type Profiles.
|
2008-05-13 17:02:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Generic type profiles for i8/i16 unary/binary operations.
|
|
|
|
// Taking one i8 or i16 and producing void.
|
|
|
|
def SDTI8VoidOp : SDTypeProfile<0, 1, [SDTCisI8<0>]>;
|
|
|
|
def SDTI16VoidOp : SDTypeProfile<0, 1, [SDTCisI16<0>]>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Taking one value and producing an output of same type.
|
|
|
|
def SDTI8UnaryOp : SDTypeProfile<1, 1, [SDTCisI8<0>, SDTCisI8<1>]>;
|
|
|
|
def SDTI16UnaryOp : SDTypeProfile<1, 1, [SDTCisI16<0>, SDTCisI16<1>]>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Taking two values and producing an output of same type.
|
|
|
|
def SDTI8BinOp : SDTypeProfile<1, 2, [SDTCisI8<0>, SDTCisI8<1>, SDTCisI8<2>]>;
|
|
|
|
def SDTI16BinOp : SDTypeProfile<1, 2, [SDTCisI16<0>, SDTCisI16<1>,
|
|
|
|
SDTCisI16<2>]>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Node specific type profiles.
|
|
|
|
def SDT_PIC16Load : SDTypeProfile<1, 3, [SDTCisI8<0>, SDTCisI8<1>,
|
|
|
|
SDTCisI8<2>, SDTCisI8<3>]>;
|
2009-01-14 03:18:47 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
def SDT_PIC16Store : SDTypeProfile<0, 4, [SDTCisI8<0>, SDTCisI8<1>,
|
|
|
|
SDTCisI8<2>, SDTCisI8<3>]>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2009-04-08 13:38:48 +08:00
|
|
|
def SDT_PIC16Connect : SDTypeProfile<1, 2, [SDTCisI8<0>, SDTCisI8<1>,
|
|
|
|
SDTCisI8<2>]>;
|
|
|
|
|
2009-01-14 03:18:47 +08:00
|
|
|
// PIC16ISD::CALL type prorile
|
|
|
|
def SDT_PIC16call : SDTypeProfile<0, -1, [SDTCisInt<0>]>;
|
2009-04-08 13:38:48 +08:00
|
|
|
def SDT_PIC16callw : SDTypeProfile<1, -1, [SDTCisInt<0>]>;
|
2009-01-14 03:18:47 +08:00
|
|
|
|
|
|
|
// PIC16ISD::BRCOND
|
|
|
|
def SDT_PIC16Brcond: SDTypeProfile<0, 2,
|
|
|
|
[SDTCisVT<0, OtherVT>, SDTCisI8<1>]>;
|
|
|
|
|
|
|
|
// PIC16ISD::BRCOND
|
|
|
|
def SDT_PIC16Selecticc: SDTypeProfile<1, 3,
|
|
|
|
[SDTCisI8<0>, SDTCisI8<1>, SDTCisI8<2>,
|
|
|
|
SDTCisI8<3>]>;
|
|
|
|
|
2008-05-13 17:02:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-19 19:00:54 +08:00
|
|
|
// PIC16 addressing modes matching via DAG.
|
2008-05-13 17:02:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-19 19:00:54 +08:00
|
|
|
def diraddr : ComplexPattern<i8, 1, "SelectDirectAddr", [], []>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-19 19:00:54 +08:00
|
|
|
// PIC16 Specific Node Definitions.
|
2008-05-13 17:02:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-19 19:00:54 +08:00
|
|
|
def PIC16callseq_start : SDNode<"ISD::CALLSEQ_START", SDTI8VoidOp,
|
|
|
|
[SDNPHasChain, SDNPOutFlag]>;
|
|
|
|
def PIC16callseq_end : SDNode<"ISD::CALLSEQ_END", SDTI8VoidOp,
|
2009-01-14 03:18:47 +08:00
|
|
|
[SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Low 8-bits of GlobalAddress.
|
2009-04-14 10:49:52 +08:00
|
|
|
def PIC16Lo : SDNode<"PIC16ISD::Lo", SDTI8BinOp>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// High 8-bits of GlobalAddress.
|
2009-04-14 10:49:52 +08:00
|
|
|
def PIC16Hi : SDNode<"PIC16ISD::Hi", SDTI8BinOp>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// The MTHI and MTLO nodes are used only to match them in the incoming
|
|
|
|
// DAG for replacement by corresponding set_fsrhi, set_fsrlo insntructions.
|
|
|
|
// These nodes are not used for defining any instructions.
|
2009-04-08 13:38:48 +08:00
|
|
|
def MTLO : SDNode<"PIC16ISD::MTLO", SDTI8UnaryOp>;
|
|
|
|
def MTHI : SDNode<"PIC16ISD::MTHI", SDTI8UnaryOp>;
|
|
|
|
def MTPCLATH : SDNode<"PIC16ISD::MTPCLATH", SDTI8UnaryOp>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Node to generate Bank Select for a GlobalAddress.
|
|
|
|
def Banksel : SDNode<"PIC16ISD::Banksel", SDTI8UnaryOp>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Node to match a direct store operation.
|
|
|
|
def PIC16Store : SDNode<"PIC16ISD::PIC16Store", SDT_PIC16Store, [SDNPHasChain]>;
|
2009-01-14 03:18:47 +08:00
|
|
|
def PIC16StWF : SDNode<"PIC16ISD::PIC16StWF", SDT_PIC16Store,
|
|
|
|
[SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Node to match a direct load operation.
|
2009-04-03 01:42:00 +08:00
|
|
|
def PIC16Load : SDNode<"PIC16ISD::PIC16Load", SDT_PIC16Load, [SDNPHasChain]>;
|
|
|
|
def PIC16LdArg : SDNode<"PIC16ISD::PIC16LdArg", SDT_PIC16Load, [SDNPHasChain]>;
|
|
|
|
def PIC16LdWF : SDNode<"PIC16ISD::PIC16LdWF", SDT_PIC16Load,
|
2009-01-14 03:18:47 +08:00
|
|
|
[SDNPHasChain, SDNPInFlag, SDNPOutFlag]>;
|
2009-04-08 13:38:48 +08:00
|
|
|
def PIC16Connect: SDNode<"PIC16ISD::PIC16Connect", SDT_PIC16Connect, []>;
|
2009-01-14 03:18:47 +08:00
|
|
|
|
|
|
|
// Node to match PIC16 call
|
|
|
|
def PIC16call : SDNode<"PIC16ISD::CALL", SDT_PIC16call,
|
|
|
|
[SDNPHasChain , SDNPOptInFlag, SDNPOutFlag]>;
|
2009-04-08 13:38:48 +08:00
|
|
|
def PIC16callw : SDNode<"PIC16ISD::CALLW", SDT_PIC16callw,
|
|
|
|
[SDNPHasChain , SDNPOptInFlag, SDNPOutFlag]>;
|
2009-01-14 03:18:47 +08:00
|
|
|
|
|
|
|
// Node to match a comparison instruction.
|
|
|
|
def PIC16Subcc : SDNode<"PIC16ISD::SUBCC", SDTI8BinOp, [SDNPOutFlag]>;
|
|
|
|
|
|
|
|
// Node to match a conditional branch.
|
|
|
|
def PIC16Brcond : SDNode<"PIC16ISD::BRCOND", SDT_PIC16Brcond,
|
|
|
|
[SDNPHasChain, SDNPInFlag]>;
|
|
|
|
|
|
|
|
def PIC16Selecticc : SDNode<"PIC16ISD::SELECT_ICC", SDT_PIC16Selecticc,
|
|
|
|
[SDNPInFlag]>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PIC16 Operand Definitions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
def i8mem : Operand<i8>;
|
2009-01-14 03:18:47 +08:00
|
|
|
def brtarget: Operand<OtherVT>;
|
|
|
|
|
|
|
|
// Operand for printing out a condition code.
|
|
|
|
let PrintMethod = "printCCOperand" in
|
|
|
|
def CCOp : Operand<i8>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-26 18:53:50 +08:00
|
|
|
include "PIC16InstrFormats.td"
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-26 18:53:50 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PIC16 Common Classes.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2009-01-14 03:18:47 +08:00
|
|
|
// W = W Op F : Load the value from F and do Op to W.
|
2009-05-12 12:30:38 +08:00
|
|
|
let isTwoAddress = 1, mayLoad = 1 in
|
2008-11-26 18:53:50 +08:00
|
|
|
class BinOpFW<bits<6> OpCode, string OpcStr, SDNode OpNode>:
|
|
|
|
ByteFormat<OpCode, (outs GPR:$dst),
|
|
|
|
(ins GPR:$src, i8imm:$offset, i8mem:$ptrlo, i8imm:$ptrhi),
|
|
|
|
!strconcat(OpcStr, " $ptrlo + $offset, W"),
|
|
|
|
[(set GPR:$dst, (OpNode GPR:$src, (PIC16Load diraddr:$ptrlo,
|
|
|
|
(i8 imm:$ptrhi),
|
|
|
|
(i8 imm:$offset))))]>;
|
2009-01-14 03:18:47 +08:00
|
|
|
|
|
|
|
// F = F Op W : Load the value from F, do op with W and store in F.
|
2009-03-10 18:35:34 +08:00
|
|
|
// This insn class is not marked as TwoAddress because the reg is
|
|
|
|
// being used as a source operand only. (Remember a TwoAddress insn
|
|
|
|
// needs a copyRegToReg.)
|
2009-05-12 12:30:38 +08:00
|
|
|
let mayStore = 1 in
|
2008-11-26 18:53:50 +08:00
|
|
|
class BinOpWF<bits<6> OpCode, string OpcStr, SDNode OpNode>:
|
|
|
|
ByteFormat<OpCode, (outs),
|
|
|
|
(ins GPR:$src, i8imm:$offset, i8mem:$ptrlo, i8imm:$ptrhi),
|
|
|
|
!strconcat(OpcStr, " $ptrlo + $offset"),
|
|
|
|
[(PIC16Store (OpNode GPR:$src, (PIC16Load diraddr:$ptrlo,
|
|
|
|
(i8 imm:$ptrhi),
|
|
|
|
(i8 imm:$offset))),
|
|
|
|
diraddr:$ptrlo,
|
|
|
|
(i8 imm:$ptrhi), (i8 imm:$offset)
|
|
|
|
)]>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2009-01-14 03:18:47 +08:00
|
|
|
// W = W Op L : Do Op of L with W and place result in W.
|
2009-03-10 18:35:34 +08:00
|
|
|
let isTwoAddress = 1 in
|
2009-01-14 03:18:47 +08:00
|
|
|
class BinOpLW<bits<6> opcode, string OpcStr, SDNode OpNode> :
|
|
|
|
LiteralFormat<opcode, (outs GPR:$dst),
|
|
|
|
(ins GPR:$src, i8imm:$literal),
|
|
|
|
!strconcat(OpcStr, " $literal"),
|
|
|
|
[(set GPR:$dst, (OpNode GPR:$src, (i8 imm:$literal)))]>;
|
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
// PIC16 Instructions.
|
|
|
|
//===----------------------------------------------------------------------===//
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Pseudo-instructions.
|
|
|
|
def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i8imm:$amt),
|
|
|
|
"!ADJCALLSTACKDOWN $amt",
|
|
|
|
[(PIC16callseq_start imm:$amt)]>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
def ADJCALLSTACKUP : Pseudo<(outs), (ins i8imm:$amt),
|
|
|
|
"!ADJCALLSTACKUP $amt",
|
|
|
|
[(PIC16callseq_end imm:$amt)]>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
//-----------------------------------
|
|
|
|
// Vaious movlw insn patterns.
|
|
|
|
//-----------------------------------
|
|
|
|
let isReMaterializable = 1 in {
|
|
|
|
// Move 8-bit literal to W.
|
|
|
|
def movlw : BitFormat<12, (outs GPR:$dst), (ins i8imm:$src),
|
|
|
|
"movlw $src",
|
|
|
|
[(set GPR:$dst, (i8 imm:$src))]>;
|
|
|
|
|
|
|
|
// Move a Lo(TGA) to W.
|
2009-04-14 10:49:52 +08:00
|
|
|
def movlw_lo_1 : BitFormat<12, (outs GPR:$dst), (ins i8imm:$src, i8imm:$src2),
|
2009-06-03 23:31:12 +08:00
|
|
|
"movlw LOW(${src} + ${src2})",
|
2009-04-14 10:49:52 +08:00
|
|
|
[(set GPR:$dst, (PIC16Lo tglobaladdr:$src, imm:$src2 ))]>;
|
|
|
|
|
|
|
|
// Move a Lo(TES) to W.
|
|
|
|
def movlw_lo_2 : BitFormat<12, (outs GPR:$dst), (ins i8imm:$src, i8imm:$src2),
|
2009-06-03 23:31:12 +08:00
|
|
|
"movlw LOW(${src} + ${src2})",
|
2009-04-14 10:49:52 +08:00
|
|
|
[(set GPR:$dst, (PIC16Lo texternalsym:$src, imm:$src2 ))]>;
|
2008-11-19 19:00:54 +08:00
|
|
|
|
|
|
|
// Move a Hi(TGA) to W.
|
2009-04-14 10:49:52 +08:00
|
|
|
def movlw_hi_1 : BitFormat<12, (outs GPR:$dst), (ins i8imm:$src, i8imm:$src2),
|
2009-06-03 23:31:12 +08:00
|
|
|
"movlw HIGH(${src} + ${src2})",
|
2009-04-14 10:49:52 +08:00
|
|
|
[(set GPR:$dst, (PIC16Hi tglobaladdr:$src, imm:$src2))]>;
|
|
|
|
|
|
|
|
// Move a Hi(TES) to W.
|
|
|
|
def movlw_hi_2 : BitFormat<12, (outs GPR:$dst), (ins i8imm:$src, i8imm:$src2),
|
2009-06-03 23:31:12 +08:00
|
|
|
"movlw HIGH(${src} + ${src2})",
|
2009-04-14 10:49:52 +08:00
|
|
|
[(set GPR:$dst, (PIC16Hi texternalsym:$src, imm:$src2))]>;
|
2008-11-19 19:00:54 +08:00
|
|
|
}
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
//-------------------
|
|
|
|
// FSR setting insns.
|
|
|
|
//-------------------
|
|
|
|
// These insns are matched via a DAG replacement pattern.
|
|
|
|
def set_fsrlo:
|
|
|
|
ByteFormat<0, (outs FSR16:$fsr),
|
|
|
|
(ins GPR:$val),
|
|
|
|
"movwf ${fsr}L",
|
|
|
|
[]>;
|
|
|
|
|
|
|
|
let isTwoAddress = 1 in
|
|
|
|
def set_fsrhi:
|
|
|
|
ByteFormat<0, (outs FSR16:$dst),
|
|
|
|
(ins FSR16:$src, GPR:$val),
|
|
|
|
"movwf ${dst}H",
|
|
|
|
[]>;
|
|
|
|
|
2009-04-08 13:38:48 +08:00
|
|
|
def set_pclath:
|
|
|
|
ByteFormat<0, (outs PCLATHR:$dst),
|
|
|
|
(ins GPR:$val),
|
|
|
|
"movwf ${dst}",
|
|
|
|
[(set PCLATHR:$dst , (MTPCLATH GPR:$val))]>;
|
|
|
|
|
2009-03-10 18:35:34 +08:00
|
|
|
//----------------------------
|
|
|
|
// copyRegToReg
|
|
|
|
// copyRegToReg insns. These are dummy. They should always be deleted
|
|
|
|
// by the optimizer and never be present in the final generated code.
|
|
|
|
// if they are, then we have to write correct macros for these insns.
|
|
|
|
//----------------------------
|
2008-11-19 19:00:54 +08:00
|
|
|
def copy_fsr:
|
|
|
|
Pseudo<(outs FSR16:$dst), (ins FSR16:$src), "copy_fsr $dst, $src", []>;
|
|
|
|
|
2009-01-14 03:18:47 +08:00
|
|
|
def copy_w:
|
|
|
|
Pseudo<(outs GPR:$dst), (ins GPR:$src), "copy_w $dst, $src", []>;
|
|
|
|
|
2009-04-10 23:10:14 +08:00
|
|
|
class SAVE_FSR<string OpcStr>:
|
|
|
|
Pseudo<(outs),
|
|
|
|
(ins FSR16:$src, i8imm:$offset, i8mem:$ptrlo, i8imm:$ptrhi),
|
|
|
|
!strconcat(OpcStr, " $ptrlo, $offset"),
|
|
|
|
[]>;
|
|
|
|
|
|
|
|
def save_fsr0: SAVE_FSR<"save_fsr0">;
|
|
|
|
def save_fsr1: SAVE_FSR<"save_fsr1">;
|
|
|
|
|
|
|
|
class RESTORE_FSR<string OpcStr>:
|
|
|
|
Pseudo<(outs FSR16:$dst),
|
|
|
|
(ins i8imm:$offset, i8mem:$ptrlo, i8imm:$ptrhi),
|
|
|
|
!strconcat(OpcStr, " $ptrlo, $offset"),
|
|
|
|
[]>;
|
|
|
|
|
|
|
|
def restore_fsr0: RESTORE_FSR<"restore_fsr0">;
|
|
|
|
def restore_fsr1: RESTORE_FSR<"restore_fsr1">;
|
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
//--------------------------
|
|
|
|
// Store to memory
|
|
|
|
//-------------------------
|
2009-03-10 18:35:34 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Direct store.
|
2009-03-10 18:35:34 +08:00
|
|
|
// Input operands are: val = W, ptrlo = GA, offset = offset, ptrhi = banksel.
|
2009-05-12 12:30:38 +08:00
|
|
|
let mayStore = 1 in
|
2009-03-10 18:35:34 +08:00
|
|
|
class MOVWF_INSN<bits<6> OpCode, SDNode OpNodeDest, SDNode Op>:
|
2008-11-19 19:00:54 +08:00
|
|
|
ByteFormat<0, (outs),
|
|
|
|
(ins GPR:$val, i8imm:$offset, i8mem:$ptrlo, i8imm:$ptrhi),
|
|
|
|
"movwf ${ptrlo} + ${offset}",
|
2009-03-10 18:35:34 +08:00
|
|
|
[(Op GPR:$val, OpNodeDest:$ptrlo, (i8 imm:$ptrhi),
|
2008-11-19 19:00:54 +08:00
|
|
|
(i8 imm:$offset))]>;
|
|
|
|
|
2009-03-10 18:35:34 +08:00
|
|
|
// Store W to a Global Address.
|
|
|
|
def movwf : MOVWF_INSN<0, tglobaladdr, PIC16Store>;
|
|
|
|
|
|
|
|
// Store W to an External Symobol.
|
|
|
|
def movwf_1 : MOVWF_INSN<0, texternalsym, PIC16Store>;
|
2008-11-19 19:00:54 +08:00
|
|
|
|
2009-01-14 03:18:47 +08:00
|
|
|
// Store with InFlag and OutFlag
|
2009-03-10 18:35:34 +08:00
|
|
|
// This is same as movwf_1 but has a flag. A flag is required to
|
|
|
|
// order the stores while passing the params to function.
|
|
|
|
def movwf_2 : MOVWF_INSN<0, texternalsym, PIC16StWF>;
|
2009-01-14 03:18:47 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Indirect store. Matched via a DAG replacement pattern.
|
|
|
|
def store_indirect :
|
|
|
|
ByteFormat<0, (outs),
|
|
|
|
(ins GPR:$val, FSR16:$fsr, i8imm:$offset),
|
|
|
|
"movwi $offset[$fsr]",
|
|
|
|
[]>;
|
|
|
|
|
|
|
|
//----------------------------
|
|
|
|
// Load from memory
|
|
|
|
//----------------------------
|
|
|
|
// Direct load.
|
2009-03-10 18:35:34 +08:00
|
|
|
// Input Operands are: ptrlo = GA, offset = offset, ptrhi = banksel.
|
|
|
|
// Output: dst = W
|
2009-07-03 15:58:59 +08:00
|
|
|
let Defs = [STATUS], mayLoad = 1 in
|
2009-03-10 18:35:34 +08:00
|
|
|
class MOVF_INSN<bits<6> OpCode, SDNode OpNodeSrc, SDNode Op>:
|
2008-11-19 19:00:54 +08:00
|
|
|
ByteFormat<0, (outs GPR:$dst),
|
|
|
|
(ins i8imm:$offset, i8mem:$ptrlo, i8imm:$ptrhi),
|
|
|
|
"movf ${ptrlo} + ${offset}, W",
|
|
|
|
[(set GPR:$dst,
|
2009-03-10 18:35:34 +08:00
|
|
|
(Op OpNodeSrc:$ptrlo, (i8 imm:$ptrhi),
|
2008-11-19 19:00:54 +08:00
|
|
|
(i8 imm:$offset)))]>;
|
|
|
|
|
2009-03-10 18:35:34 +08:00
|
|
|
// Load from a GA.
|
|
|
|
def movf : MOVF_INSN<0, tglobaladdr, PIC16Load>;
|
2008-11-19 19:00:54 +08:00
|
|
|
|
2009-03-10 18:35:34 +08:00
|
|
|
// Load from an ES.
|
|
|
|
def movf_1 : MOVF_INSN<0, texternalsym, PIC16Load>;
|
2009-04-03 01:42:00 +08:00
|
|
|
def movf_1_1 : MOVF_INSN<0, texternalsym, PIC16LdArg>;
|
2009-01-14 03:18:47 +08:00
|
|
|
|
2009-03-10 18:35:34 +08:00
|
|
|
// Load with InFlag and OutFlag
|
|
|
|
// This is same as movf_1 but has a flag. A flag is required to
|
|
|
|
// order the loads while copying the return value of a function.
|
|
|
|
def movf_2 : MOVF_INSN<0, texternalsym, PIC16LdWF>;
|
2009-01-14 03:18:47 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Indirect load. Matched via a DAG replacement pattern.
|
|
|
|
def load_indirect :
|
|
|
|
ByteFormat<0, (outs GPR:$dst),
|
|
|
|
(ins FSR16:$fsr, i8imm:$offset),
|
|
|
|
"moviw $offset[$fsr]",
|
|
|
|
[]>;
|
|
|
|
|
2008-11-26 18:53:50 +08:00
|
|
|
//-------------------------
|
|
|
|
// Bitwise operations patterns
|
|
|
|
//--------------------------
|
2009-03-10 18:35:34 +08:00
|
|
|
// W = W op [F]
|
|
|
|
let Defs = [STATUS] in {
|
2009-01-14 03:18:47 +08:00
|
|
|
def OrFW : BinOpFW<0, "iorwf", or>;
|
|
|
|
def XOrFW : BinOpFW<0, "xorwf", xor>;
|
|
|
|
def AndFW : BinOpFW<0, "andwf", and>;
|
2008-11-26 18:53:50 +08:00
|
|
|
|
2009-03-10 18:35:34 +08:00
|
|
|
// F = W op [F]
|
2009-01-14 03:18:47 +08:00
|
|
|
def OrWF : BinOpWF<0, "iorwf", or>;
|
|
|
|
def XOrWF : BinOpWF<0, "xorwf", xor>;
|
|
|
|
def AndWF : BinOpWF<0, "andwf", and>;
|
2008-11-26 18:53:50 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
//-------------------------
|
|
|
|
// Various add/sub patterns.
|
|
|
|
//-------------------------
|
2008-11-26 18:53:50 +08:00
|
|
|
|
2009-03-10 18:35:34 +08:00
|
|
|
// W = W + [F]
|
2008-11-26 18:53:50 +08:00
|
|
|
def addfw_1: BinOpFW<0, "addwf", add>;
|
|
|
|
def addfw_2: BinOpFW<0, "addwf", addc>;
|
2009-03-10 18:35:34 +08:00
|
|
|
|
|
|
|
let Uses = [STATUS] in
|
2008-11-26 18:53:50 +08:00
|
|
|
def addfwc: BinOpFW<0, "addwfc", adde>; // With Carry.
|
2008-11-19 19:00:54 +08:00
|
|
|
|
2009-03-10 18:35:34 +08:00
|
|
|
// F = W + [F]
|
2008-11-26 18:53:50 +08:00
|
|
|
def addwf_1: BinOpWF<0, "addwf", add>;
|
|
|
|
def addwf_2: BinOpWF<0, "addwf", addc>;
|
2009-03-10 18:35:34 +08:00
|
|
|
let Uses = [STATUS] in
|
2008-11-26 18:53:50 +08:00
|
|
|
def addwfc: BinOpWF<0, "addwfc", adde>; // With Carry.
|
2009-03-10 18:35:34 +08:00
|
|
|
}
|
2008-11-19 19:00:54 +08:00
|
|
|
|
|
|
|
// W -= [F] ; load from F and sub the value from W.
|
2009-05-12 12:30:38 +08:00
|
|
|
let isTwoAddress = 1, mayLoad = 1 in
|
2008-11-19 19:00:54 +08:00
|
|
|
class SUBFW<bits<6> OpCode, string OpcStr, SDNode OpNode>:
|
|
|
|
ByteFormat<OpCode, (outs GPR:$dst),
|
|
|
|
(ins GPR:$src, i8imm:$offset, i8mem:$ptrlo, i8imm:$ptrhi),
|
|
|
|
!strconcat(OpcStr, " $ptrlo + $offset, W"),
|
|
|
|
[(set GPR:$dst, (OpNode (PIC16Load diraddr:$ptrlo,
|
|
|
|
(i8 imm:$ptrhi), (i8 imm:$offset)),
|
|
|
|
GPR:$src))]>;
|
2009-03-10 18:35:34 +08:00
|
|
|
let Defs = [STATUS] in {
|
2008-11-19 19:00:54 +08:00
|
|
|
def subfw_1: SUBFW<0, "subwf", sub>;
|
|
|
|
def subfw_2: SUBFW<0, "subwf", subc>;
|
2009-03-10 18:35:34 +08:00
|
|
|
|
|
|
|
let Uses = [STATUS] in
|
2008-11-19 19:00:54 +08:00
|
|
|
def subfwb: SUBFW<0, "subwfb", sube>; // With Borrow.
|
2009-03-10 18:35:34 +08:00
|
|
|
|
2009-01-14 03:18:47 +08:00
|
|
|
}
|
2009-07-08 13:40:05 +08:00
|
|
|
let Defs = [STATUS], isTerminator = 1 in
|
|
|
|
def subfw_cc: SUBFW<0, "subwf", PIC16Subcc>;
|
2008-11-19 19:00:54 +08:00
|
|
|
|
|
|
|
// [F] -= W ;
|
2009-05-12 12:30:38 +08:00
|
|
|
let mayStore = 1 in
|
2008-11-19 19:00:54 +08:00
|
|
|
class SUBWF<bits<6> OpCode, string OpcStr, SDNode OpNode>:
|
|
|
|
ByteFormat<OpCode, (outs),
|
|
|
|
(ins GPR:$src, i8imm:$offset, i8mem:$ptrlo, i8imm:$ptrhi),
|
|
|
|
!strconcat(OpcStr, " $ptrlo + $offset"),
|
|
|
|
[(PIC16Store (OpNode (PIC16Load diraddr:$ptrlo,
|
|
|
|
(i8 imm:$ptrhi), (i8 imm:$offset)),
|
|
|
|
GPR:$src), diraddr:$ptrlo,
|
|
|
|
(i8 imm:$ptrhi), (i8 imm:$offset))]>;
|
|
|
|
|
2009-03-10 18:35:34 +08:00
|
|
|
let Defs = [STATUS] in {
|
2008-11-19 19:00:54 +08:00
|
|
|
def subwf_1: SUBWF<0, "subwf", sub>;
|
|
|
|
def subwf_2: SUBWF<0, "subwf", subc>;
|
2009-03-10 18:35:34 +08:00
|
|
|
|
|
|
|
let Uses = [STATUS] in
|
|
|
|
def subwfb: SUBWF<0, "subwfb", sube>; // With Borrow.
|
|
|
|
|
2009-01-14 03:18:47 +08:00
|
|
|
def subwf_cc: SUBWF<0, "subwf", PIC16Subcc>;
|
2009-03-10 18:35:34 +08:00
|
|
|
}
|
2008-11-19 19:00:54 +08:00
|
|
|
|
|
|
|
// addlw
|
2009-03-10 18:35:34 +08:00
|
|
|
let Defs = [STATUS] in {
|
2009-01-14 03:18:47 +08:00
|
|
|
def addlw_1 : BinOpLW<0, "addlw", add>;
|
|
|
|
def addlw_2 : BinOpLW<0, "addlw", addc>;
|
2009-03-10 18:35:34 +08:00
|
|
|
|
|
|
|
let Uses = [STATUS] in
|
2009-01-14 03:18:47 +08:00
|
|
|
def addlwc : BinOpLW<0, "addlwc", adde>; // With Carry. (Assembler macro).
|
2008-11-19 19:00:54 +08:00
|
|
|
|
2009-01-14 03:18:47 +08:00
|
|
|
// bitwise operations involving a literal and w.
|
|
|
|
def andlw : BinOpLW<0, "andlw", and>;
|
|
|
|
def xorlw : BinOpLW<0, "xorlw", xor>;
|
|
|
|
def orlw : BinOpLW<0, "iorlw", or>;
|
|
|
|
}
|
2008-11-19 19:00:54 +08:00
|
|
|
|
|
|
|
// sublw
|
|
|
|
// W = C - W ; sub W from literal. (Without borrow).
|
2009-03-10 18:35:34 +08:00
|
|
|
let isTwoAddress = 1 in
|
2008-11-19 19:00:54 +08:00
|
|
|
class SUBLW<bits<6> opcode, SDNode OpNode> :
|
|
|
|
LiteralFormat<opcode, (outs GPR:$dst),
|
|
|
|
(ins GPR:$src, i8imm:$literal),
|
2009-01-14 03:18:47 +08:00
|
|
|
"sublw $literal",
|
2008-11-19 19:00:54 +08:00
|
|
|
[(set GPR:$dst, (OpNode (i8 imm:$literal), GPR:$src))]>;
|
|
|
|
|
2009-03-10 18:35:34 +08:00
|
|
|
let Defs = [STATUS] in {
|
2008-11-19 19:00:54 +08:00
|
|
|
def sublw_1 : SUBLW<0, sub>;
|
|
|
|
def sublw_2 : SUBLW<0, subc>;
|
2009-01-14 03:18:47 +08:00
|
|
|
}
|
2009-07-08 13:40:05 +08:00
|
|
|
let Defs = [STATUS], isTerminator = 1 in
|
|
|
|
def sublw_cc : SUBLW<0, PIC16Subcc>;
|
2009-01-14 03:18:47 +08:00
|
|
|
|
|
|
|
// Call instruction.
|
2009-04-10 23:10:14 +08:00
|
|
|
let isCall = 1,
|
|
|
|
Defs = [W, FSR0, FSR1] in {
|
2009-01-14 03:18:47 +08:00
|
|
|
def CALL: LiteralFormat<0x1, (outs), (ins i8imm:$func),
|
2009-04-22 20:02:36 +08:00
|
|
|
//"call ${func} + 2",
|
|
|
|
"call ${func}",
|
2009-01-14 03:18:47 +08:00
|
|
|
[(PIC16call diraddr:$func)]>;
|
|
|
|
}
|
|
|
|
|
2009-04-10 23:10:14 +08:00
|
|
|
let isCall = 1,
|
|
|
|
Defs = [W, FSR0, FSR1] in {
|
2009-04-08 13:38:48 +08:00
|
|
|
def CALL_1: LiteralFormat<0x1, (outs), (ins GPR:$func, PCLATHR:$pc),
|
|
|
|
"callw",
|
|
|
|
[(PIC16call (PIC16Connect GPR:$func, PCLATHR:$pc))]>;
|
|
|
|
}
|
|
|
|
|
2009-04-10 23:10:14 +08:00
|
|
|
let isCall = 1,
|
|
|
|
Defs = [FSR0, FSR1] in {
|
2009-04-08 13:38:48 +08:00
|
|
|
def CALLW: LiteralFormat<0x1, (outs GPR:$dest),
|
|
|
|
(ins GPR:$func, PCLATHR:$pc),
|
|
|
|
"callw",
|
|
|
|
[(set GPR:$dest, (PIC16callw (PIC16Connect GPR:$func, PCLATHR:$pc)))]>;
|
|
|
|
}
|
|
|
|
|
2009-05-29 01:32:56 +08:00
|
|
|
let Uses = [STATUS], isBranch = 1, isTerminator = 1, hasDelaySlot = 0 in
|
2009-01-14 03:18:47 +08:00
|
|
|
def pic16brcond: ControlFormat<0x0, (outs), (ins brtarget:$dst, CCOp:$cc),
|
|
|
|
"b$cc $dst",
|
|
|
|
[(PIC16Brcond bb:$dst, imm:$cc)]>;
|
|
|
|
|
|
|
|
// Unconditional branch.
|
2009-05-29 01:32:56 +08:00
|
|
|
let isBranch = 1, isTerminator = 1, hasDelaySlot = 0 in
|
2009-01-14 03:18:47 +08:00
|
|
|
def br_uncond: ControlFormat<0x0, (outs), (ins brtarget:$dst),
|
|
|
|
"goto $dst",
|
|
|
|
[(br bb:$dst)]>;
|
|
|
|
|
|
|
|
// SELECT_CC_* - Used to implement the SELECT_CC DAG operation. Expanded by the
|
|
|
|
// scheduler into a branch sequence.
|
|
|
|
let usesCustomDAGSchedInserter = 1 in { // Expanded by the scheduler.
|
|
|
|
def SELECT_CC_Int_ICC
|
|
|
|
: Pseudo<(outs GPR:$dst), (ins GPR:$T, GPR:$F, i8imm:$Cond),
|
|
|
|
"; SELECT_CC_Int_ICC PSEUDO!",
|
|
|
|
[(set GPR:$dst, (PIC16Selecticc GPR:$T, GPR:$F,
|
|
|
|
imm:$Cond))]>;
|
|
|
|
}
|
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
|
|
|
|
// Banksel.
|
|
|
|
def banksel :
|
2009-05-06 16:02:01 +08:00
|
|
|
Pseudo<(outs),
|
2008-11-19 19:00:54 +08:00
|
|
|
(ins i8mem:$ptr),
|
|
|
|
"banksel $ptr",
|
2009-05-06 16:02:01 +08:00
|
|
|
[]>;
|
|
|
|
|
|
|
|
def pagesel :
|
|
|
|
Pseudo<(outs),
|
|
|
|
(ins i8mem:$ptr),
|
|
|
|
"movlp $ptr",
|
|
|
|
[]>;
|
|
|
|
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Return insn.
|
2009-07-25 15:48:53 +08:00
|
|
|
let isTerminator = 1, isBarrier = 1, isReturn = 1 in
|
2008-11-19 19:00:54 +08:00
|
|
|
def Return :
|
|
|
|
ControlFormat<0, (outs), (ins), "return", [(ret)]>;
|
2009-04-08 13:38:48 +08:00
|
|
|
|
2008-05-13 17:02:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2008-11-19 19:00:54 +08:00
|
|
|
// PIC16 Replacment Patterns.
|
2008-05-13 17:02:57 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Identify an indirect store and select insns for it.
|
|
|
|
def : Pat<(PIC16Store GPR:$val, (MTLO GPR:$loaddr), (MTHI GPR:$hiaddr),
|
|
|
|
imm:$offset),
|
|
|
|
(store_indirect GPR:$val,
|
|
|
|
(set_fsrhi (set_fsrlo GPR:$loaddr), GPR:$hiaddr),
|
|
|
|
imm:$offset)>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2009-04-08 13:38:48 +08:00
|
|
|
def : Pat<(PIC16StWF GPR:$val, (MTLO GPR:$loaddr), (MTHI GPR:$hiaddr),
|
|
|
|
imm:$offset),
|
|
|
|
(store_indirect GPR:$val,
|
|
|
|
(set_fsrhi (set_fsrlo GPR:$loaddr), GPR:$hiaddr),
|
|
|
|
imm:$offset)>;
|
|
|
|
|
2008-11-19 19:00:54 +08:00
|
|
|
// Identify an indirect load and select insns for it.
|
|
|
|
def : Pat<(PIC16Load (MTLO GPR:$loaddr), (MTHI GPR:$hiaddr),
|
|
|
|
imm:$offset),
|
|
|
|
(load_indirect (set_fsrhi (set_fsrlo GPR:$loaddr), GPR:$hiaddr),
|
|
|
|
imm:$offset)>;
|
2008-05-13 17:02:57 +08:00
|
|
|
|
2009-04-08 13:38:48 +08:00
|
|
|
def : Pat<(PIC16LdWF (MTLO GPR:$loaddr), (MTHI GPR:$hiaddr),
|
|
|
|
imm:$offset),
|
|
|
|
(load_indirect (set_fsrhi (set_fsrlo GPR:$loaddr), GPR:$hiaddr),
|
|
|
|
imm:$offset)>;
|
|
|
|
|