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 // FP_ROUND - Perform a rounding operation from the current
394 // precision down to the specified precision (currently always 64->32).
397 // FLT_ROUNDS - Returns current rounding mode:
400 // 1 Round to nearest
405 // FP_ROUND_INREG - This operator takes a floating point register, and
406 // rounds it to a floating point value. It then promotes it and returns it
407 // in a register of the same size. This operation effectively just discards
408 // excess precision. The type to round down to is specified by the 1th
409 // operation, a VTSDNode (currently always 64->32->64).
412 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
415 // BIT_CONVERT - Theis operator converts between integer and FP values, as
416 // if one was stored to memory as integer and the other was loaded from the
417 // same address (or equivalently for vector format conversions, etc). The
418 // source and result are required to have the same bit size (e.g.
419 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
420 // conversions, but that is a noop, deleted by getNode().
423 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
424 // negation, absolute value, square root, sine and cosine, powi, and pow
426 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
428 // LOAD and STORE have token chains as their first operand, then the same
429 // operands as an LLVM load/store instruction, then an offset node that
430 // is added / subtracted from the base pointer to form the address (for
431 // indexed memory ops).
434 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
435 // to a specified boundary. This node always has two return values: a new
436 // stack pointer value and a chain. The first operand is the token chain,
437 // the second is the number of bytes to allocate, and the third is the
438 // alignment boundary. The size is guaranteed to be a multiple of the stack
439 // alignment, and the alignment is guaranteed to be bigger than the stack
440 // alignment (if required) or 0 to get standard stack alignment.
443 // Control flow instructions. These all have token chains.
445 // BR - Unconditional branch. The first operand is the chain
446 // operand, the second is the MBB to branch to.
449 // BRIND - Indirect branch. The first operand is the chain, the second
450 // is the value to branch to, which must be of the same type as the target's
454 // BR_JT - Jumptable branch. The first operand is the chain, the second
455 // is the jumptable index, the last one is the jumptable entry index.
458 // BRCOND - Conditional branch. The first operand is the chain,
459 // the second is the condition, the third is the block to branch
460 // to if the condition is true.
463 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
464 // that the condition is represented as condition code, and two nodes to
465 // compare, rather than as a combined SetCC node. The operands in order are
466 // chain, cc, lhs, rhs, block to branch to if condition is true.
469 // RET - Return from function. The first operand is the chain,
470 // and any subsequent operands are pairs of return value and return value
471 // signness for the function. This operation can have variable number of
475 // INLINEASM - Represents an inline asm block. This node always has two
476 // return values: a chain and a flag result. The inputs are as follows:
477 // Operand #0 : Input chain.
478 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
479 // Operand #2n+2: A RegisterNode.
480 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
481 // Operand #last: Optional, an incoming flag.
484 // LABEL - Represents a label in mid basic block used to track
485 // locations needed for debug and exception handling tables. This node
487 // Operand #0 : input chain.
488 // Operand #1 : module unique number use to identify the label.
491 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
492 // value, the same type as the pointer type for the system, and an output
496 // STACKRESTORE has two operands, an input chain and a pointer to restore to
497 // it returns an output chain.
500 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain. The following
501 // correspond to the operands of the LLVM intrinsic functions and the last
502 // one is AlwaysInline. The only result is a token chain. The alignment
503 // argument is guaranteed to be a Constant node.
508 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
509 // a call sequence, and carry arbitrary information that target might want
510 // to know. The first operand is a chain, the rest are specified by the
511 // target and not touched by the DAG optimizers.
512 CALLSEQ_START, // Beginning of a call sequence
513 CALLSEQ_END, // End of a call sequence
515 // VAARG - VAARG has three operands: an input chain, a pointer, and a
516 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
519 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
520 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
524 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
525 // pointer, and a SRCVALUE.
528 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
529 // locations with their value. This allows one use alias analysis
530 // information in the backend.
533 // PCMARKER - This corresponds to the pcmarker intrinsic.
536 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
537 // The only operand is a chain and a value and a chain are produced. The
538 // value is the contents of the architecture specific cycle counter like
539 // register (or other high accuracy low latency clock source)
542 // HANDLENODE node - Used as a handle for various purposes.
545 // LOCATION - This node is used to represent a source location for debug
546 // info. It takes token chain as input, then a line number, then a column
547 // number, then a filename, then a working dir. It produces a token chain
551 // DEBUG_LOC - This node is used to represent source line information
552 // embedded in the code. It takes a token chain as input, then a line
553 // number, then a column then a file id (provided by MachineModuleInfo.) It
554 // produces a token chain as output.
557 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
558 // It takes as input a token chain, the pointer to the trampoline,
559 // the pointer to the nested function, the pointer to pass for the
560 // 'nest' parameter, a SRCVALUE for the trampoline and another for
561 // the nested function (allowing targets to access the original
562 // Function*). It produces the result of the intrinsic and a token
566 // TRAP - Trapping instruction
569 // BUILTIN_OP_END - This must be the last enum value in this list.
575 /// isBuildVectorAllOnes - Return true if the specified node is a
576 /// BUILD_VECTOR where all of the elements are ~0 or undef.
577 bool isBuildVectorAllOnes(const SDNode *N);
579 /// isBuildVectorAllZeros - Return true if the specified node is a
580 /// BUILD_VECTOR where all of the elements are 0 or undef.
581 bool isBuildVectorAllZeros(const SDNode *N);
583 //===--------------------------------------------------------------------===//
584 /// MemIndexedMode enum - This enum defines the load / store indexed
585 /// addressing modes.
587 /// UNINDEXED "Normal" load / store. The effective address is already
588 /// computed and is available in the base pointer. The offset
589 /// operand is always undefined. In addition to producing a
590 /// chain, an unindexed load produces one value (result of the
591 /// load); an unindexed store does not produces a value.
593 /// PRE_INC Similar to the unindexed mode where the effective address is
594 /// PRE_DEC the value of the base pointer add / subtract the offset.
595 /// It considers the computation as being folded into the load /
596 /// store operation (i.e. the load / store does the address
597 /// computation as well as performing the memory transaction).
598 /// The base operand is always undefined. In addition to
599 /// producing a chain, pre-indexed load produces two values
600 /// (result of the load and the result of the address
601 /// computation); a pre-indexed store produces one value (result
602 /// of the address computation).
604 /// POST_INC The effective address is the value of the base pointer. The
605 /// POST_DEC value of the offset operand is then added to / subtracted
606 /// from the base after memory transaction. In addition to
607 /// producing a chain, post-indexed load produces two values
608 /// (the result of the load and the result of the base +/- offset
609 /// computation); a post-indexed store produces one value (the
610 /// the result of the base +/- offset computation).
612 enum MemIndexedMode {
621 //===--------------------------------------------------------------------===//
622 /// LoadExtType enum - This enum defines the three variants of LOADEXT
623 /// (load with extension).
625 /// SEXTLOAD loads the integer operand and sign extends it to a larger
626 /// integer result type.
627 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
628 /// integer result type.
629 /// EXTLOAD is used for three things: floating point extending loads,
630 /// integer extending loads [the top bits are undefined], and vector
631 /// extending loads [load into low elt].
641 //===--------------------------------------------------------------------===//
642 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
643 /// below work out, when considering SETFALSE (something that never exists
644 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
645 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
646 /// to. If the "N" column is 1, the result of the comparison is undefined if
647 /// the input is a NAN.
649 /// All of these (except for the 'always folded ops') should be handled for
650 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
651 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
653 /// Note that these are laid out in a specific order to allow bit-twiddling
654 /// to transform conditions.
656 // Opcode N U L G E Intuitive operation
657 SETFALSE, // 0 0 0 0 Always false (always folded)
658 SETOEQ, // 0 0 0 1 True if ordered and equal
659 SETOGT, // 0 0 1 0 True if ordered and greater than
660 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
661 SETOLT, // 0 1 0 0 True if ordered and less than
662 SETOLE, // 0 1 0 1 True if ordered and less than or equal
663 SETONE, // 0 1 1 0 True if ordered and operands are unequal
664 SETO, // 0 1 1 1 True if ordered (no nans)
665 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
666 SETUEQ, // 1 0 0 1 True if unordered or equal
667 SETUGT, // 1 0 1 0 True if unordered or greater than
668 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
669 SETULT, // 1 1 0 0 True if unordered or less than
670 SETULE, // 1 1 0 1 True if unordered, less than, or equal
671 SETUNE, // 1 1 1 0 True if unordered or not equal
672 SETTRUE, // 1 1 1 1 Always true (always folded)
673 // Don't care operations: undefined if the input is a nan.
674 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
675 SETEQ, // 1 X 0 0 1 True if equal
676 SETGT, // 1 X 0 1 0 True if greater than
677 SETGE, // 1 X 0 1 1 True if greater than or equal
678 SETLT, // 1 X 1 0 0 True if less than
679 SETLE, // 1 X 1 0 1 True if less than or equal
680 SETNE, // 1 X 1 1 0 True if not equal
681 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
683 SETCC_INVALID // Marker value.
686 /// isSignedIntSetCC - Return true if this is a setcc instruction that
687 /// performs a signed comparison when used with integer operands.
688 inline bool isSignedIntSetCC(CondCode Code) {
689 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
692 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
693 /// performs an unsigned comparison when used with integer operands.
694 inline bool isUnsignedIntSetCC(CondCode Code) {
695 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
698 /// isTrueWhenEqual - Return true if the specified condition returns true if
699 /// the two operands to the condition are equal. Note that if one of the two
700 /// operands is a NaN, this value is meaningless.
701 inline bool isTrueWhenEqual(CondCode Cond) {
702 return ((int)Cond & 1) != 0;
705 /// getUnorderedFlavor - This function returns 0 if the condition is always
706 /// false if an operand is a NaN, 1 if the condition is always true if the
707 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
709 inline unsigned getUnorderedFlavor(CondCode Cond) {
710 return ((int)Cond >> 3) & 3;
713 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
714 /// 'op' is a valid SetCC operation.
715 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
717 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
718 /// when given the operation for (X op Y).
719 CondCode getSetCCSwappedOperands(CondCode Operation);
721 /// getSetCCOrOperation - Return the result of a logical OR between different
722 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
723 /// function returns SETCC_INVALID if it is not possible to represent the
724 /// resultant comparison.
725 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
727 /// getSetCCAndOperation - Return the result of a logical AND between
728 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
729 /// function returns SETCC_INVALID if it is not possible to represent the
730 /// resultant comparison.
731 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
732 } // end llvm::ISD namespace
735 //===----------------------------------------------------------------------===//
736 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
737 /// values as the result of a computation. Many nodes return multiple values,
738 /// from loads (which define a token and a return value) to ADDC (which returns
739 /// a result and a carry value), to calls (which may return an arbitrary number
742 /// As such, each use of a SelectionDAG computation must indicate the node that
743 /// computes it as well as which return value to use from that node. This pair
744 /// of information is represented with the SDOperand value type.
748 SDNode *Val; // The node defining the value we are using.
749 unsigned ResNo; // Which return value of the node we are using.
751 SDOperand() : Val(0), ResNo(0) {}
752 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
754 bool operator==(const SDOperand &O) const {
755 return Val == O.Val && ResNo == O.ResNo;
757 bool operator!=(const SDOperand &O) const {
758 return !operator==(O);
760 bool operator<(const SDOperand &O) const {
761 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
764 SDOperand getValue(unsigned R) const {
765 return SDOperand(Val, R);
768 // isOperand - Return true if this node is an operand of N.
769 bool isOperand(SDNode *N) const;
771 /// getValueType - Return the ValueType of the referenced return value.
773 inline MVT::ValueType getValueType() const;
775 // Forwarding methods - These forward to the corresponding methods in SDNode.
776 inline unsigned getOpcode() const;
777 inline unsigned getNumOperands() const;
778 inline const SDOperand &getOperand(unsigned i) const;
779 inline uint64_t getConstantOperandVal(unsigned i) const;
780 inline bool isTargetOpcode() const;
781 inline unsigned getTargetOpcode() const;
784 /// reachesChainWithoutSideEffects - Return true if this operand (which must
785 /// be a chain) reaches the specified operand without crossing any
786 /// side-effecting instructions. In practice, this looks through token
787 /// factors and non-volatile loads. In order to remain efficient, this only
788 /// looks a couple of nodes in, it does not do an exhaustive search.
789 bool reachesChainWithoutSideEffects(SDOperand Dest, unsigned Depth = 2) const;
791 /// hasOneUse - Return true if there is exactly one operation using this
792 /// result value of the defining operator.
793 inline bool hasOneUse() const;
795 /// use_empty - Return true if there are no operations using this
796 /// result value of the defining operator.
797 inline bool use_empty() const;
801 template<> struct DenseMapInfo<SDOperand> {
802 static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); }
803 static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);}
804 static unsigned getHashValue(const SDOperand &Val) {
805 return (unsigned)((uintptr_t)Val.Val >> 4) ^
806 (unsigned)((uintptr_t)Val.Val >> 9) + Val.ResNo;
808 static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
811 static bool isPod() { return true; }
814 /// simplify_type specializations - Allow casting operators to work directly on
815 /// SDOperands as if they were SDNode*'s.
816 template<> struct simplify_type<SDOperand> {
817 typedef SDNode* SimpleType;
818 static SimpleType getSimplifiedValue(const SDOperand &Val) {
819 return static_cast<SimpleType>(Val.Val);
822 template<> struct simplify_type<const SDOperand> {
823 typedef SDNode* SimpleType;
824 static SimpleType getSimplifiedValue(const SDOperand &Val) {
825 return static_cast<SimpleType>(Val.Val);
830 /// SDNode - Represents one node in the SelectionDAG.
832 class SDNode : public FoldingSetNode {
833 /// NodeType - The operation that this node performs.
835 unsigned short NodeType;
837 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
838 /// then they will be delete[]'d when the node is destroyed.
839 bool OperandsNeedDelete : 1;
841 /// NodeId - Unique id per SDNode in the DAG.
844 /// OperandList - The values that are used by this operation.
846 SDOperand *OperandList;
848 /// ValueList - The types of the values this node defines. SDNode's may
849 /// define multiple values simultaneously.
850 const MVT::ValueType *ValueList;
852 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
853 unsigned short NumOperands, NumValues;
855 /// Prev/Next pointers - These pointers form the linked list of of the
856 /// AllNodes list in the current DAG.
858 friend struct ilist_traits<SDNode>;
860 /// Uses - These are all of the SDNode's that use a value produced by this
862 SmallVector<SDNode*,3> Uses;
864 // Out-of-line virtual method to give class a home.
865 virtual void ANCHOR();
868 assert(NumOperands == 0 && "Operand list not cleared before deletion");
869 NodeType = ISD::DELETED_NODE;
872 //===--------------------------------------------------------------------===//
875 unsigned getOpcode() const { return NodeType; }
876 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
877 unsigned getTargetOpcode() const {
878 assert(isTargetOpcode() && "Not a target opcode!");
879 return NodeType - ISD::BUILTIN_OP_END;
882 size_t use_size() const { return Uses.size(); }
883 bool use_empty() const { return Uses.empty(); }
884 bool hasOneUse() const { return Uses.size() == 1; }
886 /// getNodeId - Return the unique node id.
888 int getNodeId() const { return NodeId; }
890 /// setNodeId - Set unique node id.
891 void setNodeId(int Id) { NodeId = Id; }
893 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
894 use_iterator use_begin() const { return Uses.begin(); }
895 use_iterator use_end() const { return Uses.end(); }
897 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
898 /// indicated value. This method ignores uses of other values defined by this
900 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
902 /// hasAnyUseOfValue - Return true if there are any use of the indicated
903 /// value. This method ignores uses of other values defined by this operation.
904 bool hasAnyUseOfValue(unsigned Value) const;
906 /// isOnlyUse - Return true if this node is the only use of N.
908 bool isOnlyUse(SDNode *N) const;
910 /// isOperand - Return true if this node is an operand of N.
912 bool isOperand(SDNode *N) const;
914 /// isPredecessor - Return true if this node is a predecessor of N. This node
915 /// is either an operand of N or it can be reached by recursively traversing
917 /// NOTE: this is an expensive method. Use it carefully.
918 bool isPredecessor(SDNode *N) const;
920 /// getNumOperands - Return the number of values used by this operation.
922 unsigned getNumOperands() const { return NumOperands; }
924 /// getConstantOperandVal - Helper method returns the integer value of a
925 /// ConstantSDNode operand.
926 uint64_t getConstantOperandVal(unsigned Num) const;
928 const SDOperand &getOperand(unsigned Num) const {
929 assert(Num < NumOperands && "Invalid child # of SDNode!");
930 return OperandList[Num];
933 typedef const SDOperand* op_iterator;
934 op_iterator op_begin() const { return OperandList; }
935 op_iterator op_end() const { return OperandList+NumOperands; }
938 SDVTList getVTList() const {
939 SDVTList X = { ValueList, NumValues };
943 /// getNumValues - Return the number of values defined/returned by this
946 unsigned getNumValues() const { return NumValues; }
948 /// getValueType - Return the type of a specified result.
950 MVT::ValueType getValueType(unsigned ResNo) const {
951 assert(ResNo < NumValues && "Illegal result number!");
952 return ValueList[ResNo];
955 typedef const MVT::ValueType* value_iterator;
956 value_iterator value_begin() const { return ValueList; }
957 value_iterator value_end() const { return ValueList+NumValues; }
959 /// getOperationName - Return the opcode of this operation for printing.
961 std::string getOperationName(const SelectionDAG *G = 0) const;
962 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
964 void dump(const SelectionDAG *G) const;
966 static bool classof(const SDNode *) { return true; }
968 /// Profile - Gather unique data for the node.
970 void Profile(FoldingSetNodeID &ID);
973 friend class SelectionDAG;
975 /// getValueTypeList - Return a pointer to the specified value type.
977 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
978 static SDVTList getSDVTList(MVT::ValueType VT) {
979 SDVTList Ret = { getValueTypeList(VT), 1 };
983 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
984 : NodeType(Opc), NodeId(-1) {
985 OperandsNeedDelete = true;
986 NumOperands = NumOps;
987 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
989 for (unsigned i = 0; i != NumOps; ++i) {
990 OperandList[i] = Ops[i];
991 Ops[i].Val->Uses.push_back(this);
995 NumValues = VTs.NumVTs;
998 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
999 OperandsNeedDelete = false; // Operands set with InitOperands.
1003 ValueList = VTs.VTs;
1004 NumValues = VTs.NumVTs;
1008 /// InitOperands - Initialize the operands list of this node with the
1009 /// specified values, which are part of the node (thus they don't need to be
1010 /// copied in or allocated).
1011 void InitOperands(SDOperand *Ops, unsigned NumOps) {
1012 assert(OperandList == 0 && "Operands already set!");
1013 NumOperands = NumOps;
1016 for (unsigned i = 0; i != NumOps; ++i)
1017 Ops[i].Val->Uses.push_back(this);
1020 /// MorphNodeTo - This frees the operands of the current node, resets the
1021 /// opcode, types, and operands to the specified value. This should only be
1022 /// used by the SelectionDAG class.
1023 void MorphNodeTo(unsigned Opc, SDVTList L,
1024 const SDOperand *Ops, unsigned NumOps);
1026 void addUser(SDNode *User) {
1027 Uses.push_back(User);
1029 void removeUser(SDNode *User) {
1030 // Remove this user from the operand's use list.
1031 for (unsigned i = Uses.size(); ; --i) {
1032 assert(i != 0 && "Didn't find user!");
1033 if (Uses[i-1] == User) {
1034 Uses[i-1] = Uses.back();
1043 // Define inline functions from the SDOperand class.
1045 inline unsigned SDOperand::getOpcode() const {
1046 return Val->getOpcode();
1048 inline MVT::ValueType SDOperand::getValueType() const {
1049 return Val->getValueType(ResNo);
1051 inline unsigned SDOperand::getNumOperands() const {
1052 return Val->getNumOperands();
1054 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1055 return Val->getOperand(i);
1057 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1058 return Val->getConstantOperandVal(i);
1060 inline bool SDOperand::isTargetOpcode() const {
1061 return Val->isTargetOpcode();
1063 inline unsigned SDOperand::getTargetOpcode() const {
1064 return Val->getTargetOpcode();
1066 inline bool SDOperand::hasOneUse() const {
1067 return Val->hasNUsesOfValue(1, ResNo);
1069 inline bool SDOperand::use_empty() const {
1070 return !Val->hasAnyUseOfValue(ResNo);
1073 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1074 /// to allow co-allocation of node operands with the node itself.
1075 class UnarySDNode : public SDNode {
1076 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1079 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1080 : SDNode(Opc, VTs), Op(X) {
1081 InitOperands(&Op, 1);
1085 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1086 /// to allow co-allocation of node operands with the node itself.
1087 class BinarySDNode : public SDNode {
1088 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1091 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1092 : SDNode(Opc, VTs) {
1095 InitOperands(Ops, 2);
1099 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1100 /// to allow co-allocation of node operands with the node itself.
1101 class TernarySDNode : public SDNode {
1102 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1105 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1107 : SDNode(Opc, VTs) {
1111 InitOperands(Ops, 3);
1116 /// HandleSDNode - This class is used to form a handle around another node that
1117 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1118 /// operand. This node should be directly created by end-users and not added to
1119 /// the AllNodes list.
1120 class HandleSDNode : public SDNode {
1121 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1124 explicit HandleSDNode(SDOperand X)
1125 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1126 InitOperands(&Op, 1);
1129 SDOperand getValue() const { return Op; }
1132 class StringSDNode : public SDNode {
1134 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1136 friend class SelectionDAG;
1137 explicit StringSDNode(const std::string &val)
1138 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1141 const std::string &getValue() const { return Value; }
1142 static bool classof(const StringSDNode *) { return true; }
1143 static bool classof(const SDNode *N) {
1144 return N->getOpcode() == ISD::STRING;
1148 class ConstantSDNode : public SDNode {
1150 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1152 friend class SelectionDAG;
1153 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1154 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1159 uint64_t getValue() const { return Value; }
1161 int64_t getSignExtended() const {
1162 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1163 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1166 bool isNullValue() const { return Value == 0; }
1167 bool isAllOnesValue() const {
1168 return Value == MVT::getIntVTBitMask(getValueType(0));
1171 static bool classof(const ConstantSDNode *) { return true; }
1172 static bool classof(const SDNode *N) {
1173 return N->getOpcode() == ISD::Constant ||
1174 N->getOpcode() == ISD::TargetConstant;
1178 class ConstantFPSDNode : public SDNode {
1180 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1181 // Longterm plan: replace all uses of getValue with getValueAPF, remove
1182 // getValue, rename getValueAPF to getValue.
1184 friend class SelectionDAG;
1185 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT)
1186 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1187 getSDVTList(VT)), Value(val) {
1191 const APFloat& getValueAPF() const { return Value; }
1193 /// isExactlyValue - We don't rely on operator== working on double values, as
1194 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1195 /// As such, this method can be used to do an exact bit-for-bit comparison of
1196 /// two floating point values.
1198 /// We leave the version with the double argument here because it's just so
1199 /// convenient to write "2.0" and the like. Without this function we'd
1200 /// have to duplicate its logic everywhere it's called.
1201 bool isExactlyValue(double V) const {
1202 if (getValueType(0)==MVT::f64)
1203 return isExactlyValue(APFloat(V));
1205 return isExactlyValue(APFloat((float)V));
1207 bool isExactlyValue(const APFloat& V) const;
1209 bool isValueValidForType(MVT::ValueType VT, const APFloat& Val);
1211 static bool classof(const ConstantFPSDNode *) { return true; }
1212 static bool classof(const SDNode *N) {
1213 return N->getOpcode() == ISD::ConstantFP ||
1214 N->getOpcode() == ISD::TargetConstantFP;
1218 class GlobalAddressSDNode : public SDNode {
1219 GlobalValue *TheGlobal;
1221 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1223 friend class SelectionDAG;
1224 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1228 GlobalValue *getGlobal() const { return TheGlobal; }
1229 int getOffset() const { return Offset; }
1231 static bool classof(const GlobalAddressSDNode *) { return true; }
1232 static bool classof(const SDNode *N) {
1233 return N->getOpcode() == ISD::GlobalAddress ||
1234 N->getOpcode() == ISD::TargetGlobalAddress ||
1235 N->getOpcode() == ISD::GlobalTLSAddress ||
1236 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1240 class FrameIndexSDNode : public SDNode {
1242 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1244 friend class SelectionDAG;
1245 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1246 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1251 int getIndex() const { return FI; }
1253 static bool classof(const FrameIndexSDNode *) { return true; }
1254 static bool classof(const SDNode *N) {
1255 return N->getOpcode() == ISD::FrameIndex ||
1256 N->getOpcode() == ISD::TargetFrameIndex;
1260 class JumpTableSDNode : public SDNode {
1262 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1264 friend class SelectionDAG;
1265 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1266 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1271 int getIndex() const { return JTI; }
1273 static bool classof(const JumpTableSDNode *) { return true; }
1274 static bool classof(const SDNode *N) {
1275 return N->getOpcode() == ISD::JumpTable ||
1276 N->getOpcode() == ISD::TargetJumpTable;
1280 class ConstantPoolSDNode : public SDNode {
1283 MachineConstantPoolValue *MachineCPVal;
1285 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1287 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1289 friend class SelectionDAG;
1290 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1292 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1293 getSDVTList(VT)), Offset(o), Alignment(0) {
1294 assert((int)Offset >= 0 && "Offset is too large");
1297 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1299 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1300 getSDVTList(VT)), Offset(o), Alignment(Align) {
1301 assert((int)Offset >= 0 && "Offset is too large");
1304 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1305 MVT::ValueType VT, int o=0)
1306 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1307 getSDVTList(VT)), Offset(o), Alignment(0) {
1308 assert((int)Offset >= 0 && "Offset is too large");
1309 Val.MachineCPVal = v;
1310 Offset |= 1 << (sizeof(unsigned)*8-1);
1312 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1313 MVT::ValueType VT, int o, unsigned Align)
1314 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1315 getSDVTList(VT)), Offset(o), Alignment(Align) {
1316 assert((int)Offset >= 0 && "Offset is too large");
1317 Val.MachineCPVal = v;
1318 Offset |= 1 << (sizeof(unsigned)*8-1);
1322 bool isMachineConstantPoolEntry() const {
1323 return (int)Offset < 0;
1326 Constant *getConstVal() const {
1327 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1328 return Val.ConstVal;
1331 MachineConstantPoolValue *getMachineCPVal() const {
1332 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1333 return Val.MachineCPVal;
1336 int getOffset() const {
1337 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1340 // Return the alignment of this constant pool object, which is either 0 (for
1341 // default alignment) or log2 of the desired value.
1342 unsigned getAlignment() const { return Alignment; }
1344 const Type *getType() const;
1346 static bool classof(const ConstantPoolSDNode *) { return true; }
1347 static bool classof(const SDNode *N) {
1348 return N->getOpcode() == ISD::ConstantPool ||
1349 N->getOpcode() == ISD::TargetConstantPool;
1353 class BasicBlockSDNode : public SDNode {
1354 MachineBasicBlock *MBB;
1355 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1357 friend class SelectionDAG;
1358 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1359 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1363 MachineBasicBlock *getBasicBlock() const { return MBB; }
1365 static bool classof(const BasicBlockSDNode *) { return true; }
1366 static bool classof(const SDNode *N) {
1367 return N->getOpcode() == ISD::BasicBlock;
1371 class SrcValueSDNode : public SDNode {
1374 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1376 friend class SelectionDAG;
1377 SrcValueSDNode(const Value* v, int o)
1378 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v), offset(o) {
1382 const Value *getValue() const { return V; }
1383 int getOffset() const { return offset; }
1385 static bool classof(const SrcValueSDNode *) { return true; }
1386 static bool classof(const SDNode *N) {
1387 return N->getOpcode() == ISD::SRCVALUE;
1392 class RegisterSDNode : public SDNode {
1394 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1396 friend class SelectionDAG;
1397 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1398 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1402 unsigned getReg() const { return Reg; }
1404 static bool classof(const RegisterSDNode *) { return true; }
1405 static bool classof(const SDNode *N) {
1406 return N->getOpcode() == ISD::Register;
1410 class ExternalSymbolSDNode : public SDNode {
1412 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1414 friend class SelectionDAG;
1415 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1416 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1417 getSDVTList(VT)), Symbol(Sym) {
1421 const char *getSymbol() const { return Symbol; }
1423 static bool classof(const ExternalSymbolSDNode *) { return true; }
1424 static bool classof(const SDNode *N) {
1425 return N->getOpcode() == ISD::ExternalSymbol ||
1426 N->getOpcode() == ISD::TargetExternalSymbol;
1430 class CondCodeSDNode : public SDNode {
1431 ISD::CondCode Condition;
1432 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1434 friend class SelectionDAG;
1435 explicit CondCodeSDNode(ISD::CondCode Cond)
1436 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1440 ISD::CondCode get() const { return Condition; }
1442 static bool classof(const CondCodeSDNode *) { return true; }
1443 static bool classof(const SDNode *N) {
1444 return N->getOpcode() == ISD::CONDCODE;
1448 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1449 /// to parameterize some operations.
1450 class VTSDNode : public SDNode {
1451 MVT::ValueType ValueType;
1452 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1454 friend class SelectionDAG;
1455 explicit VTSDNode(MVT::ValueType VT)
1456 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1460 MVT::ValueType getVT() const { return ValueType; }
1462 static bool classof(const VTSDNode *) { return true; }
1463 static bool classof(const SDNode *N) {
1464 return N->getOpcode() == ISD::VALUETYPE;
1468 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1470 class LSBaseSDNode : public SDNode {
1472 //! SrcValue - Memory location for alias analysis.
1473 const Value *SrcValue;
1475 //! SVOffset - Memory location offset.
1478 //! Alignment - Alignment of memory location in bytes.
1481 //! IsVolatile - True if the store is volatile.
1484 //! Operand array for load and store
1486 \note Moving this array to the base class captures more
1487 common functionality shared between LoadSDNode and
1492 LSBaseSDNode(ISD::NodeType NodeTy, SDVTList VTs, const Value *SV, int SVO,
1493 unsigned Align, bool Vol)
1494 : SDNode(NodeTy, VTs),
1495 SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol)
1498 const SDOperand getChain() const {
1499 return getOperand(0);
1501 const SDOperand getBasePtr() const {
1502 return getOperand(getOpcode() == ISD::LOAD ? 1 : 2);
1504 const SDOperand getOffset() const {
1505 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1507 const SDOperand getValue() const {
1508 assert(getOpcode() == ISD::STORE);
1509 return getOperand(1);
1512 const Value *getSrcValue() const { return SrcValue; }
1513 int getSrcValueOffset() const { return SVOffset; }
1514 unsigned getAlignment() const { return Alignment; }
1515 bool isVolatile() const { return IsVolatile; }
1517 static bool classof(const LSBaseSDNode *N) { return true; }
1518 static bool classof(const SDNode *N) { return true; }
1521 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1523 class LoadSDNode : public LSBaseSDNode {
1524 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1526 // AddrMode - unindexed, pre-indexed, post-indexed.
1527 ISD::MemIndexedMode AddrMode;
1529 // ExtType - non-ext, anyext, sext, zext.
1530 ISD::LoadExtType ExtType;
1532 // LoadedVT - VT of loaded value before extension.
1533 MVT::ValueType LoadedVT;
1535 friend class SelectionDAG;
1536 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1537 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1538 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1539 : LSBaseSDNode(ISD::LOAD, VTs, SV, O, Align, Vol),
1540 AddrMode(AM), ExtType(ETy), LoadedVT(LVT) {
1541 Ops[0] = ChainPtrOff[0]; // Chain
1542 Ops[1] = ChainPtrOff[1]; // Ptr
1543 Ops[2] = ChainPtrOff[2]; // Off
1544 InitOperands(Ops, 3);
1545 assert(Align != 0 && "Loads should have non-zero aligment");
1546 assert((getOffset().getOpcode() == ISD::UNDEF ||
1547 AddrMode != ISD::UNINDEXED) &&
1548 "Only indexed load has a non-undef offset operand");
1552 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1553 ISD::LoadExtType getExtensionType() const { return ExtType; }
1554 MVT::ValueType getLoadedVT() const { return LoadedVT; }
1556 static bool classof(const LoadSDNode *) { return true; }
1557 static bool classof(const SDNode *N) {
1558 return N->getOpcode() == ISD::LOAD;
1562 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1564 class StoreSDNode : public LSBaseSDNode {
1565 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1567 // AddrMode - unindexed, pre-indexed, post-indexed.
1568 ISD::MemIndexedMode AddrMode;
1570 // IsTruncStore - True if the op does a truncation before store.
1573 // StoredVT - VT of the value after truncation.
1574 MVT::ValueType StoredVT;
1576 friend class SelectionDAG;
1577 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1578 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1579 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1580 : LSBaseSDNode(ISD::STORE, VTs, SV, O, Align, Vol),
1581 AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT) {
1582 Ops[0] = ChainValuePtrOff[0]; // Chain
1583 Ops[1] = ChainValuePtrOff[1]; // Value
1584 Ops[2] = ChainValuePtrOff[2]; // Ptr
1585 Ops[3] = ChainValuePtrOff[3]; // Off
1586 InitOperands(Ops, 4);
1587 assert(Align != 0 && "Stores should have non-zero aligment");
1588 assert((getOffset().getOpcode() == ISD::UNDEF ||
1589 AddrMode != ISD::UNINDEXED) &&
1590 "Only indexed store has a non-undef offset operand");
1594 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1595 bool isTruncatingStore() const { return IsTruncStore; }
1596 MVT::ValueType getStoredVT() const { return StoredVT; }
1598 static bool classof(const StoreSDNode *) { return true; }
1599 static bool classof(const SDNode *N) {
1600 return N->getOpcode() == ISD::STORE;
1605 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1609 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1611 bool operator==(const SDNodeIterator& x) const {
1612 return Operand == x.Operand;
1614 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1616 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1617 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1618 Operand = I.Operand;
1622 pointer operator*() const {
1623 return Node->getOperand(Operand).Val;
1625 pointer operator->() const { return operator*(); }
1627 SDNodeIterator& operator++() { // Preincrement
1631 SDNodeIterator operator++(int) { // Postincrement
1632 SDNodeIterator tmp = *this; ++*this; return tmp;
1635 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1636 static SDNodeIterator end (SDNode *N) {
1637 return SDNodeIterator(N, N->getNumOperands());
1640 unsigned getOperand() const { return Operand; }
1641 const SDNode *getNode() const { return Node; }
1644 template <> struct GraphTraits<SDNode*> {
1645 typedef SDNode NodeType;
1646 typedef SDNodeIterator ChildIteratorType;
1647 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1648 static inline ChildIteratorType child_begin(NodeType *N) {
1649 return SDNodeIterator::begin(N);
1651 static inline ChildIteratorType child_end(NodeType *N) {
1652 return SDNodeIterator::end(N);
1657 struct ilist_traits<SDNode> {
1658 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1659 static SDNode *getNext(const SDNode *N) { return N->Next; }
1661 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1662 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1664 static SDNode *createSentinel() {
1665 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1667 static void destroySentinel(SDNode *N) { delete N; }
1668 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1671 void addNodeToList(SDNode *NTy) {}
1672 void removeNodeFromList(SDNode *NTy) {}
1673 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1674 const ilist_iterator<SDNode> &X,
1675 const ilist_iterator<SDNode> &Y) {}
1679 /// isNormalLoad - Returns true if the specified node is a non-extending
1680 /// and unindexed load.
1681 inline bool isNormalLoad(const SDNode *N) {
1682 if (N->getOpcode() != ISD::LOAD)
1684 const LoadSDNode *Ld = cast<LoadSDNode>(N);
1685 return Ld->getExtensionType() == ISD::NON_EXTLOAD &&
1686 Ld->getAddressingMode() == ISD::UNINDEXED;
1689 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1691 inline bool isNON_EXTLoad(const SDNode *N) {
1692 return N->getOpcode() == ISD::LOAD &&
1693 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1696 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1698 inline bool isEXTLoad(const SDNode *N) {
1699 return N->getOpcode() == ISD::LOAD &&
1700 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1703 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1705 inline bool isSEXTLoad(const SDNode *N) {
1706 return N->getOpcode() == ISD::LOAD &&
1707 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1710 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1712 inline bool isZEXTLoad(const SDNode *N) {
1713 return N->getOpcode() == ISD::LOAD &&
1714 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1717 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1719 inline bool isUNINDEXEDLoad(const SDNode *N) {
1720 return N->getOpcode() == ISD::LOAD &&
1721 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1724 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1726 inline bool isNON_TRUNCStore(const SDNode *N) {
1727 return N->getOpcode() == ISD::STORE &&
1728 !cast<StoreSDNode>(N)->isTruncatingStore();
1731 /// isTRUNCStore - Returns true if the specified node is a truncating
1733 inline bool isTRUNCStore(const SDNode *N) {
1734 return N->getOpcode() == ISD::STORE &&
1735 cast<StoreSDNode>(N)->isTruncatingStore();
1740 } // end llvm namespace