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/Allocator.h"
31 #include "llvm/Support/MathExtras.h"
32 #include "llvm/Support/RecyclingAllocator.h"
33 #include "llvm/Support/DataTypes.h"
34 #include "llvm/Support/DebugLoc.h"
42 class MachineBasicBlock;
43 class MachineConstantPoolValue;
46 template <typename T> struct DenseMapInfo;
47 template <typename T> struct simplify_type;
48 template <typename T> struct ilist_traits;
50 /// SDVTList - This represents a list of ValueType's that has been intern'd by
51 /// a SelectionDAG. Instances of this simple value class are returned by
52 /// SelectionDAG::getVTList(...).
59 /// ISD namespace - This namespace contains an enum which represents all of the
60 /// SelectionDAG node types and value types.
64 //===--------------------------------------------------------------------===//
65 /// ISD::NodeType enum - This enum defines the target-independent operators
66 /// for a SelectionDAG.
68 /// Targets may also define target-dependent operator codes for SDNodes. For
69 /// example, on x86, these are the enum values in the X86ISD namespace.
70 /// Targets should aim to use target-independent operators to model their
71 /// instruction sets as much as possible, and only use target-dependent
72 /// operators when they have special requirements.
74 /// Finally, during and after selection proper, SNodes may use special
75 /// operator codes that correspond directly with MachineInstr opcodes. These
76 /// are used to represent selected instructions. See the isMachineOpcode()
77 /// and getMachineOpcode() member functions of SDNode.
80 // DELETED_NODE - This is an illegal value that is used to catch
81 // errors. This opcode is not a legal opcode for any node.
84 // EntryToken - This is the marker used to indicate the start of the region.
87 // TokenFactor - This node takes multiple tokens as input and produces a
88 // single token result. This is used to represent the fact that the operand
89 // operators are independent of each other.
92 // AssertSext, AssertZext - These nodes record if a register contains a
93 // value that has already been zero or sign extended from a narrower type.
94 // These nodes take two operands. The first is the node that has already
95 // been extended, and the second is a value type node indicating the width
97 AssertSext, AssertZext,
99 // Various leaf nodes.
100 BasicBlock, VALUETYPE, CONDCODE, Register,
101 Constant, ConstantFP,
102 GlobalAddress, GlobalTLSAddress, FrameIndex,
103 JumpTable, ConstantPool, ExternalSymbol,
105 // The address of the GOT
108 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
109 // llvm.returnaddress on the DAG. These nodes take one operand, the index
110 // of the frame or return address to return. An index of zero corresponds
111 // to the current function's frame or return address, an index of one to the
112 // parent's frame or return address, and so on.
113 FRAMEADDR, RETURNADDR,
115 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
116 // first (possible) on-stack argument. This is needed for correct stack
117 // adjustment during unwind.
118 FRAME_TO_ARGS_OFFSET,
120 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
121 // address of the exception block on entry to an landing pad block.
124 // RESULT, OUTCHAIN = LSDAADDR(INCHAIN) - This node represents the
125 // address of the Language Specific Data Area for the enclosing function.
128 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
129 // the selection index of the exception thrown.
132 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
133 // 'eh_return' gcc dwarf builtin, which is used to return from
134 // exception. The general meaning is: adjust stack by OFFSET and pass
135 // execution to HANDLER. Many platform-related details also :)
138 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
139 // simplification of the constant.
143 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
144 // anything else with this node, and this is valid in the target-specific
145 // dag, turning into a GlobalAddress operand.
147 TargetGlobalTLSAddress,
151 TargetExternalSymbol,
153 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
154 /// This node represents a target intrinsic function with no side effects.
155 /// The first operand is the ID number of the intrinsic from the
156 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
157 /// node has returns the result of the intrinsic.
160 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
161 /// This node represents a target intrinsic function with side effects that
162 /// returns a result. The first operand is a chain pointer. The second is
163 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
164 /// operands to the intrinsic follow. The node has two results, the result
165 /// of the intrinsic and an output chain.
168 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
169 /// This node represents a target intrinsic function with side effects that
170 /// does not return a result. The first operand is a chain pointer. The
171 /// second is the ID number of the intrinsic from the llvm::Intrinsic
172 /// namespace. The operands to the intrinsic follow.
175 // CopyToReg - This node has three operands: a chain, a register number to
176 // set to this value, and a value.
179 // CopyFromReg - This node indicates that the input value is a virtual or
180 // physical register that is defined outside of the scope of this
181 // SelectionDAG. The register is available from the RegisterSDNode object.
184 // UNDEF - An undefined node
187 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
188 // a Constant, which is required to be operand #1) half of the integer or
189 // float value specified as operand #0. This is only for use before
190 // legalization, for values that will be broken into multiple registers.
193 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
194 // two values of the same integer value type, this produces a value twice as
195 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
198 // MERGE_VALUES - This node takes multiple discrete operands and returns
199 // them all as its individual results. This nodes has exactly the same
200 // number of inputs and outputs. This node is useful for some pieces of the
201 // code generator that want to think about a single node with multiple
202 // results, not multiple nodes.
205 // Simple integer binary arithmetic operators.
206 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
208 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
209 // a signed/unsigned value of type i[2*N], and return the full value as
210 // two results, each of type iN.
211 SMUL_LOHI, UMUL_LOHI,
213 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
217 // CARRY_FALSE - This node is used when folding other nodes,
218 // like ADDC/SUBC, which indicate the carry result is always false.
221 // Carry-setting nodes for multiple precision addition and subtraction.
222 // These nodes take two operands of the same value type, and produce two
223 // results. The first result is the normal add or sub result, the second
224 // result is the carry flag result.
227 // Carry-using nodes for multiple precision addition and subtraction. These
228 // nodes take three operands: The first two are the normal lhs and rhs to
229 // the add or sub, and the third is the input carry flag. These nodes
230 // produce two results; the normal result of the add or sub, and the output
231 // carry flag. These nodes both read and write a carry flag to allow them
232 // to them to be chained together for add and sub of arbitrarily large
236 // RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
237 // These nodes take two operands: the normal LHS and RHS to the add. They
238 // produce two results: the normal result of the add, and a boolean that
239 // indicates if an overflow occured (*not* a flag, because it may be stored
240 // to memory, etc.). If the type of the boolean is not i1 then the high
241 // bits conform to getBooleanContents.
242 // These nodes are generated from the llvm.[su]add.with.overflow intrinsics.
245 // Same for subtraction
248 // Same for multiplication
251 // Simple binary floating point operators.
252 FADD, FSUB, FMUL, FDIV, FREM,
254 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
255 // DAG node does not require that X and Y have the same type, just that they
256 // are both floating point. X and the result must have the same type.
257 // FCOPYSIGN(f32, f64) is allowed.
260 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
261 // value as an integer 0/1 value.
264 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the
265 /// specified, possibly variable, elements. The number of elements is
266 /// required to be a power of two. The types of the operands must all be
267 /// the same and must match the vector element type, except that integer
268 /// types are allowed to be larger than the element type, in which case
269 /// the operands are implicitly truncated.
272 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
273 /// at IDX replaced with VAL. If the type of VAL is larger than the vector
274 /// element type then VAL is truncated before replacement.
277 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
278 /// identified by the (potentially variable) element number IDX. If the
279 /// return type is an integer type larger than the element type of the
280 /// vector, the result is extended to the width of the return type.
283 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
284 /// vector type with the same length and element type, this produces a
285 /// concatenated vector result value, with length equal to the sum of the
286 /// lengths of the input vectors.
289 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
290 /// vector value) starting with the (potentially variable) element number
291 /// IDX, which must be a multiple of the result vector length.
294 /// VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as
295 /// VEC1/VEC2. A VECTOR_SHUFFLE node also contains an array of constant int
296 /// values that indicate which value (or undef) each result element will
297 /// get. These constant ints are accessible through the
298 /// ShuffleVectorSDNode class. This is quite similar to the Altivec
299 /// 'vperm' instruction, except that the indices must be constants and are
300 /// in terms of the element size of VEC1/VEC2, not in terms of bytes.
303 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
304 /// scalar value into element 0 of the resultant vector type. The top
305 /// elements 1 to N-1 of the N-element vector are undefined. The type
306 /// of the operand must match the vector element type, except when they
307 /// are integer types. In this case the operand is allowed to be wider
308 /// than the vector element type, and is implicitly truncated to it.
311 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
312 // an unsigned/signed value of type i[2*N], then return the top part.
315 // Bitwise operators - logical and, logical or, logical xor, shift left,
316 // shift right algebraic (shift in sign bits), shift right logical (shift in
317 // zeroes), rotate left, rotate right, and byteswap.
318 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
320 // Counting operators
323 // Select(COND, TRUEVAL, FALSEVAL). If the type of the boolean COND is not
324 // i1 then the high bits must conform to getBooleanContents.
327 // Select with condition operator - This selects between a true value and
328 // a false value (ops #2 and #3) based on the boolean result of comparing
329 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
330 // condition code in op #4, a CondCodeSDNode.
333 // SetCC operator - This evaluates to a true value iff the condition is
334 // true. If the result value type is not i1 then the high bits conform
335 // to getBooleanContents. The operands to this are the left and right
336 // operands to compare (ops #0, and #1) and the condition code to compare
337 // them with (op #2) as a CondCodeSDNode.
340 // RESULT = VSETCC(LHS, RHS, COND) operator - This evaluates to a vector of
341 // integer elements with all bits of the result elements set to true if the
342 // comparison is true or all cleared if the comparison is false. The
343 // operands to this are the left and right operands to compare (LHS/RHS) and
344 // the condition code to compare them with (COND) as a CondCodeSDNode.
347 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
348 // integer shift operations, just like ADD/SUB_PARTS. The operation
350 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
351 SHL_PARTS, SRA_PARTS, SRL_PARTS,
353 // Conversion operators. These are all single input single output
354 // operations. For all of these, the result type must be strictly
355 // wider or narrower (depending on the operation) than the source
358 // SIGN_EXTEND - Used for integer types, replicating the sign bit
362 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
365 // ANY_EXTEND - Used for integer types. The high bits are undefined.
368 // TRUNCATE - Completely drop the high bits.
371 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
372 // depends on the first letter) to floating point.
376 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
377 // sign extend a small value in a large integer register (e.g. sign
378 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
379 // with the 7th bit). The size of the smaller type is indicated by the 1th
380 // operand, a ValueType node.
383 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
388 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
389 /// down to the precision of the destination VT. TRUNC is a flag, which is
390 /// always an integer that is zero or one. If TRUNC is 0, this is a
391 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
394 /// The TRUNC = 1 case is used in cases where we know that the value will
395 /// not be modified by the node, because Y is not using any of the extra
396 /// precision of source type. This allows certain transformations like
397 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
398 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
401 // FLT_ROUNDS_ - Returns current rounding mode:
404 // 1 Round to nearest
409 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
410 /// rounds it to a floating point value. It then promotes it and returns it
411 /// in a register of the same size. This operation effectively just
412 /// discards excess precision. The type to round down to is specified by
413 /// the VT operand, a VTSDNode.
416 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
419 // BIT_CONVERT - Theis operator converts between integer and FP values, as
420 // if one was stored to memory as integer and the other was loaded from the
421 // same address (or equivalently for vector format conversions, etc). The
422 // source and result are required to have the same bit size (e.g.
423 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
424 // conversions, but that is a noop, deleted by getNode().
427 // CONVERT_RNDSAT - This operator is used to support various conversions
428 // between various types (float, signed, unsigned and vectors of those
429 // types) with rounding and saturation. NOTE: Avoid using this operator as
430 // most target don't support it and the operator might be removed in the
431 // future. It takes the following arguments:
433 // 1) dest type (type to convert to)
434 // 2) src type (type to convert from)
437 // 5) ISD::CvtCode indicating the type of conversion to do
440 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
441 // FLOG, FLOG2, FLOG10, FEXP, FEXP2,
442 // FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary floating
443 // point operations. These are inspired by libm.
444 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
445 FLOG, FLOG2, FLOG10, FEXP, FEXP2,
446 FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR,
448 // LOAD and STORE have token chains as their first operand, then the same
449 // operands as an LLVM load/store instruction, then an offset node that
450 // is added / subtracted from the base pointer to form the address (for
451 // indexed memory ops).
454 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
455 // to a specified boundary. This node always has two return values: a new
456 // stack pointer value and a chain. The first operand is the token chain,
457 // the second is the number of bytes to allocate, and the third is the
458 // alignment boundary. The size is guaranteed to be a multiple of the stack
459 // alignment, and the alignment is guaranteed to be bigger than the stack
460 // alignment (if required) or 0 to get standard stack alignment.
463 // Control flow instructions. These all have token chains.
465 // BR - Unconditional branch. The first operand is the chain
466 // operand, the second is the MBB to branch to.
469 // BRIND - Indirect branch. The first operand is the chain, the second
470 // is the value to branch to, which must be of the same type as the target's
474 // BR_JT - Jumptable branch. The first operand is the chain, the second
475 // is the jumptable index, the last one is the jumptable entry index.
478 // BRCOND - Conditional branch. The first operand is the chain, the
479 // second is the condition, the third is the block to branch to if the
480 // condition is true. If the type of the condition is not i1, then the
481 // high bits must conform to getBooleanContents.
484 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
485 // that the condition is represented as condition code, and two nodes to
486 // compare, rather than as a combined SetCC node. The operands in order are
487 // chain, cc, lhs, rhs, block to branch to if condition is true.
490 // INLINEASM - Represents an inline asm block. This node always has two
491 // return values: a chain and a flag result. The inputs are as follows:
492 // Operand #0 : Input chain.
493 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
494 // Operand #2n+2: A RegisterNode.
495 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
496 // Operand #last: Optional, an incoming flag.
499 // DBG_LABEL, EH_LABEL - Represents a label in mid basic block used to track
500 // locations needed for debug and exception handling tables. These nodes
501 // take a chain as input and return a chain.
505 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
506 // value, the same type as the pointer type for the system, and an output
510 // STACKRESTORE has two operands, an input chain and a pointer to restore to
511 // it returns an output chain.
514 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
515 // a call sequence, and carry arbitrary information that target might want
516 // to know. The first operand is a chain, the rest are specified by the
517 // target and not touched by the DAG optimizers.
518 // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
519 CALLSEQ_START, // Beginning of a call sequence
520 CALLSEQ_END, // End of a call sequence
522 // VAARG - VAARG has three operands: an input chain, a pointer, and a
523 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
526 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
527 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
531 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
532 // pointer, and a SRCVALUE.
535 // SRCVALUE - This is a node type that holds a Value* that is used to
536 // make reference to a value in the LLVM IR.
539 // MEMOPERAND - This is a node that contains a MachineMemOperand which
540 // records information about a memory reference. This is used to make
541 // AliasAnalysis queries from the backend.
544 // PCMARKER - This corresponds to the pcmarker intrinsic.
547 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
548 // The only operand is a chain and a value and a chain are produced. The
549 // value is the contents of the architecture specific cycle counter like
550 // register (or other high accuracy low latency clock source)
553 // HANDLENODE node - Used as a handle for various purposes.
556 // DBG_STOPPOINT - This node is used to represent a source location for
557 // debug info. It takes token chain as input, and carries a line number,
558 // column number, and a pointer to a CompileUnit object identifying
559 // the containing compilation unit. It produces a token chain as output.
562 // DEBUG_LOC - This node is used to represent source line information
563 // embedded in the code. It takes a token chain as input, then a line
564 // number, then a column then a file id (provided by MachineModuleInfo.) It
565 // produces a token chain as output.
568 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
569 // It takes as input a token chain, the pointer to the trampoline,
570 // the pointer to the nested function, the pointer to pass for the
571 // 'nest' parameter, a SRCVALUE for the trampoline and another for
572 // the nested function (allowing targets to access the original
573 // Function*). It produces the result of the intrinsic and a token
577 // TRAP - Trapping instruction
580 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
581 // their first operand. The other operands are the address to prefetch,
582 // read / write specifier, and locality specifier.
585 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
586 // store-store, device)
587 // This corresponds to the memory.barrier intrinsic.
588 // it takes an input chain, 4 operands to specify the type of barrier, an
589 // operand specifying if the barrier applies to device and uncached memory
590 // and produces an output chain.
593 // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
594 // this corresponds to the atomic.lcs intrinsic.
595 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
596 // the return is always the original value in *ptr
599 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
600 // this corresponds to the atomic.swap intrinsic.
601 // amt is stored to *ptr atomically.
602 // the return is always the original value in *ptr
605 // Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt)
606 // this corresponds to the atomic.load.[OpName] intrinsic.
607 // op(*ptr, amt) is stored to *ptr atomically.
608 // the return is always the original value in *ptr
620 // BUILTIN_OP_END - This must be the last enum value in this list.
626 /// isBuildVectorAllOnes - Return true if the specified node is a
627 /// BUILD_VECTOR where all of the elements are ~0 or undef.
628 bool isBuildVectorAllOnes(const SDNode *N);
630 /// isBuildVectorAllZeros - Return true if the specified node is a
631 /// BUILD_VECTOR where all of the elements are 0 or undef.
632 bool isBuildVectorAllZeros(const SDNode *N);
634 /// isScalarToVector - Return true if the specified node is a
635 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
636 /// element is not an undef.
637 bool isScalarToVector(const SDNode *N);
639 /// isDebugLabel - Return true if the specified node represents a debug
640 /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node).
641 bool isDebugLabel(const SDNode *N);
643 //===--------------------------------------------------------------------===//
644 /// MemIndexedMode enum - This enum defines the load / store indexed
645 /// addressing modes.
647 /// UNINDEXED "Normal" load / store. The effective address is already
648 /// computed and is available in the base pointer. The offset
649 /// operand is always undefined. In addition to producing a
650 /// chain, an unindexed load produces one value (result of the
651 /// load); an unindexed store does not produce a value.
653 /// PRE_INC Similar to the unindexed mode where the effective address is
654 /// PRE_DEC the value of the base pointer add / subtract the offset.
655 /// It considers the computation as being folded into the load /
656 /// store operation (i.e. the load / store does the address
657 /// computation as well as performing the memory transaction).
658 /// The base operand is always undefined. In addition to
659 /// producing a chain, pre-indexed load produces two values
660 /// (result of the load and the result of the address
661 /// computation); a pre-indexed store produces one value (result
662 /// of the address computation).
664 /// POST_INC The effective address is the value of the base pointer. The
665 /// POST_DEC value of the offset operand is then added to / subtracted
666 /// from the base after memory transaction. In addition to
667 /// producing a chain, post-indexed load produces two values
668 /// (the result of the load and the result of the base +/- offset
669 /// computation); a post-indexed store produces one value (the
670 /// the result of the base +/- offset computation).
672 enum MemIndexedMode {
681 //===--------------------------------------------------------------------===//
682 /// LoadExtType enum - This enum defines the three variants of LOADEXT
683 /// (load with extension).
685 /// SEXTLOAD loads the integer operand and sign extends it to a larger
686 /// integer result type.
687 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
688 /// integer result type.
689 /// EXTLOAD is used for three things: floating point extending loads,
690 /// integer extending loads [the top bits are undefined], and vector
691 /// extending loads [load into low elt].
701 //===--------------------------------------------------------------------===//
702 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
703 /// below work out, when considering SETFALSE (something that never exists
704 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
705 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
706 /// to. If the "N" column is 1, the result of the comparison is undefined if
707 /// the input is a NAN.
709 /// All of these (except for the 'always folded ops') should be handled for
710 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
711 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
713 /// Note that these are laid out in a specific order to allow bit-twiddling
714 /// to transform conditions.
716 // Opcode N U L G E Intuitive operation
717 SETFALSE, // 0 0 0 0 Always false (always folded)
718 SETOEQ, // 0 0 0 1 True if ordered and equal
719 SETOGT, // 0 0 1 0 True if ordered and greater than
720 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
721 SETOLT, // 0 1 0 0 True if ordered and less than
722 SETOLE, // 0 1 0 1 True if ordered and less than or equal
723 SETONE, // 0 1 1 0 True if ordered and operands are unequal
724 SETO, // 0 1 1 1 True if ordered (no nans)
725 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
726 SETUEQ, // 1 0 0 1 True if unordered or equal
727 SETUGT, // 1 0 1 0 True if unordered or greater than
728 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
729 SETULT, // 1 1 0 0 True if unordered or less than
730 SETULE, // 1 1 0 1 True if unordered, less than, or equal
731 SETUNE, // 1 1 1 0 True if unordered or not equal
732 SETTRUE, // 1 1 1 1 Always true (always folded)
733 // Don't care operations: undefined if the input is a nan.
734 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
735 SETEQ, // 1 X 0 0 1 True if equal
736 SETGT, // 1 X 0 1 0 True if greater than
737 SETGE, // 1 X 0 1 1 True if greater than or equal
738 SETLT, // 1 X 1 0 0 True if less than
739 SETLE, // 1 X 1 0 1 True if less than or equal
740 SETNE, // 1 X 1 1 0 True if not equal
741 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
743 SETCC_INVALID // Marker value.
746 /// isSignedIntSetCC - Return true if this is a setcc instruction that
747 /// performs a signed comparison when used with integer operands.
748 inline bool isSignedIntSetCC(CondCode Code) {
749 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
752 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
753 /// performs an unsigned comparison when used with integer operands.
754 inline bool isUnsignedIntSetCC(CondCode Code) {
755 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
758 /// isTrueWhenEqual - Return true if the specified condition returns true if
759 /// the two operands to the condition are equal. Note that if one of the two
760 /// operands is a NaN, this value is meaningless.
761 inline bool isTrueWhenEqual(CondCode Cond) {
762 return ((int)Cond & 1) != 0;
765 /// getUnorderedFlavor - This function returns 0 if the condition is always
766 /// false if an operand is a NaN, 1 if the condition is always true if the
767 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
769 inline unsigned getUnorderedFlavor(CondCode Cond) {
770 return ((int)Cond >> 3) & 3;
773 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
774 /// 'op' is a valid SetCC operation.
775 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
777 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
778 /// when given the operation for (X op Y).
779 CondCode getSetCCSwappedOperands(CondCode Operation);
781 /// getSetCCOrOperation - Return the result of a logical OR between different
782 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
783 /// function returns SETCC_INVALID if it is not possible to represent the
784 /// resultant comparison.
785 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
787 /// getSetCCAndOperation - Return the result of a logical AND between
788 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
789 /// function returns SETCC_INVALID if it is not possible to represent the
790 /// resultant comparison.
791 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
793 //===--------------------------------------------------------------------===//
794 /// CvtCode enum - This enum defines the various converts CONVERT_RNDSAT
797 CVT_FF, // Float from Float
798 CVT_FS, // Float from Signed
799 CVT_FU, // Float from Unsigned
800 CVT_SF, // Signed from Float
801 CVT_UF, // Unsigned from Float
802 CVT_SS, // Signed from Signed
803 CVT_SU, // Signed from Unsigned
804 CVT_US, // Unsigned from Signed
805 CVT_UU, // Unsigned from Unsigned
806 CVT_INVALID // Marker - Invalid opcode
808 } // end llvm::ISD namespace
811 //===----------------------------------------------------------------------===//
812 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
813 /// values as the result of a computation. Many nodes return multiple values,
814 /// from loads (which define a token and a return value) to ADDC (which returns
815 /// a result and a carry value), to calls (which may return an arbitrary number
818 /// As such, each use of a SelectionDAG computation must indicate the node that
819 /// computes it as well as which return value to use from that node. This pair
820 /// of information is represented with the SDValue value type.
823 SDNode *Node; // The node defining the value we are using.
824 unsigned ResNo; // Which return value of the node we are using.
826 SDValue() : Node(0), ResNo(0) {}
827 SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
829 /// get the index which selects a specific result in the SDNode
830 unsigned getResNo() const { return ResNo; }
832 /// get the SDNode which holds the desired result
833 SDNode *getNode() const { return Node; }
836 void setNode(SDNode *N) { Node = N; }
838 bool operator==(const SDValue &O) const {
839 return Node == O.Node && ResNo == O.ResNo;
841 bool operator!=(const SDValue &O) const {
842 return !operator==(O);
844 bool operator<(const SDValue &O) const {
845 return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
848 SDValue getValue(unsigned R) const {
849 return SDValue(Node, R);
852 // isOperandOf - Return true if this node is an operand of N.
853 bool isOperandOf(SDNode *N) const;
855 /// getValueType - Return the ValueType of the referenced return value.
857 inline EVT getValueType() const;
859 /// getValueSizeInBits - Returns the size of the value in bits.
861 unsigned getValueSizeInBits() const {
862 return getValueType().getSizeInBits();
865 // Forwarding methods - These forward to the corresponding methods in SDNode.
866 inline unsigned getOpcode() const;
867 inline unsigned getNumOperands() const;
868 inline const SDValue &getOperand(unsigned i) const;
869 inline uint64_t getConstantOperandVal(unsigned i) const;
870 inline bool isTargetOpcode() const;
871 inline bool isMachineOpcode() const;
872 inline unsigned getMachineOpcode() const;
873 inline const DebugLoc getDebugLoc() const;
876 /// reachesChainWithoutSideEffects - Return true if this operand (which must
877 /// be a chain) reaches the specified operand without crossing any
878 /// side-effecting instructions. In practice, this looks through token
879 /// factors and non-volatile loads. In order to remain efficient, this only
880 /// looks a couple of nodes in, it does not do an exhaustive search.
881 bool reachesChainWithoutSideEffects(SDValue Dest,
882 unsigned Depth = 2) const;
884 /// use_empty - Return true if there are no nodes using value ResNo
887 inline bool use_empty() const;
889 /// hasOneUse - Return true if there is exactly one node using value
892 inline bool hasOneUse() const;
896 template<> struct DenseMapInfo<SDValue> {
897 static inline SDValue getEmptyKey() {
898 return SDValue((SDNode*)-1, -1U);
900 static inline SDValue getTombstoneKey() {
901 return SDValue((SDNode*)-1, 0);
903 static unsigned getHashValue(const SDValue &Val) {
904 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
905 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
907 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
910 static bool isPod() { return true; }
913 /// simplify_type specializations - Allow casting operators to work directly on
914 /// SDValues as if they were SDNode*'s.
915 template<> struct simplify_type<SDValue> {
916 typedef SDNode* SimpleType;
917 static SimpleType getSimplifiedValue(const SDValue &Val) {
918 return static_cast<SimpleType>(Val.getNode());
921 template<> struct simplify_type<const SDValue> {
922 typedef SDNode* SimpleType;
923 static SimpleType getSimplifiedValue(const SDValue &Val) {
924 return static_cast<SimpleType>(Val.getNode());
928 /// SDUse - Represents a use of a SDNode. This class holds an SDValue,
929 /// which records the SDNode being used and the result number, a
930 /// pointer to the SDNode using the value, and Next and Prev pointers,
931 /// which link together all the uses of an SDNode.
934 /// Val - The value being used.
936 /// User - The user of this value.
938 /// Prev, Next - Pointers to the uses list of the SDNode referred by
942 SDUse(const SDUse &U); // Do not implement
943 void operator=(const SDUse &U); // Do not implement
946 SDUse() : Val(), User(NULL), Prev(NULL), Next(NULL) {}
948 /// Normally SDUse will just implicitly convert to an SDValue that it holds.
949 operator const SDValue&() const { return Val; }
951 /// If implicit conversion to SDValue doesn't work, the get() method returns
953 const SDValue &get() const { return Val; }
955 /// getUser - This returns the SDNode that contains this Use.
956 SDNode *getUser() { return User; }
958 /// getNext - Get the next SDUse in the use list.
959 SDUse *getNext() const { return Next; }
961 /// getNode - Convenience function for get().getNode().
962 SDNode *getNode() const { return Val.getNode(); }
963 /// getResNo - Convenience function for get().getResNo().
964 unsigned getResNo() const { return Val.getResNo(); }
965 /// getValueType - Convenience function for get().getValueType().
966 EVT getValueType() const { return Val.getValueType(); }
968 /// operator== - Convenience function for get().operator==
969 bool operator==(const SDValue &V) const {
973 /// operator!= - Convenience function for get().operator!=
974 bool operator!=(const SDValue &V) const {
978 /// operator< - Convenience function for get().operator<
979 bool operator<(const SDValue &V) const {
984 friend class SelectionDAG;
987 void setUser(SDNode *p) { User = p; }
989 /// set - Remove this use from its existing use list, assign it the
990 /// given value, and add it to the new value's node's use list.
991 inline void set(const SDValue &V);
992 /// setInitial - like set, but only supports initializing a newly-allocated
993 /// SDUse with a non-null value.
994 inline void setInitial(const SDValue &V);
995 /// setNode - like set, but only sets the Node portion of the value,
996 /// leaving the ResNo portion unmodified.
997 inline void setNode(SDNode *N);
999 void addToList(SDUse **List) {
1001 if (Next) Next->Prev = &Next;
1006 void removeFromList() {
1008 if (Next) Next->Prev = Prev;
1012 /// simplify_type specializations - Allow casting operators to work directly on
1013 /// SDValues as if they were SDNode*'s.
1014 template<> struct simplify_type<SDUse> {
1015 typedef SDNode* SimpleType;
1016 static SimpleType getSimplifiedValue(const SDUse &Val) {
1017 return static_cast<SimpleType>(Val.getNode());
1020 template<> struct simplify_type<const SDUse> {
1021 typedef SDNode* SimpleType;
1022 static SimpleType getSimplifiedValue(const SDUse &Val) {
1023 return static_cast<SimpleType>(Val.getNode());
1028 /// SDNode - Represents one node in the SelectionDAG.
1030 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
1032 /// NodeType - The operation that this node performs.
1036 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
1037 /// then they will be delete[]'d when the node is destroyed.
1038 unsigned short OperandsNeedDelete : 1;
1041 /// SubclassData - This member is defined by this class, but is not used for
1042 /// anything. Subclasses can use it to hold whatever state they find useful.
1043 /// This field is initialized to zero by the ctor.
1044 unsigned short SubclassData : 15;
1047 /// NodeId - Unique id per SDNode in the DAG.
1050 /// OperandList - The values that are used by this operation.
1054 /// ValueList - The types of the values this node defines. SDNode's may
1055 /// define multiple values simultaneously.
1056 const EVT *ValueList;
1058 /// UseList - List of uses for this SDNode.
1061 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1062 unsigned short NumOperands, NumValues;
1064 /// debugLoc - source line information.
1067 /// getValueTypeList - Return a pointer to the specified value type.
1068 static const EVT *getValueTypeList(EVT VT);
1070 friend class SelectionDAG;
1071 friend struct ilist_traits<SDNode>;
1074 //===--------------------------------------------------------------------===//
1078 /// getOpcode - Return the SelectionDAG opcode value for this node. For
1079 /// pre-isel nodes (those for which isMachineOpcode returns false), these
1080 /// are the opcode values in the ISD and <target>ISD namespaces. For
1081 /// post-isel opcodes, see getMachineOpcode.
1082 unsigned getOpcode() const { return (unsigned short)NodeType; }
1084 /// isTargetOpcode - Test if this node has a target-specific opcode (in the
1085 /// \<target\>ISD namespace).
1086 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1088 /// isMachineOpcode - Test if this node has a post-isel opcode, directly
1089 /// corresponding to a MachineInstr opcode.
1090 bool isMachineOpcode() const { return NodeType < 0; }
1092 /// getMachineOpcode - This may only be called if isMachineOpcode returns
1093 /// true. It returns the MachineInstr opcode value that the node's opcode
1095 unsigned getMachineOpcode() const {
1096 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
1100 /// use_empty - Return true if there are no uses of this node.
1102 bool use_empty() const { return UseList == NULL; }
1104 /// hasOneUse - Return true if there is exactly one use of this node.
1106 bool hasOneUse() const {
1107 return !use_empty() && next(use_begin()) == use_end();
1110 /// use_size - Return the number of uses of this node. This method takes
1111 /// time proportional to the number of uses.
1113 size_t use_size() const { return std::distance(use_begin(), use_end()); }
1115 /// getNodeId - Return the unique node id.
1117 int getNodeId() const { return NodeId; }
1119 /// setNodeId - Set unique node id.
1120 void setNodeId(int Id) { NodeId = Id; }
1122 /// getDebugLoc - Return the source location info.
1123 const DebugLoc getDebugLoc() const { return debugLoc; }
1125 /// setDebugLoc - Set source location info. Try to avoid this, putting
1126 /// it in the constructor is preferable.
1127 void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
1129 /// use_iterator - This class provides iterator support for SDUse
1130 /// operands that use a specific SDNode.
1132 : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
1134 explicit use_iterator(SDUse *op) : Op(op) {
1136 friend class SDNode;
1138 typedef std::iterator<std::forward_iterator_tag,
1139 SDUse, ptrdiff_t>::reference reference;
1140 typedef std::iterator<std::forward_iterator_tag,
1141 SDUse, ptrdiff_t>::pointer pointer;
1143 use_iterator(const use_iterator &I) : Op(I.Op) {}
1144 use_iterator() : Op(0) {}
1146 bool operator==(const use_iterator &x) const {
1149 bool operator!=(const use_iterator &x) const {
1150 return !operator==(x);
1153 /// atEnd - return true if this iterator is at the end of uses list.
1154 bool atEnd() const { return Op == 0; }
1156 // Iterator traversal: forward iteration only.
1157 use_iterator &operator++() { // Preincrement
1158 assert(Op && "Cannot increment end iterator!");
1163 use_iterator operator++(int) { // Postincrement
1164 use_iterator tmp = *this; ++*this; return tmp;
1167 /// Retrieve a pointer to the current user node.
1168 SDNode *operator*() const {
1169 assert(Op && "Cannot dereference end iterator!");
1170 return Op->getUser();
1173 SDNode *operator->() const { return operator*(); }
1175 SDUse &getUse() const { return *Op; }
1177 /// getOperandNo - Retrieve the operand # of this use in its user.
1179 unsigned getOperandNo() const {
1180 assert(Op && "Cannot dereference end iterator!");
1181 return (unsigned)(Op - Op->getUser()->OperandList);
1185 /// use_begin/use_end - Provide iteration support to walk over all uses
1188 use_iterator use_begin() const {
1189 return use_iterator(UseList);
1192 static use_iterator use_end() { return use_iterator(0); }
1195 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1196 /// indicated value. This method ignores uses of other values defined by this
1198 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1200 /// hasAnyUseOfValue - Return true if there are any use of the indicated
1201 /// value. This method ignores uses of other values defined by this operation.
1202 bool hasAnyUseOfValue(unsigned Value) const;
1204 /// isOnlyUserOf - Return true if this node is the only use of N.
1206 bool isOnlyUserOf(SDNode *N) const;
1208 /// isOperandOf - Return true if this node is an operand of N.
1210 bool isOperandOf(SDNode *N) const;
1212 /// isPredecessorOf - Return true if this node is a predecessor of N. This
1213 /// node is either an operand of N or it can be reached by recursively
1214 /// traversing up the operands.
1215 /// NOTE: this is an expensive method. Use it carefully.
1216 bool isPredecessorOf(SDNode *N) const;
1218 /// getNumOperands - Return the number of values used by this operation.
1220 unsigned getNumOperands() const { return NumOperands; }
1222 /// getConstantOperandVal - Helper method returns the integer value of a
1223 /// ConstantSDNode operand.
1224 uint64_t getConstantOperandVal(unsigned Num) const;
1226 const SDValue &getOperand(unsigned Num) const {
1227 assert(Num < NumOperands && "Invalid child # of SDNode!");
1228 return OperandList[Num];
1231 typedef SDUse* op_iterator;
1232 op_iterator op_begin() const { return OperandList; }
1233 op_iterator op_end() const { return OperandList+NumOperands; }
1235 SDVTList getVTList() const {
1236 SDVTList X = { ValueList, NumValues };
1240 /// getFlaggedNode - If this node has a flag operand, return the node
1241 /// to which the flag operand points. Otherwise return NULL.
1242 SDNode *getFlaggedNode() const {
1243 if (getNumOperands() != 0 &&
1244 getOperand(getNumOperands()-1).getValueType().getSimpleVT() == MVT::Flag)
1245 return getOperand(getNumOperands()-1).getNode();
1249 // If this is a pseudo op, like copyfromreg, look to see if there is a
1250 // real target node flagged to it. If so, return the target node.
1251 const SDNode *getFlaggedMachineNode() const {
1252 const SDNode *FoundNode = this;
1254 // Climb up flag edges until a machine-opcode node is found, or the
1255 // end of the chain is reached.
1256 while (!FoundNode->isMachineOpcode()) {
1257 const SDNode *N = FoundNode->getFlaggedNode();
1265 /// getNumValues - Return the number of values defined/returned by this
1268 unsigned getNumValues() const { return NumValues; }
1270 /// getValueType - Return the type of a specified result.
1272 EVT getValueType(unsigned ResNo) const {
1273 assert(ResNo < NumValues && "Illegal result number!");
1274 return ValueList[ResNo];
1277 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1279 unsigned getValueSizeInBits(unsigned ResNo) const {
1280 return getValueType(ResNo).getSizeInBits();
1283 typedef const EVT* value_iterator;
1284 value_iterator value_begin() const { return ValueList; }
1285 value_iterator value_end() const { return ValueList+NumValues; }
1287 /// getOperationName - Return the opcode of this operation for printing.
1289 std::string getOperationName(const SelectionDAG *G = 0) const;
1290 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1291 void print_types(raw_ostream &OS, const SelectionDAG *G) const;
1292 void print_details(raw_ostream &OS, const SelectionDAG *G) const;
1293 void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
1294 void printr(raw_ostream &OS, const SelectionDAG *G = 0) const;
1297 void dump(const SelectionDAG *G) const;
1298 void dumpr(const SelectionDAG *G) const;
1300 static bool classof(const SDNode *) { return true; }
1302 /// Profile - Gather unique data for the node.
1304 void Profile(FoldingSetNodeID &ID) const;
1306 /// addUse - This method should only be used by the SDUse class.
1308 void addUse(SDUse &U) { U.addToList(&UseList); }
1311 static SDVTList getSDVTList(EVT VT) {
1312 SDVTList Ret = { getValueTypeList(VT), 1 };
1316 SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops,
1318 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1320 OperandList(NumOps ? new SDUse[NumOps] : 0),
1321 ValueList(VTs.VTs), UseList(NULL),
1322 NumOperands(NumOps), NumValues(VTs.NumVTs),
1324 for (unsigned i = 0; i != NumOps; ++i) {
1325 OperandList[i].setUser(this);
1326 OperandList[i].setInitial(Ops[i]);
1330 /// This constructor adds no operands itself; operands can be
1331 /// set later with InitOperands.
1332 SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs)
1333 : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1334 NodeId(-1), OperandList(0), ValueList(VTs.VTs), UseList(NULL),
1335 NumOperands(0), NumValues(VTs.NumVTs),
1338 /// InitOperands - Initialize the operands list of this with 1 operand.
1339 void InitOperands(SDUse *Ops, const SDValue &Op0) {
1340 Ops[0].setUser(this);
1341 Ops[0].setInitial(Op0);
1346 /// InitOperands - Initialize the operands list of this with 2 operands.
1347 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
1348 Ops[0].setUser(this);
1349 Ops[0].setInitial(Op0);
1350 Ops[1].setUser(this);
1351 Ops[1].setInitial(Op1);
1356 /// InitOperands - Initialize the operands list of this with 3 operands.
1357 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
1358 const SDValue &Op2) {
1359 Ops[0].setUser(this);
1360 Ops[0].setInitial(Op0);
1361 Ops[1].setUser(this);
1362 Ops[1].setInitial(Op1);
1363 Ops[2].setUser(this);
1364 Ops[2].setInitial(Op2);
1369 /// InitOperands - Initialize the operands list of this with 4 operands.
1370 void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
1371 const SDValue &Op2, const SDValue &Op3) {
1372 Ops[0].setUser(this);
1373 Ops[0].setInitial(Op0);
1374 Ops[1].setUser(this);
1375 Ops[1].setInitial(Op1);
1376 Ops[2].setUser(this);
1377 Ops[2].setInitial(Op2);
1378 Ops[3].setUser(this);
1379 Ops[3].setInitial(Op3);
1384 /// InitOperands - Initialize the operands list of this with N operands.
1385 void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
1386 for (unsigned i = 0; i != N; ++i) {
1387 Ops[i].setUser(this);
1388 Ops[i].setInitial(Vals[i]);
1394 /// DropOperands - Release the operands and set this node to have
1396 void DropOperands();
1400 // Define inline functions from the SDValue class.
1402 inline unsigned SDValue::getOpcode() const {
1403 return Node->getOpcode();
1405 inline EVT SDValue::getValueType() const {
1406 return Node->getValueType(ResNo);
1408 inline unsigned SDValue::getNumOperands() const {
1409 return Node->getNumOperands();
1411 inline const SDValue &SDValue::getOperand(unsigned i) const {
1412 return Node->getOperand(i);
1414 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1415 return Node->getConstantOperandVal(i);
1417 inline bool SDValue::isTargetOpcode() const {
1418 return Node->isTargetOpcode();
1420 inline bool SDValue::isMachineOpcode() const {
1421 return Node->isMachineOpcode();
1423 inline unsigned SDValue::getMachineOpcode() const {
1424 return Node->getMachineOpcode();
1426 inline bool SDValue::use_empty() const {
1427 return !Node->hasAnyUseOfValue(ResNo);
1429 inline bool SDValue::hasOneUse() const {
1430 return Node->hasNUsesOfValue(1, ResNo);
1432 inline const DebugLoc SDValue::getDebugLoc() const {
1433 return Node->getDebugLoc();
1436 // Define inline functions from the SDUse class.
1438 inline void SDUse::set(const SDValue &V) {
1439 if (Val.getNode()) removeFromList();
1441 if (V.getNode()) V.getNode()->addUse(*this);
1444 inline void SDUse::setInitial(const SDValue &V) {
1446 V.getNode()->addUse(*this);
1449 inline void SDUse::setNode(SDNode *N) {
1450 if (Val.getNode()) removeFromList();
1452 if (N) N->addUse(*this);
1455 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1456 /// to allow co-allocation of node operands with the node itself.
1457 class UnarySDNode : public SDNode {
1460 UnarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X)
1461 : SDNode(Opc, dl, VTs) {
1462 InitOperands(&Op, X);
1466 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1467 /// to allow co-allocation of node operands with the node itself.
1468 class BinarySDNode : public SDNode {
1471 BinarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y)
1472 : SDNode(Opc, dl, VTs) {
1473 InitOperands(Ops, X, Y);
1477 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1478 /// to allow co-allocation of node operands with the node itself.
1479 class TernarySDNode : public SDNode {
1482 TernarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y,
1484 : SDNode(Opc, dl, VTs) {
1485 InitOperands(Ops, X, Y, Z);
1490 /// HandleSDNode - This class is used to form a handle around another node that
1491 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1492 /// operand. This node should be directly created by end-users and not added to
1493 /// the AllNodes list.
1494 class HandleSDNode : public SDNode {
1497 // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1500 explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
1502 explicit HandleSDNode(SDValue X)
1504 : SDNode(ISD::HANDLENODE, DebugLoc::getUnknownLoc(),
1505 getSDVTList(MVT::Other)) {
1506 InitOperands(&Op, X);
1509 const SDValue &getValue() const { return Op; }
1512 /// Abstact virtual class for operations for memory operations
1513 class MemSDNode : public SDNode {
1515 // MemoryVT - VT of in-memory value.
1518 //! SrcValue - Memory location for alias analysis.
1519 const Value *SrcValue;
1521 //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
1524 MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, EVT MemoryVT,
1525 const Value *srcValue, int SVOff, unsigned alignment,
1528 MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, const SDValue *Ops,
1529 unsigned NumOps, EVT MemoryVT, const Value *srcValue, int SVOff,
1530 unsigned alignment, bool isvolatile);
1532 /// Returns alignment and volatility of the memory access
1533 unsigned getOriginalAlignment() const {
1534 return (1u << (SubclassData >> 6)) >> 1;
1536 unsigned getAlignment() const {
1537 return MinAlign(getOriginalAlignment(), SVOffset);
1539 bool isVolatile() const { return (SubclassData >> 5) & 1; }
1541 /// getRawSubclassData - Return the SubclassData value, which contains an
1542 /// encoding of the alignment and volatile information, as well as bits
1543 /// used by subclasses. This function should only be used to compute a
1544 /// FoldingSetNodeID value.
1545 unsigned getRawSubclassData() const {
1546 return SubclassData;
1549 /// Returns the SrcValue and offset that describes the location of the access
1550 const Value *getSrcValue() const { return SrcValue; }
1551 int getSrcValueOffset() const { return SVOffset; }
1553 /// getMemoryVT - Return the type of the in-memory value.
1554 EVT getMemoryVT() const { return MemoryVT; }
1556 /// getMemOperand - Return a MachineMemOperand object describing the memory
1557 /// reference performed by operation.
1558 MachineMemOperand getMemOperand() const;
1560 const SDValue &getChain() const { return getOperand(0); }
1561 const SDValue &getBasePtr() const {
1562 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1565 // Methods to support isa and dyn_cast
1566 static bool classof(const MemSDNode *) { return true; }
1567 static bool classof(const SDNode *N) {
1568 // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1569 // with either an intrinsic or a target opcode.
1570 return N->getOpcode() == ISD::LOAD ||
1571 N->getOpcode() == ISD::STORE ||
1572 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1573 N->getOpcode() == ISD::ATOMIC_SWAP ||
1574 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1575 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1576 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1577 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1578 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1579 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1580 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1581 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1582 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1583 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX ||
1584 N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1585 N->getOpcode() == ISD::INTRINSIC_VOID ||
1586 N->isTargetOpcode();
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, const Value* SrcVal,
1608 : MemSDNode(Opc, dl, VTL, MemVT, SrcVal, /*SVOffset=*/0,
1609 Align, /*isVolatile=*/true) {
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, const Value* SrcVal, unsigned Align=0)
1615 : MemSDNode(Opc, dl, VTL, MemVT, SrcVal, /*SVOffset=*/0,
1616 Align, /*isVolatile=*/true) {
1617 InitOperands(Ops, Chain, Ptr, Val);
1620 const SDValue &getBasePtr() const { return getOperand(1); }
1621 const SDValue &getVal() const { return getOperand(2); }
1623 bool isCompareAndSwap() const {
1624 unsigned Op = getOpcode();
1625 return Op == ISD::ATOMIC_CMP_SWAP;
1628 // Methods to support isa and dyn_cast
1629 static bool classof(const AtomicSDNode *) { return true; }
1630 static bool classof(const SDNode *N) {
1631 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1632 N->getOpcode() == ISD::ATOMIC_SWAP ||
1633 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1634 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1635 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1636 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1637 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1638 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1639 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1640 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1641 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1642 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1646 /// MemIntrinsicSDNode - This SDNode is used for target intrinsic that touches
1647 /// memory and need an associated memory operand.
1649 class MemIntrinsicSDNode : public MemSDNode {
1650 bool ReadMem; // Intrinsic reads memory
1651 bool WriteMem; // Intrinsic writes memory
1653 MemIntrinsicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs,
1654 const SDValue *Ops, unsigned NumOps,
1655 EVT MemoryVT, const Value *srcValue, int SVO,
1656 unsigned Align, bool Vol, bool ReadMem, bool WriteMem)
1657 : MemSDNode(Opc, dl, VTs, Ops, NumOps, MemoryVT, srcValue, SVO, Align, Vol),
1658 ReadMem(ReadMem), WriteMem(WriteMem) {
1661 bool readMem() const { return ReadMem; }
1662 bool writeMem() const { return WriteMem; }
1664 // Methods to support isa and dyn_cast
1665 static bool classof(const MemIntrinsicSDNode *) { return true; }
1666 static bool classof(const SDNode *N) {
1667 // We lower some target intrinsics to their target opcode
1668 // early a node with a target opcode can be of this class
1669 return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1670 N->getOpcode() == ISD::INTRINSIC_VOID ||
1671 N->isTargetOpcode();
1675 /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
1676 /// support for the llvm IR shufflevector instruction. It combines elements
1677 /// from two input vectors into a new input vector, with the selection and
1678 /// ordering of elements determined by an array of integers, referred to as
1679 /// the shuffle mask. For input vectors of width N, mask indices of 0..N-1
1680 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1681 /// An index of -1 is treated as undef, such that the code generator may put
1682 /// any value in the corresponding element of the result.
1683 class ShuffleVectorSDNode : public SDNode {
1686 // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1687 // is freed when the SelectionDAG object is destroyed.
1690 friend class SelectionDAG;
1691 ShuffleVectorSDNode(EVT VT, DebugLoc dl, SDValue N1, SDValue N2,
1693 : SDNode(ISD::VECTOR_SHUFFLE, dl, getSDVTList(VT)), Mask(M) {
1694 InitOperands(Ops, N1, N2);
1698 void getMask(SmallVectorImpl<int> &M) const {
1699 EVT VT = getValueType(0);
1701 for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i)
1702 M.push_back(Mask[i]);
1704 int getMaskElt(unsigned Idx) const {
1705 assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1709 bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1710 int getSplatIndex() const {
1711 assert(isSplat() && "Cannot get splat index for non-splat!");
1714 static bool isSplatMask(const int *Mask, EVT VT);
1716 static bool classof(const ShuffleVectorSDNode *) { return true; }
1717 static bool classof(const SDNode *N) {
1718 return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1722 class ConstantSDNode : public SDNode {
1723 const ConstantInt *Value;
1724 friend class SelectionDAG;
1725 ConstantSDNode(bool isTarget, const ConstantInt *val, EVT VT)
1726 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1727 DebugLoc::getUnknownLoc(), getSDVTList(VT)), Value(val) {
1731 const ConstantInt *getConstantIntValue() const { return Value; }
1732 const APInt &getAPIntValue() const { return Value->getValue(); }
1733 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1734 int64_t getSExtValue() const { return Value->getSExtValue(); }
1736 bool isNullValue() const { return Value->isNullValue(); }
1737 bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1739 static bool classof(const ConstantSDNode *) { return true; }
1740 static bool classof(const SDNode *N) {
1741 return N->getOpcode() == ISD::Constant ||
1742 N->getOpcode() == ISD::TargetConstant;
1746 class ConstantFPSDNode : public SDNode {
1747 const ConstantFP *Value;
1748 friend class SelectionDAG;
1749 ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1750 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1751 DebugLoc::getUnknownLoc(), getSDVTList(VT)), Value(val) {
1755 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1756 const ConstantFP *getConstantFPValue() const { return Value; }
1758 /// isExactlyValue - We don't rely on operator== working on double values, as
1759 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1760 /// As such, this method can be used to do an exact bit-for-bit comparison of
1761 /// two floating point values.
1763 /// We leave the version with the double argument here because it's just so
1764 /// convenient to write "2.0" and the like. Without this function we'd
1765 /// have to duplicate its logic everywhere it's called.
1766 bool isExactlyValue(double V) const {
1768 // convert is not supported on this type
1769 if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
1772 Tmp.convert(Value->getValueAPF().getSemantics(),
1773 APFloat::rmNearestTiesToEven, &ignored);
1774 return isExactlyValue(Tmp);
1776 bool isExactlyValue(const APFloat& V) const;
1778 bool isValueValidForType(EVT VT, const APFloat& Val);
1780 static bool classof(const ConstantFPSDNode *) { return true; }
1781 static bool classof(const SDNode *N) {
1782 return N->getOpcode() == ISD::ConstantFP ||
1783 N->getOpcode() == ISD::TargetConstantFP;
1787 class GlobalAddressSDNode : public SDNode {
1788 GlobalValue *TheGlobal;
1790 unsigned char TargetFlags;
1791 friend class SelectionDAG;
1792 GlobalAddressSDNode(unsigned Opc, const GlobalValue *GA, EVT VT,
1793 int64_t o, unsigned char TargetFlags);
1796 GlobalValue *getGlobal() const { return TheGlobal; }
1797 int64_t getOffset() const { return Offset; }
1798 unsigned char getTargetFlags() const { return TargetFlags; }
1799 // Return the address space this GlobalAddress belongs to.
1800 unsigned getAddressSpace() const;
1802 static bool classof(const GlobalAddressSDNode *) { return true; }
1803 static bool classof(const SDNode *N) {
1804 return N->getOpcode() == ISD::GlobalAddress ||
1805 N->getOpcode() == ISD::TargetGlobalAddress ||
1806 N->getOpcode() == ISD::GlobalTLSAddress ||
1807 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1811 class FrameIndexSDNode : public SDNode {
1813 friend class SelectionDAG;
1814 FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1815 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1816 DebugLoc::getUnknownLoc(), getSDVTList(VT)), FI(fi) {
1820 int getIndex() const { return FI; }
1822 static bool classof(const FrameIndexSDNode *) { return true; }
1823 static bool classof(const SDNode *N) {
1824 return N->getOpcode() == ISD::FrameIndex ||
1825 N->getOpcode() == ISD::TargetFrameIndex;
1829 class JumpTableSDNode : public SDNode {
1831 unsigned char TargetFlags;
1832 friend class SelectionDAG;
1833 JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1834 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1835 DebugLoc::getUnknownLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1839 int getIndex() const { return JTI; }
1840 unsigned char getTargetFlags() const { return TargetFlags; }
1842 static bool classof(const JumpTableSDNode *) { return true; }
1843 static bool classof(const SDNode *N) {
1844 return N->getOpcode() == ISD::JumpTable ||
1845 N->getOpcode() == ISD::TargetJumpTable;
1849 class ConstantPoolSDNode : public SDNode {
1852 MachineConstantPoolValue *MachineCPVal;
1854 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1855 unsigned Alignment; // Minimum alignment requirement of CP (not log2 value).
1856 unsigned char TargetFlags;
1857 friend class SelectionDAG;
1858 ConstantPoolSDNode(bool isTarget, Constant *c, EVT VT, int o, unsigned Align,
1860 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1861 DebugLoc::getUnknownLoc(),
1862 getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1863 assert((int)Offset >= 0 && "Offset is too large");
1866 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1867 EVT VT, int o, unsigned Align, unsigned char TF)
1868 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1869 DebugLoc::getUnknownLoc(),
1870 getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1871 assert((int)Offset >= 0 && "Offset is too large");
1872 Val.MachineCPVal = v;
1873 Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1878 bool isMachineConstantPoolEntry() const {
1879 return (int)Offset < 0;
1882 Constant *getConstVal() const {
1883 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1884 return Val.ConstVal;
1887 MachineConstantPoolValue *getMachineCPVal() const {
1888 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1889 return Val.MachineCPVal;
1892 int getOffset() const {
1893 return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1896 // Return the alignment of this constant pool object, which is either 0 (for
1897 // default alignment) or the desired value.
1898 unsigned getAlignment() const { return Alignment; }
1899 unsigned char getTargetFlags() const { return TargetFlags; }
1901 const Type *getType() const;
1903 static bool classof(const ConstantPoolSDNode *) { return true; }
1904 static bool classof(const SDNode *N) {
1905 return N->getOpcode() == ISD::ConstantPool ||
1906 N->getOpcode() == ISD::TargetConstantPool;
1910 class BasicBlockSDNode : public SDNode {
1911 MachineBasicBlock *MBB;
1912 friend class SelectionDAG;
1913 /// Debug info is meaningful and potentially useful here, but we create
1914 /// blocks out of order when they're jumped to, which makes it a bit
1915 /// harder. Let's see if we need it first.
1916 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1917 : SDNode(ISD::BasicBlock, DebugLoc::getUnknownLoc(),
1918 getSDVTList(MVT::Other)), MBB(mbb) {
1922 MachineBasicBlock *getBasicBlock() const { return MBB; }
1924 static bool classof(const BasicBlockSDNode *) { return true; }
1925 static bool classof(const SDNode *N) {
1926 return N->getOpcode() == ISD::BasicBlock;
1930 /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
1932 class BuildVectorSDNode : public SDNode {
1933 // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1934 explicit BuildVectorSDNode(); // Do not implement
1936 /// isConstantSplat - Check if this is a constant splat, and if so, find the
1937 /// smallest element size that splats the vector. If MinSplatBits is
1938 /// nonzero, the element size must be at least that large. Note that the
1939 /// splat element may be the entire vector (i.e., a one element vector).
1940 /// Returns the splat element value in SplatValue. Any undefined bits in
1941 /// that value are zero, and the corresponding bits in the SplatUndef mask
1942 /// are set. The SplatBitSize value is set to the splat element size in
1943 /// bits. HasAnyUndefs is set to true if any bits in the vector are
1945 bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1946 unsigned &SplatBitSize, bool &HasAnyUndefs,
1947 unsigned MinSplatBits = 0);
1949 static inline bool classof(const BuildVectorSDNode *) { return true; }
1950 static inline bool classof(const SDNode *N) {
1951 return N->getOpcode() == ISD::BUILD_VECTOR;
1955 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1956 /// used when the SelectionDAG needs to make a simple reference to something
1957 /// in the LLVM IR representation.
1959 /// Note that this is not used for carrying alias information; that is done
1960 /// with MemOperandSDNode, which includes a Value which is required to be a
1961 /// pointer, and several other fields specific to memory references.
1963 class SrcValueSDNode : public SDNode {
1965 friend class SelectionDAG;
1966 /// Create a SrcValue for a general value.
1967 explicit SrcValueSDNode(const Value *v)
1968 : SDNode(ISD::SRCVALUE, DebugLoc::getUnknownLoc(),
1969 getSDVTList(MVT::Other)), V(v) {}
1972 /// getValue - return the contained Value.
1973 const Value *getValue() const { return V; }
1975 static bool classof(const SrcValueSDNode *) { return true; }
1976 static bool classof(const SDNode *N) {
1977 return N->getOpcode() == ISD::SRCVALUE;
1982 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
1983 /// used to represent a reference to memory after ISD::LOAD
1984 /// and ISD::STORE have been lowered.
1986 class MemOperandSDNode : public SDNode {
1987 friend class SelectionDAG;
1988 /// Create a MachineMemOperand node
1989 explicit MemOperandSDNode(const MachineMemOperand &mo)
1990 : SDNode(ISD::MEMOPERAND, DebugLoc::getUnknownLoc(),
1991 getSDVTList(MVT::Other)), MO(mo) {}
1994 /// MO - The contained MachineMemOperand.
1995 const MachineMemOperand MO;
1997 static bool classof(const MemOperandSDNode *) { return true; }
1998 static bool classof(const SDNode *N) {
1999 return N->getOpcode() == ISD::MEMOPERAND;
2004 class RegisterSDNode : public SDNode {
2006 friend class SelectionDAG;
2007 RegisterSDNode(unsigned reg, EVT VT)
2008 : SDNode(ISD::Register, DebugLoc::getUnknownLoc(),
2009 getSDVTList(VT)), Reg(reg) {
2013 unsigned getReg() const { return Reg; }
2015 static bool classof(const RegisterSDNode *) { return true; }
2016 static bool classof(const SDNode *N) {
2017 return N->getOpcode() == ISD::Register;
2021 class DbgStopPointSDNode : public SDNode {
2026 friend class SelectionDAG;
2027 DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
2029 : SDNode(ISD::DBG_STOPPOINT, DebugLoc::getUnknownLoc(),
2030 getSDVTList(MVT::Other)), Line(l), Column(c), CU(cu) {
2031 InitOperands(&Chain, ch);
2034 unsigned getLine() const { return Line; }
2035 unsigned getColumn() const { return Column; }
2036 MDNode *getCompileUnit() const { return CU; }
2038 static bool classof(const DbgStopPointSDNode *) { return true; }
2039 static bool classof(const SDNode *N) {
2040 return N->getOpcode() == ISD::DBG_STOPPOINT;
2044 class LabelSDNode : public SDNode {
2047 friend class SelectionDAG;
2048 LabelSDNode(unsigned NodeTy, DebugLoc dl, SDValue ch, unsigned id)
2049 : SDNode(NodeTy, dl, getSDVTList(MVT::Other)), LabelID(id) {
2050 InitOperands(&Chain, ch);
2053 unsigned getLabelID() const { return LabelID; }
2055 static bool classof(const LabelSDNode *) { return true; }
2056 static bool classof(const SDNode *N) {
2057 return N->getOpcode() == ISD::DBG_LABEL ||
2058 N->getOpcode() == ISD::EH_LABEL;
2062 class ExternalSymbolSDNode : public SDNode {
2064 unsigned char TargetFlags;
2066 friend class SelectionDAG;
2067 ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
2068 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
2069 DebugLoc::getUnknownLoc(),
2070 getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
2074 const char *getSymbol() const { return Symbol; }
2075 unsigned char getTargetFlags() const { return TargetFlags; }
2077 static bool classof(const ExternalSymbolSDNode *) { return true; }
2078 static bool classof(const SDNode *N) {
2079 return N->getOpcode() == ISD::ExternalSymbol ||
2080 N->getOpcode() == ISD::TargetExternalSymbol;
2084 class CondCodeSDNode : public SDNode {
2085 ISD::CondCode Condition;
2086 friend class SelectionDAG;
2087 explicit CondCodeSDNode(ISD::CondCode Cond)
2088 : SDNode(ISD::CONDCODE, DebugLoc::getUnknownLoc(),
2089 getSDVTList(MVT::Other)), Condition(Cond) {
2093 ISD::CondCode get() const { return Condition; }
2095 static bool classof(const CondCodeSDNode *) { return true; }
2096 static bool classof(const SDNode *N) {
2097 return N->getOpcode() == ISD::CONDCODE;
2101 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
2102 /// future and most targets don't support it.
2103 class CvtRndSatSDNode : public SDNode {
2104 ISD::CvtCode CvtCode;
2105 friend class SelectionDAG;
2106 explicit CvtRndSatSDNode(EVT VT, DebugLoc dl, const SDValue *Ops,
2107 unsigned NumOps, ISD::CvtCode Code)
2108 : SDNode(ISD::CONVERT_RNDSAT, dl, getSDVTList(VT), Ops, NumOps),
2110 assert(NumOps == 5 && "wrong number of operations");
2113 ISD::CvtCode getCvtCode() const { return CvtCode; }
2115 static bool classof(const CvtRndSatSDNode *) { return true; }
2116 static bool classof(const SDNode *N) {
2117 return N->getOpcode() == ISD::CONVERT_RNDSAT;
2124 static const uint64_t NoFlagSet = 0ULL;
2125 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
2126 static const uint64_t ZExtOffs = 0;
2127 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
2128 static const uint64_t SExtOffs = 1;
2129 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
2130 static const uint64_t InRegOffs = 2;
2131 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
2132 static const uint64_t SRetOffs = 3;
2133 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
2134 static const uint64_t ByValOffs = 4;
2135 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
2136 static const uint64_t NestOffs = 5;
2137 static const uint64_t ByValAlign = 0xFULL << 6; //< Struct alignment
2138 static const uint64_t ByValAlignOffs = 6;
2139 static const uint64_t Split = 1ULL << 10;
2140 static const uint64_t SplitOffs = 10;
2141 static const uint64_t OrigAlign = 0x1FULL<<27;
2142 static const uint64_t OrigAlignOffs = 27;
2143 static const uint64_t ByValSize = 0xffffffffULL << 32; //< Struct size
2144 static const uint64_t ByValSizeOffs = 32;
2146 static const uint64_t One = 1ULL; //< 1 of this type, for shifts
2150 ArgFlagsTy() : Flags(0) { }
2152 bool isZExt() const { return Flags & ZExt; }
2153 void setZExt() { Flags |= One << ZExtOffs; }
2155 bool isSExt() const { return Flags & SExt; }
2156 void setSExt() { Flags |= One << SExtOffs; }
2158 bool isInReg() const { return Flags & InReg; }
2159 void setInReg() { Flags |= One << InRegOffs; }
2161 bool isSRet() const { return Flags & SRet; }
2162 void setSRet() { Flags |= One << SRetOffs; }
2164 bool isByVal() const { return Flags & ByVal; }
2165 void setByVal() { Flags |= One << ByValOffs; }
2167 bool isNest() const { return Flags & Nest; }
2168 void setNest() { Flags |= One << NestOffs; }
2170 unsigned getByValAlign() const {
2172 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
2174 void setByValAlign(unsigned A) {
2175 Flags = (Flags & ~ByValAlign) |
2176 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
2179 bool isSplit() const { return Flags & Split; }
2180 void setSplit() { Flags |= One << SplitOffs; }
2182 unsigned getOrigAlign() const {
2184 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
2186 void setOrigAlign(unsigned A) {
2187 Flags = (Flags & ~OrigAlign) |
2188 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
2191 unsigned getByValSize() const {
2192 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
2194 void setByValSize(unsigned S) {
2195 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
2198 /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
2199 std::string getArgFlagsString();
2201 /// getRawBits - Represent the flags as a bunch of bits.
2202 uint64_t getRawBits() const { return Flags; }
2205 /// InputArg - This struct carries flags and type information about a
2206 /// single incoming (formal) argument or incoming (from the perspective
2207 /// of the caller) return value virtual register.
2214 InputArg() : VT(MVT::Other), Used(false) {}
2215 InputArg(ISD::ArgFlagsTy flags, EVT vt, bool used)
2216 : Flags(flags), VT(vt), Used(used) {
2217 assert(VT.isSimple() &&
2218 "InputArg value type must be Simple!");
2222 /// OutputArg - This struct carries flags and a value for a
2223 /// single outgoing (actual) argument or outgoing (from the perspective
2224 /// of the caller) return value virtual register.
2231 OutputArg() : IsFixed(false) {}
2232 OutputArg(ISD::ArgFlagsTy flags, SDValue val, bool isfixed)
2233 : Flags(flags), Val(val), IsFixed(isfixed) {
2234 assert(Val.getValueType().isSimple() &&
2235 "OutputArg value type must be Simple!");
2240 /// VTSDNode - This class is used to represent EVT's, which are used
2241 /// to parameterize some operations.
2242 class VTSDNode : public SDNode {
2244 friend class SelectionDAG;
2245 explicit VTSDNode(EVT VT)
2246 : SDNode(ISD::VALUETYPE, DebugLoc::getUnknownLoc(),
2247 getSDVTList(MVT::Other)), ValueType(VT) {
2251 EVT getVT() const { return ValueType; }
2253 static bool classof(const VTSDNode *) { return true; }
2254 static bool classof(const SDNode *N) {
2255 return N->getOpcode() == ISD::VALUETYPE;
2259 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
2261 class LSBaseSDNode : public MemSDNode {
2262 //! Operand array for load and store
2264 \note Moving this array to the base class captures more
2265 common functionality shared between LoadSDNode and
2270 LSBaseSDNode(ISD::NodeType NodeTy, DebugLoc dl, SDValue *Operands,
2271 unsigned numOperands, SDVTList VTs, ISD::MemIndexedMode AM,
2272 EVT VT, const Value *SV, int SVO, unsigned Align, bool Vol)
2273 : MemSDNode(NodeTy, dl, VTs, VT, SV, SVO, Align, Vol) {
2274 assert(Align != 0 && "Loads and stores should have non-zero aligment");
2275 SubclassData |= AM << 2;
2276 assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
2277 InitOperands(Ops, Operands, numOperands);
2278 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
2279 "Only indexed loads and stores have a non-undef offset operand");
2282 const SDValue &getOffset() const {
2283 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2286 /// getAddressingMode - Return the addressing mode for this load or store:
2287 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2288 ISD::MemIndexedMode getAddressingMode() const {
2289 return ISD::MemIndexedMode((SubclassData >> 2) & 7);
2292 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
2293 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2295 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
2296 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2298 static bool classof(const LSBaseSDNode *) { return true; }
2299 static bool classof(const SDNode *N) {
2300 return N->getOpcode() == ISD::LOAD ||
2301 N->getOpcode() == ISD::STORE;
2305 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2307 class LoadSDNode : public LSBaseSDNode {
2308 friend class SelectionDAG;
2309 LoadSDNode(SDValue *ChainPtrOff, DebugLoc dl, SDVTList VTs,
2310 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT LVT,
2311 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2312 : LSBaseSDNode(ISD::LOAD, dl, ChainPtrOff, 3,
2313 VTs, AM, LVT, SV, O, Align, Vol) {
2314 SubclassData |= (unsigned short)ETy;
2315 assert(getExtensionType() == ETy && "LoadExtType encoding error!");
2319 /// getExtensionType - Return whether this is a plain node,
2320 /// or one of the varieties of value-extending loads.
2321 ISD::LoadExtType getExtensionType() const {
2322 return ISD::LoadExtType(SubclassData & 3);
2325 const SDValue &getBasePtr() const { return getOperand(1); }
2326 const SDValue &getOffset() const { return getOperand(2); }
2328 static bool classof(const LoadSDNode *) { return true; }
2329 static bool classof(const SDNode *N) {
2330 return N->getOpcode() == ISD::LOAD;
2334 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2336 class StoreSDNode : public LSBaseSDNode {
2337 friend class SelectionDAG;
2338 StoreSDNode(SDValue *ChainValuePtrOff, DebugLoc dl, SDVTList VTs,
2339 ISD::MemIndexedMode AM, bool isTrunc, EVT SVT,
2340 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2341 : LSBaseSDNode(ISD::STORE, dl, ChainValuePtrOff, 4,
2342 VTs, AM, SVT, SV, O, Align, Vol) {
2343 SubclassData |= (unsigned short)isTrunc;
2344 assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
2348 /// isTruncatingStore - Return true if the op does a truncation before store.
2349 /// For integers this is the same as doing a TRUNCATE and storing the result.
2350 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2351 bool isTruncatingStore() const { return SubclassData & 1; }
2353 const SDValue &getValue() const { return getOperand(1); }
2354 const SDValue &getBasePtr() const { return getOperand(2); }
2355 const SDValue &getOffset() const { return getOperand(3); }
2357 static bool classof(const StoreSDNode *) { return true; }
2358 static bool classof(const SDNode *N) {
2359 return N->getOpcode() == ISD::STORE;
2364 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
2365 SDNode, ptrdiff_t> {
2369 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2371 bool operator==(const SDNodeIterator& x) const {
2372 return Operand == x.Operand;
2374 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2376 const SDNodeIterator &operator=(const SDNodeIterator &I) {
2377 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2378 Operand = I.Operand;
2382 pointer operator*() const {
2383 return Node->getOperand(Operand).getNode();
2385 pointer operator->() const { return operator*(); }
2387 SDNodeIterator& operator++() { // Preincrement
2391 SDNodeIterator operator++(int) { // Postincrement
2392 SDNodeIterator tmp = *this; ++*this; return tmp;
2395 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2396 static SDNodeIterator end (SDNode *N) {
2397 return SDNodeIterator(N, N->getNumOperands());
2400 unsigned getOperand() const { return Operand; }
2401 const SDNode *getNode() const { return Node; }
2404 template <> struct GraphTraits<SDNode*> {
2405 typedef SDNode NodeType;
2406 typedef SDNodeIterator ChildIteratorType;
2407 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2408 static inline ChildIteratorType child_begin(NodeType *N) {
2409 return SDNodeIterator::begin(N);
2411 static inline ChildIteratorType child_end(NodeType *N) {
2412 return SDNodeIterator::end(N);
2416 /// LargestSDNode - The largest SDNode class.
2418 typedef LoadSDNode LargestSDNode;
2420 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2423 typedef GlobalAddressSDNode MostAlignedSDNode;
2426 /// isNormalLoad - Returns true if the specified node is a non-extending
2427 /// and unindexed load.
2428 inline bool isNormalLoad(const SDNode *N) {
2429 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2430 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2431 Ld->getAddressingMode() == ISD::UNINDEXED;
2434 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2436 inline bool isNON_EXTLoad(const SDNode *N) {
2437 return isa<LoadSDNode>(N) &&
2438 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2441 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2443 inline bool isEXTLoad(const SDNode *N) {
2444 return isa<LoadSDNode>(N) &&
2445 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2448 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2450 inline bool isSEXTLoad(const SDNode *N) {
2451 return isa<LoadSDNode>(N) &&
2452 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2455 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2457 inline bool isZEXTLoad(const SDNode *N) {
2458 return isa<LoadSDNode>(N) &&
2459 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2462 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2464 inline bool isUNINDEXEDLoad(const SDNode *N) {
2465 return isa<LoadSDNode>(N) &&
2466 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2469 /// isNormalStore - Returns true if the specified node is a non-truncating
2470 /// and unindexed store.
2471 inline bool isNormalStore(const SDNode *N) {
2472 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2473 return St && !St->isTruncatingStore() &&
2474 St->getAddressingMode() == ISD::UNINDEXED;
2477 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2479 inline bool isNON_TRUNCStore(const SDNode *N) {
2480 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2483 /// isTRUNCStore - Returns true if the specified node is a truncating
2485 inline bool isTRUNCStore(const SDNode *N) {
2486 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2489 /// isUNINDEXEDStore - Returns true if the specified node is an
2490 /// unindexed store.
2491 inline bool isUNINDEXEDStore(const SDNode *N) {
2492 return isa<StoreSDNode>(N) &&
2493 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2498 } // end llvm namespace