1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG. These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
22 #include "llvm/Value.h"
23 #include "llvm/Constants.h"
24 #include "llvm/GlobalValue.h"
25 #include "llvm/ADT/FoldingSet.h"
26 #include "llvm/ADT/GraphTraits.h"
27 #include "llvm/ADT/iterator.h"
28 #include "llvm/ADT/ilist_node.h"
29 #include "llvm/ADT/STLExtras.h"
30 #include "llvm/CodeGen/ValueTypes.h"
31 #include "llvm/CodeGen/MachineMemOperand.h"
32 #include "llvm/Support/Allocator.h"
33 #include "llvm/Support/RecyclingAllocator.h"
34 #include "llvm/Support/DataTypes.h"
41 class MachineBasicBlock;
42 class MachineConstantPoolValue;
44 class CompileUnitDesc;
45 template <typename T> struct DenseMapInfo;
46 template <typename T> struct simplify_type;
47 template <typename T> class ilist_traits;
49 /// SDVTList - This represents a list of ValueType's that has been intern'd by
50 /// a SelectionDAG. Instances of this simple value class are returned by
51 /// SelectionDAG::getVTList(...).
55 unsigned short NumVTs;
58 /// ISD namespace - This namespace contains an enum which represents all of the
59 /// SelectionDAG node types and value types.
61 /// If you add new elements here you should increase OpActionsCapacity in
62 /// TargetLowering.h by the number of new elements.
65 //===--------------------------------------------------------------------===//
66 /// ISD::NodeType enum - This enum defines all of the operators valid in a
70 // DELETED_NODE - This is an illegal flag value that is used to catch
71 // errors. This opcode is not a legal opcode for any node.
74 // EntryToken - This is the marker used to indicate the start of the region.
77 // Token factor - This node takes multiple tokens as input and produces a
78 // single token result. This is used to represent the fact that the operand
79 // operators are independent of each other.
82 // AssertSext, AssertZext - These nodes record if a register contains a
83 // value that has already been zero or sign extended from a narrower type.
84 // These nodes take two operands. The first is the node that has already
85 // been extended, and the second is a value type node indicating the width
87 AssertSext, AssertZext,
89 // Various leaf nodes.
90 BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
92 GlobalAddress, GlobalTLSAddress, FrameIndex,
93 JumpTable, ConstantPool, Symbol,
95 // The address of the GOT
98 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
99 // llvm.returnaddress on the DAG. These nodes take one operand, the index
100 // of the frame or return address to return. An index of zero corresponds
101 // to the current function's frame or return address, an index of one to the
102 // parent's frame or return address, and so on.
103 FRAMEADDR, RETURNADDR,
105 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
106 // first (possible) on-stack argument. This is needed for correct stack
107 // adjustment during unwind.
108 FRAME_TO_ARGS_OFFSET,
110 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
111 // address of the exception block on entry to an landing pad block.
114 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
115 // the selection index of the exception thrown.
118 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
119 // 'eh_return' gcc dwarf builtin, which is used to return from
120 // exception. The general meaning is: adjust stack by OFFSET and pass
121 // execution to HANDLER. Many platform-related details also :)
124 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
125 // simplification of the constant.
129 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
130 // anything else with this node, and this is valid in the target-specific
131 // dag, turning into a GlobalAddress operand.
133 TargetGlobalTLSAddress,
139 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
140 /// This node represents a target intrinsic function with no side effects.
141 /// The first operand is the ID number of the intrinsic from the
142 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
143 /// node has returns the result of the intrinsic.
146 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
147 /// This node represents a target intrinsic function with side effects that
148 /// returns a result. The first operand is a chain pointer. The second is
149 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
150 /// operands to the intrinsic follow. The node has two results, the result
151 /// of the intrinsic and an output chain.
154 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
155 /// This node represents a target intrinsic function with side effects that
156 /// does not return a result. The first operand is a chain pointer. The
157 /// second is the ID number of the intrinsic from the llvm::Intrinsic
158 /// namespace. The operands to the intrinsic follow.
161 // CopyToReg - This node has three operands: a chain, a register number to
162 // set to this value, and a value.
165 // CopyFromReg - This node indicates that the input value is a virtual or
166 // physical register that is defined outside of the scope of this
167 // SelectionDAG. The register is available from the RegisterSDNode object.
170 // UNDEF - An undefined node
173 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
174 /// represents the formal arguments for a function. CC# is a Constant value
175 /// indicating the calling convention of the function, and ISVARARG is a
176 /// flag that indicates whether the function is varargs or not. This node
177 /// has one result value for each incoming argument, plus one for the output
178 /// chain. It must be custom legalized. See description of CALL node for
179 /// FLAG argument contents explanation.
183 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CALLEE,
184 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
185 /// This node represents a fully general function call, before the legalizer
186 /// runs. This has one result value for each argument / flag pair, plus
187 /// a chain result. It must be custom legalized. Flag argument indicates
188 /// misc. argument attributes. Currently:
190 /// Bit 1 - 'inreg' attribute
191 /// Bit 2 - 'sret' attribute
192 /// Bit 4 - 'byval' attribute
193 /// Bit 5 - 'nest' attribute
194 /// Bit 6-9 - alignment of byval structures
195 /// Bit 10-26 - size of byval structures
196 /// Bits 31:27 - argument ABI alignment in the first argument piece and
197 /// alignment '1' in other argument pieces.
199 /// CALL nodes use the CallSDNode subclass of SDNode, which
200 /// additionally carries information about the calling convention,
201 /// whether the call is varargs, and if it's marked as a tail call.
205 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
206 // a Constant, which is required to be operand #1) half of the integer or
207 // float value specified as operand #0. This is only for use before
208 // legalization, for values that will be broken into multiple registers.
211 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
212 // two values of the same integer value type, this produces a value twice as
213 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
216 // MERGE_VALUES - This node takes multiple discrete operands and returns
217 // them all as its individual results. This nodes has exactly the same
218 // number of inputs and outputs, and is only valid before legalization.
219 // This node is useful for some pieces of the code generator that want to
220 // think about a single node with multiple results, not multiple nodes.
223 // Simple integer binary arithmetic operators.
224 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
226 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
227 // a signed/unsigned value of type i[2*N], and return the full value as
228 // two results, each of type iN.
229 SMUL_LOHI, UMUL_LOHI,
231 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
235 // CARRY_FALSE - This node is used when folding other nodes,
236 // like ADDC/SUBC, which indicate the carry result is always false.
239 // Carry-setting nodes for multiple precision addition and subtraction.
240 // These nodes take two operands of the same value type, and produce two
241 // results. The first result is the normal add or sub result, the second
242 // result is the carry flag result.
245 // Carry-using nodes for multiple precision addition and subtraction. These
246 // nodes take three operands: The first two are the normal lhs and rhs to
247 // the add or sub, and the third is the input carry flag. These nodes
248 // produce two results; the normal result of the add or sub, and the output
249 // carry flag. These nodes both read and write a carry flag to allow them
250 // to them to be chained together for add and sub of arbitrarily large
254 // Simple binary floating point operators.
255 FADD, FSUB, FMUL, FDIV, FREM,
257 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
258 // DAG node does not require that X and Y have the same type, just that they
259 // are both floating point. X and the result must have the same type.
260 // FCOPYSIGN(f32, f64) is allowed.
263 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
264 // value as an integer 0/1 value.
267 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
268 /// with the specified, possibly variable, elements. The number of elements
269 /// is required to be a power of two.
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.
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, SHUFFLEVEC) - Returns a vector, of the same
293 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
294 /// (maybe of an illegal datatype) or undef that indicate which value each
295 /// result element will get. The elements of VEC1/VEC2 are enumerated in
296 /// order. This is quite similar to the Altivec 'vperm' instruction, except
297 /// that the indices must be constants and are in terms of the element size
298 /// 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.
306 // EXTRACT_SUBREG - This node is used to extract a sub-register value.
307 // This node takes a superreg and a constant sub-register index as operands.
308 // Note sub-register indices must be increasing. That is, if the
309 // sub-register index of a 8-bit sub-register is N, then the index for a
310 // 16-bit sub-register must be at least N+1.
313 // INSERT_SUBREG - This node is used to insert a sub-register value.
314 // This node takes a superreg, a subreg value, and a constant sub-register
315 // index as operands.
318 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
319 // an unsigned/signed value of type i[2*N], then return the top part.
322 // Bitwise operators - logical and, logical or, logical xor, shift left,
323 // shift right algebraic (shift in sign bits), shift right logical (shift in
324 // zeroes), rotate left, rotate right, and byteswap.
325 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
327 // Counting operators
330 // Select(COND, TRUEVAL, FALSEVAL)
333 // Select with condition operator - This selects between a true value and
334 // a false value (ops #2 and #3) based on the boolean result of comparing
335 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
336 // condition code in op #4, a CondCodeSDNode.
339 // SetCC operator - This evaluates to a boolean (i1) true value if the
340 // condition is true. The operands to this are the left and right operands
341 // to compare (ops #0, and #1) and the condition code to compare them with
342 // (op #2) as a CondCodeSDNode.
345 // Vector SetCC operator - This evaluates to a vector of integer elements
346 // with the high bit in each element set to true if the comparison is true
347 // and false if the comparison is false. All other bits in each element
348 // are undefined. The operands to this are the left and right operands
349 // to compare (ops #0, and #1) and the condition code to compare them with
350 // (op #2) as a CondCodeSDNode.
353 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
354 // integer shift operations, just like ADD/SUB_PARTS. The operation
356 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
357 SHL_PARTS, SRA_PARTS, SRL_PARTS,
359 // Conversion operators. These are all single input single output
360 // operations. For all of these, the result type must be strictly
361 // wider or narrower (depending on the operation) than the source
364 // SIGN_EXTEND - Used for integer types, replicating the sign bit
368 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
371 // ANY_EXTEND - Used for integer types. The high bits are undefined.
374 // TRUNCATE - Completely drop the high bits.
377 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
378 // depends on the first letter) to floating point.
382 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
383 // sign extend a small value in a large integer register (e.g. sign
384 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
385 // with the 7th bit). The size of the smaller type is indicated by the 1th
386 // operand, a ValueType node.
389 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
394 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
395 /// down to the precision of the destination VT. TRUNC is a flag, which is
396 /// always an integer that is zero or one. If TRUNC is 0, this is a
397 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
400 /// The TRUNC = 1 case is used in cases where we know that the value will
401 /// not be modified by the node, because Y is not using any of the extra
402 /// precision of source type. This allows certain transformations like
403 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
404 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
407 // FLT_ROUNDS_ - Returns current rounding mode:
410 // 1 Round to nearest
415 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
416 /// rounds it to a floating point value. It then promotes it and returns it
417 /// in a register of the same size. This operation effectively just
418 /// discards excess precision. The type to round down to is specified by
419 /// the VT operand, a VTSDNode.
422 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
425 // BIT_CONVERT - Theis operator converts between integer and FP values, as
426 // if one was stored to memory as integer and the other was loaded from the
427 // same address (or equivalently for vector format conversions, etc). The
428 // source and result are required to have the same bit size (e.g.
429 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
430 // conversions, but that is a noop, deleted by getNode().
433 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
434 // FLOG, FLOG2, FLOG10, FEXP, FEXP2,
435 // FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary floating
436 // point operations. These are inspired by libm.
437 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
438 FLOG, FLOG2, FLOG10, FEXP, FEXP2,
439 FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR,
441 // LOAD and STORE have token chains as their first operand, then the same
442 // operands as an LLVM load/store instruction, then an offset node that
443 // is added / subtracted from the base pointer to form the address (for
444 // indexed memory ops).
447 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
448 // to a specified boundary. This node always has two return values: a new
449 // stack pointer value and a chain. The first operand is the token chain,
450 // the second is the number of bytes to allocate, and the third is the
451 // alignment boundary. The size is guaranteed to be a multiple of the stack
452 // alignment, and the alignment is guaranteed to be bigger than the stack
453 // alignment (if required) or 0 to get standard stack alignment.
456 // Control flow instructions. These all have token chains.
458 // BR - Unconditional branch. The first operand is the chain
459 // operand, the second is the MBB to branch to.
462 // BRIND - Indirect branch. The first operand is the chain, the second
463 // is the value to branch to, which must be of the same type as the target's
467 // BR_JT - Jumptable branch. The first operand is the chain, the second
468 // is the jumptable index, the last one is the jumptable entry index.
471 // BRCOND - Conditional branch. The first operand is the chain,
472 // the second is the condition, the third is the block to branch
473 // to if the condition is true.
476 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
477 // that the condition is represented as condition code, and two nodes to
478 // compare, rather than as a combined SetCC node. The operands in order are
479 // chain, cc, lhs, rhs, block to branch to if condition is true.
482 // RET - Return from function. The first operand is the chain,
483 // and any subsequent operands are pairs of return value and return value
484 // signness for the function. This operation can have variable number of
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 SymbolSDNode 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 // DBG_LABEL, 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.
503 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
504 // local variable declarations for debugging information. First operand is
505 // a chain, while the next two operands are first two arguments (address
506 // and variable) of a llvm.dbg.declare instruction.
509 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
510 // value, the same type as the pointer type for the system, and an output
514 // STACKRESTORE has two operands, an input chain and a pointer to restore to
515 // it returns an output chain.
518 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
519 // a call sequence, and carry arbitrary information that target might want
520 // to know. The first operand is a chain, the rest are specified by the
521 // target and not touched by the DAG optimizers.
522 // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
523 CALLSEQ_START, // Beginning of a call sequence
524 CALLSEQ_END, // End of a call sequence
526 // VAARG - VAARG has three operands: an input chain, a pointer, and a
527 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
530 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
531 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
535 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
536 // pointer, and a SRCVALUE.
539 // SRCVALUE - This is a node type that holds a Value* that is used to
540 // make reference to a value in the LLVM IR.
543 // MEMOPERAND - This is a node that contains a MachineMemOperand which
544 // records information about a memory reference. This is used to make
545 // AliasAnalysis queries from the backend.
548 // PCMARKER - This corresponds to the pcmarker intrinsic.
551 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
552 // The only operand is a chain and a value and a chain are produced. The
553 // value is the contents of the architecture specific cycle counter like
554 // register (or other high accuracy low latency clock source)
557 // HANDLENODE node - Used as a handle for various purposes.
560 // DBG_STOPPOINT - This node is used to represent a source location for
561 // debug info. It takes token chain as input, and carries a line number,
562 // column number, and a pointer to a CompileUnitDesc object identifying
563 // the containing compilation unit. It produces a token chain as output.
566 // DEBUG_LOC - This node is used to represent source line information
567 // embedded in the code. It takes a token chain as input, then a line
568 // number, then a column then a file id (provided by MachineModuleInfo.) It
569 // produces a token chain as output.
572 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
573 // It takes as input a token chain, the pointer to the trampoline,
574 // the pointer to the nested function, the pointer to pass for the
575 // 'nest' parameter, a SRCVALUE for the trampoline and another for
576 // the nested function (allowing targets to access the original
577 // Function*). It produces the result of the intrinsic and a token
581 // TRAP - Trapping instruction
584 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
585 // their first operand. The other operands are the address to prefetch,
586 // read / write specifier, and locality specifier.
589 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
590 // store-store, device)
591 // This corresponds to the memory.barrier intrinsic.
592 // it takes an input chain, 4 operands to specify the type of barrier, an
593 // operand specifying if the barrier applies to device and uncached memory
594 // and produces an output chain.
597 // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
598 // this corresponds to the atomic.lcs intrinsic.
599 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
600 // the return is always the original value in *ptr
606 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
607 // this corresponds to the atomic.swap intrinsic.
608 // amt is stored to *ptr atomically.
609 // the return is always the original value in *ptr
615 // Val, OUTCHAIN = ATOMIC_L[OpName]S(INCHAIN, ptr, amt)
616 // this corresponds to the atomic.[OpName] intrinsic.
617 // op(*ptr, amt) is stored to *ptr atomically.
618 // the return is always the original value in *ptr
660 // BUILTIN_OP_END - This must be the last enum value in this list.
666 /// isBuildVectorAllOnes - Return true if the specified node is a
667 /// BUILD_VECTOR where all of the elements are ~0 or undef.
668 bool isBuildVectorAllOnes(const SDNode *N);
670 /// isBuildVectorAllZeros - Return true if the specified node is a
671 /// BUILD_VECTOR where all of the elements are 0 or undef.
672 bool isBuildVectorAllZeros(const SDNode *N);
674 /// isScalarToVector - Return true if the specified node is a
675 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
676 /// element is not an undef.
677 bool isScalarToVector(const SDNode *N);
679 /// isDebugLabel - Return true if the specified node represents a debug
680 /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node).
681 bool isDebugLabel(const SDNode *N);
683 //===--------------------------------------------------------------------===//
684 /// MemIndexedMode enum - This enum defines the load / store indexed
685 /// addressing modes.
687 /// UNINDEXED "Normal" load / store. The effective address is already
688 /// computed and is available in the base pointer. The offset
689 /// operand is always undefined. In addition to producing a
690 /// chain, an unindexed load produces one value (result of the
691 /// load); an unindexed store does not produce a value.
693 /// PRE_INC Similar to the unindexed mode where the effective address is
694 /// PRE_DEC the value of the base pointer add / subtract the offset.
695 /// It considers the computation as being folded into the load /
696 /// store operation (i.e. the load / store does the address
697 /// computation as well as performing the memory transaction).
698 /// The base operand is always undefined. In addition to
699 /// producing a chain, pre-indexed load produces two values
700 /// (result of the load and the result of the address
701 /// computation); a pre-indexed store produces one value (result
702 /// of the address computation).
704 /// POST_INC The effective address is the value of the base pointer. The
705 /// POST_DEC value of the offset operand is then added to / subtracted
706 /// from the base after memory transaction. In addition to
707 /// producing a chain, post-indexed load produces two values
708 /// (the result of the load and the result of the base +/- offset
709 /// computation); a post-indexed store produces one value (the
710 /// the result of the base +/- offset computation).
712 enum MemIndexedMode {
721 //===--------------------------------------------------------------------===//
722 /// LoadExtType enum - This enum defines the three variants of LOADEXT
723 /// (load with extension).
725 /// SEXTLOAD loads the integer operand and sign extends it to a larger
726 /// integer result type.
727 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
728 /// integer result type.
729 /// EXTLOAD is used for three things: floating point extending loads,
730 /// integer extending loads [the top bits are undefined], and vector
731 /// extending loads [load into low elt].
741 //===--------------------------------------------------------------------===//
742 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
743 /// below work out, when considering SETFALSE (something that never exists
744 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
745 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
746 /// to. If the "N" column is 1, the result of the comparison is undefined if
747 /// the input is a NAN.
749 /// All of these (except for the 'always folded ops') should be handled for
750 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
751 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
753 /// Note that these are laid out in a specific order to allow bit-twiddling
754 /// to transform conditions.
756 // Opcode N U L G E Intuitive operation
757 SETFALSE, // 0 0 0 0 Always false (always folded)
758 SETOEQ, // 0 0 0 1 True if ordered and equal
759 SETOGT, // 0 0 1 0 True if ordered and greater than
760 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
761 SETOLT, // 0 1 0 0 True if ordered and less than
762 SETOLE, // 0 1 0 1 True if ordered and less than or equal
763 SETONE, // 0 1 1 0 True if ordered and operands are unequal
764 SETO, // 0 1 1 1 True if ordered (no nans)
765 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
766 SETUEQ, // 1 0 0 1 True if unordered or equal
767 SETUGT, // 1 0 1 0 True if unordered or greater than
768 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
769 SETULT, // 1 1 0 0 True if unordered or less than
770 SETULE, // 1 1 0 1 True if unordered, less than, or equal
771 SETUNE, // 1 1 1 0 True if unordered or not equal
772 SETTRUE, // 1 1 1 1 Always true (always folded)
773 // Don't care operations: undefined if the input is a nan.
774 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
775 SETEQ, // 1 X 0 0 1 True if equal
776 SETGT, // 1 X 0 1 0 True if greater than
777 SETGE, // 1 X 0 1 1 True if greater than or equal
778 SETLT, // 1 X 1 0 0 True if less than
779 SETLE, // 1 X 1 0 1 True if less than or equal
780 SETNE, // 1 X 1 1 0 True if not equal
781 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
783 SETCC_INVALID // Marker value.
786 /// isSignedIntSetCC - Return true if this is a setcc instruction that
787 /// performs a signed comparison when used with integer operands.
788 inline bool isSignedIntSetCC(CondCode Code) {
789 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
792 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
793 /// performs an unsigned comparison when used with integer operands.
794 inline bool isUnsignedIntSetCC(CondCode Code) {
795 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
798 /// isTrueWhenEqual - Return true if the specified condition returns true if
799 /// the two operands to the condition are equal. Note that if one of the two
800 /// operands is a NaN, this value is meaningless.
801 inline bool isTrueWhenEqual(CondCode Cond) {
802 return ((int)Cond & 1) != 0;
805 /// getUnorderedFlavor - This function returns 0 if the condition is always
806 /// false if an operand is a NaN, 1 if the condition is always true if the
807 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
809 inline unsigned getUnorderedFlavor(CondCode Cond) {
810 return ((int)Cond >> 3) & 3;
813 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
814 /// 'op' is a valid SetCC operation.
815 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
817 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
818 /// when given the operation for (X op Y).
819 CondCode getSetCCSwappedOperands(CondCode Operation);
821 /// getSetCCOrOperation - Return the result of a logical OR between different
822 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
823 /// function returns SETCC_INVALID if it is not possible to represent the
824 /// resultant comparison.
825 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
827 /// getSetCCAndOperation - Return the result of a logical AND between
828 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
829 /// function returns SETCC_INVALID if it is not possible to represent the
830 /// resultant comparison.
831 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
832 } // end llvm::ISD namespace
835 //===----------------------------------------------------------------------===//
836 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
837 /// values as the result of a computation. Many nodes return multiple values,
838 /// from loads (which define a token and a return value) to ADDC (which returns
839 /// a result and a carry value), to calls (which may return an arbitrary number
842 /// As such, each use of a SelectionDAG computation must indicate the node that
843 /// computes it as well as which return value to use from that node. This pair
844 /// of information is represented with the SDValue value type.
847 SDNode *Node; // The node defining the value we are using.
848 unsigned ResNo; // Which return value of the node we are using.
850 SDValue() : Node(0), ResNo(0) {}
851 SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
853 /// get the index which selects a specific result in the SDNode
854 unsigned getResNo() const { return ResNo; }
856 /// get the SDNode which holds the desired result
857 SDNode *getNode() const { return Node; }
860 void setNode(SDNode *N) { Node = N; }
862 bool operator==(const SDValue &O) const {
863 return Node == O.Node && ResNo == O.ResNo;
865 bool operator!=(const SDValue &O) const {
866 return !operator==(O);
868 bool operator<(const SDValue &O) const {
869 return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
872 SDValue getValue(unsigned R) const {
873 return SDValue(Node, R);
876 // isOperandOf - Return true if this node is an operand of N.
877 bool isOperandOf(SDNode *N) const;
879 /// getValueType - Return the ValueType of the referenced return value.
881 inline MVT getValueType() const;
883 /// getValueSizeInBits - Returns the size of the value in bits.
885 unsigned getValueSizeInBits() const {
886 return getValueType().getSizeInBits();
889 // Forwarding methods - These forward to the corresponding methods in SDNode.
890 inline unsigned getOpcode() const;
891 inline unsigned getNumOperands() const;
892 inline const SDValue &getOperand(unsigned i) const;
893 inline uint64_t getConstantOperandVal(unsigned i) const;
894 inline bool isTargetOpcode() const;
895 inline bool isMachineOpcode() const;
896 inline unsigned getMachineOpcode() const;
899 /// reachesChainWithoutSideEffects - Return true if this operand (which must
900 /// be a chain) reaches the specified operand without crossing any
901 /// side-effecting instructions. In practice, this looks through token
902 /// factors and non-volatile loads. In order to remain efficient, this only
903 /// looks a couple of nodes in, it does not do an exhaustive search.
904 bool reachesChainWithoutSideEffects(SDValue Dest,
905 unsigned Depth = 2) const;
907 /// use_empty - Return true if there are no nodes using value ResNo
910 inline bool use_empty() const;
912 /// hasOneUse - Return true if there is exactly one node using value
915 inline bool hasOneUse() const;
919 template<> struct DenseMapInfo<SDValue> {
920 static inline SDValue getEmptyKey() {
921 return SDValue((SDNode*)-1, -1U);
923 static inline SDValue getTombstoneKey() {
924 return SDValue((SDNode*)-1, 0);
926 static unsigned getHashValue(const SDValue &Val) {
927 return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
928 (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
930 static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
933 static bool isPod() { return true; }
936 /// simplify_type specializations - Allow casting operators to work directly on
937 /// SDValues as if they were SDNode*'s.
938 template<> struct simplify_type<SDValue> {
939 typedef SDNode* SimpleType;
940 static SimpleType getSimplifiedValue(const SDValue &Val) {
941 return static_cast<SimpleType>(Val.getNode());
944 template<> struct simplify_type<const SDValue> {
945 typedef SDNode* SimpleType;
946 static SimpleType getSimplifiedValue(const SDValue &Val) {
947 return static_cast<SimpleType>(Val.getNode());
951 /// SDUse - Represents a use of the SDNode referred by
955 /// User - Parent node of this operand.
957 /// Prev, next - Pointers to the uses list of the SDNode referred by
962 SDUse(): Operand(), User(NULL), Prev(NULL), Next(NULL) {}
964 SDUse(SDNode *val, unsigned resno) :
965 Operand(val,resno), User(NULL), Prev(NULL), Next(NULL) {}
967 SDUse& operator= (const SDValue& Op) {
974 SDUse& operator= (const SDUse& Op) {
981 SDUse *getNext() { return Next; }
983 SDNode *getUser() { return User; }
985 void setUser(SDNode *p) { User = p; }
987 operator SDValue() const { return Operand; }
989 const SDValue& getSDValue() const { return Operand; }
991 SDValue &getSDValue() { return Operand; }
992 SDNode *getVal() { return Operand.getNode(); }
993 SDNode *getVal() const { return Operand.getNode(); } // FIXME: const correct?
995 bool operator==(const SDValue &O) const {
999 bool operator!=(const SDValue &O) const {
1000 return !(Operand == O);
1003 bool operator<(const SDValue &O) const {
1008 void addToList(SDUse **List) {
1010 if (Next) Next->Prev = &Next;
1015 void removeFromList() {
1017 if (Next) Next->Prev = Prev;
1022 /// simplify_type specializations - Allow casting operators to work directly on
1023 /// SDValues as if they were SDNode*'s.
1024 template<> struct simplify_type<SDUse> {
1025 typedef SDNode* SimpleType;
1026 static SimpleType getSimplifiedValue(const SDUse &Val) {
1027 return static_cast<SimpleType>(Val.getVal());
1030 template<> struct simplify_type<const SDUse> {
1031 typedef SDNode* SimpleType;
1032 static SimpleType getSimplifiedValue(const SDUse &Val) {
1033 return static_cast<SimpleType>(Val.getVal());
1038 /// SDOperandPtr - A helper SDValue pointer class, that can handle
1039 /// arrays of SDUse and arrays of SDValue objects. This is required
1040 /// in many places inside the SelectionDAG.
1042 class SDOperandPtr {
1043 const SDValue *ptr; // The pointer to the SDValue object
1044 int object_size; // The size of the object containg the SDValue
1046 SDOperandPtr() : ptr(0), object_size(0) {}
1048 SDOperandPtr(SDUse * use_ptr) {
1049 ptr = &use_ptr->getSDValue();
1050 object_size = (int)sizeof(SDUse);
1053 SDOperandPtr(const SDValue * op_ptr) {
1055 object_size = (int)sizeof(SDValue);
1058 const SDValue operator *() { return *ptr; }
1059 const SDValue *operator ->() { return ptr; }
1060 SDOperandPtr operator ++ () {
1061 ptr = (SDValue*)((char *)ptr + object_size);
1065 SDOperandPtr operator ++ (int) {
1066 SDOperandPtr tmp = *this;
1067 ptr = (SDValue*)((char *)ptr + object_size);
1071 SDValue operator[] (int idx) const {
1072 return *(SDValue*)((char*) ptr + object_size * idx);
1076 /// SDNode - Represents one node in the SelectionDAG.
1078 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
1080 /// NodeType - The operation that this node performs.
1084 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
1085 /// then they will be delete[]'d when the node is destroyed.
1086 unsigned short OperandsNeedDelete : 1;
1089 /// SubclassData - This member is defined by this class, but is not used for
1090 /// anything. Subclasses can use it to hold whatever state they find useful.
1091 /// This field is initialized to zero by the ctor.
1092 unsigned short SubclassData : 15;
1095 /// NodeId - Unique id per SDNode in the DAG.
1098 /// OperandList - The values that are used by this operation.
1102 /// ValueList - The types of the values this node defines. SDNode's may
1103 /// define multiple values simultaneously.
1104 const MVT *ValueList;
1106 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1107 unsigned short NumOperands, NumValues;
1109 /// Uses - List of uses for this SDNode.
1112 /// addUse - add SDUse to the list of uses.
1113 void addUse(SDUse &U) { U.addToList(&Uses); }
1115 // Out-of-line virtual method to give class a home.
1116 virtual void ANCHOR();
1119 assert(NumOperands == 0 && "Operand list not cleared before deletion");
1120 NodeType = ISD::DELETED_NODE;
1123 //===--------------------------------------------------------------------===//
1127 /// getOpcode - Return the SelectionDAG opcode value for this node. For
1128 /// pre-isel nodes (those for which isMachineOpcode returns false), these
1129 /// are the opcode values in the ISD and <target>ISD namespaces. For
1130 /// post-isel opcodes, see getMachineOpcode.
1131 unsigned getOpcode() const { return (unsigned short)NodeType; }
1133 /// isTargetOpcode - Test if this node has a target-specific opcode (in the
1134 /// <target>ISD namespace).
1135 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1137 /// isMachineOpcode - Test if this node has a post-isel opcode, directly
1138 /// corresponding to a MachineInstr opcode.
1139 bool isMachineOpcode() const { return NodeType < 0; }
1141 /// getMachineOpcode - This may only be called if isMachineOpcode returns
1142 /// true. It returns the MachineInstr opcode value that the node's opcode
1144 unsigned getMachineOpcode() const {
1145 assert(isMachineOpcode() && "Not a MachineInstr opcode!");
1149 /// use_empty - Return true if there are no uses of this node.
1151 bool use_empty() const { return Uses == NULL; }
1153 /// hasOneUse - Return true if there is exactly one use of this node.
1155 bool hasOneUse() const {
1156 return !use_empty() && next(use_begin()) == use_end();
1159 /// use_size - Return the number of uses of this node. This method takes
1160 /// time proportional to the number of uses.
1162 size_t use_size() const { return std::distance(use_begin(), use_end()); }
1164 /// getNodeId - Return the unique node id.
1166 int getNodeId() const { return NodeId; }
1168 /// setNodeId - Set unique node id.
1169 void setNodeId(int Id) { NodeId = Id; }
1171 /// use_iterator - This class provides iterator support for SDUse
1172 /// operands that use a specific SDNode.
1174 : public forward_iterator<SDUse, ptrdiff_t> {
1176 explicit use_iterator(SDUse *op) : Op(op) {
1178 friend class SDNode;
1180 typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
1181 typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1183 use_iterator(const use_iterator &I) : Op(I.Op) {}
1184 use_iterator() : Op(0) {}
1186 bool operator==(const use_iterator &x) const {
1189 bool operator!=(const use_iterator &x) const {
1190 return !operator==(x);
1193 /// atEnd - return true if this iterator is at the end of uses list.
1194 bool atEnd() const { return Op == 0; }
1196 // Iterator traversal: forward iteration only.
1197 use_iterator &operator++() { // Preincrement
1198 assert(Op && "Cannot increment end iterator!");
1203 use_iterator operator++(int) { // Postincrement
1204 use_iterator tmp = *this; ++*this; return tmp;
1207 /// Retrieve a pointer to the current user node.
1208 SDNode *operator*() const {
1209 assert(Op && "Cannot dereference end iterator!");
1210 return Op->getUser();
1213 SDNode *operator->() const { return operator*(); }
1215 SDUse &getUse() const { return *Op; }
1217 /// getOperandNo - Retrive the operand # of this use in its user.
1219 unsigned getOperandNo() const {
1220 assert(Op && "Cannot dereference end iterator!");
1221 return (unsigned)(Op - Op->getUser()->OperandList);
1225 /// use_begin/use_end - Provide iteration support to walk over all uses
1228 use_iterator use_begin() const {
1229 return use_iterator(Uses);
1232 static use_iterator use_end() { return use_iterator(0); }
1235 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1236 /// indicated value. This method ignores uses of other values defined by this
1238 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1240 /// hasAnyUseOfValue - Return true if there are any use of the indicated
1241 /// value. This method ignores uses of other values defined by this operation.
1242 bool hasAnyUseOfValue(unsigned Value) const;
1244 /// isOnlyUserOf - Return true if this node is the only use of N.
1246 bool isOnlyUserOf(SDNode *N) const;
1248 /// isOperandOf - Return true if this node is an operand of N.
1250 bool isOperandOf(SDNode *N) const;
1252 /// isPredecessorOf - Return true if this node is a predecessor of N. This
1253 /// node is either an operand of N or it can be reached by recursively
1254 /// traversing up the operands.
1255 /// NOTE: this is an expensive method. Use it carefully.
1256 bool isPredecessorOf(SDNode *N) const;
1258 /// getNumOperands - Return the number of values used by this operation.
1260 unsigned getNumOperands() const { return NumOperands; }
1262 /// getConstantOperandVal - Helper method returns the integer value of a
1263 /// ConstantSDNode operand.
1264 uint64_t getConstantOperandVal(unsigned Num) const;
1266 const SDValue &getOperand(unsigned Num) const {
1267 assert(Num < NumOperands && "Invalid child # of SDNode!");
1268 return OperandList[Num].getSDValue();
1271 typedef SDUse* op_iterator;
1272 op_iterator op_begin() const { return OperandList; }
1273 op_iterator op_end() const { return OperandList+NumOperands; }
1276 SDVTList getVTList() const {
1277 SDVTList X = { ValueList, NumValues };
1281 /// getNumValues - Return the number of values defined/returned by this
1284 unsigned getNumValues() const { return NumValues; }
1286 /// getValueType - Return the type of a specified result.
1288 MVT getValueType(unsigned ResNo) const {
1289 assert(ResNo < NumValues && "Illegal result number!");
1290 return ValueList[ResNo];
1293 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1295 unsigned getValueSizeInBits(unsigned ResNo) const {
1296 return getValueType(ResNo).getSizeInBits();
1299 typedef const MVT* value_iterator;
1300 value_iterator value_begin() const { return ValueList; }
1301 value_iterator value_end() const { return ValueList+NumValues; }
1303 /// getOperationName - Return the opcode of this operation for printing.
1305 std::string getOperationName(const SelectionDAG *G = 0) const;
1306 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1307 void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
1309 void dump(const SelectionDAG *G) const;
1311 static bool classof(const SDNode *) { return true; }
1313 /// Profile - Gather unique data for the node.
1315 void Profile(FoldingSetNodeID &ID) const;
1318 friend class SelectionDAG;
1319 friend class ilist_traits<SDNode>;
1321 /// getValueTypeList - Return a pointer to the specified value type.
1323 static const MVT *getValueTypeList(MVT VT);
1324 static SDVTList getSDVTList(MVT VT) {
1325 SDVTList Ret = { getValueTypeList(VT), 1 };
1329 SDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps)
1330 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1331 NodeId(-1), Uses(NULL) {
1332 NumOperands = NumOps;
1333 OperandList = NumOps ? new SDUse[NumOperands] : 0;
1335 for (unsigned i = 0; i != NumOps; ++i) {
1336 OperandList[i] = Ops[i];
1337 OperandList[i].setUser(this);
1338 Ops[i].getNode()->addUse(OperandList[i]);
1341 ValueList = VTs.VTs;
1342 NumValues = VTs.NumVTs;
1345 SDNode(unsigned Opc, SDVTList VTs, const SDUse *Ops, unsigned NumOps)
1346 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1347 NodeId(-1), Uses(NULL) {
1348 OperandsNeedDelete = true;
1349 NumOperands = NumOps;
1350 OperandList = NumOps ? new SDUse[NumOperands] : 0;
1352 for (unsigned i = 0; i != NumOps; ++i) {
1353 OperandList[i] = Ops[i];
1354 OperandList[i].setUser(this);
1355 Ops[i].getVal()->addUse(OperandList[i]);
1358 ValueList = VTs.VTs;
1359 NumValues = VTs.NumVTs;
1362 /// This constructor adds no operands itself; operands can be
1363 /// set later with InitOperands.
1364 SDNode(unsigned Opc, SDVTList VTs)
1365 : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1366 NodeId(-1), Uses(NULL) {
1369 ValueList = VTs.VTs;
1370 NumValues = VTs.NumVTs;
1373 /// InitOperands - Initialize the operands list of this node with the
1374 /// specified values, which are part of the node (thus they don't need to be
1375 /// copied in or allocated).
1376 void InitOperands(SDUse *Ops, unsigned NumOps) {
1377 assert(OperandList == 0 && "Operands already set!");
1378 NumOperands = NumOps;
1382 for (unsigned i = 0; i != NumOps; ++i) {
1383 OperandList[i].setUser(this);
1384 Ops[i].getVal()->addUse(OperandList[i]);
1388 /// DropOperands - Release the operands and set this node to have
1390 void DropOperands();
1392 void addUser(unsigned i, SDNode *User) {
1393 assert(User->OperandList[i].getUser() && "Node without parent");
1394 addUse(User->OperandList[i]);
1397 void removeUser(unsigned i, SDNode *User) {
1398 assert(User->OperandList[i].getUser() && "Node without parent");
1399 SDUse &Op = User->OperandList[i];
1400 Op.removeFromList();
1405 // Define inline functions from the SDValue class.
1407 inline unsigned SDValue::getOpcode() const {
1408 return Node->getOpcode();
1410 inline MVT SDValue::getValueType() const {
1411 return Node->getValueType(ResNo);
1413 inline unsigned SDValue::getNumOperands() const {
1414 return Node->getNumOperands();
1416 inline const SDValue &SDValue::getOperand(unsigned i) const {
1417 return Node->getOperand(i);
1419 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1420 return Node->getConstantOperandVal(i);
1422 inline bool SDValue::isTargetOpcode() const {
1423 return Node->isTargetOpcode();
1425 inline bool SDValue::isMachineOpcode() const {
1426 return Node->isMachineOpcode();
1428 inline unsigned SDValue::getMachineOpcode() const {
1429 return Node->getMachineOpcode();
1431 inline bool SDValue::use_empty() const {
1432 return !Node->hasAnyUseOfValue(ResNo);
1434 inline bool SDValue::hasOneUse() const {
1435 return Node->hasNUsesOfValue(1, ResNo);
1438 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1439 /// to allow co-allocation of node operands with the node itself.
1440 class UnarySDNode : public SDNode {
1441 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1444 UnarySDNode(unsigned Opc, SDVTList VTs, SDValue X)
1445 : SDNode(Opc, VTs) {
1447 InitOperands(&Op, 1);
1451 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1452 /// to allow co-allocation of node operands with the node itself.
1453 class BinarySDNode : public SDNode {
1454 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1457 BinarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y)
1458 : SDNode(Opc, VTs) {
1461 InitOperands(Ops, 2);
1465 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1466 /// to allow co-allocation of node operands with the node itself.
1467 class TernarySDNode : public SDNode {
1468 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1471 TernarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y,
1473 : SDNode(Opc, VTs) {
1477 InitOperands(Ops, 3);
1482 /// HandleSDNode - This class is used to form a handle around another node that
1483 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1484 /// operand. This node should be directly created by end-users and not added to
1485 /// the AllNodes list.
1486 class HandleSDNode : public SDNode {
1487 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1490 // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1493 explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
1495 explicit HandleSDNode(SDValue X)
1497 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
1499 InitOperands(&Op, 1);
1502 const SDValue &getValue() const { return Op.getSDValue(); }
1505 /// Abstact virtual class for operations for memory operations
1506 class MemSDNode : public SDNode {
1507 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1510 // MemoryVT - VT of in-memory value.
1513 //! SrcValue - Memory location for alias analysis.
1514 const Value *SrcValue;
1516 //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
1519 /// Flags - the low bit indicates whether this is a volatile reference;
1520 /// the remainder is a log2 encoding of the alignment in bytes.
1524 MemSDNode(unsigned Opc, SDVTList VTs, MVT MemoryVT,
1525 const Value *srcValue, int SVOff,
1526 unsigned alignment, bool isvolatile);
1528 /// Returns alignment and volatility of the memory access
1529 unsigned getAlignment() const { return (1u << (Flags >> 1)) >> 1; }
1530 bool isVolatile() const { return Flags & 1; }
1532 /// Returns the SrcValue and offset that describes the location of the access
1533 const Value *getSrcValue() const { return SrcValue; }
1534 int getSrcValueOffset() const { return SVOffset; }
1536 /// getMemoryVT - Return the type of the in-memory value.
1537 MVT getMemoryVT() const { return MemoryVT; }
1539 /// getMemOperand - Return a MachineMemOperand object describing the memory
1540 /// reference performed by operation.
1541 MachineMemOperand getMemOperand() const;
1543 const SDValue &getChain() const { return getOperand(0); }
1544 const SDValue &getBasePtr() const {
1545 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1548 /// getRawFlags - Represent the flags as a bunch of bits.
1550 unsigned getRawFlags() const { return Flags; }
1552 // Methods to support isa and dyn_cast
1553 static bool classof(const MemSDNode *) { return true; }
1554 static bool classof(const SDNode *N) {
1555 return N->getOpcode() == ISD::LOAD ||
1556 N->getOpcode() == ISD::STORE ||
1557 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_8 ||
1558 N->getOpcode() == ISD::ATOMIC_SWAP_8 ||
1559 N->getOpcode() == ISD::ATOMIC_LOAD_ADD_8 ||
1560 N->getOpcode() == ISD::ATOMIC_LOAD_SUB_8 ||
1561 N->getOpcode() == ISD::ATOMIC_LOAD_AND_8 ||
1562 N->getOpcode() == ISD::ATOMIC_LOAD_OR_8 ||
1563 N->getOpcode() == ISD::ATOMIC_LOAD_XOR_8 ||
1564 N->getOpcode() == ISD::ATOMIC_LOAD_NAND_8 ||
1565 N->getOpcode() == ISD::ATOMIC_LOAD_MIN_8 ||
1566 N->getOpcode() == ISD::ATOMIC_LOAD_MAX_8 ||
1567 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_8 ||
1568 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_8 ||
1570 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_16 ||
1571 N->getOpcode() == ISD::ATOMIC_SWAP_16 ||
1572 N->getOpcode() == ISD::ATOMIC_LOAD_ADD_16 ||
1573 N->getOpcode() == ISD::ATOMIC_LOAD_SUB_16 ||
1574 N->getOpcode() == ISD::ATOMIC_LOAD_AND_16 ||
1575 N->getOpcode() == ISD::ATOMIC_LOAD_OR_16 ||
1576 N->getOpcode() == ISD::ATOMIC_LOAD_XOR_16 ||
1577 N->getOpcode() == ISD::ATOMIC_LOAD_NAND_16 ||
1578 N->getOpcode() == ISD::ATOMIC_LOAD_MIN_16 ||
1579 N->getOpcode() == ISD::ATOMIC_LOAD_MAX_16 ||
1580 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_16 ||
1581 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_16 ||
1583 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_32 ||
1584 N->getOpcode() == ISD::ATOMIC_SWAP_32 ||
1585 N->getOpcode() == ISD::ATOMIC_LOAD_ADD_32 ||
1586 N->getOpcode() == ISD::ATOMIC_LOAD_SUB_32 ||
1587 N->getOpcode() == ISD::ATOMIC_LOAD_AND_32 ||
1588 N->getOpcode() == ISD::ATOMIC_LOAD_OR_32 ||
1589 N->getOpcode() == ISD::ATOMIC_LOAD_XOR_32 ||
1590 N->getOpcode() == ISD::ATOMIC_LOAD_NAND_32 ||
1591 N->getOpcode() == ISD::ATOMIC_LOAD_MIN_32 ||
1592 N->getOpcode() == ISD::ATOMIC_LOAD_MAX_32 ||
1593 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_32 ||
1594 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_32 ||
1596 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_64 ||
1597 N->getOpcode() == ISD::ATOMIC_SWAP_64 ||
1598 N->getOpcode() == ISD::ATOMIC_LOAD_ADD_64 ||
1599 N->getOpcode() == ISD::ATOMIC_LOAD_SUB_64 ||
1600 N->getOpcode() == ISD::ATOMIC_LOAD_AND_64 ||
1601 N->getOpcode() == ISD::ATOMIC_LOAD_OR_64 ||
1602 N->getOpcode() == ISD::ATOMIC_LOAD_XOR_64 ||
1603 N->getOpcode() == ISD::ATOMIC_LOAD_NAND_64 ||
1604 N->getOpcode() == ISD::ATOMIC_LOAD_MIN_64 ||
1605 N->getOpcode() == ISD::ATOMIC_LOAD_MAX_64 ||
1606 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_64 ||
1607 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_64;
1611 /// Atomic operations node
1612 class AtomicSDNode : public MemSDNode {
1613 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1617 // Opc: opcode for atomic
1618 // VTL: value type list
1619 // Chain: memory chain for operaand
1620 // Ptr: address to update as a SDValue
1621 // Cmp: compare value
1623 // SrcVal: address to update as a Value (used for MemOperand)
1624 // Align: alignment of memory
1625 AtomicSDNode(unsigned Opc, SDVTList VTL, SDValue Chain, SDValue Ptr,
1626 SDValue Cmp, SDValue Swp, const Value* SrcVal,
1628 : MemSDNode(Opc, VTL, Cmp.getValueType(), SrcVal, /*SVOffset=*/0,
1629 Align, /*isVolatile=*/true) {
1634 InitOperands(Ops, 4);
1636 AtomicSDNode(unsigned Opc, SDVTList VTL, SDValue Chain, SDValue Ptr,
1637 SDValue Val, const Value* SrcVal, unsigned Align=0)
1638 : MemSDNode(Opc, VTL, Val.getValueType(), SrcVal, /*SVOffset=*/0,
1639 Align, /*isVolatile=*/true) {
1643 InitOperands(Ops, 3);
1646 const SDValue &getBasePtr() const { return getOperand(1); }
1647 const SDValue &getVal() const { return getOperand(2); }
1649 bool isCompareAndSwap() const {
1650 unsigned Op = getOpcode();
1651 return Op == ISD::ATOMIC_CMP_SWAP_8 ||
1652 Op == ISD::ATOMIC_CMP_SWAP_16 ||
1653 Op == ISD::ATOMIC_CMP_SWAP_32 ||
1654 Op == ISD::ATOMIC_CMP_SWAP_64;
1657 // Methods to support isa and dyn_cast
1658 static bool classof(const AtomicSDNode *) { return true; }
1659 static bool classof(const SDNode *N) {
1660 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP_8 ||
1661 N->getOpcode() == ISD::ATOMIC_SWAP_8 ||
1662 N->getOpcode() == ISD::ATOMIC_LOAD_ADD_8 ||
1663 N->getOpcode() == ISD::ATOMIC_LOAD_SUB_8 ||
1664 N->getOpcode() == ISD::ATOMIC_LOAD_AND_8 ||
1665 N->getOpcode() == ISD::ATOMIC_LOAD_OR_8 ||
1666 N->getOpcode() == ISD::ATOMIC_LOAD_XOR_8 ||
1667 N->getOpcode() == ISD::ATOMIC_LOAD_NAND_8 ||
1668 N->getOpcode() == ISD::ATOMIC_LOAD_MIN_8 ||
1669 N->getOpcode() == ISD::ATOMIC_LOAD_MAX_8 ||
1670 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_8 ||
1671 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_8 ||
1672 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_16 ||
1673 N->getOpcode() == ISD::ATOMIC_SWAP_16 ||
1674 N->getOpcode() == ISD::ATOMIC_LOAD_ADD_16 ||
1675 N->getOpcode() == ISD::ATOMIC_LOAD_SUB_16 ||
1676 N->getOpcode() == ISD::ATOMIC_LOAD_AND_16 ||
1677 N->getOpcode() == ISD::ATOMIC_LOAD_OR_16 ||
1678 N->getOpcode() == ISD::ATOMIC_LOAD_XOR_16 ||
1679 N->getOpcode() == ISD::ATOMIC_LOAD_NAND_16 ||
1680 N->getOpcode() == ISD::ATOMIC_LOAD_MIN_16 ||
1681 N->getOpcode() == ISD::ATOMIC_LOAD_MAX_16 ||
1682 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_16 ||
1683 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_16 ||
1684 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_32 ||
1685 N->getOpcode() == ISD::ATOMIC_SWAP_32 ||
1686 N->getOpcode() == ISD::ATOMIC_LOAD_ADD_32 ||
1687 N->getOpcode() == ISD::ATOMIC_LOAD_SUB_32 ||
1688 N->getOpcode() == ISD::ATOMIC_LOAD_AND_32 ||
1689 N->getOpcode() == ISD::ATOMIC_LOAD_OR_32 ||
1690 N->getOpcode() == ISD::ATOMIC_LOAD_XOR_32 ||
1691 N->getOpcode() == ISD::ATOMIC_LOAD_NAND_32 ||
1692 N->getOpcode() == ISD::ATOMIC_LOAD_MIN_32 ||
1693 N->getOpcode() == ISD::ATOMIC_LOAD_MAX_32 ||
1694 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_32 ||
1695 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_32 ||
1696 N->getOpcode() == ISD::ATOMIC_CMP_SWAP_64 ||
1697 N->getOpcode() == ISD::ATOMIC_SWAP_64 ||
1698 N->getOpcode() == ISD::ATOMIC_LOAD_ADD_64 ||
1699 N->getOpcode() == ISD::ATOMIC_LOAD_SUB_64 ||
1700 N->getOpcode() == ISD::ATOMIC_LOAD_AND_64 ||
1701 N->getOpcode() == ISD::ATOMIC_LOAD_OR_64 ||
1702 N->getOpcode() == ISD::ATOMIC_LOAD_XOR_64 ||
1703 N->getOpcode() == ISD::ATOMIC_LOAD_NAND_64 ||
1704 N->getOpcode() == ISD::ATOMIC_LOAD_MIN_64 ||
1705 N->getOpcode() == ISD::ATOMIC_LOAD_MAX_64 ||
1706 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_64 ||
1707 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_64;
1711 class ConstantSDNode : public SDNode {
1712 const ConstantInt *Value;
1713 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1715 friend class SelectionDAG;
1716 ConstantSDNode(bool isTarget, const ConstantInt *val, MVT VT)
1717 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1722 const ConstantInt *getConstantIntValue() const { return Value; }
1723 const APInt &getAPIntValue() const { return Value->getValue(); }
1724 uint64_t getZExtValue() const { return Value->getZExtValue(); }
1726 int64_t getSignExtended() const {
1727 unsigned Bits = getValueType(0).getSizeInBits();
1728 return ((int64_t)getZExtValue() << (64-Bits)) >> (64-Bits);
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 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1745 friend class SelectionDAG;
1746 ConstantFPSDNode(bool isTarget, const ConstantFP *val, MVT VT)
1747 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1748 getSDVTList(VT)), Value(val) {
1752 const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1753 const ConstantFP *getConstantFPValue() const { return Value; }
1755 /// isExactlyValue - We don't rely on operator== working on double values, as
1756 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1757 /// As such, this method can be used to do an exact bit-for-bit comparison of
1758 /// two floating point values.
1760 /// We leave the version with the double argument here because it's just so
1761 /// convenient to write "2.0" and the like. Without this function we'd
1762 /// have to duplicate its logic everywhere it's called.
1763 bool isExactlyValue(double V) const {
1764 // convert is not supported on this type
1765 if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
1768 Tmp.convert(Value->getValueAPF().getSemantics(),
1769 APFloat::rmNearestTiesToEven);
1770 return isExactlyValue(Tmp);
1772 bool isExactlyValue(const APFloat& V) const;
1774 bool isValueValidForType(MVT VT, const APFloat& Val);
1776 static bool classof(const ConstantFPSDNode *) { return true; }
1777 static bool classof(const SDNode *N) {
1778 return N->getOpcode() == ISD::ConstantFP ||
1779 N->getOpcode() == ISD::TargetConstantFP;
1783 class GlobalAddressSDNode : public SDNode {
1784 GlobalValue *TheGlobal;
1786 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1788 friend class SelectionDAG;
1789 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT, int o = 0);
1792 GlobalValue *getGlobal() const { return TheGlobal; }
1793 int getOffset() const { return Offset; }
1795 static bool classof(const GlobalAddressSDNode *) { return true; }
1796 static bool classof(const SDNode *N) {
1797 return N->getOpcode() == ISD::GlobalAddress ||
1798 N->getOpcode() == ISD::TargetGlobalAddress ||
1799 N->getOpcode() == ISD::GlobalTLSAddress ||
1800 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1804 class FrameIndexSDNode : public SDNode {
1806 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1808 friend class SelectionDAG;
1809 FrameIndexSDNode(int fi, MVT VT, bool isTarg)
1810 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
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 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1828 friend class SelectionDAG;
1829 JumpTableSDNode(int jti, MVT VT, bool isTarg)
1830 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1835 int getIndex() const { return JTI; }
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.
1851 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1853 friend class SelectionDAG;
1854 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0)
1855 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1856 getSDVTList(VT)), Offset(o), Alignment(0) {
1857 assert((int)Offset >= 0 && "Offset is too large");
1860 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o, unsigned Align)
1861 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1862 getSDVTList(VT)), Offset(o), Alignment(Align) {
1863 assert((int)Offset >= 0 && "Offset is too large");
1866 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1868 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1869 getSDVTList(VT)), Offset(o), Alignment(0) {
1870 assert((int)Offset >= 0 && "Offset is too large");
1871 Val.MachineCPVal = v;
1872 Offset |= 1 << (sizeof(unsigned)*8-1);
1874 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1875 MVT VT, int o, unsigned Align)
1876 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1877 getSDVTList(VT)), Offset(o), Alignment(Align) {
1878 assert((int)Offset >= 0 && "Offset is too large");
1879 Val.MachineCPVal = v;
1880 Offset |= 1 << (sizeof(unsigned)*8-1);
1884 bool isMachineConstantPoolEntry() const {
1885 return (int)Offset < 0;
1888 Constant *getConstVal() const {
1889 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1890 return Val.ConstVal;
1893 MachineConstantPoolValue *getMachineCPVal() const {
1894 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1895 return Val.MachineCPVal;
1898 int getOffset() const {
1899 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1902 // Return the alignment of this constant pool object, which is either 0 (for
1903 // default alignment) or log2 of the desired value.
1904 unsigned getAlignment() const { return Alignment; }
1906 const Type *getType() const;
1908 static bool classof(const ConstantPoolSDNode *) { return true; }
1909 static bool classof(const SDNode *N) {
1910 return N->getOpcode() == ISD::ConstantPool ||
1911 N->getOpcode() == ISD::TargetConstantPool;
1915 class BasicBlockSDNode : public SDNode {
1916 MachineBasicBlock *MBB;
1917 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1919 friend class SelectionDAG;
1920 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1921 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1925 MachineBasicBlock *getBasicBlock() const { return MBB; }
1927 static bool classof(const BasicBlockSDNode *) { return true; }
1928 static bool classof(const SDNode *N) {
1929 return N->getOpcode() == ISD::BasicBlock;
1933 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1934 /// used when the SelectionDAG needs to make a simple reference to something
1935 /// in the LLVM IR representation.
1937 /// Note that this is not used for carrying alias information; that is done
1938 /// with MemOperandSDNode, which includes a Value which is required to be a
1939 /// pointer, and several other fields specific to memory references.
1941 class SrcValueSDNode : public SDNode {
1943 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1945 friend class SelectionDAG;
1946 /// Create a SrcValue for a general value.
1947 explicit SrcValueSDNode(const Value *v)
1948 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1951 /// getValue - return the contained Value.
1952 const Value *getValue() const { return V; }
1954 static bool classof(const SrcValueSDNode *) { return true; }
1955 static bool classof(const SDNode *N) {
1956 return N->getOpcode() == ISD::SRCVALUE;
1961 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
1962 /// used to represent a reference to memory after ISD::LOAD
1963 /// and ISD::STORE have been lowered.
1965 class MemOperandSDNode : public SDNode {
1966 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1968 friend class SelectionDAG;
1969 /// Create a MachineMemOperand node
1970 explicit MemOperandSDNode(const MachineMemOperand &mo)
1971 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1974 /// MO - The contained MachineMemOperand.
1975 const MachineMemOperand MO;
1977 static bool classof(const MemOperandSDNode *) { return true; }
1978 static bool classof(const SDNode *N) {
1979 return N->getOpcode() == ISD::MEMOPERAND;
1984 class RegisterSDNode : public SDNode {
1986 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1988 friend class SelectionDAG;
1989 RegisterSDNode(unsigned reg, MVT VT)
1990 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1994 unsigned getReg() const { return Reg; }
1996 static bool classof(const RegisterSDNode *) { return true; }
1997 static bool classof(const SDNode *N) {
1998 return N->getOpcode() == ISD::Register;
2002 class DbgStopPointSDNode : public SDNode {
2006 const CompileUnitDesc *CU;
2007 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2009 friend class SelectionDAG;
2010 DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
2011 const CompileUnitDesc *cu)
2012 : SDNode(ISD::DBG_STOPPOINT, getSDVTList(MVT::Other)),
2013 Line(l), Column(c), CU(cu) {
2015 InitOperands(&Chain, 1);
2018 unsigned getLine() const { return Line; }
2019 unsigned getColumn() const { return Column; }
2020 const CompileUnitDesc *getCompileUnit() const { return CU; }
2022 static bool classof(const DbgStopPointSDNode *) { return true; }
2023 static bool classof(const SDNode *N) {
2024 return N->getOpcode() == ISD::DBG_STOPPOINT;
2028 class LabelSDNode : public SDNode {
2031 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2033 friend class SelectionDAG;
2034 LabelSDNode(unsigned NodeTy, SDValue ch, unsigned id)
2035 : SDNode(NodeTy, getSDVTList(MVT::Other)), LabelID(id) {
2037 InitOperands(&Chain, 1);
2040 unsigned getLabelID() const { return LabelID; }
2042 static bool classof(const LabelSDNode *) { return true; }
2043 static bool classof(const SDNode *N) {
2044 return N->getOpcode() == ISD::DBG_LABEL ||
2045 N->getOpcode() == ISD::EH_LABEL;
2049 class SymbolSDNode : public SDNode {
2051 GlobalValue::LinkageTypes Linkage;
2052 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2054 friend class SelectionDAG;
2055 SymbolSDNode(bool isTarget, const char *Sym, MVT VT,
2056 GlobalValue::LinkageTypes L)
2057 : SDNode(isTarget ? ISD::TargetSymbol : ISD::Symbol,
2058 getSDVTList(VT)), Symbol(Sym), Linkage(L) {}
2060 const char *getSymbol() const { return Symbol; }
2061 GlobalValue::LinkageTypes getLinkage() const { return Linkage; }
2063 static bool classof(const SymbolSDNode *) { return true; }
2064 static bool classof(const SDNode *N) {
2065 return N->getOpcode() == ISD::Symbol ||
2066 N->getOpcode() == ISD::TargetSymbol;
2070 class CondCodeSDNode : public SDNode {
2071 ISD::CondCode Condition;
2072 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2074 friend class SelectionDAG;
2075 explicit CondCodeSDNode(ISD::CondCode Cond)
2076 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
2080 ISD::CondCode get() const { return Condition; }
2082 static bool classof(const CondCodeSDNode *) { return true; }
2083 static bool classof(const SDNode *N) {
2084 return N->getOpcode() == ISD::CONDCODE;
2091 static const uint64_t NoFlagSet = 0ULL;
2092 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
2093 static const uint64_t ZExtOffs = 0;
2094 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
2095 static const uint64_t SExtOffs = 1;
2096 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
2097 static const uint64_t InRegOffs = 2;
2098 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
2099 static const uint64_t SRetOffs = 3;
2100 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
2101 static const uint64_t ByValOffs = 4;
2102 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
2103 static const uint64_t NestOffs = 5;
2104 static const uint64_t ByValAlign = 0xFULL << 6; //< Struct alignment
2105 static const uint64_t ByValAlignOffs = 6;
2106 static const uint64_t Split = 1ULL << 10;
2107 static const uint64_t SplitOffs = 10;
2108 static const uint64_t OrigAlign = 0x1FULL<<27;
2109 static const uint64_t OrigAlignOffs = 27;
2110 static const uint64_t ByValSize = 0xffffffffULL << 32; //< Struct size
2111 static const uint64_t ByValSizeOffs = 32;
2113 static const uint64_t One = 1ULL; //< 1 of this type, for shifts
2117 ArgFlagsTy() : Flags(0) { }
2119 bool isZExt() const { return Flags & ZExt; }
2120 void setZExt() { Flags |= One << ZExtOffs; }
2122 bool isSExt() const { return Flags & SExt; }
2123 void setSExt() { Flags |= One << SExtOffs; }
2125 bool isInReg() const { return Flags & InReg; }
2126 void setInReg() { Flags |= One << InRegOffs; }
2128 bool isSRet() const { return Flags & SRet; }
2129 void setSRet() { Flags |= One << SRetOffs; }
2131 bool isByVal() const { return Flags & ByVal; }
2132 void setByVal() { Flags |= One << ByValOffs; }
2134 bool isNest() const { return Flags & Nest; }
2135 void setNest() { Flags |= One << NestOffs; }
2137 unsigned getByValAlign() const {
2139 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
2141 void setByValAlign(unsigned A) {
2142 Flags = (Flags & ~ByValAlign) |
2143 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
2146 bool isSplit() const { return Flags & Split; }
2147 void setSplit() { Flags |= One << SplitOffs; }
2149 unsigned getOrigAlign() const {
2151 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
2153 void setOrigAlign(unsigned A) {
2154 Flags = (Flags & ~OrigAlign) |
2155 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
2158 unsigned getByValSize() const {
2159 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
2161 void setByValSize(unsigned S) {
2162 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
2165 /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
2166 std::string getArgFlagsString();
2168 /// getRawBits - Represent the flags as a bunch of bits.
2169 uint64_t getRawBits() const { return Flags; }
2173 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
2174 class ARG_FLAGSSDNode : public SDNode {
2175 ISD::ArgFlagsTy TheFlags;
2176 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2178 friend class SelectionDAG;
2179 explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
2180 : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
2183 ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
2185 static bool classof(const ARG_FLAGSSDNode *) { return true; }
2186 static bool classof(const SDNode *N) {
2187 return N->getOpcode() == ISD::ARG_FLAGS;
2191 /// CallSDNode - Node for calls -- ISD::CALL.
2192 class CallSDNode : public SDNode {
2193 unsigned CallingConv;
2196 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2198 friend class SelectionDAG;
2199 CallSDNode(unsigned cc, bool isvararg, bool istailcall,
2200 SDVTList VTs, const SDValue *Operands, unsigned numOperands)
2201 : SDNode(ISD::CALL, VTs, Operands, numOperands),
2202 CallingConv(cc), IsVarArg(isvararg), IsTailCall(istailcall) {}
2204 unsigned getCallingConv() const { return CallingConv; }
2205 unsigned isVarArg() const { return IsVarArg; }
2206 unsigned isTailCall() const { return IsTailCall; }
2208 /// Set this call to not be marked as a tail call. Normally setter
2209 /// methods in SDNodes are unsafe because it breaks the CSE map,
2210 /// but we don't include the tail call flag for calls so it's ok
2212 void setNotTailCall() { IsTailCall = false; }
2214 SDValue getChain() const { return getOperand(0); }
2215 SDValue getCallee() const { return getOperand(1); }
2217 unsigned getNumArgs() const { return (getNumOperands() - 2) / 2; }
2218 SDValue getArg(unsigned i) const { return getOperand(2+2*i); }
2219 SDValue getArgFlagsVal(unsigned i) const {
2220 return getOperand(3+2*i);
2222 ISD::ArgFlagsTy getArgFlags(unsigned i) const {
2223 return cast<ARG_FLAGSSDNode>(getArgFlagsVal(i).getNode())->getArgFlags();
2226 unsigned getNumRetVals() const { return getNumValues() - 1; }
2227 MVT getRetValType(unsigned i) const { return getValueType(i); }
2229 static bool classof(const CallSDNode *) { return true; }
2230 static bool classof(const SDNode *N) {
2231 return N->getOpcode() == ISD::CALL;
2235 /// VTSDNode - This class is used to represent MVT's, which are used
2236 /// to parameterize some operations.
2237 class VTSDNode : public SDNode {
2239 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2241 friend class SelectionDAG;
2242 explicit VTSDNode(MVT VT)
2243 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
2247 MVT getVT() const { return ValueType; }
2249 static bool classof(const VTSDNode *) { return true; }
2250 static bool classof(const SDNode *N) {
2251 return N->getOpcode() == ISD::VALUETYPE;
2255 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
2257 class LSBaseSDNode : public MemSDNode {
2259 //! Operand array for load and store
2261 \note Moving this array to the base class captures more
2262 common functionality shared between LoadSDNode and
2267 LSBaseSDNode(ISD::NodeType NodeTy, SDValue *Operands, unsigned numOperands,
2268 SDVTList VTs, ISD::MemIndexedMode AM, MVT VT,
2269 const Value *SV, int SVO, unsigned Align, bool Vol)
2270 : MemSDNode(NodeTy, VTs, VT, SV, SVO, Align, Vol) {
2272 for (unsigned i = 0; i != numOperands; ++i)
2273 Ops[i] = Operands[i];
2274 InitOperands(Ops, numOperands);
2275 assert(Align != 0 && "Loads and stores should have non-zero aligment");
2276 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
2277 "Only indexed loads and stores have a non-undef offset operand");
2280 const SDValue &getOffset() const {
2281 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2284 /// getAddressingMode - Return the addressing mode for this load or store:
2285 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2286 ISD::MemIndexedMode getAddressingMode() const {
2287 return ISD::MemIndexedMode(SubclassData & 7);
2290 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
2291 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2293 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
2294 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2296 static bool classof(const LSBaseSDNode *) { return true; }
2297 static bool classof(const SDNode *N) {
2298 return N->getOpcode() == ISD::LOAD ||
2299 N->getOpcode() == ISD::STORE;
2303 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2305 class LoadSDNode : public LSBaseSDNode {
2306 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2308 friend class SelectionDAG;
2309 LoadSDNode(SDValue *ChainPtrOff, SDVTList VTs,
2310 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT,
2311 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2312 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
2313 VTs, AM, LVT, SV, O, Align, Vol) {
2314 SubclassData |= (unsigned short)ETy << 3;
2318 /// getExtensionType - Return whether this is a plain node,
2319 /// or one of the varieties of value-extending loads.
2320 ISD::LoadExtType getExtensionType() const {
2321 return ISD::LoadExtType((SubclassData >> 3) & 3);
2324 const SDValue &getBasePtr() const { return getOperand(1); }
2325 const SDValue &getOffset() const { return getOperand(2); }
2327 static bool classof(const LoadSDNode *) { return true; }
2328 static bool classof(const SDNode *N) {
2329 return N->getOpcode() == ISD::LOAD;
2333 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2335 class StoreSDNode : public LSBaseSDNode {
2336 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2338 friend class SelectionDAG;
2339 StoreSDNode(SDValue *ChainValuePtrOff, SDVTList VTs,
2340 ISD::MemIndexedMode AM, bool isTrunc, MVT SVT,
2341 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2342 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
2343 VTs, AM, SVT, SV, O, Align, Vol) {
2344 SubclassData |= (unsigned short)isTrunc << 3;
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 >> 3) & 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 forward_iterator<SDNode, ptrdiff_t> {
2368 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2370 bool operator==(const SDNodeIterator& x) const {
2371 return Operand == x.Operand;
2373 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2375 const SDNodeIterator &operator=(const SDNodeIterator &I) {
2376 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2377 Operand = I.Operand;
2381 pointer operator*() const {
2382 return Node->getOperand(Operand).getNode();
2384 pointer operator->() const { return operator*(); }
2386 SDNodeIterator& operator++() { // Preincrement
2390 SDNodeIterator operator++(int) { // Postincrement
2391 SDNodeIterator tmp = *this; ++*this; return tmp;
2394 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2395 static SDNodeIterator end (SDNode *N) {
2396 return SDNodeIterator(N, N->getNumOperands());
2399 unsigned getOperand() const { return Operand; }
2400 const SDNode *getNode() const { return Node; }
2403 template <> struct GraphTraits<SDNode*> {
2404 typedef SDNode NodeType;
2405 typedef SDNodeIterator ChildIteratorType;
2406 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2407 static inline ChildIteratorType child_begin(NodeType *N) {
2408 return SDNodeIterator::begin(N);
2410 static inline ChildIteratorType child_end(NodeType *N) {
2411 return SDNodeIterator::end(N);
2415 /// LargestSDNode - The largest SDNode class.
2417 typedef LoadSDNode LargestSDNode;
2419 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2422 typedef ConstantSDNode MostAlignedSDNode;
2425 /// isNormalLoad - Returns true if the specified node is a non-extending
2426 /// and unindexed load.
2427 inline bool isNormalLoad(const SDNode *N) {
2428 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2429 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2430 Ld->getAddressingMode() == ISD::UNINDEXED;
2433 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2435 inline bool isNON_EXTLoad(const SDNode *N) {
2436 return isa<LoadSDNode>(N) &&
2437 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2440 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2442 inline bool isEXTLoad(const SDNode *N) {
2443 return isa<LoadSDNode>(N) &&
2444 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2447 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2449 inline bool isSEXTLoad(const SDNode *N) {
2450 return isa<LoadSDNode>(N) &&
2451 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2454 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2456 inline bool isZEXTLoad(const SDNode *N) {
2457 return isa<LoadSDNode>(N) &&
2458 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2461 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2463 inline bool isUNINDEXEDLoad(const SDNode *N) {
2464 return isa<LoadSDNode>(N) &&
2465 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2468 /// isNormalStore - Returns true if the specified node is a non-truncating
2469 /// and unindexed store.
2470 inline bool isNormalStore(const SDNode *N) {
2471 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2472 return St && !St->isTruncatingStore() &&
2473 St->getAddressingMode() == ISD::UNINDEXED;
2476 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2478 inline bool isNON_TRUNCStore(const SDNode *N) {
2479 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2482 /// isTRUNCStore - Returns true if the specified node is a truncating
2484 inline bool isTRUNCStore(const SDNode *N) {
2485 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2488 /// isUNINDEXEDStore - Returns true if the specified node is an
2489 /// unindexed store.
2490 inline bool isUNINDEXEDStore(const SDNode *N) {
2491 return isa<StoreSDNode>(N) &&
2492 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2497 } // end llvm namespace