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 {
60 typedef uint64_t ParamFlagsTy;
62 const ParamFlagsTy NoFlagSet = 0ULL;
63 const ParamFlagsTy ZExt = 1ULL<<0; ///< Zero extended
64 const ParamFlagsTy ZExtOffs = 0;
65 const ParamFlagsTy SExt = 1ULL<<1; ///< Sign extended
66 const ParamFlagsTy SExtOffs = 1;
67 const ParamFlagsTy InReg = 1ULL<<2; ///< Passed in register
68 const ParamFlagsTy InRegOffs = 2;
69 const ParamFlagsTy StructReturn = 1ULL<<3; ///< Hidden struct-ret ptr
70 const ParamFlagsTy StructReturnOffs = 3;
71 const ParamFlagsTy ByVal = 1ULL<<4; ///< Struct passed by value
72 const ParamFlagsTy ByValOffs = 4;
73 const ParamFlagsTy Nest = 1ULL<<5; ///< Nested fn static chain
74 const ParamFlagsTy NestOffs = 5;
75 const ParamFlagsTy ByValAlign = 0xFULL << 6; //< Struct alignment
76 const ParamFlagsTy ByValAlignOffs = 6;
77 const ParamFlagsTy OrigAlignment = 0x1FULL<<27;
78 const ParamFlagsTy OrigAlignmentOffs = 27;
79 const ParamFlagsTy ByValSize = 0xffffffffULL << 32; //< Struct size
80 const ParamFlagsTy ByValSizeOffs = 32;
82 const ParamFlagsTy One = 1LL; //< 1 of this type, for shifts
85 //===--------------------------------------------------------------------===//
86 /// ISD::NodeType enum - This enum defines all of the operators valid in a
90 // DELETED_NODE - This is an illegal flag value that is used to catch
91 // errors. This opcode is not a legal opcode for any node.
94 // EntryToken - This is the marker used to indicate the start of the region.
97 // Token factor - This node takes multiple tokens as input and produces a
98 // single token result. This is used to represent the fact that the operand
99 // operators are independent of each other.
102 // AssertSext, AssertZext - These nodes record if a register contains a
103 // value that has already been zero or sign extended from a narrower type.
104 // These nodes take two operands. The first is the node that has already
105 // been extended, and the second is a value type node indicating the width
107 AssertSext, AssertZext,
109 // Various leaf nodes.
110 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
111 Constant, ConstantFP,
112 GlobalAddress, GlobalTLSAddress, FrameIndex,
113 JumpTable, ConstantPool, ExternalSymbol,
115 // The address of the GOT
118 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
119 // llvm.returnaddress on the DAG. These nodes take one operand, the index
120 // of the frame or return address to return. An index of zero corresponds
121 // to the current function's frame or return address, an index of one to the
122 // parent's frame or return address, and so on.
123 FRAMEADDR, RETURNADDR,
125 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
126 // first (possible) on-stack argument. This is needed for correct stack
127 // adjustment during unwind.
128 FRAME_TO_ARGS_OFFSET,
130 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
131 // address of the exception block on entry to an landing pad block.
134 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
135 // the selection index of the exception thrown.
138 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
139 // 'eh_return' gcc dwarf builtin, which is used to return from
140 // exception. The general meaning is: adjust stack by OFFSET and pass
141 // execution to HANDLER. Many platform-related details also :)
144 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
145 // simplification of the constant.
149 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
150 // anything else with this node, and this is valid in the target-specific
151 // dag, turning into a GlobalAddress operand.
153 TargetGlobalTLSAddress,
157 TargetExternalSymbol,
159 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
160 /// This node represents a target intrinsic function with no side effects.
161 /// The first operand is the ID number of the intrinsic from the
162 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
163 /// node has returns the result of the intrinsic.
166 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
167 /// This node represents a target intrinsic function with side effects that
168 /// returns a result. The first operand is a chain pointer. The second is
169 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
170 /// operands to the intrinsic follow. The node has two results, the result
171 /// of the intrinsic and an output chain.
174 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
175 /// This node represents a target intrinsic function with side effects that
176 /// does not return a result. The first operand is a chain pointer. The
177 /// second is the ID number of the intrinsic from the llvm::Intrinsic
178 /// namespace. The operands to the intrinsic follow.
181 // CopyToReg - This node has three operands: a chain, a register number to
182 // set to this value, and a value.
185 // CopyFromReg - This node indicates that the input value is a virtual or
186 // physical register that is defined outside of the scope of this
187 // SelectionDAG. The register is available from the RegisterSDNode object.
190 // UNDEF - An undefined node
193 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
194 /// represents the formal arguments for a function. CC# is a Constant value
195 /// indicating the calling convention of the function, and ISVARARG is a
196 /// flag that indicates whether the function is varargs or not. This node
197 /// has one result value for each incoming argument, plus one for the output
198 /// chain. It must be custom legalized. See description of CALL node for
199 /// FLAG argument contents explanation.
203 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
204 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
205 /// This node represents a fully general function call, before the legalizer
206 /// runs. This has one result value for each argument / flag pair, plus
207 /// a chain result. It must be custom legalized. Flag argument indicates
208 /// misc. argument attributes. Currently:
210 /// Bit 1 - 'inreg' attribute
211 /// Bit 2 - 'sret' attribute
212 /// Bit 4 - 'byval' attribute
213 /// Bit 5 - 'nest' attribute
214 /// Bit 6-9 - alignment of byval structures
215 /// Bit 10-26 - size of byval structures
216 /// Bits 31:27 - argument ABI alignment in the first argument piece and
217 /// alignment '1' in other argument pieces.
220 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
221 // a Constant, which is required to be operand #1) half of the integer value
222 // specified as operand #0. This is only for use before legalization, for
223 // values that will be broken into multiple registers.
226 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
227 // two values of the same integer value type, this produces a value twice as
228 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
231 // MERGE_VALUES - This node takes multiple discrete operands and returns
232 // them all as its individual results. This nodes has exactly the same
233 // number of inputs and outputs, and is only valid before legalization.
234 // This node is useful for some pieces of the code generator that want to
235 // think about a single node with multiple results, not multiple nodes.
238 // Simple integer binary arithmetic operators.
239 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
241 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
242 // a signed/unsigned value of type i[2*N], and return the full value as
243 // two results, each of type iN.
244 SMUL_LOHI, UMUL_LOHI,
246 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
250 // CARRY_FALSE - This node is used when folding other nodes,
251 // like ADDC/SUBC, which indicate the carry result is always false.
254 // Carry-setting nodes for multiple precision addition and subtraction.
255 // These nodes take two operands of the same value type, and produce two
256 // results. The first result is the normal add or sub result, the second
257 // result is the carry flag result.
260 // Carry-using nodes for multiple precision addition and subtraction. These
261 // nodes take three operands: The first two are the normal lhs and rhs to
262 // the add or sub, and the third is the input carry flag. These nodes
263 // produce two results; the normal result of the add or sub, and the output
264 // carry flag. These nodes both read and write a carry flag to allow them
265 // to them to be chained together for add and sub of arbitrarily large
269 // Simple binary floating point operators.
270 FADD, FSUB, FMUL, FDIV, FREM,
272 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
273 // DAG node does not require that X and Y have the same type, just that they
274 // are both floating point. X and the result must have the same type.
275 // FCOPYSIGN(f32, f64) is allowed.
278 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
279 // value as an integer 0/1 value.
282 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
283 /// with the specified, possibly variable, elements. The number of elements
284 /// is required to be a power of two.
287 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
288 /// at IDX replaced with VAL. If the type of VAL is larger than the vector
289 /// element type then VAL is truncated before replacement.
292 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
293 /// identified by the (potentially variable) element number IDX.
296 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
297 /// vector type with the same length and element type, this produces a
298 /// concatenated vector result value, with length equal to the sum of the
299 /// lengths of the input vectors.
302 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
303 /// vector value) starting with the (potentially variable) element number
304 /// IDX, which must be a multiple of the result vector length.
307 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
308 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
309 /// (maybe of an illegal datatype) or undef that indicate which value each
310 /// result element will get. The elements of VEC1/VEC2 are enumerated in
311 /// order. This is quite similar to the Altivec 'vperm' instruction, except
312 /// that the indices must be constants and are in terms of the element size
313 /// of VEC1/VEC2, not in terms of bytes.
316 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
317 /// scalar value into element 0 of the resultant vector type. The top
318 /// elements 1 to N-1 of the N-element vector are undefined.
321 // EXTRACT_SUBREG - This node is used to extract a sub-register value.
322 // This node takes a superreg and a constant sub-register index as operands.
323 // Note sub-register indices must be increasing. That is, if the
324 // sub-register index of a 8-bit sub-register is N, then the index for a
325 // 16-bit sub-register must be at least N+1.
328 // INSERT_SUBREG - This node is used to insert a sub-register value.
329 // This node takes a superreg, a subreg value, and a constant sub-register
330 // index as operands.
333 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
334 // an unsigned/signed value of type i[2*N], then return the top part.
337 // Bitwise operators - logical and, logical or, logical xor, shift left,
338 // shift right algebraic (shift in sign bits), shift right logical (shift in
339 // zeroes), rotate left, rotate right, and byteswap.
340 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
342 // Counting operators
345 // Select(COND, TRUEVAL, FALSEVAL)
348 // Select with condition operator - This selects between a true value and
349 // a false value (ops #2 and #3) based on the boolean result of comparing
350 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
351 // condition code in op #4, a CondCodeSDNode.
354 // SetCC operator - This evaluates to a boolean (i1) true value if the
355 // condition is true. The operands to this are the left and right operands
356 // to compare (ops #0, and #1) and the condition code to compare them with
357 // (op #2) as a CondCodeSDNode.
360 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
361 // integer shift operations, just like ADD/SUB_PARTS. The operation
363 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
364 SHL_PARTS, SRA_PARTS, SRL_PARTS,
366 // Conversion operators. These are all single input single output
367 // operations. For all of these, the result type must be strictly
368 // wider or narrower (depending on the operation) than the source
371 // SIGN_EXTEND - Used for integer types, replicating the sign bit
375 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
378 // ANY_EXTEND - Used for integer types. The high bits are undefined.
381 // TRUNCATE - Completely drop the high bits.
384 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
385 // depends on the first letter) to floating point.
389 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
390 // sign extend a small value in a large integer register (e.g. sign
391 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
392 // with the 7th bit). The size of the smaller type is indicated by the 1th
393 // operand, a ValueType node.
396 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
401 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
402 /// down to the precision of the destination VT. TRUNC is a flag, which is
403 /// always an integer that is zero or one. If TRUNC is 0, this is a
404 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
407 /// The TRUNC = 1 case is used in cases where we know that the value will
408 /// not be modified by the node, because Y is not using any of the extra
409 /// precision of source type. This allows certain transformations like
410 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
411 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
414 // FLT_ROUNDS_ - Returns current rounding mode:
417 // 1 Round to nearest
422 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
423 /// rounds it to a floating point value. It then promotes it and returns it
424 /// in a register of the same size. This operation effectively just
425 /// discards excess precision. The type to round down to is specified by
426 /// the VT operand, a VTSDNode.
429 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
432 // BIT_CONVERT - Theis operator converts between integer and FP values, as
433 // if one was stored to memory as integer and the other was loaded from the
434 // same address (or equivalently for vector format conversions, etc). The
435 // source and result are required to have the same bit size (e.g.
436 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
437 // conversions, but that is a noop, deleted by getNode().
440 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
441 // negation, absolute value, square root, sine and cosine, powi, and pow
443 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
445 // LOAD and STORE have token chains as their first operand, then the same
446 // operands as an LLVM load/store instruction, then an offset node that
447 // is added / subtracted from the base pointer to form the address (for
448 // indexed memory ops).
451 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
452 // to a specified boundary. This node always has two return values: a new
453 // stack pointer value and a chain. The first operand is the token chain,
454 // the second is the number of bytes to allocate, and the third is the
455 // alignment boundary. The size is guaranteed to be a multiple of the stack
456 // alignment, and the alignment is guaranteed to be bigger than the stack
457 // alignment (if required) or 0 to get standard stack alignment.
460 // Control flow instructions. These all have token chains.
462 // BR - Unconditional branch. The first operand is the chain
463 // operand, the second is the MBB to branch to.
466 // BRIND - Indirect branch. The first operand is the chain, the second
467 // is the value to branch to, which must be of the same type as the target's
471 // BR_JT - Jumptable branch. The first operand is the chain, the second
472 // is the jumptable index, the last one is the jumptable entry index.
475 // BRCOND - Conditional branch. The first operand is the chain,
476 // the second is the condition, the third is the block to branch
477 // to if the condition is true.
480 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
481 // that the condition is represented as condition code, and two nodes to
482 // compare, rather than as a combined SetCC node. The operands in order are
483 // chain, cc, lhs, rhs, block to branch to if condition is true.
486 // RET - Return from function. The first operand is the chain,
487 // and any subsequent operands are pairs of return value and return value
488 // signness for the function. This operation can have variable number of
492 // INLINEASM - Represents an inline asm block. This node always has two
493 // return values: a chain and a flag result. The inputs are as follows:
494 // Operand #0 : Input chain.
495 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
496 // Operand #2n+2: A RegisterNode.
497 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
498 // Operand #last: Optional, an incoming flag.
501 // LABEL - Represents a label in mid basic block used to track
502 // locations needed for debug and exception handling tables. This node
504 // Operand #0 : input chain.
505 // Operand #1 : module unique number use to identify the label.
506 // Operand #2 : 0 indicates a debug label (e.g. stoppoint), 1 indicates
507 // a EH label, 2 indicates unknown label type.
510 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
511 // local variable declarations for debugging information. First operand is
512 // a chain, while the next two operands are first two arguments (address
513 // and variable) of a llvm.dbg.declare instruction.
516 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
517 // value, the same type as the pointer type for the system, and an output
521 // STACKRESTORE has two operands, an input chain and a pointer to restore to
522 // it returns an output chain.
525 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain. The following
526 // correspond to the operands of the LLVM intrinsic functions and the last
527 // one is AlwaysInline. The only result is a token chain. The alignment
528 // argument is guaranteed to be a Constant node.
533 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
534 // a call sequence, and carry arbitrary information that target might want
535 // to know. The first operand is a chain, the rest are specified by the
536 // target and not touched by the DAG optimizers.
537 // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
538 CALLSEQ_START, // Beginning of a call sequence
539 CALLSEQ_END, // End of a call sequence
541 // VAARG - VAARG has three operands: an input chain, a pointer, and a
542 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
545 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
546 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
550 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
551 // pointer, and a SRCVALUE.
554 // SRCVALUE - This is a node type that holds a Value* that is used to
555 // make reference to a value in the LLVM IR.
558 // MEMOPERAND - This is a node that contains a MemOperand which records
559 // information about a memory reference. This is used to make AliasAnalysis
560 // queries from the backend.
563 // PCMARKER - This corresponds to the pcmarker intrinsic.
566 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
567 // The only operand is a chain and a value and a chain are produced. The
568 // value is the contents of the architecture specific cycle counter like
569 // register (or other high accuracy low latency clock source)
572 // HANDLENODE node - Used as a handle for various purposes.
575 // LOCATION - This node is used to represent a source location for debug
576 // info. It takes token chain as input, then a line number, then a column
577 // number, then a filename, then a working dir. It produces a token chain
581 // DEBUG_LOC - This node is used to represent source line information
582 // embedded in the code. It takes a token chain as input, then a line
583 // number, then a column then a file id (provided by MachineModuleInfo.) It
584 // produces a token chain as output.
587 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
588 // It takes as input a token chain, the pointer to the trampoline,
589 // the pointer to the nested function, the pointer to pass for the
590 // 'nest' parameter, a SRCVALUE for the trampoline and another for
591 // the nested function (allowing targets to access the original
592 // Function*). It produces the result of the intrinsic and a token
596 // TRAP - Trapping instruction
599 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
600 // their first operand. The other operands are the address to prefetch,
601 // read / write specifier, and locality specifier.
604 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
605 // store-store, device)
606 // This corresponds to the memory.barrier intrinsic.
607 // it takes an input chain, 4 operands to specify the type of barrier, an
608 // operand specifying if the barrier applies to device and uncached memory
609 // and produces an output chain.
612 // Val, OUTCHAIN = ATOMIC_LCS(INCHAIN, ptr, cmp, swap)
613 // this corresponds to the atomic.lcs intrinsic.
614 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
615 // the return is always the original value in *ptr
618 // Val, OUTCHAIN = ATOMIC_LAS(INCHAIN, ptr, amt)
619 // this corresponds to the atomic.las intrinsic.
620 // *ptr + amt is stored to *ptr atomically.
621 // the return is always the original value in *ptr
624 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
625 // this corresponds to the atomic.swap intrinsic.
626 // amt is stored to *ptr atomically.
627 // the return is always the original value in *ptr
630 // BUILTIN_OP_END - This must be the last enum value in this list.
636 /// isBuildVectorAllOnes - Return true if the specified node is a
637 /// BUILD_VECTOR where all of the elements are ~0 or undef.
638 bool isBuildVectorAllOnes(const SDNode *N);
640 /// isBuildVectorAllZeros - Return true if the specified node is a
641 /// BUILD_VECTOR where all of the elements are 0 or undef.
642 bool isBuildVectorAllZeros(const SDNode *N);
644 /// isScalarToVector - Return true if the specified node is a
645 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
646 /// element is not an undef.
647 bool isScalarToVector(const SDNode *N);
649 /// isDebugLabel - Return true if the specified node represents a debug
650 /// label (i.e. ISD::LABEL or TargetInstrInfo::LABEL node and third operand
652 bool isDebugLabel(const SDNode *N);
654 //===--------------------------------------------------------------------===//
655 /// MemIndexedMode enum - This enum defines the load / store indexed
656 /// addressing modes.
658 /// UNINDEXED "Normal" load / store. The effective address is already
659 /// computed and is available in the base pointer. The offset
660 /// operand is always undefined. In addition to producing a
661 /// chain, an unindexed load produces one value (result of the
662 /// load); an unindexed store does not produces a value.
664 /// PRE_INC Similar to the unindexed mode where the effective address is
665 /// PRE_DEC the value of the base pointer add / subtract the offset.
666 /// It considers the computation as being folded into the load /
667 /// store operation (i.e. the load / store does the address
668 /// computation as well as performing the memory transaction).
669 /// The base operand is always undefined. In addition to
670 /// producing a chain, pre-indexed load produces two values
671 /// (result of the load and the result of the address
672 /// computation); a pre-indexed store produces one value (result
673 /// of the address computation).
675 /// POST_INC The effective address is the value of the base pointer. The
676 /// POST_DEC value of the offset operand is then added to / subtracted
677 /// from the base after memory transaction. In addition to
678 /// producing a chain, post-indexed load produces two values
679 /// (the result of the load and the result of the base +/- offset
680 /// computation); a post-indexed store produces one value (the
681 /// the result of the base +/- offset computation).
683 enum MemIndexedMode {
692 //===--------------------------------------------------------------------===//
693 /// LoadExtType enum - This enum defines the three variants of LOADEXT
694 /// (load with extension).
696 /// SEXTLOAD loads the integer operand and sign extends it to a larger
697 /// integer result type.
698 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
699 /// integer result type.
700 /// EXTLOAD is used for three things: floating point extending loads,
701 /// integer extending loads [the top bits are undefined], and vector
702 /// extending loads [load into low elt].
712 //===--------------------------------------------------------------------===//
713 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
714 /// below work out, when considering SETFALSE (something that never exists
715 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
716 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
717 /// to. If the "N" column is 1, the result of the comparison is undefined if
718 /// the input is a NAN.
720 /// All of these (except for the 'always folded ops') should be handled for
721 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
722 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
724 /// Note that these are laid out in a specific order to allow bit-twiddling
725 /// to transform conditions.
727 // Opcode N U L G E Intuitive operation
728 SETFALSE, // 0 0 0 0 Always false (always folded)
729 SETOEQ, // 0 0 0 1 True if ordered and equal
730 SETOGT, // 0 0 1 0 True if ordered and greater than
731 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
732 SETOLT, // 0 1 0 0 True if ordered and less than
733 SETOLE, // 0 1 0 1 True if ordered and less than or equal
734 SETONE, // 0 1 1 0 True if ordered and operands are unequal
735 SETO, // 0 1 1 1 True if ordered (no nans)
736 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
737 SETUEQ, // 1 0 0 1 True if unordered or equal
738 SETUGT, // 1 0 1 0 True if unordered or greater than
739 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
740 SETULT, // 1 1 0 0 True if unordered or less than
741 SETULE, // 1 1 0 1 True if unordered, less than, or equal
742 SETUNE, // 1 1 1 0 True if unordered or not equal
743 SETTRUE, // 1 1 1 1 Always true (always folded)
744 // Don't care operations: undefined if the input is a nan.
745 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
746 SETEQ, // 1 X 0 0 1 True if equal
747 SETGT, // 1 X 0 1 0 True if greater than
748 SETGE, // 1 X 0 1 1 True if greater than or equal
749 SETLT, // 1 X 1 0 0 True if less than
750 SETLE, // 1 X 1 0 1 True if less than or equal
751 SETNE, // 1 X 1 1 0 True if not equal
752 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
754 SETCC_INVALID // Marker value.
757 /// isSignedIntSetCC - Return true if this is a setcc instruction that
758 /// performs a signed comparison when used with integer operands.
759 inline bool isSignedIntSetCC(CondCode Code) {
760 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
763 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
764 /// performs an unsigned comparison when used with integer operands.
765 inline bool isUnsignedIntSetCC(CondCode Code) {
766 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
769 /// isTrueWhenEqual - Return true if the specified condition returns true if
770 /// the two operands to the condition are equal. Note that if one of the two
771 /// operands is a NaN, this value is meaningless.
772 inline bool isTrueWhenEqual(CondCode Cond) {
773 return ((int)Cond & 1) != 0;
776 /// getUnorderedFlavor - This function returns 0 if the condition is always
777 /// false if an operand is a NaN, 1 if the condition is always true if the
778 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
780 inline unsigned getUnorderedFlavor(CondCode Cond) {
781 return ((int)Cond >> 3) & 3;
784 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
785 /// 'op' is a valid SetCC operation.
786 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
788 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
789 /// when given the operation for (X op Y).
790 CondCode getSetCCSwappedOperands(CondCode Operation);
792 /// getSetCCOrOperation - Return the result of a logical OR between different
793 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
794 /// function returns SETCC_INVALID if it is not possible to represent the
795 /// resultant comparison.
796 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
798 /// getSetCCAndOperation - Return the result of a logical AND between
799 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
800 /// function returns SETCC_INVALID if it is not possible to represent the
801 /// resultant comparison.
802 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
803 } // end llvm::ISD namespace
806 //===----------------------------------------------------------------------===//
807 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
808 /// values as the result of a computation. Many nodes return multiple values,
809 /// from loads (which define a token and a return value) to ADDC (which returns
810 /// a result and a carry value), to calls (which may return an arbitrary number
813 /// As such, each use of a SelectionDAG computation must indicate the node that
814 /// computes it as well as which return value to use from that node. This pair
815 /// of information is represented with the SDOperand value type.
819 SDNode *Val; // The node defining the value we are using.
820 unsigned ResNo; // Which return value of the node we are using.
822 SDOperand() : Val(0), ResNo(0) {}
823 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
825 bool operator==(const SDOperand &O) const {
826 return Val == O.Val && ResNo == O.ResNo;
828 bool operator!=(const SDOperand &O) const {
829 return !operator==(O);
831 bool operator<(const SDOperand &O) const {
832 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
835 SDOperand getValue(unsigned R) const {
836 return SDOperand(Val, R);
839 // isOperandOf - Return true if this node is an operand of N.
840 bool isOperandOf(SDNode *N) const;
842 /// getValueType - Return the ValueType of the referenced return value.
844 inline MVT::ValueType getValueType() const;
846 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType()).
848 unsigned getValueSizeInBits() const {
849 return MVT::getSizeInBits(getValueType());
852 // Forwarding methods - These forward to the corresponding methods in SDNode.
853 inline unsigned getOpcode() const;
854 inline unsigned getNumOperands() const;
855 inline const SDOperand &getOperand(unsigned i) const;
856 inline uint64_t getConstantOperandVal(unsigned i) const;
857 inline bool isTargetOpcode() const;
858 inline unsigned getTargetOpcode() const;
861 /// reachesChainWithoutSideEffects - Return true if this operand (which must
862 /// be a chain) reaches the specified operand without crossing any
863 /// side-effecting instructions. In practice, this looks through token
864 /// factors and non-volatile loads. In order to remain efficient, this only
865 /// looks a couple of nodes in, it does not do an exhaustive search.
866 bool reachesChainWithoutSideEffects(SDOperand Dest, unsigned Depth = 2) const;
868 /// hasOneUse - Return true if there is exactly one operation using this
869 /// result value of the defining operator.
870 inline bool hasOneUse() const;
872 /// use_empty - Return true if there are no operations using this
873 /// result value of the defining operator.
874 inline bool use_empty() const;
878 template<> struct DenseMapInfo<SDOperand> {
879 static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); }
880 static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);}
881 static unsigned getHashValue(const SDOperand &Val) {
882 return ((unsigned)((uintptr_t)Val.Val >> 4) ^
883 (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo;
885 static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
888 static bool isPod() { return true; }
891 /// simplify_type specializations - Allow casting operators to work directly on
892 /// SDOperands as if they were SDNode*'s.
893 template<> struct simplify_type<SDOperand> {
894 typedef SDNode* SimpleType;
895 static SimpleType getSimplifiedValue(const SDOperand &Val) {
896 return static_cast<SimpleType>(Val.Val);
899 template<> struct simplify_type<const SDOperand> {
900 typedef SDNode* SimpleType;
901 static SimpleType getSimplifiedValue(const SDOperand &Val) {
902 return static_cast<SimpleType>(Val.Val);
907 /// SDNode - Represents one node in the SelectionDAG.
909 class SDNode : public FoldingSetNode {
910 /// NodeType - The operation that this node performs.
912 unsigned short NodeType;
914 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
915 /// then they will be delete[]'d when the node is destroyed.
916 bool OperandsNeedDelete : 1;
918 /// NodeId - Unique id per SDNode in the DAG.
921 /// OperandList - The values that are used by this operation.
923 SDOperand *OperandList;
925 /// ValueList - The types of the values this node defines. SDNode's may
926 /// define multiple values simultaneously.
927 const MVT::ValueType *ValueList;
929 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
930 unsigned short NumOperands, NumValues;
932 /// Prev/Next pointers - These pointers form the linked list of of the
933 /// AllNodes list in the current DAG.
935 friend struct ilist_traits<SDNode>;
937 /// Uses - These are all of the SDNode's that use a value produced by this
939 SmallVector<SDNode*,3> Uses;
941 // Out-of-line virtual method to give class a home.
942 virtual void ANCHOR();
945 assert(NumOperands == 0 && "Operand list not cleared before deletion");
946 NodeType = ISD::DELETED_NODE;
949 //===--------------------------------------------------------------------===//
952 unsigned getOpcode() const { return NodeType; }
953 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
954 unsigned getTargetOpcode() const {
955 assert(isTargetOpcode() && "Not a target opcode!");
956 return NodeType - ISD::BUILTIN_OP_END;
959 size_t use_size() const { return Uses.size(); }
960 bool use_empty() const { return Uses.empty(); }
961 bool hasOneUse() const { return Uses.size() == 1; }
963 /// getNodeId - Return the unique node id.
965 int getNodeId() const { return NodeId; }
967 /// setNodeId - Set unique node id.
968 void setNodeId(int Id) { NodeId = Id; }
970 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
971 use_iterator use_begin() const { return Uses.begin(); }
972 use_iterator use_end() const { return Uses.end(); }
974 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
975 /// indicated value. This method ignores uses of other values defined by this
977 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
979 /// hasAnyUseOfValue - Return true if there are any use of the indicated
980 /// value. This method ignores uses of other values defined by this operation.
981 bool hasAnyUseOfValue(unsigned Value) const;
983 /// isOnlyUseOf - Return true if this node is the only use of N.
985 bool isOnlyUseOf(SDNode *N) const;
987 /// isOperandOf - Return true if this node is an operand of N.
989 bool isOperandOf(SDNode *N) const;
991 /// isPredecessorOf - Return true if this node is a predecessor of N. This
992 /// node is either an operand of N or it can be reached by recursively
993 /// traversing up the operands.
994 /// NOTE: this is an expensive method. Use it carefully.
995 bool isPredecessorOf(SDNode *N) const;
997 /// getNumOperands - Return the number of values used by this operation.
999 unsigned getNumOperands() const { return NumOperands; }
1001 /// getConstantOperandVal - Helper method returns the integer value of a
1002 /// ConstantSDNode operand.
1003 uint64_t getConstantOperandVal(unsigned Num) const;
1005 const SDOperand &getOperand(unsigned Num) const {
1006 assert(Num < NumOperands && "Invalid child # of SDNode!");
1007 return OperandList[Num];
1010 typedef const SDOperand* op_iterator;
1011 op_iterator op_begin() const { return OperandList; }
1012 op_iterator op_end() const { return OperandList+NumOperands; }
1015 SDVTList getVTList() const {
1016 SDVTList X = { ValueList, NumValues };
1020 /// getNumValues - Return the number of values defined/returned by this
1023 unsigned getNumValues() const { return NumValues; }
1025 /// getValueType - Return the type of a specified result.
1027 MVT::ValueType getValueType(unsigned ResNo) const {
1028 assert(ResNo < NumValues && "Illegal result number!");
1029 return ValueList[ResNo];
1032 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1034 unsigned getValueSizeInBits(unsigned ResNo) const {
1035 return MVT::getSizeInBits(getValueType(ResNo));
1038 typedef const MVT::ValueType* value_iterator;
1039 value_iterator value_begin() const { return ValueList; }
1040 value_iterator value_end() const { return ValueList+NumValues; }
1042 /// getOperationName - Return the opcode of this operation for printing.
1044 std::string getOperationName(const SelectionDAG *G = 0) const;
1045 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1047 void dump(const SelectionDAG *G) const;
1049 static bool classof(const SDNode *) { return true; }
1051 /// Profile - Gather unique data for the node.
1053 void Profile(FoldingSetNodeID &ID);
1056 friend class SelectionDAG;
1058 /// getValueTypeList - Return a pointer to the specified value type.
1060 static const MVT::ValueType *getValueTypeList(MVT::ValueType VT);
1061 static SDVTList getSDVTList(MVT::ValueType VT) {
1062 SDVTList Ret = { getValueTypeList(VT), 1 };
1066 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
1067 : NodeType(Opc), NodeId(-1) {
1068 OperandsNeedDelete = true;
1069 NumOperands = NumOps;
1070 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
1072 for (unsigned i = 0; i != NumOps; ++i) {
1073 OperandList[i] = Ops[i];
1074 Ops[i].Val->Uses.push_back(this);
1077 ValueList = VTs.VTs;
1078 NumValues = VTs.NumVTs;
1081 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
1082 OperandsNeedDelete = false; // Operands set with InitOperands.
1086 ValueList = VTs.VTs;
1087 NumValues = VTs.NumVTs;
1091 /// InitOperands - Initialize the operands list of this node with the
1092 /// specified values, which are part of the node (thus they don't need to be
1093 /// copied in or allocated).
1094 void InitOperands(SDOperand *Ops, unsigned NumOps) {
1095 assert(OperandList == 0 && "Operands already set!");
1096 NumOperands = NumOps;
1099 for (unsigned i = 0; i != NumOps; ++i)
1100 Ops[i].Val->Uses.push_back(this);
1103 /// MorphNodeTo - This frees the operands of the current node, resets the
1104 /// opcode, types, and operands to the specified value. This should only be
1105 /// used by the SelectionDAG class.
1106 void MorphNodeTo(unsigned Opc, SDVTList L,
1107 const SDOperand *Ops, unsigned NumOps);
1109 void addUser(SDNode *User) {
1110 Uses.push_back(User);
1112 void removeUser(SDNode *User) {
1113 // Remove this user from the operand's use list.
1114 for (unsigned i = Uses.size(); ; --i) {
1115 assert(i != 0 && "Didn't find user!");
1116 if (Uses[i-1] == User) {
1117 Uses[i-1] = Uses.back();
1126 // Define inline functions from the SDOperand class.
1128 inline unsigned SDOperand::getOpcode() const {
1129 return Val->getOpcode();
1131 inline MVT::ValueType SDOperand::getValueType() const {
1132 return Val->getValueType(ResNo);
1134 inline unsigned SDOperand::getNumOperands() const {
1135 return Val->getNumOperands();
1137 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1138 return Val->getOperand(i);
1140 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1141 return Val->getConstantOperandVal(i);
1143 inline bool SDOperand::isTargetOpcode() const {
1144 return Val->isTargetOpcode();
1146 inline unsigned SDOperand::getTargetOpcode() const {
1147 return Val->getTargetOpcode();
1149 inline bool SDOperand::hasOneUse() const {
1150 return Val->hasNUsesOfValue(1, ResNo);
1152 inline bool SDOperand::use_empty() const {
1153 return !Val->hasAnyUseOfValue(ResNo);
1156 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1157 /// to allow co-allocation of node operands with the node itself.
1158 class UnarySDNode : public SDNode {
1159 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1162 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1163 : SDNode(Opc, VTs), Op(X) {
1164 InitOperands(&Op, 1);
1168 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1169 /// to allow co-allocation of node operands with the node itself.
1170 class BinarySDNode : public SDNode {
1171 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1174 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1175 : SDNode(Opc, VTs) {
1178 InitOperands(Ops, 2);
1182 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1183 /// to allow co-allocation of node operands with the node itself.
1184 class TernarySDNode : public SDNode {
1185 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1188 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1190 : SDNode(Opc, VTs) {
1194 InitOperands(Ops, 3);
1199 /// HandleSDNode - This class is used to form a handle around another node that
1200 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1201 /// operand. This node should be directly created by end-users and not added to
1202 /// the AllNodes list.
1203 class HandleSDNode : public SDNode {
1204 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1207 explicit HandleSDNode(SDOperand X)
1208 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1209 InitOperands(&Op, 1);
1212 SDOperand getValue() const { return Op; }
1215 class AtomicSDNode : public SDNode {
1216 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1218 MVT::ValueType OrigVT;
1220 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1221 SDOperand Cmp, SDOperand Swp, MVT::ValueType VT)
1222 : SDNode(Opc, VTL) {
1227 InitOperands(Ops, 4);
1230 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1231 SDOperand Val, MVT::ValueType VT)
1232 : SDNode(Opc, VTL) {
1236 InitOperands(Ops, 3);
1239 MVT::ValueType getVT() const { return OrigVT; }
1240 bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_LCS; }
1243 class StringSDNode : public SDNode {
1245 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1247 friend class SelectionDAG;
1248 explicit StringSDNode(const std::string &val)
1249 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1252 const std::string &getValue() const { return Value; }
1253 static bool classof(const StringSDNode *) { return true; }
1254 static bool classof(const SDNode *N) {
1255 return N->getOpcode() == ISD::STRING;
1259 class ConstantSDNode : public SDNode {
1261 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1263 friend class SelectionDAG;
1264 ConstantSDNode(bool isTarget, const APInt &val, MVT::ValueType VT)
1265 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1270 const APInt &getAPIntValue() const { return Value; }
1271 uint64_t getValue() const { return Value.getZExtValue(); }
1273 int64_t getSignExtended() const {
1274 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1275 return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1278 bool isNullValue() const { return Value == 0; }
1279 bool isAllOnesValue() const {
1280 return Value == MVT::getIntVTBitMask(getValueType(0));
1283 static bool classof(const ConstantSDNode *) { return true; }
1284 static bool classof(const SDNode *N) {
1285 return N->getOpcode() == ISD::Constant ||
1286 N->getOpcode() == ISD::TargetConstant;
1290 class ConstantFPSDNode : public SDNode {
1292 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1294 friend class SelectionDAG;
1295 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT)
1296 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1297 getSDVTList(VT)), Value(val) {
1301 const APFloat& getValueAPF() const { return Value; }
1303 /// isExactlyValue - We don't rely on operator== working on double values, as
1304 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1305 /// As such, this method can be used to do an exact bit-for-bit comparison of
1306 /// two floating point values.
1308 /// We leave the version with the double argument here because it's just so
1309 /// convenient to write "2.0" and the like. Without this function we'd
1310 /// have to duplicate its logic everywhere it's called.
1311 bool isExactlyValue(double V) const {
1313 Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1314 return isExactlyValue(Tmp);
1316 bool isExactlyValue(const APFloat& V) const;
1318 bool isValueValidForType(MVT::ValueType VT, const APFloat& Val);
1320 static bool classof(const ConstantFPSDNode *) { return true; }
1321 static bool classof(const SDNode *N) {
1322 return N->getOpcode() == ISD::ConstantFP ||
1323 N->getOpcode() == ISD::TargetConstantFP;
1327 class GlobalAddressSDNode : public SDNode {
1328 GlobalValue *TheGlobal;
1330 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1332 friend class SelectionDAG;
1333 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1337 GlobalValue *getGlobal() const { return TheGlobal; }
1338 int getOffset() const { return Offset; }
1340 static bool classof(const GlobalAddressSDNode *) { return true; }
1341 static bool classof(const SDNode *N) {
1342 return N->getOpcode() == ISD::GlobalAddress ||
1343 N->getOpcode() == ISD::TargetGlobalAddress ||
1344 N->getOpcode() == ISD::GlobalTLSAddress ||
1345 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1349 class FrameIndexSDNode : public SDNode {
1351 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1353 friend class SelectionDAG;
1354 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1355 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1360 int getIndex() const { return FI; }
1362 static bool classof(const FrameIndexSDNode *) { return true; }
1363 static bool classof(const SDNode *N) {
1364 return N->getOpcode() == ISD::FrameIndex ||
1365 N->getOpcode() == ISD::TargetFrameIndex;
1369 class JumpTableSDNode : public SDNode {
1371 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1373 friend class SelectionDAG;
1374 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1375 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1380 int getIndex() const { return JTI; }
1382 static bool classof(const JumpTableSDNode *) { return true; }
1383 static bool classof(const SDNode *N) {
1384 return N->getOpcode() == ISD::JumpTable ||
1385 N->getOpcode() == ISD::TargetJumpTable;
1389 class ConstantPoolSDNode : public SDNode {
1392 MachineConstantPoolValue *MachineCPVal;
1394 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1396 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1398 friend class SelectionDAG;
1399 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1401 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1402 getSDVTList(VT)), Offset(o), Alignment(0) {
1403 assert((int)Offset >= 0 && "Offset is too large");
1406 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1408 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1409 getSDVTList(VT)), Offset(o), Alignment(Align) {
1410 assert((int)Offset >= 0 && "Offset is too large");
1413 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1414 MVT::ValueType VT, int o=0)
1415 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1416 getSDVTList(VT)), Offset(o), Alignment(0) {
1417 assert((int)Offset >= 0 && "Offset is too large");
1418 Val.MachineCPVal = v;
1419 Offset |= 1 << (sizeof(unsigned)*8-1);
1421 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1422 MVT::ValueType VT, int o, unsigned Align)
1423 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1424 getSDVTList(VT)), Offset(o), Alignment(Align) {
1425 assert((int)Offset >= 0 && "Offset is too large");
1426 Val.MachineCPVal = v;
1427 Offset |= 1 << (sizeof(unsigned)*8-1);
1431 bool isMachineConstantPoolEntry() const {
1432 return (int)Offset < 0;
1435 Constant *getConstVal() const {
1436 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1437 return Val.ConstVal;
1440 MachineConstantPoolValue *getMachineCPVal() const {
1441 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1442 return Val.MachineCPVal;
1445 int getOffset() const {
1446 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1449 // Return the alignment of this constant pool object, which is either 0 (for
1450 // default alignment) or log2 of the desired value.
1451 unsigned getAlignment() const { return Alignment; }
1453 const Type *getType() const;
1455 static bool classof(const ConstantPoolSDNode *) { return true; }
1456 static bool classof(const SDNode *N) {
1457 return N->getOpcode() == ISD::ConstantPool ||
1458 N->getOpcode() == ISD::TargetConstantPool;
1462 class BasicBlockSDNode : public SDNode {
1463 MachineBasicBlock *MBB;
1464 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1466 friend class SelectionDAG;
1467 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1468 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1472 MachineBasicBlock *getBasicBlock() const { return MBB; }
1474 static bool classof(const BasicBlockSDNode *) { return true; }
1475 static bool classof(const SDNode *N) {
1476 return N->getOpcode() == ISD::BasicBlock;
1480 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1481 /// used when the SelectionDAG needs to make a simple reference to something
1482 /// in the LLVM IR representation.
1484 /// Note that this is not used for carrying alias information; that is done
1485 /// with MemOperandSDNode, which includes a Value which is required to be a
1486 /// pointer, and several other fields specific to memory references.
1488 class SrcValueSDNode : public SDNode {
1490 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1492 friend class SelectionDAG;
1493 /// Create a SrcValue for a general value.
1494 explicit SrcValueSDNode(const Value *v)
1495 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1498 /// getValue - return the contained Value.
1499 const Value *getValue() const { return V; }
1501 static bool classof(const SrcValueSDNode *) { return true; }
1502 static bool classof(const SDNode *N) {
1503 return N->getOpcode() == ISD::SRCVALUE;
1508 /// MemOperandSDNode - An SDNode that holds a MemOperand. This is
1509 /// used to represent a reference to memory after ISD::LOAD
1510 /// and ISD::STORE have been lowered.
1512 class MemOperandSDNode : public SDNode {
1513 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1515 friend class SelectionDAG;
1516 /// Create a MemOperand node
1517 explicit MemOperandSDNode(const MemOperand &mo)
1518 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1521 /// MO - The contained MemOperand.
1522 const MemOperand MO;
1524 static bool classof(const MemOperandSDNode *) { return true; }
1525 static bool classof(const SDNode *N) {
1526 return N->getOpcode() == ISD::MEMOPERAND;
1531 class RegisterSDNode : public SDNode {
1533 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1535 friend class SelectionDAG;
1536 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1537 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1541 unsigned getReg() const { return Reg; }
1543 static bool classof(const RegisterSDNode *) { return true; }
1544 static bool classof(const SDNode *N) {
1545 return N->getOpcode() == ISD::Register;
1549 class ExternalSymbolSDNode : public SDNode {
1551 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1553 friend class SelectionDAG;
1554 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1555 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1556 getSDVTList(VT)), Symbol(Sym) {
1560 const char *getSymbol() const { return Symbol; }
1562 static bool classof(const ExternalSymbolSDNode *) { return true; }
1563 static bool classof(const SDNode *N) {
1564 return N->getOpcode() == ISD::ExternalSymbol ||
1565 N->getOpcode() == ISD::TargetExternalSymbol;
1569 class CondCodeSDNode : public SDNode {
1570 ISD::CondCode Condition;
1571 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1573 friend class SelectionDAG;
1574 explicit CondCodeSDNode(ISD::CondCode Cond)
1575 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1579 ISD::CondCode get() const { return Condition; }
1581 static bool classof(const CondCodeSDNode *) { return true; }
1582 static bool classof(const SDNode *N) {
1583 return N->getOpcode() == ISD::CONDCODE;
1587 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1588 /// to parameterize some operations.
1589 class VTSDNode : public SDNode {
1590 MVT::ValueType ValueType;
1591 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1593 friend class SelectionDAG;
1594 explicit VTSDNode(MVT::ValueType VT)
1595 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1599 MVT::ValueType getVT() const { return ValueType; }
1601 static bool classof(const VTSDNode *) { return true; }
1602 static bool classof(const SDNode *N) {
1603 return N->getOpcode() == ISD::VALUETYPE;
1607 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1609 class LSBaseSDNode : public SDNode {
1611 // AddrMode - unindexed, pre-indexed, post-indexed.
1612 ISD::MemIndexedMode AddrMode;
1614 // MemoryVT - VT of in-memory value.
1615 MVT::ValueType MemoryVT;
1617 //! SrcValue - Memory location for alias analysis.
1618 const Value *SrcValue;
1620 //! SVOffset - Memory location offset.
1623 //! Alignment - Alignment of memory location in bytes.
1626 //! IsVolatile - True if the store is volatile.
1629 //! Operand array for load and store
1631 \note Moving this array to the base class captures more
1632 common functionality shared between LoadSDNode and
1637 LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned NumOperands,
1638 SDVTList VTs, ISD::MemIndexedMode AM, MVT::ValueType VT,
1639 const Value *SV, int SVO, unsigned Align, bool Vol)
1640 : SDNode(NodeTy, VTs),
1641 AddrMode(AM), MemoryVT(VT),
1642 SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol) {
1643 for (unsigned i = 0; i != NumOperands; ++i)
1644 Ops[i] = Operands[i];
1645 InitOperands(Ops, NumOperands);
1646 assert(Align != 0 && "Loads and stores should have non-zero aligment");
1647 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1648 "Only indexed loads and stores have a non-undef offset operand");
1651 const SDOperand &getChain() const { return getOperand(0); }
1652 const SDOperand &getBasePtr() const {
1653 return getOperand(getOpcode() == ISD::LOAD ? 1 : 2);
1655 const SDOperand &getOffset() const {
1656 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1659 const Value *getSrcValue() const { return SrcValue; }
1660 int getSrcValueOffset() const { return SVOffset; }
1661 unsigned getAlignment() const { return Alignment; }
1662 MVT::ValueType getMemoryVT() const { return MemoryVT; }
1663 bool isVolatile() const { return IsVolatile; }
1665 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1667 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1668 bool isIndexed() const { return AddrMode != ISD::UNINDEXED; }
1670 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1671 bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; }
1673 /// getMemOperand - Return a MemOperand object describing the memory
1674 /// reference performed by this load or store.
1675 MemOperand getMemOperand() const;
1677 static bool classof(const LSBaseSDNode *N) { return true; }
1678 static bool classof(const SDNode *N) {
1679 return N->getOpcode() == ISD::LOAD ||
1680 N->getOpcode() == ISD::STORE;
1684 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1686 class LoadSDNode : public LSBaseSDNode {
1687 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1689 // ExtType - non-ext, anyext, sext, zext.
1690 ISD::LoadExtType ExtType;
1693 friend class SelectionDAG;
1694 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1695 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1696 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1697 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
1698 VTs, AM, LVT, SV, O, Align, Vol),
1702 ISD::LoadExtType getExtensionType() const { return ExtType; }
1703 const SDOperand &getBasePtr() const { return getOperand(1); }
1704 const SDOperand &getOffset() const { return getOperand(2); }
1706 static bool classof(const LoadSDNode *) { return true; }
1707 static bool classof(const SDNode *N) {
1708 return N->getOpcode() == ISD::LOAD;
1712 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1714 class StoreSDNode : public LSBaseSDNode {
1715 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1717 // IsTruncStore - True if the op does a truncation before store.
1720 friend class SelectionDAG;
1721 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1722 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1723 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1724 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
1725 VTs, AM, SVT, SV, O, Align, Vol),
1726 IsTruncStore(isTrunc) {}
1729 bool isTruncatingStore() const { return IsTruncStore; }
1730 const SDOperand &getValue() const { return getOperand(1); }
1731 const SDOperand &getBasePtr() const { return getOperand(2); }
1732 const SDOperand &getOffset() const { return getOperand(3); }
1734 static bool classof(const StoreSDNode *) { return true; }
1735 static bool classof(const SDNode *N) {
1736 return N->getOpcode() == ISD::STORE;
1741 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1745 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1747 bool operator==(const SDNodeIterator& x) const {
1748 return Operand == x.Operand;
1750 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1752 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1753 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1754 Operand = I.Operand;
1758 pointer operator*() const {
1759 return Node->getOperand(Operand).Val;
1761 pointer operator->() const { return operator*(); }
1763 SDNodeIterator& operator++() { // Preincrement
1767 SDNodeIterator operator++(int) { // Postincrement
1768 SDNodeIterator tmp = *this; ++*this; return tmp;
1771 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1772 static SDNodeIterator end (SDNode *N) {
1773 return SDNodeIterator(N, N->getNumOperands());
1776 unsigned getOperand() const { return Operand; }
1777 const SDNode *getNode() const { return Node; }
1780 template <> struct GraphTraits<SDNode*> {
1781 typedef SDNode NodeType;
1782 typedef SDNodeIterator ChildIteratorType;
1783 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1784 static inline ChildIteratorType child_begin(NodeType *N) {
1785 return SDNodeIterator::begin(N);
1787 static inline ChildIteratorType child_end(NodeType *N) {
1788 return SDNodeIterator::end(N);
1793 struct ilist_traits<SDNode> {
1794 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1795 static SDNode *getNext(const SDNode *N) { return N->Next; }
1797 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1798 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1800 static SDNode *createSentinel() {
1801 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1803 static void destroySentinel(SDNode *N) { delete N; }
1804 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1807 void addNodeToList(SDNode *NTy) {}
1808 void removeNodeFromList(SDNode *NTy) {}
1809 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1810 const ilist_iterator<SDNode> &X,
1811 const ilist_iterator<SDNode> &Y) {}
1815 /// isNormalLoad - Returns true if the specified node is a non-extending
1816 /// and unindexed load.
1817 inline bool isNormalLoad(const SDNode *N) {
1818 if (N->getOpcode() != ISD::LOAD)
1820 const LoadSDNode *Ld = cast<LoadSDNode>(N);
1821 return Ld->getExtensionType() == ISD::NON_EXTLOAD &&
1822 Ld->getAddressingMode() == ISD::UNINDEXED;
1825 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1827 inline bool isNON_EXTLoad(const SDNode *N) {
1828 return N->getOpcode() == ISD::LOAD &&
1829 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1832 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1834 inline bool isEXTLoad(const SDNode *N) {
1835 return N->getOpcode() == ISD::LOAD &&
1836 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1839 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1841 inline bool isSEXTLoad(const SDNode *N) {
1842 return N->getOpcode() == ISD::LOAD &&
1843 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1846 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1848 inline bool isZEXTLoad(const SDNode *N) {
1849 return N->getOpcode() == ISD::LOAD &&
1850 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1853 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1855 inline bool isUNINDEXEDLoad(const SDNode *N) {
1856 return N->getOpcode() == ISD::LOAD &&
1857 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1860 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1862 inline bool isNON_TRUNCStore(const SDNode *N) {
1863 return N->getOpcode() == ISD::STORE &&
1864 !cast<StoreSDNode>(N)->isTruncatingStore();
1867 /// isTRUNCStore - Returns true if the specified node is a truncating
1869 inline bool isTRUNCStore(const SDNode *N) {
1870 return N->getOpcode() == ISD::STORE &&
1871 cast<StoreSDNode>(N)->isTruncatingStore();
1876 } // end llvm namespace