1 //===- MSP430InstrInfo.td - MSP430 Instruction defs -----------*- tblgen-*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the MSP430 instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
14 include "MSP430InstrFormats.td"
16 //===----------------------------------------------------------------------===//
18 //===----------------------------------------------------------------------===//
19 class SDTCisI8<int OpNum> : SDTCisVT<OpNum, i8>;
20 class SDTCisI16<int OpNum> : SDTCisVT<OpNum, i16>;
22 //===----------------------------------------------------------------------===//
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 def SDT_MSP430SetCC : SDTypeProfile<1, 2, [SDTCisVT<0, i8>,
30 SDTCisVT<1, i8>, SDTCisVT<2, i16>]>;
31 def SDT_MSP430Cmp : SDTypeProfile<0, 2, [SDTCisSameAs<0, 1>]>;
32 def SDT_MSP430BrCond : SDTypeProfile<0, 3, [SDTCisVT<0, OtherVT>,
33 SDTCisVT<1, i8>, SDTCisVT<2, i16>]>;
34 def SDT_MSP430Select : SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>,
35 SDTCisVT<3, i8>, SDTCisVT<4, i16>]>;
37 //===----------------------------------------------------------------------===//
38 // MSP430 Specific Node Definitions.
39 //===----------------------------------------------------------------------===//
40 def MSP430retflag : SDNode<"MSP430ISD::RET_FLAG", SDTNone,
41 [SDNPHasChain, SDNPOptInFlag]>;
43 def MSP430rra : SDNode<"MSP430ISD::RRA", SDTIntUnaryOp, []>;
44 def MSP430rla : SDNode<"MSP430ISD::RLA", SDTIntUnaryOp, []>;
46 def MSP430call : SDNode<"MSP430ISD::CALL", SDT_MSP430Call,
47 [SDNPHasChain, SDNPOutFlag, SDNPOptInFlag]>;
48 def MSP430callseq_start :
49 SDNode<"ISD::CALLSEQ_START", SDT_MSP430CallSeqStart,
50 [SDNPHasChain, SDNPOutFlag]>;
51 def MSP430callseq_end :
52 SDNode<"ISD::CALLSEQ_END", SDT_MSP430CallSeqEnd,
53 [SDNPHasChain, SDNPOptInFlag, SDNPOutFlag]>;
54 def MSP430Wrapper : SDNode<"MSP430ISD::Wrapper", SDT_MSP430Wrapper>;
55 def MSP430setcc : SDNode<"MSP430ISD::SETCC", SDT_MSP430SetCC>;
56 def MSP430cmp : SDNode<"MSP430ISD::CMP", SDT_MSP430Cmp>;
57 def MSP430brcond : SDNode<"MSP430ISD::BRCOND", SDT_MSP430BrCond, [SDNPHasChain]>;
58 def MSP430select : SDNode<"MSP430ISD::SELECT", SDT_MSP430Select>;
60 //===----------------------------------------------------------------------===//
61 // MSP430 Operand Definitions.
62 //===----------------------------------------------------------------------===//
65 def memsrc : Operand<i16> {
66 let PrintMethod = "printSrcMemOperand";
67 let MIOperandInfo = (ops GR16, i16imm);
70 def memdst : Operand<i16> {
71 let PrintMethod = "printSrcMemOperand";
72 let MIOperandInfo = (ops GR16, i16imm);
75 // Branch targets have OtherVT type.
76 def brtarget : Operand<OtherVT>;
78 // Operand for printing out a condition code.
79 def cc : Operand<i8> {
80 let PrintMethod = "printCCOperand";
83 //===----------------------------------------------------------------------===//
84 // MSP430 Complex Pattern Definitions.
85 //===----------------------------------------------------------------------===//
87 def addr : ComplexPattern<iPTR, 2, "SelectAddr", [], []>;
89 //===----------------------------------------------------------------------===//
91 def zextloadi16i8 : PatFrag<(ops node:$ptr), (i16 (zextloadi8 node:$ptr))>;
92 def extloadi16i8 : PatFrag<(ops node:$ptr), (i16 ( extloadi8 node:$ptr))>;
94 //===----------------------------------------------------------------------===//
97 // ADJCALLSTACKDOWN/UP implicitly use/def SP because they may be expanded into
98 // a stack adjustment and the codegen must know that they may modify the stack
99 // pointer before prolog-epilog rewriting occurs.
100 // Pessimistically assume ADJCALLSTACKDOWN / ADJCALLSTACKUP will become
101 // sub / add which can clobber SRW.
102 let Defs = [SPW, SRW], Uses = [SPW] in {
103 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i16imm:$amt),
105 [(MSP430callseq_start timm:$amt)]>;
106 def ADJCALLSTACKUP : Pseudo<(outs), (ins i16imm:$amt1, i16imm:$amt2),
108 [(MSP430callseq_end timm:$amt1, timm:$amt2)]>;
111 let usesCustomDAGSchedInserter = 1 in {
112 def Select16 : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2, i8imm:$cc),
115 (MSP430select GR16:$src1, GR16:$src2, imm:$cc, SRW))]>;
118 let neverHasSideEffects = 1 in
119 def NOP : Pseudo<(outs), (ins), "nop", []>;
121 //===----------------------------------------------------------------------===//
122 // Control Flow Instructions...
125 // FIXME: Provide proper encoding!
126 let isReturn = 1, isTerminator = 1 in {
127 def RET : Pseudo<(outs), (ins), "ret", [(MSP430retflag)]>;
130 let isBranch = 1, isTerminator = 1 in {
134 def JMP : Pseudo<(outs), (ins brtarget:$dst),
138 // Conditional branches
140 def JCC : Pseudo<(outs), (ins brtarget:$dst, cc:$cc),
142 [(MSP430brcond bb:$dst, imm:$cc, SRW)]>;
143 } // isBranch, isTerminator
145 //===----------------------------------------------------------------------===//
146 // Call Instructions...
149 // All calls clobber the non-callee saved registers. SPW is marked as
150 // a use to prevent stack-pointer assignments that appear immediately
151 // before calls from potentially appearing dead. Uses for argument
152 // registers are added manually.
153 let Defs = [R12W, R13W, R14W, R15W, SRW],
155 def CALLi : Pseudo<(outs), (ins i16imm:$dst, variable_ops),
156 "call\t${dst:call}", [(MSP430call imm:$dst)]>;
157 def CALLr : Pseudo<(outs), (ins GR16:$dst, variable_ops),
158 "call\t$dst", [(MSP430call GR16:$dst)]>;
159 def CALLm : Pseudo<(outs), (ins memsrc:$dst, variable_ops),
160 "call\t${dst:mem}", [(MSP430call (load addr:$dst))]>;
164 //===----------------------------------------------------------------------===//
165 // Miscellaneous Instructions...
167 let Defs = [SPW], Uses = [SPW], neverHasSideEffects=1 in {
169 def POP16r : Pseudo<(outs GR16:$reg), (ins), "pop.w\t$reg", []>;
172 def PUSH16r : Pseudo<(outs), (ins GR16:$reg), "push.w\t$reg",[]>;
175 //===----------------------------------------------------------------------===//
178 // FIXME: Provide proper encoding!
179 let neverHasSideEffects = 1 in {
180 def MOV8rr : Pseudo<(outs GR8:$dst), (ins GR8:$src),
181 "mov.b\t{$src, $dst}",
183 def MOV16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src),
184 "mov.w\t{$src, $dst}",
188 // FIXME: Provide proper encoding!
189 let isReMaterializable = 1, isAsCheapAsAMove = 1 in {
190 def MOV8ri : Pseudo<(outs GR8:$dst), (ins i8imm:$src),
191 "mov.b\t{$src, $dst}",
192 [(set GR8:$dst, imm:$src)]>;
193 def MOV16ri : Pseudo<(outs GR16:$dst), (ins i16imm:$src),
194 "mov.w\t{$src, $dst}",
195 [(set GR16:$dst, imm:$src)]>;
198 let canFoldAsLoad = 1, isReMaterializable = 1, mayHaveSideEffects = 1 in {
199 def MOV8rm : Pseudo<(outs GR8:$dst), (ins memsrc:$src),
200 "mov.b\t{$src, $dst}",
201 [(set GR8:$dst, (load addr:$src))]>;
202 def MOV16rm : Pseudo<(outs GR16:$dst), (ins memsrc:$src),
203 "mov.w\t{$src, $dst}",
204 [(set GR16:$dst, (load addr:$src))]>;
207 def MOVZX16rr8 : Pseudo<(outs GR16:$dst), (ins GR8:$src),
208 "mov.b\t{$src, $dst}",
209 [(set GR16:$dst, (zext GR8:$src))]>;
210 def MOVZX16rm8 : Pseudo<(outs GR16:$dst), (ins memsrc:$src),
211 "mov.b\t{$src, $dst}",
212 [(set GR16:$dst, (zextloadi16i8 addr:$src))]>;
214 def MOV8mi : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
215 "mov.b\t{$src, $dst}",
216 [(store (i8 imm:$src), addr:$dst)]>;
217 def MOV16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
218 "mov.w\t{$src, $dst}",
219 [(store (i16 imm:$src), addr:$dst)]>;
221 def MOV8mr : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
222 "mov.b\t{$src, $dst}",
223 [(store GR8:$src, addr:$dst)]>;
224 def MOV16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
225 "mov.w\t{$src, $dst}",
226 [(store GR16:$src, addr:$dst)]>;
228 //===----------------------------------------------------------------------===//
229 // Arithmetic Instructions
231 let isTwoAddress = 1 in {
233 let Defs = [SRW] in {
235 let isCommutable = 1 in { // X = ADD Y, Z == X = ADD Z, Y
236 // FIXME: Provide proper encoding!
237 def ADD8rr : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
238 "add.b\t{$src2, $dst}",
239 [(set GR8:$dst, (add GR8:$src1, GR8:$src2)),
241 def ADD16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
242 "add.w\t{$src2, $dst}",
243 [(set GR16:$dst, (add GR16:$src1, GR16:$src2)),
247 def ADD8rm : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
248 "add.b\t{$src2, $dst}",
249 [(set GR8:$dst, (add GR8:$src1, (load addr:$src2))),
251 def ADD16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
252 "add.w\t{$src2, $dst}",
253 [(set GR16:$dst, (add GR16:$src1, (load addr:$src2))),
256 def ADD8ri : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
257 "add.b\t{$src2, $dst}",
258 [(set GR8:$dst, (add GR8:$src1, imm:$src2)),
260 def ADD16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
261 "add.w\t{$src2, $dst}",
262 [(set GR16:$dst, (add GR16:$src1, imm:$src2)),
265 let isTwoAddress = 0 in {
266 def ADD8mr : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
267 "add.b\t{$src, $dst}",
268 [(store (add (load addr:$dst), GR8:$src), addr:$dst),
270 def ADD16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
271 "add.w\t{$src, $dst}",
272 [(store (add (load addr:$dst), GR16:$src), addr:$dst),
275 def ADD8mi : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
276 "add.b\t{$src, $dst}",
277 [(store (add (load addr:$dst), (i8 imm:$src)), addr:$dst),
279 def ADD16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
280 "add.w\t{$src, $dst}",
281 [(store (add (load addr:$dst), (i16 imm:$src)), addr:$dst),
284 def ADD8mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
285 "add.b\t{$src, $dst}",
286 [(store (add (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
288 def ADD16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
289 "add.w\t{$src, $dst}",
290 [(store (add (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
294 let Uses = [SRW] in {
296 let isCommutable = 1 in { // X = ADDC Y, Z == X = ADDC Z, Y
297 def ADC8rr : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
298 "addc.b\t{$src2, $dst}",
299 [(set GR8:$dst, (adde GR8:$src1, GR8:$src2)),
301 def ADC16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
302 "addc.w\t{$src2, $dst}",
303 [(set GR16:$dst, (adde GR16:$src1, GR16:$src2)),
307 def ADC8ri : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
308 "addc.b\t{$src2, $dst}",
309 [(set GR8:$dst, (adde GR8:$src1, imm:$src2)),
311 def ADC16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
312 "addc.w\t{$src2, $dst}",
313 [(set GR16:$dst, (adde GR16:$src1, imm:$src2)),
316 def ADC8rm : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
317 "addc.b\t{$src2, $dst}",
318 [(set GR8:$dst, (adde GR8:$src1, (load addr:$src2))),
320 def ADC16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
321 "addc.w\t{$src2, $dst}",
322 [(set GR16:$dst, (adde GR16:$src1, (load addr:$src2))),
325 let isTwoAddress = 0 in {
326 def ADC8mr : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
327 "addc.b\t{$src, $dst}",
328 [(store (adde (load addr:$dst), GR8:$src), addr:$dst),
330 def ADC16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
331 "addc.w\t{$src, $dst}",
332 [(store (adde (load addr:$dst), GR16:$src), addr:$dst),
335 def ADC8mi : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
336 "addc.b\t{$src, $dst}",
337 [(store (adde (load addr:$dst), (i8 imm:$src)), addr:$dst),
339 def ADC16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
340 "addc.w\t{$src, $dst}",
341 [(store (adde (load addr:$dst), (i16 imm:$src)), addr:$dst),
344 def ADC8mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
345 "addc.b\t{$src, $dst}",
346 [(store (adde (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
348 def ADC16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
349 "addc.w\t{$src, $dst}",
350 [(store (adde (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
356 let isCommutable = 1 in { // X = AND Y, Z == X = AND Z, Y
357 def AND8rr : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
358 "and.b\t{$src2, $dst}",
359 [(set GR8:$dst, (and GR8:$src1, GR8:$src2)),
361 def AND16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
362 "and.w\t{$src2, $dst}",
363 [(set GR16:$dst, (and GR16:$src1, GR16:$src2)),
367 def AND8ri : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
368 "and.b\t{$src2, $dst}",
369 [(set GR8:$dst, (and GR8:$src1, imm:$src2)),
371 def AND16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
372 "and.w\t{$src2, $dst}",
373 [(set GR16:$dst, (and GR16:$src1, imm:$src2)),
376 def AND8rm : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
377 "and.b\t{$src2, $dst}",
378 [(set GR8:$dst, (and GR8:$src1, (load addr:$src2))),
380 def AND16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
381 "and.w\t{$src2, $dst}",
382 [(set GR16:$dst, (and GR16:$src1, (load addr:$src2))),
385 let isTwoAddress = 0 in {
386 def AND8mr : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
387 "and.b\t{$src, $dst}",
388 [(store (and (load addr:$dst), GR8:$src), addr:$dst),
390 def AND16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
391 "and.w\t{$src, $dst}",
392 [(store (and (load addr:$dst), GR16:$src), addr:$dst),
395 def AND8mi : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
396 "and.b\t{$src, $dst}",
397 [(store (and (load addr:$dst), (i8 imm:$src)), addr:$dst),
399 def AND16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
400 "and.w\t{$src, $dst}",
401 [(store (and (load addr:$dst), (i16 imm:$src)), addr:$dst),
404 def AND8mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
405 "and.b\t{$src, $dst}",
406 [(store (and (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
408 def AND16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
409 "and.w\t{$src, $dst}",
410 [(store (and (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
415 let isCommutable = 1 in { // X = XOR Y, Z == X = XOR Z, Y
416 def XOR8rr : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
417 "xor.b\t{$src2, $dst}",
418 [(set GR8:$dst, (xor GR8:$src1, GR8:$src2)),
420 def XOR16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
421 "xor.w\t{$src2, $dst}",
422 [(set GR16:$dst, (xor GR16:$src1, GR16:$src2)),
426 def XOR8ri : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
427 "xor.b\t{$src2, $dst}",
428 [(set GR8:$dst, (xor GR8:$src1, imm:$src2)),
430 def XOR16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
431 "xor.w\t{$src2, $dst}",
432 [(set GR16:$dst, (xor GR16:$src1, imm:$src2)),
435 def XOR8rm : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
436 "xor.b\t{$src2, $dst}",
437 [(set GR8:$dst, (xor GR8:$src1, (load addr:$src2))),
439 def XOR16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
440 "xor.w\t{$src2, $dst}",
441 [(set GR16:$dst, (xor GR16:$src1, (load addr:$src2))),
444 let isTwoAddress = 0 in {
445 def XOR8mr : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
446 "xor.b\t{$src, $dst}",
447 [(store (xor (load addr:$dst), GR8:$src), addr:$dst),
449 def XOR16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
450 "xor.w\t{$src, $dst}",
451 [(store (xor (load addr:$dst), GR16:$src), addr:$dst),
454 def XOR8mi : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
455 "xor.b\t{$src, $dst}",
456 [(store (xor (load addr:$dst), (i8 imm:$src)), addr:$dst),
458 def XOR16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
459 "xor.w\t{$src, $dst}",
460 [(store (xor (load addr:$dst), (i16 imm:$src)), addr:$dst),
463 def XOR8mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
464 "xor.b\t{$src, $dst}",
465 [(store (xor (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
467 def XOR16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
468 "xor.w\t{$src, $dst}",
469 [(store (xor (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
474 def SUB8rr : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
475 "sub.b\t{$src2, $dst}",
476 [(set GR8:$dst, (sub GR8:$src1, GR8:$src2)),
478 def SUB16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
479 "sub.w\t{$src2, $dst}",
480 [(set GR16:$dst, (sub GR16:$src1, GR16:$src2)),
483 def SUB8ri : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
484 "sub.b\t{$src2, $dst}",
485 [(set GR8:$dst, (sub GR8:$src1, imm:$src2)),
487 def SUB16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
488 "sub.w\t{$src2, $dst}",
489 [(set GR16:$dst, (sub GR16:$src1, imm:$src2)),
492 def SUB8rm : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
493 "sub.b\t{$src2, $dst}",
494 [(set GR8:$dst, (sub GR8:$src1, (load addr:$src2))),
496 def SUB16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
497 "sub.w\t{$src2, $dst}",
498 [(set GR16:$dst, (sub GR16:$src1, (load addr:$src2))),
501 let isTwoAddress = 0 in {
502 def SUB8mr : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
503 "sub.b\t{$src, $dst}",
504 [(store (sub (load addr:$dst), GR8:$src), addr:$dst),
506 def SUB16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
507 "sub.w\t{$src, $dst}",
508 [(store (sub (load addr:$dst), GR16:$src), addr:$dst),
511 def SUB8mi : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
512 "sub.b\t{$src, $dst}",
513 [(store (sub (load addr:$dst), (i8 imm:$src)), addr:$dst),
515 def SUB16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
516 "sub.w\t{$src, $dst}",
517 [(store (sub (load addr:$dst), (i16 imm:$src)), addr:$dst),
520 def SUB8mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
521 "sub.b\t{$src, $dst}",
522 [(store (sub (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
524 def SUB16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
525 "sub.w\t{$src, $dst}",
526 [(store (sub (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
530 let Uses = [SRW] in {
531 def SBC8rr : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
532 "subc.b\t{$src2, $dst}",
533 [(set GR8:$dst, (sube GR8:$src1, GR8:$src2)),
535 def SBC16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
536 "subc.w\t{$src2, $dst}",
537 [(set GR16:$dst, (sube GR16:$src1, GR16:$src2)),
540 def SBC8ri : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
541 "subc.b\t{$src2, $dst}",
542 [(set GR8:$dst, (sube GR8:$src1, imm:$src2)),
544 def SBC16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
545 "subc.w\t{$src2, $dst}",
546 [(set GR16:$dst, (sube GR16:$src1, imm:$src2)),
549 def SBC8rm : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
550 "subc.b\t{$src2, $dst}",
551 [(set GR8:$dst, (sube GR8:$src1, (load addr:$src2))),
553 def SBC16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
554 "subc.w\t{$src2, $dst}",
555 [(set GR16:$dst, (sube GR16:$src1, (load addr:$src2))),
558 let isTwoAddress = 0 in {
559 def SBC8mr : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
560 "subc.b\t{$src, $dst}",
561 [(store (sube (load addr:$dst), GR8:$src), addr:$dst),
563 def SBC16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
564 "subc.w\t{$src, $dst}",
565 [(store (sube (load addr:$dst), GR16:$src), addr:$dst),
568 def SBC8mi : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
569 "subc.b\t{$src, $dst}",
570 [(store (sube (load addr:$dst), (i8 imm:$src)), addr:$dst),
572 def SBC16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
573 "subc.w\t{$src, $dst}",
574 [(store (sube (load addr:$dst), (i16 imm:$src)), addr:$dst),
577 def SBC8mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
578 "subc.b\t{$src, $dst}",
579 [(store (sube (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
581 def SBC16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
582 "subc.w\t{$src, $dst}",
583 [(store (sube (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
589 // FIXME: Provide proper encoding!
590 def SAR16r1 : Pseudo<(outs GR16:$dst), (ins GR16:$src),
592 [(set GR16:$dst, (MSP430rra GR16:$src)),
595 def SHL16r1 : Pseudo<(outs GR16:$dst), (ins GR16:$src),
597 [(set GR16:$dst, (MSP430rla GR16:$src)),
600 def SEXT16r : Pseudo<(outs GR16:$dst), (ins GR16:$src),
602 [(set GR16:$dst, (sext_inreg GR16:$src, i8)),
605 //def SEXT16r : Pseudo<(outs GR16:$dst), (ins GR16:$src),
607 // [(set GR16:$dst, (sext_inreg GR16:$src, i8)),
612 let isCommutable = 1 in { // X = OR Y, Z == X = OR Z, Y
613 def OR8rr : Pseudo<(outs GR8:$dst), (ins GR8:$src1, GR8:$src2),
614 "bis.b\t{$src2, $dst}",
615 [(set GR8:$dst, (or GR8:$src1, GR8:$src2))]>;
616 def OR16rr : Pseudo<(outs GR16:$dst), (ins GR16:$src1, GR16:$src2),
617 "bis.w\t{$src2, $dst}",
618 [(set GR16:$dst, (or GR16:$src1, GR16:$src2))]>;
621 def OR8ri : Pseudo<(outs GR8:$dst), (ins GR8:$src1, i8imm:$src2),
622 "bis.b\t{$src2, $dst}",
623 [(set GR8:$dst, (or GR8:$src1, imm:$src2))]>;
624 def OR16ri : Pseudo<(outs GR16:$dst), (ins GR16:$src1, i16imm:$src2),
625 "bis.w\t{$src2, $dst}",
626 [(set GR16:$dst, (or GR16:$src1, imm:$src2))]>;
628 def OR8rm : Pseudo<(outs GR8:$dst), (ins GR8:$src1, memsrc:$src2),
629 "bis.b\t{$src2, $dst}",
630 [(set GR8:$dst, (or GR8:$src1, (load addr:$src2)))]>;
631 def OR16rm : Pseudo<(outs GR16:$dst), (ins GR16:$src1, memsrc:$src2),
632 "bis.w\t{$src2, $dst}",
633 [(set GR16:$dst, (or GR16:$src1, (load addr:$src2)))]>;
635 let isTwoAddress = 0 in {
636 def OR8mr : Pseudo<(outs), (ins memdst:$dst, GR8:$src),
637 "bis.b\t{$src, $dst}",
638 [(store (or (load addr:$dst), GR8:$src), addr:$dst),
640 def OR16mr : Pseudo<(outs), (ins memdst:$dst, GR16:$src),
641 "bis.w\t{$src, $dst}",
642 [(store (or (load addr:$dst), GR16:$src), addr:$dst),
645 def OR8mi : Pseudo<(outs), (ins memdst:$dst, i8imm:$src),
646 "bis.b\t{$src, $dst}",
647 [(store (or (load addr:$dst), (i8 imm:$src)), addr:$dst),
649 def OR16mi : Pseudo<(outs), (ins memdst:$dst, i16imm:$src),
650 "bis.w\t{$src, $dst}",
651 [(store (or (load addr:$dst), (i16 imm:$src)), addr:$dst),
654 def OR8mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
655 "bis.b\t{$src, $dst}",
656 [(store (or (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
658 def OR16mm : Pseudo<(outs), (ins memdst:$dst, memsrc:$src),
659 "bis.w\t{$src, $dst}",
660 [(store (or (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
664 } // isTwoAddress = 1
666 // Integer comparisons
667 let Defs = [SRW] in {
668 def CMP8rr : Pseudo<(outs), (ins GR8:$src1, GR8:$src2),
669 "cmp.b\t{$src1, $src2}",
670 [(MSP430cmp GR8:$src1, GR8:$src2), (implicit SRW)]>;
671 def CMP16rr : Pseudo<(outs), (ins GR16:$src1, GR16:$src2),
672 "cmp.w\t{$src1, $src2}",
673 [(MSP430cmp GR16:$src1, GR16:$src2), (implicit SRW)]>;
675 def CMP8ri : Pseudo<(outs), (ins GR8:$src1, i8imm:$src2),
676 "cmp.b\t{$src1, $src2}",
677 [(MSP430cmp GR8:$src1, imm:$src2), (implicit SRW)]>;
678 def CMP16ri : Pseudo<(outs), (ins GR16:$src1, i16imm:$src2),
679 "cmp.w\t{$src1, $src2}",
680 [(MSP430cmp GR16:$src1, imm:$src2), (implicit SRW)]>;
682 def CMP8rm : Pseudo<(outs), (ins GR8:$src1, memsrc:$src2),
683 "cmp.b\t{$src1, $src2}",
684 [(MSP430cmp GR8:$src1, (load addr:$src2)), (implicit SRW)]>;
685 def CMP16rm : Pseudo<(outs), (ins GR16:$src1, memsrc:$src2),
686 "cmp.w\t{$src1, $src2}",
687 [(MSP430cmp GR16:$src1, (load addr:$src2)), (implicit SRW)]>;
689 def CMP8mr : Pseudo<(outs), (ins memsrc:$src1, GR8:$src2),
690 "cmp.b\t{$src1, $src2}",
691 [(MSP430cmp (load addr:$src1), GR8:$src2), (implicit SRW)]>;
692 def CMP16mr : Pseudo<(outs), (ins memsrc:$src1, GR16:$src2),
693 "cmp.w\t{$src1, $src2}",
694 [(MSP430cmp (load addr:$src1), GR16:$src2), (implicit SRW)]>;
696 def CMP8mi : Pseudo<(outs), (ins memsrc:$src1, i8imm:$src2),
697 "cmp.b\t{$src1, $src2}",
698 [(MSP430cmp (load addr:$src1), (i8 imm:$src2)), (implicit SRW)]>;
699 def CMP16mi : Pseudo<(outs), (ins memsrc:$src1, i16imm:$src2),
700 "cmp.w\t{$src1, $src2}",
701 [(MSP430cmp (load addr:$src1), (i16 imm:$src2)), (implicit SRW)]>;
703 def CMP8mm : Pseudo<(outs), (ins memsrc:$src1, memsrc:$src2),
704 "cmp.b\t{$src1, $src2}",
705 [(MSP430cmp (load addr:$src1), (i8 (load addr:$src2))), (implicit SRW)]>;
706 def CMP16mm : Pseudo<(outs), (ins memsrc:$src1, memsrc:$src2),
707 "cmp.w\t{$src1, $src2}",
708 [(MSP430cmp (load addr:$src1), (i16 (load addr:$src2))), (implicit SRW)]>;
711 //===----------------------------------------------------------------------===//
712 // Non-Instruction Patterns
715 def : Pat<(extloadi16i8 addr:$src), (MOVZX16rm8 addr:$src)>;
718 def : Pat<(i8 (trunc GR16:$src)),
719 (EXTRACT_SUBREG GR16:$src, subreg_8bit)>;
721 // GlobalAddress, ExternalSymbol
722 def : Pat<(i16 (MSP430Wrapper tglobaladdr:$dst)), (MOV16ri tglobaladdr:$dst)>;
723 def : Pat<(i16 (MSP430Wrapper texternalsym:$dst)), (MOV16ri texternalsym:$dst)>;
725 def : Pat<(add GR16:$src1, (MSP430Wrapper tglobaladdr :$src2)),
726 (ADD16ri GR16:$src1, tglobaladdr:$src2)>;
727 def : Pat<(add GR16:$src1, (MSP430Wrapper texternalsym:$src2)),
728 (ADD16ri GR16:$src1, texternalsym:$src2)>;
730 def : Pat<(store (i16 (MSP430Wrapper tglobaladdr:$src)), addr:$dst),
731 (MOV16mi addr:$dst, tglobaladdr:$src)>;
732 def : Pat<(store (i16 (MSP430Wrapper texternalsym:$src)), addr:$dst),
733 (MOV16mi addr:$dst, texternalsym:$src)>;
736 def : Pat<(MSP430call (i16 tglobaladdr:$dst)),
737 (CALLi tglobaladdr:$dst)>;
738 def : Pat<(MSP430call (i16 texternalsym:$dst)),
739 (CALLi texternalsym:$dst)>;
741 // add and sub always produce carry
742 def : Pat<(addc GR16:$src1, GR16:$src2),
743 (ADD16rr GR16:$src1, GR16:$src2)>;
744 def : Pat<(addc GR16:$src1, (load addr:$src2)),
745 (ADD16rm GR16:$src1, addr:$src2)>;
746 def : Pat<(addc GR16:$src1, imm:$src2),
747 (ADD16ri GR16:$src1, imm:$src2)>;
748 def : Pat<(store (addc (load addr:$dst), GR16:$src), addr:$dst),
749 (ADD16mr addr:$dst, GR16:$src)>;
750 def : Pat<(store (addc (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
751 (ADD16mm addr:$dst, addr:$src)>;
753 def : Pat<(addc GR8:$src1, GR8:$src2),
754 (ADD8rr GR8:$src1, GR8:$src2)>;
755 def : Pat<(addc GR8:$src1, (load addr:$src2)),
756 (ADD8rm GR8:$src1, addr:$src2)>;
757 def : Pat<(addc GR8:$src1, imm:$src2),
758 (ADD8ri GR8:$src1, imm:$src2)>;
759 def : Pat<(store (addc (load addr:$dst), GR8:$src), addr:$dst),
760 (ADD8mr addr:$dst, GR8:$src)>;
761 def : Pat<(store (addc (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
762 (ADD8mm addr:$dst, addr:$src)>;
764 def : Pat<(subc GR16:$src1, GR16:$src2),
765 (SUB16rr GR16:$src1, GR16:$src2)>;
766 def : Pat<(subc GR16:$src1, (load addr:$src2)),
767 (SUB16rm GR16:$src1, addr:$src2)>;
768 def : Pat<(subc GR16:$src1, imm:$src2),
769 (SUB16ri GR16:$src1, imm:$src2)>;
770 def : Pat<(store (subc (load addr:$dst), GR16:$src), addr:$dst),
771 (SUB16mr addr:$dst, GR16:$src)>;
772 def : Pat<(store (subc (load addr:$dst), (i16 (load addr:$src))), addr:$dst),
773 (SUB16mm addr:$dst, addr:$src)>;
775 def : Pat<(subc GR8:$src1, GR8:$src2),
776 (SUB8rr GR8:$src1, GR8:$src2)>;
777 def : Pat<(subc GR8:$src1, (load addr:$src2)),
778 (SUB8rm GR8:$src1, addr:$src2)>;
779 def : Pat<(subc GR8:$src1, imm:$src2),
780 (SUB8ri GR8:$src1, imm:$src2)>;
781 def : Pat<(store (subc (load addr:$dst), GR8:$src), addr:$dst),
782 (SUB8mr addr:$dst, GR8:$src)>;
783 def : Pat<(store (subc (load addr:$dst), (i8 (load addr:$src))), addr:$dst),
784 (SUB8mm addr:$dst, addr:$src)>;