1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file 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/ADT/APFloat.h"
27 #include "llvm/ADT/APInt.h"
28 #include "llvm/CodeGen/ValueTypes.h"
29 #include "llvm/CodeGen/MemOperand.h"
30 #include "llvm/Support/DataTypes.h"
37 class MachineBasicBlock;
38 class MachineConstantPoolValue;
40 template <typename T> struct DenseMapInfo;
41 template <typename T> struct simplify_type;
42 template <typename T> struct ilist_traits;
43 template<typename NodeTy, typename Traits> class iplist;
44 template<typename NodeTy> class ilist_iterator;
46 /// SDVTList - This represents a list of ValueType's that has been intern'd by
47 /// a SelectionDAG. Instances of this simple value class are returned by
48 /// SelectionDAG::getVTList(...).
51 const MVT::ValueType *VTs;
52 unsigned short NumVTs;
55 /// ISD namespace - This namespace contains an enum which represents all of the
56 /// SelectionDAG node types and value types.
59 namespace ParamFlags {
62 ZExt = 1<<0, ///< Parameter should be zero extended
64 SExt = 1<<1, ///< Parameter should be sign extended
66 InReg = 1<<2, ///< Parameter should be passed in register
68 StructReturn = 1<<3, ///< Hidden struct-return pointer
70 ByVal = 1<<4, ///< Struct passed by value
72 Nest = 1<<5, ///< Parameter is nested function static chain
74 ByValAlign = 0xF << 6, //< The alignment of the struct
76 ByValSize = 0x1ffff << 10, //< The size of the struct
78 OrigAlignment = 0x1F<<27,
79 OrigAlignmentOffs = 27
83 //===--------------------------------------------------------------------===//
84 /// ISD::NodeType enum - This enum defines all of the operators valid in a
88 // DELETED_NODE - This is an illegal flag value that is used to catch
89 // errors. This opcode is not a legal opcode for any node.
92 // EntryToken - This is the marker used to indicate the start of the region.
95 // Token factor - This node takes multiple tokens as input and produces a
96 // single token result. This is used to represent the fact that the operand
97 // operators are independent of each other.
100 // AssertSext, AssertZext - These nodes record if a register contains a
101 // value that has already been zero or sign extended from a narrower type.
102 // These nodes take two operands. The first is the node that has already
103 // been extended, and the second is a value type node indicating the width
105 AssertSext, AssertZext,
107 // Various leaf nodes.
108 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
109 Constant, ConstantFP,
110 GlobalAddress, GlobalTLSAddress, FrameIndex,
111 JumpTable, ConstantPool, ExternalSymbol,
113 // The address of the GOT
116 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
117 // llvm.returnaddress on the DAG. These nodes take one operand, the index
118 // of the frame or return address to return. An index of zero corresponds
119 // to the current function's frame or return address, an index of one to the
120 // parent's frame or return address, and so on.
121 FRAMEADDR, RETURNADDR,
123 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
124 // first (possible) on-stack argument. This is needed for correct stack
125 // adjustment during unwind.
126 FRAME_TO_ARGS_OFFSET,
128 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
129 // address of the exception block on entry to an landing pad block.
132 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
133 // the selection index of the exception thrown.
136 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
137 // 'eh_return' gcc dwarf builtin, which is used to return from
138 // exception. The general meaning is: adjust stack by OFFSET and pass
139 // execution to HANDLER. Many platform-related details also :)
142 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
143 // simplification of the constant.
147 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
148 // anything else with this node, and this is valid in the target-specific
149 // dag, turning into a GlobalAddress operand.
151 TargetGlobalTLSAddress,
155 TargetExternalSymbol,
157 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
158 /// This node represents a target intrinsic function with no side effects.
159 /// The first operand is the ID number of the intrinsic from the
160 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
161 /// node has returns the result of the intrinsic.
164 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
165 /// This node represents a target intrinsic function with side effects that
166 /// returns a result. The first operand is a chain pointer. The second is
167 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
168 /// operands to the intrinsic follow. The node has two results, the result
169 /// of the intrinsic and an output chain.
172 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
173 /// This node represents a target intrinsic function with side effects that
174 /// does not return a result. The first operand is a chain pointer. The
175 /// second is the ID number of the intrinsic from the llvm::Intrinsic
176 /// namespace. The operands to the intrinsic follow.
179 // CopyToReg - This node has three operands: a chain, a register number to
180 // set to this value, and a value.
183 // CopyFromReg - This node indicates that the input value is a virtual or
184 // physical register that is defined outside of the scope of this
185 // SelectionDAG. The register is available from the RegisterSDNode object.
188 // UNDEF - An undefined node
191 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
192 /// represents the formal arguments for a function. CC# is a Constant value
193 /// indicating the calling convention of the function, and ISVARARG is a
194 /// flag that indicates whether the function is varargs or not. This node
195 /// has one result value for each incoming argument, plus one for the output
196 /// chain. It must be custom legalized. See description of CALL node for
197 /// FLAG argument contents explanation.
201 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
202 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
203 /// This node represents a fully general function call, before the legalizer
204 /// runs. This has one result value for each argument / flag pair, plus
205 /// a chain result. It must be custom legalized. Flag argument indicates
206 /// misc. argument attributes. Currently:
208 /// Bit 1 - 'inreg' attribute
209 /// Bit 2 - 'sret' attribute
210 /// Bit 4 - 'byval' attribute
211 /// Bit 5 - 'nest' attribute
212 /// Bit 6-9 - alignment of byval structures
213 /// Bit 10-26 - size of byval structures
214 /// Bits 31:27 - argument ABI alignment in the first argument piece and
215 /// alignment '1' in other argument pieces.
218 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
219 // a Constant, which is required to be operand #1), element of the aggregate
220 // value specified as operand #0. This is only for use before legalization,
221 // for values that will be broken into multiple registers.
224 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
225 // two values of the same integer value type, this produces a value twice as
226 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
229 // MERGE_VALUES - This node takes multiple discrete operands and returns
230 // them all as its individual results. This nodes has exactly the same
231 // number of inputs and outputs, and is only valid before legalization.
232 // This node is useful for some pieces of the code generator that want to
233 // think about a single node with multiple results, not multiple nodes.
236 // Simple integer binary arithmetic operators.
237 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
239 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
240 // a signed/unsigned value of type i[2*N], and return the full value as
241 // two results, each of type iN.
242 SMUL_LOHI, UMUL_LOHI,
244 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
248 // CARRY_FALSE - This node is used when folding other nodes,
249 // like ADDC/SUBC, which indicate the carry result is always false.
252 // Carry-setting nodes for multiple precision addition and subtraction.
253 // These nodes take two operands of the same value type, and produce two
254 // results. The first result is the normal add or sub result, the second
255 // result is the carry flag result.
258 // Carry-using nodes for multiple precision addition and subtraction. These
259 // nodes take three operands: The first two are the normal lhs and rhs to
260 // the add or sub, and the third is the input carry flag. These nodes
261 // produce two results; the normal result of the add or sub, and the output
262 // carry flag. These nodes both read and write a carry flag to allow them
263 // to them to be chained together for add and sub of arbitrarily large
267 // Simple binary floating point operators.
268 FADD, FSUB, FMUL, FDIV, FREM,
270 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
271 // DAG node does not require that X and Y have the same type, just that they
272 // are both floating point. X and the result must have the same type.
273 // FCOPYSIGN(f32, f64) is allowed.
276 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
277 // value as an integer 0/1 value.
280 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
281 /// with the specified, possibly variable, elements. The number of elements
282 /// is required to be a power of two.
285 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
286 /// at IDX replaced with VAL. If the type of VAL is larger than the vector
287 /// element type then VAL is truncated before replacement.
290 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
291 /// identified by the (potentially variable) element number IDX.
294 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
295 /// vector type with the same length and element type, this produces a
296 /// concatenated vector result value, with length equal to the sum of the
297 /// lengths of the input vectors.
300 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
301 /// vector value) starting with the (potentially variable) element number
302 /// IDX, which must be a multiple of the result vector length.
305 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
306 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
307 /// (maybe of an illegal datatype) or undef that indicate which value each
308 /// result element will get. The elements of VEC1/VEC2 are enumerated in
309 /// order. This is quite similar to the Altivec 'vperm' instruction, except
310 /// that the indices must be constants and are in terms of the element size
311 /// of VEC1/VEC2, not in terms of bytes.
314 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
315 /// scalar value into element 0 of the resultant vector type. The top
316 /// elements 1 to N-1 of the N-element vector are undefined.
319 // EXTRACT_SUBREG - This node is used to extract a sub-register value.
320 // This node takes a superreg and a constant sub-register index as operands.
323 // INSERT_SUBREG - This node is used to insert a sub-register value.
324 // This node takes a superreg, a subreg value, and a constant sub-register
325 // index as operands.
328 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
329 // an unsigned/signed value of type i[2*N], then return the top part.
332 // Bitwise operators - logical and, logical or, logical xor, shift left,
333 // shift right algebraic (shift in sign bits), shift right logical (shift in
334 // zeroes), rotate left, rotate right, and byteswap.
335 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
337 // Counting operators
340 // Select(COND, TRUEVAL, FALSEVAL)
343 // Select with condition operator - This selects between a true value and
344 // a false value (ops #2 and #3) based on the boolean result of comparing
345 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
346 // condition code in op #4, a CondCodeSDNode.
349 // SetCC operator - This evaluates to a boolean (i1) true value if the
350 // condition is true. The operands to this are the left and right operands
351 // to compare (ops #0, and #1) and the condition code to compare them with
352 // (op #2) as a CondCodeSDNode.
355 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
356 // integer shift operations, just like ADD/SUB_PARTS. The operation
358 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
359 SHL_PARTS, SRA_PARTS, SRL_PARTS,
361 // Conversion operators. These are all single input single output
362 // operations. For all of these, the result type must be strictly
363 // wider or narrower (depending on the operation) than the source
366 // SIGN_EXTEND - Used for integer types, replicating the sign bit
370 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
373 // ANY_EXTEND - Used for integer types. The high bits are undefined.
376 // TRUNCATE - Completely drop the high bits.
379 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
380 // depends on the first letter) to floating point.
384 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
385 // sign extend a small value in a large integer register (e.g. sign
386 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
387 // with the 7th bit). The size of the smaller type is indicated by the 1th
388 // operand, a ValueType node.
391 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
396 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
397 /// down to the precision of the destination VT. TRUNC is a flag, which is
398 /// always an integer that is zero or one. If TRUNC is 0, this is a
399 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
402 /// The TRUNC = 1 case is used in cases where we know that the value will
403 /// not be modified by the node, because Y is not using any of the extra
404 /// precision of source type. This allows certain transformations like
405 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
406 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
409 // FLT_ROUNDS_ - Returns current rounding mode:
412 // 1 Round to nearest
417 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
418 /// rounds it to a floating point value. It then promotes it and returns it
419 /// in a register of the same size. This operation effectively just
420 /// discards excess precision. The type to round down to is specified by
421 /// the VT operand, a VTSDNode.
424 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
427 // BIT_CONVERT - Theis operator converts between integer and FP values, as
428 // if one was stored to memory as integer and the other was loaded from the
429 // same address (or equivalently for vector format conversions, etc). The
430 // source and result are required to have the same bit size (e.g.
431 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
432 // conversions, but that is a noop, deleted by getNode().
435 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
436 // negation, absolute value, square root, sine and cosine, powi, and pow
438 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
440 // LOAD and STORE have token chains as their first operand, then the same
441 // operands as an LLVM load/store instruction, then an offset node that
442 // is added / subtracted from the base pointer to form the address (for
443 // indexed memory ops).
446 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
447 // to a specified boundary. This node always has two return values: a new
448 // stack pointer value and a chain. The first operand is the token chain,
449 // the second is the number of bytes to allocate, and the third is the
450 // alignment boundary. The size is guaranteed to be a multiple of the stack
451 // alignment, and the alignment is guaranteed to be bigger than the stack
452 // alignment (if required) or 0 to get standard stack alignment.
455 // Control flow instructions. These all have token chains.
457 // BR - Unconditional branch. The first operand is the chain
458 // operand, the second is the MBB to branch to.
461 // BRIND - Indirect branch. The first operand is the chain, the second
462 // is the value to branch to, which must be of the same type as the target's
466 // BR_JT - Jumptable branch. The first operand is the chain, the second
467 // is the jumptable index, the last one is the jumptable entry index.
470 // BRCOND - Conditional branch. The first operand is the chain,
471 // the second is the condition, the third is the block to branch
472 // to if the condition is true.
475 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
476 // that the condition is represented as condition code, and two nodes to
477 // compare, rather than as a combined SetCC node. The operands in order are
478 // chain, cc, lhs, rhs, block to branch to if condition is true.
481 // RET - Return from function. The first operand is the chain,
482 // and any subsequent operands are pairs of return value and return value
483 // signness for the function. This operation can have variable number of
487 // INLINEASM - Represents an inline asm block. This node always has two
488 // return values: a chain and a flag result. The inputs are as follows:
489 // Operand #0 : Input chain.
490 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
491 // Operand #2n+2: A RegisterNode.
492 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
493 // Operand #last: Optional, an incoming flag.
496 // LABEL - Represents a label in mid basic block used to track
497 // locations needed for debug and exception handling tables. This node
499 // Operand #0 : input chain.
500 // Operand #1 : module unique number use to identify the label.
501 // Operand #2 : 0 indicates a debug label (e.g. stoppoint), 1 indicates
502 // a EH label, 2 indicates unknown label type.
505 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
506 // local variable declarations for debugging information. First operand is
507 // a chain, while the next two operands are first two arguments (address
508 // and variable) of a llvm.dbg.declare instruction.
511 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
512 // value, the same type as the pointer type for the system, and an output
516 // STACKRESTORE has two operands, an input chain and a pointer to restore to
517 // it returns an output chain.
520 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain. The following
521 // correspond to the operands of the LLVM intrinsic functions and the last
522 // one is AlwaysInline. The only result is a token chain. The alignment
523 // argument is guaranteed to be a Constant node.
528 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
529 // a call sequence, and carry arbitrary information that target might want
530 // to know. The first operand is a chain, the rest are specified by the
531 // target and not touched by the DAG optimizers.
532 CALLSEQ_START, // Beginning of a call sequence
533 CALLSEQ_END, // End of a call sequence
535 // VAARG - VAARG has three operands: an input chain, a pointer, and a
536 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
539 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
540 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
544 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
545 // pointer, and a SRCVALUE.
548 // SRCVALUE - This is a node type that holds a Value* that is used to
549 // make reference to a value in the LLVM IR.
552 // MEMOPERAND - This is a node that contains a MemOperand which records
553 // information about a memory reference. This is used to make AliasAnalysis
554 // queries from the backend.
557 // PCMARKER - This corresponds to the pcmarker intrinsic.
560 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
561 // The only operand is a chain and a value and a chain are produced. The
562 // value is the contents of the architecture specific cycle counter like
563 // register (or other high accuracy low latency clock source)
566 // HANDLENODE node - Used as a handle for various purposes.
569 // LOCATION - This node is used to represent a source location for debug
570 // info. It takes token chain as input, then a line number, then a column
571 // number, then a filename, then a working dir. It produces a token chain
575 // DEBUG_LOC - This node is used to represent source line information
576 // embedded in the code. It takes a token chain as input, then a line
577 // number, then a column then a file id (provided by MachineModuleInfo.) It
578 // produces a token chain as output.
581 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
582 // It takes as input a token chain, the pointer to the trampoline,
583 // the pointer to the nested function, the pointer to pass for the
584 // 'nest' parameter, a SRCVALUE for the trampoline and another for
585 // the nested function (allowing targets to access the original
586 // Function*). It produces the result of the intrinsic and a token
590 // TRAP - Trapping instruction
593 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
594 // store-store, device)
595 // This corresponds to the memory.barrier intrinsic.
596 // it takes an input chain, 4 operands to specify the type of barrier, an
597 // operand specifying if the barrier applies to device and uncached memory
598 // and produces an output chain.
601 // Val, OUTCHAIN = ATOMIC_LCS(INCHAIN, ptr, cmp, swap)
602 // this corresponds to the atomic.lcs intrinsic.
603 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
604 // the return is always the original value in *ptr
607 // Val, OUTCHAIN = ATOMIC_LAS(INCHAIN, ptr, amt)
608 // this corresponds to the atomic.las intrinsic.
609 // *ptr + amt is stored to *ptr atomically.
610 // the return is always the original value in *ptr
613 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
614 // this corresponds to the atomic.swap intrinsic.
615 // amt is stored to *ptr atomically.
616 // the return is always the original value in *ptr
619 // BUILTIN_OP_END - This must be the last enum value in this list.
625 /// isBuildVectorAllOnes - Return true if the specified node is a
626 /// BUILD_VECTOR where all of the elements are ~0 or undef.
627 bool isBuildVectorAllOnes(const SDNode *N);
629 /// isBuildVectorAllZeros - Return true if the specified node is a
630 /// BUILD_VECTOR where all of the elements are 0 or undef.
631 bool isBuildVectorAllZeros(const SDNode *N);
633 /// isScalarToVector - Return true if the specified node is a
634 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
635 /// element is not an undef.
636 bool isScalarToVector(const SDNode *N);
638 /// isDebugLabel - Return true if the specified node represents a debug
639 /// label (i.e. ISD::LABEL or TargetInstrInfo::LABEL node and third operand
641 bool isDebugLabel(const SDNode *N);
643 //===--------------------------------------------------------------------===//
644 /// MemIndexedMode enum - This enum defines the load / store indexed
645 /// addressing modes.
647 /// UNINDEXED "Normal" load / store. The effective address is already
648 /// computed and is available in the base pointer. The offset
649 /// operand is always undefined. In addition to producing a
650 /// chain, an unindexed load produces one value (result of the
651 /// load); an unindexed store does not produces a value.
653 /// PRE_INC Similar to the unindexed mode where the effective address is
654 /// PRE_DEC the value of the base pointer add / subtract the offset.
655 /// It considers the computation as being folded into the load /
656 /// store operation (i.e. the load / store does the address
657 /// computation as well as performing the memory transaction).
658 /// The base operand is always undefined. In addition to
659 /// producing a chain, pre-indexed load produces two values
660 /// (result of the load and the result of the address
661 /// computation); a pre-indexed store produces one value (result
662 /// of the address computation).
664 /// POST_INC The effective address is the value of the base pointer. The
665 /// POST_DEC value of the offset operand is then added to / subtracted
666 /// from the base after memory transaction. In addition to
667 /// producing a chain, post-indexed load produces two values
668 /// (the result of the load and the result of the base +/- offset
669 /// computation); a post-indexed store produces one value (the
670 /// the result of the base +/- offset computation).
672 enum MemIndexedMode {
681 //===--------------------------------------------------------------------===//
682 /// LoadExtType enum - This enum defines the three variants of LOADEXT
683 /// (load with extension).
685 /// SEXTLOAD loads the integer operand and sign extends it to a larger
686 /// integer result type.
687 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
688 /// integer result type.
689 /// EXTLOAD is used for three things: floating point extending loads,
690 /// integer extending loads [the top bits are undefined], and vector
691 /// extending loads [load into low elt].
701 //===--------------------------------------------------------------------===//
702 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
703 /// below work out, when considering SETFALSE (something that never exists
704 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
705 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
706 /// to. If the "N" column is 1, the result of the comparison is undefined if
707 /// the input is a NAN.
709 /// All of these (except for the 'always folded ops') should be handled for
710 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
711 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
713 /// Note that these are laid out in a specific order to allow bit-twiddling
714 /// to transform conditions.
716 // Opcode N U L G E Intuitive operation
717 SETFALSE, // 0 0 0 0 Always false (always folded)
718 SETOEQ, // 0 0 0 1 True if ordered and equal
719 SETOGT, // 0 0 1 0 True if ordered and greater than
720 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
721 SETOLT, // 0 1 0 0 True if ordered and less than
722 SETOLE, // 0 1 0 1 True if ordered and less than or equal
723 SETONE, // 0 1 1 0 True if ordered and operands are unequal
724 SETO, // 0 1 1 1 True if ordered (no nans)
725 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
726 SETUEQ, // 1 0 0 1 True if unordered or equal
727 SETUGT, // 1 0 1 0 True if unordered or greater than
728 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
729 SETULT, // 1 1 0 0 True if unordered or less than
730 SETULE, // 1 1 0 1 True if unordered, less than, or equal
731 SETUNE, // 1 1 1 0 True if unordered or not equal
732 SETTRUE, // 1 1 1 1 Always true (always folded)
733 // Don't care operations: undefined if the input is a nan.
734 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
735 SETEQ, // 1 X 0 0 1 True if equal
736 SETGT, // 1 X 0 1 0 True if greater than
737 SETGE, // 1 X 0 1 1 True if greater than or equal
738 SETLT, // 1 X 1 0 0 True if less than
739 SETLE, // 1 X 1 0 1 True if less than or equal
740 SETNE, // 1 X 1 1 0 True if not equal
741 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
743 SETCC_INVALID // Marker value.
746 /// isSignedIntSetCC - Return true if this is a setcc instruction that
747 /// performs a signed comparison when used with integer operands.
748 inline bool isSignedIntSetCC(CondCode Code) {
749 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
752 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
753 /// performs an unsigned comparison when used with integer operands.
754 inline bool isUnsignedIntSetCC(CondCode Code) {
755 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
758 /// isTrueWhenEqual - Return true if the specified condition returns true if
759 /// the two operands to the condition are equal. Note that if one of the two
760 /// operands is a NaN, this value is meaningless.
761 inline bool isTrueWhenEqual(CondCode Cond) {
762 return ((int)Cond & 1) != 0;
765 /// getUnorderedFlavor - This function returns 0 if the condition is always
766 /// false if an operand is a NaN, 1 if the condition is always true if the
767 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
769 inline unsigned getUnorderedFlavor(CondCode Cond) {
770 return ((int)Cond >> 3) & 3;
773 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
774 /// 'op' is a valid SetCC operation.
775 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
777 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
778 /// when given the operation for (X op Y).
779 CondCode getSetCCSwappedOperands(CondCode Operation);
781 /// getSetCCOrOperation - Return the result of a logical OR between different
782 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
783 /// function returns SETCC_INVALID if it is not possible to represent the
784 /// resultant comparison.
785 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
787 /// getSetCCAndOperation - Return the result of a logical AND between
788 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
789 /// function returns SETCC_INVALID if it is not possible to represent the
790 /// resultant comparison.
791 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
792 } // end llvm::ISD namespace
795 //===----------------------------------------------------------------------===//
796 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
797 /// values as the result of a computation. Many nodes return multiple values,
798 /// from loads (which define a token and a return value) to ADDC (which returns
799 /// a result and a carry value), to calls (which may return an arbitrary number
802 /// As such, each use of a SelectionDAG computation must indicate the node that
803 /// computes it as well as which return value to use from that node. This pair
804 /// of information is represented with the SDOperand value type.
808 SDNode *Val; // The node defining the value we are using.
809 unsigned ResNo; // Which return value of the node we are using.
811 SDOperand() : Val(0), ResNo(0) {}
812 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
814 bool operator==(const SDOperand &O) const {
815 return Val == O.Val && ResNo == O.ResNo;
817 bool operator!=(const SDOperand &O) const {
818 return !operator==(O);
820 bool operator<(const SDOperand &O) const {
821 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
824 SDOperand getValue(unsigned R) const {
825 return SDOperand(Val, R);
828 // isOperand - Return true if this node is an operand of N.
829 bool isOperand(SDNode *N) const;
831 /// getValueType - Return the ValueType of the referenced return value.
833 inline MVT::ValueType getValueType() const;
835 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType()).
837 unsigned getValueSizeInBits() const {
838 return MVT::getSizeInBits(getValueType());
841 // Forwarding methods - These forward to the corresponding methods in SDNode.
842 inline unsigned getOpcode() const;
843 inline unsigned getNumOperands() const;
844 inline const SDOperand &getOperand(unsigned i) const;
845 inline uint64_t getConstantOperandVal(unsigned i) const;
846 inline bool isTargetOpcode() const;
847 inline unsigned getTargetOpcode() const;
850 /// reachesChainWithoutSideEffects - Return true if this operand (which must
851 /// be a chain) reaches the specified operand without crossing any
852 /// side-effecting instructions. In practice, this looks through token
853 /// factors and non-volatile loads. In order to remain efficient, this only
854 /// looks a couple of nodes in, it does not do an exhaustive search.
855 bool reachesChainWithoutSideEffects(SDOperand Dest, unsigned Depth = 2) const;
857 /// hasOneUse - Return true if there is exactly one operation using this
858 /// result value of the defining operator.
859 inline bool hasOneUse() const;
861 /// use_empty - Return true if there are no operations using this
862 /// result value of the defining operator.
863 inline bool use_empty() const;
867 template<> struct DenseMapInfo<SDOperand> {
868 static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); }
869 static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);}
870 static unsigned getHashValue(const SDOperand &Val) {
871 return ((unsigned)((uintptr_t)Val.Val >> 4) ^
872 (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo;
874 static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
877 static bool isPod() { return true; }
880 /// simplify_type specializations - Allow casting operators to work directly on
881 /// SDOperands as if they were SDNode*'s.
882 template<> struct simplify_type<SDOperand> {
883 typedef SDNode* SimpleType;
884 static SimpleType getSimplifiedValue(const SDOperand &Val) {
885 return static_cast<SimpleType>(Val.Val);
888 template<> struct simplify_type<const SDOperand> {
889 typedef SDNode* SimpleType;
890 static SimpleType getSimplifiedValue(const SDOperand &Val) {
891 return static_cast<SimpleType>(Val.Val);
896 /// SDNode - Represents one node in the SelectionDAG.
898 class SDNode : public FoldingSetNode {
899 /// NodeType - The operation that this node performs.
901 unsigned short NodeType;
903 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
904 /// then they will be delete[]'d when the node is destroyed.
905 bool OperandsNeedDelete : 1;
907 /// NodeId - Unique id per SDNode in the DAG.
910 /// OperandList - The values that are used by this operation.
912 SDOperand *OperandList;
914 /// ValueList - The types of the values this node defines. SDNode's may
915 /// define multiple values simultaneously.
916 const MVT::ValueType *ValueList;
918 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
919 unsigned short NumOperands, NumValues;
921 /// Prev/Next pointers - These pointers form the linked list of of the
922 /// AllNodes list in the current DAG.
924 friend struct ilist_traits<SDNode>;
926 /// Uses - These are all of the SDNode's that use a value produced by this
928 SmallVector<SDNode*,3> Uses;
930 // Out-of-line virtual method to give class a home.
931 virtual void ANCHOR();
934 assert(NumOperands == 0 && "Operand list not cleared before deletion");
935 NodeType = ISD::DELETED_NODE;
938 //===--------------------------------------------------------------------===//
941 unsigned getOpcode() const { return NodeType; }
942 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
943 unsigned getTargetOpcode() const {
944 assert(isTargetOpcode() && "Not a target opcode!");
945 return NodeType - ISD::BUILTIN_OP_END;
948 size_t use_size() const { return Uses.size(); }
949 bool use_empty() const { return Uses.empty(); }
950 bool hasOneUse() const { return Uses.size() == 1; }
952 /// getNodeId - Return the unique node id.
954 int getNodeId() const { return NodeId; }
956 /// setNodeId - Set unique node id.
957 void setNodeId(int Id) { NodeId = Id; }
959 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
960 use_iterator use_begin() const { return Uses.begin(); }
961 use_iterator use_end() const { return Uses.end(); }
963 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
964 /// indicated value. This method ignores uses of other values defined by this
966 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
968 /// hasAnyUseOfValue - Return true if there are any use of the indicated
969 /// value. This method ignores uses of other values defined by this operation.
970 bool hasAnyUseOfValue(unsigned Value) const;
972 /// isOnlyUse - Return true if this node is the only use of N.
974 bool isOnlyUse(SDNode *N) const;
976 /// isOperand - Return true if this node is an operand of N.
978 bool isOperand(SDNode *N) const;
980 /// isPredecessor - Return true if this node is a predecessor of N. This node
981 /// is either an operand of N or it can be reached by recursively traversing
983 /// NOTE: this is an expensive method. Use it carefully.
984 bool isPredecessor(SDNode *N) const;
986 /// getNumOperands - Return the number of values used by this operation.
988 unsigned getNumOperands() const { return NumOperands; }
990 /// getConstantOperandVal - Helper method returns the integer value of a
991 /// ConstantSDNode operand.
992 uint64_t getConstantOperandVal(unsigned Num) const;
994 const SDOperand &getOperand(unsigned Num) const {
995 assert(Num < NumOperands && "Invalid child # of SDNode!");
996 return OperandList[Num];
999 typedef const SDOperand* op_iterator;
1000 op_iterator op_begin() const { return OperandList; }
1001 op_iterator op_end() const { return OperandList+NumOperands; }
1004 SDVTList getVTList() const {
1005 SDVTList X = { ValueList, NumValues };
1009 /// getNumValues - Return the number of values defined/returned by this
1012 unsigned getNumValues() const { return NumValues; }
1014 /// getValueType - Return the type of a specified result.
1016 MVT::ValueType getValueType(unsigned ResNo) const {
1017 assert(ResNo < NumValues && "Illegal result number!");
1018 return ValueList[ResNo];
1021 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1023 unsigned getValueSizeInBits(unsigned ResNo) const {
1024 return MVT::getSizeInBits(getValueType(ResNo));
1027 typedef const MVT::ValueType* value_iterator;
1028 value_iterator value_begin() const { return ValueList; }
1029 value_iterator value_end() const { return ValueList+NumValues; }
1031 /// getOperationName - Return the opcode of this operation for printing.
1033 std::string getOperationName(const SelectionDAG *G = 0) const;
1034 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1036 void dump(const SelectionDAG *G) const;
1038 static bool classof(const SDNode *) { return true; }
1040 /// Profile - Gather unique data for the node.
1042 void Profile(FoldingSetNodeID &ID);
1045 friend class SelectionDAG;
1047 /// getValueTypeList - Return a pointer to the specified value type.
1049 static const MVT::ValueType *getValueTypeList(MVT::ValueType VT);
1050 static SDVTList getSDVTList(MVT::ValueType VT) {
1051 SDVTList Ret = { getValueTypeList(VT), 1 };
1055 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
1056 : NodeType(Opc), NodeId(-1) {
1057 OperandsNeedDelete = true;
1058 NumOperands = NumOps;
1059 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
1061 for (unsigned i = 0; i != NumOps; ++i) {
1062 OperandList[i] = Ops[i];
1063 Ops[i].Val->Uses.push_back(this);
1066 ValueList = VTs.VTs;
1067 NumValues = VTs.NumVTs;
1070 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
1071 OperandsNeedDelete = false; // Operands set with InitOperands.
1075 ValueList = VTs.VTs;
1076 NumValues = VTs.NumVTs;
1080 /// InitOperands - Initialize the operands list of this node with the
1081 /// specified values, which are part of the node (thus they don't need to be
1082 /// copied in or allocated).
1083 void InitOperands(SDOperand *Ops, unsigned NumOps) {
1084 assert(OperandList == 0 && "Operands already set!");
1085 NumOperands = NumOps;
1088 for (unsigned i = 0; i != NumOps; ++i)
1089 Ops[i].Val->Uses.push_back(this);
1092 /// MorphNodeTo - This frees the operands of the current node, resets the
1093 /// opcode, types, and operands to the specified value. This should only be
1094 /// used by the SelectionDAG class.
1095 void MorphNodeTo(unsigned Opc, SDVTList L,
1096 const SDOperand *Ops, unsigned NumOps);
1098 void addUser(SDNode *User) {
1099 Uses.push_back(User);
1101 void removeUser(SDNode *User) {
1102 // Remove this user from the operand's use list.
1103 for (unsigned i = Uses.size(); ; --i) {
1104 assert(i != 0 && "Didn't find user!");
1105 if (Uses[i-1] == User) {
1106 Uses[i-1] = Uses.back();
1115 // Define inline functions from the SDOperand class.
1117 inline unsigned SDOperand::getOpcode() const {
1118 return Val->getOpcode();
1120 inline MVT::ValueType SDOperand::getValueType() const {
1121 return Val->getValueType(ResNo);
1123 inline unsigned SDOperand::getNumOperands() const {
1124 return Val->getNumOperands();
1126 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1127 return Val->getOperand(i);
1129 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1130 return Val->getConstantOperandVal(i);
1132 inline bool SDOperand::isTargetOpcode() const {
1133 return Val->isTargetOpcode();
1135 inline unsigned SDOperand::getTargetOpcode() const {
1136 return Val->getTargetOpcode();
1138 inline bool SDOperand::hasOneUse() const {
1139 return Val->hasNUsesOfValue(1, ResNo);
1141 inline bool SDOperand::use_empty() const {
1142 return !Val->hasAnyUseOfValue(ResNo);
1145 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1146 /// to allow co-allocation of node operands with the node itself.
1147 class UnarySDNode : public SDNode {
1148 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1151 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1152 : SDNode(Opc, VTs), Op(X) {
1153 InitOperands(&Op, 1);
1157 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1158 /// to allow co-allocation of node operands with the node itself.
1159 class BinarySDNode : public SDNode {
1160 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1163 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1164 : SDNode(Opc, VTs) {
1167 InitOperands(Ops, 2);
1171 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1172 /// to allow co-allocation of node operands with the node itself.
1173 class TernarySDNode : public SDNode {
1174 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1177 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1179 : SDNode(Opc, VTs) {
1183 InitOperands(Ops, 3);
1188 /// HandleSDNode - This class is used to form a handle around another node that
1189 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1190 /// operand. This node should be directly created by end-users and not added to
1191 /// the AllNodes list.
1192 class HandleSDNode : public SDNode {
1193 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1196 explicit HandleSDNode(SDOperand X)
1197 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1198 InitOperands(&Op, 1);
1201 SDOperand getValue() const { return Op; }
1204 class AtomicSDNode : public SDNode {
1205 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1207 MVT::ValueType OrigVT;
1209 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1210 SDOperand Cmp, SDOperand Swp, MVT::ValueType VT)
1211 : SDNode(Opc, VTL) {
1216 InitOperands(Ops, 4);
1219 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1220 SDOperand Val, MVT::ValueType VT)
1221 : SDNode(Opc, VTL) {
1225 InitOperands(Ops, 3);
1228 MVT::ValueType getVT() const { return OrigVT; }
1229 bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_LCS; }
1232 class StringSDNode : public SDNode {
1234 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1236 friend class SelectionDAG;
1237 explicit StringSDNode(const std::string &val)
1238 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1241 const std::string &getValue() const { return Value; }
1242 static bool classof(const StringSDNode *) { return true; }
1243 static bool classof(const SDNode *N) {
1244 return N->getOpcode() == ISD::STRING;
1248 class ConstantSDNode : public SDNode {
1250 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1252 friend class SelectionDAG;
1253 ConstantSDNode(bool isTarget, const APInt &val, MVT::ValueType VT)
1254 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1259 const APInt &getAPIntValue() const { return Value; }
1260 uint64_t getValue() const { return Value.getZExtValue(); }
1262 int64_t getSignExtended() const {
1263 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1264 return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1267 bool isNullValue() const { return Value == 0; }
1268 bool isAllOnesValue() const {
1269 return Value == MVT::getIntVTBitMask(getValueType(0));
1272 static bool classof(const ConstantSDNode *) { return true; }
1273 static bool classof(const SDNode *N) {
1274 return N->getOpcode() == ISD::Constant ||
1275 N->getOpcode() == ISD::TargetConstant;
1279 class ConstantFPSDNode : public SDNode {
1281 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1283 friend class SelectionDAG;
1284 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT)
1285 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1286 getSDVTList(VT)), Value(val) {
1290 const APFloat& getValueAPF() const { return Value; }
1292 /// isExactlyValue - We don't rely on operator== working on double values, as
1293 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1294 /// As such, this method can be used to do an exact bit-for-bit comparison of
1295 /// two floating point values.
1297 /// We leave the version with the double argument here because it's just so
1298 /// convenient to write "2.0" and the like. Without this function we'd
1299 /// have to duplicate its logic everywhere it's called.
1300 bool isExactlyValue(double V) const {
1302 Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1303 return isExactlyValue(Tmp);
1305 bool isExactlyValue(const APFloat& V) const;
1307 bool isValueValidForType(MVT::ValueType VT, const APFloat& Val);
1309 static bool classof(const ConstantFPSDNode *) { return true; }
1310 static bool classof(const SDNode *N) {
1311 return N->getOpcode() == ISD::ConstantFP ||
1312 N->getOpcode() == ISD::TargetConstantFP;
1316 class GlobalAddressSDNode : public SDNode {
1317 GlobalValue *TheGlobal;
1319 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1321 friend class SelectionDAG;
1322 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1326 GlobalValue *getGlobal() const { return TheGlobal; }
1327 int getOffset() const { return Offset; }
1329 static bool classof(const GlobalAddressSDNode *) { return true; }
1330 static bool classof(const SDNode *N) {
1331 return N->getOpcode() == ISD::GlobalAddress ||
1332 N->getOpcode() == ISD::TargetGlobalAddress ||
1333 N->getOpcode() == ISD::GlobalTLSAddress ||
1334 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1338 class FrameIndexSDNode : public SDNode {
1340 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1342 friend class SelectionDAG;
1343 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1344 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1349 int getIndex() const { return FI; }
1351 static bool classof(const FrameIndexSDNode *) { return true; }
1352 static bool classof(const SDNode *N) {
1353 return N->getOpcode() == ISD::FrameIndex ||
1354 N->getOpcode() == ISD::TargetFrameIndex;
1358 class JumpTableSDNode : public SDNode {
1360 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1362 friend class SelectionDAG;
1363 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1364 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1369 int getIndex() const { return JTI; }
1371 static bool classof(const JumpTableSDNode *) { return true; }
1372 static bool classof(const SDNode *N) {
1373 return N->getOpcode() == ISD::JumpTable ||
1374 N->getOpcode() == ISD::TargetJumpTable;
1378 class ConstantPoolSDNode : public SDNode {
1381 MachineConstantPoolValue *MachineCPVal;
1383 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1385 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1387 friend class SelectionDAG;
1388 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1390 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1391 getSDVTList(VT)), Offset(o), Alignment(0) {
1392 assert((int)Offset >= 0 && "Offset is too large");
1395 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1397 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1398 getSDVTList(VT)), Offset(o), Alignment(Align) {
1399 assert((int)Offset >= 0 && "Offset is too large");
1402 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1403 MVT::ValueType VT, int o=0)
1404 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1405 getSDVTList(VT)), Offset(o), Alignment(0) {
1406 assert((int)Offset >= 0 && "Offset is too large");
1407 Val.MachineCPVal = v;
1408 Offset |= 1 << (sizeof(unsigned)*8-1);
1410 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1411 MVT::ValueType VT, int o, unsigned Align)
1412 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1413 getSDVTList(VT)), Offset(o), Alignment(Align) {
1414 assert((int)Offset >= 0 && "Offset is too large");
1415 Val.MachineCPVal = v;
1416 Offset |= 1 << (sizeof(unsigned)*8-1);
1420 bool isMachineConstantPoolEntry() const {
1421 return (int)Offset < 0;
1424 Constant *getConstVal() const {
1425 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1426 return Val.ConstVal;
1429 MachineConstantPoolValue *getMachineCPVal() const {
1430 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1431 return Val.MachineCPVal;
1434 int getOffset() const {
1435 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1438 // Return the alignment of this constant pool object, which is either 0 (for
1439 // default alignment) or log2 of the desired value.
1440 unsigned getAlignment() const { return Alignment; }
1442 const Type *getType() const;
1444 static bool classof(const ConstantPoolSDNode *) { return true; }
1445 static bool classof(const SDNode *N) {
1446 return N->getOpcode() == ISD::ConstantPool ||
1447 N->getOpcode() == ISD::TargetConstantPool;
1451 class BasicBlockSDNode : public SDNode {
1452 MachineBasicBlock *MBB;
1453 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1455 friend class SelectionDAG;
1456 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1457 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1461 MachineBasicBlock *getBasicBlock() const { return MBB; }
1463 static bool classof(const BasicBlockSDNode *) { return true; }
1464 static bool classof(const SDNode *N) {
1465 return N->getOpcode() == ISD::BasicBlock;
1469 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1470 /// used when the SelectionDAG needs to make a simple reference to something
1471 /// in the LLVM IR representation.
1473 /// Note that this is not used for carrying alias information; that is done
1474 /// with MemOperandSDNode, which includes a Value which is required to be a
1475 /// pointer, and several other fields specific to memory references.
1477 class SrcValueSDNode : public SDNode {
1479 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1481 friend class SelectionDAG;
1482 /// Create a SrcValue for a general value.
1483 explicit SrcValueSDNode(const Value *v)
1484 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1487 /// getValue - return the contained Value.
1488 const Value *getValue() const { return V; }
1490 static bool classof(const SrcValueSDNode *) { return true; }
1491 static bool classof(const SDNode *N) {
1492 return N->getOpcode() == ISD::SRCVALUE;
1497 /// MemOperandSDNode - An SDNode that holds a MemOperand. This is
1498 /// used to represent a reference to memory after ISD::LOAD
1499 /// and ISD::STORE have been lowered.
1501 class MemOperandSDNode : public SDNode {
1502 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1504 friend class SelectionDAG;
1505 /// Create a MemOperand node
1506 explicit MemOperandSDNode(const MemOperand &mo)
1507 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1510 /// MO - The contained MemOperand.
1511 const MemOperand MO;
1513 static bool classof(const MemOperandSDNode *) { return true; }
1514 static bool classof(const SDNode *N) {
1515 return N->getOpcode() == ISD::MEMOPERAND;
1520 class RegisterSDNode : public SDNode {
1522 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1524 friend class SelectionDAG;
1525 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1526 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1530 unsigned getReg() const { return Reg; }
1532 static bool classof(const RegisterSDNode *) { return true; }
1533 static bool classof(const SDNode *N) {
1534 return N->getOpcode() == ISD::Register;
1538 class ExternalSymbolSDNode : public SDNode {
1540 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1542 friend class SelectionDAG;
1543 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1544 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1545 getSDVTList(VT)), Symbol(Sym) {
1549 const char *getSymbol() const { return Symbol; }
1551 static bool classof(const ExternalSymbolSDNode *) { return true; }
1552 static bool classof(const SDNode *N) {
1553 return N->getOpcode() == ISD::ExternalSymbol ||
1554 N->getOpcode() == ISD::TargetExternalSymbol;
1558 class CondCodeSDNode : public SDNode {
1559 ISD::CondCode Condition;
1560 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1562 friend class SelectionDAG;
1563 explicit CondCodeSDNode(ISD::CondCode Cond)
1564 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1568 ISD::CondCode get() const { return Condition; }
1570 static bool classof(const CondCodeSDNode *) { return true; }
1571 static bool classof(const SDNode *N) {
1572 return N->getOpcode() == ISD::CONDCODE;
1576 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1577 /// to parameterize some operations.
1578 class VTSDNode : public SDNode {
1579 MVT::ValueType ValueType;
1580 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1582 friend class SelectionDAG;
1583 explicit VTSDNode(MVT::ValueType VT)
1584 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1588 MVT::ValueType getVT() const { return ValueType; }
1590 static bool classof(const VTSDNode *) { return true; }
1591 static bool classof(const SDNode *N) {
1592 return N->getOpcode() == ISD::VALUETYPE;
1596 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1598 class LSBaseSDNode : public SDNode {
1600 // AddrMode - unindexed, pre-indexed, post-indexed.
1601 ISD::MemIndexedMode AddrMode;
1603 // MemoryVT - VT of in-memory value.
1604 MVT::ValueType MemoryVT;
1606 //! SrcValue - Memory location for alias analysis.
1607 const Value *SrcValue;
1609 //! SVOffset - Memory location offset.
1612 //! Alignment - Alignment of memory location in bytes.
1615 //! IsVolatile - True if the store is volatile.
1618 //! Operand array for load and store
1620 \note Moving this array to the base class captures more
1621 common functionality shared between LoadSDNode and
1626 LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned NumOperands,
1627 SDVTList VTs, ISD::MemIndexedMode AM, MVT::ValueType VT,
1628 const Value *SV, int SVO, unsigned Align, bool Vol)
1629 : SDNode(NodeTy, VTs),
1630 AddrMode(AM), MemoryVT(VT),
1631 SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol) {
1632 for (unsigned i = 0; i != NumOperands; ++i)
1633 Ops[i] = Operands[i];
1634 InitOperands(Ops, NumOperands);
1635 assert(Align != 0 && "Loads and stores should have non-zero aligment");
1636 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1637 "Only indexed loads and stores have a non-undef offset operand");
1640 const SDOperand &getChain() const { return getOperand(0); }
1641 const SDOperand &getBasePtr() const {
1642 return getOperand(getOpcode() == ISD::LOAD ? 1 : 2);
1644 const SDOperand &getOffset() const {
1645 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1648 const Value *getSrcValue() const { return SrcValue; }
1649 int getSrcValueOffset() const { return SVOffset; }
1650 unsigned getAlignment() const { return Alignment; }
1651 MVT::ValueType getMemoryVT() const { return MemoryVT; }
1652 bool isVolatile() const { return IsVolatile; }
1654 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1656 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1657 bool isIndexed() const { return AddrMode != ISD::UNINDEXED; }
1659 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1660 bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; }
1662 /// getMemOperand - Return a MemOperand object describing the memory
1663 /// reference performed by this load or store.
1664 MemOperand getMemOperand() const;
1666 static bool classof(const LSBaseSDNode *N) { return true; }
1667 static bool classof(const SDNode *N) {
1668 return N->getOpcode() == ISD::LOAD ||
1669 N->getOpcode() == ISD::STORE;
1673 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1675 class LoadSDNode : public LSBaseSDNode {
1676 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1678 // ExtType - non-ext, anyext, sext, zext.
1679 ISD::LoadExtType ExtType;
1682 friend class SelectionDAG;
1683 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1684 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1685 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1686 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
1687 VTs, AM, LVT, SV, O, Align, Vol),
1691 ISD::LoadExtType getExtensionType() const { return ExtType; }
1692 const SDOperand &getBasePtr() const { return getOperand(1); }
1693 const SDOperand &getOffset() const { return getOperand(2); }
1695 static bool classof(const LoadSDNode *) { return true; }
1696 static bool classof(const SDNode *N) {
1697 return N->getOpcode() == ISD::LOAD;
1701 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1703 class StoreSDNode : public LSBaseSDNode {
1704 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1706 // IsTruncStore - True if the op does a truncation before store.
1709 friend class SelectionDAG;
1710 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1711 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1712 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1713 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
1714 VTs, AM, SVT, SV, O, Align, Vol),
1715 IsTruncStore(isTrunc) {}
1718 bool isTruncatingStore() const { return IsTruncStore; }
1719 const SDOperand &getValue() const { return getOperand(1); }
1720 const SDOperand &getBasePtr() const { return getOperand(2); }
1721 const SDOperand &getOffset() const { return getOperand(3); }
1723 static bool classof(const StoreSDNode *) { return true; }
1724 static bool classof(const SDNode *N) {
1725 return N->getOpcode() == ISD::STORE;
1730 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1734 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1736 bool operator==(const SDNodeIterator& x) const {
1737 return Operand == x.Operand;
1739 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1741 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1742 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1743 Operand = I.Operand;
1747 pointer operator*() const {
1748 return Node->getOperand(Operand).Val;
1750 pointer operator->() const { return operator*(); }
1752 SDNodeIterator& operator++() { // Preincrement
1756 SDNodeIterator operator++(int) { // Postincrement
1757 SDNodeIterator tmp = *this; ++*this; return tmp;
1760 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1761 static SDNodeIterator end (SDNode *N) {
1762 return SDNodeIterator(N, N->getNumOperands());
1765 unsigned getOperand() const { return Operand; }
1766 const SDNode *getNode() const { return Node; }
1769 template <> struct GraphTraits<SDNode*> {
1770 typedef SDNode NodeType;
1771 typedef SDNodeIterator ChildIteratorType;
1772 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1773 static inline ChildIteratorType child_begin(NodeType *N) {
1774 return SDNodeIterator::begin(N);
1776 static inline ChildIteratorType child_end(NodeType *N) {
1777 return SDNodeIterator::end(N);
1782 struct ilist_traits<SDNode> {
1783 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1784 static SDNode *getNext(const SDNode *N) { return N->Next; }
1786 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1787 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1789 static SDNode *createSentinel() {
1790 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1792 static void destroySentinel(SDNode *N) { delete N; }
1793 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1796 void addNodeToList(SDNode *NTy) {}
1797 void removeNodeFromList(SDNode *NTy) {}
1798 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1799 const ilist_iterator<SDNode> &X,
1800 const ilist_iterator<SDNode> &Y) {}
1804 /// isNormalLoad - Returns true if the specified node is a non-extending
1805 /// and unindexed load.
1806 inline bool isNormalLoad(const SDNode *N) {
1807 if (N->getOpcode() != ISD::LOAD)
1809 const LoadSDNode *Ld = cast<LoadSDNode>(N);
1810 return Ld->getExtensionType() == ISD::NON_EXTLOAD &&
1811 Ld->getAddressingMode() == ISD::UNINDEXED;
1814 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1816 inline bool isNON_EXTLoad(const SDNode *N) {
1817 return N->getOpcode() == ISD::LOAD &&
1818 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1821 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1823 inline bool isEXTLoad(const SDNode *N) {
1824 return N->getOpcode() == ISD::LOAD &&
1825 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1828 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1830 inline bool isSEXTLoad(const SDNode *N) {
1831 return N->getOpcode() == ISD::LOAD &&
1832 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1835 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1837 inline bool isZEXTLoad(const SDNode *N) {
1838 return N->getOpcode() == ISD::LOAD &&
1839 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1842 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1844 inline bool isUNINDEXEDLoad(const SDNode *N) {
1845 return N->getOpcode() == ISD::LOAD &&
1846 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1849 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1851 inline bool isNON_TRUNCStore(const SDNode *N) {
1852 return N->getOpcode() == ISD::STORE &&
1853 !cast<StoreSDNode>(N)->isTruncatingStore();
1856 /// isTRUNCStore - Returns true if the specified node is a truncating
1858 inline bool isTRUNCStore(const SDNode *N) {
1859 return N->getOpcode() == ISD::STORE &&
1860 cast<StoreSDNode>(N)->isTruncatingStore();
1865 } // end llvm namespace