blob: bb67cbfbeffcfd6995ba854e270e53b27a5de09c [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 Chenge71fe34d2006-10-09 20:57:25 +0000402def load : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
403 return ISD::isNON_EXTLoad(N);
404}]>;
405
Evan Chengab51cf22006-10-13 21:14:26 +0000406// extending load fragments.
Evan Chenge71fe34d2006-10-09 20:57:25 +0000407def extloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
408 if (ISD::isEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000409 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i1;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000410 return false;
411}]>;
412def extloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
413 if (ISD::isEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000414 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i8;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000415 return false;
416}]>;
417def extloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
418 if (ISD::isEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000419 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i16;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000420 return false;
421}]>;
422def extloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
423 if (ISD::isEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000424 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000425 return false;
426}]>;
427def extloadf32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
428 if (ISD::isEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000429 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::f32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000430 return false;
431}]>;
432
433def sextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
434 if (ISD::isSEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000435 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i1;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000436 return false;
437}]>;
438def sextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
439 if (ISD::isSEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000440 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i8;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000441 return false;
442}]>;
443def sextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
444 if (ISD::isSEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000445 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i16;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000446 return false;
447}]>;
448def sextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
449 if (ISD::isSEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000450 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000451 return false;
452}]>;
453
454def zextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
455 if (ISD::isZEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000456 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i1;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000457 return false;
458}]>;
459def zextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
460 if (ISD::isZEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000461 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i8;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000462 return false;
463}]>;
464def zextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
465 if (ISD::isZEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000466 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i16;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000467 return false;
468}]>;
469def zextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
470 if (ISD::isZEXTLoad(N))
Evan Chengd35734b2006-10-11 07:10:22 +0000471 return cast<LoadSDNode>(N)->getLoadedVT() == MVT::i32;
Evan Chenge71fe34d2006-10-09 20:57:25 +0000472 return false;
473}]>;
474
Evan Chengab51cf22006-10-13 21:14:26 +0000475def store : PatFrag<(ops node:$val, node:$ptr),
476 (st node:$val, node:$ptr), [{
477 return ISD::isNON_TRUNCStore(N);
478}]>;
479
480// truncstore fragments.
481def truncstorei1 : PatFrag<(ops node:$val, node:$ptr),
482 (st node:$val, node:$ptr), [{
483 if (ISD::isTRUNCStore(N))
484 return cast<StoreSDNode>(N)->getStoredVT() == MVT::i1;
485 return false;
486}]>;
487def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
488 (st node:$val, node:$ptr), [{
489 if (ISD::isTRUNCStore(N))
490 return cast<StoreSDNode>(N)->getStoredVT() == MVT::i8;
491 return false;
492}]>;
493def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
494 (st node:$val, node:$ptr), [{
495 if (ISD::isTRUNCStore(N))
496 return cast<StoreSDNode>(N)->getStoredVT() == MVT::i16;
497 return false;
498}]>;
499def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
500 (st node:$val, node:$ptr), [{
501 if (ISD::isTRUNCStore(N))
502 return cast<StoreSDNode>(N)->getStoredVT() == MVT::i32;
503 return false;
504}]>;
505def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
506 (st node:$val, node:$ptr), [{
507 if (ISD::isTRUNCStore(N))
508 return cast<StoreSDNode>(N)->getStoredVT() == MVT::f32;
509 return false;
510}]>;
Chris Lattnerce9580f2005-10-26 17:00:25 +0000511
512// setcc convenience fragments.
513def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
514 (setcc node:$lhs, node:$rhs, SETOEQ)>;
515def setogt : PatFrag<(ops node:$lhs, node:$rhs),
516 (setcc node:$lhs, node:$rhs, SETOGT)>;
517def setoge : PatFrag<(ops node:$lhs, node:$rhs),
518 (setcc node:$lhs, node:$rhs, SETOGE)>;
519def setolt : PatFrag<(ops node:$lhs, node:$rhs),
520 (setcc node:$lhs, node:$rhs, SETOLT)>;
521def setole : PatFrag<(ops node:$lhs, node:$rhs),
522 (setcc node:$lhs, node:$rhs, SETOLE)>;
523def setone : PatFrag<(ops node:$lhs, node:$rhs),
524 (setcc node:$lhs, node:$rhs, SETONE)>;
525def seto : PatFrag<(ops node:$lhs, node:$rhs),
526 (setcc node:$lhs, node:$rhs, SETO)>;
527def setuo : PatFrag<(ops node:$lhs, node:$rhs),
528 (setcc node:$lhs, node:$rhs, SETUO)>;
529def setueq : PatFrag<(ops node:$lhs, node:$rhs),
530 (setcc node:$lhs, node:$rhs, SETUEQ)>;
531def setugt : PatFrag<(ops node:$lhs, node:$rhs),
532 (setcc node:$lhs, node:$rhs, SETUGT)>;
533def setuge : PatFrag<(ops node:$lhs, node:$rhs),
534 (setcc node:$lhs, node:$rhs, SETUGE)>;
535def setult : PatFrag<(ops node:$lhs, node:$rhs),
536 (setcc node:$lhs, node:$rhs, SETULT)>;
537def setule : PatFrag<(ops node:$lhs, node:$rhs),
538 (setcc node:$lhs, node:$rhs, SETULE)>;
539def setune : PatFrag<(ops node:$lhs, node:$rhs),
540 (setcc node:$lhs, node:$rhs, SETUNE)>;
541def seteq : PatFrag<(ops node:$lhs, node:$rhs),
542 (setcc node:$lhs, node:$rhs, SETEQ)>;
543def setgt : PatFrag<(ops node:$lhs, node:$rhs),
544 (setcc node:$lhs, node:$rhs, SETGT)>;
545def setge : PatFrag<(ops node:$lhs, node:$rhs),
546 (setcc node:$lhs, node:$rhs, SETGE)>;
547def setlt : PatFrag<(ops node:$lhs, node:$rhs),
548 (setcc node:$lhs, node:$rhs, SETLT)>;
549def setle : PatFrag<(ops node:$lhs, node:$rhs),
550 (setcc node:$lhs, node:$rhs, SETLE)>;
551def setne : PatFrag<(ops node:$lhs, node:$rhs),
552 (setcc node:$lhs, node:$rhs, SETNE)>;
553
Chris Lattnerd83571b2005-10-10 06:00:30 +0000554//===----------------------------------------------------------------------===//
555// Selection DAG Pattern Support.
556//
557// Patterns are what are actually matched against the target-flavored
558// instruction selection DAG. Instructions defined by the target implicitly
559// define patterns in most cases, but patterns can also be explicitly added when
560// an operation is defined by a sequence of instructions (e.g. loading a large
561// immediate value on RISC targets that do not support immediates as large as
562// their GPRs).
563//
564
565class Pattern<dag patternToMatch, list<dag> resultInstrs> {
Evan Cheng52df7402006-04-19 20:38:28 +0000566 dag PatternToMatch = patternToMatch;
567 list<dag> ResultInstrs = resultInstrs;
568 list<Predicate> Predicates = []; // See class Instruction in Target.td.
569 int AddedComplexity = 0; // See class Instruction in Target.td.
Chris Lattnerd83571b2005-10-10 06:00:30 +0000570}
571
572// Pat - A simple (but common) form of a pattern, which produces a simple result
573// not needing a full list.
574class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
575
Evan Cheng790af6d2005-12-08 04:28:48 +0000576//===----------------------------------------------------------------------===//
577// Complex pattern definitions.
578//
579// Complex patterns, e.g. X86 addressing mode, requires pattern matching code
580// in C++. NumOperands is the number of operands returned by the select function;
581// SelectFunc is the name of the function used to pattern match the max. pattern;
582// RootNodes are the list of possible root nodes of the sub-dags to match.
583// e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
584//
Evan Cheng577ef762006-10-11 21:03:53 +0000585class ComplexPattern<ValueType ty, int numops, string fn,
586 list<SDNode> roots = [], list<SDNodeProperty> props = []> {
Evan Cheng790af6d2005-12-08 04:28:48 +0000587 ValueType Ty = ty;
588 int NumOperands = numops;
589 string SelectFunc = fn;
590 list<SDNode> RootNodes = roots;
Evan Cheng577ef762006-10-11 21:03:53 +0000591 list<SDNodeProperty> Properties = props;
Evan Cheng790af6d2005-12-08 04:28:48 +0000592}
Jim Laskey7c462762005-12-16 22:45:29 +0000593
594//===----------------------------------------------------------------------===//
595// Dwarf support.
596//
Jim Laskey762e9ec2006-01-05 01:25:28 +0000597def SDT_dwarf_loc : SDTypeProfile<0, 3,
598 [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
599def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;
600
601def SDT_dwarf_label : SDTypeProfile<0, 1, [SDTCisInt<0>]>;
602def dwarf_label : SDNode<"ISD::DEBUG_LABEL", SDT_dwarf_label,[SDNPHasChain]>;
Jim Laskey7c462762005-12-16 22:45:29 +0000603
604
605