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/GlobalVariable.h"
23 #include "llvm/Value.h"
24 #include "llvm/ADT/FoldingSet.h"
25 #include "llvm/ADT/GraphTraits.h"
26 #include "llvm/ADT/iterator"
27 #include "llvm/CodeGen/ValueTypes.h"
28 #include "llvm/Support/DataTypes.h"
35 class MachineBasicBlock;
36 class MachineConstantPoolValue;
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 OrigAlignment = 0x1F<<27,
68 OrigAlignmentOffs = 27
72 //===--------------------------------------------------------------------===//
73 /// ISD::NodeType enum - This enum defines all of the operators valid in a
77 // DELETED_NODE - This is an illegal flag value that is used to catch
78 // errors. This opcode is not a legal opcode for any node.
81 // EntryToken - This is the marker used to indicate the start of the region.
84 // Token factor - This node takes multiple tokens as input and produces a
85 // single token result. This is used to represent the fact that the operand
86 // operators are independent of each other.
89 // AssertSext, AssertZext - These nodes record if a register contains a
90 // value that has already been zero or sign extended from a narrower type.
91 // These nodes take two operands. The first is the node that has already
92 // been extended, and the second is a value type node indicating the width
94 AssertSext, AssertZext,
96 // Various leaf nodes.
97 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
99 GlobalAddress, GlobalTLSAddress, FrameIndex,
100 JumpTable, ConstantPool, ExternalSymbol,
102 // The address of the GOT
105 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
106 // llvm.returnaddress on the DAG. These nodes take one operand, the index
107 // of the frame or return address to return. An index of zero corresponds
108 // to the current function's frame or return address, an index of one to the
109 // parent's frame or return address, and so on.
110 FRAMEADDR, RETURNADDR,
112 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
113 // address of the exception block on entry to an landing pad block.
116 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
117 // the selection index of the exception thrown.
120 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
121 // simplification of the constant.
125 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
126 // anything else with this node, and this is valid in the target-specific
127 // dag, turning into a GlobalAddress operand.
129 TargetGlobalTLSAddress,
133 TargetExternalSymbol,
135 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
136 /// This node represents a target intrinsic function with no side effects.
137 /// The first operand is the ID number of the intrinsic from the
138 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
139 /// node has returns the result of the intrinsic.
142 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
143 /// This node represents a target intrinsic function with side effects that
144 /// returns a result. The first operand is a chain pointer. The second is
145 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
146 /// operands to the intrinsic follow. The node has two results, the result
147 /// of the intrinsic and an output chain.
150 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
151 /// This node represents a target intrinsic function with side effects that
152 /// does not return a result. The first operand is a chain pointer. The
153 /// second is the ID number of the intrinsic from the llvm::Intrinsic
154 /// namespace. The operands to the intrinsic follow.
157 // CopyToReg - This node has three operands: a chain, a register number to
158 // set to this value, and a value.
161 // CopyFromReg - This node indicates that the input value is a virtual or
162 // physical register that is defined outside of the scope of this
163 // SelectionDAG. The register is available from the RegSDNode object.
166 // UNDEF - An undefined node
169 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
170 /// represents the formal arguments for a function. CC# is a Constant value
171 /// indicating the calling convention of the function, and ISVARARG is a
172 /// flag that indicates whether the function is varargs or not. This node
173 /// has one result value for each incoming argument, plus one for the output
174 /// chain. It must be custom legalized. See description of CALL node for
175 /// FLAG argument contents explanation.
179 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
180 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
181 /// This node represents a fully general function call, before the legalizer
182 /// runs. This has one result value for each argument / flag pair, plus
183 /// a chain result. It must be custom legalized. Flag argument indicates
184 /// misc. argument attributes. Currently:
186 /// Bit 1 - 'inreg' attribute
187 /// Bit 2 - 'sret' attribute
188 /// Bits 31:27 - argument ABI alignment in the first argument piece and
189 /// alignment '1' in other argument pieces.
192 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
193 // a Constant, which is required to be operand #1), element of the aggregate
194 // value specified as operand #0. This is only for use before legalization,
195 // for values that will be broken into multiple registers.
198 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
199 // two values of the same integer value type, this produces a value twice as
200 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
203 // MERGE_VALUES - This node takes multiple discrete operands and returns
204 // them all as its individual results. This nodes has exactly the same
205 // number of inputs and outputs, and is only valid before legalization.
206 // This node is useful for some pieces of the code generator that want to
207 // think about a single node with multiple results, not multiple nodes.
210 // Simple integer binary arithmetic operators.
211 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
213 // CARRY_FALSE - This node is used when folding other nodes,
214 // like ADDC/SUBC, which indicate the carry result is always false.
217 // Carry-setting nodes for multiple precision addition and subtraction.
218 // These nodes take two operands of the same value type, and produce two
219 // results. The first result is the normal add or sub result, the second
220 // result is the carry flag result.
223 // Carry-using nodes for multiple precision addition and subtraction. These
224 // nodes take three operands: The first two are the normal lhs and rhs to
225 // the add or sub, and the third is the input carry flag. These nodes
226 // produce two results; the normal result of the add or sub, and the output
227 // carry flag. These nodes both read and write a carry flag to allow them
228 // to them to be chained together for add and sub of arbitrarily large
232 // Simple binary floating point operators.
233 FADD, FSUB, FMUL, FDIV, FREM,
235 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
236 // DAG node does not require that X and Y have the same type, just that they
237 // are both floating point. X and the result must have the same type.
238 // FCOPYSIGN(f32, f64) is allowed.
241 /// VBUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,..., COUNT,TYPE) - Return a vector
242 /// with the specified, possibly variable, elements. The number of elements
243 /// is required to be a power of two.
246 /// BUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,...) - Return a vector
247 /// with the specified, possibly variable, elements. The number of elements
248 /// is required to be a power of two.
251 /// VINSERT_VECTOR_ELT(VECTOR, VAL, IDX, COUNT,TYPE) - Given a vector
252 /// VECTOR, an element ELEMENT, and a (potentially variable) index IDX,
253 /// return an vector with the specified element of VECTOR replaced with VAL.
254 /// COUNT and TYPE specify the type of vector, as is standard for V* nodes.
257 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR (a legal packed
258 /// type) with the element at IDX replaced with VAL.
261 /// VEXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
262 /// (an MVT::Vector value) identified by the (potentially variable) element
266 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
267 /// (a legal vector type vector) identified by the (potentially variable)
268 /// element number IDX.
271 /// VVECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC, COUNT,TYPE) - Returns a vector,
272 /// of the same type as VEC1/VEC2. SHUFFLEVEC is a VBUILD_VECTOR of
273 /// constant int values that indicate which value each result element will
274 /// get. The elements of VEC1/VEC2 are enumerated in order. This is quite
275 /// similar to the Altivec 'vperm' instruction, except that the indices must
276 /// be constants and are in terms of the element size of VEC1/VEC2, not in
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 /// X = VBIT_CONVERT(Y) and X = VBIT_CONVERT(Y, COUNT,TYPE) - This node
290 /// represents a conversion from or to an ISD::Vector type.
292 /// This is lowered to a BIT_CONVERT of the appropriate input/output types.
293 /// The input and output are required to have the same size and at least one
294 /// is required to be a vector (if neither is a vector, just use
297 /// If the result is a vector, this takes three operands (like any other
298 /// vector producer) which indicate the size and type of the vector result.
299 /// Otherwise it takes one input.
302 /// BINOP(LHS, RHS, COUNT,TYPE)
303 /// Simple abstract vector operators. Unlike the integer and floating point
304 /// binary operators, these nodes also take two additional operands:
305 /// a constant element count, and a value type node indicating the type of
306 /// the elements. The order is count, type, op0, op1. All vector opcodes,
307 /// including VLOAD and VConstant must currently have count and type as
308 /// their last two operands.
309 VADD, VSUB, VMUL, VSDIV, VUDIV,
312 /// VSELECT(COND,LHS,RHS, COUNT,TYPE) - Select for MVT::Vector values.
313 /// COND is a boolean value. This node return LHS if COND is true, RHS if
317 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
318 /// scalar value into the low element of the resultant vector type. The top
319 /// elements of the vector are undefined.
322 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
323 // an unsigned/signed value of type i[2*n], then return the top part.
326 // Bitwise operators - logical and, logical or, logical xor, shift left,
327 // shift right algebraic (shift in sign bits), shift right logical (shift in
328 // zeroes), rotate left, rotate right, and byteswap.
329 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
331 // Counting operators
334 // Select(COND, TRUEVAL, FALSEVAL)
337 // Select with condition operator - This selects between a true value and
338 // a false value (ops #2 and #3) based on the boolean result of comparing
339 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
340 // condition code in op #4, a CondCodeSDNode.
343 // SetCC operator - This evaluates to a boolean (i1) true value if the
344 // condition is true. The operands to this are the left and right operands
345 // to compare (ops #0, and #1) and the condition code to compare them with
346 // (op #2) as a CondCodeSDNode.
349 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
350 // integer shift operations, just like ADD/SUB_PARTS. The operation
352 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
353 SHL_PARTS, SRA_PARTS, SRL_PARTS,
355 // Conversion operators. These are all single input single output
356 // operations. For all of these, the result type must be strictly
357 // wider or narrower (depending on the operation) than the source
360 // SIGN_EXTEND - Used for integer types, replicating the sign bit
364 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
367 // ANY_EXTEND - Used for integer types. The high bits are undefined.
370 // TRUNCATE - Completely drop the high bits.
373 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
374 // depends on the first letter) to floating point.
378 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
379 // sign extend a small value in a large integer register (e.g. sign
380 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
381 // with the 7th bit). The size of the smaller type is indicated by the 1th
382 // operand, a ValueType node.
385 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
390 // FP_ROUND - Perform a rounding operation from the current
391 // precision down to the specified precision (currently always 64->32).
394 // FP_ROUND_INREG - This operator takes a floating point register, and
395 // rounds it to a floating point value. It then promotes it and returns it
396 // in a register of the same size. This operation effectively just discards
397 // excess precision. The type to round down to is specified by the 1th
398 // operation, a VTSDNode (currently always 64->32->64).
401 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
404 // BIT_CONVERT - Theis operator converts between integer and FP values, as
405 // if one was stored to memory as integer and the other was loaded from the
406 // same address (or equivalently for vector format conversions, etc). The
407 // source and result are required to have the same bit size (e.g.
408 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
409 // conversions, but that is a noop, deleted by getNode().
412 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI - Perform unary floating point
413 // negation, absolute value, square root, sine and cosine, and powi
415 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI,
417 // LOAD and STORE have token chains as their first operand, then the same
418 // operands as an LLVM load/store instruction, then an offset node that
419 // is added / subtracted from the base pointer to form the address (for
420 // indexed memory ops).
423 // Abstract vector version of LOAD. VLOAD has a constant element count as
424 // the first operand, followed by a value type node indicating the type of
425 // the elements, a token chain, a pointer operand, and a SRCVALUE node.
428 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
429 // value and stores it to memory in one operation. This can be used for
430 // either integer or floating point operands. The first four operands of
431 // this are the same as a standard store. The fifth is the ValueType to
432 // store it as (which will be smaller than the source value).
435 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
436 // to a specified boundary. This node always has two return values: a new
437 // stack pointer value and a chain. The first operand is the token chain,
438 // the second is the number of bytes to allocate, and the third is the
439 // alignment boundary. The size is guaranteed to be a multiple of the stack
440 // alignment, and the alignment is guaranteed to be bigger than the stack
441 // alignment (if required) or 0 to get standard stack alignment.
444 // Control flow instructions. These all have token chains.
446 // BR - Unconditional branch. The first operand is the chain
447 // operand, the second is the MBB to branch to.
450 // BRIND - Indirect branch. The first operand is the chain, the second
451 // is the value to branch to, which must be of the same type as the target's
455 // BR_JT - Jumptable branch. The first operand is the chain, the second
456 // is the jumptable index, the last one is the jumptable entry index.
459 // BRCOND - Conditional branch. The first operand is the chain,
460 // the second is the condition, the third is the block to branch
461 // to if the condition is true.
464 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
465 // that the condition is represented as condition code, and two nodes to
466 // compare, rather than as a combined SetCC node. The operands in order are
467 // chain, cc, lhs, rhs, block to branch to if condition is true.
470 // RET - Return from function. The first operand is the chain,
471 // and any subsequent operands are pairs of return value and return value
472 // signness for the function. This operation can have variable number of
476 // INLINEASM - Represents an inline asm block. This node always has two
477 // return values: a chain and a flag result. The inputs are as follows:
478 // Operand #0 : Input chain.
479 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
480 // Operand #2n+2: A RegisterNode.
481 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
482 // Operand #last: Optional, an incoming flag.
485 // LABEL - Represents a label in mid basic block used to track
486 // locations needed for debug and exception handling tables. This node
488 // Operand #0 : input chain.
489 // Operand #1 : module unique number use to identify the label.
492 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
493 // value, the same type as the pointer type for the system, and an output
497 // STACKRESTORE has two operands, an input chain and a pointer to restore to
498 // it returns an output chain.
501 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
502 // correspond to the operands of the LLVM intrinsic functions. The only
503 // result is a token chain. The alignment argument is guaranteed to be a
509 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
510 // a call sequence, and carry arbitrary information that target might want
511 // to know. The first operand is a chain, the rest are specified by the
512 // target and not touched by the DAG optimizers.
513 CALLSEQ_START, // Beginning of a call sequence
514 CALLSEQ_END, // End of a call sequence
516 // VAARG - VAARG has three operands: an input chain, a pointer, and a
517 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
520 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
521 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
525 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
526 // pointer, and a SRCVALUE.
529 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
530 // locations with their value. This allows one use alias analysis
531 // information in the backend.
534 // PCMARKER - This corresponds to the pcmarker intrinsic.
537 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
538 // The only operand is a chain and a value and a chain are produced. The
539 // value is the contents of the architecture specific cycle counter like
540 // register (or other high accuracy low latency clock source)
543 // HANDLENODE node - Used as a handle for various purposes.
546 // LOCATION - This node is used to represent a source location for debug
547 // info. It takes token chain as input, then a line number, then a column
548 // number, then a filename, then a working dir. It produces a token chain
552 // DEBUG_LOC - This node is used to represent source line information
553 // embedded in the code. It takes a token chain as input, then a line
554 // number, then a column then a file id (provided by MachineModuleInfo.) It
555 // produces a token chain as output.
558 // BUILTIN_OP_END - This must be the last enum value in this list.
564 /// isBuildVectorAllOnes - Return true if the specified node is a
565 /// BUILD_VECTOR where all of the elements are ~0 or undef.
566 bool isBuildVectorAllOnes(const SDNode *N);
568 /// isBuildVectorAllZeros - Return true if the specified node is a
569 /// BUILD_VECTOR where all of the elements are 0 or undef.
570 bool isBuildVectorAllZeros(const SDNode *N);
572 //===--------------------------------------------------------------------===//
573 /// MemIndexedMode enum - This enum defines the load / store indexed
574 /// addressing modes.
576 /// UNINDEXED "Normal" load / store. The effective address is already
577 /// computed and is available in the base pointer. The offset
578 /// operand is always undefined. In addition to producing a
579 /// chain, an unindexed load produces one value (result of the
580 /// load); an unindexed store does not produces a value.
582 /// PRE_INC Similar to the unindexed mode where the effective address is
583 /// PRE_DEC the value of the base pointer add / subtract the offset.
584 /// It considers the computation as being folded into the load /
585 /// store operation (i.e. the load / store does the address
586 /// computation as well as performing the memory transaction).
587 /// The base operand is always undefined. In addition to
588 /// producing a chain, pre-indexed load produces two values
589 /// (result of the load and the result of the address
590 /// computation); a pre-indexed store produces one value (result
591 /// of the address computation).
593 /// POST_INC The effective address is the value of the base pointer. The
594 /// POST_DEC value of the offset operand is then added to / subtracted
595 /// from the base after memory transaction. In addition to
596 /// producing a chain, post-indexed load produces two values
597 /// (the result of the load and the result of the base +/- offset
598 /// computation); a post-indexed store produces one value (the
599 /// the result of the base +/- offset computation).
601 enum MemIndexedMode {
610 //===--------------------------------------------------------------------===//
611 /// LoadExtType enum - This enum defines the three variants of LOADEXT
612 /// (load with extension).
614 /// SEXTLOAD loads the integer operand and sign extends it to a larger
615 /// integer result type.
616 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
617 /// integer result type.
618 /// EXTLOAD is used for three things: floating point extending loads,
619 /// integer extending loads [the top bits are undefined], and vector
620 /// extending loads [load into low elt].
630 //===--------------------------------------------------------------------===//
631 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
632 /// below work out, when considering SETFALSE (something that never exists
633 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
634 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
635 /// to. If the "N" column is 1, the result of the comparison is undefined if
636 /// the input is a NAN.
638 /// All of these (except for the 'always folded ops') should be handled for
639 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
640 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
642 /// Note that these are laid out in a specific order to allow bit-twiddling
643 /// to transform conditions.
645 // Opcode N U L G E Intuitive operation
646 SETFALSE, // 0 0 0 0 Always false (always folded)
647 SETOEQ, // 0 0 0 1 True if ordered and equal
648 SETOGT, // 0 0 1 0 True if ordered and greater than
649 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
650 SETOLT, // 0 1 0 0 True if ordered and less than
651 SETOLE, // 0 1 0 1 True if ordered and less than or equal
652 SETONE, // 0 1 1 0 True if ordered and operands are unequal
653 SETO, // 0 1 1 1 True if ordered (no nans)
654 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
655 SETUEQ, // 1 0 0 1 True if unordered or equal
656 SETUGT, // 1 0 1 0 True if unordered or greater than
657 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
658 SETULT, // 1 1 0 0 True if unordered or less than
659 SETULE, // 1 1 0 1 True if unordered, less than, or equal
660 SETUNE, // 1 1 1 0 True if unordered or not equal
661 SETTRUE, // 1 1 1 1 Always true (always folded)
662 // Don't care operations: undefined if the input is a nan.
663 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
664 SETEQ, // 1 X 0 0 1 True if equal
665 SETGT, // 1 X 0 1 0 True if greater than
666 SETGE, // 1 X 0 1 1 True if greater than or equal
667 SETLT, // 1 X 1 0 0 True if less than
668 SETLE, // 1 X 1 0 1 True if less than or equal
669 SETNE, // 1 X 1 1 0 True if not equal
670 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
672 SETCC_INVALID // Marker value.
675 /// isSignedIntSetCC - Return true if this is a setcc instruction that
676 /// performs a signed comparison when used with integer operands.
677 inline bool isSignedIntSetCC(CondCode Code) {
678 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
681 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
682 /// performs an unsigned comparison when used with integer operands.
683 inline bool isUnsignedIntSetCC(CondCode Code) {
684 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
687 /// isTrueWhenEqual - Return true if the specified condition returns true if
688 /// the two operands to the condition are equal. Note that if one of the two
689 /// operands is a NaN, this value is meaningless.
690 inline bool isTrueWhenEqual(CondCode Cond) {
691 return ((int)Cond & 1) != 0;
694 /// getUnorderedFlavor - This function returns 0 if the condition is always
695 /// false if an operand is a NaN, 1 if the condition is always true if the
696 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
698 inline unsigned getUnorderedFlavor(CondCode Cond) {
699 return ((int)Cond >> 3) & 3;
702 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
703 /// 'op' is a valid SetCC operation.
704 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
706 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
707 /// when given the operation for (X op Y).
708 CondCode getSetCCSwappedOperands(CondCode Operation);
710 /// getSetCCOrOperation - Return the result of a logical OR between different
711 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
712 /// function returns SETCC_INVALID if it is not possible to represent the
713 /// resultant comparison.
714 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
716 /// getSetCCAndOperation - Return the result of a logical AND between
717 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
718 /// function returns SETCC_INVALID if it is not possible to represent the
719 /// resultant comparison.
720 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
721 } // end llvm::ISD namespace
724 //===----------------------------------------------------------------------===//
725 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
726 /// values as the result of a computation. Many nodes return multiple values,
727 /// from loads (which define a token and a return value) to ADDC (which returns
728 /// a result and a carry value), to calls (which may return an arbitrary number
731 /// As such, each use of a SelectionDAG computation must indicate the node that
732 /// computes it as well as which return value to use from that node. This pair
733 /// of information is represented with the SDOperand value type.
737 SDNode *Val; // The node defining the value we are using.
738 unsigned ResNo; // Which return value of the node we are using.
740 SDOperand() : Val(0), ResNo(0) {}
741 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
743 bool operator==(const SDOperand &O) const {
744 return Val == O.Val && ResNo == O.ResNo;
746 bool operator!=(const SDOperand &O) const {
747 return !operator==(O);
749 bool operator<(const SDOperand &O) const {
750 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
753 SDOperand getValue(unsigned R) const {
754 return SDOperand(Val, R);
757 // isOperand - Return true if this node is an operand of N.
758 bool isOperand(SDNode *N) const;
760 /// getValueType - Return the ValueType of the referenced return value.
762 inline MVT::ValueType getValueType() const;
764 // Forwarding methods - These forward to the corresponding methods in SDNode.
765 inline unsigned getOpcode() const;
766 inline unsigned getNumOperands() const;
767 inline const SDOperand &getOperand(unsigned i) const;
768 inline uint64_t getConstantOperandVal(unsigned i) const;
769 inline bool isTargetOpcode() const;
770 inline unsigned getTargetOpcode() const;
772 /// hasOneUse - Return true if there is exactly one operation using this
773 /// result value of the defining operator.
774 inline bool hasOneUse() const;
778 /// simplify_type specializations - Allow casting operators to work directly on
779 /// SDOperands as if they were SDNode*'s.
780 template<> struct simplify_type<SDOperand> {
781 typedef SDNode* SimpleType;
782 static SimpleType getSimplifiedValue(const SDOperand &Val) {
783 return static_cast<SimpleType>(Val.Val);
786 template<> struct simplify_type<const SDOperand> {
787 typedef SDNode* SimpleType;
788 static SimpleType getSimplifiedValue(const SDOperand &Val) {
789 return static_cast<SimpleType>(Val.Val);
794 /// SDNode - Represents one node in the SelectionDAG.
796 class SDNode : public FoldingSetNode {
797 /// NodeType - The operation that this node performs.
799 unsigned short NodeType;
801 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
802 /// then they will be delete[]'d when the node is destroyed.
803 bool OperandsNeedDelete : 1;
805 /// NodeId - Unique id per SDNode in the DAG.
808 /// OperandList - The values that are used by this operation.
810 SDOperand *OperandList;
812 /// ValueList - The types of the values this node defines. SDNode's may
813 /// define multiple values simultaneously.
814 const MVT::ValueType *ValueList;
816 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
817 unsigned short NumOperands, NumValues;
819 /// Prev/Next pointers - These pointers form the linked list of of the
820 /// AllNodes list in the current DAG.
822 friend struct ilist_traits<SDNode>;
824 /// Uses - These are all of the SDNode's that use a value produced by this
826 SmallVector<SDNode*,3> Uses;
828 // Out-of-line virtual method to give class a home.
829 virtual void ANCHOR();
832 assert(NumOperands == 0 && "Operand list not cleared before deletion");
833 NodeType = ISD::DELETED_NODE;
836 //===--------------------------------------------------------------------===//
839 unsigned getOpcode() const { return NodeType; }
840 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
841 unsigned getTargetOpcode() const {
842 assert(isTargetOpcode() && "Not a target opcode!");
843 return NodeType - ISD::BUILTIN_OP_END;
846 size_t use_size() const { return Uses.size(); }
847 bool use_empty() const { return Uses.empty(); }
848 bool hasOneUse() const { return Uses.size() == 1; }
850 /// getNodeId - Return the unique node id.
852 int getNodeId() const { return NodeId; }
854 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
855 use_iterator use_begin() const { return Uses.begin(); }
856 use_iterator use_end() const { return Uses.end(); }
858 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
859 /// indicated value. This method ignores uses of other values defined by this
861 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
863 /// isOnlyUse - Return true if this node is the only use of N.
865 bool isOnlyUse(SDNode *N) const;
867 /// isOperand - Return true if this node is an operand of N.
869 bool isOperand(SDNode *N) const;
871 /// isPredecessor - Return true if this node is a predecessor of N. This node
872 /// is either an operand of N or it can be reached by recursively traversing
874 /// NOTE: this is an expensive method. Use it carefully.
875 bool isPredecessor(SDNode *N) const;
877 /// getNumOperands - Return the number of values used by this operation.
879 unsigned getNumOperands() const { return NumOperands; }
881 /// getConstantOperandVal - Helper method returns the integer value of a
882 /// ConstantSDNode operand.
883 uint64_t getConstantOperandVal(unsigned Num) const;
885 const SDOperand &getOperand(unsigned Num) const {
886 assert(Num < NumOperands && "Invalid child # of SDNode!");
887 return OperandList[Num];
890 typedef const SDOperand* op_iterator;
891 op_iterator op_begin() const { return OperandList; }
892 op_iterator op_end() const { return OperandList+NumOperands; }
895 SDVTList getVTList() const {
896 SDVTList X = { ValueList, NumValues };
900 /// getNumValues - Return the number of values defined/returned by this
903 unsigned getNumValues() const { return NumValues; }
905 /// getValueType - Return the type of a specified result.
907 MVT::ValueType getValueType(unsigned ResNo) const {
908 assert(ResNo < NumValues && "Illegal result number!");
909 return ValueList[ResNo];
912 typedef const MVT::ValueType* value_iterator;
913 value_iterator value_begin() const { return ValueList; }
914 value_iterator value_end() const { return ValueList+NumValues; }
916 /// getOperationName - Return the opcode of this operation for printing.
918 std::string getOperationName(const SelectionDAG *G = 0) const;
919 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
921 void dump(const SelectionDAG *G) const;
923 static bool classof(const SDNode *) { return true; }
925 /// Profile - Gather unique data for the node.
927 void Profile(FoldingSetNodeID &ID);
930 friend class SelectionDAG;
932 /// getValueTypeList - Return a pointer to the specified value type.
934 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
935 static SDVTList getSDVTList(MVT::ValueType VT) {
936 SDVTList Ret = { getValueTypeList(VT), 1 };
940 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
941 : NodeType(Opc), NodeId(-1) {
942 OperandsNeedDelete = true;
943 NumOperands = NumOps;
944 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
946 for (unsigned i = 0; i != NumOps; ++i) {
947 OperandList[i] = Ops[i];
948 Ops[i].Val->Uses.push_back(this);
952 NumValues = VTs.NumVTs;
955 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
956 OperandsNeedDelete = false; // Operands set with InitOperands.
961 NumValues = VTs.NumVTs;
965 /// InitOperands - Initialize the operands list of this node with the
966 /// specified values, which are part of the node (thus they don't need to be
967 /// copied in or allocated).
968 void InitOperands(SDOperand *Ops, unsigned NumOps) {
969 assert(OperandList == 0 && "Operands already set!");
970 NumOperands = NumOps;
973 for (unsigned i = 0; i != NumOps; ++i)
974 Ops[i].Val->Uses.push_back(this);
977 /// MorphNodeTo - This frees the operands of the current node, resets the
978 /// opcode, types, and operands to the specified value. This should only be
979 /// used by the SelectionDAG class.
980 void MorphNodeTo(unsigned Opc, SDVTList L,
981 const SDOperand *Ops, unsigned NumOps);
983 void addUser(SDNode *User) {
984 Uses.push_back(User);
986 void removeUser(SDNode *User) {
987 // Remove this user from the operand's use list.
988 for (unsigned i = Uses.size(); ; --i) {
989 assert(i != 0 && "Didn't find user!");
990 if (Uses[i-1] == User) {
991 Uses[i-1] = Uses.back();
998 void setNodeId(int Id) {
1004 // Define inline functions from the SDOperand class.
1006 inline unsigned SDOperand::getOpcode() const {
1007 return Val->getOpcode();
1009 inline MVT::ValueType SDOperand::getValueType() const {
1010 return Val->getValueType(ResNo);
1012 inline unsigned SDOperand::getNumOperands() const {
1013 return Val->getNumOperands();
1015 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1016 return Val->getOperand(i);
1018 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1019 return Val->getConstantOperandVal(i);
1021 inline bool SDOperand::isTargetOpcode() const {
1022 return Val->isTargetOpcode();
1024 inline unsigned SDOperand::getTargetOpcode() const {
1025 return Val->getTargetOpcode();
1027 inline bool SDOperand::hasOneUse() const {
1028 return Val->hasNUsesOfValue(1, ResNo);
1031 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1032 /// to allow co-allocation of node operands with the node itself.
1033 class UnarySDNode : public SDNode {
1034 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1037 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1038 : SDNode(Opc, VTs), Op(X) {
1039 InitOperands(&Op, 1);
1043 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1044 /// to allow co-allocation of node operands with the node itself.
1045 class BinarySDNode : public SDNode {
1046 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1049 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1050 : SDNode(Opc, VTs) {
1053 InitOperands(Ops, 2);
1057 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1058 /// to allow co-allocation of node operands with the node itself.
1059 class TernarySDNode : public SDNode {
1060 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1063 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1065 : SDNode(Opc, VTs) {
1069 InitOperands(Ops, 3);
1074 /// HandleSDNode - This class is used to form a handle around another node that
1075 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1076 /// operand. This node should be directly created by end-users and not added to
1077 /// the AllNodes list.
1078 class HandleSDNode : public SDNode {
1079 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1082 explicit HandleSDNode(SDOperand X)
1083 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1084 InitOperands(&Op, 1);
1087 SDOperand getValue() const { return Op; }
1090 class StringSDNode : public SDNode {
1092 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1094 friend class SelectionDAG;
1095 explicit StringSDNode(const std::string &val)
1096 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1099 const std::string &getValue() const { return Value; }
1100 static bool classof(const StringSDNode *) { return true; }
1101 static bool classof(const SDNode *N) {
1102 return N->getOpcode() == ISD::STRING;
1106 class ConstantSDNode : public SDNode {
1108 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1110 friend class SelectionDAG;
1111 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1112 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1117 uint64_t getValue() const { return Value; }
1119 int64_t getSignExtended() const {
1120 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1121 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1124 bool isNullValue() const { return Value == 0; }
1125 bool isAllOnesValue() const {
1126 return Value == MVT::getIntVTBitMask(getValueType(0));
1129 static bool classof(const ConstantSDNode *) { return true; }
1130 static bool classof(const SDNode *N) {
1131 return N->getOpcode() == ISD::Constant ||
1132 N->getOpcode() == ISD::TargetConstant;
1136 class ConstantFPSDNode : public SDNode {
1138 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1140 friend class SelectionDAG;
1141 ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1142 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1143 getSDVTList(VT)), Value(val) {
1147 double getValue() const { return Value; }
1149 /// isExactlyValue - We don't rely on operator== working on double values, as
1150 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1151 /// As such, this method can be used to do an exact bit-for-bit comparison of
1152 /// two floating point values.
1153 bool isExactlyValue(double V) const;
1155 static bool classof(const ConstantFPSDNode *) { return true; }
1156 static bool classof(const SDNode *N) {
1157 return N->getOpcode() == ISD::ConstantFP ||
1158 N->getOpcode() == ISD::TargetConstantFP;
1162 class GlobalAddressSDNode : public SDNode {
1163 GlobalValue *TheGlobal;
1165 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1167 friend class SelectionDAG;
1168 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1170 : SDNode(dyn_cast<GlobalVariable>(GA) &&
1171 dyn_cast<GlobalVariable>(GA)->isThreadLocal() ?
1173 (isTarget ? ISD::TargetGlobalTLSAddress : ISD::GlobalTLSAddress) :
1175 (isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress),
1176 getSDVTList(VT)), Offset(o) {
1177 TheGlobal = const_cast<GlobalValue*>(GA);
1181 GlobalValue *getGlobal() const { return TheGlobal; }
1182 int getOffset() const { return Offset; }
1184 static bool classof(const GlobalAddressSDNode *) { return true; }
1185 static bool classof(const SDNode *N) {
1186 return N->getOpcode() == ISD::GlobalAddress ||
1187 N->getOpcode() == ISD::TargetGlobalAddress ||
1188 N->getOpcode() == ISD::GlobalTLSAddress ||
1189 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1193 class FrameIndexSDNode : public SDNode {
1195 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1197 friend class SelectionDAG;
1198 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1199 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1204 int getIndex() const { return FI; }
1206 static bool classof(const FrameIndexSDNode *) { return true; }
1207 static bool classof(const SDNode *N) {
1208 return N->getOpcode() == ISD::FrameIndex ||
1209 N->getOpcode() == ISD::TargetFrameIndex;
1213 class JumpTableSDNode : public SDNode {
1215 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1217 friend class SelectionDAG;
1218 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1219 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1224 int getIndex() const { return JTI; }
1226 static bool classof(const JumpTableSDNode *) { return true; }
1227 static bool classof(const SDNode *N) {
1228 return N->getOpcode() == ISD::JumpTable ||
1229 N->getOpcode() == ISD::TargetJumpTable;
1233 class ConstantPoolSDNode : public SDNode {
1236 MachineConstantPoolValue *MachineCPVal;
1238 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1240 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1242 friend class SelectionDAG;
1243 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1245 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1246 getSDVTList(VT)), Offset(o), Alignment(0) {
1247 assert((int)Offset >= 0 && "Offset is too large");
1250 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1252 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1253 getSDVTList(VT)), Offset(o), Alignment(Align) {
1254 assert((int)Offset >= 0 && "Offset is too large");
1257 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1258 MVT::ValueType VT, int o=0)
1259 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1260 getSDVTList(VT)), Offset(o), Alignment(0) {
1261 assert((int)Offset >= 0 && "Offset is too large");
1262 Val.MachineCPVal = v;
1263 Offset |= 1 << (sizeof(unsigned)*8-1);
1265 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1266 MVT::ValueType VT, int o, unsigned Align)
1267 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1268 getSDVTList(VT)), Offset(o), Alignment(Align) {
1269 assert((int)Offset >= 0 && "Offset is too large");
1270 Val.MachineCPVal = v;
1271 Offset |= 1 << (sizeof(unsigned)*8-1);
1275 bool isMachineConstantPoolEntry() const {
1276 return (int)Offset < 0;
1279 Constant *getConstVal() const {
1280 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1281 return Val.ConstVal;
1284 MachineConstantPoolValue *getMachineCPVal() const {
1285 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1286 return Val.MachineCPVal;
1289 int getOffset() const {
1290 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1293 // Return the alignment of this constant pool object, which is either 0 (for
1294 // default alignment) or log2 of the desired value.
1295 unsigned getAlignment() const { return Alignment; }
1297 const Type *getType() const;
1299 static bool classof(const ConstantPoolSDNode *) { return true; }
1300 static bool classof(const SDNode *N) {
1301 return N->getOpcode() == ISD::ConstantPool ||
1302 N->getOpcode() == ISD::TargetConstantPool;
1306 class BasicBlockSDNode : public SDNode {
1307 MachineBasicBlock *MBB;
1308 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1310 friend class SelectionDAG;
1311 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1312 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1316 MachineBasicBlock *getBasicBlock() const { return MBB; }
1318 static bool classof(const BasicBlockSDNode *) { return true; }
1319 static bool classof(const SDNode *N) {
1320 return N->getOpcode() == ISD::BasicBlock;
1324 class SrcValueSDNode : public SDNode {
1327 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1329 friend class SelectionDAG;
1330 SrcValueSDNode(const Value* v, int o)
1331 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v), offset(o) {
1335 const Value *getValue() const { return V; }
1336 int getOffset() const { return offset; }
1338 static bool classof(const SrcValueSDNode *) { return true; }
1339 static bool classof(const SDNode *N) {
1340 return N->getOpcode() == ISD::SRCVALUE;
1345 class RegisterSDNode : public SDNode {
1347 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1349 friend class SelectionDAG;
1350 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1351 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1355 unsigned getReg() const { return Reg; }
1357 static bool classof(const RegisterSDNode *) { return true; }
1358 static bool classof(const SDNode *N) {
1359 return N->getOpcode() == ISD::Register;
1363 class ExternalSymbolSDNode : public SDNode {
1365 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1367 friend class SelectionDAG;
1368 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1369 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1370 getSDVTList(VT)), Symbol(Sym) {
1374 const char *getSymbol() const { return Symbol; }
1376 static bool classof(const ExternalSymbolSDNode *) { return true; }
1377 static bool classof(const SDNode *N) {
1378 return N->getOpcode() == ISD::ExternalSymbol ||
1379 N->getOpcode() == ISD::TargetExternalSymbol;
1383 class CondCodeSDNode : public SDNode {
1384 ISD::CondCode Condition;
1385 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1387 friend class SelectionDAG;
1388 explicit CondCodeSDNode(ISD::CondCode Cond)
1389 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1393 ISD::CondCode get() const { return Condition; }
1395 static bool classof(const CondCodeSDNode *) { return true; }
1396 static bool classof(const SDNode *N) {
1397 return N->getOpcode() == ISD::CONDCODE;
1401 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1402 /// to parameterize some operations.
1403 class VTSDNode : public SDNode {
1404 MVT::ValueType ValueType;
1405 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1407 friend class SelectionDAG;
1408 explicit VTSDNode(MVT::ValueType VT)
1409 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1413 MVT::ValueType getVT() const { return ValueType; }
1415 static bool classof(const VTSDNode *) { return true; }
1416 static bool classof(const SDNode *N) {
1417 return N->getOpcode() == ISD::VALUETYPE;
1421 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1423 class LoadSDNode : public SDNode {
1424 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1427 // AddrMode - unindexed, pre-indexed, post-indexed.
1428 ISD::MemIndexedMode AddrMode;
1430 // ExtType - non-ext, anyext, sext, zext.
1431 ISD::LoadExtType ExtType;
1433 // LoadedVT - VT of loaded value before extension.
1434 MVT::ValueType LoadedVT;
1436 // SrcValue - Memory location for alias analysis.
1437 const Value *SrcValue;
1439 // SVOffset - Memory location offset.
1442 // Alignment - Alignment of memory location in bytes.
1445 // IsVolatile - True if the load is volatile.
1448 friend class SelectionDAG;
1449 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1450 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1451 const Value *SV, int O=0, unsigned Align=1, bool Vol=false)
1452 : SDNode(ISD::LOAD, VTs),
1453 AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
1454 Alignment(Align), IsVolatile(Vol) {
1455 Ops[0] = ChainPtrOff[0]; // Chain
1456 Ops[1] = ChainPtrOff[1]; // Ptr
1457 Ops[2] = ChainPtrOff[2]; // Off
1458 InitOperands(Ops, 3);
1459 assert((getOffset().getOpcode() == ISD::UNDEF ||
1460 AddrMode != ISD::UNINDEXED) &&
1461 "Only indexed load has a non-undef offset operand");
1465 const SDOperand getChain() const { return getOperand(0); }
1466 const SDOperand getBasePtr() const { return getOperand(1); }
1467 const SDOperand getOffset() const { return getOperand(2); }
1468 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1469 ISD::LoadExtType getExtensionType() const { return ExtType; }
1470 MVT::ValueType getLoadedVT() const { return LoadedVT; }
1471 const Value *getSrcValue() const { return SrcValue; }
1472 int getSrcValueOffset() const { return SVOffset; }
1473 unsigned getAlignment() const { return Alignment; }
1474 bool isVolatile() const { return IsVolatile; }
1476 static bool classof(const LoadSDNode *) { return true; }
1477 static bool classof(const SDNode *N) {
1478 return N->getOpcode() == ISD::LOAD;
1482 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1484 class StoreSDNode : public SDNode {
1485 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1488 // AddrMode - unindexed, pre-indexed, post-indexed.
1489 ISD::MemIndexedMode AddrMode;
1491 // IsTruncStore - True is the op does a truncation before store.
1494 // StoredVT - VT of the value after truncation.
1495 MVT::ValueType StoredVT;
1497 // SrcValue - Memory location for alias analysis.
1498 const Value *SrcValue;
1500 // SVOffset - Memory location offset.
1503 // Alignment - Alignment of memory location in bytes.
1506 // IsVolatile - True if the store is volatile.
1509 friend class SelectionDAG;
1510 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1511 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1512 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1513 : SDNode(ISD::STORE, VTs),
1514 AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT), SrcValue(SV),
1515 SVOffset(O), Alignment(Align), IsVolatile(Vol) {
1516 Ops[0] = ChainValuePtrOff[0]; // Chain
1517 Ops[1] = ChainValuePtrOff[1]; // Value
1518 Ops[2] = ChainValuePtrOff[2]; // Ptr
1519 Ops[3] = ChainValuePtrOff[3]; // Off
1520 InitOperands(Ops, 4);
1521 assert((getOffset().getOpcode() == ISD::UNDEF ||
1522 AddrMode != ISD::UNINDEXED) &&
1523 "Only indexed store has a non-undef offset operand");
1527 const SDOperand getChain() const { return getOperand(0); }
1528 const SDOperand getValue() const { return getOperand(1); }
1529 const SDOperand getBasePtr() const { return getOperand(2); }
1530 const SDOperand getOffset() const { return getOperand(3); }
1531 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1532 bool isTruncatingStore() const { return IsTruncStore; }
1533 MVT::ValueType getStoredVT() const { return StoredVT; }
1534 const Value *getSrcValue() const { return SrcValue; }
1535 int getSrcValueOffset() const { return SVOffset; }
1536 unsigned getAlignment() const { return Alignment; }
1537 bool isVolatile() const { return IsVolatile; }
1539 static bool classof(const StoreSDNode *) { return true; }
1540 static bool classof(const SDNode *N) {
1541 return N->getOpcode() == ISD::STORE;
1546 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1550 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1552 bool operator==(const SDNodeIterator& x) const {
1553 return Operand == x.Operand;
1555 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1557 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1558 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1559 Operand = I.Operand;
1563 pointer operator*() const {
1564 return Node->getOperand(Operand).Val;
1566 pointer operator->() const { return operator*(); }
1568 SDNodeIterator& operator++() { // Preincrement
1572 SDNodeIterator operator++(int) { // Postincrement
1573 SDNodeIterator tmp = *this; ++*this; return tmp;
1576 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1577 static SDNodeIterator end (SDNode *N) {
1578 return SDNodeIterator(N, N->getNumOperands());
1581 unsigned getOperand() const { return Operand; }
1582 const SDNode *getNode() const { return Node; }
1585 template <> struct GraphTraits<SDNode*> {
1586 typedef SDNode NodeType;
1587 typedef SDNodeIterator ChildIteratorType;
1588 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1589 static inline ChildIteratorType child_begin(NodeType *N) {
1590 return SDNodeIterator::begin(N);
1592 static inline ChildIteratorType child_end(NodeType *N) {
1593 return SDNodeIterator::end(N);
1598 struct ilist_traits<SDNode> {
1599 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1600 static SDNode *getNext(const SDNode *N) { return N->Next; }
1602 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1603 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1605 static SDNode *createSentinel() {
1606 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1608 static void destroySentinel(SDNode *N) { delete N; }
1609 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1612 void addNodeToList(SDNode *NTy) {}
1613 void removeNodeFromList(SDNode *NTy) {}
1614 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1615 const ilist_iterator<SDNode> &X,
1616 const ilist_iterator<SDNode> &Y) {}
1620 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1622 inline bool isNON_EXTLoad(const SDNode *N) {
1623 return N->getOpcode() == ISD::LOAD &&
1624 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1627 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1629 inline bool isEXTLoad(const SDNode *N) {
1630 return N->getOpcode() == ISD::LOAD &&
1631 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1634 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1636 inline bool isSEXTLoad(const SDNode *N) {
1637 return N->getOpcode() == ISD::LOAD &&
1638 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1641 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1643 inline bool isZEXTLoad(const SDNode *N) {
1644 return N->getOpcode() == ISD::LOAD &&
1645 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1648 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1650 inline bool isUNINDEXEDLoad(const SDNode *N) {
1651 return N->getOpcode() == ISD::LOAD &&
1652 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1655 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1657 inline bool isNON_TRUNCStore(const SDNode *N) {
1658 return N->getOpcode() == ISD::STORE &&
1659 !cast<StoreSDNode>(N)->isTruncatingStore();
1662 /// isTRUNCStore - Returns true if the specified node is a truncating
1664 inline bool isTRUNCStore(const SDNode *N) {
1665 return N->getOpcode() == ISD::STORE &&
1666 cast<StoreSDNode>(N)->isTruncatingStore();
1671 } // end llvm namespace