1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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/CodeGen/ValueTypes.h"
27 #include "llvm/Support/DataTypes.h"
34 class MachineBasicBlock;
35 class MachineConstantPoolValue;
37 template <typename T> struct DenseMapKeyInfo;
38 template <typename T> struct simplify_type;
39 template <typename T> struct ilist_traits;
40 template<typename NodeTy, typename Traits> class iplist;
41 template<typename NodeTy> class ilist_iterator;
43 /// SDVTList - This represents a list of ValueType's that has been intern'd by
44 /// a SelectionDAG. Instances of this simple value class are returned by
45 /// SelectionDAG::getVTList(...).
48 const MVT::ValueType *VTs;
49 unsigned short NumVTs;
52 /// ISD namespace - This namespace contains an enum which represents all of the
53 /// SelectionDAG node types and value types.
56 namespace ParamFlags {
59 ZExt = 1<<0, ///< Parameter should be zero extended
61 SExt = 1<<1, ///< Parameter should be sign extended
63 InReg = 1<<2, ///< Parameter should be passed in register
65 StructReturn = 1<<3, ///< Hidden struct-return pointer
67 ByVal = 1<<4, ///< Struct passed by value
69 Nest = 1<<5, ///< Parameter is nested function static chain
71 OrigAlignment = 0x1F<<27,
72 OrigAlignmentOffs = 27
76 //===--------------------------------------------------------------------===//
77 /// ISD::NodeType enum - This enum defines all of the operators valid in a
81 // DELETED_NODE - This is an illegal flag value that is used to catch
82 // errors. This opcode is not a legal opcode for any node.
85 // EntryToken - This is the marker used to indicate the start of the region.
88 // Token factor - This node takes multiple tokens as input and produces a
89 // single token result. This is used to represent the fact that the operand
90 // operators are independent of each other.
93 // AssertSext, AssertZext - These nodes record if a register contains a
94 // value that has already been zero or sign extended from a narrower type.
95 // These nodes take two operands. The first is the node that has already
96 // been extended, and the second is a value type node indicating the width
98 AssertSext, AssertZext,
100 // Various leaf nodes.
101 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
102 Constant, ConstantFP,
103 GlobalAddress, GlobalTLSAddress, FrameIndex,
104 JumpTable, ConstantPool, ExternalSymbol,
106 // The address of the GOT
109 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
110 // llvm.returnaddress on the DAG. These nodes take one operand, the index
111 // of the frame or return address to return. An index of zero corresponds
112 // to the current function's frame or return address, an index of one to the
113 // parent's frame or return address, and so on.
114 FRAMEADDR, RETURNADDR,
116 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
117 // first (possible) on-stack argument. This is needed for correct stack
118 // adjustment during unwind.
119 FRAME_TO_ARGS_OFFSET,
121 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
122 // address of the exception block on entry to an landing pad block.
125 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
126 // the selection index of the exception thrown.
129 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
130 // 'eh_return' gcc dwarf builtin, which is used to return from
131 // exception. The general meaning is: adjust stack by OFFSET and pass
132 // execution to HANDLER. Many platform-related details also :)
135 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
136 // simplification of the constant.
140 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
141 // anything else with this node, and this is valid in the target-specific
142 // dag, turning into a GlobalAddress operand.
144 TargetGlobalTLSAddress,
148 TargetExternalSymbol,
150 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
151 /// This node represents a target intrinsic function with no side effects.
152 /// The first operand is the ID number of the intrinsic from the
153 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
154 /// node has returns the result of the intrinsic.
157 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
158 /// This node represents a target intrinsic function with side effects that
159 /// returns a result. The first operand is a chain pointer. The second is
160 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
161 /// operands to the intrinsic follow. The node has two results, the result
162 /// of the intrinsic and an output chain.
165 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
166 /// This node represents a target intrinsic function with side effects that
167 /// does not return a result. The first operand is a chain pointer. The
168 /// second is the ID number of the intrinsic from the llvm::Intrinsic
169 /// namespace. The operands to the intrinsic follow.
172 // CopyToReg - This node has three operands: a chain, a register number to
173 // set to this value, and a value.
176 // CopyFromReg - This node indicates that the input value is a virtual or
177 // physical register that is defined outside of the scope of this
178 // SelectionDAG. The register is available from the RegSDNode object.
181 // UNDEF - An undefined node
184 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
185 /// represents the formal arguments for a function. CC# is a Constant value
186 /// indicating the calling convention of the function, and ISVARARG is a
187 /// flag that indicates whether the function is varargs or not. This node
188 /// has one result value for each incoming argument, plus one for the output
189 /// chain. It must be custom legalized. See description of CALL node for
190 /// FLAG argument contents explanation.
194 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
195 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
196 /// This node represents a fully general function call, before the legalizer
197 /// runs. This has one result value for each argument / flag pair, plus
198 /// a chain result. It must be custom legalized. Flag argument indicates
199 /// misc. argument attributes. Currently:
201 /// Bit 1 - 'inreg' attribute
202 /// Bit 2 - 'sret' attribute
203 /// Bits 31:27 - argument ABI alignment in the first argument piece and
204 /// alignment '1' in other argument pieces.
207 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
208 // a Constant, which is required to be operand #1), element of the aggregate
209 // value specified as operand #0. This is only for use before legalization,
210 // for values that will be broken into multiple registers.
213 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
214 // two values of the same integer value type, this produces a value twice as
215 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
218 // MERGE_VALUES - This node takes multiple discrete operands and returns
219 // them all as its individual results. This nodes has exactly the same
220 // number of inputs and outputs, and is only valid before legalization.
221 // This node is useful for some pieces of the code generator that want to
222 // think about a single node with multiple results, not multiple nodes.
225 // Simple integer binary arithmetic operators.
226 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
228 // CARRY_FALSE - This node is used when folding other nodes,
229 // like ADDC/SUBC, which indicate the carry result is always false.
232 // Carry-setting nodes for multiple precision addition and subtraction.
233 // These nodes take two operands of the same value type, and produce two
234 // results. The first result is the normal add or sub result, the second
235 // result is the carry flag result.
238 // Carry-using nodes for multiple precision addition and subtraction. These
239 // nodes take three operands: The first two are the normal lhs and rhs to
240 // the add or sub, and the third is the input carry flag. These nodes
241 // produce two results; the normal result of the add or sub, and the output
242 // carry flag. These nodes both read and write a carry flag to allow them
243 // to them to be chained together for add and sub of arbitrarily large
247 // Simple binary floating point operators.
248 FADD, FSUB, FMUL, FDIV, FREM,
250 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
251 // DAG node does not require that X and Y have the same type, just that they
252 // are both floating point. X and the result must have the same type.
253 // FCOPYSIGN(f32, f64) is allowed.
256 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
257 /// with the specified, possibly variable, elements. The number of elements
258 /// is required to be a power of two.
261 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
262 /// at IDX replaced with VAL.
265 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
266 /// identified by the (potentially variable) element number IDX.
269 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
270 /// vector type with the same length and element type, this produces a
271 /// concatenated vector result value, with length equal to the sum of the
272 /// lengths of the input vectors.
275 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
276 /// vector value) starting with the (potentially variable) element number
277 /// IDX, which must be a multiple of the result vector length.
280 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
281 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
282 /// (regardless of whether its datatype is legal or not) that indicate
283 /// which value each result element will get. The elements of VEC1/VEC2 are
284 /// enumerated in order. This is quite similar to the Altivec 'vperm'
285 /// instruction, except that the indices must be constants and are in terms
286 /// of the element size of VEC1/VEC2, not in terms of bytes.
289 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
290 /// scalar value into the low element of the resultant vector type. The top
291 /// elements of the vector are undefined.
294 // EXTRACT_SUBREG - This node is used to extract a sub-register value.
295 // This node takes a superreg and a constant sub-register index as operands.
298 // INSERT_SUBREG - This node is used to insert a sub-register value.
299 // This node takes a superreg, a subreg value, and a constant sub-register
300 // index as operands.
303 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
304 // an unsigned/signed value of type i[2*n], then return the top part.
307 // Bitwise operators - logical and, logical or, logical xor, shift left,
308 // shift right algebraic (shift in sign bits), shift right logical (shift in
309 // zeroes), rotate left, rotate right, and byteswap.
310 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
312 // Counting operators
315 // Select(COND, TRUEVAL, FALSEVAL)
318 // Select with condition operator - This selects between a true value and
319 // a false value (ops #2 and #3) based on the boolean result of comparing
320 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
321 // condition code in op #4, a CondCodeSDNode.
324 // SetCC operator - This evaluates to a boolean (i1) true value if the
325 // condition is true. The operands to this are the left and right operands
326 // to compare (ops #0, and #1) and the condition code to compare them with
327 // (op #2) as a CondCodeSDNode.
330 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
331 // integer shift operations, just like ADD/SUB_PARTS. The operation
333 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
334 SHL_PARTS, SRA_PARTS, SRL_PARTS,
336 // Conversion operators. These are all single input single output
337 // operations. For all of these, the result type must be strictly
338 // wider or narrower (depending on the operation) than the source
341 // SIGN_EXTEND - Used for integer types, replicating the sign bit
345 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
348 // ANY_EXTEND - Used for integer types. The high bits are undefined.
351 // TRUNCATE - Completely drop the high bits.
354 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
355 // depends on the first letter) to floating point.
359 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
360 // sign extend a small value in a large integer register (e.g. sign
361 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
362 // with the 7th bit). The size of the smaller type is indicated by the 1th
363 // operand, a ValueType node.
366 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
371 // FP_ROUND - Perform a rounding operation from the current
372 // precision down to the specified precision (currently always 64->32).
375 // FP_ROUND_INREG - This operator takes a floating point register, and
376 // rounds it to a floating point value. It then promotes it and returns it
377 // in a register of the same size. This operation effectively just discards
378 // excess precision. The type to round down to is specified by the 1th
379 // operation, a VTSDNode (currently always 64->32->64).
382 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
385 // BIT_CONVERT - Theis operator converts between integer and FP values, as
386 // if one was stored to memory as integer and the other was loaded from the
387 // same address (or equivalently for vector format conversions, etc). The
388 // source and result are required to have the same bit size (e.g.
389 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
390 // conversions, but that is a noop, deleted by getNode().
393 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI - Perform unary floating point
394 // negation, absolute value, square root, sine and cosine, and powi
396 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI,
398 // LOAD and STORE have token chains as their first operand, then the same
399 // operands as an LLVM load/store instruction, then an offset node that
400 // is added / subtracted from the base pointer to form the address (for
401 // indexed memory ops).
404 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
405 // value and stores it to memory in one operation. This can be used for
406 // either integer or floating point operands. The first four operands of
407 // this are the same as a standard store. The fifth is the ValueType to
408 // store it as (which will be smaller than the source value).
411 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
412 // to a specified boundary. This node always has two return values: a new
413 // stack pointer value and a chain. The first operand is the token chain,
414 // the second is the number of bytes to allocate, and the third is the
415 // alignment boundary. The size is guaranteed to be a multiple of the stack
416 // alignment, and the alignment is guaranteed to be bigger than the stack
417 // alignment (if required) or 0 to get standard stack alignment.
420 // Control flow instructions. These all have token chains.
422 // BR - Unconditional branch. The first operand is the chain
423 // operand, the second is the MBB to branch to.
426 // BRIND - Indirect branch. The first operand is the chain, the second
427 // is the value to branch to, which must be of the same type as the target's
431 // BR_JT - Jumptable branch. The first operand is the chain, the second
432 // is the jumptable index, the last one is the jumptable entry index.
435 // BRCOND - Conditional branch. The first operand is the chain,
436 // the second is the condition, the third is the block to branch
437 // to if the condition is true.
440 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
441 // that the condition is represented as condition code, and two nodes to
442 // compare, rather than as a combined SetCC node. The operands in order are
443 // chain, cc, lhs, rhs, block to branch to if condition is true.
446 // RET - Return from function. The first operand is the chain,
447 // and any subsequent operands are pairs of return value and return value
448 // signness for the function. This operation can have variable number of
452 // INLINEASM - Represents an inline asm block. This node always has two
453 // return values: a chain and a flag result. The inputs are as follows:
454 // Operand #0 : Input chain.
455 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
456 // Operand #2n+2: A RegisterNode.
457 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
458 // Operand #last: Optional, an incoming flag.
461 // LABEL - Represents a label in mid basic block used to track
462 // locations needed for debug and exception handling tables. This node
464 // Operand #0 : input chain.
465 // Operand #1 : module unique number use to identify the label.
468 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
469 // value, the same type as the pointer type for the system, and an output
473 // STACKRESTORE has two operands, an input chain and a pointer to restore to
474 // it returns an output chain.
477 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
478 // correspond to the operands of the LLVM intrinsic functions. The only
479 // result is a token chain. The alignment argument is guaranteed to be a
485 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
486 // a call sequence, and carry arbitrary information that target might want
487 // to know. The first operand is a chain, the rest are specified by the
488 // target and not touched by the DAG optimizers.
489 CALLSEQ_START, // Beginning of a call sequence
490 CALLSEQ_END, // End of a call sequence
492 // VAARG - VAARG has three operands: an input chain, a pointer, and a
493 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
496 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
497 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
501 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
502 // pointer, and a SRCVALUE.
505 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
506 // locations with their value. This allows one use alias analysis
507 // information in the backend.
510 // PCMARKER - This corresponds to the pcmarker intrinsic.
513 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
514 // The only operand is a chain and a value and a chain are produced. The
515 // value is the contents of the architecture specific cycle counter like
516 // register (or other high accuracy low latency clock source)
519 // HANDLENODE node - Used as a handle for various purposes.
522 // LOCATION - This node is used to represent a source location for debug
523 // info. It takes token chain as input, then a line number, then a column
524 // number, then a filename, then a working dir. It produces a token chain
528 // DEBUG_LOC - This node is used to represent source line information
529 // embedded in the code. It takes a token chain as input, then a line
530 // number, then a column then a file id (provided by MachineModuleInfo.) It
531 // produces a token chain as output.
534 // ADJUST_TRAMP - This corresponds to the adjust_trampoline intrinsic.
535 // It takes a value as input and returns a value as output.
538 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
539 // It takes as input a token chain, the pointer to the trampoline,
540 // the pointer to the nested function, the pointer to pass for the
541 // 'nest' parameter, a SRCVALUE for the trampoline and another for
542 // the nested function (allowing targets to access the original
543 // Function*). It produces a token chain as output.
546 // BUILTIN_OP_END - This must be the last enum value in this list.
552 /// isBuildVectorAllOnes - Return true if the specified node is a
553 /// BUILD_VECTOR where all of the elements are ~0 or undef.
554 bool isBuildVectorAllOnes(const SDNode *N);
556 /// isBuildVectorAllZeros - Return true if the specified node is a
557 /// BUILD_VECTOR where all of the elements are 0 or undef.
558 bool isBuildVectorAllZeros(const SDNode *N);
560 //===--------------------------------------------------------------------===//
561 /// MemIndexedMode enum - This enum defines the load / store indexed
562 /// addressing modes.
564 /// UNINDEXED "Normal" load / store. The effective address is already
565 /// computed and is available in the base pointer. The offset
566 /// operand is always undefined. In addition to producing a
567 /// chain, an unindexed load produces one value (result of the
568 /// load); an unindexed store does not produces a value.
570 /// PRE_INC Similar to the unindexed mode where the effective address is
571 /// PRE_DEC the value of the base pointer add / subtract the offset.
572 /// It considers the computation as being folded into the load /
573 /// store operation (i.e. the load / store does the address
574 /// computation as well as performing the memory transaction).
575 /// The base operand is always undefined. In addition to
576 /// producing a chain, pre-indexed load produces two values
577 /// (result of the load and the result of the address
578 /// computation); a pre-indexed store produces one value (result
579 /// of the address computation).
581 /// POST_INC The effective address is the value of the base pointer. The
582 /// POST_DEC value of the offset operand is then added to / subtracted
583 /// from the base after memory transaction. In addition to
584 /// producing a chain, post-indexed load produces two values
585 /// (the result of the load and the result of the base +/- offset
586 /// computation); a post-indexed store produces one value (the
587 /// the result of the base +/- offset computation).
589 enum MemIndexedMode {
598 //===--------------------------------------------------------------------===//
599 /// LoadExtType enum - This enum defines the three variants of LOADEXT
600 /// (load with extension).
602 /// SEXTLOAD loads the integer operand and sign extends it to a larger
603 /// integer result type.
604 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
605 /// integer result type.
606 /// EXTLOAD is used for three things: floating point extending loads,
607 /// integer extending loads [the top bits are undefined], and vector
608 /// extending loads [load into low elt].
618 //===--------------------------------------------------------------------===//
619 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
620 /// below work out, when considering SETFALSE (something that never exists
621 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
622 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
623 /// to. If the "N" column is 1, the result of the comparison is undefined if
624 /// the input is a NAN.
626 /// All of these (except for the 'always folded ops') should be handled for
627 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
628 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
630 /// Note that these are laid out in a specific order to allow bit-twiddling
631 /// to transform conditions.
633 // Opcode N U L G E Intuitive operation
634 SETFALSE, // 0 0 0 0 Always false (always folded)
635 SETOEQ, // 0 0 0 1 True if ordered and equal
636 SETOGT, // 0 0 1 0 True if ordered and greater than
637 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
638 SETOLT, // 0 1 0 0 True if ordered and less than
639 SETOLE, // 0 1 0 1 True if ordered and less than or equal
640 SETONE, // 0 1 1 0 True if ordered and operands are unequal
641 SETO, // 0 1 1 1 True if ordered (no nans)
642 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
643 SETUEQ, // 1 0 0 1 True if unordered or equal
644 SETUGT, // 1 0 1 0 True if unordered or greater than
645 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
646 SETULT, // 1 1 0 0 True if unordered or less than
647 SETULE, // 1 1 0 1 True if unordered, less than, or equal
648 SETUNE, // 1 1 1 0 True if unordered or not equal
649 SETTRUE, // 1 1 1 1 Always true (always folded)
650 // Don't care operations: undefined if the input is a nan.
651 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
652 SETEQ, // 1 X 0 0 1 True if equal
653 SETGT, // 1 X 0 1 0 True if greater than
654 SETGE, // 1 X 0 1 1 True if greater than or equal
655 SETLT, // 1 X 1 0 0 True if less than
656 SETLE, // 1 X 1 0 1 True if less than or equal
657 SETNE, // 1 X 1 1 0 True if not equal
658 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
660 SETCC_INVALID // Marker value.
663 /// isSignedIntSetCC - Return true if this is a setcc instruction that
664 /// performs a signed comparison when used with integer operands.
665 inline bool isSignedIntSetCC(CondCode Code) {
666 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
669 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
670 /// performs an unsigned comparison when used with integer operands.
671 inline bool isUnsignedIntSetCC(CondCode Code) {
672 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
675 /// isTrueWhenEqual - Return true if the specified condition returns true if
676 /// the two operands to the condition are equal. Note that if one of the two
677 /// operands is a NaN, this value is meaningless.
678 inline bool isTrueWhenEqual(CondCode Cond) {
679 return ((int)Cond & 1) != 0;
682 /// getUnorderedFlavor - This function returns 0 if the condition is always
683 /// false if an operand is a NaN, 1 if the condition is always true if the
684 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
686 inline unsigned getUnorderedFlavor(CondCode Cond) {
687 return ((int)Cond >> 3) & 3;
690 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
691 /// 'op' is a valid SetCC operation.
692 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
694 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
695 /// when given the operation for (X op Y).
696 CondCode getSetCCSwappedOperands(CondCode Operation);
698 /// getSetCCOrOperation - Return the result of a logical OR between different
699 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
700 /// function returns SETCC_INVALID if it is not possible to represent the
701 /// resultant comparison.
702 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
704 /// getSetCCAndOperation - Return the result of a logical AND between
705 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
706 /// function returns SETCC_INVALID if it is not possible to represent the
707 /// resultant comparison.
708 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
709 } // end llvm::ISD namespace
712 //===----------------------------------------------------------------------===//
713 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
714 /// values as the result of a computation. Many nodes return multiple values,
715 /// from loads (which define a token and a return value) to ADDC (which returns
716 /// a result and a carry value), to calls (which may return an arbitrary number
719 /// As such, each use of a SelectionDAG computation must indicate the node that
720 /// computes it as well as which return value to use from that node. This pair
721 /// of information is represented with the SDOperand value type.
725 SDNode *Val; // The node defining the value we are using.
726 unsigned ResNo; // Which return value of the node we are using.
728 SDOperand() : Val(0), ResNo(0) {}
729 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
731 bool operator==(const SDOperand &O) const {
732 return Val == O.Val && ResNo == O.ResNo;
734 bool operator!=(const SDOperand &O) const {
735 return !operator==(O);
737 bool operator<(const SDOperand &O) const {
738 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
741 SDOperand getValue(unsigned R) const {
742 return SDOperand(Val, R);
745 // isOperand - Return true if this node is an operand of N.
746 bool isOperand(SDNode *N) const;
748 /// getValueType - Return the ValueType of the referenced return value.
750 inline MVT::ValueType getValueType() const;
752 // Forwarding methods - These forward to the corresponding methods in SDNode.
753 inline unsigned getOpcode() const;
754 inline unsigned getNumOperands() const;
755 inline const SDOperand &getOperand(unsigned i) const;
756 inline uint64_t getConstantOperandVal(unsigned i) const;
757 inline bool isTargetOpcode() const;
758 inline unsigned getTargetOpcode() const;
760 /// hasOneUse - Return true if there is exactly one operation using this
761 /// result value of the defining operator.
762 inline bool hasOneUse() const;
766 template<> struct DenseMapKeyInfo<SDOperand> {
767 static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); }
768 static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);}
769 static unsigned getHashValue(const SDOperand &Val) {
770 return (unsigned)((uintptr_t)Val.Val >> 4) ^
771 (unsigned)((uintptr_t)Val.Val >> 9) + Val.ResNo;
773 static bool isPod() { return true; }
776 /// simplify_type specializations - Allow casting operators to work directly on
777 /// SDOperands as if they were SDNode*'s.
778 template<> struct simplify_type<SDOperand> {
779 typedef SDNode* SimpleType;
780 static SimpleType getSimplifiedValue(const SDOperand &Val) {
781 return static_cast<SimpleType>(Val.Val);
784 template<> struct simplify_type<const SDOperand> {
785 typedef SDNode* SimpleType;
786 static SimpleType getSimplifiedValue(const SDOperand &Val) {
787 return static_cast<SimpleType>(Val.Val);
792 /// SDNode - Represents one node in the SelectionDAG.
794 class SDNode : public FoldingSetNode {
795 /// NodeType - The operation that this node performs.
797 unsigned short NodeType;
799 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
800 /// then they will be delete[]'d when the node is destroyed.
801 bool OperandsNeedDelete : 1;
803 /// NodeId - Unique id per SDNode in the DAG.
806 /// OperandList - The values that are used by this operation.
808 SDOperand *OperandList;
810 /// ValueList - The types of the values this node defines. SDNode's may
811 /// define multiple values simultaneously.
812 const MVT::ValueType *ValueList;
814 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
815 unsigned short NumOperands, NumValues;
817 /// Prev/Next pointers - These pointers form the linked list of of the
818 /// AllNodes list in the current DAG.
820 friend struct ilist_traits<SDNode>;
822 /// Uses - These are all of the SDNode's that use a value produced by this
824 SmallVector<SDNode*,3> Uses;
826 // Out-of-line virtual method to give class a home.
827 virtual void ANCHOR();
830 assert(NumOperands == 0 && "Operand list not cleared before deletion");
831 NodeType = ISD::DELETED_NODE;
834 //===--------------------------------------------------------------------===//
837 unsigned getOpcode() const { return NodeType; }
838 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
839 unsigned getTargetOpcode() const {
840 assert(isTargetOpcode() && "Not a target opcode!");
841 return NodeType - ISD::BUILTIN_OP_END;
844 size_t use_size() const { return Uses.size(); }
845 bool use_empty() const { return Uses.empty(); }
846 bool hasOneUse() const { return Uses.size() == 1; }
848 /// getNodeId - Return the unique node id.
850 int getNodeId() const { return NodeId; }
852 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
853 use_iterator use_begin() const { return Uses.begin(); }
854 use_iterator use_end() const { return Uses.end(); }
856 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
857 /// indicated value. This method ignores uses of other values defined by this
859 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
861 /// isOnlyUse - Return true if this node is the only use of N.
863 bool isOnlyUse(SDNode *N) const;
865 /// isOperand - Return true if this node is an operand of N.
867 bool isOperand(SDNode *N) const;
869 /// isPredecessor - Return true if this node is a predecessor of N. This node
870 /// is either an operand of N or it can be reached by recursively traversing
872 /// NOTE: this is an expensive method. Use it carefully.
873 bool isPredecessor(SDNode *N) const;
875 /// getNumOperands - Return the number of values used by this operation.
877 unsigned getNumOperands() const { return NumOperands; }
879 /// getConstantOperandVal - Helper method returns the integer value of a
880 /// ConstantSDNode operand.
881 uint64_t getConstantOperandVal(unsigned Num) const;
883 const SDOperand &getOperand(unsigned Num) const {
884 assert(Num < NumOperands && "Invalid child # of SDNode!");
885 return OperandList[Num];
888 typedef const SDOperand* op_iterator;
889 op_iterator op_begin() const { return OperandList; }
890 op_iterator op_end() const { return OperandList+NumOperands; }
893 SDVTList getVTList() const {
894 SDVTList X = { ValueList, NumValues };
898 /// getNumValues - Return the number of values defined/returned by this
901 unsigned getNumValues() const { return NumValues; }
903 /// getValueType - Return the type of a specified result.
905 MVT::ValueType getValueType(unsigned ResNo) const {
906 assert(ResNo < NumValues && "Illegal result number!");
907 return ValueList[ResNo];
910 typedef const MVT::ValueType* value_iterator;
911 value_iterator value_begin() const { return ValueList; }
912 value_iterator value_end() const { return ValueList+NumValues; }
914 /// getOperationName - Return the opcode of this operation for printing.
916 std::string getOperationName(const SelectionDAG *G = 0) const;
917 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
919 void dump(const SelectionDAG *G) const;
921 static bool classof(const SDNode *) { return true; }
923 /// Profile - Gather unique data for the node.
925 void Profile(FoldingSetNodeID &ID);
928 friend class SelectionDAG;
930 /// getValueTypeList - Return a pointer to the specified value type.
932 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
933 static SDVTList getSDVTList(MVT::ValueType VT) {
934 SDVTList Ret = { getValueTypeList(VT), 1 };
938 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
939 : NodeType(Opc), NodeId(-1) {
940 OperandsNeedDelete = true;
941 NumOperands = NumOps;
942 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
944 for (unsigned i = 0; i != NumOps; ++i) {
945 OperandList[i] = Ops[i];
946 Ops[i].Val->Uses.push_back(this);
950 NumValues = VTs.NumVTs;
953 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
954 OperandsNeedDelete = false; // Operands set with InitOperands.
959 NumValues = VTs.NumVTs;
963 /// InitOperands - Initialize the operands list of this node with the
964 /// specified values, which are part of the node (thus they don't need to be
965 /// copied in or allocated).
966 void InitOperands(SDOperand *Ops, unsigned NumOps) {
967 assert(OperandList == 0 && "Operands already set!");
968 NumOperands = NumOps;
971 for (unsigned i = 0; i != NumOps; ++i)
972 Ops[i].Val->Uses.push_back(this);
975 /// MorphNodeTo - This frees the operands of the current node, resets the
976 /// opcode, types, and operands to the specified value. This should only be
977 /// used by the SelectionDAG class.
978 void MorphNodeTo(unsigned Opc, SDVTList L,
979 const SDOperand *Ops, unsigned NumOps);
981 void addUser(SDNode *User) {
982 Uses.push_back(User);
984 void removeUser(SDNode *User) {
985 // Remove this user from the operand's use list.
986 for (unsigned i = Uses.size(); ; --i) {
987 assert(i != 0 && "Didn't find user!");
988 if (Uses[i-1] == User) {
989 Uses[i-1] = Uses.back();
996 void setNodeId(int Id) {
1002 // Define inline functions from the SDOperand class.
1004 inline unsigned SDOperand::getOpcode() const {
1005 return Val->getOpcode();
1007 inline MVT::ValueType SDOperand::getValueType() const {
1008 return Val->getValueType(ResNo);
1010 inline unsigned SDOperand::getNumOperands() const {
1011 return Val->getNumOperands();
1013 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1014 return Val->getOperand(i);
1016 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1017 return Val->getConstantOperandVal(i);
1019 inline bool SDOperand::isTargetOpcode() const {
1020 return Val->isTargetOpcode();
1022 inline unsigned SDOperand::getTargetOpcode() const {
1023 return Val->getTargetOpcode();
1025 inline bool SDOperand::hasOneUse() const {
1026 return Val->hasNUsesOfValue(1, ResNo);
1029 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1030 /// to allow co-allocation of node operands with the node itself.
1031 class UnarySDNode : public SDNode {
1032 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1035 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1036 : SDNode(Opc, VTs), Op(X) {
1037 InitOperands(&Op, 1);
1041 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1042 /// to allow co-allocation of node operands with the node itself.
1043 class BinarySDNode : public SDNode {
1044 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1047 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1048 : SDNode(Opc, VTs) {
1051 InitOperands(Ops, 2);
1055 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1056 /// to allow co-allocation of node operands with the node itself.
1057 class TernarySDNode : public SDNode {
1058 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1061 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1063 : SDNode(Opc, VTs) {
1067 InitOperands(Ops, 3);
1072 /// HandleSDNode - This class is used to form a handle around another node that
1073 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1074 /// operand. This node should be directly created by end-users and not added to
1075 /// the AllNodes list.
1076 class HandleSDNode : public SDNode {
1077 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1080 explicit HandleSDNode(SDOperand X)
1081 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1082 InitOperands(&Op, 1);
1085 SDOperand getValue() const { return Op; }
1088 class StringSDNode : public SDNode {
1090 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1092 friend class SelectionDAG;
1093 explicit StringSDNode(const std::string &val)
1094 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1097 const std::string &getValue() const { return Value; }
1098 static bool classof(const StringSDNode *) { return true; }
1099 static bool classof(const SDNode *N) {
1100 return N->getOpcode() == ISD::STRING;
1104 class ConstantSDNode : public SDNode {
1106 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1108 friend class SelectionDAG;
1109 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1110 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1115 uint64_t getValue() const { return Value; }
1117 int64_t getSignExtended() const {
1118 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1119 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1122 bool isNullValue() const { return Value == 0; }
1123 bool isAllOnesValue() const {
1124 return Value == MVT::getIntVTBitMask(getValueType(0));
1127 static bool classof(const ConstantSDNode *) { return true; }
1128 static bool classof(const SDNode *N) {
1129 return N->getOpcode() == ISD::Constant ||
1130 N->getOpcode() == ISD::TargetConstant;
1134 class ConstantFPSDNode : public SDNode {
1136 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1138 friend class SelectionDAG;
1139 ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1140 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1141 getSDVTList(VT)), Value(val) {
1145 double getValue() const { return Value; }
1147 /// isExactlyValue - We don't rely on operator== working on double values, as
1148 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1149 /// As such, this method can be used to do an exact bit-for-bit comparison of
1150 /// two floating point values.
1151 bool isExactlyValue(double V) const;
1153 static bool classof(const ConstantFPSDNode *) { return true; }
1154 static bool classof(const SDNode *N) {
1155 return N->getOpcode() == ISD::ConstantFP ||
1156 N->getOpcode() == ISD::TargetConstantFP;
1160 class GlobalAddressSDNode : public SDNode {
1161 GlobalValue *TheGlobal;
1163 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1165 friend class SelectionDAG;
1166 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1170 GlobalValue *getGlobal() const { return TheGlobal; }
1171 int getOffset() const { return Offset; }
1173 static bool classof(const GlobalAddressSDNode *) { return true; }
1174 static bool classof(const SDNode *N) {
1175 return N->getOpcode() == ISD::GlobalAddress ||
1176 N->getOpcode() == ISD::TargetGlobalAddress ||
1177 N->getOpcode() == ISD::GlobalTLSAddress ||
1178 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1182 class FrameIndexSDNode : public SDNode {
1184 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1186 friend class SelectionDAG;
1187 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1188 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1193 int getIndex() const { return FI; }
1195 static bool classof(const FrameIndexSDNode *) { return true; }
1196 static bool classof(const SDNode *N) {
1197 return N->getOpcode() == ISD::FrameIndex ||
1198 N->getOpcode() == ISD::TargetFrameIndex;
1202 class JumpTableSDNode : public SDNode {
1204 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1206 friend class SelectionDAG;
1207 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1208 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1213 int getIndex() const { return JTI; }
1215 static bool classof(const JumpTableSDNode *) { return true; }
1216 static bool classof(const SDNode *N) {
1217 return N->getOpcode() == ISD::JumpTable ||
1218 N->getOpcode() == ISD::TargetJumpTable;
1222 class ConstantPoolSDNode : public SDNode {
1225 MachineConstantPoolValue *MachineCPVal;
1227 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1229 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1231 friend class SelectionDAG;
1232 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1234 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1235 getSDVTList(VT)), Offset(o), Alignment(0) {
1236 assert((int)Offset >= 0 && "Offset is too large");
1239 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1241 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1242 getSDVTList(VT)), Offset(o), Alignment(Align) {
1243 assert((int)Offset >= 0 && "Offset is too large");
1246 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1247 MVT::ValueType VT, int o=0)
1248 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1249 getSDVTList(VT)), Offset(o), Alignment(0) {
1250 assert((int)Offset >= 0 && "Offset is too large");
1251 Val.MachineCPVal = v;
1252 Offset |= 1 << (sizeof(unsigned)*8-1);
1254 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1255 MVT::ValueType VT, int o, unsigned Align)
1256 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1257 getSDVTList(VT)), Offset(o), Alignment(Align) {
1258 assert((int)Offset >= 0 && "Offset is too large");
1259 Val.MachineCPVal = v;
1260 Offset |= 1 << (sizeof(unsigned)*8-1);
1264 bool isMachineConstantPoolEntry() const {
1265 return (int)Offset < 0;
1268 Constant *getConstVal() const {
1269 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1270 return Val.ConstVal;
1273 MachineConstantPoolValue *getMachineCPVal() const {
1274 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1275 return Val.MachineCPVal;
1278 int getOffset() const {
1279 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1282 // Return the alignment of this constant pool object, which is either 0 (for
1283 // default alignment) or log2 of the desired value.
1284 unsigned getAlignment() const { return Alignment; }
1286 const Type *getType() const;
1288 static bool classof(const ConstantPoolSDNode *) { return true; }
1289 static bool classof(const SDNode *N) {
1290 return N->getOpcode() == ISD::ConstantPool ||
1291 N->getOpcode() == ISD::TargetConstantPool;
1295 class BasicBlockSDNode : public SDNode {
1296 MachineBasicBlock *MBB;
1297 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1299 friend class SelectionDAG;
1300 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1301 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1305 MachineBasicBlock *getBasicBlock() const { return MBB; }
1307 static bool classof(const BasicBlockSDNode *) { return true; }
1308 static bool classof(const SDNode *N) {
1309 return N->getOpcode() == ISD::BasicBlock;
1313 class SrcValueSDNode : public SDNode {
1316 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1318 friend class SelectionDAG;
1319 SrcValueSDNode(const Value* v, int o)
1320 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v), offset(o) {
1324 const Value *getValue() const { return V; }
1325 int getOffset() const { return offset; }
1327 static bool classof(const SrcValueSDNode *) { return true; }
1328 static bool classof(const SDNode *N) {
1329 return N->getOpcode() == ISD::SRCVALUE;
1334 class RegisterSDNode : public SDNode {
1336 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1338 friend class SelectionDAG;
1339 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1340 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1344 unsigned getReg() const { return Reg; }
1346 static bool classof(const RegisterSDNode *) { return true; }
1347 static bool classof(const SDNode *N) {
1348 return N->getOpcode() == ISD::Register;
1352 class ExternalSymbolSDNode : public SDNode {
1354 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1356 friend class SelectionDAG;
1357 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1358 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1359 getSDVTList(VT)), Symbol(Sym) {
1363 const char *getSymbol() const { return Symbol; }
1365 static bool classof(const ExternalSymbolSDNode *) { return true; }
1366 static bool classof(const SDNode *N) {
1367 return N->getOpcode() == ISD::ExternalSymbol ||
1368 N->getOpcode() == ISD::TargetExternalSymbol;
1372 class CondCodeSDNode : public SDNode {
1373 ISD::CondCode Condition;
1374 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1376 friend class SelectionDAG;
1377 explicit CondCodeSDNode(ISD::CondCode Cond)
1378 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1382 ISD::CondCode get() const { return Condition; }
1384 static bool classof(const CondCodeSDNode *) { return true; }
1385 static bool classof(const SDNode *N) {
1386 return N->getOpcode() == ISD::CONDCODE;
1390 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1391 /// to parameterize some operations.
1392 class VTSDNode : public SDNode {
1393 MVT::ValueType ValueType;
1394 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1396 friend class SelectionDAG;
1397 explicit VTSDNode(MVT::ValueType VT)
1398 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1402 MVT::ValueType getVT() const { return ValueType; }
1404 static bool classof(const VTSDNode *) { return true; }
1405 static bool classof(const SDNode *N) {
1406 return N->getOpcode() == ISD::VALUETYPE;
1410 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1412 class LoadSDNode : public SDNode {
1413 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1416 // AddrMode - unindexed, pre-indexed, post-indexed.
1417 ISD::MemIndexedMode AddrMode;
1419 // ExtType - non-ext, anyext, sext, zext.
1420 ISD::LoadExtType ExtType;
1422 // LoadedVT - VT of loaded value before extension.
1423 MVT::ValueType LoadedVT;
1425 // SrcValue - Memory location for alias analysis.
1426 const Value *SrcValue;
1428 // SVOffset - Memory location offset.
1431 // Alignment - Alignment of memory location in bytes.
1434 // IsVolatile - True if the load is volatile.
1437 friend class SelectionDAG;
1438 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1439 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1440 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1441 : SDNode(ISD::LOAD, VTs),
1442 AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
1443 Alignment(Align), IsVolatile(Vol) {
1444 Ops[0] = ChainPtrOff[0]; // Chain
1445 Ops[1] = ChainPtrOff[1]; // Ptr
1446 Ops[2] = ChainPtrOff[2]; // Off
1447 InitOperands(Ops, 3);
1448 assert(Align != 0 && "Loads should have non-zero aligment");
1449 assert((getOffset().getOpcode() == ISD::UNDEF ||
1450 AddrMode != ISD::UNINDEXED) &&
1451 "Only indexed load has a non-undef offset operand");
1455 const SDOperand getChain() const { return getOperand(0); }
1456 const SDOperand getBasePtr() const { return getOperand(1); }
1457 const SDOperand getOffset() const { return getOperand(2); }
1458 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1459 ISD::LoadExtType getExtensionType() const { return ExtType; }
1460 MVT::ValueType getLoadedVT() const { return LoadedVT; }
1461 const Value *getSrcValue() const { return SrcValue; }
1462 int getSrcValueOffset() const { return SVOffset; }
1463 unsigned getAlignment() const { return Alignment; }
1464 bool isVolatile() const { return IsVolatile; }
1466 static bool classof(const LoadSDNode *) { return true; }
1467 static bool classof(const SDNode *N) {
1468 return N->getOpcode() == ISD::LOAD;
1472 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1474 class StoreSDNode : public SDNode {
1475 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1478 // AddrMode - unindexed, pre-indexed, post-indexed.
1479 ISD::MemIndexedMode AddrMode;
1481 // IsTruncStore - True is the op does a truncation before store.
1484 // StoredVT - VT of the value after truncation.
1485 MVT::ValueType StoredVT;
1487 // SrcValue - Memory location for alias analysis.
1488 const Value *SrcValue;
1490 // SVOffset - Memory location offset.
1493 // Alignment - Alignment of memory location in bytes.
1496 // IsVolatile - True if the store is volatile.
1499 friend class SelectionDAG;
1500 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1501 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1502 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1503 : SDNode(ISD::STORE, VTs),
1504 AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT), SrcValue(SV),
1505 SVOffset(O), Alignment(Align), IsVolatile(Vol) {
1506 Ops[0] = ChainValuePtrOff[0]; // Chain
1507 Ops[1] = ChainValuePtrOff[1]; // Value
1508 Ops[2] = ChainValuePtrOff[2]; // Ptr
1509 Ops[3] = ChainValuePtrOff[3]; // Off
1510 InitOperands(Ops, 4);
1511 assert(Align != 0 && "Stores should have non-zero aligment");
1512 assert((getOffset().getOpcode() == ISD::UNDEF ||
1513 AddrMode != ISD::UNINDEXED) &&
1514 "Only indexed store has a non-undef offset operand");
1518 const SDOperand getChain() const { return getOperand(0); }
1519 const SDOperand getValue() const { return getOperand(1); }
1520 const SDOperand getBasePtr() const { return getOperand(2); }
1521 const SDOperand getOffset() const { return getOperand(3); }
1522 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1523 bool isTruncatingStore() const { return IsTruncStore; }
1524 MVT::ValueType getStoredVT() const { return StoredVT; }
1525 const Value *getSrcValue() const { return SrcValue; }
1526 int getSrcValueOffset() const { return SVOffset; }
1527 unsigned getAlignment() const { return Alignment; }
1528 bool isVolatile() const { return IsVolatile; }
1530 static bool classof(const StoreSDNode *) { return true; }
1531 static bool classof(const SDNode *N) {
1532 return N->getOpcode() == ISD::STORE;
1537 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1541 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1543 bool operator==(const SDNodeIterator& x) const {
1544 return Operand == x.Operand;
1546 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1548 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1549 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1550 Operand = I.Operand;
1554 pointer operator*() const {
1555 return Node->getOperand(Operand).Val;
1557 pointer operator->() const { return operator*(); }
1559 SDNodeIterator& operator++() { // Preincrement
1563 SDNodeIterator operator++(int) { // Postincrement
1564 SDNodeIterator tmp = *this; ++*this; return tmp;
1567 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1568 static SDNodeIterator end (SDNode *N) {
1569 return SDNodeIterator(N, N->getNumOperands());
1572 unsigned getOperand() const { return Operand; }
1573 const SDNode *getNode() const { return Node; }
1576 template <> struct GraphTraits<SDNode*> {
1577 typedef SDNode NodeType;
1578 typedef SDNodeIterator ChildIteratorType;
1579 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1580 static inline ChildIteratorType child_begin(NodeType *N) {
1581 return SDNodeIterator::begin(N);
1583 static inline ChildIteratorType child_end(NodeType *N) {
1584 return SDNodeIterator::end(N);
1589 struct ilist_traits<SDNode> {
1590 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1591 static SDNode *getNext(const SDNode *N) { return N->Next; }
1593 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1594 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1596 static SDNode *createSentinel() {
1597 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1599 static void destroySentinel(SDNode *N) { delete N; }
1600 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1603 void addNodeToList(SDNode *NTy) {}
1604 void removeNodeFromList(SDNode *NTy) {}
1605 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1606 const ilist_iterator<SDNode> &X,
1607 const ilist_iterator<SDNode> &Y) {}
1611 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1613 inline bool isNON_EXTLoad(const SDNode *N) {
1614 return N->getOpcode() == ISD::LOAD &&
1615 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1618 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1620 inline bool isEXTLoad(const SDNode *N) {
1621 return N->getOpcode() == ISD::LOAD &&
1622 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1625 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1627 inline bool isSEXTLoad(const SDNode *N) {
1628 return N->getOpcode() == ISD::LOAD &&
1629 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1632 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1634 inline bool isZEXTLoad(const SDNode *N) {
1635 return N->getOpcode() == ISD::LOAD &&
1636 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1639 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1641 inline bool isUNINDEXEDLoad(const SDNode *N) {
1642 return N->getOpcode() == ISD::LOAD &&
1643 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1646 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1648 inline bool isNON_TRUNCStore(const SDNode *N) {
1649 return N->getOpcode() == ISD::STORE &&
1650 !cast<StoreSDNode>(N)->isTruncatingStore();
1653 /// isTRUNCStore - Returns true if the specified node is a truncating
1655 inline bool isTRUNCStore(const SDNode *N) {
1656 return N->getOpcode() == ISD::STORE &&
1657 cast<StoreSDNode>(N)->isTruncatingStore();
1662 } // end llvm namespace