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