blob: dc0fcb5443ea8b890df4a67fd1b2ae8931202493 [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
56/// MVT::getIntVectorWithNumElements with the number of elements that ThisOp
57/// has.
58class SDTCisIntVectorOfSameSize<int ThisOp, int OtherOp>
59 : SDTypeConstraint<ThisOp> {
60 int OtherOpNum = OtherOp;
61}
62
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.
65class SDTCisEltOfVec<int ThisOp, int OtherOp>
66 : 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'.
Dan Gohmanf17a25c2007-07-18 16:29:46 +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 Chengf031fcb2007-09-25 01:48:59 +0000236def implicit;
Evan Cheng775baac2007-09-12 23:30:14 +0000237def parallel;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000238def node;
239def srcvalue;
240
241def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
Nate Begemane2ba64f2008-02-14 08:57:00 +0000242def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000243def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
244def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
245def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
246def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
247def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
248 "GlobalAddressSDNode">;
249def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
250 "GlobalAddressSDNode">;
251def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
252 "GlobalAddressSDNode">;
253def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
254 "GlobalAddressSDNode">;
255def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
256 "ConstantPoolSDNode">;
257def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
258 "ConstantPoolSDNode">;
259def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
260 "JumpTableSDNode">;
261def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
262 "JumpTableSDNode">;
263def 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
272def 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>;
283def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
284def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
285def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
286def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
287def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
288def 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]>;
294def 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]>;
302
303def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
304def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
305def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
306def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
307def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
308def 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>;
312def bitconvert : SDNode<"ISD::BIT_CONVERT", SDTUnaryOp>;
Nate Begemanea391a22008-02-09 01:37:05 +0000313def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
314def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
315
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000316
317def 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>;
325def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
326def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
327
328def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
329def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
330def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
331
332def 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
337def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
338def select : SDNode<"ISD::SELECT" , SDTSelect>;
339def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
340
341def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
342def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
343def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
Chris Lattner3d254552008-01-15 22:02:54 +0000344def ret : SDNode<"ISD::RET" , SDTNone, [SDNPHasChain]>;
345def trap : SDNode<"ISD::TRAP" , SDTNone,
346 [SDNPHasChain, SDNPSideEffect]>;
Evan Chengd1d68072008-03-08 00:58:38 +0000347
348def prefetch : SDNode<"ISD::PREFETCH" , STDPrefetch,
349 [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
350
351def membarrier : SDNode<"ISD::MEMBARRIER" , STDMemBarrier,
Andrew Lenharth785610d2008-02-16 01:24:58 +0000352 [SDNPHasChain, SDNPSideEffect]>;
Evan Chengd1d68072008-03-08 00:58:38 +0000353
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000354// Do not use atomic_* directly, use atomic_*_size (see below)
Evan Chengd1d68072008-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 Lenharthe44f3902008-02-21 06:45:13 +0000359def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", STDAtomic2,
Evan Chengd1d68072008-03-08 00:58:38 +0000360 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000361
362// Do not use ld, st directly. Use load, extload, sextload, zextload, store,
363// and truncst (see below).
Chris Lattnerdfde8132008-01-10 04:44:32 +0000364def ld : SDNode<"ISD::LOAD" , SDTLoad,
365 [SDNPHasChain, SDNPMayLoad]>;
Chris Lattneref8d6082008-01-06 06:44:58 +0000366def st : SDNode<"ISD::STORE" , SDTStore,
367 [SDNPHasChain, SDNPMayStore]>;
368def ist : SDNode<"ISD::STORE" , SDTIStore,
369 [SDNPHasChain, SDNPMayStore]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000370
371def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
372def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, 0, []>, []>;
373def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
374 []>;
375def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
376 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
377def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
378 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
Christopher Lambb768c2e2007-07-26 07:34:40 +0000379
380def extract_subreg : SDNode<"ISD::EXTRACT_SUBREG",
381 SDTypeProfile<1, 2, []>>;
382def insert_subreg : SDNode<"ISD::INSERT_SUBREG",
383 SDTypeProfile<1, 3, []>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000384
385// Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
386// these internally. Don't reference these directly.
387def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
388 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
389 [SDNPHasChain]>;
390def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
391 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
392 [SDNPHasChain]>;
393def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
394 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
395
396
397//===----------------------------------------------------------------------===//
398// Selection DAG Condition Codes
399
400class CondCode; // ISD::CondCode enums
401def SETOEQ : CondCode; def SETOGT : CondCode;
402def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
403def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
404def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
405def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
406
407def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
408def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
409
410
411//===----------------------------------------------------------------------===//
412// Selection DAG Node Transformation Functions.
413//
414// This mechanism allows targets to manipulate nodes in the output DAG once a
415// match has been formed. This is typically used to manipulate immediate
416// values.
417//
418class SDNodeXForm<SDNode opc, code xformFunction> {
419 SDNode Opcode = opc;
420 code XFormFunction = xformFunction;
421}
422
423def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
424
425
426//===----------------------------------------------------------------------===//
427// Selection DAG Pattern Fragments.
428//
429// Pattern fragments are reusable chunks of dags that match specific things.
430// They can take arguments and have C++ predicates that control whether they
431// match. They are intended to make the patterns for common instructions more
432// compact and readable.
433//
434
435/// PatFrag - Represents a pattern fragment. This can match something on the
436/// DAG, frame a single node to multiply nested other fragments.
437///
438class PatFrag<dag ops, dag frag, code pred = [{}],
439 SDNodeXForm xform = NOOP_SDNodeXForm> {
440 dag Operands = ops;
441 dag Fragment = frag;
442 code Predicate = pred;
443 SDNodeXForm OperandTransform = xform;
444}
445
446// PatLeaf's are pattern fragments that have no operands. This is just a helper
447// to define immediates and other common things concisely.
448class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
449 : PatFrag<(ops), frag, pred, xform>;
450
451// Leaf fragments.
452
453def vtInt : PatLeaf<(vt), [{ return MVT::isInteger(N->getVT()); }]>;
454def vtFP : PatLeaf<(vt), [{ return MVT::isFloatingPoint(N->getVT()); }]>;
455
456def immAllOnes : PatLeaf<(imm), [{ return N->isAllOnesValue(); }]>;
457def immAllOnesV: PatLeaf<(build_vector), [{
458 return ISD::isBuildVectorAllOnes(N);
459}]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000460def immAllOnesV_bc: PatLeaf<(bitconvert), [{
461 return ISD::isBuildVectorAllOnes(N);
462}]>;
Chris Lattner8f259c02007-11-24 19:02:07 +0000463def immAllZerosV: PatLeaf<(build_vector), [{
464 return ISD::isBuildVectorAllZeros(N);
465}]>;
466def immAllZerosV_bc: PatLeaf<(bitconvert), [{
467 return ISD::isBuildVectorAllZeros(N);
468}]>;
469
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000470
471
472// Other helper fragments.
473def not : PatFrag<(ops node:$in), (xor node:$in, immAllOnes)>;
474def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
475def vnot_conv : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV_bc)>;
476def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
477
478// load fragments.
479def load : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
480 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
481 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
482 LD->getAddressingMode() == ISD::UNINDEXED;
483 return false;
484}]>;
485
486// extending load fragments.
487def extloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
488 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
489 return LD->getExtensionType() == ISD::EXTLOAD &&
490 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000491 LD->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000492 return false;
493}]>;
494def extloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
495 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
496 return LD->getExtensionType() == ISD::EXTLOAD &&
497 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000498 LD->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000499 return false;
500}]>;
501def extloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
502 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
503 return LD->getExtensionType() == ISD::EXTLOAD &&
504 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000505 LD->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000506 return false;
507}]>;
508def extloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
509 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
510 return LD->getExtensionType() == ISD::EXTLOAD &&
511 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000512 LD->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000513 return false;
514}]>;
515def extloadf32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
516 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
517 return LD->getExtensionType() == ISD::EXTLOAD &&
518 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000519 LD->getMemoryVT() == MVT::f32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000520 return false;
521}]>;
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000522def extloadf64 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
523 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
524 return LD->getExtensionType() == ISD::EXTLOAD &&
525 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000526 LD->getMemoryVT() == MVT::f64;
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000527 return false;
528}]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000529
530def sextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
531 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
532 return LD->getExtensionType() == ISD::SEXTLOAD &&
533 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000534 LD->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000535 return false;
536}]>;
537def sextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
538 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
539 return LD->getExtensionType() == ISD::SEXTLOAD &&
540 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000541 LD->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000542 return false;
543}]>;
544def sextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
545 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
546 return LD->getExtensionType() == ISD::SEXTLOAD &&
547 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000548 LD->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000549 return false;
550}]>;
551def sextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
552 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
553 return LD->getExtensionType() == ISD::SEXTLOAD &&
554 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000555 LD->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000556 return false;
557}]>;
558
559def zextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
560 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
561 return LD->getExtensionType() == ISD::ZEXTLOAD &&
562 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000563 LD->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000564 return false;
565}]>;
566def zextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
567 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
568 return LD->getExtensionType() == ISD::ZEXTLOAD &&
569 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000570 LD->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000571 return false;
572}]>;
573def zextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
574 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
575 return LD->getExtensionType() == ISD::ZEXTLOAD &&
576 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000577 LD->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000578 return false;
579}]>;
580def zextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
581 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
582 return LD->getExtensionType() == ISD::ZEXTLOAD &&
583 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000584 LD->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000585 return false;
586}]>;
587
588// store fragments.
589def store : PatFrag<(ops node:$val, node:$ptr),
590 (st node:$val, node:$ptr), [{
591 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
592 return !ST->isTruncatingStore() &&
593 ST->getAddressingMode() == ISD::UNINDEXED;
594 return false;
595}]>;
596
597// truncstore fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000598def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
599 (st node:$val, node:$ptr), [{
600 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000601 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8 &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000602 ST->getAddressingMode() == ISD::UNINDEXED;
603 return false;
604}]>;
605def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
606 (st node:$val, node:$ptr), [{
607 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000608 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16 &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000609 ST->getAddressingMode() == ISD::UNINDEXED;
610 return false;
611}]>;
612def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
613 (st node:$val, node:$ptr), [{
614 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000615 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32 &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000616 ST->getAddressingMode() == ISD::UNINDEXED;
617 return false;
618}]>;
619def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
620 (st node:$val, node:$ptr), [{
621 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000622 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32 &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000623 ST->getAddressingMode() == ISD::UNINDEXED;
624 return false;
625}]>;
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000626def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
627 (st node:$val, node:$ptr), [{
628 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000629 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f64 &&
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000630 ST->getAddressingMode() == ISD::UNINDEXED;
631 return false;
632}]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000633
634// indexed store fragments.
635def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
636 (ist node:$val, node:$base, node:$offset), [{
637 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
638 ISD::MemIndexedMode AM = ST->getAddressingMode();
639 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
640 !ST->isTruncatingStore();
641 }
642 return false;
643}]>;
644
645def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
646 (ist node:$val, node:$base, node:$offset), [{
647 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
648 ISD::MemIndexedMode AM = ST->getAddressingMode();
649 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000650 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651 }
652 return false;
653}]>;
654def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
655 (ist node:$val, node:$base, node:$offset), [{
656 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
657 ISD::MemIndexedMode AM = ST->getAddressingMode();
658 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000659 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000660 }
661 return false;
662}]>;
663def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
664 (ist node:$val, node:$base, node:$offset), [{
665 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
666 ISD::MemIndexedMode AM = ST->getAddressingMode();
667 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000668 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669 }
670 return false;
671}]>;
672def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
673 (ist node:$val, node:$base, node:$offset), [{
674 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
675 ISD::MemIndexedMode AM = ST->getAddressingMode();
676 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000677 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000678 }
679 return false;
680}]>;
681def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
682 (ist node:$val, node:$base, node:$offset), [{
683 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
684 ISD::MemIndexedMode AM = ST->getAddressingMode();
685 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000686 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000687 }
688 return false;
689}]>;
690
691def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
692 (ist node:$val, node:$ptr, node:$offset), [{
693 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
694 ISD::MemIndexedMode AM = ST->getAddressingMode();
695 return !ST->isTruncatingStore() &&
696 (AM == ISD::POST_INC || AM == ISD::POST_DEC);
697 }
698 return false;
699}]>;
700
701def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
702 (ist node:$val, node:$base, node:$offset), [{
703 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
704 ISD::MemIndexedMode AM = ST->getAddressingMode();
705 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000706 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000707 }
708 return false;
709}]>;
710def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
711 (ist node:$val, node:$base, node:$offset), [{
712 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
713 ISD::MemIndexedMode AM = ST->getAddressingMode();
714 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000715 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716 }
717 return false;
718}]>;
719def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
720 (ist node:$val, node:$base, node:$offset), [{
721 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
722 ISD::MemIndexedMode AM = ST->getAddressingMode();
723 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000724 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725 }
726 return false;
727}]>;
728def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
729 (ist node:$val, node:$base, node:$offset), [{
730 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
731 ISD::MemIndexedMode AM = ST->getAddressingMode();
732 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000733 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000734 }
735 return false;
736}]>;
737def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
738 (ist node:$val, node:$base, node:$offset), [{
739 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
740 ISD::MemIndexedMode AM = ST->getAddressingMode();
741 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000742 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000743 }
744 return false;
745}]>;
746
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000747//Atomic patterns
748def atomic_lcs_8 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
749 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
750 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
751 return V->getVT() == MVT::i8;
752 return false;
753}]>;
754def atomic_lcs_16 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
755 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
756 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
757 return V->getVT() == MVT::i16;
758 return false;
759}]>;
760def atomic_lcs_32 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
761 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
762 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
763 return V->getVT() == MVT::i32;
764 return false;
765}]>;
766def atomic_lcs_64 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
767 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
768 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
769 return V->getVT() == MVT::i64;
770 return false;
771}]>;
772
773def atomic_las_8 : PatFrag<(ops node:$ptr, node:$inc),
774 (atomic_las node:$ptr, node:$inc), [{
775 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
776 return V->getVT() == MVT::i8;
777 return false;
778}]>;
779def atomic_las_16 : PatFrag<(ops node:$ptr, node:$inc),
780 (atomic_las node:$ptr, node:$inc), [{
781 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
782 return V->getVT() == MVT::i16;
783 return false;
784}]>;
785def atomic_las_32 : PatFrag<(ops node:$ptr, node:$inc),
786 (atomic_las node:$ptr, node:$inc), [{
787 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
788 return V->getVT() == MVT::i32;
789 return false;
790}]>;
791def atomic_las_64 : PatFrag<(ops node:$ptr, node:$inc),
792 (atomic_las node:$ptr, node:$inc), [{
793 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
794 return V->getVT() == MVT::i64;
795 return false;
796}]>;
797
798def atomic_swap_8 : PatFrag<(ops node:$ptr, node:$inc),
799 (atomic_swap node:$ptr, node:$inc), [{
800 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
801 return V->getVT() == MVT::i8;
802 return false;
803}]>;
804def atomic_swap_16 : PatFrag<(ops node:$ptr, node:$inc),
805 (atomic_swap node:$ptr, node:$inc), [{
806 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
807 return V->getVT() == MVT::i16;
808 return false;
809}]>;
810def atomic_swap_32 : PatFrag<(ops node:$ptr, node:$inc),
811 (atomic_swap node:$ptr, node:$inc), [{
812 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
813 return V->getVT() == MVT::i32;
814 return false;
815}]>;
816def atomic_swap_64 : PatFrag<(ops node:$ptr, node:$inc),
817 (atomic_swap node:$ptr, node:$inc), [{
818 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
819 return V->getVT() == MVT::i64;
820 return false;
821}]>;
822
823
824
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000825// setcc convenience fragments.
826def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
827 (setcc node:$lhs, node:$rhs, SETOEQ)>;
828def setogt : PatFrag<(ops node:$lhs, node:$rhs),
829 (setcc node:$lhs, node:$rhs, SETOGT)>;
830def setoge : PatFrag<(ops node:$lhs, node:$rhs),
831 (setcc node:$lhs, node:$rhs, SETOGE)>;
832def setolt : PatFrag<(ops node:$lhs, node:$rhs),
833 (setcc node:$lhs, node:$rhs, SETOLT)>;
834def setole : PatFrag<(ops node:$lhs, node:$rhs),
835 (setcc node:$lhs, node:$rhs, SETOLE)>;
836def setone : PatFrag<(ops node:$lhs, node:$rhs),
837 (setcc node:$lhs, node:$rhs, SETONE)>;
838def seto : PatFrag<(ops node:$lhs, node:$rhs),
839 (setcc node:$lhs, node:$rhs, SETO)>;
840def setuo : PatFrag<(ops node:$lhs, node:$rhs),
841 (setcc node:$lhs, node:$rhs, SETUO)>;
842def setueq : PatFrag<(ops node:$lhs, node:$rhs),
843 (setcc node:$lhs, node:$rhs, SETUEQ)>;
844def setugt : PatFrag<(ops node:$lhs, node:$rhs),
845 (setcc node:$lhs, node:$rhs, SETUGT)>;
846def setuge : PatFrag<(ops node:$lhs, node:$rhs),
847 (setcc node:$lhs, node:$rhs, SETUGE)>;
848def setult : PatFrag<(ops node:$lhs, node:$rhs),
849 (setcc node:$lhs, node:$rhs, SETULT)>;
850def setule : PatFrag<(ops node:$lhs, node:$rhs),
851 (setcc node:$lhs, node:$rhs, SETULE)>;
852def setune : PatFrag<(ops node:$lhs, node:$rhs),
853 (setcc node:$lhs, node:$rhs, SETUNE)>;
854def seteq : PatFrag<(ops node:$lhs, node:$rhs),
855 (setcc node:$lhs, node:$rhs, SETEQ)>;
856def setgt : PatFrag<(ops node:$lhs, node:$rhs),
857 (setcc node:$lhs, node:$rhs, SETGT)>;
858def setge : PatFrag<(ops node:$lhs, node:$rhs),
859 (setcc node:$lhs, node:$rhs, SETGE)>;
860def setlt : PatFrag<(ops node:$lhs, node:$rhs),
861 (setcc node:$lhs, node:$rhs, SETLT)>;
862def setle : PatFrag<(ops node:$lhs, node:$rhs),
863 (setcc node:$lhs, node:$rhs, SETLE)>;
864def setne : PatFrag<(ops node:$lhs, node:$rhs),
865 (setcc node:$lhs, node:$rhs, SETNE)>;
866
867//===----------------------------------------------------------------------===//
868// Selection DAG Pattern Support.
869//
870// Patterns are what are actually matched against the target-flavored
871// instruction selection DAG. Instructions defined by the target implicitly
872// define patterns in most cases, but patterns can also be explicitly added when
873// an operation is defined by a sequence of instructions (e.g. loading a large
874// immediate value on RISC targets that do not support immediates as large as
875// their GPRs).
876//
877
878class Pattern<dag patternToMatch, list<dag> resultInstrs> {
879 dag PatternToMatch = patternToMatch;
880 list<dag> ResultInstrs = resultInstrs;
881 list<Predicate> Predicates = []; // See class Instruction in Target.td.
882 int AddedComplexity = 0; // See class Instruction in Target.td.
883}
884
885// Pat - A simple (but common) form of a pattern, which produces a simple result
886// not needing a full list.
887class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
888
889//===----------------------------------------------------------------------===//
890// Complex pattern definitions.
891//
Christopher Lamb059c7c92008-01-31 07:27:46 +0000892
893class CPAttribute;
894// Pass the parent Operand as root to CP function rather
895// than the root of the sub-DAG
896def CPAttrParentAsRoot : CPAttribute;
897
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000898// Complex patterns, e.g. X86 addressing mode, requires pattern matching code
899// in C++. NumOperands is the number of operands returned by the select function;
900// SelectFunc is the name of the function used to pattern match the max. pattern;
901// RootNodes are the list of possible root nodes of the sub-dags to match.
902// e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
903//
904class ComplexPattern<ValueType ty, int numops, string fn,
Christopher Lamb059c7c92008-01-31 07:27:46 +0000905 list<SDNode> roots = [], list<SDNodeProperty> props = [],
906 list<CPAttribute> attrs = []> {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000907 ValueType Ty = ty;
908 int NumOperands = numops;
909 string SelectFunc = fn;
910 list<SDNode> RootNodes = roots;
911 list<SDNodeProperty> Properties = props;
Christopher Lamb059c7c92008-01-31 07:27:46 +0000912 list<CPAttribute> Attributes = attrs;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000913}
914
915//===----------------------------------------------------------------------===//
916// Dwarf support.
917//
918def SDT_dwarf_loc : SDTypeProfile<0, 3,
919 [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
920def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;
921
922
923