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"
39 class MachineBasicBlock;
40 class MachineConstantPoolValue;
42 class CompileUnitDesc;
43 template <typename T> struct DenseMapInfo;
44 template <typename T> struct simplify_type;
45 template <typename T> struct ilist_traits;
47 /// SDVTList - This represents a list of ValueType's that has been intern'd by
48 /// a SelectionDAG. Instances of this simple value class are returned by
49 /// SelectionDAG::getVTList(...).
53 unsigned short NumVTs;
56 /// ISD namespace - This namespace contains an enum which represents all of the
57 /// SelectionDAG node types and value types.
61 //===--------------------------------------------------------------------===//
62 /// ISD::NodeType enum - This enum defines all of the operators valid in a
66 // DELETED_NODE - This is an illegal flag value that is used to catch
67 // errors. This opcode is not a legal opcode for any node.
70 // EntryToken - This is the marker used to indicate the start of the region.
73 // TokenFactor - This node takes multiple tokens as input and produces a
74 // single token result. This is used to represent the fact that the operand
75 // operators are independent of each other.
78 // AssertSext, AssertZext - These nodes record if a register contains a
79 // value that has already been zero or sign extended from a narrower type.
80 // These nodes take two operands. The first is the node that has already
81 // been extended, and the second is a value type node indicating the width
83 AssertSext, AssertZext,
85 // Various leaf nodes.
86 BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
88 GlobalAddress, GlobalTLSAddress, FrameIndex,
89 JumpTable, ConstantPool, ExternalSymbol,
91 // The address of the GOT
94 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
95 // llvm.returnaddress on the DAG. These nodes take one operand, the index
96 // of the frame or return address to return. An index of zero corresponds
97 // to the current function's frame or return address, an index of one to the
98 // parent's frame or return address, and so on.
99 FRAMEADDR, RETURNADDR,
101 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
102 // first (possible) on-stack argument. This is needed for correct stack
103 // adjustment during unwind.
104 FRAME_TO_ARGS_OFFSET,
106 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
107 // address of the exception block on entry to an landing pad block.
110 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
111 // the selection index of the exception thrown.
114 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
115 // 'eh_return' gcc dwarf builtin, which is used to return from
116 // exception. The general meaning is: adjust stack by OFFSET and pass
117 // execution to HANDLER. Many platform-related details also :)
120 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
121 // simplification of the constant.
125 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
126 // anything else with this node, and this is valid in the target-specific
127 // dag, turning into a GlobalAddress operand.
129 TargetGlobalTLSAddress,
133 TargetExternalSymbol,
135 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
136 /// This node represents a target intrinsic function with no side effects.
137 /// The first operand is the ID number of the intrinsic from the
138 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
139 /// node has returns the result of the intrinsic.
142 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
143 /// This node represents a target intrinsic function with side effects that
144 /// returns a result. The first operand is a chain pointer. The second is
145 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
146 /// operands to the intrinsic follow. The node has two results, the result
147 /// of the intrinsic and an output chain.
150 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
151 /// This node represents a target intrinsic function with side effects that
152 /// does not return a result. The first operand is a chain pointer. The
153 /// second is the ID number of the intrinsic from the llvm::Intrinsic
154 /// namespace. The operands to the intrinsic follow.
157 // CopyToReg - This node has three operands: a chain, a register number to
158 // set to this value, and a value.
161 // CopyFromReg - This node indicates that the input value is a virtual or
162 // physical register that is defined outside of the scope of this
163 // SelectionDAG. The register is available from the RegisterSDNode object.
166 // UNDEF - An undefined node
169 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
170 /// represents the formal arguments for a function. CC# is a Constant value
171 /// indicating the calling convention of the function, and ISVARARG is a
172 /// flag that indicates whether the function is varargs or not. This node
173 /// has one result value for each incoming argument, plus one for the output
174 /// chain. It must be custom legalized. See description of CALL node for
175 /// FLAG argument contents explanation.
179 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CALLEE,
180 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
181 /// This node represents a fully general function call, before the legalizer
182 /// runs. This has one result value for each argument / flag pair, plus
183 /// a chain result. It must be custom legalized. Flag argument indicates
184 /// misc. argument attributes. Currently:
186 /// Bit 1 - 'inreg' attribute
187 /// Bit 2 - 'sret' attribute
188 /// Bit 4 - 'byval' attribute
189 /// Bit 5 - 'nest' attribute
190 /// Bit 6-9 - alignment of byval structures
191 /// Bit 10-26 - size of byval structures
192 /// Bits 31:27 - argument ABI alignment in the first argument piece and
193 /// alignment '1' in other argument pieces.
195 /// CALL nodes use the CallSDNode subclass of SDNode, which
196 /// additionally carries information about the calling convention,
197 /// whether the call is varargs, and if it's marked as a tail call.
201 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
202 // a Constant, which is required to be operand #1) half of the integer or
203 // float value specified as operand #0. This is only for use before
204 // legalization, for values that will be broken into multiple registers.
207 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
208 // two values of the same integer value type, this produces a value twice as
209 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
212 // MERGE_VALUES - This node takes multiple discrete operands and returns
213 // them all as its individual results. This nodes has exactly the same
214 // number of inputs and outputs, and is only valid before legalization.
215 // This node is useful for some pieces of the code generator that want to
216 // think about a single node with multiple results, not multiple nodes.
219 // Simple integer binary arithmetic operators.
220 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
222 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
223 // a signed/unsigned value of type i[2*N], and return the full value as
224 // two results, each of type iN.
225 SMUL_LOHI, UMUL_LOHI,
227 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
231 // CARRY_FALSE - This node is used when folding other nodes,
232 // like ADDC/SUBC, which indicate the carry result is always false.
235 // Carry-setting nodes for multiple precision addition and subtraction.
236 // These nodes take two operands of the same value type, and produce two
237 // results. The first result is the normal add or sub result, the second
238 // result is the carry flag result.
241 // Carry-using nodes for multiple precision addition and subtraction. These
242 // nodes take three operands: The first two are the normal lhs and rhs to
243 // the add or sub, and the third is the input carry flag. These nodes
244 // produce two results; the normal result of the add or sub, and the output
245 // carry flag. These nodes both read and write a carry flag to allow them
246 // to them to be chained together for add and sub of arbitrarily large
250 // RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
251 // These nodes take two operands: the normal LHS and RHS to the add. They
252 // produce two results: the normal result of the add, and a boolean that
253 // indicates if an overflow occured (*not* a flag, because it may be stored
254 // to memory, etc.). If the type of the boolean is not i1 then the high
255 // bits conform to getBooleanContents.
256 // These nodes are generated from the llvm.[su]add.with.overflow intrinsics.
259 // Same for subtraction
262 // Same for multiplication
265 // Simple binary floating point operators.
266 FADD, FSUB, FMUL, FDIV, FREM,
268 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
269 // DAG node does not require that X and Y have the same type, just that they
270 // are both floating point. X and the result must have the same type.
271 // FCOPYSIGN(f32, f64) is allowed.
274 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
275 // value as an integer 0/1 value.
278 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
279 /// with the specified, possibly variable, elements. The number of elements
280 /// is required to be a power of two.
283 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
284 /// at IDX replaced with VAL. If the type of VAL is larger than the vector
285 /// element type then VAL is truncated before replacement.
288 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
289 /// identified by the (potentially variable) element number IDX.
292 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
293 /// vector type with the same length and element type, this produces a
294 /// concatenated vector result value, with length equal to the sum of the
295 /// lengths of the input vectors.
298 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
299 /// vector value) starting with the (potentially variable) element number
300 /// IDX, which must be a multiple of the result vector length.
303 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
304 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
305 /// (maybe of an illegal datatype) or undef that indicate which value each
306 /// result element will get. The elements of VEC1/VEC2 are enumerated in
307 /// order. This is quite similar to the Altivec 'vperm' instruction, except
308 /// that the indices must be constants and are in terms of the element size
309 /// of VEC1/VEC2, not in terms of bytes.
312 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
313 /// scalar value into element 0 of the resultant vector type. The top
314 /// elements 1 to N-1 of the N-element vector are undefined.
317 // EXTRACT_SUBREG - This node is used to extract a sub-register value.
318 // This node takes a superreg and a constant sub-register index as operands.
319 // Note sub-register indices must be increasing. That is, if the
320 // sub-register index of a 8-bit sub-register is N, then the index for a
321 // 16-bit sub-register must be at least N+1.
324 // INSERT_SUBREG - This node is used to insert a sub-register value.
325 // This node takes a superreg, a subreg value, and a constant sub-register
326 // index as operands.
329 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
330 // an unsigned/signed value of type i[2*N], then return the top part.
333 // Bitwise operators - logical and, logical or, logical xor, shift left,
334 // shift right algebraic (shift in sign bits), shift right logical (shift in
335 // zeroes), rotate left, rotate right, and byteswap.
336 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
338 // Counting operators
341 // Select(COND, TRUEVAL, FALSEVAL). If the type of the boolean COND is not
342 // i1 then the high bits must conform to getBooleanContents.
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 true value iff the condition is
352 // true. If the result value type is not i1 then the high bits conform
353 // to getBooleanContents. The operands to this are the left and right
354 // operands to compare (ops #0, and #1) and the condition code to compare
355 // them with (op #2) as a CondCodeSDNode.
358 // Vector SetCC operator - This evaluates to a vector of integer elements
359 // with the high bit in each element set to true if the comparison is true
360 // and false if the comparison is false. All other bits in each element
361 // are undefined. The operands to this are the left and right operands
362 // to compare (ops #0, and #1) and the condition code to compare them with
363 // (op #2) as a CondCodeSDNode.
366 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
367 // integer shift operations, just like ADD/SUB_PARTS. The operation
369 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
370 SHL_PARTS, SRA_PARTS, SRL_PARTS,
372 // Conversion operators. These are all single input single output
373 // operations. For all of these, the result type must be strictly
374 // wider or narrower (depending on the operation) than the source
377 // SIGN_EXTEND - Used for integer types, replicating the sign bit
381 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
384 // ANY_EXTEND - Used for integer types. The high bits are undefined.
387 // TRUNCATE - Completely drop the high bits.
390 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
391 // depends on the first letter) to floating point.
395 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
396 // sign extend a small value in a large integer register (e.g. sign
397 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
398 // with the 7th bit). The size of the smaller type is indicated by the 1th
399 // operand, a ValueType node.
402 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
407 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
408 /// down to the precision of the destination VT. TRUNC is a flag, which is
409 /// always an integer that is zero or one. If TRUNC is 0, this is a
410 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
413 /// The TRUNC = 1 case is used in cases where we know that the value will
414 /// not be modified by the node, because Y is not using any of the extra
415 /// precision of source type. This allows certain transformations like
416 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
417 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
420 // FLT_ROUNDS_ - Returns current rounding mode:
423 // 1 Round to nearest
428 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
429 /// rounds it to a floating point value. It then promotes it and returns it
430 /// in a register of the same size. This operation effectively just
431 /// discards excess precision. The type to round down to is specified by
432 /// the VT operand, a VTSDNode.
435 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
438 // BIT_CONVERT - Theis operator converts between integer and FP values, as
439 // if one was stored to memory as integer and the other was loaded from the
440 // same address (or equivalently for vector format conversions, etc). The
441 // source and result are required to have the same bit size (e.g.
442 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
443 // conversions, but that is a noop, deleted by getNode().
446 // CONVERT_RNDSAT - This operator is used to support various conversions
447 // between various types (float, signed, unsigned and vectors of those
448 // types) with rounding and saturation. NOTE: Avoid using this operator as
449 // most target don't support it and the operator might be removed in the
450 // future. It takes the following arguments:
452 // 1) dest type (type to convert to)
453 // 2) src type (type to convert from)
456 // 5) ISD::CvtCode indicating the type of conversion to do
459 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
460 // FLOG, FLOG2, FLOG10, FEXP, FEXP2,
461 // FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary floating
462 // point operations. These are inspired by libm.
463 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
464 FLOG, FLOG2, FLOG10, FEXP, FEXP2,
465 FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR,
467 // LOAD and STORE have token chains as their first operand, then the same
468 // operands as an LLVM load/store instruction, then an offset node that
469 // is added / subtracted from the base pointer to form the address (for
470 // indexed memory ops).
473 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
474 // to a specified boundary. This node always has two return values: a new
475 // stack pointer value and a chain. The first operand is the token chain,
476 // the second is the number of bytes to allocate, and the third is the
477 // alignment boundary. The size is guaranteed to be a multiple of the stack
478 // alignment, and the alignment is guaranteed to be bigger than the stack
479 // alignment (if required) or 0 to get standard stack alignment.
482 // Control flow instructions. These all have token chains.
484 // BR - Unconditional branch. The first operand is the chain
485 // operand, the second is the MBB to branch to.
488 // BRIND - Indirect branch. The first operand is the chain, the second
489 // is the value to branch to, which must be of the same type as the target's
493 // BR_JT - Jumptable branch. The first operand is the chain, the second
494 // is the jumptable index, the last one is the jumptable entry index.
497 // BRCOND - Conditional branch. The first operand is the chain, the
498 // second is the condition, the third is the block to branch to if the
499 // condition is true. If the type of the condition is not i1, then the
500 // high bits must conform to getBooleanContents.
503 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
504 // that the condition is represented as condition code, and two nodes to
505 // compare, rather than as a combined SetCC node. The operands in order are
506 // chain, cc, lhs, rhs, block to branch to if condition is true.
509 // RET - Return from function. The first operand is the chain,
510 // and any subsequent operands are pairs of return value and return value
511 // attributes (see CALL for description of attributes) for the function.
512 // This operation can have variable number of operands.
515 // INLINEASM - Represents an inline asm block. This node always has two
516 // return values: a chain and a flag result. The inputs are as follows:
517 // Operand #0 : Input chain.
518 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
519 // Operand #2n+2: A RegisterNode.
520 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
521 // Operand #last: Optional, an incoming flag.
524 // DBG_LABEL, EH_LABEL - Represents a label in mid basic block used to track
525 // locations needed for debug and exception handling tables. These nodes
526 // take a chain as input and return a chain.
530 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
531 // local variable declarations for debugging information. First operand is
532 // a chain, while the next two operands are first two arguments (address
533 // and variable) of a llvm.dbg.declare instruction.
536 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
537 // value, the same type as the pointer type for the system, and an output
541 // STACKRESTORE has two operands, an input chain and a pointer to restore to
542 // it returns an output chain.
545 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
546 // a call sequence, and carry arbitrary information that target might want
547 // to know. The first operand is a chain, the rest are specified by the
548 // target and not touched by the DAG optimizers.
549 // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
550 CALLSEQ_START, // Beginning of a call sequence
551 CALLSEQ_END, // End of a call sequence
553 // VAARG - VAARG has three operands: an input chain, a pointer, and a
554 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
557 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
558 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
562 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
563 // pointer, and a SRCVALUE.
566 // SRCVALUE - This is a node type that holds a Value* that is used to
567 // make reference to a value in the LLVM IR.
570 // MEMOPERAND - This is a node that contains a MachineMemOperand which
571 // records information about a memory reference. This is used to make
572 // AliasAnalysis queries from the backend.
575 // PCMARKER - This corresponds to the pcmarker intrinsic.
578 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
579 // The only operand is a chain and a value and a chain are produced. The
580 // value is the contents of the architecture specific cycle counter like
581 // register (or other high accuracy low latency clock source)
584 // HANDLENODE node - Used as a handle for various purposes.
587 // DBG_STOPPOINT - This node is used to represent a source location for
588 // debug info. It takes token chain as input, and carries a line number,
589 // column number, and a pointer to a CompileUnitDesc object identifying
590 // the containing compilation unit. It produces a token chain as output.
593 // DEBUG_LOC - This node is used to represent source line information
594 // embedded in the code. It takes a token chain as input, then a line
595 // number, then a column then a file id (provided by MachineModuleInfo.) It
596 // produces a token chain as output.
599 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
600 // It takes as input a token chain, the pointer to the trampoline,
601 // the pointer to the nested function, the pointer to pass for the
602 // 'nest' parameter, a SRCVALUE for the trampoline and another for
603 // the nested function (allowing targets to access the original
604 // Function*). It produces the result of the intrinsic and a token
608 // TRAP - Trapping instruction
611 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
612 // their first operand. The other operands are the address to prefetch,
613 // read / write specifier, and locality specifier.
616 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
617 // store-store, device)
618 // This corresponds to the memory.barrier intrinsic.
619 // it takes an input chain, 4 operands to specify the type of barrier, an
620 // operand specifying if the barrier applies to device and uncached memory
621 // and produces an output chain.
624 // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
625 // this corresponds to the atomic.lcs intrinsic.
626 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
627 // the return is always the original value in *ptr
630 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
631 // this corresponds to the atomic.swap intrinsic.
632 // amt is stored to *ptr atomically.
633 // the return is always the original value in *ptr
636 // Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt)
637 // this corresponds to the atomic.load.[OpName] intrinsic.
638 // op(*ptr, amt) is stored to *ptr atomically.
639 // the return is always the original value in *ptr
651 // BUILTIN_OP_END - This must be the last enum value in this list.
657 /// isBuildVectorAllOnes - Return true if the specified node is a
658 /// BUILD_VECTOR where all of the elements are ~0 or undef.
659 bool isBuildVectorAllOnes(const SDNode *N);
661 /// isBuildVectorAllZeros - Return true if the specified node is a
662 /// BUILD_VECTOR where all of the elements are 0 or undef.
663 bool isBuildVectorAllZeros(const SDNode *N);
665 /// isScalarToVector - Return true if the specified node is a
666 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
667 /// element is not an undef.
668 bool isScalarToVector(const SDNode *N);
670 /// isDebugLabel - Return true if the specified node represents a debug
671 /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node).
672 bool isDebugLabel(const SDNode *N);
674 //===--------------------------------------------------------------------===//
675 /// MemIndexedMode enum - This enum defines the load / store indexed
676 /// addressing modes.
678 /// UNINDEXED "Normal" load / store. The effective address is already
679 /// computed and is available in the base pointer. The offset
680 /// operand is always undefined. In addition to producing a
681 /// chain, an unindexed load produces one value (result of the
682 /// load); an unindexed store does not produce a value.
684 /// PRE_INC Similar to the unindexed mode where the effective address is
685 /// PRE_DEC the value of the base pointer add / subtract the offset.
686 /// It considers the computation as being folded into the load /
687 /// store operation (i.e. the load / store does the address
688 /// computation as well as performing the memory transaction).
689 /// The base operand is always undefined. In addition to
690 /// producing a chain, pre-indexed load produces two values
691 /// (result of the load and the result of the address
692 /// computation); a pre-indexed store produces one value (result
693 /// of the address computation).
695 /// POST_INC The effective address is the value of the base pointer. The
696 /// POST_DEC value of the offset operand is then added to / subtracted
697 /// from the base after memory transaction. In addition to
698 /// producing a chain, post-indexed load produces two values
699 /// (the result of the load and the result of the base +/- offset
700 /// computation); a post-indexed store produces one value (the
701 /// the result of the base +/- offset computation).
703 enum MemIndexedMode {
712 //===--------------------------------------------------------------------===//
713 /// LoadExtType enum - This enum defines the three variants of LOADEXT
714 /// (load with extension).
716 /// SEXTLOAD loads the integer operand and sign extends it to a larger
717 /// integer result type.
718 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
719 /// integer result type.
720 /// EXTLOAD is used for three things: floating point extending loads,
721 /// integer extending loads [the top bits are undefined], and vector
722 /// extending loads [load into low elt].
732 //===--------------------------------------------------------------------===//
733 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
734 /// below work out, when considering SETFALSE (something that never exists
735 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
736 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
737 /// to. If the "N" column is 1, the result of the comparison is undefined if
738 /// the input is a NAN.
740 /// All of these (except for the 'always folded ops') should be handled for
741 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
742 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
744 /// Note that these are laid out in a specific order to allow bit-twiddling
745 /// to transform conditions.
747 // Opcode N U L G E Intuitive operation
748 SETFALSE, // 0 0 0 0 Always false (always folded)
749 SETOEQ, // 0 0 0 1 True if ordered and equal
750 SETOGT, // 0 0 1 0 True if ordered and greater than
751 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
752 SETOLT, // 0 1 0 0 True if ordered and less than
753 SETOLE, // 0 1 0 1 True if ordered and less than or equal
754 SETONE, // 0 1 1 0 True if ordered and operands are unequal
755 SETO, // 0 1 1 1 True if ordered (no nans)
756 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
757 SETUEQ, // 1 0 0 1 True if unordered or equal
758 SETUGT, // 1 0 1 0 True if unordered or greater than
759 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
760 SETULT, // 1 1 0 0 True if unordered or less than
761 SETULE, // 1 1 0 1 True if unordered, less than, or equal
762 SETUNE, // 1 1 1 0 True if unordered or not equal
763 SETTRUE, // 1 1 1 1 Always true (always folded)
764 // Don't care operations: undefined if the input is a nan.
765 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
766 SETEQ, // 1 X 0 0 1 True if equal
767 SETGT, // 1 X 0 1 0 True if greater than
768 SETGE, // 1 X 0 1 1 True if greater than or equal
769 SETLT, // 1 X 1 0 0 True if less than
770 SETLE, // 1 X 1 0 1 True if less than or equal
771 SETNE, // 1 X 1 1 0 True if not equal
772 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
774 SETCC_INVALID // Marker value.
777 /// isSignedIntSetCC - Return true if this is a setcc instruction that
778 /// performs a signed comparison when used with integer operands.
779 inline bool isSignedIntSetCC(CondCode Code) {
780 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
783 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
784 /// performs an unsigned comparison when used with integer operands.
785 inline bool isUnsignedIntSetCC(CondCode Code) {
786 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
789 /// isTrueWhenEqual - Return true if the specified condition returns true if
790 /// the two operands to the condition are equal. Note that if one of the two
791 /// operands is a NaN, this value is meaningless.
792 inline bool isTrueWhenEqual(CondCode Cond) {
793 return ((int)Cond & 1) != 0;
796 /// getUnorderedFlavor - This function returns 0 if the condition is always
797 /// false if an operand is a NaN, 1 if the condition is always true if the
798 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
800 inline unsigned getUnorderedFlavor(CondCode Cond) {
801 return ((int)Cond >> 3) & 3;
804 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
805 /// 'op' is a valid SetCC operation.
806 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
808 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
809 /// when given the operation for (X op Y).
810 CondCode getSetCCSwappedOperands(CondCode Operation);
812 /// getSetCCOrOperation - Return the result of a logical OR between different
813 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
814 /// function returns SETCC_INVALID if it is not possible to represent the
815 /// resultant comparison.
816 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
818 /// getSetCCAndOperation - Return the result of a logical AND between
819 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
820 /// function returns SETCC_INVALID if it is not possible to represent the
821 /// resultant comparison.
822 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
824 //===--------------------------------------------------------------------===//
825 /// CvtCode enum - This enum defines the various converts CONVERT_RNDSAT
828 CVT_FF, // Float from Float
829 CVT_FS, // Float from Signed
830 CVT_FU, // Float from Unsigned
831 CVT_SF, // Signed from Float
832 CVT_UF, // Unsigned from Float
833 CVT_SS, // Signed from Signed
834 CVT_SU, // Signed from Unsigned
835 CVT_US, // Unsigned from Signed
836 CVT_UU, // Unsigned from Unsigned
837 CVT_INVALID // Marker - Invalid opcode
839 } // end llvm::ISD namespace
842 //===----------------------------------------------------------------------===//
843 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
844 /// values as the result of a computation. Many nodes return multiple values,
845 /// from loads (which define a token and a return value) to ADDC (which returns
846 /// a result and a carry value), to calls (which may return an arbitrary number
849 /// As such, each use of a SelectionDAG computation must indicate the node that
850 /// computes it as well as which return value to use from that node. This pair
851 /// of information is represented with the SDValue value type.
854 SDNode *Node; // The node defining the value we are using.
855 unsigned ResNo; // Which return value of the node we are using.
857 SDValue() : Node(0), ResNo(0) {}
858 SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
860 /// get the index which selects a specific result in the SDNode
861 unsigned getResNo() const { return ResNo; }
863 /// get the SDNode which holds the desired result
864 SDNode *getNode() const { return Node; }
867 void setNode(SDNode *N) { Node = N; }
869 bool operator==(const SDValue &O) const {
870 return Node == O.Node && ResNo == O.ResNo;
872 bool operator!=(const SDValue &O) const {
873 return !operator==(O);
875 bool operator<(const SDValue &O) const {
876 return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
879 SDValue getValue(unsigned R) const {
880 return SDValue(Node, R);
883 // isOperandOf - Return true if this node is an operand of N.
884 bool isOperandOf(SDNode *N) const;
886 /// getValueType - Return the ValueType of the referenced return value.
888 inline MVT getValueType() const;
890 /// getValueSizeInBits - Returns the size of the value in bits.
892 unsigned getValueSizeInBits() const {
893 return getValueType().getSizeInBits();
896 // Forwarding methods - These forward to the corresponding methods in SDNode.
897 inline unsigned getOpcode() const;
898 inline unsigned getNumOperands() const;
899 inline const SDValue &getOperand(unsigned i) const;
900 inline uint64_t getConstantOperandVal(unsigned i) const;
901 inline bool isTargetOpcode() const;
902 inline bool isMachineOpcode() const;
903 inline unsigned getMachineOpcode() const;
906 /// reachesChainWithoutSideEffects - Return true if this operand (which must
907 /// be a chain) reaches the specified operand without crossing any
908 /// side-effecting instructions. In practice, this looks through token
909 /// factors and non-volatile loads. In order to remain efficient, this only
910 /// looks a couple of nodes in, it does not do an exhaustive search.
911 bool reachesChainWithoutSideEffects(SDValue Dest,
912 unsigned Depth = 2) const;
914 /// use_empty - Return true if there are no nodes using value ResNo
917 inline bool use_empty() const;
919 /// hasOneUse - Return true if there is exactly one node using value
922 inline bool hasOneUse() const;
926 template<> struct DenseMapInfo<SDValue> {
927 static inline SDValue getEmptyKey() {
928 return SDValue((SDNode*)-1, -1U);
930 static inline SDValue getTombstoneKey() {
931 return SDValue((SDNode*)-1, 0);
933 static unsigned getHashValue(const SDValue &Val) {
934 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
935 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
937 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
940 static bool isPod() { return true; }
943 /// simplify_type specializations - Allow casting operators to work directly on
944 /// SDValues as if they were SDNode*'s.
945 template<> struct simplify_type<SDValue> {
946 typedef SDNode* SimpleType;
947 static SimpleType getSimplifiedValue(const SDValue &Val) {
948 return static_cast<SimpleType>(Val.getNode());
951 template<> struct simplify_type<const SDValue> {
952 typedef SDNode* SimpleType;
953 static SimpleType getSimplifiedValue(const SDValue &Val) {
954 return static_cast<SimpleType>(Val.getNode());
958 /// SDUse - Represents a use of the SDNode referred by
962 /// User - Parent node of this operand.
964 /// Prev, next - Pointers to the uses list of the SDNode referred by
969 SDUse(): Operand(), User(NULL), Prev(NULL), Next(NULL) {}
971 SDUse(SDNode *val, unsigned resno) :
972 Operand(val,resno), User(NULL), Prev(NULL), Next(NULL) {}
974 SDUse& operator= (const SDValue& Op) {
981 SDUse& operator= (const SDUse& Op) {
988 SDUse *getNext() { return Next; }
990 SDNode *getUser() { return User; }
992 void setUser(SDNode *p) { User = p; }
994 operator SDValue() const { return Operand; }
996 const SDValue& getSDValue() const { return Operand; }
998 SDValue &getSDValue() { return Operand; }
999 SDNode *getVal() { return Operand.getNode(); }
1000 SDNode *getVal() const { return Operand.getNode(); } // FIXME: const correct?
1002 bool operator==(const SDValue &O) const {
1003 return Operand == O;
1006 bool operator!=(const SDValue &O) const {
1007 return !(Operand == O);
1010 bool operator<(const SDValue &O) const {
1015 void addToList(SDUse **List) {
1017 if (Next) Next->Prev = &Next;
1022 void removeFromList() {
1024 if (Next) Next->Prev = Prev;
1029 /// simplify_type specializations - Allow casting operators to work directly on
1030 /// SDValues as if they were SDNode*'s.
1031 template<> struct simplify_type<SDUse> {
1032 typedef SDNode* SimpleType;
1033 static SimpleType getSimplifiedValue(const SDUse &Val) {
1034 return static_cast<SimpleType>(Val.getVal());
1037 template<> struct simplify_type<const SDUse> {
1038 typedef SDNode* SimpleType;
1039 static SimpleType getSimplifiedValue(const SDUse &Val) {
1040 return static_cast<SimpleType>(Val.getVal());
1045 /// SDOperandPtr - A helper SDValue pointer class, that can handle
1046 /// arrays of SDUse and arrays of SDValue objects. This is required
1047 /// in many places inside the SelectionDAG.
1049 class SDOperandPtr {
1050 const SDValue *ptr; // The pointer to the SDValue object
1051 int object_size; // The size of the object containg the SDValue
1053 SDOperandPtr() : ptr(0), object_size(0) {}
1055 SDOperandPtr(SDUse * use_ptr) {
1056 ptr = &use_ptr->getSDValue();
1057 object_size = (int)sizeof(SDUse);
1060 SDOperandPtr(const SDValue * op_ptr) {
1062 object_size = (int)sizeof(SDValue);
1065 const SDValue operator *() { return *ptr; }
1066 const SDValue *operator ->() { return ptr; }
1067 SDOperandPtr operator ++ () {
1068 ptr = (SDValue*)((char *)ptr + object_size);
1072 SDOperandPtr operator ++ (int) {
1073 SDOperandPtr tmp = *this;
1074 ptr = (SDValue*)((char *)ptr + object_size);
1078 SDValue operator[] (int idx) const {
1079 return *(SDValue*)((char*) ptr + object_size * idx);
1083 /// SDNode - Represents one node in the SelectionDAG.
1085 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
1087 /// NodeType - The operation that this node performs.
1091 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
1092 /// then they will be delete[]'d when the node is destroyed.
1093 unsigned short OperandsNeedDelete : 1;
1096 /// SubclassData - This member is defined by this class, but is not used for
1097 /// anything. Subclasses can use it to hold whatever state they find useful.
1098 /// This field is initialized to zero by the ctor.
1099 unsigned short SubclassData : 15;
1102 /// NodeId - Unique id per SDNode in the DAG.
1105 /// OperandList - The values that are used by this operation.
1109 /// ValueList - The types of the values this node defines. SDNode's may
1110 /// define multiple values simultaneously.
1111 const MVT *ValueList;
1113 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1114 unsigned short NumOperands, NumValues;
1116 /// Uses - List of uses for this SDNode.
1119 /// addUse - add SDUse to the list of uses.
1120 void addUse(SDUse &U) { U.addToList(&Uses); }
1122 // Out-of-line virtual method to give class a home.
1123 virtual void ANCHOR();
1126 assert(NumOperands == 0 && "Operand list not cleared before deletion");
1127 NodeType = ISD::DELETED_NODE;
1130 //===--------------------------------------------------------------------===//
1134 /// getOpcode - Return the SelectionDAG opcode value for this node. For
1135 /// pre-isel nodes (those for which isMachineOpcode returns false), these
1136 /// are the opcode values in the ISD and <target>ISD namespaces. For
1137 /// post-isel opcodes, see getMachineOpcode.
1138 unsigned getOpcode() const { return (unsigned short)NodeType; }
1140 /// isTargetOpcode - Test if this node has a target-specific opcode (in the
1141 /// <target>ISD namespace).
1142 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1144 /// isMachineOpcode - Test if this node has a post-isel opcode, directly
1145 /// corresponding to a MachineInstr opcode.
1146 bool isMachineOpcode() const { return NodeType < 0; }
1148 /// getMachineOpcode - This may only be called if isMachineOpcode returns
1149 /// true. It returns the MachineInstr opcode value that the node's opcode
1151 unsigned getMachineOpcode() const {
1152 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
1156 /// use_empty - Return true if there are no uses of this node.
1158 bool use_empty() const { return Uses == NULL; }
1160 /// hasOneUse - Return true if there is exactly one use of this node.
1162 bool hasOneUse() const {
1163 return !use_empty() && next(use_begin()) == use_end();
1166 /// use_size - Return the number of uses of this node. This method takes
1167 /// time proportional to the number of uses.
1169 size_t use_size() const { return std::distance(use_begin(), use_end()); }
1171 /// getNodeId - Return the unique node id.
1173 int getNodeId() const { return NodeId; }
1175 /// setNodeId - Set unique node id.
1176 void setNodeId(int Id) { NodeId = Id; }
1178 /// use_iterator - This class provides iterator support for SDUse
1179 /// operands that use a specific SDNode.
1181 : public forward_iterator<SDUse, ptrdiff_t> {
1183 explicit use_iterator(SDUse *op) : Op(op) {
1185 friend class SDNode;
1187 typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
1188 typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1190 use_iterator(const use_iterator &I) : Op(I.Op) {}
1191 use_iterator() : Op(0) {}
1193 bool operator==(const use_iterator &x) const {
1196 bool operator!=(const use_iterator &x) const {
1197 return !operator==(x);
1200 /// atEnd - return true if this iterator is at the end of uses list.
1201 bool atEnd() const { return Op == 0; }
1203 // Iterator traversal: forward iteration only.
1204 use_iterator &operator++() { // Preincrement
1205 assert(Op && "Cannot increment end iterator!");
1210 use_iterator operator++(int) { // Postincrement
1211 use_iterator tmp = *this; ++*this; return tmp;
1214 /// Retrieve a pointer to the current user node.
1215 SDNode *operator*() const {
1216 assert(Op && "Cannot dereference end iterator!");
1217 return Op->getUser();
1220 SDNode *operator->() const { return operator*(); }
1222 SDUse &getUse() const { return *Op; }
1224 /// getOperandNo - Retrieve the operand # of this use in its user.
1226 unsigned getOperandNo() const {
1227 assert(Op && "Cannot dereference end iterator!");
1228 return (unsigned)(Op - Op->getUser()->OperandList);
1232 /// use_begin/use_end - Provide iteration support to walk over all uses
1235 use_iterator use_begin() const {
1236 return use_iterator(Uses);
1239 static use_iterator use_end() { return use_iterator(0); }
1242 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1243 /// indicated value. This method ignores uses of other values defined by this
1245 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1247 /// hasAnyUseOfValue - Return true if there are any use of the indicated
1248 /// value. This method ignores uses of other values defined by this operation.
1249 bool hasAnyUseOfValue(unsigned Value) const;
1251 /// isOnlyUserOf - Return true if this node is the only use of N.
1253 bool isOnlyUserOf(SDNode *N) const;
1255 /// isOperandOf - Return true if this node is an operand of N.
1257 bool isOperandOf(SDNode *N) const;
1259 /// isPredecessorOf - Return true if this node is a predecessor of N. This
1260 /// node is either an operand of N or it can be reached by recursively
1261 /// traversing up the operands.
1262 /// NOTE: this is an expensive method. Use it carefully.
1263 bool isPredecessorOf(SDNode *N) const;
1265 /// getNumOperands - Return the number of values used by this operation.
1267 unsigned getNumOperands() const { return NumOperands; }
1269 /// getConstantOperandVal - Helper method returns the integer value of a
1270 /// ConstantSDNode operand.
1271 uint64_t getConstantOperandVal(unsigned Num) const;
1273 const SDValue &getOperand(unsigned Num) const {
1274 assert(Num < NumOperands && "Invalid child # of SDNode!");
1275 return OperandList[Num].getSDValue();
1278 typedef SDUse* op_iterator;
1279 op_iterator op_begin() const { return OperandList; }
1280 op_iterator op_end() const { return OperandList+NumOperands; }
1283 SDVTList getVTList() const {
1284 SDVTList X = { ValueList, NumValues };
1288 /// getFlaggedNode - If this node has a flag operand, return the node
1289 /// to which the flag operand points. Otherwise return NULL.
1290 SDNode *getFlaggedNode() const {
1291 if (getNumOperands() != 0 &&
1292 getOperand(getNumOperands()-1).getValueType() == MVT::Flag)
1293 return getOperand(getNumOperands()-1).getNode();
1297 /// getNumValues - Return the number of values defined/returned by this
1300 unsigned getNumValues() const { return NumValues; }
1302 /// getValueType - Return the type of a specified result.
1304 MVT getValueType(unsigned ResNo) const {
1305 assert(ResNo < NumValues && "Illegal result number!");
1306 return ValueList[ResNo];
1309 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1311 unsigned getValueSizeInBits(unsigned ResNo) const {
1312 return getValueType(ResNo).getSizeInBits();
1315 typedef const MVT* value_iterator;
1316 value_iterator value_begin() const { return ValueList; }
1317 value_iterator value_end() const { return ValueList+NumValues; }
1319 /// getOperationName - Return the opcode of this operation for printing.
1321 std::string getOperationName(const SelectionDAG *G = 0) const;
1322 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1323 void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
1325 void dump(const SelectionDAG *G) const;
1327 static bool classof(const SDNode *) { return true; }
1329 /// Profile - Gather unique data for the node.
1331 void Profile(FoldingSetNodeID &ID) const;
1334 friend class SelectionDAG;
1335 friend struct ilist_traits<SDNode>;
1337 /// getValueTypeList - Return a pointer to the specified value type.
1339 static const MVT *getValueTypeList(MVT VT);
1340 static SDVTList getSDVTList(MVT VT) {
1341 SDVTList Ret = { getValueTypeList(VT), 1 };
1345 SDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps)
1346 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1347 NodeId(-1), Uses(NULL) {
1348 NumOperands = NumOps;
1349 OperandList = NumOps ? new SDUse[NumOperands] : 0;
1351 for (unsigned i = 0; i != NumOps; ++i) {
1352 OperandList[i] = Ops[i];
1353 OperandList[i].setUser(this);
1354 Ops[i].getNode()->addUse(OperandList[i]);
1357 ValueList = VTs.VTs;
1358 NumValues = VTs.NumVTs;
1361 SDNode(unsigned Opc, SDVTList VTs, const SDUse *Ops, unsigned NumOps)
1362 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1363 NodeId(-1), Uses(NULL) {
1364 OperandsNeedDelete = true;
1365 NumOperands = NumOps;
1366 OperandList = NumOps ? new SDUse[NumOperands] : 0;
1368 for (unsigned i = 0; i != NumOps; ++i) {
1369 OperandList[i] = Ops[i];
1370 OperandList[i].setUser(this);
1371 Ops[i].getVal()->addUse(OperandList[i]);
1374 ValueList = VTs.VTs;
1375 NumValues = VTs.NumVTs;
1378 /// This constructor adds no operands itself; operands can be
1379 /// set later with InitOperands.
1380 SDNode(unsigned Opc, SDVTList VTs)
1381 : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1382 NodeId(-1), Uses(NULL) {
1385 ValueList = VTs.VTs;
1386 NumValues = VTs.NumVTs;
1389 /// InitOperands - Initialize the operands list of this node with the
1390 /// specified values, which are part of the node (thus they don't need to be
1391 /// copied in or allocated).
1392 void InitOperands(SDUse *Ops, unsigned NumOps) {
1393 assert(OperandList == 0 && "Operands already set!");
1394 NumOperands = NumOps;
1398 for (unsigned i = 0; i != NumOps; ++i) {
1399 OperandList[i].setUser(this);
1400 Ops[i].getVal()->addUse(OperandList[i]);
1404 /// DropOperands - Release the operands and set this node to have
1406 void DropOperands();
1408 void addUser(unsigned i, SDNode *User) {
1409 assert(User->OperandList[i].getUser() && "Node without parent");
1410 addUse(User->OperandList[i]);
1413 void removeUser(unsigned i, SDNode *User) {
1414 assert(User->OperandList[i].getUser() && "Node without parent");
1415 SDUse &Op = User->OperandList[i];
1416 Op.removeFromList();
1421 // Define inline functions from the SDValue class.
1423 inline unsigned SDValue::getOpcode() const {
1424 return Node->getOpcode();
1426 inline MVT SDValue::getValueType() const {
1427 return Node->getValueType(ResNo);
1429 inline unsigned SDValue::getNumOperands() const {
1430 return Node->getNumOperands();
1432 inline const SDValue &SDValue::getOperand(unsigned i) const {
1433 return Node->getOperand(i);
1435 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1436 return Node->getConstantOperandVal(i);
1438 inline bool SDValue::isTargetOpcode() const {
1439 return Node->isTargetOpcode();
1441 inline bool SDValue::isMachineOpcode() const {
1442 return Node->isMachineOpcode();
1444 inline unsigned SDValue::getMachineOpcode() const {
1445 return Node->getMachineOpcode();
1447 inline bool SDValue::use_empty() const {
1448 return !Node->hasAnyUseOfValue(ResNo);
1450 inline bool SDValue::hasOneUse() const {
1451 return Node->hasNUsesOfValue(1, ResNo);
1454 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1455 /// to allow co-allocation of node operands with the node itself.
1456 class UnarySDNode : public SDNode {
1457 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1460 UnarySDNode(unsigned Opc, SDVTList VTs, SDValue X)
1461 : SDNode(Opc, VTs) {
1463 InitOperands(&Op, 1);
1467 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1468 /// to allow co-allocation of node operands with the node itself.
1469 class BinarySDNode : public SDNode {
1470 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1473 BinarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y)
1474 : SDNode(Opc, VTs) {
1477 InitOperands(Ops, 2);
1481 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1482 /// to allow co-allocation of node operands with the node itself.
1483 class TernarySDNode : public SDNode {
1484 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1487 TernarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y,
1489 : SDNode(Opc, VTs) {
1493 InitOperands(Ops, 3);
1498 /// HandleSDNode - This class is used to form a handle around another node that
1499 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1500 /// operand. This node should be directly created by end-users and not added to
1501 /// the AllNodes list.
1502 class HandleSDNode : public SDNode {
1503 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1506 // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1509 explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
1511 explicit HandleSDNode(SDValue X)
1513 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
1515 InitOperands(&Op, 1);
1518 const SDValue &getValue() const { return Op.getSDValue(); }
1521 /// Abstact virtual class for operations for memory operations
1522 class MemSDNode : public SDNode {
1523 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1526 // MemoryVT - VT of in-memory value.
1529 //! SrcValue - Memory location for alias analysis.
1530 const Value *SrcValue;
1532 //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
1535 /// Flags - the low bit indicates whether this is a volatile reference;
1536 /// the remainder is a log2 encoding of the alignment in bytes.
1540 MemSDNode(unsigned Opc, SDVTList VTs, MVT MemoryVT,
1541 const Value *srcValue, int SVOff,
1542 unsigned alignment, bool isvolatile);
1544 MemSDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps,
1545 MVT MemoryVT, const Value *srcValue, int SVOff,
1546 unsigned alignment, bool isvolatile);
1548 /// Returns alignment and volatility of the memory access
1549 unsigned getAlignment() const { return (1u << (Flags >> 1)) >> 1; }
1550 bool isVolatile() const { return Flags & 1; }
1552 /// Returns the SrcValue and offset that describes the location of the access
1553 const Value *getSrcValue() const { return SrcValue; }
1554 int getSrcValueOffset() const { return SVOffset; }
1556 /// getMemoryVT - Return the type of the in-memory value.
1557 MVT getMemoryVT() const { return MemoryVT; }
1559 /// getMemOperand - Return a MachineMemOperand object describing the memory
1560 /// reference performed by operation.
1561 MachineMemOperand getMemOperand() const;
1563 const SDValue &getChain() const { return getOperand(0); }
1564 const SDValue &getBasePtr() const {
1565 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1568 /// getRawFlags - Represent the flags as a bunch of bits.
1570 unsigned getRawFlags() const { return Flags; }
1572 // Methods to support isa and dyn_cast
1573 static bool classof(const MemSDNode *) { return true; }
1574 static bool classof(const SDNode *N) {
1575 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1576 // with either an intrinsic or a target opcode.
1577 return N->getOpcode() == ISD::LOAD ||
1578 N->getOpcode() == ISD::STORE ||
1579 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1580 N->getOpcode() == ISD::ATOMIC_SWAP ||
1581 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1582 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1583 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1584 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1585 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1586 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1587 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1588 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1589 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1590 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1591 N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1592 N->getOpcode() == ISD::INTRINSIC_VOID ||
1593 N->isTargetOpcode();
1597 /// AtomicSDNode - A SDNode reprenting atomic operations.
1599 class AtomicSDNode : public MemSDNode {
1600 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1604 // Opc: opcode for atomic
1605 // VTL: value type list
1606 // Chain: memory chain for operaand
1607 // Ptr: address to update as a SDValue
1608 // Cmp: compare value
1610 // SrcVal: address to update as a Value (used for MemOperand)
1611 // Align: alignment of memory
1612 AtomicSDNode(unsigned Opc, SDVTList VTL, MVT MemVT,
1613 SDValue Chain, SDValue Ptr,
1614 SDValue Cmp, SDValue Swp, const Value* SrcVal,
1616 : MemSDNode(Opc, VTL, MemVT, SrcVal, /*SVOffset=*/0,
1617 Align, /*isVolatile=*/true) {
1622 InitOperands(Ops, 4);
1624 AtomicSDNode(unsigned Opc, SDVTList VTL, MVT MemVT,
1625 SDValue Chain, SDValue Ptr,
1626 SDValue Val, const Value* SrcVal, unsigned Align=0)
1627 : MemSDNode(Opc, VTL, MemVT, SrcVal, /*SVOffset=*/0,
1628 Align, /*isVolatile=*/true) {
1632 InitOperands(Ops, 3);
1635 const SDValue &getBasePtr() const { return getOperand(1); }
1636 const SDValue &getVal() const { return getOperand(2); }
1638 bool isCompareAndSwap() const {
1639 unsigned Op = getOpcode();
1640 return Op == ISD::ATOMIC_CMP_SWAP;
1643 // Methods to support isa and dyn_cast
1644 static bool classof(const AtomicSDNode *) { return true; }
1645 static bool classof(const SDNode *N) {
1646 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1647 N->getOpcode() == ISD::ATOMIC_SWAP ||
1648 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1649 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1650 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1651 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1652 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1653 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1654 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1655 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1656 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1657 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1661 /// MemIntrinsicSDNode - This SDNode is used for target intrinsic that touches
1662 /// memory and need an associated memory operand.
1664 class MemIntrinsicSDNode : public MemSDNode {
1665 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1666 bool ReadMem; // Intrinsic reads memory
1667 bool WriteMem; // Intrinsic writes memory
1669 MemIntrinsicSDNode(unsigned Opc, SDVTList VTs,
1670 const SDValue *Ops, unsigned NumOps,
1671 MVT MemoryVT, const Value *srcValue, int SVO,
1672 unsigned Align, bool Vol, bool ReadMem, bool WriteMem)
1673 : MemSDNode(Opc, VTs, Ops, NumOps, MemoryVT, srcValue, SVO, Align, Vol),
1674 ReadMem(ReadMem), WriteMem(WriteMem) {
1677 bool readMem() const { return ReadMem; }
1678 bool writeMem() const { return WriteMem; }
1680 // Methods to support isa and dyn_cast
1681 static bool classof(const MemIntrinsicSDNode *) { return true; }
1682 static bool classof(const SDNode *N) {
1683 // We lower some target intrinsics to their target opcode
1684 // early a node with a target opcode can be of this class
1685 return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1686 N->getOpcode() == ISD::INTRINSIC_VOID ||
1687 N->isTargetOpcode();
1691 class ConstantSDNode : public SDNode {
1692 const ConstantInt *Value;
1693 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1695 friend class SelectionDAG;
1696 ConstantSDNode(bool isTarget, const ConstantInt *val, MVT VT)
1697 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1702 const ConstantInt *getConstantIntValue() const { return Value; }
1703 const APInt &getAPIntValue() const { return Value->getValue(); }
1704 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1705 int64_t getSExtValue() const { return Value->getSExtValue(); }
1707 bool isNullValue() const { return Value->isNullValue(); }
1708 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1710 static bool classof(const ConstantSDNode *) { return true; }
1711 static bool classof(const SDNode *N) {
1712 return N->getOpcode() == ISD::Constant ||
1713 N->getOpcode() == ISD::TargetConstant;
1717 class ConstantFPSDNode : public SDNode {
1718 const ConstantFP *Value;
1719 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1721 friend class SelectionDAG;
1722 ConstantFPSDNode(bool isTarget, const ConstantFP *val, MVT VT)
1723 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1724 getSDVTList(VT)), Value(val) {
1728 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1729 const ConstantFP *getConstantFPValue() const { return Value; }
1731 /// isExactlyValue - We don't rely on operator== working on double values, as
1732 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1733 /// As such, this method can be used to do an exact bit-for-bit comparison of
1734 /// two floating point values.
1736 /// We leave the version with the double argument here because it's just so
1737 /// convenient to write "2.0" and the like. Without this function we'd
1738 /// have to duplicate its logic everywhere it's called.
1739 bool isExactlyValue(double V) const {
1741 // convert is not supported on this type
1742 if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
1745 Tmp.convert(Value->getValueAPF().getSemantics(),
1746 APFloat::rmNearestTiesToEven, &ignored);
1747 return isExactlyValue(Tmp);
1749 bool isExactlyValue(const APFloat& V) const;
1751 bool isValueValidForType(MVT VT, const APFloat& Val);
1753 static bool classof(const ConstantFPSDNode *) { return true; }
1754 static bool classof(const SDNode *N) {
1755 return N->getOpcode() == ISD::ConstantFP ||
1756 N->getOpcode() == ISD::TargetConstantFP;
1760 class GlobalAddressSDNode : public SDNode {
1761 GlobalValue *TheGlobal;
1763 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1765 friend class SelectionDAG;
1766 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT,
1770 GlobalValue *getGlobal() const { return TheGlobal; }
1771 int64_t getOffset() const { return Offset; }
1773 static bool classof(const GlobalAddressSDNode *) { return true; }
1774 static bool classof(const SDNode *N) {
1775 return N->getOpcode() == ISD::GlobalAddress ||
1776 N->getOpcode() == ISD::TargetGlobalAddress ||
1777 N->getOpcode() == ISD::GlobalTLSAddress ||
1778 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1782 class FrameIndexSDNode : public SDNode {
1784 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1786 friend class SelectionDAG;
1787 FrameIndexSDNode(int fi, MVT VT, bool isTarg)
1788 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1793 int getIndex() const { return FI; }
1795 static bool classof(const FrameIndexSDNode *) { return true; }
1796 static bool classof(const SDNode *N) {
1797 return N->getOpcode() == ISD::FrameIndex ||
1798 N->getOpcode() == ISD::TargetFrameIndex;
1802 class JumpTableSDNode : public SDNode {
1804 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1806 friend class SelectionDAG;
1807 JumpTableSDNode(int jti, MVT VT, bool isTarg)
1808 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1813 int getIndex() const { return JTI; }
1815 static bool classof(const JumpTableSDNode *) { return true; }
1816 static bool classof(const SDNode *N) {
1817 return N->getOpcode() == ISD::JumpTable ||
1818 N->getOpcode() == ISD::TargetJumpTable;
1822 class ConstantPoolSDNode : public SDNode {
1825 MachineConstantPoolValue *MachineCPVal;
1827 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1829 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1831 friend class SelectionDAG;
1832 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0)
1833 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1834 getSDVTList(VT)), Offset(o), Alignment(0) {
1835 assert((int)Offset >= 0 && "Offset is too large");
1838 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o, unsigned Align)
1839 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1840 getSDVTList(VT)), Offset(o), Alignment(Align) {
1841 assert((int)Offset >= 0 && "Offset is too large");
1844 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1846 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1847 getSDVTList(VT)), Offset(o), Alignment(0) {
1848 assert((int)Offset >= 0 && "Offset is too large");
1849 Val.MachineCPVal = v;
1850 Offset |= 1 << (sizeof(unsigned)*8-1);
1852 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1853 MVT VT, int o, unsigned Align)
1854 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1855 getSDVTList(VT)), Offset(o), Alignment(Align) {
1856 assert((int)Offset >= 0 && "Offset is too large");
1857 Val.MachineCPVal = v;
1858 Offset |= 1 << (sizeof(unsigned)*8-1);
1862 bool isMachineConstantPoolEntry() const {
1863 return (int)Offset < 0;
1866 Constant *getConstVal() const {
1867 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1868 return Val.ConstVal;
1871 MachineConstantPoolValue *getMachineCPVal() const {
1872 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1873 return Val.MachineCPVal;
1876 int getOffset() const {
1877 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1880 // Return the alignment of this constant pool object, which is either 0 (for
1881 // default alignment) or log2 of the desired value.
1882 unsigned getAlignment() const { return Alignment; }
1884 const Type *getType() const;
1886 static bool classof(const ConstantPoolSDNode *) { return true; }
1887 static bool classof(const SDNode *N) {
1888 return N->getOpcode() == ISD::ConstantPool ||
1889 N->getOpcode() == ISD::TargetConstantPool;
1893 class BasicBlockSDNode : public SDNode {
1894 MachineBasicBlock *MBB;
1895 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1897 friend class SelectionDAG;
1898 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1899 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1903 MachineBasicBlock *getBasicBlock() const { return MBB; }
1905 static bool classof(const BasicBlockSDNode *) { return true; }
1906 static bool classof(const SDNode *N) {
1907 return N->getOpcode() == ISD::BasicBlock;
1911 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1912 /// used when the SelectionDAG needs to make a simple reference to something
1913 /// in the LLVM IR representation.
1915 /// Note that this is not used for carrying alias information; that is done
1916 /// with MemOperandSDNode, which includes a Value which is required to be a
1917 /// pointer, and several other fields specific to memory references.
1919 class SrcValueSDNode : public SDNode {
1921 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1923 friend class SelectionDAG;
1924 /// Create a SrcValue for a general value.
1925 explicit SrcValueSDNode(const Value *v)
1926 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1929 /// getValue - return the contained Value.
1930 const Value *getValue() const { return V; }
1932 static bool classof(const SrcValueSDNode *) { return true; }
1933 static bool classof(const SDNode *N) {
1934 return N->getOpcode() == ISD::SRCVALUE;
1939 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
1940 /// used to represent a reference to memory after ISD::LOAD
1941 /// and ISD::STORE have been lowered.
1943 class MemOperandSDNode : public SDNode {
1944 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1946 friend class SelectionDAG;
1947 /// Create a MachineMemOperand node
1948 explicit MemOperandSDNode(const MachineMemOperand &mo)
1949 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1952 /// MO - The contained MachineMemOperand.
1953 const MachineMemOperand MO;
1955 static bool classof(const MemOperandSDNode *) { return true; }
1956 static bool classof(const SDNode *N) {
1957 return N->getOpcode() == ISD::MEMOPERAND;
1962 class RegisterSDNode : public SDNode {
1964 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1966 friend class SelectionDAG;
1967 RegisterSDNode(unsigned reg, MVT VT)
1968 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1972 unsigned getReg() const { return Reg; }
1974 static bool classof(const RegisterSDNode *) { return true; }
1975 static bool classof(const SDNode *N) {
1976 return N->getOpcode() == ISD::Register;
1980 class DbgStopPointSDNode : public SDNode {
1984 const CompileUnitDesc *CU;
1985 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1987 friend class SelectionDAG;
1988 DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
1989 const CompileUnitDesc *cu)
1990 : SDNode(ISD::DBG_STOPPOINT, getSDVTList(MVT::Other)),
1991 Line(l), Column(c), CU(cu) {
1993 InitOperands(&Chain, 1);
1996 unsigned getLine() const { return Line; }
1997 unsigned getColumn() const { return Column; }
1998 const CompileUnitDesc *getCompileUnit() const { return CU; }
2000 static bool classof(const DbgStopPointSDNode *) { return true; }
2001 static bool classof(const SDNode *N) {
2002 return N->getOpcode() == ISD::DBG_STOPPOINT;
2006 class LabelSDNode : public SDNode {
2009 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2011 friend class SelectionDAG;
2012 LabelSDNode(unsigned NodeTy, SDValue ch, unsigned id)
2013 : SDNode(NodeTy, getSDVTList(MVT::Other)), LabelID(id) {
2015 InitOperands(&Chain, 1);
2018 unsigned getLabelID() const { return LabelID; }
2020 static bool classof(const LabelSDNode *) { return true; }
2021 static bool classof(const SDNode *N) {
2022 return N->getOpcode() == ISD::DBG_LABEL ||
2023 N->getOpcode() == ISD::EH_LABEL;
2027 class ExternalSymbolSDNode : public SDNode {
2029 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2031 friend class SelectionDAG;
2032 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT VT)
2033 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
2034 getSDVTList(VT)), Symbol(Sym) {
2038 const char *getSymbol() const { return Symbol; }
2040 static bool classof(const ExternalSymbolSDNode *) { return true; }
2041 static bool classof(const SDNode *N) {
2042 return N->getOpcode() == ISD::ExternalSymbol ||
2043 N->getOpcode() == ISD::TargetExternalSymbol;
2047 class CondCodeSDNode : public SDNode {
2048 ISD::CondCode Condition;
2049 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2051 friend class SelectionDAG;
2052 explicit CondCodeSDNode(ISD::CondCode Cond)
2053 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
2057 ISD::CondCode get() const { return Condition; }
2059 static bool classof(const CondCodeSDNode *) { return true; }
2060 static bool classof(const SDNode *N) {
2061 return N->getOpcode() == ISD::CONDCODE;
2065 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
2066 /// future and most targets don't support it.
2067 class CvtRndSatSDNode : public SDNode {
2068 ISD::CvtCode CvtCode;
2069 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2071 friend class SelectionDAG;
2072 explicit CvtRndSatSDNode(MVT VT, const SDValue *Ops, unsigned NumOps,
2074 : SDNode(ISD::CONVERT_RNDSAT, getSDVTList(VT), Ops, NumOps), CvtCode(Code) {
2075 assert(NumOps == 5 && "wrong number of operations");
2078 ISD::CvtCode getCvtCode() const { return CvtCode; }
2080 static bool classof(const CvtRndSatSDNode *) { return true; }
2081 static bool classof(const SDNode *N) {
2082 return N->getOpcode() == ISD::CONVERT_RNDSAT;
2089 static const uint64_t NoFlagSet = 0ULL;
2090 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
2091 static const uint64_t ZExtOffs = 0;
2092 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
2093 static const uint64_t SExtOffs = 1;
2094 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
2095 static const uint64_t InRegOffs = 2;
2096 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
2097 static const uint64_t SRetOffs = 3;
2098 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
2099 static const uint64_t ByValOffs = 4;
2100 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
2101 static const uint64_t NestOffs = 5;
2102 static const uint64_t ByValAlign = 0xFULL << 6; //< Struct alignment
2103 static const uint64_t ByValAlignOffs = 6;
2104 static const uint64_t Split = 1ULL << 10;
2105 static const uint64_t SplitOffs = 10;
2106 static const uint64_t OrigAlign = 0x1FULL<<27;
2107 static const uint64_t OrigAlignOffs = 27;
2108 static const uint64_t ByValSize = 0xffffffffULL << 32; //< Struct size
2109 static const uint64_t ByValSizeOffs = 32;
2111 static const uint64_t One = 1ULL; //< 1 of this type, for shifts
2115 ArgFlagsTy() : Flags(0) { }
2117 bool isZExt() const { return Flags & ZExt; }
2118 void setZExt() { Flags |= One << ZExtOffs; }
2120 bool isSExt() const { return Flags & SExt; }
2121 void setSExt() { Flags |= One << SExtOffs; }
2123 bool isInReg() const { return Flags & InReg; }
2124 void setInReg() { Flags |= One << InRegOffs; }
2126 bool isSRet() const { return Flags & SRet; }
2127 void setSRet() { Flags |= One << SRetOffs; }
2129 bool isByVal() const { return Flags & ByVal; }
2130 void setByVal() { Flags |= One << ByValOffs; }
2132 bool isNest() const { return Flags & Nest; }
2133 void setNest() { Flags |= One << NestOffs; }
2135 unsigned getByValAlign() const {
2137 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
2139 void setByValAlign(unsigned A) {
2140 Flags = (Flags & ~ByValAlign) |
2141 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
2144 bool isSplit() const { return Flags & Split; }
2145 void setSplit() { Flags |= One << SplitOffs; }
2147 unsigned getOrigAlign() const {
2149 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
2151 void setOrigAlign(unsigned A) {
2152 Flags = (Flags & ~OrigAlign) |
2153 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
2156 unsigned getByValSize() const {
2157 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
2159 void setByValSize(unsigned S) {
2160 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
2163 /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
2164 std::string getArgFlagsString();
2166 /// getRawBits - Represent the flags as a bunch of bits.
2167 uint64_t getRawBits() const { return Flags; }
2171 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
2172 class ARG_FLAGSSDNode : public SDNode {
2173 ISD::ArgFlagsTy TheFlags;
2174 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2176 friend class SelectionDAG;
2177 explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
2178 : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
2181 ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
2183 static bool classof(const ARG_FLAGSSDNode *) { return true; }
2184 static bool classof(const SDNode *N) {
2185 return N->getOpcode() == ISD::ARG_FLAGS;
2189 /// CallSDNode - Node for calls -- ISD::CALL.
2190 class CallSDNode : public SDNode {
2191 unsigned CallingConv;
2194 // We might eventually want a full-blown Attributes for the result; that
2195 // will expand the size of the representation. At the moment we only
2198 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2200 friend class SelectionDAG;
2201 CallSDNode(unsigned cc, bool isvararg, bool istailcall, bool isinreg,
2202 SDVTList VTs, const SDValue *Operands, unsigned numOperands)
2203 : SDNode(ISD::CALL, VTs, Operands, numOperands),
2204 CallingConv(cc), IsVarArg(isvararg), IsTailCall(istailcall),
2207 unsigned getCallingConv() const { return CallingConv; }
2208 unsigned isVarArg() const { return IsVarArg; }
2209 unsigned isTailCall() const { return IsTailCall; }
2210 unsigned isInreg() const { return Inreg; }
2212 /// Set this call to not be marked as a tail call. Normally setter
2213 /// methods in SDNodes are unsafe because it breaks the CSE map,
2214 /// but we don't include the tail call flag for calls so it's ok
2216 void setNotTailCall() { IsTailCall = false; }
2218 SDValue getChain() const { return getOperand(0); }
2219 SDValue getCallee() const { return getOperand(1); }
2221 unsigned getNumArgs() const { return (getNumOperands() - 2) / 2; }
2222 SDValue getArg(unsigned i) const { return getOperand(2+2*i); }
2223 SDValue getArgFlagsVal(unsigned i) const {
2224 return getOperand(3+2*i);
2226 ISD::ArgFlagsTy getArgFlags(unsigned i) const {
2227 return cast<ARG_FLAGSSDNode>(getArgFlagsVal(i).getNode())->getArgFlags();
2230 unsigned getNumRetVals() const { return getNumValues() - 1; }
2231 MVT getRetValType(unsigned i) const { return getValueType(i); }
2233 static bool classof(const CallSDNode *) { return true; }
2234 static bool classof(const SDNode *N) {
2235 return N->getOpcode() == ISD::CALL;
2239 /// VTSDNode - This class is used to represent MVT's, which are used
2240 /// to parameterize some operations.
2241 class VTSDNode : public SDNode {
2243 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2245 friend class SelectionDAG;
2246 explicit VTSDNode(MVT VT)
2247 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
2251 MVT getVT() const { return ValueType; }
2253 static bool classof(const VTSDNode *) { return true; }
2254 static bool classof(const SDNode *N) {
2255 return N->getOpcode() == ISD::VALUETYPE;
2259 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
2261 class LSBaseSDNode : public MemSDNode {
2263 //! Operand array for load and store
2265 \note Moving this array to the base class captures more
2266 common functionality shared between LoadSDNode and
2271 LSBaseSDNode(ISD::NodeType NodeTy, SDValue *Operands, unsigned numOperands,
2272 SDVTList VTs, ISD::MemIndexedMode AM, MVT VT,
2273 const Value *SV, int SVO, unsigned Align, bool Vol)
2274 : MemSDNode(NodeTy, VTs, VT, SV, SVO, Align, Vol) {
2276 for (unsigned i = 0; i != numOperands; ++i)
2277 Ops[i] = Operands[i];
2278 InitOperands(Ops, numOperands);
2279 assert(Align != 0 && "Loads and stores should have non-zero aligment");
2280 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
2281 "Only indexed loads and stores have a non-undef offset operand");
2284 const SDValue &getOffset() const {
2285 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2288 /// getAddressingMode - Return the addressing mode for this load or store:
2289 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2290 ISD::MemIndexedMode getAddressingMode() const {
2291 return ISD::MemIndexedMode(SubclassData & 7);
2294 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
2295 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2297 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
2298 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2300 static bool classof(const LSBaseSDNode *) { return true; }
2301 static bool classof(const SDNode *N) {
2302 return N->getOpcode() == ISD::LOAD ||
2303 N->getOpcode() == ISD::STORE;
2307 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2309 class LoadSDNode : public LSBaseSDNode {
2310 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2312 friend class SelectionDAG;
2313 LoadSDNode(SDValue *ChainPtrOff, SDVTList VTs,
2314 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT,
2315 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2316 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
2317 VTs, AM, LVT, SV, O, Align, Vol) {
2318 SubclassData |= (unsigned short)ETy << 3;
2322 /// getExtensionType - Return whether this is a plain node,
2323 /// or one of the varieties of value-extending loads.
2324 ISD::LoadExtType getExtensionType() const {
2325 return ISD::LoadExtType((SubclassData >> 3) & 3);
2328 const SDValue &getBasePtr() const { return getOperand(1); }
2329 const SDValue &getOffset() const { return getOperand(2); }
2331 static bool classof(const LoadSDNode *) { return true; }
2332 static bool classof(const SDNode *N) {
2333 return N->getOpcode() == ISD::LOAD;
2337 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2339 class StoreSDNode : public LSBaseSDNode {
2340 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2342 friend class SelectionDAG;
2343 StoreSDNode(SDValue *ChainValuePtrOff, SDVTList VTs,
2344 ISD::MemIndexedMode AM, bool isTrunc, MVT SVT,
2345 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2346 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
2347 VTs, AM, SVT, SV, O, Align, Vol) {
2348 SubclassData |= (unsigned short)isTrunc << 3;
2352 /// isTruncatingStore - Return true if the op does a truncation before store.
2353 /// For integers this is the same as doing a TRUNCATE and storing the result.
2354 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2355 bool isTruncatingStore() const { return (SubclassData >> 3) & 1; }
2357 const SDValue &getValue() const { return getOperand(1); }
2358 const SDValue &getBasePtr() const { return getOperand(2); }
2359 const SDValue &getOffset() const { return getOperand(3); }
2361 static bool classof(const StoreSDNode *) { return true; }
2362 static bool classof(const SDNode *N) {
2363 return N->getOpcode() == ISD::STORE;
2368 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
2372 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2374 bool operator==(const SDNodeIterator& x) const {
2375 return Operand == x.Operand;
2377 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2379 const SDNodeIterator &operator=(const SDNodeIterator &I) {
2380 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2381 Operand = I.Operand;
2385 pointer operator*() const {
2386 return Node->getOperand(Operand).getNode();
2388 pointer operator->() const { return operator*(); }
2390 SDNodeIterator& operator++() { // Preincrement
2394 SDNodeIterator operator++(int) { // Postincrement
2395 SDNodeIterator tmp = *this; ++*this; return tmp;
2398 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2399 static SDNodeIterator end (SDNode *N) {
2400 return SDNodeIterator(N, N->getNumOperands());
2403 unsigned getOperand() const { return Operand; }
2404 const SDNode *getNode() const { return Node; }
2407 template <> struct GraphTraits<SDNode*> {
2408 typedef SDNode NodeType;
2409 typedef SDNodeIterator ChildIteratorType;
2410 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2411 static inline ChildIteratorType child_begin(NodeType *N) {
2412 return SDNodeIterator::begin(N);
2414 static inline ChildIteratorType child_end(NodeType *N) {
2415 return SDNodeIterator::end(N);
2419 /// LargestSDNode - The largest SDNode class.
2421 typedef LoadSDNode LargestSDNode;
2423 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2426 typedef ARG_FLAGSSDNode MostAlignedSDNode;
2429 /// isNormalLoad - Returns true if the specified node is a non-extending
2430 /// and unindexed load.
2431 inline bool isNormalLoad(const SDNode *N) {
2432 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2433 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2434 Ld->getAddressingMode() == ISD::UNINDEXED;
2437 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2439 inline bool isNON_EXTLoad(const SDNode *N) {
2440 return isa<LoadSDNode>(N) &&
2441 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2444 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2446 inline bool isEXTLoad(const SDNode *N) {
2447 return isa<LoadSDNode>(N) &&
2448 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2451 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2453 inline bool isSEXTLoad(const SDNode *N) {
2454 return isa<LoadSDNode>(N) &&
2455 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2458 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2460 inline bool isZEXTLoad(const SDNode *N) {
2461 return isa<LoadSDNode>(N) &&
2462 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2465 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2467 inline bool isUNINDEXEDLoad(const SDNode *N) {
2468 return isa<LoadSDNode>(N) &&
2469 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2472 /// isNormalStore - Returns true if the specified node is a non-truncating
2473 /// and unindexed store.
2474 inline bool isNormalStore(const SDNode *N) {
2475 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2476 return St && !St->isTruncatingStore() &&
2477 St->getAddressingMode() == ISD::UNINDEXED;
2480 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2482 inline bool isNON_TRUNCStore(const SDNode *N) {
2483 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2486 /// isTRUNCStore - Returns true if the specified node is a truncating
2488 inline bool isTRUNCStore(const SDNode *N) {
2489 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2492 /// isUNINDEXEDStore - Returns true if the specified node is an
2493 /// unindexed store.
2494 inline bool isUNINDEXEDStore(const SDNode *N) {
2495 return isa<StoreSDNode>(N) &&
2496 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2501 } // end llvm namespace