1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG. These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
22 #include "llvm/Value.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator"
26 #include "llvm/CodeGen/ValueTypes.h"
27 #include "llvm/Support/DataTypes.h"
34 class MachineBasicBlock;
35 class MachineConstantPoolValue;
37 template <typename T> struct DenseMapKeyInfo;
38 template <typename T> struct simplify_type;
39 template <typename T> struct ilist_traits;
40 template<typename NodeTy, typename Traits> class iplist;
41 template<typename NodeTy> class ilist_iterator;
43 /// SDVTList - This represents a list of ValueType's that has been intern'd by
44 /// a SelectionDAG. Instances of this simple value class are returned by
45 /// SelectionDAG::getVTList(...).
48 const MVT::ValueType *VTs;
49 unsigned short NumVTs;
52 /// ISD namespace - This namespace contains an enum which represents all of the
53 /// SelectionDAG node types and value types.
56 namespace ParamFlags {
59 ZExt = 1<<0, ///< Parameter should be zero extended
61 SExt = 1<<1, ///< Parameter should be sign extended
63 InReg = 1<<2, ///< Parameter should be passed in register
65 StructReturn = 1<<3, ///< Hidden struct-return pointer
67 ByVal = 1<<4, ///< Struct passed by value
69 OrigAlignment = 0x1F<<27,
70 OrigAlignmentOffs = 27
74 //===--------------------------------------------------------------------===//
75 /// ISD::NodeType enum - This enum defines all of the operators valid in a
79 // DELETED_NODE - This is an illegal flag value that is used to catch
80 // errors. This opcode is not a legal opcode for any node.
83 // EntryToken - This is the marker used to indicate the start of the region.
86 // Token factor - This node takes multiple tokens as input and produces a
87 // single token result. This is used to represent the fact that the operand
88 // operators are independent of each other.
91 // AssertSext, AssertZext - These nodes record if a register contains a
92 // value that has already been zero or sign extended from a narrower type.
93 // These nodes take two operands. The first is the node that has already
94 // been extended, and the second is a value type node indicating the width
96 AssertSext, AssertZext,
98 // Various leaf nodes.
99 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
100 Constant, ConstantFP,
101 GlobalAddress, GlobalTLSAddress, FrameIndex,
102 JumpTable, ConstantPool, ExternalSymbol,
104 // The address of the GOT
107 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
108 // llvm.returnaddress on the DAG. These nodes take one operand, the index
109 // of the frame or return address to return. An index of zero corresponds
110 // to the current function's frame or return address, an index of one to the
111 // parent's frame or return address, and so on.
112 FRAMEADDR, RETURNADDR,
114 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
115 // address of the exception block on entry to an landing pad block.
118 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
119 // the selection index of the exception thrown.
122 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
123 // simplification of the constant.
127 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
128 // anything else with this node, and this is valid in the target-specific
129 // dag, turning into a GlobalAddress operand.
131 TargetGlobalTLSAddress,
135 TargetExternalSymbol,
137 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
138 /// This node represents a target intrinsic function with no side effects.
139 /// The first operand is the ID number of the intrinsic from the
140 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
141 /// node has returns the result of the intrinsic.
144 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
145 /// This node represents a target intrinsic function with side effects that
146 /// returns a result. The first operand is a chain pointer. The second is
147 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
148 /// operands to the intrinsic follow. The node has two results, the result
149 /// of the intrinsic and an output chain.
152 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
153 /// This node represents a target intrinsic function with side effects that
154 /// does not return a result. The first operand is a chain pointer. The
155 /// second is the ID number of the intrinsic from the llvm::Intrinsic
156 /// namespace. The operands to the intrinsic follow.
159 // CopyToReg - This node has three operands: a chain, a register number to
160 // set to this value, and a value.
163 // CopyFromReg - This node indicates that the input value is a virtual or
164 // physical register that is defined outside of the scope of this
165 // SelectionDAG. The register is available from the RegSDNode object.
168 // UNDEF - An undefined node
171 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
172 /// represents the formal arguments for a function. CC# is a Constant value
173 /// indicating the calling convention of the function, and ISVARARG is a
174 /// flag that indicates whether the function is varargs or not. This node
175 /// has one result value for each incoming argument, plus one for the output
176 /// chain. It must be custom legalized. See description of CALL node for
177 /// FLAG argument contents explanation.
181 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
182 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
183 /// This node represents a fully general function call, before the legalizer
184 /// runs. This has one result value for each argument / flag pair, plus
185 /// a chain result. It must be custom legalized. Flag argument indicates
186 /// misc. argument attributes. Currently:
188 /// Bit 1 - 'inreg' attribute
189 /// Bit 2 - 'sret' attribute
190 /// Bits 31:27 - argument ABI alignment in the first argument piece and
191 /// alignment '1' in other argument pieces.
194 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
195 // a Constant, which is required to be operand #1), element of the aggregate
196 // value specified as operand #0. This is only for use before legalization,
197 // for values that will be broken into multiple registers.
200 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
201 // two values of the same integer value type, this produces a value twice as
202 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
205 // MERGE_VALUES - This node takes multiple discrete operands and returns
206 // them all as its individual results. This nodes has exactly the same
207 // number of inputs and outputs, and is only valid before legalization.
208 // This node is useful for some pieces of the code generator that want to
209 // think about a single node with multiple results, not multiple nodes.
212 // Simple integer binary arithmetic operators.
213 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
215 // CARRY_FALSE - This node is used when folding other nodes,
216 // like ADDC/SUBC, which indicate the carry result is always false.
219 // Carry-setting nodes for multiple precision addition and subtraction.
220 // These nodes take two operands of the same value type, and produce two
221 // results. The first result is the normal add or sub result, the second
222 // result is the carry flag result.
225 // Carry-using nodes for multiple precision addition and subtraction. These
226 // nodes take three operands: The first two are the normal lhs and rhs to
227 // the add or sub, and the third is the input carry flag. These nodes
228 // produce two results; the normal result of the add or sub, and the output
229 // carry flag. These nodes both read and write a carry flag to allow them
230 // to them to be chained together for add and sub of arbitrarily large
234 // Simple binary floating point operators.
235 FADD, FSUB, FMUL, FDIV, FREM,
237 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
238 // DAG node does not require that X and Y have the same type, just that they
239 // are both floating point. X and the result must have the same type.
240 // FCOPYSIGN(f32, f64) is allowed.
243 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
244 /// with the specified, possibly variable, elements. The number of elements
245 /// is required to be a power of two.
248 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
249 /// at IDX replaced with VAL.
252 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
253 /// identified by the (potentially variable) element number IDX.
256 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
257 /// vector type with the same length and element type, this produces a
258 /// concatenated vector result value, with length equal to the sum of the
259 /// lengths of the input vectors.
262 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
263 /// vector value) starting with the (potentially variable) element number
264 /// IDX, which must be a multiple of the result vector length.
267 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
268 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
269 /// (regardless of whether its datatype is legal or not) that indicate
270 /// which value each result element will get. The elements of VEC1/VEC2 are
271 /// enumerated in order. This is quite similar to the Altivec 'vperm'
272 /// instruction, except that the indices must be constants and are in terms
273 /// of the element size of VEC1/VEC2, not in terms of bytes.
276 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
277 /// scalar value into the low element of the resultant vector type. The top
278 /// elements of the vector are undefined.
281 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
282 // an unsigned/signed value of type i[2*n], then return the top part.
285 // Bitwise operators - logical and, logical or, logical xor, shift left,
286 // shift right algebraic (shift in sign bits), shift right logical (shift in
287 // zeroes), rotate left, rotate right, and byteswap.
288 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
290 // Counting operators
293 // Select(COND, TRUEVAL, FALSEVAL)
296 // Select with condition operator - This selects between a true value and
297 // a false value (ops #2 and #3) based on the boolean result of comparing
298 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
299 // condition code in op #4, a CondCodeSDNode.
302 // SetCC operator - This evaluates to a boolean (i1) true value if the
303 // condition is true. The operands to this are the left and right operands
304 // to compare (ops #0, and #1) and the condition code to compare them with
305 // (op #2) as a CondCodeSDNode.
308 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
309 // integer shift operations, just like ADD/SUB_PARTS. The operation
311 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
312 SHL_PARTS, SRA_PARTS, SRL_PARTS,
314 // Conversion operators. These are all single input single output
315 // operations. For all of these, the result type must be strictly
316 // wider or narrower (depending on the operation) than the source
319 // SIGN_EXTEND - Used for integer types, replicating the sign bit
323 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
326 // ANY_EXTEND - Used for integer types. The high bits are undefined.
329 // TRUNCATE - Completely drop the high bits.
332 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
333 // depends on the first letter) to floating point.
337 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
338 // sign extend a small value in a large integer register (e.g. sign
339 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
340 // with the 7th bit). The size of the smaller type is indicated by the 1th
341 // operand, a ValueType node.
344 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
349 // FP_ROUND - Perform a rounding operation from the current
350 // precision down to the specified precision (currently always 64->32).
353 // FP_ROUND_INREG - This operator takes a floating point register, and
354 // rounds it to a floating point value. It then promotes it and returns it
355 // in a register of the same size. This operation effectively just discards
356 // excess precision. The type to round down to is specified by the 1th
357 // operation, a VTSDNode (currently always 64->32->64).
360 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
363 // BIT_CONVERT - Theis operator converts between integer and FP values, as
364 // if one was stored to memory as integer and the other was loaded from the
365 // same address (or equivalently for vector format conversions, etc). The
366 // source and result are required to have the same bit size (e.g.
367 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
368 // conversions, but that is a noop, deleted by getNode().
371 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI - Perform unary floating point
372 // negation, absolute value, square root, sine and cosine, and powi
374 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI,
376 // LOAD and STORE have token chains as their first operand, then the same
377 // operands as an LLVM load/store instruction, then an offset node that
378 // is added / subtracted from the base pointer to form the address (for
379 // indexed memory ops).
382 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
383 // value and stores it to memory in one operation. This can be used for
384 // either integer or floating point operands. The first four operands of
385 // this are the same as a standard store. The fifth is the ValueType to
386 // store it as (which will be smaller than the source value).
389 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
390 // to a specified boundary. This node always has two return values: a new
391 // stack pointer value and a chain. The first operand is the token chain,
392 // the second is the number of bytes to allocate, and the third is the
393 // alignment boundary. The size is guaranteed to be a multiple of the stack
394 // alignment, and the alignment is guaranteed to be bigger than the stack
395 // alignment (if required) or 0 to get standard stack alignment.
398 // Control flow instructions. These all have token chains.
400 // BR - Unconditional branch. The first operand is the chain
401 // operand, the second is the MBB to branch to.
404 // BRIND - Indirect branch. The first operand is the chain, the second
405 // is the value to branch to, which must be of the same type as the target's
409 // BR_JT - Jumptable branch. The first operand is the chain, the second
410 // is the jumptable index, the last one is the jumptable entry index.
413 // BRCOND - Conditional branch. The first operand is the chain,
414 // the second is the condition, the third is the block to branch
415 // to if the condition is true.
418 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
419 // that the condition is represented as condition code, and two nodes to
420 // compare, rather than as a combined SetCC node. The operands in order are
421 // chain, cc, lhs, rhs, block to branch to if condition is true.
424 // RET - Return from function. The first operand is the chain,
425 // and any subsequent operands are pairs of return value and return value
426 // signness for the function. This operation can have variable number of
430 // INLINEASM - Represents an inline asm block. This node always has two
431 // return values: a chain and a flag result. The inputs are as follows:
432 // Operand #0 : Input chain.
433 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
434 // Operand #2n+2: A RegisterNode.
435 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
436 // Operand #last: Optional, an incoming flag.
439 // LABEL - Represents a label in mid basic block used to track
440 // locations needed for debug and exception handling tables. This node
442 // Operand #0 : input chain.
443 // Operand #1 : module unique number use to identify the label.
446 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
447 // value, the same type as the pointer type for the system, and an output
451 // STACKRESTORE has two operands, an input chain and a pointer to restore to
452 // it returns an output chain.
455 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
456 // correspond to the operands of the LLVM intrinsic functions. The only
457 // result is a token chain. The alignment argument is guaranteed to be a
463 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
464 // a call sequence, and carry arbitrary information that target might want
465 // to know. The first operand is a chain, the rest are specified by the
466 // target and not touched by the DAG optimizers.
467 CALLSEQ_START, // Beginning of a call sequence
468 CALLSEQ_END, // End of a call sequence
470 // VAARG - VAARG has three operands: an input chain, a pointer, and a
471 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
474 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
475 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
479 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
480 // pointer, and a SRCVALUE.
483 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
484 // locations with their value. This allows one use alias analysis
485 // information in the backend.
488 // PCMARKER - This corresponds to the pcmarker intrinsic.
491 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
492 // The only operand is a chain and a value and a chain are produced. The
493 // value is the contents of the architecture specific cycle counter like
494 // register (or other high accuracy low latency clock source)
497 // HANDLENODE node - Used as a handle for various purposes.
500 // LOCATION - This node is used to represent a source location for debug
501 // info. It takes token chain as input, then a line number, then a column
502 // number, then a filename, then a working dir. It produces a token chain
506 // DEBUG_LOC - This node is used to represent source line information
507 // embedded in the code. It takes a token chain as input, then a line
508 // number, then a column then a file id (provided by MachineModuleInfo.) It
509 // produces a token chain as output.
512 // BUILTIN_OP_END - This must be the last enum value in this list.
518 /// isBuildVectorAllOnes - Return true if the specified node is a
519 /// BUILD_VECTOR where all of the elements are ~0 or undef.
520 bool isBuildVectorAllOnes(const SDNode *N);
522 /// isBuildVectorAllZeros - Return true if the specified node is a
523 /// BUILD_VECTOR where all of the elements are 0 or undef.
524 bool isBuildVectorAllZeros(const SDNode *N);
526 //===--------------------------------------------------------------------===//
527 /// MemIndexedMode enum - This enum defines the load / store indexed
528 /// addressing modes.
530 /// UNINDEXED "Normal" load / store. The effective address is already
531 /// computed and is available in the base pointer. The offset
532 /// operand is always undefined. In addition to producing a
533 /// chain, an unindexed load produces one value (result of the
534 /// load); an unindexed store does not produces a value.
536 /// PRE_INC Similar to the unindexed mode where the effective address is
537 /// PRE_DEC the value of the base pointer add / subtract the offset.
538 /// It considers the computation as being folded into the load /
539 /// store operation (i.e. the load / store does the address
540 /// computation as well as performing the memory transaction).
541 /// The base operand is always undefined. In addition to
542 /// producing a chain, pre-indexed load produces two values
543 /// (result of the load and the result of the address
544 /// computation); a pre-indexed store produces one value (result
545 /// of the address computation).
547 /// POST_INC The effective address is the value of the base pointer. The
548 /// POST_DEC value of the offset operand is then added to / subtracted
549 /// from the base after memory transaction. In addition to
550 /// producing a chain, post-indexed load produces two values
551 /// (the result of the load and the result of the base +/- offset
552 /// computation); a post-indexed store produces one value (the
553 /// the result of the base +/- offset computation).
555 enum MemIndexedMode {
564 //===--------------------------------------------------------------------===//
565 /// LoadExtType enum - This enum defines the three variants of LOADEXT
566 /// (load with extension).
568 /// SEXTLOAD loads the integer operand and sign extends it to a larger
569 /// integer result type.
570 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
571 /// integer result type.
572 /// EXTLOAD is used for three things: floating point extending loads,
573 /// integer extending loads [the top bits are undefined], and vector
574 /// extending loads [load into low elt].
584 //===--------------------------------------------------------------------===//
585 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
586 /// below work out, when considering SETFALSE (something that never exists
587 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
588 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
589 /// to. If the "N" column is 1, the result of the comparison is undefined if
590 /// the input is a NAN.
592 /// All of these (except for the 'always folded ops') should be handled for
593 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
594 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
596 /// Note that these are laid out in a specific order to allow bit-twiddling
597 /// to transform conditions.
599 // Opcode N U L G E Intuitive operation
600 SETFALSE, // 0 0 0 0 Always false (always folded)
601 SETOEQ, // 0 0 0 1 True if ordered and equal
602 SETOGT, // 0 0 1 0 True if ordered and greater than
603 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
604 SETOLT, // 0 1 0 0 True if ordered and less than
605 SETOLE, // 0 1 0 1 True if ordered and less than or equal
606 SETONE, // 0 1 1 0 True if ordered and operands are unequal
607 SETO, // 0 1 1 1 True if ordered (no nans)
608 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
609 SETUEQ, // 1 0 0 1 True if unordered or equal
610 SETUGT, // 1 0 1 0 True if unordered or greater than
611 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
612 SETULT, // 1 1 0 0 True if unordered or less than
613 SETULE, // 1 1 0 1 True if unordered, less than, or equal
614 SETUNE, // 1 1 1 0 True if unordered or not equal
615 SETTRUE, // 1 1 1 1 Always true (always folded)
616 // Don't care operations: undefined if the input is a nan.
617 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
618 SETEQ, // 1 X 0 0 1 True if equal
619 SETGT, // 1 X 0 1 0 True if greater than
620 SETGE, // 1 X 0 1 1 True if greater than or equal
621 SETLT, // 1 X 1 0 0 True if less than
622 SETLE, // 1 X 1 0 1 True if less than or equal
623 SETNE, // 1 X 1 1 0 True if not equal
624 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
626 SETCC_INVALID // Marker value.
629 /// isSignedIntSetCC - Return true if this is a setcc instruction that
630 /// performs a signed comparison when used with integer operands.
631 inline bool isSignedIntSetCC(CondCode Code) {
632 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
635 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
636 /// performs an unsigned comparison when used with integer operands.
637 inline bool isUnsignedIntSetCC(CondCode Code) {
638 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
641 /// isTrueWhenEqual - Return true if the specified condition returns true if
642 /// the two operands to the condition are equal. Note that if one of the two
643 /// operands is a NaN, this value is meaningless.
644 inline bool isTrueWhenEqual(CondCode Cond) {
645 return ((int)Cond & 1) != 0;
648 /// getUnorderedFlavor - This function returns 0 if the condition is always
649 /// false if an operand is a NaN, 1 if the condition is always true if the
650 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
652 inline unsigned getUnorderedFlavor(CondCode Cond) {
653 return ((int)Cond >> 3) & 3;
656 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
657 /// 'op' is a valid SetCC operation.
658 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
660 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
661 /// when given the operation for (X op Y).
662 CondCode getSetCCSwappedOperands(CondCode Operation);
664 /// getSetCCOrOperation - Return the result of a logical OR between different
665 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
666 /// function returns SETCC_INVALID if it is not possible to represent the
667 /// resultant comparison.
668 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
670 /// getSetCCAndOperation - Return the result of a logical AND between
671 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
672 /// function returns SETCC_INVALID if it is not possible to represent the
673 /// resultant comparison.
674 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
675 } // end llvm::ISD namespace
678 //===----------------------------------------------------------------------===//
679 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
680 /// values as the result of a computation. Many nodes return multiple values,
681 /// from loads (which define a token and a return value) to ADDC (which returns
682 /// a result and a carry value), to calls (which may return an arbitrary number
685 /// As such, each use of a SelectionDAG computation must indicate the node that
686 /// computes it as well as which return value to use from that node. This pair
687 /// of information is represented with the SDOperand value type.
691 SDNode *Val; // The node defining the value we are using.
692 unsigned ResNo; // Which return value of the node we are using.
694 SDOperand() : Val(0), ResNo(0) {}
695 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
697 bool operator==(const SDOperand &O) const {
698 return Val == O.Val && ResNo == O.ResNo;
700 bool operator!=(const SDOperand &O) const {
701 return !operator==(O);
703 bool operator<(const SDOperand &O) const {
704 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
707 SDOperand getValue(unsigned R) const {
708 return SDOperand(Val, R);
711 // isOperand - Return true if this node is an operand of N.
712 bool isOperand(SDNode *N) const;
714 /// getValueType - Return the ValueType of the referenced return value.
716 inline MVT::ValueType getValueType() const;
718 // Forwarding methods - These forward to the corresponding methods in SDNode.
719 inline unsigned getOpcode() const;
720 inline unsigned getNumOperands() const;
721 inline const SDOperand &getOperand(unsigned i) const;
722 inline uint64_t getConstantOperandVal(unsigned i) const;
723 inline bool isTargetOpcode() const;
724 inline unsigned getTargetOpcode() const;
726 /// hasOneUse - Return true if there is exactly one operation using this
727 /// result value of the defining operator.
728 inline bool hasOneUse() const;
732 template<> struct DenseMapKeyInfo<SDOperand> {
733 static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); }
734 static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);}
735 static unsigned getHashValue(const SDOperand &Val) {
736 return (unsigned)((uintptr_t)Val.Val >> 4) ^
737 (unsigned)((uintptr_t)Val.Val >> 9) + Val.ResNo;
739 static bool isPod() { return true; }
742 /// simplify_type specializations - Allow casting operators to work directly on
743 /// SDOperands as if they were SDNode*'s.
744 template<> struct simplify_type<SDOperand> {
745 typedef SDNode* SimpleType;
746 static SimpleType getSimplifiedValue(const SDOperand &Val) {
747 return static_cast<SimpleType>(Val.Val);
750 template<> struct simplify_type<const SDOperand> {
751 typedef SDNode* SimpleType;
752 static SimpleType getSimplifiedValue(const SDOperand &Val) {
753 return static_cast<SimpleType>(Val.Val);
758 /// SDNode - Represents one node in the SelectionDAG.
760 class SDNode : public FoldingSetNode {
761 /// NodeType - The operation that this node performs.
763 unsigned short NodeType;
765 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
766 /// then they will be delete[]'d when the node is destroyed.
767 bool OperandsNeedDelete : 1;
769 /// NodeId - Unique id per SDNode in the DAG.
772 /// OperandList - The values that are used by this operation.
774 SDOperand *OperandList;
776 /// ValueList - The types of the values this node defines. SDNode's may
777 /// define multiple values simultaneously.
778 const MVT::ValueType *ValueList;
780 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
781 unsigned short NumOperands, NumValues;
783 /// Prev/Next pointers - These pointers form the linked list of of the
784 /// AllNodes list in the current DAG.
786 friend struct ilist_traits<SDNode>;
788 /// Uses - These are all of the SDNode's that use a value produced by this
790 SmallVector<SDNode*,3> Uses;
792 // Out-of-line virtual method to give class a home.
793 virtual void ANCHOR();
796 assert(NumOperands == 0 && "Operand list not cleared before deletion");
797 NodeType = ISD::DELETED_NODE;
800 //===--------------------------------------------------------------------===//
803 unsigned getOpcode() const { return NodeType; }
804 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
805 unsigned getTargetOpcode() const {
806 assert(isTargetOpcode() && "Not a target opcode!");
807 return NodeType - ISD::BUILTIN_OP_END;
810 size_t use_size() const { return Uses.size(); }
811 bool use_empty() const { return Uses.empty(); }
812 bool hasOneUse() const { return Uses.size() == 1; }
814 /// getNodeId - Return the unique node id.
816 int getNodeId() const { return NodeId; }
818 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
819 use_iterator use_begin() const { return Uses.begin(); }
820 use_iterator use_end() const { return Uses.end(); }
822 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
823 /// indicated value. This method ignores uses of other values defined by this
825 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
827 /// isOnlyUse - Return true if this node is the only use of N.
829 bool isOnlyUse(SDNode *N) const;
831 /// isOperand - Return true if this node is an operand of N.
833 bool isOperand(SDNode *N) const;
835 /// isPredecessor - Return true if this node is a predecessor of N. This node
836 /// is either an operand of N or it can be reached by recursively traversing
838 /// NOTE: this is an expensive method. Use it carefully.
839 bool isPredecessor(SDNode *N) const;
841 /// getNumOperands - Return the number of values used by this operation.
843 unsigned getNumOperands() const { return NumOperands; }
845 /// getConstantOperandVal - Helper method returns the integer value of a
846 /// ConstantSDNode operand.
847 uint64_t getConstantOperandVal(unsigned Num) const;
849 const SDOperand &getOperand(unsigned Num) const {
850 assert(Num < NumOperands && "Invalid child # of SDNode!");
851 return OperandList[Num];
854 typedef const SDOperand* op_iterator;
855 op_iterator op_begin() const { return OperandList; }
856 op_iterator op_end() const { return OperandList+NumOperands; }
859 SDVTList getVTList() const {
860 SDVTList X = { ValueList, NumValues };
864 /// getNumValues - Return the number of values defined/returned by this
867 unsigned getNumValues() const { return NumValues; }
869 /// getValueType - Return the type of a specified result.
871 MVT::ValueType getValueType(unsigned ResNo) const {
872 assert(ResNo < NumValues && "Illegal result number!");
873 return ValueList[ResNo];
876 typedef const MVT::ValueType* value_iterator;
877 value_iterator value_begin() const { return ValueList; }
878 value_iterator value_end() const { return ValueList+NumValues; }
880 /// getOperationName - Return the opcode of this operation for printing.
882 std::string getOperationName(const SelectionDAG *G = 0) const;
883 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
885 void dump(const SelectionDAG *G) const;
887 static bool classof(const SDNode *) { return true; }
889 /// Profile - Gather unique data for the node.
891 void Profile(FoldingSetNodeID &ID);
894 friend class SelectionDAG;
896 /// getValueTypeList - Return a pointer to the specified value type.
898 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
899 static SDVTList getSDVTList(MVT::ValueType VT) {
900 SDVTList Ret = { getValueTypeList(VT), 1 };
904 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
905 : NodeType(Opc), NodeId(-1) {
906 OperandsNeedDelete = true;
907 NumOperands = NumOps;
908 OperandList = NumOps ? new SDOperand[NumOperands] : 0;
910 for (unsigned i = 0; i != NumOps; ++i) {
911 OperandList[i] = Ops[i];
912 Ops[i].Val->Uses.push_back(this);
916 NumValues = VTs.NumVTs;
919 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
920 OperandsNeedDelete = false; // Operands set with InitOperands.
925 NumValues = VTs.NumVTs;
929 /// InitOperands - Initialize the operands list of this node with the
930 /// specified values, which are part of the node (thus they don't need to be
931 /// copied in or allocated).
932 void InitOperands(SDOperand *Ops, unsigned NumOps) {
933 assert(OperandList == 0 && "Operands already set!");
934 NumOperands = NumOps;
937 for (unsigned i = 0; i != NumOps; ++i)
938 Ops[i].Val->Uses.push_back(this);
941 /// MorphNodeTo - This frees the operands of the current node, resets the
942 /// opcode, types, and operands to the specified value. This should only be
943 /// used by the SelectionDAG class.
944 void MorphNodeTo(unsigned Opc, SDVTList L,
945 const SDOperand *Ops, unsigned NumOps);
947 void addUser(SDNode *User) {
948 Uses.push_back(User);
950 void removeUser(SDNode *User) {
951 // Remove this user from the operand's use list.
952 for (unsigned i = Uses.size(); ; --i) {
953 assert(i != 0 && "Didn't find user!");
954 if (Uses[i-1] == User) {
955 Uses[i-1] = Uses.back();
962 void setNodeId(int Id) {
968 // Define inline functions from the SDOperand class.
970 inline unsigned SDOperand::getOpcode() const {
971 return Val->getOpcode();
973 inline MVT::ValueType SDOperand::getValueType() const {
974 return Val->getValueType(ResNo);
976 inline unsigned SDOperand::getNumOperands() const {
977 return Val->getNumOperands();
979 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
980 return Val->getOperand(i);
982 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
983 return Val->getConstantOperandVal(i);
985 inline bool SDOperand::isTargetOpcode() const {
986 return Val->isTargetOpcode();
988 inline unsigned SDOperand::getTargetOpcode() const {
989 return Val->getTargetOpcode();
991 inline bool SDOperand::hasOneUse() const {
992 return Val->hasNUsesOfValue(1, ResNo);
995 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
996 /// to allow co-allocation of node operands with the node itself.
997 class UnarySDNode : public SDNode {
998 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1001 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1002 : SDNode(Opc, VTs), Op(X) {
1003 InitOperands(&Op, 1);
1007 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1008 /// to allow co-allocation of node operands with the node itself.
1009 class BinarySDNode : public SDNode {
1010 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1013 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1014 : SDNode(Opc, VTs) {
1017 InitOperands(Ops, 2);
1021 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1022 /// to allow co-allocation of node operands with the node itself.
1023 class TernarySDNode : public SDNode {
1024 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1027 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1029 : SDNode(Opc, VTs) {
1033 InitOperands(Ops, 3);
1038 /// HandleSDNode - This class is used to form a handle around another node that
1039 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1040 /// operand. This node should be directly created by end-users and not added to
1041 /// the AllNodes list.
1042 class HandleSDNode : public SDNode {
1043 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1046 explicit HandleSDNode(SDOperand X)
1047 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1048 InitOperands(&Op, 1);
1051 SDOperand getValue() const { return Op; }
1054 class StringSDNode : public SDNode {
1056 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1058 friend class SelectionDAG;
1059 explicit StringSDNode(const std::string &val)
1060 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1063 const std::string &getValue() const { return Value; }
1064 static bool classof(const StringSDNode *) { return true; }
1065 static bool classof(const SDNode *N) {
1066 return N->getOpcode() == ISD::STRING;
1070 class ConstantSDNode : public SDNode {
1072 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1074 friend class SelectionDAG;
1075 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1076 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1081 uint64_t getValue() const { return Value; }
1083 int64_t getSignExtended() const {
1084 unsigned Bits = MVT::getSizeInBits(getValueType(0));
1085 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1088 bool isNullValue() const { return Value == 0; }
1089 bool isAllOnesValue() const {
1090 return Value == MVT::getIntVTBitMask(getValueType(0));
1093 static bool classof(const ConstantSDNode *) { return true; }
1094 static bool classof(const SDNode *N) {
1095 return N->getOpcode() == ISD::Constant ||
1096 N->getOpcode() == ISD::TargetConstant;
1100 class ConstantFPSDNode : public SDNode {
1102 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1104 friend class SelectionDAG;
1105 ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1106 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1107 getSDVTList(VT)), Value(val) {
1111 double getValue() const { return Value; }
1113 /// isExactlyValue - We don't rely on operator== working on double values, as
1114 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1115 /// As such, this method can be used to do an exact bit-for-bit comparison of
1116 /// two floating point values.
1117 bool isExactlyValue(double V) const;
1119 static bool classof(const ConstantFPSDNode *) { return true; }
1120 static bool classof(const SDNode *N) {
1121 return N->getOpcode() == ISD::ConstantFP ||
1122 N->getOpcode() == ISD::TargetConstantFP;
1126 class GlobalAddressSDNode : public SDNode {
1127 GlobalValue *TheGlobal;
1129 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1131 friend class SelectionDAG;
1132 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1136 GlobalValue *getGlobal() const { return TheGlobal; }
1137 int getOffset() const { return Offset; }
1139 static bool classof(const GlobalAddressSDNode *) { return true; }
1140 static bool classof(const SDNode *N) {
1141 return N->getOpcode() == ISD::GlobalAddress ||
1142 N->getOpcode() == ISD::TargetGlobalAddress ||
1143 N->getOpcode() == ISD::GlobalTLSAddress ||
1144 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1148 class FrameIndexSDNode : public SDNode {
1150 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1152 friend class SelectionDAG;
1153 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1154 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1159 int getIndex() const { return FI; }
1161 static bool classof(const FrameIndexSDNode *) { return true; }
1162 static bool classof(const SDNode *N) {
1163 return N->getOpcode() == ISD::FrameIndex ||
1164 N->getOpcode() == ISD::TargetFrameIndex;
1168 class JumpTableSDNode : public SDNode {
1170 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1172 friend class SelectionDAG;
1173 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1174 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1179 int getIndex() const { return JTI; }
1181 static bool classof(const JumpTableSDNode *) { return true; }
1182 static bool classof(const SDNode *N) {
1183 return N->getOpcode() == ISD::JumpTable ||
1184 N->getOpcode() == ISD::TargetJumpTable;
1188 class ConstantPoolSDNode : public SDNode {
1191 MachineConstantPoolValue *MachineCPVal;
1193 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1195 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1197 friend class SelectionDAG;
1198 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1200 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1201 getSDVTList(VT)), Offset(o), Alignment(0) {
1202 assert((int)Offset >= 0 && "Offset is too large");
1205 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1207 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1208 getSDVTList(VT)), Offset(o), Alignment(Align) {
1209 assert((int)Offset >= 0 && "Offset is too large");
1212 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1213 MVT::ValueType VT, int o=0)
1214 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1215 getSDVTList(VT)), Offset(o), Alignment(0) {
1216 assert((int)Offset >= 0 && "Offset is too large");
1217 Val.MachineCPVal = v;
1218 Offset |= 1 << (sizeof(unsigned)*8-1);
1220 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1221 MVT::ValueType VT, int o, unsigned Align)
1222 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1223 getSDVTList(VT)), Offset(o), Alignment(Align) {
1224 assert((int)Offset >= 0 && "Offset is too large");
1225 Val.MachineCPVal = v;
1226 Offset |= 1 << (sizeof(unsigned)*8-1);
1230 bool isMachineConstantPoolEntry() const {
1231 return (int)Offset < 0;
1234 Constant *getConstVal() const {
1235 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1236 return Val.ConstVal;
1239 MachineConstantPoolValue *getMachineCPVal() const {
1240 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1241 return Val.MachineCPVal;
1244 int getOffset() const {
1245 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1248 // Return the alignment of this constant pool object, which is either 0 (for
1249 // default alignment) or log2 of the desired value.
1250 unsigned getAlignment() const { return Alignment; }
1252 const Type *getType() const;
1254 static bool classof(const ConstantPoolSDNode *) { return true; }
1255 static bool classof(const SDNode *N) {
1256 return N->getOpcode() == ISD::ConstantPool ||
1257 N->getOpcode() == ISD::TargetConstantPool;
1261 class BasicBlockSDNode : public SDNode {
1262 MachineBasicBlock *MBB;
1263 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1265 friend class SelectionDAG;
1266 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1267 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1271 MachineBasicBlock *getBasicBlock() const { return MBB; }
1273 static bool classof(const BasicBlockSDNode *) { return true; }
1274 static bool classof(const SDNode *N) {
1275 return N->getOpcode() == ISD::BasicBlock;
1279 class SrcValueSDNode : public SDNode {
1282 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1284 friend class SelectionDAG;
1285 SrcValueSDNode(const Value* v, int o)
1286 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v), offset(o) {
1290 const Value *getValue() const { return V; }
1291 int getOffset() const { return offset; }
1293 static bool classof(const SrcValueSDNode *) { return true; }
1294 static bool classof(const SDNode *N) {
1295 return N->getOpcode() == ISD::SRCVALUE;
1300 class RegisterSDNode : public SDNode {
1302 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1304 friend class SelectionDAG;
1305 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1306 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1310 unsigned getReg() const { return Reg; }
1312 static bool classof(const RegisterSDNode *) { return true; }
1313 static bool classof(const SDNode *N) {
1314 return N->getOpcode() == ISD::Register;
1318 class ExternalSymbolSDNode : public SDNode {
1320 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1322 friend class SelectionDAG;
1323 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1324 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1325 getSDVTList(VT)), Symbol(Sym) {
1329 const char *getSymbol() const { return Symbol; }
1331 static bool classof(const ExternalSymbolSDNode *) { return true; }
1332 static bool classof(const SDNode *N) {
1333 return N->getOpcode() == ISD::ExternalSymbol ||
1334 N->getOpcode() == ISD::TargetExternalSymbol;
1338 class CondCodeSDNode : public SDNode {
1339 ISD::CondCode Condition;
1340 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1342 friend class SelectionDAG;
1343 explicit CondCodeSDNode(ISD::CondCode Cond)
1344 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1348 ISD::CondCode get() const { return Condition; }
1350 static bool classof(const CondCodeSDNode *) { return true; }
1351 static bool classof(const SDNode *N) {
1352 return N->getOpcode() == ISD::CONDCODE;
1356 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1357 /// to parameterize some operations.
1358 class VTSDNode : public SDNode {
1359 MVT::ValueType ValueType;
1360 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1362 friend class SelectionDAG;
1363 explicit VTSDNode(MVT::ValueType VT)
1364 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1368 MVT::ValueType getVT() const { return ValueType; }
1370 static bool classof(const VTSDNode *) { return true; }
1371 static bool classof(const SDNode *N) {
1372 return N->getOpcode() == ISD::VALUETYPE;
1376 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1378 class LoadSDNode : public SDNode {
1379 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1382 // AddrMode - unindexed, pre-indexed, post-indexed.
1383 ISD::MemIndexedMode AddrMode;
1385 // ExtType - non-ext, anyext, sext, zext.
1386 ISD::LoadExtType ExtType;
1388 // LoadedVT - VT of loaded value before extension.
1389 MVT::ValueType LoadedVT;
1391 // SrcValue - Memory location for alias analysis.
1392 const Value *SrcValue;
1394 // SVOffset - Memory location offset.
1397 // Alignment - Alignment of memory location in bytes.
1400 // IsVolatile - True if the load is volatile.
1403 friend class SelectionDAG;
1404 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1405 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1406 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1407 : SDNode(ISD::LOAD, VTs),
1408 AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
1409 Alignment(Align), IsVolatile(Vol) {
1410 Ops[0] = ChainPtrOff[0]; // Chain
1411 Ops[1] = ChainPtrOff[1]; // Ptr
1412 Ops[2] = ChainPtrOff[2]; // Off
1413 InitOperands(Ops, 3);
1414 assert(Align != 0 && "Loads should have non-zero aligment");
1415 assert((getOffset().getOpcode() == ISD::UNDEF ||
1416 AddrMode != ISD::UNINDEXED) &&
1417 "Only indexed load has a non-undef offset operand");
1421 const SDOperand getChain() const { return getOperand(0); }
1422 const SDOperand getBasePtr() const { return getOperand(1); }
1423 const SDOperand getOffset() const { return getOperand(2); }
1424 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1425 ISD::LoadExtType getExtensionType() const { return ExtType; }
1426 MVT::ValueType getLoadedVT() const { return LoadedVT; }
1427 const Value *getSrcValue() const { return SrcValue; }
1428 int getSrcValueOffset() const { return SVOffset; }
1429 unsigned getAlignment() const { return Alignment; }
1430 bool isVolatile() const { return IsVolatile; }
1432 static bool classof(const LoadSDNode *) { return true; }
1433 static bool classof(const SDNode *N) {
1434 return N->getOpcode() == ISD::LOAD;
1438 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1440 class StoreSDNode : public SDNode {
1441 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1444 // AddrMode - unindexed, pre-indexed, post-indexed.
1445 ISD::MemIndexedMode AddrMode;
1447 // IsTruncStore - True is the op does a truncation before store.
1450 // StoredVT - VT of the value after truncation.
1451 MVT::ValueType StoredVT;
1453 // SrcValue - Memory location for alias analysis.
1454 const Value *SrcValue;
1456 // SVOffset - Memory location offset.
1459 // Alignment - Alignment of memory location in bytes.
1462 // IsVolatile - True if the store is volatile.
1465 friend class SelectionDAG;
1466 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1467 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1468 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1469 : SDNode(ISD::STORE, VTs),
1470 AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT), SrcValue(SV),
1471 SVOffset(O), Alignment(Align), IsVolatile(Vol) {
1472 Ops[0] = ChainValuePtrOff[0]; // Chain
1473 Ops[1] = ChainValuePtrOff[1]; // Value
1474 Ops[2] = ChainValuePtrOff[2]; // Ptr
1475 Ops[3] = ChainValuePtrOff[3]; // Off
1476 InitOperands(Ops, 4);
1477 assert(Align != 0 && "Stores should have non-zero aligment");
1478 assert((getOffset().getOpcode() == ISD::UNDEF ||
1479 AddrMode != ISD::UNINDEXED) &&
1480 "Only indexed store has a non-undef offset operand");
1484 const SDOperand getChain() const { return getOperand(0); }
1485 const SDOperand getValue() const { return getOperand(1); }
1486 const SDOperand getBasePtr() const { return getOperand(2); }
1487 const SDOperand getOffset() const { return getOperand(3); }
1488 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1489 bool isTruncatingStore() const { return IsTruncStore; }
1490 MVT::ValueType getStoredVT() const { return StoredVT; }
1491 const Value *getSrcValue() const { return SrcValue; }
1492 int getSrcValueOffset() const { return SVOffset; }
1493 unsigned getAlignment() const { return Alignment; }
1494 bool isVolatile() const { return IsVolatile; }
1496 static bool classof(const StoreSDNode *) { return true; }
1497 static bool classof(const SDNode *N) {
1498 return N->getOpcode() == ISD::STORE;
1503 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1507 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1509 bool operator==(const SDNodeIterator& x) const {
1510 return Operand == x.Operand;
1512 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1514 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1515 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1516 Operand = I.Operand;
1520 pointer operator*() const {
1521 return Node->getOperand(Operand).Val;
1523 pointer operator->() const { return operator*(); }
1525 SDNodeIterator& operator++() { // Preincrement
1529 SDNodeIterator operator++(int) { // Postincrement
1530 SDNodeIterator tmp = *this; ++*this; return tmp;
1533 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1534 static SDNodeIterator end (SDNode *N) {
1535 return SDNodeIterator(N, N->getNumOperands());
1538 unsigned getOperand() const { return Operand; }
1539 const SDNode *getNode() const { return Node; }
1542 template <> struct GraphTraits<SDNode*> {
1543 typedef SDNode NodeType;
1544 typedef SDNodeIterator ChildIteratorType;
1545 static inline NodeType *getEntryNode(SDNode *N) { return N; }
1546 static inline ChildIteratorType child_begin(NodeType *N) {
1547 return SDNodeIterator::begin(N);
1549 static inline ChildIteratorType child_end(NodeType *N) {
1550 return SDNodeIterator::end(N);
1555 struct ilist_traits<SDNode> {
1556 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1557 static SDNode *getNext(const SDNode *N) { return N->Next; }
1559 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1560 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1562 static SDNode *createSentinel() {
1563 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1565 static void destroySentinel(SDNode *N) { delete N; }
1566 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1569 void addNodeToList(SDNode *NTy) {}
1570 void removeNodeFromList(SDNode *NTy) {}
1571 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1572 const ilist_iterator<SDNode> &X,
1573 const ilist_iterator<SDNode> &Y) {}
1577 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1579 inline bool isNON_EXTLoad(const SDNode *N) {
1580 return N->getOpcode() == ISD::LOAD &&
1581 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1584 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1586 inline bool isEXTLoad(const SDNode *N) {
1587 return N->getOpcode() == ISD::LOAD &&
1588 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1591 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1593 inline bool isSEXTLoad(const SDNode *N) {
1594 return N->getOpcode() == ISD::LOAD &&
1595 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1598 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1600 inline bool isZEXTLoad(const SDNode *N) {
1601 return N->getOpcode() == ISD::LOAD &&
1602 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1605 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1607 inline bool isUNINDEXEDLoad(const SDNode *N) {
1608 return N->getOpcode() == ISD::LOAD &&
1609 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1612 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1614 inline bool isNON_TRUNCStore(const SDNode *N) {
1615 return N->getOpcode() == ISD::STORE &&
1616 !cast<StoreSDNode>(N)->isTruncatingStore();
1619 /// isTRUNCStore - Returns true if the specified node is a truncating
1621 inline bool isTRUNCStore(const SDNode *N) {
1622 return N->getOpcode() == ISD::STORE &&
1623 cast<StoreSDNode>(N)->isTruncatingStore();
1628 } // end llvm namespace