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