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 simplify_type;
38 template <typename T> struct ilist_traits;
39 template<typename NodeTy, typename Traits> class iplist;
40 template<typename NodeTy> class ilist_iterator;
42 /// SDVTList - This represents a list of ValueType's that has been intern'd by
43 /// a SelectionDAG. Instances of this simple value class are returned by
44 /// SelectionDAG::getVTList(...).
47 const MVT::ValueType *VTs;
48 unsigned short NumVTs;
52 /// ISD namespace - This namespace contains an enum which represents all of the
53 /// SelectionDAG node types and value types.
56 //===--------------------------------------------------------------------===//
57 /// ISD::NodeType enum - This enum defines all of the operators valid in a
61 // DELETED_NODE - This is an illegal flag value that is used to catch
62 // errors. This opcode is not a legal opcode for any node.
65 // EntryToken - This is the marker used to indicate the start of the region.
68 // Token factor - This node takes multiple tokens as input and produces a
69 // single token result. This is used to represent the fact that the operand
70 // operators are independent of each other.
73 // AssertSext, AssertZext - These nodes record if a register contains a
74 // value that has already been zero or sign extended from a narrower type.
75 // These nodes take two operands. The first is the node that has already
76 // been extended, and the second is a value type node indicating the width
78 AssertSext, AssertZext,
80 // Various leaf nodes.
81 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
83 GlobalAddress, FrameIndex, JumpTable, ConstantPool, ExternalSymbol,
85 // The address of the GOT
88 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
89 // llvm.returnaddress on the DAG. These nodes take one operand, the index
90 // of the frame or return address to return. An index of zero corresponds
91 // to the current function's frame or return address, an index of one to the
92 // parent's frame or return address, and so on.
93 FRAMEADDR, RETURNADDR,
95 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
96 // simplification of the constant.
100 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
101 // anything else with this node, and this is valid in the target-specific
102 // dag, turning into a GlobalAddress operand.
107 TargetExternalSymbol,
109 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
110 /// This node represents a target intrinsic function with no side effects.
111 /// The first operand is the ID number of the intrinsic from the
112 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
113 /// node has returns the result of the intrinsic.
116 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
117 /// This node represents a target intrinsic function with side effects that
118 /// returns a result. The first operand is a chain pointer. The second is
119 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
120 /// operands to the intrinsic follow. The node has two results, the result
121 /// of the intrinsic and an output chain.
124 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
125 /// This node represents a target intrinsic function with side effects that
126 /// does not return a result. The first operand is a chain pointer. The
127 /// second is the ID number of the intrinsic from the llvm::Intrinsic
128 /// namespace. The operands to the intrinsic follow.
131 // CopyToReg - This node has three operands: a chain, a register number to
132 // set to this value, and a value.
135 // CopyFromReg - This node indicates that the input value is a virtual or
136 // physical register that is defined outside of the scope of this
137 // SelectionDAG. The register is available from the RegSDNode object.
140 // UNDEF - An undefined node
143 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
144 /// represents the formal arguments for a function. CC# is a Constant value
145 /// indicating the calling convention of the function, and ISVARARG is a
146 /// flag that indicates whether the function is varargs or not. This node
147 /// has one result value for each incoming argument, plus one for the output
148 /// chain. It must be custom legalized. See description of CALL node for
149 /// FLAG argument contents explanation.
153 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
154 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
155 /// This node represents a fully general function call, before the legalizer
156 /// runs. This has one result value for each argument / flag pair, plus
157 /// a chain result. It must be custom legalized. Flag argument indicates
158 /// misc. argument attributes. Currently:
160 /// Bit 1 - 'inreg' attribute
161 /// Bit 2 - 'sret' attribute
162 /// Bits 31:27 - argument ABI alignment in the first argument piece and
163 /// alignment '1' in other argument pieces.
166 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
167 // a Constant, which is required to be operand #1), element of the aggregate
168 // value specified as operand #0. This is only for use before legalization,
169 // for values that will be broken into multiple registers.
172 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
173 // two values of the same integer value type, this produces a value twice as
174 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
177 // MERGE_VALUES - This node takes multiple discrete operands and returns
178 // them all as its individual results. This nodes has exactly the same
179 // number of inputs and outputs, and is only valid before legalization.
180 // This node is useful for some pieces of the code generator that want to
181 // think about a single node with multiple results, not multiple nodes.
184 // Simple integer binary arithmetic operators.
185 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
187 // Carry-setting nodes for multiple precision addition and subtraction.
188 // These nodes take two operands of the same value type, and produce two
189 // results. The first result is the normal add or sub result, the second
190 // result is the carry flag result.
193 // Carry-using nodes for multiple precision addition and subtraction. These
194 // nodes take three operands: The first two are the normal lhs and rhs to
195 // the add or sub, and the third is the input carry flag. These nodes
196 // produce two results; the normal result of the add or sub, and the output
197 // carry flag. These nodes both read and write a carry flag to allow them
198 // to them to be chained together for add and sub of arbitrarily large
202 // Simple binary floating point operators.
203 FADD, FSUB, FMUL, FDIV, FREM,
205 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
206 // DAG node does not require that X and Y have the same type, just that they
207 // are both floating point. X and the result must have the same type.
208 // FCOPYSIGN(f32, f64) is allowed.
211 /// VBUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,..., COUNT,TYPE) - Return a vector
212 /// with the specified, possibly variable, elements. The number of elements
213 /// is required to be a power of two.
216 /// BUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,...) - Return a vector
217 /// with the specified, possibly variable, elements. The number of elements
218 /// is required to be a power of two.
221 /// VINSERT_VECTOR_ELT(VECTOR, VAL, IDX, COUNT,TYPE) - Given a vector
222 /// VECTOR, an element ELEMENT, and a (potentially variable) index IDX,
223 /// return an vector with the specified element of VECTOR replaced with VAL.
224 /// COUNT and TYPE specify the type of vector, as is standard for V* nodes.
227 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR (a legal packed
228 /// type) with the element at IDX replaced with VAL.
231 /// VEXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
232 /// (an MVT::Vector value) identified by the (potentially variable) element
236 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
237 /// (a legal vector type vector) identified by the (potentially variable)
238 /// element number IDX.
241 /// VVECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC, COUNT,TYPE) - Returns a vector,
242 /// of the same type as VEC1/VEC2. SHUFFLEVEC is a VBUILD_VECTOR of
243 /// constant int values that indicate which value each result element will
244 /// get. The elements of VEC1/VEC2 are enumerated in order. This is quite
245 /// similar to the Altivec 'vperm' instruction, except that the indices must
246 /// be constants and are in terms of the element size of VEC1/VEC2, not in
250 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
251 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
252 /// (regardless of whether its datatype is legal or not) that indicate
253 /// which value each result element will get. The elements of VEC1/VEC2 are
254 /// enumerated in order. This is quite similar to the Altivec 'vperm'
255 /// instruction, except that the indices must be constants and are in terms
256 /// of the element size of VEC1/VEC2, not in terms of bytes.
259 /// X = VBIT_CONVERT(Y) and X = VBIT_CONVERT(Y, COUNT,TYPE) - This node
260 /// represents a conversion from or to an ISD::Vector type.
262 /// This is lowered to a BIT_CONVERT of the appropriate input/output types.
263 /// The input and output are required to have the same size and at least one
264 /// is required to be a vector (if neither is a vector, just use
267 /// If the result is a vector, this takes three operands (like any other
268 /// vector producer) which indicate the size and type of the vector result.
269 /// Otherwise it takes one input.
272 /// BINOP(LHS, RHS, COUNT,TYPE)
273 /// Simple abstract vector operators. Unlike the integer and floating point
274 /// binary operators, these nodes also take two additional operands:
275 /// a constant element count, and a value type node indicating the type of
276 /// the elements. The order is count, type, op0, op1. All vector opcodes,
277 /// including VLOAD and VConstant must currently have count and type as
278 /// their last two operands.
279 VADD, VSUB, VMUL, VSDIV, VUDIV,
282 /// VSELECT(COND,LHS,RHS, COUNT,TYPE) - Select for MVT::Vector values.
283 /// COND is a boolean value. This node return LHS if COND is true, RHS if
287 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
288 /// scalar value into the low element of the resultant vector type. The top
289 /// elements of the vector are undefined.
292 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
293 // an unsigned/signed value of type i[2*n], then return the top part.
296 // Bitwise operators - logical and, logical or, logical xor, shift left,
297 // shift right algebraic (shift in sign bits), shift right logical (shift in
298 // zeroes), rotate left, rotate right, and byteswap.
299 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
301 // Counting operators
304 // Select(COND, TRUEVAL, FALSEVAL)
307 // Select with condition operator - This selects between a true value and
308 // a false value (ops #2 and #3) based on the boolean result of comparing
309 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
310 // condition code in op #4, a CondCodeSDNode.
313 // SetCC operator - This evaluates to a boolean (i1) true value if the
314 // condition is true. The operands to this are the left and right operands
315 // to compare (ops #0, and #1) and the condition code to compare them with
316 // (op #2) as a CondCodeSDNode.
319 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
320 // integer shift operations, just like ADD/SUB_PARTS. The operation
322 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
323 SHL_PARTS, SRA_PARTS, SRL_PARTS,
325 // Conversion operators. These are all single input single output
326 // operations. For all of these, the result type must be strictly
327 // wider or narrower (depending on the operation) than the source
330 // SIGN_EXTEND - Used for integer types, replicating the sign bit
334 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
337 // ANY_EXTEND - Used for integer types. The high bits are undefined.
340 // TRUNCATE - Completely drop the high bits.
343 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
344 // depends on the first letter) to floating point.
348 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
349 // sign extend a small value in a large integer register (e.g. sign
350 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
351 // with the 7th bit). The size of the smaller type is indicated by the 1th
352 // operand, a ValueType node.
355 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
360 // FP_ROUND - Perform a rounding operation from the current
361 // precision down to the specified precision (currently always 64->32).
364 // FP_ROUND_INREG - This operator takes a floating point register, and
365 // rounds it to a floating point value. It then promotes it and returns it
366 // in a register of the same size. This operation effectively just discards
367 // excess precision. The type to round down to is specified by the 1th
368 // operation, a VTSDNode (currently always 64->32->64).
371 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
374 // BIT_CONVERT - Theis operator converts between integer and FP values, as
375 // if one was stored to memory as integer and the other was loaded from the
376 // same address (or equivalently for vector format conversions, etc). The
377 // source and result are required to have the same bit size (e.g.
378 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
379 // conversions, but that is a noop, deleted by getNode().
382 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI - Perform unary floating point
383 // negation, absolute value, square root, sine and cosine, and powi
385 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI,
387 // LOAD and STORE have token chains as their first operand, then the same
388 // operands as an LLVM load/store instruction, then an offset node that
389 // is added / subtracted from the base pointer to form the address (for
390 // indexed memory ops).
393 // Abstract vector version of LOAD. VLOAD has a constant element count as
394 // the first operand, followed by a value type node indicating the type of
395 // the elements, a token chain, a pointer operand, and a SRCVALUE node.
398 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
399 // value and stores it to memory in one operation. This can be used for
400 // either integer or floating point operands. The first four operands of
401 // this are the same as a standard store. The fifth is the ValueType to
402 // store it as (which will be smaller than the source value).
405 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
406 // to a specified boundary. The first operand is the token chain, the
407 // second is the number of bytes to allocate, and the third is the alignment
408 // boundary. The size is guaranteed to be a multiple of the stack
409 // alignment, and the alignment is guaranteed to be bigger than the stack
410 // alignment (if required) or 0 to get standard stack alignment.
413 // Control flow instructions. These all have token chains.
415 // BR - Unconditional branch. The first operand is the chain
416 // operand, the second is the MBB to branch to.
419 // BRIND - Indirect branch. The first operand is the chain, the second
420 // is the value to branch to, which must be of the same type as the target's
424 // BR_JT - Jumptable branch. The first operand is the chain, the second
425 // is the jumptable index, the last one is the jumptable entry index.
428 // BRCOND - Conditional branch. The first operand is the chain,
429 // the second is the condition, the third is the block to branch
430 // to if the condition is true.
433 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
434 // that the condition is represented as condition code, and two nodes to
435 // compare, rather than as a combined SetCC node. The operands in order are
436 // chain, cc, lhs, rhs, block to branch to if condition is true.
439 // RET - Return from function. The first operand is the chain,
440 // and any subsequent operands are pairs of return value and return value
441 // signness for the function. This operation can have variable number of
445 // INLINEASM - Represents an inline asm block. This node always has two
446 // return values: a chain and a flag result. The inputs are as follows:
447 // Operand #0 : Input chain.
448 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
449 // Operand #2n+2: A RegisterNode.
450 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
451 // Operand #last: Optional, an incoming flag.
454 // LABEL - Represents a label in mid basic block used to track
455 // locations needed for debug and exception handling tables. This node
457 // Operand #0 : input chain.
458 // Operand #1 : module unique number use to identify the label.
461 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
462 // value, the same type as the pointer type for the system, and an output
466 // STACKRESTORE has two operands, an input chain and a pointer to restore to
467 // it returns an output chain.
470 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
471 // correspond to the operands of the LLVM intrinsic functions. The only
472 // result is a token chain. The alignment argument is guaranteed to be a
478 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
479 // a call sequence, and carry arbitrary information that target might want
480 // to know. The first operand is a chain, the rest are specified by the
481 // target and not touched by the DAG optimizers.
482 CALLSEQ_START, // Beginning of a call sequence
483 CALLSEQ_END, // End of a call sequence
485 // VAARG - VAARG has three operands: an input chain, a pointer, and a
486 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
489 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
490 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
494 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
495 // pointer, and a SRCVALUE.
498 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
499 // locations with their value. This allows one use alias analysis
500 // information in the backend.
503 // PCMARKER - This corresponds to the pcmarker intrinsic.
506 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
507 // The only operand is a chain and a value and a chain are produced. The
508 // value is the contents of the architecture specific cycle counter like
509 // register (or other high accuracy low latency clock source)
512 // HANDLENODE node - Used as a handle for various purposes.
515 // LOCATION - This node is used to represent a source location for debug
516 // info. It takes token chain as input, then a line number, then a column
517 // number, then a filename, then a working dir. It produces a token chain
521 // DEBUG_LOC - This node is used to represent source line information
522 // embedded in the code. It takes a token chain as input, then a line
523 // number, then a column then a file id (provided by MachineModuleInfo.) It
524 // produces a token chain as output.
527 // BUILTIN_OP_END - This must be the last enum value in this list.
533 /// isBuildVectorAllOnes - Return true if the specified node is a
534 /// BUILD_VECTOR where all of the elements are ~0 or undef.
535 bool isBuildVectorAllOnes(const SDNode *N);
537 /// isBuildVectorAllZeros - Return true if the specified node is a
538 /// BUILD_VECTOR where all of the elements are 0 or undef.
539 bool isBuildVectorAllZeros(const SDNode *N);
541 //===--------------------------------------------------------------------===//
542 /// MemIndexedMode enum - This enum defines the load / store indexed
543 /// addressing modes.
545 /// UNINDEXED "Normal" load / store. The effective address is already
546 /// computed and is available in the base pointer. The offset
547 /// operand is always undefined. In addition to producing a
548 /// chain, an unindexed load produces one value (result of the
549 /// load); an unindexed store does not produces a value.
551 /// PRE_INC Similar to the unindexed mode where the effective address is
552 /// PRE_DEC the value of the base pointer add / subtract the offset.
553 /// It considers the computation as being folded into the load /
554 /// store operation (i.e. the load / store does the address
555 /// computation as well as performing the memory transaction).
556 /// The base operand is always undefined. In addition to
557 /// producing a chain, pre-indexed load produces two values
558 /// (result of the load and the result of the address
559 /// computation); a pre-indexed store produces one value (result
560 /// of the address computation).
562 /// POST_INC The effective address is the value of the base pointer. The
563 /// POST_DEC value of the offset operand is then added to / subtracted
564 /// from the base after memory transaction. In addition to
565 /// producing a chain, post-indexed load produces two values
566 /// (the result of the load and the result of the base +/- offset
567 /// computation); a post-indexed store produces one value (the
568 /// the result of the base +/- offset computation).
570 enum MemIndexedMode {
579 //===--------------------------------------------------------------------===//
580 /// LoadExtType enum - This enum defines the three variants of LOADEXT
581 /// (load with extension).
583 /// SEXTLOAD loads the integer operand and sign extends it to a larger
584 /// integer result type.
585 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
586 /// integer result type.
587 /// EXTLOAD is used for three things: floating point extending loads,
588 /// integer extending loads [the top bits are undefined], and vector
589 /// extending loads [load into low elt].
599 //===--------------------------------------------------------------------===//
600 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
601 /// below work out, when considering SETFALSE (something that never exists
602 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
603 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
604 /// to. If the "N" column is 1, the result of the comparison is undefined if
605 /// the input is a NAN.
607 /// All of these (except for the 'always folded ops') should be handled for
608 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
609 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
611 /// Note that these are laid out in a specific order to allow bit-twiddling
612 /// to transform conditions.
614 // Opcode N U L G E Intuitive operation
615 SETFALSE, // 0 0 0 0 Always false (always folded)
616 SETOEQ, // 0 0 0 1 True if ordered and equal
617 SETOGT, // 0 0 1 0 True if ordered and greater than
618 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
619 SETOLT, // 0 1 0 0 True if ordered and less than
620 SETOLE, // 0 1 0 1 True if ordered and less than or equal
621 SETONE, // 0 1 1 0 True if ordered and operands are unequal
622 SETO, // 0 1 1 1 True if ordered (no nans)
623 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
624 SETUEQ, // 1 0 0 1 True if unordered or equal
625 SETUGT, // 1 0 1 0 True if unordered or greater than
626 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
627 SETULT, // 1 1 0 0 True if unordered or less than
628 SETULE, // 1 1 0 1 True if unordered, less than, or equal
629 SETUNE, // 1 1 1 0 True if unordered or not equal
630 SETTRUE, // 1 1 1 1 Always true (always folded)
631 // Don't care operations: undefined if the input is a nan.
632 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
633 SETEQ, // 1 X 0 0 1 True if equal
634 SETGT, // 1 X 0 1 0 True if greater than
635 SETGE, // 1 X 0 1 1 True if greater than or equal
636 SETLT, // 1 X 1 0 0 True if less than
637 SETLE, // 1 X 1 0 1 True if less than or equal
638 SETNE, // 1 X 1 1 0 True if not equal
639 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
641 SETCC_INVALID // Marker value.
644 /// isSignedIntSetCC - Return true if this is a setcc instruction that
645 /// performs a signed comparison when used with integer operands.
646 inline bool isSignedIntSetCC(CondCode Code) {
647 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
650 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
651 /// performs an unsigned comparison when used with integer operands.
652 inline bool isUnsignedIntSetCC(CondCode Code) {
653 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
656 /// isTrueWhenEqual - Return true if the specified condition returns true if
657 /// the two operands to the condition are equal. Note that if one of the two
658 /// operands is a NaN, this value is meaningless.
659 inline bool isTrueWhenEqual(CondCode Cond) {
660 return ((int)Cond & 1) != 0;
663 /// getUnorderedFlavor - This function returns 0 if the condition is always
664 /// false if an operand is a NaN, 1 if the condition is always true if the
665 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
667 inline unsigned getUnorderedFlavor(CondCode Cond) {
668 return ((int)Cond >> 3) & 3;
671 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
672 /// 'op' is a valid SetCC operation.
673 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
675 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
676 /// when given the operation for (X op Y).
677 CondCode getSetCCSwappedOperands(CondCode Operation);
679 /// getSetCCOrOperation - Return the result of a logical OR between different
680 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
681 /// function returns SETCC_INVALID if it is not possible to represent the
682 /// resultant comparison.
683 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
685 /// getSetCCAndOperation - Return the result of a logical AND between
686 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
687 /// function returns SETCC_INVALID if it is not possible to represent the
688 /// resultant comparison.
689 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
690 } // end llvm::ISD namespace
693 //===----------------------------------------------------------------------===//
694 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
695 /// values as the result of a computation. Many nodes return multiple values,
696 /// from loads (which define a token and a return value) to ADDC (which returns
697 /// a result and a carry value), to calls (which may return an arbitrary number
700 /// As such, each use of a SelectionDAG computation must indicate the node that
701 /// computes it as well as which return value to use from that node. This pair
702 /// of information is represented with the SDOperand value type.
706 SDNode *Val; // The node defining the value we are using.
707 unsigned ResNo; // Which return value of the node we are using.
709 SDOperand() : Val(0), ResNo(0) {}
710 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
712 bool operator==(const SDOperand &O) const {
713 return Val == O.Val && ResNo == O.ResNo;
715 bool operator!=(const SDOperand &O) const {
716 return !operator==(O);
718 bool operator<(const SDOperand &O) const {
719 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
722 SDOperand getValue(unsigned R) const {
723 return SDOperand(Val, R);
726 // isOperand - Return true if this node is an operand of N.
727 bool isOperand(SDNode *N) const;
729 /// getValueType - Return the ValueType of the referenced return value.
731 inline MVT::ValueType getValueType() const;
733 // Forwarding methods - These forward to the corresponding methods in SDNode.
734 inline unsigned getOpcode() const;
735 inline unsigned getNumOperands() const;
736 inline const SDOperand &getOperand(unsigned i) const;
737 inline uint64_t getConstantOperandVal(unsigned i) const;
738 inline bool isTargetOpcode() const;
739 inline unsigned getTargetOpcode() const;
741 /// hasOneUse - Return true if there is exactly one operation using this
742 /// result value of the defining operator.
743 inline bool hasOneUse() const;
747 /// simplify_type specializations - Allow casting operators to work directly on
748 /// SDOperands as if they were SDNode*'s.
749 template<> struct simplify_type<SDOperand> {
750 typedef SDNode* SimpleType;
751 static SimpleType getSimplifiedValue(const SDOperand &Val) {
752 return static_cast<SimpleType>(Val.Val);
755 template<> struct simplify_type<const SDOperand> {
756 typedef SDNode* SimpleType;
757 static SimpleType getSimplifiedValue(const SDOperand &Val) {
758 return static_cast<SimpleType>(Val.Val);
763 /// SDNode - Represents one node in the SelectionDAG.
765 class SDNode : public FoldingSetNode {
766 /// NodeType - The operation that this node performs.
768 unsigned short NodeType;
770 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
771 /// then they will be delete[]'d when the node is destroyed.
772 bool OperandsNeedDelete : 1;
774 /// NodeId - Unique id per SDNode in the DAG.
777 /// OperandList - The values that are used by this operation.
779 SDOperand *OperandList;
781 /// ValueList - The types of the values this node defines. SDNode's may
782 /// define multiple values simultaneously.
783 const MVT::ValueType *ValueList;
785 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
786 unsigned short NumOperands, NumValues;
788 /// Prev/Next pointers - These pointers form the linked list of of the
789 /// AllNodes list in the current DAG.
791 friend struct ilist_traits<SDNode>;
793 /// Uses - These are all of the SDNode's that use a value produced by this
795 SmallVector<SDNode*,3> Uses;
797 // Out-of-line virtual method to give class a home.
798 virtual void ANCHOR();
801 assert(NumOperands == 0 && "Operand list not cleared before deletion");
802 NodeType = ISD::DELETED_NODE;
805 //===--------------------------------------------------------------------===//
808 unsigned getOpcode() const { return NodeType; }
809 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
810 unsigned getTargetOpcode() const {
811 assert(isTargetOpcode() && "Not a target opcode!");
812 return NodeType - ISD::BUILTIN_OP_END;
815 size_t use_size() const { return Uses.size(); }
816 bool use_empty() const { return Uses.empty(); }
817 bool hasOneUse() const { return Uses.size() == 1; }
819 /// getNodeId - Return the unique node id.
821 int getNodeId() const { return NodeId; }
823 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
824 use_iterator use_begin() const { return Uses.begin(); }
825 use_iterator use_end() const { return Uses.end(); }
827 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
828 /// indicated value. This method ignores uses of other values defined by this
830 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
832 /// isOnlyUse - Return true if this node is the only use of N.
834 bool isOnlyUse(SDNode *N) const;
836 /// isOperand - Return true if this node is an operand of N.
838 bool isOperand(SDNode *N) const;
840 /// isPredecessor - Return true if this node is a predecessor of N. This node
841 /// is either an operand of N or it can be reached by recursively traversing
843 /// NOTE: this is an expensive method. Use it carefully.
844 bool isPredecessor(SDNode *N) const;
846 /// getNumOperands - Return the number of values used by this operation.
848 unsigned getNumOperands() const { return NumOperands; }
850 /// getConstantOperandVal - Helper method returns the integer value of a
851 /// ConstantSDNode operand.
852 uint64_t getConstantOperandVal(unsigned Num) const;
854 const SDOperand &getOperand(unsigned Num) const {
855 assert(Num < NumOperands && "Invalid child # of SDNode!");
856 return OperandList[Num];
859 typedef const SDOperand* op_iterator;
860 op_iterator op_begin() const { return OperandList; }
861 op_iterator op_end() const { return OperandList+NumOperands; }
864 SDVTList getVTList() const {
865 SDVTList X = { ValueList, NumValues };
869 /// getNumValues - Return the number of values defined/returned by this
872 unsigned getNumValues() const { return NumValues; }
874 /// getValueType - Return the type of a specified result.
876 MVT::ValueType getValueType(unsigned ResNo) const {
877 assert(ResNo < NumValues && "Illegal result number!");
878 return ValueList[ResNo];
881 typedef const MVT::ValueType* value_iterator;
882 value_iterator value_begin() const { return ValueList; }
883 value_iterator value_end() const { return ValueList+NumValues; }
885 /// getOperationName - Return the opcode of this operation for printing.
887 const char* getOperationName(const SelectionDAG *G = 0) const;
888 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
890 void dump(const SelectionDAG *G) const;
892 static bool classof(const SDNode *) { return true; }
894 /// Profile - Gather unique data for the node.
896 void Profile(FoldingSetNodeID &ID);
899 friend class SelectionDAG;
901 /// getValueTypeList - Return a pointer to the specified value type.
903 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
904 static SDVTList getSDVTList(MVT::ValueType VT) {
905 SDVTList Ret = { getValueTypeList(VT), 1 };
909 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
910 : NodeType(Opc), NodeId(-1) {
911 OperandsNeedDelete = true;
912 NumOperands = NumOps;
913 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
915 for (unsigned i = 0; i != NumOps; ++i) {
916 OperandList[i] = Ops[i];
917 Ops[i].Val->Uses.push_back(this);
921 NumValues = VTs.NumVTs;
924 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
925 OperandsNeedDelete = false; // Operands set with InitOperands.
930 NumValues = VTs.NumVTs;
934 /// InitOperands - Initialize the operands list of this node with the
935 /// specified values, which are part of the node (thus they don't need to be
936 /// copied in or allocated).
937 void InitOperands(SDOperand *Ops, unsigned NumOps) {
938 assert(OperandList == 0 && "Operands already set!");
939 NumOperands = NumOps;
942 for (unsigned i = 0; i != NumOps; ++i)
943 Ops[i].Val->Uses.push_back(this);
946 /// MorphNodeTo - This frees the operands of the current node, resets the
947 /// opcode, types, and operands to the specified value. This should only be
948 /// used by the SelectionDAG class.
949 void MorphNodeTo(unsigned Opc, SDVTList L,
950 const SDOperand *Ops, unsigned NumOps);
952 void addUser(SDNode *User) {
953 Uses.push_back(User);
955 void removeUser(SDNode *User) {
956 // Remove this user from the operand's use list.
957 for (unsigned i = Uses.size(); ; --i) {
958 assert(i != 0 && "Didn't find user!");
959 if (Uses[i-1] == User) {
960 Uses[i-1] = Uses.back();
967 void setNodeId(int Id) {
973 // Define inline functions from the SDOperand class.
975 inline unsigned SDOperand::getOpcode() const {
976 return Val->getOpcode();
978 inline MVT::ValueType SDOperand::getValueType() const {
979 return Val->getValueType(ResNo);
981 inline unsigned SDOperand::getNumOperands() const {
982 return Val->getNumOperands();
984 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
985 return Val->getOperand(i);
987 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
988 return Val->getConstantOperandVal(i);
990 inline bool SDOperand::isTargetOpcode() const {
991 return Val->isTargetOpcode();
993 inline unsigned SDOperand::getTargetOpcode() const {
994 return Val->getTargetOpcode();
996 inline bool SDOperand::hasOneUse() const {
997 return Val->hasNUsesOfValue(1, ResNo);
1000 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1001 /// to allow co-allocation of node operands with the node itself.
1002 class UnarySDNode : public SDNode {
1003 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1006 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1007 : SDNode(Opc, VTs), Op(X) {
1008 InitOperands(&Op, 1);
1012 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1013 /// to allow co-allocation of node operands with the node itself.
1014 class BinarySDNode : public SDNode {
1015 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1018 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1019 : SDNode(Opc, VTs) {
1022 InitOperands(Ops, 2);
1026 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1027 /// to allow co-allocation of node operands with the node itself.
1028 class TernarySDNode : public SDNode {
1029 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1032 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1034 : SDNode(Opc, VTs) {
1038 InitOperands(Ops, 3);
1043 /// HandleSDNode - This class is used to form a handle around another node that
1044 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1045 /// operand. This node should be directly created by end-users and not added to
1046 /// the AllNodes list.
1047 class HandleSDNode : public SDNode {
1048 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1051 HandleSDNode(SDOperand X)
1052 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1053 InitOperands(&Op, 1);
1056 SDOperand getValue() const { return Op; }
1059 class StringSDNode : public SDNode {
1061 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1063 friend class SelectionDAG;
1064 StringSDNode(const std::string &val)
1065 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1068 const std::string &getValue() const { return Value; }
1069 static bool classof(const StringSDNode *) { return true; }
1070 static bool classof(const SDNode *N) {
1071 return N->getOpcode() == ISD::STRING;
1075 class ConstantSDNode : public SDNode {
1077 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1079 friend class SelectionDAG;
1080 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1081 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1086 uint64_t getValue() const { return Value; }
1088 int64_t getSignExtended() const {
1089 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1090 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1093 bool isNullValue() const { return Value == 0; }
1094 bool isAllOnesValue() const {
1095 return Value == MVT::getIntVTBitMask(getValueType(0));
1098 static bool classof(const ConstantSDNode *) { return true; }
1099 static bool classof(const SDNode *N) {
1100 return N->getOpcode() == ISD::Constant ||
1101 N->getOpcode() == ISD::TargetConstant;
1105 class ConstantFPSDNode : public SDNode {
1107 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1109 friend class SelectionDAG;
1110 ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1111 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1112 getSDVTList(VT)), Value(val) {
1116 double getValue() const { return Value; }
1118 /// isExactlyValue - We don't rely on operator== working on double values, as
1119 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1120 /// As such, this method can be used to do an exact bit-for-bit comparison of
1121 /// two floating point values.
1122 bool isExactlyValue(double V) const;
1124 static bool classof(const ConstantFPSDNode *) { return true; }
1125 static bool classof(const SDNode *N) {
1126 return N->getOpcode() == ISD::ConstantFP ||
1127 N->getOpcode() == ISD::TargetConstantFP;
1131 class GlobalAddressSDNode : public SDNode {
1132 GlobalValue *TheGlobal;
1134 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1136 friend class SelectionDAG;
1137 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1139 : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress,
1140 getSDVTList(VT)), Offset(o) {
1141 TheGlobal = const_cast<GlobalValue*>(GA);
1145 GlobalValue *getGlobal() const { return TheGlobal; }
1146 int getOffset() const { return Offset; }
1148 static bool classof(const GlobalAddressSDNode *) { return true; }
1149 static bool classof(const SDNode *N) {
1150 return N->getOpcode() == ISD::GlobalAddress ||
1151 N->getOpcode() == ISD::TargetGlobalAddress;
1156 class FrameIndexSDNode : public SDNode {
1158 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1160 friend class SelectionDAG;
1161 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1162 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1167 int getIndex() const { return FI; }
1169 static bool classof(const FrameIndexSDNode *) { return true; }
1170 static bool classof(const SDNode *N) {
1171 return N->getOpcode() == ISD::FrameIndex ||
1172 N->getOpcode() == ISD::TargetFrameIndex;
1176 class JumpTableSDNode : public SDNode {
1178 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1180 friend class SelectionDAG;
1181 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1182 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1187 int getIndex() const { return JTI; }
1189 static bool classof(const JumpTableSDNode *) { return true; }
1190 static bool classof(const SDNode *N) {
1191 return N->getOpcode() == ISD::JumpTable ||
1192 N->getOpcode() == ISD::TargetJumpTable;
1196 class ConstantPoolSDNode : public SDNode {
1199 MachineConstantPoolValue *MachineCPVal;
1201 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1203 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1205 friend class SelectionDAG;
1206 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1208 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1209 getSDVTList(VT)), Offset(o), Alignment(0) {
1210 assert((int)Offset >= 0 && "Offset is too large");
1213 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1215 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1216 getSDVTList(VT)), Offset(o), Alignment(Align) {
1217 assert((int)Offset >= 0 && "Offset is too large");
1220 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1221 MVT::ValueType VT, int o=0)
1222 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1223 getSDVTList(VT)), Offset(o), Alignment(0) {
1224 assert((int)Offset >= 0 && "Offset is too large");
1225 Val.MachineCPVal = v;
1226 Offset |= 1 << (sizeof(unsigned)*8-1);
1228 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1229 MVT::ValueType VT, int o, unsigned Align)
1230 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1231 getSDVTList(VT)), Offset(o), Alignment(Align) {
1232 assert((int)Offset >= 0 && "Offset is too large");
1233 Val.MachineCPVal = v;
1234 Offset |= 1 << (sizeof(unsigned)*8-1);
1238 bool isMachineConstantPoolEntry() const {
1239 return (int)Offset < 0;
1242 Constant *getConstVal() const {
1243 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1244 return Val.ConstVal;
1247 MachineConstantPoolValue *getMachineCPVal() const {
1248 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1249 return Val.MachineCPVal;
1252 int getOffset() const {
1253 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1256 // Return the alignment of this constant pool object, which is either 0 (for
1257 // default alignment) or log2 of the desired value.
1258 unsigned getAlignment() const { return Alignment; }
1260 const Type *getType() const;
1262 static bool classof(const ConstantPoolSDNode *) { return true; }
1263 static bool classof(const SDNode *N) {
1264 return N->getOpcode() == ISD::ConstantPool ||
1265 N->getOpcode() == ISD::TargetConstantPool;
1269 class BasicBlockSDNode : public SDNode {
1270 MachineBasicBlock *MBB;
1271 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1273 friend class SelectionDAG;
1274 BasicBlockSDNode(MachineBasicBlock *mbb)
1275 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1279 MachineBasicBlock *getBasicBlock() const { return MBB; }
1281 static bool classof(const BasicBlockSDNode *) { return true; }
1282 static bool classof(const SDNode *N) {
1283 return N->getOpcode() == ISD::BasicBlock;
1287 class SrcValueSDNode : public SDNode {
1290 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1292 friend class SelectionDAG;
1293 SrcValueSDNode(const Value* v, int o)
1294 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v), offset(o) {
1298 const Value *getValue() const { return V; }
1299 int getOffset() const { return offset; }
1301 static bool classof(const SrcValueSDNode *) { return true; }
1302 static bool classof(const SDNode *N) {
1303 return N->getOpcode() == ISD::SRCVALUE;
1308 class RegisterSDNode : public SDNode {
1310 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1312 friend class SelectionDAG;
1313 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1314 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1318 unsigned getReg() const { return Reg; }
1320 static bool classof(const RegisterSDNode *) { return true; }
1321 static bool classof(const SDNode *N) {
1322 return N->getOpcode() == ISD::Register;
1326 class ExternalSymbolSDNode : public SDNode {
1328 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1330 friend class SelectionDAG;
1331 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1332 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1333 getSDVTList(VT)), Symbol(Sym) {
1337 const char *getSymbol() const { return Symbol; }
1339 static bool classof(const ExternalSymbolSDNode *) { return true; }
1340 static bool classof(const SDNode *N) {
1341 return N->getOpcode() == ISD::ExternalSymbol ||
1342 N->getOpcode() == ISD::TargetExternalSymbol;
1346 class CondCodeSDNode : public SDNode {
1347 ISD::CondCode Condition;
1348 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1350 friend class SelectionDAG;
1351 CondCodeSDNode(ISD::CondCode Cond)
1352 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1356 ISD::CondCode get() const { return Condition; }
1358 static bool classof(const CondCodeSDNode *) { return true; }
1359 static bool classof(const SDNode *N) {
1360 return N->getOpcode() == ISD::CONDCODE;
1364 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1365 /// to parameterize some operations.
1366 class VTSDNode : public SDNode {
1367 MVT::ValueType ValueType;
1368 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1370 friend class SelectionDAG;
1371 VTSDNode(MVT::ValueType VT)
1372 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1376 MVT::ValueType getVT() const { return ValueType; }
1378 static bool classof(const VTSDNode *) { return true; }
1379 static bool classof(const SDNode *N) {
1380 return N->getOpcode() == ISD::VALUETYPE;
1384 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1386 class LoadSDNode : public SDNode {
1387 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1390 // AddrMode - unindexed, pre-indexed, post-indexed.
1391 ISD::MemIndexedMode AddrMode;
1393 // ExtType - non-ext, anyext, sext, zext.
1394 ISD::LoadExtType ExtType;
1396 // LoadedVT - VT of loaded value before extension.
1397 MVT::ValueType LoadedVT;
1399 // SrcValue - Memory location for alias analysis.
1400 const Value *SrcValue;
1402 // SVOffset - Memory location offset.
1405 // Alignment - Alignment of memory location in bytes.
1408 // IsVolatile - True if the load is volatile.
1411 friend class SelectionDAG;
1412 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1413 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1414 const Value *SV, int O=0, unsigned Align=1, bool Vol=false)
1415 : SDNode(ISD::LOAD, VTs),
1416 AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
1417 Alignment(Align), IsVolatile(Vol) {
1418 Ops[0] = ChainPtrOff[0]; // Chain
1419 Ops[1] = ChainPtrOff[1]; // Ptr
1420 Ops[2] = ChainPtrOff[2]; // Off
1421 InitOperands(Ops, 3);
1422 assert((getOffset().getOpcode() == ISD::UNDEF ||
1423 AddrMode != ISD::UNINDEXED) &&
1424 "Only indexed load has a non-undef offset operand");
1428 const SDOperand getChain() const { return getOperand(0); }
1429 const SDOperand getBasePtr() const { return getOperand(1); }
1430 const SDOperand getOffset() const { return getOperand(2); }
1431 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1432 ISD::LoadExtType getExtensionType() const { return ExtType; }
1433 MVT::ValueType getLoadedVT() const { return LoadedVT; }
1434 const Value *getSrcValue() const { return SrcValue; }
1435 int getSrcValueOffset() const { return SVOffset; }
1436 unsigned getAlignment() const { return Alignment; }
1437 bool isVolatile() const { return IsVolatile; }
1439 static bool classof(const LoadSDNode *) { return true; }
1440 static bool classof(const SDNode *N) {
1441 return N->getOpcode() == ISD::LOAD;
1445 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1447 class StoreSDNode : public SDNode {
1448 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1451 // AddrMode - unindexed, pre-indexed, post-indexed.
1452 ISD::MemIndexedMode AddrMode;
1454 // IsTruncStore - True is the op does a truncation before store.
1457 // StoredVT - VT of the value after truncation.
1458 MVT::ValueType StoredVT;
1460 // SrcValue - Memory location for alias analysis.
1461 const Value *SrcValue;
1463 // SVOffset - Memory location offset.
1466 // Alignment - Alignment of memory location in bytes.
1469 // IsVolatile - True if the store is volatile.
1472 friend class SelectionDAG;
1473 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1474 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1475 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1476 : SDNode(ISD::STORE, VTs),
1477 AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT), SrcValue(SV),
1478 SVOffset(O), Alignment(Align), IsVolatile(Vol) {
1479 Ops[0] = ChainValuePtrOff[0]; // Chain
1480 Ops[1] = ChainValuePtrOff[1]; // Value
1481 Ops[2] = ChainValuePtrOff[2]; // Ptr
1482 Ops[3] = ChainValuePtrOff[3]; // Off
1483 InitOperands(Ops, 4);
1484 assert((getOffset().getOpcode() == ISD::UNDEF ||
1485 AddrMode != ISD::UNINDEXED) &&
1486 "Only indexed store has a non-undef offset operand");
1490 const SDOperand getChain() const { return getOperand(0); }
1491 const SDOperand getValue() const { return getOperand(1); }
1492 const SDOperand getBasePtr() const { return getOperand(2); }
1493 const SDOperand getOffset() const { return getOperand(3); }
1494 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1495 bool isTruncatingStore() const { return IsTruncStore; }
1496 MVT::ValueType getStoredVT() const { return StoredVT; }
1497 const Value *getSrcValue() const { return SrcValue; }
1498 int getSrcValueOffset() const { return SVOffset; }
1499 unsigned getAlignment() const { return Alignment; }
1500 bool isVolatile() const { return IsVolatile; }
1502 static bool classof(const StoreSDNode *) { return true; }
1503 static bool classof(const SDNode *N) {
1504 return N->getOpcode() == ISD::STORE;
1509 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1513 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1515 bool operator==(const SDNodeIterator& x) const {
1516 return Operand == x.Operand;
1518 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1520 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1521 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1522 Operand = I.Operand;
1526 pointer operator*() const {
1527 return Node->getOperand(Operand).Val;
1529 pointer operator->() const { return operator*(); }
1531 SDNodeIterator& operator++() { // Preincrement
1535 SDNodeIterator operator++(int) { // Postincrement
1536 SDNodeIterator tmp = *this; ++*this; return tmp;
1539 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1540 static SDNodeIterator end (SDNode *N) {
1541 return SDNodeIterator(N, N->getNumOperands());
1544 unsigned getOperand() const { return Operand; }
1545 const SDNode *getNode() const { return Node; }
1548 template <> struct GraphTraits<SDNode*> {
1549 typedef SDNode NodeType;
1550 typedef SDNodeIterator ChildIteratorType;
1551 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1552 static inline ChildIteratorType child_begin(NodeType *N) {
1553 return SDNodeIterator::begin(N);
1555 static inline ChildIteratorType child_end(NodeType *N) {
1556 return SDNodeIterator::end(N);
1561 struct ilist_traits<SDNode> {
1562 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1563 static SDNode *getNext(const SDNode *N) { return N->Next; }
1565 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1566 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1568 static SDNode *createSentinel() {
1569 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1571 static void destroySentinel(SDNode *N) { delete N; }
1572 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1575 void addNodeToList(SDNode *NTy) {}
1576 void removeNodeFromList(SDNode *NTy) {}
1577 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1578 const ilist_iterator<SDNode> &X,
1579 const ilist_iterator<SDNode> &Y) {}
1583 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1585 inline bool isNON_EXTLoad(const SDNode *N) {
1586 return N->getOpcode() == ISD::LOAD &&
1587 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1590 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1592 inline bool isEXTLoad(const SDNode *N) {
1593 return N->getOpcode() == ISD::LOAD &&
1594 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1597 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1599 inline bool isSEXTLoad(const SDNode *N) {
1600 return N->getOpcode() == ISD::LOAD &&
1601 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1604 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1606 inline bool isZEXTLoad(const SDNode *N) {
1607 return N->getOpcode() == ISD::LOAD &&
1608 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1611 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1613 inline bool isNON_TRUNCStore(const SDNode *N) {
1614 return N->getOpcode() == ISD::STORE &&
1615 !cast<StoreSDNode>(N)->isTruncatingStore();
1618 /// isTRUNCStore - Returns true if the specified node is a truncating
1620 inline bool isTRUNCStore(const SDNode *N) {
1621 return N->getOpcode() == ISD::STORE &&
1622 cast<StoreSDNode>(N)->isTruncatingStore();
1627 } // end llvm namespace