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