]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/Target/Sparc/SparcInstrInfo.td
Merge llvm, clang, lld, lldb, compiler-rt and libc++ r303197, and update
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / Target / Sparc / SparcInstrInfo.td
1 //===-- SparcInstrInfo.td - Target Description for Sparc Target -----------===//
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 Sparc instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
17
18 include "SparcInstrFormats.td"
19
20 //===----------------------------------------------------------------------===//
21 // Feature predicates.
22 //===----------------------------------------------------------------------===//
23
24 // True when generating 32-bit code.
25 def Is32Bit : Predicate<"!Subtarget->is64Bit()">;
26
27 // True when generating 64-bit code. This also implies HasV9.
28 def Is64Bit : Predicate<"Subtarget->is64Bit()">;
29
30 // HasV9 - This predicate is true when the target processor supports V9
31 // instructions.  Note that the machine may be running in 32-bit mode.
32 def HasV9   : Predicate<"Subtarget->isV9()">,
33               AssemblerPredicate<"FeatureV9">;
34
35 // HasNoV9 - This predicate is true when the target doesn't have V9
36 // instructions.  Use of this is just a hack for the isel not having proper
37 // costs for V8 instructions that are more expensive than their V9 ones.
38 def HasNoV9 : Predicate<"!Subtarget->isV9()">;
39
40 // HasVIS - This is true when the target processor has VIS extensions.
41 def HasVIS : Predicate<"Subtarget->isVIS()">,
42              AssemblerPredicate<"FeatureVIS">;
43 def HasVIS2 : Predicate<"Subtarget->isVIS2()">,
44              AssemblerPredicate<"FeatureVIS2">;
45 def HasVIS3 : Predicate<"Subtarget->isVIS3()">,
46              AssemblerPredicate<"FeatureVIS3">;
47
48 // HasHardQuad - This is true when the target processor supports quad floating
49 // point instructions.
50 def HasHardQuad : Predicate<"Subtarget->hasHardQuad()">;
51
52 // HasLeonCASA - This is true when the target processor supports the CASA
53 // instruction
54 def HasLeonCASA : Predicate<"Subtarget->hasLeonCasa()">;
55
56 // HasUMAC_SMAC - This is true when the target processor supports the
57 // UMAC and SMAC instructions
58 def HasUMAC_SMAC : Predicate<"Subtarget->hasUmacSmac()">;
59
60 def HasNoFdivSqrtFix : Predicate<"!Subtarget->fixAllFDIVSQRT()">;
61 def HasNoFmulsFix : Predicate<"!Subtarget->replaceFMULS()">;
62 def HasNoFsmuldFix : Predicate<"!Subtarget->fixFSMULD()">;
63
64 // UseDeprecatedInsts - This predicate is true when the target processor is a
65 // V8, or when it is V9 but the V8 deprecated instructions are efficient enough
66 // to use when appropriate.  In either of these cases, the instruction selector
67 // will pick deprecated instructions.
68 def UseDeprecatedInsts : Predicate<"Subtarget->useDeprecatedV8Instructions()">;
69
70 //===----------------------------------------------------------------------===//
71 // Instruction Pattern Stuff
72 //===----------------------------------------------------------------------===//
73
74 def simm11  : PatLeaf<(imm), [{ return isInt<11>(N->getSExtValue()); }]>;
75
76 def simm13  : PatLeaf<(imm), [{ return isInt<13>(N->getSExtValue()); }]>;
77
78 def LO10 : SDNodeXForm<imm, [{
79   return CurDAG->getTargetConstant((unsigned)N->getZExtValue() & 1023, SDLoc(N),
80                                    MVT::i32);
81 }]>;
82
83 def HI22 : SDNodeXForm<imm, [{
84   // Transformation function: shift the immediate value down into the low bits.
85   return CurDAG->getTargetConstant((unsigned)N->getZExtValue() >> 10, SDLoc(N),
86                                    MVT::i32);
87 }]>;
88
89 def SETHIimm : PatLeaf<(imm), [{
90   return isShiftedUInt<22, 10>(N->getZExtValue());
91 }], HI22>;
92
93 // Addressing modes.
94 def ADDRrr : ComplexPattern<iPTR, 2, "SelectADDRrr", [], []>;
95 def ADDRri : ComplexPattern<iPTR, 2, "SelectADDRri", [frameindex], []>;
96
97 // Address operands
98 def SparcMEMrrAsmOperand : AsmOperandClass {
99   let Name = "MEMrr";
100   let ParserMethod = "parseMEMOperand";
101 }
102
103 def SparcMEMriAsmOperand : AsmOperandClass {
104   let Name = "MEMri";
105   let ParserMethod = "parseMEMOperand";
106 }
107
108 def MEMrr : Operand<iPTR> {
109   let PrintMethod = "printMemOperand";
110   let MIOperandInfo = (ops ptr_rc, ptr_rc);
111   let ParserMatchClass = SparcMEMrrAsmOperand;
112 }
113 def MEMri : Operand<iPTR> {
114   let PrintMethod = "printMemOperand";
115   let MIOperandInfo = (ops ptr_rc, i32imm);
116   let ParserMatchClass = SparcMEMriAsmOperand;
117 }
118
119 def TLSSym : Operand<iPTR>;
120
121 // Branch targets have OtherVT type.
122 def brtarget : Operand<OtherVT> {
123   let EncoderMethod = "getBranchTargetOpValue";
124 }
125
126 def bprtarget : Operand<OtherVT> {
127   let EncoderMethod = "getBranchPredTargetOpValue";
128 }
129
130 def bprtarget16 : Operand<OtherVT> {
131   let EncoderMethod = "getBranchOnRegTargetOpValue";
132 }
133
134 def calltarget : Operand<i32> {
135   let EncoderMethod = "getCallTargetOpValue";
136   let DecoderMethod = "DecodeCall";
137 }
138
139 def simm13Op : Operand<i32> {
140   let DecoderMethod = "DecodeSIMM13";
141 }
142
143 // Operand for printing out a condition code.
144 let PrintMethod = "printCCOperand" in
145   def CCOp : Operand<i32>;
146
147 def SDTSPcmpicc :
148 SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisSameAs<0, 1>]>;
149 def SDTSPcmpfcc :
150 SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisSameAs<0, 1>]>;
151 def SDTSPbrcc :
152 SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
153 def SDTSPselectcc :
154 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>]>;
155 def SDTSPFTOI :
156 SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisFP<1>]>;
157 def SDTSPITOF :
158 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f32>]>;
159 def SDTSPFTOX :
160 SDTypeProfile<1, 1, [SDTCisVT<0, f64>, SDTCisFP<1>]>;
161 def SDTSPXTOF :
162 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f64>]>;
163
164 def SDTSPtlsadd :
165 SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>, SDTCisPtrTy<2>]>;
166 def SDTSPtlsld :
167 SDTypeProfile<1, 2, [SDTCisPtrTy<0>, SDTCisPtrTy<1>]>;
168
169 def SDTSPeh_sjlj_setjmp : SDTypeProfile<1, 1, [SDTCisInt<0>, SDTCisPtrTy<1>]>;
170 def SDTSPeh_sjlj_longjmp: SDTypeProfile<0, 1, [SDTCisPtrTy<0>]>;
171
172 def SPcmpicc : SDNode<"SPISD::CMPICC", SDTSPcmpicc, [SDNPOutGlue]>;
173 def SPcmpfcc : SDNode<"SPISD::CMPFCC", SDTSPcmpfcc, [SDNPOutGlue]>;
174 def SPbricc : SDNode<"SPISD::BRICC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
175 def SPbrxcc : SDNode<"SPISD::BRXCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
176 def SPbrfcc : SDNode<"SPISD::BRFCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
177
178 def SPhi    : SDNode<"SPISD::Hi", SDTIntUnaryOp>;
179 def SPlo    : SDNode<"SPISD::Lo", SDTIntUnaryOp>;
180
181 def SPftoi  : SDNode<"SPISD::FTOI", SDTSPFTOI>;
182 def SPitof  : SDNode<"SPISD::ITOF", SDTSPITOF>;
183 def SPftox  : SDNode<"SPISD::FTOX", SDTSPFTOX>;
184 def SPxtof  : SDNode<"SPISD::XTOF", SDTSPXTOF>;
185
186 def SPselecticc : SDNode<"SPISD::SELECT_ICC", SDTSPselectcc, [SDNPInGlue]>;
187 def SPselectxcc : SDNode<"SPISD::SELECT_XCC", SDTSPselectcc, [SDNPInGlue]>;
188 def SPselectfcc : SDNode<"SPISD::SELECT_FCC", SDTSPselectcc, [SDNPInGlue]>;
189
190 def SPsjlj_setjmp: SDNode<"SPISD::EH_SJLJ_SETJMP",
191                           SDTSPeh_sjlj_setjmp,
192                           [SDNPHasChain, SDNPSideEffect]>;
193 def SPsjlj_longjmp: SDNode<"SPISD::EH_SJLJ_LONGJMP",
194                            SDTSPeh_sjlj_longjmp,
195                            [SDNPHasChain, SDNPSideEffect]>;
196
197 //  These are target-independent nodes, but have target-specific formats.
198 def SDT_SPCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32>,
199                                           SDTCisVT<1, i32> ]>;
200 def SDT_SPCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>,
201                                         SDTCisVT<1, i32> ]>;
202
203 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeqStart,
204                            [SDNPHasChain, SDNPOutGlue]>;
205 def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_SPCallSeqEnd,
206                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
207
208 def SDT_SPCall    : SDTypeProfile<0, -1, [SDTCisVT<0, i32>]>;
209 def call          : SDNode<"SPISD::CALL", SDT_SPCall,
210                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
211                             SDNPVariadic]>;
212
213 def SDT_SPRet     : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
214 def retflag       : SDNode<"SPISD::RET_FLAG", SDT_SPRet,
215                            [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
216
217 def flushw        : SDNode<"SPISD::FLUSHW", SDTNone,
218                            [SDNPHasChain, SDNPSideEffect, SDNPMayStore]>;
219
220 def tlsadd        : SDNode<"SPISD::TLS_ADD", SDTSPtlsadd>;
221 def tlsld         : SDNode<"SPISD::TLS_LD",  SDTSPtlsld>;
222 def tlscall       : SDNode<"SPISD::TLS_CALL", SDT_SPCall,
223                             [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
224                              SDNPVariadic]>;
225
226 def getPCX        : Operand<iPTR> {
227   let PrintMethod = "printGetPCX";
228 }
229
230 //===----------------------------------------------------------------------===//
231 // SPARC Flag Conditions
232 //===----------------------------------------------------------------------===//
233
234 // Note that these values must be kept in sync with the CCOp::CondCode enum
235 // values.
236 class ICC_VAL<int N> : PatLeaf<(i32 N)>;
237 def ICC_NE  : ICC_VAL< 9>;  // Not Equal
238 def ICC_E   : ICC_VAL< 1>;  // Equal
239 def ICC_G   : ICC_VAL<10>;  // Greater
240 def ICC_LE  : ICC_VAL< 2>;  // Less or Equal
241 def ICC_GE  : ICC_VAL<11>;  // Greater or Equal
242 def ICC_L   : ICC_VAL< 3>;  // Less
243 def ICC_GU  : ICC_VAL<12>;  // Greater Unsigned
244 def ICC_LEU : ICC_VAL< 4>;  // Less or Equal Unsigned
245 def ICC_CC  : ICC_VAL<13>;  // Carry Clear/Great or Equal Unsigned
246 def ICC_CS  : ICC_VAL< 5>;  // Carry Set/Less Unsigned
247 def ICC_POS : ICC_VAL<14>;  // Positive
248 def ICC_NEG : ICC_VAL< 6>;  // Negative
249 def ICC_VC  : ICC_VAL<15>;  // Overflow Clear
250 def ICC_VS  : ICC_VAL< 7>;  // Overflow Set
251
252 class FCC_VAL<int N> : PatLeaf<(i32 N)>;
253 def FCC_U   : FCC_VAL<23>;  // Unordered
254 def FCC_G   : FCC_VAL<22>;  // Greater
255 def FCC_UG  : FCC_VAL<21>;  // Unordered or Greater
256 def FCC_L   : FCC_VAL<20>;  // Less
257 def FCC_UL  : FCC_VAL<19>;  // Unordered or Less
258 def FCC_LG  : FCC_VAL<18>;  // Less or Greater
259 def FCC_NE  : FCC_VAL<17>;  // Not Equal
260 def FCC_E   : FCC_VAL<25>;  // Equal
261 def FCC_UE  : FCC_VAL<26>;  // Unordered or Equal
262 def FCC_GE  : FCC_VAL<27>;  // Greater or Equal
263 def FCC_UGE : FCC_VAL<28>;  // Unordered or Greater or Equal
264 def FCC_LE  : FCC_VAL<29>;  // Less or Equal
265 def FCC_ULE : FCC_VAL<30>;  // Unordered or Less or Equal
266 def FCC_O   : FCC_VAL<31>;  // Ordered
267
268 class CPCC_VAL<int N> : PatLeaf<(i32 N)>;
269 def CPCC_3   : CPCC_VAL<39>;  // 3
270 def CPCC_2   : CPCC_VAL<38>;  // 2
271 def CPCC_23  : CPCC_VAL<37>;  // 2 or 3
272 def CPCC_1   : CPCC_VAL<36>;  // 1
273 def CPCC_13  : CPCC_VAL<35>;  // 1 or 3
274 def CPCC_12  : CPCC_VAL<34>;  // 1 or 2
275 def CPCC_123 : CPCC_VAL<33>;  // 1 or 2 or 3
276 def CPCC_0   : CPCC_VAL<41>;  // 0
277 def CPCC_03  : CPCC_VAL<42>;  // 0 or 3
278 def CPCC_02  : CPCC_VAL<43>;  // 0 or 2
279 def CPCC_023 : CPCC_VAL<44>;  // 0 or 2 or 3
280 def CPCC_01  : CPCC_VAL<45>;  // 0 or 1
281 def CPCC_013 : CPCC_VAL<46>;  // 0 or 1 or 3
282 def CPCC_012 : CPCC_VAL<47>;  // 0 or 1 or 2
283
284 //===----------------------------------------------------------------------===//
285 // Instruction Class Templates
286 //===----------------------------------------------------------------------===//
287
288 /// F3_12 multiclass - Define a normal F3_1/F3_2 pattern in one shot.
289 multiclass F3_12<string OpcStr, bits<6> Op3Val, SDNode OpNode,
290                  RegisterClass RC, ValueType Ty, Operand immOp,
291                  InstrItinClass itin = IIC_iu_instr> {
292   def rr  : F3_1<2, Op3Val,
293                  (outs RC:$rd), (ins RC:$rs1, RC:$rs2),
294                  !strconcat(OpcStr, " $rs1, $rs2, $rd"),
295                  [(set Ty:$rd, (OpNode Ty:$rs1, Ty:$rs2))],
296                  itin>;
297   def ri  : F3_2<2, Op3Val,
298                  (outs RC:$rd), (ins RC:$rs1, immOp:$simm13),
299                  !strconcat(OpcStr, " $rs1, $simm13, $rd"),
300                  [(set Ty:$rd, (OpNode Ty:$rs1, (Ty simm13:$simm13)))],
301                  itin>;
302 }
303
304 /// F3_12np multiclass - Define a normal F3_1/F3_2 pattern in one shot, with no
305 /// pattern.
306 multiclass F3_12np<string OpcStr, bits<6> Op3Val, InstrItinClass itin = IIC_iu_instr> {
307   def rr  : F3_1<2, Op3Val,
308                  (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
309                  !strconcat(OpcStr, " $rs1, $rs2, $rd"), [],
310                  itin>;
311   def ri  : F3_2<2, Op3Val,
312                  (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
313                  !strconcat(OpcStr, " $rs1, $simm13, $rd"), [],
314                  itin>;
315 }
316
317 // Load multiclass - Define both Reg+Reg/Reg+Imm patterns in one shot.
318 multiclass Load<string OpcStr, bits<6> Op3Val, SDPatternOperator OpNode,
319            RegisterClass RC, ValueType Ty, InstrItinClass itin = IIC_iu_instr> {
320   def rr  : F3_1<3, Op3Val,
321                  (outs RC:$dst), (ins MEMrr:$addr),
322                  !strconcat(OpcStr, " [$addr], $dst"),
323                  [(set Ty:$dst, (OpNode ADDRrr:$addr))],
324                  itin>;
325   def ri  : F3_2<3, Op3Val,
326                  (outs RC:$dst), (ins MEMri:$addr),
327                  !strconcat(OpcStr, " [$addr], $dst"),
328                  [(set Ty:$dst, (OpNode ADDRri:$addr))],
329                  itin>;
330 }
331
332 // TODO: Instructions of the LoadASI class are currently asm only; hooking up
333 // CodeGen's address spaces to use these is a future task.
334 class LoadASI<string OpcStr, bits<6> Op3Val, SDPatternOperator OpNode,
335               RegisterClass RC, ValueType Ty, InstrItinClass itin = NoItinerary> :
336   F3_1_asi<3, Op3Val, (outs RC:$dst), (ins MEMrr:$addr, i8imm:$asi),
337                 !strconcat(OpcStr, "a [$addr] $asi, $dst"),
338                 []>;
339
340 // LoadA multiclass - As above, but also define alternate address space variant
341 multiclass LoadA<string OpcStr, bits<6> Op3Val, bits<6> LoadAOp3Val,
342                  SDPatternOperator OpNode, RegisterClass RC, ValueType Ty,
343                  InstrItinClass itin = NoItinerary> :
344              Load<OpcStr, Op3Val, OpNode, RC, Ty, itin> {
345   def Arr  : LoadASI<OpcStr, LoadAOp3Val, OpNode, RC, Ty>;
346 }
347
348 // The LDSTUB instruction is supported for asm only.
349 // It is unlikely that general-purpose code could make use of it.
350 // CAS is preferred for sparc v9.
351 def LDSTUBrr : F3_1<3, 0b001101, (outs IntRegs:$dst), (ins MEMrr:$addr),
352                     "ldstub [$addr], $dst", []>;
353 def LDSTUBri : F3_2<3, 0b001101, (outs IntRegs:$dst), (ins MEMri:$addr),
354                     "ldstub [$addr], $dst", []>;
355 def LDSTUBArr : F3_1_asi<3, 0b011101, (outs IntRegs:$dst),
356                          (ins MEMrr:$addr, i8imm:$asi),
357                          "ldstuba [$addr] $asi, $dst", []>;
358
359 // Store multiclass - Define both Reg+Reg/Reg+Imm patterns in one shot.
360 multiclass Store<string OpcStr, bits<6> Op3Val, SDPatternOperator OpNode,
361            RegisterClass RC, ValueType Ty, InstrItinClass itin = IIC_st> {
362   def rr  : F3_1<3, Op3Val,
363                  (outs), (ins MEMrr:$addr, RC:$rd),
364                  !strconcat(OpcStr, " $rd, [$addr]"),
365                  [(OpNode Ty:$rd, ADDRrr:$addr)],
366                  itin>;
367   def ri  : F3_2<3, Op3Val,
368                  (outs), (ins MEMri:$addr, RC:$rd),
369                  !strconcat(OpcStr, " $rd, [$addr]"),
370                  [(OpNode Ty:$rd, ADDRri:$addr)],
371                  itin>;
372 }
373
374 // TODO: Instructions of the StoreASI class are currently asm only; hooking up
375 // CodeGen's address spaces to use these is a future task.
376 class StoreASI<string OpcStr, bits<6> Op3Val,
377                SDPatternOperator OpNode, RegisterClass RC, ValueType Ty,
378                InstrItinClass itin = IIC_st> :
379   F3_1_asi<3, Op3Val, (outs), (ins MEMrr:$addr, RC:$rd, i8imm:$asi),
380            !strconcat(OpcStr, "a $rd, [$addr] $asi"),
381            [],
382            itin>;
383
384 multiclass StoreA<string OpcStr, bits<6> Op3Val, bits<6> StoreAOp3Val,
385                   SDPatternOperator OpNode, RegisterClass RC, ValueType Ty,
386                   InstrItinClass itin = IIC_st> :
387              Store<OpcStr, Op3Val, OpNode, RC, Ty> {
388   def Arr : StoreASI<OpcStr, StoreAOp3Val, OpNode, RC, Ty, itin>;
389 }
390
391 //===----------------------------------------------------------------------===//
392 // Instructions
393 //===----------------------------------------------------------------------===//
394
395 // Pseudo instructions.
396 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
397    : InstSP<outs, ins, asmstr, pattern> {
398   let isCodeGenOnly = 1;
399   let isPseudo = 1;
400 }
401
402 // GETPCX for PIC
403 let Defs = [O7] in {
404   def GETPCX : Pseudo<(outs getPCX:$getpcseq), (ins), "$getpcseq", [] >;
405 }
406
407 let Defs = [O6], Uses = [O6] in {
408 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
409                                "!ADJCALLSTACKDOWN $amt1, $amt2",
410                                [(callseq_start timm:$amt1, timm:$amt2)]>;
411 def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
412                             "!ADJCALLSTACKUP $amt1",
413                             [(callseq_end timm:$amt1, timm:$amt2)]>;
414 }
415
416 let hasSideEffects = 1, mayStore = 1 in {
417   let rd = 0, rs1 = 0, rs2 = 0 in
418     def FLUSHW : F3_1<0b10, 0b101011, (outs), (ins),
419                       "flushw",
420                       [(flushw)]>, Requires<[HasV9]>;
421   let rd = 0, rs1 = 1, simm13 = 3 in
422     def TA3 : F3_2<0b10, 0b111010, (outs), (ins),
423                    "ta 3",
424                    [(flushw)]>;
425 }
426
427 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded after
428 // instruction selection into a branch sequence.  This has to handle all
429 // permutations of selection between i32/f32/f64 on ICC and FCC.
430 // Expanded after instruction selection.
431 let Uses = [ICC], usesCustomInserter = 1 in {
432   def SELECT_CC_Int_ICC
433    : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
434             "; SELECT_CC_Int_ICC PSEUDO!",
435             [(set i32:$dst, (SPselecticc i32:$T, i32:$F, imm:$Cond))]>;
436   def SELECT_CC_FP_ICC
437    : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
438             "; SELECT_CC_FP_ICC PSEUDO!",
439             [(set f32:$dst, (SPselecticc f32:$T, f32:$F, imm:$Cond))]>;
440
441   def SELECT_CC_DFP_ICC
442    : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
443             "; SELECT_CC_DFP_ICC PSEUDO!",
444             [(set f64:$dst, (SPselecticc f64:$T, f64:$F, imm:$Cond))]>;
445
446   def SELECT_CC_QFP_ICC
447    : Pseudo<(outs QFPRegs:$dst), (ins QFPRegs:$T, QFPRegs:$F, i32imm:$Cond),
448             "; SELECT_CC_QFP_ICC PSEUDO!",
449             [(set f128:$dst, (SPselecticc f128:$T, f128:$F, imm:$Cond))]>;
450 }
451
452 let usesCustomInserter = 1, Uses = [FCC0] in {
453
454   def SELECT_CC_Int_FCC
455    : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
456             "; SELECT_CC_Int_FCC PSEUDO!",
457             [(set i32:$dst, (SPselectfcc i32:$T, i32:$F, imm:$Cond))]>;
458
459   def SELECT_CC_FP_FCC
460    : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
461             "; SELECT_CC_FP_FCC PSEUDO!",
462             [(set f32:$dst, (SPselectfcc f32:$T, f32:$F, imm:$Cond))]>;
463   def SELECT_CC_DFP_FCC
464    : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
465             "; SELECT_CC_DFP_FCC PSEUDO!",
466             [(set f64:$dst, (SPselectfcc f64:$T, f64:$F, imm:$Cond))]>;
467   def SELECT_CC_QFP_FCC
468    : Pseudo<(outs QFPRegs:$dst), (ins QFPRegs:$T, QFPRegs:$F, i32imm:$Cond),
469             "; SELECT_CC_QFP_FCC PSEUDO!",
470             [(set f128:$dst, (SPselectfcc f128:$T, f128:$F, imm:$Cond))]>;
471 }
472
473 let hasSideEffects = 1, isBarrier = 1, usesCustomInserter = 1 in {
474   let Defs = [WIM] in
475   def EH_SJLJ_SETJMP32ri  : Pseudo<(outs IntRegs:$dst), (ins MEMri:$buf),
476                             "#EH_SJLJ_SETJMP32",
477                             [(set i32:$dst, (SPsjlj_setjmp ADDRri:$buf))]>,
478                             Requires<[Is32Bit]>;
479   def EH_SJLJ_SETJMP32rr  : Pseudo<(outs IntRegs:$dst), (ins MEMrr:$buf),
480                             "#EH_SJLJ_SETJMP32",
481                             [(set i32:$dst, (SPsjlj_setjmp ADDRrr:$buf))]>,
482                             Requires<[Is32Bit]>;
483   let isTerminator = 1 in
484   def EH_SJLJ_LONGJMP32ri : Pseudo<(outs), (ins MEMri:$buf),
485                             "#EH_SJLJ_LONGJMP32",
486                             [(SPsjlj_longjmp ADDRri:$buf)]>,
487                             Requires<[Is32Bit]>;
488   def EH_SJLJ_LONGJMP32rr : Pseudo<(outs), (ins MEMrr:$buf),
489                             "#EH_SJLJ_LONGJMP32",
490                             [(SPsjlj_longjmp ADDRrr:$buf)]>,
491                             Requires<[Is32Bit]>;
492 }
493
494 // Section B.1 - Load Integer Instructions, p. 90
495 let DecoderMethod = "DecodeLoadInt" in {
496   defm LDSB : LoadA<"ldsb", 0b001001, 0b011001, sextloadi8,  IntRegs, i32>;
497   defm LDSH : LoadA<"ldsh", 0b001010, 0b011010, sextloadi16, IntRegs, i32>;
498   defm LDUB : LoadA<"ldub", 0b000001, 0b010001, zextloadi8,  IntRegs, i32>;
499   defm LDUH : LoadA<"lduh", 0b000010, 0b010010, zextloadi16, IntRegs, i32>;
500   defm LD   : LoadA<"ld",   0b000000, 0b010000, load,        IntRegs, i32>;
501 }
502
503 let DecoderMethod = "DecodeLoadIntPair" in
504   defm LDD : LoadA<"ldd", 0b000011, 0b010011, load, IntPair, v2i32, IIC_ldd>;
505
506 // Section B.2 - Load Floating-point Instructions, p. 92
507 let DecoderMethod = "DecodeLoadFP" in {
508   defm LDF   : Load<"ld",  0b100000, load,    FPRegs,  f32, IIC_iu_or_fpu_instr>;
509   def LDFArr : LoadASI<"ld",  0b110000, load, FPRegs,  f32, IIC_iu_or_fpu_instr>,
510                 Requires<[HasV9]>;
511 }
512 let DecoderMethod = "DecodeLoadDFP" in {
513   defm LDDF   : Load<"ldd", 0b100011, load,    DFPRegs, f64, IIC_ldd>;
514   def LDDFArr : LoadASI<"ldd", 0b110011, load, DFPRegs, f64>,
515                  Requires<[HasV9]>;
516 }
517 let DecoderMethod = "DecodeLoadQFP" in
518   defm LDQF  : LoadA<"ldq", 0b100010, 0b110010, load, QFPRegs, f128>,
519                Requires<[HasV9, HasHardQuad]>;
520
521 let DecoderMethod = "DecodeLoadCP" in 
522   defm LDC   : Load<"ld", 0b110000, load, CoprocRegs, i32>; 
523 let DecoderMethod = "DecodeLoadCPPair" in 
524   defm LDDC   : Load<"ldd", 0b110011, load, CoprocPair, v2i32, IIC_ldd>;
525
526 let DecoderMethod = "DecodeLoadCP", Defs = [CPSR] in {
527   let rd = 0 in {
528     def LDCSRrr : F3_1<3, 0b110001, (outs), (ins MEMrr:$addr),
529                        "ld [$addr], %csr", []>;
530     def LDCSRri : F3_2<3, 0b110001, (outs), (ins MEMri:$addr),
531                        "ld [$addr], %csr", []>;
532   }
533 }
534   
535 let DecoderMethod = "DecodeLoadFP" in
536   let Defs = [FSR] in {
537     let rd = 0 in {
538       def LDFSRrr : F3_1<3, 0b100001, (outs), (ins MEMrr:$addr),
539                      "ld [$addr], %fsr", [], IIC_iu_or_fpu_instr>;
540       def LDFSRri : F3_2<3, 0b100001, (outs), (ins MEMri:$addr),
541                      "ld [$addr], %fsr", [], IIC_iu_or_fpu_instr>;
542     }
543     let rd = 1 in {
544       def LDXFSRrr : F3_1<3, 0b100001, (outs), (ins MEMrr:$addr),
545                      "ldx [$addr], %fsr", []>, Requires<[HasV9]>;
546       def LDXFSRri : F3_2<3, 0b100001, (outs), (ins MEMri:$addr),
547                      "ldx [$addr], %fsr", []>, Requires<[HasV9]>;
548     }
549   }
550
551 // Section B.4 - Store Integer Instructions, p. 95
552 let DecoderMethod = "DecodeStoreInt" in {
553   defm STB   : StoreA<"stb", 0b000101, 0b010101, truncstorei8,  IntRegs, i32>;
554   defm STH   : StoreA<"sth", 0b000110, 0b010110, truncstorei16, IntRegs, i32>;
555   defm ST    : StoreA<"st",  0b000100, 0b010100, store,         IntRegs, i32>;
556 }
557
558 let DecoderMethod = "DecodeStoreIntPair" in
559   defm STD   : StoreA<"std", 0b000111, 0b010111, store, IntPair, v2i32, IIC_std>;
560
561 // Section B.5 - Store Floating-point Instructions, p. 97
562 let DecoderMethod = "DecodeStoreFP" in {
563   defm STF   : Store<"st",  0b100100, store,         FPRegs,  f32>;
564   def STFArr : StoreASI<"st",  0b110100, store,      FPRegs,  f32>,
565                Requires<[HasV9]>;
566 }
567 let DecoderMethod = "DecodeStoreDFP" in {
568   defm STDF   : Store<"std", 0b100111, store,         DFPRegs, f64, IIC_std>;
569   def STDFArr : StoreASI<"std", 0b110111, store,      DFPRegs, f64>,
570                 Requires<[HasV9]>;
571 }
572 let DecoderMethod = "DecodeStoreQFP" in
573   defm STQF  : StoreA<"stq", 0b100110, 0b110110, store, QFPRegs, f128>,
574                Requires<[HasV9, HasHardQuad]>;
575
576 let DecoderMethod = "DecodeStoreCP" in 
577   defm STC   : Store<"st", 0b110100, store, CoprocRegs, i32>; 
578   
579 let DecoderMethod = "DecodeStoreCPPair" in 
580   defm STDC   : Store<"std", 0b110111, store, CoprocPair, v2i32, IIC_std>;
581   
582 let DecoderMethod = "DecodeStoreCP", rd = 0 in {
583   let Defs = [CPSR] in {
584     def STCSRrr : F3_1<3, 0b110101, (outs MEMrr:$addr), (ins),
585                        "st %csr, [$addr]", [], IIC_st>;
586     def STCSRri : F3_2<3, 0b110101, (outs MEMri:$addr), (ins),
587                        "st %csr, [$addr]", [], IIC_st>;
588   }
589   let Defs = [CPQ] in {
590     def STDCQrr : F3_1<3, 0b110110, (outs MEMrr:$addr), (ins),
591                        "std %cq, [$addr]", [], IIC_std>;
592     def STDCQri : F3_2<3, 0b110110, (outs MEMri:$addr), (ins),
593                        "std %cq, [$addr]", [], IIC_std>;
594   }
595 }
596
597 let DecoderMethod = "DecodeStoreFP" in {
598   let rd = 0 in {
599     let Defs = [FSR] in {
600       def STFSRrr : F3_1<3, 0b100101, (outs MEMrr:$addr), (ins),
601                      "st %fsr, [$addr]", [], IIC_st>;
602       def STFSRri : F3_2<3, 0b100101, (outs MEMri:$addr), (ins),
603                      "st %fsr, [$addr]", [], IIC_st>;
604     }
605     let Defs = [FQ] in {
606       def STDFQrr : F3_1<3, 0b100110, (outs MEMrr:$addr), (ins),
607                      "std %fq, [$addr]", [], IIC_std>;
608       def STDFQri : F3_2<3, 0b100110, (outs MEMri:$addr), (ins),
609                      "std %fq, [$addr]", [], IIC_std>;
610     }
611   }
612   let rd = 1, Defs = [FSR] in {
613     def STXFSRrr : F3_1<3, 0b100101, (outs MEMrr:$addr), (ins),
614                    "stx %fsr, [$addr]", []>, Requires<[HasV9]>;
615     def STXFSRri : F3_2<3, 0b100101, (outs MEMri:$addr), (ins),
616                    "stx %fsr, [$addr]", []>, Requires<[HasV9]>;
617   }
618 }
619
620 // Section B.8 - SWAP Register with Memory Instruction
621 // (Atomic swap)
622 let Constraints = "$val = $dst", DecoderMethod = "DecodeSWAP" in {
623   def SWAPrr : F3_1<3, 0b001111,
624                  (outs IntRegs:$dst), (ins MEMrr:$addr, IntRegs:$val),
625                  "swap [$addr], $dst",
626                  [(set i32:$dst, (atomic_swap_32 ADDRrr:$addr, i32:$val))]>;
627   def SWAPri : F3_2<3, 0b001111,
628                  (outs IntRegs:$dst), (ins MEMri:$addr, IntRegs:$val),
629                  "swap [$addr], $dst",
630                  [(set i32:$dst, (atomic_swap_32 ADDRri:$addr, i32:$val))]>;
631   def SWAPArr : F3_1_asi<3, 0b011111,
632                  (outs IntRegs:$dst), (ins MEMrr:$addr, i8imm:$asi, IntRegs:$val),
633                  "swapa [$addr] $asi, $dst",
634                  [/*FIXME: pattern?*/]>;
635 }
636
637
638 // Section B.9 - SETHI Instruction, p. 104
639 def SETHIi: F2_1<0b100,
640                  (outs IntRegs:$rd), (ins i32imm:$imm22),
641                  "sethi $imm22, $rd",
642                  [(set i32:$rd, SETHIimm:$imm22)],
643                  IIC_iu_instr>;
644
645 // Section B.10 - NOP Instruction, p. 105
646 // (It's a special case of SETHI)
647 let rd = 0, imm22 = 0 in
648   def NOP : F2_1<0b100, (outs), (ins), "nop", []>;
649
650 // Section B.11 - Logical Instructions, p. 106
651 defm AND    : F3_12<"and", 0b000001, and, IntRegs, i32, simm13Op>;
652
653 def ANDNrr  : F3_1<2, 0b000101,
654                    (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
655                    "andn $rs1, $rs2, $rd",
656                    [(set i32:$rd, (and i32:$rs1, (not i32:$rs2)))]>;
657 def ANDNri  : F3_2<2, 0b000101,
658                    (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
659                    "andn $rs1, $simm13, $rd", []>;
660
661 defm OR     : F3_12<"or", 0b000010, or, IntRegs, i32, simm13Op>;
662
663 def ORNrr   : F3_1<2, 0b000110,
664                    (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
665                    "orn $rs1, $rs2, $rd",
666                    [(set i32:$rd, (or i32:$rs1, (not i32:$rs2)))]>;
667 def ORNri   : F3_2<2, 0b000110,
668                    (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
669                    "orn $rs1, $simm13, $rd", []>;
670 defm XOR    : F3_12<"xor", 0b000011, xor, IntRegs, i32, simm13Op>;
671
672 def XNORrr  : F3_1<2, 0b000111,
673                    (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
674                    "xnor $rs1, $rs2, $rd",
675                    [(set i32:$rd, (not (xor i32:$rs1, i32:$rs2)))]>;
676 def XNORri  : F3_2<2, 0b000111,
677                    (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
678                    "xnor $rs1, $simm13, $rd", []>;
679
680 let Defs = [ICC] in {
681   defm ANDCC  : F3_12np<"andcc",  0b010001>;
682   defm ANDNCC : F3_12np<"andncc", 0b010101>;
683   defm ORCC   : F3_12np<"orcc",   0b010010>;
684   defm ORNCC  : F3_12np<"orncc",  0b010110>;
685   defm XORCC  : F3_12np<"xorcc",  0b010011>;
686   defm XNORCC : F3_12np<"xnorcc", 0b010111>;
687 }
688
689 // Section B.12 - Shift Instructions, p. 107
690 defm SLL : F3_12<"sll", 0b100101, shl, IntRegs, i32, simm13Op>;
691 defm SRL : F3_12<"srl", 0b100110, srl, IntRegs, i32, simm13Op>;
692 defm SRA : F3_12<"sra", 0b100111, sra, IntRegs, i32, simm13Op>;
693
694 // Section B.13 - Add Instructions, p. 108
695 defm ADD   : F3_12<"add", 0b000000, add, IntRegs, i32, simm13Op>;
696
697 // "LEA" forms of add (patterns to make tblgen happy)
698 let Predicates = [Is32Bit], isCodeGenOnly = 1 in
699   def LEA_ADDri   : F3_2<2, 0b000000,
700                      (outs IntRegs:$dst), (ins MEMri:$addr),
701                      "add ${addr:arith}, $dst",
702                      [(set iPTR:$dst, ADDRri:$addr)]>;
703
704 let Defs = [ICC] in
705   defm ADDCC  : F3_12<"addcc", 0b010000, addc, IntRegs, i32, simm13Op>;
706
707 let Uses = [ICC] in
708   defm ADDC   : F3_12np<"addx", 0b001000>;
709
710 let Uses = [ICC], Defs = [ICC] in
711   defm ADDE  : F3_12<"addxcc", 0b011000, adde, IntRegs, i32, simm13Op>;
712
713 // Section B.15 - Subtract Instructions, p. 110
714 defm SUB    : F3_12  <"sub"  , 0b000100, sub, IntRegs, i32, simm13Op>;
715 let Uses = [ICC], Defs = [ICC] in
716   defm SUBE   : F3_12  <"subxcc" , 0b011100, sube, IntRegs, i32, simm13Op>;
717
718 let Defs = [ICC] in
719   defm SUBCC  : F3_12  <"subcc", 0b010100, subc, IntRegs, i32, simm13Op>;
720
721 let Uses = [ICC] in
722   defm SUBC   : F3_12np <"subx", 0b001100>;
723
724 // cmp (from Section A.3) is a specialized alias for subcc
725 let Defs = [ICC], rd = 0 in {
726   def CMPrr   : F3_1<2, 0b010100,
727                      (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
728                      "cmp $rs1, $rs2",
729                      [(SPcmpicc i32:$rs1, i32:$rs2)]>;
730   def CMPri   : F3_2<2, 0b010100,
731                      (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
732                      "cmp $rs1, $simm13",
733                      [(SPcmpicc i32:$rs1, (i32 simm13:$simm13))]>;
734 }
735
736 // Section B.18 - Multiply Instructions, p. 113
737 let Defs = [Y] in {
738   defm UMUL : F3_12<"umul", 0b001010, umullohi, IntRegs, i32, simm13Op, IIC_iu_umul>;
739   defm SMUL : F3_12<"smul", 0b001011, smullohi, IntRegs, i32, simm13Op, IIC_iu_smul>;
740 }
741
742 let Defs = [Y, ICC] in {
743   defm UMULCC : F3_12np<"umulcc", 0b011010, IIC_iu_umul>;
744   defm SMULCC : F3_12np<"smulcc", 0b011011, IIC_iu_smul>;
745 }
746
747 let Defs = [Y, ICC], Uses = [Y, ICC] in {
748   defm MULSCC : F3_12np<"mulscc", 0b100100>;
749 }
750
751 // Section B.19 - Divide Instructions, p. 115
752 let Uses = [Y], Defs = [Y] in {
753   defm UDIV : F3_12np<"udiv", 0b001110, IIC_iu_div>;
754   defm SDIV : F3_12np<"sdiv", 0b001111, IIC_iu_div>;
755 }
756
757 let Uses = [Y], Defs = [Y, ICC] in {
758   defm UDIVCC : F3_12np<"udivcc", 0b011110, IIC_iu_div>;
759   defm SDIVCC : F3_12np<"sdivcc", 0b011111, IIC_iu_div>;
760 }
761
762 // Section B.20 - SAVE and RESTORE, p. 117
763 defm SAVE    : F3_12np<"save"   , 0b111100>;
764 defm RESTORE : F3_12np<"restore", 0b111101>;
765
766 // Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
767
768 // unconditional branch class.
769 class BranchAlways<dag ins, string asmstr, list<dag> pattern>
770   : F2_2<0b010, 0, (outs), ins, asmstr, pattern> {
771   let isBranch     = 1;
772   let isTerminator = 1;
773   let hasDelaySlot = 1;
774   let isBarrier    = 1;
775 }
776
777 let cond = 8 in
778   def BA : BranchAlways<(ins brtarget:$imm22), "ba $imm22", [(br bb:$imm22)]>;
779
780
781 let isBranch = 1, isTerminator = 1, hasDelaySlot = 1 in {
782
783 // conditional branch class:
784 class BranchSP<dag ins, string asmstr, list<dag> pattern>
785  : F2_2<0b010, 0, (outs), ins, asmstr, pattern, IIC_iu_instr>;
786
787 // conditional branch with annul class:
788 class BranchSPA<dag ins, string asmstr, list<dag> pattern>
789  : F2_2<0b010, 1, (outs), ins, asmstr, pattern, IIC_iu_instr>;
790
791 // Conditional branch class on %icc|%xcc with predication:
792 multiclass IPredBranch<string regstr, list<dag> CCPattern> {
793   def CC    : F2_3<0b001, 0, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond),
794                    !strconcat("b$cond ", !strconcat(regstr, ", $imm19")),
795                    CCPattern,
796                    IIC_iu_instr>;
797   def CCA   : F2_3<0b001, 1, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond),
798                    !strconcat("b$cond,a ", !strconcat(regstr, ", $imm19")),
799                    [],
800                    IIC_iu_instr>;
801   def CCNT  : F2_3<0b001, 0, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond),
802                    !strconcat("b$cond,pn ", !strconcat(regstr, ", $imm19")),
803                    [],
804                    IIC_iu_instr>;
805   def CCANT : F2_3<0b001, 1, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond),
806                    !strconcat("b$cond,a,pn ", !strconcat(regstr, ", $imm19")),
807                    [],
808                    IIC_iu_instr>;
809 }
810
811 } // let isBranch = 1, isTerminator = 1, hasDelaySlot = 1
812
813
814 // Indirect branch instructions.
815 let isTerminator = 1, isBarrier = 1,  hasDelaySlot = 1, isBranch =1,
816      isIndirectBranch = 1, rd = 0, isCodeGenOnly = 1 in {
817   def BINDrr  : F3_1<2, 0b111000,
818                    (outs), (ins MEMrr:$ptr),
819                    "jmp $ptr",
820                    [(brind ADDRrr:$ptr)]>;
821   def BINDri  : F3_2<2, 0b111000,
822                    (outs), (ins MEMri:$ptr),
823                    "jmp $ptr",
824                    [(brind ADDRri:$ptr)]>;
825 }
826
827 let Uses = [ICC] in {
828   def BCOND : BranchSP<(ins brtarget:$imm22, CCOp:$cond),
829                          "b$cond $imm22",
830                         [(SPbricc bb:$imm22, imm:$cond)]>;
831   def BCONDA : BranchSPA<(ins brtarget:$imm22, CCOp:$cond),
832                          "b$cond,a $imm22", []>;
833
834   let Predicates = [HasV9], cc = 0b00 in
835     defm BPI : IPredBranch<"%icc", []>;
836 }
837
838 // Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
839
840 let isBranch = 1, isTerminator = 1, hasDelaySlot = 1 in {
841
842 // floating-point conditional branch class:
843 class FPBranchSP<dag ins, string asmstr, list<dag> pattern>
844  : F2_2<0b110, 0, (outs), ins, asmstr, pattern, IIC_fpu_normal_instr>;
845
846 // floating-point conditional branch with annul class:
847 class FPBranchSPA<dag ins, string asmstr, list<dag> pattern>
848  : F2_2<0b110, 1, (outs), ins, asmstr, pattern, IIC_fpu_normal_instr>;
849
850 // Conditional branch class on %fcc0-%fcc3 with predication:
851 multiclass FPredBranch {
852   def CC    : F2_3<0b101, 0, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond,
853                                          FCCRegs:$cc),
854                   "fb$cond $cc, $imm19", [], IIC_fpu_normal_instr>;
855   def CCA   : F2_3<0b101, 1, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond,
856                                          FCCRegs:$cc),
857                   "fb$cond,a $cc, $imm19", [], IIC_fpu_normal_instr>;
858   def CCNT  : F2_3<0b101, 0, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond,
859                                          FCCRegs:$cc),
860                   "fb$cond,pn $cc, $imm19", [], IIC_fpu_normal_instr>;
861   def CCANT : F2_3<0b101, 1, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond,
862                                          FCCRegs:$cc),
863                   "fb$cond,a,pn $cc, $imm19", [], IIC_fpu_normal_instr>;
864 }
865 } // let isBranch = 1, isTerminator = 1, hasDelaySlot = 1
866
867 let Uses = [FCC0] in {
868   def FBCOND  : FPBranchSP<(ins brtarget:$imm22, CCOp:$cond),
869                               "fb$cond $imm22",
870                               [(SPbrfcc bb:$imm22, imm:$cond)]>;
871   def FBCONDA : FPBranchSPA<(ins brtarget:$imm22, CCOp:$cond),
872                              "fb$cond,a $imm22", []>;
873 }
874
875 let Predicates = [HasV9] in
876   defm BPF : FPredBranch;
877
878 // Section B.22 - Branch on Co-processor Condition Codes Instructions, p. 123
879 let isBranch = 1, isTerminator = 1, hasDelaySlot = 1 in {
880
881 // co-processor conditional branch class:
882 class CPBranchSP<dag ins, string asmstr, list<dag> pattern>
883  : F2_2<0b111, 0, (outs), ins, asmstr, pattern>;
884
885 // co-processor conditional branch with annul class:
886 class CPBranchSPA<dag ins, string asmstr, list<dag> pattern>
887  : F2_2<0b111, 1, (outs), ins, asmstr, pattern>;
888
889 } // let isBranch = 1, isTerminator = 1, hasDelaySlot = 1
890
891 def CBCOND  : CPBranchSP<(ins brtarget:$imm22, CCOp:$cond),
892                           "cb$cond $imm22",
893                           [(SPbrfcc bb:$imm22, imm:$cond)]>;
894 def CBCONDA : CPBranchSPA<(ins brtarget:$imm22, CCOp:$cond),
895                            "cb$cond,a $imm22", []>;
896                            
897 // Section B.24 - Call and Link Instruction, p. 125
898 // This is the only Format 1 instruction
899 let Uses = [O6],
900     hasDelaySlot = 1, isCall = 1 in {
901   def CALL : InstSP<(outs), (ins calltarget:$disp, variable_ops),
902                     "call $disp",
903                     [],
904                     IIC_jmp_or_call> {
905     bits<30> disp;
906     let op = 1;
907     let Inst{29-0} = disp;
908   }
909
910   // indirect calls: special cases of JMPL.
911   let isCodeGenOnly = 1, rd = 15 in {
912     def CALLrr : F3_1<2, 0b111000,
913                       (outs), (ins MEMrr:$ptr, variable_ops),
914                       "call $ptr",
915                       [(call ADDRrr:$ptr)],
916                       IIC_jmp_or_call>;
917     def CALLri : F3_2<2, 0b111000,
918                       (outs), (ins MEMri:$ptr, variable_ops),
919                       "call $ptr",
920                       [(call ADDRri:$ptr)],
921                       IIC_jmp_or_call>;
922   }
923 }
924
925 // Section B.25 - Jump and Link Instruction
926
927 // JMPL Instruction.
928 let isTerminator = 1, hasDelaySlot = 1, isBarrier = 1,
929     DecoderMethod = "DecodeJMPL" in {
930   def JMPLrr: F3_1<2, 0b111000,
931                    (outs IntRegs:$dst), (ins MEMrr:$addr),
932                    "jmpl $addr, $dst",
933                    [],
934                    IIC_jmp_or_call>;
935   def JMPLri: F3_2<2, 0b111000,
936                    (outs IntRegs:$dst), (ins MEMri:$addr),
937                    "jmpl $addr, $dst",
938                    [],
939                    IIC_jmp_or_call>;
940 }
941
942 // Section A.3 - Synthetic Instructions, p. 85
943 // special cases of JMPL:
944 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1, isBarrier = 1,
945     isCodeGenOnly = 1 in {
946   let rd = 0, rs1 = 15 in
947     def RETL: F3_2<2, 0b111000,
948                    (outs), (ins i32imm:$val),
949                    "jmp %o7+$val",
950                    [(retflag simm13:$val)],
951                    IIC_jmp_or_call>;
952
953   let rd = 0, rs1 = 31 in
954     def RET: F3_2<2, 0b111000,
955                   (outs), (ins i32imm:$val),
956                   "jmp %i7+$val",
957                   [],
958                   IIC_jmp_or_call>;
959 }
960
961 // Section B.26 - Return from Trap Instruction
962 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1,
963      isBarrier = 1, rd = 0, DecoderMethod = "DecodeReturn" in {
964   def RETTrr : F3_1<2, 0b111001,
965                    (outs), (ins MEMrr:$addr),
966                    "rett $addr",
967                    [],
968                    IIC_jmp_or_call>;
969   def RETTri : F3_2<2, 0b111001,
970                     (outs), (ins MEMri:$addr),
971                     "rett $addr",
972                     [],
973                     IIC_jmp_or_call>;
974 }
975
976
977 // Section B.27 - Trap on Integer Condition Codes Instruction
978 // conditional branch class:
979 let DecoderNamespace = "SparcV8", DecoderMethod = "DecodeTRAP", hasSideEffects = 1, Uses = [ICC], cc = 0b00 in
980 {
981   def TRAPrr : TRAPSPrr<0b111010,
982                         (outs), (ins IntRegs:$rs1, IntRegs:$rs2, CCOp:$cond),
983                         "t$cond $rs1 + $rs2",
984                         []>;
985   def TRAPri : TRAPSPri<0b111010,
986                         (outs), (ins IntRegs:$rs1, i32imm:$imm, CCOp:$cond),
987                         "t$cond $rs1 + $imm",
988                         []>;
989 }
990
991 multiclass TRAP<string regStr> {
992   def rr : TRAPSPrr<0b111010,
993                     (outs), (ins IntRegs:$rs1, IntRegs:$rs2, CCOp:$cond),
994                     !strconcat(!strconcat("t$cond ", regStr), ", $rs1 + $rs2"),
995                     []>;
996   def ri : TRAPSPri<0b111010,
997                     (outs), (ins IntRegs:$rs1, i32imm:$imm, CCOp:$cond),
998                     !strconcat(!strconcat("t$cond ", regStr), ", $rs1 + $imm"),
999                     []>;
1000 }
1001
1002 let DecoderNamespace = "SparcV9", DecoderMethod = "DecodeTRAP", Predicates = [HasV9], hasSideEffects = 1, Uses = [ICC], cc = 0b00 in
1003   defm TICC : TRAP<"%icc">;
1004
1005
1006 let isBarrier = 1, isTerminator = 1, rd = 0b01000, rs1 = 0, simm13 = 5 in
1007   def TA5 : F3_2<0b10, 0b111010, (outs), (ins), "ta 5", [(trap)]>;
1008
1009 // Section B.28 - Read State Register Instructions
1010 let rs2 = 0 in
1011   def RDASR : F3_1<2, 0b101000,
1012                  (outs IntRegs:$rd), (ins ASRRegs:$rs1),
1013                  "rd $rs1, $rd", []>;
1014
1015 // PSR, WIM, and TBR don't exist on the SparcV9, only the V8.
1016 let Predicates = [HasNoV9] in {
1017   let rs2 = 0, rs1 = 0, Uses=[PSR] in
1018     def RDPSR : F3_1<2, 0b101001,
1019                      (outs IntRegs:$rd), (ins),
1020                      "rd %psr, $rd", []>;
1021
1022   let rs2 = 0, rs1 = 0, Uses=[WIM] in
1023     def RDWIM : F3_1<2, 0b101010,
1024                      (outs IntRegs:$rd), (ins),
1025                      "rd %wim, $rd", []>;
1026
1027   let rs2 = 0, rs1 = 0, Uses=[TBR] in
1028     def RDTBR : F3_1<2, 0b101011,
1029                      (outs IntRegs:$rd), (ins),
1030                      "rd %tbr, $rd", []>;
1031 }
1032
1033 // Section B.29 - Write State Register Instructions
1034 def WRASRrr : F3_1<2, 0b110000,
1035                  (outs ASRRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
1036                  "wr $rs1, $rs2, $rd", []>;
1037 def WRASRri : F3_2<2, 0b110000,
1038                  (outs ASRRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
1039                  "wr $rs1, $simm13, $rd", []>;
1040
1041 // PSR, WIM, and TBR don't exist on the SparcV9, only the V8.
1042 let Predicates = [HasNoV9] in {
1043   let Defs = [PSR], rd=0 in {
1044     def WRPSRrr : F3_1<2, 0b110001,
1045                      (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
1046                      "wr $rs1, $rs2, %psr", []>;
1047     def WRPSRri : F3_2<2, 0b110001,
1048                      (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
1049                      "wr $rs1, $simm13, %psr", []>;
1050   }
1051
1052   let Defs = [WIM], rd=0 in {
1053     def WRWIMrr : F3_1<2, 0b110010,
1054                      (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
1055                      "wr $rs1, $rs2, %wim", []>;
1056     def WRWIMri : F3_2<2, 0b110010,
1057                      (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
1058                      "wr $rs1, $simm13, %wim", []>;
1059   }
1060
1061   let Defs = [TBR], rd=0 in {
1062     def WRTBRrr : F3_1<2, 0b110011,
1063                      (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
1064                      "wr $rs1, $rs2, %tbr", []>;
1065     def WRTBRri : F3_2<2, 0b110011,
1066                      (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
1067                      "wr $rs1, $simm13, %tbr", []>;
1068   }
1069 }
1070
1071 // Section B.30 - STBAR Instruction
1072 let hasSideEffects = 1, rd = 0, rs1 = 0b01111, rs2 = 0 in
1073   def STBAR : F3_1<2, 0b101000, (outs), (ins), "stbar", []>;
1074
1075
1076 // Section B.31 - Unimplmented Instruction
1077 let rd = 0 in
1078   def UNIMP : F2_1<0b000, (outs), (ins i32imm:$imm22),
1079                   "unimp $imm22", []>;
1080
1081 // Section B.32 - Flush Instruction Memory
1082 let rd = 0 in {
1083   def FLUSHrr : F3_1<2, 0b111011, (outs), (ins MEMrr:$addr),
1084                        "flush $addr", []>;
1085   def FLUSHri : F3_2<2, 0b111011, (outs), (ins MEMri:$addr),
1086                        "flush $addr", []>;
1087
1088   // The no-arg FLUSH is only here for the benefit of the InstAlias
1089   // "flush", which cannot seem to use FLUSHrr, due to the inability
1090   // to construct a MEMrr with fixed G0 registers.
1091   let rs1 = 0, rs2 = 0 in
1092     def FLUSH   : F3_1<2, 0b111011, (outs), (ins), "flush %g0", []>;
1093 }
1094
1095 // Section B.33 - Floating-point Operate (FPop) Instructions
1096
1097 // Convert Integer to Floating-point Instructions, p. 141
1098 def FITOS : F3_3u<2, 0b110100, 0b011000100,
1099                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
1100                  "fitos $rs2, $rd",
1101                  [(set FPRegs:$rd, (SPitof FPRegs:$rs2))],
1102                  IIC_fpu_fast_instr>;
1103 def FITOD : F3_3u<2, 0b110100, 0b011001000,
1104                  (outs DFPRegs:$rd), (ins FPRegs:$rs2),
1105                  "fitod $rs2, $rd",
1106                  [(set DFPRegs:$rd, (SPitof FPRegs:$rs2))],
1107                  IIC_fpu_fast_instr>;
1108 def FITOQ : F3_3u<2, 0b110100, 0b011001100,
1109                  (outs QFPRegs:$rd), (ins FPRegs:$rs2),
1110                  "fitoq $rs2, $rd",
1111                  [(set QFPRegs:$rd, (SPitof FPRegs:$rs2))]>,
1112                  Requires<[HasHardQuad]>;
1113
1114 // Convert Floating-point to Integer Instructions, p. 142
1115 def FSTOI : F3_3u<2, 0b110100, 0b011010001,
1116                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
1117                  "fstoi $rs2, $rd",
1118                  [(set FPRegs:$rd, (SPftoi FPRegs:$rs2))],
1119                  IIC_fpu_fast_instr>;
1120 def FDTOI : F3_3u<2, 0b110100, 0b011010010,
1121                  (outs FPRegs:$rd), (ins DFPRegs:$rs2),
1122                  "fdtoi $rs2, $rd",
1123                  [(set FPRegs:$rd, (SPftoi DFPRegs:$rs2))],
1124                  IIC_fpu_fast_instr>;
1125 def FQTOI : F3_3u<2, 0b110100, 0b011010011,
1126                  (outs FPRegs:$rd), (ins QFPRegs:$rs2),
1127                  "fqtoi $rs2, $rd",
1128                  [(set FPRegs:$rd, (SPftoi QFPRegs:$rs2))]>,
1129                  Requires<[HasHardQuad]>;
1130
1131 // Convert between Floating-point Formats Instructions, p. 143
1132 def FSTOD : F3_3u<2, 0b110100, 0b011001001,
1133                  (outs DFPRegs:$rd), (ins FPRegs:$rs2),
1134                  "fstod $rs2, $rd",
1135                  [(set f64:$rd, (fpextend f32:$rs2))],
1136                  IIC_fpu_stod>;
1137 def FSTOQ : F3_3u<2, 0b110100, 0b011001101,
1138                  (outs QFPRegs:$rd), (ins FPRegs:$rs2),
1139                  "fstoq $rs2, $rd",
1140                  [(set f128:$rd, (fpextend f32:$rs2))]>,
1141                  Requires<[HasHardQuad]>;
1142 def FDTOS : F3_3u<2, 0b110100, 0b011000110,
1143                  (outs FPRegs:$rd), (ins DFPRegs:$rs2),
1144                  "fdtos $rs2, $rd",
1145                  [(set f32:$rd, (fpround f64:$rs2))],
1146                  IIC_fpu_fast_instr>;
1147 def FDTOQ : F3_3u<2, 0b110100, 0b011001110,
1148                  (outs QFPRegs:$rd), (ins DFPRegs:$rs2),
1149                  "fdtoq $rs2, $rd",
1150                  [(set f128:$rd, (fpextend f64:$rs2))]>,
1151                  Requires<[HasHardQuad]>;
1152 def FQTOS : F3_3u<2, 0b110100, 0b011000111,
1153                  (outs FPRegs:$rd), (ins QFPRegs:$rs2),
1154                  "fqtos $rs2, $rd",
1155                  [(set f32:$rd, (fpround f128:$rs2))]>,
1156                  Requires<[HasHardQuad]>;
1157 def FQTOD : F3_3u<2, 0b110100, 0b011001011,
1158                  (outs DFPRegs:$rd), (ins QFPRegs:$rs2),
1159                  "fqtod $rs2, $rd",
1160                  [(set f64:$rd, (fpround f128:$rs2))]>,
1161                  Requires<[HasHardQuad]>;
1162
1163 // Floating-point Move Instructions, p. 144
1164 def FMOVS : F3_3u<2, 0b110100, 0b000000001,
1165                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
1166                  "fmovs $rs2, $rd", []>;
1167 def FNEGS : F3_3u<2, 0b110100, 0b000000101,
1168                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
1169                  "fnegs $rs2, $rd",
1170                  [(set f32:$rd, (fneg f32:$rs2))],
1171                  IIC_fpu_negs>;
1172 def FABSS : F3_3u<2, 0b110100, 0b000001001,
1173                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
1174                  "fabss $rs2, $rd",
1175                  [(set f32:$rd, (fabs f32:$rs2))],
1176                  IIC_fpu_abs>;
1177
1178
1179 // Floating-point Square Root Instructions, p.145
1180 // FSQRTS generates an erratum on LEON processors, so by disabling this instruction
1181 // this will be promoted to use FSQRTD with doubles instead.
1182 let Predicates = [HasNoFdivSqrtFix] in 
1183 def FSQRTS : F3_3u<2, 0b110100, 0b000101001,
1184                   (outs FPRegs:$rd), (ins FPRegs:$rs2),
1185                   "fsqrts $rs2, $rd",
1186                   [(set f32:$rd, (fsqrt f32:$rs2))],
1187                   IIC_fpu_sqrts>;
1188 def FSQRTD : F3_3u<2, 0b110100, 0b000101010,
1189                   (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1190                   "fsqrtd $rs2, $rd",
1191                   [(set f64:$rd, (fsqrt f64:$rs2))],
1192                   IIC_fpu_sqrtd>;
1193 def FSQRTQ : F3_3u<2, 0b110100, 0b000101011,
1194                   (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1195                   "fsqrtq $rs2, $rd",
1196                   [(set f128:$rd, (fsqrt f128:$rs2))]>,
1197                   Requires<[HasHardQuad]>;
1198
1199
1200
1201 // Floating-point Add and Subtract Instructions, p. 146
1202 def FADDS  : F3_3<2, 0b110100, 0b001000001,
1203                   (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1204                   "fadds $rs1, $rs2, $rd",
1205                   [(set f32:$rd, (fadd f32:$rs1, f32:$rs2))],
1206                   IIC_fpu_fast_instr>;
1207 def FADDD  : F3_3<2, 0b110100, 0b001000010,
1208                   (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1209                   "faddd $rs1, $rs2, $rd",
1210                   [(set f64:$rd, (fadd f64:$rs1, f64:$rs2))],
1211                   IIC_fpu_fast_instr>;
1212 def FADDQ  : F3_3<2, 0b110100, 0b001000011,
1213                   (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1214                   "faddq $rs1, $rs2, $rd",
1215                   [(set f128:$rd, (fadd f128:$rs1, f128:$rs2))]>,
1216                   Requires<[HasHardQuad]>;
1217
1218 def FSUBS  : F3_3<2, 0b110100, 0b001000101,
1219                   (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1220                   "fsubs $rs1, $rs2, $rd",
1221                   [(set f32:$rd, (fsub f32:$rs1, f32:$rs2))],
1222                   IIC_fpu_fast_instr>;
1223 def FSUBD  : F3_3<2, 0b110100, 0b001000110,
1224                   (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1225                   "fsubd $rs1, $rs2, $rd",
1226                   [(set f64:$rd, (fsub f64:$rs1, f64:$rs2))],
1227                   IIC_fpu_fast_instr>;
1228 def FSUBQ  : F3_3<2, 0b110100, 0b001000111,
1229                   (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1230                   "fsubq $rs1, $rs2, $rd",
1231                   [(set f128:$rd, (fsub f128:$rs1, f128:$rs2))]>,
1232                   Requires<[HasHardQuad]>;
1233
1234
1235 // Floating-point Multiply and Divide Instructions, p. 147
1236 // FMULS generates an erratum on LEON processors, so by disabling this instruction
1237 // this will be promoted to use FMULD with doubles instead.
1238 let Predicates = [HasNoFmulsFix] in 
1239 def FMULS  : F3_3<2, 0b110100, 0b001001001,
1240                   (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1241                   "fmuls $rs1, $rs2, $rd",
1242                   [(set f32:$rd, (fmul f32:$rs1, f32:$rs2))],
1243                   IIC_fpu_muls>;
1244 def FMULD  : F3_3<2, 0b110100, 0b001001010,
1245                   (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1246                   "fmuld $rs1, $rs2, $rd",
1247                   [(set f64:$rd, (fmul f64:$rs1, f64:$rs2))],
1248                   IIC_fpu_muld>;
1249 def FMULQ  : F3_3<2, 0b110100, 0b001001011,
1250                   (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1251                   "fmulq $rs1, $rs2, $rd",
1252                   [(set f128:$rd, (fmul f128:$rs1, f128:$rs2))]>,
1253                   Requires<[HasHardQuad]>;
1254
1255 let Predicates = [HasNoFsmuldFix] in
1256 def FSMULD : F3_3<2, 0b110100, 0b001101001,
1257                   (outs DFPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1258                   "fsmuld $rs1, $rs2, $rd",
1259                   [(set f64:$rd, (fmul (fpextend f32:$rs1),
1260                                         (fpextend f32:$rs2)))],
1261                   IIC_fpu_muld>;
1262 def FDMULQ : F3_3<2, 0b110100, 0b001101110,
1263                   (outs QFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1264                   "fdmulq $rs1, $rs2, $rd",
1265                   [(set f128:$rd, (fmul (fpextend f64:$rs1),
1266                                          (fpextend f64:$rs2)))]>,
1267                   Requires<[HasHardQuad]>;
1268
1269 // FDIVS generates an erratum on LEON processors, so by disabling this instruction
1270 // this will be promoted to use FDIVD with doubles instead.
1271 def FDIVS  : F3_3<2, 0b110100, 0b001001101,
1272                  (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1273                  "fdivs $rs1, $rs2, $rd",
1274                  [(set f32:$rd, (fdiv f32:$rs1, f32:$rs2))],
1275                  IIC_fpu_divs>;
1276 def FDIVD  : F3_3<2, 0b110100, 0b001001110,
1277                  (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1278                  "fdivd $rs1, $rs2, $rd",
1279                  [(set f64:$rd, (fdiv f64:$rs1, f64:$rs2))],
1280                  IIC_fpu_divd>;
1281 def FDIVQ  : F3_3<2, 0b110100, 0b001001111,
1282                  (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1283                  "fdivq $rs1, $rs2, $rd",
1284                  [(set f128:$rd, (fdiv f128:$rs1, f128:$rs2))]>,
1285                  Requires<[HasHardQuad]>;
1286
1287 // Floating-point Compare Instructions, p. 148
1288 // Note: the 2nd template arg is different for these guys.
1289 // Note 2: the result of a FCMP is not available until the 2nd cycle
1290 // after the instr is retired, but there is no interlock in Sparc V8.
1291 // This behavior is modeled with a forced noop after the instruction in
1292 // DelaySlotFiller.
1293
1294 let Defs = [FCC0], rd = 0, isCodeGenOnly = 1 in {
1295   def FCMPS  : F3_3c<2, 0b110101, 0b001010001,
1296                    (outs), (ins FPRegs:$rs1, FPRegs:$rs2),
1297                    "fcmps $rs1, $rs2",
1298                    [(SPcmpfcc f32:$rs1, f32:$rs2)],
1299                    IIC_fpu_fast_instr>;
1300   def FCMPD  : F3_3c<2, 0b110101, 0b001010010,
1301                    (outs), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1302                    "fcmpd $rs1, $rs2",
1303                    [(SPcmpfcc f64:$rs1, f64:$rs2)],
1304                    IIC_fpu_fast_instr>;
1305   def FCMPQ  : F3_3c<2, 0b110101, 0b001010011,
1306                    (outs), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1307                    "fcmpq $rs1, $rs2",
1308                    [(SPcmpfcc f128:$rs1, f128:$rs2)]>,
1309                    Requires<[HasHardQuad]>;
1310 }
1311
1312 //===----------------------------------------------------------------------===//
1313 // Instructions for Thread Local Storage(TLS).
1314 //===----------------------------------------------------------------------===//
1315 let isCodeGenOnly = 1, isAsmParserOnly = 1 in {
1316 def TLS_ADDrr : F3_1<2, 0b000000,
1317                     (outs IntRegs:$rd),
1318                     (ins IntRegs:$rs1, IntRegs:$rs2, TLSSym:$sym),
1319                     "add $rs1, $rs2, $rd, $sym",
1320                     [(set i32:$rd,
1321                         (tlsadd i32:$rs1, i32:$rs2, tglobaltlsaddr:$sym))]>;
1322
1323 let mayLoad = 1 in
1324   def TLS_LDrr : F3_1<3, 0b000000,
1325                       (outs IntRegs:$dst), (ins MEMrr:$addr, TLSSym:$sym),
1326                       "ld [$addr], $dst, $sym",
1327                       [(set i32:$dst,
1328                           (tlsld ADDRrr:$addr, tglobaltlsaddr:$sym))]>;
1329
1330 let Uses = [O6], isCall = 1, hasDelaySlot = 1 in
1331   def TLS_CALL : InstSP<(outs),
1332                         (ins calltarget:$disp, TLSSym:$sym, variable_ops),
1333                         "call $disp, $sym",
1334                         [(tlscall texternalsym:$disp, tglobaltlsaddr:$sym)],
1335                         IIC_jmp_or_call> {
1336   bits<30> disp;
1337   let op = 1;
1338   let Inst{29-0} = disp;
1339 }
1340 }
1341
1342 //===----------------------------------------------------------------------===//
1343 // V9 Instructions
1344 //===----------------------------------------------------------------------===//
1345
1346 // V9 Conditional Moves.
1347 let Predicates = [HasV9], Constraints = "$f = $rd" in {
1348   // Move Integer Register on Condition (MOVcc) p. 194 of the V9 manual.
1349   let Uses = [ICC], intcc = 1, cc = 0b00 in {
1350     def MOVICCrr
1351       : F4_1<0b101100, (outs IntRegs:$rd),
1352              (ins IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
1353              "mov$cond %icc, $rs2, $rd",
1354              [(set i32:$rd, (SPselecticc i32:$rs2, i32:$f, imm:$cond))]>;
1355
1356     def MOVICCri
1357       : F4_2<0b101100, (outs IntRegs:$rd),
1358              (ins i32imm:$simm11, IntRegs:$f, CCOp:$cond),
1359              "mov$cond %icc, $simm11, $rd",
1360              [(set i32:$rd,
1361                     (SPselecticc simm11:$simm11, i32:$f, imm:$cond))]>;
1362   }
1363
1364   let Uses = [FCC0], intcc = 0, cc = 0b00 in {
1365     def MOVFCCrr
1366       : F4_1<0b101100, (outs IntRegs:$rd),
1367              (ins IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
1368              "mov$cond %fcc0, $rs2, $rd",
1369              [(set i32:$rd, (SPselectfcc i32:$rs2, i32:$f, imm:$cond))]>;
1370     def MOVFCCri
1371       : F4_2<0b101100, (outs IntRegs:$rd),
1372              (ins i32imm:$simm11, IntRegs:$f, CCOp:$cond),
1373              "mov$cond %fcc0, $simm11, $rd",
1374              [(set i32:$rd,
1375                     (SPselectfcc simm11:$simm11, i32:$f, imm:$cond))]>;
1376   }
1377
1378   let Uses = [ICC], intcc = 1, opf_cc = 0b00 in {
1379     def FMOVS_ICC
1380       : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
1381              (ins FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
1382              "fmovs$cond %icc, $rs2, $rd",
1383              [(set f32:$rd, (SPselecticc f32:$rs2, f32:$f, imm:$cond))]>;
1384     def FMOVD_ICC
1385       : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
1386                (ins DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
1387                "fmovd$cond %icc, $rs2, $rd",
1388                [(set f64:$rd, (SPselecticc f64:$rs2, f64:$f, imm:$cond))]>;
1389     def FMOVQ_ICC
1390       : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
1391                (ins QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
1392                "fmovq$cond %icc, $rs2, $rd",
1393                [(set f128:$rd, (SPselecticc f128:$rs2, f128:$f, imm:$cond))]>,
1394                Requires<[HasHardQuad]>;
1395   }
1396
1397   let Uses = [FCC0], intcc = 0, opf_cc = 0b00 in {
1398     def FMOVS_FCC
1399       : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
1400              (ins FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
1401              "fmovs$cond %fcc0, $rs2, $rd",
1402              [(set f32:$rd, (SPselectfcc f32:$rs2, f32:$f, imm:$cond))]>;
1403     def FMOVD_FCC
1404       : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
1405              (ins DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
1406              "fmovd$cond %fcc0, $rs2, $rd",
1407              [(set f64:$rd, (SPselectfcc f64:$rs2, f64:$f, imm:$cond))]>;
1408     def FMOVQ_FCC
1409       : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
1410              (ins QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
1411              "fmovq$cond %fcc0, $rs2, $rd",
1412              [(set f128:$rd, (SPselectfcc f128:$rs2, f128:$f, imm:$cond))]>,
1413              Requires<[HasHardQuad]>;
1414   }
1415
1416 }
1417
1418 // Floating-Point Move Instructions, p. 164 of the V9 manual.
1419 let Predicates = [HasV9] in {
1420   def FMOVD : F3_3u<2, 0b110100, 0b000000010,
1421                    (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1422                    "fmovd $rs2, $rd", []>;
1423   def FMOVQ : F3_3u<2, 0b110100, 0b000000011,
1424                    (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1425                    "fmovq $rs2, $rd", []>,
1426                    Requires<[HasHardQuad]>;
1427   def FNEGD : F3_3u<2, 0b110100, 0b000000110,
1428                    (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1429                    "fnegd $rs2, $rd",
1430                    [(set f64:$rd, (fneg f64:$rs2))]>;
1431   def FNEGQ : F3_3u<2, 0b110100, 0b000000111,
1432                    (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1433                    "fnegq $rs2, $rd",
1434                    [(set f128:$rd, (fneg f128:$rs2))]>,
1435                    Requires<[HasHardQuad]>;
1436   def FABSD : F3_3u<2, 0b110100, 0b000001010,
1437                    (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1438                    "fabsd $rs2, $rd",
1439                    [(set f64:$rd, (fabs f64:$rs2))]>;
1440   def FABSQ : F3_3u<2, 0b110100, 0b000001011,
1441                    (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1442                    "fabsq $rs2, $rd",
1443                    [(set f128:$rd, (fabs f128:$rs2))]>,
1444                    Requires<[HasHardQuad]>;
1445 }
1446
1447 // Floating-point compare instruction with %fcc0-%fcc3.
1448 def V9FCMPS  : F3_3c<2, 0b110101, 0b001010001,
1449                (outs FCCRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1450                "fcmps $rd, $rs1, $rs2", []>;
1451 def V9FCMPD  : F3_3c<2, 0b110101, 0b001010010,
1452                 (outs FCCRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1453                 "fcmpd $rd, $rs1, $rs2", []>;
1454 def V9FCMPQ  : F3_3c<2, 0b110101, 0b001010011,
1455                 (outs FCCRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1456                 "fcmpq $rd, $rs1, $rs2", []>,
1457                  Requires<[HasHardQuad]>;
1458
1459 let hasSideEffects = 1 in {
1460   def V9FCMPES  : F3_3c<2, 0b110101, 0b001010101,
1461                    (outs FCCRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1462                    "fcmpes $rd, $rs1, $rs2", []>;
1463   def V9FCMPED  : F3_3c<2, 0b110101, 0b001010110,
1464                    (outs FCCRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1465                    "fcmped $rd, $rs1, $rs2", []>;
1466   def V9FCMPEQ  : F3_3c<2, 0b110101, 0b001010111,
1467                    (outs FCCRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1468                    "fcmpeq $rd, $rs1, $rs2", []>,
1469                    Requires<[HasHardQuad]>;
1470 }
1471
1472 // Floating point conditional move instrucitons with %fcc0-%fcc3.
1473 let Predicates = [HasV9] in {
1474   let Constraints = "$f = $rd", intcc = 0 in {
1475     def V9MOVFCCrr
1476       : F4_1<0b101100, (outs IntRegs:$rd),
1477              (ins FCCRegs:$cc, IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
1478              "mov$cond $cc, $rs2, $rd", []>;
1479     def V9MOVFCCri
1480       : F4_2<0b101100, (outs IntRegs:$rd),
1481              (ins FCCRegs:$cc, i32imm:$simm11, IntRegs:$f, CCOp:$cond),
1482              "mov$cond $cc, $simm11, $rd", []>;
1483     def V9FMOVS_FCC
1484       : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
1485              (ins FCCRegs:$opf_cc, FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
1486              "fmovs$cond $opf_cc, $rs2, $rd", []>;
1487     def V9FMOVD_FCC
1488       : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
1489              (ins FCCRegs:$opf_cc, DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
1490              "fmovd$cond $opf_cc, $rs2, $rd", []>;
1491     def V9FMOVQ_FCC
1492       : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
1493              (ins FCCRegs:$opf_cc, QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
1494              "fmovq$cond $opf_cc, $rs2, $rd", []>,
1495              Requires<[HasHardQuad]>;
1496   } // Constraints = "$f = $rd", ...
1497 } // let Predicates = [hasV9]
1498
1499
1500 // POPCrr - This does a ctpop of a 64-bit register.  As such, we have to clear
1501 // the top 32-bits before using it.  To do this clearing, we use a SRLri X,0.
1502 let rs1 = 0 in
1503   def POPCrr : F3_1<2, 0b101110,
1504                     (outs IntRegs:$rd), (ins IntRegs:$rs2),
1505                     "popc $rs2, $rd", []>, Requires<[HasV9]>;
1506 def : Pat<(ctpop i32:$src),
1507           (POPCrr (SRLri $src, 0))>;
1508
1509 let Predicates = [HasV9], hasSideEffects = 1, rd = 0, rs1 = 0b01111 in
1510  def MEMBARi : F3_2<2, 0b101000, (outs), (ins simm13Op:$simm13),
1511                     "membar $simm13", []>;
1512
1513 // The CAS instruction, unlike other instructions, only comes in a 
1514 // form which requires an ASI be provided. The ASI value hardcoded 
1515 // here is ASI_PRIMARY, the default unprivileged ASI for SparcV9.
1516 let Predicates = [HasV9], Constraints = "$swap = $rd", asi = 0b10000000 in
1517   def CASrr: F3_1_asi<3, 0b111100,
1518                 (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2,
1519                                      IntRegs:$swap),
1520                  "cas [$rs1], $rs2, $rd",
1521                  [(set i32:$rd,
1522                      (atomic_cmp_swap_32 iPTR:$rs1, i32:$rs2, i32:$swap))]>;
1523
1524
1525 // CASA is supported as an instruction on some LEON3 and all LEON4 processors.
1526 // This version can be automatically lowered from C code, selecting ASI 10
1527 let Predicates = [HasLeonCASA], Constraints = "$swap = $rd", asi = 0b00001010 in
1528   def CASAasi10: F3_1_asi<3, 0b111100,
1529                 (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2,
1530                                      IntRegs:$swap),
1531                  "casa [$rs1] 10, $rs2, $rd",
1532                  [(set i32:$rd,
1533                      (atomic_cmp_swap_32 iPTR:$rs1, i32:$rs2, i32:$swap))]>;
1534                  
1535 // CASA supported on some LEON3 and all LEON4 processors. Same pattern as
1536 // CASrr, above, but with a different ASI. This version is supported for
1537 // inline assembly lowering only. 
1538 let Predicates = [HasLeonCASA], Constraints = "$swap = $rd" in
1539   def CASArr: F3_1_asi<3, 0b111100,
1540                 (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2,
1541                                      IntRegs:$swap, i8imm:$asi),
1542                  "casa [$rs1] $asi, $rs2, $rd", []>;
1543                 
1544 // TODO: Add DAG sequence to lower these instructions. Currently, only provided
1545 // as inline assembler-supported instructions. 
1546 let Predicates = [HasUMAC_SMAC], Defs = [Y, ASR18], Uses = [Y, ASR18] in {
1547   def SMACrr :  F3_1<2, 0b111111,
1548                    (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2, ASRRegs:$asr18),
1549                    "smac $rs1, $rs2, $rd",
1550                    [], IIC_smac_umac>;
1551
1552   def SMACri :  F3_2<2, 0b111111,
1553                   (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13, ASRRegs:$asr18),
1554                    "smac $rs1, $simm13, $rd",
1555                    [], IIC_smac_umac>;
1556                  
1557   def UMACrr :  F3_1<2, 0b111110,
1558                   (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2, ASRRegs:$asr18),
1559                    "umac $rs1, $rs2, $rd",
1560                    [], IIC_smac_umac>;
1561                  
1562   def UMACri :  F3_2<2, 0b111110,
1563                   (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13, ASRRegs:$asr18),
1564                    "umac $rs1, $simm13, $rd",
1565                    [], IIC_smac_umac>;
1566 }
1567
1568 let Defs = [ICC] in {
1569 defm TADDCC   : F3_12np<"taddcc",   0b100000>;
1570 defm TSUBCC   : F3_12np<"tsubcc",   0b100001>;
1571
1572 let hasSideEffects = 1 in {
1573   defm TADDCCTV : F3_12np<"taddcctv", 0b100010>;
1574   defm TSUBCCTV : F3_12np<"tsubcctv", 0b100011>;
1575 }
1576 }
1577
1578
1579 // Section A.43 - Read Privileged Register Instructions
1580 let Predicates = [HasV9] in {
1581 let rs2 = 0 in
1582   def RDPR : F3_1<2, 0b101010,
1583                  (outs IntRegs:$rd), (ins PRRegs:$rs1),
1584                  "rdpr $rs1, $rd", []>;
1585 }
1586
1587 // Section A.62 - Write Privileged Register Instructions
1588 let Predicates = [HasV9] in {
1589   def WRPRrr : F3_1<2, 0b110010,
1590                    (outs PRRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
1591                    "wrpr $rs1, $rs2, $rd", []>;
1592   def WRPRri : F3_2<2, 0b110010,
1593                    (outs PRRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
1594                    "wrpr $rs1, $simm13, $rd", []>;
1595 }
1596
1597 //===----------------------------------------------------------------------===//
1598 // Non-Instruction Patterns
1599 //===----------------------------------------------------------------------===//
1600
1601 // Small immediates.
1602 def : Pat<(i32 simm13:$val),
1603           (ORri (i32 G0), imm:$val)>;
1604 // Arbitrary immediates.
1605 def : Pat<(i32 imm:$val),
1606           (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
1607
1608
1609 // Global addresses, constant pool entries
1610 let Predicates = [Is32Bit] in {
1611
1612 def : Pat<(SPhi tglobaladdr:$in), (SETHIi tglobaladdr:$in)>;
1613 def : Pat<(SPlo tglobaladdr:$in), (ORri (i32 G0), tglobaladdr:$in)>;
1614 def : Pat<(SPhi tconstpool:$in), (SETHIi tconstpool:$in)>;
1615 def : Pat<(SPlo tconstpool:$in), (ORri (i32 G0), tconstpool:$in)>;
1616
1617 // GlobalTLS addresses
1618 def : Pat<(SPhi tglobaltlsaddr:$in), (SETHIi tglobaltlsaddr:$in)>;
1619 def : Pat<(SPlo tglobaltlsaddr:$in), (ORri (i32 G0), tglobaltlsaddr:$in)>;
1620 def : Pat<(add (SPhi tglobaltlsaddr:$in1), (SPlo tglobaltlsaddr:$in2)),
1621           (ADDri (SETHIi tglobaltlsaddr:$in1), (tglobaltlsaddr:$in2))>;
1622 def : Pat<(xor (SPhi tglobaltlsaddr:$in1), (SPlo tglobaltlsaddr:$in2)),
1623           (XORri (SETHIi tglobaltlsaddr:$in1), (tglobaltlsaddr:$in2))>;
1624
1625 // Blockaddress
1626 def : Pat<(SPhi tblockaddress:$in), (SETHIi tblockaddress:$in)>;
1627 def : Pat<(SPlo tblockaddress:$in), (ORri (i32 G0), tblockaddress:$in)>;
1628
1629 // Add reg, lo.  This is used when taking the addr of a global/constpool entry.
1630 def : Pat<(add iPTR:$r, (SPlo tglobaladdr:$in)), (ADDri $r, tglobaladdr:$in)>;
1631 def : Pat<(add iPTR:$r, (SPlo tconstpool:$in)),  (ADDri $r, tconstpool:$in)>;
1632 def : Pat<(add iPTR:$r, (SPlo tblockaddress:$in)),
1633                         (ADDri $r, tblockaddress:$in)>;
1634 }
1635
1636 // Calls:
1637 def : Pat<(call tglobaladdr:$dst),
1638           (CALL tglobaladdr:$dst)>;
1639 def : Pat<(call texternalsym:$dst),
1640           (CALL texternalsym:$dst)>;
1641
1642 // Map integer extload's to zextloads.
1643 def : Pat<(i32 (extloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1644 def : Pat<(i32 (extloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1645 def : Pat<(i32 (extloadi8 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1646 def : Pat<(i32 (extloadi8 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1647 def : Pat<(i32 (extloadi16 ADDRrr:$src)), (LDUHrr ADDRrr:$src)>;
1648 def : Pat<(i32 (extloadi16 ADDRri:$src)), (LDUHri ADDRri:$src)>;
1649
1650 // zextload bool -> zextload byte
1651 def : Pat<(i32 (zextloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1652 def : Pat<(i32 (zextloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1653
1654 // store 0, addr -> store %g0, addr
1655 def : Pat<(store (i32 0), ADDRrr:$dst), (STrr ADDRrr:$dst, (i32 G0))>;
1656 def : Pat<(store (i32 0), ADDRri:$dst), (STri ADDRri:$dst, (i32 G0))>;
1657
1658 // store bar for all atomic_fence in V8.
1659 let Predicates = [HasNoV9] in
1660   def : Pat<(atomic_fence imm, imm), (STBAR)>;
1661
1662 // atomic_load addr -> load addr
1663 def : Pat<(i32 (atomic_load_8 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1664 def : Pat<(i32 (atomic_load_8 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1665 def : Pat<(i32 (atomic_load_16 ADDRrr:$src)), (LDUHrr ADDRrr:$src)>;
1666 def : Pat<(i32 (atomic_load_16 ADDRri:$src)), (LDUHri ADDRri:$src)>;
1667 def : Pat<(i32 (atomic_load_32 ADDRrr:$src)), (LDrr ADDRrr:$src)>;
1668 def : Pat<(i32 (atomic_load_32 ADDRri:$src)), (LDri ADDRri:$src)>;
1669
1670 // atomic_store val, addr -> store val, addr
1671 def : Pat<(atomic_store_8 ADDRrr:$dst, i32:$val), (STBrr ADDRrr:$dst, $val)>;
1672 def : Pat<(atomic_store_8 ADDRri:$dst, i32:$val), (STBri ADDRri:$dst, $val)>;
1673 def : Pat<(atomic_store_16 ADDRrr:$dst, i32:$val), (STHrr ADDRrr:$dst, $val)>;
1674 def : Pat<(atomic_store_16 ADDRri:$dst, i32:$val), (STHri ADDRri:$dst, $val)>;
1675 def : Pat<(atomic_store_32 ADDRrr:$dst, i32:$val), (STrr ADDRrr:$dst, $val)>;
1676 def : Pat<(atomic_store_32 ADDRri:$dst, i32:$val), (STri ADDRri:$dst, $val)>;
1677
1678 // extract_vector
1679 def : Pat<(extractelt (v2i32 IntPair:$Rn), 0),
1680           (i32 (EXTRACT_SUBREG IntPair:$Rn, sub_even))>;
1681 def : Pat<(extractelt (v2i32 IntPair:$Rn), 1),
1682           (i32 (EXTRACT_SUBREG IntPair:$Rn, sub_odd))>;
1683
1684 // build_vector
1685 def : Pat<(build_vector (i32 IntRegs:$a1), (i32 IntRegs:$a2)),
1686           (INSERT_SUBREG
1687             (INSERT_SUBREG (v2i32 (IMPLICIT_DEF)), (i32 IntRegs:$a1), sub_even),
1688             (i32 IntRegs:$a2), sub_odd)>;
1689
1690
1691 include "SparcInstr64Bit.td"
1692 include "SparcInstrVIS.td"
1693 include "SparcInstrAliases.td"