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 ByVal = 1<<4, ///< Struct passed by value
68 OrigAlignment = 0x1F<<27,
69 OrigAlignmentOffs = 27
73 //===--------------------------------------------------------------------===//
74 /// ISD::NodeType enum - This enum defines all of the operators valid in a
78 // DELETED_NODE - This is an illegal flag value that is used to catch
79 // errors. This opcode is not a legal opcode for any node.
82 // EntryToken - This is the marker used to indicate the start of the region.
85 // Token factor - This node takes multiple tokens as input and produces a
86 // single token result. This is used to represent the fact that the operand
87 // operators are independent of each other.
90 // AssertSext, AssertZext - These nodes record if a register contains a
91 // value that has already been zero or sign extended from a narrower type.
92 // These nodes take two operands. The first is the node that has already
93 // been extended, and the second is a value type node indicating the width
95 AssertSext, AssertZext,
97 // Various leaf nodes.
98 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
100 GlobalAddress, GlobalTLSAddress, FrameIndex,
101 JumpTable, ConstantPool, ExternalSymbol,
103 // The address of the GOT
106 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
107 // llvm.returnaddress on the DAG. These nodes take one operand, the index
108 // of the frame or return address to return. An index of zero corresponds
109 // to the current function's frame or return address, an index of one to the
110 // parent's frame or return address, and so on.
111 FRAMEADDR, RETURNADDR,
113 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
114 // address of the exception block on entry to an landing pad block.
117 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
118 // the selection index of the exception thrown.
121 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
122 // simplification of the constant.
126 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
127 // anything else with this node, and this is valid in the target-specific
128 // dag, turning into a GlobalAddress operand.
130 TargetGlobalTLSAddress,
134 TargetExternalSymbol,
136 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
137 /// This node represents a target intrinsic function with no side effects.
138 /// The first operand is the ID number of the intrinsic from the
139 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
140 /// node has returns the result of the intrinsic.
143 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
144 /// This node represents a target intrinsic function with side effects that
145 /// returns a result. The first operand is a chain pointer. The second is
146 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
147 /// operands to the intrinsic follow. The node has two results, the result
148 /// of the intrinsic and an output chain.
151 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
152 /// This node represents a target intrinsic function with side effects that
153 /// does not return a result. The first operand is a chain pointer. The
154 /// second is the ID number of the intrinsic from the llvm::Intrinsic
155 /// namespace. The operands to the intrinsic follow.
158 // CopyToReg - This node has three operands: a chain, a register number to
159 // set to this value, and a value.
162 // CopyFromReg - This node indicates that the input value is a virtual or
163 // physical register that is defined outside of the scope of this
164 // SelectionDAG. The register is available from the RegSDNode object.
167 // UNDEF - An undefined node
170 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
171 /// represents the formal arguments for a function. CC# is a Constant value
172 /// indicating the calling convention of the function, and ISVARARG is a
173 /// flag that indicates whether the function is varargs or not. This node
174 /// has one result value for each incoming argument, plus one for the output
175 /// chain. It must be custom legalized. See description of CALL node for
176 /// FLAG argument contents explanation.
180 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
181 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
182 /// This node represents a fully general function call, before the legalizer
183 /// runs. This has one result value for each argument / flag pair, plus
184 /// a chain result. It must be custom legalized. Flag argument indicates
185 /// misc. argument attributes. Currently:
187 /// Bit 1 - 'inreg' attribute
188 /// Bit 2 - 'sret' attribute
189 /// Bits 31:27 - argument ABI alignment in the first argument piece and
190 /// alignment '1' in other argument pieces.
193 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
194 // a Constant, which is required to be operand #1), element of the aggregate
195 // value specified as operand #0. This is only for use before legalization,
196 // for values that will be broken into multiple registers.
199 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
200 // two values of the same integer value type, this produces a value twice as
201 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
204 // MERGE_VALUES - This node takes multiple discrete operands and returns
205 // them all as its individual results. This nodes has exactly the same
206 // number of inputs and outputs, and is only valid before legalization.
207 // This node is useful for some pieces of the code generator that want to
208 // think about a single node with multiple results, not multiple nodes.
211 // Simple integer binary arithmetic operators.
212 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
214 // CARRY_FALSE - This node is used when folding other nodes,
215 // like ADDC/SUBC, which indicate the carry result is always false.
218 // Carry-setting nodes for multiple precision addition and subtraction.
219 // These nodes take two operands of the same value type, and produce two
220 // results. The first result is the normal add or sub result, the second
221 // result is the carry flag result.
224 // Carry-using nodes for multiple precision addition and subtraction. These
225 // nodes take three operands: The first two are the normal lhs and rhs to
226 // the add or sub, and the third is the input carry flag. These nodes
227 // produce two results; the normal result of the add or sub, and the output
228 // carry flag. These nodes both read and write a carry flag to allow them
229 // to them to be chained together for add and sub of arbitrarily large
233 // Simple binary floating point operators.
234 FADD, FSUB, FMUL, FDIV, FREM,
236 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
237 // DAG node does not require that X and Y have the same type, just that they
238 // are both floating point. X and the result must have the same type.
239 // FCOPYSIGN(f32, f64) is allowed.
242 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
243 /// with the specified, possibly variable, elements. The number of elements
244 /// is required to be a power of two.
247 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
248 /// at IDX replaced with VAL.
251 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
252 /// identified by the (potentially variable) element number IDX.
255 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
256 /// vector type with the same length and element type, this produces a
257 /// concatenated vector result value, with length equal to the sum of the
258 /// lengths of the input vectors.
261 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
262 /// vector value) starting with the (potentially variable) element number
263 /// IDX, which must be a multiple of the result vector length.
266 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
267 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
268 /// (regardless of whether its datatype is legal or not) that indicate
269 /// which value each result element will get. The elements of VEC1/VEC2 are
270 /// enumerated in order. This is quite similar to the Altivec 'vperm'
271 /// instruction, except that the indices must be constants and are in terms
272 /// of the element size of VEC1/VEC2, not in terms of bytes.
275 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
276 /// scalar value into the low element of the resultant vector type. The top
277 /// elements of the vector are undefined.
280 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
281 // an unsigned/signed value of type i[2*n], then return the top part.
284 // Bitwise operators - logical and, logical or, logical xor, shift left,
285 // shift right algebraic (shift in sign bits), shift right logical (shift in
286 // zeroes), rotate left, rotate right, and byteswap.
287 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
289 // Counting operators
292 // Select(COND, TRUEVAL, FALSEVAL)
295 // Select with condition operator - This selects between a true value and
296 // a false value (ops #2 and #3) based on the boolean result of comparing
297 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
298 // condition code in op #4, a CondCodeSDNode.
301 // SetCC operator - This evaluates to a boolean (i1) true value if the
302 // condition is true. The operands to this are the left and right operands
303 // to compare (ops #0, and #1) and the condition code to compare them with
304 // (op #2) as a CondCodeSDNode.
307 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
308 // integer shift operations, just like ADD/SUB_PARTS. The operation
310 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
311 SHL_PARTS, SRA_PARTS, SRL_PARTS,
313 // Conversion operators. These are all single input single output
314 // operations. For all of these, the result type must be strictly
315 // wider or narrower (depending on the operation) than the source
318 // SIGN_EXTEND - Used for integer types, replicating the sign bit
322 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
325 // ANY_EXTEND - Used for integer types. The high bits are undefined.
328 // TRUNCATE - Completely drop the high bits.
331 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
332 // depends on the first letter) to floating point.
336 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
337 // sign extend a small value in a large integer register (e.g. sign
338 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
339 // with the 7th bit). The size of the smaller type is indicated by the 1th
340 // operand, a ValueType node.
343 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
348 // FP_ROUND - Perform a rounding operation from the current
349 // precision down to the specified precision (currently always 64->32).
352 // FP_ROUND_INREG - This operator takes a floating point register, and
353 // rounds it to a floating point value. It then promotes it and returns it
354 // in a register of the same size. This operation effectively just discards
355 // excess precision. The type to round down to is specified by the 1th
356 // operation, a VTSDNode (currently always 64->32->64).
359 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
362 // BIT_CONVERT - Theis operator converts between integer and FP values, as
363 // if one was stored to memory as integer and the other was loaded from the
364 // same address (or equivalently for vector format conversions, etc). The
365 // source and result are required to have the same bit size (e.g.
366 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
367 // conversions, but that is a noop, deleted by getNode().
370 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI - Perform unary floating point
371 // negation, absolute value, square root, sine and cosine, and powi
373 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI,
375 // LOAD and STORE have token chains as their first operand, then the same
376 // operands as an LLVM load/store instruction, then an offset node that
377 // is added / subtracted from the base pointer to form the address (for
378 // indexed memory ops).
381 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
382 // value and stores it to memory in one operation. This can be used for
383 // either integer or floating point operands. The first four operands of
384 // this are the same as a standard store. The fifth is the ValueType to
385 // store it as (which will be smaller than the source value).
388 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
389 // to a specified boundary. This node always has two return values: a new
390 // stack pointer value and a chain. The first operand is the token chain,
391 // the second is the number of bytes to allocate, and the third is the
392 // alignment boundary. The size is guaranteed to be a multiple of the stack
393 // alignment, and the alignment is guaranteed to be bigger than the stack
394 // alignment (if required) or 0 to get standard stack alignment.
397 // Control flow instructions. These all have token chains.
399 // BR - Unconditional branch. The first operand is the chain
400 // operand, the second is the MBB to branch to.
403 // BRIND - Indirect branch. The first operand is the chain, the second
404 // is the value to branch to, which must be of the same type as the target's
408 // BR_JT - Jumptable branch. The first operand is the chain, the second
409 // is the jumptable index, the last one is the jumptable entry index.
412 // BRCOND - Conditional branch. The first operand is the chain,
413 // the second is the condition, the third is the block to branch
414 // to if the condition is true.
417 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
418 // that the condition is represented as condition code, and two nodes to
419 // compare, rather than as a combined SetCC node. The operands in order are
420 // chain, cc, lhs, rhs, block to branch to if condition is true.
423 // RET - Return from function. The first operand is the chain,
424 // and any subsequent operands are pairs of return value and return value
425 // signness for the function. This operation can have variable number of
429 // INLINEASM - Represents an inline asm block. This node always has two
430 // return values: a chain and a flag result. The inputs are as follows:
431 // Operand #0 : Input chain.
432 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
433 // Operand #2n+2: A RegisterNode.
434 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
435 // Operand #last: Optional, an incoming flag.
438 // LABEL - Represents a label in mid basic block used to track
439 // locations needed for debug and exception handling tables. This node
441 // Operand #0 : input chain.
442 // Operand #1 : module unique number use to identify the label.
445 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
446 // value, the same type as the pointer type for the system, and an output
450 // STACKRESTORE has two operands, an input chain and a pointer to restore to
451 // it returns an output chain.
454 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
455 // correspond to the operands of the LLVM intrinsic functions. The only
456 // result is a token chain. The alignment argument is guaranteed to be a
462 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
463 // a call sequence, and carry arbitrary information that target might want
464 // to know. The first operand is a chain, the rest are specified by the
465 // target and not touched by the DAG optimizers.
466 CALLSEQ_START, // Beginning of a call sequence
467 CALLSEQ_END, // End of a call sequence
469 // VAARG - VAARG has three operands: an input chain, a pointer, and a
470 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
473 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
474 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
478 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
479 // pointer, and a SRCVALUE.
482 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
483 // locations with their value. This allows one use alias analysis
484 // information in the backend.
487 // PCMARKER - This corresponds to the pcmarker intrinsic.
490 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
491 // The only operand is a chain and a value and a chain are produced. The
492 // value is the contents of the architecture specific cycle counter like
493 // register (or other high accuracy low latency clock source)
496 // HANDLENODE node - Used as a handle for various purposes.
499 // LOCATION - This node is used to represent a source location for debug
500 // info. It takes token chain as input, then a line number, then a column
501 // number, then a filename, then a working dir. It produces a token chain
505 // DEBUG_LOC - This node is used to represent source line information
506 // embedded in the code. It takes a token chain as input, then a line
507 // number, then a column then a file id (provided by MachineModuleInfo.) It
508 // produces a token chain as output.
511 // BUILTIN_OP_END - This must be the last enum value in this list.
517 /// isBuildVectorAllOnes - Return true if the specified node is a
518 /// BUILD_VECTOR where all of the elements are ~0 or undef.
519 bool isBuildVectorAllOnes(const SDNode *N);
521 /// isBuildVectorAllZeros - Return true if the specified node is a
522 /// BUILD_VECTOR where all of the elements are 0 or undef.
523 bool isBuildVectorAllZeros(const SDNode *N);
525 //===--------------------------------------------------------------------===//
526 /// MemIndexedMode enum - This enum defines the load / store indexed
527 /// addressing modes.
529 /// UNINDEXED "Normal" load / store. The effective address is already
530 /// computed and is available in the base pointer. The offset
531 /// operand is always undefined. In addition to producing a
532 /// chain, an unindexed load produces one value (result of the
533 /// load); an unindexed store does not produces a value.
535 /// PRE_INC Similar to the unindexed mode where the effective address is
536 /// PRE_DEC the value of the base pointer add / subtract the offset.
537 /// It considers the computation as being folded into the load /
538 /// store operation (i.e. the load / store does the address
539 /// computation as well as performing the memory transaction).
540 /// The base operand is always undefined. In addition to
541 /// producing a chain, pre-indexed load produces two values
542 /// (result of the load and the result of the address
543 /// computation); a pre-indexed store produces one value (result
544 /// of the address computation).
546 /// POST_INC The effective address is the value of the base pointer. The
547 /// POST_DEC value of the offset operand is then added to / subtracted
548 /// from the base after memory transaction. In addition to
549 /// producing a chain, post-indexed load produces two values
550 /// (the result of the load and the result of the base +/- offset
551 /// computation); a post-indexed store produces one value (the
552 /// the result of the base +/- offset computation).
554 enum MemIndexedMode {
563 //===--------------------------------------------------------------------===//
564 /// LoadExtType enum - This enum defines the three variants of LOADEXT
565 /// (load with extension).
567 /// SEXTLOAD loads the integer operand and sign extends it to a larger
568 /// integer result type.
569 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
570 /// integer result type.
571 /// EXTLOAD is used for three things: floating point extending loads,
572 /// integer extending loads [the top bits are undefined], and vector
573 /// extending loads [load into low elt].
583 //===--------------------------------------------------------------------===//
584 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
585 /// below work out, when considering SETFALSE (something that never exists
586 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
587 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
588 /// to. If the "N" column is 1, the result of the comparison is undefined if
589 /// the input is a NAN.
591 /// All of these (except for the 'always folded ops') should be handled for
592 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
593 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
595 /// Note that these are laid out in a specific order to allow bit-twiddling
596 /// to transform conditions.
598 // Opcode N U L G E Intuitive operation
599 SETFALSE, // 0 0 0 0 Always false (always folded)
600 SETOEQ, // 0 0 0 1 True if ordered and equal
601 SETOGT, // 0 0 1 0 True if ordered and greater than
602 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
603 SETOLT, // 0 1 0 0 True if ordered and less than
604 SETOLE, // 0 1 0 1 True if ordered and less than or equal
605 SETONE, // 0 1 1 0 True if ordered and operands are unequal
606 SETO, // 0 1 1 1 True if ordered (no nans)
607 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
608 SETUEQ, // 1 0 0 1 True if unordered or equal
609 SETUGT, // 1 0 1 0 True if unordered or greater than
610 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
611 SETULT, // 1 1 0 0 True if unordered or less than
612 SETULE, // 1 1 0 1 True if unordered, less than, or equal
613 SETUNE, // 1 1 1 0 True if unordered or not equal
614 SETTRUE, // 1 1 1 1 Always true (always folded)
615 // Don't care operations: undefined if the input is a nan.
616 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
617 SETEQ, // 1 X 0 0 1 True if equal
618 SETGT, // 1 X 0 1 0 True if greater than
619 SETGE, // 1 X 0 1 1 True if greater than or equal
620 SETLT, // 1 X 1 0 0 True if less than
621 SETLE, // 1 X 1 0 1 True if less than or equal
622 SETNE, // 1 X 1 1 0 True if not equal
623 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
625 SETCC_INVALID // Marker value.
628 /// isSignedIntSetCC - Return true if this is a setcc instruction that
629 /// performs a signed comparison when used with integer operands.
630 inline bool isSignedIntSetCC(CondCode Code) {
631 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
634 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
635 /// performs an unsigned comparison when used with integer operands.
636 inline bool isUnsignedIntSetCC(CondCode Code) {
637 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
640 /// isTrueWhenEqual - Return true if the specified condition returns true if
641 /// the two operands to the condition are equal. Note that if one of the two
642 /// operands is a NaN, this value is meaningless.
643 inline bool isTrueWhenEqual(CondCode Cond) {
644 return ((int)Cond & 1) != 0;
647 /// getUnorderedFlavor - This function returns 0 if the condition is always
648 /// false if an operand is a NaN, 1 if the condition is always true if the
649 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
651 inline unsigned getUnorderedFlavor(CondCode Cond) {
652 return ((int)Cond >> 3) & 3;
655 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
656 /// 'op' is a valid SetCC operation.
657 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
659 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
660 /// when given the operation for (X op Y).
661 CondCode getSetCCSwappedOperands(CondCode Operation);
663 /// getSetCCOrOperation - Return the result of a logical OR between different
664 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
665 /// function returns SETCC_INVALID if it is not possible to represent the
666 /// resultant comparison.
667 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
669 /// getSetCCAndOperation - Return the result of a logical AND between
670 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
671 /// function returns SETCC_INVALID if it is not possible to represent the
672 /// resultant comparison.
673 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
674 } // end llvm::ISD namespace
677 //===----------------------------------------------------------------------===//
678 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
679 /// values as the result of a computation. Many nodes return multiple values,
680 /// from loads (which define a token and a return value) to ADDC (which returns
681 /// a result and a carry value), to calls (which may return an arbitrary number
684 /// As such, each use of a SelectionDAG computation must indicate the node that
685 /// computes it as well as which return value to use from that node. This pair
686 /// of information is represented with the SDOperand value type.
690 SDNode *Val; // The node defining the value we are using.
691 unsigned ResNo; // Which return value of the node we are using.
693 SDOperand() : Val(0), ResNo(0) {}
694 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
696 bool operator==(const SDOperand &O) const {
697 return Val == O.Val && ResNo == O.ResNo;
699 bool operator!=(const SDOperand &O) const {
700 return !operator==(O);
702 bool operator<(const SDOperand &O) const {
703 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
706 SDOperand getValue(unsigned R) const {
707 return SDOperand(Val, R);
710 // isOperand - Return true if this node is an operand of N.
711 bool isOperand(SDNode *N) const;
713 /// getValueType - Return the ValueType of the referenced return value.
715 inline MVT::ValueType getValueType() const;
717 // Forwarding methods - These forward to the corresponding methods in SDNode.
718 inline unsigned getOpcode() const;
719 inline unsigned getNumOperands() const;
720 inline const SDOperand &getOperand(unsigned i) const;
721 inline uint64_t getConstantOperandVal(unsigned i) const;
722 inline bool isTargetOpcode() const;
723 inline unsigned getTargetOpcode() const;
725 /// hasOneUse - Return true if there is exactly one operation using this
726 /// result value of the defining operator.
727 inline bool hasOneUse() const;
731 /// simplify_type specializations - Allow casting operators to work directly on
732 /// SDOperands as if they were SDNode*'s.
733 template<> struct simplify_type<SDOperand> {
734 typedef SDNode* SimpleType;
735 static SimpleType getSimplifiedValue(const SDOperand &Val) {
736 return static_cast<SimpleType>(Val.Val);
739 template<> struct simplify_type<const SDOperand> {
740 typedef SDNode* SimpleType;
741 static SimpleType getSimplifiedValue(const SDOperand &Val) {
742 return static_cast<SimpleType>(Val.Val);
747 /// SDNode - Represents one node in the SelectionDAG.
749 class SDNode : public FoldingSetNode {
750 /// NodeType - The operation that this node performs.
752 unsigned short NodeType;
754 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
755 /// then they will be delete[]'d when the node is destroyed.
756 bool OperandsNeedDelete : 1;
758 /// NodeId - Unique id per SDNode in the DAG.
761 /// OperandList - The values that are used by this operation.
763 SDOperand *OperandList;
765 /// ValueList - The types of the values this node defines. SDNode's may
766 /// define multiple values simultaneously.
767 const MVT::ValueType *ValueList;
769 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
770 unsigned short NumOperands, NumValues;
772 /// Prev/Next pointers - These pointers form the linked list of of the
773 /// AllNodes list in the current DAG.
775 friend struct ilist_traits<SDNode>;
777 /// Uses - These are all of the SDNode's that use a value produced by this
779 SmallVector<SDNode*,3> Uses;
781 // Out-of-line virtual method to give class a home.
782 virtual void ANCHOR();
785 assert(NumOperands == 0 && "Operand list not cleared before deletion");
786 NodeType = ISD::DELETED_NODE;
789 //===--------------------------------------------------------------------===//
792 unsigned getOpcode() const { return NodeType; }
793 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
794 unsigned getTargetOpcode() const {
795 assert(isTargetOpcode() && "Not a target opcode!");
796 return NodeType - ISD::BUILTIN_OP_END;
799 size_t use_size() const { return Uses.size(); }
800 bool use_empty() const { return Uses.empty(); }
801 bool hasOneUse() const { return Uses.size() == 1; }
803 /// getNodeId - Return the unique node id.
805 int getNodeId() const { return NodeId; }
807 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
808 use_iterator use_begin() const { return Uses.begin(); }
809 use_iterator use_end() const { return Uses.end(); }
811 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
812 /// indicated value. This method ignores uses of other values defined by this
814 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
816 /// isOnlyUse - Return true if this node is the only use of N.
818 bool isOnlyUse(SDNode *N) const;
820 /// isOperand - Return true if this node is an operand of N.
822 bool isOperand(SDNode *N) const;
824 /// isPredecessor - Return true if this node is a predecessor of N. This node
825 /// is either an operand of N or it can be reached by recursively traversing
827 /// NOTE: this is an expensive method. Use it carefully.
828 bool isPredecessor(SDNode *N) const;
830 /// getNumOperands - Return the number of values used by this operation.
832 unsigned getNumOperands() const { return NumOperands; }
834 /// getConstantOperandVal - Helper method returns the integer value of a
835 /// ConstantSDNode operand.
836 uint64_t getConstantOperandVal(unsigned Num) const;
838 const SDOperand &getOperand(unsigned Num) const {
839 assert(Num < NumOperands && "Invalid child # of SDNode!");
840 return OperandList[Num];
843 typedef const SDOperand* op_iterator;
844 op_iterator op_begin() const { return OperandList; }
845 op_iterator op_end() const { return OperandList+NumOperands; }
848 SDVTList getVTList() const {
849 SDVTList X = { ValueList, NumValues };
853 /// getNumValues - Return the number of values defined/returned by this
856 unsigned getNumValues() const { return NumValues; }
858 /// getValueType - Return the type of a specified result.
860 MVT::ValueType getValueType(unsigned ResNo) const {
861 assert(ResNo < NumValues && "Illegal result number!");
862 return ValueList[ResNo];
865 typedef const MVT::ValueType* value_iterator;
866 value_iterator value_begin() const { return ValueList; }
867 value_iterator value_end() const { return ValueList+NumValues; }
869 /// getOperationName - Return the opcode of this operation for printing.
871 std::string getOperationName(const SelectionDAG *G = 0) const;
872 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
874 void dump(const SelectionDAG *G) const;
876 static bool classof(const SDNode *) { return true; }
878 /// Profile - Gather unique data for the node.
880 void Profile(FoldingSetNodeID &ID);
883 friend class SelectionDAG;
885 /// getValueTypeList - Return a pointer to the specified value type.
887 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
888 static SDVTList getSDVTList(MVT::ValueType VT) {
889 SDVTList Ret = { getValueTypeList(VT), 1 };
893 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
894 : NodeType(Opc), NodeId(-1) {
895 OperandsNeedDelete = true;
896 NumOperands = NumOps;
897 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
899 for (unsigned i = 0; i != NumOps; ++i) {
900 OperandList[i] = Ops[i];
901 Ops[i].Val->Uses.push_back(this);
905 NumValues = VTs.NumVTs;
908 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
909 OperandsNeedDelete = false; // Operands set with InitOperands.
914 NumValues = VTs.NumVTs;
918 /// InitOperands - Initialize the operands list of this node with the
919 /// specified values, which are part of the node (thus they don't need to be
920 /// copied in or allocated).
921 void InitOperands(SDOperand *Ops, unsigned NumOps) {
922 assert(OperandList == 0 && "Operands already set!");
923 NumOperands = NumOps;
926 for (unsigned i = 0; i != NumOps; ++i)
927 Ops[i].Val->Uses.push_back(this);
930 /// MorphNodeTo - This frees the operands of the current node, resets the
931 /// opcode, types, and operands to the specified value. This should only be
932 /// used by the SelectionDAG class.
933 void MorphNodeTo(unsigned Opc, SDVTList L,
934 const SDOperand *Ops, unsigned NumOps);
936 void addUser(SDNode *User) {
937 Uses.push_back(User);
939 void removeUser(SDNode *User) {
940 // Remove this user from the operand's use list.
941 for (unsigned i = Uses.size(); ; --i) {
942 assert(i != 0 && "Didn't find user!");
943 if (Uses[i-1] == User) {
944 Uses[i-1] = Uses.back();
951 void setNodeId(int Id) {
957 // Define inline functions from the SDOperand class.
959 inline unsigned SDOperand::getOpcode() const {
960 return Val->getOpcode();
962 inline MVT::ValueType SDOperand::getValueType() const {
963 return Val->getValueType(ResNo);
965 inline unsigned SDOperand::getNumOperands() const {
966 return Val->getNumOperands();
968 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
969 return Val->getOperand(i);
971 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
972 return Val->getConstantOperandVal(i);
974 inline bool SDOperand::isTargetOpcode() const {
975 return Val->isTargetOpcode();
977 inline unsigned SDOperand::getTargetOpcode() const {
978 return Val->getTargetOpcode();
980 inline bool SDOperand::hasOneUse() const {
981 return Val->hasNUsesOfValue(1, ResNo);
984 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
985 /// to allow co-allocation of node operands with the node itself.
986 class UnarySDNode : public SDNode {
987 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
990 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
991 : SDNode(Opc, VTs), Op(X) {
992 InitOperands(&Op, 1);
996 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
997 /// to allow co-allocation of node operands with the node itself.
998 class BinarySDNode : public SDNode {
999 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1002 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1003 : SDNode(Opc, VTs) {
1006 InitOperands(Ops, 2);
1010 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1011 /// to allow co-allocation of node operands with the node itself.
1012 class TernarySDNode : public SDNode {
1013 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1016 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1018 : SDNode(Opc, VTs) {
1022 InitOperands(Ops, 3);
1027 /// HandleSDNode - This class is used to form a handle around another node that
1028 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1029 /// operand. This node should be directly created by end-users and not added to
1030 /// the AllNodes list.
1031 class HandleSDNode : public SDNode {
1032 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1035 explicit HandleSDNode(SDOperand X)
1036 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1037 InitOperands(&Op, 1);
1040 SDOperand getValue() const { return Op; }
1043 class StringSDNode : public SDNode {
1045 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1047 friend class SelectionDAG;
1048 explicit StringSDNode(const std::string &val)
1049 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1052 const std::string &getValue() const { return Value; }
1053 static bool classof(const StringSDNode *) { return true; }
1054 static bool classof(const SDNode *N) {
1055 return N->getOpcode() == ISD::STRING;
1059 class ConstantSDNode : public SDNode {
1061 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1063 friend class SelectionDAG;
1064 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1065 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1070 uint64_t getValue() const { return Value; }
1072 int64_t getSignExtended() const {
1073 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1074 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1077 bool isNullValue() const { return Value == 0; }
1078 bool isAllOnesValue() const {
1079 return Value == MVT::getIntVTBitMask(getValueType(0));
1082 static bool classof(const ConstantSDNode *) { return true; }
1083 static bool classof(const SDNode *N) {
1084 return N->getOpcode() == ISD::Constant ||
1085 N->getOpcode() == ISD::TargetConstant;
1089 class ConstantFPSDNode : public SDNode {
1091 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1093 friend class SelectionDAG;
1094 ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1095 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1096 getSDVTList(VT)), Value(val) {
1100 double getValue() const { return Value; }
1102 /// isExactlyValue - We don't rely on operator== working on double values, as
1103 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1104 /// As such, this method can be used to do an exact bit-for-bit comparison of
1105 /// two floating point values.
1106 bool isExactlyValue(double V) const;
1108 static bool classof(const ConstantFPSDNode *) { return true; }
1109 static bool classof(const SDNode *N) {
1110 return N->getOpcode() == ISD::ConstantFP ||
1111 N->getOpcode() == ISD::TargetConstantFP;
1115 class GlobalAddressSDNode : public SDNode {
1116 GlobalValue *TheGlobal;
1118 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1120 friend class SelectionDAG;
1121 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1125 GlobalValue *getGlobal() const { return TheGlobal; }
1126 int getOffset() const { return Offset; }
1128 static bool classof(const GlobalAddressSDNode *) { return true; }
1129 static bool classof(const SDNode *N) {
1130 return N->getOpcode() == ISD::GlobalAddress ||
1131 N->getOpcode() == ISD::TargetGlobalAddress ||
1132 N->getOpcode() == ISD::GlobalTLSAddress ||
1133 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1137 class FrameIndexSDNode : public SDNode {
1139 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1141 friend class SelectionDAG;
1142 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1143 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1148 int getIndex() const { return FI; }
1150 static bool classof(const FrameIndexSDNode *) { return true; }
1151 static bool classof(const SDNode *N) {
1152 return N->getOpcode() == ISD::FrameIndex ||
1153 N->getOpcode() == ISD::TargetFrameIndex;
1157 class JumpTableSDNode : public SDNode {
1159 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1161 friend class SelectionDAG;
1162 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1163 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1168 int getIndex() const { return JTI; }
1170 static bool classof(const JumpTableSDNode *) { return true; }
1171 static bool classof(const SDNode *N) {
1172 return N->getOpcode() == ISD::JumpTable ||
1173 N->getOpcode() == ISD::TargetJumpTable;
1177 class ConstantPoolSDNode : public SDNode {
1180 MachineConstantPoolValue *MachineCPVal;
1182 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1184 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1186 friend class SelectionDAG;
1187 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1189 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1190 getSDVTList(VT)), Offset(o), Alignment(0) {
1191 assert((int)Offset >= 0 && "Offset is too large");
1194 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1196 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1197 getSDVTList(VT)), Offset(o), Alignment(Align) {
1198 assert((int)Offset >= 0 && "Offset is too large");
1201 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1202 MVT::ValueType VT, int o=0)
1203 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1204 getSDVTList(VT)), Offset(o), Alignment(0) {
1205 assert((int)Offset >= 0 && "Offset is too large");
1206 Val.MachineCPVal = v;
1207 Offset |= 1 << (sizeof(unsigned)*8-1);
1209 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1210 MVT::ValueType VT, int o, unsigned Align)
1211 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1212 getSDVTList(VT)), Offset(o), Alignment(Align) {
1213 assert((int)Offset >= 0 && "Offset is too large");
1214 Val.MachineCPVal = v;
1215 Offset |= 1 << (sizeof(unsigned)*8-1);
1219 bool isMachineConstantPoolEntry() const {
1220 return (int)Offset < 0;
1223 Constant *getConstVal() const {
1224 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1225 return Val.ConstVal;
1228 MachineConstantPoolValue *getMachineCPVal() const {
1229 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1230 return Val.MachineCPVal;
1233 int getOffset() const {
1234 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1237 // Return the alignment of this constant pool object, which is either 0 (for
1238 // default alignment) or log2 of the desired value.
1239 unsigned getAlignment() const { return Alignment; }
1241 const Type *getType() const;
1243 static bool classof(const ConstantPoolSDNode *) { return true; }
1244 static bool classof(const SDNode *N) {
1245 return N->getOpcode() == ISD::ConstantPool ||
1246 N->getOpcode() == ISD::TargetConstantPool;
1250 class BasicBlockSDNode : public SDNode {
1251 MachineBasicBlock *MBB;
1252 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1254 friend class SelectionDAG;
1255 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1256 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1260 MachineBasicBlock *getBasicBlock() const { return MBB; }
1262 static bool classof(const BasicBlockSDNode *) { return true; }
1263 static bool classof(const SDNode *N) {
1264 return N->getOpcode() == ISD::BasicBlock;
1268 class SrcValueSDNode : public SDNode {
1271 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1273 friend class SelectionDAG;
1274 SrcValueSDNode(const Value* v, int o)
1275 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v), offset(o) {
1279 const Value *getValue() const { return V; }
1280 int getOffset() const { return offset; }
1282 static bool classof(const SrcValueSDNode *) { return true; }
1283 static bool classof(const SDNode *N) {
1284 return N->getOpcode() == ISD::SRCVALUE;
1289 class RegisterSDNode : public SDNode {
1291 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1293 friend class SelectionDAG;
1294 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1295 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1299 unsigned getReg() const { return Reg; }
1301 static bool classof(const RegisterSDNode *) { return true; }
1302 static bool classof(const SDNode *N) {
1303 return N->getOpcode() == ISD::Register;
1307 class ExternalSymbolSDNode : public SDNode {
1309 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1311 friend class SelectionDAG;
1312 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1313 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1314 getSDVTList(VT)), Symbol(Sym) {
1318 const char *getSymbol() const { return Symbol; }
1320 static bool classof(const ExternalSymbolSDNode *) { return true; }
1321 static bool classof(const SDNode *N) {
1322 return N->getOpcode() == ISD::ExternalSymbol ||
1323 N->getOpcode() == ISD::TargetExternalSymbol;
1327 class CondCodeSDNode : public SDNode {
1328 ISD::CondCode Condition;
1329 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1331 friend class SelectionDAG;
1332 explicit CondCodeSDNode(ISD::CondCode Cond)
1333 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1337 ISD::CondCode get() const { return Condition; }
1339 static bool classof(const CondCodeSDNode *) { return true; }
1340 static bool classof(const SDNode *N) {
1341 return N->getOpcode() == ISD::CONDCODE;
1345 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1346 /// to parameterize some operations.
1347 class VTSDNode : public SDNode {
1348 MVT::ValueType ValueType;
1349 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1351 friend class SelectionDAG;
1352 explicit VTSDNode(MVT::ValueType VT)
1353 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1357 MVT::ValueType getVT() const { return ValueType; }
1359 static bool classof(const VTSDNode *) { return true; }
1360 static bool classof(const SDNode *N) {
1361 return N->getOpcode() == ISD::VALUETYPE;
1365 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1367 class LoadSDNode : public SDNode {
1368 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1371 // AddrMode - unindexed, pre-indexed, post-indexed.
1372 ISD::MemIndexedMode AddrMode;
1374 // ExtType - non-ext, anyext, sext, zext.
1375 ISD::LoadExtType ExtType;
1377 // LoadedVT - VT of loaded value before extension.
1378 MVT::ValueType LoadedVT;
1380 // SrcValue - Memory location for alias analysis.
1381 const Value *SrcValue;
1383 // SVOffset - Memory location offset.
1386 // Alignment - Alignment of memory location in bytes.
1389 // IsVolatile - True if the load is volatile.
1392 friend class SelectionDAG;
1393 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1394 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1395 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1396 : SDNode(ISD::LOAD, VTs),
1397 AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
1398 Alignment(Align), IsVolatile(Vol) {
1399 Ops[0] = ChainPtrOff[0]; // Chain
1400 Ops[1] = ChainPtrOff[1]; // Ptr
1401 Ops[2] = ChainPtrOff[2]; // Off
1402 InitOperands(Ops, 3);
1403 assert(Align != 0 && "Loads should have non-zero aligment");
1404 assert((getOffset().getOpcode() == ISD::UNDEF ||
1405 AddrMode != ISD::UNINDEXED) &&
1406 "Only indexed load has a non-undef offset operand");
1410 const SDOperand getChain() const { return getOperand(0); }
1411 const SDOperand getBasePtr() const { return getOperand(1); }
1412 const SDOperand getOffset() const { return getOperand(2); }
1413 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1414 ISD::LoadExtType getExtensionType() const { return ExtType; }
1415 MVT::ValueType getLoadedVT() const { return LoadedVT; }
1416 const Value *getSrcValue() const { return SrcValue; }
1417 int getSrcValueOffset() const { return SVOffset; }
1418 unsigned getAlignment() const { return Alignment; }
1419 bool isVolatile() const { return IsVolatile; }
1421 static bool classof(const LoadSDNode *) { return true; }
1422 static bool classof(const SDNode *N) {
1423 return N->getOpcode() == ISD::LOAD;
1427 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1429 class StoreSDNode : public SDNode {
1430 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1433 // AddrMode - unindexed, pre-indexed, post-indexed.
1434 ISD::MemIndexedMode AddrMode;
1436 // IsTruncStore - True is the op does a truncation before store.
1439 // StoredVT - VT of the value after truncation.
1440 MVT::ValueType StoredVT;
1442 // SrcValue - Memory location for alias analysis.
1443 const Value *SrcValue;
1445 // SVOffset - Memory location offset.
1448 // Alignment - Alignment of memory location in bytes.
1451 // IsVolatile - True if the store is volatile.
1454 friend class SelectionDAG;
1455 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1456 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1457 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1458 : SDNode(ISD::STORE, VTs),
1459 AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT), SrcValue(SV),
1460 SVOffset(O), Alignment(Align), IsVolatile(Vol) {
1461 Ops[0] = ChainValuePtrOff[0]; // Chain
1462 Ops[1] = ChainValuePtrOff[1]; // Value
1463 Ops[2] = ChainValuePtrOff[2]; // Ptr
1464 Ops[3] = ChainValuePtrOff[3]; // Off
1465 InitOperands(Ops, 4);
1466 assert(Align != 0 && "Stores should have non-zero aligment");
1467 assert((getOffset().getOpcode() == ISD::UNDEF ||
1468 AddrMode != ISD::UNINDEXED) &&
1469 "Only indexed store has a non-undef offset operand");
1473 const SDOperand getChain() const { return getOperand(0); }
1474 const SDOperand getValue() const { return getOperand(1); }
1475 const SDOperand getBasePtr() const { return getOperand(2); }
1476 const SDOperand getOffset() const { return getOperand(3); }
1477 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1478 bool isTruncatingStore() const { return IsTruncStore; }
1479 MVT::ValueType getStoredVT() const { return StoredVT; }
1480 const Value *getSrcValue() const { return SrcValue; }
1481 int getSrcValueOffset() const { return SVOffset; }
1482 unsigned getAlignment() const { return Alignment; }
1483 bool isVolatile() const { return IsVolatile; }
1485 static bool classof(const StoreSDNode *) { return true; }
1486 static bool classof(const SDNode *N) {
1487 return N->getOpcode() == ISD::STORE;
1492 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1496 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1498 bool operator==(const SDNodeIterator& x) const {
1499 return Operand == x.Operand;
1501 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1503 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1504 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1505 Operand = I.Operand;
1509 pointer operator*() const {
1510 return Node->getOperand(Operand).Val;
1512 pointer operator->() const { return operator*(); }
1514 SDNodeIterator& operator++() { // Preincrement
1518 SDNodeIterator operator++(int) { // Postincrement
1519 SDNodeIterator tmp = *this; ++*this; return tmp;
1522 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1523 static SDNodeIterator end (SDNode *N) {
1524 return SDNodeIterator(N, N->getNumOperands());
1527 unsigned getOperand() const { return Operand; }
1528 const SDNode *getNode() const { return Node; }
1531 template <> struct GraphTraits<SDNode*> {
1532 typedef SDNode NodeType;
1533 typedef SDNodeIterator ChildIteratorType;
1534 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1535 static inline ChildIteratorType child_begin(NodeType *N) {
1536 return SDNodeIterator::begin(N);
1538 static inline ChildIteratorType child_end(NodeType *N) {
1539 return SDNodeIterator::end(N);
1544 struct ilist_traits<SDNode> {
1545 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1546 static SDNode *getNext(const SDNode *N) { return N->Next; }
1548 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1549 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1551 static SDNode *createSentinel() {
1552 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1554 static void destroySentinel(SDNode *N) { delete N; }
1555 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1558 void addNodeToList(SDNode *NTy) {}
1559 void removeNodeFromList(SDNode *NTy) {}
1560 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1561 const ilist_iterator<SDNode> &X,
1562 const ilist_iterator<SDNode> &Y) {}
1566 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1568 inline bool isNON_EXTLoad(const SDNode *N) {
1569 return N->getOpcode() == ISD::LOAD &&
1570 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1573 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1575 inline bool isEXTLoad(const SDNode *N) {
1576 return N->getOpcode() == ISD::LOAD &&
1577 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1580 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1582 inline bool isSEXTLoad(const SDNode *N) {
1583 return N->getOpcode() == ISD::LOAD &&
1584 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1587 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1589 inline bool isZEXTLoad(const SDNode *N) {
1590 return N->getOpcode() == ISD::LOAD &&
1591 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1594 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1596 inline bool isUNINDEXEDLoad(const SDNode *N) {
1597 return N->getOpcode() == ISD::LOAD &&
1598 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1601 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1603 inline bool isNON_TRUNCStore(const SDNode *N) {
1604 return N->getOpcode() == ISD::STORE &&
1605 !cast<StoreSDNode>(N)->isTruncatingStore();
1608 /// isTRUNCStore - Returns true if the specified node is a truncating
1610 inline bool isTRUNCStore(const SDNode *N) {
1611 return N->getOpcode() == ISD::STORE &&
1612 cast<StoreSDNode>(N)->isTruncatingStore();
1617 } // end llvm namespace