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/Constants.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator.h"
26 #include "llvm/ADT/ilist_node.h"
27 #include "llvm/ADT/STLExtras.h"
28 #include "llvm/CodeGen/ValueTypes.h"
29 #include "llvm/CodeGen/MachineMemOperand.h"
30 #include "llvm/Support/Allocator.h"
31 #include "llvm/Support/RecyclingAllocator.h"
32 #include "llvm/Support/DataTypes.h"
33 #include "llvm/CodeGen/DebugLoc.h"
40 class MachineBasicBlock;
41 class MachineConstantPoolValue;
44 template <typename T> struct DenseMapInfo;
45 template <typename T> struct simplify_type;
46 template <typename T> struct ilist_traits;
48 /// SDVTList - This represents a list of ValueType's that has been intern'd by
49 /// a SelectionDAG. Instances of this simple value class are returned by
50 /// SelectionDAG::getVTList(...).
54 unsigned short NumVTs;
57 /// ISD namespace - This namespace contains an enum which represents all of the
58 /// SelectionDAG node types and value types.
62 //===--------------------------------------------------------------------===//
63 /// ISD::NodeType enum - This enum defines all of the operators valid in a
67 // DELETED_NODE - This is an illegal flag value that is used to catch
68 // errors. This opcode is not a legal opcode for any node.
71 // EntryToken - This is the marker used to indicate the start of the region.
74 // TokenFactor - This node takes multiple tokens as input and produces a
75 // single token result. This is used to represent the fact that the operand
76 // operators are independent of each other.
79 // AssertSext, AssertZext - These nodes record if a register contains a
80 // value that has already been zero or sign extended from a narrower type.
81 // These nodes take two operands. The first is the node that has already
82 // been extended, and the second is a value type node indicating the width
84 AssertSext, AssertZext,
86 // Various leaf nodes.
87 BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
89 GlobalAddress, GlobalTLSAddress, FrameIndex,
90 JumpTable, ConstantPool, ExternalSymbol,
92 // The address of the GOT
95 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
96 // llvm.returnaddress on the DAG. These nodes take one operand, the index
97 // of the frame or return address to return. An index of zero corresponds
98 // to the current function's frame or return address, an index of one to the
99 // parent's frame or return address, and so on.
100 FRAMEADDR, RETURNADDR,
102 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
103 // first (possible) on-stack argument. This is needed for correct stack
104 // adjustment during unwind.
105 FRAME_TO_ARGS_OFFSET,
107 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
108 // address of the exception block on entry to an landing pad block.
111 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
112 // the selection index of the exception thrown.
115 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
116 // 'eh_return' gcc dwarf builtin, which is used to return from
117 // exception. The general meaning is: adjust stack by OFFSET and pass
118 // execution to HANDLER. Many platform-related details also :)
121 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
122 // simplification of the constant.
126 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
127 // anything else with this node, and this is valid in the target-specific
128 // dag, turning into a GlobalAddress operand.
130 TargetGlobalTLSAddress,
134 TargetExternalSymbol,
136 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
137 /// This node represents a target intrinsic function with no side effects.
138 /// The first operand is the ID number of the intrinsic from the
139 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
140 /// node has returns the result of the intrinsic.
143 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
144 /// This node represents a target intrinsic function with side effects that
145 /// returns a result. The first operand is a chain pointer. The second is
146 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
147 /// operands to the intrinsic follow. The node has two results, the result
148 /// of the intrinsic and an output chain.
151 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
152 /// This node represents a target intrinsic function with side effects that
153 /// does not return a result. The first operand is a chain pointer. The
154 /// second is the ID number of the intrinsic from the llvm::Intrinsic
155 /// namespace. The operands to the intrinsic follow.
158 // CopyToReg - This node has three operands: a chain, a register number to
159 // set to this value, and a value.
162 // CopyFromReg - This node indicates that the input value is a virtual or
163 // physical register that is defined outside of the scope of this
164 // SelectionDAG. The register is available from the RegisterSDNode object.
167 // UNDEF - An undefined node
170 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
171 /// represents the formal arguments for a function. CC# is a Constant value
172 /// indicating the calling convention of the function, and ISVARARG is a
173 /// flag that indicates whether the function is varargs or not. This node
174 /// has one result value for each incoming argument, plus one for the output
175 /// chain. It must be custom legalized. See description of CALL node for
176 /// FLAG argument contents explanation.
180 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CALLEE,
181 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
182 /// This node represents a fully general function call, before the legalizer
183 /// runs. This has one result value for each argument / flag pair, plus
184 /// a chain result. It must be custom legalized. Flag argument indicates
185 /// misc. argument attributes. Currently:
187 /// Bit 1 - 'inreg' attribute
188 /// Bit 2 - 'sret' attribute
189 /// Bit 4 - 'byval' attribute
190 /// Bit 5 - 'nest' attribute
191 /// Bit 6-9 - alignment of byval structures
192 /// Bit 10-26 - size of byval structures
193 /// Bits 31:27 - argument ABI alignment in the first argument piece and
194 /// alignment '1' in other argument pieces.
196 /// CALL nodes use the CallSDNode subclass of SDNode, which
197 /// additionally carries information about the calling convention,
198 /// whether the call is varargs, and if it's marked as a tail call.
202 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
203 // a Constant, which is required to be operand #1) half of the integer or
204 // float value specified as operand #0. This is only for use before
205 // legalization, for values that will be broken into multiple registers.
208 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
209 // two values of the same integer value type, this produces a value twice as
210 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
213 // MERGE_VALUES - This node takes multiple discrete operands and returns
214 // them all as its individual results. This nodes has exactly the same
215 // number of inputs and outputs, and is only valid before legalization.
216 // This node is useful for some pieces of the code generator that want to
217 // think about a single node with multiple results, not multiple nodes.
220 // Simple integer binary arithmetic operators.
221 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
223 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
224 // a signed/unsigned value of type i[2*N], and return the full value as
225 // two results, each of type iN.
226 SMUL_LOHI, UMUL_LOHI,
228 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
232 // CARRY_FALSE - This node is used when folding other nodes,
233 // like ADDC/SUBC, which indicate the carry result is always false.
236 // Carry-setting nodes for multiple precision addition and subtraction.
237 // These nodes take two operands of the same value type, and produce two
238 // results. The first result is the normal add or sub result, the second
239 // result is the carry flag result.
242 // Carry-using nodes for multiple precision addition and subtraction. These
243 // nodes take three operands: The first two are the normal lhs and rhs to
244 // the add or sub, and the third is the input carry flag. These nodes
245 // produce two results; the normal result of the add or sub, and the output
246 // carry flag. These nodes both read and write a carry flag to allow them
247 // to them to be chained together for add and sub of arbitrarily large
251 // RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
252 // These nodes take two operands: the normal LHS and RHS to the add. They
253 // produce two results: the normal result of the add, and a boolean that
254 // indicates if an overflow occured (*not* a flag, because it may be stored
255 // to memory, etc.). If the type of the boolean is not i1 then the high
256 // bits conform to getBooleanContents.
257 // These nodes are generated from the llvm.[su]add.with.overflow intrinsics.
260 // Same for subtraction
263 // Same for multiplication
266 // Simple binary floating point operators.
267 FADD, FSUB, FMUL, FDIV, FREM,
269 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
270 // DAG node does not require that X and Y have the same type, just that they
271 // are both floating point. X and the result must have the same type.
272 // FCOPYSIGN(f32, f64) is allowed.
275 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
276 // value as an integer 0/1 value.
279 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
280 /// with the specified, possibly variable, elements. The number of elements
281 /// is required to be a power of two.
284 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
285 /// at IDX replaced with VAL. If the type of VAL is larger than the vector
286 /// element type then VAL is truncated before replacement.
289 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
290 /// identified by the (potentially variable) element number IDX.
293 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
294 /// vector type with the same length and element type, this produces a
295 /// concatenated vector result value, with length equal to the sum of the
296 /// lengths of the input vectors.
299 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
300 /// vector value) starting with the (potentially variable) element number
301 /// IDX, which must be a multiple of the result vector length.
304 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
305 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
306 /// (maybe of an illegal datatype) or undef that indicate which value each
307 /// result element will get. The elements of VEC1/VEC2 are enumerated in
308 /// order. This is quite similar to the Altivec 'vperm' instruction, except
309 /// that the indices must be constants and are in terms of the element size
310 /// of VEC1/VEC2, not in terms of bytes.
313 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
314 /// scalar value into element 0 of the resultant vector type. The top
315 /// elements 1 to N-1 of the N-element vector are undefined.
318 // EXTRACT_SUBREG - This node is used to extract a sub-register value.
319 // This node takes a superreg and a constant sub-register index as operands.
320 // Note sub-register indices must be increasing. That is, if the
321 // sub-register index of a 8-bit sub-register is N, then the index for a
322 // 16-bit sub-register must be at least N+1.
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). If the type of the boolean COND is not
343 // i1 then the high bits must conform to getBooleanContents.
346 // Select with condition operator - This selects between a true value and
347 // a false value (ops #2 and #3) based on the boolean result of comparing
348 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
349 // condition code in op #4, a CondCodeSDNode.
352 // SetCC operator - This evaluates to a true value iff the condition is
353 // true. If the result value type is not i1 then the high bits conform
354 // to getBooleanContents. The operands to this are the left and right
355 // operands to compare (ops #0, and #1) and the condition code to compare
356 // them with (op #2) as a CondCodeSDNode.
359 // Vector SetCC operator - This evaluates to a vector of integer elements
360 // with the high bit in each element set to true if the comparison is true
361 // and false if the comparison is false. All other bits in each element
362 // are undefined. The operands to this are the left and right operands
363 // to compare (ops #0, and #1) and the condition code to compare them with
364 // (op #2) as a CondCodeSDNode.
367 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
368 // integer shift operations, just like ADD/SUB_PARTS. The operation
370 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
371 SHL_PARTS, SRA_PARTS, SRL_PARTS,
373 // Conversion operators. These are all single input single output
374 // operations. For all of these, the result type must be strictly
375 // wider or narrower (depending on the operation) than the source
378 // SIGN_EXTEND - Used for integer types, replicating the sign bit
382 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
385 // ANY_EXTEND - Used for integer types. The high bits are undefined.
388 // TRUNCATE - Completely drop the high bits.
391 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
392 // depends on the first letter) to floating point.
396 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
397 // sign extend a small value in a large integer register (e.g. sign
398 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
399 // with the 7th bit). The size of the smaller type is indicated by the 1th
400 // operand, a ValueType node.
403 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
408 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
409 /// down to the precision of the destination VT. TRUNC is a flag, which is
410 /// always an integer that is zero or one. If TRUNC is 0, this is a
411 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
414 /// The TRUNC = 1 case is used in cases where we know that the value will
415 /// not be modified by the node, because Y is not using any of the extra
416 /// precision of source type. This allows certain transformations like
417 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
418 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
421 // FLT_ROUNDS_ - Returns current rounding mode:
424 // 1 Round to nearest
429 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
430 /// rounds it to a floating point value. It then promotes it and returns it
431 /// in a register of the same size. This operation effectively just
432 /// discards excess precision. The type to round down to is specified by
433 /// the VT operand, a VTSDNode.
436 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
439 // BIT_CONVERT - Theis operator converts between integer and FP values, as
440 // if one was stored to memory as integer and the other was loaded from the
441 // same address (or equivalently for vector format conversions, etc). The
442 // source and result are required to have the same bit size (e.g.
443 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
444 // conversions, but that is a noop, deleted by getNode().
447 // CONVERT_RNDSAT - This operator is used to support various conversions
448 // between various types (float, signed, unsigned and vectors of those
449 // types) with rounding and saturation. NOTE: Avoid using this operator as
450 // most target don't support it and the operator might be removed in the
451 // future. It takes the following arguments:
453 // 1) dest type (type to convert to)
454 // 2) src type (type to convert from)
457 // 5) ISD::CvtCode indicating the type of conversion to do
460 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
461 // FLOG, FLOG2, FLOG10, FEXP, FEXP2,
462 // FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary floating
463 // point operations. These are inspired by libm.
464 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
465 FLOG, FLOG2, FLOG10, FEXP, FEXP2,
466 FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR,
468 // LOAD and STORE have token chains as their first operand, then the same
469 // operands as an LLVM load/store instruction, then an offset node that
470 // is added / subtracted from the base pointer to form the address (for
471 // indexed memory ops).
474 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
475 // to a specified boundary. This node always has two return values: a new
476 // stack pointer value and a chain. The first operand is the token chain,
477 // the second is the number of bytes to allocate, and the third is the
478 // alignment boundary. The size is guaranteed to be a multiple of the stack
479 // alignment, and the alignment is guaranteed to be bigger than the stack
480 // alignment (if required) or 0 to get standard stack alignment.
483 // Control flow instructions. These all have token chains.
485 // BR - Unconditional branch. The first operand is the chain
486 // operand, the second is the MBB to branch to.
489 // BRIND - Indirect branch. The first operand is the chain, the second
490 // is the value to branch to, which must be of the same type as the target's
494 // BR_JT - Jumptable branch. The first operand is the chain, the second
495 // is the jumptable index, the last one is the jumptable entry index.
498 // BRCOND - Conditional branch. The first operand is the chain, the
499 // second is the condition, the third is the block to branch to if the
500 // condition is true. If the type of the condition is not i1, then the
501 // high bits must conform to getBooleanContents.
504 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
505 // that the condition is represented as condition code, and two nodes to
506 // compare, rather than as a combined SetCC node. The operands in order are
507 // chain, cc, lhs, rhs, block to branch to if condition is true.
510 // RET - Return from function. The first operand is the chain,
511 // and any subsequent operands are pairs of return value and return value
512 // attributes (see CALL for description of attributes) for the function.
513 // This operation can have variable number of operands.
516 // INLINEASM - Represents an inline asm block. This node always has two
517 // return values: a chain and a flag result. The inputs are as follows:
518 // Operand #0 : Input chain.
519 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
520 // Operand #2n+2: A RegisterNode.
521 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
522 // Operand #last: Optional, an incoming flag.
525 // DBG_LABEL, EH_LABEL - Represents a label in mid basic block used to track
526 // locations needed for debug and exception handling tables. These nodes
527 // take a chain as input and return a chain.
531 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
532 // local variable declarations for debugging information. First operand is
533 // a chain, while the next two operands are first two arguments (address
534 // and variable) of a llvm.dbg.declare instruction.
537 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
538 // value, the same type as the pointer type for the system, and an output
542 // STACKRESTORE has two operands, an input chain and a pointer to restore to
543 // it returns an output chain.
546 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
547 // a call sequence, and carry arbitrary information that target might want
548 // to know. The first operand is a chain, the rest are specified by the
549 // target and not touched by the DAG optimizers.
550 // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
551 CALLSEQ_START, // Beginning of a call sequence
552 CALLSEQ_END, // End of a call sequence
554 // VAARG - VAARG has three operands: an input chain, a pointer, and a
555 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
558 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
559 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
563 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
564 // pointer, and a SRCVALUE.
567 // SRCVALUE - This is a node type that holds a Value* that is used to
568 // make reference to a value in the LLVM IR.
571 // MEMOPERAND - This is a node that contains a MachineMemOperand which
572 // records information about a memory reference. This is used to make
573 // AliasAnalysis queries from the backend.
576 // PCMARKER - This corresponds to the pcmarker intrinsic.
579 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
580 // The only operand is a chain and a value and a chain are produced. The
581 // value is the contents of the architecture specific cycle counter like
582 // register (or other high accuracy low latency clock source)
585 // HANDLENODE node - Used as a handle for various purposes.
588 // DBG_STOPPOINT - This node is used to represent a source location for
589 // debug info. It takes token chain as input, and carries a line number,
590 // column number, and a pointer to a CompileUnit object identifying
591 // the containing compilation unit. It produces a token chain as output.
594 // DEBUG_LOC - This node is used to represent source line information
595 // embedded in the code. It takes a token chain as input, then a line
596 // number, then a column then a file id (provided by MachineModuleInfo.) It
597 // produces a token chain as output.
600 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
601 // It takes as input a token chain, the pointer to the trampoline,
602 // the pointer to the nested function, the pointer to pass for the
603 // 'nest' parameter, a SRCVALUE for the trampoline and another for
604 // the nested function (allowing targets to access the original
605 // Function*). It produces the result of the intrinsic and a token
609 // TRAP - Trapping instruction
612 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
613 // their first operand. The other operands are the address to prefetch,
614 // read / write specifier, and locality specifier.
617 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
618 // store-store, device)
619 // This corresponds to the memory.barrier intrinsic.
620 // it takes an input chain, 4 operands to specify the type of barrier, an
621 // operand specifying if the barrier applies to device and uncached memory
622 // and produces an output chain.
625 // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
626 // this corresponds to the atomic.lcs intrinsic.
627 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
628 // the return is always the original value in *ptr
631 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
632 // this corresponds to the atomic.swap intrinsic.
633 // amt is stored to *ptr atomically.
634 // the return is always the original value in *ptr
637 // Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt)
638 // this corresponds to the atomic.load.[OpName] intrinsic.
639 // op(*ptr, amt) is stored to *ptr atomically.
640 // the return is always the original value in *ptr
652 // BUILTIN_OP_END - This must be the last enum value in this list.
658 /// isBuildVectorAllOnes - Return true if the specified node is a
659 /// BUILD_VECTOR where all of the elements are ~0 or undef.
660 bool isBuildVectorAllOnes(const SDNode *N);
662 /// isBuildVectorAllZeros - Return true if the specified node is a
663 /// BUILD_VECTOR where all of the elements are 0 or undef.
664 bool isBuildVectorAllZeros(const SDNode *N);
666 /// isScalarToVector - Return true if the specified node is a
667 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
668 /// element is not an undef.
669 bool isScalarToVector(const SDNode *N);
671 /// isDebugLabel - Return true if the specified node represents a debug
672 /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node).
673 bool isDebugLabel(const SDNode *N);
675 //===--------------------------------------------------------------------===//
676 /// MemIndexedMode enum - This enum defines the load / store indexed
677 /// addressing modes.
679 /// UNINDEXED "Normal" load / store. The effective address is already
680 /// computed and is available in the base pointer. The offset
681 /// operand is always undefined. In addition to producing a
682 /// chain, an unindexed load produces one value (result of the
683 /// load); an unindexed store does not produce a value.
685 /// PRE_INC Similar to the unindexed mode where the effective address is
686 /// PRE_DEC the value of the base pointer add / subtract the offset.
687 /// It considers the computation as being folded into the load /
688 /// store operation (i.e. the load / store does the address
689 /// computation as well as performing the memory transaction).
690 /// The base operand is always undefined. In addition to
691 /// producing a chain, pre-indexed load produces two values
692 /// (result of the load and the result of the address
693 /// computation); a pre-indexed store produces one value (result
694 /// of the address computation).
696 /// POST_INC The effective address is the value of the base pointer. The
697 /// POST_DEC value of the offset operand is then added to / subtracted
698 /// from the base after memory transaction. In addition to
699 /// producing a chain, post-indexed load produces two values
700 /// (the result of the load and the result of the base +/- offset
701 /// computation); a post-indexed store produces one value (the
702 /// the result of the base +/- offset computation).
704 enum MemIndexedMode {
713 //===--------------------------------------------------------------------===//
714 /// LoadExtType enum - This enum defines the three variants of LOADEXT
715 /// (load with extension).
717 /// SEXTLOAD loads the integer operand and sign extends it to a larger
718 /// integer result type.
719 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
720 /// integer result type.
721 /// EXTLOAD is used for three things: floating point extending loads,
722 /// integer extending loads [the top bits are undefined], and vector
723 /// extending loads [load into low elt].
733 //===--------------------------------------------------------------------===//
734 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
735 /// below work out, when considering SETFALSE (something that never exists
736 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
737 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
738 /// to. If the "N" column is 1, the result of the comparison is undefined if
739 /// the input is a NAN.
741 /// All of these (except for the 'always folded ops') should be handled for
742 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
743 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
745 /// Note that these are laid out in a specific order to allow bit-twiddling
746 /// to transform conditions.
748 // Opcode N U L G E Intuitive operation
749 SETFALSE, // 0 0 0 0 Always false (always folded)
750 SETOEQ, // 0 0 0 1 True if ordered and equal
751 SETOGT, // 0 0 1 0 True if ordered and greater than
752 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
753 SETOLT, // 0 1 0 0 True if ordered and less than
754 SETOLE, // 0 1 0 1 True if ordered and less than or equal
755 SETONE, // 0 1 1 0 True if ordered and operands are unequal
756 SETO, // 0 1 1 1 True if ordered (no nans)
757 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
758 SETUEQ, // 1 0 0 1 True if unordered or equal
759 SETUGT, // 1 0 1 0 True if unordered or greater than
760 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
761 SETULT, // 1 1 0 0 True if unordered or less than
762 SETULE, // 1 1 0 1 True if unordered, less than, or equal
763 SETUNE, // 1 1 1 0 True if unordered or not equal
764 SETTRUE, // 1 1 1 1 Always true (always folded)
765 // Don't care operations: undefined if the input is a nan.
766 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
767 SETEQ, // 1 X 0 0 1 True if equal
768 SETGT, // 1 X 0 1 0 True if greater than
769 SETGE, // 1 X 0 1 1 True if greater than or equal
770 SETLT, // 1 X 1 0 0 True if less than
771 SETLE, // 1 X 1 0 1 True if less than or equal
772 SETNE, // 1 X 1 1 0 True if not equal
773 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
775 SETCC_INVALID // Marker value.
778 /// isSignedIntSetCC - Return true if this is a setcc instruction that
779 /// performs a signed comparison when used with integer operands.
780 inline bool isSignedIntSetCC(CondCode Code) {
781 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
784 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
785 /// performs an unsigned comparison when used with integer operands.
786 inline bool isUnsignedIntSetCC(CondCode Code) {
787 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
790 /// isTrueWhenEqual - Return true if the specified condition returns true if
791 /// the two operands to the condition are equal. Note that if one of the two
792 /// operands is a NaN, this value is meaningless.
793 inline bool isTrueWhenEqual(CondCode Cond) {
794 return ((int)Cond & 1) != 0;
797 /// getUnorderedFlavor - This function returns 0 if the condition is always
798 /// false if an operand is a NaN, 1 if the condition is always true if the
799 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
801 inline unsigned getUnorderedFlavor(CondCode Cond) {
802 return ((int)Cond >> 3) & 3;
805 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
806 /// 'op' is a valid SetCC operation.
807 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
809 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
810 /// when given the operation for (X op Y).
811 CondCode getSetCCSwappedOperands(CondCode Operation);
813 /// getSetCCOrOperation - Return the result of a logical OR between different
814 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
815 /// function returns SETCC_INVALID if it is not possible to represent the
816 /// resultant comparison.
817 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
819 /// getSetCCAndOperation - Return the result of a logical AND between
820 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
821 /// function returns SETCC_INVALID if it is not possible to represent the
822 /// resultant comparison.
823 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
825 //===--------------------------------------------------------------------===//
826 /// CvtCode enum - This enum defines the various converts CONVERT_RNDSAT
829 CVT_FF, // Float from Float
830 CVT_FS, // Float from Signed
831 CVT_FU, // Float from Unsigned
832 CVT_SF, // Signed from Float
833 CVT_UF, // Unsigned from Float
834 CVT_SS, // Signed from Signed
835 CVT_SU, // Signed from Unsigned
836 CVT_US, // Unsigned from Signed
837 CVT_UU, // Unsigned from Unsigned
838 CVT_INVALID // Marker - Invalid opcode
840 } // end llvm::ISD namespace
843 //===----------------------------------------------------------------------===//
844 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
845 /// values as the result of a computation. Many nodes return multiple values,
846 /// from loads (which define a token and a return value) to ADDC (which returns
847 /// a result and a carry value), to calls (which may return an arbitrary number
850 /// As such, each use of a SelectionDAG computation must indicate the node that
851 /// computes it as well as which return value to use from that node. This pair
852 /// of information is represented with the SDValue value type.
855 SDNode *Node; // The node defining the value we are using.
856 unsigned ResNo; // Which return value of the node we are using.
858 SDValue() : Node(0), ResNo(0) {}
859 SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
861 /// get the index which selects a specific result in the SDNode
862 unsigned getResNo() const { return ResNo; }
864 /// get the SDNode which holds the desired result
865 SDNode *getNode() const { return Node; }
868 void setNode(SDNode *N) { Node = N; }
870 bool operator==(const SDValue &O) const {
871 return Node == O.Node && ResNo == O.ResNo;
873 bool operator!=(const SDValue &O) const {
874 return !operator==(O);
876 bool operator<(const SDValue &O) const {
877 return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
880 SDValue getValue(unsigned R) const {
881 return SDValue(Node, R);
884 // isOperandOf - Return true if this node is an operand of N.
885 bool isOperandOf(SDNode *N) const;
887 /// getValueType - Return the ValueType of the referenced return value.
889 inline MVT getValueType() const;
891 /// getValueSizeInBits - Returns the size of the value in bits.
893 unsigned getValueSizeInBits() const {
894 return getValueType().getSizeInBits();
897 // Forwarding methods - These forward to the corresponding methods in SDNode.
898 inline unsigned getOpcode() const;
899 inline unsigned getNumOperands() const;
900 inline const SDValue &getOperand(unsigned i) const;
901 inline uint64_t getConstantOperandVal(unsigned i) const;
902 inline bool isTargetOpcode() const;
903 inline bool isMachineOpcode() const;
904 inline unsigned getMachineOpcode() const;
905 inline const DebugLoc getDebugLoc() const;
908 /// reachesChainWithoutSideEffects - Return true if this operand (which must
909 /// be a chain) reaches the specified operand without crossing any
910 /// side-effecting instructions. In practice, this looks through token
911 /// factors and non-volatile loads. In order to remain efficient, this only
912 /// looks a couple of nodes in, it does not do an exhaustive search.
913 bool reachesChainWithoutSideEffects(SDValue Dest,
914 unsigned Depth = 2) const;
916 /// use_empty - Return true if there are no nodes using value ResNo
919 inline bool use_empty() const;
921 /// hasOneUse - Return true if there is exactly one node using value
924 inline bool hasOneUse() const;
928 template<> struct DenseMapInfo<SDValue> {
929 static inline SDValue getEmptyKey() {
930 return SDValue((SDNode*)-1, -1U);
932 static inline SDValue getTombstoneKey() {
933 return SDValue((SDNode*)-1, 0);
935 static unsigned getHashValue(const SDValue &Val) {
936 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
937 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
939 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
942 static bool isPod() { return true; }
945 /// simplify_type specializations - Allow casting operators to work directly on
946 /// SDValues as if they were SDNode*'s.
947 template<> struct simplify_type<SDValue> {
948 typedef SDNode* SimpleType;
949 static SimpleType getSimplifiedValue(const SDValue &Val) {
950 return static_cast<SimpleType>(Val.getNode());
953 template<> struct simplify_type<const SDValue> {
954 typedef SDNode* SimpleType;
955 static SimpleType getSimplifiedValue(const SDValue &Val) {
956 return static_cast<SimpleType>(Val.getNode());
960 /// SDUse - Represents a use of a SDNode. This class holds an SDValue,
961 /// which records the SDNode being used and the result number, a
962 /// pointer to the SDNode using the value, and Next and Prev pointers,
963 /// which link together all the uses of an SDNode.
966 /// Val - The value being used.
968 /// User - The user of this value.
970 /// Prev, Next - Pointers to the uses list of the SDNode referred by
974 SDUse(const SDUse &U); // Do not implement
975 void operator=(const SDUse &U); // Do not implement
978 SDUse() : Val(), User(NULL), Prev(NULL), Next(NULL) {}
980 /// Normally SDUse will just implicitly convert to an SDValue that it holds.
981 operator const SDValue&() const { return Val; }
983 /// If implicit conversion to SDValue doesn't work, the get() method returns
985 const SDValue &get() const { return Val; }
987 /// getUser - This returns the SDNode that contains this Use.
988 SDNode *getUser() { return User; }
990 /// getNext - Get the next SDUse in the use list.
991 SDUse *getNext() const { return Next; }
993 /// getNode - Convenience function for get().getNode().
994 SDNode *getNode() const { return Val.getNode(); }
995 /// getResNo - Convenience function for get().getResNo().
996 unsigned getResNo() const { return Val.getResNo(); }
997 /// getValueType - Convenience function for get().getValueType().
998 MVT getValueType() const { return Val.getValueType(); }
1000 /// operator== - Convenience function for get().operator==
1001 bool operator==(const SDValue &V) const {
1005 /// operator!= - Convenience function for get().operator!=
1006 bool operator!=(const SDValue &V) const {
1010 /// operator< - Convenience function for get().operator<
1011 bool operator<(const SDValue &V) const {
1016 friend class SelectionDAG;
1017 friend class SDNode;
1019 void setUser(SDNode *p) { User = p; }
1021 /// set - Remove this use from its existing use list, assign it the
1022 /// given value, and add it to the new value's node's use list.
1023 inline void set(const SDValue &V);
1024 /// setInitial - like set, but only supports initializing a newly-allocated
1025 /// SDUse with a non-null value.
1026 inline void setInitial(const SDValue &V);
1027 /// setNode - like set, but only sets the Node portion of the value,
1028 /// leaving the ResNo portion unmodified.
1029 inline void setNode(SDNode *N);
1031 void addToList(SDUse **List) {
1033 if (Next) Next->Prev = &Next;
1038 void removeFromList() {
1040 if (Next) Next->Prev = Prev;
1044 /// simplify_type specializations - Allow casting operators to work directly on
1045 /// SDValues as if they were SDNode*'s.
1046 template<> struct simplify_type<SDUse> {
1047 typedef SDNode* SimpleType;
1048 static SimpleType getSimplifiedValue(const SDUse &Val) {
1049 return static_cast<SimpleType>(Val.getNode());
1052 template<> struct simplify_type<const SDUse> {
1053 typedef SDNode* SimpleType;
1054 static SimpleType getSimplifiedValue(const SDUse &Val) {
1055 return static_cast<SimpleType>(Val.getNode());
1060 /// SDNode - Represents one node in the SelectionDAG.
1062 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
1064 /// NodeType - The operation that this node performs.
1068 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
1069 /// then they will be delete[]'d when the node is destroyed.
1070 unsigned short OperandsNeedDelete : 1;
1073 /// SubclassData - This member is defined by this class, but is not used for
1074 /// anything. Subclasses can use it to hold whatever state they find useful.
1075 /// This field is initialized to zero by the ctor.
1076 unsigned short SubclassData : 15;
1079 /// NodeId - Unique id per SDNode in the DAG.
1082 /// debugLoc - source line information.
1085 /// OperandList - The values that are used by this operation.
1089 /// ValueList - The types of the values this node defines. SDNode's may
1090 /// define multiple values simultaneously.
1091 const MVT *ValueList;
1093 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1094 unsigned short NumOperands, NumValues;
1096 /// UseList - List of uses for this SDNode.
1099 /// getValueTypeList - Return a pointer to the specified value type.
1100 static const MVT *getValueTypeList(MVT VT);
1102 friend class SelectionDAG;
1103 friend struct ilist_traits<SDNode>;
1106 //===--------------------------------------------------------------------===//
1110 /// getOpcode - Return the SelectionDAG opcode value for this node. For
1111 /// pre-isel nodes (those for which isMachineOpcode returns false), these
1112 /// are the opcode values in the ISD and <target>ISD namespaces. For
1113 /// post-isel opcodes, see getMachineOpcode.
1114 unsigned getOpcode() const { return (unsigned short)NodeType; }
1116 /// isTargetOpcode - Test if this node has a target-specific opcode (in the
1117 /// <target>ISD namespace).
1118 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1120 /// isMachineOpcode - Test if this node has a post-isel opcode, directly
1121 /// corresponding to a MachineInstr opcode.
1122 bool isMachineOpcode() const { return NodeType < 0; }
1124 /// getMachineOpcode - This may only be called if isMachineOpcode returns
1125 /// true. It returns the MachineInstr opcode value that the node's opcode
1127 unsigned getMachineOpcode() const {
1128 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
1132 /// use_empty - Return true if there are no uses of this node.
1134 bool use_empty() const { return UseList == NULL; }
1136 /// hasOneUse - Return true if there is exactly one use of this node.
1138 bool hasOneUse() const {
1139 return !use_empty() && next(use_begin()) == use_end();
1142 /// use_size - Return the number of uses of this node. This method takes
1143 /// time proportional to the number of uses.
1145 size_t use_size() const { return std::distance(use_begin(), use_end()); }
1147 /// getNodeId - Return the unique node id.
1149 int getNodeId() const { return NodeId; }
1151 /// setNodeId - Set unique node id.
1152 void setNodeId(int Id) { NodeId = Id; }
1154 /// getDebugLoc - Return the source location info.
1155 const DebugLoc getDebugLoc() const { return debugLoc; }
1157 /// setDebugLoc - Set source location info. Try to avoid this, putting
1158 /// it in the constructor is preferable.
1159 void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
1161 /// use_iterator - This class provides iterator support for SDUse
1162 /// operands that use a specific SDNode.
1164 : public forward_iterator<SDUse, ptrdiff_t> {
1166 explicit use_iterator(SDUse *op) : Op(op) {
1168 friend class SDNode;
1170 typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
1171 typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1173 use_iterator(const use_iterator &I) : Op(I.Op) {}
1174 use_iterator() : Op(0) {}
1176 bool operator==(const use_iterator &x) const {
1179 bool operator!=(const use_iterator &x) const {
1180 return !operator==(x);
1183 /// atEnd - return true if this iterator is at the end of uses list.
1184 bool atEnd() const { return Op == 0; }
1186 // Iterator traversal: forward iteration only.
1187 use_iterator &operator++() { // Preincrement
1188 assert(Op && "Cannot increment end iterator!");
1193 use_iterator operator++(int) { // Postincrement
1194 use_iterator tmp = *this; ++*this; return tmp;
1197 /// Retrieve a pointer to the current user node.
1198 SDNode *operator*() const {
1199 assert(Op && "Cannot dereference end iterator!");
1200 return Op->getUser();
1203 SDNode *operator->() const { return operator*(); }
1205 SDUse &getUse() const { return *Op; }
1207 /// getOperandNo - Retrieve the operand # of this use in its user.
1209 unsigned getOperandNo() const {
1210 assert(Op && "Cannot dereference end iterator!");
1211 return (unsigned)(Op - Op->getUser()->OperandList);
1215 /// use_begin/use_end - Provide iteration support to walk over all uses
1218 use_iterator use_begin() const {
1219 return use_iterator(UseList);
1222 static use_iterator use_end() { return use_iterator(0); }
1225 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1226 /// indicated value. This method ignores uses of other values defined by this
1228 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1230 /// hasAnyUseOfValue - Return true if there are any use of the indicated
1231 /// value. This method ignores uses of other values defined by this operation.
1232 bool hasAnyUseOfValue(unsigned Value) const;
1234 /// isOnlyUserOf - Return true if this node is the only use of N.
1236 bool isOnlyUserOf(SDNode *N) const;
1238 /// isOperandOf - Return true if this node is an operand of N.
1240 bool isOperandOf(SDNode *N) const;
1242 /// isPredecessorOf - Return true if this node is a predecessor of N. This
1243 /// node is either an operand of N or it can be reached by recursively
1244 /// traversing up the operands.
1245 /// NOTE: this is an expensive method. Use it carefully.
1246 bool isPredecessorOf(SDNode *N) const;
1248 /// getNumOperands - Return the number of values used by this operation.
1250 unsigned getNumOperands() const { return NumOperands; }
1252 /// getConstantOperandVal - Helper method returns the integer value of a
1253 /// ConstantSDNode operand.
1254 uint64_t getConstantOperandVal(unsigned Num) const;
1256 const SDValue &getOperand(unsigned Num) const {
1257 assert(Num < NumOperands && "Invalid child # of SDNode!");
1258 return OperandList[Num];
1261 typedef SDUse* op_iterator;
1262 op_iterator op_begin() const { return OperandList; }
1263 op_iterator op_end() const { return OperandList+NumOperands; }
1265 SDVTList getVTList() const {
1266 SDVTList X = { ValueList, NumValues };
1270 /// getFlaggedNode - If this node has a flag operand, return the node
1271 /// to which the flag operand points. Otherwise return NULL.
1272 SDNode *getFlaggedNode() const {
1273 if (getNumOperands() != 0 &&
1274 getOperand(getNumOperands()-1).getValueType() == MVT::Flag)
1275 return getOperand(getNumOperands()-1).getNode();
1279 // If this is a pseudo op, like copyfromreg, look to see if there is a
1280 // real target node flagged to it. If so, return the target node.
1281 const SDNode *getFlaggedMachineNode() const {
1282 const SDNode *FoundNode = this;
1284 // Climb up flag edges until a machine-opcode node is found, or the
1285 // end of the chain is reached.
1286 while (!FoundNode->isMachineOpcode()) {
1287 const SDNode *N = FoundNode->getFlaggedNode();
1295 /// getNumValues - Return the number of values defined/returned by this
1298 unsigned getNumValues() const { return NumValues; }
1300 /// getValueType - Return the type of a specified result.
1302 MVT getValueType(unsigned ResNo) const {
1303 assert(ResNo < NumValues && "Illegal result number!");
1304 return ValueList[ResNo];
1307 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1309 unsigned getValueSizeInBits(unsigned ResNo) const {
1310 return getValueType(ResNo).getSizeInBits();
1313 typedef const MVT* value_iterator;
1314 value_iterator value_begin() const { return ValueList; }
1315 value_iterator value_end() const { return ValueList+NumValues; }
1317 /// getOperationName - Return the opcode of this operation for printing.
1319 std::string getOperationName(const SelectionDAG *G = 0) const;
1320 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1321 void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
1323 void dump(const SelectionDAG *G) const;
1325 static bool classof(const SDNode *) { return true; }
1327 /// Profile - Gather unique data for the node.
1329 void Profile(FoldingSetNodeID &ID) const;
1331 /// addUse - This method should only be used by the SDUse class.
1333 void addUse(SDUse &U) { U.addToList(&UseList); }
1336 static SDVTList getSDVTList(MVT VT) {
1337 SDVTList Ret = { getValueTypeList(VT), 1 };
1341 /// The constructors that supply DebugLoc explicitly should be preferred
1343 SDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps)
1344 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1345 NodeId(-1), debugLoc(DebugLoc::getUnknownLoc()),
1346 OperandList(NumOps ? new SDUse[NumOps] : 0),
1348 NumOperands(NumOps), NumValues(VTs.NumVTs),
1350 for (unsigned i = 0; i != NumOps; ++i) {
1351 OperandList[i].setUser(this);
1352 OperandList[i].setInitial(Ops[i]);
1356 /// This constructor adds no operands itself; operands can be
1357 /// set later with InitOperands.
1358 SDNode(unsigned Opc, SDVTList VTs)
1359 : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1360 NodeId(-1), debugLoc(DebugLoc::getUnknownLoc()), OperandList(0),
1361 ValueList(VTs.VTs), NumOperands(0), NumValues(VTs.NumVTs),
1364 /// The next two constructors specify DebugLoc explicitly; the intent
1365 /// is that they will replace the above two over time, and eventually
1366 /// the ones above can be removed.
1367 SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops,
1369 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1370 NodeId(-1), debugLoc(dl),
1371 OperandList(NumOps ? new SDUse[NumOps] : 0),
1373 NumOperands(NumOps), NumValues(VTs.NumVTs),
1375 for (unsigned i = 0; i != NumOps; ++i) {
1376 OperandList[i].setUser(this);
1377 OperandList[i].setInitial(Ops[i]);
1381 /// This constructor adds no operands itself; operands can be
1382 /// set later with InitOperands.
1383 SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs)
1384 : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1385 NodeId(-1), debugLoc(dl), OperandList(0),
1386 ValueList(VTs.VTs), NumOperands(0), NumValues(VTs.NumVTs),
1389 /// InitOperands - Initialize the operands list of this with 1 operand.
1390 void InitOperands(SDUse *Ops, const SDValue &Op0) {
1391 Ops[0].setUser(this);
1392 Ops[0].setInitial(Op0);
1397 /// InitOperands - Initialize the operands list of this with 2 operands.
1398 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
1399 Ops[0].setUser(this);
1400 Ops[0].setInitial(Op0);
1401 Ops[1].setUser(this);
1402 Ops[1].setInitial(Op1);
1407 /// InitOperands - Initialize the operands list of this with 3 operands.
1408 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
1409 const SDValue &Op2) {
1410 Ops[0].setUser(this);
1411 Ops[0].setInitial(Op0);
1412 Ops[1].setUser(this);
1413 Ops[1].setInitial(Op1);
1414 Ops[2].setUser(this);
1415 Ops[2].setInitial(Op2);
1420 /// InitOperands - Initialize the operands list of this with 4 operands.
1421 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
1422 const SDValue &Op2, const SDValue &Op3) {
1423 Ops[0].setUser(this);
1424 Ops[0].setInitial(Op0);
1425 Ops[1].setUser(this);
1426 Ops[1].setInitial(Op1);
1427 Ops[2].setUser(this);
1428 Ops[2].setInitial(Op2);
1429 Ops[3].setUser(this);
1430 Ops[3].setInitial(Op3);
1435 /// InitOperands - Initialize the operands list of this with N operands.
1436 void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
1437 for (unsigned i = 0; i != N; ++i) {
1438 Ops[i].setUser(this);
1439 Ops[i].setInitial(Vals[i]);
1445 /// DropOperands - Release the operands and set this node to have
1447 void DropOperands();
1451 // Define inline functions from the SDValue class.
1453 inline unsigned SDValue::getOpcode() const {
1454 return Node->getOpcode();
1456 inline MVT SDValue::getValueType() const {
1457 return Node->getValueType(ResNo);
1459 inline unsigned SDValue::getNumOperands() const {
1460 return Node->getNumOperands();
1462 inline const SDValue &SDValue::getOperand(unsigned i) const {
1463 return Node->getOperand(i);
1465 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1466 return Node->getConstantOperandVal(i);
1468 inline bool SDValue::isTargetOpcode() const {
1469 return Node->isTargetOpcode();
1471 inline bool SDValue::isMachineOpcode() const {
1472 return Node->isMachineOpcode();
1474 inline unsigned SDValue::getMachineOpcode() const {
1475 return Node->getMachineOpcode();
1477 inline bool SDValue::use_empty() const {
1478 return !Node->hasAnyUseOfValue(ResNo);
1480 inline bool SDValue::hasOneUse() const {
1481 return Node->hasNUsesOfValue(1, ResNo);
1483 inline const DebugLoc SDValue::getDebugLoc() const {
1484 return Node->getDebugLoc();
1487 // Define inline functions from the SDUse class.
1489 inline void SDUse::set(const SDValue &V) {
1490 if (Val.getNode()) removeFromList();
1492 if (V.getNode()) V.getNode()->addUse(*this);
1495 inline void SDUse::setInitial(const SDValue &V) {
1497 V.getNode()->addUse(*this);
1500 inline void SDUse::setNode(SDNode *N) {
1501 if (Val.getNode()) removeFromList();
1503 if (N) N->addUse(*this);
1506 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1507 /// to allow co-allocation of node operands with the node itself.
1508 class UnarySDNode : public SDNode {
1511 UnarySDNode(unsigned Opc, SDVTList VTs, SDValue X)
1512 : SDNode(Opc, VTs) {
1513 InitOperands(&Op, X);
1517 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1518 /// to allow co-allocation of node operands with the node itself.
1519 class BinarySDNode : public SDNode {
1522 BinarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y)
1523 : SDNode(Opc, VTs) {
1524 InitOperands(Ops, X, Y);
1528 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1529 /// to allow co-allocation of node operands with the node itself.
1530 class TernarySDNode : public SDNode {
1533 TernarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y,
1535 : SDNode(Opc, VTs) {
1536 InitOperands(Ops, X, Y, Z);
1541 /// HandleSDNode - This class is used to form a handle around another node that
1542 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1543 /// operand. This node should be directly created by end-users and not added to
1544 /// the AllNodes list.
1545 class HandleSDNode : public SDNode {
1548 // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1551 explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
1553 explicit HandleSDNode(SDValue X)
1555 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
1556 InitOperands(&Op, X);
1559 const SDValue &getValue() const { return Op; }
1562 /// Abstact virtual class for operations for memory operations
1563 class MemSDNode : public SDNode {
1565 // MemoryVT - VT of in-memory value.
1568 //! SrcValue - Memory location for alias analysis.
1569 const Value *SrcValue;
1571 //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
1574 /// Flags - the low bit indicates whether this is a volatile reference;
1575 /// the remainder is a log2 encoding of the alignment in bytes.
1579 MemSDNode(unsigned Opc, SDVTList VTs, MVT MemoryVT,
1580 const Value *srcValue, int SVOff,
1581 unsigned alignment, bool isvolatile);
1583 MemSDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps,
1584 MVT MemoryVT, const Value *srcValue, int SVOff,
1585 unsigned alignment, bool isvolatile);
1587 /// Returns alignment and volatility of the memory access
1588 unsigned getAlignment() const { return (1u << (Flags >> 1)) >> 1; }
1589 bool isVolatile() const { return Flags & 1; }
1591 /// Returns the SrcValue and offset that describes the location of the access
1592 const Value *getSrcValue() const { return SrcValue; }
1593 int getSrcValueOffset() const { return SVOffset; }
1595 /// getMemoryVT - Return the type of the in-memory value.
1596 MVT getMemoryVT() const { return MemoryVT; }
1598 /// getMemOperand - Return a MachineMemOperand object describing the memory
1599 /// reference performed by operation.
1600 MachineMemOperand getMemOperand() const;
1602 const SDValue &getChain() const { return getOperand(0); }
1603 const SDValue &getBasePtr() const {
1604 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1607 /// getRawFlags - Represent the flags as a bunch of bits.
1609 unsigned getRawFlags() const { return Flags; }
1611 // Methods to support isa and dyn_cast
1612 static bool classof(const MemSDNode *) { return true; }
1613 static bool classof(const SDNode *N) {
1614 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1615 // with either an intrinsic or a target opcode.
1616 return N->getOpcode() == ISD::LOAD ||
1617 N->getOpcode() == ISD::STORE ||
1618 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1619 N->getOpcode() == ISD::ATOMIC_SWAP ||
1620 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1621 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1622 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1623 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1624 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1625 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1626 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1627 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1628 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1629 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1630 N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1631 N->getOpcode() == ISD::INTRINSIC_VOID ||
1632 N->isTargetOpcode();
1636 /// AtomicSDNode - A SDNode reprenting atomic operations.
1638 class AtomicSDNode : public MemSDNode {
1642 // Opc: opcode for atomic
1643 // VTL: value type list
1644 // Chain: memory chain for operaand
1645 // Ptr: address to update as a SDValue
1646 // Cmp: compare value
1648 // SrcVal: address to update as a Value (used for MemOperand)
1649 // Align: alignment of memory
1650 AtomicSDNode(unsigned Opc, SDVTList VTL, MVT MemVT,
1651 SDValue Chain, SDValue Ptr,
1652 SDValue Cmp, SDValue Swp, const Value* SrcVal,
1654 : MemSDNode(Opc, VTL, MemVT, SrcVal, /*SVOffset=*/0,
1655 Align, /*isVolatile=*/true) {
1656 InitOperands(Ops, Chain, Ptr, Cmp, Swp);
1658 AtomicSDNode(unsigned Opc, SDVTList VTL, MVT MemVT,
1659 SDValue Chain, SDValue Ptr,
1660 SDValue Val, const Value* SrcVal, unsigned Align=0)
1661 : MemSDNode(Opc, VTL, MemVT, SrcVal, /*SVOffset=*/0,
1662 Align, /*isVolatile=*/true) {
1663 InitOperands(Ops, Chain, Ptr, Val);
1666 const SDValue &getBasePtr() const { return getOperand(1); }
1667 const SDValue &getVal() const { return getOperand(2); }
1669 bool isCompareAndSwap() const {
1670 unsigned Op = getOpcode();
1671 return Op == ISD::ATOMIC_CMP_SWAP;
1674 // Methods to support isa and dyn_cast
1675 static bool classof(const AtomicSDNode *) { return true; }
1676 static bool classof(const SDNode *N) {
1677 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1678 N->getOpcode() == ISD::ATOMIC_SWAP ||
1679 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1680 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1681 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1682 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1683 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1684 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1685 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1686 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1687 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1688 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1692 /// MemIntrinsicSDNode - This SDNode is used for target intrinsic that touches
1693 /// memory and need an associated memory operand.
1695 class MemIntrinsicSDNode : public MemSDNode {
1696 bool ReadMem; // Intrinsic reads memory
1697 bool WriteMem; // Intrinsic writes memory
1699 MemIntrinsicSDNode(unsigned Opc, SDVTList VTs,
1700 const SDValue *Ops, unsigned NumOps,
1701 MVT MemoryVT, const Value *srcValue, int SVO,
1702 unsigned Align, bool Vol, bool ReadMem, bool WriteMem)
1703 : MemSDNode(Opc, VTs, Ops, NumOps, MemoryVT, srcValue, SVO, Align, Vol),
1704 ReadMem(ReadMem), WriteMem(WriteMem) {
1707 bool readMem() const { return ReadMem; }
1708 bool writeMem() const { return WriteMem; }
1710 // Methods to support isa and dyn_cast
1711 static bool classof(const MemIntrinsicSDNode *) { return true; }
1712 static bool classof(const SDNode *N) {
1713 // We lower some target intrinsics to their target opcode
1714 // early a node with a target opcode can be of this class
1715 return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1716 N->getOpcode() == ISD::INTRINSIC_VOID ||
1717 N->isTargetOpcode();
1721 class ConstantSDNode : public SDNode {
1722 const ConstantInt *Value;
1724 friend class SelectionDAG;
1725 ConstantSDNode(bool isTarget, const ConstantInt *val, MVT VT)
1726 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1731 const ConstantInt *getConstantIntValue() const { return Value; }
1732 const APInt &getAPIntValue() const { return Value->getValue(); }
1733 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1734 int64_t getSExtValue() const { return Value->getSExtValue(); }
1736 bool isNullValue() const { return Value->isNullValue(); }
1737 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1739 static bool classof(const ConstantSDNode *) { return true; }
1740 static bool classof(const SDNode *N) {
1741 return N->getOpcode() == ISD::Constant ||
1742 N->getOpcode() == ISD::TargetConstant;
1746 class ConstantFPSDNode : public SDNode {
1747 const ConstantFP *Value;
1749 friend class SelectionDAG;
1750 ConstantFPSDNode(bool isTarget, const ConstantFP *val, MVT VT)
1751 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1752 getSDVTList(VT)), Value(val) {
1756 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1757 const ConstantFP *getConstantFPValue() const { return Value; }
1759 /// isExactlyValue - We don't rely on operator== working on double values, as
1760 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1761 /// As such, this method can be used to do an exact bit-for-bit comparison of
1762 /// two floating point values.
1764 /// We leave the version with the double argument here because it's just so
1765 /// convenient to write "2.0" and the like. Without this function we'd
1766 /// have to duplicate its logic everywhere it's called.
1767 bool isExactlyValue(double V) const {
1769 // convert is not supported on this type
1770 if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
1773 Tmp.convert(Value->getValueAPF().getSemantics(),
1774 APFloat::rmNearestTiesToEven, &ignored);
1775 return isExactlyValue(Tmp);
1777 bool isExactlyValue(const APFloat& V) const;
1779 bool isValueValidForType(MVT VT, const APFloat& Val);
1781 static bool classof(const ConstantFPSDNode *) { return true; }
1782 static bool classof(const SDNode *N) {
1783 return N->getOpcode() == ISD::ConstantFP ||
1784 N->getOpcode() == ISD::TargetConstantFP;
1788 class GlobalAddressSDNode : public SDNode {
1789 GlobalValue *TheGlobal;
1792 friend class SelectionDAG;
1793 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT,
1797 GlobalValue *getGlobal() const { return TheGlobal; }
1798 int64_t getOffset() const { return Offset; }
1800 static bool classof(const GlobalAddressSDNode *) { return true; }
1801 static bool classof(const SDNode *N) {
1802 return N->getOpcode() == ISD::GlobalAddress ||
1803 N->getOpcode() == ISD::TargetGlobalAddress ||
1804 N->getOpcode() == ISD::GlobalTLSAddress ||
1805 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1809 class FrameIndexSDNode : public SDNode {
1812 friend class SelectionDAG;
1813 FrameIndexSDNode(int fi, MVT VT, bool isTarg)
1814 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1819 int getIndex() const { return FI; }
1821 static bool classof(const FrameIndexSDNode *) { return true; }
1822 static bool classof(const SDNode *N) {
1823 return N->getOpcode() == ISD::FrameIndex ||
1824 N->getOpcode() == ISD::TargetFrameIndex;
1828 class JumpTableSDNode : public SDNode {
1831 friend class SelectionDAG;
1832 JumpTableSDNode(int jti, MVT VT, bool isTarg)
1833 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1838 int getIndex() const { return JTI; }
1840 static bool classof(const JumpTableSDNode *) { return true; }
1841 static bool classof(const SDNode *N) {
1842 return N->getOpcode() == ISD::JumpTable ||
1843 N->getOpcode() == ISD::TargetJumpTable;
1847 class ConstantPoolSDNode : public SDNode {
1850 MachineConstantPoolValue *MachineCPVal;
1852 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1855 friend class SelectionDAG;
1856 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0)
1857 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1858 getSDVTList(VT)), Offset(o), Alignment(0) {
1859 assert((int)Offset >= 0 && "Offset is too large");
1862 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o, unsigned Align)
1863 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1864 getSDVTList(VT)), Offset(o), Alignment(Align) {
1865 assert((int)Offset >= 0 && "Offset is too large");
1868 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1870 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1871 getSDVTList(VT)), Offset(o), Alignment(0) {
1872 assert((int)Offset >= 0 && "Offset is too large");
1873 Val.MachineCPVal = v;
1874 Offset |= 1 << (sizeof(unsigned)*8-1);
1876 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1877 MVT VT, int o, unsigned Align)
1878 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1879 getSDVTList(VT)), Offset(o), Alignment(Align) {
1880 assert((int)Offset >= 0 && "Offset is too large");
1881 Val.MachineCPVal = v;
1882 Offset |= 1 << (sizeof(unsigned)*8-1);
1886 bool isMachineConstantPoolEntry() const {
1887 return (int)Offset < 0;
1890 Constant *getConstVal() const {
1891 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1892 return Val.ConstVal;
1895 MachineConstantPoolValue *getMachineCPVal() const {
1896 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1897 return Val.MachineCPVal;
1900 int getOffset() const {
1901 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1904 // Return the alignment of this constant pool object, which is either 0 (for
1905 // default alignment) or log2 of the desired value.
1906 unsigned getAlignment() const { return Alignment; }
1908 const Type *getType() const;
1910 static bool classof(const ConstantPoolSDNode *) { return true; }
1911 static bool classof(const SDNode *N) {
1912 return N->getOpcode() == ISD::ConstantPool ||
1913 N->getOpcode() == ISD::TargetConstantPool;
1917 class BasicBlockSDNode : public SDNode {
1918 MachineBasicBlock *MBB;
1920 friend class SelectionDAG;
1921 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1922 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1926 MachineBasicBlock *getBasicBlock() const { return MBB; }
1928 static bool classof(const BasicBlockSDNode *) { return true; }
1929 static bool classof(const SDNode *N) {
1930 return N->getOpcode() == ISD::BasicBlock;
1934 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1935 /// used when the SelectionDAG needs to make a simple reference to something
1936 /// in the LLVM IR representation.
1938 /// Note that this is not used for carrying alias information; that is done
1939 /// with MemOperandSDNode, which includes a Value which is required to be a
1940 /// pointer, and several other fields specific to memory references.
1942 class SrcValueSDNode : public SDNode {
1945 friend class SelectionDAG;
1946 /// Create a SrcValue for a general value.
1947 explicit SrcValueSDNode(const Value *v)
1948 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1951 /// getValue - return the contained Value.
1952 const Value *getValue() const { return V; }
1954 static bool classof(const SrcValueSDNode *) { return true; }
1955 static bool classof(const SDNode *N) {
1956 return N->getOpcode() == ISD::SRCVALUE;
1961 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
1962 /// used to represent a reference to memory after ISD::LOAD
1963 /// and ISD::STORE have been lowered.
1965 class MemOperandSDNode : public SDNode {
1967 friend class SelectionDAG;
1968 /// Create a MachineMemOperand node
1969 explicit MemOperandSDNode(const MachineMemOperand &mo)
1970 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1973 /// MO - The contained MachineMemOperand.
1974 const MachineMemOperand MO;
1976 static bool classof(const MemOperandSDNode *) { return true; }
1977 static bool classof(const SDNode *N) {
1978 return N->getOpcode() == ISD::MEMOPERAND;
1983 class RegisterSDNode : public SDNode {
1986 friend class SelectionDAG;
1987 RegisterSDNode(unsigned reg, MVT VT)
1988 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1992 unsigned getReg() const { return Reg; }
1994 static bool classof(const RegisterSDNode *) { return true; }
1995 static bool classof(const SDNode *N) {
1996 return N->getOpcode() == ISD::Register;
2000 class DbgStopPointSDNode : public SDNode {
2006 friend class SelectionDAG;
2007 DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
2009 : SDNode(ISD::DBG_STOPPOINT, getSDVTList(MVT::Other)),
2010 Line(l), Column(c), CU(cu) {
2011 InitOperands(&Chain, ch);
2014 unsigned getLine() const { return Line; }
2015 unsigned getColumn() const { return Column; }
2016 Value *getCompileUnit() const { return CU; }
2018 static bool classof(const DbgStopPointSDNode *) { return true; }
2019 static bool classof(const SDNode *N) {
2020 return N->getOpcode() == ISD::DBG_STOPPOINT;
2024 class LabelSDNode : public SDNode {
2028 friend class SelectionDAG;
2029 LabelSDNode(unsigned NodeTy, SDValue ch, unsigned id)
2030 : SDNode(NodeTy, getSDVTList(MVT::Other)), LabelID(id) {
2031 InitOperands(&Chain, ch);
2034 unsigned getLabelID() const { return LabelID; }
2036 static bool classof(const LabelSDNode *) { return true; }
2037 static bool classof(const SDNode *N) {
2038 return N->getOpcode() == ISD::DBG_LABEL ||
2039 N->getOpcode() == ISD::EH_LABEL;
2043 class ExternalSymbolSDNode : public SDNode {
2046 friend class SelectionDAG;
2047 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT VT)
2048 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
2049 getSDVTList(VT)), Symbol(Sym) {
2053 const char *getSymbol() const { return Symbol; }
2055 static bool classof(const ExternalSymbolSDNode *) { return true; }
2056 static bool classof(const SDNode *N) {
2057 return N->getOpcode() == ISD::ExternalSymbol ||
2058 N->getOpcode() == ISD::TargetExternalSymbol;
2062 class CondCodeSDNode : public SDNode {
2063 ISD::CondCode Condition;
2065 friend class SelectionDAG;
2066 explicit CondCodeSDNode(ISD::CondCode Cond)
2067 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
2071 ISD::CondCode get() const { return Condition; }
2073 static bool classof(const CondCodeSDNode *) { return true; }
2074 static bool classof(const SDNode *N) {
2075 return N->getOpcode() == ISD::CONDCODE;
2079 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
2080 /// future and most targets don't support it.
2081 class CvtRndSatSDNode : public SDNode {
2082 ISD::CvtCode CvtCode;
2084 friend class SelectionDAG;
2085 explicit CvtRndSatSDNode(MVT VT, const SDValue *Ops, unsigned NumOps,
2087 : SDNode(ISD::CONVERT_RNDSAT, getSDVTList(VT), Ops, NumOps), CvtCode(Code) {
2088 assert(NumOps == 5 && "wrong number of operations");
2091 ISD::CvtCode getCvtCode() const { return CvtCode; }
2093 static bool classof(const CvtRndSatSDNode *) { return true; }
2094 static bool classof(const SDNode *N) {
2095 return N->getOpcode() == ISD::CONVERT_RNDSAT;
2102 static const uint64_t NoFlagSet = 0ULL;
2103 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
2104 static const uint64_t ZExtOffs = 0;
2105 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
2106 static const uint64_t SExtOffs = 1;
2107 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
2108 static const uint64_t InRegOffs = 2;
2109 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
2110 static const uint64_t SRetOffs = 3;
2111 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
2112 static const uint64_t ByValOffs = 4;
2113 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
2114 static const uint64_t NestOffs = 5;
2115 static const uint64_t ByValAlign = 0xFULL << 6; //< Struct alignment
2116 static const uint64_t ByValAlignOffs = 6;
2117 static const uint64_t Split = 1ULL << 10;
2118 static const uint64_t SplitOffs = 10;
2119 static const uint64_t OrigAlign = 0x1FULL<<27;
2120 static const uint64_t OrigAlignOffs = 27;
2121 static const uint64_t ByValSize = 0xffffffffULL << 32; //< Struct size
2122 static const uint64_t ByValSizeOffs = 32;
2124 static const uint64_t One = 1ULL; //< 1 of this type, for shifts
2128 ArgFlagsTy() : Flags(0) { }
2130 bool isZExt() const { return Flags & ZExt; }
2131 void setZExt() { Flags |= One << ZExtOffs; }
2133 bool isSExt() const { return Flags & SExt; }
2134 void setSExt() { Flags |= One << SExtOffs; }
2136 bool isInReg() const { return Flags & InReg; }
2137 void setInReg() { Flags |= One << InRegOffs; }
2139 bool isSRet() const { return Flags & SRet; }
2140 void setSRet() { Flags |= One << SRetOffs; }
2142 bool isByVal() const { return Flags & ByVal; }
2143 void setByVal() { Flags |= One << ByValOffs; }
2145 bool isNest() const { return Flags & Nest; }
2146 void setNest() { Flags |= One << NestOffs; }
2148 unsigned getByValAlign() const {
2150 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
2152 void setByValAlign(unsigned A) {
2153 Flags = (Flags & ~ByValAlign) |
2154 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
2157 bool isSplit() const { return Flags & Split; }
2158 void setSplit() { Flags |= One << SplitOffs; }
2160 unsigned getOrigAlign() const {
2162 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
2164 void setOrigAlign(unsigned A) {
2165 Flags = (Flags & ~OrigAlign) |
2166 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
2169 unsigned getByValSize() const {
2170 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
2172 void setByValSize(unsigned S) {
2173 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
2176 /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
2177 std::string getArgFlagsString();
2179 /// getRawBits - Represent the flags as a bunch of bits.
2180 uint64_t getRawBits() const { return Flags; }
2184 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
2185 class ARG_FLAGSSDNode : public SDNode {
2186 ISD::ArgFlagsTy TheFlags;
2188 friend class SelectionDAG;
2189 explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
2190 : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
2193 ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
2195 static bool classof(const ARG_FLAGSSDNode *) { return true; }
2196 static bool classof(const SDNode *N) {
2197 return N->getOpcode() == ISD::ARG_FLAGS;
2201 /// CallSDNode - Node for calls -- ISD::CALL.
2202 class CallSDNode : public SDNode {
2203 unsigned CallingConv;
2206 // We might eventually want a full-blown Attributes for the result; that
2207 // will expand the size of the representation. At the moment we only
2211 friend class SelectionDAG;
2212 CallSDNode(unsigned cc, bool isvararg, bool istailcall, bool isinreg,
2213 SDVTList VTs, const SDValue *Operands, unsigned numOperands)
2214 : SDNode(ISD::CALL, VTs, Operands, numOperands),
2215 CallingConv(cc), IsVarArg(isvararg), IsTailCall(istailcall),
2218 unsigned getCallingConv() const { return CallingConv; }
2219 unsigned isVarArg() const { return IsVarArg; }
2220 unsigned isTailCall() const { return IsTailCall; }
2221 unsigned isInreg() const { return Inreg; }
2223 /// Set this call to not be marked as a tail call. Normally setter
2224 /// methods in SDNodes are unsafe because it breaks the CSE map,
2225 /// but we don't include the tail call flag for calls so it's ok
2227 void setNotTailCall() { IsTailCall = false; }
2229 SDValue getChain() const { return getOperand(0); }
2230 SDValue getCallee() const { return getOperand(1); }
2232 unsigned getNumArgs() const { return (getNumOperands() - 2) / 2; }
2233 SDValue getArg(unsigned i) const { return getOperand(2+2*i); }
2234 SDValue getArgFlagsVal(unsigned i) const {
2235 return getOperand(3+2*i);
2237 ISD::ArgFlagsTy getArgFlags(unsigned i) const {
2238 return cast<ARG_FLAGSSDNode>(getArgFlagsVal(i).getNode())->getArgFlags();
2241 unsigned getNumRetVals() const { return getNumValues() - 1; }
2242 MVT getRetValType(unsigned i) const { return getValueType(i); }
2244 static bool classof(const CallSDNode *) { return true; }
2245 static bool classof(const SDNode *N) {
2246 return N->getOpcode() == ISD::CALL;
2250 /// VTSDNode - This class is used to represent MVT's, which are used
2251 /// to parameterize some operations.
2252 class VTSDNode : public SDNode {
2255 friend class SelectionDAG;
2256 explicit VTSDNode(MVT VT)
2257 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
2261 MVT getVT() const { return ValueType; }
2263 static bool classof(const VTSDNode *) { return true; }
2264 static bool classof(const SDNode *N) {
2265 return N->getOpcode() == ISD::VALUETYPE;
2269 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
2271 class LSBaseSDNode : public MemSDNode {
2273 //! Operand array for load and store
2275 \note Moving this array to the base class captures more
2276 common functionality shared between LoadSDNode and
2281 LSBaseSDNode(ISD::NodeType NodeTy, SDValue *Operands, unsigned numOperands,
2282 SDVTList VTs, ISD::MemIndexedMode AM, MVT VT,
2283 const Value *SV, int SVO, unsigned Align, bool Vol)
2284 : MemSDNode(NodeTy, VTs, VT, SV, SVO, Align, Vol) {
2286 InitOperands(Ops, Operands, numOperands);
2287 assert(Align != 0 && "Loads and stores should have non-zero aligment");
2288 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
2289 "Only indexed loads and stores have a non-undef offset operand");
2292 const SDValue &getOffset() const {
2293 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2296 /// getAddressingMode - Return the addressing mode for this load or store:
2297 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2298 ISD::MemIndexedMode getAddressingMode() const {
2299 return ISD::MemIndexedMode(SubclassData & 7);
2302 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
2303 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2305 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
2306 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2308 static bool classof(const LSBaseSDNode *) { return true; }
2309 static bool classof(const SDNode *N) {
2310 return N->getOpcode() == ISD::LOAD ||
2311 N->getOpcode() == ISD::STORE;
2315 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2317 class LoadSDNode : public LSBaseSDNode {
2319 friend class SelectionDAG;
2320 LoadSDNode(SDValue *ChainPtrOff, SDVTList VTs,
2321 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT,
2322 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2323 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
2324 VTs, AM, LVT, SV, O, Align, Vol) {
2325 SubclassData |= (unsigned short)ETy << 3;
2329 /// getExtensionType - Return whether this is a plain node,
2330 /// or one of the varieties of value-extending loads.
2331 ISD::LoadExtType getExtensionType() const {
2332 return ISD::LoadExtType((SubclassData >> 3) & 3);
2335 const SDValue &getBasePtr() const { return getOperand(1); }
2336 const SDValue &getOffset() const { return getOperand(2); }
2338 static bool classof(const LoadSDNode *) { return true; }
2339 static bool classof(const SDNode *N) {
2340 return N->getOpcode() == ISD::LOAD;
2344 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2346 class StoreSDNode : public LSBaseSDNode {
2348 friend class SelectionDAG;
2349 StoreSDNode(SDValue *ChainValuePtrOff, SDVTList VTs,
2350 ISD::MemIndexedMode AM, bool isTrunc, MVT SVT,
2351 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2352 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
2353 VTs, AM, SVT, SV, O, Align, Vol) {
2354 SubclassData |= (unsigned short)isTrunc << 3;
2358 /// isTruncatingStore - Return true if the op does a truncation before store.
2359 /// For integers this is the same as doing a TRUNCATE and storing the result.
2360 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2361 bool isTruncatingStore() const { return (SubclassData >> 3) & 1; }
2363 const SDValue &getValue() const { return getOperand(1); }
2364 const SDValue &getBasePtr() const { return getOperand(2); }
2365 const SDValue &getOffset() const { return getOperand(3); }
2367 static bool classof(const StoreSDNode *) { return true; }
2368 static bool classof(const SDNode *N) {
2369 return N->getOpcode() == ISD::STORE;
2374 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
2378 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2380 bool operator==(const SDNodeIterator& x) const {
2381 return Operand == x.Operand;
2383 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2385 const SDNodeIterator &operator=(const SDNodeIterator &I) {
2386 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2387 Operand = I.Operand;
2391 pointer operator*() const {
2392 return Node->getOperand(Operand).getNode();
2394 pointer operator->() const { return operator*(); }
2396 SDNodeIterator& operator++() { // Preincrement
2400 SDNodeIterator operator++(int) { // Postincrement
2401 SDNodeIterator tmp = *this; ++*this; return tmp;
2404 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2405 static SDNodeIterator end (SDNode *N) {
2406 return SDNodeIterator(N, N->getNumOperands());
2409 unsigned getOperand() const { return Operand; }
2410 const SDNode *getNode() const { return Node; }
2413 template <> struct GraphTraits<SDNode*> {
2414 typedef SDNode NodeType;
2415 typedef SDNodeIterator ChildIteratorType;
2416 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2417 static inline ChildIteratorType child_begin(NodeType *N) {
2418 return SDNodeIterator::begin(N);
2420 static inline ChildIteratorType child_end(NodeType *N) {
2421 return SDNodeIterator::end(N);
2425 /// LargestSDNode - The largest SDNode class.
2427 typedef LoadSDNode LargestSDNode;
2429 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2432 typedef ARG_FLAGSSDNode MostAlignedSDNode;
2435 /// isNormalLoad - Returns true if the specified node is a non-extending
2436 /// and unindexed load.
2437 inline bool isNormalLoad(const SDNode *N) {
2438 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2439 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2440 Ld->getAddressingMode() == ISD::UNINDEXED;
2443 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2445 inline bool isNON_EXTLoad(const SDNode *N) {
2446 return isa<LoadSDNode>(N) &&
2447 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2450 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2452 inline bool isEXTLoad(const SDNode *N) {
2453 return isa<LoadSDNode>(N) &&
2454 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2457 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2459 inline bool isSEXTLoad(const SDNode *N) {
2460 return isa<LoadSDNode>(N) &&
2461 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2464 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2466 inline bool isZEXTLoad(const SDNode *N) {
2467 return isa<LoadSDNode>(N) &&
2468 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2471 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2473 inline bool isUNINDEXEDLoad(const SDNode *N) {
2474 return isa<LoadSDNode>(N) &&
2475 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2478 /// isNormalStore - Returns true if the specified node is a non-truncating
2479 /// and unindexed store.
2480 inline bool isNormalStore(const SDNode *N) {
2481 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2482 return St && !St->isTruncatingStore() &&
2483 St->getAddressingMode() == ISD::UNINDEXED;
2486 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2488 inline bool isNON_TRUNCStore(const SDNode *N) {
2489 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2492 /// isTRUNCStore - Returns true if the specified node is a truncating
2494 inline bool isTRUNCStore(const SDNode *N) {
2495 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2498 /// isUNINDEXEDStore - Returns true if the specified node is an
2499 /// unindexed store.
2500 inline bool isUNINDEXEDStore(const SDNode *N) {
2501 return isa<StoreSDNode>(N) &&
2502 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2507 } // end llvm namespace