1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG. These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
22 #include "llvm/Value.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator.h"
26 #include "llvm/ADT/APFloat.h"
27 #include "llvm/ADT/APInt.h"
28 #include "llvm/ADT/alist.h"
29 #include "llvm/CodeGen/ValueTypes.h"
30 #include "llvm/CodeGen/MachineMemOperand.h"
31 #include "llvm/Support/Allocator.h"
32 #include "llvm/Support/RecyclingAllocator.h"
33 #include "llvm/Support/DataTypes.h"
40 class MachineBasicBlock;
41 class MachineConstantPoolValue;
43 class CompileUnitDesc;
44 template <typename T> struct DenseMapInfo;
45 template <typename T> struct simplify_type;
47 /// SDVTList - This represents a list of ValueType's that has been intern'd by
48 /// a SelectionDAG. Instances of this simple value class are returned by
49 /// SelectionDAG::getVTList(...).
53 unsigned short NumVTs;
56 /// ISD namespace - This namespace contains an enum which represents all of the
57 /// SelectionDAG node types and value types.
61 //===--------------------------------------------------------------------===//
62 /// ISD::NodeType enum - This enum defines all of the operators valid in a
66 // DELETED_NODE - This is an illegal flag value that is used to catch
67 // errors. This opcode is not a legal opcode for any node.
70 // EntryToken - This is the marker used to indicate the start of the region.
73 // Token factor - This node takes multiple tokens as input and produces a
74 // single token result. This is used to represent the fact that the operand
75 // operators are independent of each other.
78 // AssertSext, AssertZext - These nodes record if a register contains a
79 // value that has already been zero or sign extended from a narrower type.
80 // These nodes take two operands. The first is the node that has already
81 // been extended, and the second is a value type node indicating the width
83 AssertSext, AssertZext,
85 // Various leaf nodes.
86 BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
88 GlobalAddress, GlobalTLSAddress, FrameIndex,
89 JumpTable, ConstantPool, ExternalSymbol,
91 // The address of the GOT
94 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
95 // llvm.returnaddress on the DAG. These nodes take one operand, the index
96 // of the frame or return address to return. An index of zero corresponds
97 // to the current function's frame or return address, an index of one to the
98 // parent's frame or return address, and so on.
99 FRAMEADDR, RETURNADDR,
101 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
102 // first (possible) on-stack argument. This is needed for correct stack
103 // adjustment during unwind.
104 FRAME_TO_ARGS_OFFSET,
106 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
107 // address of the exception block on entry to an landing pad block.
110 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
111 // the selection index of the exception thrown.
114 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
115 // 'eh_return' gcc dwarf builtin, which is used to return from
116 // exception. The general meaning is: adjust stack by OFFSET and pass
117 // execution to HANDLER. Many platform-related details also :)
120 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
121 // simplification of the constant.
125 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
126 // anything else with this node, and this is valid in the target-specific
127 // dag, turning into a GlobalAddress operand.
129 TargetGlobalTLSAddress,
133 TargetExternalSymbol,
135 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
136 /// This node represents a target intrinsic function with no side effects.
137 /// The first operand is the ID number of the intrinsic from the
138 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
139 /// node has returns the result of the intrinsic.
142 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
143 /// This node represents a target intrinsic function with side effects that
144 /// returns a result. The first operand is a chain pointer. The second is
145 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
146 /// operands to the intrinsic follow. The node has two results, the result
147 /// of the intrinsic and an output chain.
150 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
151 /// This node represents a target intrinsic function with side effects that
152 /// does not return a result. The first operand is a chain pointer. The
153 /// second is the ID number of the intrinsic from the llvm::Intrinsic
154 /// namespace. The operands to the intrinsic follow.
157 // CopyToReg - This node has three operands: a chain, a register number to
158 // set to this value, and a value.
161 // CopyFromReg - This node indicates that the input value is a virtual or
162 // physical register that is defined outside of the scope of this
163 // SelectionDAG. The register is available from the RegisterSDNode object.
166 // UNDEF - An undefined node
169 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
170 /// represents the formal arguments for a function. CC# is a Constant value
171 /// indicating the calling convention of the function, and ISVARARG is a
172 /// flag that indicates whether the function is varargs or not. This node
173 /// has one result value for each incoming argument, plus one for the output
174 /// chain. It must be custom legalized. See description of CALL node for
175 /// FLAG argument contents explanation.
179 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
180 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
181 /// This node represents a fully general function call, before the legalizer
182 /// runs. This has one result value for each argument / flag pair, plus
183 /// a chain result. It must be custom legalized. Flag argument indicates
184 /// misc. argument attributes. Currently:
186 /// Bit 1 - 'inreg' attribute
187 /// Bit 2 - 'sret' attribute
188 /// Bit 4 - 'byval' attribute
189 /// Bit 5 - 'nest' attribute
190 /// Bit 6-9 - alignment of byval structures
191 /// Bit 10-26 - size of byval structures
192 /// Bits 31:27 - argument ABI alignment in the first argument piece and
193 /// alignment '1' in other argument pieces.
196 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
197 // a Constant, which is required to be operand #1) half of the integer or
198 // float value specified as operand #0. This is only for use before
199 // legalization, for values that will be broken into multiple registers.
202 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
203 // two values of the same integer value type, this produces a value twice as
204 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
207 // MERGE_VALUES - This node takes multiple discrete operands and returns
208 // them all as its individual results. This nodes has exactly the same
209 // number of inputs and outputs, and is only valid before legalization.
210 // This node is useful for some pieces of the code generator that want to
211 // think about a single node with multiple results, not multiple nodes.
214 // Simple integer binary arithmetic operators.
215 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
217 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
218 // a signed/unsigned value of type i[2*N], and return the full value as
219 // two results, each of type iN.
220 SMUL_LOHI, UMUL_LOHI,
222 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
226 // CARRY_FALSE - This node is used when folding other nodes,
227 // like ADDC/SUBC, which indicate the carry result is always false.
230 // Carry-setting nodes for multiple precision addition and subtraction.
231 // These nodes take two operands of the same value type, and produce two
232 // results. The first result is the normal add or sub result, the second
233 // result is the carry flag result.
236 // Carry-using nodes for multiple precision addition and subtraction. These
237 // nodes take three operands: The first two are the normal lhs and rhs to
238 // the add or sub, and the third is the input carry flag. These nodes
239 // produce two results; the normal result of the add or sub, and the output
240 // carry flag. These nodes both read and write a carry flag to allow them
241 // to them to be chained together for add and sub of arbitrarily large
245 // Simple binary floating point operators.
246 FADD, FSUB, FMUL, FDIV, FREM,
248 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
249 // DAG node does not require that X and Y have the same type, just that they
250 // are both floating point. X and the result must have the same type.
251 // FCOPYSIGN(f32, f64) is allowed.
254 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
255 // value as an integer 0/1 value.
258 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
259 /// with the specified, possibly variable, elements. The number of elements
260 /// is required to be a power of two.
263 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
264 /// at IDX replaced with VAL. If the type of VAL is larger than the vector
265 /// element type then VAL is truncated before replacement.
268 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
269 /// identified by the (potentially variable) element number IDX.
272 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
273 /// vector type with the same length and element type, this produces a
274 /// concatenated vector result value, with length equal to the sum of the
275 /// lengths of the input vectors.
278 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
279 /// vector value) starting with the (potentially variable) element number
280 /// IDX, which must be a multiple of the result vector length.
283 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
284 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
285 /// (maybe of an illegal datatype) or undef that indicate which value each
286 /// result element will get. The elements of VEC1/VEC2 are enumerated in
287 /// order. This is quite similar to the Altivec 'vperm' instruction, except
288 /// that the indices must be constants and are in terms of the element size
289 /// of VEC1/VEC2, not in terms of bytes.
292 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
293 /// scalar value into element 0 of the resultant vector type. The top
294 /// elements 1 to N-1 of the N-element vector are undefined.
297 // EXTRACT_SUBREG - This node is used to extract a sub-register value.
298 // This node takes a superreg and a constant sub-register index as operands.
299 // Note sub-register indices must be increasing. That is, if the
300 // sub-register index of a 8-bit sub-register is N, then the index for a
301 // 16-bit sub-register must be at least N+1.
304 // INSERT_SUBREG - This node is used to insert a sub-register value.
305 // This node takes a superreg, a subreg value, and a constant sub-register
306 // index as operands.
309 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
310 // an unsigned/signed value of type i[2*N], then return the top part.
313 // Bitwise operators - logical and, logical or, logical xor, shift left,
314 // shift right algebraic (shift in sign bits), shift right logical (shift in
315 // zeroes), rotate left, rotate right, and byteswap.
316 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
318 // Counting operators
321 // Select(COND, TRUEVAL, FALSEVAL)
324 // Select with condition operator - This selects between a true value and
325 // a false value (ops #2 and #3) based on the boolean result of comparing
326 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
327 // condition code in op #4, a CondCodeSDNode.
330 // SetCC operator - This evaluates to a boolean (i1) true value if the
331 // condition is true. The operands to this are the left and right operands
332 // to compare (ops #0, and #1) and the condition code to compare them with
333 // (op #2) as a CondCodeSDNode.
336 // Vector SetCC operator - This evaluates to a vector of integer elements
337 // with the high bit in each element set to true if the comparison is true
338 // and false if the comparison is false. All other bits in each element
339 // are undefined. The operands to this are the left and right operands
340 // to compare (ops #0, and #1) and the condition code to compare them with
341 // (op #2) as a CondCodeSDNode.
344 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
345 // integer shift operations, just like ADD/SUB_PARTS. The operation
347 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
348 SHL_PARTS, SRA_PARTS, SRL_PARTS,
350 // Conversion operators. These are all single input single output
351 // operations. For all of these, the result type must be strictly
352 // wider or narrower (depending on the operation) than the source
355 // SIGN_EXTEND - Used for integer types, replicating the sign bit
359 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
362 // ANY_EXTEND - Used for integer types. The high bits are undefined.
365 // TRUNCATE - Completely drop the high bits.
368 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
369 // depends on the first letter) to floating point.
373 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
374 // sign extend a small value in a large integer register (e.g. sign
375 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
376 // with the 7th bit). The size of the smaller type is indicated by the 1th
377 // operand, a ValueType node.
380 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
385 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
386 /// down to the precision of the destination VT. TRUNC is a flag, which is
387 /// always an integer that is zero or one. If TRUNC is 0, this is a
388 /// normal rounding, if it is 1, this FP_ROUND is known to not change the
391 /// The TRUNC = 1 case is used in cases where we know that the value will
392 /// not be modified by the node, because Y is not using any of the extra
393 /// precision of source type. This allows certain transformations like
394 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
395 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
398 // FLT_ROUNDS_ - Returns current rounding mode:
401 // 1 Round to nearest
406 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
407 /// rounds it to a floating point value. It then promotes it and returns it
408 /// in a register of the same size. This operation effectively just
409 /// discards excess precision. The type to round down to is specified by
410 /// the VT operand, a VTSDNode.
413 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
416 // BIT_CONVERT - Theis operator converts between integer and FP values, as
417 // if one was stored to memory as integer and the other was loaded from the
418 // same address (or equivalently for vector format conversions, etc). The
419 // source and result are required to have the same bit size (e.g.
420 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
421 // conversions, but that is a noop, deleted by getNode().
424 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
425 // negation, absolute value, square root, sine and cosine, powi, and pow
427 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
429 // LOAD and STORE have token chains as their first operand, then the same
430 // operands as an LLVM load/store instruction, then an offset node that
431 // is added / subtracted from the base pointer to form the address (for
432 // indexed memory ops).
435 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
436 // to a specified boundary. This node always has two return values: a new
437 // stack pointer value and a chain. The first operand is the token chain,
438 // the second is the number of bytes to allocate, and the third is the
439 // alignment boundary. The size is guaranteed to be a multiple of the stack
440 // alignment, and the alignment is guaranteed to be bigger than the stack
441 // alignment (if required) or 0 to get standard stack alignment.
444 // Control flow instructions. These all have token chains.
446 // BR - Unconditional branch. The first operand is the chain
447 // operand, the second is the MBB to branch to.
450 // BRIND - Indirect branch. The first operand is the chain, the second
451 // is the value to branch to, which must be of the same type as the target's
455 // BR_JT - Jumptable branch. The first operand is the chain, the second
456 // is the jumptable index, the last one is the jumptable entry index.
459 // BRCOND - Conditional branch. The first operand is the chain,
460 // the second is the condition, the third is the block to branch
461 // to if the condition is true.
464 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
465 // that the condition is represented as condition code, and two nodes to
466 // compare, rather than as a combined SetCC node. The operands in order are
467 // chain, cc, lhs, rhs, block to branch to if condition is true.
470 // RET - Return from function. The first operand is the chain,
471 // and any subsequent operands are pairs of return value and return value
472 // signness for the function. This operation can have variable number of
476 // INLINEASM - Represents an inline asm block. This node always has two
477 // return values: a chain and a flag result. The inputs are as follows:
478 // Operand #0 : Input chain.
479 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
480 // Operand #2n+2: A RegisterNode.
481 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
482 // Operand #last: Optional, an incoming flag.
485 // DBG_LABEL, EH_LABEL - Represents a label in mid basic block used to track
486 // locations needed for debug and exception handling tables. These nodes
487 // take a chain as input and return a chain.
491 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
492 // local variable declarations for debugging information. First operand is
493 // a chain, while the next two operands are first two arguments (address
494 // and variable) of a llvm.dbg.declare instruction.
497 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
498 // value, the same type as the pointer type for the system, and an output
502 // STACKRESTORE has two operands, an input chain and a pointer to restore to
503 // it returns an output chain.
506 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
507 // a call sequence, and carry arbitrary information that target might want
508 // to know. The first operand is a chain, the rest are specified by the
509 // target and not touched by the DAG optimizers.
510 // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
511 CALLSEQ_START, // Beginning of a call sequence
512 CALLSEQ_END, // End of a call sequence
514 // VAARG - VAARG has three operands: an input chain, a pointer, and a
515 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
518 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
519 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
523 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
524 // pointer, and a SRCVALUE.
527 // SRCVALUE - This is a node type that holds a Value* that is used to
528 // make reference to a value in the LLVM IR.
531 // MEMOPERAND - This is a node that contains a MachineMemOperand which
532 // records information about a memory reference. This is used to make
533 // AliasAnalysis queries from the backend.
536 // PCMARKER - This corresponds to the pcmarker intrinsic.
539 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
540 // The only operand is a chain and a value and a chain are produced. The
541 // value is the contents of the architecture specific cycle counter like
542 // register (or other high accuracy low latency clock source)
545 // HANDLENODE node - Used as a handle for various purposes.
548 // DBG_STOPPOINT - This node is used to represent a source location for
549 // debug info. It takes token chain as input, and carries a line number,
550 // column number, and a pointer to a CompileUnitDesc object identifying
551 // the containing compilation unit. It produces a token chain as output.
554 // DEBUG_LOC - This node is used to represent source line information
555 // embedded in the code. It takes a token chain as input, then a line
556 // number, then a column then a file id (provided by MachineModuleInfo.) It
557 // produces a token chain as output.
560 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
561 // It takes as input a token chain, the pointer to the trampoline,
562 // the pointer to the nested function, the pointer to pass for the
563 // 'nest' parameter, a SRCVALUE for the trampoline and another for
564 // the nested function (allowing targets to access the original
565 // Function*). It produces the result of the intrinsic and a token
569 // TRAP - Trapping instruction
572 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
573 // their first operand. The other operands are the address to prefetch,
574 // read / write specifier, and locality specifier.
577 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
578 // store-store, device)
579 // This corresponds to the memory.barrier intrinsic.
580 // it takes an input chain, 4 operands to specify the type of barrier, an
581 // operand specifying if the barrier applies to device and uncached memory
582 // and produces an output chain.
585 // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
586 // this corresponds to the atomic.lcs intrinsic.
587 // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
588 // the return is always the original value in *ptr
591 // Val, OUTCHAIN = ATOMIC_LOAD_ADD(INCHAIN, ptr, amt)
592 // this corresponds to the atomic.las intrinsic.
593 // *ptr + amt is stored to *ptr atomically.
594 // the return is always the original value in *ptr
597 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
598 // this corresponds to the atomic.swap intrinsic.
599 // amt is stored to *ptr atomically.
600 // the return is always the original value in *ptr
603 // Val, OUTCHAIN = ATOMIC_LOAD_SUB(INCHAIN, ptr, amt)
604 // this corresponds to the atomic.lss intrinsic.
605 // *ptr - amt is stored to *ptr atomically.
606 // the return is always the original value in *ptr
609 // Val, OUTCHAIN = ATOMIC_L[OpName]S(INCHAIN, ptr, amt)
610 // this corresponds to the atomic.[OpName] intrinsic.
611 // op(*ptr, amt) is stored to *ptr atomically.
612 // the return is always the original value in *ptr
622 // BUILTIN_OP_END - This must be the last enum value in this list.
628 /// isBuildVectorAllOnes - Return true if the specified node is a
629 /// BUILD_VECTOR where all of the elements are ~0 or undef.
630 bool isBuildVectorAllOnes(const SDNode *N);
632 /// isBuildVectorAllZeros - Return true if the specified node is a
633 /// BUILD_VECTOR where all of the elements are 0 or undef.
634 bool isBuildVectorAllZeros(const SDNode *N);
636 /// isScalarToVector - Return true if the specified node is a
637 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
638 /// element is not an undef.
639 bool isScalarToVector(const SDNode *N);
641 /// isDebugLabel - Return true if the specified node represents a debug
642 /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node).
643 bool isDebugLabel(const SDNode *N);
645 //===--------------------------------------------------------------------===//
646 /// MemIndexedMode enum - This enum defines the load / store indexed
647 /// addressing modes.
649 /// UNINDEXED "Normal" load / store. The effective address is already
650 /// computed and is available in the base pointer. The offset
651 /// operand is always undefined. In addition to producing a
652 /// chain, an unindexed load produces one value (result of the
653 /// load); an unindexed store does not produce a value.
655 /// PRE_INC Similar to the unindexed mode where the effective address is
656 /// PRE_DEC the value of the base pointer add / subtract the offset.
657 /// It considers the computation as being folded into the load /
658 /// store operation (i.e. the load / store does the address
659 /// computation as well as performing the memory transaction).
660 /// The base operand is always undefined. In addition to
661 /// producing a chain, pre-indexed load produces two values
662 /// (result of the load and the result of the address
663 /// computation); a pre-indexed store produces one value (result
664 /// of the address computation).
666 /// POST_INC The effective address is the value of the base pointer. The
667 /// POST_DEC value of the offset operand is then added to / subtracted
668 /// from the base after memory transaction. In addition to
669 /// producing a chain, post-indexed load produces two values
670 /// (the result of the load and the result of the base +/- offset
671 /// computation); a post-indexed store produces one value (the
672 /// the result of the base +/- offset computation).
674 enum MemIndexedMode {
683 //===--------------------------------------------------------------------===//
684 /// LoadExtType enum - This enum defines the three variants of LOADEXT
685 /// (load with extension).
687 /// SEXTLOAD loads the integer operand and sign extends it to a larger
688 /// integer result type.
689 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
690 /// integer result type.
691 /// EXTLOAD is used for three things: floating point extending loads,
692 /// integer extending loads [the top bits are undefined], and vector
693 /// extending loads [load into low elt].
703 //===--------------------------------------------------------------------===//
704 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
705 /// below work out, when considering SETFALSE (something that never exists
706 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
707 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
708 /// to. If the "N" column is 1, the result of the comparison is undefined if
709 /// the input is a NAN.
711 /// All of these (except for the 'always folded ops') should be handled for
712 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
713 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
715 /// Note that these are laid out in a specific order to allow bit-twiddling
716 /// to transform conditions.
718 // Opcode N U L G E Intuitive operation
719 SETFALSE, // 0 0 0 0 Always false (always folded)
720 SETOEQ, // 0 0 0 1 True if ordered and equal
721 SETOGT, // 0 0 1 0 True if ordered and greater than
722 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
723 SETOLT, // 0 1 0 0 True if ordered and less than
724 SETOLE, // 0 1 0 1 True if ordered and less than or equal
725 SETONE, // 0 1 1 0 True if ordered and operands are unequal
726 SETO, // 0 1 1 1 True if ordered (no nans)
727 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
728 SETUEQ, // 1 0 0 1 True if unordered or equal
729 SETUGT, // 1 0 1 0 True if unordered or greater than
730 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
731 SETULT, // 1 1 0 0 True if unordered or less than
732 SETULE, // 1 1 0 1 True if unordered, less than, or equal
733 SETUNE, // 1 1 1 0 True if unordered or not equal
734 SETTRUE, // 1 1 1 1 Always true (always folded)
735 // Don't care operations: undefined if the input is a nan.
736 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
737 SETEQ, // 1 X 0 0 1 True if equal
738 SETGT, // 1 X 0 1 0 True if greater than
739 SETGE, // 1 X 0 1 1 True if greater than or equal
740 SETLT, // 1 X 1 0 0 True if less than
741 SETLE, // 1 X 1 0 1 True if less than or equal
742 SETNE, // 1 X 1 1 0 True if not equal
743 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
745 SETCC_INVALID // Marker value.
748 /// isSignedIntSetCC - Return true if this is a setcc instruction that
749 /// performs a signed comparison when used with integer operands.
750 inline bool isSignedIntSetCC(CondCode Code) {
751 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
754 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
755 /// performs an unsigned comparison when used with integer operands.
756 inline bool isUnsignedIntSetCC(CondCode Code) {
757 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
760 /// isTrueWhenEqual - Return true if the specified condition returns true if
761 /// the two operands to the condition are equal. Note that if one of the two
762 /// operands is a NaN, this value is meaningless.
763 inline bool isTrueWhenEqual(CondCode Cond) {
764 return ((int)Cond & 1) != 0;
767 /// getUnorderedFlavor - This function returns 0 if the condition is always
768 /// false if an operand is a NaN, 1 if the condition is always true if the
769 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
771 inline unsigned getUnorderedFlavor(CondCode Cond) {
772 return ((int)Cond >> 3) & 3;
775 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
776 /// 'op' is a valid SetCC operation.
777 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
779 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
780 /// when given the operation for (X op Y).
781 CondCode getSetCCSwappedOperands(CondCode Operation);
783 /// getSetCCOrOperation - Return the result of a logical OR between different
784 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
785 /// function returns SETCC_INVALID if it is not possible to represent the
786 /// resultant comparison.
787 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
789 /// getSetCCAndOperation - Return the result of a logical AND between
790 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
791 /// function returns SETCC_INVALID if it is not possible to represent the
792 /// resultant comparison.
793 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
794 } // end llvm::ISD namespace
797 //===----------------------------------------------------------------------===//
798 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
799 /// values as the result of a computation. Many nodes return multiple values,
800 /// from loads (which define a token and a return value) to ADDC (which returns
801 /// a result and a carry value), to calls (which may return an arbitrary number
804 /// As such, each use of a SelectionDAG computation must indicate the node that
805 /// computes it as well as which return value to use from that node. This pair
806 /// of information is represented with the SDOperand value type.
810 SDNode *Val; // The node defining the value we are using.
811 unsigned ResNo; // Which return value of the node we are using.
813 SDOperand() : Val(0), ResNo(0) {}
814 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
816 bool operator==(const SDOperand &O) const {
817 return Val == O.Val && ResNo == O.ResNo;
819 bool operator!=(const SDOperand &O) const {
820 return !operator==(O);
822 bool operator<(const SDOperand &O) const {
823 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
826 SDOperand getValue(unsigned R) const {
827 return SDOperand(Val, R);
830 // isOperandOf - Return true if this node is an operand of N.
831 bool isOperandOf(SDNode *N) const;
833 /// getValueType - Return the ValueType of the referenced return value.
835 inline MVT getValueType() const;
837 /// getValueSizeInBits - Returns the size of the value in bits.
839 unsigned getValueSizeInBits() const {
840 return getValueType().getSizeInBits();
843 // Forwarding methods - These forward to the corresponding methods in SDNode.
844 inline unsigned getOpcode() const;
845 inline unsigned getNumOperands() const;
846 inline const SDOperand &getOperand(unsigned i) const;
847 inline uint64_t getConstantOperandVal(unsigned i) const;
848 inline bool isTargetOpcode() const;
849 inline bool isMachineOpcode() const;
850 inline unsigned getMachineOpcode() const;
853 /// reachesChainWithoutSideEffects - Return true if this operand (which must
854 /// be a chain) reaches the specified operand without crossing any
855 /// side-effecting instructions. In practice, this looks through token
856 /// factors and non-volatile loads. In order to remain efficient, this only
857 /// looks a couple of nodes in, it does not do an exhaustive search.
858 bool reachesChainWithoutSideEffects(SDOperand Dest,
859 unsigned Depth = 2) const;
861 /// hasOneUse - Return true if there is exactly one operation using this
862 /// result value of the defining operator.
863 inline bool hasOneUse() const;
865 /// use_empty - Return true if there are no operations using this
866 /// result value of the defining operator.
867 inline bool use_empty() const;
871 template<> struct DenseMapInfo<SDOperand> {
872 static inline SDOperand getEmptyKey() {
873 return SDOperand((SDNode*)-1, -1U);
875 static inline SDOperand getTombstoneKey() {
876 return SDOperand((SDNode*)-1, 0);
878 static unsigned getHashValue(const SDOperand &Val) {
879 return ((unsigned)((uintptr_t)Val.Val >> 4) ^
880 (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo;
882 static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
885 static bool isPod() { return true; }
888 /// simplify_type specializations - Allow casting operators to work directly on
889 /// SDOperands as if they were SDNode*'s.
890 template<> struct simplify_type<SDOperand> {
891 typedef SDNode* SimpleType;
892 static SimpleType getSimplifiedValue(const SDOperand &Val) {
893 return static_cast<SimpleType>(Val.Val);
896 template<> struct simplify_type<const SDOperand> {
897 typedef SDNode* SimpleType;
898 static SimpleType getSimplifiedValue(const SDOperand &Val) {
899 return static_cast<SimpleType>(Val.Val);
903 /// SDUse - Represents a use of the SDNode referred by
907 /// User - Parent node of this operand.
909 /// Prev, next - Pointers to the uses list of the SDNode referred by
914 SDUse(): Operand(), User(NULL), Prev(NULL), Next(NULL) {}
916 SDUse(SDNode *val, unsigned resno) :
917 Operand(val,resno), User(NULL), Prev(NULL), Next(NULL) {}
919 SDUse& operator= (const SDOperand& Op) {
926 SDUse& operator= (const SDUse& Op) {
933 SDUse * getNext() { return Next; }
935 SDNode *getUser() { return User; }
937 void setUser(SDNode *p) { User = p; }
939 operator SDOperand() const { return Operand; }
941 const SDOperand& getSDOperand() const { return Operand; }
943 SDNode* &getVal () { return Operand.Val; }
945 bool operator==(const SDOperand &O) const {
949 bool operator!=(const SDOperand &O) const {
950 return !(Operand == O);
953 bool operator<(const SDOperand &O) const {
958 void addToList(SDUse **List) {
960 if (Next) Next->Prev = &Next;
965 void removeFromList() {
967 if (Next) Next->Prev = Prev;
972 /// simplify_type specializations - Allow casting operators to work directly on
973 /// SDOperands as if they were SDNode*'s.
974 template<> struct simplify_type<SDUse> {
975 typedef SDNode* SimpleType;
976 static SimpleType getSimplifiedValue(const SDUse &Val) {
977 return static_cast<SimpleType>(Val.getSDOperand().Val);
980 template<> struct simplify_type<const SDUse> {
981 typedef SDNode* SimpleType;
982 static SimpleType getSimplifiedValue(const SDUse &Val) {
983 return static_cast<SimpleType>(Val.getSDOperand().Val);
988 /// SDOperandPtr - A helper SDOperand pointer class, that can handle
989 /// arrays of SDUse and arrays of SDOperand objects. This is required
990 /// in many places inside the SelectionDAG.
993 const SDOperand *ptr; // The pointer to the SDOperand object
994 int object_size; // The size of the object containg the SDOperand
996 SDOperandPtr() : ptr(0), object_size(0) {}
998 SDOperandPtr(SDUse * use_ptr) {
999 ptr = &use_ptr->getSDOperand();
1000 object_size = (int)sizeof(SDUse);
1003 SDOperandPtr(const SDOperand * op_ptr) {
1005 object_size = (int)sizeof(SDOperand);
1008 const SDOperand operator *() { return *ptr; }
1009 const SDOperand *operator ->() { return ptr; }
1010 SDOperandPtr operator ++ () {
1011 ptr = (SDOperand*)((char *)ptr + object_size);
1015 SDOperandPtr operator ++ (int) {
1016 SDOperandPtr tmp = *this;
1017 ptr = (SDOperand*)((char *)ptr + object_size);
1021 SDOperand operator[] (int idx) const {
1022 return *(SDOperand*)((char*) ptr + object_size * idx);
1026 /// SDNode - Represents one node in the SelectionDAG.
1028 class SDNode : public FoldingSetNode {
1030 /// NodeType - The operation that this node performs.
1034 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true,
1035 /// then they will be delete[]'d when the node is destroyed.
1036 unsigned short OperandsNeedDelete : 1;
1039 /// SubclassData - This member is defined by this class, but is not used for
1040 /// anything. Subclasses can use it to hold whatever state they find useful.
1041 /// This field is initialized to zero by the ctor.
1042 unsigned short SubclassData : 15;
1045 /// NodeId - Unique id per SDNode in the DAG.
1048 /// OperandList - The values that are used by this operation.
1052 /// ValueList - The types of the values this node defines. SDNode's may
1053 /// define multiple values simultaneously.
1054 const MVT *ValueList;
1056 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1057 unsigned short NumOperands, NumValues;
1059 /// Uses - List of uses for this SDNode.
1062 /// addUse - add SDUse to the list of uses.
1063 void addUse(SDUse &U) { U.addToList(&Uses); }
1065 // Out-of-line virtual method to give class a home.
1066 virtual void ANCHOR();
1069 assert(NumOperands == 0 && "Operand list not cleared before deletion");
1070 NodeType = ISD::DELETED_NODE;
1073 //===--------------------------------------------------------------------===//
1077 /// getOpcode - Return the SelectionDAG opcode value for this node. For
1078 /// pre-isel nodes (those for which isMachineOpcode returns false), these
1079 /// are the opcode values in the ISD and <target>ISD namespaces. For
1080 /// post-isel opcodes, see getMachineOpcode.
1081 unsigned getOpcode() const { return (unsigned short)NodeType; }
1083 /// isTargetOpcode - Test if this node has a target-specific opcode (in the
1084 /// <target>ISD namespace).
1085 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1087 /// isMachineOpcode - Test if this node has a post-isel opcode, directly
1088 /// corresponding to a MachineInstr opcode.
1089 bool isMachineOpcode() const { return NodeType < 0; }
1091 /// getMachineOpcode - This may only be called if isMachineOpcode returns
1092 /// true. It returns the MachineInstr opcode value that the node's opcode
1094 unsigned getMachineOpcode() const {
1095 assert(isMachineOpcode() && "Not a target opcode!");
1099 size_t use_size() const { return std::distance(use_begin(), use_end()); }
1100 bool use_empty() const { return Uses == NULL; }
1101 bool hasOneUse() const {
1102 return !use_empty() && next(use_begin()) == use_end();
1105 /// getNodeId - Return the unique node id.
1107 int getNodeId() const { return NodeId; }
1109 /// setNodeId - Set unique node id.
1110 void setNodeId(int Id) { NodeId = Id; }
1112 /// use_iterator - This class provides iterator support for SDUse
1113 /// operands that use a specific SDNode.
1115 : public forward_iterator<SDUse, ptrdiff_t> {
1117 explicit use_iterator(SDUse *op) : Op(op) {
1119 friend class SDNode;
1121 typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
1122 typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1124 use_iterator(const use_iterator &I) : Op(I.Op) {}
1125 use_iterator() : Op(0) {}
1127 bool operator==(const use_iterator &x) const {
1130 bool operator!=(const use_iterator &x) const {
1131 return !operator==(x);
1134 /// atEnd - return true if this iterator is at the end of uses list.
1135 bool atEnd() const { return Op == 0; }
1137 // Iterator traversal: forward iteration only.
1138 use_iterator &operator++() { // Preincrement
1139 assert(Op && "Cannot increment end iterator!");
1144 use_iterator operator++(int) { // Postincrement
1145 use_iterator tmp = *this; ++*this; return tmp;
1149 /// getOperandNum - Retrive a number of a current operand.
1150 unsigned getOperandNum() const {
1151 assert(Op && "Cannot dereference end iterator!");
1152 return (unsigned)(Op - Op->getUser()->OperandList);
1155 /// Retrieve a reference to the current operand.
1156 SDUse &operator*() const {
1157 assert(Op && "Cannot dereference end iterator!");
1161 /// Retrieve a pointer to the current operand.
1162 SDUse *operator->() const {
1163 assert(Op && "Cannot dereference end iterator!");
1168 /// use_begin/use_end - Provide iteration support to walk over all uses
1171 use_iterator use_begin(SDNode *node) const {
1172 return use_iterator(node->Uses);
1175 use_iterator use_begin() const {
1176 return use_iterator(Uses);
1179 static use_iterator use_end() { return use_iterator(0); }
1182 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1183 /// indicated value. This method ignores uses of other values defined by this
1185 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1187 /// hasAnyUseOfValue - Return true if there are any use of the indicated
1188 /// value. This method ignores uses of other values defined by this operation.
1189 bool hasAnyUseOfValue(unsigned Value) const;
1191 /// isOnlyUseOf - Return true if this node is the only use of N.
1193 bool isOnlyUseOf(SDNode *N) const;
1195 /// isOperandOf - Return true if this node is an operand of N.
1197 bool isOperandOf(SDNode *N) const;
1199 /// isPredecessorOf - Return true if this node is a predecessor of N. This
1200 /// node is either an operand of N or it can be reached by recursively
1201 /// traversing up the operands.
1202 /// NOTE: this is an expensive method. Use it carefully.
1203 bool isPredecessorOf(SDNode *N) const;
1205 /// getNumOperands - Return the number of values used by this operation.
1207 unsigned getNumOperands() const { return NumOperands; }
1209 /// getConstantOperandVal - Helper method returns the integer value of a
1210 /// ConstantSDNode operand.
1211 uint64_t getConstantOperandVal(unsigned Num) const;
1213 const SDOperand &getOperand(unsigned Num) const {
1214 assert(Num < NumOperands && "Invalid child # of SDNode!");
1215 return OperandList[Num].getSDOperand();
1218 typedef SDUse* op_iterator;
1219 op_iterator op_begin() const { return OperandList; }
1220 op_iterator op_end() const { return OperandList+NumOperands; }
1223 SDVTList getVTList() const {
1224 SDVTList X = { ValueList, NumValues };
1228 /// getNumValues - Return the number of values defined/returned by this
1231 unsigned getNumValues() const { return NumValues; }
1233 /// getValueType - Return the type of a specified result.
1235 MVT getValueType(unsigned ResNo) const {
1236 assert(ResNo < NumValues && "Illegal result number!");
1237 return ValueList[ResNo];
1240 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1242 unsigned getValueSizeInBits(unsigned ResNo) const {
1243 return getValueType(ResNo).getSizeInBits();
1246 typedef const MVT* value_iterator;
1247 value_iterator value_begin() const { return ValueList; }
1248 value_iterator value_end() const { return ValueList+NumValues; }
1250 /// getOperationName - Return the opcode of this operation for printing.
1252 std::string getOperationName(const SelectionDAG *G = 0) const;
1253 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1255 void dump(const SelectionDAG *G) const;
1257 static bool classof(const SDNode *) { return true; }
1259 /// Profile - Gather unique data for the node.
1261 void Profile(FoldingSetNodeID &ID);
1264 friend class SelectionDAG;
1266 /// getValueTypeList - Return a pointer to the specified value type.
1268 static const MVT *getValueTypeList(MVT VT);
1269 static SDVTList getSDVTList(MVT VT) {
1270 SDVTList Ret = { getValueTypeList(VT), 1 };
1274 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
1275 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1276 NodeId(-1), Uses(NULL) {
1277 NumOperands = NumOps;
1278 OperandList = NumOps ? new SDUse[NumOperands] : 0;
1280 for (unsigned i = 0; i != NumOps; ++i) {
1281 OperandList[i] = Ops[i];
1282 OperandList[i].setUser(this);
1283 Ops[i].Val->addUse(OperandList[i]);
1286 ValueList = VTs.VTs;
1287 NumValues = VTs.NumVTs;
1290 SDNode(unsigned Opc, SDVTList VTs, const SDUse *Ops, unsigned NumOps)
1291 : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1292 NodeId(-1), Uses(NULL) {
1293 OperandsNeedDelete = true;
1294 NumOperands = NumOps;
1295 OperandList = NumOps ? new SDUse[NumOperands] : 0;
1297 for (unsigned i = 0; i != NumOps; ++i) {
1298 OperandList[i] = Ops[i];
1299 OperandList[i].setUser(this);
1300 Ops[i].getSDOperand().Val->addUse(OperandList[i]);
1303 ValueList = VTs.VTs;
1304 NumValues = VTs.NumVTs;
1307 /// This constructor adds no operands itself; operands can be
1308 /// set later with InitOperands.
1309 SDNode(unsigned Opc, SDVTList VTs)
1310 : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1311 NodeId(-1), Uses(NULL) {
1314 ValueList = VTs.VTs;
1315 NumValues = VTs.NumVTs;
1318 /// InitOperands - Initialize the operands list of this node with the
1319 /// specified values, which are part of the node (thus they don't need to be
1320 /// copied in or allocated).
1321 void InitOperands(SDUse *Ops, unsigned NumOps) {
1322 assert(OperandList == 0 && "Operands already set!");
1323 NumOperands = NumOps;
1327 for (unsigned i = 0; i != NumOps; ++i) {
1328 OperandList[i].setUser(this);
1329 Ops[i].getVal()->addUse(OperandList[i]);
1333 /// DropOperands - Release the operands and set this node to have
1335 void DropOperands();
1337 void addUser(unsigned i, SDNode *User) {
1338 assert(User->OperandList[i].getUser() && "Node without parent");
1339 addUse(User->OperandList[i]);
1342 void removeUser(unsigned i, SDNode *User) {
1343 assert(User->OperandList[i].getUser() && "Node without parent");
1344 SDUse &Op = User->OperandList[i];
1345 Op.removeFromList();
1350 // Define inline functions from the SDOperand class.
1352 inline unsigned SDOperand::getOpcode() const {
1353 return Val->getOpcode();
1355 inline MVT SDOperand::getValueType() const {
1356 return Val->getValueType(ResNo);
1358 inline unsigned SDOperand::getNumOperands() const {
1359 return Val->getNumOperands();
1361 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1362 return Val->getOperand(i);
1364 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1365 return Val->getConstantOperandVal(i);
1367 inline bool SDOperand::isTargetOpcode() const {
1368 return Val->isTargetOpcode();
1370 inline bool SDOperand::isMachineOpcode() const {
1371 return Val->isMachineOpcode();
1373 inline unsigned SDOperand::getMachineOpcode() const {
1374 return Val->getMachineOpcode();
1376 inline bool SDOperand::hasOneUse() const {
1377 return Val->hasNUsesOfValue(1, ResNo);
1379 inline bool SDOperand::use_empty() const {
1380 return !Val->hasAnyUseOfValue(ResNo);
1383 /// UnarySDNode - This class is used for single-operand SDNodes. This is solely
1384 /// to allow co-allocation of node operands with the node itself.
1385 class UnarySDNode : public SDNode {
1386 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1389 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1390 : SDNode(Opc, VTs) {
1392 InitOperands(&Op, 1);
1396 /// BinarySDNode - This class is used for two-operand SDNodes. This is solely
1397 /// to allow co-allocation of node operands with the node itself.
1398 class BinarySDNode : public SDNode {
1399 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1402 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1403 : SDNode(Opc, VTs) {
1406 InitOperands(Ops, 2);
1410 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1411 /// to allow co-allocation of node operands with the node itself.
1412 class TernarySDNode : public SDNode {
1413 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1416 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1418 : SDNode(Opc, VTs) {
1422 InitOperands(Ops, 3);
1427 /// HandleSDNode - This class is used to form a handle around another node that
1428 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1429 /// operand. This node should be directly created by end-users and not added to
1430 /// the AllNodes list.
1431 class HandleSDNode : public SDNode {
1432 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1435 // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1438 explicit __attribute__((__noinline__)) HandleSDNode(SDOperand X)
1440 explicit HandleSDNode(SDOperand X)
1442 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
1444 InitOperands(&Op, 1);
1447 SDUse getValue() const { return Op; }
1450 /// Abstact virtual class for operations for memory operations
1451 class MemSDNode : public SDNode {
1452 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1455 // MemoryVT - VT of in-memory value.
1458 //! SrcValue - Memory location for alias analysis.
1459 const Value *SrcValue;
1461 //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
1464 /// Flags - the low bit indicates whether this is a volatile reference;
1465 /// the remainder is a log2 encoding of the alignment in bytes.
1469 MemSDNode(unsigned Opc, SDVTList VTs, MVT MemoryVT,
1470 const Value *srcValue, int SVOff,
1471 unsigned alignment, bool isvolatile);
1473 /// Returns alignment and volatility of the memory access
1474 unsigned getAlignment() const { return (1u << (Flags >> 1)) >> 1; }
1475 bool isVolatile() const { return Flags & 1; }
1477 /// Returns the SrcValue and offset that describes the location of the access
1478 const Value *getSrcValue() const { return SrcValue; }
1479 int getSrcValueOffset() const { return SVOffset; }
1481 /// getMemoryVT - Return the type of the in-memory value.
1482 MVT getMemoryVT() const { return MemoryVT; }
1484 /// getMemOperand - Return a MachineMemOperand object describing the memory
1485 /// reference performed by operation.
1486 MachineMemOperand getMemOperand() const;
1488 const SDOperand &getChain() const { return getOperand(0); }
1489 const SDOperand &getBasePtr() const {
1490 return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1493 // Methods to support isa and dyn_cast
1494 static bool classof(const MemSDNode *) { return true; }
1495 static bool classof(const SDNode *N) {
1496 return N->getOpcode() == ISD::LOAD ||
1497 N->getOpcode() == ISD::STORE ||
1498 N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1499 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1500 N->getOpcode() == ISD::ATOMIC_SWAP ||
1501 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1502 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1503 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1504 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1505 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1506 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1507 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1508 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1509 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1513 /// Atomic operations node
1514 class AtomicSDNode : public MemSDNode {
1515 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1519 // Opc: opcode for atomic
1520 // VTL: value type list
1521 // Chain: memory chain for operaand
1522 // Ptr: address to update as a SDOperand
1523 // Cmp: compare value
1525 // SrcVal: address to update as a Value (used for MemOperand)
1526 // Align: alignment of memory
1527 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1528 SDOperand Cmp, SDOperand Swp, const Value* SrcVal,
1530 : MemSDNode(Opc, VTL, Cmp.getValueType(), SrcVal, /*SVOffset=*/0,
1531 Align, /*isVolatile=*/true) {
1536 InitOperands(Ops, 4);
1538 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1539 SDOperand Val, const Value* SrcVal, unsigned Align=0)
1540 : MemSDNode(Opc, VTL, Val.getValueType(), SrcVal, /*SVOffset=*/0,
1541 Align, /*isVolatile=*/true) {
1545 InitOperands(Ops, 3);
1548 const SDOperand &getBasePtr() const { return getOperand(1); }
1549 const SDOperand &getVal() const { return getOperand(2); }
1551 bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_CMP_SWAP; }
1553 // Methods to support isa and dyn_cast
1554 static bool classof(const AtomicSDNode *) { return true; }
1555 static bool classof(const SDNode *N) {
1556 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP ||
1557 N->getOpcode() == ISD::ATOMIC_LOAD_ADD ||
1558 N->getOpcode() == ISD::ATOMIC_SWAP ||
1559 N->getOpcode() == ISD::ATOMIC_LOAD_SUB ||
1560 N->getOpcode() == ISD::ATOMIC_LOAD_AND ||
1561 N->getOpcode() == ISD::ATOMIC_LOAD_OR ||
1562 N->getOpcode() == ISD::ATOMIC_LOAD_XOR ||
1563 N->getOpcode() == ISD::ATOMIC_LOAD_NAND ||
1564 N->getOpcode() == ISD::ATOMIC_LOAD_MIN ||
1565 N->getOpcode() == ISD::ATOMIC_LOAD_MAX ||
1566 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN ||
1567 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1571 class ConstantSDNode : public SDNode {
1573 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1575 friend class SelectionDAG;
1576 ConstantSDNode(bool isTarget, const APInt &val, MVT VT)
1577 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1582 const APInt &getAPIntValue() const { return Value; }
1583 uint64_t getValue() const { return Value.getZExtValue(); }
1585 int64_t getSignExtended() const {
1586 unsigned Bits = getValueType(0).getSizeInBits();
1587 return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1590 bool isNullValue() const { return Value == 0; }
1591 bool isAllOnesValue() const {
1592 return Value == getValueType(0).getIntegerVTBitMask();
1595 static bool classof(const ConstantSDNode *) { return true; }
1596 static bool classof(const SDNode *N) {
1597 return N->getOpcode() == ISD::Constant ||
1598 N->getOpcode() == ISD::TargetConstant;
1602 class ConstantFPSDNode : public SDNode {
1604 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1606 friend class SelectionDAG;
1607 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT VT)
1608 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1609 getSDVTList(VT)), Value(val) {
1613 const APFloat& getValueAPF() const { return Value; }
1615 /// isExactlyValue - We don't rely on operator== working on double values, as
1616 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1617 /// As such, this method can be used to do an exact bit-for-bit comparison of
1618 /// two floating point values.
1620 /// We leave the version with the double argument here because it's just so
1621 /// convenient to write "2.0" and the like. Without this function we'd
1622 /// have to duplicate its logic everywhere it's called.
1623 bool isExactlyValue(double V) const {
1624 // convert is not supported on this type
1625 if (&Value.getSemantics() == &APFloat::PPCDoubleDouble)
1628 Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1629 return isExactlyValue(Tmp);
1631 bool isExactlyValue(const APFloat& V) const;
1633 bool isValueValidForType(MVT VT, const APFloat& Val);
1635 static bool classof(const ConstantFPSDNode *) { return true; }
1636 static bool classof(const SDNode *N) {
1637 return N->getOpcode() == ISD::ConstantFP ||
1638 N->getOpcode() == ISD::TargetConstantFP;
1642 class GlobalAddressSDNode : public SDNode {
1643 GlobalValue *TheGlobal;
1645 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1647 friend class SelectionDAG;
1648 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT, int o = 0);
1651 GlobalValue *getGlobal() const { return TheGlobal; }
1652 int getOffset() const { return Offset; }
1654 static bool classof(const GlobalAddressSDNode *) { return true; }
1655 static bool classof(const SDNode *N) {
1656 return N->getOpcode() == ISD::GlobalAddress ||
1657 N->getOpcode() == ISD::TargetGlobalAddress ||
1658 N->getOpcode() == ISD::GlobalTLSAddress ||
1659 N->getOpcode() == ISD::TargetGlobalTLSAddress;
1663 class FrameIndexSDNode : public SDNode {
1665 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1667 friend class SelectionDAG;
1668 FrameIndexSDNode(int fi, MVT VT, bool isTarg)
1669 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1674 int getIndex() const { return FI; }
1676 static bool classof(const FrameIndexSDNode *) { return true; }
1677 static bool classof(const SDNode *N) {
1678 return N->getOpcode() == ISD::FrameIndex ||
1679 N->getOpcode() == ISD::TargetFrameIndex;
1683 class JumpTableSDNode : public SDNode {
1685 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1687 friend class SelectionDAG;
1688 JumpTableSDNode(int jti, MVT VT, bool isTarg)
1689 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1694 int getIndex() const { return JTI; }
1696 static bool classof(const JumpTableSDNode *) { return true; }
1697 static bool classof(const SDNode *N) {
1698 return N->getOpcode() == ISD::JumpTable ||
1699 N->getOpcode() == ISD::TargetJumpTable;
1703 class ConstantPoolSDNode : public SDNode {
1706 MachineConstantPoolValue *MachineCPVal;
1708 int Offset; // It's a MachineConstantPoolValue if top bit is set.
1710 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1712 friend class SelectionDAG;
1713 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0)
1714 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1715 getSDVTList(VT)), Offset(o), Alignment(0) {
1716 assert((int)Offset >= 0 && "Offset is too large");
1719 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o, unsigned Align)
1720 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1721 getSDVTList(VT)), Offset(o), Alignment(Align) {
1722 assert((int)Offset >= 0 && "Offset is too large");
1725 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1727 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1728 getSDVTList(VT)), Offset(o), Alignment(0) {
1729 assert((int)Offset >= 0 && "Offset is too large");
1730 Val.MachineCPVal = v;
1731 Offset |= 1 << (sizeof(unsigned)*8-1);
1733 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1734 MVT VT, int o, unsigned Align)
1735 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1736 getSDVTList(VT)), Offset(o), Alignment(Align) {
1737 assert((int)Offset >= 0 && "Offset is too large");
1738 Val.MachineCPVal = v;
1739 Offset |= 1 << (sizeof(unsigned)*8-1);
1743 bool isMachineConstantPoolEntry() const {
1744 return (int)Offset < 0;
1747 Constant *getConstVal() const {
1748 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1749 return Val.ConstVal;
1752 MachineConstantPoolValue *getMachineCPVal() const {
1753 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1754 return Val.MachineCPVal;
1757 int getOffset() const {
1758 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1761 // Return the alignment of this constant pool object, which is either 0 (for
1762 // default alignment) or log2 of the desired value.
1763 unsigned getAlignment() const { return Alignment; }
1765 const Type *getType() const;
1767 static bool classof(const ConstantPoolSDNode *) { return true; }
1768 static bool classof(const SDNode *N) {
1769 return N->getOpcode() == ISD::ConstantPool ||
1770 N->getOpcode() == ISD::TargetConstantPool;
1774 class BasicBlockSDNode : public SDNode {
1775 MachineBasicBlock *MBB;
1776 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1778 friend class SelectionDAG;
1779 explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1780 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1784 MachineBasicBlock *getBasicBlock() const { return MBB; }
1786 static bool classof(const BasicBlockSDNode *) { return true; }
1787 static bool classof(const SDNode *N) {
1788 return N->getOpcode() == ISD::BasicBlock;
1792 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1793 /// used when the SelectionDAG needs to make a simple reference to something
1794 /// in the LLVM IR representation.
1796 /// Note that this is not used for carrying alias information; that is done
1797 /// with MemOperandSDNode, which includes a Value which is required to be a
1798 /// pointer, and several other fields specific to memory references.
1800 class SrcValueSDNode : public SDNode {
1802 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1804 friend class SelectionDAG;
1805 /// Create a SrcValue for a general value.
1806 explicit SrcValueSDNode(const Value *v)
1807 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1810 /// getValue - return the contained Value.
1811 const Value *getValue() const { return V; }
1813 static bool classof(const SrcValueSDNode *) { return true; }
1814 static bool classof(const SDNode *N) {
1815 return N->getOpcode() == ISD::SRCVALUE;
1820 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
1821 /// used to represent a reference to memory after ISD::LOAD
1822 /// and ISD::STORE have been lowered.
1824 class MemOperandSDNode : public SDNode {
1825 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1827 friend class SelectionDAG;
1828 /// Create a MachineMemOperand node
1829 explicit MemOperandSDNode(const MachineMemOperand &mo)
1830 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1833 /// MO - The contained MachineMemOperand.
1834 const MachineMemOperand MO;
1836 static bool classof(const MemOperandSDNode *) { return true; }
1837 static bool classof(const SDNode *N) {
1838 return N->getOpcode() == ISD::MEMOPERAND;
1843 class RegisterSDNode : public SDNode {
1845 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1847 friend class SelectionDAG;
1848 RegisterSDNode(unsigned reg, MVT VT)
1849 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1853 unsigned getReg() const { return Reg; }
1855 static bool classof(const RegisterSDNode *) { return true; }
1856 static bool classof(const SDNode *N) {
1857 return N->getOpcode() == ISD::Register;
1861 class DbgStopPointSDNode : public SDNode {
1865 const CompileUnitDesc *CU;
1866 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1868 friend class SelectionDAG;
1869 DbgStopPointSDNode(SDOperand ch, unsigned l, unsigned c,
1870 const CompileUnitDesc *cu)
1871 : SDNode(ISD::DBG_STOPPOINT, getSDVTList(MVT::Other)),
1872 Line(l), Column(c), CU(cu) {
1874 InitOperands(&Chain, 1);
1877 unsigned getLine() const { return Line; }
1878 unsigned getColumn() const { return Column; }
1879 const CompileUnitDesc *getCompileUnit() const { return CU; }
1881 static bool classof(const DbgStopPointSDNode *) { return true; }
1882 static bool classof(const SDNode *N) {
1883 return N->getOpcode() == ISD::DBG_STOPPOINT;
1887 class LabelSDNode : public SDNode {
1890 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1892 friend class SelectionDAG;
1893 LabelSDNode(unsigned NodeTy, SDOperand ch, unsigned id)
1894 : SDNode(NodeTy, getSDVTList(MVT::Other)), LabelID(id) {
1896 InitOperands(&Chain, 1);
1899 unsigned getLabelID() const { return LabelID; }
1901 static bool classof(const LabelSDNode *) { return true; }
1902 static bool classof(const SDNode *N) {
1903 return N->getOpcode() == ISD::DBG_LABEL ||
1904 N->getOpcode() == ISD::EH_LABEL;
1908 class ExternalSymbolSDNode : public SDNode {
1910 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1912 friend class SelectionDAG;
1913 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT VT)
1914 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1915 getSDVTList(VT)), Symbol(Sym) {
1919 const char *getSymbol() const { return Symbol; }
1921 static bool classof(const ExternalSymbolSDNode *) { return true; }
1922 static bool classof(const SDNode *N) {
1923 return N->getOpcode() == ISD::ExternalSymbol ||
1924 N->getOpcode() == ISD::TargetExternalSymbol;
1928 class CondCodeSDNode : public SDNode {
1929 ISD::CondCode Condition;
1930 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
1932 friend class SelectionDAG;
1933 explicit CondCodeSDNode(ISD::CondCode Cond)
1934 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1938 ISD::CondCode get() const { return Condition; }
1940 static bool classof(const CondCodeSDNode *) { return true; }
1941 static bool classof(const SDNode *N) {
1942 return N->getOpcode() == ISD::CONDCODE;
1949 static const uint64_t NoFlagSet = 0ULL;
1950 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended
1951 static const uint64_t ZExtOffs = 0;
1952 static const uint64_t SExt = 1ULL<<1; ///< Sign extended
1953 static const uint64_t SExtOffs = 1;
1954 static const uint64_t InReg = 1ULL<<2; ///< Passed in register
1955 static const uint64_t InRegOffs = 2;
1956 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr
1957 static const uint64_t SRetOffs = 3;
1958 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value
1959 static const uint64_t ByValOffs = 4;
1960 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain
1961 static const uint64_t NestOffs = 5;
1962 static const uint64_t ByValAlign = 0xFULL << 6; //< Struct alignment
1963 static const uint64_t ByValAlignOffs = 6;
1964 static const uint64_t Split = 1ULL << 10;
1965 static const uint64_t SplitOffs = 10;
1966 static const uint64_t OrigAlign = 0x1FULL<<27;
1967 static const uint64_t OrigAlignOffs = 27;
1968 static const uint64_t ByValSize = 0xffffffffULL << 32; //< Struct size
1969 static const uint64_t ByValSizeOffs = 32;
1971 static const uint64_t One = 1ULL; //< 1 of this type, for shifts
1975 ArgFlagsTy() : Flags(0) { }
1977 bool isZExt() const { return Flags & ZExt; }
1978 void setZExt() { Flags |= One << ZExtOffs; }
1980 bool isSExt() const { return Flags & SExt; }
1981 void setSExt() { Flags |= One << SExtOffs; }
1983 bool isInReg() const { return Flags & InReg; }
1984 void setInReg() { Flags |= One << InRegOffs; }
1986 bool isSRet() const { return Flags & SRet; }
1987 void setSRet() { Flags |= One << SRetOffs; }
1989 bool isByVal() const { return Flags & ByVal; }
1990 void setByVal() { Flags |= One << ByValOffs; }
1992 bool isNest() const { return Flags & Nest; }
1993 void setNest() { Flags |= One << NestOffs; }
1995 unsigned getByValAlign() const {
1997 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
1999 void setByValAlign(unsigned A) {
2000 Flags = (Flags & ~ByValAlign) |
2001 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
2004 bool isSplit() const { return Flags & Split; }
2005 void setSplit() { Flags |= One << SplitOffs; }
2007 unsigned getOrigAlign() const {
2009 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
2011 void setOrigAlign(unsigned A) {
2012 Flags = (Flags & ~OrigAlign) |
2013 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
2016 unsigned getByValSize() const {
2017 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
2019 void setByValSize(unsigned S) {
2020 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
2023 /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
2024 std::string getArgFlagsString();
2026 /// getRawBits - Represent the flags as a bunch of bits.
2027 uint64_t getRawBits() const { return Flags; }
2031 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
2032 class ARG_FLAGSSDNode : public SDNode {
2033 ISD::ArgFlagsTy TheFlags;
2034 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2036 friend class SelectionDAG;
2037 explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
2038 : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
2041 ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
2043 static bool classof(const ARG_FLAGSSDNode *) { return true; }
2044 static bool classof(const SDNode *N) {
2045 return N->getOpcode() == ISD::ARG_FLAGS;
2049 /// VTSDNode - This class is used to represent MVT's, which are used
2050 /// to parameterize some operations.
2051 class VTSDNode : public SDNode {
2053 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2055 friend class SelectionDAG;
2056 explicit VTSDNode(MVT VT)
2057 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
2061 MVT getVT() const { return ValueType; }
2063 static bool classof(const VTSDNode *) { return true; }
2064 static bool classof(const SDNode *N) {
2065 return N->getOpcode() == ISD::VALUETYPE;
2069 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
2071 class LSBaseSDNode : public MemSDNode {
2073 //! Operand array for load and store
2075 \note Moving this array to the base class captures more
2076 common functionality shared between LoadSDNode and
2081 LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned numOperands,
2082 SDVTList VTs, ISD::MemIndexedMode AM, MVT VT,
2083 const Value *SV, int SVO, unsigned Align, bool Vol)
2084 : MemSDNode(NodeTy, VTs, VT, SV, SVO, Align, Vol) {
2086 for (unsigned i = 0; i != numOperands; ++i)
2087 Ops[i] = Operands[i];
2088 InitOperands(Ops, numOperands);
2089 assert(Align != 0 && "Loads and stores should have non-zero aligment");
2090 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
2091 "Only indexed loads and stores have a non-undef offset operand");
2094 const SDOperand &getOffset() const {
2095 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2098 /// getAddressingMode - Return the addressing mode for this load or store:
2099 /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2100 ISD::MemIndexedMode getAddressingMode() const {
2101 return ISD::MemIndexedMode(SubclassData & 7);
2104 /// isIndexed - Return true if this is a pre/post inc/dec load/store.
2105 bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2107 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
2108 bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2110 static bool classof(const LSBaseSDNode *) { return true; }
2111 static bool classof(const SDNode *N) {
2112 return N->getOpcode() == ISD::LOAD ||
2113 N->getOpcode() == ISD::STORE;
2117 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2119 class LoadSDNode : public LSBaseSDNode {
2120 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2122 friend class SelectionDAG;
2123 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
2124 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT,
2125 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2126 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
2127 VTs, AM, LVT, SV, O, Align, Vol) {
2128 SubclassData |= (unsigned short)ETy << 3;
2132 /// getExtensionType - Return whether this is a plain node,
2133 /// or one of the varieties of value-extending loads.
2134 ISD::LoadExtType getExtensionType() const {
2135 return ISD::LoadExtType((SubclassData >> 3) & 3);
2138 const SDOperand &getBasePtr() const { return getOperand(1); }
2139 const SDOperand &getOffset() const { return getOperand(2); }
2141 static bool classof(const LoadSDNode *) { return true; }
2142 static bool classof(const SDNode *N) {
2143 return N->getOpcode() == ISD::LOAD;
2147 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2149 class StoreSDNode : public LSBaseSDNode {
2150 virtual void ANCHOR(); // Out-of-line virtual method to give class a home.
2152 friend class SelectionDAG;
2153 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
2154 ISD::MemIndexedMode AM, bool isTrunc, MVT SVT,
2155 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2156 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
2157 VTs, AM, SVT, SV, O, Align, Vol) {
2158 SubclassData |= (unsigned short)isTrunc << 3;
2162 /// isTruncatingStore - Return true if the op does a truncation before store.
2163 /// For integers this is the same as doing a TRUNCATE and storing the result.
2164 /// For floats, it is the same as doing an FP_ROUND and storing the result.
2165 bool isTruncatingStore() const { return (SubclassData >> 3) & 1; }
2167 const SDOperand &getValue() const { return getOperand(1); }
2168 const SDOperand &getBasePtr() const { return getOperand(2); }
2169 const SDOperand &getOffset() const { return getOperand(3); }
2171 static bool classof(const StoreSDNode *) { return true; }
2172 static bool classof(const SDNode *N) {
2173 return N->getOpcode() == ISD::STORE;
2178 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
2182 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2184 bool operator==(const SDNodeIterator& x) const {
2185 return Operand == x.Operand;
2187 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2189 const SDNodeIterator &operator=(const SDNodeIterator &I) {
2190 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2191 Operand = I.Operand;
2195 pointer operator*() const {
2196 return Node->getOperand(Operand).Val;
2198 pointer operator->() const { return operator*(); }
2200 SDNodeIterator& operator++() { // Preincrement
2204 SDNodeIterator operator++(int) { // Postincrement
2205 SDNodeIterator tmp = *this; ++*this; return tmp;
2208 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2209 static SDNodeIterator end (SDNode *N) {
2210 return SDNodeIterator(N, N->getNumOperands());
2213 unsigned getOperand() const { return Operand; }
2214 const SDNode *getNode() const { return Node; }
2217 template <> struct GraphTraits<SDNode*> {
2218 typedef SDNode NodeType;
2219 typedef SDNodeIterator ChildIteratorType;
2220 static inline NodeType *getEntryNode(SDNode *N) { return N; }
2221 static inline ChildIteratorType child_begin(NodeType *N) {
2222 return SDNodeIterator::begin(N);
2224 static inline ChildIteratorType child_end(NodeType *N) {
2225 return SDNodeIterator::end(N);
2229 /// LargestSDNode - The largest SDNode class.
2231 typedef LoadSDNode LargestSDNode;
2233 // alist_traits specialization for pool-allocating SDNodes.
2235 class alist_traits<SDNode, LargestSDNode> {
2236 typedef alist_iterator<SDNode, LargestSDNode> iterator;
2239 // Pool-allocate and recycle SDNodes.
2240 typedef RecyclingAllocator<BumpPtrAllocator, SDNode, LargestSDNode>
2243 // Allocate the allocator immediately inside the traits class.
2244 AllocatorType Allocator;
2246 void addNodeToList(SDNode*) {}
2247 void removeNodeFromList(SDNode*) {}
2248 void transferNodesFromList(alist_traits &, iterator, iterator) {}
2249 void deleteNode(SDNode *N) {
2251 Allocator.Deallocate(N);
2256 /// isNormalLoad - Returns true if the specified node is a non-extending
2257 /// and unindexed load.
2258 inline bool isNormalLoad(const SDNode *N) {
2259 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2260 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2261 Ld->getAddressingMode() == ISD::UNINDEXED;
2264 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2266 inline bool isNON_EXTLoad(const SDNode *N) {
2267 return isa<LoadSDNode>(N) &&
2268 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2271 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2273 inline bool isEXTLoad(const SDNode *N) {
2274 return isa<LoadSDNode>(N) &&
2275 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2278 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2280 inline bool isSEXTLoad(const SDNode *N) {
2281 return isa<LoadSDNode>(N) &&
2282 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2285 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2287 inline bool isZEXTLoad(const SDNode *N) {
2288 return isa<LoadSDNode>(N) &&
2289 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2292 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2294 inline bool isUNINDEXEDLoad(const SDNode *N) {
2295 return isa<LoadSDNode>(N) &&
2296 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2299 /// isNormalStore - Returns true if the specified node is a non-truncating
2300 /// and unindexed store.
2301 inline bool isNormalStore(const SDNode *N) {
2302 const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2303 return St && !St->isTruncatingStore() &&
2304 St->getAddressingMode() == ISD::UNINDEXED;
2307 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2309 inline bool isNON_TRUNCStore(const SDNode *N) {
2310 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2313 /// isTRUNCStore - Returns true if the specified node is a truncating
2315 inline bool isTRUNCStore(const SDNode *N) {
2316 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2319 /// isUNINDEXEDStore - Returns true if the specified node is an
2320 /// unindexed store.
2321 inline bool isUNINDEXEDStore(const SDNode *N) {
2322 return isa<StoreSDNode>(N) &&
2323 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2328 } // end llvm namespace