blob: eeed99429694f67b63d117e35bdcb53af43231bb [file] [log] [blame]
Chris Lattnerd83571b2005-10-10 06:00:30 +00001//===- TargetSelectionDAG.td - Common code for DAG isels ---*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattnerf3ebc3f2007-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 Lattnerd83571b2005-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 Lattner27656ac2005-12-09 22:58:42 +000027class SDTCisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
Chris Lattnerd83571b2005-10-10 06:00:30 +000028 ValueType VT = vt;
29}
30
Chris Lattner27656ac2005-12-09 22:58:42 +000031class SDTCisPtrTy<int OpNum> : SDTypeConstraint<OpNum>;
32
Chris Lattnerd83571b2005-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 Lattner27656ac2005-12-09 22:58:42 +000037class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
Chris Lattnerd83571b2005-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 Lattner6e83cbf2005-10-14 04:55:10 +000050class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
51 int BigOperandNum = BigOp;
52}
53
Chris Lattnere4e1ac372006-03-20 05:40:45 +000054/// SDTCisIntVectorOfSameSize - This indicates that ThisOp and OtherOp are
Dan Gohman06c60b62007-07-16 14:29:03 +000055/// vector types, and that ThisOp is the result of
Chris Lattnere4e1ac372006-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 Begeman17bedbc2008-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 Lattnerd83571b2005-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 Lattnere6f2c822005-12-11 07:45:04 +000088def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>; // for 'imm'.
Evan Chenge0d1b652006-01-05 02:07:49 +000089def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>; // for 'fpimm'.
Chris Lattnere6f2c822005-12-11 07:45:04 +000090def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; // for '&g'.
Evan Chenge8531382005-12-04 08:13:17 +000091def SDTOther : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
Chris Lattner3a4b1412005-10-25 21:03:14 +000092def SDTUNDEF : SDTypeProfile<1, 0, []>; // for 'undef'.
Chris Lattner4b41e402006-03-16 01:29:53 +000093def SDTUnaryOp : SDTypeProfile<1, 1, []>; // bitconvert
94
Chris Lattnerd83571b2005-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 Lattner282c2af2005-12-05 02:37:26 +000098def SDTIntShiftOp : SDTypeProfile<1, 2, [ // shl, sra, srl
99 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
100]>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000101def SDTFPBinOp : SDTypeProfile<1, 2, [ // fadd, fmul, etc.
102 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
103]>;
Andrew Lenharthebfd94f2006-03-09 17:47:22 +0000104def SDTFPSignOp : SDTypeProfile<1, 2, [ // fcopysign.
105 SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
106]>;
Nate Begeman69caef22005-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 Lattnerd83571b2005-10-10 06:00:30 +0000110def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // ctlz
111 SDTCisSameAs<0, 1>, SDTCisInt<0>
112]>;
Chris Lattner56f31f52005-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 Lattnerd83571b2005-10-10 06:00:30 +0000119def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
120 SDTCisSameAs<0, 1>, SDTCisFP<0>
121]>;
Chris Lattner6e83cbf2005-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 Madina6c912bf2005-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 Lattnerd83571b2005-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 Lattnerce9580f2005-10-26 17:00:25 +0000139def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
140 SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
141]>;
142
Duraid Madina17decbb2005-11-02 02:37:18 +0000143def SDTSelect : SDTypeProfile<1, 3, [ // select
144 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
145]>;
146
Chris Lattnera4c6cc5a2005-12-11 18:43:13 +0000147def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
Chris Lattner254e0a82005-12-11 08:35:54 +0000148 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
149 SDTCisVT<5, OtherVT>
150]>;
151
Evan Chenge8531382005-12-04 08:13:17 +0000152def SDTBr : SDTypeProfile<0, 1, [ // br
153 SDTCisVT<0, OtherVT>
154]>;
155
Andrew Lenharthf99c3382006-01-01 22:16:43 +0000156def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
157 SDTCisInt<0>, SDTCisVT<1, OtherVT>
158]>;
159
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000160def SDTBrind : SDTypeProfile<0, 1, [ // brind
161 SDTCisPtrTy<0>
162]>;
163
Chris Lattner9a249b02008-01-15 22:02:54 +0000164def SDTNone : SDTypeProfile<0, 0, []>; // ret, trap
Evan Chenge8531382005-12-04 08:13:17 +0000165
Evan Cheng790af6d2005-12-08 04:28:48 +0000166def SDTLoad : SDTypeProfile<1, 1, [ // load
Chris Lattner27656ac2005-12-09 22:58:42 +0000167 SDTCisPtrTy<1>
Evan Cheng790af6d2005-12-08 04:28:48 +0000168]>;
169
Evan Cheng0d6cfee2005-12-10 00:48:20 +0000170def SDTStore : SDTypeProfile<0, 2, [ // store
Evan Cheng3c519832005-12-10 01:59:36 +0000171 SDTCisPtrTy<1>
Evan Cheng0d6cfee2005-12-10 00:48:20 +0000172]>;
173
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000174def SDTIStore : SDTypeProfile<1, 3, [ // indexed store
175 SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
176]>;
177
Chris Lattnere4e1ac372006-03-20 05:40:45 +0000178def SDTVecShuffle : SDTypeProfile<1, 3, [
179 SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisIntVectorOfSameSize<3, 0>
180]>;
Nate Begeman17bedbc2008-02-09 01:37:05 +0000181def SDTVecExtract : SDTypeProfile<1, 2, [ // vector extract
182 SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
183]>;
Nate Begeman2d77e8e42008-02-11 04:19:36 +0000184def SDTVecInsert : SDTypeProfile<1, 3, [ // vector insert
185 SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
Nate Begeman17bedbc2008-02-09 01:37:05 +0000186]>;
Chris Lattnere4e1ac372006-03-20 05:40:45 +0000187
Andrew Lenharth9b254ee2008-02-16 01:24:58 +0000188def STDMemBarrier : SDTypeProfile<0, 5, [
189 SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
190 SDTCisInt<0>
191]>;
192
Bill Wendling77b13af2007-11-13 09:19:02 +0000193class SDCallSeqStart<list<SDTypeConstraint> constraints> :
194 SDTypeProfile<0, 1, constraints>;
195class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
196 SDTypeProfile<0, 2, constraints>;
197
Chris Lattnerd83571b2005-10-10 06:00:30 +0000198//===----------------------------------------------------------------------===//
199// Selection DAG Node Properties.
200//
201// Note: These are hard coded into tblgen.
202//
203class SDNodeProperty;
204def SDNPCommutative : SDNodeProperty; // X op Y == Y op X
205def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z)
Evan Chenge8531382005-12-04 08:13:17 +0000206def SDNPHasChain : SDNodeProperty; // R/W chain operand and result
Evan Cheng7785e5b2006-01-09 18:28:21 +0000207def SDNPOutFlag : SDNodeProperty; // Write a flag result
208def SDNPInFlag : SDNodeProperty; // Read a flag operand
209def SDNPOptInFlag : SDNodeProperty; // Optionally read a flag operand
Chris Lattner10324d02008-01-06 08:36:04 +0000210def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'.
Chris Lattnerc7233582008-01-10 04:44:32 +0000211def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'.
Chris Lattner520d4ad2008-01-10 05:48:23 +0000212def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'.
Chris Lattnerd83571b2005-10-10 06:00:30 +0000213
214//===----------------------------------------------------------------------===//
215// Selection DAG Node definitions.
216//
217class SDNode<string opcode, SDTypeProfile typeprof,
218 list<SDNodeProperty> props = [], string sdclass = "SDNode"> {
219 string Opcode = opcode;
220 string SDClass = sdclass;
221 list<SDNodeProperty> Properties = props;
222 SDTypeProfile TypeProfile = typeprof;
223}
224
225def set;
Evan Cheng43686da2007-09-25 01:48:59 +0000226def implicit;
Evan Cheng59c39dc2007-09-12 23:30:14 +0000227def parallel;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000228def node;
Evan Cheng683d8512005-12-14 02:21:01 +0000229def srcvalue;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000230
Chris Lattnere6f2c822005-12-11 07:45:04 +0000231def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
Nate Begeman53e1b3f2008-02-14 08:57:00 +0000232def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
Evan Chenge8531382005-12-04 08:13:17 +0000233def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
234def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
235def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
Chris Lattner3a4b1412005-10-25 21:03:14 +0000236def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
Andrew Lenharth0dc12c32005-12-24 23:36:59 +0000237def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
Chris Lattner84045822005-11-17 07:20:15 +0000238 "GlobalAddressSDNode">;
Andrew Lenharth0dc12c32005-12-24 23:36:59 +0000239def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
240 "GlobalAddressSDNode">;
Lauro Ramos Venancio25188892007-04-20 21:38:10 +0000241def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
242 "GlobalAddressSDNode">;
243def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
244 "GlobalAddressSDNode">;
Andrew Lenharth0dc12c32005-12-24 23:36:59 +0000245def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
246 "ConstantPoolSDNode">;
247def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
248 "ConstantPoolSDNode">;
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000249def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
250 "JumpTableSDNode">;
251def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
252 "JumpTableSDNode">;
Andrew Lenharth0dc12c32005-12-24 23:36:59 +0000253def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
254 "FrameIndexSDNode">;
255def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
256 "FrameIndexSDNode">;
257def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
258 "ExternalSymbolSDNode">;
259def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
260 "ExternalSymbolSDNode">;
261
Chris Lattnerd83571b2005-10-10 06:00:30 +0000262def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
263 [SDNPCommutative, SDNPAssociative]>;
264def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
265def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
266 [SDNPCommutative, SDNPAssociative]>;
267def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
268def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
269def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
270def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
271def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
272def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
Chris Lattner282c2af2005-12-05 02:37:26 +0000273def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
274def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
275def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
Nate Begeman1b8121b2006-01-11 21:21:00 +0000276def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
277def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000278def and : SDNode<"ISD::AND" , SDTIntBinOp,
279 [SDNPCommutative, SDNPAssociative]>;
280def or : SDNode<"ISD::OR" , SDTIntBinOp,
281 [SDNPCommutative, SDNPAssociative]>;
282def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
283 [SDNPCommutative, SDNPAssociative]>;
Nate Begeman5965bd12006-02-17 05:43:56 +0000284def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
285 [SDNPCommutative, SDNPOutFlag]>;
286def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
287 [SDNPCommutative, SDNPOutFlag, SDNPInFlag]>;
288def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
289 [SDNPOutFlag]>;
290def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
291 [SDNPOutFlag, SDNPInFlag]>;
Chris Lattner56f31f52005-10-14 06:40:20 +0000292
293def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
Nate Begeman2fba8a32006-01-14 03:14:10 +0000294def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
Chris Lattner56f31f52005-10-14 06:40:20 +0000295def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
Andrew Lenharth7e0e8232005-10-20 19:38:11 +0000296def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
297def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
Chris Lattner56f31f52005-10-14 06:40:20 +0000298def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
299def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
300def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
301def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
Chris Lattner4b41e402006-03-16 01:29:53 +0000302def bitconvert : SDNode<"ISD::BIT_CONVERT", SDTUnaryOp>;
Nate Begeman17bedbc2008-02-09 01:37:05 +0000303def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
304def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
305
Chris Lattner56f31f52005-10-14 06:40:20 +0000306
Chris Lattnerd83571b2005-10-10 06:00:30 +0000307def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
308def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
309def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
310def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
311def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
312def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
313def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
314def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
Chris Lattner81f26532005-12-21 16:22:46 +0000315def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
316def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000317
Chris Lattner6e83cbf2005-10-14 04:55:10 +0000318def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
319def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
Andrew Lenharthebfd94f2006-03-09 17:47:22 +0000320def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
Chris Lattner6e83cbf2005-10-14 04:55:10 +0000321
Duraid Madina6c912bf2005-11-01 03:07:25 +0000322def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
323def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
324def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
325def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
326
Chris Lattnerce9580f2005-10-26 17:00:25 +0000327def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
Duraid Madina17decbb2005-11-02 02:37:18 +0000328def select : SDNode<"ISD::SELECT" , SDTSelect>;
Chris Lattner254e0a82005-12-11 08:35:54 +0000329def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
Chris Lattnerce9580f2005-10-26 17:00:25 +0000330
Andrew Lenharthf99c3382006-01-01 22:16:43 +0000331def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000332def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
Evan Chenge8531382005-12-04 08:13:17 +0000333def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
Chris Lattner9a249b02008-01-15 22:02:54 +0000334def ret : SDNode<"ISD::RET" , SDTNone, [SDNPHasChain]>;
335def trap : SDNode<"ISD::TRAP" , SDTNone,
336 [SDNPHasChain, SDNPSideEffect]>;
Andrew Lenharth9b254ee2008-02-16 01:24:58 +0000337def membarrier : SDNode<"ISD::MEMBARRIER" , STDMemBarrier,
338 [SDNPHasChain, SDNPSideEffect]>;
Evan Chenge8531382005-12-04 08:13:17 +0000339
Evan Chengab51cf22006-10-13 21:14:26 +0000340// Do not use ld, st directly. Use load, extload, sextload, zextload, store,
341// and truncst (see below).
Chris Lattnerc7233582008-01-10 04:44:32 +0000342def ld : SDNode<"ISD::LOAD" , SDTLoad,
343 [SDNPHasChain, SDNPMayLoad]>;
Chris Lattnera348f552008-01-06 06:44:58 +0000344def st : SDNode<"ISD::STORE" , SDTStore,
345 [SDNPHasChain, SDNPMayStore]>;
346def ist : SDNode<"ISD::STORE" , SDTIStore,
347 [SDNPHasChain, SDNPMayStore]>;
Evan Cheng683d8512005-12-14 02:21:01 +0000348
Chris Lattnere4e1ac372006-03-20 05:40:45 +0000349def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
Chris Lattner80b6bd272006-03-20 06:18:01 +0000350def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, 0, []>, []>;
Evan Chenge4d14162006-03-21 00:33:35 +0000351def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
352 []>;
Evan Cheng3296f292006-03-31 19:21:16 +0000353def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
Evan Cheng66f0e092006-06-15 08:19:05 +0000354 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
Evan Cheng3296f292006-03-31 19:21:16 +0000355def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
Evan Cheng66f0e092006-06-15 08:19:05 +0000356 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
Christopher Lamba8fc0e52007-07-26 07:34:40 +0000357
358def extract_subreg : SDNode<"ISD::EXTRACT_SUBREG",
359 SDTypeProfile<1, 2, []>>;
360def insert_subreg : SDNode<"ISD::INSERT_SUBREG",
361 SDTypeProfile<1, 3, []>>;
Chris Lattnere4e1ac372006-03-20 05:40:45 +0000362
Chris Lattner9dc2d172006-03-25 02:29:35 +0000363// Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
364// these internally. Don't reference these directly.
Chris Lattnere55d1712006-03-28 00:40:33 +0000365def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
Chris Lattner9dc2d172006-03-25 02:29:35 +0000366 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
367 [SDNPHasChain]>;
Chris Lattnere55d1712006-03-28 00:40:33 +0000368def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
Chris Lattner9dc2d172006-03-25 02:29:35 +0000369 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
370 [SDNPHasChain]>;
Chris Lattnere55d1712006-03-28 00:40:33 +0000371def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
Chris Lattner9dc2d172006-03-25 02:29:35 +0000372 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
373
374
Chris Lattnerce9580f2005-10-26 17:00:25 +0000375//===----------------------------------------------------------------------===//
376// Selection DAG Condition Codes
377
378class CondCode; // ISD::CondCode enums
379def SETOEQ : CondCode; def SETOGT : CondCode;
380def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
381def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
382def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
383def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
384
385def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
386def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
387
388
Chris Lattnerd83571b2005-10-10 06:00:30 +0000389//===----------------------------------------------------------------------===//
390// Selection DAG Node Transformation Functions.
391//
392// This mechanism allows targets to manipulate nodes in the output DAG once a
393// match has been formed. This is typically used to manipulate immediate
394// values.
395//
396class SDNodeXForm<SDNode opc, code xformFunction> {
397 SDNode Opcode = opc;
398 code XFormFunction = xformFunction;
399}
400
401def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
402
403
404//===----------------------------------------------------------------------===//
405// Selection DAG Pattern Fragments.
406//
407// Pattern fragments are reusable chunks of dags that match specific things.
408// They can take arguments and have C++ predicates that control whether they
409// match. They are intended to make the patterns for common instructions more
410// compact and readable.
411//
412
413/// PatFrag - Represents a pattern fragment. This can match something on the
414/// DAG, frame a single node to multiply nested other fragments.
415///
416class PatFrag<dag ops, dag frag, code pred = [{}],
417 SDNodeXForm xform = NOOP_SDNodeXForm> {
418 dag Operands = ops;
419 dag Fragment = frag;
420 code Predicate = pred;
421 SDNodeXForm OperandTransform = xform;
422}
423
424// PatLeaf's are pattern fragments that have no operands. This is just a helper
425// to define immediates and other common things concisely.
426class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
427 : PatFrag<(ops), frag, pred, xform>;
428
429// Leaf fragments.
430
Chris Lattnerd83571b2005-10-10 06:00:30 +0000431def vtInt : PatLeaf<(vt), [{ return MVT::isInteger(N->getVT()); }]>;
432def vtFP : PatLeaf<(vt), [{ return MVT::isFloatingPoint(N->getVT()); }]>;
433
Chris Lattner3de92862006-03-25 23:00:08 +0000434def immAllOnes : PatLeaf<(imm), [{ return N->isAllOnesValue(); }]>;
435def immAllOnesV: PatLeaf<(build_vector), [{
Evan Chenga74792f2006-03-27 06:59:32 +0000436 return ISD::isBuildVectorAllOnes(N);
Chris Lattner3de92862006-03-25 23:00:08 +0000437}]>;
Chris Lattner41df12f2006-04-15 23:39:14 +0000438def immAllOnesV_bc: PatLeaf<(bitconvert), [{
439 return ISD::isBuildVectorAllOnes(N);
440}]>;
Chris Lattner6a495932007-11-24 19:02:07 +0000441def immAllZerosV: PatLeaf<(build_vector), [{
442 return ISD::isBuildVectorAllZeros(N);
443}]>;
444def immAllZerosV_bc: PatLeaf<(bitconvert), [{
445 return ISD::isBuildVectorAllZeros(N);
446}]>;
447
Chris Lattner41df12f2006-04-15 23:39:14 +0000448
449
Chris Lattner3de92862006-03-25 23:00:08 +0000450// Other helper fragments.
Chris Lattnerd83571b2005-10-10 06:00:30 +0000451def not : PatFrag<(ops node:$in), (xor node:$in, immAllOnes)>;
Chris Lattner3de92862006-03-25 23:00:08 +0000452def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
Chris Lattner41df12f2006-04-15 23:39:14 +0000453def vnot_conv : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV_bc)>;
Chris Lattnera5537802005-10-20 23:30:37 +0000454def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000455
Evan Chengf53ae6932006-10-26 21:55:50 +0000456// load fragments.
Evan Chenge71fe34d2006-10-09 20:57:25 +0000457def load : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000458 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
459 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000460 LD->getAddressingMode() == ISD::UNINDEXED;
Evan Chengf53ae6932006-10-26 21:55:50 +0000461 return false;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000462}]>;
463
Evan Chengab51cf22006-10-13 21:14:26 +0000464// extending load fragments.
Evan Chenge71fe34d2006-10-09 20:57:25 +0000465def extloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000466 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
467 return LD->getExtensionType() == ISD::EXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000468 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000469 LD->getMemoryVT() == MVT::i1;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000470 return false;
471}]>;
472def extloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000473 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
474 return LD->getExtensionType() == ISD::EXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000475 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000476 LD->getMemoryVT() == MVT::i8;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000477 return false;
478}]>;
479def extloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000480 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
481 return LD->getExtensionType() == ISD::EXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000482 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000483 LD->getMemoryVT() == MVT::i16;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000484 return false;
485}]>;
486def extloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000487 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
488 return LD->getExtensionType() == ISD::EXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000489 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000490 LD->getMemoryVT() == MVT::i32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000491 return false;
492}]>;
493def extloadf32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000494 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
495 return LD->getExtensionType() == ISD::EXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000496 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000497 LD->getMemoryVT() == MVT::f32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000498 return false;
499}]>;
Dale Johannesenb1888e72007-08-05 18:49:15 +0000500def extloadf64 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
501 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
502 return LD->getExtensionType() == ISD::EXTLOAD &&
503 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000504 LD->getMemoryVT() == MVT::f64;
Dale Johannesenb1888e72007-08-05 18:49:15 +0000505 return false;
506}]>;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000507
Evan Chengf53ae6932006-10-26 21:55:50 +0000508def sextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
509 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
510 return LD->getExtensionType() == ISD::SEXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000511 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000512 LD->getMemoryVT() == MVT::i1;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000513 return false;
514}]>;
Evan Chengf53ae6932006-10-26 21:55:50 +0000515def sextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
516 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
517 return LD->getExtensionType() == ISD::SEXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000518 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000519 LD->getMemoryVT() == MVT::i8;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000520 return false;
521}]>;
522def sextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000523 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
524 return LD->getExtensionType() == ISD::SEXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000525 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000526 LD->getMemoryVT() == MVT::i16;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000527 return false;
528}]>;
529def sextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000530 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
531 return LD->getExtensionType() == ISD::SEXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000532 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000533 LD->getMemoryVT() == MVT::i32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000534 return false;
535}]>;
536
Evan Chengf53ae6932006-10-26 21:55:50 +0000537def zextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
538 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
539 return LD->getExtensionType() == ISD::ZEXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000540 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000541 LD->getMemoryVT() == MVT::i1;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000542 return false;
543}]>;
Evan Chengf53ae6932006-10-26 21:55:50 +0000544def zextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
545 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
546 return LD->getExtensionType() == ISD::ZEXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000547 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000548 LD->getMemoryVT() == MVT::i8;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000549 return false;
550}]>;
551def zextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000552 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
553 return LD->getExtensionType() == ISD::ZEXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000554 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000555 LD->getMemoryVT() == MVT::i16;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000556 return false;
557}]>;
558def zextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000559 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
560 return LD->getExtensionType() == ISD::ZEXTLOAD &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000561 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000562 LD->getMemoryVT() == MVT::i32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000563 return false;
564}]>;
565
Evan Chengf53ae6932006-10-26 21:55:50 +0000566// store fragments.
Evan Chengab51cf22006-10-13 21:14:26 +0000567def store : PatFrag<(ops node:$val, node:$ptr),
568 (st node:$val, node:$ptr), [{
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000569 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Chris Lattner58e8bed2006-11-14 19:13:39 +0000570 return !ST->isTruncatingStore() &&
571 ST->getAddressingMode() == ISD::UNINDEXED;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000572 return false;
Evan Chengab51cf22006-10-13 21:14:26 +0000573}]>;
574
575// truncstore fragments.
Evan Chengab51cf22006-10-13 21:14:26 +0000576def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
577 (st node:$val, node:$ptr), [{
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000578 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000579 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8 &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000580 ST->getAddressingMode() == ISD::UNINDEXED;
Evan Chengab51cf22006-10-13 21:14:26 +0000581 return false;
582}]>;
583def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
584 (st node:$val, node:$ptr), [{
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000585 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000586 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16 &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000587 ST->getAddressingMode() == ISD::UNINDEXED;
Evan Chengab51cf22006-10-13 21:14:26 +0000588 return false;
589}]>;
590def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
591 (st node:$val, node:$ptr), [{
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000592 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000593 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32 &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000594 ST->getAddressingMode() == ISD::UNINDEXED;
Evan Chengab51cf22006-10-13 21:14:26 +0000595 return false;
596}]>;
597def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
598 (st node:$val, node:$ptr), [{
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000599 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000600 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32 &&
Chris Lattner58e8bed2006-11-14 19:13:39 +0000601 ST->getAddressingMode() == ISD::UNINDEXED;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000602 return false;
603}]>;
Dale Johannesenb1888e72007-08-05 18:49:15 +0000604def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
605 (st node:$val, node:$ptr), [{
606 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000607 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f64 &&
Dale Johannesenb1888e72007-08-05 18:49:15 +0000608 ST->getAddressingMode() == ISD::UNINDEXED;
609 return false;
610}]>;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000611
612// indexed store fragments.
613def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
614 (ist node:$val, node:$base, node:$offset), [{
615 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000616 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000617 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
618 !ST->isTruncatingStore();
619 }
620 return false;
621}]>;
622
623def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
624 (ist node:$val, node:$base, node:$offset), [{
625 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000626 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000627 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000628 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000629 }
630 return false;
631}]>;
632def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
633 (ist node:$val, node:$base, node:$offset), [{
634 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000635 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000636 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000637 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000638 }
639 return false;
640}]>;
641def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
642 (ist node:$val, node:$base, node:$offset), [{
643 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000644 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000645 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000646 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000647 }
648 return false;
649}]>;
650def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
651 (ist node:$val, node:$base, node:$offset), [{
652 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000653 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000654 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000655 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000656 }
657 return false;
658}]>;
659def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
660 (ist node:$val, node:$base, node:$offset), [{
661 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000662 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000663 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000664 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000665 }
666 return false;
667}]>;
668
669def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
670 (ist node:$val, node:$ptr, node:$offset), [{
671 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000672 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000673 return !ST->isTruncatingStore() &&
674 (AM == ISD::POST_INC || AM == ISD::POST_DEC);
675 }
676 return false;
677}]>;
678
679def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
680 (ist node:$val, node:$base, node:$offset), [{
681 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000682 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000683 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000684 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000685 }
686 return false;
687}]>;
688def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
689 (ist node:$val, node:$base, node:$offset), [{
690 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000691 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000692 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000693 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000694 }
695 return false;
696}]>;
697def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
698 (ist node:$val, node:$base, node:$offset), [{
699 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000700 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000701 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000702 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000703 }
704 return false;
705}]>;
706def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
707 (ist node:$val, node:$base, node:$offset), [{
708 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000709 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000710 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000711 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000712 }
713 return false;
714}]>;
715def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
716 (ist node:$val, node:$base, node:$offset), [{
717 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
Evan Chengc034f142006-11-09 18:44:21 +0000718 ISD::MemIndexedMode AM = ST->getAddressingMode();
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000719 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman47a7d6f2008-01-30 00:15:11 +0000720 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32;
Evan Chengc9a4cdc2006-11-08 23:02:11 +0000721 }
Evan Chengab51cf22006-10-13 21:14:26 +0000722 return false;
723}]>;
Chris Lattnerce9580f2005-10-26 17:00:25 +0000724
725// setcc convenience fragments.
726def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
727 (setcc node:$lhs, node:$rhs, SETOEQ)>;
728def setogt : PatFrag<(ops node:$lhs, node:$rhs),
729 (setcc node:$lhs, node:$rhs, SETOGT)>;
730def setoge : PatFrag<(ops node:$lhs, node:$rhs),
731 (setcc node:$lhs, node:$rhs, SETOGE)>;
732def setolt : PatFrag<(ops node:$lhs, node:$rhs),
733 (setcc node:$lhs, node:$rhs, SETOLT)>;
734def setole : PatFrag<(ops node:$lhs, node:$rhs),
735 (setcc node:$lhs, node:$rhs, SETOLE)>;
736def setone : PatFrag<(ops node:$lhs, node:$rhs),
737 (setcc node:$lhs, node:$rhs, SETONE)>;
738def seto : PatFrag<(ops node:$lhs, node:$rhs),
739 (setcc node:$lhs, node:$rhs, SETO)>;
740def setuo : PatFrag<(ops node:$lhs, node:$rhs),
741 (setcc node:$lhs, node:$rhs, SETUO)>;
742def setueq : PatFrag<(ops node:$lhs, node:$rhs),
743 (setcc node:$lhs, node:$rhs, SETUEQ)>;
744def setugt : PatFrag<(ops node:$lhs, node:$rhs),
745 (setcc node:$lhs, node:$rhs, SETUGT)>;
746def setuge : PatFrag<(ops node:$lhs, node:$rhs),
747 (setcc node:$lhs, node:$rhs, SETUGE)>;
748def setult : PatFrag<(ops node:$lhs, node:$rhs),
749 (setcc node:$lhs, node:$rhs, SETULT)>;
750def setule : PatFrag<(ops node:$lhs, node:$rhs),
751 (setcc node:$lhs, node:$rhs, SETULE)>;
752def setune : PatFrag<(ops node:$lhs, node:$rhs),
753 (setcc node:$lhs, node:$rhs, SETUNE)>;
754def seteq : PatFrag<(ops node:$lhs, node:$rhs),
755 (setcc node:$lhs, node:$rhs, SETEQ)>;
756def setgt : PatFrag<(ops node:$lhs, node:$rhs),
757 (setcc node:$lhs, node:$rhs, SETGT)>;
758def setge : PatFrag<(ops node:$lhs, node:$rhs),
759 (setcc node:$lhs, node:$rhs, SETGE)>;
760def setlt : PatFrag<(ops node:$lhs, node:$rhs),
761 (setcc node:$lhs, node:$rhs, SETLT)>;
762def setle : PatFrag<(ops node:$lhs, node:$rhs),
763 (setcc node:$lhs, node:$rhs, SETLE)>;
764def setne : PatFrag<(ops node:$lhs, node:$rhs),
765 (setcc node:$lhs, node:$rhs, SETNE)>;
766
Chris Lattnerd83571b2005-10-10 06:00:30 +0000767//===----------------------------------------------------------------------===//
768// Selection DAG Pattern Support.
769//
770// Patterns are what are actually matched against the target-flavored
771// instruction selection DAG. Instructions defined by the target implicitly
772// define patterns in most cases, but patterns can also be explicitly added when
773// an operation is defined by a sequence of instructions (e.g. loading a large
774// immediate value on RISC targets that do not support immediates as large as
775// their GPRs).
776//
777
778class Pattern<dag patternToMatch, list<dag> resultInstrs> {
Evan Cheng52df7402006-04-19 20:38:28 +0000779 dag PatternToMatch = patternToMatch;
780 list<dag> ResultInstrs = resultInstrs;
781 list<Predicate> Predicates = []; // See class Instruction in Target.td.
782 int AddedComplexity = 0; // See class Instruction in Target.td.
Chris Lattnerd83571b2005-10-10 06:00:30 +0000783}
784
785// Pat - A simple (but common) form of a pattern, which produces a simple result
786// not needing a full list.
787class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
788
Evan Cheng790af6d2005-12-08 04:28:48 +0000789//===----------------------------------------------------------------------===//
790// Complex pattern definitions.
791//
Christopher Lamb0592cf72008-01-31 07:27:46 +0000792
793class CPAttribute;
794// Pass the parent Operand as root to CP function rather
795// than the root of the sub-DAG
796def CPAttrParentAsRoot : CPAttribute;
797
Evan Cheng790af6d2005-12-08 04:28:48 +0000798// Complex patterns, e.g. X86 addressing mode, requires pattern matching code
799// in C++. NumOperands is the number of operands returned by the select function;
800// SelectFunc is the name of the function used to pattern match the max. pattern;
801// RootNodes are the list of possible root nodes of the sub-dags to match.
802// e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
803//
Evan Cheng577ef762006-10-11 21:03:53 +0000804class ComplexPattern<ValueType ty, int numops, string fn,
Christopher Lamb0592cf72008-01-31 07:27:46 +0000805 list<SDNode> roots = [], list<SDNodeProperty> props = [],
806 list<CPAttribute> attrs = []> {
Evan Cheng790af6d2005-12-08 04:28:48 +0000807 ValueType Ty = ty;
808 int NumOperands = numops;
809 string SelectFunc = fn;
810 list<SDNode> RootNodes = roots;
Evan Cheng577ef762006-10-11 21:03:53 +0000811 list<SDNodeProperty> Properties = props;
Christopher Lamb0592cf72008-01-31 07:27:46 +0000812 list<CPAttribute> Attributes = attrs;
Evan Cheng790af6d2005-12-08 04:28:48 +0000813}
Jim Laskey7c462762005-12-16 22:45:29 +0000814
815//===----------------------------------------------------------------------===//
816// Dwarf support.
817//
Jim Laskey762e9ec2006-01-05 01:25:28 +0000818def SDT_dwarf_loc : SDTypeProfile<0, 3,
819 [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
820def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;
821
Jim Laskey7c462762005-12-16 22:45:29 +0000822
823