1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG. These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
22 #include "llvm/Value.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator"
26 #include "llvm/ADT/APFloat.h"
27 #include "llvm/ADT/APInt.h"
28 #include "llvm/CodeGen/ValueTypes.h"
29 #include "llvm/CodeGen/MachineMemOperand.h"
30 #include "llvm/Support/DataTypes.h"
37 class MachineBasicBlock;
38 class MachineConstantPoolValue;
40 template <typename T> struct DenseMapInfo;
41 template <typename T> struct simplify_type;
42 template <typename T> struct ilist_traits;
43 template<typename NodeTy, typename Traits> class iplist;
44 template<typename NodeTy> class ilist_iterator;
46 /// SDVTList - This represents a list of ValueType's that has been intern'd by
47 /// a SelectionDAG. Instances of this simple value class are returned by
48 /// SelectionDAG::getVTList(...).
51 const MVT::ValueType *VTs;
52 unsigned short NumVTs;
55 /// ISD namespace - This namespace contains an enum which represents all of the
56 /// SelectionDAG node types and value types.
60 //===--------------------------------------------------------------------===//
61 /// ISD::NodeType enum - This enum defines all of the operators valid in a
65 // DELETED_NODE - This is an illegal flag value that is used to catch
66 // errors. This opcode is not a legal opcode for any node.
69 // EntryToken - This is the marker used to indicate the start of the region.
72 // Token factor - This node takes multiple tokens as input and produces a
73 // single token result. This is used to represent the fact that the operand
74 // operators are independent of each other.
77 // AssertSext, AssertZext - These nodes record if a register contains a
78 // value that has already been zero or sign extended from a narrower type.
79 // These nodes take two operands. The first is the node that has already
80 // been extended, and the second is a value type node indicating the width
82 AssertSext, AssertZext,
84 // Various leaf nodes.
85 STRING, BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
87 GlobalAddress, GlobalTLSAddress, FrameIndex,
88 JumpTable, ConstantPool, ExternalSymbol,
90 // The address of the GOT
93 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
94 // llvm.returnaddress on the DAG. These nodes take one operand, the index
95 // of the frame or return address to return. An index of zero corresponds
96 // to the current function's frame or return address, an index of one to the
97 // parent's frame or return address, and so on.
98 FRAMEADDR, RETURNADDR,
100 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
101 // first (possible) on-stack argument. This is needed for correct stack
102 // adjustment during unwind.
103 FRAME_TO_ARGS_OFFSET,
105 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
106 // address of the exception block on entry to an landing pad block.
109 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
110 // the selection index of the exception thrown.
113 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
114 // 'eh_return' gcc dwarf builtin, which is used to return from
115 // exception. The general meaning is: adjust stack by OFFSET and pass
116 // execution to HANDLER. Many platform-related details also :)
119 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
120 // simplification of the constant.
124 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
125 // anything else with this node, and this is valid in the target-specific
126 // dag, turning into a GlobalAddress operand.
128 TargetGlobalTLSAddress,
132 TargetExternalSymbol,
134 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
135 /// This node represents a target intrinsic function with no side effects.
136 /// The first operand is the ID number of the intrinsic from the
137 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
138 /// node has returns the result of the intrinsic.
141 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
142 /// This node represents a target intrinsic function with side effects that
143 /// returns a result. The first operand is a chain pointer. The second is
144 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
145 /// operands to the intrinsic follow. The node has two results, the result
146 /// of the intrinsic and an output chain.
149 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
150 /// This node represents a target intrinsic function with side effects that
151 /// does not return a result. The first operand is a chain pointer. The
152 /// second is the ID number of the intrinsic from the llvm::Intrinsic
153 /// namespace. The operands to the intrinsic follow.
156 // CopyToReg - This node has three operands: a chain, a register number to
157 // set to this value, and a value.
160 // CopyFromReg - This node indicates that the input value is a virtual or
161 // physical register that is defined outside of the scope of this
162 // SelectionDAG. The register is available from the RegisterSDNode object.
165 // UNDEF - An undefined node
168 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
169 /// represents the formal arguments for a function. CC# is a Constant value
170 /// indicating the calling convention of the function, and ISVARARG is a
171 /// flag that indicates whether the function is varargs or not. This node
172 /// has one result value for each incoming argument, plus one for the output
173 /// chain. It must be custom legalized. See description of CALL node for
174 /// FLAG argument contents explanation.
178 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
179 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
180 /// This node represents a fully general function call, before the legalizer
181 /// runs. This has one result value for each argument / flag pair, plus
182 /// a chain result. It must be custom legalized. Flag argument indicates
183 /// misc. argument attributes. Currently:
185 /// Bit 1 - 'inreg' attribute
186 /// Bit 2 - 'sret' attribute
187 /// Bit 4 - 'byval' attribute
188 /// Bit 5 - 'nest' attribute
189 /// Bit 6-9 - alignment of byval structures
190 /// Bit 10-26 - size of byval structures
191 /// Bits 31:27 - argument ABI alignment in the first argument piece and
192 /// alignment '1' in other argument pieces.
195 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
196 // a Constant, which is required to be operand #1) half of the integer value
197 // specified as operand #0. This is only for use before legalization, for
198 // values that will be broken into multiple registers.
201 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
202 // two values of the same integer value type, this produces a value twice as
203 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
206 // MERGE_VALUES - This node takes multiple discrete operands and returns
207 // them all as its individual results. This nodes has exactly the same
208 // number of inputs and outputs, and is only valid before legalization.
209 // This node is useful for some pieces of the code generator that want to
210 // think about a single node with multiple results, not multiple nodes.
213 // Simple integer binary arithmetic operators.
214 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
216 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
217 // a signed/unsigned value of type i[2*N], and return the full value as
218 // two results, each of type iN.
219 SMUL_LOHI, UMUL_LOHI,
221 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
225 // CARRY_FALSE - This node is used when folding other nodes,
226 // like ADDC/SUBC, which indicate the carry result is always false.
229 // Carry-setting nodes for multiple precision addition and subtraction.
230 // These nodes take two operands of the same value type, and produce two
231 // results. The first result is the normal add or sub result, the second
232 // result is the carry flag result.
235 // Carry-using nodes for multiple precision addition and subtraction. These
236 // nodes take three operands: The first two are the normal lhs and rhs to
237 // the add or sub, and the third is the input carry flag. These nodes
238 // produce two results; the normal result of the add or sub, and the output
239 // carry flag. These nodes both read and write a carry flag to allow them
240 // to them to be chained together for add and sub of arbitrarily large
244 // Simple binary floating point operators.
245 FADD, FSUB, FMUL, FDIV, FREM,
247 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
248 // DAG node does not require that X and Y have the same type, just that they
249 // are both floating point. X and the result must have the same type.
250 // FCOPYSIGN(f32, f64) is allowed.
253 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
254 // value as an integer 0/1 value.
257 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
258 /// with the specified, possibly variable, elements. The number of elements
259 /// is required to be a power of two.
262 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
263 /// at IDX replaced with VAL. If the type of VAL is larger than the vector
264 /// element type then VAL is truncated before replacement.
267 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
268 /// identified by the (potentially variable) element number IDX.
271 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
272 /// vector type with the same length and element type, this produces a
273 /// concatenated vector result value, with length equal to the sum of the
274 /// lengths of the input vectors.
277 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
278 /// vector value) starting with the (potentially variable) element number
279 /// IDX, which must be a multiple of the result vector length.
282 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
283 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
284 /// (maybe of an illegal datatype) or undef that indicate which value each
285 /// result element will get. The elements of VEC1/VEC2 are enumerated in
286 /// order. This is quite similar to the Altivec 'vperm' instruction, except
287 /// that the indices must be constants and are in terms of the element size
288 /// of VEC1/VEC2, not in terms of bytes.
291 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
292 /// scalar value into element 0 of the resultant vector type. The top
293 /// elements 1 to N-1 of the N-element vector are undefined.
296 // EXTRACT_SUBREG - This node is used to extract a sub-register value.
297 // This node takes a superreg and a constant sub-register index as operands.
298 // Note sub-register indices must be increasing. That is, if the
299 // sub-register index of a 8-bit sub-register is N, then the index for a
300 // 16-bit sub-register must be at least N+1.
303 // INSERT_SUBREG - This node is used to insert a sub-register value.
304 // This node takes a superreg, a subreg value, and a constant sub-register
305 // index as operands.
308 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
309 // an unsigned/signed value of type i[2*N], then return the top part.
312 // Bitwise operators - logical and, logical or, logical xor, shift left,
313 // shift right algebraic (shift in sign bits), shift right logical (shift in
314 // zeroes), rotate left, rotate right, and byteswap.
315 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
317 // Counting operators
320 // Select(COND, TRUEVAL, FALSEVAL)
323 // Select with condition operator - This selects between a true value and
324 // a false value (ops #2 and #3) based on the boolean result of comparing
325 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
326 // condition code in op #4, a CondCodeSDNode.
329 // SetCC operator - This evaluates to a boolean (i1) true value if the
330 // condition is true. The operands to this are the left and right operands
331 // to compare (ops #0, and #1) and the condition code to compare them with
332 // (op #2) as a CondCodeSDNode.
335 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
336 // integer shift operations, just like ADD/SUB_PARTS. The operation
338 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
339 SHL_PARTS, SRA_PARTS, SRL_PARTS,
341 // Conversion operators. These are all single input single output
342 // operations. For all of these, the result type must be strictly
343 // wider or narrower (depending on the operation) than the source
346 // SIGN_EXTEND - Used for integer types, replicating the sign bit
350 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
353 // ANY_EXTEND - Used for integer types. The high bits are undefined.
356 // TRUNCATE - Completely drop the high bits.
359 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
360 // depends on the first letter) to floating point.
364 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
365 // sign extend a small value in a large integer register (e.g. sign
366 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
367 // with the 7th bit). The size of the smaller type is indicated by the 1th
368 // operand, a ValueType node.
371 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
376 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
377 /// down to the precision of the destination VT. TRUNC is a flag, which is
378 /// always an integer that is zero or one. If TRUNC is 0, this is a
379 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
382 /// The TRUNC = 1 case is used in cases where we know that the value will
383 /// not be modified by the node, because Y is not using any of the extra
384 /// precision of source type. This allows certain transformations like
385 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
386 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
389 // FLT_ROUNDS_ - Returns current rounding mode:
392 // 1 Round to nearest
397 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
398 /// rounds it to a floating point value. It then promotes it and returns it
399 /// in a register of the same size. This operation effectively just
400 /// discards excess precision. The type to round down to is specified by
401 /// the VT operand, a VTSDNode.
404 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
407 // BIT_CONVERT - Theis operator converts between integer and FP values, as
408 // if one was stored to memory as integer and the other was loaded from the
409 // same address (or equivalently for vector format conversions, etc). The
410 // source and result are required to have the same bit size (e.g.
411 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
412 // conversions, but that is a noop, deleted by getNode().
415 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
416 // negation, absolute value, square root, sine and cosine, powi, and pow
418 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
420 // LOAD and STORE have token chains as their first operand, then the same
421 // operands as an LLVM load/store instruction, then an offset node that
422 // is added / subtracted from the base pointer to form the address (for
423 // indexed memory ops).
426 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
427 // to a specified boundary. This node always has two return values: a new
428 // stack pointer value and a chain. The first operand is the token chain,
429 // the second is the number of bytes to allocate, and the third is the
430 // alignment boundary. The size is guaranteed to be a multiple of the stack
431 // alignment, and the alignment is guaranteed to be bigger than the stack
432 // alignment (if required) or 0 to get standard stack alignment.
435 // Control flow instructions. These all have token chains.
437 // BR - Unconditional branch. The first operand is the chain
438 // operand, the second is the MBB to branch to.
441 // BRIND - Indirect branch. The first operand is the chain, the second
442 // is the value to branch to, which must be of the same type as the target's
446 // BR_JT - Jumptable branch. The first operand is the chain, the second
447 // is the jumptable index, the last one is the jumptable entry index.
450 // BRCOND - Conditional branch. The first operand is the chain,
451 // the second is the condition, the third is the block to branch
452 // to if the condition is true.
455 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
456 // that the condition is represented as condition code, and two nodes to
457 // compare, rather than as a combined SetCC node. The operands in order are
458 // chain, cc, lhs, rhs, block to branch to if condition is true.
461 // RET - Return from function. The first operand is the chain,
462 // and any subsequent operands are pairs of return value and return value
463 // signness for the function. This operation can have variable number of
467 // INLINEASM - Represents an inline asm block. This node always has two
468 // return values: a chain and a flag result. The inputs are as follows:
469 // Operand #0 : Input chain.
470 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
471 // Operand #2n+2: A RegisterNode.
472 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
473 // Operand #last: Optional, an incoming flag.
476 // LABEL - Represents a label in mid basic block used to track
477 // locations needed for debug and exception handling tables. This node
479 // Operand #0 : input chain.
480 // Operand #1 : module unique number use to identify the label.
481 // Operand #2 : 0 indicates a debug label (e.g. stoppoint), 1 indicates
482 // a EH label, 2 indicates unknown label type.
485 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
486 // local variable declarations for debugging information. First operand is
487 // a chain, while the next two operands are first two arguments (address
488 // and variable) of a llvm.dbg.declare instruction.
491 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
492 // value, the same type as the pointer type for the system, and an output
496 // STACKRESTORE has two operands, an input chain and a pointer to restore to
497 // it returns an output chain.
500 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
501 // a call sequence, and carry arbitrary information that target might want
502 // to know. The first operand is a chain, the rest are specified by the
503 // target and not touched by the DAG optimizers.
504 // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
505 CALLSEQ_START, // Beginning of a call sequence
506 CALLSEQ_END, // End of a call sequence
508 // VAARG - VAARG has three operands: an input chain, a pointer, and a
509 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
512 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
513 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
517 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
518 // pointer, and a SRCVALUE.
521 // SRCVALUE - This is a node type that holds a Value* that is used to
522 // make reference to a value in the LLVM IR.
525 // MEMOPERAND - This is a node that contains a MachineMemOperand which
526 // records information about a memory reference. This is used to make
527 // AliasAnalysis queries from the backend.
530 // PCMARKER - This corresponds to the pcmarker intrinsic.
533 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
534 // The only operand is a chain and a value and a chain are produced. The
535 // value is the contents of the architecture specific cycle counter like
536 // register (or other high accuracy low latency clock source)
539 // HANDLENODE node - Used as a handle for various purposes.
542 // LOCATION - This node is used to represent a source location for debug
543 // info. It takes token chain as input, then a line number, then a column
544 // number, then a filename, then a working dir. It produces a token chain
548 // DEBUG_LOC - This node is used to represent source line information
549 // embedded in the code. It takes a token chain as input, then a line
550 // number, then a column then a file id (provided by MachineModuleInfo.) It
551 // produces a token chain as output.
554 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
555 // It takes as input a token chain, the pointer to the trampoline,
556 // the pointer to the nested function, the pointer to pass for the
557 // 'nest' parameter, a SRCVALUE for the trampoline and another for
558 // the nested function (allowing targets to access the original
559 // Function*). It produces the result of the intrinsic and a token
563 // TRAP - Trapping instruction
566 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
567 // their first operand. The other operands are the address to prefetch,
568 // read / write specifier, and locality specifier.
571 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
572 // store-store, device)
573 // This corresponds to the memory.barrier intrinsic.
574 // it takes an input chain, 4 operands to specify the type of barrier, an
575 // operand specifying if the barrier applies to device and uncached memory
576 // and produces an output chain.
579 // Val, OUTCHAIN = ATOMIC_LCS(INCHAIN, ptr, cmp, swap)
580 // this corresponds to the atomic.lcs intrinsic.
581 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
582 // the return is always the original value in *ptr
585 // Val, OUTCHAIN = ATOMIC_LAS(INCHAIN, ptr, amt)
586 // this corresponds to the atomic.las intrinsic.
587 // *ptr + amt is stored to *ptr atomically.
588 // the return is always the original value in *ptr
591 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
592 // this corresponds to the atomic.swap intrinsic.
593 // amt is stored to *ptr atomically.
594 // the return is always the original value in *ptr
597 // Val, OUTCHAIN = ATOMIC_LSS(INCHAIN, ptr, amt)
598 // this corresponds to the atomic.lss intrinsic.
599 // *ptr - amt is stored to *ptr atomically.
600 // the return is always the original value in *ptr
603 // Val, OUTCHAIN = ATOMIC_L[OpName]S(INCHAIN, ptr, amt)
604 // this corresponds to the atomic.[OpName] intrinsic.
605 // op(*ptr, amt) is stored to *ptr atomically.
606 // the return is always the original value in *ptr
615 // BUILTIN_OP_END - This must be the last enum value in this list.
621 /// isBuildVectorAllOnes - Return true if the specified node is a
622 /// BUILD_VECTOR where all of the elements are ~0 or undef.
623 bool isBuildVectorAllOnes(const SDNode *N);
625 /// isBuildVectorAllZeros - Return true if the specified node is a
626 /// BUILD_VECTOR where all of the elements are 0 or undef.
627 bool isBuildVectorAllZeros(const SDNode *N);
629 /// isScalarToVector - Return true if the specified node is a
630 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
631 /// element is not an undef.
632 bool isScalarToVector(const SDNode *N);
634 /// isDebugLabel - Return true if the specified node represents a debug
635 /// label (i.e. ISD::LABEL or TargetInstrInfo::LABEL node and third operand
637 bool isDebugLabel(const SDNode *N);
639 //===--------------------------------------------------------------------===//
640 /// MemIndexedMode enum - This enum defines the load / store indexed
641 /// addressing modes.
643 /// UNINDEXED "Normal" load / store. The effective address is already
644 /// computed and is available in the base pointer. The offset
645 /// operand is always undefined. In addition to producing a
646 /// chain, an unindexed load produces one value (result of the
647 /// load); an unindexed store does not produce a value.
649 /// PRE_INC Similar to the unindexed mode where the effective address is
650 /// PRE_DEC the value of the base pointer add / subtract the offset.
651 /// It considers the computation as being folded into the load /
652 /// store operation (i.e. the load / store does the address
653 /// computation as well as performing the memory transaction).
654 /// The base operand is always undefined. In addition to
655 /// producing a chain, pre-indexed load produces two values
656 /// (result of the load and the result of the address
657 /// computation); a pre-indexed store produces one value (result
658 /// of the address computation).
660 /// POST_INC The effective address is the value of the base pointer. The
661 /// POST_DEC value of the offset operand is then added to / subtracted
662 /// from the base after memory transaction. In addition to
663 /// producing a chain, post-indexed load produces two values
664 /// (the result of the load and the result of the base +/- offset
665 /// computation); a post-indexed store produces one value (the
666 /// the result of the base +/- offset computation).
668 enum MemIndexedMode {
677 //===--------------------------------------------------------------------===//
678 /// LoadExtType enum - This enum defines the three variants of LOADEXT
679 /// (load with extension).
681 /// SEXTLOAD loads the integer operand and sign extends it to a larger
682 /// integer result type.
683 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
684 /// integer result type.
685 /// EXTLOAD is used for three things: floating point extending loads,
686 /// integer extending loads [the top bits are undefined], and vector
687 /// extending loads [load into low elt].
697 //===--------------------------------------------------------------------===//
698 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
699 /// below work out, when considering SETFALSE (something that never exists
700 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
701 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
702 /// to. If the "N" column is 1, the result of the comparison is undefined if
703 /// the input is a NAN.
705 /// All of these (except for the 'always folded ops') should be handled for
706 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
707 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
709 /// Note that these are laid out in a specific order to allow bit-twiddling
710 /// to transform conditions.
712 // Opcode N U L G E Intuitive operation
713 SETFALSE, // 0 0 0 0 Always false (always folded)
714 SETOEQ, // 0 0 0 1 True if ordered and equal
715 SETOGT, // 0 0 1 0 True if ordered and greater than
716 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
717 SETOLT, // 0 1 0 0 True if ordered and less than
718 SETOLE, // 0 1 0 1 True if ordered and less than or equal
719 SETONE, // 0 1 1 0 True if ordered and operands are unequal
720 SETO, // 0 1 1 1 True if ordered (no nans)
721 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
722 SETUEQ, // 1 0 0 1 True if unordered or equal
723 SETUGT, // 1 0 1 0 True if unordered or greater than
724 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
725 SETULT, // 1 1 0 0 True if unordered or less than
726 SETULE, // 1 1 0 1 True if unordered, less than, or equal
727 SETUNE, // 1 1 1 0 True if unordered or not equal
728 SETTRUE, // 1 1 1 1 Always true (always folded)
729 // Don't care operations: undefined if the input is a nan.
730 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
731 SETEQ, // 1 X 0 0 1 True if equal
732 SETGT, // 1 X 0 1 0 True if greater than
733 SETGE, // 1 X 0 1 1 True if greater than or equal
734 SETLT, // 1 X 1 0 0 True if less than
735 SETLE, // 1 X 1 0 1 True if less than or equal
736 SETNE, // 1 X 1 1 0 True if not equal
737 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
739 SETCC_INVALID // Marker value.
742 /// isSignedIntSetCC - Return true if this is a setcc instruction that
743 /// performs a signed comparison when used with integer operands.
744 inline bool isSignedIntSetCC(CondCode Code) {
745 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
748 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
749 /// performs an unsigned comparison when used with integer operands.
750 inline bool isUnsignedIntSetCC(CondCode Code) {
751 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
754 /// isTrueWhenEqual - Return true if the specified condition returns true if
755 /// the two operands to the condition are equal. Note that if one of the two
756 /// operands is a NaN, this value is meaningless.
757 inline bool isTrueWhenEqual(CondCode Cond) {
758 return ((int)Cond & 1) != 0;
761 /// getUnorderedFlavor - This function returns 0 if the condition is always
762 /// false if an operand is a NaN, 1 if the condition is always true if the
763 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
765 inline unsigned getUnorderedFlavor(CondCode Cond) {
766 return ((int)Cond >> 3) & 3;
769 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
770 /// 'op' is a valid SetCC operation.
771 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
773 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
774 /// when given the operation for (X op Y).
775 CondCode getSetCCSwappedOperands(CondCode Operation);
777 /// getSetCCOrOperation - Return the result of a logical OR between different
778 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
779 /// function returns SETCC_INVALID if it is not possible to represent the
780 /// resultant comparison.
781 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
783 /// getSetCCAndOperation - Return the result of a logical AND between
784 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
785 /// function returns SETCC_INVALID if it is not possible to represent the
786 /// resultant comparison.
787 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
788 } // end llvm::ISD namespace
791 //===----------------------------------------------------------------------===//
792 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
793 /// values as the result of a computation. Many nodes return multiple values,
794 /// from loads (which define a token and a return value) to ADDC (which returns
795 /// a result and a carry value), to calls (which may return an arbitrary number
798 /// As such, each use of a SelectionDAG computation must indicate the node that
799 /// computes it as well as which return value to use from that node. This pair
800 /// of information is represented with the SDOperand value type.
804 SDNode *Val; // The node defining the value we are using.
805 unsigned ResNo; // Which return value of the node we are using.
807 SDOperand() : Val(0), ResNo(0) {}
808 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
810 bool operator==(const SDOperand &O) const {
811 return Val == O.Val && ResNo == O.ResNo;
813 bool operator!=(const SDOperand &O) const {
814 return !operator==(O);
816 bool operator<(const SDOperand &O) const {
817 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
820 SDOperand getValue(unsigned R) const {
821 return SDOperand(Val, R);
824 // isOperandOf - Return true if this node is an operand of N.
825 bool isOperandOf(SDNode *N) const;
827 /// getValueType - Return the ValueType of the referenced return value.
829 inline MVT::ValueType getValueType() const;
831 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType()).
833 unsigned getValueSizeInBits() const {
834 return MVT::getSizeInBits(getValueType());
837 // Forwarding methods - These forward to the corresponding methods in SDNode.
838 inline unsigned getOpcode() const;
839 inline unsigned getNumOperands() const;
840 inline const SDOperand &getOperand(unsigned i) const;
841 inline uint64_t getConstantOperandVal(unsigned i) const;
842 inline bool isTargetOpcode() const;
843 inline unsigned getTargetOpcode() const;
846 /// reachesChainWithoutSideEffects - Return true if this operand (which must
847 /// be a chain) reaches the specified operand without crossing any
848 /// side-effecting instructions. In practice, this looks through token
849 /// factors and non-volatile loads. In order to remain efficient, this only
850 /// looks a couple of nodes in, it does not do an exhaustive search.
851 bool reachesChainWithoutSideEffects(SDOperand Dest,
852 unsigned Depth = 2) const;
854 /// hasOneUse - Return true if there is exactly one operation using this
855 /// result value of the defining operator.
856 inline bool hasOneUse() const;
858 /// use_empty - Return true if there are no operations using this
859 /// result value of the defining operator.
860 inline bool use_empty() const;
864 template<> struct DenseMapInfo<SDOperand> {
865 static inline SDOperand getEmptyKey() {
866 return SDOperand((SDNode*)-1, -1U);
868 static inline SDOperand getTombstoneKey() {
869 return SDOperand((SDNode*)-1, 0);
871 static unsigned getHashValue(const SDOperand &Val) {
872 return ((unsigned)((uintptr_t)Val.Val >> 4) ^
873 (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo;
875 static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
878 static bool isPod() { return true; }
881 /// simplify_type specializations - Allow casting operators to work directly on
882 /// SDOperands as if they were SDNode*'s.
883 template<> struct simplify_type<SDOperand> {
884 typedef SDNode* SimpleType;
885 static SimpleType getSimplifiedValue(const SDOperand &Val) {
886 return static_cast<SimpleType>(Val.Val);
889 template<> struct simplify_type<const SDOperand> {
890 typedef SDNode* SimpleType;
891 static SimpleType getSimplifiedValue(const SDOperand &Val) {
892 return static_cast<SimpleType>(Val.Val);
896 /// SDUse - Represents a use of the SDNode referred by
900 /// User - Parent node of this operand.
902 /// Prev, next - Pointers to the uses list of the SDNode referred by
907 SDUse(): Operand(), User(NULL), Prev(NULL), Next(NULL) {}
909 SDUse(SDNode *val, unsigned resno) :
910 Operand(val,resno), User(NULL), Prev(NULL), Next(NULL) {}
912 SDUse& operator= (const SDOperand& Op) {
919 SDUse& operator= (const SDUse& Op) {
926 SDUse * getNext() { return Next; }
928 SDNode *getUser() { return User; }
930 void setUser(SDNode *p) { User = p; }
932 operator SDOperand() const { return Operand; }
934 const SDOperand& getSDOperand() const { return Operand; }
936 SDNode* &getVal () { return Operand.Val; }
938 bool operator==(const SDOperand &O) const {
942 bool operator!=(const SDOperand &O) const {
943 return !(Operand == O);
946 bool operator<(const SDOperand &O) const {
951 void addToList(SDUse **List) {
953 if (Next) Next->Prev = &Next;
958 void removeFromList() {
960 if (Next) Next->Prev = Prev;
965 /// simplify_type specializations - Allow casting operators to work directly on
966 /// SDOperands as if they were SDNode*'s.
967 template<> struct simplify_type<SDUse> {
968 typedef SDNode* SimpleType;
969 static SimpleType getSimplifiedValue(const SDUse &Val) {
970 return static_cast<SimpleType>(Val.getSDOperand().Val);
973 template<> struct simplify_type<const SDUse> {
974 typedef SDNode* SimpleType;
975 static SimpleType getSimplifiedValue(const SDUse &Val) {
976 return static_cast<SimpleType>(Val.getSDOperand().Val);
981 /// SDOperandPtr - A helper SDOperand pointer class, that can handle
982 /// arrays of SDUse and arrays of SDOperand objects. This is required
983 /// in many places inside the SelectionDAG.
986 const SDOperand *ptr; // The pointer to the SDOperand object
987 int object_size; // The size of the object containg the SDOperand
989 SDOperandPtr() : ptr(0), object_size(0) {}
991 SDOperandPtr(SDUse * use_ptr) {
992 ptr = &use_ptr->getSDOperand();
993 object_size = (int)sizeof(SDUse);
996 SDOperandPtr(const SDOperand * op_ptr) {
998 object_size = (int)sizeof(SDOperand);
1001 const SDOperand operator *() { return *ptr; }
1002 const SDOperand *operator ->() { return ptr; }
1003 SDOperandPtr operator ++ () {
1004 ptr = (SDOperand*)((char *)ptr + object_size);
1008 SDOperandPtr operator ++ (int) {
1009 SDOperandPtr tmp = *this;
1010 ptr = (SDOperand*)((char *)ptr + object_size);
1014 SDOperand operator[] (int idx) const {
1015 return *(SDOperand*)((char*) ptr + object_size * idx);
1019 /// SDNode - Represents one node in the SelectionDAG.
1021 class SDNode : public FoldingSetNode {
1023 /// NodeType - The operation that this node performs.
1025 unsigned short NodeType;
1027 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
1028 /// then they will be delete[]'d when the node is destroyed.
1029 bool OperandsNeedDelete : 1;
1031 /// NodeId - Unique id per SDNode in the DAG.
1034 /// OperandList - The values that are used by this operation.
1038 /// ValueList - The types of the values this node defines. SDNode's may
1039 /// define multiple values simultaneously.
1040 const MVT::ValueType *ValueList;
1042 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1043 unsigned short NumOperands, NumValues;
1045 /// Prev/Next pointers - These pointers form the linked list of of the
1046 /// AllNodes list in the current DAG.
1047 SDNode *Prev, *Next;
1048 friend struct ilist_traits<SDNode>;
1050 /// UsesSize - The size of the uses list.
1053 /// Uses - List of uses for this SDNode.
1056 /// addUse - add SDUse to the list of uses.
1057 void addUse(SDUse &U) { U.addToList(&Uses); }
1059 // Out-of-line virtual method to give class a home.
1060 virtual void ANCHOR();
1063 assert(NumOperands == 0 && "Operand list not cleared before deletion");
1064 NodeType = ISD::DELETED_NODE;
1067 //===--------------------------------------------------------------------===//
1070 unsigned getOpcode() const { return NodeType; }
1071 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1072 unsigned getTargetOpcode() const {
1073 assert(isTargetOpcode() && "Not a target opcode!");
1074 return NodeType - ISD::BUILTIN_OP_END;
1077 size_t use_size() const { return UsesSize; }
1078 bool use_empty() const { return Uses == NULL; }
1079 bool hasOneUse() const { return use_size() == 1; }
1081 /// getNodeId - Return the unique node id.
1083 int getNodeId() const { return NodeId; }
1085 /// setNodeId - Set unique node id.
1086 void setNodeId(int Id) { NodeId = Id; }
1088 /// use_iterator - This class provides iterator support for SDUse
1089 /// operands that use a specific SDNode.
1091 : public forward_iterator<SDUse, ptrdiff_t> {
1093 explicit use_iterator(SDUse *op) : Op(op) {
1095 friend class SDNode;
1097 typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
1098 typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1100 use_iterator(const use_iterator &I) : Op(I.Op) {}
1101 use_iterator() : Op(0) {}
1103 bool operator==(const use_iterator &x) const {
1106 bool operator!=(const use_iterator &x) const {
1107 return !operator==(x);
1110 /// atEnd - return true if this iterator is at the end of uses list.
1111 bool atEnd() const { return Op == 0; }
1113 // Iterator traversal: forward iteration only.
1114 use_iterator &operator++() { // Preincrement
1115 assert(Op && "Cannot increment end iterator!");
1120 use_iterator operator++(int) { // Postincrement
1121 use_iterator tmp = *this; ++*this; return tmp;
1125 /// getOperandNum - Retrive a number of a current operand.
1126 unsigned getOperandNum() const {
1127 assert(Op && "Cannot dereference end iterator!");
1128 return (unsigned)(Op - Op->getUser()->OperandList);
1131 /// Retrieve a reference to the current operand.
1132 SDUse &operator*() const {
1133 assert(Op && "Cannot dereference end iterator!");
1137 /// Retrieve a pointer to the current operand.
1138 SDUse *operator->() const {
1139 assert(Op && "Cannot dereference end iterator!");
1144 /// use_begin/use_end - Provide iteration support to walk over all uses
1147 use_iterator use_begin(SDNode *node) const {
1148 return use_iterator(node->Uses);
1151 use_iterator use_begin() const {
1152 return use_iterator(Uses);
1155 static use_iterator use_end() { return use_iterator(0); }
1158 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1159 /// indicated value. This method ignores uses of other values defined by this
1161 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1163 /// hasAnyUseOfValue - Return true if there are any use of the indicated
1164 /// value. This method ignores uses of other values defined by this operation.
1165 bool hasAnyUseOfValue(unsigned Value) const;
1167 /// isOnlyUseOf - Return true if this node is the only use of N.
1169 bool isOnlyUseOf(SDNode *N) const;
1171 /// isOperandOf - Return true if this node is an operand of N.
1173 bool isOperandOf(SDNode *N) const;
1175 /// isPredecessorOf - Return true if this node is a predecessor of N. This
1176 /// node is either an operand of N or it can be reached by recursively
1177 /// traversing up the operands.
1178 /// NOTE: this is an expensive method. Use it carefully.
1179 bool isPredecessorOf(SDNode *N) const;
1181 /// getNumOperands - Return the number of values used by this operation.
1183 unsigned getNumOperands() const { return NumOperands; }
1185 /// getConstantOperandVal - Helper method returns the integer value of a
1186 /// ConstantSDNode operand.
1187 uint64_t getConstantOperandVal(unsigned Num) const;
1189 const SDOperand &getOperand(unsigned Num) const {
1190 assert(Num < NumOperands && "Invalid child # of SDNode!");
1191 return OperandList[Num].getSDOperand();
1194 typedef SDUse* op_iterator;
1195 op_iterator op_begin() const { return OperandList; }
1196 op_iterator op_end() const { return OperandList+NumOperands; }
1199 SDVTList getVTList() const {
1200 SDVTList X = { ValueList, NumValues };
1204 /// getNumValues - Return the number of values defined/returned by this
1207 unsigned getNumValues() const { return NumValues; }
1209 /// getValueType - Return the type of a specified result.
1211 MVT::ValueType getValueType(unsigned ResNo) const {
1212 assert(ResNo < NumValues && "Illegal result number!");
1213 return ValueList[ResNo];
1216 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1218 unsigned getValueSizeInBits(unsigned ResNo) const {
1219 return MVT::getSizeInBits(getValueType(ResNo));
1222 typedef const MVT::ValueType* value_iterator;
1223 value_iterator value_begin() const { return ValueList; }
1224 value_iterator value_end() const { return ValueList+NumValues; }
1226 /// getOperationName - Return the opcode of this operation for printing.
1228 std::string getOperationName(const SelectionDAG *G = 0) const;
1229 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1231 void dump(const SelectionDAG *G) const;
1233 static bool classof(const SDNode *) { return true; }
1235 /// Profile - Gather unique data for the node.
1237 void Profile(FoldingSetNodeID &ID);
1240 friend class SelectionDAG;
1242 /// getValueTypeList - Return a pointer to the specified value type.
1244 static const MVT::ValueType *getValueTypeList(MVT::ValueType VT);
1245 static SDVTList getSDVTList(MVT::ValueType VT) {
1246 SDVTList Ret = { getValueTypeList(VT), 1 };
1250 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
1251 : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
1252 OperandsNeedDelete = true;
1253 NumOperands = NumOps;
1254 OperandList = NumOps ? new SDUse[NumOperands] : 0;
1256 for (unsigned i = 0; i != NumOps; ++i) {
1257 OperandList[i] = Ops[i];
1258 OperandList[i].setUser(this);
1259 Ops[i].Val->addUse(OperandList[i]);
1260 ++Ops[i].Val->UsesSize;
1263 ValueList = VTs.VTs;
1264 NumValues = VTs.NumVTs;
1268 SDNode(unsigned Opc, SDVTList VTs, SDOperandPtr Ops, unsigned NumOps)
1269 : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
1270 OperandsNeedDelete = true;
1271 NumOperands = NumOps;
1272 OperandList = NumOps ? new SDUse[NumOperands] : 0;
1274 for (unsigned i = 0; i != NumOps; ++i) {
1275 OperandList[i] = Ops[i];
1276 OperandList[i].setUser(this);
1277 Ops[i].Val->addUse(OperandList[i]);
1278 ++Ops[i].Val->UsesSize;
1281 ValueList = VTs.VTs;
1282 NumValues = VTs.NumVTs;
1286 SDNode(unsigned Opc, SDVTList VTs)
1287 : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
1288 OperandsNeedDelete = false; // Operands set with InitOperands.
1291 ValueList = VTs.VTs;
1292 NumValues = VTs.NumVTs;
1296 /// InitOperands - Initialize the operands list of this node with the
1297 /// specified values, which are part of the node (thus they don't need to be
1298 /// copied in or allocated).
1299 void InitOperands(SDUse *Ops, unsigned NumOps) {
1300 assert(OperandList == 0 && "Operands already set!");
1301 NumOperands = NumOps;
1306 for (unsigned i = 0; i != NumOps; ++i) {
1307 OperandList[i].setUser(this);
1308 Ops[i].getVal()->addUse(OperandList[i]);
1309 ++Ops[i].getVal()->UsesSize;
1313 /// MorphNodeTo - This frees the operands of the current node, resets the
1314 /// opcode, types, and operands to the specified value. This should only be
1315 /// used by the SelectionDAG class.
1316 void MorphNodeTo(unsigned Opc, SDVTList L,
1317 SDOperandPtr Ops, unsigned NumOps);
1319 void addUser(unsigned i, SDNode *User) {
1320 assert(User->OperandList[i].getUser() && "Node without parent");
1321 addUse(User->OperandList[i]);
1325 void removeUser(unsigned i, SDNode *User) {
1326 assert(User->OperandList[i].getUser() && "Node without parent");
1327 SDUse &Op = User->OperandList[i];
1328 Op.removeFromList();
1334 // Define inline functions from the SDOperand class.
1336 inline unsigned SDOperand::getOpcode() const {
1337 return Val->getOpcode();
1339 inline MVT::ValueType SDOperand::getValueType() const {
1340 return Val->getValueType(ResNo);
1342 inline unsigned SDOperand::getNumOperands() const {
1343 return Val->getNumOperands();
1345 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1346 return Val->getOperand(i);
1348 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1349 return Val->getConstantOperandVal(i);
1351 inline bool SDOperand::isTargetOpcode() const {
1352 return Val->isTargetOpcode();
1354 inline unsigned SDOperand::getTargetOpcode() const {
1355 return Val->getTargetOpcode();
1357 inline bool SDOperand::hasOneUse() const {
1358 return Val->hasNUsesOfValue(1, ResNo);
1360 inline bool SDOperand::use_empty() const {
1361 return !Val->hasAnyUseOfValue(ResNo);
1364 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1365 /// to allow co-allocation of node operands with the node itself.
1366 class UnarySDNode : public SDNode {
1367 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1370 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1371 : SDNode(Opc, VTs) {
1373 InitOperands(&Op, 1);
1377 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1378 /// to allow co-allocation of node operands with the node itself.
1379 class BinarySDNode : public SDNode {
1380 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1383 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1384 : SDNode(Opc, VTs) {
1387 InitOperands(Ops, 2);
1391 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1392 /// to allow co-allocation of node operands with the node itself.
1393 class TernarySDNode : public SDNode {
1394 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1397 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1399 : SDNode(Opc, VTs) {
1403 InitOperands(Ops, 3);
1408 /// HandleSDNode - This class is used to form a handle around another node that
1409 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1410 /// operand. This node should be directly created by end-users and not added to
1411 /// the AllNodes list.
1412 class HandleSDNode : public SDNode {
1413 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1416 // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1419 explicit __attribute__((__noinline__)) HandleSDNode(SDOperand X)
1421 explicit HandleSDNode(SDOperand X)
1423 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
1425 InitOperands(&Op, 1);
1428 SDUse getValue() const { return Op; }
1431 class AtomicSDNode : public SDNode {
1432 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1434 MVT::ValueType OrigVT;
1436 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1437 SDOperand Cmp, SDOperand Swp, MVT::ValueType VT)
1438 : SDNode(Opc, VTL) {
1443 InitOperands(Ops, 4);
1446 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1447 SDOperand Val, MVT::ValueType VT)
1448 : SDNode(Opc, VTL) {
1452 InitOperands(Ops, 3);
1455 MVT::ValueType getVT() const { return OrigVT; }
1456 bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_LCS; }
1459 class StringSDNode : public SDNode {
1461 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1463 friend class SelectionDAG;
1464 explicit StringSDNode(const std::string &val)
1465 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1468 const std::string &getValue() const { return Value; }
1469 static bool classof(const StringSDNode *) { return true; }
1470 static bool classof(const SDNode *N) {
1471 return N->getOpcode() == ISD::STRING;
1475 class ConstantSDNode : public SDNode {
1477 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1479 friend class SelectionDAG;
1480 ConstantSDNode(bool isTarget, const APInt &val, MVT::ValueType VT)
1481 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1486 const APInt &getAPIntValue() const { return Value; }
1487 uint64_t getValue() const { return Value.getZExtValue(); }
1489 int64_t getSignExtended() const {
1490 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1491 return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1494 bool isNullValue() const { return Value == 0; }
1495 bool isAllOnesValue() const {
1496 return Value == MVT::getIntVTBitMask(getValueType(0));
1499 static bool classof(const ConstantSDNode *) { return true; }
1500 static bool classof(const SDNode *N) {
1501 return N->getOpcode() == ISD::Constant ||
1502 N->getOpcode() == ISD::TargetConstant;
1506 class ConstantFPSDNode : public SDNode {
1508 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1510 friend class SelectionDAG;
1511 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT)
1512 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1513 getSDVTList(VT)), Value(val) {
1517 const APFloat& getValueAPF() const { return Value; }
1519 /// isExactlyValue - We don't rely on operator== working on double values, as
1520 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1521 /// As such, this method can be used to do an exact bit-for-bit comparison of
1522 /// two floating point values.
1524 /// We leave the version with the double argument here because it's just so
1525 /// convenient to write "2.0" and the like. Without this function we'd
1526 /// have to duplicate its logic everywhere it's called.
1527 bool isExactlyValue(double V) const {
1528 // convert is not supported on this type
1529 if (&Value.getSemantics() == &APFloat::PPCDoubleDouble)
1532 Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1533 return isExactlyValue(Tmp);
1535 bool isExactlyValue(const APFloat& V) const;
1537 bool isValueValidForType(MVT::ValueType VT, const APFloat& Val);
1539 static bool classof(const ConstantFPSDNode *) { return true; }
1540 static bool classof(const SDNode *N) {
1541 return N->getOpcode() == ISD::ConstantFP ||
1542 N->getOpcode() == ISD::TargetConstantFP;
1546 class GlobalAddressSDNode : public SDNode {
1547 GlobalValue *TheGlobal;
1549 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1551 friend class SelectionDAG;
1552 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1556 GlobalValue *getGlobal() const { return TheGlobal; }
1557 int getOffset() const { return Offset; }
1559 static bool classof(const GlobalAddressSDNode *) { return true; }
1560 static bool classof(const SDNode *N) {
1561 return N->getOpcode() == ISD::GlobalAddress ||
1562 N->getOpcode() == ISD::TargetGlobalAddress ||
1563 N->getOpcode() == ISD::GlobalTLSAddress ||
1564 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1568 class FrameIndexSDNode : public SDNode {
1570 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1572 friend class SelectionDAG;
1573 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1574 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1579 int getIndex() const { return FI; }
1581 static bool classof(const FrameIndexSDNode *) { return true; }
1582 static bool classof(const SDNode *N) {
1583 return N->getOpcode() == ISD::FrameIndex ||
1584 N->getOpcode() == ISD::TargetFrameIndex;
1588 class JumpTableSDNode : public SDNode {
1590 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1592 friend class SelectionDAG;
1593 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1594 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1599 int getIndex() const { return JTI; }
1601 static bool classof(const JumpTableSDNode *) { return true; }
1602 static bool classof(const SDNode *N) {
1603 return N->getOpcode() == ISD::JumpTable ||
1604 N->getOpcode() == ISD::TargetJumpTable;
1608 class ConstantPoolSDNode : public SDNode {
1611 MachineConstantPoolValue *MachineCPVal;
1613 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1615 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1617 friend class SelectionDAG;
1618 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1620 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1621 getSDVTList(VT)), Offset(o), Alignment(0) {
1622 assert((int)Offset >= 0 && "Offset is too large");
1625 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1627 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1628 getSDVTList(VT)), Offset(o), Alignment(Align) {
1629 assert((int)Offset >= 0 && "Offset is too large");
1632 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1633 MVT::ValueType VT, int o=0)
1634 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1635 getSDVTList(VT)), Offset(o), Alignment(0) {
1636 assert((int)Offset >= 0 && "Offset is too large");
1637 Val.MachineCPVal = v;
1638 Offset |= 1 << (sizeof(unsigned)*8-1);
1640 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1641 MVT::ValueType VT, int o, unsigned Align)
1642 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1643 getSDVTList(VT)), Offset(o), Alignment(Align) {
1644 assert((int)Offset >= 0 && "Offset is too large");
1645 Val.MachineCPVal = v;
1646 Offset |= 1 << (sizeof(unsigned)*8-1);
1650 bool isMachineConstantPoolEntry() const {
1651 return (int)Offset < 0;
1654 Constant *getConstVal() const {
1655 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1656 return Val.ConstVal;
1659 MachineConstantPoolValue *getMachineCPVal() const {
1660 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1661 return Val.MachineCPVal;
1664 int getOffset() const {
1665 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1668 // Return the alignment of this constant pool object, which is either 0 (for
1669 // default alignment) or log2 of the desired value.
1670 unsigned getAlignment() const { return Alignment; }
1672 const Type *getType() const;
1674 static bool classof(const ConstantPoolSDNode *) { return true; }
1675 static bool classof(const SDNode *N) {
1676 return N->getOpcode() == ISD::ConstantPool ||
1677 N->getOpcode() == ISD::TargetConstantPool;
1681 class BasicBlockSDNode : public SDNode {
1682 MachineBasicBlock *MBB;
1683 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1685 friend class SelectionDAG;
1686 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1687 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1691 MachineBasicBlock *getBasicBlock() const { return MBB; }
1693 static bool classof(const BasicBlockSDNode *) { return true; }
1694 static bool classof(const SDNode *N) {
1695 return N->getOpcode() == ISD::BasicBlock;
1699 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1700 /// used when the SelectionDAG needs to make a simple reference to something
1701 /// in the LLVM IR representation.
1703 /// Note that this is not used for carrying alias information; that is done
1704 /// with MemOperandSDNode, which includes a Value which is required to be a
1705 /// pointer, and several other fields specific to memory references.
1707 class SrcValueSDNode : public SDNode {
1709 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1711 friend class SelectionDAG;
1712 /// Create a SrcValue for a general value.
1713 explicit SrcValueSDNode(const Value *v)
1714 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1717 /// getValue - return the contained Value.
1718 const Value *getValue() const { return V; }
1720 static bool classof(const SrcValueSDNode *) { return true; }
1721 static bool classof(const SDNode *N) {
1722 return N->getOpcode() == ISD::SRCVALUE;
1727 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
1728 /// used to represent a reference to memory after ISD::LOAD
1729 /// and ISD::STORE have been lowered.
1731 class MemOperandSDNode : public SDNode {
1732 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1734 friend class SelectionDAG;
1735 /// Create a MachineMemOperand node
1736 explicit MemOperandSDNode(const MachineMemOperand &mo)
1737 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1740 /// MO - The contained MachineMemOperand.
1741 const MachineMemOperand MO;
1743 static bool classof(const MemOperandSDNode *) { return true; }
1744 static bool classof(const SDNode *N) {
1745 return N->getOpcode() == ISD::MEMOPERAND;
1750 class RegisterSDNode : public SDNode {
1752 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1754 friend class SelectionDAG;
1755 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1756 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1760 unsigned getReg() const { return Reg; }
1762 static bool classof(const RegisterSDNode *) { return true; }
1763 static bool classof(const SDNode *N) {
1764 return N->getOpcode() == ISD::Register;
1768 class ExternalSymbolSDNode : public SDNode {
1770 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1772 friend class SelectionDAG;
1773 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1774 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1775 getSDVTList(VT)), Symbol(Sym) {
1779 const char *getSymbol() const { return Symbol; }
1781 static bool classof(const ExternalSymbolSDNode *) { return true; }
1782 static bool classof(const SDNode *N) {
1783 return N->getOpcode() == ISD::ExternalSymbol ||
1784 N->getOpcode() == ISD::TargetExternalSymbol;
1788 class CondCodeSDNode : public SDNode {
1789 ISD::CondCode Condition;
1790 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1792 friend class SelectionDAG;
1793 explicit CondCodeSDNode(ISD::CondCode Cond)
1794 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1798 ISD::CondCode get() const { return Condition; }
1800 static bool classof(const CondCodeSDNode *) { return true; }
1801 static bool classof(const SDNode *N) {
1802 return N->getOpcode() == ISD::CONDCODE;
1809 static const uint64_t NoFlagSet = 0ULL;
1810 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
1811 static const uint64_t ZExtOffs = 0;
1812 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
1813 static const uint64_t SExtOffs = 1;
1814 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
1815 static const uint64_t InRegOffs = 2;
1816 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
1817 static const uint64_t SRetOffs = 3;
1818 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
1819 static const uint64_t ByValOffs = 4;
1820 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
1821 static const uint64_t NestOffs = 5;
1822 static const uint64_t ByValAlign = 0xFULL << 6; //< Struct alignment
1823 static const uint64_t ByValAlignOffs = 6;
1824 static const uint64_t Split = 1ULL << 10;
1825 static const uint64_t SplitOffs = 10;
1826 static const uint64_t OrigAlign = 0x1FULL<<27;
1827 static const uint64_t OrigAlignOffs = 27;
1828 static const uint64_t ByValSize = 0xffffffffULL << 32; //< Struct size
1829 static const uint64_t ByValSizeOffs = 32;
1831 static const uint64_t One = 1ULL; //< 1 of this type, for shifts
1835 ArgFlagsTy() : Flags(0) { }
1837 bool isZExt() const { return Flags & ZExt; }
1838 void setZExt() { Flags |= One << ZExtOffs; }
1840 bool isSExt() const { return Flags & SExt; }
1841 void setSExt() { Flags |= One << SExtOffs; }
1843 bool isInReg() const { return Flags & InReg; }
1844 void setInReg() { Flags |= One << InRegOffs; }
1846 bool isSRet() const { return Flags & SRet; }
1847 void setSRet() { Flags |= One << SRetOffs; }
1849 bool isByVal() const { return Flags & ByVal; }
1850 void setByVal() { Flags |= One << ByValOffs; }
1852 bool isNest() const { return Flags & Nest; }
1853 void setNest() { Flags |= One << NestOffs; }
1855 unsigned getByValAlign() const {
1857 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
1859 void setByValAlign(unsigned A) {
1860 Flags = (Flags & ~ByValAlign) |
1861 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
1864 bool isSplit() const { return Flags & Split; }
1865 void setSplit() { Flags |= One << SplitOffs; }
1867 unsigned getOrigAlign() const {
1869 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
1871 void setOrigAlign(unsigned A) {
1872 Flags = (Flags & ~OrigAlign) |
1873 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
1876 unsigned getByValSize() const {
1877 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
1879 void setByValSize(unsigned S) {
1880 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
1883 /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
1884 std::string getArgFlagsString();
1886 /// getRawBits - Represent the flags as a bunch of bits.
1887 uint64_t getRawBits() const { return Flags; }
1891 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
1892 class ARG_FLAGSSDNode : public SDNode {
1893 ISD::ArgFlagsTy TheFlags;
1894 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1896 friend class SelectionDAG;
1897 explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
1898 : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
1901 ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
1903 static bool classof(const ARG_FLAGSSDNode *) { return true; }
1904 static bool classof(const SDNode *N) {
1905 return N->getOpcode() == ISD::ARG_FLAGS;
1909 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1910 /// to parameterize some operations.
1911 class VTSDNode : public SDNode {
1912 MVT::ValueType ValueType;
1913 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1915 friend class SelectionDAG;
1916 explicit VTSDNode(MVT::ValueType VT)
1917 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1921 MVT::ValueType getVT() const { return ValueType; }
1923 static bool classof(const VTSDNode *) { return true; }
1924 static bool classof(const SDNode *N) {
1925 return N->getOpcode() == ISD::VALUETYPE;
1929 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1931 class LSBaseSDNode : public SDNode {
1933 // AddrMode - unindexed, pre-indexed, post-indexed.
1934 ISD::MemIndexedMode AddrMode;
1936 // MemoryVT - VT of in-memory value.
1937 MVT::ValueType MemoryVT;
1939 //! SrcValue - Memory location for alias analysis.
1940 const Value *SrcValue;
1942 //! SVOffset - Memory location offset.
1945 //! Alignment - Alignment of memory location in bytes.
1948 //! IsVolatile - True if the store is volatile.
1951 //! Operand array for load and store
1953 \note Moving this array to the base class captures more
1954 common functionality shared between LoadSDNode and
1959 LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned NumOperands,
1960 SDVTList VTs, ISD::MemIndexedMode AM, MVT::ValueType VT,
1961 const Value *SV, int SVO, unsigned Align, bool Vol)
1962 : SDNode(NodeTy, VTs),
1963 AddrMode(AM), MemoryVT(VT),
1964 SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol) {
1965 for (unsigned i = 0; i != NumOperands; ++i)
1966 Ops[i] = Operands[i];
1967 InitOperands(Ops, NumOperands);
1968 assert(Align != 0 && "Loads and stores should have non-zero aligment");
1969 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1970 "Only indexed loads and stores have a non-undef offset operand");
1973 const SDOperand &getChain() const { return getOperand(0); }
1974 const SDOperand &getBasePtr() const {
1975 return getOperand(getOpcode() == ISD::LOAD ? 1 : 2);
1977 const SDOperand &getOffset() const {
1978 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1981 const Value *getSrcValue() const { return SrcValue; }
1982 int getSrcValueOffset() const { return SVOffset; }
1983 unsigned getAlignment() const { return Alignment; }
1984 MVT::ValueType getMemoryVT() const { return MemoryVT; }
1985 bool isVolatile() const { return IsVolatile; }
1987 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1989 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1990 bool isIndexed() const { return AddrMode != ISD::UNINDEXED; }
1992 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1993 bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; }
1995 /// getMemOperand - Return a MachineMemOperand object describing the memory
1996 /// reference performed by this load or store.
1997 MachineMemOperand getMemOperand() const;
1999 static bool classof(const LSBaseSDNode *N) { return true; }
2000 static bool classof(const SDNode *N) {
2001 return N->getOpcode() == ISD::LOAD ||
2002 N->getOpcode() == ISD::STORE;
2006 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2008 class LoadSDNode : public LSBaseSDNode {
2009 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2011 // ExtType - non-ext, anyext, sext, zext.
2012 ISD::LoadExtType ExtType;
2015 friend class SelectionDAG;
2016 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
2017 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
2018 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2019 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
2020 VTs, AM, LVT, SV, O, Align, Vol),
2024 ISD::LoadExtType getExtensionType() const { return ExtType; }
2025 const SDOperand &getBasePtr() const { return getOperand(1); }
2026 const SDOperand &getOffset() const { return getOperand(2); }
2028 static bool classof(const LoadSDNode *) { return true; }
2029 static bool classof(const SDNode *N) {
2030 return N->getOpcode() == ISD::LOAD;
2034 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2036 class StoreSDNode : public LSBaseSDNode {
2037 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2039 // IsTruncStore - True if the op does a truncation before store.
2042 friend class SelectionDAG;
2043 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
2044 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
2045 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2046 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
2047 VTs, AM, SVT, SV, O, Align, Vol),
2048 IsTruncStore(isTrunc) {}
2051 bool isTruncatingStore() const { return IsTruncStore; }
2052 const SDOperand &getValue() const { return getOperand(1); }
2053 const SDOperand &getBasePtr() const { return getOperand(2); }
2054 const SDOperand &getOffset() const { return getOperand(3); }
2056 static bool classof(const StoreSDNode *) { return true; }
2057 static bool classof(const SDNode *N) {
2058 return N->getOpcode() == ISD::STORE;
2063 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
2067 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2069 bool operator==(const SDNodeIterator& x) const {
2070 return Operand == x.Operand;
2072 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2074 const SDNodeIterator &operator=(const SDNodeIterator &I) {
2075 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2076 Operand = I.Operand;
2080 pointer operator*() const {
2081 return Node->getOperand(Operand).Val;
2083 pointer operator->() const { return operator*(); }
2085 SDNodeIterator& operator++() { // Preincrement
2089 SDNodeIterator operator++(int) { // Postincrement
2090 SDNodeIterator tmp = *this; ++*this; return tmp;
2093 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2094 static SDNodeIterator end (SDNode *N) {
2095 return SDNodeIterator(N, N->getNumOperands());
2098 unsigned getOperand() const { return Operand; }
2099 const SDNode *getNode() const { return Node; }
2102 template <> struct GraphTraits<SDNode*> {
2103 typedef SDNode NodeType;
2104 typedef SDNodeIterator ChildIteratorType;
2105 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2106 static inline ChildIteratorType child_begin(NodeType *N) {
2107 return SDNodeIterator::begin(N);
2109 static inline ChildIteratorType child_end(NodeType *N) {
2110 return SDNodeIterator::end(N);
2115 struct ilist_traits<SDNode> {
2116 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
2117 static SDNode *getNext(const SDNode *N) { return N->Next; }
2119 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
2120 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
2122 static SDNode *createSentinel() {
2123 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
2125 static void destroySentinel(SDNode *N) { delete N; }
2126 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
2129 void addNodeToList(SDNode *NTy) {}
2130 void removeNodeFromList(SDNode *NTy) {}
2131 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
2132 const ilist_iterator<SDNode> &X,
2133 const ilist_iterator<SDNode> &Y) {}
2137 /// isNormalLoad - Returns true if the specified node is a non-extending
2138 /// and unindexed load.
2139 inline bool isNormalLoad(const SDNode *N) {
2140 if (N->getOpcode() != ISD::LOAD)
2142 const LoadSDNode *Ld = cast<LoadSDNode>(N);
2143 return Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2144 Ld->getAddressingMode() == ISD::UNINDEXED;
2147 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2149 inline bool isNON_EXTLoad(const SDNode *N) {
2150 return N->getOpcode() == ISD::LOAD &&
2151 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2154 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2156 inline bool isEXTLoad(const SDNode *N) {
2157 return N->getOpcode() == ISD::LOAD &&
2158 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2161 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2163 inline bool isSEXTLoad(const SDNode *N) {
2164 return N->getOpcode() == ISD::LOAD &&
2165 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2168 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2170 inline bool isZEXTLoad(const SDNode *N) {
2171 return N->getOpcode() == ISD::LOAD &&
2172 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2175 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
2177 inline bool isUNINDEXEDLoad(const SDNode *N) {
2178 return N->getOpcode() == ISD::LOAD &&
2179 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2182 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2184 inline bool isNON_TRUNCStore(const SDNode *N) {
2185 return N->getOpcode() == ISD::STORE &&
2186 !cast<StoreSDNode>(N)->isTruncatingStore();
2189 /// isTRUNCStore - Returns true if the specified node is a truncating
2191 inline bool isTRUNCStore(const SDNode *N) {
2192 return N->getOpcode() == ISD::STORE &&
2193 cast<StoreSDNode>(N)->isTruncatingStore();
2198 } // end llvm namespace