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;
52 /// ISD namespace - This namespace contains an enum which represents all of the
53 /// SelectionDAG node types and value types.
56 //===--------------------------------------------------------------------===//
57 /// ISD::NodeType enum - This enum defines all of the operators valid in a
61 // DELETED_NODE - This is an illegal flag value that is used to catch
62 // errors. This opcode is not a legal opcode for any node.
65 // EntryToken - This is the marker used to indicate the start of the region.
68 // Token factor - This node takes multiple tokens as input and produces a
69 // single token result. This is used to represent the fact that the operand
70 // operators are independent of each other.
73 // AssertSext, AssertZext - These nodes record if a register contains a
74 // value that has already been zero or sign extended from a narrower type.
75 // These nodes take two operands. The first is the node that has already
76 // been extended, and the second is a value type node indicating the width
78 AssertSext, AssertZext,
80 // Various leaf nodes.
81 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
83 GlobalAddress, FrameIndex, JumpTable, ConstantPool, ExternalSymbol,
85 // The address of the GOT
88 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
89 // llvm.returnaddress on the DAG. These nodes take one operand, the index
90 // of the frame or return address to return. An index of zero corresponds
91 // to the current function's frame or return address, an index of one to the
92 // parent's frame or return address, and so on.
93 FRAMEADDR, RETURNADDR,
95 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
96 // simplification of the constant.
100 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
101 // anything else with this node, and this is valid in the target-specific
102 // dag, turning into a GlobalAddress operand.
107 TargetExternalSymbol,
109 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
110 /// This node represents a target intrinsic function with no side effects.
111 /// The first operand is the ID number of the intrinsic from the
112 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
113 /// node has returns the result of the intrinsic.
116 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
117 /// This node represents a target intrinsic function with side effects that
118 /// returns a result. The first operand is a chain pointer. The second is
119 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
120 /// operands to the intrinsic follow. The node has two results, the result
121 /// of the intrinsic and an output chain.
124 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
125 /// This node represents a target intrinsic function with side effects that
126 /// does not return a result. The first operand is a chain pointer. The
127 /// second is the ID number of the intrinsic from the llvm::Intrinsic
128 /// namespace. The operands to the intrinsic follow.
131 // CopyToReg - This node has three operands: a chain, a register number to
132 // set to this value, and a value.
135 // CopyFromReg - This node indicates that the input value is a virtual or
136 // physical register that is defined outside of the scope of this
137 // SelectionDAG. The register is available from the RegSDNode object.
140 // UNDEF - An undefined node
143 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
144 /// represents the formal arguments for a function. CC# is a Constant value
145 /// indicating the calling convention of the function, and ISVARARG is a
146 /// flag that indicates whether the function is varargs or not. This node
147 /// has one result value for each incoming argument, plus one for the output
148 /// chain. It must be custom legalized. See description of CALL node for
149 /// FLAG argument contents explanation.
153 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
154 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
155 /// This node represents a fully general function call, before the legalizer
156 /// runs. This has one result value for each argument / flag pair, plus
157 /// a chain result. It must be custom legalized. Flag argument indicates
158 /// misc. argument attributes. Currently:
160 /// Bit 1 - 'inreg' attribute
161 /// Bit 2 - 'sret' attribute
164 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
165 // a Constant, which is required to be operand #1), element of the aggregate
166 // value specified as operand #0. This is only for use before legalization,
167 // for values that will be broken into multiple registers.
170 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
171 // two values of the same integer value type, this produces a value twice as
172 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
175 // MERGE_VALUES - This node takes multiple discrete operands and returns
176 // them all as its individual results. This nodes has exactly the same
177 // number of inputs and outputs, and is only valid before legalization.
178 // This node is useful for some pieces of the code generator that want to
179 // think about a single node with multiple results, not multiple nodes.
182 // Simple integer binary arithmetic operators.
183 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
185 // Carry-setting nodes for multiple precision addition and subtraction.
186 // These nodes take two operands of the same value type, and produce two
187 // results. The first result is the normal add or sub result, the second
188 // result is the carry flag result.
191 // Carry-using nodes for multiple precision addition and subtraction. These
192 // nodes take three operands: The first two are the normal lhs and rhs to
193 // the add or sub, and the third is the input carry flag. These nodes
194 // produce two results; the normal result of the add or sub, and the output
195 // carry flag. These nodes both read and write a carry flag to allow them
196 // to them to be chained together for add and sub of arbitrarily large
200 // Simple binary floating point operators.
201 FADD, FSUB, FMUL, FDIV, FREM,
203 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
204 // DAG node does not require that X and Y have the same type, just that they
205 // are both floating point. X and the result must have the same type.
206 // FCOPYSIGN(f32, f64) is allowed.
209 /// VBUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,..., COUNT,TYPE) - Return a vector
210 /// with the specified, possibly variable, elements. The number of elements
211 /// is required to be a power of two.
214 /// BUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,...) - Return a vector
215 /// with the specified, possibly variable, elements. The number of elements
216 /// is required to be a power of two.
219 /// VINSERT_VECTOR_ELT(VECTOR, VAL, IDX, COUNT,TYPE) - Given a vector
220 /// VECTOR, an element ELEMENT, and a (potentially variable) index IDX,
221 /// return an vector with the specified element of VECTOR replaced with VAL.
222 /// COUNT and TYPE specify the type of vector, as is standard for V* nodes.
225 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR (a legal packed
226 /// type) with the element at IDX replaced with VAL.
229 /// VEXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
230 /// (an MVT::Vector value) identified by the (potentially variable) element
234 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
235 /// (a legal packed type vector) identified by the (potentially variable)
236 /// element number IDX.
239 /// VVECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC, COUNT,TYPE) - Returns a vector,
240 /// of the same type as VEC1/VEC2. SHUFFLEVEC is a VBUILD_VECTOR of
241 /// constant int values that indicate which value each result element will
242 /// get. The elements of VEC1/VEC2 are enumerated in order. This is quite
243 /// similar to the Altivec 'vperm' instruction, except that the indices must
244 /// be constants and are in terms of the element size of VEC1/VEC2, not in
248 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
249 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
250 /// (regardless of whether its datatype is legal or not) that indicate
251 /// which value each result element will get. The elements of VEC1/VEC2 are
252 /// enumerated in order. This is quite similar to the Altivec 'vperm'
253 /// instruction, except that the indices must be constants and are in terms
254 /// of the element size of VEC1/VEC2, not in terms of bytes.
257 /// X = VBIT_CONVERT(Y) and X = VBIT_CONVERT(Y, COUNT,TYPE) - This node
258 /// represents a conversion from or to an ISD::Vector type.
260 /// This is lowered to a BIT_CONVERT of the appropriate input/output types.
261 /// The input and output are required to have the same size and at least one
262 /// is required to be a vector (if neither is a vector, just use
265 /// If the result is a vector, this takes three operands (like any other
266 /// vector producer) which indicate the size and type of the vector result.
267 /// Otherwise it takes one input.
270 /// BINOP(LHS, RHS, COUNT,TYPE)
271 /// Simple abstract vector operators. Unlike the integer and floating point
272 /// binary operators, these nodes also take two additional operands:
273 /// a constant element count, and a value type node indicating the type of
274 /// the elements. The order is count, type, op0, op1. All vector opcodes,
275 /// including VLOAD and VConstant must currently have count and type as
276 /// their last two operands.
277 VADD, VSUB, VMUL, VSDIV, VUDIV,
280 /// VSELECT(COND,LHS,RHS, COUNT,TYPE) - Select for MVT::Vector values.
281 /// COND is a boolean value. This node return LHS if COND is true, RHS if
285 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
286 /// scalar value into the low element of the resultant vector type. The top
287 /// elements of the vector are undefined.
290 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
291 // an unsigned/signed value of type i[2*n], then return the top part.
294 // Bitwise operators - logical and, logical or, logical xor, shift left,
295 // shift right algebraic (shift in sign bits), shift right logical (shift in
296 // zeroes), rotate left, rotate right, and byteswap.
297 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
299 // Counting operators
302 // Select(COND, TRUEVAL, FALSEVAL)
305 // Select with condition operator - This selects between a true value and
306 // a false value (ops #2 and #3) based on the boolean result of comparing
307 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
308 // condition code in op #4, a CondCodeSDNode.
311 // SetCC operator - This evaluates to a boolean (i1) true value if the
312 // condition is true. The operands to this are the left and right operands
313 // to compare (ops #0, and #1) and the condition code to compare them with
314 // (op #2) as a CondCodeSDNode.
317 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
318 // integer shift operations, just like ADD/SUB_PARTS. The operation
320 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
321 SHL_PARTS, SRA_PARTS, SRL_PARTS,
323 // Conversion operators. These are all single input single output
324 // operations. For all of these, the result type must be strictly
325 // wider or narrower (depending on the operation) than the source
328 // SIGN_EXTEND - Used for integer types, replicating the sign bit
332 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
335 // ANY_EXTEND - Used for integer types. The high bits are undefined.
338 // TRUNCATE - Completely drop the high bits.
341 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
342 // depends on the first letter) to floating point.
346 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
347 // sign extend a small value in a large integer register (e.g. sign
348 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
349 // with the 7th bit). The size of the smaller type is indicated by the 1th
350 // operand, a ValueType node.
353 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
358 // FP_ROUND - Perform a rounding operation from the current
359 // precision down to the specified precision (currently always 64->32).
362 // FP_ROUND_INREG - This operator takes a floating point register, and
363 // rounds it to a floating point value. It then promotes it and returns it
364 // in a register of the same size. This operation effectively just discards
365 // excess precision. The type to round down to is specified by the 1th
366 // operation, a VTSDNode (currently always 64->32->64).
369 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
372 // BIT_CONVERT - Theis operator converts between integer and FP values, as
373 // if one was stored to memory as integer and the other was loaded from the
374 // same address (or equivalently for vector format conversions, etc). The
375 // source and result are required to have the same bit size (e.g.
376 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
377 // conversions, but that is a noop, deleted by getNode().
380 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI - Perform unary floating point
381 // negation, absolute value, square root, sine and cosine, and powi
383 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI,
385 // LOAD and STORE have token chains as their first operand, then the same
386 // operands as an LLVM load/store instruction, then an offset node that
387 // is added / subtracted from the base pointer to form the address (for
388 // indexed memory ops).
391 // Abstract vector version of LOAD. VLOAD has a constant element count as
392 // the first operand, followed by a value type node indicating the type of
393 // the elements, a token chain, a pointer operand, and a SRCVALUE node.
396 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
397 // value and stores it to memory in one operation. This can be used for
398 // either integer or floating point operands. The first four operands of
399 // this are the same as a standard store. The fifth is the ValueType to
400 // store it as (which will be smaller than the source value).
403 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
404 // to a specified boundary. The first operand is the token chain, the
405 // second is the number of bytes to allocate, and the third is the alignment
406 // boundary. The size is guaranteed to be a multiple of the stack
407 // alignment, and the alignment is guaranteed to be bigger than the stack
408 // alignment (if required) or 0 to get standard stack alignment.
411 // Control flow instructions. These all have token chains.
413 // BR - Unconditional branch. The first operand is the chain
414 // operand, the second is the MBB to branch to.
417 // BRIND - Indirect branch. The first operand is the chain, the second
418 // is the value to branch to, which must be of the same type as the target's
422 // BR_JT - Jumptable branch. The first operand is the chain, the second
423 // is the jumptable index, the last one is the jumptable entry index.
426 // BRCOND - Conditional branch. The first operand is the chain,
427 // the second is the condition, the third is the block to branch
428 // to if the condition is true.
431 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
432 // that the condition is represented as condition code, and two nodes to
433 // compare, rather than as a combined SetCC node. The operands in order are
434 // chain, cc, lhs, rhs, block to branch to if condition is true.
437 // RET - Return from function. The first operand is the chain,
438 // and any subsequent operands are pairs of return value and return value
439 // signness for the function. This operation can have variable number of
443 // INLINEASM - Represents an inline asm block. This node always has two
444 // return values: a chain and a flag result. The inputs are as follows:
445 // Operand #0 : Input chain.
446 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
447 // Operand #2n+2: A RegisterNode.
448 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
449 // Operand #last: Optional, an incoming flag.
452 // LABEL - Represents a label in mid basic block used to track
453 // locations needed for debug and exception handling tables. This node
455 // Operand #0 : input chain.
456 // Operand #1 : module unique number use to identify the label.
459 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
460 // value, the same type as the pointer type for the system, and an output
464 // STACKRESTORE has two operands, an input chain and a pointer to restore to
465 // it returns an output chain.
468 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
469 // correspond to the operands of the LLVM intrinsic functions. The only
470 // result is a token chain. The alignment argument is guaranteed to be a
476 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
477 // a call sequence, and carry arbitrary information that target might want
478 // to know. The first operand is a chain, the rest are specified by the
479 // target and not touched by the DAG optimizers.
480 CALLSEQ_START, // Beginning of a call sequence
481 CALLSEQ_END, // End of a call sequence
483 // VAARG - VAARG has three operands: an input chain, a pointer, and a
484 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
487 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
488 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
492 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
493 // pointer, and a SRCVALUE.
496 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
497 // locations with their value. This allows one use alias analysis
498 // information in the backend.
501 // PCMARKER - This corresponds to the pcmarker intrinsic.
504 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
505 // The only operand is a chain and a value and a chain are produced. The
506 // value is the contents of the architecture specific cycle counter like
507 // register (or other high accuracy low latency clock source)
510 // HANDLENODE node - Used as a handle for various purposes.
513 // LOCATION - This node is used to represent a source location for debug
514 // info. It takes token chain as input, then a line number, then a column
515 // number, then a filename, then a working dir. It produces a token chain
519 // DEBUG_LOC - This node is used to represent source line information
520 // embedded in the code. It takes a token chain as input, then a line
521 // number, then a column then a file id (provided by MachineModuleInfo.) It
522 // produces a token chain as output.
525 // BUILTIN_OP_END - This must be the last enum value in this list.
531 /// isBuildVectorAllOnes - Return true if the specified node is a
532 /// BUILD_VECTOR where all of the elements are ~0 or undef.
533 bool isBuildVectorAllOnes(const SDNode *N);
535 /// isBuildVectorAllZeros - Return true if the specified node is a
536 /// BUILD_VECTOR where all of the elements are 0 or undef.
537 bool isBuildVectorAllZeros(const SDNode *N);
539 //===--------------------------------------------------------------------===//
540 /// MemIndexedMode enum - This enum defines the load / store indexed
541 /// addressing modes.
543 /// UNINDEXED "Normal" load / store. The effective address is already
544 /// computed and is available in the base pointer. The offset
545 /// operand is always undefined. In addition to producing a
546 /// chain, an unindexed load produces one value (result of the
547 /// load); an unindexed store does not produces a value.
549 /// PRE_INC Similar to the unindexed mode where the effective address is
550 /// PRE_DEC the value of the base pointer add / subtract the offset.
551 /// It considers the computation as being folded into the load /
552 /// store operation (i.e. the load / store does the address
553 /// computation as well as performing the memory transaction).
554 /// The base operand is always undefined. In addition to
555 /// producing a chain, pre-indexed load produces two values
556 /// (result of the load and the result of the address
557 /// computation); a pre-indexed store produces one value (result
558 /// of the address computation).
560 /// POST_INC The effective address is the value of the base pointer. The
561 /// POST_DEC value of the offset operand is then added to / subtracted
562 /// from the base after memory transaction. In addition to
563 /// producing a chain, post-indexed load produces two values
564 /// (the result of the load and the result of the base +/- offset
565 /// computation); a post-indexed store produces one value (the
566 /// the result of the base +/- offset computation).
568 enum MemIndexedMode {
577 //===--------------------------------------------------------------------===//
578 /// LoadExtType enum - This enum defines the three variants of LOADEXT
579 /// (load with extension).
581 /// SEXTLOAD loads the integer operand and sign extends it to a larger
582 /// integer result type.
583 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
584 /// integer result type.
585 /// EXTLOAD is used for three things: floating point extending loads,
586 /// integer extending loads [the top bits are undefined], and vector
587 /// extending loads [load into low elt].
597 //===--------------------------------------------------------------------===//
598 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
599 /// below work out, when considering SETFALSE (something that never exists
600 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
601 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
602 /// to. If the "N" column is 1, the result of the comparison is undefined if
603 /// the input is a NAN.
605 /// All of these (except for the 'always folded ops') should be handled for
606 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
607 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
609 /// Note that these are laid out in a specific order to allow bit-twiddling
610 /// to transform conditions.
612 // Opcode N U L G E Intuitive operation
613 SETFALSE, // 0 0 0 0 Always false (always folded)
614 SETOEQ, // 0 0 0 1 True if ordered and equal
615 SETOGT, // 0 0 1 0 True if ordered and greater than
616 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
617 SETOLT, // 0 1 0 0 True if ordered and less than
618 SETOLE, // 0 1 0 1 True if ordered and less than or equal
619 SETONE, // 0 1 1 0 True if ordered and operands are unequal
620 SETO, // 0 1 1 1 True if ordered (no nans)
621 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
622 SETUEQ, // 1 0 0 1 True if unordered or equal
623 SETUGT, // 1 0 1 0 True if unordered or greater than
624 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
625 SETULT, // 1 1 0 0 True if unordered or less than
626 SETULE, // 1 1 0 1 True if unordered, less than, or equal
627 SETUNE, // 1 1 1 0 True if unordered or not equal
628 SETTRUE, // 1 1 1 1 Always true (always folded)
629 // Don't care operations: undefined if the input is a nan.
630 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
631 SETEQ, // 1 X 0 0 1 True if equal
632 SETGT, // 1 X 0 1 0 True if greater than
633 SETGE, // 1 X 0 1 1 True if greater than or equal
634 SETLT, // 1 X 1 0 0 True if less than
635 SETLE, // 1 X 1 0 1 True if less than or equal
636 SETNE, // 1 X 1 1 0 True if not equal
637 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
639 SETCC_INVALID // Marker value.
642 /// isSignedIntSetCC - Return true if this is a setcc instruction that
643 /// performs a signed comparison when used with integer operands.
644 inline bool isSignedIntSetCC(CondCode Code) {
645 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
648 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
649 /// performs an unsigned comparison when used with integer operands.
650 inline bool isUnsignedIntSetCC(CondCode Code) {
651 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
654 /// isTrueWhenEqual - Return true if the specified condition returns true if
655 /// the two operands to the condition are equal. Note that if one of the two
656 /// operands is a NaN, this value is meaningless.
657 inline bool isTrueWhenEqual(CondCode Cond) {
658 return ((int)Cond & 1) != 0;
661 /// getUnorderedFlavor - This function returns 0 if the condition is always
662 /// false if an operand is a NaN, 1 if the condition is always true if the
663 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
665 inline unsigned getUnorderedFlavor(CondCode Cond) {
666 return ((int)Cond >> 3) & 3;
669 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
670 /// 'op' is a valid SetCC operation.
671 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
673 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
674 /// when given the operation for (X op Y).
675 CondCode getSetCCSwappedOperands(CondCode Operation);
677 /// getSetCCOrOperation - Return the result of a logical OR between different
678 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
679 /// function returns SETCC_INVALID if it is not possible to represent the
680 /// resultant comparison.
681 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
683 /// getSetCCAndOperation - Return the result of a logical AND between
684 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
685 /// function returns SETCC_INVALID if it is not possible to represent the
686 /// resultant comparison.
687 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
688 } // end llvm::ISD namespace
691 //===----------------------------------------------------------------------===//
692 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
693 /// values as the result of a computation. Many nodes return multiple values,
694 /// from loads (which define a token and a return value) to ADDC (which returns
695 /// a result and a carry value), to calls (which may return an arbitrary number
698 /// As such, each use of a SelectionDAG computation must indicate the node that
699 /// computes it as well as which return value to use from that node. This pair
700 /// of information is represented with the SDOperand value type.
704 SDNode *Val; // The node defining the value we are using.
705 unsigned ResNo; // Which return value of the node we are using.
707 SDOperand() : Val(0), ResNo(0) {}
708 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
710 bool operator==(const SDOperand &O) const {
711 return Val == O.Val && ResNo == O.ResNo;
713 bool operator!=(const SDOperand &O) const {
714 return !operator==(O);
716 bool operator<(const SDOperand &O) const {
717 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
720 SDOperand getValue(unsigned R) const {
721 return SDOperand(Val, R);
724 // isOperand - Return true if this node is an operand of N.
725 bool isOperand(SDNode *N) const;
727 /// getValueType - Return the ValueType of the referenced return value.
729 inline MVT::ValueType getValueType() const;
731 // Forwarding methods - These forward to the corresponding methods in SDNode.
732 inline unsigned getOpcode() const;
733 inline unsigned getNumOperands() const;
734 inline const SDOperand &getOperand(unsigned i) const;
735 inline uint64_t getConstantOperandVal(unsigned i) const;
736 inline bool isTargetOpcode() const;
737 inline unsigned getTargetOpcode() const;
739 /// hasOneUse - Return true if there is exactly one operation using this
740 /// result value of the defining operator.
741 inline bool hasOneUse() const;
745 /// simplify_type specializations - Allow casting operators to work directly on
746 /// SDOperands as if they were SDNode*'s.
747 template<> struct simplify_type<SDOperand> {
748 typedef SDNode* SimpleType;
749 static SimpleType getSimplifiedValue(const SDOperand &Val) {
750 return static_cast<SimpleType>(Val.Val);
753 template<> struct simplify_type<const SDOperand> {
754 typedef SDNode* SimpleType;
755 static SimpleType getSimplifiedValue(const SDOperand &Val) {
756 return static_cast<SimpleType>(Val.Val);
761 /// SDNode - Represents one node in the SelectionDAG.
763 class SDNode : public FoldingSetNode {
764 /// NodeType - The operation that this node performs.
766 unsigned short NodeType;
768 /// NodeId - Unique id per SDNode in the DAG.
771 /// OperandList - The values that are used by this operation.
773 SDOperand *OperandList;
775 /// ValueList - The types of the values this node defines. SDNode's may
776 /// define multiple values simultaneously.
777 const MVT::ValueType *ValueList;
779 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
780 unsigned short NumOperands, NumValues;
782 /// Prev/Next pointers - These pointers form the linked list of of the
783 /// AllNodes list in the current DAG.
785 friend struct ilist_traits<SDNode>;
787 /// Uses - These are all of the SDNode's that use a value produced by this
789 SmallVector<SDNode*,3> Uses;
791 // Out-of-line virtual method to give class a home.
792 virtual void ANCHOR();
795 assert(NumOperands == 0 && "Operand list not cleared before deletion");
796 NodeType = ISD::DELETED_NODE;
799 //===--------------------------------------------------------------------===//
802 unsigned getOpcode() const { return NodeType; }
803 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
804 unsigned getTargetOpcode() const {
805 assert(isTargetOpcode() && "Not a target opcode!");
806 return NodeType - ISD::BUILTIN_OP_END;
809 size_t use_size() const { return Uses.size(); }
810 bool use_empty() const { return Uses.empty(); }
811 bool hasOneUse() const { return Uses.size() == 1; }
813 /// getNodeId - Return the unique node id.
815 int getNodeId() const { return NodeId; }
817 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
818 use_iterator use_begin() const { return Uses.begin(); }
819 use_iterator use_end() const { return Uses.end(); }
821 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
822 /// indicated value. This method ignores uses of other values defined by this
824 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
826 /// isOnlyUse - Return true if this node is the only use of N.
828 bool isOnlyUse(SDNode *N) const;
830 /// isOperand - Return true if this node is an operand of N.
832 bool isOperand(SDNode *N) const;
834 /// isPredecessor - Return true if this node is a predecessor of N. This node
835 /// is either an operand of N or it can be reached by recursively traversing
837 /// NOTE: this is an expensive method. Use it carefully.
838 bool isPredecessor(SDNode *N) const;
840 /// getNumOperands - Return the number of values used by this operation.
842 unsigned getNumOperands() const { return NumOperands; }
844 /// getConstantOperandVal - Helper method returns the integer value of a
845 /// ConstantSDNode operand.
846 uint64_t getConstantOperandVal(unsigned Num) const;
848 const SDOperand &getOperand(unsigned Num) const {
849 assert(Num < NumOperands && "Invalid child # of SDNode!");
850 return OperandList[Num];
853 typedef const SDOperand* op_iterator;
854 op_iterator op_begin() const { return OperandList; }
855 op_iterator op_end() const { return OperandList+NumOperands; }
858 SDVTList getVTList() const {
859 SDVTList X = { ValueList, NumValues };
863 /// getNumValues - Return the number of values defined/returned by this
866 unsigned getNumValues() const { return NumValues; }
868 /// getValueType - Return the type of a specified result.
870 MVT::ValueType getValueType(unsigned ResNo) const {
871 assert(ResNo < NumValues && "Illegal result number!");
872 return ValueList[ResNo];
875 typedef const MVT::ValueType* value_iterator;
876 value_iterator value_begin() const { return ValueList; }
877 value_iterator value_end() const { return ValueList+NumValues; }
879 /// getOperationName - Return the opcode of this operation for printing.
881 const char* getOperationName(const SelectionDAG *G = 0) const;
882 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
884 void dump(const SelectionDAG *G) const;
886 static bool classof(const SDNode *) { return true; }
888 /// Profile - Gather unique data for the node.
890 void Profile(FoldingSetNodeID &ID);
893 friend class SelectionDAG;
895 /// getValueTypeList - Return a pointer to the specified value type.
897 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
899 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeId(-1) {
900 OperandList = 0; NumOperands = 0;
901 ValueList = getValueTypeList(VT);
905 SDNode(unsigned NT, SDOperand Op)
906 : NodeType(NT), NodeId(-1) {
907 OperandList = new SDOperand[1];
910 Op.Val->Uses.push_back(this);
915 SDNode(unsigned NT, SDOperand N1, SDOperand N2)
916 : NodeType(NT), NodeId(-1) {
917 OperandList = new SDOperand[2];
921 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
926 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
927 : NodeType(NT), NodeId(-1) {
928 OperandList = new SDOperand[3];
934 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
935 N3.Val->Uses.push_back(this);
940 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4)
941 : NodeType(NT), NodeId(-1) {
942 OperandList = new SDOperand[4];
949 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
950 N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this);
955 SDNode(unsigned Opc, const SDOperand *Ops, unsigned NumOps)
956 : NodeType(Opc), NodeId(-1) {
957 NumOperands = NumOps;
958 OperandList = new SDOperand[NumOperands];
960 for (unsigned i = 0, e = NumOps; i != e; ++i) {
961 OperandList[i] = Ops[i];
962 SDNode *N = OperandList[i].Val;
963 N->Uses.push_back(this);
970 /// MorphNodeTo - This clears the return value and operands list, and sets the
971 /// opcode of the node to the specified value. This should only be used by
972 /// the SelectionDAG class.
973 void MorphNodeTo(unsigned Opc) {
978 // Clear the operands list, updating used nodes to remove this from their
980 for (op_iterator I = op_begin(), E = op_end(); I != E; ++I)
981 I->Val->removeUser(this);
982 delete [] OperandList;
987 void setValueTypes(SDVTList L) {
988 assert(NumValues == 0 && "Should not have values yet!");
990 NumValues = L.NumVTs;
993 void setOperands(SDOperand Op0) {
994 assert(NumOperands == 0 && "Should not have operands yet!");
995 OperandList = new SDOperand[1];
996 OperandList[0] = Op0;
998 Op0.Val->Uses.push_back(this);
1000 void setOperands(SDOperand Op0, SDOperand Op1) {
1001 assert(NumOperands == 0 && "Should not have operands yet!");
1002 OperandList = new SDOperand[2];
1003 OperandList[0] = Op0;
1004 OperandList[1] = Op1;
1006 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
1008 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) {
1009 assert(NumOperands == 0 && "Should not have operands yet!");
1010 OperandList = new SDOperand[3];
1011 OperandList[0] = Op0;
1012 OperandList[1] = Op1;
1013 OperandList[2] = Op2;
1015 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
1016 Op2.Val->Uses.push_back(this);
1018 void setOperands(const SDOperand *Ops, unsigned NumOps) {
1019 assert(NumOperands == 0 && "Should not have operands yet!");
1020 NumOperands = NumOps;
1021 OperandList = new SDOperand[NumOperands];
1023 for (unsigned i = 0, e = NumOps; i != e; ++i) {
1024 OperandList[i] = Ops[i];
1025 SDNode *N = OperandList[i].Val;
1026 N->Uses.push_back(this);
1030 void addUser(SDNode *User) {
1031 Uses.push_back(User);
1033 void removeUser(SDNode *User) {
1034 // Remove this user from the operand's use list.
1035 for (unsigned i = Uses.size(); ; --i) {
1036 assert(i != 0 && "Didn't find user!");
1037 if (Uses[i-1] == User) {
1038 Uses[i-1] = Uses.back();
1045 void setNodeId(int Id) {
1051 // Define inline functions from the SDOperand class.
1053 inline unsigned SDOperand::getOpcode() const {
1054 return Val->getOpcode();
1056 inline MVT::ValueType SDOperand::getValueType() const {
1057 return Val->getValueType(ResNo);
1059 inline unsigned SDOperand::getNumOperands() const {
1060 return Val->getNumOperands();
1062 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1063 return Val->getOperand(i);
1065 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1066 return Val->getConstantOperandVal(i);
1068 inline bool SDOperand::isTargetOpcode() const {
1069 return Val->isTargetOpcode();
1071 inline unsigned SDOperand::getTargetOpcode() const {
1072 return Val->getTargetOpcode();
1074 inline bool SDOperand::hasOneUse() const {
1075 return Val->hasNUsesOfValue(1, ResNo);
1078 /// HandleSDNode - This class is used to form a handle around another node that
1079 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1080 /// operand. This node should be directly created by end-users and not added to
1081 /// the AllNodes list.
1082 class HandleSDNode : public SDNode {
1084 HandleSDNode(SDOperand X) : SDNode(ISD::HANDLENODE, X) {}
1086 MorphNodeTo(ISD::HANDLENODE); // Drops operand uses.
1089 SDOperand getValue() const { return getOperand(0); }
1092 class StringSDNode : public SDNode {
1095 friend class SelectionDAG;
1096 StringSDNode(const std::string &val)
1097 : SDNode(ISD::STRING, MVT::Other), Value(val) {
1100 const std::string &getValue() const { return Value; }
1101 static bool classof(const StringSDNode *) { return true; }
1102 static bool classof(const SDNode *N) {
1103 return N->getOpcode() == ISD::STRING;
1107 class ConstantSDNode : public SDNode {
1110 friend class SelectionDAG;
1111 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1112 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, VT), Value(val) {
1116 uint64_t getValue() const { return Value; }
1118 int64_t getSignExtended() const {
1119 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1120 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1123 bool isNullValue() const { return Value == 0; }
1124 bool isAllOnesValue() const {
1125 return Value == MVT::getIntVTBitMask(getValueType(0));
1128 static bool classof(const ConstantSDNode *) { return true; }
1129 static bool classof(const SDNode *N) {
1130 return N->getOpcode() == ISD::Constant ||
1131 N->getOpcode() == ISD::TargetConstant;
1135 class ConstantFPSDNode : public SDNode {
1138 friend class SelectionDAG;
1139 ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1140 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, VT),
1145 double getValue() const { return Value; }
1147 /// isExactlyValue - We don't rely on operator== working on double values, as
1148 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1149 /// As such, this method can be used to do an exact bit-for-bit comparison of
1150 /// two floating point values.
1151 bool isExactlyValue(double V) const;
1153 static bool classof(const ConstantFPSDNode *) { return true; }
1154 static bool classof(const SDNode *N) {
1155 return N->getOpcode() == ISD::ConstantFP ||
1156 N->getOpcode() == ISD::TargetConstantFP;
1160 class GlobalAddressSDNode : public SDNode {
1161 GlobalValue *TheGlobal;
1164 friend class SelectionDAG;
1165 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1167 : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT),
1169 TheGlobal = const_cast<GlobalValue*>(GA);
1173 GlobalValue *getGlobal() const { return TheGlobal; }
1174 int getOffset() const { return Offset; }
1176 static bool classof(const GlobalAddressSDNode *) { return true; }
1177 static bool classof(const SDNode *N) {
1178 return N->getOpcode() == ISD::GlobalAddress ||
1179 N->getOpcode() == ISD::TargetGlobalAddress;
1184 class FrameIndexSDNode : public SDNode {
1187 friend class SelectionDAG;
1188 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1189 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, VT), FI(fi) {}
1192 int getIndex() const { return FI; }
1194 static bool classof(const FrameIndexSDNode *) { return true; }
1195 static bool classof(const SDNode *N) {
1196 return N->getOpcode() == ISD::FrameIndex ||
1197 N->getOpcode() == ISD::TargetFrameIndex;
1201 class JumpTableSDNode : public SDNode {
1204 friend class SelectionDAG;
1205 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1206 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, VT),
1210 int getIndex() const { return JTI; }
1212 static bool classof(const JumpTableSDNode *) { return true; }
1213 static bool classof(const SDNode *N) {
1214 return N->getOpcode() == ISD::JumpTable ||
1215 N->getOpcode() == ISD::TargetJumpTable;
1219 class ConstantPoolSDNode : public SDNode {
1222 MachineConstantPoolValue *MachineCPVal;
1224 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1227 friend class SelectionDAG;
1228 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1230 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
1231 Offset(o), Alignment(0) {
1232 assert((int)Offset >= 0 && "Offset is too large");
1235 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1237 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
1238 Offset(o), Alignment(Align) {
1239 assert((int)Offset >= 0 && "Offset is too large");
1242 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1243 MVT::ValueType VT, int o=0)
1244 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
1245 Offset(o), Alignment(0) {
1246 assert((int)Offset >= 0 && "Offset is too large");
1247 Val.MachineCPVal = v;
1248 Offset |= 1 << (sizeof(unsigned)*8-1);
1250 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1251 MVT::ValueType VT, int o, unsigned Align)
1252 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
1253 Offset(o), Alignment(Align) {
1254 assert((int)Offset >= 0 && "Offset is too large");
1255 Val.MachineCPVal = v;
1256 Offset |= 1 << (sizeof(unsigned)*8-1);
1260 bool isMachineConstantPoolEntry() const {
1261 return (int)Offset < 0;
1264 Constant *getConstVal() const {
1265 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1266 return Val.ConstVal;
1269 MachineConstantPoolValue *getMachineCPVal() const {
1270 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1271 return Val.MachineCPVal;
1274 int getOffset() const {
1275 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1278 // Return the alignment of this constant pool object, which is either 0 (for
1279 // default alignment) or log2 of the desired value.
1280 unsigned getAlignment() const { return Alignment; }
1282 const Type *getType() const;
1284 static bool classof(const ConstantPoolSDNode *) { return true; }
1285 static bool classof(const SDNode *N) {
1286 return N->getOpcode() == ISD::ConstantPool ||
1287 N->getOpcode() == ISD::TargetConstantPool;
1291 class BasicBlockSDNode : public SDNode {
1292 MachineBasicBlock *MBB;
1294 friend class SelectionDAG;
1295 BasicBlockSDNode(MachineBasicBlock *mbb)
1296 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
1299 MachineBasicBlock *getBasicBlock() const { return MBB; }
1301 static bool classof(const BasicBlockSDNode *) { return true; }
1302 static bool classof(const SDNode *N) {
1303 return N->getOpcode() == ISD::BasicBlock;
1307 class SrcValueSDNode : public SDNode {
1311 friend class SelectionDAG;
1312 SrcValueSDNode(const Value* v, int o)
1313 : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {}
1316 const Value *getValue() const { return V; }
1317 int getOffset() const { return offset; }
1319 static bool classof(const SrcValueSDNode *) { return true; }
1320 static bool classof(const SDNode *N) {
1321 return N->getOpcode() == ISD::SRCVALUE;
1326 class RegisterSDNode : public SDNode {
1329 friend class SelectionDAG;
1330 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1331 : SDNode(ISD::Register, VT), Reg(reg) {}
1334 unsigned getReg() const { return Reg; }
1336 static bool classof(const RegisterSDNode *) { return true; }
1337 static bool classof(const SDNode *N) {
1338 return N->getOpcode() == ISD::Register;
1342 class ExternalSymbolSDNode : public SDNode {
1345 friend class SelectionDAG;
1346 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1347 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, VT),
1352 const char *getSymbol() const { return Symbol; }
1354 static bool classof(const ExternalSymbolSDNode *) { return true; }
1355 static bool classof(const SDNode *N) {
1356 return N->getOpcode() == ISD::ExternalSymbol ||
1357 N->getOpcode() == ISD::TargetExternalSymbol;
1361 class CondCodeSDNode : public SDNode {
1362 ISD::CondCode Condition;
1364 friend class SelectionDAG;
1365 CondCodeSDNode(ISD::CondCode Cond)
1366 : SDNode(ISD::CONDCODE, MVT::Other), Condition(Cond) {
1370 ISD::CondCode get() const { return Condition; }
1372 static bool classof(const CondCodeSDNode *) { return true; }
1373 static bool classof(const SDNode *N) {
1374 return N->getOpcode() == ISD::CONDCODE;
1378 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1379 /// to parameterize some operations.
1380 class VTSDNode : public SDNode {
1381 MVT::ValueType ValueType;
1383 friend class SelectionDAG;
1384 VTSDNode(MVT::ValueType VT)
1385 : SDNode(ISD::VALUETYPE, MVT::Other), ValueType(VT) {}
1388 MVT::ValueType getVT() const { return ValueType; }
1390 static bool classof(const VTSDNode *) { return true; }
1391 static bool classof(const SDNode *N) {
1392 return N->getOpcode() == ISD::VALUETYPE;
1396 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1398 class LoadSDNode : public SDNode {
1399 // AddrMode - unindexed, pre-indexed, post-indexed.
1400 ISD::MemIndexedMode AddrMode;
1402 // ExtType - non-ext, anyext, sext, zext.
1403 ISD::LoadExtType ExtType;
1405 // LoadedVT - VT of loaded value before extension.
1406 MVT::ValueType LoadedVT;
1408 // SrcValue - Memory location for alias analysis.
1409 const Value *SrcValue;
1411 // SVOffset - Memory location offset.
1414 // Alignment - Alignment of memory location in bytes.
1417 // IsVolatile - True if the load is volatile.
1420 friend class SelectionDAG;
1421 LoadSDNode(SDOperand Chain, SDOperand Ptr, SDOperand Off,
1422 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1423 const Value *SV, int O=0, unsigned Align=1, bool Vol=false)
1424 : SDNode(ISD::LOAD, Chain, Ptr, Off),
1425 AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
1426 Alignment(Align), IsVolatile(Vol) {
1427 assert((Off.getOpcode() == ISD::UNDEF || AddrMode != ISD::UNINDEXED) &&
1428 "Only indexed load has a non-undef offset operand");
1432 const SDOperand getChain() const { return getOperand(0); }
1433 const SDOperand getBasePtr() const { return getOperand(1); }
1434 const SDOperand getOffset() const { return getOperand(2); }
1435 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1436 ISD::LoadExtType getExtensionType() const { return ExtType; }
1437 MVT::ValueType getLoadedVT() const { return LoadedVT; }
1438 const Value *getSrcValue() const { return SrcValue; }
1439 int getSrcValueOffset() const { return SVOffset; }
1440 unsigned getAlignment() const { return Alignment; }
1441 bool isVolatile() const { return IsVolatile; }
1443 static bool classof(const LoadSDNode *) { return true; }
1444 static bool classof(const SDNode *N) {
1445 return N->getOpcode() == ISD::LOAD;
1449 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1451 class StoreSDNode : public SDNode {
1452 // AddrMode - unindexed, pre-indexed, post-indexed.
1453 ISD::MemIndexedMode AddrMode;
1455 // IsTruncStore - True is the op does a truncation before store.
1458 // StoredVT - VT of the value after truncation.
1459 MVT::ValueType StoredVT;
1461 // SrcValue - Memory location for alias analysis.
1462 const Value *SrcValue;
1464 // SVOffset - Memory location offset.
1467 // Alignment - Alignment of memory location in bytes.
1470 // IsVolatile - True if the store is volatile.
1473 friend class SelectionDAG;
1474 StoreSDNode(SDOperand Chain, SDOperand Value, SDOperand Ptr, SDOperand Off,
1475 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1476 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1477 : SDNode(ISD::STORE, Chain, Value, Ptr, Off),
1478 AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT), SrcValue(SV),
1479 SVOffset(O), Alignment(Align), IsVolatile(Vol) {
1480 assert((Off.getOpcode() == ISD::UNDEF || AddrMode != ISD::UNINDEXED) &&
1481 "Only indexed store has a non-undef offset operand");
1485 const SDOperand getChain() const { return getOperand(0); }
1486 const SDOperand getValue() const { return getOperand(1); }
1487 const SDOperand getBasePtr() const { return getOperand(2); }
1488 const SDOperand getOffset() const { return getOperand(3); }
1489 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1490 bool isTruncatingStore() const { return IsTruncStore; }
1491 MVT::ValueType getStoredVT() const { return StoredVT; }
1492 const Value *getSrcValue() const { return SrcValue; }
1493 int getSrcValueOffset() const { return SVOffset; }
1494 unsigned getAlignment() const { return Alignment; }
1495 bool isVolatile() const { return IsVolatile; }
1497 static bool classof(const StoreSDNode *) { return true; }
1498 static bool classof(const SDNode *N) {
1499 return N->getOpcode() == ISD::STORE;
1504 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1508 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1510 bool operator==(const SDNodeIterator& x) const {
1511 return Operand == x.Operand;
1513 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1515 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1516 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1517 Operand = I.Operand;
1521 pointer operator*() const {
1522 return Node->getOperand(Operand).Val;
1524 pointer operator->() const { return operator*(); }
1526 SDNodeIterator& operator++() { // Preincrement
1530 SDNodeIterator operator++(int) { // Postincrement
1531 SDNodeIterator tmp = *this; ++*this; return tmp;
1534 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1535 static SDNodeIterator end (SDNode *N) {
1536 return SDNodeIterator(N, N->getNumOperands());
1539 unsigned getOperand() const { return Operand; }
1540 const SDNode *getNode() const { return Node; }
1543 template <> struct GraphTraits<SDNode*> {
1544 typedef SDNode NodeType;
1545 typedef SDNodeIterator ChildIteratorType;
1546 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1547 static inline ChildIteratorType child_begin(NodeType *N) {
1548 return SDNodeIterator::begin(N);
1550 static inline ChildIteratorType child_end(NodeType *N) {
1551 return SDNodeIterator::end(N);
1556 struct ilist_traits<SDNode> {
1557 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1558 static SDNode *getNext(const SDNode *N) { return N->Next; }
1560 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1561 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1563 static SDNode *createSentinel() {
1564 return new SDNode(ISD::EntryToken, MVT::Other);
1566 static void destroySentinel(SDNode *N) { delete N; }
1567 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1570 void addNodeToList(SDNode *NTy) {}
1571 void removeNodeFromList(SDNode *NTy) {}
1572 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1573 const ilist_iterator<SDNode> &X,
1574 const ilist_iterator<SDNode> &Y) {}
1578 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1580 inline bool isNON_EXTLoad(const SDNode *N) {
1581 return N->getOpcode() == ISD::LOAD &&
1582 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1585 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1587 inline bool isEXTLoad(const SDNode *N) {
1588 return N->getOpcode() == ISD::LOAD &&
1589 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1592 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1594 inline bool isSEXTLoad(const SDNode *N) {
1595 return N->getOpcode() == ISD::LOAD &&
1596 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1599 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1601 inline bool isZEXTLoad(const SDNode *N) {
1602 return N->getOpcode() == ISD::LOAD &&
1603 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1606 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1608 inline bool isNON_TRUNCStore(const SDNode *N) {
1609 return N->getOpcode() == ISD::STORE &&
1610 !cast<StoreSDNode>(N)->isTruncatingStore();
1613 /// isTRUNCStore - Returns true if the specified node is a truncating
1615 inline bool isTRUNCStore(const SDNode *N) {
1616 return N->getOpcode() == ISD::STORE &&
1617 cast<StoreSDNode>(N)->isTruncatingStore();
1622 } // end llvm namespace