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 first or second (determined by
221 // a Constant, which is required to be operand #1), element of the aggregate
222 // value specified as operand #0. This is only for use before legalization,
223 // for 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.
325 // INSERT_SUBREG - This node is used to insert a sub-register value.
326 // This node takes a superreg, a subreg value, and a constant sub-register
327 // index as operands.
330 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
331 // an unsigned/signed value of type i[2*N], then return the top part.
334 // Bitwise operators - logical and, logical or, logical xor, shift left,
335 // shift right algebraic (shift in sign bits), shift right logical (shift in
336 // zeroes), rotate left, rotate right, and byteswap.
337 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
339 // Counting operators
342 // Select(COND, TRUEVAL, FALSEVAL)
345 // Select with condition operator - This selects between a true value and
346 // a false value (ops #2 and #3) based on the boolean result of comparing
347 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
348 // condition code in op #4, a CondCodeSDNode.
351 // SetCC operator - This evaluates to a boolean (i1) true value if the
352 // condition is true. The operands to this are the left and right operands
353 // to compare (ops #0, and #1) and the condition code to compare them with
354 // (op #2) as a CondCodeSDNode.
357 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
358 // integer shift operations, just like ADD/SUB_PARTS. The operation
360 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
361 SHL_PARTS, SRA_PARTS, SRL_PARTS,
363 // Conversion operators. These are all single input single output
364 // operations. For all of these, the result type must be strictly
365 // wider or narrower (depending on the operation) than the source
368 // SIGN_EXTEND - Used for integer types, replicating the sign bit
372 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
375 // ANY_EXTEND - Used for integer types. The high bits are undefined.
378 // TRUNCATE - Completely drop the high bits.
381 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
382 // depends on the first letter) to floating point.
386 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
387 // sign extend a small value in a large integer register (e.g. sign
388 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
389 // with the 7th bit). The size of the smaller type is indicated by the 1th
390 // operand, a ValueType node.
393 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
398 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
399 /// down to the precision of the destination VT. TRUNC is a flag, which is
400 /// always an integer that is zero or one. If TRUNC is 0, this is a
401 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
404 /// The TRUNC = 1 case is used in cases where we know that the value will
405 /// not be modified by the node, because Y is not using any of the extra
406 /// precision of source type. This allows certain transformations like
407 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
408 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
411 // FLT_ROUNDS_ - Returns current rounding mode:
414 // 1 Round to nearest
419 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
420 /// rounds it to a floating point value. It then promotes it and returns it
421 /// in a register of the same size. This operation effectively just
422 /// discards excess precision. The type to round down to is specified by
423 /// the VT operand, a VTSDNode.
426 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
429 // BIT_CONVERT - Theis operator converts between integer and FP values, as
430 // if one was stored to memory as integer and the other was loaded from the
431 // same address (or equivalently for vector format conversions, etc). The
432 // source and result are required to have the same bit size (e.g.
433 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
434 // conversions, but that is a noop, deleted by getNode().
437 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
438 // negation, absolute value, square root, sine and cosine, powi, and pow
440 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
442 // LOAD and STORE have token chains as their first operand, then the same
443 // operands as an LLVM load/store instruction, then an offset node that
444 // is added / subtracted from the base pointer to form the address (for
445 // indexed memory ops).
448 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
449 // to a specified boundary. This node always has two return values: a new
450 // stack pointer value and a chain. The first operand is the token chain,
451 // the second is the number of bytes to allocate, and the third is the
452 // alignment boundary. The size is guaranteed to be a multiple of the stack
453 // alignment, and the alignment is guaranteed to be bigger than the stack
454 // alignment (if required) or 0 to get standard stack alignment.
457 // Control flow instructions. These all have token chains.
459 // BR - Unconditional branch. The first operand is the chain
460 // operand, the second is the MBB to branch to.
463 // BRIND - Indirect branch. The first operand is the chain, the second
464 // is the value to branch to, which must be of the same type as the target's
468 // BR_JT - Jumptable branch. The first operand is the chain, the second
469 // is the jumptable index, the last one is the jumptable entry index.
472 // BRCOND - Conditional branch. The first operand is the chain,
473 // the second is the condition, the third is the block to branch
474 // to if the condition is true.
477 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
478 // that the condition is represented as condition code, and two nodes to
479 // compare, rather than as a combined SetCC node. The operands in order are
480 // chain, cc, lhs, rhs, block to branch to if condition is true.
483 // RET - Return from function. The first operand is the chain,
484 // and any subsequent operands are pairs of return value and return value
485 // signness for the function. This operation can have variable number of
489 // INLINEASM - Represents an inline asm block. This node always has two
490 // return values: a chain and a flag result. The inputs are as follows:
491 // Operand #0 : Input chain.
492 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
493 // Operand #2n+2: A RegisterNode.
494 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
495 // Operand #last: Optional, an incoming flag.
498 // LABEL - Represents a label in mid basic block used to track
499 // locations needed for debug and exception handling tables. This node
501 // Operand #0 : input chain.
502 // Operand #1 : module unique number use to identify the label.
503 // Operand #2 : 0 indicates a debug label (e.g. stoppoint), 1 indicates
504 // a EH label, 2 indicates unknown label type.
507 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
508 // local variable declarations for debugging information. First operand is
509 // a chain, while the next two operands are first two arguments (address
510 // and variable) of a llvm.dbg.declare instruction.
513 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
514 // value, the same type as the pointer type for the system, and an output
518 // STACKRESTORE has two operands, an input chain and a pointer to restore to
519 // it returns an output chain.
522 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain. The following
523 // correspond to the operands of the LLVM intrinsic functions and the last
524 // one is AlwaysInline. The only result is a token chain. The alignment
525 // argument is guaranteed to be a Constant node.
530 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
531 // a call sequence, and carry arbitrary information that target might want
532 // to know. The first operand is a chain, the rest are specified by the
533 // target and not touched by the DAG optimizers.
534 // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
535 CALLSEQ_START, // Beginning of a call sequence
536 CALLSEQ_END, // End of a call sequence
538 // VAARG - VAARG has three operands: an input chain, a pointer, and a
539 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
542 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
543 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
547 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
548 // pointer, and a SRCVALUE.
551 // SRCVALUE - This is a node type that holds a Value* that is used to
552 // make reference to a value in the LLVM IR.
555 // MEMOPERAND - This is a node that contains a MemOperand which records
556 // information about a memory reference. This is used to make AliasAnalysis
557 // queries from the backend.
560 // PCMARKER - This corresponds to the pcmarker intrinsic.
563 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
564 // The only operand is a chain and a value and a chain are produced. The
565 // value is the contents of the architecture specific cycle counter like
566 // register (or other high accuracy low latency clock source)
569 // HANDLENODE node - Used as a handle for various purposes.
572 // LOCATION - This node is used to represent a source location for debug
573 // info. It takes token chain as input, then a line number, then a column
574 // number, then a filename, then a working dir. It produces a token chain
578 // DEBUG_LOC - This node is used to represent source line information
579 // embedded in the code. It takes a token chain as input, then a line
580 // number, then a column then a file id (provided by MachineModuleInfo.) It
581 // produces a token chain as output.
584 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
585 // It takes as input a token chain, the pointer to the trampoline,
586 // the pointer to the nested function, the pointer to pass for the
587 // 'nest' parameter, a SRCVALUE for the trampoline and another for
588 // the nested function (allowing targets to access the original
589 // Function*). It produces the result of the intrinsic and a token
593 // TRAP - Trapping instruction
596 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
597 // their first operand. The other operands are the address to prefetch,
598 // read / write specifier, and locality specifier.
601 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
602 // store-store, device)
603 // This corresponds to the memory.barrier intrinsic.
604 // it takes an input chain, 4 operands to specify the type of barrier, an
605 // operand specifying if the barrier applies to device and uncached memory
606 // and produces an output chain.
609 // Val, OUTCHAIN = ATOMIC_LCS(INCHAIN, ptr, cmp, swap)
610 // this corresponds to the atomic.lcs intrinsic.
611 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
612 // the return is always the original value in *ptr
615 // Val, OUTCHAIN = ATOMIC_LAS(INCHAIN, ptr, amt)
616 // this corresponds to the atomic.las intrinsic.
617 // *ptr + amt is stored to *ptr atomically.
618 // the return is always the original value in *ptr
621 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
622 // this corresponds to the atomic.swap intrinsic.
623 // amt is stored to *ptr atomically.
624 // the return is always the original value in *ptr
627 // BUILTIN_OP_END - This must be the last enum value in this list.
633 /// isBuildVectorAllOnes - Return true if the specified node is a
634 /// BUILD_VECTOR where all of the elements are ~0 or undef.
635 bool isBuildVectorAllOnes(const SDNode *N);
637 /// isBuildVectorAllZeros - Return true if the specified node is a
638 /// BUILD_VECTOR where all of the elements are 0 or undef.
639 bool isBuildVectorAllZeros(const SDNode *N);
641 /// isScalarToVector - Return true if the specified node is a
642 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
643 /// element is not an undef.
644 bool isScalarToVector(const SDNode *N);
646 /// isDebugLabel - Return true if the specified node represents a debug
647 /// label (i.e. ISD::LABEL or TargetInstrInfo::LABEL node and third operand
649 bool isDebugLabel(const SDNode *N);
651 //===--------------------------------------------------------------------===//
652 /// MemIndexedMode enum - This enum defines the load / store indexed
653 /// addressing modes.
655 /// UNINDEXED "Normal" load / store. The effective address is already
656 /// computed and is available in the base pointer. The offset
657 /// operand is always undefined. In addition to producing a
658 /// chain, an unindexed load produces one value (result of the
659 /// load); an unindexed store does not produces a value.
661 /// PRE_INC Similar to the unindexed mode where the effective address is
662 /// PRE_DEC the value of the base pointer add / subtract the offset.
663 /// It considers the computation as being folded into the load /
664 /// store operation (i.e. the load / store does the address
665 /// computation as well as performing the memory transaction).
666 /// The base operand is always undefined. In addition to
667 /// producing a chain, pre-indexed load produces two values
668 /// (result of the load and the result of the address
669 /// computation); a pre-indexed store produces one value (result
670 /// of the address computation).
672 /// POST_INC The effective address is the value of the base pointer. The
673 /// POST_DEC value of the offset operand is then added to / subtracted
674 /// from the base after memory transaction. In addition to
675 /// producing a chain, post-indexed load produces two values
676 /// (the result of the load and the result of the base +/- offset
677 /// computation); a post-indexed store produces one value (the
678 /// the result of the base +/- offset computation).
680 enum MemIndexedMode {
689 //===--------------------------------------------------------------------===//
690 /// LoadExtType enum - This enum defines the three variants of LOADEXT
691 /// (load with extension).
693 /// SEXTLOAD loads the integer operand and sign extends it to a larger
694 /// integer result type.
695 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
696 /// integer result type.
697 /// EXTLOAD is used for three things: floating point extending loads,
698 /// integer extending loads [the top bits are undefined], and vector
699 /// extending loads [load into low elt].
709 //===--------------------------------------------------------------------===//
710 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
711 /// below work out, when considering SETFALSE (something that never exists
712 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
713 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
714 /// to. If the "N" column is 1, the result of the comparison is undefined if
715 /// the input is a NAN.
717 /// All of these (except for the 'always folded ops') should be handled for
718 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
719 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
721 /// Note that these are laid out in a specific order to allow bit-twiddling
722 /// to transform conditions.
724 // Opcode N U L G E Intuitive operation
725 SETFALSE, // 0 0 0 0 Always false (always folded)
726 SETOEQ, // 0 0 0 1 True if ordered and equal
727 SETOGT, // 0 0 1 0 True if ordered and greater than
728 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
729 SETOLT, // 0 1 0 0 True if ordered and less than
730 SETOLE, // 0 1 0 1 True if ordered and less than or equal
731 SETONE, // 0 1 1 0 True if ordered and operands are unequal
732 SETO, // 0 1 1 1 True if ordered (no nans)
733 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
734 SETUEQ, // 1 0 0 1 True if unordered or equal
735 SETUGT, // 1 0 1 0 True if unordered or greater than
736 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
737 SETULT, // 1 1 0 0 True if unordered or less than
738 SETULE, // 1 1 0 1 True if unordered, less than, or equal
739 SETUNE, // 1 1 1 0 True if unordered or not equal
740 SETTRUE, // 1 1 1 1 Always true (always folded)
741 // Don't care operations: undefined if the input is a nan.
742 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
743 SETEQ, // 1 X 0 0 1 True if equal
744 SETGT, // 1 X 0 1 0 True if greater than
745 SETGE, // 1 X 0 1 1 True if greater than or equal
746 SETLT, // 1 X 1 0 0 True if less than
747 SETLE, // 1 X 1 0 1 True if less than or equal
748 SETNE, // 1 X 1 1 0 True if not equal
749 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
751 SETCC_INVALID // Marker value.
754 /// isSignedIntSetCC - Return true if this is a setcc instruction that
755 /// performs a signed comparison when used with integer operands.
756 inline bool isSignedIntSetCC(CondCode Code) {
757 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
760 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
761 /// performs an unsigned comparison when used with integer operands.
762 inline bool isUnsignedIntSetCC(CondCode Code) {
763 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
766 /// isTrueWhenEqual - Return true if the specified condition returns true if
767 /// the two operands to the condition are equal. Note that if one of the two
768 /// operands is a NaN, this value is meaningless.
769 inline bool isTrueWhenEqual(CondCode Cond) {
770 return ((int)Cond & 1) != 0;
773 /// getUnorderedFlavor - This function returns 0 if the condition is always
774 /// false if an operand is a NaN, 1 if the condition is always true if the
775 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
777 inline unsigned getUnorderedFlavor(CondCode Cond) {
778 return ((int)Cond >> 3) & 3;
781 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
782 /// 'op' is a valid SetCC operation.
783 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
785 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
786 /// when given the operation for (X op Y).
787 CondCode getSetCCSwappedOperands(CondCode Operation);
789 /// getSetCCOrOperation - Return the result of a logical OR between different
790 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
791 /// function returns SETCC_INVALID if it is not possible to represent the
792 /// resultant comparison.
793 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
795 /// getSetCCAndOperation - Return the result of a logical AND between
796 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
797 /// function returns SETCC_INVALID if it is not possible to represent the
798 /// resultant comparison.
799 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
800 } // end llvm::ISD namespace
803 //===----------------------------------------------------------------------===//
804 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
805 /// values as the result of a computation. Many nodes return multiple values,
806 /// from loads (which define a token and a return value) to ADDC (which returns
807 /// a result and a carry value), to calls (which may return an arbitrary number
810 /// As such, each use of a SelectionDAG computation must indicate the node that
811 /// computes it as well as which return value to use from that node. This pair
812 /// of information is represented with the SDOperand value type.
816 SDNode *Val; // The node defining the value we are using.
817 unsigned ResNo; // Which return value of the node we are using.
819 SDOperand() : Val(0), ResNo(0) {}
820 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
822 bool operator==(const SDOperand &O) const {
823 return Val == O.Val && ResNo == O.ResNo;
825 bool operator!=(const SDOperand &O) const {
826 return !operator==(O);
828 bool operator<(const SDOperand &O) const {
829 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
832 SDOperand getValue(unsigned R) const {
833 return SDOperand(Val, R);
836 // isOperandOf - Return true if this node is an operand of N.
837 bool isOperandOf(SDNode *N) const;
839 /// getValueType - Return the ValueType of the referenced return value.
841 inline MVT::ValueType getValueType() const;
843 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType()).
845 unsigned getValueSizeInBits() const {
846 return MVT::getSizeInBits(getValueType());
849 // Forwarding methods - These forward to the corresponding methods in SDNode.
850 inline unsigned getOpcode() const;
851 inline unsigned getNumOperands() const;
852 inline const SDOperand &getOperand(unsigned i) const;
853 inline uint64_t getConstantOperandVal(unsigned i) const;
854 inline bool isTargetOpcode() const;
855 inline unsigned getTargetOpcode() const;
858 /// reachesChainWithoutSideEffects - Return true if this operand (which must
859 /// be a chain) reaches the specified operand without crossing any
860 /// side-effecting instructions. In practice, this looks through token
861 /// factors and non-volatile loads. In order to remain efficient, this only
862 /// looks a couple of nodes in, it does not do an exhaustive search.
863 bool reachesChainWithoutSideEffects(SDOperand Dest, unsigned Depth = 2) const;
865 /// hasOneUse - Return true if there is exactly one operation using this
866 /// result value of the defining operator.
867 inline bool hasOneUse() const;
869 /// use_empty - Return true if there are no operations using this
870 /// result value of the defining operator.
871 inline bool use_empty() const;
875 template<> struct DenseMapInfo<SDOperand> {
876 static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); }
877 static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);}
878 static unsigned getHashValue(const SDOperand &Val) {
879 return ((unsigned)((uintptr_t)Val.Val >> 4) ^
880 (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo;
882 static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
885 static bool isPod() { return true; }
888 /// simplify_type specializations - Allow casting operators to work directly on
889 /// SDOperands as if they were SDNode*'s.
890 template<> struct simplify_type<SDOperand> {
891 typedef SDNode* SimpleType;
892 static SimpleType getSimplifiedValue(const SDOperand &Val) {
893 return static_cast<SimpleType>(Val.Val);
896 template<> struct simplify_type<const SDOperand> {
897 typedef SDNode* SimpleType;
898 static SimpleType getSimplifiedValue(const SDOperand &Val) {
899 return static_cast<SimpleType>(Val.Val);
904 /// SDNode - Represents one node in the SelectionDAG.
906 class SDNode : public FoldingSetNode {
907 /// NodeType - The operation that this node performs.
909 unsigned short NodeType;
911 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
912 /// then they will be delete[]'d when the node is destroyed.
913 bool OperandsNeedDelete : 1;
915 /// NodeId - Unique id per SDNode in the DAG.
918 /// OperandList - The values that are used by this operation.
920 SDOperand *OperandList;
922 /// ValueList - The types of the values this node defines. SDNode's may
923 /// define multiple values simultaneously.
924 const MVT::ValueType *ValueList;
926 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
927 unsigned short NumOperands, NumValues;
929 /// Prev/Next pointers - These pointers form the linked list of of the
930 /// AllNodes list in the current DAG.
932 friend struct ilist_traits<SDNode>;
934 /// Uses - These are all of the SDNode's that use a value produced by this
936 SmallVector<SDNode*,3> Uses;
938 // Out-of-line virtual method to give class a home.
939 virtual void ANCHOR();
942 assert(NumOperands == 0 && "Operand list not cleared before deletion");
943 NodeType = ISD::DELETED_NODE;
946 //===--------------------------------------------------------------------===//
949 unsigned getOpcode() const { return NodeType; }
950 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
951 unsigned getTargetOpcode() const {
952 assert(isTargetOpcode() && "Not a target opcode!");
953 return NodeType - ISD::BUILTIN_OP_END;
956 size_t use_size() const { return Uses.size(); }
957 bool use_empty() const { return Uses.empty(); }
958 bool hasOneUse() const { return Uses.size() == 1; }
960 /// getNodeId - Return the unique node id.
962 int getNodeId() const { return NodeId; }
964 /// setNodeId - Set unique node id.
965 void setNodeId(int Id) { NodeId = Id; }
967 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
968 use_iterator use_begin() const { return Uses.begin(); }
969 use_iterator use_end() const { return Uses.end(); }
971 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
972 /// indicated value. This method ignores uses of other values defined by this
974 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
976 /// hasAnyUseOfValue - Return true if there are any use of the indicated
977 /// value. This method ignores uses of other values defined by this operation.
978 bool hasAnyUseOfValue(unsigned Value) const;
980 /// isOnlyUseOf - Return true if this node is the only use of N.
982 bool isOnlyUseOf(SDNode *N) const;
984 /// isOperandOf - Return true if this node is an operand of N.
986 bool isOperandOf(SDNode *N) const;
988 /// isPredecessorOf - Return true if this node is a predecessor of N. This
989 /// node is either an operand of N or it can be reached by recursively
990 /// traversing up the operands.
991 /// NOTE: this is an expensive method. Use it carefully.
992 bool isPredecessorOf(SDNode *N) const;
994 /// getNumOperands - Return the number of values used by this operation.
996 unsigned getNumOperands() const { return NumOperands; }
998 /// getConstantOperandVal - Helper method returns the integer value of a
999 /// ConstantSDNode operand.
1000 uint64_t getConstantOperandVal(unsigned Num) const;
1002 const SDOperand &getOperand(unsigned Num) const {
1003 assert(Num < NumOperands && "Invalid child # of SDNode!");
1004 return OperandList[Num];
1007 typedef const SDOperand* op_iterator;
1008 op_iterator op_begin() const { return OperandList; }
1009 op_iterator op_end() const { return OperandList+NumOperands; }
1012 SDVTList getVTList() const {
1013 SDVTList X = { ValueList, NumValues };
1017 /// getNumValues - Return the number of values defined/returned by this
1020 unsigned getNumValues() const { return NumValues; }
1022 /// getValueType - Return the type of a specified result.
1024 MVT::ValueType getValueType(unsigned ResNo) const {
1025 assert(ResNo < NumValues && "Illegal result number!");
1026 return ValueList[ResNo];
1029 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1031 unsigned getValueSizeInBits(unsigned ResNo) const {
1032 return MVT::getSizeInBits(getValueType(ResNo));
1035 typedef const MVT::ValueType* value_iterator;
1036 value_iterator value_begin() const { return ValueList; }
1037 value_iterator value_end() const { return ValueList+NumValues; }
1039 /// getOperationName - Return the opcode of this operation for printing.
1041 std::string getOperationName(const SelectionDAG *G = 0) const;
1042 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1044 void dump(const SelectionDAG *G) const;
1046 static bool classof(const SDNode *) { return true; }
1048 /// Profile - Gather unique data for the node.
1050 void Profile(FoldingSetNodeID &ID);
1053 friend class SelectionDAG;
1055 /// getValueTypeList - Return a pointer to the specified value type.
1057 static const MVT::ValueType *getValueTypeList(MVT::ValueType VT);
1058 static SDVTList getSDVTList(MVT::ValueType VT) {
1059 SDVTList Ret = { getValueTypeList(VT), 1 };
1063 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
1064 : NodeType(Opc), NodeId(-1) {
1065 OperandsNeedDelete = true;
1066 NumOperands = NumOps;
1067 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
1069 for (unsigned i = 0; i != NumOps; ++i) {
1070 OperandList[i] = Ops[i];
1071 Ops[i].Val->Uses.push_back(this);
1074 ValueList = VTs.VTs;
1075 NumValues = VTs.NumVTs;
1078 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
1079 OperandsNeedDelete = false; // Operands set with InitOperands.
1083 ValueList = VTs.VTs;
1084 NumValues = VTs.NumVTs;
1088 /// InitOperands - Initialize the operands list of this node with the
1089 /// specified values, which are part of the node (thus they don't need to be
1090 /// copied in or allocated).
1091 void InitOperands(SDOperand *Ops, unsigned NumOps) {
1092 assert(OperandList == 0 && "Operands already set!");
1093 NumOperands = NumOps;
1096 for (unsigned i = 0; i != NumOps; ++i)
1097 Ops[i].Val->Uses.push_back(this);
1100 /// MorphNodeTo - This frees the operands of the current node, resets the
1101 /// opcode, types, and operands to the specified value. This should only be
1102 /// used by the SelectionDAG class.
1103 void MorphNodeTo(unsigned Opc, SDVTList L,
1104 const SDOperand *Ops, unsigned NumOps);
1106 void addUser(SDNode *User) {
1107 Uses.push_back(User);
1109 void removeUser(SDNode *User) {
1110 // Remove this user from the operand's use list.
1111 for (unsigned i = Uses.size(); ; --i) {
1112 assert(i != 0 && "Didn't find user!");
1113 if (Uses[i-1] == User) {
1114 Uses[i-1] = Uses.back();
1123 // Define inline functions from the SDOperand class.
1125 inline unsigned SDOperand::getOpcode() const {
1126 return Val->getOpcode();
1128 inline MVT::ValueType SDOperand::getValueType() const {
1129 return Val->getValueType(ResNo);
1131 inline unsigned SDOperand::getNumOperands() const {
1132 return Val->getNumOperands();
1134 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1135 return Val->getOperand(i);
1137 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1138 return Val->getConstantOperandVal(i);
1140 inline bool SDOperand::isTargetOpcode() const {
1141 return Val->isTargetOpcode();
1143 inline unsigned SDOperand::getTargetOpcode() const {
1144 return Val->getTargetOpcode();
1146 inline bool SDOperand::hasOneUse() const {
1147 return Val->hasNUsesOfValue(1, ResNo);
1149 inline bool SDOperand::use_empty() const {
1150 return !Val->hasAnyUseOfValue(ResNo);
1153 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1154 /// to allow co-allocation of node operands with the node itself.
1155 class UnarySDNode : public SDNode {
1156 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1159 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1160 : SDNode(Opc, VTs), Op(X) {
1161 InitOperands(&Op, 1);
1165 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1166 /// to allow co-allocation of node operands with the node itself.
1167 class BinarySDNode : public SDNode {
1168 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1171 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1172 : SDNode(Opc, VTs) {
1175 InitOperands(Ops, 2);
1179 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1180 /// to allow co-allocation of node operands with the node itself.
1181 class TernarySDNode : public SDNode {
1182 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1185 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1187 : SDNode(Opc, VTs) {
1191 InitOperands(Ops, 3);
1196 /// HandleSDNode - This class is used to form a handle around another node that
1197 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1198 /// operand. This node should be directly created by end-users and not added to
1199 /// the AllNodes list.
1200 class HandleSDNode : public SDNode {
1201 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1204 explicit HandleSDNode(SDOperand X)
1205 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1206 InitOperands(&Op, 1);
1209 SDOperand getValue() const { return Op; }
1212 class AtomicSDNode : public SDNode {
1213 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1215 MVT::ValueType OrigVT;
1217 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1218 SDOperand Cmp, SDOperand Swp, MVT::ValueType VT)
1219 : SDNode(Opc, VTL) {
1224 InitOperands(Ops, 4);
1227 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1228 SDOperand Val, MVT::ValueType VT)
1229 : SDNode(Opc, VTL) {
1233 InitOperands(Ops, 3);
1236 MVT::ValueType getVT() const { return OrigVT; }
1237 bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_LCS; }
1240 class StringSDNode : public SDNode {
1242 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1244 friend class SelectionDAG;
1245 explicit StringSDNode(const std::string &val)
1246 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1249 const std::string &getValue() const { return Value; }
1250 static bool classof(const StringSDNode *) { return true; }
1251 static bool classof(const SDNode *N) {
1252 return N->getOpcode() == ISD::STRING;
1256 class ConstantSDNode : public SDNode {
1258 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1260 friend class SelectionDAG;
1261 ConstantSDNode(bool isTarget, const APInt &val, MVT::ValueType VT)
1262 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1267 const APInt &getAPIntValue() const { return Value; }
1268 uint64_t getValue() const { return Value.getZExtValue(); }
1270 int64_t getSignExtended() const {
1271 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1272 return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1275 bool isNullValue() const { return Value == 0; }
1276 bool isAllOnesValue() const {
1277 return Value == MVT::getIntVTBitMask(getValueType(0));
1280 static bool classof(const ConstantSDNode *) { return true; }
1281 static bool classof(const SDNode *N) {
1282 return N->getOpcode() == ISD::Constant ||
1283 N->getOpcode() == ISD::TargetConstant;
1287 class ConstantFPSDNode : public SDNode {
1289 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1291 friend class SelectionDAG;
1292 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT)
1293 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1294 getSDVTList(VT)), Value(val) {
1298 const APFloat& getValueAPF() const { return Value; }
1300 /// isExactlyValue - We don't rely on operator== working on double values, as
1301 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1302 /// As such, this method can be used to do an exact bit-for-bit comparison of
1303 /// two floating point values.
1305 /// We leave the version with the double argument here because it's just so
1306 /// convenient to write "2.0" and the like. Without this function we'd
1307 /// have to duplicate its logic everywhere it's called.
1308 bool isExactlyValue(double V) const {
1310 Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1311 return isExactlyValue(Tmp);
1313 bool isExactlyValue(const APFloat& V) const;
1315 bool isValueValidForType(MVT::ValueType VT, const APFloat& Val);
1317 static bool classof(const ConstantFPSDNode *) { return true; }
1318 static bool classof(const SDNode *N) {
1319 return N->getOpcode() == ISD::ConstantFP ||
1320 N->getOpcode() == ISD::TargetConstantFP;
1324 class GlobalAddressSDNode : public SDNode {
1325 GlobalValue *TheGlobal;
1327 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1329 friend class SelectionDAG;
1330 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1334 GlobalValue *getGlobal() const { return TheGlobal; }
1335 int getOffset() const { return Offset; }
1337 static bool classof(const GlobalAddressSDNode *) { return true; }
1338 static bool classof(const SDNode *N) {
1339 return N->getOpcode() == ISD::GlobalAddress ||
1340 N->getOpcode() == ISD::TargetGlobalAddress ||
1341 N->getOpcode() == ISD::GlobalTLSAddress ||
1342 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1346 class FrameIndexSDNode : public SDNode {
1348 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1350 friend class SelectionDAG;
1351 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1352 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1357 int getIndex() const { return FI; }
1359 static bool classof(const FrameIndexSDNode *) { return true; }
1360 static bool classof(const SDNode *N) {
1361 return N->getOpcode() == ISD::FrameIndex ||
1362 N->getOpcode() == ISD::TargetFrameIndex;
1366 class JumpTableSDNode : public SDNode {
1368 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1370 friend class SelectionDAG;
1371 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1372 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1377 int getIndex() const { return JTI; }
1379 static bool classof(const JumpTableSDNode *) { return true; }
1380 static bool classof(const SDNode *N) {
1381 return N->getOpcode() == ISD::JumpTable ||
1382 N->getOpcode() == ISD::TargetJumpTable;
1386 class ConstantPoolSDNode : public SDNode {
1389 MachineConstantPoolValue *MachineCPVal;
1391 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1393 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1395 friend class SelectionDAG;
1396 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1398 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1399 getSDVTList(VT)), Offset(o), Alignment(0) {
1400 assert((int)Offset >= 0 && "Offset is too large");
1403 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1405 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1406 getSDVTList(VT)), Offset(o), Alignment(Align) {
1407 assert((int)Offset >= 0 && "Offset is too large");
1410 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1411 MVT::ValueType VT, int o=0)
1412 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1413 getSDVTList(VT)), Offset(o), Alignment(0) {
1414 assert((int)Offset >= 0 && "Offset is too large");
1415 Val.MachineCPVal = v;
1416 Offset |= 1 << (sizeof(unsigned)*8-1);
1418 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1419 MVT::ValueType VT, int o, unsigned Align)
1420 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1421 getSDVTList(VT)), Offset(o), Alignment(Align) {
1422 assert((int)Offset >= 0 && "Offset is too large");
1423 Val.MachineCPVal = v;
1424 Offset |= 1 << (sizeof(unsigned)*8-1);
1428 bool isMachineConstantPoolEntry() const {
1429 return (int)Offset < 0;
1432 Constant *getConstVal() const {
1433 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1434 return Val.ConstVal;
1437 MachineConstantPoolValue *getMachineCPVal() const {
1438 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1439 return Val.MachineCPVal;
1442 int getOffset() const {
1443 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1446 // Return the alignment of this constant pool object, which is either 0 (for
1447 // default alignment) or log2 of the desired value.
1448 unsigned getAlignment() const { return Alignment; }
1450 const Type *getType() const;
1452 static bool classof(const ConstantPoolSDNode *) { return true; }
1453 static bool classof(const SDNode *N) {
1454 return N->getOpcode() == ISD::ConstantPool ||
1455 N->getOpcode() == ISD::TargetConstantPool;
1459 class BasicBlockSDNode : public SDNode {
1460 MachineBasicBlock *MBB;
1461 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1463 friend class SelectionDAG;
1464 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1465 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1469 MachineBasicBlock *getBasicBlock() const { return MBB; }
1471 static bool classof(const BasicBlockSDNode *) { return true; }
1472 static bool classof(const SDNode *N) {
1473 return N->getOpcode() == ISD::BasicBlock;
1477 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1478 /// used when the SelectionDAG needs to make a simple reference to something
1479 /// in the LLVM IR representation.
1481 /// Note that this is not used for carrying alias information; that is done
1482 /// with MemOperandSDNode, which includes a Value which is required to be a
1483 /// pointer, and several other fields specific to memory references.
1485 class SrcValueSDNode : public SDNode {
1487 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1489 friend class SelectionDAG;
1490 /// Create a SrcValue for a general value.
1491 explicit SrcValueSDNode(const Value *v)
1492 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1495 /// getValue - return the contained Value.
1496 const Value *getValue() const { return V; }
1498 static bool classof(const SrcValueSDNode *) { return true; }
1499 static bool classof(const SDNode *N) {
1500 return N->getOpcode() == ISD::SRCVALUE;
1505 /// MemOperandSDNode - An SDNode that holds a MemOperand. This is
1506 /// used to represent a reference to memory after ISD::LOAD
1507 /// and ISD::STORE have been lowered.
1509 class MemOperandSDNode : public SDNode {
1510 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1512 friend class SelectionDAG;
1513 /// Create a MemOperand node
1514 explicit MemOperandSDNode(const MemOperand &mo)
1515 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1518 /// MO - The contained MemOperand.
1519 const MemOperand MO;
1521 static bool classof(const MemOperandSDNode *) { return true; }
1522 static bool classof(const SDNode *N) {
1523 return N->getOpcode() == ISD::MEMOPERAND;
1528 class RegisterSDNode : public SDNode {
1530 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1532 friend class SelectionDAG;
1533 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1534 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1538 unsigned getReg() const { return Reg; }
1540 static bool classof(const RegisterSDNode *) { return true; }
1541 static bool classof(const SDNode *N) {
1542 return N->getOpcode() == ISD::Register;
1546 class ExternalSymbolSDNode : public SDNode {
1548 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1550 friend class SelectionDAG;
1551 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1552 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1553 getSDVTList(VT)), Symbol(Sym) {
1557 const char *getSymbol() const { return Symbol; }
1559 static bool classof(const ExternalSymbolSDNode *) { return true; }
1560 static bool classof(const SDNode *N) {
1561 return N->getOpcode() == ISD::ExternalSymbol ||
1562 N->getOpcode() == ISD::TargetExternalSymbol;
1566 class CondCodeSDNode : public SDNode {
1567 ISD::CondCode Condition;
1568 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1570 friend class SelectionDAG;
1571 explicit CondCodeSDNode(ISD::CondCode Cond)
1572 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1576 ISD::CondCode get() const { return Condition; }
1578 static bool classof(const CondCodeSDNode *) { return true; }
1579 static bool classof(const SDNode *N) {
1580 return N->getOpcode() == ISD::CONDCODE;
1584 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1585 /// to parameterize some operations.
1586 class VTSDNode : public SDNode {
1587 MVT::ValueType ValueType;
1588 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1590 friend class SelectionDAG;
1591 explicit VTSDNode(MVT::ValueType VT)
1592 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1596 MVT::ValueType getVT() const { return ValueType; }
1598 static bool classof(const VTSDNode *) { return true; }
1599 static bool classof(const SDNode *N) {
1600 return N->getOpcode() == ISD::VALUETYPE;
1604 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1606 class LSBaseSDNode : public SDNode {
1608 // AddrMode - unindexed, pre-indexed, post-indexed.
1609 ISD::MemIndexedMode AddrMode;
1611 // MemoryVT - VT of in-memory value.
1612 MVT::ValueType MemoryVT;
1614 //! SrcValue - Memory location for alias analysis.
1615 const Value *SrcValue;
1617 //! SVOffset - Memory location offset.
1620 //! Alignment - Alignment of memory location in bytes.
1623 //! IsVolatile - True if the store is volatile.
1626 //! Operand array for load and store
1628 \note Moving this array to the base class captures more
1629 common functionality shared between LoadSDNode and
1634 LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned NumOperands,
1635 SDVTList VTs, ISD::MemIndexedMode AM, MVT::ValueType VT,
1636 const Value *SV, int SVO, unsigned Align, bool Vol)
1637 : SDNode(NodeTy, VTs),
1638 AddrMode(AM), MemoryVT(VT),
1639 SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol) {
1640 for (unsigned i = 0; i != NumOperands; ++i)
1641 Ops[i] = Operands[i];
1642 InitOperands(Ops, NumOperands);
1643 assert(Align != 0 && "Loads and stores should have non-zero aligment");
1644 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1645 "Only indexed loads and stores have a non-undef offset operand");
1648 const SDOperand &getChain() const { return getOperand(0); }
1649 const SDOperand &getBasePtr() const {
1650 return getOperand(getOpcode() == ISD::LOAD ? 1 : 2);
1652 const SDOperand &getOffset() const {
1653 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1656 const Value *getSrcValue() const { return SrcValue; }
1657 int getSrcValueOffset() const { return SVOffset; }
1658 unsigned getAlignment() const { return Alignment; }
1659 MVT::ValueType getMemoryVT() const { return MemoryVT; }
1660 bool isVolatile() const { return IsVolatile; }
1662 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1664 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1665 bool isIndexed() const { return AddrMode != ISD::UNINDEXED; }
1667 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1668 bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; }
1670 /// getMemOperand - Return a MemOperand object describing the memory
1671 /// reference performed by this load or store.
1672 MemOperand getMemOperand() const;
1674 static bool classof(const LSBaseSDNode *N) { return true; }
1675 static bool classof(const SDNode *N) {
1676 return N->getOpcode() == ISD::LOAD ||
1677 N->getOpcode() == ISD::STORE;
1681 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1683 class LoadSDNode : public LSBaseSDNode {
1684 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1686 // ExtType - non-ext, anyext, sext, zext.
1687 ISD::LoadExtType ExtType;
1690 friend class SelectionDAG;
1691 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1692 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1693 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1694 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
1695 VTs, AM, LVT, SV, O, Align, Vol),
1699 ISD::LoadExtType getExtensionType() const { return ExtType; }
1700 const SDOperand &getBasePtr() const { return getOperand(1); }
1701 const SDOperand &getOffset() const { return getOperand(2); }
1703 static bool classof(const LoadSDNode *) { return true; }
1704 static bool classof(const SDNode *N) {
1705 return N->getOpcode() == ISD::LOAD;
1709 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1711 class StoreSDNode : public LSBaseSDNode {
1712 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1714 // IsTruncStore - True if the op does a truncation before store.
1717 friend class SelectionDAG;
1718 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1719 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1720 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1721 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
1722 VTs, AM, SVT, SV, O, Align, Vol),
1723 IsTruncStore(isTrunc) {}
1726 bool isTruncatingStore() const { return IsTruncStore; }
1727 const SDOperand &getValue() const { return getOperand(1); }
1728 const SDOperand &getBasePtr() const { return getOperand(2); }
1729 const SDOperand &getOffset() const { return getOperand(3); }
1731 static bool classof(const StoreSDNode *) { return true; }
1732 static bool classof(const SDNode *N) {
1733 return N->getOpcode() == ISD::STORE;
1738 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1742 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1744 bool operator==(const SDNodeIterator& x) const {
1745 return Operand == x.Operand;
1747 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1749 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1750 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1751 Operand = I.Operand;
1755 pointer operator*() const {
1756 return Node->getOperand(Operand).Val;
1758 pointer operator->() const { return operator*(); }
1760 SDNodeIterator& operator++() { // Preincrement
1764 SDNodeIterator operator++(int) { // Postincrement
1765 SDNodeIterator tmp = *this; ++*this; return tmp;
1768 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1769 static SDNodeIterator end (SDNode *N) {
1770 return SDNodeIterator(N, N->getNumOperands());
1773 unsigned getOperand() const { return Operand; }
1774 const SDNode *getNode() const { return Node; }
1777 template <> struct GraphTraits<SDNode*> {
1778 typedef SDNode NodeType;
1779 typedef SDNodeIterator ChildIteratorType;
1780 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1781 static inline ChildIteratorType child_begin(NodeType *N) {
1782 return SDNodeIterator::begin(N);
1784 static inline ChildIteratorType child_end(NodeType *N) {
1785 return SDNodeIterator::end(N);
1790 struct ilist_traits<SDNode> {
1791 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1792 static SDNode *getNext(const SDNode *N) { return N->Next; }
1794 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1795 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1797 static SDNode *createSentinel() {
1798 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1800 static void destroySentinel(SDNode *N) { delete N; }
1801 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1804 void addNodeToList(SDNode *NTy) {}
1805 void removeNodeFromList(SDNode *NTy) {}
1806 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1807 const ilist_iterator<SDNode> &X,
1808 const ilist_iterator<SDNode> &Y) {}
1812 /// isNormalLoad - Returns true if the specified node is a non-extending
1813 /// and unindexed load.
1814 inline bool isNormalLoad(const SDNode *N) {
1815 if (N->getOpcode() != ISD::LOAD)
1817 const LoadSDNode *Ld = cast<LoadSDNode>(N);
1818 return Ld->getExtensionType() == ISD::NON_EXTLOAD &&
1819 Ld->getAddressingMode() == ISD::UNINDEXED;
1822 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1824 inline bool isNON_EXTLoad(const SDNode *N) {
1825 return N->getOpcode() == ISD::LOAD &&
1826 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1829 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1831 inline bool isEXTLoad(const SDNode *N) {
1832 return N->getOpcode() == ISD::LOAD &&
1833 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1836 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1838 inline bool isSEXTLoad(const SDNode *N) {
1839 return N->getOpcode() == ISD::LOAD &&
1840 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1843 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1845 inline bool isZEXTLoad(const SDNode *N) {
1846 return N->getOpcode() == ISD::LOAD &&
1847 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1850 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1852 inline bool isUNINDEXEDLoad(const SDNode *N) {
1853 return N->getOpcode() == ISD::LOAD &&
1854 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1857 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1859 inline bool isNON_TRUNCStore(const SDNode *N) {
1860 return N->getOpcode() == ISD::STORE &&
1861 !cast<StoreSDNode>(N)->isTruncatingStore();
1864 /// isTRUNCStore - Returns true if the specified node is a truncating
1866 inline bool isTRUNCStore(const SDNode *N) {
1867 return N->getOpcode() == ISD::STORE &&
1868 cast<StoreSDNode>(N)->isTruncatingStore();
1873 } // end llvm namespace