blob: 0d4da01f57bd2248691c3a8b9ca736526d8ebefd [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//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
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
55/// packed vector types, and that ThisOp is the result of
56/// 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
Chris Lattnerd83571b2005-10-10 06:00:30 +000063//===----------------------------------------------------------------------===//
64// Selection DAG Type Profile definitions.
65//
66// These use the constraints defined above to describe the type requirements of
67// the various nodes. These are not hard coded into tblgen, allowing targets to
68// add their own if needed.
69//
70
71// SDTypeProfile - This profile describes the type requirements of a Selection
72// DAG node.
73class SDTypeProfile<int numresults, int numoperands,
74 list<SDTypeConstraint> constraints> {
75 int NumResults = numresults;
76 int NumOperands = numoperands;
77 list<SDTypeConstraint> Constraints = constraints;
78}
79
80// Builtin profiles.
Chris Lattnere6f2c822005-12-11 07:45:04 +000081def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>; // for 'imm'.
Evan Chenge0d1b652006-01-05 02:07:49 +000082def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>; // for 'fpimm'.
Chris Lattnere6f2c822005-12-11 07:45:04 +000083def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; // for '&g'.
Evan Chenge8531382005-12-04 08:13:17 +000084def SDTOther : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
Chris Lattner3a4b1412005-10-25 21:03:14 +000085def SDTUNDEF : SDTypeProfile<1, 0, []>; // for 'undef'.
Chris Lattner4b41e402006-03-16 01:29:53 +000086def SDTUnaryOp : SDTypeProfile<1, 1, []>; // bitconvert
87
Chris Lattnerd83571b2005-10-10 06:00:30 +000088def SDTIntBinOp : SDTypeProfile<1, 2, [ // add, and, or, xor, udiv, etc.
89 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
90]>;
Chris Lattner282c2af2005-12-05 02:37:26 +000091def SDTIntShiftOp : SDTypeProfile<1, 2, [ // shl, sra, srl
92 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
93]>;
Chris Lattnerd83571b2005-10-10 06:00:30 +000094def SDTFPBinOp : SDTypeProfile<1, 2, [ // fadd, fmul, etc.
95 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
96]>;
Andrew Lenharthebfd94f2006-03-09 17:47:22 +000097def SDTFPSignOp : SDTypeProfile<1, 2, [ // fcopysign.
98 SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
99]>;
Nate Begeman69caef22005-12-13 22:55:22 +0000100def SDTFPTernaryOp : SDTypeProfile<1, 3, [ // fmadd, fnmsub, etc.
101 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
102]>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000103def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // ctlz
104 SDTCisSameAs<0, 1>, SDTCisInt<0>
105]>;
Chris Lattner56f31f52005-10-14 06:40:20 +0000106def SDTIntExtendOp : SDTypeProfile<1, 1, [ // sext, zext, anyext
107 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>
108]>;
109def SDTIntTruncOp : SDTypeProfile<1, 1, [ // trunc
110 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>
111]>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000112def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
113 SDTCisSameAs<0, 1>, SDTCisFP<0>
114]>;
Chris Lattner6e83cbf2005-10-14 04:55:10 +0000115def SDTFPRoundOp : SDTypeProfile<1, 1, [ // fround
116 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>
117]>;
118def SDTFPExtendOp : SDTypeProfile<1, 1, [ // fextend
119 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>
120]>;
Duraid Madina6c912bf2005-11-01 03:07:25 +0000121def SDTIntToFPOp : SDTypeProfile<1, 1, [ // [su]int_to_fp
122 SDTCisFP<0>, SDTCisInt<1>
123]>;
124def SDTFPToIntOp : SDTypeProfile<1, 1, [ // fp_to_[su]int
125 SDTCisInt<0>, SDTCisFP<1>
126]>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000127def SDTExtInreg : SDTypeProfile<1, 2, [ // sext_inreg
128 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
129 SDTCisVTSmallerThanOp<2, 1>
130]>;
131
Chris Lattnerce9580f2005-10-26 17:00:25 +0000132def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
133 SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
134]>;
135
Duraid Madina17decbb2005-11-02 02:37:18 +0000136def SDTSelect : SDTypeProfile<1, 3, [ // select
137 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
138]>;
139
Chris Lattnera4c6cc5a2005-12-11 18:43:13 +0000140def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
Chris Lattner254e0a82005-12-11 08:35:54 +0000141 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
142 SDTCisVT<5, OtherVT>
143]>;
144
Evan Chenge8531382005-12-04 08:13:17 +0000145def SDTBr : SDTypeProfile<0, 1, [ // br
146 SDTCisVT<0, OtherVT>
147]>;
148
Andrew Lenharthf99c3382006-01-01 22:16:43 +0000149def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
150 SDTCisInt<0>, SDTCisVT<1, OtherVT>
151]>;
152
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000153def SDTBrind : SDTypeProfile<0, 1, [ // brind
154 SDTCisPtrTy<0>
155]>;
156
Chris Lattner233e0442005-12-17 20:42:29 +0000157def SDTRet : SDTypeProfile<0, 0, []>; // ret
Evan Chenge8531382005-12-04 08:13:17 +0000158
Evan Cheng790af6d2005-12-08 04:28:48 +0000159def SDTLoad : SDTypeProfile<1, 1, [ // load
Chris Lattner27656ac2005-12-09 22:58:42 +0000160 SDTCisPtrTy<1>
Evan Cheng790af6d2005-12-08 04:28:48 +0000161]>;
162
Evan Cheng0d6cfee2005-12-10 00:48:20 +0000163def SDTStore : SDTypeProfile<0, 2, [ // store
Evan Cheng3c519832005-12-10 01:59:36 +0000164 SDTCisPtrTy<1>
Evan Cheng0d6cfee2005-12-10 00:48:20 +0000165]>;
166
Chris Lattnere4e1ac372006-03-20 05:40:45 +0000167def SDTVecShuffle : SDTypeProfile<1, 3, [
168 SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisIntVectorOfSameSize<3, 0>
169]>;
170
Chris Lattnerd83571b2005-10-10 06:00:30 +0000171//===----------------------------------------------------------------------===//
172// Selection DAG Node Properties.
173//
174// Note: These are hard coded into tblgen.
175//
176class SDNodeProperty;
177def SDNPCommutative : SDNodeProperty; // X op Y == Y op X
178def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z)
Evan Chenge8531382005-12-04 08:13:17 +0000179def SDNPHasChain : SDNodeProperty; // R/W chain operand and result
Evan Cheng7785e5b2006-01-09 18:28:21 +0000180def SDNPOutFlag : SDNodeProperty; // Write a flag result
181def SDNPInFlag : SDNodeProperty; // Read a flag operand
182def SDNPOptInFlag : SDNodeProperty; // Optionally read a flag operand
Chris Lattnerd83571b2005-10-10 06:00:30 +0000183
184//===----------------------------------------------------------------------===//
185// Selection DAG Node definitions.
186//
187class SDNode<string opcode, SDTypeProfile typeprof,
188 list<SDNodeProperty> props = [], string sdclass = "SDNode"> {
189 string Opcode = opcode;
190 string SDClass = sdclass;
191 list<SDNodeProperty> Properties = props;
192 SDTypeProfile TypeProfile = typeprof;
193}
194
195def set;
196def node;
Evan Cheng683d8512005-12-14 02:21:01 +0000197def srcvalue;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000198
Chris Lattnere6f2c822005-12-11 07:45:04 +0000199def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
Chris Lattner61c9a8e2006-01-29 06:26:08 +0000200def fpimm : SDNode<"ISD::TargetConstantFP",
201 SDTFPLeaf, [], "ConstantFPSDNode">;
Evan Chenge8531382005-12-04 08:13:17 +0000202def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
203def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
204def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
Chris Lattner3a4b1412005-10-25 21:03:14 +0000205def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
Andrew Lenharth0dc12c32005-12-24 23:36:59 +0000206def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
Chris Lattner84045822005-11-17 07:20:15 +0000207 "GlobalAddressSDNode">;
Andrew Lenharth0dc12c32005-12-24 23:36:59 +0000208def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
209 "GlobalAddressSDNode">;
210def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
211 "ConstantPoolSDNode">;
212def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
213 "ConstantPoolSDNode">;
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000214def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
215 "JumpTableSDNode">;
216def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
217 "JumpTableSDNode">;
Andrew Lenharth0dc12c32005-12-24 23:36:59 +0000218def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
219 "FrameIndexSDNode">;
220def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
221 "FrameIndexSDNode">;
222def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
223 "ExternalSymbolSDNode">;
224def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
225 "ExternalSymbolSDNode">;
226
Chris Lattnerd83571b2005-10-10 06:00:30 +0000227def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
228 [SDNPCommutative, SDNPAssociative]>;
229def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
230def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
231 [SDNPCommutative, SDNPAssociative]>;
232def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
233def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
234def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
235def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
236def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
237def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
Chris Lattner282c2af2005-12-05 02:37:26 +0000238def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
239def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
240def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
Nate Begeman1b8121b2006-01-11 21:21:00 +0000241def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
242def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000243def and : SDNode<"ISD::AND" , SDTIntBinOp,
244 [SDNPCommutative, SDNPAssociative]>;
245def or : SDNode<"ISD::OR" , SDTIntBinOp,
246 [SDNPCommutative, SDNPAssociative]>;
247def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
248 [SDNPCommutative, SDNPAssociative]>;
Nate Begeman5965bd12006-02-17 05:43:56 +0000249def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
250 [SDNPCommutative, SDNPOutFlag]>;
251def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
252 [SDNPCommutative, SDNPOutFlag, SDNPInFlag]>;
253def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
254 [SDNPOutFlag]>;
255def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
256 [SDNPOutFlag, SDNPInFlag]>;
Chris Lattner56f31f52005-10-14 06:40:20 +0000257
258def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
Nate Begeman2fba8a32006-01-14 03:14:10 +0000259def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
Chris Lattner56f31f52005-10-14 06:40:20 +0000260def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
Andrew Lenharth7e0e8232005-10-20 19:38:11 +0000261def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
262def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
Chris Lattner56f31f52005-10-14 06:40:20 +0000263def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
264def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
265def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
266def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
Chris Lattner4b41e402006-03-16 01:29:53 +0000267def bitconvert : SDNode<"ISD::BIT_CONVERT", SDTUnaryOp>;
Chris Lattner56f31f52005-10-14 06:40:20 +0000268
Chris Lattnerd83571b2005-10-10 06:00:30 +0000269def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
270def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
271def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
272def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
273def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
274def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
275def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
276def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
Chris Lattner81f26532005-12-21 16:22:46 +0000277def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
278def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000279
Chris Lattner6e83cbf2005-10-14 04:55:10 +0000280def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
281def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
Andrew Lenharthebfd94f2006-03-09 17:47:22 +0000282def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
Chris Lattner6e83cbf2005-10-14 04:55:10 +0000283
Duraid Madina6c912bf2005-11-01 03:07:25 +0000284def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
285def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
286def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
287def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
288
Chris Lattnerce9580f2005-10-26 17:00:25 +0000289def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
Duraid Madina17decbb2005-11-02 02:37:18 +0000290def select : SDNode<"ISD::SELECT" , SDTSelect>;
Chris Lattner254e0a82005-12-11 08:35:54 +0000291def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
Chris Lattnerce9580f2005-10-26 17:00:25 +0000292
Andrew Lenharthf99c3382006-01-01 22:16:43 +0000293def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
Nate Begeman4ca2ea52006-04-22 18:53:45 +0000294def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
Evan Chenge8531382005-12-04 08:13:17 +0000295def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
Evan Chenge8531382005-12-04 08:13:17 +0000296def ret : SDNode<"ISD::RET" , SDTRet, [SDNPHasChain]>;
297
Evan Chengab51cf22006-10-13 21:14:26 +0000298// Do not use ld, st directly. Use load, extload, sextload, zextload, store,
299// and truncst (see below).
Evan Chenge71fe34d2006-10-09 20:57:25 +0000300def ld : SDNode<"ISD::LOAD" , SDTLoad, [SDNPHasChain]>;
Evan Chengab51cf22006-10-13 21:14:26 +0000301def st : SDNode<"ISD::STORE" , SDTStore, [SDNPHasChain]>;
Evan Cheng683d8512005-12-14 02:21:01 +0000302
Chris Lattnere4e1ac372006-03-20 05:40:45 +0000303def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
Chris Lattner80b6bd272006-03-20 06:18:01 +0000304def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, 0, []>, []>;
Evan Chenge4d14162006-03-21 00:33:35 +0000305def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
306 []>;
Evan Cheng3296f292006-03-31 19:21:16 +0000307def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
Evan Cheng66f0e092006-06-15 08:19:05 +0000308 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
Evan Cheng3296f292006-03-31 19:21:16 +0000309def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
Evan Cheng66f0e092006-06-15 08:19:05 +0000310 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
Chris Lattnere4e1ac372006-03-20 05:40:45 +0000311
Chris Lattner9dc2d172006-03-25 02:29:35 +0000312// Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
313// these internally. Don't reference these directly.
Chris Lattnere55d1712006-03-28 00:40:33 +0000314def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
Chris Lattner9dc2d172006-03-25 02:29:35 +0000315 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
316 [SDNPHasChain]>;
Chris Lattnere55d1712006-03-28 00:40:33 +0000317def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
Chris Lattner9dc2d172006-03-25 02:29:35 +0000318 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
319 [SDNPHasChain]>;
Chris Lattnere55d1712006-03-28 00:40:33 +0000320def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
Chris Lattner9dc2d172006-03-25 02:29:35 +0000321 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
322
323
Chris Lattnerce9580f2005-10-26 17:00:25 +0000324//===----------------------------------------------------------------------===//
325// Selection DAG Condition Codes
326
327class CondCode; // ISD::CondCode enums
328def SETOEQ : CondCode; def SETOGT : CondCode;
329def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
330def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
331def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
332def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
333
334def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
335def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
336
337
Chris Lattnerd83571b2005-10-10 06:00:30 +0000338//===----------------------------------------------------------------------===//
339// Selection DAG Node Transformation Functions.
340//
341// This mechanism allows targets to manipulate nodes in the output DAG once a
342// match has been formed. This is typically used to manipulate immediate
343// values.
344//
345class SDNodeXForm<SDNode opc, code xformFunction> {
346 SDNode Opcode = opc;
347 code XFormFunction = xformFunction;
348}
349
350def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
351
352
353//===----------------------------------------------------------------------===//
354// Selection DAG Pattern Fragments.
355//
356// Pattern fragments are reusable chunks of dags that match specific things.
357// They can take arguments and have C++ predicates that control whether they
358// match. They are intended to make the patterns for common instructions more
359// compact and readable.
360//
361
362/// PatFrag - Represents a pattern fragment. This can match something on the
363/// DAG, frame a single node to multiply nested other fragments.
364///
365class PatFrag<dag ops, dag frag, code pred = [{}],
366 SDNodeXForm xform = NOOP_SDNodeXForm> {
367 dag Operands = ops;
368 dag Fragment = frag;
369 code Predicate = pred;
370 SDNodeXForm OperandTransform = xform;
371}
372
373// PatLeaf's are pattern fragments that have no operands. This is just a helper
374// to define immediates and other common things concisely.
375class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
376 : PatFrag<(ops), frag, pred, xform>;
377
378// Leaf fragments.
379
Chris Lattnerd83571b2005-10-10 06:00:30 +0000380def vtInt : PatLeaf<(vt), [{ return MVT::isInteger(N->getVT()); }]>;
381def vtFP : PatLeaf<(vt), [{ return MVT::isFloatingPoint(N->getVT()); }]>;
382
Chris Lattner3de92862006-03-25 23:00:08 +0000383def immAllOnes : PatLeaf<(imm), [{ return N->isAllOnesValue(); }]>;
384def immAllOnesV: PatLeaf<(build_vector), [{
Evan Chenga74792f2006-03-27 06:59:32 +0000385 return ISD::isBuildVectorAllOnes(N);
Chris Lattner3de92862006-03-25 23:00:08 +0000386}]>;
Evan Cheng5562f202006-03-26 09:51:39 +0000387def immAllZerosV: PatLeaf<(build_vector), [{
388 return ISD::isBuildVectorAllZeros(N);
389}]>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000390
Chris Lattner41df12f2006-04-15 23:39:14 +0000391def immAllOnesV_bc: PatLeaf<(bitconvert), [{
392 return ISD::isBuildVectorAllOnes(N);
393}]>;
394
395
Chris Lattner3de92862006-03-25 23:00:08 +0000396// Other helper fragments.
Chris Lattnerd83571b2005-10-10 06:00:30 +0000397def not : PatFrag<(ops node:$in), (xor node:$in, immAllOnes)>;
Chris Lattner3de92862006-03-25 23:00:08 +0000398def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
Chris Lattner41df12f2006-04-15 23:39:14 +0000399def vnot_conv : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV_bc)>;
Chris Lattnera5537802005-10-20 23:30:37 +0000400def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
Chris Lattnerd83571b2005-10-10 06:00:30 +0000401
Evan Chengf53ae6932006-10-26 21:55:50 +0000402// load fragments.
Evan Chenge71fe34d2006-10-09 20:57:25 +0000403def load : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000404 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
405 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
406 LD->getAddressingMode() == ISD::UNINDEXED;
407 return false;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000408}]>;
409
Evan Chengab51cf22006-10-13 21:14:26 +0000410// extending load fragments.
Evan Chenge71fe34d2006-10-09 20:57:25 +0000411def extloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000412 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
413 return LD->getExtensionType() == ISD::EXTLOAD &&
414 LD->getAddressingMode() == ISD::UNINDEXED &&
415 LD->getLoadedVT() == MVT::i1;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000416 return false;
417}]>;
418def extloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000419 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
420 return LD->getExtensionType() == ISD::EXTLOAD &&
421 LD->getAddressingMode() == ISD::UNINDEXED &&
422 LD->getLoadedVT() == MVT::i8;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000423 return false;
424}]>;
425def extloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000426 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
427 return LD->getExtensionType() == ISD::EXTLOAD &&
428 LD->getAddressingMode() == ISD::UNINDEXED &&
429 LD->getLoadedVT() == MVT::i16;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000430 return false;
431}]>;
432def extloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000433 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
434 return LD->getExtensionType() == ISD::EXTLOAD &&
435 LD->getAddressingMode() == ISD::UNINDEXED &&
436 LD->getLoadedVT() == MVT::i32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000437 return false;
438}]>;
439def extloadf32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000440 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
441 return LD->getExtensionType() == ISD::EXTLOAD &&
442 LD->getAddressingMode() == ISD::UNINDEXED &&
443 LD->getLoadedVT() == MVT::f32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000444 return false;
445}]>;
446
Evan Chengf53ae6932006-10-26 21:55:50 +0000447def sextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
448 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
449 return LD->getExtensionType() == ISD::SEXTLOAD &&
450 LD->getAddressingMode() == ISD::UNINDEXED &&
451 LD->getLoadedVT() == MVT::i1;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000452 return false;
453}]>;
Evan Chengf53ae6932006-10-26 21:55:50 +0000454def sextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
455 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
456 return LD->getExtensionType() == ISD::SEXTLOAD &&
457 LD->getAddressingMode() == ISD::UNINDEXED &&
458 LD->getLoadedVT() == MVT::i8;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000459 return false;
460}]>;
461def sextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000462 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
463 return LD->getExtensionType() == ISD::SEXTLOAD &&
464 LD->getAddressingMode() == ISD::UNINDEXED &&
465 LD->getLoadedVT() == MVT::i16;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000466 return false;
467}]>;
468def sextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000469 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
470 return LD->getExtensionType() == ISD::SEXTLOAD &&
471 LD->getAddressingMode() == ISD::UNINDEXED &&
472 LD->getLoadedVT() == MVT::i32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000473 return false;
474}]>;
475
Evan Chengf53ae6932006-10-26 21:55:50 +0000476def zextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
477 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
478 return LD->getExtensionType() == ISD::ZEXTLOAD &&
479 LD->getAddressingMode() == ISD::UNINDEXED &&
480 LD->getLoadedVT() == MVT::i1;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000481 return false;
482}]>;
Evan Chengf53ae6932006-10-26 21:55:50 +0000483def zextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
484 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
485 return LD->getExtensionType() == ISD::ZEXTLOAD &&
486 LD->getAddressingMode() == ISD::UNINDEXED &&
487 LD->getLoadedVT() == MVT::i8;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000488 return false;
489}]>;
490def zextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000491 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
492 return LD->getExtensionType() == ISD::ZEXTLOAD &&
493 LD->getAddressingMode() == ISD::UNINDEXED &&
494 LD->getLoadedVT() == MVT::i16;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000495 return false;
496}]>;
497def zextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Evan Chengf53ae6932006-10-26 21:55:50 +0000498 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
499 return LD->getExtensionType() == ISD::ZEXTLOAD &&
500 LD->getAddressingMode() == ISD::UNINDEXED &&
501 LD->getLoadedVT() == MVT::i32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000502 return false;
503}]>;
504
Evan Chengf53ae6932006-10-26 21:55:50 +0000505// store fragments.
Evan Chengab51cf22006-10-13 21:14:26 +0000506def store : PatFrag<(ops node:$val, node:$ptr),
507 (st node:$val, node:$ptr), [{
508 return ISD::isNON_TRUNCStore(N);
509}]>;
510
511// truncstore fragments.
512def truncstorei1 : PatFrag<(ops node:$val, node:$ptr),
513 (st node:$val, node:$ptr), [{
514 if (ISD::isTRUNCStore(N))
515 return cast<StoreSDNode>(N)->getStoredVT() == MVT::i1;
516 return false;
517}]>;
518def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
519 (st node:$val, node:$ptr), [{
520 if (ISD::isTRUNCStore(N))
521 return cast<StoreSDNode>(N)->getStoredVT() == MVT::i8;
522 return false;
523}]>;
524def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
525 (st node:$val, node:$ptr), [{
526 if (ISD::isTRUNCStore(N))
527 return cast<StoreSDNode>(N)->getStoredVT() == MVT::i16;
528 return false;
529}]>;
530def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
531 (st node:$val, node:$ptr), [{
532 if (ISD::isTRUNCStore(N))
533 return cast<StoreSDNode>(N)->getStoredVT() == MVT::i32;
534 return false;
535}]>;
536def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
537 (st node:$val, node:$ptr), [{
538 if (ISD::isTRUNCStore(N))
539 return cast<StoreSDNode>(N)->getStoredVT() == MVT::f32;
540 return false;
541}]>;
Chris Lattnerce9580f2005-10-26 17:00:25 +0000542
543// setcc convenience fragments.
544def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
545 (setcc node:$lhs, node:$rhs, SETOEQ)>;
546def setogt : PatFrag<(ops node:$lhs, node:$rhs),
547 (setcc node:$lhs, node:$rhs, SETOGT)>;
548def setoge : PatFrag<(ops node:$lhs, node:$rhs),
549 (setcc node:$lhs, node:$rhs, SETOGE)>;
550def setolt : PatFrag<(ops node:$lhs, node:$rhs),
551 (setcc node:$lhs, node:$rhs, SETOLT)>;
552def setole : PatFrag<(ops node:$lhs, node:$rhs),
553 (setcc node:$lhs, node:$rhs, SETOLE)>;
554def setone : PatFrag<(ops node:$lhs, node:$rhs),
555 (setcc node:$lhs, node:$rhs, SETONE)>;
556def seto : PatFrag<(ops node:$lhs, node:$rhs),
557 (setcc node:$lhs, node:$rhs, SETO)>;
558def setuo : PatFrag<(ops node:$lhs, node:$rhs),
559 (setcc node:$lhs, node:$rhs, SETUO)>;
560def setueq : PatFrag<(ops node:$lhs, node:$rhs),
561 (setcc node:$lhs, node:$rhs, SETUEQ)>;
562def setugt : PatFrag<(ops node:$lhs, node:$rhs),
563 (setcc node:$lhs, node:$rhs, SETUGT)>;
564def setuge : PatFrag<(ops node:$lhs, node:$rhs),
565 (setcc node:$lhs, node:$rhs, SETUGE)>;
566def setult : PatFrag<(ops node:$lhs, node:$rhs),
567 (setcc node:$lhs, node:$rhs, SETULT)>;
568def setule : PatFrag<(ops node:$lhs, node:$rhs),
569 (setcc node:$lhs, node:$rhs, SETULE)>;
570def setune : PatFrag<(ops node:$lhs, node:$rhs),
571 (setcc node:$lhs, node:$rhs, SETUNE)>;
572def seteq : PatFrag<(ops node:$lhs, node:$rhs),
573 (setcc node:$lhs, node:$rhs, SETEQ)>;
574def setgt : PatFrag<(ops node:$lhs, node:$rhs),
575 (setcc node:$lhs, node:$rhs, SETGT)>;
576def setge : PatFrag<(ops node:$lhs, node:$rhs),
577 (setcc node:$lhs, node:$rhs, SETGE)>;
578def setlt : PatFrag<(ops node:$lhs, node:$rhs),
579 (setcc node:$lhs, node:$rhs, SETLT)>;
580def setle : PatFrag<(ops node:$lhs, node:$rhs),
581 (setcc node:$lhs, node:$rhs, SETLE)>;
582def setne : PatFrag<(ops node:$lhs, node:$rhs),
583 (setcc node:$lhs, node:$rhs, SETNE)>;
584
Chris Lattnerd83571b2005-10-10 06:00:30 +0000585//===----------------------------------------------------------------------===//
586// Selection DAG Pattern Support.
587//
588// Patterns are what are actually matched against the target-flavored
589// instruction selection DAG. Instructions defined by the target implicitly
590// define patterns in most cases, but patterns can also be explicitly added when
591// an operation is defined by a sequence of instructions (e.g. loading a large
592// immediate value on RISC targets that do not support immediates as large as
593// their GPRs).
594//
595
596class Pattern<dag patternToMatch, list<dag> resultInstrs> {
Evan Cheng52df7402006-04-19 20:38:28 +0000597 dag PatternToMatch = patternToMatch;
598 list<dag> ResultInstrs = resultInstrs;
599 list<Predicate> Predicates = []; // See class Instruction in Target.td.
600 int AddedComplexity = 0; // See class Instruction in Target.td.
Chris Lattnerd83571b2005-10-10 06:00:30 +0000601}
602
603// Pat - A simple (but common) form of a pattern, which produces a simple result
604// not needing a full list.
605class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
606
Evan Cheng790af6d2005-12-08 04:28:48 +0000607//===----------------------------------------------------------------------===//
608// Complex pattern definitions.
609//
610// Complex patterns, e.g. X86 addressing mode, requires pattern matching code
611// in C++. NumOperands is the number of operands returned by the select function;
612// SelectFunc is the name of the function used to pattern match the max. pattern;
613// RootNodes are the list of possible root nodes of the sub-dags to match.
614// e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
615//
Evan Cheng577ef762006-10-11 21:03:53 +0000616class ComplexPattern<ValueType ty, int numops, string fn,
617 list<SDNode> roots = [], list<SDNodeProperty> props = []> {
Evan Cheng790af6d2005-12-08 04:28:48 +0000618 ValueType Ty = ty;
619 int NumOperands = numops;
620 string SelectFunc = fn;
621 list<SDNode> RootNodes = roots;
Evan Cheng577ef762006-10-11 21:03:53 +0000622 list<SDNodeProperty> Properties = props;
Evan Cheng790af6d2005-12-08 04:28:48 +0000623}
Jim Laskey7c462762005-12-16 22:45:29 +0000624
625//===----------------------------------------------------------------------===//
626// Dwarf support.
627//
Jim Laskey762e9ec2006-01-05 01:25:28 +0000628def SDT_dwarf_loc : SDTypeProfile<0, 3,
629 [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
630def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;
631
632def SDT_dwarf_label : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
633def dwarf_label : SDNode<"ISD::DEBUG_LABEL", SDT_dwarf_label,[SDNPHasChain]>;
Jim Laskey7c462762005-12-16 22:45:29 +0000634
635
636