1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG. These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
22 #include "llvm/Value.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator"
26 #include "llvm/ADT/APFloat.h"
27 #include "llvm/CodeGen/ValueTypes.h"
28 #include "llvm/Support/DataTypes.h"
35 class MachineBasicBlock;
36 class MachineConstantPoolValue;
38 template <typename T> struct DenseMapInfo;
39 template <typename T> struct simplify_type;
40 template <typename T> struct ilist_traits;
41 template<typename NodeTy, typename Traits> class iplist;
42 template<typename NodeTy> class ilist_iterator;
44 /// SDVTList - This represents a list of ValueType's that has been intern'd by
45 /// a SelectionDAG. Instances of this simple value class are returned by
46 /// SelectionDAG::getVTList(...).
49 const MVT::ValueType *VTs;
50 unsigned short NumVTs;
53 /// ISD namespace - This namespace contains an enum which represents all of the
54 /// SelectionDAG node types and value types.
57 namespace ParamFlags {
60 ZExt = 1<<0, ///< Parameter should be zero extended
62 SExt = 1<<1, ///< Parameter should be sign extended
64 InReg = 1<<2, ///< Parameter should be passed in register
66 StructReturn = 1<<3, ///< Hidden struct-return pointer
68 ByVal = 1<<4, ///< Struct passed by value
70 Nest = 1<<5, ///< Parameter is nested function static chain
72 ByValAlign = 0xF << 6, //< The alignment of the struct
74 ByValSize = 0x1ffff << 10, //< The size of the struct
76 OrigAlignment = 0x1F<<27,
77 OrigAlignmentOffs = 27
81 //===--------------------------------------------------------------------===//
82 /// ISD::NodeType enum - This enum defines all of the operators valid in a
86 // DELETED_NODE - This is an illegal flag value that is used to catch
87 // errors. This opcode is not a legal opcode for any node.
90 // EntryToken - This is the marker used to indicate the start of the region.
93 // Token factor - This node takes multiple tokens as input and produces a
94 // single token result. This is used to represent the fact that the operand
95 // operators are independent of each other.
98 // AssertSext, AssertZext - These nodes record if a register contains a
99 // value that has already been zero or sign extended from a narrower type.
100 // These nodes take two operands. The first is the node that has already
101 // been extended, and the second is a value type node indicating the width
103 AssertSext, AssertZext,
105 // Various leaf nodes.
106 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
107 Constant, ConstantFP,
108 GlobalAddress, GlobalTLSAddress, FrameIndex,
109 JumpTable, ConstantPool, ExternalSymbol,
111 // The address of the GOT
114 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
115 // llvm.returnaddress on the DAG. These nodes take one operand, the index
116 // of the frame or return address to return. An index of zero corresponds
117 // to the current function's frame or return address, an index of one to the
118 // parent's frame or return address, and so on.
119 FRAMEADDR, RETURNADDR,
121 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
122 // first (possible) on-stack argument. This is needed for correct stack
123 // adjustment during unwind.
124 FRAME_TO_ARGS_OFFSET,
126 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
127 // address of the exception block on entry to an landing pad block.
130 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
131 // the selection index of the exception thrown.
134 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
135 // 'eh_return' gcc dwarf builtin, which is used to return from
136 // exception. The general meaning is: adjust stack by OFFSET and pass
137 // execution to HANDLER. Many platform-related details also :)
140 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
141 // simplification of the constant.
145 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
146 // anything else with this node, and this is valid in the target-specific
147 // dag, turning into a GlobalAddress operand.
149 TargetGlobalTLSAddress,
153 TargetExternalSymbol,
155 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
156 /// This node represents a target intrinsic function with no side effects.
157 /// The first operand is the ID number of the intrinsic from the
158 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
159 /// node has returns the result of the intrinsic.
162 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
163 /// This node represents a target intrinsic function with side effects that
164 /// returns a result. The first operand is a chain pointer. The second is
165 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
166 /// operands to the intrinsic follow. The node has two results, the result
167 /// of the intrinsic and an output chain.
170 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
171 /// This node represents a target intrinsic function with side effects that
172 /// does not return a result. The first operand is a chain pointer. The
173 /// second is the ID number of the intrinsic from the llvm::Intrinsic
174 /// namespace. The operands to the intrinsic follow.
177 // CopyToReg - This node has three operands: a chain, a register number to
178 // set to this value, and a value.
181 // CopyFromReg - This node indicates that the input value is a virtual or
182 // physical register that is defined outside of the scope of this
183 // SelectionDAG. The register is available from the RegisterSDNode object.
186 // UNDEF - An undefined node
189 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
190 /// represents the formal arguments for a function. CC# is a Constant value
191 /// indicating the calling convention of the function, and ISVARARG is a
192 /// flag that indicates whether the function is varargs or not. This node
193 /// has one result value for each incoming argument, plus one for the output
194 /// chain. It must be custom legalized. See description of CALL node for
195 /// FLAG argument contents explanation.
199 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
200 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
201 /// This node represents a fully general function call, before the legalizer
202 /// runs. This has one result value for each argument / flag pair, plus
203 /// a chain result. It must be custom legalized. Flag argument indicates
204 /// misc. argument attributes. Currently:
206 /// Bit 1 - 'inreg' attribute
207 /// Bit 2 - 'sret' attribute
208 /// Bit 4 - 'byval' attribute
209 /// Bit 5 - 'nest' attribute
210 /// Bit 6-9 - alignment of byval structures
211 /// Bit 10-26 - size of byval structures
212 /// Bits 31:27 - argument ABI alignment in the first argument piece and
213 /// alignment '1' in other argument pieces.
216 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
217 // a Constant, which is required to be operand #1), element of the aggregate
218 // value specified as operand #0. This is only for use before legalization,
219 // for values that will be broken into multiple registers.
222 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
223 // two values of the same integer value type, this produces a value twice as
224 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
227 // MERGE_VALUES - This node takes multiple discrete operands and returns
228 // them all as its individual results. This nodes has exactly the same
229 // number of inputs and outputs, and is only valid before legalization.
230 // This node is useful for some pieces of the code generator that want to
231 // think about a single node with multiple results, not multiple nodes.
234 // Simple integer binary arithmetic operators.
235 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
237 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
238 // a signed/unsigned value of type i[2*N], and return the full value as
239 // two results, each of type iN.
240 SMUL_LOHI, UMUL_LOHI,
242 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
246 // CARRY_FALSE - This node is used when folding other nodes,
247 // like ADDC/SUBC, which indicate the carry result is always false.
250 // Carry-setting nodes for multiple precision addition and subtraction.
251 // These nodes take two operands of the same value type, and produce two
252 // results. The first result is the normal add or sub result, the second
253 // result is the carry flag result.
256 // Carry-using nodes for multiple precision addition and subtraction. These
257 // nodes take three operands: The first two are the normal lhs and rhs to
258 // the add or sub, and the third is the input carry flag. These nodes
259 // produce two results; the normal result of the add or sub, and the output
260 // carry flag. These nodes both read and write a carry flag to allow them
261 // to them to be chained together for add and sub of arbitrarily large
265 // Simple binary floating point operators.
266 FADD, FSUB, FMUL, FDIV, FREM,
268 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
269 // DAG node does not require that X and Y have the same type, just that they
270 // are both floating point. X and the result must have the same type.
271 // FCOPYSIGN(f32, f64) is allowed.
274 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
275 // value as an integer 0/1 value.
278 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
279 /// with the specified, possibly variable, elements. The number of elements
280 /// is required to be a power of two.
283 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
284 /// at IDX replaced with VAL.
287 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
288 /// identified by the (potentially variable) element number IDX.
291 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
292 /// vector type with the same length and element type, this produces a
293 /// concatenated vector result value, with length equal to the sum of the
294 /// lengths of the input vectors.
297 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
298 /// vector value) starting with the (potentially variable) element number
299 /// IDX, which must be a multiple of the result vector length.
302 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
303 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
304 /// (regardless of whether its datatype is legal or not) that indicate
305 /// which value each result element will get. The elements of VEC1/VEC2 are
306 /// enumerated in order. This is quite similar to the Altivec 'vperm'
307 /// instruction, except that the indices must be constants and are in terms
308 /// of the element size of VEC1/VEC2, not in terms of bytes.
311 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
312 /// scalar value into element 0 of the resultant vector type. The top
313 /// elements 1 to N-1 of the N-element vector are undefined.
316 // EXTRACT_SUBREG - This node is used to extract a sub-register value.
317 // This node takes a superreg and a constant sub-register index as operands.
320 // INSERT_SUBREG - This node is used to insert a sub-register value.
321 // This node takes a superreg, a subreg value, and a constant sub-register
322 // index as operands.
325 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
326 // an unsigned/signed value of type i[2*N], then return the top part.
329 // Bitwise operators - logical and, logical or, logical xor, shift left,
330 // shift right algebraic (shift in sign bits), shift right logical (shift in
331 // zeroes), rotate left, rotate right, and byteswap.
332 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
334 // Counting operators
337 // Select(COND, TRUEVAL, FALSEVAL)
340 // Select with condition operator - This selects between a true value and
341 // a false value (ops #2 and #3) based on the boolean result of comparing
342 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
343 // condition code in op #4, a CondCodeSDNode.
346 // SetCC operator - This evaluates to a boolean (i1) true value if the
347 // condition is true. The operands to this are the left and right operands
348 // to compare (ops #0, and #1) and the condition code to compare them with
349 // (op #2) as a CondCodeSDNode.
352 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
353 // integer shift operations, just like ADD/SUB_PARTS. The operation
355 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
356 SHL_PARTS, SRA_PARTS, SRL_PARTS,
358 // Conversion operators. These are all single input single output
359 // operations. For all of these, the result type must be strictly
360 // wider or narrower (depending on the operation) than the source
363 // SIGN_EXTEND - Used for integer types, replicating the sign bit
367 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
370 // ANY_EXTEND - Used for integer types. The high bits are undefined.
373 // TRUNCATE - Completely drop the high bits.
376 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
377 // depends on the first letter) to floating point.
381 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
382 // sign extend a small value in a large integer register (e.g. sign
383 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
384 // with the 7th bit). The size of the smaller type is indicated by the 1th
385 // operand, a ValueType node.
388 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
393 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
394 /// down to the precision of the destination VT. TRUNC is a flag, which is
395 /// always an integer that is zero or one. If TRUNC is 0, this is a
396 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
399 /// The TRUNC = 1 case is used in cases where we know that the value will
400 /// not be modified by the node, because Y is not using any of the extra
401 /// precision of source type. This allows certain transformations like
402 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
403 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
406 // FLT_ROUNDS - Returns current rounding mode:
409 // 1 Round to nearest
414 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
415 /// rounds it to a floating point value. It then promotes it and returns it
416 /// in a register of the same size. This operation effectively just
417 /// discards excess precision. The type to round down to is specified by
418 /// the VT operand, a VTSDNode.
421 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
424 // BIT_CONVERT - Theis operator converts between integer and FP values, as
425 // if one was stored to memory as integer and the other was loaded from the
426 // same address (or equivalently for vector format conversions, etc). The
427 // source and result are required to have the same bit size (e.g.
428 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
429 // conversions, but that is a noop, deleted by getNode().
432 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
433 // negation, absolute value, square root, sine and cosine, powi, and pow
435 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
437 // LOAD and STORE have token chains as their first operand, then the same
438 // operands as an LLVM load/store instruction, then an offset node that
439 // is added / subtracted from the base pointer to form the address (for
440 // indexed memory ops).
443 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
444 // to a specified boundary. This node always has two return values: a new
445 // stack pointer value and a chain. The first operand is the token chain,
446 // the second is the number of bytes to allocate, and the third is the
447 // alignment boundary. The size is guaranteed to be a multiple of the stack
448 // alignment, and the alignment is guaranteed to be bigger than the stack
449 // alignment (if required) or 0 to get standard stack alignment.
452 // Control flow instructions. These all have token chains.
454 // BR - Unconditional branch. The first operand is the chain
455 // operand, the second is the MBB to branch to.
458 // BRIND - Indirect branch. The first operand is the chain, the second
459 // is the value to branch to, which must be of the same type as the target's
463 // BR_JT - Jumptable branch. The first operand is the chain, the second
464 // is the jumptable index, the last one is the jumptable entry index.
467 // BRCOND - Conditional branch. The first operand is the chain,
468 // the second is the condition, the third is the block to branch
469 // to if the condition is true.
472 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
473 // that the condition is represented as condition code, and two nodes to
474 // compare, rather than as a combined SetCC node. The operands in order are
475 // chain, cc, lhs, rhs, block to branch to if condition is true.
478 // RET - Return from function. The first operand is the chain,
479 // and any subsequent operands are pairs of return value and return value
480 // signness for the function. This operation can have variable number of
484 // INLINEASM - Represents an inline asm block. This node always has two
485 // return values: a chain and a flag result. The inputs are as follows:
486 // Operand #0 : Input chain.
487 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
488 // Operand #2n+2: A RegisterNode.
489 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
490 // Operand #last: Optional, an incoming flag.
493 // LABEL - Represents a label in mid basic block used to track
494 // locations needed for debug and exception handling tables. This node
496 // Operand #0 : input chain.
497 // Operand #1 : module unique number use to identify the label.
500 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
501 // value, the same type as the pointer type for the system, and an output
505 // STACKRESTORE has two operands, an input chain and a pointer to restore to
506 // it returns an output chain.
509 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain. The following
510 // correspond to the operands of the LLVM intrinsic functions and the last
511 // one is AlwaysInline. The only result is a token chain. The alignment
512 // argument is guaranteed to be a Constant node.
517 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
518 // a call sequence, and carry arbitrary information that target might want
519 // to know. The first operand is a chain, the rest are specified by the
520 // target and not touched by the DAG optimizers.
521 CALLSEQ_START, // Beginning of a call sequence
522 CALLSEQ_END, // End of a call sequence
524 // VAARG - VAARG has three operands: an input chain, a pointer, and a
525 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
528 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
529 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
533 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
534 // pointer, and a SRCVALUE.
537 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
538 // locations with their value. This allows one use alias analysis
539 // information in the backend.
542 // PCMARKER - This corresponds to the pcmarker intrinsic.
545 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
546 // The only operand is a chain and a value and a chain are produced. The
547 // value is the contents of the architecture specific cycle counter like
548 // register (or other high accuracy low latency clock source)
551 // HANDLENODE node - Used as a handle for various purposes.
554 // LOCATION - This node is used to represent a source location for debug
555 // info. It takes token chain as input, then a line number, then a column
556 // number, then a filename, then a working dir. It produces a token chain
560 // DEBUG_LOC - This node is used to represent source line information
561 // embedded in the code. It takes a token chain as input, then a line
562 // number, then a column then a file id (provided by MachineModuleInfo.) It
563 // produces a token chain as output.
566 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
567 // It takes as input a token chain, the pointer to the trampoline,
568 // the pointer to the nested function, the pointer to pass for the
569 // 'nest' parameter, a SRCVALUE for the trampoline and another for
570 // the nested function (allowing targets to access the original
571 // Function*). It produces the result of the intrinsic and a token
575 // TRAP - Trapping instruction
578 // BUILTIN_OP_END - This must be the last enum value in this list.
584 /// isBuildVectorAllOnes - Return true if the specified node is a
585 /// BUILD_VECTOR where all of the elements are ~0 or undef.
586 bool isBuildVectorAllOnes(const SDNode *N);
588 /// isBuildVectorAllZeros - Return true if the specified node is a
589 /// BUILD_VECTOR where all of the elements are 0 or undef.
590 bool isBuildVectorAllZeros(const SDNode *N);
592 //===--------------------------------------------------------------------===//
593 /// MemIndexedMode enum - This enum defines the load / store indexed
594 /// addressing modes.
596 /// UNINDEXED "Normal" load / store. The effective address is already
597 /// computed and is available in the base pointer. The offset
598 /// operand is always undefined. In addition to producing a
599 /// chain, an unindexed load produces one value (result of the
600 /// load); an unindexed store does not produces a value.
602 /// PRE_INC Similar to the unindexed mode where the effective address is
603 /// PRE_DEC the value of the base pointer add / subtract the offset.
604 /// It considers the computation as being folded into the load /
605 /// store operation (i.e. the load / store does the address
606 /// computation as well as performing the memory transaction).
607 /// The base operand is always undefined. In addition to
608 /// producing a chain, pre-indexed load produces two values
609 /// (result of the load and the result of the address
610 /// computation); a pre-indexed store produces one value (result
611 /// of the address computation).
613 /// POST_INC The effective address is the value of the base pointer. The
614 /// POST_DEC value of the offset operand is then added to / subtracted
615 /// from the base after memory transaction. In addition to
616 /// producing a chain, post-indexed load produces two values
617 /// (the result of the load and the result of the base +/- offset
618 /// computation); a post-indexed store produces one value (the
619 /// the result of the base +/- offset computation).
621 enum MemIndexedMode {
630 //===--------------------------------------------------------------------===//
631 /// LoadExtType enum - This enum defines the three variants of LOADEXT
632 /// (load with extension).
634 /// SEXTLOAD loads the integer operand and sign extends it to a larger
635 /// integer result type.
636 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
637 /// integer result type.
638 /// EXTLOAD is used for three things: floating point extending loads,
639 /// integer extending loads [the top bits are undefined], and vector
640 /// extending loads [load into low elt].
650 //===--------------------------------------------------------------------===//
651 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
652 /// below work out, when considering SETFALSE (something that never exists
653 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
654 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
655 /// to. If the "N" column is 1, the result of the comparison is undefined if
656 /// the input is a NAN.
658 /// All of these (except for the 'always folded ops') should be handled for
659 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
660 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
662 /// Note that these are laid out in a specific order to allow bit-twiddling
663 /// to transform conditions.
665 // Opcode N U L G E Intuitive operation
666 SETFALSE, // 0 0 0 0 Always false (always folded)
667 SETOEQ, // 0 0 0 1 True if ordered and equal
668 SETOGT, // 0 0 1 0 True if ordered and greater than
669 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
670 SETOLT, // 0 1 0 0 True if ordered and less than
671 SETOLE, // 0 1 0 1 True if ordered and less than or equal
672 SETONE, // 0 1 1 0 True if ordered and operands are unequal
673 SETO, // 0 1 1 1 True if ordered (no nans)
674 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
675 SETUEQ, // 1 0 0 1 True if unordered or equal
676 SETUGT, // 1 0 1 0 True if unordered or greater than
677 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
678 SETULT, // 1 1 0 0 True if unordered or less than
679 SETULE, // 1 1 0 1 True if unordered, less than, or equal
680 SETUNE, // 1 1 1 0 True if unordered or not equal
681 SETTRUE, // 1 1 1 1 Always true (always folded)
682 // Don't care operations: undefined if the input is a nan.
683 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
684 SETEQ, // 1 X 0 0 1 True if equal
685 SETGT, // 1 X 0 1 0 True if greater than
686 SETGE, // 1 X 0 1 1 True if greater than or equal
687 SETLT, // 1 X 1 0 0 True if less than
688 SETLE, // 1 X 1 0 1 True if less than or equal
689 SETNE, // 1 X 1 1 0 True if not equal
690 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
692 SETCC_INVALID // Marker value.
695 /// isSignedIntSetCC - Return true if this is a setcc instruction that
696 /// performs a signed comparison when used with integer operands.
697 inline bool isSignedIntSetCC(CondCode Code) {
698 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
701 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
702 /// performs an unsigned comparison when used with integer operands.
703 inline bool isUnsignedIntSetCC(CondCode Code) {
704 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
707 /// isTrueWhenEqual - Return true if the specified condition returns true if
708 /// the two operands to the condition are equal. Note that if one of the two
709 /// operands is a NaN, this value is meaningless.
710 inline bool isTrueWhenEqual(CondCode Cond) {
711 return ((int)Cond & 1) != 0;
714 /// getUnorderedFlavor - This function returns 0 if the condition is always
715 /// false if an operand is a NaN, 1 if the condition is always true if the
716 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
718 inline unsigned getUnorderedFlavor(CondCode Cond) {
719 return ((int)Cond >> 3) & 3;
722 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
723 /// 'op' is a valid SetCC operation.
724 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
726 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
727 /// when given the operation for (X op Y).
728 CondCode getSetCCSwappedOperands(CondCode Operation);
730 /// getSetCCOrOperation - Return the result of a logical OR between different
731 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
732 /// function returns SETCC_INVALID if it is not possible to represent the
733 /// resultant comparison.
734 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
736 /// getSetCCAndOperation - Return the result of a logical AND between
737 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
738 /// function returns SETCC_INVALID if it is not possible to represent the
739 /// resultant comparison.
740 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
741 } // end llvm::ISD namespace
744 //===----------------------------------------------------------------------===//
745 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
746 /// values as the result of a computation. Many nodes return multiple values,
747 /// from loads (which define a token and a return value) to ADDC (which returns
748 /// a result and a carry value), to calls (which may return an arbitrary number
751 /// As such, each use of a SelectionDAG computation must indicate the node that
752 /// computes it as well as which return value to use from that node. This pair
753 /// of information is represented with the SDOperand value type.
757 SDNode *Val; // The node defining the value we are using.
758 unsigned ResNo; // Which return value of the node we are using.
760 SDOperand() : Val(0), ResNo(0) {}
761 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
763 bool operator==(const SDOperand &O) const {
764 return Val == O.Val && ResNo == O.ResNo;
766 bool operator!=(const SDOperand &O) const {
767 return !operator==(O);
769 bool operator<(const SDOperand &O) const {
770 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
773 SDOperand getValue(unsigned R) const {
774 return SDOperand(Val, R);
777 // isOperand - Return true if this node is an operand of N.
778 bool isOperand(SDNode *N) const;
780 /// getValueType - Return the ValueType of the referenced return value.
782 inline MVT::ValueType getValueType() const;
784 // Forwarding methods - These forward to the corresponding methods in SDNode.
785 inline unsigned getOpcode() const;
786 inline unsigned getNumOperands() const;
787 inline const SDOperand &getOperand(unsigned i) const;
788 inline uint64_t getConstantOperandVal(unsigned i) const;
789 inline bool isTargetOpcode() const;
790 inline unsigned getTargetOpcode() const;
793 /// reachesChainWithoutSideEffects - Return true if this operand (which must
794 /// be a chain) reaches the specified operand without crossing any
795 /// side-effecting instructions. In practice, this looks through token
796 /// factors and non-volatile loads. In order to remain efficient, this only
797 /// looks a couple of nodes in, it does not do an exhaustive search.
798 bool reachesChainWithoutSideEffects(SDOperand Dest, unsigned Depth = 2) const;
800 /// hasOneUse - Return true if there is exactly one operation using this
801 /// result value of the defining operator.
802 inline bool hasOneUse() const;
804 /// use_empty - Return true if there are no operations using this
805 /// result value of the defining operator.
806 inline bool use_empty() const;
810 template<> struct DenseMapInfo<SDOperand> {
811 static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); }
812 static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);}
813 static unsigned getHashValue(const SDOperand &Val) {
814 return (unsigned)((uintptr_t)Val.Val >> 4) ^
815 (unsigned)((uintptr_t)Val.Val >> 9) + Val.ResNo;
817 static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
820 static bool isPod() { return true; }
823 /// simplify_type specializations - Allow casting operators to work directly on
824 /// SDOperands as if they were SDNode*'s.
825 template<> struct simplify_type<SDOperand> {
826 typedef SDNode* SimpleType;
827 static SimpleType getSimplifiedValue(const SDOperand &Val) {
828 return static_cast<SimpleType>(Val.Val);
831 template<> struct simplify_type<const SDOperand> {
832 typedef SDNode* SimpleType;
833 static SimpleType getSimplifiedValue(const SDOperand &Val) {
834 return static_cast<SimpleType>(Val.Val);
839 /// SDNode - Represents one node in the SelectionDAG.
841 class SDNode : public FoldingSetNode {
842 /// NodeType - The operation that this node performs.
844 unsigned short NodeType;
846 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
847 /// then they will be delete[]'d when the node is destroyed.
848 bool OperandsNeedDelete : 1;
850 /// NodeId - Unique id per SDNode in the DAG.
853 /// OperandList - The values that are used by this operation.
855 SDOperand *OperandList;
857 /// ValueList - The types of the values this node defines. SDNode's may
858 /// define multiple values simultaneously.
859 const MVT::ValueType *ValueList;
861 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
862 unsigned short NumOperands, NumValues;
864 /// Prev/Next pointers - These pointers form the linked list of of the
865 /// AllNodes list in the current DAG.
867 friend struct ilist_traits<SDNode>;
869 /// Uses - These are all of the SDNode's that use a value produced by this
871 SmallVector<SDNode*,3> Uses;
873 // Out-of-line virtual method to give class a home.
874 virtual void ANCHOR();
877 assert(NumOperands == 0 && "Operand list not cleared before deletion");
878 NodeType = ISD::DELETED_NODE;
881 //===--------------------------------------------------------------------===//
884 unsigned getOpcode() const { return NodeType; }
885 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
886 unsigned getTargetOpcode() const {
887 assert(isTargetOpcode() && "Not a target opcode!");
888 return NodeType - ISD::BUILTIN_OP_END;
891 size_t use_size() const { return Uses.size(); }
892 bool use_empty() const { return Uses.empty(); }
893 bool hasOneUse() const { return Uses.size() == 1; }
895 /// getNodeId - Return the unique node id.
897 int getNodeId() const { return NodeId; }
899 /// setNodeId - Set unique node id.
900 void setNodeId(int Id) { NodeId = Id; }
902 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
903 use_iterator use_begin() const { return Uses.begin(); }
904 use_iterator use_end() const { return Uses.end(); }
906 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
907 /// indicated value. This method ignores uses of other values defined by this
909 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
911 /// hasAnyUseOfValue - Return true if there are any use of the indicated
912 /// value. This method ignores uses of other values defined by this operation.
913 bool hasAnyUseOfValue(unsigned Value) const;
915 /// isOnlyUse - Return true if this node is the only use of N.
917 bool isOnlyUse(SDNode *N) const;
919 /// isOperand - Return true if this node is an operand of N.
921 bool isOperand(SDNode *N) const;
923 /// isPredecessor - Return true if this node is a predecessor of N. This node
924 /// is either an operand of N or it can be reached by recursively traversing
926 /// NOTE: this is an expensive method. Use it carefully.
927 bool isPredecessor(SDNode *N) const;
929 /// getNumOperands - Return the number of values used by this operation.
931 unsigned getNumOperands() const { return NumOperands; }
933 /// getConstantOperandVal - Helper method returns the integer value of a
934 /// ConstantSDNode operand.
935 uint64_t getConstantOperandVal(unsigned Num) const;
937 const SDOperand &getOperand(unsigned Num) const {
938 assert(Num < NumOperands && "Invalid child # of SDNode!");
939 return OperandList[Num];
942 typedef const SDOperand* op_iterator;
943 op_iterator op_begin() const { return OperandList; }
944 op_iterator op_end() const { return OperandList+NumOperands; }
947 SDVTList getVTList() const {
948 SDVTList X = { ValueList, NumValues };
952 /// getNumValues - Return the number of values defined/returned by this
955 unsigned getNumValues() const { return NumValues; }
957 /// getValueType - Return the type of a specified result.
959 MVT::ValueType getValueType(unsigned ResNo) const {
960 assert(ResNo < NumValues && "Illegal result number!");
961 return ValueList[ResNo];
964 typedef const MVT::ValueType* value_iterator;
965 value_iterator value_begin() const { return ValueList; }
966 value_iterator value_end() const { return ValueList+NumValues; }
968 /// getOperationName - Return the opcode of this operation for printing.
970 std::string getOperationName(const SelectionDAG *G = 0) const;
971 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
973 void dump(const SelectionDAG *G) const;
975 static bool classof(const SDNode *) { return true; }
977 /// Profile - Gather unique data for the node.
979 void Profile(FoldingSetNodeID &ID);
982 friend class SelectionDAG;
984 /// getValueTypeList - Return a pointer to the specified value type.
986 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
987 static SDVTList getSDVTList(MVT::ValueType VT) {
988 SDVTList Ret = { getValueTypeList(VT), 1 };
992 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
993 : NodeType(Opc), NodeId(-1) {
994 OperandsNeedDelete = true;
995 NumOperands = NumOps;
996 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
998 for (unsigned i = 0; i != NumOps; ++i) {
999 OperandList[i] = Ops[i];
1000 Ops[i].Val->Uses.push_back(this);
1003 ValueList = VTs.VTs;
1004 NumValues = VTs.NumVTs;
1007 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
1008 OperandsNeedDelete = false; // Operands set with InitOperands.
1012 ValueList = VTs.VTs;
1013 NumValues = VTs.NumVTs;
1017 /// InitOperands - Initialize the operands list of this node with the
1018 /// specified values, which are part of the node (thus they don't need to be
1019 /// copied in or allocated).
1020 void InitOperands(SDOperand *Ops, unsigned NumOps) {
1021 assert(OperandList == 0 && "Operands already set!");
1022 NumOperands = NumOps;
1025 for (unsigned i = 0; i != NumOps; ++i)
1026 Ops[i].Val->Uses.push_back(this);
1029 /// MorphNodeTo - This frees the operands of the current node, resets the
1030 /// opcode, types, and operands to the specified value. This should only be
1031 /// used by the SelectionDAG class.
1032 void MorphNodeTo(unsigned Opc, SDVTList L,
1033 const SDOperand *Ops, unsigned NumOps);
1035 void addUser(SDNode *User) {
1036 Uses.push_back(User);
1038 void removeUser(SDNode *User) {
1039 // Remove this user from the operand's use list.
1040 for (unsigned i = Uses.size(); ; --i) {
1041 assert(i != 0 && "Didn't find user!");
1042 if (Uses[i-1] == User) {
1043 Uses[i-1] = Uses.back();
1052 // Define inline functions from the SDOperand class.
1054 inline unsigned SDOperand::getOpcode() const {
1055 return Val->getOpcode();
1057 inline MVT::ValueType SDOperand::getValueType() const {
1058 return Val->getValueType(ResNo);
1060 inline unsigned SDOperand::getNumOperands() const {
1061 return Val->getNumOperands();
1063 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1064 return Val->getOperand(i);
1066 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1067 return Val->getConstantOperandVal(i);
1069 inline bool SDOperand::isTargetOpcode() const {
1070 return Val->isTargetOpcode();
1072 inline unsigned SDOperand::getTargetOpcode() const {
1073 return Val->getTargetOpcode();
1075 inline bool SDOperand::hasOneUse() const {
1076 return Val->hasNUsesOfValue(1, ResNo);
1078 inline bool SDOperand::use_empty() const {
1079 return !Val->hasAnyUseOfValue(ResNo);
1082 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1083 /// to allow co-allocation of node operands with the node itself.
1084 class UnarySDNode : public SDNode {
1085 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1088 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1089 : SDNode(Opc, VTs), Op(X) {
1090 InitOperands(&Op, 1);
1094 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1095 /// to allow co-allocation of node operands with the node itself.
1096 class BinarySDNode : public SDNode {
1097 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1100 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1101 : SDNode(Opc, VTs) {
1104 InitOperands(Ops, 2);
1108 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1109 /// to allow co-allocation of node operands with the node itself.
1110 class TernarySDNode : public SDNode {
1111 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1114 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1116 : SDNode(Opc, VTs) {
1120 InitOperands(Ops, 3);
1125 /// HandleSDNode - This class is used to form a handle around another node that
1126 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1127 /// operand. This node should be directly created by end-users and not added to
1128 /// the AllNodes list.
1129 class HandleSDNode : public SDNode {
1130 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1133 explicit HandleSDNode(SDOperand X)
1134 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1135 InitOperands(&Op, 1);
1138 SDOperand getValue() const { return Op; }
1141 class StringSDNode : public SDNode {
1143 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1145 friend class SelectionDAG;
1146 explicit StringSDNode(const std::string &val)
1147 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1150 const std::string &getValue() const { return Value; }
1151 static bool classof(const StringSDNode *) { return true; }
1152 static bool classof(const SDNode *N) {
1153 return N->getOpcode() == ISD::STRING;
1157 class ConstantSDNode : public SDNode {
1159 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1161 friend class SelectionDAG;
1162 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1163 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1168 uint64_t getValue() const { return Value; }
1170 int64_t getSignExtended() const {
1171 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1172 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1175 bool isNullValue() const { return Value == 0; }
1176 bool isAllOnesValue() const {
1177 return Value == MVT::getIntVTBitMask(getValueType(0));
1180 static bool classof(const ConstantSDNode *) { return true; }
1181 static bool classof(const SDNode *N) {
1182 return N->getOpcode() == ISD::Constant ||
1183 N->getOpcode() == ISD::TargetConstant;
1187 class ConstantFPSDNode : public SDNode {
1189 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1190 // Longterm plan: replace all uses of getValue with getValueAPF, remove
1191 // getValue, rename getValueAPF to getValue.
1193 friend class SelectionDAG;
1194 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT)
1195 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1196 getSDVTList(VT)), Value(val) {
1200 const APFloat& getValueAPF() const { return Value; }
1202 /// isExactlyValue - We don't rely on operator== working on double values, as
1203 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1204 /// As such, this method can be used to do an exact bit-for-bit comparison of
1205 /// two floating point values.
1207 /// We leave the version with the double argument here because it's just so
1208 /// convenient to write "2.0" and the like. Without this function we'd
1209 /// have to duplicate its logic everywhere it's called.
1210 bool isExactlyValue(double V) const {
1212 Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1213 return isExactlyValue(Tmp);
1215 bool isExactlyValue(const APFloat& V) const;
1217 bool isValueValidForType(MVT::ValueType VT, const APFloat& Val);
1219 static bool classof(const ConstantFPSDNode *) { return true; }
1220 static bool classof(const SDNode *N) {
1221 return N->getOpcode() == ISD::ConstantFP ||
1222 N->getOpcode() == ISD::TargetConstantFP;
1226 class GlobalAddressSDNode : public SDNode {
1227 GlobalValue *TheGlobal;
1229 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1231 friend class SelectionDAG;
1232 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1236 GlobalValue *getGlobal() const { return TheGlobal; }
1237 int getOffset() const { return Offset; }
1239 static bool classof(const GlobalAddressSDNode *) { return true; }
1240 static bool classof(const SDNode *N) {
1241 return N->getOpcode() == ISD::GlobalAddress ||
1242 N->getOpcode() == ISD::TargetGlobalAddress ||
1243 N->getOpcode() == ISD::GlobalTLSAddress ||
1244 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1248 class FrameIndexSDNode : public SDNode {
1250 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1252 friend class SelectionDAG;
1253 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1254 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1259 int getIndex() const { return FI; }
1261 static bool classof(const FrameIndexSDNode *) { return true; }
1262 static bool classof(const SDNode *N) {
1263 return N->getOpcode() == ISD::FrameIndex ||
1264 N->getOpcode() == ISD::TargetFrameIndex;
1268 class JumpTableSDNode : public SDNode {
1270 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1272 friend class SelectionDAG;
1273 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1274 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1279 int getIndex() const { return JTI; }
1281 static bool classof(const JumpTableSDNode *) { return true; }
1282 static bool classof(const SDNode *N) {
1283 return N->getOpcode() == ISD::JumpTable ||
1284 N->getOpcode() == ISD::TargetJumpTable;
1288 class ConstantPoolSDNode : public SDNode {
1291 MachineConstantPoolValue *MachineCPVal;
1293 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1295 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1297 friend class SelectionDAG;
1298 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1300 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1301 getSDVTList(VT)), Offset(o), Alignment(0) {
1302 assert((int)Offset >= 0 && "Offset is too large");
1305 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1307 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1308 getSDVTList(VT)), Offset(o), Alignment(Align) {
1309 assert((int)Offset >= 0 && "Offset is too large");
1312 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1313 MVT::ValueType VT, int o=0)
1314 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1315 getSDVTList(VT)), Offset(o), Alignment(0) {
1316 assert((int)Offset >= 0 && "Offset is too large");
1317 Val.MachineCPVal = v;
1318 Offset |= 1 << (sizeof(unsigned)*8-1);
1320 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1321 MVT::ValueType VT, int o, unsigned Align)
1322 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1323 getSDVTList(VT)), Offset(o), Alignment(Align) {
1324 assert((int)Offset >= 0 && "Offset is too large");
1325 Val.MachineCPVal = v;
1326 Offset |= 1 << (sizeof(unsigned)*8-1);
1330 bool isMachineConstantPoolEntry() const {
1331 return (int)Offset < 0;
1334 Constant *getConstVal() const {
1335 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1336 return Val.ConstVal;
1339 MachineConstantPoolValue *getMachineCPVal() const {
1340 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1341 return Val.MachineCPVal;
1344 int getOffset() const {
1345 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1348 // Return the alignment of this constant pool object, which is either 0 (for
1349 // default alignment) or log2 of the desired value.
1350 unsigned getAlignment() const { return Alignment; }
1352 const Type *getType() const;
1354 static bool classof(const ConstantPoolSDNode *) { return true; }
1355 static bool classof(const SDNode *N) {
1356 return N->getOpcode() == ISD::ConstantPool ||
1357 N->getOpcode() == ISD::TargetConstantPool;
1361 class BasicBlockSDNode : public SDNode {
1362 MachineBasicBlock *MBB;
1363 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1365 friend class SelectionDAG;
1366 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1367 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1371 MachineBasicBlock *getBasicBlock() const { return MBB; }
1373 static bool classof(const BasicBlockSDNode *) { return true; }
1374 static bool classof(const SDNode *N) {
1375 return N->getOpcode() == ISD::BasicBlock;
1379 class SrcValueSDNode : public SDNode {
1382 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1384 friend class SelectionDAG;
1385 SrcValueSDNode(const Value* v, int o)
1386 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v), offset(o) {
1390 const Value *getValue() const { return V; }
1391 int getOffset() const { return offset; }
1393 static bool classof(const SrcValueSDNode *) { return true; }
1394 static bool classof(const SDNode *N) {
1395 return N->getOpcode() == ISD::SRCVALUE;
1400 class RegisterSDNode : public SDNode {
1402 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1404 friend class SelectionDAG;
1405 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1406 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1410 unsigned getReg() const { return Reg; }
1412 static bool classof(const RegisterSDNode *) { return true; }
1413 static bool classof(const SDNode *N) {
1414 return N->getOpcode() == ISD::Register;
1418 class ExternalSymbolSDNode : public SDNode {
1420 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1422 friend class SelectionDAG;
1423 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1424 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1425 getSDVTList(VT)), Symbol(Sym) {
1429 const char *getSymbol() const { return Symbol; }
1431 static bool classof(const ExternalSymbolSDNode *) { return true; }
1432 static bool classof(const SDNode *N) {
1433 return N->getOpcode() == ISD::ExternalSymbol ||
1434 N->getOpcode() == ISD::TargetExternalSymbol;
1438 class CondCodeSDNode : public SDNode {
1439 ISD::CondCode Condition;
1440 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1442 friend class SelectionDAG;
1443 explicit CondCodeSDNode(ISD::CondCode Cond)
1444 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1448 ISD::CondCode get() const { return Condition; }
1450 static bool classof(const CondCodeSDNode *) { return true; }
1451 static bool classof(const SDNode *N) {
1452 return N->getOpcode() == ISD::CONDCODE;
1456 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1457 /// to parameterize some operations.
1458 class VTSDNode : public SDNode {
1459 MVT::ValueType ValueType;
1460 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1462 friend class SelectionDAG;
1463 explicit VTSDNode(MVT::ValueType VT)
1464 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1468 MVT::ValueType getVT() const { return ValueType; }
1470 static bool classof(const VTSDNode *) { return true; }
1471 static bool classof(const SDNode *N) {
1472 return N->getOpcode() == ISD::VALUETYPE;
1476 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1478 class LSBaseSDNode : public SDNode {
1480 // AddrMode - unindexed, pre-indexed, post-indexed.
1481 ISD::MemIndexedMode AddrMode;
1483 // MemoryVT - VT of in-memory value.
1484 MVT::ValueType MemoryVT;
1486 //! SrcValue - Memory location for alias analysis.
1487 const Value *SrcValue;
1489 //! SVOffset - Memory location offset.
1492 //! Alignment - Alignment of memory location in bytes.
1495 //! IsVolatile - True if the store is volatile.
1498 //! Operand array for load and store
1500 \note Moving this array to the base class captures more
1501 common functionality shared between LoadSDNode and
1506 LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned NumOperands,
1507 SDVTList VTs, ISD::MemIndexedMode AM, MVT::ValueType VT,
1508 const Value *SV, int SVO, unsigned Align, bool Vol)
1509 : SDNode(NodeTy, VTs),
1510 AddrMode(AM), MemoryVT(VT),
1511 SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol)
1513 for (unsigned i = 0; i != NumOperands; ++i)
1514 Ops[i] = Operands[i];
1515 InitOperands(Ops, NumOperands);
1516 assert(Align != 0 && "Loads and stores should have non-zero aligment");
1517 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1518 "Only indexed loads and stores have a non-undef offset operand");
1521 const SDOperand getChain() const {
1522 return getOperand(0);
1524 const SDOperand getBasePtr() const {
1525 return getOperand(getOpcode() == ISD::LOAD ? 1 : 2);
1527 const SDOperand getOffset() const {
1528 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1530 const SDOperand getValue() const {
1531 assert(getOpcode() == ISD::STORE);
1532 return getOperand(1);
1535 const Value *getSrcValue() const { return SrcValue; }
1536 int getSrcValueOffset() const { return SVOffset; }
1537 unsigned getAlignment() const { return Alignment; }
1538 MVT::ValueType getMemoryVT() const { return MemoryVT; }
1539 bool isVolatile() const { return IsVolatile; }
1541 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1543 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1544 bool isIndexed() const { return AddrMode != ISD::UNINDEXED; }
1546 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1547 bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; }
1549 static bool classof(const LSBaseSDNode *N) { return true; }
1550 static bool classof(const SDNode *N) {
1551 return N->getOpcode() == ISD::LOAD ||
1552 N->getOpcode() == ISD::STORE;
1556 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1558 class LoadSDNode : public LSBaseSDNode {
1559 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1561 // ExtType - non-ext, anyext, sext, zext.
1562 ISD::LoadExtType ExtType;
1565 friend class SelectionDAG;
1566 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1567 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1568 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1569 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
1570 VTs, AM, LVT, SV, O, Align, Vol),
1574 ISD::LoadExtType getExtensionType() const { return ExtType; }
1576 static bool classof(const LoadSDNode *) { return true; }
1577 static bool classof(const SDNode *N) {
1578 return N->getOpcode() == ISD::LOAD;
1582 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1584 class StoreSDNode : public LSBaseSDNode {
1585 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1587 // IsTruncStore - True if the op does a truncation before store.
1590 friend class SelectionDAG;
1591 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1592 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1593 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1594 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
1595 VTs, AM, SVT, SV, O, Align, Vol),
1596 IsTruncStore(isTrunc) { }
1599 bool isTruncatingStore() const { return IsTruncStore; }
1601 static bool classof(const StoreSDNode *) { return true; }
1602 static bool classof(const SDNode *N) {
1603 return N->getOpcode() == ISD::STORE;
1608 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1612 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1614 bool operator==(const SDNodeIterator& x) const {
1615 return Operand == x.Operand;
1617 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1619 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1620 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1621 Operand = I.Operand;
1625 pointer operator*() const {
1626 return Node->getOperand(Operand).Val;
1628 pointer operator->() const { return operator*(); }
1630 SDNodeIterator& operator++() { // Preincrement
1634 SDNodeIterator operator++(int) { // Postincrement
1635 SDNodeIterator tmp = *this; ++*this; return tmp;
1638 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1639 static SDNodeIterator end (SDNode *N) {
1640 return SDNodeIterator(N, N->getNumOperands());
1643 unsigned getOperand() const { return Operand; }
1644 const SDNode *getNode() const { return Node; }
1647 template <> struct GraphTraits<SDNode*> {
1648 typedef SDNode NodeType;
1649 typedef SDNodeIterator ChildIteratorType;
1650 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1651 static inline ChildIteratorType child_begin(NodeType *N) {
1652 return SDNodeIterator::begin(N);
1654 static inline ChildIteratorType child_end(NodeType *N) {
1655 return SDNodeIterator::end(N);
1660 struct ilist_traits<SDNode> {
1661 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1662 static SDNode *getNext(const SDNode *N) { return N->Next; }
1664 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1665 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1667 static SDNode *createSentinel() {
1668 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1670 static void destroySentinel(SDNode *N) { delete N; }
1671 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1674 void addNodeToList(SDNode *NTy) {}
1675 void removeNodeFromList(SDNode *NTy) {}
1676 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1677 const ilist_iterator<SDNode> &X,
1678 const ilist_iterator<SDNode> &Y) {}
1682 /// isNormalLoad - Returns true if the specified node is a non-extending
1683 /// and unindexed load.
1684 inline bool isNormalLoad(const SDNode *N) {
1685 if (N->getOpcode() != ISD::LOAD)
1687 const LoadSDNode *Ld = cast<LoadSDNode>(N);
1688 return Ld->getExtensionType() == ISD::NON_EXTLOAD &&
1689 Ld->getAddressingMode() == ISD::UNINDEXED;
1692 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1694 inline bool isNON_EXTLoad(const SDNode *N) {
1695 return N->getOpcode() == ISD::LOAD &&
1696 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1699 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1701 inline bool isEXTLoad(const SDNode *N) {
1702 return N->getOpcode() == ISD::LOAD &&
1703 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1706 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1708 inline bool isSEXTLoad(const SDNode *N) {
1709 return N->getOpcode() == ISD::LOAD &&
1710 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1713 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1715 inline bool isZEXTLoad(const SDNode *N) {
1716 return N->getOpcode() == ISD::LOAD &&
1717 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1720 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1722 inline bool isUNINDEXEDLoad(const SDNode *N) {
1723 return N->getOpcode() == ISD::LOAD &&
1724 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1727 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1729 inline bool isNON_TRUNCStore(const SDNode *N) {
1730 return N->getOpcode() == ISD::STORE &&
1731 !cast<StoreSDNode>(N)->isTruncatingStore();
1734 /// isTRUNCStore - Returns true if the specified node is a truncating
1736 inline bool isTRUNCStore(const SDNode *N) {
1737 return N->getOpcode() == ISD::STORE &&
1738 cast<StoreSDNode>(N)->isTruncatingStore();
1743 } // end llvm namespace