1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG. These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
22 #include "llvm/Value.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator"
26 #include "llvm/CodeGen/ValueTypes.h"
27 #include "llvm/Support/DataTypes.h"
34 class MachineBasicBlock;
35 class MachineConstantPoolValue;
37 template <typename T> struct simplify_type;
38 template <typename T> struct ilist_traits;
39 template<typename NodeTy, typename Traits> class iplist;
40 template<typename NodeTy> class ilist_iterator;
42 /// SDVTList - This represents a list of ValueType's that has been intern'd by
43 /// a SelectionDAG. Instances of this simple value class are returned by
44 /// SelectionDAG::getVTList(...).
47 const MVT::ValueType *VTs;
48 unsigned short NumVTs;
51 /// ISD namespace - This namespace contains an enum which represents all of the
52 /// SelectionDAG node types and value types.
55 namespace ParamFlags {
58 ZExt = 1<<0, ///< Parameter should be zero extended
60 SExt = 1<<1, ///< Parameter should be sign extended
62 InReg = 1<<2, ///< Parameter should be passed in register
64 StructReturn = 1<<3, ///< Hidden struct-return pointer
66 OrigAlignment = 0x1F<<27,
67 OrigAlignmentOffs = 27
71 //===--------------------------------------------------------------------===//
72 /// ISD::NodeType enum - This enum defines all of the operators valid in a
76 // DELETED_NODE - This is an illegal flag value that is used to catch
77 // errors. This opcode is not a legal opcode for any node.
80 // EntryToken - This is the marker used to indicate the start of the region.
83 // Token factor - This node takes multiple tokens as input and produces a
84 // single token result. This is used to represent the fact that the operand
85 // operators are independent of each other.
88 // AssertSext, AssertZext - These nodes record if a register contains a
89 // value that has already been zero or sign extended from a narrower type.
90 // These nodes take two operands. The first is the node that has already
91 // been extended, and the second is a value type node indicating the width
93 AssertSext, AssertZext,
95 // Various leaf nodes.
96 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
98 GlobalAddress, GlobalTLSAddress, FrameIndex,
99 JumpTable, ConstantPool, ExternalSymbol,
101 // The address of the GOT
104 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
105 // llvm.returnaddress on the DAG. These nodes take one operand, the index
106 // of the frame or return address to return. An index of zero corresponds
107 // to the current function's frame or return address, an index of one to the
108 // parent's frame or return address, and so on.
109 FRAMEADDR, RETURNADDR,
111 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
112 // address of the exception block on entry to an landing pad block.
115 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
116 // the selection index of the exception thrown.
119 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
120 // simplification of the constant.
124 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
125 // anything else with this node, and this is valid in the target-specific
126 // dag, turning into a GlobalAddress operand.
128 TargetGlobalTLSAddress,
132 TargetExternalSymbol,
134 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
135 /// This node represents a target intrinsic function with no side effects.
136 /// The first operand is the ID number of the intrinsic from the
137 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
138 /// node has returns the result of the intrinsic.
141 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
142 /// This node represents a target intrinsic function with side effects that
143 /// returns a result. The first operand is a chain pointer. The second is
144 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
145 /// operands to the intrinsic follow. The node has two results, the result
146 /// of the intrinsic and an output chain.
149 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
150 /// This node represents a target intrinsic function with side effects that
151 /// does not return a result. The first operand is a chain pointer. The
152 /// second is the ID number of the intrinsic from the llvm::Intrinsic
153 /// namespace. The operands to the intrinsic follow.
156 // CopyToReg - This node has three operands: a chain, a register number to
157 // set to this value, and a value.
160 // CopyFromReg - This node indicates that the input value is a virtual or
161 // physical register that is defined outside of the scope of this
162 // SelectionDAG. The register is available from the RegSDNode object.
165 // UNDEF - An undefined node
168 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
169 /// represents the formal arguments for a function. CC# is a Constant value
170 /// indicating the calling convention of the function, and ISVARARG is a
171 /// flag that indicates whether the function is varargs or not. This node
172 /// has one result value for each incoming argument, plus one for the output
173 /// chain. It must be custom legalized. See description of CALL node for
174 /// FLAG argument contents explanation.
178 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
179 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
180 /// This node represents a fully general function call, before the legalizer
181 /// runs. This has one result value for each argument / flag pair, plus
182 /// a chain result. It must be custom legalized. Flag argument indicates
183 /// misc. argument attributes. Currently:
185 /// Bit 1 - 'inreg' attribute
186 /// Bit 2 - 'sret' attribute
187 /// Bits 31:27 - argument ABI alignment in the first argument piece and
188 /// alignment '1' in other argument pieces.
191 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
192 // a Constant, which is required to be operand #1), element of the aggregate
193 // value specified as operand #0. This is only for use before legalization,
194 // for values that will be broken into multiple registers.
197 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
198 // two values of the same integer value type, this produces a value twice as
199 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
202 // MERGE_VALUES - This node takes multiple discrete operands and returns
203 // them all as its individual results. This nodes has exactly the same
204 // number of inputs and outputs, and is only valid before legalization.
205 // This node is useful for some pieces of the code generator that want to
206 // think about a single node with multiple results, not multiple nodes.
209 // Simple integer binary arithmetic operators.
210 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
212 // CARRY_FALSE - This node is used when folding other nodes,
213 // like ADDC/SUBC, which indicate the carry result is always false.
216 // Carry-setting nodes for multiple precision addition and subtraction.
217 // These nodes take two operands of the same value type, and produce two
218 // results. The first result is the normal add or sub result, the second
219 // result is the carry flag result.
222 // Carry-using nodes for multiple precision addition and subtraction. These
223 // nodes take three operands: The first two are the normal lhs and rhs to
224 // the add or sub, and the third is the input carry flag. These nodes
225 // produce two results; the normal result of the add or sub, and the output
226 // carry flag. These nodes both read and write a carry flag to allow them
227 // to them to be chained together for add and sub of arbitrarily large
231 // Simple binary floating point operators.
232 FADD, FSUB, FMUL, FDIV, FREM,
234 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
235 // DAG node does not require that X and Y have the same type, just that they
236 // are both floating point. X and the result must have the same type.
237 // FCOPYSIGN(f32, f64) is allowed.
240 /// VBUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,..., COUNT,TYPE) - Return a vector
241 /// with the specified, possibly variable, elements. The number of elements
242 /// is required to be a power of two.
245 /// BUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,...) - Return a vector
246 /// with the specified, possibly variable, elements. The number of elements
247 /// is required to be a power of two.
250 /// VINSERT_VECTOR_ELT(VECTOR, VAL, IDX, COUNT,TYPE) - Given a vector
251 /// VECTOR, an element ELEMENT, and a (potentially variable) index IDX,
252 /// return a vector with the specified element of VECTOR replaced with VAL.
253 /// COUNT and TYPE specify the type of vector, as is standard for V* nodes.
256 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR (a legal packed
257 /// type) with the element at IDX replaced with VAL.
260 /// VEXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
261 /// (an MVT::Vector value) identified by the (potentially variable) element
265 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
266 /// (a legal vector type vector) identified by the (potentially variable)
267 /// element number IDX.
270 /// VCONCAT_VECTORS(VECTOR0, VECTOR1, ..., COUNT,TYPE) - Given a number of
271 /// values of MVT::Vector type with the same length and element type, this
272 /// produces a concatenated MVT::Vector result value, with length equal to
273 /// the sum of the input vectors. This can only be used before
277 /// VEXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
278 /// MVT::Vector value) starting with the (potentially variable)
279 /// element number IDX, which must be a multiple of the result vector
280 /// length. This can only be used before legalization.
283 /// VVECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC, COUNT,TYPE) - Returns a vector,
284 /// of the same type as VEC1/VEC2. SHUFFLEVEC is a VBUILD_VECTOR of
285 /// constant int values that indicate which value each result element will
286 /// get. The elements of VEC1/VEC2 are enumerated in order. This is quite
287 /// similar to the Altivec 'vperm' instruction, except that the indices must
288 /// be constants and are in terms of the element size of VEC1/VEC2, not in
292 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
293 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
294 /// (regardless of whether its datatype is legal or not) that indicate
295 /// which value each result element will get. The elements of VEC1/VEC2 are
296 /// enumerated in order. This is quite similar to the Altivec 'vperm'
297 /// instruction, except that the indices must be constants and are in terms
298 /// of the element size of VEC1/VEC2, not in terms of bytes.
301 /// X = VBIT_CONVERT(Y) and X = VBIT_CONVERT(Y, COUNT,TYPE) - This node
302 /// represents a conversion from or to an ISD::Vector type.
304 /// This is lowered to a BIT_CONVERT of the appropriate input/output types.
305 /// The input and output are required to have the same size and at least one
306 /// is required to be a vector (if neither is a vector, just use
309 /// If the result is a vector, this takes three operands (like any other
310 /// vector producer) which indicate the size and type of the vector result.
311 /// Otherwise it takes one input.
314 /// BINOP(LHS, RHS, COUNT,TYPE)
315 /// Simple abstract vector operators. Unlike the integer and floating point
316 /// binary operators, these nodes also take two additional operands:
317 /// a constant element count, and a value type node indicating the type of
318 /// the elements. The order is op0, op1, count, type. All vector opcodes,
319 /// including VLOAD and VConstant must currently have count and type as
320 /// their last two operands.
321 VADD, VSUB, VMUL, VSDIV, VUDIV,
324 /// VSELECT(COND,LHS,RHS, COUNT,TYPE) - Select for MVT::Vector values.
325 /// COND is a boolean value. This node return LHS if COND is true, RHS if
329 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
330 /// scalar value into the low element of the resultant vector type. The top
331 /// elements of the vector are undefined.
334 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
335 // an unsigned/signed value of type i[2*n], then return the top part.
338 // Bitwise operators - logical and, logical or, logical xor, shift left,
339 // shift right algebraic (shift in sign bits), shift right logical (shift in
340 // zeroes), rotate left, rotate right, and byteswap.
341 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
343 // Counting operators
346 // Select(COND, TRUEVAL, FALSEVAL)
349 // Select with condition operator - This selects between a true value and
350 // a false value (ops #2 and #3) based on the boolean result of comparing
351 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
352 // condition code in op #4, a CondCodeSDNode.
355 // SetCC operator - This evaluates to a boolean (i1) true value if the
356 // condition is true. The operands to this are the left and right operands
357 // to compare (ops #0, and #1) and the condition code to compare them with
358 // (op #2) as a CondCodeSDNode.
361 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
362 // integer shift operations, just like ADD/SUB_PARTS. The operation
364 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
365 SHL_PARTS, SRA_PARTS, SRL_PARTS,
367 // Conversion operators. These are all single input single output
368 // operations. For all of these, the result type must be strictly
369 // wider or narrower (depending on the operation) than the source
372 // SIGN_EXTEND - Used for integer types, replicating the sign bit
376 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
379 // ANY_EXTEND - Used for integer types. The high bits are undefined.
382 // TRUNCATE - Completely drop the high bits.
385 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
386 // depends on the first letter) to floating point.
390 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
391 // sign extend a small value in a large integer register (e.g. sign
392 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
393 // with the 7th bit). The size of the smaller type is indicated by the 1th
394 // operand, a ValueType node.
397 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
402 // FP_ROUND - Perform a rounding operation from the current
403 // precision down to the specified precision (currently always 64->32).
406 // FP_ROUND_INREG - This operator takes a floating point register, and
407 // rounds it to a floating point value. It then promotes it and returns it
408 // in a register of the same size. This operation effectively just discards
409 // excess precision. The type to round down to is specified by the 1th
410 // operation, a VTSDNode (currently always 64->32->64).
413 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
416 // BIT_CONVERT - Theis operator converts between integer and FP values, as
417 // if one was stored to memory as integer and the other was loaded from the
418 // same address (or equivalently for vector format conversions, etc). The
419 // source and result are required to have the same bit size (e.g.
420 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
421 // conversions, but that is a noop, deleted by getNode().
424 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI - Perform unary floating point
425 // negation, absolute value, square root, sine and cosine, and powi
427 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI,
429 // LOAD and STORE have token chains as their first operand, then the same
430 // operands as an LLVM load/store instruction, then an offset node that
431 // is added / subtracted from the base pointer to form the address (for
432 // indexed memory ops).
435 // Abstract vector version of LOAD. VLOAD has a constant element count as
436 // the first operand, followed by a value type node indicating the type of
437 // the elements, a token chain, a pointer operand, and a SRCVALUE node.
440 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
441 // value and stores it to memory in one operation. This can be used for
442 // either integer or floating point operands. The first four operands of
443 // this are the same as a standard store. The fifth is the ValueType to
444 // store it as (which will be smaller than the source value).
447 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
448 // to a specified boundary. This node always has two return values: a new
449 // stack pointer value and a chain. The first operand is the token chain,
450 // the second is the number of bytes to allocate, and the third is the
451 // alignment boundary. The size is guaranteed to be a multiple of the stack
452 // alignment, and the alignment is guaranteed to be bigger than the stack
453 // alignment (if required) or 0 to get standard stack alignment.
456 // Control flow instructions. These all have token chains.
458 // BR - Unconditional branch. The first operand is the chain
459 // operand, the second is the MBB to branch to.
462 // BRIND - Indirect branch. The first operand is the chain, the second
463 // is the value to branch to, which must be of the same type as the target's
467 // BR_JT - Jumptable branch. The first operand is the chain, the second
468 // is the jumptable index, the last one is the jumptable entry index.
471 // BRCOND - Conditional branch. The first operand is the chain,
472 // the second is the condition, the third is the block to branch
473 // to if the condition is true.
476 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
477 // that the condition is represented as condition code, and two nodes to
478 // compare, rather than as a combined SetCC node. The operands in order are
479 // chain, cc, lhs, rhs, block to branch to if condition is true.
482 // RET - Return from function. The first operand is the chain,
483 // and any subsequent operands are pairs of return value and return value
484 // signness for the function. This operation can have variable number of
488 // INLINEASM - Represents an inline asm block. This node always has two
489 // return values: a chain and a flag result. The inputs are as follows:
490 // Operand #0 : Input chain.
491 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
492 // Operand #2n+2: A RegisterNode.
493 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
494 // Operand #last: Optional, an incoming flag.
497 // LABEL - Represents a label in mid basic block used to track
498 // locations needed for debug and exception handling tables. This node
500 // Operand #0 : input chain.
501 // Operand #1 : module unique number use to identify the label.
504 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
505 // value, the same type as the pointer type for the system, and an output
509 // STACKRESTORE has two operands, an input chain and a pointer to restore to
510 // it returns an output chain.
513 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
514 // correspond to the operands of the LLVM intrinsic functions. The only
515 // result is a token chain. The alignment argument is guaranteed to be a
521 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
522 // a call sequence, and carry arbitrary information that target might want
523 // to know. The first operand is a chain, the rest are specified by the
524 // target and not touched by the DAG optimizers.
525 CALLSEQ_START, // Beginning of a call sequence
526 CALLSEQ_END, // End of a call sequence
528 // VAARG - VAARG has three operands: an input chain, a pointer, and a
529 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
532 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
533 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
537 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
538 // pointer, and a SRCVALUE.
541 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
542 // locations with their value. This allows one use alias analysis
543 // information in the backend.
546 // PCMARKER - This corresponds to the pcmarker intrinsic.
549 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
550 // The only operand is a chain and a value and a chain are produced. The
551 // value is the contents of the architecture specific cycle counter like
552 // register (or other high accuracy low latency clock source)
555 // HANDLENODE node - Used as a handle for various purposes.
558 // LOCATION - This node is used to represent a source location for debug
559 // info. It takes token chain as input, then a line number, then a column
560 // number, then a filename, then a working dir. It produces a token chain
564 // DEBUG_LOC - This node is used to represent source line information
565 // embedded in the code. It takes a token chain as input, then a line
566 // number, then a column then a file id (provided by MachineModuleInfo.) It
567 // produces a token chain as output.
570 // BUILTIN_OP_END - This must be the last enum value in this list.
576 /// isBuildVectorAllOnes - Return true if the specified node is a
577 /// BUILD_VECTOR where all of the elements are ~0 or undef.
578 bool isBuildVectorAllOnes(const SDNode *N);
580 /// isBuildVectorAllZeros - Return true if the specified node is a
581 /// BUILD_VECTOR where all of the elements are 0 or undef.
582 bool isBuildVectorAllZeros(const SDNode *N);
584 //===--------------------------------------------------------------------===//
585 /// MemIndexedMode enum - This enum defines the load / store indexed
586 /// addressing modes.
588 /// UNINDEXED "Normal" load / store. The effective address is already
589 /// computed and is available in the base pointer. The offset
590 /// operand is always undefined. In addition to producing a
591 /// chain, an unindexed load produces one value (result of the
592 /// load); an unindexed store does not produces a value.
594 /// PRE_INC Similar to the unindexed mode where the effective address is
595 /// PRE_DEC the value of the base pointer add / subtract the offset.
596 /// It considers the computation as being folded into the load /
597 /// store operation (i.e. the load / store does the address
598 /// computation as well as performing the memory transaction).
599 /// The base operand is always undefined. In addition to
600 /// producing a chain, pre-indexed load produces two values
601 /// (result of the load and the result of the address
602 /// computation); a pre-indexed store produces one value (result
603 /// of the address computation).
605 /// POST_INC The effective address is the value of the base pointer. The
606 /// POST_DEC value of the offset operand is then added to / subtracted
607 /// from the base after memory transaction. In addition to
608 /// producing a chain, post-indexed load produces two values
609 /// (the result of the load and the result of the base +/- offset
610 /// computation); a post-indexed store produces one value (the
611 /// the result of the base +/- offset computation).
613 enum MemIndexedMode {
622 //===--------------------------------------------------------------------===//
623 /// LoadExtType enum - This enum defines the three variants of LOADEXT
624 /// (load with extension).
626 /// SEXTLOAD loads the integer operand and sign extends it to a larger
627 /// integer result type.
628 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
629 /// integer result type.
630 /// EXTLOAD is used for three things: floating point extending loads,
631 /// integer extending loads [the top bits are undefined], and vector
632 /// extending loads [load into low elt].
642 //===--------------------------------------------------------------------===//
643 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
644 /// below work out, when considering SETFALSE (something that never exists
645 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
646 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
647 /// to. If the "N" column is 1, the result of the comparison is undefined if
648 /// the input is a NAN.
650 /// All of these (except for the 'always folded ops') should be handled for
651 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
652 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
654 /// Note that these are laid out in a specific order to allow bit-twiddling
655 /// to transform conditions.
657 // Opcode N U L G E Intuitive operation
658 SETFALSE, // 0 0 0 0 Always false (always folded)
659 SETOEQ, // 0 0 0 1 True if ordered and equal
660 SETOGT, // 0 0 1 0 True if ordered and greater than
661 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
662 SETOLT, // 0 1 0 0 True if ordered and less than
663 SETOLE, // 0 1 0 1 True if ordered and less than or equal
664 SETONE, // 0 1 1 0 True if ordered and operands are unequal
665 SETO, // 0 1 1 1 True if ordered (no nans)
666 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
667 SETUEQ, // 1 0 0 1 True if unordered or equal
668 SETUGT, // 1 0 1 0 True if unordered or greater than
669 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
670 SETULT, // 1 1 0 0 True if unordered or less than
671 SETULE, // 1 1 0 1 True if unordered, less than, or equal
672 SETUNE, // 1 1 1 0 True if unordered or not equal
673 SETTRUE, // 1 1 1 1 Always true (always folded)
674 // Don't care operations: undefined if the input is a nan.
675 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
676 SETEQ, // 1 X 0 0 1 True if equal
677 SETGT, // 1 X 0 1 0 True if greater than
678 SETGE, // 1 X 0 1 1 True if greater than or equal
679 SETLT, // 1 X 1 0 0 True if less than
680 SETLE, // 1 X 1 0 1 True if less than or equal
681 SETNE, // 1 X 1 1 0 True if not equal
682 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
684 SETCC_INVALID // Marker value.
687 /// isSignedIntSetCC - Return true if this is a setcc instruction that
688 /// performs a signed comparison when used with integer operands.
689 inline bool isSignedIntSetCC(CondCode Code) {
690 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
693 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
694 /// performs an unsigned comparison when used with integer operands.
695 inline bool isUnsignedIntSetCC(CondCode Code) {
696 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
699 /// isTrueWhenEqual - Return true if the specified condition returns true if
700 /// the two operands to the condition are equal. Note that if one of the two
701 /// operands is a NaN, this value is meaningless.
702 inline bool isTrueWhenEqual(CondCode Cond) {
703 return ((int)Cond & 1) != 0;
706 /// getUnorderedFlavor - This function returns 0 if the condition is always
707 /// false if an operand is a NaN, 1 if the condition is always true if the
708 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
710 inline unsigned getUnorderedFlavor(CondCode Cond) {
711 return ((int)Cond >> 3) & 3;
714 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
715 /// 'op' is a valid SetCC operation.
716 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
718 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
719 /// when given the operation for (X op Y).
720 CondCode getSetCCSwappedOperands(CondCode Operation);
722 /// getSetCCOrOperation - Return the result of a logical OR between different
723 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
724 /// function returns SETCC_INVALID if it is not possible to represent the
725 /// resultant comparison.
726 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
728 /// getSetCCAndOperation - Return the result of a logical AND between
729 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
730 /// function returns SETCC_INVALID if it is not possible to represent the
731 /// resultant comparison.
732 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
733 } // end llvm::ISD namespace
736 //===----------------------------------------------------------------------===//
737 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
738 /// values as the result of a computation. Many nodes return multiple values,
739 /// from loads (which define a token and a return value) to ADDC (which returns
740 /// a result and a carry value), to calls (which may return an arbitrary number
743 /// As such, each use of a SelectionDAG computation must indicate the node that
744 /// computes it as well as which return value to use from that node. This pair
745 /// of information is represented with the SDOperand value type.
749 SDNode *Val; // The node defining the value we are using.
750 unsigned ResNo; // Which return value of the node we are using.
752 SDOperand() : Val(0), ResNo(0) {}
753 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
755 bool operator==(const SDOperand &O) const {
756 return Val == O.Val && ResNo == O.ResNo;
758 bool operator!=(const SDOperand &O) const {
759 return !operator==(O);
761 bool operator<(const SDOperand &O) const {
762 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
765 SDOperand getValue(unsigned R) const {
766 return SDOperand(Val, R);
769 // isOperand - Return true if this node is an operand of N.
770 bool isOperand(SDNode *N) const;
772 /// getValueType - Return the ValueType of the referenced return value.
774 inline MVT::ValueType getValueType() const;
776 // Forwarding methods - These forward to the corresponding methods in SDNode.
777 inline unsigned getOpcode() const;
778 inline unsigned getNumOperands() const;
779 inline const SDOperand &getOperand(unsigned i) const;
780 inline uint64_t getConstantOperandVal(unsigned i) const;
781 inline bool isTargetOpcode() const;
782 inline unsigned getTargetOpcode() const;
784 /// hasOneUse - Return true if there is exactly one operation using this
785 /// result value of the defining operator.
786 inline bool hasOneUse() const;
790 /// simplify_type specializations - Allow casting operators to work directly on
791 /// SDOperands as if they were SDNode*'s.
792 template<> struct simplify_type<SDOperand> {
793 typedef SDNode* SimpleType;
794 static SimpleType getSimplifiedValue(const SDOperand &Val) {
795 return static_cast<SimpleType>(Val.Val);
798 template<> struct simplify_type<const SDOperand> {
799 typedef SDNode* SimpleType;
800 static SimpleType getSimplifiedValue(const SDOperand &Val) {
801 return static_cast<SimpleType>(Val.Val);
806 /// SDNode - Represents one node in the SelectionDAG.
808 class SDNode : public FoldingSetNode {
809 /// NodeType - The operation that this node performs.
811 unsigned short NodeType;
813 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
814 /// then they will be delete[]'d when the node is destroyed.
815 bool OperandsNeedDelete : 1;
817 /// NodeId - Unique id per SDNode in the DAG.
820 /// OperandList - The values that are used by this operation.
822 SDOperand *OperandList;
824 /// ValueList - The types of the values this node defines. SDNode's may
825 /// define multiple values simultaneously.
826 const MVT::ValueType *ValueList;
828 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
829 unsigned short NumOperands, NumValues;
831 /// Prev/Next pointers - These pointers form the linked list of of the
832 /// AllNodes list in the current DAG.
834 friend struct ilist_traits<SDNode>;
836 /// Uses - These are all of the SDNode's that use a value produced by this
838 SmallVector<SDNode*,3> Uses;
840 // Out-of-line virtual method to give class a home.
841 virtual void ANCHOR();
844 assert(NumOperands == 0 && "Operand list not cleared before deletion");
845 NodeType = ISD::DELETED_NODE;
848 //===--------------------------------------------------------------------===//
851 unsigned getOpcode() const { return NodeType; }
852 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
853 unsigned getTargetOpcode() const {
854 assert(isTargetOpcode() && "Not a target opcode!");
855 return NodeType - ISD::BUILTIN_OP_END;
858 size_t use_size() const { return Uses.size(); }
859 bool use_empty() const { return Uses.empty(); }
860 bool hasOneUse() const { return Uses.size() == 1; }
862 /// getNodeId - Return the unique node id.
864 int getNodeId() const { return NodeId; }
866 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
867 use_iterator use_begin() const { return Uses.begin(); }
868 use_iterator use_end() const { return Uses.end(); }
870 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
871 /// indicated value. This method ignores uses of other values defined by this
873 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
875 /// isOnlyUse - Return true if this node is the only use of N.
877 bool isOnlyUse(SDNode *N) const;
879 /// isOperand - Return true if this node is an operand of N.
881 bool isOperand(SDNode *N) const;
883 /// isPredecessor - Return true if this node is a predecessor of N. This node
884 /// is either an operand of N or it can be reached by recursively traversing
886 /// NOTE: this is an expensive method. Use it carefully.
887 bool isPredecessor(SDNode *N) const;
889 /// getNumOperands - Return the number of values used by this operation.
891 unsigned getNumOperands() const { return NumOperands; }
893 /// getConstantOperandVal - Helper method returns the integer value of a
894 /// ConstantSDNode operand.
895 uint64_t getConstantOperandVal(unsigned Num) const;
897 const SDOperand &getOperand(unsigned Num) const {
898 assert(Num < NumOperands && "Invalid child # of SDNode!");
899 return OperandList[Num];
902 typedef const SDOperand* op_iterator;
903 op_iterator op_begin() const { return OperandList; }
904 op_iterator op_end() const { return OperandList+NumOperands; }
907 SDVTList getVTList() const {
908 SDVTList X = { ValueList, NumValues };
912 /// getNumValues - Return the number of values defined/returned by this
915 unsigned getNumValues() const { return NumValues; }
917 /// getValueType - Return the type of a specified result.
919 MVT::ValueType getValueType(unsigned ResNo) const {
920 assert(ResNo < NumValues && "Illegal result number!");
921 return ValueList[ResNo];
924 typedef const MVT::ValueType* value_iterator;
925 value_iterator value_begin() const { return ValueList; }
926 value_iterator value_end() const { return ValueList+NumValues; }
928 /// getOperationName - Return the opcode of this operation for printing.
930 std::string getOperationName(const SelectionDAG *G = 0) const;
931 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
933 void dump(const SelectionDAG *G) const;
935 static bool classof(const SDNode *) { return true; }
937 /// Profile - Gather unique data for the node.
939 void Profile(FoldingSetNodeID &ID);
942 friend class SelectionDAG;
944 /// getValueTypeList - Return a pointer to the specified value type.
946 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
947 static SDVTList getSDVTList(MVT::ValueType VT) {
948 SDVTList Ret = { getValueTypeList(VT), 1 };
952 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
953 : NodeType(Opc), NodeId(-1) {
954 OperandsNeedDelete = true;
955 NumOperands = NumOps;
956 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
958 for (unsigned i = 0; i != NumOps; ++i) {
959 OperandList[i] = Ops[i];
960 Ops[i].Val->Uses.push_back(this);
964 NumValues = VTs.NumVTs;
967 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
968 OperandsNeedDelete = false; // Operands set with InitOperands.
973 NumValues = VTs.NumVTs;
977 /// InitOperands - Initialize the operands list of this node with the
978 /// specified values, which are part of the node (thus they don't need to be
979 /// copied in or allocated).
980 void InitOperands(SDOperand *Ops, unsigned NumOps) {
981 assert(OperandList == 0 && "Operands already set!");
982 NumOperands = NumOps;
985 for (unsigned i = 0; i != NumOps; ++i)
986 Ops[i].Val->Uses.push_back(this);
989 /// MorphNodeTo - This frees the operands of the current node, resets the
990 /// opcode, types, and operands to the specified value. This should only be
991 /// used by the SelectionDAG class.
992 void MorphNodeTo(unsigned Opc, SDVTList L,
993 const SDOperand *Ops, unsigned NumOps);
995 void addUser(SDNode *User) {
996 Uses.push_back(User);
998 void removeUser(SDNode *User) {
999 // Remove this user from the operand's use list.
1000 for (unsigned i = Uses.size(); ; --i) {
1001 assert(i != 0 && "Didn't find user!");
1002 if (Uses[i-1] == User) {
1003 Uses[i-1] = Uses.back();
1010 void setNodeId(int Id) {
1016 // Define inline functions from the SDOperand class.
1018 inline unsigned SDOperand::getOpcode() const {
1019 return Val->getOpcode();
1021 inline MVT::ValueType SDOperand::getValueType() const {
1022 return Val->getValueType(ResNo);
1024 inline unsigned SDOperand::getNumOperands() const {
1025 return Val->getNumOperands();
1027 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1028 return Val->getOperand(i);
1030 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1031 return Val->getConstantOperandVal(i);
1033 inline bool SDOperand::isTargetOpcode() const {
1034 return Val->isTargetOpcode();
1036 inline unsigned SDOperand::getTargetOpcode() const {
1037 return Val->getTargetOpcode();
1039 inline bool SDOperand::hasOneUse() const {
1040 return Val->hasNUsesOfValue(1, ResNo);
1043 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1044 /// to allow co-allocation of node operands with the node itself.
1045 class UnarySDNode : public SDNode {
1046 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1049 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1050 : SDNode(Opc, VTs), Op(X) {
1051 InitOperands(&Op, 1);
1055 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1056 /// to allow co-allocation of node operands with the node itself.
1057 class BinarySDNode : public SDNode {
1058 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1061 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1062 : SDNode(Opc, VTs) {
1065 InitOperands(Ops, 2);
1069 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1070 /// to allow co-allocation of node operands with the node itself.
1071 class TernarySDNode : public SDNode {
1072 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1075 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1077 : SDNode(Opc, VTs) {
1081 InitOperands(Ops, 3);
1086 /// HandleSDNode - This class is used to form a handle around another node that
1087 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1088 /// operand. This node should be directly created by end-users and not added to
1089 /// the AllNodes list.
1090 class HandleSDNode : public SDNode {
1091 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1094 explicit HandleSDNode(SDOperand X)
1095 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1096 InitOperands(&Op, 1);
1099 SDOperand getValue() const { return Op; }
1102 class StringSDNode : public SDNode {
1104 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1106 friend class SelectionDAG;
1107 explicit StringSDNode(const std::string &val)
1108 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1111 const std::string &getValue() const { return Value; }
1112 static bool classof(const StringSDNode *) { return true; }
1113 static bool classof(const SDNode *N) {
1114 return N->getOpcode() == ISD::STRING;
1118 class ConstantSDNode : public SDNode {
1120 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1122 friend class SelectionDAG;
1123 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1124 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1129 uint64_t getValue() const { return Value; }
1131 int64_t getSignExtended() const {
1132 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1133 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1136 bool isNullValue() const { return Value == 0; }
1137 bool isAllOnesValue() const {
1138 return Value == MVT::getIntVTBitMask(getValueType(0));
1141 static bool classof(const ConstantSDNode *) { return true; }
1142 static bool classof(const SDNode *N) {
1143 return N->getOpcode() == ISD::Constant ||
1144 N->getOpcode() == ISD::TargetConstant;
1148 class ConstantFPSDNode : public SDNode {
1150 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1152 friend class SelectionDAG;
1153 ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1154 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1155 getSDVTList(VT)), Value(val) {
1159 double getValue() const { return Value; }
1161 /// isExactlyValue - We don't rely on operator== working on double values, as
1162 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1163 /// As such, this method can be used to do an exact bit-for-bit comparison of
1164 /// two floating point values.
1165 bool isExactlyValue(double V) const;
1167 static bool classof(const ConstantFPSDNode *) { return true; }
1168 static bool classof(const SDNode *N) {
1169 return N->getOpcode() == ISD::ConstantFP ||
1170 N->getOpcode() == ISD::TargetConstantFP;
1174 class GlobalAddressSDNode : public SDNode {
1175 GlobalValue *TheGlobal;
1177 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1179 friend class SelectionDAG;
1180 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1184 GlobalValue *getGlobal() const { return TheGlobal; }
1185 int getOffset() const { return Offset; }
1187 static bool classof(const GlobalAddressSDNode *) { return true; }
1188 static bool classof(const SDNode *N) {
1189 return N->getOpcode() == ISD::GlobalAddress ||
1190 N->getOpcode() == ISD::TargetGlobalAddress ||
1191 N->getOpcode() == ISD::GlobalTLSAddress ||
1192 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1196 class FrameIndexSDNode : public SDNode {
1198 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1200 friend class SelectionDAG;
1201 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1202 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1207 int getIndex() const { return FI; }
1209 static bool classof(const FrameIndexSDNode *) { return true; }
1210 static bool classof(const SDNode *N) {
1211 return N->getOpcode() == ISD::FrameIndex ||
1212 N->getOpcode() == ISD::TargetFrameIndex;
1216 class JumpTableSDNode : public SDNode {
1218 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1220 friend class SelectionDAG;
1221 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1222 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1227 int getIndex() const { return JTI; }
1229 static bool classof(const JumpTableSDNode *) { return true; }
1230 static bool classof(const SDNode *N) {
1231 return N->getOpcode() == ISD::JumpTable ||
1232 N->getOpcode() == ISD::TargetJumpTable;
1236 class ConstantPoolSDNode : public SDNode {
1239 MachineConstantPoolValue *MachineCPVal;
1241 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1243 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1245 friend class SelectionDAG;
1246 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1248 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1249 getSDVTList(VT)), Offset(o), Alignment(0) {
1250 assert((int)Offset >= 0 && "Offset is too large");
1253 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1255 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1256 getSDVTList(VT)), Offset(o), Alignment(Align) {
1257 assert((int)Offset >= 0 && "Offset is too large");
1260 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1261 MVT::ValueType VT, int o=0)
1262 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1263 getSDVTList(VT)), Offset(o), Alignment(0) {
1264 assert((int)Offset >= 0 && "Offset is too large");
1265 Val.MachineCPVal = v;
1266 Offset |= 1 << (sizeof(unsigned)*8-1);
1268 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1269 MVT::ValueType VT, int o, unsigned Align)
1270 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1271 getSDVTList(VT)), Offset(o), Alignment(Align) {
1272 assert((int)Offset >= 0 && "Offset is too large");
1273 Val.MachineCPVal = v;
1274 Offset |= 1 << (sizeof(unsigned)*8-1);
1278 bool isMachineConstantPoolEntry() const {
1279 return (int)Offset < 0;
1282 Constant *getConstVal() const {
1283 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1284 return Val.ConstVal;
1287 MachineConstantPoolValue *getMachineCPVal() const {
1288 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1289 return Val.MachineCPVal;
1292 int getOffset() const {
1293 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1296 // Return the alignment of this constant pool object, which is either 0 (for
1297 // default alignment) or log2 of the desired value.
1298 unsigned getAlignment() const { return Alignment; }
1300 const Type *getType() const;
1302 static bool classof(const ConstantPoolSDNode *) { return true; }
1303 static bool classof(const SDNode *N) {
1304 return N->getOpcode() == ISD::ConstantPool ||
1305 N->getOpcode() == ISD::TargetConstantPool;
1309 class BasicBlockSDNode : public SDNode {
1310 MachineBasicBlock *MBB;
1311 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1313 friend class SelectionDAG;
1314 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1315 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1319 MachineBasicBlock *getBasicBlock() const { return MBB; }
1321 static bool classof(const BasicBlockSDNode *) { return true; }
1322 static bool classof(const SDNode *N) {
1323 return N->getOpcode() == ISD::BasicBlock;
1327 class SrcValueSDNode : public SDNode {
1330 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1332 friend class SelectionDAG;
1333 SrcValueSDNode(const Value* v, int o)
1334 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v), offset(o) {
1338 const Value *getValue() const { return V; }
1339 int getOffset() const { return offset; }
1341 static bool classof(const SrcValueSDNode *) { return true; }
1342 static bool classof(const SDNode *N) {
1343 return N->getOpcode() == ISD::SRCVALUE;
1348 class RegisterSDNode : public SDNode {
1350 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1352 friend class SelectionDAG;
1353 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1354 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1358 unsigned getReg() const { return Reg; }
1360 static bool classof(const RegisterSDNode *) { return true; }
1361 static bool classof(const SDNode *N) {
1362 return N->getOpcode() == ISD::Register;
1366 class ExternalSymbolSDNode : public SDNode {
1368 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1370 friend class SelectionDAG;
1371 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1372 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1373 getSDVTList(VT)), Symbol(Sym) {
1377 const char *getSymbol() const { return Symbol; }
1379 static bool classof(const ExternalSymbolSDNode *) { return true; }
1380 static bool classof(const SDNode *N) {
1381 return N->getOpcode() == ISD::ExternalSymbol ||
1382 N->getOpcode() == ISD::TargetExternalSymbol;
1386 class CondCodeSDNode : public SDNode {
1387 ISD::CondCode Condition;
1388 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1390 friend class SelectionDAG;
1391 explicit CondCodeSDNode(ISD::CondCode Cond)
1392 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1396 ISD::CondCode get() const { return Condition; }
1398 static bool classof(const CondCodeSDNode *) { return true; }
1399 static bool classof(const SDNode *N) {
1400 return N->getOpcode() == ISD::CONDCODE;
1404 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1405 /// to parameterize some operations.
1406 class VTSDNode : public SDNode {
1407 MVT::ValueType ValueType;
1408 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1410 friend class SelectionDAG;
1411 explicit VTSDNode(MVT::ValueType VT)
1412 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1416 MVT::ValueType getVT() const { return ValueType; }
1418 static bool classof(const VTSDNode *) { return true; }
1419 static bool classof(const SDNode *N) {
1420 return N->getOpcode() == ISD::VALUETYPE;
1424 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1426 class LoadSDNode : public SDNode {
1427 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1430 // AddrMode - unindexed, pre-indexed, post-indexed.
1431 ISD::MemIndexedMode AddrMode;
1433 // ExtType - non-ext, anyext, sext, zext.
1434 ISD::LoadExtType ExtType;
1436 // LoadedVT - VT of loaded value before extension.
1437 MVT::ValueType LoadedVT;
1439 // SrcValue - Memory location for alias analysis.
1440 const Value *SrcValue;
1442 // SVOffset - Memory location offset.
1445 // Alignment - Alignment of memory location in bytes.
1448 // IsVolatile - True if the load is volatile.
1451 friend class SelectionDAG;
1452 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1453 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1454 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1455 : SDNode(ISD::LOAD, VTs),
1456 AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
1457 Alignment(Align), IsVolatile(Vol) {
1458 Ops[0] = ChainPtrOff[0]; // Chain
1459 Ops[1] = ChainPtrOff[1]; // Ptr
1460 Ops[2] = ChainPtrOff[2]; // Off
1461 InitOperands(Ops, 3);
1462 assert(Align != 0 && "Loads should have non-zero aligment");
1463 assert((getOffset().getOpcode() == ISD::UNDEF ||
1464 AddrMode != ISD::UNINDEXED) &&
1465 "Only indexed load has a non-undef offset operand");
1469 const SDOperand getChain() const { return getOperand(0); }
1470 const SDOperand getBasePtr() const { return getOperand(1); }
1471 const SDOperand getOffset() const { return getOperand(2); }
1472 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1473 ISD::LoadExtType getExtensionType() const { return ExtType; }
1474 MVT::ValueType getLoadedVT() const { return LoadedVT; }
1475 const Value *getSrcValue() const { return SrcValue; }
1476 int getSrcValueOffset() const { return SVOffset; }
1477 unsigned getAlignment() const { return Alignment; }
1478 bool isVolatile() const { return IsVolatile; }
1480 static bool classof(const LoadSDNode *) { return true; }
1481 static bool classof(const SDNode *N) {
1482 return N->getOpcode() == ISD::LOAD;
1486 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1488 class StoreSDNode : public SDNode {
1489 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1492 // AddrMode - unindexed, pre-indexed, post-indexed.
1493 ISD::MemIndexedMode AddrMode;
1495 // IsTruncStore - True is the op does a truncation before store.
1498 // StoredVT - VT of the value after truncation.
1499 MVT::ValueType StoredVT;
1501 // SrcValue - Memory location for alias analysis.
1502 const Value *SrcValue;
1504 // SVOffset - Memory location offset.
1507 // Alignment - Alignment of memory location in bytes.
1510 // IsVolatile - True if the store is volatile.
1513 friend class SelectionDAG;
1514 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1515 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1516 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1517 : SDNode(ISD::STORE, VTs),
1518 AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT), SrcValue(SV),
1519 SVOffset(O), Alignment(Align), IsVolatile(Vol) {
1520 Ops[0] = ChainValuePtrOff[0]; // Chain
1521 Ops[1] = ChainValuePtrOff[1]; // Value
1522 Ops[2] = ChainValuePtrOff[2]; // Ptr
1523 Ops[3] = ChainValuePtrOff[3]; // Off
1524 InitOperands(Ops, 4);
1525 assert(Align != 0 && "Stores should have non-zero aligment");
1526 assert((getOffset().getOpcode() == ISD::UNDEF ||
1527 AddrMode != ISD::UNINDEXED) &&
1528 "Only indexed store has a non-undef offset operand");
1532 const SDOperand getChain() const { return getOperand(0); }
1533 const SDOperand getValue() const { return getOperand(1); }
1534 const SDOperand getBasePtr() const { return getOperand(2); }
1535 const SDOperand getOffset() const { return getOperand(3); }
1536 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1537 bool isTruncatingStore() const { return IsTruncStore; }
1538 MVT::ValueType getStoredVT() const { return StoredVT; }
1539 const Value *getSrcValue() const { return SrcValue; }
1540 int getSrcValueOffset() const { return SVOffset; }
1541 unsigned getAlignment() const { return Alignment; }
1542 bool isVolatile() const { return IsVolatile; }
1544 static bool classof(const StoreSDNode *) { return true; }
1545 static bool classof(const SDNode *N) {
1546 return N->getOpcode() == ISD::STORE;
1551 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1555 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1557 bool operator==(const SDNodeIterator& x) const {
1558 return Operand == x.Operand;
1560 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1562 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1563 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1564 Operand = I.Operand;
1568 pointer operator*() const {
1569 return Node->getOperand(Operand).Val;
1571 pointer operator->() const { return operator*(); }
1573 SDNodeIterator& operator++() { // Preincrement
1577 SDNodeIterator operator++(int) { // Postincrement
1578 SDNodeIterator tmp = *this; ++*this; return tmp;
1581 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1582 static SDNodeIterator end (SDNode *N) {
1583 return SDNodeIterator(N, N->getNumOperands());
1586 unsigned getOperand() const { return Operand; }
1587 const SDNode *getNode() const { return Node; }
1590 template <> struct GraphTraits<SDNode*> {
1591 typedef SDNode NodeType;
1592 typedef SDNodeIterator ChildIteratorType;
1593 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1594 static inline ChildIteratorType child_begin(NodeType *N) {
1595 return SDNodeIterator::begin(N);
1597 static inline ChildIteratorType child_end(NodeType *N) {
1598 return SDNodeIterator::end(N);
1603 struct ilist_traits<SDNode> {
1604 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1605 static SDNode *getNext(const SDNode *N) { return N->Next; }
1607 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1608 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1610 static SDNode *createSentinel() {
1611 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1613 static void destroySentinel(SDNode *N) { delete N; }
1614 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1617 void addNodeToList(SDNode *NTy) {}
1618 void removeNodeFromList(SDNode *NTy) {}
1619 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1620 const ilist_iterator<SDNode> &X,
1621 const ilist_iterator<SDNode> &Y) {}
1625 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1627 inline bool isNON_EXTLoad(const SDNode *N) {
1628 return N->getOpcode() == ISD::LOAD &&
1629 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1632 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1634 inline bool isEXTLoad(const SDNode *N) {
1635 return N->getOpcode() == ISD::LOAD &&
1636 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1639 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1641 inline bool isSEXTLoad(const SDNode *N) {
1642 return N->getOpcode() == ISD::LOAD &&
1643 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1646 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1648 inline bool isZEXTLoad(const SDNode *N) {
1649 return N->getOpcode() == ISD::LOAD &&
1650 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1653 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1655 inline bool isUNINDEXEDLoad(const SDNode *N) {
1656 return N->getOpcode() == ISD::LOAD &&
1657 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1660 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1662 inline bool isNON_TRUNCStore(const SDNode *N) {
1663 return N->getOpcode() == ISD::STORE &&
1664 !cast<StoreSDNode>(N)->isTruncatingStore();
1667 /// isTRUNCStore - Returns true if the specified node is a truncating
1669 inline bool isTRUNCStore(const SDNode *N) {
1670 return N->getOpcode() == ISD::STORE &&
1671 cast<StoreSDNode>(N)->isTruncatingStore();
1676 } // end llvm namespace