Add code for save/restore of callee-saved registers
[oota-llvm.git] / lib / Target / MSP430 / MSP430InstrInfo.td
1 //===- MSP430InstrInfo.td - MSP430 Instruction 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 // This file describes the MSP430 instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 include "MSP430InstrFormats.td"
15
16 //===----------------------------------------------------------------------===//
17 // Type Constraints.
18 //===----------------------------------------------------------------------===//
19 class SDTCisI8<int OpNum> : SDTCisVT<OpNum, i8>;
20 class SDTCisI16<int OpNum> : SDTCisVT<OpNum, i16>;
21
22 //===----------------------------------------------------------------------===//
23 // Type Profiles.
24 //===----------------------------------------------------------------------===//
25 def SDT_MSP430Call         : SDTypeProfile<0, -1, [SDTCisVT<0, iPTR>]>;
26 def SDT_MSP430CallSeqStart : SDCallSeqStart<[SDTCisVT<0, i16>]>;
27 def SDT_MSP430CallSeqEnd   : SDCallSeqEnd<[SDTCisVT<0, i16>, SDTCisVT<1, i16>]>;
28 def SDT_MSP430Wrapper      : SDTypeProfile<1, 1, [SDTCisSameAs<0, 1>, SDTCisPtrTy<0>]>;
29
30 //===----------------------------------------------------------------------===//
31 // MSP430 Specific Node Definitions.
32 //===----------------------------------------------------------------------===//
33 def MSP430retflag : SDNode<"MSP430ISD::RET_FLAG", SDTNone,
34                      [SDNPHasChain, SDNPOptInFlag]>;
35
36 def MSP430rra     : SDNode<"MSP430ISD::RRA", SDTIntUnaryOp, []>;
37
38 def MSP430call    : SDNode<"MSP430ISD::CALL", SDT_MSP430Call,
39                      [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag]>;
40 def MSP430callseq_start :
41                  SDNode<"ISD::CALLSEQ_START", SDT_MSP430CallSeqStart,
42                         [SDNPHasChain, SDNPOutFlag]>;
43 def MSP430callseq_end :
44                  SDNode<"ISD::CALLSEQ_END",   SDT_MSP430CallSeqEnd,
45                         [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
46 def MSP430Wrapper : SDNode<"MSP430ISD::Wrapper",     SDT_MSP430Wrapper>;
47
48 //===----------------------------------------------------------------------===//
49 // MSP430 Operand Definitions.
50 //===----------------------------------------------------------------------===//
51
52 // Address operands
53 def memsrc : Operand<i16> {
54   let PrintMethod = "printSrcMemOperand";
55   let MIOperandInfo = (ops GR16, i16imm);
56 }
57
58 def memdst : Operand<i16> {
59   let PrintMethod = "printSrcMemOperand";
60   let MIOperandInfo = (ops GR16, i16imm);
61 }
62
63 //===----------------------------------------------------------------------===//
64 // MSP430 Complex Pattern Definitions.
65 //===----------------------------------------------------------------------===//
66
67 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [], []>;
68
69 //===----------------------------------------------------------------------===//
70 // Pattern Fragments
71 def zextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
72 def  extloadi16i8 : PatFrag<(ops node:$ptr), (i16 ( extloadi8 node:$ptr))>;
73
74 //===----------------------------------------------------------------------===//
75 // Instruction list..
76
77 // ADJCALLSTACKDOWN/UP implicitly use/def SP because they may be expanded into
78 // a stack adjustment and the codegen must know that they may modify the stack
79 // pointer before prolog-epilog rewriting occurs.
80 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
81 // sub / add which can clobber SRW.
82 let Defs = [SPW, SRW], Uses = [SPW] in {
83 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i16imm:$amt),
84                               "#ADJCALLSTACKDOWN",
85                               [(MSP430callseq_start timm:$amt)]>;
86 def ADJCALLSTACKUP   : Pseudo<(outs), (ins i16imm:$amt1, i16imm:$amt2),
87                               "#ADJCALLSTACKUP",
88                               [(MSP430callseq_end timm:$amt1, timm:$amt2)]>;
89 }
90
91
92 let neverHasSideEffects = 1 in
93 def NOP : Pseudo<(outs), (ins), "nop", []>;
94
95 // FIXME: Provide proper encoding!
96 let isReturn = 1, isTerminator = 1 in {
97   def RET : Pseudo<(outs), (ins), "ret", [(MSP430retflag)]>;
98 }
99
100 //===----------------------------------------------------------------------===//
101 //  Call Instructions...
102 //
103 let isCall = 1 in
104   // All calls clobber the non-callee saved registers. SPW is marked as
105   // a use to prevent stack-pointer assignments that appear immediately
106   // before calls from potentially appearing dead. Uses for argument
107   // registers are added manually.
108   let Defs = [R12W, R13W, R14W, R15W, SRW],
109       Uses = [SPW] in {
110     def CALLi     : Pseudo<(outs), (ins i16imm:$dst, variable_ops),
111                            "call\t${dst:call}", [(MSP430call imm:$dst)]>;
112     def CALLr     : Pseudo<(outs), (ins GR16:$dst, variable_ops),
113                            "call\t$dst", [(MSP430call GR16:$dst)]>;
114     def CALLm     : Pseudo<(outs), (ins memsrc:$dst, variable_ops),
115                            "call\t${dst:mem}", [(MSP430call (load addr:$dst))]>;
116   }
117
118
119 //===----------------------------------------------------------------------===//
120 //  Miscellaneous Instructions...
121 //
122 let Defs = [SPW], Uses = [SPW], neverHasSideEffects=1 in {
123 let mayLoad = 1 in
124 def POP16r   : Pseudo<(outs GR16:$reg), (ins), "pop.w\t$reg", []>;
125
126 let mayStore = 1 in
127 def PUSH16r  : Pseudo<(outs), (ins GR16:$reg), "push.w\t$reg",[]>;
128 }
129
130 //===----------------------------------------------------------------------===//
131 // Move Instructions
132
133 // FIXME: Provide proper encoding!
134 let neverHasSideEffects = 1 in {
135 def MOV8rr  : Pseudo<(outs GR8:$dst), (ins GR8:$src),
136                      "mov.b\t{$src, $dst|$dst, $src}",
137                      []>;
138 def MOV16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src),
139                      "mov.w\t{$src, $dst|$dst, $src}",
140                      []>;
141 }
142
143 // FIXME: Provide proper encoding!
144 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
145 def MOV8ri  : Pseudo<(outs GR8:$dst), (ins i8imm:$src),
146                      "mov.b\t{$src, $dst|$dst, $src}",
147                      [(set GR8:$dst, imm:$src)]>;
148 def MOV16ri : Pseudo<(outs GR16:$dst), (ins i16imm:$src),
149                      "mov.w\t{$src, $dst|$dst, $src}",
150                      [(set GR16:$dst, imm:$src)]>;
151 }
152
153 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in {
154 def MOV8rm  : Pseudo<(outs GR8:$dst), (ins memsrc:$src),
155                 "mov.b\t{$src, $dst|$dst, $src}",
156                 [(set GR8:$dst, (load addr:$src))]>;
157 def MOV16rm : Pseudo<(outs GR16:$dst), (ins memsrc:$src),
158                 "mov.w\t{$src, $dst|$dst, $src}",
159                 [(set GR16:$dst, (load addr:$src))]>;
160 }
161
162 def MOVZX16rr8 : Pseudo<(outs GR16:$dst), (ins GR8:$src),
163                 "mov.b\t{$src, $dst|$dst, $src}",
164                 [(set GR16:$dst, (zext GR8:$src))]>;
165 def MOVZX16rm8 : Pseudo<(outs GR16:$dst), (ins memsrc:$src),
166                 "mov.b\t{$src, $dst|$dst, $src}",
167                 [(set GR16:$dst, (zextloadi16i8 addr:$src))]>;
168
169 def MOV8mi  : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
170                 "mov.b\t{$src, $dst|$dst, $src}",
171                 [(store (i8 imm:$src), addr:$dst)]>;
172 def MOV16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
173                 "mov.w\t{$src, $dst|$dst, $src}",
174                 [(store (i16 imm:$src), addr:$dst)]>;
175
176 def MOV8mr  : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
177                 "mov.b\t{$src, $dst|$dst, $src}",
178                 [(store GR8:$src, addr:$dst)]>;
179 def MOV16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
180                 "mov.w\t{$src, $dst|$dst, $src}",
181                 [(store GR16:$src, addr:$dst)]>;
182
183 //===----------------------------------------------------------------------===//
184 // Arithmetic Instructions
185
186 let isTwoAddress = 1 in {
187
188 let Defs = [SRW] in {
189
190 let isCommutable = 1 in { // X = ADD Y, Z  == X = ADD Z, Y
191 // FIXME: Provide proper encoding!
192 def ADD8rr  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
193                      "add.b\t{$src2, $dst|$dst, $src2}",
194                      [(set GR8:$dst, (add GR8:$src1, GR8:$src2)),
195                       (implicit SRW)]>;
196 def ADD16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
197                      "add.w\t{$src2, $dst|$dst, $src2}",
198                      [(set GR16:$dst, (add GR16:$src1, GR16:$src2)),
199                       (implicit SRW)]>;
200 }
201
202 def ADD8rm  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
203                      "add.b\t{$src2, $dst|$dst, $src2}",
204                      [(set GR8:$dst, (add GR8:$src1, (load addr:$src2))),
205                       (implicit SRW)]>;
206 def ADD16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
207                      "add.w\t{$src2, $dst|$dst, $src2}",
208                      [(set GR16:$dst, (add GR16:$src1, (load addr:$src2))),
209                       (implicit SRW)]>;
210
211 def ADD8ri  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
212                      "add.b\t{$src2, $dst|$dst, $src2}",
213                      [(set GR8:$dst, (add GR8:$src1, imm:$src2)),
214                       (implicit SRW)]>;
215 def ADD16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
216                      "add.w\t{$src2, $dst|$dst, $src2}",
217                      [(set GR16:$dst, (add GR16:$src1, imm:$src2)),
218                       (implicit SRW)]>;
219
220 let isTwoAddress = 0 in {
221 def ADD8mr  : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
222                 "add.b\t{$src, $dst|$dst, $src}",
223                 [(store (add (load addr:$dst), GR8:$src), addr:$dst),
224                  (implicit SRW)]>;
225 def ADD16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
226                 "add.w\t{$src, $dst|$dst, $src}",
227                 [(store (add (load addr:$dst), GR16:$src), addr:$dst),
228                  (implicit SRW)]>;
229
230 def ADD8mi  : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
231                 "add.b\t{$src, $dst|$dst, $src}",
232                 [(store (add (load addr:$dst), (i8 imm:$src)), addr:$dst),
233                  (implicit SRW)]>;
234 def ADD16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
235                 "add.w\t{$src, $dst|$dst, $src}",
236                 [(store (add (load addr:$dst), (i16 imm:$src)), addr:$dst),
237                  (implicit SRW)]>;
238
239 def ADD8mm  : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
240                 "add.b\t{$src, $dst|$dst, $src}",
241                 [(store (add (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
242                  (implicit SRW)]>;
243 def ADD16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
244                 "add.w\t{$src, $dst|$dst, $src}",
245                 [(store (add (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
246                  (implicit SRW)]>;
247 }
248
249 let Uses = [SRW] in {
250
251 let isCommutable = 1 in { // X = ADDC Y, Z  == X = ADDC Z, Y
252 def ADC8rr  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
253                      "addc.b\t{$src2, $dst|$dst, $src2}",
254                      [(set GR8:$dst, (adde GR8:$src1, GR8:$src2)),
255                       (implicit SRW)]>;
256 def ADC16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
257                      "addc.w\t{$src2, $dst|$dst, $src2}",
258                      [(set GR16:$dst, (adde GR16:$src1, GR16:$src2)),
259                       (implicit SRW)]>;
260 } // isCommutable
261
262 def ADC8ri  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
263                      "addc.b\t{$src2, $dst|$dst, $src2}",
264                      [(set GR8:$dst, (adde GR8:$src1, imm:$src2)),
265                       (implicit SRW)]>;
266 def ADC16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
267                      "addc.w\t{$src2, $dst|$dst, $src2}",
268                      [(set GR16:$dst, (adde GR16:$src1, imm:$src2)),
269                       (implicit SRW)]>;
270
271 def ADC8rm  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
272                      "addc.b\t{$src2, $dst|$dst, $src2}",
273                      [(set GR8:$dst, (adde GR8:$src1, (load addr:$src2))),
274                       (implicit SRW)]>;
275 def ADC16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
276                      "addc.w\t{$src2, $dst|$dst, $src2}",
277                      [(set GR16:$dst, (adde GR16:$src1, (load addr:$src2))),
278                       (implicit SRW)]>;
279
280 let isTwoAddress = 0 in {
281 def ADC8mr  : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
282                 "addc.b\t{$src, $dst|$dst, $src}",
283                 [(store (adde (load addr:$dst), GR8:$src), addr:$dst),
284                  (implicit SRW)]>;
285 def ADC16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
286                 "addc.w\t{$src, $dst|$dst, $src}",
287                 [(store (adde (load addr:$dst), GR16:$src), addr:$dst),
288                  (implicit SRW)]>;
289
290 def ADC8mi  : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
291                 "addc.b\t{$src, $dst|$dst, $src}",
292                 [(store (adde (load addr:$dst), (i8 imm:$src)), addr:$dst),
293                  (implicit SRW)]>;
294 def ADC16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
295                 "addc.w\t{$src, $dst|$dst, $src}",
296                 [(store (adde (load addr:$dst), (i16 imm:$src)), addr:$dst),
297                  (implicit SRW)]>;
298
299 def ADC8mm  : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
300                 "addc.b\t{$src, $dst|$dst, $src}",
301                 [(store (adde (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
302                  (implicit SRW)]>;
303 def ADC16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
304                 "addc.w\t{$src, $dst|$dst, $src}",
305                 [(store (adde (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
306                  (implicit SRW)]>;
307 }
308
309 } // Uses = [SRW]
310
311 let isCommutable = 1 in { // X = AND Y, Z  == X = AND Z, Y
312 def AND8rr  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
313                      "and.b\t{$src2, $dst|$dst, $src2}",
314                      [(set GR8:$dst, (and GR8:$src1, GR8:$src2)),
315                       (implicit SRW)]>;
316 def AND16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
317                      "and.w\t{$src2, $dst|$dst, $src2}",
318                      [(set GR16:$dst, (and GR16:$src1, GR16:$src2)),
319                       (implicit SRW)]>;
320 }
321
322 def AND8ri  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
323                      "and.b\t{$src2, $dst|$dst, $src2}",
324                      [(set GR8:$dst, (and GR8:$src1, imm:$src2)),
325                       (implicit SRW)]>;
326 def AND16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
327                      "and.w\t{$src2, $dst|$dst, $src2}",
328                      [(set GR16:$dst, (and GR16:$src1, imm:$src2)),
329                       (implicit SRW)]>;
330
331 def AND8rm  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
332                      "and.b\t{$src2, $dst|$dst, $src2}",
333                      [(set GR8:$dst, (and GR8:$src1, (load addr:$src2))),
334                       (implicit SRW)]>;
335 def AND16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
336                      "and.w\t{$src2, $dst|$dst, $src2}",
337                      [(set GR16:$dst, (and GR16:$src1, (load addr:$src2))),
338                       (implicit SRW)]>;
339
340 let isTwoAddress = 0 in {
341 def AND8mr  : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
342                 "and.b\t{$src, $dst|$dst, $src}",
343                 [(store (and (load addr:$dst), GR8:$src), addr:$dst),
344                  (implicit SRW)]>;
345 def AND16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
346                 "and.w\t{$src, $dst|$dst, $src}",
347                 [(store (and (load addr:$dst), GR16:$src), addr:$dst),
348                  (implicit SRW)]>;
349
350 def AND8mi  : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
351                 "and.b\t{$src, $dst|$dst, $src}",
352                 [(store (and (load addr:$dst), (i8 imm:$src)), addr:$dst),
353                  (implicit SRW)]>;
354 def AND16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
355                 "and.w\t{$src, $dst|$dst, $src}",
356                 [(store (and (load addr:$dst), (i16 imm:$src)), addr:$dst),
357                  (implicit SRW)]>;
358
359 def AND8mm  : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
360                 "and.b\t{$src, $dst|$dst, $src}",
361                 [(store (and (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
362                  (implicit SRW)]>;
363 def AND16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
364                 "and.w\t{$src, $dst|$dst, $src}",
365                 [(store (and (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
366                  (implicit SRW)]>;
367 }
368
369
370 let isCommutable = 1 in { // X = XOR Y, Z  == X = XOR Z, Y
371 def XOR8rr  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
372                      "xor.b\t{$src2, $dst|$dst, $src2}",
373                      [(set GR8:$dst, (xor GR8:$src1, GR8:$src2)),
374                       (implicit SRW)]>;
375 def XOR16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
376                      "xor.w\t{$src2, $dst|$dst, $src2}",
377                      [(set GR16:$dst, (xor GR16:$src1, GR16:$src2)),
378                       (implicit SRW)]>;
379 }
380
381 def XOR8ri  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
382                      "xor.b\t{$src2, $dst|$dst, $src2}",
383                      [(set GR8:$dst, (xor GR8:$src1, imm:$src2)),
384                       (implicit SRW)]>;
385 def XOR16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
386                      "xor.w\t{$src2, $dst|$dst, $src2}",
387                      [(set GR16:$dst, (xor GR16:$src1, imm:$src2)),
388                       (implicit SRW)]>;
389
390 def XOR8rm  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
391                      "xor.b\t{$src2, $dst|$dst, $src2}",
392                      [(set GR8:$dst, (xor GR8:$src1, (load addr:$src2))),
393                       (implicit SRW)]>;
394 def XOR16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
395                      "xor.w\t{$src2, $dst|$dst, $src2}",
396                      [(set GR16:$dst, (xor GR16:$src1, (load addr:$src2))),
397                       (implicit SRW)]>;
398
399 let isTwoAddress = 0 in {
400 def XOR8mr  : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
401                 "xor.b\t{$src, $dst|$dst, $src}",
402                 [(store (xor (load addr:$dst), GR8:$src), addr:$dst),
403                  (implicit SRW)]>;
404 def XOR16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
405                 "xor.w\t{$src, $dst|$dst, $src}",
406                 [(store (xor (load addr:$dst), GR16:$src), addr:$dst),
407                  (implicit SRW)]>;
408
409 def XOR8mi  : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
410                 "xor.b\t{$src, $dst|$dst, $src}",
411                 [(store (xor (load addr:$dst), (i8 imm:$src)), addr:$dst),
412                  (implicit SRW)]>;
413 def XOR16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
414                 "xor.w\t{$src, $dst|$dst, $src}",
415                 [(store (xor (load addr:$dst), (i16 imm:$src)), addr:$dst),
416                  (implicit SRW)]>;
417
418 def XOR8mm  : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
419                 "xor.b\t{$src, $dst|$dst, $src}",
420                 [(store (xor (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
421                  (implicit SRW)]>;
422 def XOR16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
423                 "xor.w\t{$src, $dst|$dst, $src}",
424                 [(store (xor (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
425                  (implicit SRW)]>;
426 }
427
428
429 def SUB8rr  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
430                      "sub.b\t{$src2, $dst|$dst, $src2}",
431                      [(set GR8:$dst, (sub GR8:$src1, GR8:$src2)),
432                       (implicit SRW)]>;
433 def SUB16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
434                      "sub.w\t{$src2, $dst|$dst, $src2}",
435                      [(set GR16:$dst, (sub GR16:$src1, GR16:$src2)),
436                       (implicit SRW)]>;
437
438 def SUB8ri  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
439                      "sub.b\t{$src2, $dst|$dst, $src2}",
440                      [(set GR8:$dst, (sub GR8:$src1, imm:$src2)),
441                       (implicit SRW)]>;
442 def SUB16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
443                      "sub.w\t{$src2, $dst|$dst, $src2}",
444                      [(set GR16:$dst, (sub GR16:$src1, imm:$src2)),
445                       (implicit SRW)]>;
446
447 def SUB8rm  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
448                      "sub.b\t{$src2, $dst|$dst, $src2}",
449                      [(set GR8:$dst, (sub GR8:$src1, (load addr:$src2))),
450                       (implicit SRW)]>;
451 def SUB16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
452                      "sub.w\t{$src2, $dst|$dst, $src2}",
453                      [(set GR16:$dst, (sub GR16:$src1, (load addr:$src2))),
454                       (implicit SRW)]>;
455
456 let isTwoAddress = 0 in {
457 def SUB8mr  : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
458                 "sub.b\t{$src, $dst|$dst, $src}",
459                 [(store (sub (load addr:$dst), GR8:$src), addr:$dst),
460                  (implicit SRW)]>;
461 def SUB16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
462                 "sub.w\t{$src, $dst|$dst, $src}",
463                 [(store (sub (load addr:$dst), GR16:$src), addr:$dst),
464                  (implicit SRW)]>;
465
466 def SUB8mi  : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
467                 "sub.b\t{$src, $dst|$dst, $src}",
468                 [(store (sub (load addr:$dst), (i8 imm:$src)), addr:$dst),
469                  (implicit SRW)]>;
470 def SUB16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
471                 "sub.w\t{$src, $dst|$dst, $src}",
472                 [(store (sub (load addr:$dst), (i16 imm:$src)), addr:$dst),
473                  (implicit SRW)]>;
474
475 def SUB8mm  : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
476                 "sub.b\t{$src, $dst|$dst, $src}",
477                 [(store (sub (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
478                  (implicit SRW)]>;
479 def SUB16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
480                 "sub.w\t{$src, $dst|$dst, $src}",
481                 [(store (sub (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
482                  (implicit SRW)]>;
483 }
484
485 let Uses = [SRW] in {
486 def SBC8rr  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
487                      "subc.b\t{$src2, $dst|$dst, $src2}",
488                      [(set GR8:$dst, (sube GR8:$src1, GR8:$src2)),
489                       (implicit SRW)]>;
490 def SBC16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
491                      "subc.w\t{$src2, $dst|$dst, $src2}",
492                      [(set GR16:$dst, (sube GR16:$src1, GR16:$src2)),
493                       (implicit SRW)]>;
494
495 def SBC8ri  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
496                      "subc.b\t{$src2, $dst|$dst, $src2}",
497                      [(set GR8:$dst, (sube GR8:$src1, imm:$src2)),
498                       (implicit SRW)]>;
499 def SBC16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
500                      "subc.w\t{$src2, $dst|$dst, $src2}",
501                      [(set GR16:$dst, (sube GR16:$src1, imm:$src2)),
502                       (implicit SRW)]>;
503
504 def SBC8rm  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
505                      "subc.b\t{$src2, $dst|$dst, $src2}",
506                      [(set GR8:$dst, (sube GR8:$src1, (load addr:$src2))),
507                       (implicit SRW)]>;
508 def SBC16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
509                      "subc.w\t{$src2, $dst|$dst, $src2}",
510                      [(set GR16:$dst, (sube GR16:$src1, (load addr:$src2))),
511                       (implicit SRW)]>;
512
513 let isTwoAddress = 0 in {
514 def SBC8mr  : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
515                 "subc.b\t{$src, $dst|$dst, $src}",
516                 [(store (sube (load addr:$dst), GR8:$src), addr:$dst),
517                  (implicit SRW)]>;
518 def SBC16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
519                 "subc.w\t{$src, $dst|$dst, $src}",
520                 [(store (sube (load addr:$dst), GR16:$src), addr:$dst),
521                  (implicit SRW)]>;
522
523 def SBC8mi  : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
524                 "subc.b\t{$src, $dst|$dst, $src}",
525                 [(store (sube (load addr:$dst), (i8 imm:$src)), addr:$dst),
526                  (implicit SRW)]>;
527 def SBC16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
528                 "subc.w\t{$src, $dst|$dst, $src}",
529                 [(store (sube (load addr:$dst), (i16 imm:$src)), addr:$dst),
530                  (implicit SRW)]>;
531
532 def SBC8mm  : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
533                 "subc.b\t{$src, $dst|$dst, $src}",
534                 [(store (sube (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
535                  (implicit SRW)]>;
536 def SBC16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
537                 "subc.w\t{$src, $dst|$dst, $src}",
538                 [(store (sube (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
539                  (implicit SRW)]>;
540 }
541
542 } // Uses = [SRW]
543
544 // FIXME: Provide proper encoding!
545 def SAR16r1 : Pseudo<(outs GR16:$dst), (ins GR16:$src),
546                      "rra.w\t$dst",
547                      [(set GR16:$dst, (MSP430rra GR16:$src)),
548                       (implicit SRW)]>;
549
550 def SEXT16r : Pseudo<(outs GR16:$dst), (ins GR16:$src),
551                      "sxt\t$dst",
552                      [(set GR16:$dst, (sext_inreg GR16:$src, i8)),
553                       (implicit SRW)]>;
554
555 //def SEXT16r : Pseudo<(outs GR16:$dst), (ins GR16:$src),
556 //                     "sxt\t$dst",
557 //                     [(set GR16:$dst, (sext_inreg GR16:$src, i8)),
558 //                      (implicit SRW)]>;
559
560 } // Defs = [SRW]
561
562 let isCommutable = 1 in { // X = OR Y, Z  == X = OR Z, Y
563 def OR8rr  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
564                     "bis.b\t{$src2, $dst|$dst, $src2}",
565                     [(set GR8:$dst, (or GR8:$src1, GR8:$src2))]>;
566 def OR16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
567                     "bis.w\t{$src2, $dst|$dst, $src2}",
568                     [(set GR16:$dst, (or GR16:$src1, GR16:$src2))]>;
569 }
570
571 def OR8ri  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
572                     "bis.b\t{$src2, $dst|$dst, $src2}",
573                     [(set GR8:$dst, (or GR8:$src1, imm:$src2))]>;
574 def OR16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
575                     "bis.w\t{$src2, $dst|$dst, $src2}",
576                     [(set GR16:$dst, (or GR16:$src1, imm:$src2))]>;
577
578 def OR8rm  : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
579                     "bis.b\t{$src2, $dst|$dst, $src2}",
580                     [(set GR8:$dst, (or GR8:$src1, (load addr:$src2)))]>;
581 def OR16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
582                     "bis.w\t{$src2, $dst|$dst, $src2}",
583                     [(set GR16:$dst, (or GR16:$src1, (load addr:$src2)))]>;
584
585 let isTwoAddress = 0 in {
586 def OR8mr  : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
587                 "bis.b\t{$src, $dst|$dst, $src}",
588                 [(store (or (load addr:$dst), GR8:$src), addr:$dst),
589                  (implicit SRW)]>;
590 def OR16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
591                 "bis.w\t{$src, $dst|$dst, $src}",
592                 [(store (or (load addr:$dst), GR16:$src), addr:$dst),
593                  (implicit SRW)]>;
594
595 def OR8mi  : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
596                 "bis.b\t{$src, $dst|$dst, $src}",
597                 [(store (or (load addr:$dst), (i8 imm:$src)), addr:$dst),
598                  (implicit SRW)]>;
599 def OR16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
600                 "bis.w\t{$src, $dst|$dst, $src}",
601                 [(store (or (load addr:$dst), (i16 imm:$src)), addr:$dst),
602                  (implicit SRW)]>;
603
604 def OR8mm  : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
605                 "bis.b\t{$src, $dst|$dst, $src}",
606                 [(store (or (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
607                  (implicit SRW)]>;
608 def OR16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
609                 "bis.w\t{$src, $dst|$dst, $src}",
610                 [(store (or (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
611                  (implicit SRW)]>;
612 }
613
614 } // isTwoAddress = 1
615
616 //===----------------------------------------------------------------------===//
617 // Non-Instruction Patterns
618
619 // extload
620 def : Pat<(extloadi16i8 addr:$src), (MOVZX16rm8 addr:$src)>;
621
622 // truncs
623 def : Pat<(i8 (trunc GR16:$src)),
624           (EXTRACT_SUBREG GR16:$src, subreg_8bit)>;
625
626 // GlobalAddress
627 def : Pat<(i16 (MSP430Wrapper tglobaladdr:$dst)), (MOV16ri tglobaladdr:$dst)>;
628
629 def : Pat<(add GR16:$src1, (MSP430Wrapper tglobaladdr :$src2)),
630           (ADD16ri GR16:$src1, tglobaladdr:$src2)>;
631
632 // calls
633 def : Pat<(MSP430call (i16 tglobaladdr:$dst)),
634           (CALLi tglobaladdr:$dst)>;