blob: a05d91b651151afa22d5560ec4e9d02e877493f4 [file] [log] [blame]
Dan Gohmanf17a25c2007-07-18 16:29:46 +00001//===- TargetSelectionDAG.td - Common code for DAG isels ---*- tablegen -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner081ce942007-12-29 20:36:04 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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.
27class SDTCisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
28 ValueType VT = vt;
29}
30
31class SDTCisPtrTy<int OpNum> : SDTypeConstraint<OpNum>;
32
33// 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.
37class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
38
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
50class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
51 int BigOperandNum = BigOp;
52}
53
54/// SDTCisIntVectorOfSameSize - This indicates that ThisOp and OtherOp are
55/// vector types, and that ThisOp is the result of
Duncan Sands92c43912008-06-06 12:08:01 +000056/// MVT::getIntVectorWithNumElements with the number of elements
57/// that ThisOp has.
Dan Gohmanf17a25c2007-07-18 16:29:46 +000058class SDTCisIntVectorOfSameSize<int ThisOp, int OtherOp>
59 : SDTypeConstraint<ThisOp> {
60 int OtherOpNum = OtherOp;
61}
62
Nate Begemanea391a22008-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.
Dan Gohman2c4be2a2008-05-31 02:11:25 +000065class SDTCisEltOfVec<int ThisOp, int OtherOp>
Nate Begemanea391a22008-02-09 01:37:05 +000066 : SDTypeConstraint<ThisOp> {
67 int OtherOpNum = OtherOp;
68}
69
Dan Gohmanf17a25c2007-07-18 16:29:46 +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.
88def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>; // for 'imm'.
89def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>; // for 'fpimm'.
90def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; // for '&g'.
91def SDTOther : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
92def SDTUNDEF : SDTypeProfile<1, 0, []>; // for 'undef'.
93def SDTUnaryOp : SDTypeProfile<1, 1, []>; // bitconvert
94
95def SDTIntBinOp : SDTypeProfile<1, 2, [ // add, and, or, xor, udiv, etc.
96 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
97]>;
98def SDTIntShiftOp : SDTypeProfile<1, 2, [ // shl, sra, srl
99 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
100]>;
101def SDTFPBinOp : SDTypeProfile<1, 2, [ // fadd, fmul, etc.
102 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
103]>;
104def SDTFPSignOp : SDTypeProfile<1, 2, [ // fcopysign.
105 SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
106]>;
107def SDTFPTernaryOp : SDTypeProfile<1, 3, [ // fmadd, fnmsub, etc.
108 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
109]>;
110def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // ctlz
111 SDTCisSameAs<0, 1>, SDTCisInt<0>
112]>;
113def 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]>;
119def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
120 SDTCisSameAs<0, 1>, SDTCisFP<0>
121]>;
122def 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]>;
128def 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]>;
134def SDTExtInreg : SDTypeProfile<1, 2, [ // sext_inreg
135 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
136 SDTCisVTSmallerThanOp<2, 1>
137]>;
138
139def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
140 SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
141]>;
142
143def SDTSelect : SDTypeProfile<1, 3, [ // select
144 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
145]>;
146
147def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
148 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
149 SDTCisVT<5, OtherVT>
150]>;
151
152def SDTBr : SDTypeProfile<0, 1, [ // br
153 SDTCisVT<0, OtherVT>
154]>;
155
156def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
157 SDTCisInt<0>, SDTCisVT<1, OtherVT>
158]>;
159
160def SDTBrind : SDTypeProfile<0, 1, [ // brind
161 SDTCisPtrTy<0>
162]>;
163
Chris Lattner3d254552008-01-15 22:02:54 +0000164def SDTNone : SDTypeProfile<0, 0, []>; // ret, trap
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000165
166def SDTLoad : SDTypeProfile<1, 1, [ // load
167 SDTCisPtrTy<1>
168]>;
169
170def SDTStore : SDTypeProfile<0, 2, [ // store
171 SDTCisPtrTy<1>
172]>;
173
174def SDTIStore : SDTypeProfile<1, 3, [ // indexed store
175 SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
176]>;
177
178def SDTVecShuffle : SDTypeProfile<1, 3, [
179 SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisIntVectorOfSameSize<3, 0>
180]>;
Nate Begemanea391a22008-02-09 01:37:05 +0000181def SDTVecExtract : SDTypeProfile<1, 2, [ // vector extract
182 SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
183]>;
Nate Begemand77e59e2008-02-11 04:19:36 +0000184def SDTVecInsert : SDTypeProfile<1, 3, [ // vector insert
185 SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
Nate Begemanea391a22008-02-09 01:37:05 +0000186]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000187
Evan Chengd1d68072008-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 Lenharth785610d2008-02-16 01:24:58 +0000193 SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
194 SDTCisInt<0>
195]>;
Andrew Lenharthe44f3902008-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 Lenharth785610d2008-02-16 01:24:58 +0000202
Bill Wendling7173da52007-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
Dan Gohmanf17a25c2007-07-18 16:29:46 +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)
216def SDNPHasChain : SDNodeProperty; // R/W chain operand and result
217def SDNPOutFlag : SDNodeProperty; // Write a flag result
218def SDNPInFlag : SDNodeProperty; // Read a flag operand
219def SDNPOptInFlag : SDNodeProperty; // Optionally read a flag operand
Chris Lattner6887b142008-01-06 08:36:04 +0000220def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'.
Chris Lattnerdfde8132008-01-10 04:44:32 +0000221def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'.
Chris Lattner2e40ad12008-01-10 05:48:23 +0000222def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'.
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000223def SDNPMemOperand : SDNodeProperty; // Touches memory, has assoc MemOperand
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000224
225//===----------------------------------------------------------------------===//
226// Selection DAG Node definitions.
227//
228class SDNode<string opcode, SDTypeProfile typeprof,
229 list<SDNodeProperty> props = [], string sdclass = "SDNode"> {
230 string Opcode = opcode;
231 string SDClass = sdclass;
232 list<SDNodeProperty> Properties = props;
233 SDTypeProfile TypeProfile = typeprof;
234}
235
236def set;
Evan Chengf031fcb2007-09-25 01:48:59 +0000237def implicit;
Evan Cheng775baac2007-09-12 23:30:14 +0000238def parallel;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000239def node;
240def srcvalue;
241
242def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
Nate Begemane2ba64f2008-02-14 08:57:00 +0000243def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000244def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
245def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
246def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
247def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
248def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
249 "GlobalAddressSDNode">;
250def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
251 "GlobalAddressSDNode">;
252def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
253 "GlobalAddressSDNode">;
254def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
255 "GlobalAddressSDNode">;
256def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
257 "ConstantPoolSDNode">;
258def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
259 "ConstantPoolSDNode">;
260def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
261 "JumpTableSDNode">;
262def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
263 "JumpTableSDNode">;
264def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
265 "FrameIndexSDNode">;
266def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
267 "FrameIndexSDNode">;
268def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
269 "ExternalSymbolSDNode">;
270def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
271 "ExternalSymbolSDNode">;
272
273def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
274 [SDNPCommutative, SDNPAssociative]>;
275def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
276def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
277 [SDNPCommutative, SDNPAssociative]>;
278def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
279def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
280def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
281def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
282def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
283def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
284def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
285def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
286def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
287def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
288def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
289def and : SDNode<"ISD::AND" , SDTIntBinOp,
290 [SDNPCommutative, SDNPAssociative]>;
291def or : SDNode<"ISD::OR" , SDTIntBinOp,
292 [SDNPCommutative, SDNPAssociative]>;
293def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
294 [SDNPCommutative, SDNPAssociative]>;
295def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
296 [SDNPCommutative, SDNPOutFlag]>;
297def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
298 [SDNPCommutative, SDNPOutFlag, SDNPInFlag]>;
299def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
300 [SDNPOutFlag]>;
301def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
302 [SDNPOutFlag, SDNPInFlag]>;
303
304def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
305def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
306def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
307def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
308def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
309def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
310def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
311def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
312def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
313def bitconvert : SDNode<"ISD::BIT_CONVERT", SDTUnaryOp>;
Nate Begemanea391a22008-02-09 01:37:05 +0000314def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
315def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
316
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000317
318def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
319def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
320def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
321def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
322def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
323def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
324def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
325def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
326def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
327def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
Dan Gohmanc8b20e22008-08-21 17:55:02 +0000328def frint : SDNode<"ISD::FRINT" , SDTFPUnaryOp>;
329def ftrunc : SDNode<"ISD::FTRUNC" , SDTFPUnaryOp>;
330def fceil : SDNode<"ISD::FCEIL" , SDTFPUnaryOp>;
331def ffloor : SDNode<"ISD::FFLOOR" , SDTFPUnaryOp>;
332def fnearbyint : SDNode<"ISD::FNEARBYINT" , SDTFPUnaryOp>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000333
334def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
335def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
336def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
337
338def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
339def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
340def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
341def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
342
343def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
344def select : SDNode<"ISD::SELECT" , SDTSelect>;
345def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
Nate Begeman9a1ce152008-05-12 19:40:03 +0000346def vsetcc : SDNode<"ISD::VSETCC" , SDTSetCC>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000347
348def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
349def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
350def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
Chris Lattner3d254552008-01-15 22:02:54 +0000351def ret : SDNode<"ISD::RET" , SDTNone, [SDNPHasChain]>;
352def trap : SDNode<"ISD::TRAP" , SDTNone,
353 [SDNPHasChain, SDNPSideEffect]>;
Evan Chengd1d68072008-03-08 00:58:38 +0000354
355def prefetch : SDNode<"ISD::PREFETCH" , STDPrefetch,
356 [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
357
358def membarrier : SDNode<"ISD::MEMBARRIER" , STDMemBarrier,
Andrew Lenharth785610d2008-02-16 01:24:58 +0000359 [SDNPHasChain, SDNPSideEffect]>;
Evan Chengd1d68072008-03-08 00:58:38 +0000360
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000361// Do not use atomic_* directly, use atomic_*_size (see below)
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000362def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , STDAtomic3,
363 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
364def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , STDAtomic2,
365 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Bill Wendling6f189e22008-08-19 23:09:18 +0000366def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", STDAtomic2,
367 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Bill Wendlingdb2280a2008-08-20 00:28:16 +0000368def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , STDAtomic2,
369 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Mon P Wang078a62d2008-05-05 19:05:59 +0000370def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , STDAtomic2,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000371 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Mon P Wang078a62d2008-05-05 19:05:59 +0000372def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , STDAtomic2,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000373 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Mon P Wang078a62d2008-05-05 19:05:59 +0000374def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , STDAtomic2,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000375 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Andrew Lenharthaf02d592008-06-14 05:48:15 +0000376def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", STDAtomic2,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000377 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Mon P Wang078a62d2008-05-05 19:05:59 +0000378def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", STDAtomic2,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000379 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Mon P Wang078a62d2008-05-05 19:05:59 +0000380def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", STDAtomic2,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000381 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Mon P Wang078a62d2008-05-05 19:05:59 +0000382def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", STDAtomic2,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000383 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Mon P Wang078a62d2008-05-05 19:05:59 +0000384def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", STDAtomic2,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000385 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000386
387// Do not use ld, st directly. Use load, extload, sextload, zextload, store,
388// and truncst (see below).
Chris Lattnerdfde8132008-01-10 04:44:32 +0000389def ld : SDNode<"ISD::LOAD" , SDTLoad,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000390 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
Chris Lattneref8d6082008-01-06 06:44:58 +0000391def st : SDNode<"ISD::STORE" , SDTStore,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000392 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Chris Lattneref8d6082008-01-06 06:44:58 +0000393def ist : SDNode<"ISD::STORE" , SDTIStore,
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000394 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000395
396def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
Duncan Sandse10a0cb2008-07-28 19:17:21 +0000397def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000398def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
399 []>;
400def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
401 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
402def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
403 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
Christopher Lambb768c2e2007-07-26 07:34:40 +0000404
405def extract_subreg : SDNode<"ISD::EXTRACT_SUBREG",
406 SDTypeProfile<1, 2, []>>;
407def insert_subreg : SDNode<"ISD::INSERT_SUBREG",
408 SDTypeProfile<1, 3, []>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000409
410// Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
411// these internally. Don't reference these directly.
412def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
413 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
414 [SDNPHasChain]>;
415def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
416 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
417 [SDNPHasChain]>;
418def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
419 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
420
421
422//===----------------------------------------------------------------------===//
423// Selection DAG Condition Codes
424
425class CondCode; // ISD::CondCode enums
426def SETOEQ : CondCode; def SETOGT : CondCode;
427def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
428def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
429def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
430def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
431
432def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
433def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
434
435
436//===----------------------------------------------------------------------===//
437// Selection DAG Node Transformation Functions.
438//
439// This mechanism allows targets to manipulate nodes in the output DAG once a
440// match has been formed. This is typically used to manipulate immediate
441// values.
442//
443class SDNodeXForm<SDNode opc, code xformFunction> {
444 SDNode Opcode = opc;
445 code XFormFunction = xformFunction;
446}
447
448def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
449
450
451//===----------------------------------------------------------------------===//
452// Selection DAG Pattern Fragments.
453//
454// Pattern fragments are reusable chunks of dags that match specific things.
455// They can take arguments and have C++ predicates that control whether they
456// match. They are intended to make the patterns for common instructions more
457// compact and readable.
458//
459
460/// PatFrag - Represents a pattern fragment. This can match something on the
461/// DAG, frame a single node to multiply nested other fragments.
462///
463class PatFrag<dag ops, dag frag, code pred = [{}],
464 SDNodeXForm xform = NOOP_SDNodeXForm> {
465 dag Operands = ops;
466 dag Fragment = frag;
467 code Predicate = pred;
468 SDNodeXForm OperandTransform = xform;
469}
470
471// PatLeaf's are pattern fragments that have no operands. This is just a helper
472// to define immediates and other common things concisely.
473class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
474 : PatFrag<(ops), frag, pred, xform>;
475
476// Leaf fragments.
477
Duncan Sands92c43912008-06-06 12:08:01 +0000478def vtInt : PatLeaf<(vt), [{ return N->getVT().isInteger(); }]>;
479def vtFP : PatLeaf<(vt), [{ return N->getVT().isFloatingPoint(); }]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000480
481def immAllOnes : PatLeaf<(imm), [{ return N->isAllOnesValue(); }]>;
482def immAllOnesV: PatLeaf<(build_vector), [{
483 return ISD::isBuildVectorAllOnes(N);
484}]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000485def immAllOnesV_bc: PatLeaf<(bitconvert), [{
486 return ISD::isBuildVectorAllOnes(N);
487}]>;
Chris Lattner8f259c02007-11-24 19:02:07 +0000488def immAllZerosV: PatLeaf<(build_vector), [{
489 return ISD::isBuildVectorAllZeros(N);
490}]>;
491def immAllZerosV_bc: PatLeaf<(bitconvert), [{
492 return ISD::isBuildVectorAllZeros(N);
493}]>;
494
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000495
496
497// Other helper fragments.
498def not : PatFrag<(ops node:$in), (xor node:$in, immAllOnes)>;
499def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
500def vnot_conv : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV_bc)>;
501def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
502
503// load fragments.
504def load : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000505 LoadSDNode *LD = cast<LoadSDNode>(N);
506 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
507 LD->getAddressingMode() == ISD::UNINDEXED;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000508}]>;
509
510// extending load fragments.
511def extloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000512 LoadSDNode *LD = cast<LoadSDNode>(N);
513 return LD->getExtensionType() == ISD::EXTLOAD &&
514 LD->getAddressingMode() == ISD::UNINDEXED &&
515 LD->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000516}]>;
517def extloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000518 LoadSDNode *LD = cast<LoadSDNode>(N);
519 return LD->getExtensionType() == ISD::EXTLOAD &&
520 LD->getAddressingMode() == ISD::UNINDEXED &&
521 LD->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000522}]>;
523def extloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000524 LoadSDNode *LD = cast<LoadSDNode>(N);
525 return LD->getExtensionType() == ISD::EXTLOAD &&
526 LD->getAddressingMode() == ISD::UNINDEXED &&
527 LD->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000528}]>;
529def extloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000530 LoadSDNode *LD = cast<LoadSDNode>(N);
531 return LD->getExtensionType() == ISD::EXTLOAD &&
532 LD->getAddressingMode() == ISD::UNINDEXED &&
533 LD->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000534}]>;
535def extloadf32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000536 LoadSDNode *LD = cast<LoadSDNode>(N);
537 return LD->getExtensionType() == ISD::EXTLOAD &&
538 LD->getAddressingMode() == ISD::UNINDEXED &&
539 LD->getMemoryVT() == MVT::f32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000540}]>;
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000541def extloadf64 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000542 LoadSDNode *LD = cast<LoadSDNode>(N);
543 return LD->getExtensionType() == ISD::EXTLOAD &&
544 LD->getAddressingMode() == ISD::UNINDEXED &&
545 LD->getMemoryVT() == MVT::f64;
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000546}]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547
548def sextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000549 LoadSDNode *LD = cast<LoadSDNode>(N);
550 return LD->getExtensionType() == ISD::SEXTLOAD &&
551 LD->getAddressingMode() == ISD::UNINDEXED &&
552 LD->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000553}]>;
554def sextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000555 LoadSDNode *LD = cast<LoadSDNode>(N);
556 return LD->getExtensionType() == ISD::SEXTLOAD &&
557 LD->getAddressingMode() == ISD::UNINDEXED &&
558 LD->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000559}]>;
560def sextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000561 LoadSDNode *LD = cast<LoadSDNode>(N);
562 return LD->getExtensionType() == ISD::SEXTLOAD &&
563 LD->getAddressingMode() == ISD::UNINDEXED &&
564 LD->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000565}]>;
566def sextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000567 LoadSDNode *LD = cast<LoadSDNode>(N);
568 return LD->getExtensionType() == ISD::SEXTLOAD &&
569 LD->getAddressingMode() == ISD::UNINDEXED &&
570 LD->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000571}]>;
572
573def zextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000574 LoadSDNode *LD = cast<LoadSDNode>(N);
575 return LD->getExtensionType() == ISD::ZEXTLOAD &&
576 LD->getAddressingMode() == ISD::UNINDEXED &&
577 LD->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000578}]>;
579def zextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000580 LoadSDNode *LD = cast<LoadSDNode>(N);
581 return LD->getExtensionType() == ISD::ZEXTLOAD &&
582 LD->getAddressingMode() == ISD::UNINDEXED &&
583 LD->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000584}]>;
585def zextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000586 LoadSDNode *LD = cast<LoadSDNode>(N);
587 return LD->getExtensionType() == ISD::ZEXTLOAD &&
588 LD->getAddressingMode() == ISD::UNINDEXED &&
589 LD->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000590}]>;
591def zextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000592 LoadSDNode *LD = cast<LoadSDNode>(N);
593 return LD->getExtensionType() == ISD::ZEXTLOAD &&
594 LD->getAddressingMode() == ISD::UNINDEXED &&
595 LD->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000596}]>;
597
598// store fragments.
599def store : PatFrag<(ops node:$val, node:$ptr),
600 (st node:$val, node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000601 StoreSDNode *ST = cast<StoreSDNode>(N);
602 return !ST->isTruncatingStore() &&
603 ST->getAddressingMode() == ISD::UNINDEXED;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000604}]>;
605
606// truncstore fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000607def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
608 (st node:$val, node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000609 StoreSDNode *ST = cast<StoreSDNode>(N);
610 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8 &&
611 ST->getAddressingMode() == ISD::UNINDEXED;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000612}]>;
613def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
614 (st node:$val, node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000615 StoreSDNode *ST = cast<StoreSDNode>(N);
616 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16 &&
617 ST->getAddressingMode() == ISD::UNINDEXED;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000618}]>;
619def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
620 (st node:$val, node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000621 StoreSDNode *ST = cast<StoreSDNode>(N);
Dan Gohman41a458d2008-08-20 15:54:46 +0000622 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32 &&
623 ST->getAddressingMode() == ISD::UNINDEXED;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624}]>;
625def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
626 (st node:$val, node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000627 StoreSDNode *ST = cast<StoreSDNode>(N);
628 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32 &&
629 ST->getAddressingMode() == ISD::UNINDEXED;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000630}]>;
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000631def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
632 (st node:$val, node:$ptr), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000633 StoreSDNode *ST = cast<StoreSDNode>(N);
634 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f64 &&
635 ST->getAddressingMode() == ISD::UNINDEXED;
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000636}]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000637
638// indexed store fragments.
639def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
640 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000641 StoreSDNode *ST = cast<StoreSDNode>(N);
642 ISD::MemIndexedMode AM = ST->getAddressingMode();
643 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
644 !ST->isTruncatingStore();
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000645}]>;
646
647def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
648 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000649 StoreSDNode *ST = cast<StoreSDNode>(N);
650 ISD::MemIndexedMode AM = ST->getAddressingMode();
651 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
652 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000653}]>;
654def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
655 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000656 StoreSDNode *ST = cast<StoreSDNode>(N);
657 ISD::MemIndexedMode AM = ST->getAddressingMode();
658 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
659 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000660}]>;
661def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
662 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000663 StoreSDNode *ST = cast<StoreSDNode>(N);
664 ISD::MemIndexedMode AM = ST->getAddressingMode();
665 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
666 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000667}]>;
668def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
669 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000670 StoreSDNode *ST = cast<StoreSDNode>(N);
671 ISD::MemIndexedMode AM = ST->getAddressingMode();
672 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
673 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000674}]>;
675def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
676 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000677 StoreSDNode *ST = cast<StoreSDNode>(N);
678 ISD::MemIndexedMode AM = ST->getAddressingMode();
679 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
680 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000681}]>;
682
683def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
684 (ist node:$val, node:$ptr, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000685 StoreSDNode *ST = cast<StoreSDNode>(N);
686 ISD::MemIndexedMode AM = ST->getAddressingMode();
687 return !ST->isTruncatingStore() &&
688 (AM == ISD::POST_INC || AM == ISD::POST_DEC);
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000689}]>;
690
691def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
692 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000693 StoreSDNode *ST = cast<StoreSDNode>(N);
694 ISD::MemIndexedMode AM = ST->getAddressingMode();
695 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
696 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000697}]>;
698def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
699 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000700 StoreSDNode *ST = cast<StoreSDNode>(N);
701 ISD::MemIndexedMode AM = ST->getAddressingMode();
702 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
703 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000704}]>;
705def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
706 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000707 StoreSDNode *ST = cast<StoreSDNode>(N);
708 ISD::MemIndexedMode AM = ST->getAddressingMode();
709 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
710 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000711}]>;
712def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
713 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000714 StoreSDNode *ST = cast<StoreSDNode>(N);
715 ISD::MemIndexedMode AM = ST->getAddressingMode();
716 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
717 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000718}]>;
719def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
720 (ist node:$val, node:$base, node:$offset), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000721 StoreSDNode *ST = cast<StoreSDNode>(N);
722 ISD::MemIndexedMode AM = ST->getAddressingMode();
723 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
724 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725}]>;
726
Dan Gohman8335c412008-08-20 15:24:22 +0000727// Atomic patterns
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000728def atomic_cmp_swap_8 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
729 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swp), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000730 AtomicSDNode* V = cast<AtomicSDNode>(N);
731 return V->getValueType(0) == MVT::i8;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000732}]>;
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000733def atomic_cmp_swap_16 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
734 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swp), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000735 AtomicSDNode* V = cast<AtomicSDNode>(N);
736 return V->getValueType(0) == MVT::i16;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000737}]>;
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000738def atomic_cmp_swap_32 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
739 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swp), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000740 AtomicSDNode* V = cast<AtomicSDNode>(N);
741 return V->getValueType(0) == MVT::i32;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000742}]>;
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000743def atomic_cmp_swap_64 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
744 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swp), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000745 AtomicSDNode* V = cast<AtomicSDNode>(N);
746 return V->getValueType(0) == MVT::i64;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000747}]>;
748
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000749def atomic_load_add_8 : PatFrag<(ops node:$ptr, node:$inc),
750 (atomic_load_add node:$ptr, node:$inc), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000751 AtomicSDNode* V = cast<AtomicSDNode>(N);
752 return V->getValueType(0) == MVT::i8;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000753}]>;
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000754def atomic_load_add_16 : PatFrag<(ops node:$ptr, node:$inc),
755 (atomic_load_add node:$ptr, node:$inc), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000756 AtomicSDNode* V = cast<AtomicSDNode>(N);
757 return V->getValueType(0) == MVT::i16;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000758}]>;
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000759def atomic_load_add_32 : PatFrag<(ops node:$ptr, node:$inc),
760 (atomic_load_add node:$ptr, node:$inc), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000761 AtomicSDNode* V = cast<AtomicSDNode>(N);
762 return V->getValueType(0) == MVT::i32;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000763}]>;
Mon P Wang6bde9ec2008-06-25 08:15:39 +0000764def atomic_load_add_64 : PatFrag<(ops node:$ptr, node:$inc),
765 (atomic_load_add node:$ptr, node:$inc), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000766 AtomicSDNode* V = cast<AtomicSDNode>(N);
767 return V->getValueType(0) == MVT::i64;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000768}]>;
769
770def atomic_swap_8 : PatFrag<(ops node:$ptr, node:$inc),
771 (atomic_swap node:$ptr, node:$inc), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000772 AtomicSDNode* V = cast<AtomicSDNode>(N);
773 return V->getValueType(0) == MVT::i8;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000774}]>;
775def atomic_swap_16 : PatFrag<(ops node:$ptr, node:$inc),
776 (atomic_swap node:$ptr, node:$inc), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000777 AtomicSDNode* V = cast<AtomicSDNode>(N);
778 return V->getValueType(0) == MVT::i16;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000779}]>;
780def atomic_swap_32 : PatFrag<(ops node:$ptr, node:$inc),
781 (atomic_swap node:$ptr, node:$inc), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000782 AtomicSDNode* V = cast<AtomicSDNode>(N);
783 return V->getValueType(0) == MVT::i32;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000784}]>;
785def atomic_swap_64 : PatFrag<(ops node:$ptr, node:$inc),
786 (atomic_swap node:$ptr, node:$inc), [{
Dan Gohman8335c412008-08-20 15:24:22 +0000787 AtomicSDNode* V = cast<AtomicSDNode>(N);
788 return V->getValueType(0) == MVT::i64;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000789}]>;
790
791
Bill Wendlingdb2280a2008-08-20 00:28:16 +0000792
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000793// setcc convenience fragments.
794def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
795 (setcc node:$lhs, node:$rhs, SETOEQ)>;
796def setogt : PatFrag<(ops node:$lhs, node:$rhs),
797 (setcc node:$lhs, node:$rhs, SETOGT)>;
798def setoge : PatFrag<(ops node:$lhs, node:$rhs),
799 (setcc node:$lhs, node:$rhs, SETOGE)>;
800def setolt : PatFrag<(ops node:$lhs, node:$rhs),
801 (setcc node:$lhs, node:$rhs, SETOLT)>;
802def setole : PatFrag<(ops node:$lhs, node:$rhs),
803 (setcc node:$lhs, node:$rhs, SETOLE)>;
804def setone : PatFrag<(ops node:$lhs, node:$rhs),
805 (setcc node:$lhs, node:$rhs, SETONE)>;
806def seto : PatFrag<(ops node:$lhs, node:$rhs),
807 (setcc node:$lhs, node:$rhs, SETO)>;
808def setuo : PatFrag<(ops node:$lhs, node:$rhs),
809 (setcc node:$lhs, node:$rhs, SETUO)>;
810def setueq : PatFrag<(ops node:$lhs, node:$rhs),
811 (setcc node:$lhs, node:$rhs, SETUEQ)>;
812def setugt : PatFrag<(ops node:$lhs, node:$rhs),
813 (setcc node:$lhs, node:$rhs, SETUGT)>;
814def setuge : PatFrag<(ops node:$lhs, node:$rhs),
815 (setcc node:$lhs, node:$rhs, SETUGE)>;
816def setult : PatFrag<(ops node:$lhs, node:$rhs),
817 (setcc node:$lhs, node:$rhs, SETULT)>;
818def setule : PatFrag<(ops node:$lhs, node:$rhs),
819 (setcc node:$lhs, node:$rhs, SETULE)>;
820def setune : PatFrag<(ops node:$lhs, node:$rhs),
821 (setcc node:$lhs, node:$rhs, SETUNE)>;
822def seteq : PatFrag<(ops node:$lhs, node:$rhs),
823 (setcc node:$lhs, node:$rhs, SETEQ)>;
824def setgt : PatFrag<(ops node:$lhs, node:$rhs),
825 (setcc node:$lhs, node:$rhs, SETGT)>;
826def setge : PatFrag<(ops node:$lhs, node:$rhs),
827 (setcc node:$lhs, node:$rhs, SETGE)>;
828def setlt : PatFrag<(ops node:$lhs, node:$rhs),
829 (setcc node:$lhs, node:$rhs, SETLT)>;
830def setle : PatFrag<(ops node:$lhs, node:$rhs),
831 (setcc node:$lhs, node:$rhs, SETLE)>;
832def setne : PatFrag<(ops node:$lhs, node:$rhs),
833 (setcc node:$lhs, node:$rhs, SETNE)>;
834
835//===----------------------------------------------------------------------===//
836// Selection DAG Pattern Support.
837//
838// Patterns are what are actually matched against the target-flavored
839// instruction selection DAG. Instructions defined by the target implicitly
840// define patterns in most cases, but patterns can also be explicitly added when
841// an operation is defined by a sequence of instructions (e.g. loading a large
842// immediate value on RISC targets that do not support immediates as large as
843// their GPRs).
844//
845
846class Pattern<dag patternToMatch, list<dag> resultInstrs> {
847 dag PatternToMatch = patternToMatch;
848 list<dag> ResultInstrs = resultInstrs;
849 list<Predicate> Predicates = []; // See class Instruction in Target.td.
850 int AddedComplexity = 0; // See class Instruction in Target.td.
851}
852
853// Pat - A simple (but common) form of a pattern, which produces a simple result
854// not needing a full list.
855class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
856
857//===----------------------------------------------------------------------===//
858// Complex pattern definitions.
859//
Christopher Lamb059c7c92008-01-31 07:27:46 +0000860
861class CPAttribute;
862// Pass the parent Operand as root to CP function rather
863// than the root of the sub-DAG
864def CPAttrParentAsRoot : CPAttribute;
865
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000866// Complex patterns, e.g. X86 addressing mode, requires pattern matching code
867// in C++. NumOperands is the number of operands returned by the select function;
868// SelectFunc is the name of the function used to pattern match the max. pattern;
869// RootNodes are the list of possible root nodes of the sub-dags to match.
870// e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
871//
872class ComplexPattern<ValueType ty, int numops, string fn,
Christopher Lamb059c7c92008-01-31 07:27:46 +0000873 list<SDNode> roots = [], list<SDNodeProperty> props = [],
874 list<CPAttribute> attrs = []> {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000875 ValueType Ty = ty;
876 int NumOperands = numops;
877 string SelectFunc = fn;
878 list<SDNode> RootNodes = roots;
879 list<SDNodeProperty> Properties = props;
Christopher Lamb059c7c92008-01-31 07:27:46 +0000880 list<CPAttribute> Attributes = attrs;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000881}
882
883//===----------------------------------------------------------------------===//
884// Dwarf support.
885//
886def SDT_dwarf_loc : SDTypeProfile<0, 3,
887 [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
888def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;