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