1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG. These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
22 #include "llvm/Constants.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/ilist_node.h"
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/ADT/STLExtras.h"
28 #include "llvm/CodeGen/ValueTypes.h"
29 #include "llvm/CodeGen/MachineMemOperand.h"
30 #include "llvm/Support/MathExtras.h"
31 #include "llvm/System/DataTypes.h"
32 #include "llvm/Support/DebugLoc.h"
39 class MachineBasicBlock;
40 class MachineConstantPoolValue;
43 template <typename T> struct DenseMapInfo;
44 template <typename T> struct simplify_type;
45 template <typename T> struct ilist_traits;
47 /// SDVTList - This represents a list of ValueType's that has been intern'd by
48 /// a SelectionDAG. Instances of this simple value class are returned by
49 /// SelectionDAG::getVTList(...).
56 /// ISD namespace - This namespace contains an enum which represents all of the
57 /// SelectionDAG node types and value types.
61 //===--------------------------------------------------------------------===//
62 /// ISD::NodeType enum - This enum defines the target-independent operators
63 /// for a SelectionDAG.
65 /// Targets may also define target-dependent operator codes for SDNodes. For
66 /// example, on x86, these are the enum values in the X86ISD namespace.
67 /// Targets should aim to use target-independent operators to model their
68 /// instruction sets as much as possible, and only use target-dependent
69 /// operators when they have special requirements.
71 /// Finally, during and after selection proper, SNodes may use special
72 /// operator codes that correspond directly with MachineInstr opcodes. These
73 /// are used to represent selected instructions. See the isMachineOpcode()
74 /// and getMachineOpcode() member functions of SDNode.
77 // DELETED_NODE - This is an illegal value that is used to catch
78 // errors. This opcode is not a legal opcode for any node.
81 // EntryToken - This is the marker used to indicate the start of the region.
84 // TokenFactor - This node takes multiple tokens as input and produces a
85 // single token result. This is used to represent the fact that the operand
86 // operators are independent of each other.
89 // AssertSext, AssertZext - These nodes record if a register contains a
90 // value that has already been zero or sign extended from a narrower type.
91 // These nodes take two operands. The first is the node that has already
92 // been extended, and the second is a value type node indicating the width
94 AssertSext, AssertZext,
96 // Various leaf nodes.
97 BasicBlock, VALUETYPE, CONDCODE, Register,
99 GlobalAddress, GlobalTLSAddress, FrameIndex,
100 JumpTable, ConstantPool, ExternalSymbol, BlockAddress,
102 // The address of the GOT
105 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
106 // llvm.returnaddress on the DAG. These nodes take one operand, the index
107 // of the frame or return address to return. An index of zero corresponds
108 // to the current function's frame or return address, an index of one to the
109 // parent's frame or return address, and so on.
110 FRAMEADDR, RETURNADDR,
112 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
113 // first (possible) on-stack argument. This is needed for correct stack
114 // adjustment during unwind.
115 FRAME_TO_ARGS_OFFSET,
117 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
118 // address of the exception block on entry to an landing pad block.
121 // RESULT, OUTCHAIN = LSDAADDR(INCHAIN) - This node represents the
122 // address of the Language Specific Data Area for the enclosing function.
125 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
126 // the selection index of the exception thrown.
129 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
130 // 'eh_return' gcc dwarf builtin, which is used to return from
131 // exception. The general meaning is: adjust stack by OFFSET and pass
132 // execution to HANDLER. Many platform-related details also :)
135 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
136 // simplification of the constant.
140 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
141 // anything else with this node, and this is valid in the target-specific
142 // dag, turning into a GlobalAddress operand.
144 TargetGlobalTLSAddress,
148 TargetExternalSymbol,
151 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
152 /// This node represents a target intrinsic function with no side effects.
153 /// The first operand is the ID number of the intrinsic from the
154 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
155 /// node has returns the result of the intrinsic.
158 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
159 /// This node represents a target intrinsic function with side effects that
160 /// returns a result. The first operand is a chain pointer. The second is
161 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
162 /// operands to the intrinsic follow. The node has two results, the result
163 /// of the intrinsic and an output chain.
166 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
167 /// This node represents a target intrinsic function with side effects that
168 /// does not return a result. The first operand is a chain pointer. The
169 /// second is the ID number of the intrinsic from the llvm::Intrinsic
170 /// namespace. The operands to the intrinsic follow.
173 // CopyToReg - This node has three operands: a chain, a register number to
174 // set to this value, and a value.
177 // CopyFromReg - This node indicates that the input value is a virtual or
178 // physical register that is defined outside of the scope of this
179 // SelectionDAG. The register is available from the RegisterSDNode object.
182 // UNDEF - An undefined node
185 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
186 // a Constant, which is required to be operand #1) half of the integer or
187 // float value specified as operand #0. This is only for use before
188 // legalization, for values that will be broken into multiple registers.
191 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
192 // two values of the same integer value type, this produces a value twice as
193 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
196 // MERGE_VALUES - This node takes multiple discrete operands and returns
197 // them all as its individual results. This nodes has exactly the same
198 // number of inputs and outputs. This node is useful for some pieces of the
199 // code generator that want to think about a single node with multiple
200 // results, not multiple nodes.
203 // Simple integer binary arithmetic operators.
204 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
206 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
207 // a signed/unsigned value of type i[2*N], and return the full value as
208 // two results, each of type iN.
209 SMUL_LOHI, UMUL_LOHI,
211 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
215 // CARRY_FALSE - This node is used when folding other nodes,
216 // like ADDC/SUBC, which indicate the carry result is always false.
219 // Carry-setting nodes for multiple precision addition and subtraction.
220 // These nodes take two operands of the same value type, and produce two
221 // results. The first result is the normal add or sub result, the second
222 // result is the carry flag result.
225 // Carry-using nodes for multiple precision addition and subtraction. These
226 // nodes take three operands: The first two are the normal lhs and rhs to
227 // the add or sub, and the third is the input carry flag. These nodes
228 // produce two results; the normal result of the add or sub, and the output
229 // carry flag. These nodes both read and write a carry flag to allow them
230 // to them to be chained together for add and sub of arbitrarily large
234 // RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
235 // These nodes take two operands: the normal LHS and RHS to the add. They
236 // produce two results: the normal result of the add, and a boolean that
237 // indicates if an overflow occured (*not* a flag, because it may be stored
238 // to memory, etc.). If the type of the boolean is not i1 then the high
239 // bits conform to getBooleanContents.
240 // These nodes are generated from the llvm.[su]add.with.overflow intrinsics.
243 // Same for subtraction
246 // Same for multiplication
249 // Simple binary floating point operators.
250 FADD, FSUB, FMUL, FDIV, FREM,
252 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
253 // DAG node does not require that X and Y have the same type, just that they
254 // are both floating point. X and the result must have the same type.
255 // FCOPYSIGN(f32, f64) is allowed.
258 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
259 // value as an integer 0/1 value.
262 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the
263 /// specified, possibly variable, elements. The number of elements is
264 /// required to be a power of two. The types of the operands must all be
265 /// the same and must match the vector element type, except that integer
266 /// types are allowed to be larger than the element type, in which case
267 /// the operands are implicitly truncated.
270 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
271 /// at IDX replaced with VAL. If the type of VAL is larger than the vector
272 /// element type then VAL is truncated before replacement.
275 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
276 /// identified by the (potentially variable) element number IDX. If the
277 /// return type is an integer type larger than the element type of the
278 /// vector, the result is extended to the width of the return type.
281 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
282 /// vector type with the same length and element type, this produces a
283 /// concatenated vector result value, with length equal to the sum of the
284 /// lengths of the input vectors.
287 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
288 /// vector value) starting with the (potentially variable) element number
289 /// IDX, which must be a multiple of the result vector length.
292 /// VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as
293 /// VEC1/VEC2. A VECTOR_SHUFFLE node also contains an array of constant int
294 /// values that indicate which value (or undef) each result element will
295 /// get. These constant ints are accessible through the
296 /// ShuffleVectorSDNode class. This is quite similar to the Altivec
297 /// 'vperm' instruction, except that the indices must be constants and are
298 /// in terms of the element size of VEC1/VEC2, not in terms of bytes.
301 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
302 /// scalar value into element 0 of the resultant vector type. The top
303 /// elements 1 to N-1 of the N-element vector are undefined. The type
304 /// of the operand must match the vector element type, except when they
305 /// are integer types. In this case the operand is allowed to be wider
306 /// than the vector element type, and is implicitly truncated to it.
309 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
310 // an unsigned/signed value of type i[2*N], then return the top part.
313 // Bitwise operators - logical and, logical or, logical xor, shift left,
314 // shift right algebraic (shift in sign bits), shift right logical (shift in
315 // zeroes), rotate left, rotate right, and byteswap.
316 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
318 // Counting operators
321 // Select(COND, TRUEVAL, FALSEVAL). If the type of the boolean COND is not
322 // i1 then the high bits must conform to getBooleanContents.
325 // Select with condition operator - This selects between a true value and
326 // a false value (ops #2 and #3) based on the boolean result of comparing
327 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
328 // condition code in op #4, a CondCodeSDNode.
331 // SetCC operator - This evaluates to a true value iff the condition is
332 // true. If the result value type is not i1 then the high bits conform
333 // to getBooleanContents. The operands to this are the left and right
334 // operands to compare (ops #0, and #1) and the condition code to compare
335 // them with (op #2) as a CondCodeSDNode.
338 // RESULT = VSETCC(LHS, RHS, COND) operator - This evaluates to a vector of
339 // integer elements with all bits of the result elements set to true if the
340 // comparison is true or all cleared if the comparison is false. The
341 // operands to this are the left and right operands to compare (LHS/RHS) and
342 // the condition code to compare them with (COND) as a CondCodeSDNode.
345 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
346 // integer shift operations, just like ADD/SUB_PARTS. The operation
348 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
349 SHL_PARTS, SRA_PARTS, SRL_PARTS,
351 // Conversion operators. These are all single input single output
352 // operations. For all of these, the result type must be strictly
353 // wider or narrower (depending on the operation) than the source
356 // SIGN_EXTEND - Used for integer types, replicating the sign bit
360 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
363 // ANY_EXTEND - Used for integer types. The high bits are undefined.
366 // TRUNCATE - Completely drop the high bits.
369 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
370 // depends on the first letter) to floating point.
374 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
375 // sign extend a small value in a large integer register (e.g. sign
376 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
377 // with the 7th bit). The size of the smaller type is indicated by the 1th
378 // operand, a ValueType node.
381 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
386 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
387 /// down to the precision of the destination VT. TRUNC is a flag, which is
388 /// always an integer that is zero or one. If TRUNC is 0, this is a
389 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
392 /// The TRUNC = 1 case is used in cases where we know that the value will
393 /// not be modified by the node, because Y is not using any of the extra
394 /// precision of source type. This allows certain transformations like
395 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
396 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
399 // FLT_ROUNDS_ - Returns current rounding mode:
402 // 1 Round to nearest
407 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
408 /// rounds it to a floating point value. It then promotes it and returns it
409 /// in a register of the same size. This operation effectively just
410 /// discards excess precision. The type to round down to is specified by
411 /// the VT operand, a VTSDNode.
414 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
417 // BIT_CONVERT - Theis operator converts between integer and FP values, as
418 // if one was stored to memory as integer and the other was loaded from the
419 // same address (or equivalently for vector format conversions, etc). The
420 // source and result are required to have the same bit size (e.g.
421 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
422 // conversions, but that is a noop, deleted by getNode().
425 // CONVERT_RNDSAT - This operator is used to support various conversions
426 // between various types (float, signed, unsigned and vectors of those
427 // types) with rounding and saturation. NOTE: Avoid using this operator as
428 // most target don't support it and the operator might be removed in the
429 // future. It takes the following arguments:
431 // 1) dest type (type to convert to)
432 // 2) src type (type to convert from)
435 // 5) ISD::CvtCode indicating the type of conversion to do
438 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
439 // FLOG, FLOG2, FLOG10, FEXP, FEXP2,
440 // FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary floating
441 // point operations. These are inspired by libm.
442 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
443 FLOG, FLOG2, FLOG10, FEXP, FEXP2,
444 FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR,
446 // LOAD and STORE have token chains as their first operand, then the same
447 // operands as an LLVM load/store instruction, then an offset node that
448 // is added / subtracted from the base pointer to form the address (for
449 // indexed memory ops).
452 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
453 // to a specified boundary. This node always has two return values: a new
454 // stack pointer value and a chain. The first operand is the token chain,
455 // the second is the number of bytes to allocate, and the third is the
456 // alignment boundary. The size is guaranteed to be a multiple of the stack
457 // alignment, and the alignment is guaranteed to be bigger than the stack
458 // alignment (if required) or 0 to get standard stack alignment.
461 // Control flow instructions. These all have token chains.
463 // BR - Unconditional branch. The first operand is the chain
464 // operand, the second is the MBB to branch to.
467 // BRIND - Indirect branch. The first operand is the chain, the second
468 // is the value to branch to, which must be of the same type as the target's
472 // BR_JT - Jumptable branch. The first operand is the chain, the second
473 // is the jumptable index, the last one is the jumptable entry index.
476 // BRCOND - Conditional branch. The first operand is the chain, the
477 // second is the condition, the third is the block to branch to if the
478 // condition is true. If the type of the condition is not i1, then the
479 // high bits must conform to getBooleanContents.
482 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
483 // that the condition is represented as condition code, and two nodes to
484 // compare, rather than as a combined SetCC node. The operands in order are
485 // chain, cc, lhs, rhs, block to branch to if condition is true.
488 // INLINEASM - Represents an inline asm block. This node always has two
489 // return values: a chain and a flag result. The inputs are as follows:
490 // Operand #0 : Input chain.
491 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
492 // Operand #2n+2: A RegisterNode.
493 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
494 // Operand #last: Optional, an incoming flag.
497 // EH_LABEL - Represents a label in mid basic block used to track
498 // locations needed for debug and exception handling tables. These nodes
499 // take a chain as input and return a chain.
502 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
503 // value, the same type as the pointer type for the system, and an output
507 // STACKRESTORE has two operands, an input chain and a pointer to restore to
508 // it returns an output chain.
511 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
512 // a call sequence, and carry arbitrary information that target might want
513 // to know. The first operand is a chain, the rest are specified by the
514 // target and not touched by the DAG optimizers.
515 // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
516 CALLSEQ_START, // Beginning of a call sequence
517 CALLSEQ_END, // End of a call sequence
519 // VAARG - VAARG has three operands: an input chain, a pointer, and a
520 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
523 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
524 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
528 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
529 // pointer, and a SRCVALUE.
532 // SRCVALUE - This is a node type that holds a Value* that is used to
533 // make reference to a value in the LLVM IR.
536 // PCMARKER - This corresponds to the pcmarker intrinsic.
539 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
540 // The only operand is a chain and a value and a chain are produced. The
541 // value is the contents of the architecture specific cycle counter like
542 // register (or other high accuracy low latency clock source)
545 // HANDLENODE node - Used as a handle for various purposes.
548 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
549 // It takes as input a token chain, the pointer to the trampoline,
550 // the pointer to the nested function, the pointer to pass for the
551 // 'nest' parameter, a SRCVALUE for the trampoline and another for
552 // the nested function (allowing targets to access the original
553 // Function*). It produces the result of the intrinsic and a token
557 // TRAP - Trapping instruction
560 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
561 // their first operand. The other operands are the address to prefetch,
562 // read / write specifier, and locality specifier.
565 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
566 // store-store, device)
567 // This corresponds to the memory.barrier intrinsic.
568 // it takes an input chain, 4 operands to specify the type of barrier, an
569 // operand specifying if the barrier applies to device and uncached memory
570 // and produces an output chain.
573 // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
574 // this corresponds to the atomic.lcs intrinsic.
575 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
576 // the return is always the original value in *ptr
579 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
580 // this corresponds to the atomic.swap intrinsic.
581 // amt is stored to *ptr atomically.
582 // the return is always the original value in *ptr
585 // Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt)
586 // this corresponds to the atomic.load.[OpName] intrinsic.
587 // op(*ptr, amt) is stored to *ptr atomically.
588 // the return is always the original value in *ptr
600 /// BUILTIN_OP_END - This must be the last enum value in this list.
601 /// The target-specific pre-isel opcode values start here.
605 /// FIRST_TARGET_MEMORY_OPCODE - Target-specific pre-isel operations
606 /// which do not reference a specific memory location should be less than
607 /// this value. Those that do must not be less than this value, and can
608 /// be used with SelectionDAG::getMemIntrinsicNode.
609 static const int FIRST_TARGET_MEMORY_OPCODE = 1 << 14;
613 /// isBuildVectorAllOnes - Return true if the specified node is a
614 /// BUILD_VECTOR where all of the elements are ~0 or undef.
615 bool isBuildVectorAllOnes(const SDNode *N);
617 /// isBuildVectorAllZeros - Return true if the specified node is a
618 /// BUILD_VECTOR where all of the elements are 0 or undef.
619 bool isBuildVectorAllZeros(const SDNode *N);
621 /// isScalarToVector - Return true if the specified node is a
622 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
623 /// element is not an undef.
624 bool isScalarToVector(const SDNode *N);
626 //===--------------------------------------------------------------------===//
627 /// MemIndexedMode enum - This enum defines the load / store indexed
628 /// addressing modes.
630 /// UNINDEXED "Normal" load / store. The effective address is already
631 /// computed and is available in the base pointer. The offset
632 /// operand is always undefined. In addition to producing a
633 /// chain, an unindexed load produces one value (result of the
634 /// load); an unindexed store does not produce a value.
636 /// PRE_INC Similar to the unindexed mode where the effective address is
637 /// PRE_DEC the value of the base pointer add / subtract the offset.
638 /// It considers the computation as being folded into the load /
639 /// store operation (i.e. the load / store does the address
640 /// computation as well as performing the memory transaction).
641 /// The base operand is always undefined. In addition to
642 /// producing a chain, pre-indexed load produces two values
643 /// (result of the load and the result of the address
644 /// computation); a pre-indexed store produces one value (result
645 /// of the address computation).
647 /// POST_INC The effective address is the value of the base pointer. The
648 /// POST_DEC value of the offset operand is then added to / subtracted
649 /// from the base after memory transaction. In addition to
650 /// producing a chain, post-indexed load produces two values
651 /// (the result of the load and the result of the base +/- offset
652 /// computation); a post-indexed store produces one value (the
653 /// the result of the base +/- offset computation).
655 enum MemIndexedMode {
664 //===--------------------------------------------------------------------===//
665 /// LoadExtType enum - This enum defines the three variants of LOADEXT
666 /// (load with extension).
668 /// SEXTLOAD loads the integer operand and sign extends it to a larger
669 /// integer result type.
670 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
671 /// integer result type.
672 /// EXTLOAD is used for three things: floating point extending loads,
673 /// integer extending loads [the top bits are undefined], and vector
674 /// extending loads [load into low elt].
684 //===--------------------------------------------------------------------===//
685 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
686 /// below work out, when considering SETFALSE (something that never exists
687 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
688 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
689 /// to. If the "N" column is 1, the result of the comparison is undefined if
690 /// the input is a NAN.
692 /// All of these (except for the 'always folded ops') should be handled for
693 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
694 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
696 /// Note that these are laid out in a specific order to allow bit-twiddling
697 /// to transform conditions.
699 // Opcode N U L G E Intuitive operation
700 SETFALSE, // 0 0 0 0 Always false (always folded)
701 SETOEQ, // 0 0 0 1 True if ordered and equal
702 SETOGT, // 0 0 1 0 True if ordered and greater than
703 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
704 SETOLT, // 0 1 0 0 True if ordered and less than
705 SETOLE, // 0 1 0 1 True if ordered and less than or equal
706 SETONE, // 0 1 1 0 True if ordered and operands are unequal
707 SETO, // 0 1 1 1 True if ordered (no nans)
708 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
709 SETUEQ, // 1 0 0 1 True if unordered or equal
710 SETUGT, // 1 0 1 0 True if unordered or greater than
711 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
712 SETULT, // 1 1 0 0 True if unordered or less than
713 SETULE, // 1 1 0 1 True if unordered, less than, or equal
714 SETUNE, // 1 1 1 0 True if unordered or not equal
715 SETTRUE, // 1 1 1 1 Always true (always folded)
716 // Don't care operations: undefined if the input is a nan.
717 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
718 SETEQ, // 1 X 0 0 1 True if equal
719 SETGT, // 1 X 0 1 0 True if greater than
720 SETGE, // 1 X 0 1 1 True if greater than or equal
721 SETLT, // 1 X 1 0 0 True if less than
722 SETLE, // 1 X 1 0 1 True if less than or equal
723 SETNE, // 1 X 1 1 0 True if not equal
724 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
726 SETCC_INVALID // Marker value.
729 /// isSignedIntSetCC - Return true if this is a setcc instruction that
730 /// performs a signed comparison when used with integer operands.
731 inline bool isSignedIntSetCC(CondCode Code) {
732 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
735 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
736 /// performs an unsigned comparison when used with integer operands.
737 inline bool isUnsignedIntSetCC(CondCode Code) {
738 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
741 /// isTrueWhenEqual - Return true if the specified condition returns true if
742 /// the two operands to the condition are equal. Note that if one of the two
743 /// operands is a NaN, this value is meaningless.
744 inline bool isTrueWhenEqual(CondCode Cond) {
745 return ((int)Cond & 1) != 0;
748 /// getUnorderedFlavor - This function returns 0 if the condition is always
749 /// false if an operand is a NaN, 1 if the condition is always true if the
750 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
752 inline unsigned getUnorderedFlavor(CondCode Cond) {
753 return ((int)Cond >> 3) & 3;
756 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
757 /// 'op' is a valid SetCC operation.
758 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
760 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
761 /// when given the operation for (X op Y).
762 CondCode getSetCCSwappedOperands(CondCode Operation);
764 /// getSetCCOrOperation - Return the result of a logical OR between different
765 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
766 /// function returns SETCC_INVALID if it is not possible to represent the
767 /// resultant comparison.
768 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
770 /// getSetCCAndOperation - Return the result of a logical AND between
771 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
772 /// function returns SETCC_INVALID if it is not possible to represent the
773 /// resultant comparison.
774 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
776 //===--------------------------------------------------------------------===//
777 /// CvtCode enum - This enum defines the various converts CONVERT_RNDSAT
780 CVT_FF, // Float from Float
781 CVT_FS, // Float from Signed
782 CVT_FU, // Float from Unsigned
783 CVT_SF, // Signed from Float
784 CVT_UF, // Unsigned from Float
785 CVT_SS, // Signed from Signed
786 CVT_SU, // Signed from Unsigned
787 CVT_US, // Unsigned from Signed
788 CVT_UU, // Unsigned from Unsigned
789 CVT_INVALID // Marker - Invalid opcode
791 } // end llvm::ISD namespace
794 //===----------------------------------------------------------------------===//
795 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
796 /// values as the result of a computation. Many nodes return multiple values,
797 /// from loads (which define a token and a return value) to ADDC (which returns
798 /// a result and a carry value), to calls (which may return an arbitrary number
801 /// As such, each use of a SelectionDAG computation must indicate the node that
802 /// computes it as well as which return value to use from that node. This pair
803 /// of information is represented with the SDValue value type.
806 SDNode *Node; // The node defining the value we are using.
807 unsigned ResNo; // Which return value of the node we are using.
809 SDValue() : Node(0), ResNo(0) {}
810 SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
812 /// get the index which selects a specific result in the SDNode
813 unsigned getResNo() const { return ResNo; }
815 /// get the SDNode which holds the desired result
816 SDNode *getNode() const { return Node; }
819 void setNode(SDNode *N) { Node = N; }
821 bool operator==(const SDValue &O) const {
822 return Node == O.Node && ResNo == O.ResNo;
824 bool operator!=(const SDValue &O) const {
825 return !operator==(O);
827 bool operator<(const SDValue &O) const {
828 return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
831 SDValue getValue(unsigned R) const {
832 return SDValue(Node, R);
835 // isOperandOf - Return true if this node is an operand of N.
836 bool isOperandOf(SDNode *N) const;
838 /// getValueType - Return the ValueType of the referenced return value.
840 inline EVT getValueType() const;
842 /// getValueSizeInBits - Returns the size of the value in bits.
844 unsigned getValueSizeInBits() const {
845 return getValueType().getSizeInBits();
848 // Forwarding methods - These forward to the corresponding methods in SDNode.
849 inline unsigned getOpcode() const;
850 inline unsigned getNumOperands() const;
851 inline const SDValue &getOperand(unsigned i) const;
852 inline uint64_t getConstantOperandVal(unsigned i) const;
853 inline bool isTargetMemoryOpcode() const;
854 inline bool isTargetOpcode() const;
855 inline bool isMachineOpcode() const;
856 inline unsigned getMachineOpcode() const;
857 inline const DebugLoc getDebugLoc() const;
860 /// reachesChainWithoutSideEffects - Return true if this operand (which must
861 /// be a chain) reaches the specified operand without crossing any
862 /// side-effecting instructions. In practice, this looks through token
863 /// factors and non-volatile loads. In order to remain efficient, this only
864 /// looks a couple of nodes in, it does not do an exhaustive search.
865 bool reachesChainWithoutSideEffects(SDValue Dest,
866 unsigned Depth = 2) const;
868 /// use_empty - Return true if there are no nodes using value ResNo
871 inline bool use_empty() const;
873 /// hasOneUse - Return true if there is exactly one node using value
876 inline bool hasOneUse() const;
880 template<> struct DenseMapInfo<SDValue> {
881 static inline SDValue getEmptyKey() {
882 return SDValue((SDNode*)-1, -1U);
884 static inline SDValue getTombstoneKey() {
885 return SDValue((SDNode*)-1, 0);
887 static unsigned getHashValue(const SDValue &Val) {
888 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
889 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
891 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
894 static bool isPod() { return true; }
897 /// simplify_type specializations - Allow casting operators to work directly on
898 /// SDValues as if they were SDNode*'s.
899 template<> struct simplify_type<SDValue> {
900 typedef SDNode* SimpleType;
901 static SimpleType getSimplifiedValue(const SDValue &Val) {
902 return static_cast<SimpleType>(Val.getNode());
905 template<> struct simplify_type<const SDValue> {
906 typedef SDNode* SimpleType;
907 static SimpleType getSimplifiedValue(const SDValue &Val) {
908 return static_cast<SimpleType>(Val.getNode());
912 /// SDUse - Represents a use of a SDNode. This class holds an SDValue,
913 /// which records the SDNode being used and the result number, a
914 /// pointer to the SDNode using the value, and Next and Prev pointers,
915 /// which link together all the uses of an SDNode.
918 /// Val - The value being used.
920 /// User - The user of this value.
922 /// Prev, Next - Pointers to the uses list of the SDNode referred by
926 SDUse(const SDUse &U); // Do not implement
927 void operator=(const SDUse &U); // Do not implement
930 SDUse() : Val(), User(NULL), Prev(NULL), Next(NULL) {}
932 /// Normally SDUse will just implicitly convert to an SDValue that it holds.
933 operator const SDValue&() const { return Val; }
935 /// If implicit conversion to SDValue doesn't work, the get() method returns
937 const SDValue &get() const { return Val; }
939 /// getUser - This returns the SDNode that contains this Use.
940 SDNode *getUser() { return User; }
942 /// getNext - Get the next SDUse in the use list.
943 SDUse *getNext() const { return Next; }
945 /// getNode - Convenience function for get().getNode().
946 SDNode *getNode() const { return Val.getNode(); }
947 /// getResNo - Convenience function for get().getResNo().
948 unsigned getResNo() const { return Val.getResNo(); }
949 /// getValueType - Convenience function for get().getValueType().
950 EVT getValueType() const { return Val.getValueType(); }
952 /// operator== - Convenience function for get().operator==
953 bool operator==(const SDValue &V) const {
957 /// operator!= - Convenience function for get().operator!=
958 bool operator!=(const SDValue &V) const {
962 /// operator< - Convenience function for get().operator<
963 bool operator<(const SDValue &V) const {
968 friend class SelectionDAG;
971 void setUser(SDNode *p) { User = p; }
973 /// set - Remove this use from its existing use list, assign it the
974 /// given value, and add it to the new value's node's use list.
975 inline void set(const SDValue &V);
976 /// setInitial - like set, but only supports initializing a newly-allocated
977 /// SDUse with a non-null value.
978 inline void setInitial(const SDValue &V);
979 /// setNode - like set, but only sets the Node portion of the value,
980 /// leaving the ResNo portion unmodified.
981 inline void setNode(SDNode *N);
983 void addToList(SDUse **List) {
985 if (Next) Next->Prev = &Next;
990 void removeFromList() {
992 if (Next) Next->Prev = Prev;
996 /// simplify_type specializations - Allow casting operators to work directly on
997 /// SDValues as if they were SDNode*'s.
998 template<> struct simplify_type<SDUse> {
999 typedef SDNode* SimpleType;
1000 static SimpleType getSimplifiedValue(const SDUse &Val) {
1001 return static_cast<SimpleType>(Val.getNode());
1004 template<> struct simplify_type<const SDUse> {
1005 typedef SDNode* SimpleType;
1006 static SimpleType getSimplifiedValue(const SDUse &Val) {
1007 return static_cast<SimpleType>(Val.getNode());
1012 /// SDNode - Represents one node in the SelectionDAG.
1014 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
1016 /// NodeType - The operation that this node performs.
1020 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
1021 /// then they will be delete[]'d when the node is destroyed.
1022 uint16_t OperandsNeedDelete : 1;
1025 /// SubclassData - This member is defined by this class, but is not used for
1026 /// anything. Subclasses can use it to hold whatever state they find useful.
1027 /// This field is initialized to zero by the ctor.
1028 uint16_t SubclassData : 15;
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 EVT *ValueList;
1042 /// UseList - List of uses for this SDNode.
1045 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1046 unsigned short NumOperands, NumValues;
1048 /// debugLoc - source line information.
1051 /// getValueTypeList - Return a pointer to the specified value type.
1052 static const EVT *getValueTypeList(EVT VT);
1054 friend class SelectionDAG;
1055 friend struct ilist_traits<SDNode>;
1058 //===--------------------------------------------------------------------===//
1062 /// getOpcode - Return the SelectionDAG opcode value for this node. For
1063 /// pre-isel nodes (those for which isMachineOpcode returns false), these
1064 /// are the opcode values in the ISD and <target>ISD namespaces. For
1065 /// post-isel opcodes, see getMachineOpcode.
1066 unsigned getOpcode() const { return (unsigned short)NodeType; }
1068 /// isTargetOpcode - Test if this node has a target-specific opcode (in the
1069 /// \<target\>ISD namespace).
1070 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1072 /// isTargetMemoryOpcode - Test if this node has a target-specific
1073 /// memory-referencing opcode (in the \<target\>ISD namespace and
1074 /// greater than FIRST_TARGET_MEMORY_OPCODE).
1075 bool isTargetMemoryOpcode() const {
1076 return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
1079 /// isMachineOpcode - Test if this node has a post-isel opcode, directly
1080 /// corresponding to a MachineInstr opcode.
1081 bool isMachineOpcode() const { return NodeType < 0; }
1083 /// getMachineOpcode - This may only be called if isMachineOpcode returns
1084 /// true. It returns the MachineInstr opcode value that the node's opcode
1086 unsigned getMachineOpcode() const {
1087 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
1091 /// use_empty - Return true if there are no uses of this node.
1093 bool use_empty() const { return UseList == NULL; }
1095 /// hasOneUse - Return true if there is exactly one use of this node.
1097 bool hasOneUse() const {
1098 return !use_empty() && next(use_begin()) == use_end();
1101 /// use_size - Return the number of uses of this node. This method takes
1102 /// time proportional to the number of uses.
1104 size_t use_size() const { return std::distance(use_begin(), use_end()); }
1106 /// getNodeId - Return the unique node id.
1108 int getNodeId() const { return NodeId; }
1110 /// setNodeId - Set unique node id.
1111 void setNodeId(int Id) { NodeId = Id; }
1113 /// getDebugLoc - Return the source location info.
1114 const DebugLoc getDebugLoc() const { return debugLoc; }
1116 /// setDebugLoc - Set source location info. Try to avoid this, putting
1117 /// it in the constructor is preferable.
1118 void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
1120 /// use_iterator - This class provides iterator support for SDUse
1121 /// operands that use a specific SDNode.
1123 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
1125 explicit use_iterator(SDUse *op) : Op(op) {
1127 friend class SDNode;
1129 typedef std::iterator<std::forward_iterator_tag,
1130 SDUse, ptrdiff_t>::reference reference;
1131 typedef std::iterator<std::forward_iterator_tag,
1132 SDUse, ptrdiff_t>::pointer pointer;
1134 use_iterator(const use_iterator &I) : Op(I.Op) {}
1135 use_iterator() : Op(0) {}
1137 bool operator==(const use_iterator &x) const {
1140 bool operator!=(const use_iterator &x) const {
1141 return !operator==(x);
1144 /// atEnd - return true if this iterator is at the end of uses list.
1145 bool atEnd() const { return Op == 0; }
1147 // Iterator traversal: forward iteration only.
1148 use_iterator &operator++() { // Preincrement
1149 assert(Op && "Cannot increment end iterator!");
1154 use_iterator operator++(int) { // Postincrement
1155 use_iterator tmp = *this; ++*this; return tmp;
1158 /// Retrieve a pointer to the current user node.
1159 SDNode *operator*() const {
1160 assert(Op && "Cannot dereference end iterator!");
1161 return Op->getUser();
1164 SDNode *operator->() const { return operator*(); }
1166 SDUse &getUse() const { return *Op; }
1168 /// getOperandNo - Retrieve the operand # of this use in its user.
1170 unsigned getOperandNo() const {
1171 assert(Op && "Cannot dereference end iterator!");
1172 return (unsigned)(Op - Op->getUser()->OperandList);
1176 /// use_begin/use_end - Provide iteration support to walk over all uses
1179 use_iterator use_begin() const {
1180 return use_iterator(UseList);
1183 static use_iterator use_end() { return use_iterator(0); }
1186 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1187 /// indicated value. This method ignores uses of other values defined by this
1189 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1191 /// hasAnyUseOfValue - Return true if there are any use of the indicated
1192 /// value. This method ignores uses of other values defined by this operation.
1193 bool hasAnyUseOfValue(unsigned Value) const;
1195 /// isOnlyUserOf - Return true if this node is the only use of N.
1197 bool isOnlyUserOf(SDNode *N) const;
1199 /// isOperandOf - Return true if this node is an operand of N.
1201 bool isOperandOf(SDNode *N) const;
1203 /// isPredecessorOf - Return true if this node is a predecessor of N. This
1204 /// node is either an operand of N or it can be reached by recursively
1205 /// traversing up the operands.
1206 /// NOTE: this is an expensive method. Use it carefully.
1207 bool isPredecessorOf(SDNode *N) const;
1209 /// getNumOperands - Return the number of values used by this operation.
1211 unsigned getNumOperands() const { return NumOperands; }
1213 /// getConstantOperandVal - Helper method returns the integer value of a
1214 /// ConstantSDNode operand.
1215 uint64_t getConstantOperandVal(unsigned Num) const;
1217 const SDValue &getOperand(unsigned Num) const {
1218 assert(Num < NumOperands && "Invalid child # of SDNode!");
1219 return OperandList[Num];
1222 typedef SDUse* op_iterator;
1223 op_iterator op_begin() const { return OperandList; }
1224 op_iterator op_end() const { return OperandList+NumOperands; }
1226 SDVTList getVTList() const {
1227 SDVTList X = { ValueList, NumValues };
1231 /// getFlaggedNode - If this node has a flag operand, return the node
1232 /// to which the flag operand points. Otherwise return NULL.
1233 SDNode *getFlaggedNode() const {
1234 if (getNumOperands() != 0 &&
1235 getOperand(getNumOperands()-1).getValueType().getSimpleVT() == MVT::Flag)
1236 return getOperand(getNumOperands()-1).getNode();
1240 // If this is a pseudo op, like copyfromreg, look to see if there is a
1241 // real target node flagged to it. If so, return the target node.
1242 const SDNode *getFlaggedMachineNode() const {
1243 const SDNode *FoundNode = this;
1245 // Climb up flag edges until a machine-opcode node is found, or the
1246 // end of the chain is reached.
1247 while (!FoundNode->isMachineOpcode()) {
1248 const SDNode *N = FoundNode->getFlaggedNode();
1256 /// getNumValues - Return the number of values defined/returned by this
1259 unsigned getNumValues() const { return NumValues; }
1261 /// getValueType - Return the type of a specified result.
1263 EVT getValueType(unsigned ResNo) const {
1264 assert(ResNo < NumValues && "Illegal result number!");
1265 return ValueList[ResNo];
1268 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1270 unsigned getValueSizeInBits(unsigned ResNo) const {
1271 return getValueType(ResNo).getSizeInBits();
1274 typedef const EVT* value_iterator;
1275 value_iterator value_begin() const { return ValueList; }
1276 value_iterator value_end() const { return ValueList+NumValues; }
1278 /// getOperationName - Return the opcode of this operation for printing.
1280 std::string getOperationName(const SelectionDAG *G = 0) const;
1281 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1282 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
1283 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
1284 void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
1285 void printr(raw_ostream &OS, const SelectionDAG *G = 0) const;
1288 void dump(const SelectionDAG *G) const;
1289 void dumpr(const SelectionDAG *G) const;
1291 static bool classof(const SDNode *) { return true; }
1293 /// Profile - Gather unique data for the node.
1295 void Profile(FoldingSetNodeID &ID) const;
1297 /// addUse - This method should only be used by the SDUse class.
1299 void addUse(SDUse &U) { U.addToList(&UseList); }
1302 static SDVTList getSDVTList(EVT VT) {
1303 SDVTList Ret = { getValueTypeList(VT), 1 };
1307 SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops,
1309 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1311 OperandList(NumOps ? new SDUse[NumOps] : 0),
1312 ValueList(VTs.VTs), UseList(NULL),
1313 NumOperands(NumOps), NumValues(VTs.NumVTs),
1315 for (unsigned i = 0; i != NumOps; ++i) {
1316 OperandList[i].setUser(this);
1317 OperandList[i].setInitial(Ops[i]);
1321 /// This constructor adds no operands itself; operands can be
1322 /// set later with InitOperands.
1323 SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs)
1324 : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1325 NodeId(-1), OperandList(0), ValueList(VTs.VTs), UseList(NULL),
1326 NumOperands(0), NumValues(VTs.NumVTs),
1329 /// InitOperands - Initialize the operands list of this with 1 operand.
1330 void InitOperands(SDUse *Ops, const SDValue &Op0) {
1331 Ops[0].setUser(this);
1332 Ops[0].setInitial(Op0);
1337 /// InitOperands - Initialize the operands list of this with 2 operands.
1338 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
1339 Ops[0].setUser(this);
1340 Ops[0].setInitial(Op0);
1341 Ops[1].setUser(this);
1342 Ops[1].setInitial(Op1);
1347 /// InitOperands - Initialize the operands list of this with 3 operands.
1348 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
1349 const SDValue &Op2) {
1350 Ops[0].setUser(this);
1351 Ops[0].setInitial(Op0);
1352 Ops[1].setUser(this);
1353 Ops[1].setInitial(Op1);
1354 Ops[2].setUser(this);
1355 Ops[2].setInitial(Op2);
1360 /// InitOperands - Initialize the operands list of this with 4 operands.
1361 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
1362 const SDValue &Op2, const SDValue &Op3) {
1363 Ops[0].setUser(this);
1364 Ops[0].setInitial(Op0);
1365 Ops[1].setUser(this);
1366 Ops[1].setInitial(Op1);
1367 Ops[2].setUser(this);
1368 Ops[2].setInitial(Op2);
1369 Ops[3].setUser(this);
1370 Ops[3].setInitial(Op3);
1375 /// InitOperands - Initialize the operands list of this with N operands.
1376 void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
1377 for (unsigned i = 0; i != N; ++i) {
1378 Ops[i].setUser(this);
1379 Ops[i].setInitial(Vals[i]);
1385 /// DropOperands - Release the operands and set this node to have
1387 void DropOperands();
1391 // Define inline functions from the SDValue class.
1393 inline unsigned SDValue::getOpcode() const {
1394 return Node->getOpcode();
1396 inline EVT SDValue::getValueType() const {
1397 return Node->getValueType(ResNo);
1399 inline unsigned SDValue::getNumOperands() const {
1400 return Node->getNumOperands();
1402 inline const SDValue &SDValue::getOperand(unsigned i) const {
1403 return Node->getOperand(i);
1405 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1406 return Node->getConstantOperandVal(i);
1408 inline bool SDValue::isTargetOpcode() const {
1409 return Node->isTargetOpcode();
1411 inline bool SDValue::isTargetMemoryOpcode() const {
1412 return Node->isTargetMemoryOpcode();
1414 inline bool SDValue::isMachineOpcode() const {
1415 return Node->isMachineOpcode();
1417 inline unsigned SDValue::getMachineOpcode() const {
1418 return Node->getMachineOpcode();
1420 inline bool SDValue::use_empty() const {
1421 return !Node->hasAnyUseOfValue(ResNo);
1423 inline bool SDValue::hasOneUse() const {
1424 return Node->hasNUsesOfValue(1, ResNo);
1426 inline const DebugLoc SDValue::getDebugLoc() const {
1427 return Node->getDebugLoc();
1430 // Define inline functions from the SDUse class.
1432 inline void SDUse::set(const SDValue &V) {
1433 if (Val.getNode()) removeFromList();
1435 if (V.getNode()) V.getNode()->addUse(*this);
1438 inline void SDUse::setInitial(const SDValue &V) {
1440 V.getNode()->addUse(*this);
1443 inline void SDUse::setNode(SDNode *N) {
1444 if (Val.getNode()) removeFromList();
1446 if (N) N->addUse(*this);
1449 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1450 /// to allow co-allocation of node operands with the node itself.
1451 class UnarySDNode : public SDNode {
1454 UnarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X)
1455 : SDNode(Opc, dl, VTs) {
1456 InitOperands(&Op, X);
1460 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1461 /// to allow co-allocation of node operands with the node itself.
1462 class BinarySDNode : public SDNode {
1465 BinarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y)
1466 : SDNode(Opc, dl, VTs) {
1467 InitOperands(Ops, X, Y);
1471 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1472 /// to allow co-allocation of node operands with the node itself.
1473 class TernarySDNode : public SDNode {
1476 TernarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y,
1478 : SDNode(Opc, dl, VTs) {
1479 InitOperands(Ops, X, Y, Z);
1484 /// HandleSDNode - This class is used to form a handle around another node that
1485 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1486 /// operand. This node should be directly created by end-users and not added to
1487 /// the AllNodes list.
1488 class HandleSDNode : public SDNode {
1491 // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1494 explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
1496 explicit HandleSDNode(SDValue X)
1498 : SDNode(ISD::HANDLENODE, DebugLoc::getUnknownLoc(),
1499 getSDVTList(MVT::Other)) {
1500 InitOperands(&Op, X);
1503 const SDValue &getValue() const { return Op; }
1506 /// Abstact virtual class for operations for memory operations
1507 class MemSDNode : public SDNode {
1509 // MemoryVT - VT of in-memory value.
1513 /// MMO - Memory reference information.
1514 MachineMemOperand *MMO;
1517 MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, EVT MemoryVT,
1518 MachineMemOperand *MMO);
1520 MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, const SDValue *Ops,
1521 unsigned NumOps, EVT MemoryVT, MachineMemOperand *MMO);
1523 bool readMem() const { return MMO->isLoad(); }
1524 bool writeMem() const { return MMO->isStore(); }
1526 /// Returns alignment and volatility of the memory access
1527 unsigned getOriginalAlignment() const {
1528 return MMO->getBaseAlignment();
1530 unsigned getAlignment() const {
1531 return MMO->getAlignment();
1534 /// getRawSubclassData - Return the SubclassData value, which contains an
1535 /// encoding of the volatile flag, as well as bits used by subclasses. This
1536 /// function should only be used to compute a FoldingSetNodeID value.
1537 unsigned getRawSubclassData() const {
1538 return SubclassData;
1541 bool isVolatile() const { return (SubclassData >> 5) & 1; }
1543 /// Returns the SrcValue and offset that describes the location of the access
1544 const Value *getSrcValue() const { return MMO->getValue(); }
1545 int64_t getSrcValueOffset() const { return MMO->getOffset(); }
1547 /// getMemoryVT - Return the type of the in-memory value.
1548 EVT getMemoryVT() const { return MemoryVT; }
1550 /// getMemOperand - Return a MachineMemOperand object describing the memory
1551 /// reference performed by operation.
1552 MachineMemOperand *getMemOperand() const { return MMO; }
1554 /// refineAlignment - Update this MemSDNode's MachineMemOperand information
1555 /// to reflect the alignment of NewMMO, if it has a greater alignment.
1556 /// This must only be used when the new alignment applies to all users of
1557 /// this MachineMemOperand.
1558 void refineAlignment(const MachineMemOperand *NewMMO) {
1559 MMO->refineAlignment(NewMMO);
1562 const SDValue &getChain() const { return getOperand(0); }
1563 const SDValue &getBasePtr() const {
1564 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1567 // Methods to support isa and dyn_cast
1568 static bool classof(const MemSDNode *) { return true; }
1569 static bool classof(const SDNode *N) {
1570 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1571 // with either an intrinsic or a target opcode.
1572 return N->getOpcode() == ISD::LOAD ||
1573 N->getOpcode() == ISD::STORE ||
1574 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1575 N->getOpcode() == ISD::ATOMIC_SWAP ||
1576 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1577 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1578 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1579 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1580 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1581 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1582 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1583 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1584 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1585 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1586 N->isTargetMemoryOpcode();
1590 /// AtomicSDNode - A SDNode reprenting atomic operations.
1592 class AtomicSDNode : public MemSDNode {
1596 // Opc: opcode for atomic
1597 // VTL: value type list
1598 // Chain: memory chain for operaand
1599 // Ptr: address to update as a SDValue
1600 // Cmp: compare value
1602 // SrcVal: address to update as a Value (used for MemOperand)
1603 // Align: alignment of memory
1604 AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
1605 SDValue Chain, SDValue Ptr,
1606 SDValue Cmp, SDValue Swp, MachineMemOperand *MMO)
1607 : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
1608 assert(readMem() && "Atomic MachineMemOperand is not a load!");
1609 assert(writeMem() && "Atomic MachineMemOperand is not a store!");
1610 InitOperands(Ops, Chain, Ptr, Cmp, Swp);
1612 AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
1613 SDValue Chain, SDValue Ptr,
1614 SDValue Val, MachineMemOperand *MMO)
1615 : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
1616 assert(readMem() && "Atomic MachineMemOperand is not a load!");
1617 assert(writeMem() && "Atomic MachineMemOperand is not a store!");
1618 InitOperands(Ops, Chain, Ptr, Val);
1621 const SDValue &getBasePtr() const { return getOperand(1); }
1622 const SDValue &getVal() const { return getOperand(2); }
1624 bool isCompareAndSwap() const {
1625 unsigned Op = getOpcode();
1626 return Op == ISD::ATOMIC_CMP_SWAP;
1629 // Methods to support isa and dyn_cast
1630 static bool classof(const AtomicSDNode *) { return true; }
1631 static bool classof(const SDNode *N) {
1632 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1633 N->getOpcode() == ISD::ATOMIC_SWAP ||
1634 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1635 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1636 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1637 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1638 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1639 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1640 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1641 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1642 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1643 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1647 /// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
1648 /// memory and need an associated MachineMemOperand. Its opcode may be
1649 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, or a target-specific opcode with a
1650 /// value not less than FIRST_TARGET_MEMORY_OPCODE.
1651 class MemIntrinsicSDNode : public MemSDNode {
1653 MemIntrinsicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs,
1654 const SDValue *Ops, unsigned NumOps,
1655 EVT MemoryVT, MachineMemOperand *MMO)
1656 : MemSDNode(Opc, dl, VTs, Ops, NumOps, MemoryVT, MMO) {
1659 // Methods to support isa and dyn_cast
1660 static bool classof(const MemIntrinsicSDNode *) { return true; }
1661 static bool classof(const SDNode *N) {
1662 // We lower some target intrinsics to their target opcode
1663 // early a node with a target opcode can be of this class
1664 return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1665 N->getOpcode() == ISD::INTRINSIC_VOID ||
1666 N->isTargetMemoryOpcode();
1670 /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
1671 /// support for the llvm IR shufflevector instruction. It combines elements
1672 /// from two input vectors into a new input vector, with the selection and
1673 /// ordering of elements determined by an array of integers, referred to as
1674 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1675 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1676 /// An index of -1 is treated as undef, such that the code generator may put
1677 /// any value in the corresponding element of the result.
1678 class ShuffleVectorSDNode : public SDNode {
1681 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1682 // is freed when the SelectionDAG object is destroyed.
1685 friend class SelectionDAG;
1686 ShuffleVectorSDNode(EVT VT, DebugLoc dl, SDValue N1, SDValue N2,
1688 : SDNode(ISD::VECTOR_SHUFFLE, dl, getSDVTList(VT)), Mask(M) {
1689 InitOperands(Ops, N1, N2);
1693 void getMask(SmallVectorImpl<int> &M) const {
1694 EVT VT = getValueType(0);
1696 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i)
1697 M.push_back(Mask[i]);
1699 int getMaskElt(unsigned Idx) const {
1700 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1704 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1705 int getSplatIndex() const {
1706 assert(isSplat() && "Cannot get splat index for non-splat!");
1709 static bool isSplatMask(const int *Mask, EVT VT);
1711 static bool classof(const ShuffleVectorSDNode *) { return true; }
1712 static bool classof(const SDNode *N) {
1713 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1717 class ConstantSDNode : public SDNode {
1718 const ConstantInt *Value;
1719 friend class SelectionDAG;
1720 ConstantSDNode(bool isTarget, const ConstantInt *val, EVT VT)
1721 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1722 DebugLoc::getUnknownLoc(), getSDVTList(VT)), Value(val) {
1726 const ConstantInt *getConstantIntValue() const { return Value; }
1727 const APInt &getAPIntValue() const { return Value->getValue(); }
1728 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1729 int64_t getSExtValue() const { return Value->getSExtValue(); }
1731 bool isNullValue() const { return Value->isNullValue(); }
1732 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1734 static bool classof(const ConstantSDNode *) { return true; }
1735 static bool classof(const SDNode *N) {
1736 return N->getOpcode() == ISD::Constant ||
1737 N->getOpcode() == ISD::TargetConstant;
1741 class ConstantFPSDNode : public SDNode {
1742 const ConstantFP *Value;
1743 friend class SelectionDAG;
1744 ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1745 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1746 DebugLoc::getUnknownLoc(), getSDVTList(VT)), Value(val) {
1750 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1751 const ConstantFP *getConstantFPValue() const { return Value; }
1753 /// isExactlyValue - We don't rely on operator== working on double values, as
1754 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1755 /// As such, this method can be used to do an exact bit-for-bit comparison of
1756 /// two floating point values.
1758 /// We leave the version with the double argument here because it's just so
1759 /// convenient to write "2.0" and the like. Without this function we'd
1760 /// have to duplicate its logic everywhere it's called.
1761 bool isExactlyValue(double V) const {
1763 // convert is not supported on this type
1764 if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
1767 Tmp.convert(Value->getValueAPF().getSemantics(),
1768 APFloat::rmNearestTiesToEven, &ignored);
1769 return isExactlyValue(Tmp);
1771 bool isExactlyValue(const APFloat& V) const;
1773 bool isValueValidForType(EVT VT, const APFloat& Val);
1775 static bool classof(const ConstantFPSDNode *) { return true; }
1776 static bool classof(const SDNode *N) {
1777 return N->getOpcode() == ISD::ConstantFP ||
1778 N->getOpcode() == ISD::TargetConstantFP;
1782 class GlobalAddressSDNode : public SDNode {
1783 GlobalValue *TheGlobal;
1785 unsigned char TargetFlags;
1786 friend class SelectionDAG;
1787 GlobalAddressSDNode(unsigned Opc, const GlobalValue *GA, EVT VT,
1788 int64_t o, unsigned char TargetFlags);
1791 GlobalValue *getGlobal() const { return TheGlobal; }
1792 int64_t getOffset() const { return Offset; }
1793 unsigned char getTargetFlags() const { return TargetFlags; }
1794 // Return the address space this GlobalAddress belongs to.
1795 unsigned getAddressSpace() const;
1797 static bool classof(const GlobalAddressSDNode *) { return true; }
1798 static bool classof(const SDNode *N) {
1799 return N->getOpcode() == ISD::GlobalAddress ||
1800 N->getOpcode() == ISD::TargetGlobalAddress ||
1801 N->getOpcode() == ISD::GlobalTLSAddress ||
1802 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1806 class FrameIndexSDNode : public SDNode {
1808 friend class SelectionDAG;
1809 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1810 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1811 DebugLoc::getUnknownLoc(), getSDVTList(VT)), FI(fi) {
1815 int getIndex() const { return FI; }
1817 static bool classof(const FrameIndexSDNode *) { return true; }
1818 static bool classof(const SDNode *N) {
1819 return N->getOpcode() == ISD::FrameIndex ||
1820 N->getOpcode() == ISD::TargetFrameIndex;
1824 class JumpTableSDNode : public SDNode {
1826 unsigned char TargetFlags;
1827 friend class SelectionDAG;
1828 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1829 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1830 DebugLoc::getUnknownLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1834 int getIndex() const { return JTI; }
1835 unsigned char getTargetFlags() const { return TargetFlags; }
1837 static bool classof(const JumpTableSDNode *) { return true; }
1838 static bool classof(const SDNode *N) {
1839 return N->getOpcode() == ISD::JumpTable ||
1840 N->getOpcode() == ISD::TargetJumpTable;
1844 class ConstantPoolSDNode : public SDNode {
1847 MachineConstantPoolValue *MachineCPVal;
1849 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1850 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1851 unsigned char TargetFlags;
1852 friend class SelectionDAG;
1853 ConstantPoolSDNode(bool isTarget, Constant *c, EVT VT, int o, unsigned Align,
1855 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1856 DebugLoc::getUnknownLoc(),
1857 getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1858 assert((int)Offset >= 0 && "Offset is too large");
1861 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1862 EVT VT, int o, unsigned Align, unsigned char TF)
1863 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1864 DebugLoc::getUnknownLoc(),
1865 getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1866 assert((int)Offset >= 0 && "Offset is too large");
1867 Val.MachineCPVal = v;
1868 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1873 bool isMachineConstantPoolEntry() const {
1874 return (int)Offset < 0;
1877 Constant *getConstVal() const {
1878 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1879 return Val.ConstVal;
1882 MachineConstantPoolValue *getMachineCPVal() const {
1883 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1884 return Val.MachineCPVal;
1887 int getOffset() const {
1888 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1891 // Return the alignment of this constant pool object, which is either 0 (for
1892 // default alignment) or the desired value.
1893 unsigned getAlignment() const { return Alignment; }
1894 unsigned char getTargetFlags() const { return TargetFlags; }
1896 const Type *getType() const;
1898 static bool classof(const ConstantPoolSDNode *) { return true; }
1899 static bool classof(const SDNode *N) {
1900 return N->getOpcode() == ISD::ConstantPool ||
1901 N->getOpcode() == ISD::TargetConstantPool;
1905 class BasicBlockSDNode : public SDNode {
1906 MachineBasicBlock *MBB;
1907 friend class SelectionDAG;
1908 /// Debug info is meaningful and potentially useful here, but we create
1909 /// blocks out of order when they're jumped to, which makes it a bit
1910 /// harder. Let's see if we need it first.
1911 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1912 : SDNode(ISD::BasicBlock, DebugLoc::getUnknownLoc(),
1913 getSDVTList(MVT::Other)), MBB(mbb) {
1917 MachineBasicBlock *getBasicBlock() const { return MBB; }
1919 static bool classof(const BasicBlockSDNode *) { return true; }
1920 static bool classof(const SDNode *N) {
1921 return N->getOpcode() == ISD::BasicBlock;
1925 /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
1927 class BuildVectorSDNode : public SDNode {
1928 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1929 explicit BuildVectorSDNode(); // Do not implement
1931 /// isConstantSplat - Check if this is a constant splat, and if so, find the
1932 /// smallest element size that splats the vector. If MinSplatBits is
1933 /// nonzero, the element size must be at least that large. Note that the
1934 /// splat element may be the entire vector (i.e., a one element vector).
1935 /// Returns the splat element value in SplatValue. Any undefined bits in
1936 /// that value are zero, and the corresponding bits in the SplatUndef mask
1937 /// are set. The SplatBitSize value is set to the splat element size in
1938 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1939 /// undefined. isBigEndian describes the endianness of the target.
1940 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1941 unsigned &SplatBitSize, bool &HasAnyUndefs,
1942 unsigned MinSplatBits = 0, bool isBigEndian = false);
1944 static inline bool classof(const BuildVectorSDNode *) { return true; }
1945 static inline bool classof(const SDNode *N) {
1946 return N->getOpcode() == ISD::BUILD_VECTOR;
1950 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1951 /// used when the SelectionDAG needs to make a simple reference to something
1952 /// in the LLVM IR representation.
1954 class SrcValueSDNode : public SDNode {
1956 friend class SelectionDAG;
1957 /// Create a SrcValue for a general value.
1958 explicit SrcValueSDNode(const Value *v)
1959 : SDNode(ISD::SRCVALUE, DebugLoc::getUnknownLoc(),
1960 getSDVTList(MVT::Other)), V(v) {}
1963 /// getValue - return the contained Value.
1964 const Value *getValue() const { return V; }
1966 static bool classof(const SrcValueSDNode *) { return true; }
1967 static bool classof(const SDNode *N) {
1968 return N->getOpcode() == ISD::SRCVALUE;
1973 class RegisterSDNode : public SDNode {
1975 friend class SelectionDAG;
1976 RegisterSDNode(unsigned reg, EVT VT)
1977 : SDNode(ISD::Register, DebugLoc::getUnknownLoc(),
1978 getSDVTList(VT)), Reg(reg) {
1982 unsigned getReg() const { return Reg; }
1984 static bool classof(const RegisterSDNode *) { return true; }
1985 static bool classof(const SDNode *N) {
1986 return N->getOpcode() == ISD::Register;
1990 class BlockAddressSDNode : public SDNode {
1992 unsigned char TargetFlags;
1993 friend class SelectionDAG;
1994 BlockAddressSDNode(unsigned NodeTy, EVT VT, BlockAddress *ba,
1995 unsigned char Flags)
1996 : SDNode(NodeTy, DebugLoc::getUnknownLoc(), getSDVTList(VT)),
1997 BA(ba), TargetFlags(Flags) {
2000 BlockAddress *getBlockAddress() const { return BA; }
2001 unsigned char getTargetFlags() const { return TargetFlags; }
2003 static bool classof(const BlockAddressSDNode *) { return true; }
2004 static bool classof(const SDNode *N) {
2005 return N->getOpcode() == ISD::BlockAddress ||
2006 N->getOpcode() == ISD::TargetBlockAddress;
2010 class LabelSDNode : public SDNode {
2013 friend class SelectionDAG;
2014 LabelSDNode(unsigned NodeTy, DebugLoc dl, SDValue ch, unsigned id)
2015 : SDNode(NodeTy, dl, getSDVTList(MVT::Other)), LabelID(id) {
2016 InitOperands(&Chain, ch);
2019 unsigned getLabelID() const { return LabelID; }
2021 static bool classof(const LabelSDNode *) { return true; }
2022 static bool classof(const SDNode *N) {
2023 return N->getOpcode() == ISD::EH_LABEL;
2027 class ExternalSymbolSDNode : public SDNode {
2029 unsigned char TargetFlags;
2031 friend class SelectionDAG;
2032 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
2033 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
2034 DebugLoc::getUnknownLoc(),
2035 getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
2039 const char *getSymbol() const { return Symbol; }
2040 unsigned char getTargetFlags() const { return TargetFlags; }
2042 static bool classof(const ExternalSymbolSDNode *) { return true; }
2043 static bool classof(const SDNode *N) {
2044 return N->getOpcode() == ISD::ExternalSymbol ||
2045 N->getOpcode() == ISD::TargetExternalSymbol;
2049 class CondCodeSDNode : public SDNode {
2050 ISD::CondCode Condition;
2051 friend class SelectionDAG;
2052 explicit CondCodeSDNode(ISD::CondCode Cond)
2053 : SDNode(ISD::CONDCODE, DebugLoc::getUnknownLoc(),
2054 getSDVTList(MVT::Other)), Condition(Cond) {
2058 ISD::CondCode get() const { return Condition; }
2060 static bool classof(const CondCodeSDNode *) { return true; }
2061 static bool classof(const SDNode *N) {
2062 return N->getOpcode() == ISD::CONDCODE;
2066 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
2067 /// future and most targets don't support it.
2068 class CvtRndSatSDNode : public SDNode {
2069 ISD::CvtCode CvtCode;
2070 friend class SelectionDAG;
2071 explicit CvtRndSatSDNode(EVT VT, DebugLoc dl, const SDValue *Ops,
2072 unsigned NumOps, ISD::CvtCode Code)
2073 : SDNode(ISD::CONVERT_RNDSAT, dl, getSDVTList(VT), Ops, NumOps),
2075 assert(NumOps == 5 && "wrong number of operations");
2078 ISD::CvtCode getCvtCode() const { return CvtCode; }
2080 static bool classof(const CvtRndSatSDNode *) { return true; }
2081 static bool classof(const SDNode *N) {
2082 return N->getOpcode() == ISD::CONVERT_RNDSAT;
2089 static const uint64_t NoFlagSet = 0ULL;
2090 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
2091 static const uint64_t ZExtOffs = 0;
2092 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
2093 static const uint64_t SExtOffs = 1;
2094 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
2095 static const uint64_t InRegOffs = 2;
2096 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
2097 static const uint64_t SRetOffs = 3;
2098 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
2099 static const uint64_t ByValOffs = 4;
2100 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
2101 static const uint64_t NestOffs = 5;
2102 static const uint64_t ByValAlign = 0xFULL << 6; //< Struct alignment
2103 static const uint64_t ByValAlignOffs = 6;
2104 static const uint64_t Split = 1ULL << 10;
2105 static const uint64_t SplitOffs = 10;
2106 static const uint64_t OrigAlign = 0x1FULL<<27;
2107 static const uint64_t OrigAlignOffs = 27;
2108 static const uint64_t ByValSize = 0xffffffffULL << 32; //< Struct size
2109 static const uint64_t ByValSizeOffs = 32;
2111 static const uint64_t One = 1ULL; //< 1 of this type, for shifts
2115 ArgFlagsTy() : Flags(0) { }
2117 bool isZExt() const { return Flags & ZExt; }
2118 void setZExt() { Flags |= One << ZExtOffs; }
2120 bool isSExt() const { return Flags & SExt; }
2121 void setSExt() { Flags |= One << SExtOffs; }
2123 bool isInReg() const { return Flags & InReg; }
2124 void setInReg() { Flags |= One << InRegOffs; }
2126 bool isSRet() const { return Flags & SRet; }
2127 void setSRet() { Flags |= One << SRetOffs; }
2129 bool isByVal() const { return Flags & ByVal; }
2130 void setByVal() { Flags |= One << ByValOffs; }
2132 bool isNest() const { return Flags & Nest; }
2133 void setNest() { Flags |= One << NestOffs; }
2135 unsigned getByValAlign() const {
2137 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
2139 void setByValAlign(unsigned A) {
2140 Flags = (Flags & ~ByValAlign) |
2141 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
2144 bool isSplit() const { return Flags & Split; }
2145 void setSplit() { Flags |= One << SplitOffs; }
2147 unsigned getOrigAlign() const {
2149 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
2151 void setOrigAlign(unsigned A) {
2152 Flags = (Flags & ~OrigAlign) |
2153 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
2156 unsigned getByValSize() const {
2157 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
2159 void setByValSize(unsigned S) {
2160 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
2163 /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
2164 std::string getArgFlagsString();
2166 /// getRawBits - Represent the flags as a bunch of bits.
2167 uint64_t getRawBits() const { return Flags; }
2170 /// InputArg - This struct carries flags and type information about a
2171 /// single incoming (formal) argument or incoming (from the perspective
2172 /// of the caller) return value virtual register.
2179 InputArg() : VT(MVT::Other), Used(false) {}
2180 InputArg(ISD::ArgFlagsTy flags, EVT vt, bool used)
2181 : Flags(flags), VT(vt), Used(used) {
2182 assert(VT.isSimple() &&
2183 "InputArg value type must be Simple!");
2187 /// OutputArg - This struct carries flags and a value for a
2188 /// single outgoing (actual) argument or outgoing (from the perspective
2189 /// of the caller) return value virtual register.
2196 OutputArg() : IsFixed(false) {}
2197 OutputArg(ISD::ArgFlagsTy flags, SDValue val, bool isfixed)
2198 : Flags(flags), Val(val), IsFixed(isfixed) {
2199 assert(Val.getValueType().isSimple() &&
2200 "OutputArg value type must be Simple!");
2205 /// VTSDNode - This class is used to represent EVT's, which are used
2206 /// to parameterize some operations.
2207 class VTSDNode : public SDNode {
2209 friend class SelectionDAG;
2210 explicit VTSDNode(EVT VT)
2211 : SDNode(ISD::VALUETYPE, DebugLoc::getUnknownLoc(),
2212 getSDVTList(MVT::Other)), ValueType(VT) {
2216 EVT getVT() const { return ValueType; }
2218 static bool classof(const VTSDNode *) { return true; }
2219 static bool classof(const SDNode *N) {
2220 return N->getOpcode() == ISD::VALUETYPE;
2224 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
2226 class LSBaseSDNode : public MemSDNode {
2227 //! Operand array for load and store
2229 \note Moving this array to the base class captures more
2230 common functionality shared between LoadSDNode and
2235 LSBaseSDNode(ISD::NodeType NodeTy, DebugLoc dl, SDValue *Operands,
2236 unsigned numOperands, SDVTList VTs, ISD::MemIndexedMode AM,
2237 EVT MemVT, MachineMemOperand *MMO)
2238 : MemSDNode(NodeTy, dl, VTs, MemVT, MMO) {
2239 SubclassData |= AM << 2;
2240 assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
2241 InitOperands(Ops, Operands, numOperands);
2242 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
2243 "Only indexed loads and stores have a non-undef offset operand");
2246 const SDValue &getOffset() const {
2247 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2250 /// getAddressingMode - Return the addressing mode for this load or store:
2251 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2252 ISD::MemIndexedMode getAddressingMode() const {
2253 return ISD::MemIndexedMode((SubclassData >> 2) & 7);
2256 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
2257 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2259 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
2260 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2262 static bool classof(const LSBaseSDNode *) { return true; }
2263 static bool classof(const SDNode *N) {
2264 return N->getOpcode() == ISD::LOAD ||
2265 N->getOpcode() == ISD::STORE;
2269 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2271 class LoadSDNode : public LSBaseSDNode {
2272 friend class SelectionDAG;
2273 LoadSDNode(SDValue *ChainPtrOff, DebugLoc dl, SDVTList VTs,
2274 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
2275 MachineMemOperand *MMO)
2276 : LSBaseSDNode(ISD::LOAD, dl, ChainPtrOff, 3,
2277 VTs, AM, MemVT, MMO) {
2278 SubclassData |= (unsigned short)ETy;
2279 assert(getExtensionType() == ETy && "LoadExtType encoding error!");
2280 assert(readMem() && "Load MachineMemOperand is not a load!");
2281 assert(!writeMem() && "Load MachineMemOperand is a store!");
2285 /// getExtensionType - Return whether this is a plain node,
2286 /// or one of the varieties of value-extending loads.
2287 ISD::LoadExtType getExtensionType() const {
2288 return ISD::LoadExtType(SubclassData & 3);
2291 const SDValue &getBasePtr() const { return getOperand(1); }
2292 const SDValue &getOffset() const { return getOperand(2); }
2294 static bool classof(const LoadSDNode *) { return true; }
2295 static bool classof(const SDNode *N) {
2296 return N->getOpcode() == ISD::LOAD;
2300 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2302 class StoreSDNode : public LSBaseSDNode {
2303 friend class SelectionDAG;
2304 StoreSDNode(SDValue *ChainValuePtrOff, DebugLoc dl, SDVTList VTs,
2305 ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
2306 MachineMemOperand *MMO)
2307 : LSBaseSDNode(ISD::STORE, dl, ChainValuePtrOff, 4,
2308 VTs, AM, MemVT, MMO) {
2309 SubclassData |= (unsigned short)isTrunc;
2310 assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
2311 assert(!readMem() && "Store MachineMemOperand is a load!");
2312 assert(writeMem() && "Store MachineMemOperand is not a store!");
2316 /// isTruncatingStore - Return true if the op does a truncation before store.
2317 /// For integers this is the same as doing a TRUNCATE and storing the result.
2318 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2319 bool isTruncatingStore() const { return SubclassData & 1; }
2321 const SDValue &getValue() const { return getOperand(1); }
2322 const SDValue &getBasePtr() const { return getOperand(2); }
2323 const SDValue &getOffset() const { return getOperand(3); }
2325 static bool classof(const StoreSDNode *) { return true; }
2326 static bool classof(const SDNode *N) {
2327 return N->getOpcode() == ISD::STORE;
2331 /// MachineSDNode - An SDNode that represents everything that will be needed
2332 /// to construct a MachineInstr. These nodes are created during the
2333 /// instruction selection proper phase.
2335 class MachineSDNode : public SDNode {
2337 typedef MachineMemOperand **mmo_iterator;
2340 friend class SelectionDAG;
2341 MachineSDNode(unsigned Opc, const DebugLoc DL, SDVTList VTs)
2342 : SDNode(Opc, DL, VTs), MemRefs(0), MemRefsEnd(0) {}
2344 /// LocalOperands - Operands for this instruction, if they fit here. If
2345 /// they don't, this field is unused.
2346 SDUse LocalOperands[4];
2348 /// MemRefs - Memory reference descriptions for this instruction.
2349 mmo_iterator MemRefs;
2350 mmo_iterator MemRefsEnd;
2353 mmo_iterator memoperands_begin() const { return MemRefs; }
2354 mmo_iterator memoperands_end() const { return MemRefsEnd; }
2355 bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
2357 /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
2358 /// list. This does not transfer ownership.
2359 void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
2360 MemRefs = NewMemRefs;
2361 MemRefsEnd = NewMemRefsEnd;
2364 static bool classof(const MachineSDNode *) { return true; }
2365 static bool classof(const SDNode *N) {
2366 return N->isMachineOpcode();
2370 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2371 SDNode, ptrdiff_t> {
2375 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2377 bool operator==(const SDNodeIterator& x) const {
2378 return Operand == x.Operand;
2380 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2382 const SDNodeIterator &operator=(const SDNodeIterator &I) {
2383 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2384 Operand = I.Operand;
2388 pointer operator*() const {
2389 return Node->getOperand(Operand).getNode();
2391 pointer operator->() const { return operator*(); }
2393 SDNodeIterator& operator++() { // Preincrement
2397 SDNodeIterator operator++(int) { // Postincrement
2398 SDNodeIterator tmp = *this; ++*this; return tmp;
2400 size_t operator-(SDNodeIterator Other) const {
2401 assert(Node == Other.Node &&
2402 "Cannot compare iterators of two different nodes!");
2403 return Operand - Other.Operand;
2406 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2407 static SDNodeIterator end (SDNode *N) {
2408 return SDNodeIterator(N, N->getNumOperands());
2411 unsigned getOperand() const { return Operand; }
2412 const SDNode *getNode() const { return Node; }
2415 template <> struct GraphTraits<SDNode*> {
2416 typedef SDNode NodeType;
2417 typedef SDNodeIterator ChildIteratorType;
2418 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2419 static inline ChildIteratorType child_begin(NodeType *N) {
2420 return SDNodeIterator::begin(N);
2422 static inline ChildIteratorType child_end(NodeType *N) {
2423 return SDNodeIterator::end(N);
2427 /// LargestSDNode - The largest SDNode class.
2429 typedef LoadSDNode LargestSDNode;
2431 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2434 typedef GlobalAddressSDNode MostAlignedSDNode;
2437 /// isNormalLoad - Returns true if the specified node is a non-extending
2438 /// and unindexed load.
2439 inline bool isNormalLoad(const SDNode *N) {
2440 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2441 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2442 Ld->getAddressingMode() == ISD::UNINDEXED;
2445 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2447 inline bool isNON_EXTLoad(const SDNode *N) {
2448 return isa<LoadSDNode>(N) &&
2449 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2452 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2454 inline bool isEXTLoad(const SDNode *N) {
2455 return isa<LoadSDNode>(N) &&
2456 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2459 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2461 inline bool isSEXTLoad(const SDNode *N) {
2462 return isa<LoadSDNode>(N) &&
2463 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2466 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2468 inline bool isZEXTLoad(const SDNode *N) {
2469 return isa<LoadSDNode>(N) &&
2470 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2473 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2475 inline bool isUNINDEXEDLoad(const SDNode *N) {
2476 return isa<LoadSDNode>(N) &&
2477 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2480 /// isNormalStore - Returns true if the specified node is a non-truncating
2481 /// and unindexed store.
2482 inline bool isNormalStore(const SDNode *N) {
2483 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2484 return St && !St->isTruncatingStore() &&
2485 St->getAddressingMode() == ISD::UNINDEXED;
2488 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2490 inline bool isNON_TRUNCStore(const SDNode *N) {
2491 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2494 /// isTRUNCStore - Returns true if the specified node is a truncating
2496 inline bool isTRUNCStore(const SDNode *N) {
2497 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2500 /// isUNINDEXEDStore - Returns true if the specified node is an
2501 /// unindexed store.
2502 inline bool isUNINDEXEDStore(const SDNode *N) {
2503 return isa<StoreSDNode>(N) &&
2504 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2509 } // end llvm namespace