1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG. These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
22 #include "llvm/Value.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator.h"
26 #include "llvm/ADT/APFloat.h"
27 #include "llvm/ADT/APInt.h"
28 #include "llvm/ADT/ilist_node.h"
29 #include "llvm/ADT/STLExtras.h"
30 #include "llvm/CodeGen/ValueTypes.h"
31 #include "llvm/CodeGen/MachineMemOperand.h"
32 #include "llvm/Support/Allocator.h"
33 #include "llvm/Support/RecyclingAllocator.h"
34 #include "llvm/Support/DataTypes.h"
41 class MachineBasicBlock;
42 class MachineConstantPoolValue;
44 class CompileUnitDesc;
45 template <typename T> struct DenseMapInfo;
46 template <typename T> struct simplify_type;
47 template <typename T> class ilist_traits;
49 /// SDVTList - This represents a list of ValueType's that has been intern'd by
50 /// a SelectionDAG. Instances of this simple value class are returned by
51 /// SelectionDAG::getVTList(...).
55 unsigned short NumVTs;
58 /// ISD namespace - This namespace contains an enum which represents all of the
59 /// SelectionDAG node types and value types.
63 //===--------------------------------------------------------------------===//
64 /// ISD::NodeType enum - This enum defines all of the operators valid in a
68 // DELETED_NODE - This is an illegal flag value that is used to catch
69 // errors. This opcode is not a legal opcode for any node.
72 // EntryToken - This is the marker used to indicate the start of the region.
75 // Token factor - This node takes multiple tokens as input and produces a
76 // single token result. This is used to represent the fact that the operand
77 // operators are independent of each other.
80 // AssertSext, AssertZext - These nodes record if a register contains a
81 // value that has already been zero or sign extended from a narrower type.
82 // These nodes take two operands. The first is the node that has already
83 // been extended, and the second is a value type node indicating the width
85 AssertSext, AssertZext,
87 // Various leaf nodes.
88 BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
90 GlobalAddress, GlobalTLSAddress, FrameIndex,
91 JumpTable, ConstantPool, ExternalSymbol,
93 // The address of the GOT
96 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
97 // llvm.returnaddress on the DAG. These nodes take one operand, the index
98 // of the frame or return address to return. An index of zero corresponds
99 // to the current function's frame or return address, an index of one to the
100 // parent's frame or return address, and so on.
101 FRAMEADDR, RETURNADDR,
103 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
104 // first (possible) on-stack argument. This is needed for correct stack
105 // adjustment during unwind.
106 FRAME_TO_ARGS_OFFSET,
108 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
109 // address of the exception block on entry to an landing pad block.
112 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
113 // the selection index of the exception thrown.
116 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
117 // 'eh_return' gcc dwarf builtin, which is used to return from
118 // exception. The general meaning is: adjust stack by OFFSET and pass
119 // execution to HANDLER. Many platform-related details also :)
122 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
123 // simplification of the constant.
127 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
128 // anything else with this node, and this is valid in the target-specific
129 // dag, turning into a GlobalAddress operand.
131 TargetGlobalTLSAddress,
135 TargetExternalSymbol,
137 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
138 /// This node represents a target intrinsic function with no side effects.
139 /// The first operand is the ID number of the intrinsic from the
140 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
141 /// node has returns the result of the intrinsic.
144 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
145 /// This node represents a target intrinsic function with side effects that
146 /// returns a result. The first operand is a chain pointer. The second is
147 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
148 /// operands to the intrinsic follow. The node has two results, the result
149 /// of the intrinsic and an output chain.
152 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
153 /// This node represents a target intrinsic function with side effects that
154 /// does not return a result. The first operand is a chain pointer. The
155 /// second is the ID number of the intrinsic from the llvm::Intrinsic
156 /// namespace. The operands to the intrinsic follow.
159 // CopyToReg - This node has three operands: a chain, a register number to
160 // set to this value, and a value.
163 // CopyFromReg - This node indicates that the input value is a virtual or
164 // physical register that is defined outside of the scope of this
165 // SelectionDAG. The register is available from the RegisterSDNode object.
168 // UNDEF - An undefined node
171 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
172 /// represents the formal arguments for a function. CC# is a Constant value
173 /// indicating the calling convention of the function, and ISVARARG is a
174 /// flag that indicates whether the function is varargs or not. This node
175 /// has one result value for each incoming argument, plus one for the output
176 /// chain. It must be custom legalized. See description of CALL node for
177 /// FLAG argument contents explanation.
181 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
182 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
183 /// This node represents a fully general function call, before the legalizer
184 /// runs. This has one result value for each argument / flag pair, plus
185 /// a chain result. It must be custom legalized. Flag argument indicates
186 /// misc. argument attributes. Currently:
188 /// Bit 1 - 'inreg' attribute
189 /// Bit 2 - 'sret' attribute
190 /// Bit 4 - 'byval' attribute
191 /// Bit 5 - 'nest' attribute
192 /// Bit 6-9 - alignment of byval structures
193 /// Bit 10-26 - size of byval structures
194 /// Bits 31:27 - argument ABI alignment in the first argument piece and
195 /// alignment '1' in other argument pieces.
198 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
199 // a Constant, which is required to be operand #1) half of the integer or
200 // float value specified as operand #0. This is only for use before
201 // legalization, for values that will be broken into multiple registers.
204 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
205 // two values of the same integer value type, this produces a value twice as
206 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
209 // MERGE_VALUES - This node takes multiple discrete operands and returns
210 // them all as its individual results. This nodes has exactly the same
211 // number of inputs and outputs, and is only valid before legalization.
212 // This node is useful for some pieces of the code generator that want to
213 // think about a single node with multiple results, not multiple nodes.
216 // Simple integer binary arithmetic operators.
217 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
219 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
220 // a signed/unsigned value of type i[2*N], and return the full value as
221 // two results, each of type iN.
222 SMUL_LOHI, UMUL_LOHI,
224 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
228 // CARRY_FALSE - This node is used when folding other nodes,
229 // like ADDC/SUBC, which indicate the carry result is always false.
232 // Carry-setting nodes for multiple precision addition and subtraction.
233 // These nodes take two operands of the same value type, and produce two
234 // results. The first result is the normal add or sub result, the second
235 // result is the carry flag result.
238 // Carry-using nodes for multiple precision addition and subtraction. These
239 // nodes take three operands: The first two are the normal lhs and rhs to
240 // the add or sub, and the third is the input carry flag. These nodes
241 // produce two results; the normal result of the add or sub, and the output
242 // carry flag. These nodes both read and write a carry flag to allow them
243 // to them to be chained together for add and sub of arbitrarily large
247 // Simple binary floating point operators.
248 FADD, FSUB, FMUL, FDIV, FREM,
250 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
251 // DAG node does not require that X and Y have the same type, just that they
252 // are both floating point. X and the result must have the same type.
253 // FCOPYSIGN(f32, f64) is allowed.
256 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
257 // value as an integer 0/1 value.
260 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
261 /// with the specified, possibly variable, elements. The number of elements
262 /// is required to be a power of two.
265 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
266 /// at IDX replaced with VAL. If the type of VAL is larger than the vector
267 /// element type then VAL is truncated before replacement.
270 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
271 /// identified by the (potentially variable) element number IDX.
274 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
275 /// vector type with the same length and element type, this produces a
276 /// concatenated vector result value, with length equal to the sum of the
277 /// lengths of the input vectors.
280 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
281 /// vector value) starting with the (potentially variable) element number
282 /// IDX, which must be a multiple of the result vector length.
285 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
286 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
287 /// (maybe of an illegal datatype) or undef that indicate which value each
288 /// result element will get. The elements of VEC1/VEC2 are enumerated in
289 /// order. This is quite similar to the Altivec 'vperm' instruction, except
290 /// that the indices must be constants and are in terms of the element size
291 /// of VEC1/VEC2, not in terms of bytes.
294 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
295 /// scalar value into element 0 of the resultant vector type. The top
296 /// elements 1 to N-1 of the N-element vector are undefined.
299 // EXTRACT_SUBREG - This node is used to extract a sub-register value.
300 // This node takes a superreg and a constant sub-register index as operands.
301 // Note sub-register indices must be increasing. That is, if the
302 // sub-register index of a 8-bit sub-register is N, then the index for a
303 // 16-bit sub-register must be at least N+1.
306 // INSERT_SUBREG - This node is used to insert a sub-register value.
307 // This node takes a superreg, a subreg value, and a constant sub-register
308 // index as operands.
311 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
312 // an unsigned/signed value of type i[2*N], then return the top part.
315 // Bitwise operators - logical and, logical or, logical xor, shift left,
316 // shift right algebraic (shift in sign bits), shift right logical (shift in
317 // zeroes), rotate left, rotate right, and byteswap.
318 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
320 // Counting operators
323 // Select(COND, TRUEVAL, FALSEVAL)
326 // Select with condition operator - This selects between a true value and
327 // a false value (ops #2 and #3) based on the boolean result of comparing
328 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
329 // condition code in op #4, a CondCodeSDNode.
332 // SetCC operator - This evaluates to a boolean (i1) true value if the
333 // condition is true. The operands to this are the left and right operands
334 // to compare (ops #0, and #1) and the condition code to compare them with
335 // (op #2) as a CondCodeSDNode.
338 // Vector SetCC operator - This evaluates to a vector of integer elements
339 // with the high bit in each element set to true if the comparison is true
340 // and false if the comparison is false. All other bits in each element
341 // are undefined. The operands to this are the left and right operands
342 // to compare (ops #0, and #1) and the condition code to compare them with
343 // (op #2) as a CondCodeSDNode.
346 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
347 // integer shift operations, just like ADD/SUB_PARTS. The operation
349 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
350 SHL_PARTS, SRA_PARTS, SRL_PARTS,
352 // Conversion operators. These are all single input single output
353 // operations. For all of these, the result type must be strictly
354 // wider or narrower (depending on the operation) than the source
357 // SIGN_EXTEND - Used for integer types, replicating the sign bit
361 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
364 // ANY_EXTEND - Used for integer types. The high bits are undefined.
367 // TRUNCATE - Completely drop the high bits.
370 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
371 // depends on the first letter) to floating point.
375 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
376 // sign extend a small value in a large integer register (e.g. sign
377 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
378 // with the 7th bit). The size of the smaller type is indicated by the 1th
379 // operand, a ValueType node.
382 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
387 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
388 /// down to the precision of the destination VT. TRUNC is a flag, which is
389 /// always an integer that is zero or one. If TRUNC is 0, this is a
390 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
393 /// The TRUNC = 1 case is used in cases where we know that the value will
394 /// not be modified by the node, because Y is not using any of the extra
395 /// precision of source type. This allows certain transformations like
396 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
397 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
400 // FLT_ROUNDS_ - Returns current rounding mode:
403 // 1 Round to nearest
408 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
409 /// rounds it to a floating point value. It then promotes it and returns it
410 /// in a register of the same size. This operation effectively just
411 /// discards excess precision. The type to round down to is specified by
412 /// the VT operand, a VTSDNode.
415 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
418 // BIT_CONVERT - Theis operator converts between integer and FP values, as
419 // if one was stored to memory as integer and the other was loaded from the
420 // same address (or equivalently for vector format conversions, etc). The
421 // source and result are required to have the same bit size (e.g.
422 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
423 // conversions, but that is a noop, deleted by getNode().
426 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
427 // negation, absolute value, square root, sine and cosine, powi, and pow
429 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
431 // LOAD and STORE have token chains as their first operand, then the same
432 // operands as an LLVM load/store instruction, then an offset node that
433 // is added / subtracted from the base pointer to form the address (for
434 // indexed memory ops).
437 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
438 // to a specified boundary. This node always has two return values: a new
439 // stack pointer value and a chain. The first operand is the token chain,
440 // the second is the number of bytes to allocate, and the third is the
441 // alignment boundary. The size is guaranteed to be a multiple of the stack
442 // alignment, and the alignment is guaranteed to be bigger than the stack
443 // alignment (if required) or 0 to get standard stack alignment.
446 // Control flow instructions. These all have token chains.
448 // BR - Unconditional branch. The first operand is the chain
449 // operand, the second is the MBB to branch to.
452 // BRIND - Indirect branch. The first operand is the chain, the second
453 // is the value to branch to, which must be of the same type as the target's
457 // BR_JT - Jumptable branch. The first operand is the chain, the second
458 // is the jumptable index, the last one is the jumptable entry index.
461 // BRCOND - Conditional branch. The first operand is the chain,
462 // the second is the condition, the third is the block to branch
463 // to if the condition is true.
466 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
467 // that the condition is represented as condition code, and two nodes to
468 // compare, rather than as a combined SetCC node. The operands in order are
469 // chain, cc, lhs, rhs, block to branch to if condition is true.
472 // RET - Return from function. The first operand is the chain,
473 // and any subsequent operands are pairs of return value and return value
474 // signness for the function. This operation can have variable number of
478 // INLINEASM - Represents an inline asm block. This node always has two
479 // return values: a chain and a flag result. The inputs are as follows:
480 // Operand #0 : Input chain.
481 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
482 // Operand #2n+2: A RegisterNode.
483 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
484 // Operand #last: Optional, an incoming flag.
487 // DBG_LABEL, EH_LABEL - Represents a label in mid basic block used to track
488 // locations needed for debug and exception handling tables. These nodes
489 // take a chain as input and return a chain.
493 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
494 // local variable declarations for debugging information. First operand is
495 // a chain, while the next two operands are first two arguments (address
496 // and variable) of a llvm.dbg.declare instruction.
499 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
500 // value, the same type as the pointer type for the system, and an output
504 // STACKRESTORE has two operands, an input chain and a pointer to restore to
505 // it returns an output chain.
508 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
509 // a call sequence, and carry arbitrary information that target might want
510 // to know. The first operand is a chain, the rest are specified by the
511 // target and not touched by the DAG optimizers.
512 // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
513 CALLSEQ_START, // Beginning of a call sequence
514 CALLSEQ_END, // End of a call sequence
516 // VAARG - VAARG has three operands: an input chain, a pointer, and a
517 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
520 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
521 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
525 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
526 // pointer, and a SRCVALUE.
529 // SRCVALUE - This is a node type that holds a Value* that is used to
530 // make reference to a value in the LLVM IR.
533 // MEMOPERAND - This is a node that contains a MachineMemOperand which
534 // records information about a memory reference. This is used to make
535 // AliasAnalysis queries from the backend.
538 // PCMARKER - This corresponds to the pcmarker intrinsic.
541 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
542 // The only operand is a chain and a value and a chain are produced. The
543 // value is the contents of the architecture specific cycle counter like
544 // register (or other high accuracy low latency clock source)
547 // HANDLENODE node - Used as a handle for various purposes.
550 // DBG_STOPPOINT - This node is used to represent a source location for
551 // debug info. It takes token chain as input, and carries a line number,
552 // column number, and a pointer to a CompileUnitDesc object identifying
553 // the containing compilation unit. It produces a token chain as output.
556 // DEBUG_LOC - This node is used to represent source line information
557 // embedded in the code. It takes a token chain as input, then a line
558 // number, then a column then a file id (provided by MachineModuleInfo.) It
559 // produces a token chain as output.
562 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
563 // It takes as input a token chain, the pointer to the trampoline,
564 // the pointer to the nested function, the pointer to pass for the
565 // 'nest' parameter, a SRCVALUE for the trampoline and another for
566 // the nested function (allowing targets to access the original
567 // Function*). It produces the result of the intrinsic and a token
571 // TRAP - Trapping instruction
574 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
575 // their first operand. The other operands are the address to prefetch,
576 // read / write specifier, and locality specifier.
579 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
580 // store-store, device)
581 // This corresponds to the memory.barrier intrinsic.
582 // it takes an input chain, 4 operands to specify the type of barrier, an
583 // operand specifying if the barrier applies to device and uncached memory
584 // and produces an output chain.
587 // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
588 // this corresponds to the atomic.lcs intrinsic.
589 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
590 // the return is always the original value in *ptr
593 // Val, OUTCHAIN = ATOMIC_LOAD_ADD(INCHAIN, ptr, amt)
594 // this corresponds to the atomic.las intrinsic.
595 // *ptr + amt is stored to *ptr atomically.
596 // the return is always the original value in *ptr
599 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
600 // this corresponds to the atomic.swap intrinsic.
601 // amt is stored to *ptr atomically.
602 // the return is always the original value in *ptr
605 // Val, OUTCHAIN = ATOMIC_LOAD_SUB(INCHAIN, ptr, amt)
606 // this corresponds to the atomic.lss intrinsic.
607 // *ptr - amt is stored to *ptr atomically.
608 // the return is always the original value in *ptr
611 // Val, OUTCHAIN = ATOMIC_L[OpName]S(INCHAIN, ptr, amt)
612 // this corresponds to the atomic.[OpName] intrinsic.
613 // op(*ptr, amt) is stored to *ptr atomically.
614 // the return is always the original value in *ptr
624 // BUILTIN_OP_END - This must be the last enum value in this list.
630 /// isBuildVectorAllOnes - Return true if the specified node is a
631 /// BUILD_VECTOR where all of the elements are ~0 or undef.
632 bool isBuildVectorAllOnes(const SDNode *N);
634 /// isBuildVectorAllZeros - Return true if the specified node is a
635 /// BUILD_VECTOR where all of the elements are 0 or undef.
636 bool isBuildVectorAllZeros(const SDNode *N);
638 /// isScalarToVector - Return true if the specified node is a
639 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
640 /// element is not an undef.
641 bool isScalarToVector(const SDNode *N);
643 /// isDebugLabel - Return true if the specified node represents a debug
644 /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node).
645 bool isDebugLabel(const SDNode *N);
647 //===--------------------------------------------------------------------===//
648 /// MemIndexedMode enum - This enum defines the load / store indexed
649 /// addressing modes.
651 /// UNINDEXED "Normal" load / store. The effective address is already
652 /// computed and is available in the base pointer. The offset
653 /// operand is always undefined. In addition to producing a
654 /// chain, an unindexed load produces one value (result of the
655 /// load); an unindexed store does not produce a value.
657 /// PRE_INC Similar to the unindexed mode where the effective address is
658 /// PRE_DEC the value of the base pointer add / subtract the offset.
659 /// It considers the computation as being folded into the load /
660 /// store operation (i.e. the load / store does the address
661 /// computation as well as performing the memory transaction).
662 /// The base operand is always undefined. In addition to
663 /// producing a chain, pre-indexed load produces two values
664 /// (result of the load and the result of the address
665 /// computation); a pre-indexed store produces one value (result
666 /// of the address computation).
668 /// POST_INC The effective address is the value of the base pointer. The
669 /// POST_DEC value of the offset operand is then added to / subtracted
670 /// from the base after memory transaction. In addition to
671 /// producing a chain, post-indexed load produces two values
672 /// (the result of the load and the result of the base +/- offset
673 /// computation); a post-indexed store produces one value (the
674 /// the result of the base +/- offset computation).
676 enum MemIndexedMode {
685 //===--------------------------------------------------------------------===//
686 /// LoadExtType enum - This enum defines the three variants of LOADEXT
687 /// (load with extension).
689 /// SEXTLOAD loads the integer operand and sign extends it to a larger
690 /// integer result type.
691 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
692 /// integer result type.
693 /// EXTLOAD is used for three things: floating point extending loads,
694 /// integer extending loads [the top bits are undefined], and vector
695 /// extending loads [load into low elt].
705 //===--------------------------------------------------------------------===//
706 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
707 /// below work out, when considering SETFALSE (something that never exists
708 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
709 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
710 /// to. If the "N" column is 1, the result of the comparison is undefined if
711 /// the input is a NAN.
713 /// All of these (except for the 'always folded ops') should be handled for
714 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
715 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
717 /// Note that these are laid out in a specific order to allow bit-twiddling
718 /// to transform conditions.
720 // Opcode N U L G E Intuitive operation
721 SETFALSE, // 0 0 0 0 Always false (always folded)
722 SETOEQ, // 0 0 0 1 True if ordered and equal
723 SETOGT, // 0 0 1 0 True if ordered and greater than
724 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
725 SETOLT, // 0 1 0 0 True if ordered and less than
726 SETOLE, // 0 1 0 1 True if ordered and less than or equal
727 SETONE, // 0 1 1 0 True if ordered and operands are unequal
728 SETO, // 0 1 1 1 True if ordered (no nans)
729 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
730 SETUEQ, // 1 0 0 1 True if unordered or equal
731 SETUGT, // 1 0 1 0 True if unordered or greater than
732 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
733 SETULT, // 1 1 0 0 True if unordered or less than
734 SETULE, // 1 1 0 1 True if unordered, less than, or equal
735 SETUNE, // 1 1 1 0 True if unordered or not equal
736 SETTRUE, // 1 1 1 1 Always true (always folded)
737 // Don't care operations: undefined if the input is a nan.
738 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
739 SETEQ, // 1 X 0 0 1 True if equal
740 SETGT, // 1 X 0 1 0 True if greater than
741 SETGE, // 1 X 0 1 1 True if greater than or equal
742 SETLT, // 1 X 1 0 0 True if less than
743 SETLE, // 1 X 1 0 1 True if less than or equal
744 SETNE, // 1 X 1 1 0 True if not equal
745 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
747 SETCC_INVALID // Marker value.
750 /// isSignedIntSetCC - Return true if this is a setcc instruction that
751 /// performs a signed comparison when used with integer operands.
752 inline bool isSignedIntSetCC(CondCode Code) {
753 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
756 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
757 /// performs an unsigned comparison when used with integer operands.
758 inline bool isUnsignedIntSetCC(CondCode Code) {
759 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
762 /// isTrueWhenEqual - Return true if the specified condition returns true if
763 /// the two operands to the condition are equal. Note that if one of the two
764 /// operands is a NaN, this value is meaningless.
765 inline bool isTrueWhenEqual(CondCode Cond) {
766 return ((int)Cond & 1) != 0;
769 /// getUnorderedFlavor - This function returns 0 if the condition is always
770 /// false if an operand is a NaN, 1 if the condition is always true if the
771 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
773 inline unsigned getUnorderedFlavor(CondCode Cond) {
774 return ((int)Cond >> 3) & 3;
777 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
778 /// 'op' is a valid SetCC operation.
779 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
781 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
782 /// when given the operation for (X op Y).
783 CondCode getSetCCSwappedOperands(CondCode Operation);
785 /// getSetCCOrOperation - Return the result of a logical OR between different
786 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
787 /// function returns SETCC_INVALID if it is not possible to represent the
788 /// resultant comparison.
789 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
791 /// getSetCCAndOperation - Return the result of a logical AND between
792 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
793 /// function returns SETCC_INVALID if it is not possible to represent the
794 /// resultant comparison.
795 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
796 } // end llvm::ISD namespace
799 //===----------------------------------------------------------------------===//
800 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
801 /// values as the result of a computation. Many nodes return multiple values,
802 /// from loads (which define a token and a return value) to ADDC (which returns
803 /// a result and a carry value), to calls (which may return an arbitrary number
806 /// As such, each use of a SelectionDAG computation must indicate the node that
807 /// computes it as well as which return value to use from that node. This pair
808 /// of information is represented with the SDValue value type.
812 SDNode *Val; // The node defining the value we are using.
813 unsigned ResNo; // Which return value of the node we are using.
815 SDValue() : Val(0), ResNo(0) {}
816 SDValue(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
818 bool operator==(const SDValue &O) const {
819 return Val == O.Val && ResNo == O.ResNo;
821 bool operator!=(const SDValue &O) const {
822 return !operator==(O);
824 bool operator<(const SDValue &O) const {
825 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
828 SDValue getValue(unsigned R) const {
829 return SDValue(Val, R);
832 // isOperandOf - Return true if this node is an operand of N.
833 bool isOperandOf(SDNode *N) const;
835 /// getValueType - Return the ValueType of the referenced return value.
837 inline MVT getValueType() const;
839 /// getValueSizeInBits - Returns the size of the value in bits.
841 unsigned getValueSizeInBits() const {
842 return getValueType().getSizeInBits();
845 // Forwarding methods - These forward to the corresponding methods in SDNode.
846 inline unsigned getOpcode() const;
847 inline unsigned getNumOperands() const;
848 inline const SDValue &getOperand(unsigned i) const;
849 inline uint64_t getConstantOperandVal(unsigned i) const;
850 inline bool isTargetOpcode() const;
851 inline bool isMachineOpcode() const;
852 inline unsigned getMachineOpcode() const;
855 /// reachesChainWithoutSideEffects - Return true if this operand (which must
856 /// be a chain) reaches the specified operand without crossing any
857 /// side-effecting instructions. In practice, this looks through token
858 /// factors and non-volatile loads. In order to remain efficient, this only
859 /// looks a couple of nodes in, it does not do an exhaustive search.
860 bool reachesChainWithoutSideEffects(SDValue Dest,
861 unsigned Depth = 2) const;
863 /// use_empty - Return true if there are no nodes using value ResNo
866 inline bool use_empty() const;
868 /// use_empty - Return true if there is exactly one node using value
869 /// ResNo of node Val.
871 inline bool hasOneUse() const;
875 template<> struct DenseMapInfo<SDValue> {
876 static inline SDValue getEmptyKey() {
877 return SDValue((SDNode*)-1, -1U);
879 static inline SDValue getTombstoneKey() {
880 return SDValue((SDNode*)-1, 0);
882 static unsigned getHashValue(const SDValue &Val) {
883 return ((unsigned)((uintptr_t)Val.Val >> 4) ^
884 (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo;
886 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
889 static bool isPod() { return true; }
892 /// simplify_type specializations - Allow casting operators to work directly on
893 /// SDValues as if they were SDNode*'s.
894 template<> struct simplify_type<SDValue> {
895 typedef SDNode* SimpleType;
896 static SimpleType getSimplifiedValue(const SDValue &Val) {
897 return static_cast<SimpleType>(Val.Val);
900 template<> struct simplify_type<const SDValue> {
901 typedef SDNode* SimpleType;
902 static SimpleType getSimplifiedValue(const SDValue &Val) {
903 return static_cast<SimpleType>(Val.Val);
907 /// SDUse - Represents a use of the SDNode referred by
911 /// User - Parent node of this operand.
913 /// Prev, next - Pointers to the uses list of the SDNode referred by
918 SDUse(): Operand(), User(NULL), Prev(NULL), Next(NULL) {}
920 SDUse(SDNode *val, unsigned resno) :
921 Operand(val,resno), User(NULL), Prev(NULL), Next(NULL) {}
923 SDUse& operator= (const SDValue& Op) {
930 SDUse& operator= (const SDUse& Op) {
937 SDUse *getNext() { return Next; }
939 SDNode *getUser() { return User; }
941 void setUser(SDNode *p) { User = p; }
943 operator SDValue() const { return Operand; }
945 const SDValue& getSDValue() const { return Operand; }
947 SDNode *&getVal() { return Operand.Val; }
948 SDNode *const &getVal() const { return Operand.Val; }
950 bool operator==(const SDValue &O) const {
954 bool operator!=(const SDValue &O) const {
955 return !(Operand == O);
958 bool operator<(const SDValue &O) const {
963 void addToList(SDUse **List) {
965 if (Next) Next->Prev = &Next;
970 void removeFromList() {
972 if (Next) Next->Prev = Prev;
977 /// simplify_type specializations - Allow casting operators to work directly on
978 /// SDValues as if they were SDNode*'s.
979 template<> struct simplify_type<SDUse> {
980 typedef SDNode* SimpleType;
981 static SimpleType getSimplifiedValue(const SDUse &Val) {
982 return static_cast<SimpleType>(Val.getVal());
985 template<> struct simplify_type<const SDUse> {
986 typedef SDNode* SimpleType;
987 static SimpleType getSimplifiedValue(const SDUse &Val) {
988 return static_cast<SimpleType>(Val.getVal());
993 /// SDOperandPtr - A helper SDValue pointer class, that can handle
994 /// arrays of SDUse and arrays of SDValue objects. This is required
995 /// in many places inside the SelectionDAG.
998 const SDValue *ptr; // The pointer to the SDValue object
999 int object_size; // The size of the object containg the SDValue
1001 SDOperandPtr() : ptr(0), object_size(0) {}
1003 SDOperandPtr(SDUse * use_ptr) {
1004 ptr = &use_ptr->getSDValue();
1005 object_size = (int)sizeof(SDUse);
1008 SDOperandPtr(const SDValue * op_ptr) {
1010 object_size = (int)sizeof(SDValue);
1013 const SDValue operator *() { return *ptr; }
1014 const SDValue *operator ->() { return ptr; }
1015 SDOperandPtr operator ++ () {
1016 ptr = (SDValue*)((char *)ptr + object_size);
1020 SDOperandPtr operator ++ (int) {
1021 SDOperandPtr tmp = *this;
1022 ptr = (SDValue*)((char *)ptr + object_size);
1026 SDValue operator[] (int idx) const {
1027 return *(SDValue*)((char*) ptr + object_size * idx);
1031 /// SDNode - Represents one node in the SelectionDAG.
1033 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
1035 /// NodeType - The operation that this node performs.
1039 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
1040 /// then they will be delete[]'d when the node is destroyed.
1041 unsigned short OperandsNeedDelete : 1;
1044 /// SubclassData - This member is defined by this class, but is not used for
1045 /// anything. Subclasses can use it to hold whatever state they find useful.
1046 /// This field is initialized to zero by the ctor.
1047 unsigned short SubclassData : 15;
1050 /// NodeId - Unique id per SDNode in the DAG.
1053 /// OperandList - The values that are used by this operation.
1057 /// ValueList - The types of the values this node defines. SDNode's may
1058 /// define multiple values simultaneously.
1059 const MVT *ValueList;
1061 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1062 unsigned short NumOperands, NumValues;
1064 /// Uses - List of uses for this SDNode.
1067 /// addUse - add SDUse to the list of uses.
1068 void addUse(SDUse &U) { U.addToList(&Uses); }
1070 // Out-of-line virtual method to give class a home.
1071 virtual void ANCHOR();
1074 assert(NumOperands == 0 && "Operand list not cleared before deletion");
1075 NodeType = ISD::DELETED_NODE;
1078 //===--------------------------------------------------------------------===//
1082 /// getOpcode - Return the SelectionDAG opcode value for this node. For
1083 /// pre-isel nodes (those for which isMachineOpcode returns false), these
1084 /// are the opcode values in the ISD and <target>ISD namespaces. For
1085 /// post-isel opcodes, see getMachineOpcode.
1086 unsigned getOpcode() const { return (unsigned short)NodeType; }
1088 /// isTargetOpcode - Test if this node has a target-specific opcode (in the
1089 /// <target>ISD namespace).
1090 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1092 /// isMachineOpcode - Test if this node has a post-isel opcode, directly
1093 /// corresponding to a MachineInstr opcode.
1094 bool isMachineOpcode() const { return NodeType < 0; }
1096 /// getMachineOpcode - This may only be called if isMachineOpcode returns
1097 /// true. It returns the MachineInstr opcode value that the node's opcode
1099 unsigned getMachineOpcode() const {
1100 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
1104 /// use_empty - Return true if there are no uses of this node.
1106 bool use_empty() const { return Uses == NULL; }
1108 /// hasOneUse - Return true if there is exactly one use of this node.
1110 bool hasOneUse() const {
1111 return !use_empty() && next(use_begin()) == use_end();
1114 /// use_size - Return the number of uses of this node. This method takes
1115 /// time proportional to the number of uses.
1117 size_t use_size() const { return std::distance(use_begin(), use_end()); }
1119 /// getNodeId - Return the unique node id.
1121 int getNodeId() const { return NodeId; }
1123 /// setNodeId - Set unique node id.
1124 void setNodeId(int Id) { NodeId = Id; }
1126 /// use_iterator - This class provides iterator support for SDUse
1127 /// operands that use a specific SDNode.
1129 : public forward_iterator<SDUse, ptrdiff_t> {
1131 explicit use_iterator(SDUse *op) : Op(op) {
1133 friend class SDNode;
1135 typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
1136 typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1138 use_iterator(const use_iterator &I) : Op(I.Op) {}
1139 use_iterator() : Op(0) {}
1141 bool operator==(const use_iterator &x) const {
1144 bool operator!=(const use_iterator &x) const {
1145 return !operator==(x);
1148 /// atEnd - return true if this iterator is at the end of uses list.
1149 bool atEnd() const { return Op == 0; }
1151 // Iterator traversal: forward iteration only.
1152 use_iterator &operator++() { // Preincrement
1153 assert(Op && "Cannot increment end iterator!");
1158 use_iterator operator++(int) { // Postincrement
1159 use_iterator tmp = *this; ++*this; return tmp;
1162 /// Retrieve a pointer to the current user node.
1163 SDNode *operator*() const {
1164 assert(Op && "Cannot dereference end iterator!");
1165 return Op->getUser();
1168 SDNode *operator->() const { return operator*(); }
1170 SDUse &getUse() const { return *Op; }
1172 /// getOperandNo - Retrive the operand # of this use in its user.
1174 unsigned getOperandNo() const {
1175 assert(Op && "Cannot dereference end iterator!");
1176 return (unsigned)(Op - Op->getUser()->OperandList);
1180 /// use_begin/use_end - Provide iteration support to walk over all uses
1183 use_iterator use_begin() const {
1184 return use_iterator(Uses);
1187 static use_iterator use_end() { return use_iterator(0); }
1190 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1191 /// indicated value. This method ignores uses of other values defined by this
1193 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1195 /// hasAnyUseOfValue - Return true if there are any use of the indicated
1196 /// value. This method ignores uses of other values defined by this operation.
1197 bool hasAnyUseOfValue(unsigned Value) const;
1199 /// isOnlyUserOf - Return true if this node is the only use of N.
1201 bool isOnlyUserOf(SDNode *N) const;
1203 /// isOperandOf - Return true if this node is an operand of N.
1205 bool isOperandOf(SDNode *N) const;
1207 /// isPredecessorOf - Return true if this node is a predecessor of N. This
1208 /// node is either an operand of N or it can be reached by recursively
1209 /// traversing up the operands.
1210 /// NOTE: this is an expensive method. Use it carefully.
1211 bool isPredecessorOf(SDNode *N) const;
1213 /// getNumOperands - Return the number of values used by this operation.
1215 unsigned getNumOperands() const { return NumOperands; }
1217 /// getConstantOperandVal - Helper method returns the integer value of a
1218 /// ConstantSDNode operand.
1219 uint64_t getConstantOperandVal(unsigned Num) const;
1221 const SDValue &getOperand(unsigned Num) const {
1222 assert(Num < NumOperands && "Invalid child # of SDNode!");
1223 return OperandList[Num].getSDValue();
1226 typedef SDUse* op_iterator;
1227 op_iterator op_begin() const { return OperandList; }
1228 op_iterator op_end() const { return OperandList+NumOperands; }
1231 SDVTList getVTList() const {
1232 SDVTList X = { ValueList, NumValues };
1236 /// getNumValues - Return the number of values defined/returned by this
1239 unsigned getNumValues() const { return NumValues; }
1241 /// getValueType - Return the type of a specified result.
1243 MVT getValueType(unsigned ResNo) const {
1244 assert(ResNo < NumValues && "Illegal result number!");
1245 return ValueList[ResNo];
1248 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1250 unsigned getValueSizeInBits(unsigned ResNo) const {
1251 return getValueType(ResNo).getSizeInBits();
1254 typedef const MVT* value_iterator;
1255 value_iterator value_begin() const { return ValueList; }
1256 value_iterator value_end() const { return ValueList+NumValues; }
1258 /// getOperationName - Return the opcode of this operation for printing.
1260 std::string getOperationName(const SelectionDAG *G = 0) const;
1261 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1263 void dump(const SelectionDAG *G) const;
1265 static bool classof(const SDNode *) { return true; }
1267 /// Profile - Gather unique data for the node.
1269 void Profile(FoldingSetNodeID &ID);
1272 friend class SelectionDAG;
1273 friend class ilist_traits<SDNode>;
1275 /// getValueTypeList - Return a pointer to the specified value type.
1277 static const MVT *getValueTypeList(MVT VT);
1278 static SDVTList getSDVTList(MVT VT) {
1279 SDVTList Ret = { getValueTypeList(VT), 1 };
1283 SDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps)
1284 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1285 NodeId(-1), Uses(NULL) {
1286 NumOperands = NumOps;
1287 OperandList = NumOps ? new SDUse[NumOperands] : 0;
1289 for (unsigned i = 0; i != NumOps; ++i) {
1290 OperandList[i] = Ops[i];
1291 OperandList[i].setUser(this);
1292 Ops[i].Val->addUse(OperandList[i]);
1295 ValueList = VTs.VTs;
1296 NumValues = VTs.NumVTs;
1299 SDNode(unsigned Opc, SDVTList VTs, const SDUse *Ops, unsigned NumOps)
1300 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1301 NodeId(-1), Uses(NULL) {
1302 OperandsNeedDelete = true;
1303 NumOperands = NumOps;
1304 OperandList = NumOps ? new SDUse[NumOperands] : 0;
1306 for (unsigned i = 0; i != NumOps; ++i) {
1307 OperandList[i] = Ops[i];
1308 OperandList[i].setUser(this);
1309 Ops[i].getVal()->addUse(OperandList[i]);
1312 ValueList = VTs.VTs;
1313 NumValues = VTs.NumVTs;
1316 /// This constructor adds no operands itself; operands can be
1317 /// set later with InitOperands.
1318 SDNode(unsigned Opc, SDVTList VTs)
1319 : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1320 NodeId(-1), Uses(NULL) {
1323 ValueList = VTs.VTs;
1324 NumValues = VTs.NumVTs;
1327 /// InitOperands - Initialize the operands list of this node with the
1328 /// specified values, which are part of the node (thus they don't need to be
1329 /// copied in or allocated).
1330 void InitOperands(SDUse *Ops, unsigned NumOps) {
1331 assert(OperandList == 0 && "Operands already set!");
1332 NumOperands = NumOps;
1336 for (unsigned i = 0; i != NumOps; ++i) {
1337 OperandList[i].setUser(this);
1338 Ops[i].getVal()->addUse(OperandList[i]);
1342 /// DropOperands - Release the operands and set this node to have
1344 void DropOperands();
1346 void addUser(unsigned i, SDNode *User) {
1347 assert(User->OperandList[i].getUser() && "Node without parent");
1348 addUse(User->OperandList[i]);
1351 void removeUser(unsigned i, SDNode *User) {
1352 assert(User->OperandList[i].getUser() && "Node without parent");
1353 SDUse &Op = User->OperandList[i];
1354 Op.removeFromList();
1359 // Define inline functions from the SDValue class.
1361 inline unsigned SDValue::getOpcode() const {
1362 return Val->getOpcode();
1364 inline MVT SDValue::getValueType() const {
1365 return Val->getValueType(ResNo);
1367 inline unsigned SDValue::getNumOperands() const {
1368 return Val->getNumOperands();
1370 inline const SDValue &SDValue::getOperand(unsigned i) const {
1371 return Val->getOperand(i);
1373 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1374 return Val->getConstantOperandVal(i);
1376 inline bool SDValue::isTargetOpcode() const {
1377 return Val->isTargetOpcode();
1379 inline bool SDValue::isMachineOpcode() const {
1380 return Val->isMachineOpcode();
1382 inline unsigned SDValue::getMachineOpcode() const {
1383 return Val->getMachineOpcode();
1385 inline bool SDValue::use_empty() const {
1386 return !Val->hasAnyUseOfValue(ResNo);
1388 inline bool SDValue::hasOneUse() const {
1389 return Val->hasNUsesOfValue(1, ResNo);
1392 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1393 /// to allow co-allocation of node operands with the node itself.
1394 class UnarySDNode : public SDNode {
1395 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1398 UnarySDNode(unsigned Opc, SDVTList VTs, SDValue X)
1399 : SDNode(Opc, VTs) {
1401 InitOperands(&Op, 1);
1405 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1406 /// to allow co-allocation of node operands with the node itself.
1407 class BinarySDNode : public SDNode {
1408 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1411 BinarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y)
1412 : SDNode(Opc, VTs) {
1415 InitOperands(Ops, 2);
1419 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1420 /// to allow co-allocation of node operands with the node itself.
1421 class TernarySDNode : public SDNode {
1422 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1425 TernarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y,
1427 : SDNode(Opc, VTs) {
1431 InitOperands(Ops, 3);
1436 /// HandleSDNode - This class is used to form a handle around another node that
1437 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1438 /// operand. This node should be directly created by end-users and not added to
1439 /// the AllNodes list.
1440 class HandleSDNode : public SDNode {
1441 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1444 // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1447 explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
1449 explicit HandleSDNode(SDValue X)
1451 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
1453 InitOperands(&Op, 1);
1456 SDUse getValue() const { return Op; }
1459 /// Abstact virtual class for operations for memory operations
1460 class MemSDNode : public SDNode {
1461 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1464 // MemoryVT - VT of in-memory value.
1467 //! SrcValue - Memory location for alias analysis.
1468 const Value *SrcValue;
1470 //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
1473 /// Flags - the low bit indicates whether this is a volatile reference;
1474 /// the remainder is a log2 encoding of the alignment in bytes.
1478 MemSDNode(unsigned Opc, SDVTList VTs, MVT MemoryVT,
1479 const Value *srcValue, int SVOff,
1480 unsigned alignment, bool isvolatile);
1482 /// Returns alignment and volatility of the memory access
1483 unsigned getAlignment() const { return (1u << (Flags >> 1)) >> 1; }
1484 bool isVolatile() const { return Flags & 1; }
1486 /// Returns the SrcValue and offset that describes the location of the access
1487 const Value *getSrcValue() const { return SrcValue; }
1488 int getSrcValueOffset() const { return SVOffset; }
1490 /// getMemoryVT - Return the type of the in-memory value.
1491 MVT getMemoryVT() const { return MemoryVT; }
1493 /// getMemOperand - Return a MachineMemOperand object describing the memory
1494 /// reference performed by operation.
1495 MachineMemOperand getMemOperand() const;
1497 const SDValue &getChain() const { return getOperand(0); }
1498 const SDValue &getBasePtr() const {
1499 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1502 // Methods to support isa and dyn_cast
1503 static bool classof(const MemSDNode *) { return true; }
1504 static bool classof(const SDNode *N) {
1505 return N->getOpcode() == ISD::LOAD ||
1506 N->getOpcode() == ISD::STORE ||
1507 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1508 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1509 N->getOpcode() == ISD::ATOMIC_SWAP ||
1510 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1511 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1512 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1513 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1514 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1515 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1516 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1517 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1518 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1522 /// Atomic operations node
1523 class AtomicSDNode : public MemSDNode {
1524 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1528 // Opc: opcode for atomic
1529 // VTL: value type list
1530 // Chain: memory chain for operaand
1531 // Ptr: address to update as a SDValue
1532 // Cmp: compare value
1534 // SrcVal: address to update as a Value (used for MemOperand)
1535 // Align: alignment of memory
1536 AtomicSDNode(unsigned Opc, SDVTList VTL, SDValue Chain, SDValue Ptr,
1537 SDValue Cmp, SDValue Swp, const Value* SrcVal,
1539 : MemSDNode(Opc, VTL, Cmp.getValueType(), SrcVal, /*SVOffset=*/0,
1540 Align, /*isVolatile=*/true) {
1545 InitOperands(Ops, 4);
1547 AtomicSDNode(unsigned Opc, SDVTList VTL, SDValue Chain, SDValue Ptr,
1548 SDValue Val, const Value* SrcVal, unsigned Align=0)
1549 : MemSDNode(Opc, VTL, Val.getValueType(), SrcVal, /*SVOffset=*/0,
1550 Align, /*isVolatile=*/true) {
1554 InitOperands(Ops, 3);
1557 const SDValue &getBasePtr() const { return getOperand(1); }
1558 const SDValue &getVal() const { return getOperand(2); }
1560 bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_CMP_SWAP; }
1562 // Methods to support isa and dyn_cast
1563 static bool classof(const AtomicSDNode *) { return true; }
1564 static bool classof(const SDNode *N) {
1565 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1566 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1567 N->getOpcode() == ISD::ATOMIC_SWAP ||
1568 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1569 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1570 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1571 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1572 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1573 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1574 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1575 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1576 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1580 class ConstantSDNode : public SDNode {
1582 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1584 friend class SelectionDAG;
1585 ConstantSDNode(bool isTarget, const APInt &val, MVT VT)
1586 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1591 const APInt &getAPIntValue() const { return Value; }
1592 uint64_t getValue() const { return Value.getZExtValue(); }
1594 int64_t getSignExtended() const {
1595 unsigned Bits = getValueType(0).getSizeInBits();
1596 return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1599 bool isNullValue() const { return Value == 0; }
1600 bool isAllOnesValue() const {
1601 return Value == getValueType(0).getIntegerVTBitMask();
1604 static bool classof(const ConstantSDNode *) { return true; }
1605 static bool classof(const SDNode *N) {
1606 return N->getOpcode() == ISD::Constant ||
1607 N->getOpcode() == ISD::TargetConstant;
1611 class ConstantFPSDNode : public SDNode {
1613 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1615 friend class SelectionDAG;
1616 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT VT)
1617 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1618 getSDVTList(VT)), Value(val) {
1622 const APFloat& getValueAPF() const { return Value; }
1624 /// isExactlyValue - We don't rely on operator== working on double values, as
1625 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1626 /// As such, this method can be used to do an exact bit-for-bit comparison of
1627 /// two floating point values.
1629 /// We leave the version with the double argument here because it's just so
1630 /// convenient to write "2.0" and the like. Without this function we'd
1631 /// have to duplicate its logic everywhere it's called.
1632 bool isExactlyValue(double V) const {
1633 // convert is not supported on this type
1634 if (&Value.getSemantics() == &APFloat::PPCDoubleDouble)
1637 Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1638 return isExactlyValue(Tmp);
1640 bool isExactlyValue(const APFloat& V) const;
1642 bool isValueValidForType(MVT VT, const APFloat& Val);
1644 static bool classof(const ConstantFPSDNode *) { return true; }
1645 static bool classof(const SDNode *N) {
1646 return N->getOpcode() == ISD::ConstantFP ||
1647 N->getOpcode() == ISD::TargetConstantFP;
1651 class GlobalAddressSDNode : public SDNode {
1652 GlobalValue *TheGlobal;
1654 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1656 friend class SelectionDAG;
1657 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT, int o = 0);
1660 GlobalValue *getGlobal() const { return TheGlobal; }
1661 int getOffset() const { return Offset; }
1663 static bool classof(const GlobalAddressSDNode *) { return true; }
1664 static bool classof(const SDNode *N) {
1665 return N->getOpcode() == ISD::GlobalAddress ||
1666 N->getOpcode() == ISD::TargetGlobalAddress ||
1667 N->getOpcode() == ISD::GlobalTLSAddress ||
1668 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1672 class FrameIndexSDNode : public SDNode {
1674 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1676 friend class SelectionDAG;
1677 FrameIndexSDNode(int fi, MVT VT, bool isTarg)
1678 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1683 int getIndex() const { return FI; }
1685 static bool classof(const FrameIndexSDNode *) { return true; }
1686 static bool classof(const SDNode *N) {
1687 return N->getOpcode() == ISD::FrameIndex ||
1688 N->getOpcode() == ISD::TargetFrameIndex;
1692 class JumpTableSDNode : public SDNode {
1694 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1696 friend class SelectionDAG;
1697 JumpTableSDNode(int jti, MVT VT, bool isTarg)
1698 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1703 int getIndex() const { return JTI; }
1705 static bool classof(const JumpTableSDNode *) { return true; }
1706 static bool classof(const SDNode *N) {
1707 return N->getOpcode() == ISD::JumpTable ||
1708 N->getOpcode() == ISD::TargetJumpTable;
1712 class ConstantPoolSDNode : public SDNode {
1715 MachineConstantPoolValue *MachineCPVal;
1717 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1719 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1721 friend class SelectionDAG;
1722 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0)
1723 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1724 getSDVTList(VT)), Offset(o), Alignment(0) {
1725 assert((int)Offset >= 0 && "Offset is too large");
1728 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o, unsigned Align)
1729 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1730 getSDVTList(VT)), Offset(o), Alignment(Align) {
1731 assert((int)Offset >= 0 && "Offset is too large");
1734 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1736 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1737 getSDVTList(VT)), Offset(o), Alignment(0) {
1738 assert((int)Offset >= 0 && "Offset is too large");
1739 Val.MachineCPVal = v;
1740 Offset |= 1 << (sizeof(unsigned)*8-1);
1742 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1743 MVT VT, int o, unsigned Align)
1744 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1745 getSDVTList(VT)), Offset(o), Alignment(Align) {
1746 assert((int)Offset >= 0 && "Offset is too large");
1747 Val.MachineCPVal = v;
1748 Offset |= 1 << (sizeof(unsigned)*8-1);
1752 bool isMachineConstantPoolEntry() const {
1753 return (int)Offset < 0;
1756 Constant *getConstVal() const {
1757 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1758 return Val.ConstVal;
1761 MachineConstantPoolValue *getMachineCPVal() const {
1762 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1763 return Val.MachineCPVal;
1766 int getOffset() const {
1767 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1770 // Return the alignment of this constant pool object, which is either 0 (for
1771 // default alignment) or log2 of the desired value.
1772 unsigned getAlignment() const { return Alignment; }
1774 const Type *getType() const;
1776 static bool classof(const ConstantPoolSDNode *) { return true; }
1777 static bool classof(const SDNode *N) {
1778 return N->getOpcode() == ISD::ConstantPool ||
1779 N->getOpcode() == ISD::TargetConstantPool;
1783 class BasicBlockSDNode : public SDNode {
1784 MachineBasicBlock *MBB;
1785 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1787 friend class SelectionDAG;
1788 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1789 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1793 MachineBasicBlock *getBasicBlock() const { return MBB; }
1795 static bool classof(const BasicBlockSDNode *) { return true; }
1796 static bool classof(const SDNode *N) {
1797 return N->getOpcode() == ISD::BasicBlock;
1801 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1802 /// used when the SelectionDAG needs to make a simple reference to something
1803 /// in the LLVM IR representation.
1805 /// Note that this is not used for carrying alias information; that is done
1806 /// with MemOperandSDNode, which includes a Value which is required to be a
1807 /// pointer, and several other fields specific to memory references.
1809 class SrcValueSDNode : public SDNode {
1811 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1813 friend class SelectionDAG;
1814 /// Create a SrcValue for a general value.
1815 explicit SrcValueSDNode(const Value *v)
1816 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1819 /// getValue - return the contained Value.
1820 const Value *getValue() const { return V; }
1822 static bool classof(const SrcValueSDNode *) { return true; }
1823 static bool classof(const SDNode *N) {
1824 return N->getOpcode() == ISD::SRCVALUE;
1829 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
1830 /// used to represent a reference to memory after ISD::LOAD
1831 /// and ISD::STORE have been lowered.
1833 class MemOperandSDNode : public SDNode {
1834 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1836 friend class SelectionDAG;
1837 /// Create a MachineMemOperand node
1838 explicit MemOperandSDNode(const MachineMemOperand &mo)
1839 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1842 /// MO - The contained MachineMemOperand.
1843 const MachineMemOperand MO;
1845 static bool classof(const MemOperandSDNode *) { return true; }
1846 static bool classof(const SDNode *N) {
1847 return N->getOpcode() == ISD::MEMOPERAND;
1852 class RegisterSDNode : public SDNode {
1854 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1856 friend class SelectionDAG;
1857 RegisterSDNode(unsigned reg, MVT VT)
1858 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1862 unsigned getReg() const { return Reg; }
1864 static bool classof(const RegisterSDNode *) { return true; }
1865 static bool classof(const SDNode *N) {
1866 return N->getOpcode() == ISD::Register;
1870 class DbgStopPointSDNode : public SDNode {
1874 const CompileUnitDesc *CU;
1875 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1877 friend class SelectionDAG;
1878 DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
1879 const CompileUnitDesc *cu)
1880 : SDNode(ISD::DBG_STOPPOINT, getSDVTList(MVT::Other)),
1881 Line(l), Column(c), CU(cu) {
1883 InitOperands(&Chain, 1);
1886 unsigned getLine() const { return Line; }
1887 unsigned getColumn() const { return Column; }
1888 const CompileUnitDesc *getCompileUnit() const { return CU; }
1890 static bool classof(const DbgStopPointSDNode *) { return true; }
1891 static bool classof(const SDNode *N) {
1892 return N->getOpcode() == ISD::DBG_STOPPOINT;
1896 class LabelSDNode : public SDNode {
1899 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1901 friend class SelectionDAG;
1902 LabelSDNode(unsigned NodeTy, SDValue ch, unsigned id)
1903 : SDNode(NodeTy, getSDVTList(MVT::Other)), LabelID(id) {
1905 InitOperands(&Chain, 1);
1908 unsigned getLabelID() const { return LabelID; }
1910 static bool classof(const LabelSDNode *) { return true; }
1911 static bool classof(const SDNode *N) {
1912 return N->getOpcode() == ISD::DBG_LABEL ||
1913 N->getOpcode() == ISD::EH_LABEL;
1917 class ExternalSymbolSDNode : public SDNode {
1919 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1921 friend class SelectionDAG;
1922 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT VT)
1923 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1924 getSDVTList(VT)), Symbol(Sym) {
1928 const char *getSymbol() const { return Symbol; }
1930 static bool classof(const ExternalSymbolSDNode *) { return true; }
1931 static bool classof(const SDNode *N) {
1932 return N->getOpcode() == ISD::ExternalSymbol ||
1933 N->getOpcode() == ISD::TargetExternalSymbol;
1937 class CondCodeSDNode : public SDNode {
1938 ISD::CondCode Condition;
1939 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1941 friend class SelectionDAG;
1942 explicit CondCodeSDNode(ISD::CondCode Cond)
1943 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1947 ISD::CondCode get() const { return Condition; }
1949 static bool classof(const CondCodeSDNode *) { return true; }
1950 static bool classof(const SDNode *N) {
1951 return N->getOpcode() == ISD::CONDCODE;
1958 static const uint64_t NoFlagSet = 0ULL;
1959 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
1960 static const uint64_t ZExtOffs = 0;
1961 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
1962 static const uint64_t SExtOffs = 1;
1963 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
1964 static const uint64_t InRegOffs = 2;
1965 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
1966 static const uint64_t SRetOffs = 3;
1967 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
1968 static const uint64_t ByValOffs = 4;
1969 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
1970 static const uint64_t NestOffs = 5;
1971 static const uint64_t ByValAlign = 0xFULL << 6; //< Struct alignment
1972 static const uint64_t ByValAlignOffs = 6;
1973 static const uint64_t Split = 1ULL << 10;
1974 static const uint64_t SplitOffs = 10;
1975 static const uint64_t OrigAlign = 0x1FULL<<27;
1976 static const uint64_t OrigAlignOffs = 27;
1977 static const uint64_t ByValSize = 0xffffffffULL << 32; //< Struct size
1978 static const uint64_t ByValSizeOffs = 32;
1980 static const uint64_t One = 1ULL; //< 1 of this type, for shifts
1984 ArgFlagsTy() : Flags(0) { }
1986 bool isZExt() const { return Flags & ZExt; }
1987 void setZExt() { Flags |= One << ZExtOffs; }
1989 bool isSExt() const { return Flags & SExt; }
1990 void setSExt() { Flags |= One << SExtOffs; }
1992 bool isInReg() const { return Flags & InReg; }
1993 void setInReg() { Flags |= One << InRegOffs; }
1995 bool isSRet() const { return Flags & SRet; }
1996 void setSRet() { Flags |= One << SRetOffs; }
1998 bool isByVal() const { return Flags & ByVal; }
1999 void setByVal() { Flags |= One << ByValOffs; }
2001 bool isNest() const { return Flags & Nest; }
2002 void setNest() { Flags |= One << NestOffs; }
2004 unsigned getByValAlign() const {
2006 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
2008 void setByValAlign(unsigned A) {
2009 Flags = (Flags & ~ByValAlign) |
2010 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
2013 bool isSplit() const { return Flags & Split; }
2014 void setSplit() { Flags |= One << SplitOffs; }
2016 unsigned getOrigAlign() const {
2018 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
2020 void setOrigAlign(unsigned A) {
2021 Flags = (Flags & ~OrigAlign) |
2022 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
2025 unsigned getByValSize() const {
2026 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
2028 void setByValSize(unsigned S) {
2029 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
2032 /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
2033 std::string getArgFlagsString();
2035 /// getRawBits - Represent the flags as a bunch of bits.
2036 uint64_t getRawBits() const { return Flags; }
2040 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
2041 class ARG_FLAGSSDNode : public SDNode {
2042 ISD::ArgFlagsTy TheFlags;
2043 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2045 friend class SelectionDAG;
2046 explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
2047 : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
2050 ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
2052 static bool classof(const ARG_FLAGSSDNode *) { return true; }
2053 static bool classof(const SDNode *N) {
2054 return N->getOpcode() == ISD::ARG_FLAGS;
2058 /// VTSDNode - This class is used to represent MVT's, which are used
2059 /// to parameterize some operations.
2060 class VTSDNode : public SDNode {
2062 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2064 friend class SelectionDAG;
2065 explicit VTSDNode(MVT VT)
2066 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
2070 MVT getVT() const { return ValueType; }
2072 static bool classof(const VTSDNode *) { return true; }
2073 static bool classof(const SDNode *N) {
2074 return N->getOpcode() == ISD::VALUETYPE;
2078 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
2080 class LSBaseSDNode : public MemSDNode {
2082 //! Operand array for load and store
2084 \note Moving this array to the base class captures more
2085 common functionality shared between LoadSDNode and
2090 LSBaseSDNode(ISD::NodeType NodeTy, SDValue *Operands, unsigned numOperands,
2091 SDVTList VTs, ISD::MemIndexedMode AM, MVT VT,
2092 const Value *SV, int SVO, unsigned Align, bool Vol)
2093 : MemSDNode(NodeTy, VTs, VT, SV, SVO, Align, Vol) {
2095 for (unsigned i = 0; i != numOperands; ++i)
2096 Ops[i] = Operands[i];
2097 InitOperands(Ops, numOperands);
2098 assert(Align != 0 && "Loads and stores should have non-zero aligment");
2099 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
2100 "Only indexed loads and stores have a non-undef offset operand");
2103 const SDValue &getOffset() const {
2104 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2107 /// getAddressingMode - Return the addressing mode for this load or store:
2108 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2109 ISD::MemIndexedMode getAddressingMode() const {
2110 return ISD::MemIndexedMode(SubclassData & 7);
2113 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
2114 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2116 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
2117 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2119 static bool classof(const LSBaseSDNode *) { return true; }
2120 static bool classof(const SDNode *N) {
2121 return N->getOpcode() == ISD::LOAD ||
2122 N->getOpcode() == ISD::STORE;
2126 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2128 class LoadSDNode : public LSBaseSDNode {
2129 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2131 friend class SelectionDAG;
2132 LoadSDNode(SDValue *ChainPtrOff, SDVTList VTs,
2133 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT,
2134 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2135 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
2136 VTs, AM, LVT, SV, O, Align, Vol) {
2137 SubclassData |= (unsigned short)ETy << 3;
2141 /// getExtensionType - Return whether this is a plain node,
2142 /// or one of the varieties of value-extending loads.
2143 ISD::LoadExtType getExtensionType() const {
2144 return ISD::LoadExtType((SubclassData >> 3) & 3);
2147 const SDValue &getBasePtr() const { return getOperand(1); }
2148 const SDValue &getOffset() const { return getOperand(2); }
2150 static bool classof(const LoadSDNode *) { return true; }
2151 static bool classof(const SDNode *N) {
2152 return N->getOpcode() == ISD::LOAD;
2156 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2158 class StoreSDNode : public LSBaseSDNode {
2159 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2161 friend class SelectionDAG;
2162 StoreSDNode(SDValue *ChainValuePtrOff, SDVTList VTs,
2163 ISD::MemIndexedMode AM, bool isTrunc, MVT SVT,
2164 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2165 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
2166 VTs, AM, SVT, SV, O, Align, Vol) {
2167 SubclassData |= (unsigned short)isTrunc << 3;
2171 /// isTruncatingStore - Return true if the op does a truncation before store.
2172 /// For integers this is the same as doing a TRUNCATE and storing the result.
2173 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2174 bool isTruncatingStore() const { return (SubclassData >> 3) & 1; }
2176 const SDValue &getValue() const { return getOperand(1); }
2177 const SDValue &getBasePtr() const { return getOperand(2); }
2178 const SDValue &getOffset() const { return getOperand(3); }
2180 static bool classof(const StoreSDNode *) { return true; }
2181 static bool classof(const SDNode *N) {
2182 return N->getOpcode() == ISD::STORE;
2187 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
2191 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2193 bool operator==(const SDNodeIterator& x) const {
2194 return Operand == x.Operand;
2196 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2198 const SDNodeIterator &operator=(const SDNodeIterator &I) {
2199 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2200 Operand = I.Operand;
2204 pointer operator*() const {
2205 return Node->getOperand(Operand).Val;
2207 pointer operator->() const { return operator*(); }
2209 SDNodeIterator& operator++() { // Preincrement
2213 SDNodeIterator operator++(int) { // Postincrement
2214 SDNodeIterator tmp = *this; ++*this; return tmp;
2217 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2218 static SDNodeIterator end (SDNode *N) {
2219 return SDNodeIterator(N, N->getNumOperands());
2222 unsigned getOperand() const { return Operand; }
2223 const SDNode *getNode() const { return Node; }
2226 template <> struct GraphTraits<SDNode*> {
2227 typedef SDNode NodeType;
2228 typedef SDNodeIterator ChildIteratorType;
2229 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2230 static inline ChildIteratorType child_begin(NodeType *N) {
2231 return SDNodeIterator::begin(N);
2233 static inline ChildIteratorType child_end(NodeType *N) {
2234 return SDNodeIterator::end(N);
2238 /// LargestSDNode - The largest SDNode class.
2240 typedef LoadSDNode LargestSDNode;
2242 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2245 typedef ConstantSDNode MostAlignedSDNode;
2248 /// isNormalLoad - Returns true if the specified node is a non-extending
2249 /// and unindexed load.
2250 inline bool isNormalLoad(const SDNode *N) {
2251 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2252 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2253 Ld->getAddressingMode() == ISD::UNINDEXED;
2256 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2258 inline bool isNON_EXTLoad(const SDNode *N) {
2259 return isa<LoadSDNode>(N) &&
2260 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2263 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2265 inline bool isEXTLoad(const SDNode *N) {
2266 return isa<LoadSDNode>(N) &&
2267 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2270 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2272 inline bool isSEXTLoad(const SDNode *N) {
2273 return isa<LoadSDNode>(N) &&
2274 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2277 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2279 inline bool isZEXTLoad(const SDNode *N) {
2280 return isa<LoadSDNode>(N) &&
2281 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2284 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2286 inline bool isUNINDEXEDLoad(const SDNode *N) {
2287 return isa<LoadSDNode>(N) &&
2288 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2291 /// isNormalStore - Returns true if the specified node is a non-truncating
2292 /// and unindexed store.
2293 inline bool isNormalStore(const SDNode *N) {
2294 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2295 return St && !St->isTruncatingStore() &&
2296 St->getAddressingMode() == ISD::UNINDEXED;
2299 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2301 inline bool isNON_TRUNCStore(const SDNode *N) {
2302 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2305 /// isTRUNCStore - Returns true if the specified node is a truncating
2307 inline bool isTRUNCStore(const SDNode *N) {
2308 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2311 /// isUNINDEXEDStore - Returns true if the specified node is an
2312 /// unindexed store.
2313 inline bool isUNINDEXEDStore(const SDNode *N) {
2314 return isa<StoreSDNode>(N) &&
2315 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2320 } // end llvm namespace