1 //===- TargetSelectionDAG.td - Common code for DAG isels ---*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the target-independent interfaces used by SelectionDAG
11 // instruction selection generators.
13 //===----------------------------------------------------------------------===//
15 //===----------------------------------------------------------------------===//
16 // Selection DAG Type Constraint definitions.
18 // Note that the semantics of these constraints are hard coded into tblgen. To
19 // modify or add constraints, you have to hack tblgen.
22 class SDTypeConstraint<int opnum> {
23 int OperandNum = opnum;
26 // SDTCisVT - The specified operand has exactly this VT.
27 class SDTCisVT<int OpNum, ValueType vt> : SDTypeConstraint<OpNum> {
31 class SDTCisPtrTy<int OpNum> : SDTypeConstraint<OpNum>;
33 // SDTCisInt - The specified operand is has integer type.
34 class SDTCisInt<int OpNum> : SDTypeConstraint<OpNum>;
36 // SDTCisFP - The specified operand is has floating point type.
37 class SDTCisFP<int OpNum> : SDTypeConstraint<OpNum>;
39 // SDTCisSameAs - The two specified operands have identical types.
40 class SDTCisSameAs<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
41 int OtherOperandNum = OtherOp;
44 // SDTCisVTSmallerThanOp - The specified operand is a VT SDNode, and its type is
45 // smaller than the 'Other' operand.
46 class SDTCisVTSmallerThanOp<int OpNum, int OtherOp> : SDTypeConstraint<OpNum> {
47 int OtherOperandNum = OtherOp;
50 class SDTCisOpSmallerThanOp<int SmallOp, int BigOp> : SDTypeConstraint<SmallOp>{
51 int BigOperandNum = BigOp;
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
58 class SDTCisIntVectorOfSameSize<int ThisOp, int OtherOp>
59 : SDTypeConstraint<ThisOp> {
60 int OtherOpNum = OtherOp;
63 /// 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.
65 class SDTCisEltOfVec<int ThisOp, int OtherOp>
66 : SDTypeConstraint<ThisOp> {
67 int OtherOpNum = OtherOp;
70 //===----------------------------------------------------------------------===//
71 // Selection DAG Type Profile definitions.
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.
78 // SDTypeProfile - This profile describes the type requirements of a Selection
80 class SDTypeProfile<int numresults, int numoperands,
81 list<SDTypeConstraint> constraints> {
82 int NumResults = numresults;
83 int NumOperands = numoperands;
84 list<SDTypeConstraint> Constraints = constraints;
88 def SDTIntLeaf: SDTypeProfile<1, 0, [SDTCisInt<0>]>; // for 'imm'.
89 def SDTFPLeaf : SDTypeProfile<1, 0, [SDTCisFP<0>]>; // for 'fpimm'.
90 def SDTPtrLeaf: SDTypeProfile<1, 0, [SDTCisPtrTy<0>]>; // for '&g'.
91 def SDTOther : SDTypeProfile<1, 0, [SDTCisVT<0, OtherVT>]>; // for 'vt'.
92 def SDTUNDEF : SDTypeProfile<1, 0, []>; // for 'undef'.
93 def SDTUnaryOp : SDTypeProfile<1, 1, []>; // for bitconvert.
95 def SDTIntBinOp : SDTypeProfile<1, 2, [ // add, and, or, xor, udiv, etc.
96 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisInt<0>
98 def SDTIntShiftOp : SDTypeProfile<1, 2, [ // shl, sra, srl
99 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<2>
101 def SDTFPBinOp : SDTypeProfile<1, 2, [ // fadd, fmul, etc.
102 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisFP<0>
104 def SDTFPSignOp : SDTypeProfile<1, 2, [ // fcopysign.
105 SDTCisSameAs<0, 1>, SDTCisFP<0>, SDTCisFP<2>
107 def SDTFPTernaryOp : SDTypeProfile<1, 3, [ // fmadd, fnmsub, etc.
108 SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>, SDTCisSameAs<0, 3>, SDTCisFP<0>
110 def SDTIntUnaryOp : SDTypeProfile<1, 1, [ // ctlz
111 SDTCisSameAs<0, 1>, SDTCisInt<0>
113 def SDTIntExtendOp : SDTypeProfile<1, 1, [ // sext, zext, anyext
114 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<1, 0>
116 def SDTIntTruncOp : SDTypeProfile<1, 1, [ // trunc
117 SDTCisInt<0>, SDTCisInt<1>, SDTCisOpSmallerThanOp<0, 1>
119 def SDTFPUnaryOp : SDTypeProfile<1, 1, [ // fneg, fsqrt, etc
120 SDTCisSameAs<0, 1>, SDTCisFP<0>
122 def SDTFPRoundOp : SDTypeProfile<1, 1, [ // fround
123 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<0, 1>
125 def SDTFPExtendOp : SDTypeProfile<1, 1, [ // fextend
126 SDTCisFP<0>, SDTCisFP<1>, SDTCisOpSmallerThanOp<1, 0>
128 def SDTIntToFPOp : SDTypeProfile<1, 1, [ // [su]int_to_fp
129 SDTCisFP<0>, SDTCisInt<1>
131 def SDTFPToIntOp : SDTypeProfile<1, 1, [ // fp_to_[su]int
132 SDTCisInt<0>, SDTCisFP<1>
134 def SDTExtInreg : SDTypeProfile<1, 2, [ // sext_inreg
135 SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisVT<2, OtherVT>,
136 SDTCisVTSmallerThanOp<2, 1>
139 def SDTSetCC : SDTypeProfile<1, 3, [ // setcc
140 SDTCisInt<0>, SDTCisSameAs<1, 2>, SDTCisVT<3, OtherVT>
143 def SDTSelect : SDTypeProfile<1, 3, [ // select
144 SDTCisInt<1>, SDTCisSameAs<0, 2>, SDTCisSameAs<2, 3>
147 def SDTSelectCC : SDTypeProfile<1, 5, [ // select_cc
148 SDTCisSameAs<1, 2>, SDTCisSameAs<3, 4>, SDTCisSameAs<0, 3>,
152 def SDTBr : SDTypeProfile<0, 1, [ // br
156 def SDTBrcond : SDTypeProfile<0, 2, [ // brcond
157 SDTCisInt<0>, SDTCisVT<1, OtherVT>
160 def SDTBrind : SDTypeProfile<0, 1, [ // brind
164 def SDTNone : SDTypeProfile<0, 0, []>; // ret, trap
166 def SDTLoad : SDTypeProfile<1, 1, [ // load
170 def SDTStore : SDTypeProfile<0, 2, [ // store
174 def SDTIStore : SDTypeProfile<1, 3, [ // indexed store
175 SDTCisSameAs<0, 2>, SDTCisPtrTy<0>, SDTCisPtrTy<3>
178 def SDTVecShuffle : SDTypeProfile<1, 3, [
179 SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisIntVectorOfSameSize<3, 0>
181 def SDTVecExtract : SDTypeProfile<1, 2, [ // vector extract
182 SDTCisEltOfVec<0, 1>, SDTCisPtrTy<2>
184 def SDTVecInsert : SDTypeProfile<1, 3, [ // vector insert
185 SDTCisEltOfVec<2, 1>, SDTCisSameAs<0, 1>, SDTCisPtrTy<3>
188 def STDPrefetch : SDTypeProfile<0, 3, [ // prefetch
189 SDTCisPtrTy<0>, SDTCisSameAs<1, 2>, SDTCisInt<1>
192 def STDMemBarrier : SDTypeProfile<0, 5, [ // memory barier
193 SDTCisSameAs<0,1>, SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisSameAs<0,4>,
196 def STDAtomic3 : SDTypeProfile<1, 3, [
197 SDTCisSameAs<0,2>, SDTCisSameAs<0,3>, SDTCisInt<0>, SDTCisPtrTy<1>
199 def STDAtomic2 : SDTypeProfile<1, 2, [
200 SDTCisSameAs<0,2>, SDTCisInt<0>, SDTCisPtrTy<1>
203 def SDTConvertOp : SDTypeProfile<1, 5, [ //cvtss, su, us, uu, ff, fs, fu, sf, su
204 SDTCisVT<2, OtherVT>, SDTCisVT<3, OtherVT>, SDTCisPtrTy<4>, SDTCisPtrTy<5>
207 class SDCallSeqStart<list<SDTypeConstraint> constraints> :
208 SDTypeProfile<0, 1, constraints>;
209 class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
210 SDTypeProfile<0, 2, constraints>;
212 //===----------------------------------------------------------------------===//
213 // Selection DAG Node Properties.
215 // Note: These are hard coded into tblgen.
217 class SDNodeProperty;
218 def SDNPCommutative : SDNodeProperty; // X op Y == Y op X
219 def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z)
220 def SDNPHasChain : SDNodeProperty; // R/W chain operand and result
221 def SDNPOutFlag : SDNodeProperty; // Write a flag result
222 def SDNPInFlag : SDNodeProperty; // Read a flag operand
223 def SDNPOptInFlag : SDNodeProperty; // Optionally read a flag operand
224 def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'.
225 def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'.
226 def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'.
227 def SDNPMemOperand : SDNodeProperty; // Touches memory, has assoc MemOperand
229 //===----------------------------------------------------------------------===//
230 // Selection DAG Node definitions.
232 class SDNode<string opcode, SDTypeProfile typeprof,
233 list<SDNodeProperty> props = [], string sdclass = "SDNode"> {
234 string Opcode = opcode;
235 string SDClass = sdclass;
236 list<SDNodeProperty> Properties = props;
237 SDTypeProfile TypeProfile = typeprof;
246 def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
247 def timm : SDNode<"ISD::TargetConstant",SDTIntLeaf, [], "ConstantSDNode">;
248 def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
249 def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
250 def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
251 def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
252 def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
253 def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
254 "GlobalAddressSDNode">;
255 def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
256 "GlobalAddressSDNode">;
257 def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
258 "GlobalAddressSDNode">;
259 def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
260 "GlobalAddressSDNode">;
261 def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
262 "ConstantPoolSDNode">;
263 def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
264 "ConstantPoolSDNode">;
265 def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
267 def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
269 def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
271 def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
273 def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
274 "ExternalSymbolSDNode">;
275 def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
276 "ExternalSymbolSDNode">;
278 def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
279 [SDNPCommutative, SDNPAssociative]>;
280 def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
281 def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
282 [SDNPCommutative, SDNPAssociative]>;
283 def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
284 def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
285 def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
286 def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
287 def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
288 def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
289 def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
290 def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
291 def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
292 def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
293 def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
294 def and : SDNode<"ISD::AND" , SDTIntBinOp,
295 [SDNPCommutative, SDNPAssociative]>;
296 def or : SDNode<"ISD::OR" , SDTIntBinOp,
297 [SDNPCommutative, SDNPAssociative]>;
298 def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
299 [SDNPCommutative, SDNPAssociative]>;
300 def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
301 [SDNPCommutative, SDNPOutFlag]>;
302 def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
303 [SDNPCommutative, SDNPOutFlag, SDNPInFlag]>;
304 def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
306 def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
307 [SDNPOutFlag, SDNPInFlag]>;
309 def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
310 def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
311 def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
312 def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
313 def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
314 def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
315 def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
316 def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
317 def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
318 def bitconvert : SDNode<"ISD::BIT_CONVERT", SDTUnaryOp>;
319 def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
320 def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
323 def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
324 def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
325 def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
326 def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
327 def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
328 def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
329 def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
330 def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
331 def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
332 def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
333 def frint : SDNode<"ISD::FRINT" , SDTFPUnaryOp>;
334 def ftrunc : SDNode<"ISD::FTRUNC" , SDTFPUnaryOp>;
335 def fceil : SDNode<"ISD::FCEIL" , SDTFPUnaryOp>;
336 def ffloor : SDNode<"ISD::FFLOOR" , SDTFPUnaryOp>;
337 def fnearbyint : SDNode<"ISD::FNEARBYINT" , SDTFPUnaryOp>;
339 def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
340 def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
341 def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
343 def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
344 def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
345 def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
346 def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
348 def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
349 def select : SDNode<"ISD::SELECT" , SDTSelect>;
350 def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
351 def vsetcc : SDNode<"ISD::VSETCC" , SDTSetCC>;
353 def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
354 def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
355 def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
356 def ret : SDNode<"ISD::RET" , SDTNone, [SDNPHasChain]>;
357 def trap : SDNode<"ISD::TRAP" , SDTNone,
358 [SDNPHasChain, SDNPSideEffect]>;
360 def prefetch : SDNode<"ISD::PREFETCH" , STDPrefetch,
361 [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
363 def membarrier : SDNode<"ISD::MEMBARRIER" , STDMemBarrier,
364 [SDNPHasChain, SDNPSideEffect]>;
366 def atomic_cmp_swap : SDNode<"ISD::ATOMIC_CMP_SWAP" , STDAtomic3,
367 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
368 def atomic_load_add : SDNode<"ISD::ATOMIC_LOAD_ADD" , STDAtomic2,
369 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
370 def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", STDAtomic2,
371 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
372 def atomic_load_sub : SDNode<"ISD::ATOMIC_LOAD_SUB" , STDAtomic2,
373 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
374 def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , STDAtomic2,
375 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
376 def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , STDAtomic2,
377 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
378 def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , STDAtomic2,
379 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
380 def atomic_load_nand: SDNode<"ISD::ATOMIC_LOAD_NAND", STDAtomic2,
381 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
382 def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", STDAtomic2,
383 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
384 def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", STDAtomic2,
385 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
386 def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", STDAtomic2,
387 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
388 def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", STDAtomic2,
389 [SDNPHasChain, SDNPMayStore, SDNPMayLoad, SDNPMemOperand]>;
391 // Do not use ld, st directly. Use load, extload, sextload, zextload, store,
392 // and truncst (see below).
393 def ld : SDNode<"ISD::LOAD" , SDTLoad,
394 [SDNPHasChain, SDNPMayLoad, SDNPMemOperand]>;
395 def st : SDNode<"ISD::STORE" , SDTStore,
396 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
397 def ist : SDNode<"ISD::STORE" , SDTIStore,
398 [SDNPHasChain, SDNPMayStore, SDNPMemOperand]>;
400 def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
401 def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, -1, []>, []>;
402 def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
404 def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
405 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
406 def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
407 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
409 def extract_subreg : SDNode<"ISD::EXTRACT_SUBREG",
410 SDTypeProfile<1, 2, []>>;
411 def insert_subreg : SDNode<"ISD::INSERT_SUBREG",
412 SDTypeProfile<1, 3, []>>;
414 // Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
415 // these internally. Don't reference these directly.
416 def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
417 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
419 def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
420 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
422 def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
423 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
425 // Do not use cvt directly. Use cvt forms below
426 def cvt : SDNode<"ISD::CONVERT_RNDSAT", SDTConvertOp>;
428 //===----------------------------------------------------------------------===//
429 // Selection DAG Condition Codes
431 class CondCode; // ISD::CondCode enums
432 def SETOEQ : CondCode; def SETOGT : CondCode;
433 def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
434 def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
435 def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
436 def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
438 def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
439 def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
442 //===----------------------------------------------------------------------===//
443 // Selection DAG Node Transformation Functions.
445 // This mechanism allows targets to manipulate nodes in the output DAG once a
446 // match has been formed. This is typically used to manipulate immediate
449 class SDNodeXForm<SDNode opc, code xformFunction> {
451 code XFormFunction = xformFunction;
454 def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
457 //===----------------------------------------------------------------------===//
458 // Selection DAG Pattern Fragments.
460 // Pattern fragments are reusable chunks of dags that match specific things.
461 // They can take arguments and have C++ predicates that control whether they
462 // match. They are intended to make the patterns for common instructions more
463 // compact and readable.
466 /// PatFrag - Represents a pattern fragment. This can match something on the
467 /// DAG, frame a single node to multiply nested other fragments.
469 class PatFrag<dag ops, dag frag, code pred = [{}],
470 SDNodeXForm xform = NOOP_SDNodeXForm> {
473 code Predicate = pred;
474 SDNodeXForm OperandTransform = xform;
477 // PatLeaf's are pattern fragments that have no operands. This is just a helper
478 // to define immediates and other common things concisely.
479 class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
480 : PatFrag<(ops), frag, pred, xform>;
484 def vtInt : PatLeaf<(vt), [{ return N->getVT().isInteger(); }]>;
485 def vtFP : PatLeaf<(vt), [{ return N->getVT().isFloatingPoint(); }]>;
487 def immAllOnes : PatLeaf<(imm), [{ return N->isAllOnesValue(); }]>;
488 def immAllOnesV: PatLeaf<(build_vector), [{
489 return ISD::isBuildVectorAllOnes(N);
491 def immAllOnesV_bc: PatLeaf<(bitconvert), [{
492 return ISD::isBuildVectorAllOnes(N);
494 def immAllZerosV: PatLeaf<(build_vector), [{
495 return ISD::isBuildVectorAllZeros(N);
497 def immAllZerosV_bc: PatLeaf<(bitconvert), [{
498 return ISD::isBuildVectorAllZeros(N);
503 // Other helper fragments.
504 def not : PatFrag<(ops node:$in), (xor node:$in, immAllOnes)>;
505 def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
506 def vnot_conv : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV_bc)>;
507 def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
510 def unindexedload : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
511 return cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
513 def load : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
514 return cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
517 // extending load fragments.
518 def extload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
519 return cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
521 def sextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
522 return cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
524 def zextload : PatFrag<(ops node:$ptr), (unindexedload node:$ptr), [{
525 return cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
528 def extloadi1 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
529 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
531 def extloadi8 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
532 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
534 def extloadi16 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
535 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
537 def extloadi32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
538 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
540 def extloadf32 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
541 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::f32;
543 def extloadf64 : PatFrag<(ops node:$ptr), (extload node:$ptr), [{
544 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::f64;
547 def sextloadi1 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
548 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
550 def sextloadi8 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
551 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
553 def sextloadi16 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
554 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
556 def sextloadi32 : PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
557 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
560 def zextloadi1 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
561 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i1;
563 def zextloadi8 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
564 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i8;
566 def zextloadi16 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
567 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i16;
569 def zextloadi32 : PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
570 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::i32;
574 def unindexedstore : PatFrag<(ops node:$val, node:$ptr),
575 (st node:$val, node:$ptr), [{
576 return cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
578 def store : PatFrag<(ops node:$val, node:$ptr),
579 (unindexedstore node:$val, node:$ptr), [{
580 return !cast<StoreSDNode>(N)->isTruncatingStore();
583 // truncstore fragments.
584 def truncstore : PatFrag<(ops node:$val, node:$ptr),
585 (unindexedstore node:$val, node:$ptr), [{
586 return cast<StoreSDNode>(N)->isTruncatingStore();
588 def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
589 (truncstore node:$val, node:$ptr), [{
590 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
592 def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
593 (truncstore node:$val, node:$ptr), [{
594 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
596 def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
597 (truncstore node:$val, node:$ptr), [{
598 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
600 def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
601 (truncstore node:$val, node:$ptr), [{
602 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
604 def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
605 (truncstore node:$val, node:$ptr), [{
606 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f64;
609 // indexed store fragments.
610 def istore : PatFrag<(ops node:$val, node:$base, node:$offset),
611 (ist node:$val, node:$base, node:$offset), [{
612 return !cast<StoreSDNode>(N)->isTruncatingStore();
615 def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
616 (istore node:$val, node:$base, node:$offset), [{
617 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
618 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
621 def itruncstore : PatFrag<(ops node:$val, node:$base, node:$offset),
622 (ist node:$val, node:$base, node:$offset), [{
623 return cast<StoreSDNode>(N)->isTruncatingStore();
625 def pre_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
626 (itruncstore node:$val, node:$base, node:$offset), [{
627 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
628 return AM == ISD::PRE_INC || AM == ISD::PRE_DEC;
630 def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
631 (pre_truncst node:$val, node:$base, node:$offset), [{
632 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i1;
634 def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
635 (pre_truncst node:$val, node:$base, node:$offset), [{
636 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
638 def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
639 (pre_truncst node:$val, node:$base, node:$offset), [{
640 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
642 def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
643 (pre_truncst node:$val, node:$base, node:$offset), [{
644 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
646 def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
647 (pre_truncst node:$val, node:$base, node:$offset), [{
648 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
651 def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
652 (istore node:$val, node:$ptr, node:$offset), [{
653 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
654 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
657 def post_truncst : PatFrag<(ops node:$val, node:$base, node:$offset),
658 (itruncstore node:$val, node:$base, node:$offset), [{
659 ISD::MemIndexedMode AM = cast<StoreSDNode>(N)->getAddressingMode();
660 return AM == ISD::POST_INC || AM == ISD::POST_DEC;
662 def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
663 (post_truncst node:$val, node:$base, node:$offset), [{
664 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i1;
666 def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
667 (post_truncst node:$val, node:$base, node:$offset), [{
668 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i8;
670 def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
671 (post_truncst node:$val, node:$base, node:$offset), [{
672 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i16;
674 def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
675 (post_truncst node:$val, node:$base, node:$offset), [{
676 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::i32;
678 def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
679 (post_truncst node:$val, node:$base, node:$offset), [{
680 return cast<StoreSDNode>(N)->getMemoryVT() == MVT::f32;
683 // setcc convenience fragments.
684 def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
685 (setcc node:$lhs, node:$rhs, SETOEQ)>;
686 def setogt : PatFrag<(ops node:$lhs, node:$rhs),
687 (setcc node:$lhs, node:$rhs, SETOGT)>;
688 def setoge : PatFrag<(ops node:$lhs, node:$rhs),
689 (setcc node:$lhs, node:$rhs, SETOGE)>;
690 def setolt : PatFrag<(ops node:$lhs, node:$rhs),
691 (setcc node:$lhs, node:$rhs, SETOLT)>;
692 def setole : PatFrag<(ops node:$lhs, node:$rhs),
693 (setcc node:$lhs, node:$rhs, SETOLE)>;
694 def setone : PatFrag<(ops node:$lhs, node:$rhs),
695 (setcc node:$lhs, node:$rhs, SETONE)>;
696 def seto : PatFrag<(ops node:$lhs, node:$rhs),
697 (setcc node:$lhs, node:$rhs, SETO)>;
698 def setuo : PatFrag<(ops node:$lhs, node:$rhs),
699 (setcc node:$lhs, node:$rhs, SETUO)>;
700 def setueq : PatFrag<(ops node:$lhs, node:$rhs),
701 (setcc node:$lhs, node:$rhs, SETUEQ)>;
702 def setugt : PatFrag<(ops node:$lhs, node:$rhs),
703 (setcc node:$lhs, node:$rhs, SETUGT)>;
704 def setuge : PatFrag<(ops node:$lhs, node:$rhs),
705 (setcc node:$lhs, node:$rhs, SETUGE)>;
706 def setult : PatFrag<(ops node:$lhs, node:$rhs),
707 (setcc node:$lhs, node:$rhs, SETULT)>;
708 def setule : PatFrag<(ops node:$lhs, node:$rhs),
709 (setcc node:$lhs, node:$rhs, SETULE)>;
710 def setune : PatFrag<(ops node:$lhs, node:$rhs),
711 (setcc node:$lhs, node:$rhs, SETUNE)>;
712 def seteq : PatFrag<(ops node:$lhs, node:$rhs),
713 (setcc node:$lhs, node:$rhs, SETEQ)>;
714 def setgt : PatFrag<(ops node:$lhs, node:$rhs),
715 (setcc node:$lhs, node:$rhs, SETGT)>;
716 def setge : PatFrag<(ops node:$lhs, node:$rhs),
717 (setcc node:$lhs, node:$rhs, SETGE)>;
718 def setlt : PatFrag<(ops node:$lhs, node:$rhs),
719 (setcc node:$lhs, node:$rhs, SETLT)>;
720 def setle : PatFrag<(ops node:$lhs, node:$rhs),
721 (setcc node:$lhs, node:$rhs, SETLE)>;
722 def setne : PatFrag<(ops node:$lhs, node:$rhs),
723 (setcc node:$lhs, node:$rhs, SETNE)>;
725 def atomic_cmp_swap_8 :
726 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
727 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
728 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
730 def atomic_cmp_swap_16 :
731 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
732 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
733 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
735 def atomic_cmp_swap_32 :
736 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
737 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
738 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
740 def atomic_cmp_swap_64 :
741 PatFrag<(ops node:$ptr, node:$cmp, node:$swap),
742 (atomic_cmp_swap node:$ptr, node:$cmp, node:$swap), [{
743 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
746 multiclass binary_atomic_op<SDNode atomic_op> {
747 def _8 : PatFrag<(ops node:$ptr, node:$val),
748 (atomic_op node:$ptr, node:$val), [{
749 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i8;
751 def _16 : PatFrag<(ops node:$ptr, node:$val),
752 (atomic_op node:$ptr, node:$val), [{
753 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i16;
755 def _32 : PatFrag<(ops node:$ptr, node:$val),
756 (atomic_op node:$ptr, node:$val), [{
757 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i32;
759 def _64 : PatFrag<(ops node:$ptr, node:$val),
760 (atomic_op node:$ptr, node:$val), [{
761 return cast<AtomicSDNode>(N)->getMemoryVT() == MVT::i64;
765 defm atomic_load_add : binary_atomic_op<atomic_load_add>;
766 defm atomic_swap : binary_atomic_op<atomic_swap>;
767 defm atomic_load_sub : binary_atomic_op<atomic_load_sub>;
768 defm atomic_load_and : binary_atomic_op<atomic_load_and>;
769 defm atomic_load_or : binary_atomic_op<atomic_load_or>;
770 defm atomic_load_xor : binary_atomic_op<atomic_load_xor>;
771 defm atomic_load_nand : binary_atomic_op<atomic_load_nand>;
772 defm atomic_load_min : binary_atomic_op<atomic_load_min>;
773 defm atomic_load_max : binary_atomic_op<atomic_load_max>;
774 defm atomic_load_umin : binary_atomic_op<atomic_load_umin>;
775 defm atomic_load_umax : binary_atomic_op<atomic_load_umax>;
777 //===----------------------------------------------------------------------===//
778 // Selection DAG CONVERT_RNDSAT patterns
780 def cvtff : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
781 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
782 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FF;
785 def cvtss : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
786 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
787 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SS;
790 def cvtsu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
791 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
792 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SU;
795 def cvtus : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
796 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
797 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_US;
800 def cvtuu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
801 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
802 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_UU;
805 def cvtsf : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
806 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
807 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_SF;
810 def cvtuf : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
811 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
812 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_UF;
815 def cvtfs : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
816 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
817 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FS;
820 def cvtfu : PatFrag<(ops node:$val, node:$dty, node:$sty, node:$rd, node:$sat),
821 (cvt node:$val, node:$dty, node:$sty, node:$rd, node:$sat), [{
822 return cast<CvtRndSatSDNode>(N)->getCvtCode() == ISD::CVT_FU;
825 //===----------------------------------------------------------------------===//
826 // Selection DAG Pattern Support.
828 // Patterns are what are actually matched against the target-flavored
829 // instruction selection DAG. Instructions defined by the target implicitly
830 // define patterns in most cases, but patterns can also be explicitly added when
831 // an operation is defined by a sequence of instructions (e.g. loading a large
832 // immediate value on RISC targets that do not support immediates as large as
836 class Pattern<dag patternToMatch, list<dag> resultInstrs> {
837 dag PatternToMatch = patternToMatch;
838 list<dag> ResultInstrs = resultInstrs;
839 list<Predicate> Predicates = []; // See class Instruction in Target.td.
840 int AddedComplexity = 0; // See class Instruction in Target.td.
843 // Pat - A simple (but common) form of a pattern, which produces a simple result
844 // not needing a full list.
845 class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
847 //===----------------------------------------------------------------------===//
848 // Complex pattern definitions.
852 // Pass the parent Operand as root to CP function rather
853 // than the root of the sub-DAG
854 def CPAttrParentAsRoot : CPAttribute;
856 // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
857 // in C++. NumOperands is the number of operands returned by the select function;
858 // SelectFunc is the name of the function used to pattern match the max. pattern;
859 // RootNodes are the list of possible root nodes of the sub-dags to match.
860 // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
862 class ComplexPattern<ValueType ty, int numops, string fn,
863 list<SDNode> roots = [], list<SDNodeProperty> props = [],
864 list<CPAttribute> attrs = []> {
866 int NumOperands = numops;
867 string SelectFunc = fn;
868 list<SDNode> RootNodes = roots;
869 list<SDNodeProperty> Properties = props;
870 list<CPAttribute> Attributes = attrs;
873 //===----------------------------------------------------------------------===//
876 def SDT_dwarf_loc : SDTypeProfile<0, 3,
877 [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
878 def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;