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