blob: 47d9ba48b7b66f51e4bd7cd557262b626fc986d1 [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
Andrew Lenharth785610d2008-02-16 01:24:58 +0000188def STDMemBarrier : SDTypeProfile<0, 5, [
189 SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
190 SDTCisInt<0>
191]>;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000192def STDAtomic3 : SDTypeProfile<1, 3, [
193 SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
194]>;
195def STDAtomic2 : SDTypeProfile<1, 2, [
196 SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
197]>;
Andrew Lenharth785610d2008-02-16 01:24:58 +0000198
Bill Wendling7173da52007-11-13 09:19:02 +0000199class SDCallSeqStart<list<SDTypeConstraint> constraints> :
200 SDTypeProfile<0, 1, constraints>;
201class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
202 SDTypeProfile<0, 2, constraints>;
203
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000204//===----------------------------------------------------------------------===//
205// Selection DAG Node Properties.
206//
207// Note: These are hard coded into tblgen.
208//
209class SDNodeProperty;
210def SDNPCommutative : SDNodeProperty; // X op Y == Y op X
211def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z)
212def SDNPHasChain : SDNodeProperty; // R/W chain operand and result
213def SDNPOutFlag : SDNodeProperty; // Write a flag result
214def SDNPInFlag : SDNodeProperty; // Read a flag operand
215def SDNPOptInFlag : SDNodeProperty; // Optionally read a flag operand
Chris Lattner6887b142008-01-06 08:36:04 +0000216def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'.
Chris Lattnerdfde8132008-01-10 04:44:32 +0000217def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'.
Chris Lattner2e40ad12008-01-10 05:48:23 +0000218def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000219
220//===----------------------------------------------------------------------===//
221// Selection DAG Node definitions.
222//
223class SDNode<string opcode, SDTypeProfile typeprof,
224 list<SDNodeProperty> props = [], string sdclass = "SDNode"> {
225 string Opcode = opcode;
226 string SDClass = sdclass;
227 list<SDNodeProperty> Properties = props;
228 SDTypeProfile TypeProfile = typeprof;
229}
230
231def set;
Evan Chengf031fcb2007-09-25 01:48:59 +0000232def implicit;
Evan Cheng775baac2007-09-12 23:30:14 +0000233def parallel;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000234def node;
235def srcvalue;
236
237def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
Nate Begemane2ba64f2008-02-14 08:57:00 +0000238def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000239def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
240def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
241def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
242def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
243def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
244 "GlobalAddressSDNode">;
245def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
246 "GlobalAddressSDNode">;
247def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
248 "GlobalAddressSDNode">;
249def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
250 "GlobalAddressSDNode">;
251def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
252 "ConstantPoolSDNode">;
253def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
254 "ConstantPoolSDNode">;
255def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
256 "JumpTableSDNode">;
257def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
258 "JumpTableSDNode">;
259def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
260 "FrameIndexSDNode">;
261def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
262 "FrameIndexSDNode">;
263def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
264 "ExternalSymbolSDNode">;
265def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
266 "ExternalSymbolSDNode">;
267
268def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
269 [SDNPCommutative, SDNPAssociative]>;
270def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
271def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
272 [SDNPCommutative, SDNPAssociative]>;
273def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
274def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
275def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
276def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
277def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
278def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
279def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
280def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
281def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
282def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
283def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
284def and : SDNode<"ISD::AND" , SDTIntBinOp,
285 [SDNPCommutative, SDNPAssociative]>;
286def or : SDNode<"ISD::OR" , SDTIntBinOp,
287 [SDNPCommutative, SDNPAssociative]>;
288def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
289 [SDNPCommutative, SDNPAssociative]>;
290def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
291 [SDNPCommutative, SDNPOutFlag]>;
292def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
293 [SDNPCommutative, SDNPOutFlag, SDNPInFlag]>;
294def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
295 [SDNPOutFlag]>;
296def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
297 [SDNPOutFlag, SDNPInFlag]>;
298
299def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
300def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
301def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
302def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
303def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
304def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
305def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
306def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
307def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
308def bitconvert : SDNode<"ISD::BIT_CONVERT", SDTUnaryOp>;
Nate Begemanea391a22008-02-09 01:37:05 +0000309def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
310def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
311
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000312
313def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
314def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
315def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
316def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
317def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
318def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
319def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
320def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
321def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
322def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
323
324def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
325def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
326def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
327
328def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
329def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
330def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
331def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
332
333def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
334def select : SDNode<"ISD::SELECT" , SDTSelect>;
335def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
336
337def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
338def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
339def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
Chris Lattner3d254552008-01-15 22:02:54 +0000340def ret : SDNode<"ISD::RET" , SDTNone, [SDNPHasChain]>;
341def trap : SDNode<"ISD::TRAP" , SDTNone,
342 [SDNPHasChain, SDNPSideEffect]>;
Andrew Lenharth785610d2008-02-16 01:24:58 +0000343def membarrier : SDNode<"ISD::MEMBARRIER" , STDMemBarrier,
344 [SDNPHasChain, SDNPSideEffect]>;
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000345// Do not use atomic_* directly, use atomic_*_size (see below)
346def atomic_lcs : SDNode<"ISD::ATOMIC_LCS", STDAtomic3,
347 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
348def atomic_las : SDNode<"ISD::ATOMIC_LAS", STDAtomic2,
349 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
350def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", STDAtomic2,
351 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000352
353// Do not use ld, st directly. Use load, extload, sextload, zextload, store,
354// and truncst (see below).
Chris Lattnerdfde8132008-01-10 04:44:32 +0000355def ld : SDNode<"ISD::LOAD" , SDTLoad,
356 [SDNPHasChain, SDNPMayLoad]>;
Chris Lattneref8d6082008-01-06 06:44:58 +0000357def st : SDNode<"ISD::STORE" , SDTStore,
358 [SDNPHasChain, SDNPMayStore]>;
359def ist : SDNode<"ISD::STORE" , SDTIStore,
360 [SDNPHasChain, SDNPMayStore]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000361
362def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
363def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, 0, []>, []>;
364def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
365 []>;
366def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
367 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
368def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
369 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
Christopher Lambb768c2e2007-07-26 07:34:40 +0000370
371def extract_subreg : SDNode<"ISD::EXTRACT_SUBREG",
372 SDTypeProfile<1, 2, []>>;
373def insert_subreg : SDNode<"ISD::INSERT_SUBREG",
374 SDTypeProfile<1, 3, []>>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000375
376// Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
377// these internally. Don't reference these directly.
378def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
379 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
380 [SDNPHasChain]>;
381def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
382 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
383 [SDNPHasChain]>;
384def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
385 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
386
387
388//===----------------------------------------------------------------------===//
389// Selection DAG Condition Codes
390
391class CondCode; // ISD::CondCode enums
392def SETOEQ : CondCode; def SETOGT : CondCode;
393def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
394def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
395def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
396def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
397
398def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
399def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
400
401
402//===----------------------------------------------------------------------===//
403// Selection DAG Node Transformation Functions.
404//
405// This mechanism allows targets to manipulate nodes in the output DAG once a
406// match has been formed. This is typically used to manipulate immediate
407// values.
408//
409class SDNodeXForm<SDNode opc, code xformFunction> {
410 SDNode Opcode = opc;
411 code XFormFunction = xformFunction;
412}
413
414def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
415
416
417//===----------------------------------------------------------------------===//
418// Selection DAG Pattern Fragments.
419//
420// Pattern fragments are reusable chunks of dags that match specific things.
421// They can take arguments and have C++ predicates that control whether they
422// match. They are intended to make the patterns for common instructions more
423// compact and readable.
424//
425
426/// PatFrag - Represents a pattern fragment. This can match something on the
427/// DAG, frame a single node to multiply nested other fragments.
428///
429class PatFrag<dag ops, dag frag, code pred = [{}],
430 SDNodeXForm xform = NOOP_SDNodeXForm> {
431 dag Operands = ops;
432 dag Fragment = frag;
433 code Predicate = pred;
434 SDNodeXForm OperandTransform = xform;
435}
436
437// PatLeaf's are pattern fragments that have no operands. This is just a helper
438// to define immediates and other common things concisely.
439class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
440 : PatFrag<(ops), frag, pred, xform>;
441
442// Leaf fragments.
443
444def vtInt : PatLeaf<(vt), [{ return MVT::isInteger(N->getVT()); }]>;
445def vtFP : PatLeaf<(vt), [{ return MVT::isFloatingPoint(N->getVT()); }]>;
446
447def immAllOnes : PatLeaf<(imm), [{ return N->isAllOnesValue(); }]>;
448def immAllOnesV: PatLeaf<(build_vector), [{
449 return ISD::isBuildVectorAllOnes(N);
450}]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000451def immAllOnesV_bc: PatLeaf<(bitconvert), [{
452 return ISD::isBuildVectorAllOnes(N);
453}]>;
Chris Lattner8f259c02007-11-24 19:02:07 +0000454def immAllZerosV: PatLeaf<(build_vector), [{
455 return ISD::isBuildVectorAllZeros(N);
456}]>;
457def immAllZerosV_bc: PatLeaf<(bitconvert), [{
458 return ISD::isBuildVectorAllZeros(N);
459}]>;
460
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000461
462
463// Other helper fragments.
464def not : PatFrag<(ops node:$in), (xor node:$in, immAllOnes)>;
465def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
466def vnot_conv : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV_bc)>;
467def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
468
469// load fragments.
470def load : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
471 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
472 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
473 LD->getAddressingMode() == ISD::UNINDEXED;
474 return false;
475}]>;
476
477// extending load fragments.
478def extloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
479 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
480 return LD->getExtensionType() == ISD::EXTLOAD &&
481 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000482 LD->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000483 return false;
484}]>;
485def extloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
486 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
487 return LD->getExtensionType() == ISD::EXTLOAD &&
488 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000489 LD->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000490 return false;
491}]>;
492def extloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
493 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
494 return LD->getExtensionType() == ISD::EXTLOAD &&
495 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000496 LD->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000497 return false;
498}]>;
499def extloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
500 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
501 return LD->getExtensionType() == ISD::EXTLOAD &&
502 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000503 LD->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000504 return false;
505}]>;
506def extloadf32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
507 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
508 return LD->getExtensionType() == ISD::EXTLOAD &&
509 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000510 LD->getMemoryVT() == MVT::f32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000511 return false;
512}]>;
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000513def extloadf64 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
514 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
515 return LD->getExtensionType() == ISD::EXTLOAD &&
516 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000517 LD->getMemoryVT() == MVT::f64;
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000518 return false;
519}]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000520
521def sextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
522 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
523 return LD->getExtensionType() == ISD::SEXTLOAD &&
524 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000525 LD->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000526 return false;
527}]>;
528def sextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
529 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
530 return LD->getExtensionType() == ISD::SEXTLOAD &&
531 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000532 LD->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000533 return false;
534}]>;
535def sextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
536 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
537 return LD->getExtensionType() == ISD::SEXTLOAD &&
538 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000539 LD->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000540 return false;
541}]>;
542def sextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
543 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
544 return LD->getExtensionType() == ISD::SEXTLOAD &&
545 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000546 LD->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000547 return false;
548}]>;
549
550def zextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
551 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
552 return LD->getExtensionType() == ISD::ZEXTLOAD &&
553 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000554 LD->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000555 return false;
556}]>;
557def zextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
558 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
559 return LD->getExtensionType() == ISD::ZEXTLOAD &&
560 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000561 LD->getMemoryVT() == MVT::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000562 return false;
563}]>;
564def zextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
565 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
566 return LD->getExtensionType() == ISD::ZEXTLOAD &&
567 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000568 LD->getMemoryVT() == MVT::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000569 return false;
570}]>;
571def zextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
572 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
573 return LD->getExtensionType() == ISD::ZEXTLOAD &&
574 LD->getAddressingMode() == ISD::UNINDEXED &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000575 LD->getMemoryVT() == MVT::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000576 return false;
577}]>;
578
579// store fragments.
580def store : PatFrag<(ops node:$val, node:$ptr),
581 (st node:$val, node:$ptr), [{
582 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
583 return !ST->isTruncatingStore() &&
584 ST->getAddressingMode() == ISD::UNINDEXED;
585 return false;
586}]>;
587
588// truncstore fragments.
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000589def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
590 (st node:$val, node:$ptr), [{
591 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000592 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8 &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000593 ST->getAddressingMode() == ISD::UNINDEXED;
594 return false;
595}]>;
596def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
597 (st node:$val, node:$ptr), [{
598 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000599 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16 &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000600 ST->getAddressingMode() == ISD::UNINDEXED;
601 return false;
602}]>;
603def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
604 (st node:$val, node:$ptr), [{
605 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000606 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32 &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000607 ST->getAddressingMode() == ISD::UNINDEXED;
608 return false;
609}]>;
610def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
611 (st node:$val, node:$ptr), [{
612 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000613 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32 &&
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000614 ST->getAddressingMode() == ISD::UNINDEXED;
615 return false;
616}]>;
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000617def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
618 (st node:$val, node:$ptr), [{
619 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000620 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f64 &&
Dale Johannesen4ab00bd2007-08-05 18:49:15 +0000621 ST->getAddressingMode() == ISD::UNINDEXED;
622 return false;
623}]>;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000624
625// indexed store fragments.
626def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
627 (ist node:$val, node:$base, node:$offset), [{
628 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
629 ISD::MemIndexedMode AM = ST->getAddressingMode();
630 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
631 !ST->isTruncatingStore();
632 }
633 return false;
634}]>;
635
636def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
637 (ist node:$val, node:$base, node:$offset), [{
638 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
639 ISD::MemIndexedMode AM = ST->getAddressingMode();
640 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000641 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000642 }
643 return false;
644}]>;
645def pre_truncsti8 : 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::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000651 }
652 return false;
653}]>;
654def pre_truncsti16 : 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::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000660 }
661 return false;
662}]>;
663def pre_truncsti32 : 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::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000669 }
670 return false;
671}]>;
672def pre_truncstf32 : 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::f32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000678 }
679 return false;
680}]>;
681
682def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
683 (ist node:$val, node:$ptr, node:$offset), [{
684 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
685 ISD::MemIndexedMode AM = ST->getAddressingMode();
686 return !ST->isTruncatingStore() &&
687 (AM == ISD::POST_INC || AM == ISD::POST_DEC);
688 }
689 return false;
690}]>;
691
692def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
693 (ist node:$val, node:$base, node:$offset), [{
694 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
695 ISD::MemIndexedMode AM = ST->getAddressingMode();
696 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
Dan Gohman9a4c92c2008-01-30 00:15:11 +0000697 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000698 }
699 return false;
700}]>;
701def post_truncsti8 : 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::i8;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000707 }
708 return false;
709}]>;
710def post_truncsti16 : 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::i16;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000716 }
717 return false;
718}]>;
719def post_truncsti32 : 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::i32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000725 }
726 return false;
727}]>;
728def post_truncstf32 : 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::f32;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000734 }
735 return false;
736}]>;
737
Andrew Lenharthe44f3902008-02-21 06:45:13 +0000738//Atomic patterns
739def atomic_lcs_8 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
740 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
741 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
742 return V->getVT() == MVT::i8;
743 return false;
744}]>;
745def atomic_lcs_16 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
746 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
747 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
748 return V->getVT() == MVT::i16;
749 return false;
750}]>;
751def atomic_lcs_32 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
752 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
753 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
754 return V->getVT() == MVT::i32;
755 return false;
756}]>;
757def atomic_lcs_64 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
758 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
759 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
760 return V->getVT() == MVT::i64;
761 return false;
762}]>;
763
764def atomic_las_8 : PatFrag<(ops node:$ptr, node:$inc),
765 (atomic_las node:$ptr, node:$inc), [{
766 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
767 return V->getVT() == MVT::i8;
768 return false;
769}]>;
770def atomic_las_16 : PatFrag<(ops node:$ptr, node:$inc),
771 (atomic_las node:$ptr, node:$inc), [{
772 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
773 return V->getVT() == MVT::i16;
774 return false;
775}]>;
776def atomic_las_32 : PatFrag<(ops node:$ptr, node:$inc),
777 (atomic_las node:$ptr, node:$inc), [{
778 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
779 return V->getVT() == MVT::i32;
780 return false;
781}]>;
782def atomic_las_64 : PatFrag<(ops node:$ptr, node:$inc),
783 (atomic_las node:$ptr, node:$inc), [{
784 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
785 return V->getVT() == MVT::i64;
786 return false;
787}]>;
788
789def atomic_swap_8 : PatFrag<(ops node:$ptr, node:$inc),
790 (atomic_swap node:$ptr, node:$inc), [{
791 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
792 return V->getVT() == MVT::i8;
793 return false;
794}]>;
795def atomic_swap_16 : PatFrag<(ops node:$ptr, node:$inc),
796 (atomic_swap node:$ptr, node:$inc), [{
797 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
798 return V->getVT() == MVT::i16;
799 return false;
800}]>;
801def atomic_swap_32 : PatFrag<(ops node:$ptr, node:$inc),
802 (atomic_swap node:$ptr, node:$inc), [{
803 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
804 return V->getVT() == MVT::i32;
805 return false;
806}]>;
807def atomic_swap_64 : PatFrag<(ops node:$ptr, node:$inc),
808 (atomic_swap node:$ptr, node:$inc), [{
809 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
810 return V->getVT() == MVT::i64;
811 return false;
812}]>;
813
814
815
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000816// setcc convenience fragments.
817def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
818 (setcc node:$lhs, node:$rhs, SETOEQ)>;
819def setogt : PatFrag<(ops node:$lhs, node:$rhs),
820 (setcc node:$lhs, node:$rhs, SETOGT)>;
821def setoge : PatFrag<(ops node:$lhs, node:$rhs),
822 (setcc node:$lhs, node:$rhs, SETOGE)>;
823def setolt : PatFrag<(ops node:$lhs, node:$rhs),
824 (setcc node:$lhs, node:$rhs, SETOLT)>;
825def setole : PatFrag<(ops node:$lhs, node:$rhs),
826 (setcc node:$lhs, node:$rhs, SETOLE)>;
827def setone : PatFrag<(ops node:$lhs, node:$rhs),
828 (setcc node:$lhs, node:$rhs, SETONE)>;
829def seto : PatFrag<(ops node:$lhs, node:$rhs),
830 (setcc node:$lhs, node:$rhs, SETO)>;
831def setuo : PatFrag<(ops node:$lhs, node:$rhs),
832 (setcc node:$lhs, node:$rhs, SETUO)>;
833def setueq : PatFrag<(ops node:$lhs, node:$rhs),
834 (setcc node:$lhs, node:$rhs, SETUEQ)>;
835def setugt : PatFrag<(ops node:$lhs, node:$rhs),
836 (setcc node:$lhs, node:$rhs, SETUGT)>;
837def setuge : PatFrag<(ops node:$lhs, node:$rhs),
838 (setcc node:$lhs, node:$rhs, SETUGE)>;
839def setult : PatFrag<(ops node:$lhs, node:$rhs),
840 (setcc node:$lhs, node:$rhs, SETULT)>;
841def setule : PatFrag<(ops node:$lhs, node:$rhs),
842 (setcc node:$lhs, node:$rhs, SETULE)>;
843def setune : PatFrag<(ops node:$lhs, node:$rhs),
844 (setcc node:$lhs, node:$rhs, SETUNE)>;
845def seteq : PatFrag<(ops node:$lhs, node:$rhs),
846 (setcc node:$lhs, node:$rhs, SETEQ)>;
847def setgt : PatFrag<(ops node:$lhs, node:$rhs),
848 (setcc node:$lhs, node:$rhs, SETGT)>;
849def setge : PatFrag<(ops node:$lhs, node:$rhs),
850 (setcc node:$lhs, node:$rhs, SETGE)>;
851def setlt : PatFrag<(ops node:$lhs, node:$rhs),
852 (setcc node:$lhs, node:$rhs, SETLT)>;
853def setle : PatFrag<(ops node:$lhs, node:$rhs),
854 (setcc node:$lhs, node:$rhs, SETLE)>;
855def setne : PatFrag<(ops node:$lhs, node:$rhs),
856 (setcc node:$lhs, node:$rhs, SETNE)>;
857
858//===----------------------------------------------------------------------===//
859// Selection DAG Pattern Support.
860//
861// Patterns are what are actually matched against the target-flavored
862// instruction selection DAG. Instructions defined by the target implicitly
863// define patterns in most cases, but patterns can also be explicitly added when
864// an operation is defined by a sequence of instructions (e.g. loading a large
865// immediate value on RISC targets that do not support immediates as large as
866// their GPRs).
867//
868
869class Pattern<dag patternToMatch, list<dag> resultInstrs> {
870 dag PatternToMatch = patternToMatch;
871 list<dag> ResultInstrs = resultInstrs;
872 list<Predicate> Predicates = []; // See class Instruction in Target.td.
873 int AddedComplexity = 0; // See class Instruction in Target.td.
874}
875
876// Pat - A simple (but common) form of a pattern, which produces a simple result
877// not needing a full list.
878class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
879
880//===----------------------------------------------------------------------===//
881// Complex pattern definitions.
882//
Christopher Lamb059c7c92008-01-31 07:27:46 +0000883
884class CPAttribute;
885// Pass the parent Operand as root to CP function rather
886// than the root of the sub-DAG
887def CPAttrParentAsRoot : CPAttribute;
888
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000889// Complex patterns, e.g. X86 addressing mode, requires pattern matching code
890// in C++. NumOperands is the number of operands returned by the select function;
891// SelectFunc is the name of the function used to pattern match the max. pattern;
892// RootNodes are the list of possible root nodes of the sub-dags to match.
893// e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
894//
895class ComplexPattern<ValueType ty, int numops, string fn,
Christopher Lamb059c7c92008-01-31 07:27:46 +0000896 list<SDNode> roots = [], list<SDNodeProperty> props = [],
897 list<CPAttribute> attrs = []> {
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000898 ValueType Ty = ty;
899 int NumOperands = numops;
900 string SelectFunc = fn;
901 list<SDNode> RootNodes = roots;
902 list<SDNodeProperty> Properties = props;
Christopher Lamb059c7c92008-01-31 07:27:46 +0000903 list<CPAttribute> Attributes = attrs;
Dan Gohmanf17a25c2007-07-18 16:29:46 +0000904}
905
906//===----------------------------------------------------------------------===//
907// Dwarf support.
908//
909def SDT_dwarf_loc : SDTypeProfile<0, 3,
910 [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
911def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;
912
913
914