blob: a0e7f7cb966a452ad18c48fed5ae288f0283eb6b [file] [log] [blame]
Sanjiv Gupta09bb4202008-05-13 09:02:57 +00001//===- PIC16InstrInfo.td - PIC16 Register defs ----------------*- tblgen-*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10//===----------------------------------------------------------------------===//
11// Instruction format superclass
12//===----------------------------------------------------------------------===//
13
14include "PIC16InstrFormats.td"
15
16//===----------------------------------------------------------------------===//
17// PIC16 profiles and nodes
18//===----------------------------------------------------------------------===//
19
20//===----------------------------------------------------------------------===//
21// PIC16 addressing mode.
22//===----------------------------------------------------------------------===//
23// It matches address of globals as well as the stack slots
24// that are created for locals and temporaries. This addressing mode
25// converts the GlobalAddress and FrameIndex nodes to TargetGlobalAddress
26// and TargetFrameIndex nodes.
27def diraddrmode : ComplexPattern<i16, 2, "SelectDirectAM", [frameindex], []>;
28def dirloadmode : ComplexPattern<i16, 2, "LoadNothing", [frameindex], []>;
29def indirloadmode : ComplexPattern<i16, 2, "LoadFSR", [frameindex], []>;
30
31
32// Address operand.
33def mem : Operand<i16> {
34 let PrintMethod = "printAddrModeOperand";
35 let MIOperandInfo = (ops i16imm, PTRRegs);
36}
37
38// Instruction operand types
39def simm8 : Operand<i8>;
40
41
42// These are target-independent nodes, but have target-specific formats.
43def SDT_PIC16CallSeq : SDTypeProfile<0, 1, [ SDTCisVT<0, i8> ]>;
44def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_PIC16CallSeq,
45 [SDNPHasChain, SDNPOutFlag]>;
46def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_PIC16CallSeq,
47 [SDNPHasChain, SDNPOutFlag]>;
48
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +000049def PIC16Wrapper : SDNode<"PIC16ISD::Wrapper", SDTIntUnaryOp>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000050
51// so_imm_XFORM - Return a so_imm value packed into the format described for
52// so_imm def below.
53def so_imm_XFORM : SDNodeXForm<imm, [{
Dan Gohmanfaeb4a32008-09-12 16:56:44 +000054 return CurDAG->getTargetConstant((int8_t)N->getZExtValue(), MVT::i32);
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000055}]>;
56
57def so_imm : Operand<i8>,
58 PatLeaf<(imm), [{}]> {
59 let PrintMethod = "printSOImmOperand";
60}
61
62
63
64// PIC16 Address Mode! SDNode frameindex could possibily be a match
65// since load and store instructions from stack used it.
66def addr : Operand<i16>;
67
68// Arithmetic 2 register operands
69class ArithI<bits<6> op, string instr_asm, SDNode OpNode,
70 Operand Od> :
71 LiteralFormat< op,
72 (outs CPURegs:$dst),
73 (ins CPURegs:$b, Od:$c),
74 !strconcat(instr_asm, " $c"),
75 [(set CPURegs:$dst, (OpNode CPURegs:$b, Od:$c))]>;
76
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +000077// Memory Load/Store.
Sanjiv Gupta09bb4202008-05-13 09:02:57 +000078class LoadDirect<bits<6> op, string instr_asm, PatFrag OpNode>:
79 ByteFormat< op,
80 (outs CPURegs:$dst),
81 (ins mem:$addr),
82 !strconcat(instr_asm, " $addr"),
83 [(set CPURegs:$dst, (OpNode diraddrmode:$addr))]>;
84
85class LoadInDirect<bits<6> op, string instr_asm, PatFrag OpNode>:
86 ByteFormat< op,
87 (outs PTRRegs:$dst),
88 (ins mem:$addr),
89 !strconcat(instr_asm, " $addr, $dst"),
90 [(set PTRRegs:$dst, (OpNode indirloadmode:$addr))]>;
91
92class StoreDirect<bits<6> op, string instr_asm, PatFrag OpNode>:
93 ByteFormat< op,
94 (outs),
95 (ins CPURegs:$src, mem:$addr),
96 !strconcat(instr_asm, " $addr"),
97 [(OpNode CPURegs:$src, diraddrmode:$addr)]>;
98
99class StoreInDirect<bits<6> op, string instr_asm, PatFrag OpNode>:
100 ByteFormat< op,
101 (outs),
102 (ins CPURegs:$src, PTRRegs:$fsr),
103 !strconcat(instr_asm, " $fsr"),
104 [(OpNode CPURegs:$src, PTRRegs:$fsr)]>;
105
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000106// Move.
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000107class MovLit<bits<6> op, string instr_asm>:
108 LiteralFormat< op,
109 (outs CPURegs:$dst),
110 (ins i8imm:$src),
111 !strconcat(instr_asm, " $src"),
112 [(set CPURegs:$dst, imm:$src)]>;
113
114
115// Arithmetic with memory store.
116// Arithmetic instrunctions involving W and memory location.
117// Since W is implicit, we only print the memory operand.
118class Arith1M<bits<6> op, string instr_asm, SDNode OpNode>:
119 ByteFormat< op,
120 (outs),
121 (ins CPURegs:$b, mem:$dst),
122 !strconcat(instr_asm, " $dst"),
123 [(store (OpNode (load diraddrmode:$dst), CPURegs:$b), diraddrmode:$dst),
124 (store (OpNode CPURegs:$b, (load diraddrmode:$dst)), diraddrmode:$dst)]>;
125
126// Arithmetic with memory load.
127// Arithmetic instrunctions involving W and memory location.
128// Since W is implicit, we only print the memory operand.
129class Arith1R<bits<6> op, string instr_asm, SDNode OpNode>:
130 ByteFormat< op,
131 (outs CPURegs:$dst),
132 (ins mem:$src1, CPURegs:$src2),
133 !strconcat(instr_asm, " $src1"),
134 [(set CPURegs:$dst, (OpNode (load diraddrmode:$src1), CPURegs:$src2))]>;
135
136// Arithmetic with memory load.
137// Arithmetic instrunctions involving W and memory location.
138// Since W is implicit, we only print the memory operand.
139class Arith2R<bits<6> op, string instr_asm, SDNode OpNode>:
140 ByteFormat< op,
141 (outs CPURegs:$dst),
142 (ins mem:$src1, CPURegs:$src2),
143 !strconcat(instr_asm, " $src1"),
144 [(set CPURegs:$dst, (OpNode CPURegs:$src2, (load diraddrmode:$src1)))]>;
145
146//===----------------------------------------------------------------------===//
147// Instruction definition
148//===----------------------------------------------------------------------===//
149
150//===----------------------------------------------------------------------===//
151// PIC16I Instructions
152//===----------------------------------------------------------------------===//
153
154// Arithmetic
155
156// ADDiu just accept 16-bit immediates but we handle this on Pat's.
157// immZExt32 is used here so it can match GlobalAddress immediates.
158// def ADDLW : ArithI<0x09, "addlw", add, so_imm>;
159
160let isReMaterializable = 1 in {
161def MOVLW : MovLit<0x24, "movlw">;
162}
163
164// Load/Store
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000165def LFSR1 : LoadInDirect <0x4, "lfsr", load>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000166
167let isReMaterializable = 1 in {
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000168def MOVF : LoadDirect <0x23, "movf", load>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000169}
170
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000171def MOVWF : StoreDirect <0x2b, "movwf", store>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000172
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000173def MOVFSRINC : StoreInDirect <0x5, "movfsrinc", store>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000174
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000175def RETURN : ControlFormat<0x03, (outs), (ins), "return", []>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000176
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000177def ADDWF : Arith1M<0x01, "addwf", add>;
178def ADDFW : Arith1R<0x02, "addfw", add>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000179
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000180def ADDWFE : Arith1M<0x03, "addwfe", adde>;
181def ADDFWE : Arith1R<0x04, "addfwe", adde>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000182
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000183def ADDWFC : Arith1M<0x05, "addwfc", addc>;
184def ADDFWC : Arith1R<0x06, "addfwc", addc>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000185
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000186def SUBWF : Arith1M<0x07, "subwf", sub>;
187def SUBFW : Arith1R<0x08, "subfw", sub>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000188
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000189def SUBWFE : Arith1M<0x09, "subwfe", sube>;
190def SUBFWE : Arith1R<0x0a, "subfwe", sube>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000191
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000192def SUBWFC : Arith1M<0x0b, "subwfc", subc>;
193def SUBFWC : Arith1R<0x0d, "subfwc", subc>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000194
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000195def SUBRFW : Arith2R<0x08, "subfw", sub>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000196
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000197def SUBRFWE : Arith2R<0x0a, "subfwe", sube>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000198
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000199def SUBRFWC : Arith2R<0x0d, "subfwc", subc>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000200
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000201def brtarget : Operand<OtherVT>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000202
203class UncondJump< bits<4> op, string instr_asm>:
204 BitFormat< op,
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000205 (outs),
206 (ins brtarget:$target),
207 !strconcat(instr_asm, " $target"),
208 [(br bb:$target)]>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000209
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000210def GOTO : UncondJump<0x1, "goto">;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000211
212class LogicM<bits<6> op, string instr_asm, SDNode OpNode> :
213 ByteFormat< op,
214 (outs),
215 (ins CPURegs:$b, mem:$dst),
216 !strconcat(instr_asm, " $dst"),
217 [(store (OpNode (load diraddrmode:$dst), CPURegs:$b), diraddrmode:$dst)]>;
218
219class LogicR<bits<6> op, string instr_asm, SDNode OpNode> :
220 ByteFormat< op,
221 (outs CPURegs:$dst),
222 (ins CPURegs:$b, mem:$c),
223 !strconcat(instr_asm, " $c"),
224 [(set CPURegs:$dst, (OpNode (load diraddrmode:$c), CPURegs:$b))]>;
225
226class LogicI<bits<6> op, string instr_asm, SDNode OpNode, Operand Od> :
227 LiteralFormat< op,
228 (outs CPURegs:$dst),
229 (ins CPURegs:$b, Od:$c),
230 !strconcat(instr_asm, " $c"),
231 [(set CPURegs:$dst, (OpNode CPURegs:$b, Od:$c ))]>;
232
233def XORWF : LogicM<0x1,"xorwf",xor>;
234def XORFW : LogicR<0x1,"xorfw",xor>;
235def XORLW : LogicI<0x1,"xorlw",xor, so_imm>;
236
237def ANDWF : LogicM<0x1,"andwf",and>;
238def ANDFW : LogicR<0x1,"andfw",and>;
239def ANDLW : LogicI<0x1,"andlw",and, so_imm>;
240
241def IORWF : LogicM<0x1,"iorwf",or>;
242def IORFW : LogicR<0x1,"iorfw",or>;
243def IORLW : LogicI<0x1,"iorlw",or, so_imm>;
244
245
246/* For comparison before branch */
247def SDT_PIC16Cmp : SDTypeProfile<1, 3, [SDTCisSameAs<0,1>]>;
248def SDTIntBinOpPIC16 : SDTypeProfile<1, 2, [SDTCisSameAs<0,1>,
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000249 SDTCisSameAs<1,2>, SDTCisInt<1>]>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000250
251def PIC16Cmp : SDNode<"PIC16ISD::Cmp",SDTIntBinOpPIC16, [SDNPOutFlag]>;
252def PIC16XORCC : SDNode<"PIC16ISD::XORCC",SDTIntBinOpPIC16, [SDNPOutFlag]>;
253def PIC16SUBCC : SDNode<"PIC16ISD::SUBCC",SDTIntBinOpPIC16, [SDNPOutFlag]>;
254
255def XORFWCC : LogicR<0x1,"xorfw",PIC16XORCC>;
256def XORLWCC : LogicI<0x1,"xorlw",PIC16XORCC, so_imm>;
257def SUBFWCC : Arith1R<0x1,"subfw",PIC16SUBCC>;
258def SUBLWCC : ArithI<0x1,"sublw",PIC16SUBCC, so_imm>;
259
260
261/* For branch conditions */
262def SDT_PIC16Branch : SDTypeProfile<0, 3, [SDTCisVT<0, OtherVT>,
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000263 SDTCisVT<1,i8>, SDTCisVT<2,i8>]>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000264
265def PIC16Branch : SDNode<"PIC16ISD::Branch",SDT_PIC16Branch,
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000266 [SDNPHasChain, SDNPInFlag]>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000267
268def PIC16BTFSS : SDNode<"PIC16ISD::BTFSS",SDT_PIC16Branch,
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000269 [SDNPHasChain, SDNPInFlag]>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000270
271def PIC16BTFSC : SDNode<"PIC16ISD::BTFSC",SDT_PIC16Branch,
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000272 [SDNPHasChain, SDNPInFlag]>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000273
274class InstrBitTestCC<bits<4> op, string instr_asm,SDNode OpNode>:
275 BitFormat< op,
Sanjiv Gupta1f7b12b2008-05-14 11:31:39 +0000276 (outs),
277 (ins brtarget:$target ,so_imm:$i, STATUSRegs:$s ),
278 !strconcat(instr_asm, " $s, $i, $target"),
279 [(OpNode bb:$target, so_imm:$i, STATUSRegs:$s )]>;
Sanjiv Gupta09bb4202008-05-13 09:02:57 +0000280
281def BTFSS : InstrBitTestCC<0x1,"btfss",PIC16BTFSS>;
282def BTFSC : InstrBitTestCC<0x1,"btfsc",PIC16BTFSC>;
283
284
285//===----------------------------------------------------------------------===//
286// Pseudo instructions
287//===----------------------------------------------------------------------===//
288
289let Defs = [STKPTR], Uses = [STKPTR] in {
290def ADJCALLSTACKDOWN : Pseudo<255, (outs), (ins i8imm:$amt),
291 "!ADJCALLSTACKDOWN $amt",
292 [(callseq_start imm:$amt)]>;
293def ADJCALLSTACKUP : Pseudo<254, (outs), (ins i8imm:$amt),
294 "!ADJCALLSTACKUP $amt",
295 [(callseq_end imm:$amt)]>;
296}
297
298
299//===----------------------------------------------------------------------===//
300// Arbitrary patterns that map to one or more instructions
301//===----------------------------------------------------------------------===//
302def : Pat<(ret), (RETURN)>;