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