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 that ThisOp
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, []>; // 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 class SDCallSeqStart<list<SDTypeConstraint> constraints> :
204 SDTypeProfile<0, 1, constraints>;
205 class SDCallSeqEnd<list<SDTypeConstraint> constraints> :
206 SDTypeProfile<0, 2, constraints>;
208 //===----------------------------------------------------------------------===//
209 // Selection DAG Node Properties.
211 // Note: These are hard coded into tblgen.
213 class SDNodeProperty;
214 def SDNPCommutative : SDNodeProperty; // X op Y == Y op X
215 def SDNPAssociative : SDNodeProperty; // (X op Y) op Z == X op (Y op Z)
216 def SDNPHasChain : SDNodeProperty; // R/W chain operand and result
217 def SDNPOutFlag : SDNodeProperty; // Write a flag result
218 def SDNPInFlag : SDNodeProperty; // Read a flag operand
219 def SDNPOptInFlag : SDNodeProperty; // Optionally read a flag operand
220 def SDNPMayStore : SDNodeProperty; // May write to memory, sets 'mayStore'.
221 def SDNPMayLoad : SDNodeProperty; // May read memory, sets 'mayLoad'.
222 def SDNPSideEffect : SDNodeProperty; // Sets 'HasUnmodelledSideEffects'.
224 //===----------------------------------------------------------------------===//
225 // Selection DAG Node definitions.
227 class 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;
241 def imm : SDNode<"ISD::Constant" , SDTIntLeaf , [], "ConstantSDNode">;
242 def fpimm : SDNode<"ISD::ConstantFP", SDTFPLeaf , [], "ConstantFPSDNode">;
243 def vt : SDNode<"ISD::VALUETYPE" , SDTOther , [], "VTSDNode">;
244 def bb : SDNode<"ISD::BasicBlock", SDTOther , [], "BasicBlockSDNode">;
245 def cond : SDNode<"ISD::CONDCODE" , SDTOther , [], "CondCodeSDNode">;
246 def undef : SDNode<"ISD::UNDEF" , SDTUNDEF , []>;
247 def globaladdr : SDNode<"ISD::GlobalAddress", SDTPtrLeaf, [],
248 "GlobalAddressSDNode">;
249 def tglobaladdr : SDNode<"ISD::TargetGlobalAddress", SDTPtrLeaf, [],
250 "GlobalAddressSDNode">;
251 def globaltlsaddr : SDNode<"ISD::GlobalTLSAddress", SDTPtrLeaf, [],
252 "GlobalAddressSDNode">;
253 def tglobaltlsaddr : SDNode<"ISD::TargetGlobalTLSAddress", SDTPtrLeaf, [],
254 "GlobalAddressSDNode">;
255 def constpool : SDNode<"ISD::ConstantPool", SDTPtrLeaf, [],
256 "ConstantPoolSDNode">;
257 def tconstpool : SDNode<"ISD::TargetConstantPool", SDTPtrLeaf, [],
258 "ConstantPoolSDNode">;
259 def jumptable : SDNode<"ISD::JumpTable", SDTPtrLeaf, [],
261 def tjumptable : SDNode<"ISD::TargetJumpTable", SDTPtrLeaf, [],
263 def frameindex : SDNode<"ISD::FrameIndex", SDTPtrLeaf, [],
265 def tframeindex : SDNode<"ISD::TargetFrameIndex", SDTPtrLeaf, [],
267 def externalsym : SDNode<"ISD::ExternalSymbol", SDTPtrLeaf, [],
268 "ExternalSymbolSDNode">;
269 def texternalsym: SDNode<"ISD::TargetExternalSymbol", SDTPtrLeaf, [],
270 "ExternalSymbolSDNode">;
272 def add : SDNode<"ISD::ADD" , SDTIntBinOp ,
273 [SDNPCommutative, SDNPAssociative]>;
274 def sub : SDNode<"ISD::SUB" , SDTIntBinOp>;
275 def mul : SDNode<"ISD::MUL" , SDTIntBinOp,
276 [SDNPCommutative, SDNPAssociative]>;
277 def mulhs : SDNode<"ISD::MULHS" , SDTIntBinOp, [SDNPCommutative]>;
278 def mulhu : SDNode<"ISD::MULHU" , SDTIntBinOp, [SDNPCommutative]>;
279 def sdiv : SDNode<"ISD::SDIV" , SDTIntBinOp>;
280 def udiv : SDNode<"ISD::UDIV" , SDTIntBinOp>;
281 def srem : SDNode<"ISD::SREM" , SDTIntBinOp>;
282 def urem : SDNode<"ISD::UREM" , SDTIntBinOp>;
283 def srl : SDNode<"ISD::SRL" , SDTIntShiftOp>;
284 def sra : SDNode<"ISD::SRA" , SDTIntShiftOp>;
285 def shl : SDNode<"ISD::SHL" , SDTIntShiftOp>;
286 def rotl : SDNode<"ISD::ROTL" , SDTIntShiftOp>;
287 def rotr : SDNode<"ISD::ROTR" , SDTIntShiftOp>;
288 def and : SDNode<"ISD::AND" , SDTIntBinOp,
289 [SDNPCommutative, SDNPAssociative]>;
290 def or : SDNode<"ISD::OR" , SDTIntBinOp,
291 [SDNPCommutative, SDNPAssociative]>;
292 def xor : SDNode<"ISD::XOR" , SDTIntBinOp,
293 [SDNPCommutative, SDNPAssociative]>;
294 def addc : SDNode<"ISD::ADDC" , SDTIntBinOp,
295 [SDNPCommutative, SDNPOutFlag]>;
296 def adde : SDNode<"ISD::ADDE" , SDTIntBinOp,
297 [SDNPCommutative, SDNPOutFlag, SDNPInFlag]>;
298 def subc : SDNode<"ISD::SUBC" , SDTIntBinOp,
300 def sube : SDNode<"ISD::SUBE" , SDTIntBinOp,
301 [SDNPOutFlag, SDNPInFlag]>;
303 def sext_inreg : SDNode<"ISD::SIGN_EXTEND_INREG", SDTExtInreg>;
304 def bswap : SDNode<"ISD::BSWAP" , SDTIntUnaryOp>;
305 def ctlz : SDNode<"ISD::CTLZ" , SDTIntUnaryOp>;
306 def cttz : SDNode<"ISD::CTTZ" , SDTIntUnaryOp>;
307 def ctpop : SDNode<"ISD::CTPOP" , SDTIntUnaryOp>;
308 def sext : SDNode<"ISD::SIGN_EXTEND", SDTIntExtendOp>;
309 def zext : SDNode<"ISD::ZERO_EXTEND", SDTIntExtendOp>;
310 def anyext : SDNode<"ISD::ANY_EXTEND" , SDTIntExtendOp>;
311 def trunc : SDNode<"ISD::TRUNCATE" , SDTIntTruncOp>;
312 def bitconvert : SDNode<"ISD::BIT_CONVERT", SDTUnaryOp>;
313 def extractelt : SDNode<"ISD::EXTRACT_VECTOR_ELT", SDTVecExtract>;
314 def insertelt : SDNode<"ISD::INSERT_VECTOR_ELT", SDTVecInsert>;
317 def fadd : SDNode<"ISD::FADD" , SDTFPBinOp, [SDNPCommutative]>;
318 def fsub : SDNode<"ISD::FSUB" , SDTFPBinOp>;
319 def fmul : SDNode<"ISD::FMUL" , SDTFPBinOp, [SDNPCommutative]>;
320 def fdiv : SDNode<"ISD::FDIV" , SDTFPBinOp>;
321 def frem : SDNode<"ISD::FREM" , SDTFPBinOp>;
322 def fabs : SDNode<"ISD::FABS" , SDTFPUnaryOp>;
323 def fneg : SDNode<"ISD::FNEG" , SDTFPUnaryOp>;
324 def fsqrt : SDNode<"ISD::FSQRT" , SDTFPUnaryOp>;
325 def fsin : SDNode<"ISD::FSIN" , SDTFPUnaryOp>;
326 def fcos : SDNode<"ISD::FCOS" , SDTFPUnaryOp>;
328 def fround : SDNode<"ISD::FP_ROUND" , SDTFPRoundOp>;
329 def fextend : SDNode<"ISD::FP_EXTEND" , SDTFPExtendOp>;
330 def fcopysign : SDNode<"ISD::FCOPYSIGN" , SDTFPSignOp>;
332 def sint_to_fp : SDNode<"ISD::SINT_TO_FP" , SDTIntToFPOp>;
333 def uint_to_fp : SDNode<"ISD::UINT_TO_FP" , SDTIntToFPOp>;
334 def fp_to_sint : SDNode<"ISD::FP_TO_SINT" , SDTFPToIntOp>;
335 def fp_to_uint : SDNode<"ISD::FP_TO_UINT" , SDTFPToIntOp>;
337 def setcc : SDNode<"ISD::SETCC" , SDTSetCC>;
338 def select : SDNode<"ISD::SELECT" , SDTSelect>;
339 def selectcc : SDNode<"ISD::SELECT_CC" , SDTSelectCC>;
341 def brcond : SDNode<"ISD::BRCOND" , SDTBrcond, [SDNPHasChain]>;
342 def brind : SDNode<"ISD::BRIND" , SDTBrind, [SDNPHasChain]>;
343 def br : SDNode<"ISD::BR" , SDTBr, [SDNPHasChain]>;
344 def ret : SDNode<"ISD::RET" , SDTNone, [SDNPHasChain]>;
345 def trap : SDNode<"ISD::TRAP" , SDTNone,
346 [SDNPHasChain, SDNPSideEffect]>;
348 def prefetch : SDNode<"ISD::PREFETCH" , STDPrefetch,
349 [SDNPHasChain, SDNPMayLoad, SDNPMayStore]>;
351 def membarrier : SDNode<"ISD::MEMBARRIER" , STDMemBarrier,
352 [SDNPHasChain, SDNPSideEffect]>;
354 // Do not use atomic_* directly, use atomic_*_size (see below)
355 def atomic_lcs : SDNode<"ISD::ATOMIC_LCS" , STDAtomic3,
356 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
357 def atomic_las : SDNode<"ISD::ATOMIC_LAS" , STDAtomic2,
358 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
359 def atomic_swap : SDNode<"ISD::ATOMIC_SWAP", STDAtomic2,
360 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
361 def atomic_lss : SDNode<"ISD::ATOMIC_LSS" , STDAtomic2,
362 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
363 def atomic_load_and : SDNode<"ISD::ATOMIC_LOAD_AND" , STDAtomic2,
364 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
365 def atomic_load_or : SDNode<"ISD::ATOMIC_LOAD_OR" , STDAtomic2,
366 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
367 def atomic_load_xor : SDNode<"ISD::ATOMIC_LOAD_XOR" , STDAtomic2,
368 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
369 def atomic_load_min : SDNode<"ISD::ATOMIC_LOAD_MIN", STDAtomic2,
370 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
371 def atomic_load_max : SDNode<"ISD::ATOMIC_LOAD_MAX", STDAtomic2,
372 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
373 def atomic_load_umin : SDNode<"ISD::ATOMIC_LOAD_UMIN", STDAtomic2,
374 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
375 def atomic_load_umax : SDNode<"ISD::ATOMIC_LOAD_UMAX", STDAtomic2,
376 [SDNPHasChain, SDNPMayStore, SDNPMayLoad]>;
378 // Do not use ld, st directly. Use load, extload, sextload, zextload, store,
379 // and truncst (see below).
380 def ld : SDNode<"ISD::LOAD" , SDTLoad,
381 [SDNPHasChain, SDNPMayLoad]>;
382 def st : SDNode<"ISD::STORE" , SDTStore,
383 [SDNPHasChain, SDNPMayStore]>;
384 def ist : SDNode<"ISD::STORE" , SDTIStore,
385 [SDNPHasChain, SDNPMayStore]>;
387 def vector_shuffle : SDNode<"ISD::VECTOR_SHUFFLE", SDTVecShuffle, []>;
388 def build_vector : SDNode<"ISD::BUILD_VECTOR", SDTypeProfile<1, 0, []>, []>;
389 def scalar_to_vector : SDNode<"ISD::SCALAR_TO_VECTOR", SDTypeProfile<1, 1, []>,
391 def vector_extract : SDNode<"ISD::EXTRACT_VECTOR_ELT",
392 SDTypeProfile<1, 2, [SDTCisPtrTy<2>]>, []>;
393 def vector_insert : SDNode<"ISD::INSERT_VECTOR_ELT",
394 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisPtrTy<3>]>, []>;
396 def extract_subreg : SDNode<"ISD::EXTRACT_SUBREG",
397 SDTypeProfile<1, 2, []>>;
398 def insert_subreg : SDNode<"ISD::INSERT_SUBREG",
399 SDTypeProfile<1, 3, []>>;
401 // Nodes for intrinsics, you should use the intrinsic itself and let tblgen use
402 // these internally. Don't reference these directly.
403 def intrinsic_void : SDNode<"ISD::INTRINSIC_VOID",
404 SDTypeProfile<0, -1, [SDTCisPtrTy<0>]>,
406 def intrinsic_w_chain : SDNode<"ISD::INTRINSIC_W_CHAIN",
407 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>,
409 def intrinsic_wo_chain : SDNode<"ISD::INTRINSIC_WO_CHAIN",
410 SDTypeProfile<1, -1, [SDTCisPtrTy<1>]>, []>;
413 //===----------------------------------------------------------------------===//
414 // Selection DAG Condition Codes
416 class CondCode; // ISD::CondCode enums
417 def SETOEQ : CondCode; def SETOGT : CondCode;
418 def SETOGE : CondCode; def SETOLT : CondCode; def SETOLE : CondCode;
419 def SETONE : CondCode; def SETO : CondCode; def SETUO : CondCode;
420 def SETUEQ : CondCode; def SETUGT : CondCode; def SETUGE : CondCode;
421 def SETULT : CondCode; def SETULE : CondCode; def SETUNE : CondCode;
423 def SETEQ : CondCode; def SETGT : CondCode; def SETGE : CondCode;
424 def SETLT : CondCode; def SETLE : CondCode; def SETNE : CondCode;
427 //===----------------------------------------------------------------------===//
428 // Selection DAG Node Transformation Functions.
430 // This mechanism allows targets to manipulate nodes in the output DAG once a
431 // match has been formed. This is typically used to manipulate immediate
434 class SDNodeXForm<SDNode opc, code xformFunction> {
436 code XFormFunction = xformFunction;
439 def NOOP_SDNodeXForm : SDNodeXForm<imm, [{}]>;
442 //===----------------------------------------------------------------------===//
443 // Selection DAG Pattern Fragments.
445 // Pattern fragments are reusable chunks of dags that match specific things.
446 // They can take arguments and have C++ predicates that control whether they
447 // match. They are intended to make the patterns for common instructions more
448 // compact and readable.
451 /// PatFrag - Represents a pattern fragment. This can match something on the
452 /// DAG, frame a single node to multiply nested other fragments.
454 class PatFrag<dag ops, dag frag, code pred = [{}],
455 SDNodeXForm xform = NOOP_SDNodeXForm> {
458 code Predicate = pred;
459 SDNodeXForm OperandTransform = xform;
462 // PatLeaf's are pattern fragments that have no operands. This is just a helper
463 // to define immediates and other common things concisely.
464 class PatLeaf<dag frag, code pred = [{}], SDNodeXForm xform = NOOP_SDNodeXForm>
465 : PatFrag<(ops), frag, pred, xform>;
469 def vtInt : PatLeaf<(vt), [{ return MVT::isInteger(N->getVT()); }]>;
470 def vtFP : PatLeaf<(vt), [{ return MVT::isFloatingPoint(N->getVT()); }]>;
472 def immAllOnes : PatLeaf<(imm), [{ return N->isAllOnesValue(); }]>;
473 def immAllOnesV: PatLeaf<(build_vector), [{
474 return ISD::isBuildVectorAllOnes(N);
476 def immAllOnesV_bc: PatLeaf<(bitconvert), [{
477 return ISD::isBuildVectorAllOnes(N);
479 def immAllZerosV: PatLeaf<(build_vector), [{
480 return ISD::isBuildVectorAllZeros(N);
482 def immAllZerosV_bc: PatLeaf<(bitconvert), [{
483 return ISD::isBuildVectorAllZeros(N);
488 // Other helper fragments.
489 def not : PatFrag<(ops node:$in), (xor node:$in, immAllOnes)>;
490 def vnot : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV)>;
491 def vnot_conv : PatFrag<(ops node:$in), (xor node:$in, immAllOnesV_bc)>;
492 def ineg : PatFrag<(ops node:$in), (sub 0, node:$in)>;
495 def load : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
496 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
497 return LD->getExtensionType() == ISD::NON_EXTLOAD &&
498 LD->getAddressingMode() == ISD::UNINDEXED;
502 // extending load fragments.
503 def extloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
504 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
505 return LD->getExtensionType() == ISD::EXTLOAD &&
506 LD->getAddressingMode() == ISD::UNINDEXED &&
507 LD->getMemoryVT() == MVT::i1;
510 def extloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
511 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
512 return LD->getExtensionType() == ISD::EXTLOAD &&
513 LD->getAddressingMode() == ISD::UNINDEXED &&
514 LD->getMemoryVT() == MVT::i8;
517 def extloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
518 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
519 return LD->getExtensionType() == ISD::EXTLOAD &&
520 LD->getAddressingMode() == ISD::UNINDEXED &&
521 LD->getMemoryVT() == MVT::i16;
524 def extloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
525 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
526 return LD->getExtensionType() == ISD::EXTLOAD &&
527 LD->getAddressingMode() == ISD::UNINDEXED &&
528 LD->getMemoryVT() == MVT::i32;
531 def extloadf32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
532 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
533 return LD->getExtensionType() == ISD::EXTLOAD &&
534 LD->getAddressingMode() == ISD::UNINDEXED &&
535 LD->getMemoryVT() == MVT::f32;
538 def extloadf64 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
539 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
540 return LD->getExtensionType() == ISD::EXTLOAD &&
541 LD->getAddressingMode() == ISD::UNINDEXED &&
542 LD->getMemoryVT() == MVT::f64;
546 def sextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
547 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
548 return LD->getExtensionType() == ISD::SEXTLOAD &&
549 LD->getAddressingMode() == ISD::UNINDEXED &&
550 LD->getMemoryVT() == MVT::i1;
553 def sextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
554 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
555 return LD->getExtensionType() == ISD::SEXTLOAD &&
556 LD->getAddressingMode() == ISD::UNINDEXED &&
557 LD->getMemoryVT() == MVT::i8;
560 def sextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
561 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
562 return LD->getExtensionType() == ISD::SEXTLOAD &&
563 LD->getAddressingMode() == ISD::UNINDEXED &&
564 LD->getMemoryVT() == MVT::i16;
567 def sextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
568 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
569 return LD->getExtensionType() == ISD::SEXTLOAD &&
570 LD->getAddressingMode() == ISD::UNINDEXED &&
571 LD->getMemoryVT() == MVT::i32;
575 def zextloadi1 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
576 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
577 return LD->getExtensionType() == ISD::ZEXTLOAD &&
578 LD->getAddressingMode() == ISD::UNINDEXED &&
579 LD->getMemoryVT() == MVT::i1;
582 def zextloadi8 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
583 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
584 return LD->getExtensionType() == ISD::ZEXTLOAD &&
585 LD->getAddressingMode() == ISD::UNINDEXED &&
586 LD->getMemoryVT() == MVT::i8;
589 def zextloadi16 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
590 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
591 return LD->getExtensionType() == ISD::ZEXTLOAD &&
592 LD->getAddressingMode() == ISD::UNINDEXED &&
593 LD->getMemoryVT() == MVT::i16;
596 def zextloadi32 : PatFrag<(ops node:$ptr), (ld node:$ptr), [{
597 if (LoadSDNode *LD = dyn_cast<LoadSDNode>(N))
598 return LD->getExtensionType() == ISD::ZEXTLOAD &&
599 LD->getAddressingMode() == ISD::UNINDEXED &&
600 LD->getMemoryVT() == MVT::i32;
605 def store : PatFrag<(ops node:$val, node:$ptr),
606 (st node:$val, node:$ptr), [{
607 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
608 return !ST->isTruncatingStore() &&
609 ST->getAddressingMode() == ISD::UNINDEXED;
613 // truncstore fragments.
614 def truncstorei8 : PatFrag<(ops node:$val, node:$ptr),
615 (st node:$val, node:$ptr), [{
616 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
617 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8 &&
618 ST->getAddressingMode() == ISD::UNINDEXED;
621 def truncstorei16 : PatFrag<(ops node:$val, node:$ptr),
622 (st node:$val, node:$ptr), [{
623 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
624 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16 &&
625 ST->getAddressingMode() == ISD::UNINDEXED;
628 def truncstorei32 : PatFrag<(ops node:$val, node:$ptr),
629 (st node:$val, node:$ptr), [{
630 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
631 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32 &&
632 ST->getAddressingMode() == ISD::UNINDEXED;
635 def truncstoref32 : PatFrag<(ops node:$val, node:$ptr),
636 (st node:$val, node:$ptr), [{
637 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
638 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32 &&
639 ST->getAddressingMode() == ISD::UNINDEXED;
642 def truncstoref64 : PatFrag<(ops node:$val, node:$ptr),
643 (st node:$val, node:$ptr), [{
644 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N))
645 return ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f64 &&
646 ST->getAddressingMode() == ISD::UNINDEXED;
650 // indexed store fragments.
651 def pre_store : PatFrag<(ops node:$val, node:$base, node:$offset),
652 (ist node:$val, node:$base, node:$offset), [{
653 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
654 ISD::MemIndexedMode AM = ST->getAddressingMode();
655 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
656 !ST->isTruncatingStore();
661 def pre_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
662 (ist node:$val, node:$base, node:$offset), [{
663 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
664 ISD::MemIndexedMode AM = ST->getAddressingMode();
665 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
666 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
670 def pre_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
671 (ist node:$val, node:$base, node:$offset), [{
672 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
673 ISD::MemIndexedMode AM = ST->getAddressingMode();
674 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
675 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8;
679 def pre_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
680 (ist node:$val, node:$base, node:$offset), [{
681 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
682 ISD::MemIndexedMode AM = ST->getAddressingMode();
683 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
684 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16;
688 def pre_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
689 (ist node:$val, node:$base, node:$offset), [{
690 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
691 ISD::MemIndexedMode AM = ST->getAddressingMode();
692 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
693 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32;
697 def pre_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
698 (ist node:$val, node:$base, node:$offset), [{
699 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
700 ISD::MemIndexedMode AM = ST->getAddressingMode();
701 return (AM == ISD::PRE_INC || AM == ISD::PRE_DEC) &&
702 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32;
707 def post_store : PatFrag<(ops node:$val, node:$ptr, node:$offset),
708 (ist node:$val, node:$ptr, node:$offset), [{
709 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
710 ISD::MemIndexedMode AM = ST->getAddressingMode();
711 return !ST->isTruncatingStore() &&
712 (AM == ISD::POST_INC || AM == ISD::POST_DEC);
717 def post_truncsti1 : PatFrag<(ops node:$val, node:$base, node:$offset),
718 (ist node:$val, node:$base, node:$offset), [{
719 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
720 ISD::MemIndexedMode AM = ST->getAddressingMode();
721 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
722 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i1;
726 def post_truncsti8 : PatFrag<(ops node:$val, node:$base, node:$offset),
727 (ist node:$val, node:$base, node:$offset), [{
728 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
729 ISD::MemIndexedMode AM = ST->getAddressingMode();
730 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
731 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i8;
735 def post_truncsti16 : PatFrag<(ops node:$val, node:$base, node:$offset),
736 (ist node:$val, node:$base, node:$offset), [{
737 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
738 ISD::MemIndexedMode AM = ST->getAddressingMode();
739 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
740 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i16;
744 def post_truncsti32 : PatFrag<(ops node:$val, node:$base, node:$offset),
745 (ist node:$val, node:$base, node:$offset), [{
746 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
747 ISD::MemIndexedMode AM = ST->getAddressingMode();
748 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
749 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::i32;
753 def post_truncstf32 : PatFrag<(ops node:$val, node:$base, node:$offset),
754 (ist node:$val, node:$base, node:$offset), [{
755 if (StoreSDNode *ST = dyn_cast<StoreSDNode>(N)) {
756 ISD::MemIndexedMode AM = ST->getAddressingMode();
757 return (AM == ISD::POST_INC || AM == ISD::POST_DEC) &&
758 ST->isTruncatingStore() && ST->getMemoryVT() == MVT::f32;
764 def atomic_lcs_8 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
765 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
766 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
767 return V->getVT() == MVT::i8;
770 def atomic_lcs_16 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
771 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
772 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
773 return V->getVT() == MVT::i16;
776 def atomic_lcs_32 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
777 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
778 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
779 return V->getVT() == MVT::i32;
782 def atomic_lcs_64 : PatFrag<(ops node:$ptr, node:$cmp, node:$swp),
783 (atomic_lcs node:$ptr, node:$cmp, node:$swp), [{
784 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
785 return V->getVT() == MVT::i64;
789 def atomic_las_8 : PatFrag<(ops node:$ptr, node:$inc),
790 (atomic_las node:$ptr, node:$inc), [{
791 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
792 return V->getVT() == MVT::i8;
795 def atomic_las_16 : PatFrag<(ops node:$ptr, node:$inc),
796 (atomic_las node:$ptr, node:$inc), [{
797 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
798 return V->getVT() == MVT::i16;
801 def atomic_las_32 : PatFrag<(ops node:$ptr, node:$inc),
802 (atomic_las node:$ptr, node:$inc), [{
803 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
804 return V->getVT() == MVT::i32;
807 def atomic_las_64 : PatFrag<(ops node:$ptr, node:$inc),
808 (atomic_las node:$ptr, node:$inc), [{
809 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
810 return V->getVT() == MVT::i64;
814 def atomic_swap_8 : PatFrag<(ops node:$ptr, node:$inc),
815 (atomic_swap node:$ptr, node:$inc), [{
816 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
817 return V->getVT() == MVT::i8;
820 def atomic_swap_16 : PatFrag<(ops node:$ptr, node:$inc),
821 (atomic_swap node:$ptr, node:$inc), [{
822 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
823 return V->getVT() == MVT::i16;
826 def atomic_swap_32 : PatFrag<(ops node:$ptr, node:$inc),
827 (atomic_swap node:$ptr, node:$inc), [{
828 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
829 return V->getVT() == MVT::i32;
832 def atomic_swap_64 : PatFrag<(ops node:$ptr, node:$inc),
833 (atomic_swap node:$ptr, node:$inc), [{
834 if (AtomicSDNode* V = dyn_cast<AtomicSDNode>(N))
835 return V->getVT() == MVT::i64;
841 // setcc convenience fragments.
842 def setoeq : PatFrag<(ops node:$lhs, node:$rhs),
843 (setcc node:$lhs, node:$rhs, SETOEQ)>;
844 def setogt : PatFrag<(ops node:$lhs, node:$rhs),
845 (setcc node:$lhs, node:$rhs, SETOGT)>;
846 def setoge : PatFrag<(ops node:$lhs, node:$rhs),
847 (setcc node:$lhs, node:$rhs, SETOGE)>;
848 def setolt : PatFrag<(ops node:$lhs, node:$rhs),
849 (setcc node:$lhs, node:$rhs, SETOLT)>;
850 def setole : PatFrag<(ops node:$lhs, node:$rhs),
851 (setcc node:$lhs, node:$rhs, SETOLE)>;
852 def setone : PatFrag<(ops node:$lhs, node:$rhs),
853 (setcc node:$lhs, node:$rhs, SETONE)>;
854 def seto : PatFrag<(ops node:$lhs, node:$rhs),
855 (setcc node:$lhs, node:$rhs, SETO)>;
856 def setuo : PatFrag<(ops node:$lhs, node:$rhs),
857 (setcc node:$lhs, node:$rhs, SETUO)>;
858 def setueq : PatFrag<(ops node:$lhs, node:$rhs),
859 (setcc node:$lhs, node:$rhs, SETUEQ)>;
860 def setugt : PatFrag<(ops node:$lhs, node:$rhs),
861 (setcc node:$lhs, node:$rhs, SETUGT)>;
862 def setuge : PatFrag<(ops node:$lhs, node:$rhs),
863 (setcc node:$lhs, node:$rhs, SETUGE)>;
864 def setult : PatFrag<(ops node:$lhs, node:$rhs),
865 (setcc node:$lhs, node:$rhs, SETULT)>;
866 def setule : PatFrag<(ops node:$lhs, node:$rhs),
867 (setcc node:$lhs, node:$rhs, SETULE)>;
868 def setune : PatFrag<(ops node:$lhs, node:$rhs),
869 (setcc node:$lhs, node:$rhs, SETUNE)>;
870 def seteq : PatFrag<(ops node:$lhs, node:$rhs),
871 (setcc node:$lhs, node:$rhs, SETEQ)>;
872 def setgt : PatFrag<(ops node:$lhs, node:$rhs),
873 (setcc node:$lhs, node:$rhs, SETGT)>;
874 def setge : PatFrag<(ops node:$lhs, node:$rhs),
875 (setcc node:$lhs, node:$rhs, SETGE)>;
876 def setlt : PatFrag<(ops node:$lhs, node:$rhs),
877 (setcc node:$lhs, node:$rhs, SETLT)>;
878 def setle : PatFrag<(ops node:$lhs, node:$rhs),
879 (setcc node:$lhs, node:$rhs, SETLE)>;
880 def setne : PatFrag<(ops node:$lhs, node:$rhs),
881 (setcc node:$lhs, node:$rhs, SETNE)>;
883 //===----------------------------------------------------------------------===//
884 // Selection DAG Pattern Support.
886 // Patterns are what are actually matched against the target-flavored
887 // instruction selection DAG. Instructions defined by the target implicitly
888 // define patterns in most cases, but patterns can also be explicitly added when
889 // an operation is defined by a sequence of instructions (e.g. loading a large
890 // immediate value on RISC targets that do not support immediates as large as
894 class Pattern<dag patternToMatch, list<dag> resultInstrs> {
895 dag PatternToMatch = patternToMatch;
896 list<dag> ResultInstrs = resultInstrs;
897 list<Predicate> Predicates = []; // See class Instruction in Target.td.
898 int AddedComplexity = 0; // See class Instruction in Target.td.
901 // Pat - A simple (but common) form of a pattern, which produces a simple result
902 // not needing a full list.
903 class Pat<dag pattern, dag result> : Pattern<pattern, [result]>;
905 //===----------------------------------------------------------------------===//
906 // Complex pattern definitions.
910 // Pass the parent Operand as root to CP function rather
911 // than the root of the sub-DAG
912 def CPAttrParentAsRoot : CPAttribute;
914 // Complex patterns, e.g. X86 addressing mode, requires pattern matching code
915 // in C++. NumOperands is the number of operands returned by the select function;
916 // SelectFunc is the name of the function used to pattern match the max. pattern;
917 // RootNodes are the list of possible root nodes of the sub-dags to match.
918 // e.g. X86 addressing mode - def addr : ComplexPattern<4, "SelectAddr", [add]>;
920 class ComplexPattern<ValueType ty, int numops, string fn,
921 list<SDNode> roots = [], list<SDNodeProperty> props = [],
922 list<CPAttribute> attrs = []> {
924 int NumOperands = numops;
925 string SelectFunc = fn;
926 list<SDNode> RootNodes = roots;
927 list<SDNodeProperty> Properties = props;
928 list<CPAttribute> Attributes = attrs;
931 //===----------------------------------------------------------------------===//
934 def SDT_dwarf_loc : SDTypeProfile<0, 3,
935 [SDTCisInt<0>, SDTCisInt<1>, SDTCisInt<2>]>;
936 def dwarf_loc : SDNode<"ISD::DEBUG_LOC", SDT_dwarf_loc,[SDNPHasChain]>;