blob: f1944437de8cdbe8bc2b65a4c8c24e5e57a273ec [file] [log] [blame]
Chris Lattner17f2cf02005-10-10 06:00:30 +00001//===- TargetSelectionDAG.td - Common code for DAG isels ---*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner4ee451d2007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattner17f2cf02005-10-10 06:00:30 +00007//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the target-independent interfaces used by SelectionDAG
11// instruction selection generators.
12//
13//===----------------------------------------------------------------------===//
14
15//===----------------------------------------------------------------------===//
16// Selection DAG Type Constraint definitions.
17//
18// Note that the semantics of these constraints are hard coded into tblgen. To
19// modify or add constraints, you have to hack tblgen.
20//
21
22class SDTypeConstraint<int opnum> {
23 int OperandNum = opnum;
24}
25
26// SDTCisVT - The specified operand has exactly this VT.
Chris Lattnerd8fe3b32005-12-09 22:58:42 +000027class SDTCisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
Chris Lattner17f2cf02005-10-10 06:00:30 +000028 ValueType VT = vt;
29}
30
Chris Lattnerd8fe3b32005-12-09 22:58:42 +000031class SDTCisPtrTy<int OpNum> : SDTypeConstraint<OpNum>;
32
Chris Lattner17f2cf02005-10-10 06:00:30 +000033// SDTCisInt - The specified operand is has integer type.
34class SDTCisInt<int OpNum> : SDTypeConstraint<OpNum>;
35
36// SDTCisFP - The specified operand is has floating point type.
Chris Lattnerd8fe3b32005-12-09 22:58:42 +000037class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
Chris Lattner17f2cf02005-10-10 06:00:30 +000038
39// SDTCisSameAs - The two specified operands have identical types.
40class SDTCisSameAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
41 int OtherOperandNum = OtherOp;
42}
43
44// SDTCisVTSmallerThanOp - The specified operand is a VT SDNode, and its type is
45// smaller than the 'Other' operand.
46class SDTCisVTSmallerThanOp<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
47 int OtherOperandNum = OtherOp;
48}
49
Chris Lattner13664a62005-10-14 04:55:10 +000050class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
51 int BigOperandNum = BigOp;
52}
53
Chris Lattnerfa818d02006-03-20 05:40:45 +000054/// SDTCisIntVectorOfSameSize - This indicates that ThisOp and OtherOp are
Dan Gohman07a96762007-07-16 14:29:03 +000055/// vector types, and that ThisOp is the result of
Chris Lattnerfa818d02006-03-20 05:40:45 +000056/// MVT::getIntVectorWithNumElements with the number of elements that ThisOp
57/// has.
58class SDTCisIntVectorOfSameSize<int ThisOp, int OtherOp>
59 : SDTypeConstraint<ThisOp> {
60 int OtherOpNum = OtherOp;
61}
62
Nate Begemanb5af3342008-02-09 01:37:05 +000063/// SDTCisEltOfVec - This indicates that ThisOp is a scalar type of the same
64/// type as the element type of OtherOp, which is a vector type.
65class SDTCisEltOfVec<int ThisOp, int OtherOp>
66 : SDTypeConstraint<ThisOp> {
67 int OtherOpNum = OtherOp;
68}
69
Chris Lattner17f2cf02005-10-10 06:00:30 +000070//===----------------------------------------------------------------------===//
71// Selection DAG Type Profile definitions.
72//
73// These use the constraints defined above to describe the type requirements of
74// the various nodes. These are not hard coded into tblgen, allowing targets to
75// add their own if needed.
76//
77
78// SDTypeProfile - This profile describes the type requirements of a Selection
79// DAG node.
80class SDTypeProfile<int numresults, int numoperands,
81 list<SDTypeConstraint> constraints> {
82 int NumResults = numresults;
83 int NumOperands = numoperands;
84 list<SDTypeConstraint> Constraints = constraints;
85}
86
87// Builtin profiles.
Chris Lattner84384542005-12-11 07:45:04 +000088def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>; // for 'imm'.
Evan Cheng0a3a5e22006-01-05 02:07:49 +000089def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>; // for 'fpimm'.
Chris Lattner84384542005-12-11 07:45:04 +000090def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; // for '&g'.
Evan Chengf8ac8142005-12-04 08:13:17 +000091def SDTOther : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
Chris Lattner97898262005-10-25 21:03:14 +000092def SDTUNDEF : SDTypeProfile<1, 0, []>; // for 'undef'.
Chris Lattnerc29e1262006-03-16 01:29:53 +000093def SDTUnaryOp : SDTypeProfile<1, 1, []>; // bitconvert
94
Chris Lattner17f2cf02005-10-10 06:00:30 +000095def SDTIntBinOp : SDTypeProfile<1, 2, [ // add, and, or, xor, udiv, etc.
96 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
97]>;
Chris Lattner68bfd9c2005-12-05 02:37:26 +000098def SDTIntShiftOp : SDTypeProfile<1, 2, [ // shl, sra, srl
99 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
100]>;
Chris Lattner17f2cf02005-10-10 06:00:30 +0000101def SDTFPBinOp : SDTypeProfile<1, 2, [ // fadd, fmul, etc.
102 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
103]>;
Andrew Lenharthd26b8f92006-03-09 17:47:22 +0000104def SDTFPSignOp : SDTypeProfile<1, 2, [ // fcopysign.
105 SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
106]>;
Nate Begeman993aeb22005-12-13 22:55:22 +0000107def SDTFPTernaryOp : SDTypeProfile<1, 3, [ // fmadd, fnmsub, etc.
108 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
109]>;
Chris Lattner17f2cf02005-10-10 06:00:30 +0000110def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // ctlz
111 SDTCisSameAs<0, 1>, SDTCisInt<0>
112]>;
Chris Lattner444215d2005-10-14 06:40:20 +0000113def SDTIntExtendOp : SDTypeProfile<1, 1, [ // sext, zext, anyext
114 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>
115]>;
116def SDTIntTruncOp : SDTypeProfile<1, 1, [ // trunc
117 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>
118]>;
Chris Lattner17f2cf02005-10-10 06:00:30 +0000119def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
120 SDTCisSameAs<0, 1>, SDTCisFP<0>
121]>;
Chris Lattner13664a62005-10-14 04:55:10 +0000122def SDTFPRoundOp : SDTypeProfile<1, 1, [ // fround
123 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>
124]>;
125def SDTFPExtendOp : SDTypeProfile<1, 1, [ // fextend
126 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>
127]>;
Duraid Madinae2fd9e22005-11-01 03:07:25 +0000128def SDTIntToFPOp : SDTypeProfile<1, 1, [ // [su]int_to_fp
129 SDTCisFP<0>, SDTCisInt<1>
130]>;
131def SDTFPToIntOp : SDTypeProfile<1, 1, [ // fp_to_[su]int
132 SDTCisInt<0>, SDTCisFP<1>
133]>;
Chris Lattner17f2cf02005-10-10 06:00:30 +0000134def SDTExtInreg : SDTypeProfile<1, 2, [ // sext_inreg
135 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
136 SDTCisVTSmallerThanOp<2, 1>
137]>;
138
Chris Lattner1f426de2005-10-26 17:00:25 +0000139def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
140 SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
141]>;
142
Duraid Madina59669552005-11-02 02:37:18 +0000143def SDTSelect : SDTypeProfile<1, 3, [ // select
144 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
145]>;
146
Chris Lattnerd2c339c2005-12-11 18:43:13 +0000147def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
Chris Lattner3aed79e2005-12-11 08:35:54 +0000148 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
149 SDTCisVT<5, OtherVT>
150]>;
151
Evan Chengf8ac8142005-12-04 08:13:17 +0000152def SDTBr : SDTypeProfile<0, 1, [ // br
153 SDTCisVT<0, OtherVT>
154]>;
155
Andrew Lenharth993ff1c2006-01-01 22:16:43 +0000156def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
157 SDTCisInt<0>, SDTCisVT<1, OtherVT>
158]>;
159
Nate Begeman37efe672006-04-22 18:53:45 +0000160def SDTBrind : SDTypeProfile<0, 1, [ // brind
161 SDTCisPtrTy<0>
162]>;
163
Chris Lattner48be23c2008-01-15 22:02:54 +0000164def SDTNone : SDTypeProfile<0, 0, []>; // ret, trap
Evan Chengf8ac8142005-12-04 08:13:17 +0000165
Evan Chengf20da7e2005-12-08 04:28:48 +0000166def SDTLoad : SDTypeProfile<1, 1, [ // load
Chris Lattnerd8fe3b32005-12-09 22:58:42 +0000167 SDTCisPtrTy<1>
Evan Chengf20da7e2005-12-08 04:28:48 +0000168]>;
169
Evan Chengb51a0592005-12-10 00:48:20 +0000170def SDTStore : SDTypeProfile<0, 2, [ // store
Evan Chengb612ff92005-12-10 01:59:36 +0000171 SDTCisPtrTy<1>
Evan Chengb51a0592005-12-10 00:48:20 +0000172]>;
173
Evan Cheng81fd6072006-11-08 23:02:11 +0000174def SDTIStore : SDTypeProfile<1, 3, [ // indexed store
175 SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
176]>;
177
Chris Lattnerfa818d02006-03-20 05:40:45 +0000178def SDTVecShuffle : SDTypeProfile<1, 3, [
179 SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisIntVectorOfSameSize<3, 0>
180]>;
Nate Begemanb5af3342008-02-09 01:37:05 +0000181def SDTVecExtract : SDTypeProfile<1, 2, [ // vector extract
182 SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
183]>;
Nate Begeman14d12ca2008-02-11 04:19:36 +0000184def SDTVecInsert : SDTypeProfile<1, 3, [ // vector insert
185 SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
Nate Begemanb5af3342008-02-09 01:37:05 +0000186]>;
Chris Lattnerfa818d02006-03-20 05:40:45 +0000187
Evan Cheng27b7db52008-03-08 00:58:38 +0000188def STDPrefetch : SDTypeProfile<0, 3, [ // prefetch
189 SDTCisPtrTy<0>, SDTCisSameAs<1, 2>, SDTCisInt<1>
190]>;
191
192def STDMemBarrier : SDTypeProfile<0, 5, [ // memory barier
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +0000193 SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
194 SDTCisInt<0>
195]>;
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000196def STDAtomic3 : SDTypeProfile<1, 3, [
197 SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
198]>;
199def STDAtomic2 : SDTypeProfile<1, 2, [
200 SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
201]>;
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +0000202
Bill Wendlingc69107c2007-11-13 09:19:02 +0000203class SDCallSeqStart<list<SDTypeConstraint> constraints> :
204 SDTypeProfile<0, 1, constraints>;
205class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
206 SDTypeProfile<0, 2, constraints>;
207
Chris Lattner17f2cf02005-10-10 06:00:30 +0000208//===----------------------------------------------------------------------===//
209// Selection DAG Node Properties.
210//
211// Note: These are hard coded into tblgen.
212//
213class SDNodeProperty;
214def SDNPCommutative : SDNodeProperty; // X op Y == Y op X
215def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z)
Evan Chengf8ac8142005-12-04 08:13:17 +0000216def SDNPHasChain : SDNodeProperty; // R/W chain operand and result
Evan Cheng6da8d992006-01-09 18:28:21 +0000217def SDNPOutFlag : SDNodeProperty; // Write a flag result
218def SDNPInFlag : SDNodeProperty; // Read a flag operand
219def SDNPOptInFlag : SDNodeProperty; // Optionally read a flag operand
Chris Lattner2e48a702008-01-06 08:36:04 +0000220def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'.
Chris Lattner8947dd52008-01-10 04:44:32 +0000221def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'.
Chris Lattnerb8f217f2008-01-10 05:48:23 +0000222def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'.
Chris Lattner17f2cf02005-10-10 06:00:30 +0000223
224//===----------------------------------------------------------------------===//
225// Selection DAG Node definitions.
226//
227class SDNode<string opcode, SDTypeProfile typeprof,
228 list<SDNodeProperty> props = [], string sdclass = "SDNode"> {
229 string Opcode = opcode;
230 string SDClass = sdclass;
231 list<SDNodeProperty> Properties = props;
232 SDTypeProfile TypeProfile = typeprof;
233}
234
235def set;
Evan Chengd23aa5a2007-09-25 01:48:59 +0000236def implicit;
Evan Cheng85dbe1a2007-09-12 23:30:14 +0000237def parallel;
Chris Lattner17f2cf02005-10-10 06:00:30 +0000238def node;
Evan Cheng3d2331d2005-12-14 02:21:01 +0000239def srcvalue;
Chris Lattner17f2cf02005-10-10 06:00:30 +0000240
Chris Lattner84384542005-12-11 07:45:04 +0000241def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
Nate Begemane1795842008-02-14 08:57:00 +0000242def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
Evan Chengf8ac8142005-12-04 08:13:17 +0000243def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
244def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
245def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
Chris Lattner97898262005-10-25 21:03:14 +0000246def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
Andrew Lenharth330851a2005-12-24 23:36:59 +0000247def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
Chris Lattnerdb40dc22005-11-17 07:20:15 +0000248 "GlobalAddressSDNode">;
Andrew Lenharth330851a2005-12-24 23:36:59 +0000249def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
250 "GlobalAddressSDNode">;
Lauro Ramos Venanciob3a04172007-04-20 21:38:10 +0000251def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
252 "GlobalAddressSDNode">;
253def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
254 "GlobalAddressSDNode">;
Andrew Lenharth330851a2005-12-24 23:36:59 +0000255def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
256 "ConstantPoolSDNode">;
257def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
258 "ConstantPoolSDNode">;
Nate Begeman37efe672006-04-22 18:53:45 +0000259def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
260 "JumpTableSDNode">;
261def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
262 "JumpTableSDNode">;
Andrew Lenharth330851a2005-12-24 23:36:59 +0000263def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
264 "FrameIndexSDNode">;
265def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
266 "FrameIndexSDNode">;
267def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
268 "ExternalSymbolSDNode">;
269def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
270 "ExternalSymbolSDNode">;
271
Chris Lattner17f2cf02005-10-10 06:00:30 +0000272def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
273 [SDNPCommutative, SDNPAssociative]>;
274def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
275def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
276 [SDNPCommutative, SDNPAssociative]>;
277def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
278def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
279def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
280def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
281def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
282def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
Chris Lattner68bfd9c2005-12-05 02:37:26 +0000283def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
284def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
285def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
Nate Begeman35ef9132006-01-11 21:21:00 +0000286def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
287def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
Chris Lattner17f2cf02005-10-10 06:00:30 +0000288def and : SDNode<"ISD::AND" , SDTIntBinOp,
289 [SDNPCommutative, SDNPAssociative]>;
290def or : SDNode<"ISD::OR" , SDTIntBinOp,
291 [SDNPCommutative, SDNPAssociative]>;
292def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
293 [SDNPCommutative, SDNPAssociative]>;
Nate Begeman551bf3f2006-02-17 05:43:56 +0000294def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
295 [SDNPCommutative, SDNPOutFlag]>;
296def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
297 [SDNPCommutative, SDNPOutFlag, SDNPInFlag]>;
298def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
299 [SDNPOutFlag]>;
300def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
301 [SDNPOutFlag, SDNPInFlag]>;
Chris Lattner444215d2005-10-14 06:40:20 +0000302
303def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
Nate Begemand88fc032006-01-14 03:14:10 +0000304def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
Chris Lattner444215d2005-10-14 06:40:20 +0000305def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
Andrew Lenharthd684e1a2005-10-20 19:38:11 +0000306def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
307def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
Chris Lattner444215d2005-10-14 06:40:20 +0000308def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
309def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
310def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
311def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
Chris Lattnerc29e1262006-03-16 01:29:53 +0000312def bitconvert : SDNode<"ISD::BIT_CONVERT", SDTUnaryOp>;
Nate Begemanb5af3342008-02-09 01:37:05 +0000313def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
314def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
315
Chris Lattner444215d2005-10-14 06:40:20 +0000316
Chris Lattner17f2cf02005-10-10 06:00:30 +0000317def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
318def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
319def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
320def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
321def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
322def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
323def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
324def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
Chris Lattner5c82f4d2005-12-21 16:22:46 +0000325def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
326def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
Chris Lattner17f2cf02005-10-10 06:00:30 +0000327
Chris Lattner13664a62005-10-14 04:55:10 +0000328def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
329def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
Andrew Lenharthd26b8f92006-03-09 17:47:22 +0000330def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
Chris Lattner13664a62005-10-14 04:55:10 +0000331
Duraid Madinae2fd9e22005-11-01 03:07:25 +0000332def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
333def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
334def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
335def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
336
Chris Lattner1f426de2005-10-26 17:00:25 +0000337def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
Duraid Madina59669552005-11-02 02:37:18 +0000338def select : SDNode<"ISD::SELECT" , SDTSelect>;
Chris Lattner3aed79e2005-12-11 08:35:54 +0000339def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
Nate Begemanb43e9c12008-05-12 19:40:03 +0000340def vsetcc : SDNode<"ISD::VSETCC" , SDTSetCC>;
Chris Lattner1f426de2005-10-26 17:00:25 +0000341
Andrew Lenharth993ff1c2006-01-01 22:16:43 +0000342def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
Nate Begeman37efe672006-04-22 18:53:45 +0000343def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
Evan Chengf8ac8142005-12-04 08:13:17 +0000344def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
Chris Lattner48be23c2008-01-15 22:02:54 +0000345def ret : SDNode<"ISD::RET" , SDTNone, [SDNPHasChain]>;
346def trap : SDNode<"ISD::TRAP" , SDTNone,
347 [SDNPHasChain, SDNPSideEffect]>;
Evan Cheng27b7db52008-03-08 00:58:38 +0000348
349def prefetch : SDNode<"ISD::PREFETCH" , STDPrefetch,
350 [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
351
352def membarrier : SDNode<"ISD::MEMBARRIER" , STDMemBarrier,
Andrew Lenharth22c5c1b2008-02-16 01:24:58 +0000353 [SDNPHasChain, SDNPSideEffect]>;
Evan Cheng27b7db52008-03-08 00:58:38 +0000354
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000355// Do not use atomic_* directly, use atomic_*_size (see below)
Evan Cheng27b7db52008-03-08 00:58:38 +0000356def atomic_lcs : SDNode<"ISD::ATOMIC_LCS" , STDAtomic3,
357 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
358def atomic_las : SDNode<"ISD::ATOMIC_LAS" , STDAtomic2,
359 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000360def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", STDAtomic2,
Evan Cheng27b7db52008-03-08 00:58:38 +0000361 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
Mon P Wang63307c32008-05-05 19:05:59 +0000362def atomic_lss : SDNode<"ISD::ATOMIC_LSS" , STDAtomic2,
363 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
364def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , STDAtomic2,
365 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
366def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , STDAtomic2,
367 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
368def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , STDAtomic2,
369 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
370def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", STDAtomic2,
371 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
372def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", STDAtomic2,
373 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
374def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", STDAtomic2,
375 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
376def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", STDAtomic2,
377 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
Evan Chengf8ac8142005-12-04 08:13:17 +0000378
Evan Cheng8b2794a2006-10-13 21:14:26 +0000379// Do not use ld, st directly. Use load, extload, sextload, zextload, store,
380// and truncst (see below).
Chris Lattner8947dd52008-01-10 04:44:32 +0000381def ld : SDNode<"ISD::LOAD" , SDTLoad,
382 [SDNPHasChain, SDNPMayLoad]>;
Chris Lattnerc8478d82008-01-06 06:44:58 +0000383def st : SDNode<"ISD::STORE" , SDTStore,
384 [SDNPHasChain, SDNPMayStore]>;
385def ist : SDNode<"ISD::STORE" , SDTIStore,
386 [SDNPHasChain, SDNPMayStore]>;
Evan Cheng3d2331d2005-12-14 02:21:01 +0000387
Chris Lattnerfa818d02006-03-20 05:40:45 +0000388def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
Chris Lattner39afef32006-03-20 06:18:01 +0000389def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, 0, []>, []>;
Evan Cheng811ec1c2006-03-21 00:33:35 +0000390def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
391 []>;
Evan Cheng1eda6e72006-03-31 19:21:16 +0000392def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
Evan Cheng31f7be92006-06-15 08:19:05 +0000393 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
Evan Cheng1eda6e72006-03-31 19:21:16 +0000394def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
Evan Cheng31f7be92006-06-15 08:19:05 +0000395 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
Christopher Lamb557c3632007-07-26 07:34:40 +0000396
397def extract_subreg : SDNode<"ISD::EXTRACT_SUBREG",
398 SDTypeProfile<1, 2, []>>;
399def insert_subreg : SDNode<"ISD::INSERT_SUBREG",
400 SDTypeProfile<1, 3, []>>;
Chris Lattnerfa818d02006-03-20 05:40:45 +0000401
Chris Lattnerea93f632006-03-25 02:29:35 +0000402// Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
403// these internally. Don't reference these directly.
Chris Lattner48b61a72006-03-28 00:40:33 +0000404def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
Chris Lattnerea93f632006-03-25 02:29:35 +0000405 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
406 [SDNPHasChain]>;
Chris Lattner48b61a72006-03-28 00:40:33 +0000407def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
Chris Lattnerea93f632006-03-25 02:29:35 +0000408 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
409 [SDNPHasChain]>;
Chris Lattner48b61a72006-03-28 00:40:33 +0000410def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
Chris Lattnerea93f632006-03-25 02:29:35 +0000411 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
412
413
Chris Lattner1f426de2005-10-26 17:00:25 +0000414//===----------------------------------------------------------------------===//
415// Selection DAG Condition Codes
416
417class CondCode; // ISD::CondCode enums
418def SETOEQ : CondCode; def SETOGT : CondCode;
419def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
420def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
421def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
422def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
423
424def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
425def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
426
427
Chris Lattner17f2cf02005-10-10 06:00:30 +0000428//===----------------------------------------------------------------------===//
429// Selection DAG Node Transformation Functions.
430//
431// This mechanism allows targets to manipulate nodes in the output DAG once a
432// match has been formed. This is typically used to manipulate immediate
433// values.
434//
435class SDNodeXForm<SDNode opc, code xformFunction> {
436 SDNode Opcode = opc;
437 code XFormFunction = xformFunction;
438}
439
440def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
441
442
443//===----------------------------------------------------------------------===//
444// Selection DAG Pattern Fragments.
445//
446// Pattern fragments are reusable chunks of dags that match specific things.
447// They can take arguments and have C++ predicates that control whether they
448// match. They are intended to make the patterns for common instructions more
449// compact and readable.
450//
451
452/// PatFrag - Represents a pattern fragment. This can match something on the
453/// DAG, frame a single node to multiply nested other fragments.
454///
455class PatFrag<dag ops, dag frag, code pred = [{}],
456 SDNodeXForm xform = NOOP_SDNodeXForm> {
457 dag Operands = ops;
458 dag Fragment = frag;
459 code Predicate = pred;
460 SDNodeXForm OperandTransform = xform;
461}
462
463// PatLeaf's are pattern fragments that have no operands. This is just a helper
464// to define immediates and other common things concisely.
465class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
466 : PatFrag<(ops), frag, pred, xform>;
467
468// Leaf fragments.
469
Chris Lattner17f2cf02005-10-10 06:00:30 +0000470def vtInt : PatLeaf<(vt), [{ return MVT::isInteger(N->getVT()); }]>;
471def vtFP : PatLeaf<(vt), [{ return MVT::isFloatingPoint(N->getVT()); }]>;
472
Chris Lattnerc985d822006-03-25 23:00:08 +0000473def immAllOnes : PatLeaf<(imm), [{ return N->isAllOnesValue(); }]>;
474def immAllOnesV: PatLeaf<(build_vector), [{
Evan Cheng999f3b52006-03-27 06:59:32 +0000475 return ISD::isBuildVectorAllOnes(N);
Chris Lattnerc985d822006-03-25 23:00:08 +0000476}]>;
Chris Lattner1fcee4e2006-04-15 23:39:14 +0000477def immAllOnesV_bc: PatLeaf<(bitconvert), [{
478 return ISD::isBuildVectorAllOnes(N);
479}]>;
Chris Lattnerffc04d32007-11-24 19:02:07 +0000480def immAllZerosV: PatLeaf<(build_vector), [{
481 return ISD::isBuildVectorAllZeros(N);
482}]>;
483def immAllZerosV_bc: PatLeaf<(bitconvert), [{
484 return ISD::isBuildVectorAllZeros(N);
485}]>;
486
Chris Lattner1fcee4e2006-04-15 23:39:14 +0000487
488
Chris Lattnerc985d822006-03-25 23:00:08 +0000489// Other helper fragments.
Chris Lattner17f2cf02005-10-10 06:00:30 +0000490def not : PatFrag<(ops node:$in), (xor node:$in, immAllOnes)>;
Chris Lattnerc985d822006-03-25 23:00:08 +0000491def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
Chris Lattner1fcee4e2006-04-15 23:39:14 +0000492def vnot_conv : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV_bc)>;
Chris Lattnereae6d642005-10-20 23:30:37 +0000493def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
Chris Lattner17f2cf02005-10-10 06:00:30 +0000494
Evan Cheng87e08132006-10-26 21:55:50 +0000495// load fragments.
Evan Cheng466685d2006-10-09 20:57:25 +0000496def load : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Cheng87e08132006-10-26 21:55:50 +0000497 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
498 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000499 LD->getAddressingMode() == ISD::UNINDEXED;
Evan Cheng87e08132006-10-26 21:55:50 +0000500 return false;
Evan Cheng466685d2006-10-09 20:57:25 +0000501}]>;
502
Evan Cheng8b2794a2006-10-13 21:14:26 +0000503// extending load fragments.
Evan Cheng466685d2006-10-09 20:57:25 +0000504def extloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Cheng87e08132006-10-26 21:55:50 +0000505 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
506 return LD->getExtensionType() == ISD::EXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000507 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000508 LD->getMemoryVT() == MVT::i1;
Evan Cheng466685d2006-10-09 20:57:25 +0000509 return false;
510}]>;
511def extloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Cheng87e08132006-10-26 21:55:50 +0000512 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
513 return LD->getExtensionType() == ISD::EXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000514 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000515 LD->getMemoryVT() == MVT::i8;
Evan Cheng466685d2006-10-09 20:57:25 +0000516 return false;
517}]>;
518def extloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Cheng87e08132006-10-26 21:55:50 +0000519 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
520 return LD->getExtensionType() == ISD::EXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000521 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000522 LD->getMemoryVT() == MVT::i16;
Evan Cheng466685d2006-10-09 20:57:25 +0000523 return false;
524}]>;
525def extloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Cheng87e08132006-10-26 21:55:50 +0000526 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
527 return LD->getExtensionType() == ISD::EXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000528 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000529 LD->getMemoryVT() == MVT::i32;
Evan Cheng466685d2006-10-09 20:57:25 +0000530 return false;
531}]>;
532def extloadf32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Cheng87e08132006-10-26 21:55:50 +0000533 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
534 return LD->getExtensionType() == ISD::EXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000535 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000536 LD->getMemoryVT() == MVT::f32;
Evan Cheng466685d2006-10-09 20:57:25 +0000537 return false;
538}]>;
Dale Johannesen59a58732007-08-05 18:49:15 +0000539def extloadf64 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
540 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
541 return LD->getExtensionType() == ISD::EXTLOAD &&
542 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000543 LD->getMemoryVT() == MVT::f64;
Dale Johannesen59a58732007-08-05 18:49:15 +0000544 return false;
545}]>;
Evan Cheng466685d2006-10-09 20:57:25 +0000546
Evan Cheng87e08132006-10-26 21:55:50 +0000547def sextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
548 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
549 return LD->getExtensionType() == ISD::SEXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000550 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000551 LD->getMemoryVT() == MVT::i1;
Evan Cheng466685d2006-10-09 20:57:25 +0000552 return false;
553}]>;
Evan Cheng87e08132006-10-26 21:55:50 +0000554def sextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
555 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
556 return LD->getExtensionType() == ISD::SEXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000557 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000558 LD->getMemoryVT() == MVT::i8;
Evan Cheng466685d2006-10-09 20:57:25 +0000559 return false;
560}]>;
561def sextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Cheng87e08132006-10-26 21:55:50 +0000562 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
563 return LD->getExtensionType() == ISD::SEXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000564 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000565 LD->getMemoryVT() == MVT::i16;
Evan Cheng466685d2006-10-09 20:57:25 +0000566 return false;
567}]>;
568def sextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Cheng87e08132006-10-26 21:55:50 +0000569 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
570 return LD->getExtensionType() == ISD::SEXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000571 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000572 LD->getMemoryVT() == MVT::i32;
Evan Cheng466685d2006-10-09 20:57:25 +0000573 return false;
574}]>;
575
Evan Cheng87e08132006-10-26 21:55:50 +0000576def zextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
577 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
578 return LD->getExtensionType() == ISD::ZEXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000579 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000580 LD->getMemoryVT() == MVT::i1;
Evan Cheng466685d2006-10-09 20:57:25 +0000581 return false;
582}]>;
Evan Cheng87e08132006-10-26 21:55:50 +0000583def zextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
584 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
585 return LD->getExtensionType() == ISD::ZEXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000586 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000587 LD->getMemoryVT() == MVT::i8;
Evan Cheng466685d2006-10-09 20:57:25 +0000588 return false;
589}]>;
590def zextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Cheng87e08132006-10-26 21:55:50 +0000591 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
592 return LD->getExtensionType() == ISD::ZEXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000593 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000594 LD->getMemoryVT() == MVT::i16;
Evan Cheng466685d2006-10-09 20:57:25 +0000595 return false;
596}]>;
597def zextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Cheng87e08132006-10-26 21:55:50 +0000598 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
599 return LD->getExtensionType() == ISD::ZEXTLOAD &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000600 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000601 LD->getMemoryVT() == MVT::i32;
Evan Cheng466685d2006-10-09 20:57:25 +0000602 return false;
603}]>;
604
Evan Cheng87e08132006-10-26 21:55:50 +0000605// store fragments.
Evan Cheng8b2794a2006-10-13 21:14:26 +0000606def store : PatFrag<(ops node:$val, node:$ptr),
607 (st node:$val, node:$ptr), [{
Evan Cheng81fd6072006-11-08 23:02:11 +0000608 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Chris Lattnerfc14b312006-11-14 19:13:39 +0000609 return !ST->isTruncatingStore() &&
610 ST->getAddressingMode() == ISD::UNINDEXED;
Evan Cheng81fd6072006-11-08 23:02:11 +0000611 return false;
Evan Cheng8b2794a2006-10-13 21:14:26 +0000612}]>;
613
614// truncstore fragments.
Evan Cheng8b2794a2006-10-13 21:14:26 +0000615def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
616 (st node:$val, node:$ptr), [{
Evan Cheng81fd6072006-11-08 23:02:11 +0000617 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000618 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8 &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000619 ST->getAddressingMode() == ISD::UNINDEXED;
Evan Cheng8b2794a2006-10-13 21:14:26 +0000620 return false;
621}]>;
622def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
623 (st node:$val, node:$ptr), [{
Evan Cheng81fd6072006-11-08 23:02:11 +0000624 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000625 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16 &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000626 ST->getAddressingMode() == ISD::UNINDEXED;
Evan Cheng8b2794a2006-10-13 21:14:26 +0000627 return false;
628}]>;
629def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
630 (st node:$val, node:$ptr), [{
Evan Cheng81fd6072006-11-08 23:02:11 +0000631 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000632 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32 &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000633 ST->getAddressingMode() == ISD::UNINDEXED;
Evan Cheng8b2794a2006-10-13 21:14:26 +0000634 return false;
635}]>;
636def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
637 (st node:$val, node:$ptr), [{
Evan Cheng81fd6072006-11-08 23:02:11 +0000638 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000639 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32 &&
Chris Lattnerfc14b312006-11-14 19:13:39 +0000640 ST->getAddressingMode() == ISD::UNINDEXED;
Evan Cheng81fd6072006-11-08 23:02:11 +0000641 return false;
642}]>;
Dale Johannesen59a58732007-08-05 18:49:15 +0000643def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
644 (st node:$val, node:$ptr), [{
645 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000646 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f64 &&
Dale Johannesen59a58732007-08-05 18:49:15 +0000647 ST->getAddressingMode() == ISD::UNINDEXED;
648 return false;
649}]>;
Evan Cheng81fd6072006-11-08 23:02:11 +0000650
651// indexed store fragments.
652def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
653 (ist node:$val, node:$base, node:$offset), [{
654 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000655 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000656 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
657 !ST->isTruncatingStore();
658 }
659 return false;
660}]>;
661
662def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
663 (ist node:$val, node:$base, node:$offset), [{
664 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000665 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000666 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000667 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
Evan Cheng81fd6072006-11-08 23:02:11 +0000668 }
669 return false;
670}]>;
671def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
672 (ist node:$val, node:$base, node:$offset), [{
673 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000674 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000675 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000676 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8;
Evan Cheng81fd6072006-11-08 23:02:11 +0000677 }
678 return false;
679}]>;
680def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
681 (ist node:$val, node:$base, node:$offset), [{
682 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000683 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000684 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000685 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16;
Evan Cheng81fd6072006-11-08 23:02:11 +0000686 }
687 return false;
688}]>;
689def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
690 (ist node:$val, node:$base, node:$offset), [{
691 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000692 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000693 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000694 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32;
Evan Cheng81fd6072006-11-08 23:02:11 +0000695 }
696 return false;
697}]>;
698def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
699 (ist node:$val, node:$base, node:$offset), [{
700 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000701 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000702 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000703 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32;
Evan Cheng81fd6072006-11-08 23:02:11 +0000704 }
705 return false;
706}]>;
707
708def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
709 (ist node:$val, node:$ptr, node:$offset), [{
710 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000711 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000712 return !ST->isTruncatingStore() &&
713 (AM == ISD::POST_INC || AM == ISD::POST_DEC);
714 }
715 return false;
716}]>;
717
718def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
719 (ist node:$val, node:$base, node:$offset), [{
720 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000721 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000722 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000723 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
Evan Cheng81fd6072006-11-08 23:02:11 +0000724 }
725 return false;
726}]>;
727def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
728 (ist node:$val, node:$base, node:$offset), [{
729 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000730 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000731 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000732 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8;
Evan Cheng81fd6072006-11-08 23:02:11 +0000733 }
734 return false;
735}]>;
736def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
737 (ist node:$val, node:$base, node:$offset), [{
738 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000739 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000740 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000741 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16;
Evan Cheng81fd6072006-11-08 23:02:11 +0000742 }
743 return false;
744}]>;
745def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
746 (ist node:$val, node:$base, node:$offset), [{
747 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000748 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000749 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000750 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32;
Evan Cheng81fd6072006-11-08 23:02:11 +0000751 }
752 return false;
753}]>;
754def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
755 (ist node:$val, node:$base, node:$offset), [{
756 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Cheng00305822006-11-09 18:44:21 +0000757 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Cheng81fd6072006-11-08 23:02:11 +0000758 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohmanb625f2f2008-01-30 00:15:11 +0000759 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32;
Evan Cheng81fd6072006-11-08 23:02:11 +0000760 }
Evan Cheng8b2794a2006-10-13 21:14:26 +0000761 return false;
762}]>;
Chris Lattner1f426de2005-10-26 17:00:25 +0000763
Andrew Lenharthab0b9492008-02-21 06:45:13 +0000764//Atomic patterns
765def atomic_lcs_8 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
766 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
767 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
768 return V->getVT() == MVT::i8;
769 return false;
770}]>;
771def atomic_lcs_16 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
772 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
773 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
774 return V->getVT() == MVT::i16;
775 return false;
776}]>;
777def atomic_lcs_32 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
778 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
779 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
780 return V->getVT() == MVT::i32;
781 return false;
782}]>;
783def atomic_lcs_64 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
784 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
785 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
786 return V->getVT() == MVT::i64;
787 return false;
788}]>;
789
790def atomic_las_8 : PatFrag<(ops node:$ptr, node:$inc),
791 (atomic_las node:$ptr, node:$inc), [{
792 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
793 return V->getVT() == MVT::i8;
794 return false;
795}]>;
796def atomic_las_16 : PatFrag<(ops node:$ptr, node:$inc),
797 (atomic_las node:$ptr, node:$inc), [{
798 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
799 return V->getVT() == MVT::i16;
800 return false;
801}]>;
802def atomic_las_32 : PatFrag<(ops node:$ptr, node:$inc),
803 (atomic_las node:$ptr, node:$inc), [{
804 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
805 return V->getVT() == MVT::i32;
806 return false;
807}]>;
808def atomic_las_64 : PatFrag<(ops node:$ptr, node:$inc),
809 (atomic_las node:$ptr, node:$inc), [{
810 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
811 return V->getVT() == MVT::i64;
812 return false;
813}]>;
814
815def atomic_swap_8 : PatFrag<(ops node:$ptr, node:$inc),
816 (atomic_swap node:$ptr, node:$inc), [{
817 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
818 return V->getVT() == MVT::i8;
819 return false;
820}]>;
821def atomic_swap_16 : PatFrag<(ops node:$ptr, node:$inc),
822 (atomic_swap node:$ptr, node:$inc), [{
823 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
824 return V->getVT() == MVT::i16;
825 return false;
826}]>;
827def atomic_swap_32 : PatFrag<(ops node:$ptr, node:$inc),
828 (atomic_swap node:$ptr, node:$inc), [{
829 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
830 return V->getVT() == MVT::i32;
831 return false;
832}]>;
833def atomic_swap_64 : PatFrag<(ops node:$ptr, node:$inc),
834 (atomic_swap node:$ptr, node:$inc), [{
835 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
836 return V->getVT() == MVT::i64;
837 return false;
838}]>;
839
840
841
Chris Lattner1f426de2005-10-26 17:00:25 +0000842// setcc convenience fragments.
843def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
844 (setcc node:$lhs, node:$rhs, SETOEQ)>;
845def setogt : PatFrag<(ops node:$lhs, node:$rhs),
846 (setcc node:$lhs, node:$rhs, SETOGT)>;
847def setoge : PatFrag<(ops node:$lhs, node:$rhs),
848 (setcc node:$lhs, node:$rhs, SETOGE)>;
849def setolt : PatFrag<(ops node:$lhs, node:$rhs),
850 (setcc node:$lhs, node:$rhs, SETOLT)>;
851def setole : PatFrag<(ops node:$lhs, node:$rhs),
852 (setcc node:$lhs, node:$rhs, SETOLE)>;
853def setone : PatFrag<(ops node:$lhs, node:$rhs),
854 (setcc node:$lhs, node:$rhs, SETONE)>;
855def seto : PatFrag<(ops node:$lhs, node:$rhs),
856 (setcc node:$lhs, node:$rhs, SETO)>;
857def setuo : PatFrag<(ops node:$lhs, node:$rhs),
858 (setcc node:$lhs, node:$rhs, SETUO)>;
859def setueq : PatFrag<(ops node:$lhs, node:$rhs),
860 (setcc node:$lhs, node:$rhs, SETUEQ)>;
861def setugt : PatFrag<(ops node:$lhs, node:$rhs),
862 (setcc node:$lhs, node:$rhs, SETUGT)>;
863def setuge : PatFrag<(ops node:$lhs, node:$rhs),
864 (setcc node:$lhs, node:$rhs, SETUGE)>;
865def setult : PatFrag<(ops node:$lhs, node:$rhs),
866 (setcc node:$lhs, node:$rhs, SETULT)>;
867def setule : PatFrag<(ops node:$lhs, node:$rhs),
868 (setcc node:$lhs, node:$rhs, SETULE)>;
869def setune : PatFrag<(ops node:$lhs, node:$rhs),
870 (setcc node:$lhs, node:$rhs, SETUNE)>;
871def seteq : PatFrag<(ops node:$lhs, node:$rhs),
872 (setcc node:$lhs, node:$rhs, SETEQ)>;
873def setgt : PatFrag<(ops node:$lhs, node:$rhs),
874 (setcc node:$lhs, node:$rhs, SETGT)>;
875def setge : PatFrag<(ops node:$lhs, node:$rhs),
876 (setcc node:$lhs, node:$rhs, SETGE)>;
877def setlt : PatFrag<(ops node:$lhs, node:$rhs),
878 (setcc node:$lhs, node:$rhs, SETLT)>;
879def setle : PatFrag<(ops node:$lhs, node:$rhs),
880 (setcc node:$lhs, node:$rhs, SETLE)>;
881def setne : PatFrag<(ops node:$lhs, node:$rhs),
882 (setcc node:$lhs, node:$rhs, SETNE)>;
883
Chris Lattner17f2cf02005-10-10 06:00:30 +0000884//===----------------------------------------------------------------------===//
885// Selection DAG Pattern Support.
886//
887// Patterns are what are actually matched against the target-flavored
888// instruction selection DAG. Instructions defined by the target implicitly
889// define patterns in most cases, but patterns can also be explicitly added when
890// an operation is defined by a sequence of instructions (e.g. loading a large
891// immediate value on RISC targets that do not support immediates as large as
892// their GPRs).
893//
894
895class Pattern<dag patternToMatch, list<dag> resultInstrs> {
Evan Chengf5e1dc22006-04-19 20:38:28 +0000896 dag PatternToMatch = patternToMatch;
897 list<dag> ResultInstrs = resultInstrs;
898 list<Predicate> Predicates = []; // See class Instruction in Target.td.
899 int AddedComplexity = 0; // See class Instruction in Target.td.
Chris Lattner17f2cf02005-10-10 06:00:30 +0000900}
901
902// Pat - A simple (but common) form of a pattern, which produces a simple result
903// not needing a full list.
904class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
905
Evan Chengf20da7e2005-12-08 04:28:48 +0000906//===----------------------------------------------------------------------===//
907// Complex pattern definitions.
908//
Christopher Lamb85356242008-01-31 07:27:46 +0000909
910class CPAttribute;
911// Pass the parent Operand as root to CP function rather
912// than the root of the sub-DAG
913def CPAttrParentAsRoot : CPAttribute;
914
Evan Chengf20da7e2005-12-08 04:28:48 +0000915// Complex patterns, e.g. X86 addressing mode, requires pattern matching code
916// in C++. NumOperands is the number of operands returned by the select function;
917// SelectFunc is the name of the function used to pattern match the max. pattern;
918// RootNodes are the list of possible root nodes of the sub-dags to match.
919// e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
920//
Evan Chengaf9db752006-10-11 21:03:53 +0000921class ComplexPattern<ValueType ty, int numops, string fn,
Christopher Lamb85356242008-01-31 07:27:46 +0000922 list<SDNode> roots = [], list<SDNodeProperty> props = [],
923 list<CPAttribute> attrs = []> {
Evan Chengf20da7e2005-12-08 04:28:48 +0000924 ValueType Ty = ty;
925 int NumOperands = numops;
926 string SelectFunc = fn;
927 list<SDNode> RootNodes = roots;
Evan Chengaf9db752006-10-11 21:03:53 +0000928 list<SDNodeProperty> Properties = props;
Christopher Lamb85356242008-01-31 07:27:46 +0000929 list<CPAttribute> Attributes = attrs;
Evan Chengf20da7e2005-12-08 04:28:48 +0000930}
Jim Laskeyf5395ce2005-12-16 22:45:29 +0000931
932//===----------------------------------------------------------------------===//
933// Dwarf support.
934//
Jim Laskeyabf6d172006-01-05 01:25:28 +0000935def SDT_dwarf_loc : SDTypeProfile<0, 3,
936 [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
937def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;