SelectionDAGNodes.h revision 195098
190075Sobrien//===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
290075Sobrien//
390075Sobrien//                     The LLVM Compiler Infrastructure
490075Sobrien//
590075Sobrien// This file is distributed under the University of Illinois Open Source
690075Sobrien// License. See LICENSE.TXT for details.
790075Sobrien//
890075Sobrien//===----------------------------------------------------------------------===//
990075Sobrien//
1090075Sobrien// This file declares the SDNode class and derived classes, which are used to
1190075Sobrien// represent the nodes and operations present in a SelectionDAG.  These nodes
1290075Sobrien// and operations are machine code level operations, with some similarities to
1390075Sobrien// the GCC RTL representation.
1490075Sobrien//
1590075Sobrien// Clients should include the SelectionDAG.h file instead of this file directly.
1690075Sobrien//
1790075Sobrien//===----------------------------------------------------------------------===//
1890075Sobrien
1990075Sobrien#ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
2090075Sobrien#define LLVM_CODEGEN_SELECTIONDAGNODES_H
2190075Sobrien
2290075Sobrien#include "llvm/Constants.h"
2390075Sobrien#include "llvm/ADT/FoldingSet.h"
2490075Sobrien#include "llvm/ADT/GraphTraits.h"
2590075Sobrien#include "llvm/ADT/iterator.h"
2690075Sobrien#include "llvm/ADT/ilist_node.h"
2790075Sobrien#include "llvm/ADT/SmallVector.h"
2890075Sobrien#include "llvm/ADT/STLExtras.h"
2990075Sobrien#include "llvm/CodeGen/ValueTypes.h"
3090075Sobrien#include "llvm/CodeGen/MachineMemOperand.h"
3190075Sobrien#include "llvm/Support/Allocator.h"
3290075Sobrien#include "llvm/Support/RecyclingAllocator.h"
3390075Sobrien#include "llvm/Support/DataTypes.h"
3490075Sobrien#include "llvm/Support/DebugLoc.h"
3590075Sobrien#include <cassert>
3690075Sobrien#include <climits>
3790075Sobrien
3890075Sobriennamespace llvm {
3990075Sobrien
4090075Sobrienclass SelectionDAG;
4190075Sobrienclass GlobalValue;
4290075Sobrienclass MachineBasicBlock;
4390075Sobrienclass MachineConstantPoolValue;
4490075Sobrienclass SDNode;
4590075Sobrienclass Value;
4690075Sobrientemplate <typename T> struct DenseMapInfo;
4790075Sobrientemplate <typename T> struct simplify_type;
4890075Sobrientemplate <typename T> struct ilist_traits;
4990075Sobrien
5090075Sobrien/// SDVTList - This represents a list of ValueType's that has been intern'd by
5190075Sobrien/// a SelectionDAG.  Instances of this simple value class are returned by
5290075Sobrien/// SelectionDAG::getVTList(...).
5390075Sobrien///
5490075Sobrienstruct SDVTList {
5590075Sobrien  const MVT *VTs;
5690075Sobrien  unsigned int NumVTs;
5790075Sobrien};
5890075Sobrien
5990075Sobrien/// ISD namespace - This namespace contains an enum which represents all of the
6090075Sobrien/// SelectionDAG node types and value types.
6190075Sobrien///
6290075Sobriennamespace ISD {
6390075Sobrien
6490075Sobrien  //===--------------------------------------------------------------------===//
6590075Sobrien  /// ISD::NodeType enum - This enum defines the target-independent operators
6690075Sobrien  /// for a SelectionDAG.
6790075Sobrien  ///
6890075Sobrien  /// Targets may also define target-dependent operator codes for SDNodes. For
6990075Sobrien  /// example, on x86, these are the enum values in the X86ISD namespace.
7090075Sobrien  /// Targets should aim to use target-independent operators to model their
7190075Sobrien  /// instruction sets as much as possible, and only use target-dependent
7290075Sobrien  /// operators when they have special requirements.
7390075Sobrien  ///
7490075Sobrien  /// Finally, during and after selection proper, SNodes may use special
7590075Sobrien  /// operator codes that correspond directly with MachineInstr opcodes. These
7690075Sobrien  /// are used to represent selected instructions. See the isMachineOpcode()
7790075Sobrien  /// and getMachineOpcode() member functions of SDNode.
7890075Sobrien  ///
7990075Sobrien  enum NodeType {
8090075Sobrien    // DELETED_NODE - This is an illegal value that is used to catch
8190075Sobrien    // errors.  This opcode is not a legal opcode for any node.
8290075Sobrien    DELETED_NODE,
8390075Sobrien
8490075Sobrien    // EntryToken - This is the marker used to indicate the start of the region.
8590075Sobrien    EntryToken,
8690075Sobrien
8790075Sobrien    // TokenFactor - This node takes multiple tokens as input and produces a
8890075Sobrien    // single token result.  This is used to represent the fact that the operand
8990075Sobrien    // operators are independent of each other.
9090075Sobrien    TokenFactor,
9190075Sobrien
9290075Sobrien    // AssertSext, AssertZext - These nodes record if a register contains a
9390075Sobrien    // value that has already been zero or sign extended from a narrower type.
9490075Sobrien    // These nodes take two operands.  The first is the node that has already
9590075Sobrien    // been extended, and the second is a value type node indicating the width
9690075Sobrien    // of the extension
9790075Sobrien    AssertSext, AssertZext,
9890075Sobrien
9990075Sobrien    // Various leaf nodes.
10090075Sobrien    BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
10190075Sobrien    Constant, ConstantFP,
10290075Sobrien    GlobalAddress, GlobalTLSAddress, FrameIndex,
10390075Sobrien    JumpTable, ConstantPool, ExternalSymbol,
10490075Sobrien
10590075Sobrien    // The address of the GOT
10690075Sobrien    GLOBAL_OFFSET_TABLE,
10790075Sobrien
10890075Sobrien    // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
10990075Sobrien    // llvm.returnaddress on the DAG.  These nodes take one operand, the index
11090075Sobrien    // of the frame or return address to return.  An index of zero corresponds
11190075Sobrien    // to the current function's frame or return address, an index of one to the
11290075Sobrien    // parent's frame or return address, and so on.
11390075Sobrien    FRAMEADDR, RETURNADDR,
11490075Sobrien
11590075Sobrien    // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
11690075Sobrien    // first (possible) on-stack argument. This is needed for correct stack
11790075Sobrien    // adjustment during unwind.
11890075Sobrien    FRAME_TO_ARGS_OFFSET,
11990075Sobrien
12090075Sobrien    // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
12190075Sobrien    // address of the exception block on entry to an landing pad block.
12290075Sobrien    EXCEPTIONADDR,
12390075Sobrien
12490075Sobrien    // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
12590075Sobrien    // the selection index of the exception thrown.
12690075Sobrien    EHSELECTION,
12790075Sobrien
12890075Sobrien    // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
12990075Sobrien    // 'eh_return' gcc dwarf builtin, which is used to return from
13090075Sobrien    // exception. The general meaning is: adjust stack by OFFSET and pass
13190075Sobrien    // execution to HANDLER. Many platform-related details also :)
13290075Sobrien    EH_RETURN,
13390075Sobrien
13490075Sobrien    // TargetConstant* - Like Constant*, but the DAG does not do any folding or
13590075Sobrien    // simplification of the constant.
13690075Sobrien    TargetConstant,
13790075Sobrien    TargetConstantFP,
13890075Sobrien
13990075Sobrien    // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
14090075Sobrien    // anything else with this node, and this is valid in the target-specific
14190075Sobrien    // dag, turning into a GlobalAddress operand.
14290075Sobrien    TargetGlobalAddress,
14390075Sobrien    TargetGlobalTLSAddress,
14490075Sobrien    TargetFrameIndex,
14590075Sobrien    TargetJumpTable,
14690075Sobrien    TargetConstantPool,
14790075Sobrien    TargetExternalSymbol,
14890075Sobrien
14990075Sobrien    /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
15090075Sobrien    /// This node represents a target intrinsic function with no side effects.
15190075Sobrien    /// The first operand is the ID number of the intrinsic from the
15290075Sobrien    /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
15390075Sobrien    /// node has returns the result of the intrinsic.
15490075Sobrien    INTRINSIC_WO_CHAIN,
15590075Sobrien
15690075Sobrien    /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
15790075Sobrien    /// This node represents a target intrinsic function with side effects that
15890075Sobrien    /// returns a result.  The first operand is a chain pointer.  The second is
15990075Sobrien    /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
16090075Sobrien    /// operands to the intrinsic follow.  The node has two results, the result
16190075Sobrien    /// of the intrinsic and an output chain.
16290075Sobrien    INTRINSIC_W_CHAIN,
16390075Sobrien
16490075Sobrien    /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
16590075Sobrien    /// This node represents a target intrinsic function with side effects that
16690075Sobrien    /// does not return a result.  The first operand is a chain pointer.  The
16790075Sobrien    /// second is the ID number of the intrinsic from the llvm::Intrinsic
16890075Sobrien    /// namespace.  The operands to the intrinsic follow.
16990075Sobrien    INTRINSIC_VOID,
17090075Sobrien
17190075Sobrien    // CopyToReg - This node has three operands: a chain, a register number to
17290075Sobrien    // set to this value, and a value.
17390075Sobrien    CopyToReg,
17490075Sobrien
17590075Sobrien    // CopyFromReg - This node indicates that the input value is a virtual or
17690075Sobrien    // physical register that is defined outside of the scope of this
17790075Sobrien    // SelectionDAG.  The register is available from the RegisterSDNode object.
17890075Sobrien    CopyFromReg,
17990075Sobrien
18090075Sobrien    // UNDEF - An undefined node
18190075Sobrien    UNDEF,
18290075Sobrien
18390075Sobrien    /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
18490075Sobrien    /// represents the formal arguments for a function.  CC# is a Constant value
18590075Sobrien    /// indicating the calling convention of the function, and ISVARARG is a
18690075Sobrien    /// flag that indicates whether the function is varargs or not. This node
18790075Sobrien    /// has one result value for each incoming argument, plus one for the output
18890075Sobrien    /// chain. It must be custom legalized. See description of CALL node for
18990075Sobrien    /// FLAG argument contents explanation.
19090075Sobrien    ///
19190075Sobrien    FORMAL_ARGUMENTS,
19290075Sobrien
19390075Sobrien    /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CALLEE,
19490075Sobrien    ///                              ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
19590075Sobrien    /// This node represents a fully general function call, before the legalizer
19690075Sobrien    /// runs.  This has one result value for each argument / flag pair, plus
19790075Sobrien    /// a chain result. It must be custom legalized. Flag argument indicates
19890075Sobrien    /// misc. argument attributes. Currently:
19990075Sobrien    /// Bit 0 - signness
20090075Sobrien    /// Bit 1 - 'inreg' attribute
20190075Sobrien    /// Bit 2 - 'sret' attribute
20290075Sobrien    /// Bit 4 - 'byval' attribute
20390075Sobrien    /// Bit 5 - 'nest' attribute
20490075Sobrien    /// Bit 6-9 - alignment of byval structures
20590075Sobrien    /// Bit 10-26 - size of byval structures
20690075Sobrien    /// Bits 31:27 - argument ABI alignment in the first argument piece and
20790075Sobrien    /// alignment '1' in other argument pieces.
20890075Sobrien    ///
20990075Sobrien    /// CALL nodes use the CallSDNode subclass of SDNode, which
21090075Sobrien    /// additionally carries information about the calling convention,
21190075Sobrien    /// whether the call is varargs, and if it's marked as a tail call.
21290075Sobrien    ///
21390075Sobrien    CALL,
21490075Sobrien
21590075Sobrien    // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
21690075Sobrien    // a Constant, which is required to be operand #1) half of the integer or
21790075Sobrien    // float value specified as operand #0.  This is only for use before
21890075Sobrien    // legalization, for values that will be broken into multiple registers.
21990075Sobrien    EXTRACT_ELEMENT,
22090075Sobrien
22190075Sobrien    // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
22290075Sobrien    // two values of the same integer value type, this produces a value twice as
22390075Sobrien    // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
22490075Sobrien    BUILD_PAIR,
225117395Skan
22690075Sobrien    // MERGE_VALUES - This node takes multiple discrete operands and returns
22790075Sobrien    // them all as its individual results.  This nodes has exactly the same
22890075Sobrien    // number of inputs and outputs, and is only valid before legalization.
22990075Sobrien    // This node is useful for some pieces of the code generator that want to
23090075Sobrien    // think about a single node with multiple results, not multiple nodes.
23190075Sobrien    MERGE_VALUES,
23290075Sobrien
23390075Sobrien    // Simple integer binary arithmetic operators.
23490075Sobrien    ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
23590075Sobrien
23690075Sobrien    // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
237117395Skan    // a signed/unsigned value of type i[2*N], and return the full value as
238117395Skan    // two results, each of type iN.
23990075Sobrien    SMUL_LOHI, UMUL_LOHI,
24090075Sobrien
24190075Sobrien    // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
24290075Sobrien    // remainder result.
24390075Sobrien    SDIVREM, UDIVREM,
24490075Sobrien
24590075Sobrien    // CARRY_FALSE - This node is used when folding other nodes,
24690075Sobrien    // like ADDC/SUBC, which indicate the carry result is always false.
24790075Sobrien    CARRY_FALSE,
24890075Sobrien
24990075Sobrien    // Carry-setting nodes for multiple precision addition and subtraction.
25090075Sobrien    // These nodes take two operands of the same value type, and produce two
25190075Sobrien    // results.  The first result is the normal add or sub result, the second
25290075Sobrien    // result is the carry flag result.
25390075Sobrien    ADDC, SUBC,
25490075Sobrien
25590075Sobrien    // Carry-using nodes for multiple precision addition and subtraction.  These
25690075Sobrien    // nodes take three operands: The first two are the normal lhs and rhs to
25790075Sobrien    // the add or sub, and the third is the input carry flag.  These nodes
25890075Sobrien    // produce two results; the normal result of the add or sub, and the output
25990075Sobrien    // carry flag.  These nodes both read and write a carry flag to allow them
26090075Sobrien    // to them to be chained together for add and sub of arbitrarily large
26190075Sobrien    // values.
26290075Sobrien    ADDE, SUBE,
26390075Sobrien
26490075Sobrien    // RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
26590075Sobrien    // These nodes take two operands: the normal LHS and RHS to the add. They
26690075Sobrien    // produce two results: the normal result of the add, and a boolean that
26790075Sobrien    // indicates if an overflow occured (*not* a flag, because it may be stored
26890075Sobrien    // to memory, etc.).  If the type of the boolean is not i1 then the high
26990075Sobrien    // bits conform to getBooleanContents.
27090075Sobrien    // These nodes are generated from the llvm.[su]add.with.overflow intrinsics.
27190075Sobrien    SADDO, UADDO,
27290075Sobrien
27390075Sobrien    // Same for subtraction
27490075Sobrien    SSUBO, USUBO,
27590075Sobrien
27690075Sobrien    // Same for multiplication
27790075Sobrien    SMULO, UMULO,
27890075Sobrien
27990075Sobrien    // Simple binary floating point operators.
28090075Sobrien    FADD, FSUB, FMUL, FDIV, FREM,
28190075Sobrien
282117395Skan    // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
28390075Sobrien    // DAG node does not require that X and Y have the same type, just that they
28490075Sobrien    // are both floating point.  X and the result must have the same type.
28590075Sobrien    // FCOPYSIGN(f32, f64) is allowed.
28690075Sobrien    FCOPYSIGN,
28790075Sobrien
28890075Sobrien    // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
28990075Sobrien    // value as an integer 0/1 value.
29090075Sobrien    FGETSIGN,
29190075Sobrien
29290075Sobrien    /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the
29390075Sobrien    /// specified, possibly variable, elements.  The number of elements is
29490075Sobrien    /// required to be a power of two.  The types of the operands must all be
29590075Sobrien    /// the same and must match the vector element type, except that integer
29690075Sobrien    /// types are allowed to be larger than the element type, in which case
29790075Sobrien    /// the operands are implicitly truncated.
29890075Sobrien    BUILD_VECTOR,
29990075Sobrien
30090075Sobrien    /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
30190075Sobrien    /// at IDX replaced with VAL.  If the type of VAL is larger than the vector
30290075Sobrien    /// element type then VAL is truncated before replacement.
30390075Sobrien    INSERT_VECTOR_ELT,
30490075Sobrien
30590075Sobrien    /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
30690075Sobrien    /// identified by the (potentially variable) element number IDX.
30790075Sobrien    EXTRACT_VECTOR_ELT,
30890075Sobrien
30990075Sobrien    /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
31090075Sobrien    /// vector type with the same length and element type, this produces a
31190075Sobrien    /// concatenated vector result value, with length equal to the sum of the
31290075Sobrien    /// lengths of the input vectors.
31390075Sobrien    CONCAT_VECTORS,
31490075Sobrien
315117395Skan    /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
31690075Sobrien    /// vector value) starting with the (potentially variable) element number
31790075Sobrien    /// IDX, which must be a multiple of the result vector length.
31890075Sobrien    EXTRACT_SUBVECTOR,
31990075Sobrien
32090075Sobrien    /// VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as
32190075Sobrien    /// VEC1/VEC2.  A VECTOR_SHUFFLE node also contains an array of constant int
32290075Sobrien    /// values that indicate which value (or undef) each result element will
32390075Sobrien    /// get.  These constant ints are accessible through the
32490075Sobrien    /// ShuffleVectorSDNode class.  This is quite similar to the Altivec
32590075Sobrien    /// 'vperm' instruction, except that the indices must be constants and are
32690075Sobrien    /// in terms of the element size of VEC1/VEC2, not in terms of bytes.
32790075Sobrien    VECTOR_SHUFFLE,
32890075Sobrien
32990075Sobrien    /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
33090075Sobrien    /// scalar value into element 0 of the resultant vector type.  The top
33190075Sobrien    /// elements 1 to N-1 of the N-element vector are undefined.  The type
33290075Sobrien    /// of the operand must match the vector element type, except when they
33390075Sobrien    /// are integer types.  In this case the operand is allowed to be wider
33490075Sobrien    /// than the vector element type, and is implicitly truncated to it.
33590075Sobrien    SCALAR_TO_VECTOR,
33690075Sobrien
33790075Sobrien    // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
33890075Sobrien    // an unsigned/signed value of type i[2*N], then return the top part.
33990075Sobrien    MULHU, MULHS,
34090075Sobrien
34190075Sobrien    // Bitwise operators - logical and, logical or, logical xor, shift left,
34290075Sobrien    // shift right algebraic (shift in sign bits), shift right logical (shift in
34390075Sobrien    // zeroes), rotate left, rotate right, and byteswap.
34490075Sobrien    AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
34590075Sobrien
34690075Sobrien    // Counting operators
34790075Sobrien    CTTZ, CTLZ, CTPOP,
34890075Sobrien
34990075Sobrien    // Select(COND, TRUEVAL, FALSEVAL).  If the type of the boolean COND is not
35090075Sobrien    // i1 then the high bits must conform to getBooleanContents.
35190075Sobrien    SELECT,
35290075Sobrien
35390075Sobrien    // Select with condition operator - This selects between a true value and
35490075Sobrien    // a false value (ops #2 and #3) based on the boolean result of comparing
35590075Sobrien    // the lhs and rhs (ops #0 and #1) of a conditional expression with the
35690075Sobrien    // condition code in op #4, a CondCodeSDNode.
35790075Sobrien    SELECT_CC,
35890075Sobrien
35990075Sobrien    // SetCC operator - This evaluates to a true value iff the condition is
36090075Sobrien    // true.  If the result value type is not i1 then the high bits conform
36190075Sobrien    // to getBooleanContents.  The operands to this are the left and right
36290075Sobrien    // operands to compare (ops #0, and #1) and the condition code to compare
36390075Sobrien    // them with (op #2) as a CondCodeSDNode.
36490075Sobrien    SETCC,
36590075Sobrien
36690075Sobrien    // Vector SetCC operator - This evaluates to a vector of integer elements
36790075Sobrien    // with the high bit in each element set to true if the comparison is true
36890075Sobrien    // and false if the comparison is false.  All other bits in each element
36990075Sobrien    // are undefined.  The operands to this are the left and right operands
37090075Sobrien    // to compare (ops #0, and #1) and the condition code to compare them with
37190075Sobrien    // (op #2) as a CondCodeSDNode.
37290075Sobrien    VSETCC,
37390075Sobrien
37490075Sobrien    // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
37590075Sobrien    // integer shift operations, just like ADD/SUB_PARTS.  The operation
37690075Sobrien    // ordering is:
37790075Sobrien    //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
37890075Sobrien    SHL_PARTS, SRA_PARTS, SRL_PARTS,
37990075Sobrien
38090075Sobrien    // Conversion operators.  These are all single input single output
38190075Sobrien    // operations.  For all of these, the result type must be strictly
38290075Sobrien    // wider or narrower (depending on the operation) than the source
38390075Sobrien    // type.
38490075Sobrien
38590075Sobrien    // SIGN_EXTEND - Used for integer types, replicating the sign bit
38690075Sobrien    // into new bits.
38790075Sobrien    SIGN_EXTEND,
38890075Sobrien
38990075Sobrien    // ZERO_EXTEND - Used for integer types, zeroing the new bits.
39090075Sobrien    ZERO_EXTEND,
39190075Sobrien
39290075Sobrien    // ANY_EXTEND - Used for integer types.  The high bits are undefined.
39390075Sobrien    ANY_EXTEND,
39490075Sobrien
39590075Sobrien    // TRUNCATE - Completely drop the high bits.
39690075Sobrien    TRUNCATE,
39790075Sobrien
39890075Sobrien    // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
39990075Sobrien    // depends on the first letter) to floating point.
40090075Sobrien    SINT_TO_FP,
40190075Sobrien    UINT_TO_FP,
40290075Sobrien
40390075Sobrien    // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
40490075Sobrien    // sign extend a small value in a large integer register (e.g. sign
40590075Sobrien    // extending the low 8 bits of a 32-bit register to fill the top 24 bits
40690075Sobrien    // with the 7th bit).  The size of the smaller type is indicated by the 1th
40790075Sobrien    // operand, a ValueType node.
40890075Sobrien    SIGN_EXTEND_INREG,
40990075Sobrien
41090075Sobrien    /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
41190075Sobrien    /// integer.
41290075Sobrien    FP_TO_SINT,
41390075Sobrien    FP_TO_UINT,
41490075Sobrien
41590075Sobrien    /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
41690075Sobrien    /// down to the precision of the destination VT.  TRUNC is a flag, which is
41790075Sobrien    /// always an integer that is zero or one.  If TRUNC is 0, this is a
41890075Sobrien    /// normal rounding, if it is 1, this FP_ROUND is known to not change the
41990075Sobrien    /// value of Y.
42090075Sobrien    ///
42190075Sobrien    /// The TRUNC = 1 case is used in cases where we know that the value will
42290075Sobrien    /// not be modified by the node, because Y is not using any of the extra
42390075Sobrien    /// precision of source type.  This allows certain transformations like
42490075Sobrien    /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
42590075Sobrien    /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
42690075Sobrien    FP_ROUND,
42790075Sobrien
42890075Sobrien    // FLT_ROUNDS_ - Returns current rounding mode:
42990075Sobrien    // -1 Undefined
43090075Sobrien    //  0 Round to 0
43190075Sobrien    //  1 Round to nearest
43290075Sobrien    //  2 Round to +inf
43390075Sobrien    //  3 Round to -inf
43490075Sobrien    FLT_ROUNDS_,
43590075Sobrien
43690075Sobrien    /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
43790075Sobrien    /// rounds it to a floating point value.  It then promotes it and returns it
43890075Sobrien    /// in a register of the same size.  This operation effectively just
43990075Sobrien    /// discards excess precision.  The type to round down to is specified by
44090075Sobrien    /// the VT operand, a VTSDNode.
44190075Sobrien    FP_ROUND_INREG,
44290075Sobrien
44390075Sobrien    /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
44490075Sobrien    FP_EXTEND,
44590075Sobrien
44690075Sobrien    // BIT_CONVERT - Theis operator converts between integer and FP values, as
44790075Sobrien    // if one was stored to memory as integer and the other was loaded from the
44890075Sobrien    // same address (or equivalently for vector format conversions, etc).  The
44990075Sobrien    // source and result are required to have the same bit size (e.g.
450117395Skan    // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp
45190075Sobrien    // conversions, but that is a noop, deleted by getNode().
45290075Sobrien    BIT_CONVERT,
45390075Sobrien
45490075Sobrien    // CONVERT_RNDSAT - This operator is used to support various conversions
45590075Sobrien    // between various types (float, signed, unsigned and vectors of those
45690075Sobrien    // types) with rounding and saturation. NOTE: Avoid using this operator as
45790075Sobrien    // most target don't support it and the operator might be removed in the
45890075Sobrien    // future. It takes the following arguments:
45990075Sobrien    //   0) value
46090075Sobrien    //   1) dest type (type to convert to)
46190075Sobrien    //   2) src type (type to convert from)
46290075Sobrien    //   3) rounding imm
46390075Sobrien    //   4) saturation imm
46490075Sobrien    //   5) ISD::CvtCode indicating the type of conversion to do
46590075Sobrien    CONVERT_RNDSAT,
46690075Sobrien
46790075Sobrien    // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
46890075Sobrien    // FLOG, FLOG2, FLOG10, FEXP, FEXP2,
46990075Sobrien    // FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary floating
47090075Sobrien    // point operations. These are inspired by libm.
47190075Sobrien    FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
47290075Sobrien    FLOG, FLOG2, FLOG10, FEXP, FEXP2,
47390075Sobrien    FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR,
47490075Sobrien
47590075Sobrien    // LOAD and STORE have token chains as their first operand, then the same
47690075Sobrien    // operands as an LLVM load/store instruction, then an offset node that
47790075Sobrien    // is added / subtracted from the base pointer to form the address (for
47890075Sobrien    // indexed memory ops).
47990075Sobrien    LOAD, STORE,
48090075Sobrien
48190075Sobrien    // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
48290075Sobrien    // to a specified boundary.  This node always has two return values: a new
48390075Sobrien    // stack pointer value and a chain. The first operand is the token chain,
48490075Sobrien    // the second is the number of bytes to allocate, and the third is the
48590075Sobrien    // alignment boundary.  The size is guaranteed to be a multiple of the stack
48690075Sobrien    // alignment, and the alignment is guaranteed to be bigger than the stack
48790075Sobrien    // alignment (if required) or 0 to get standard stack alignment.
48890075Sobrien    DYNAMIC_STACKALLOC,
48990075Sobrien
49090075Sobrien    // Control flow instructions.  These all have token chains.
49190075Sobrien
49290075Sobrien    // BR - Unconditional branch.  The first operand is the chain
49390075Sobrien    // operand, the second is the MBB to branch to.
49490075Sobrien    BR,
49590075Sobrien
49690075Sobrien    // BRIND - Indirect branch.  The first operand is the chain, the second
49790075Sobrien    // is the value to branch to, which must be of the same type as the target's
49890075Sobrien    // pointer type.
49990075Sobrien    BRIND,
50090075Sobrien
50190075Sobrien    // BR_JT - Jumptable branch. The first operand is the chain, the second
50290075Sobrien    // is the jumptable index, the last one is the jumptable entry index.
50390075Sobrien    BR_JT,
50490075Sobrien
50590075Sobrien    // BRCOND - Conditional branch.  The first operand is the chain, the
50690075Sobrien    // second is the condition, the third is the block to branch to if the
50790075Sobrien    // condition is true.  If the type of the condition is not i1, then the
50890075Sobrien    // high bits must conform to getBooleanContents.
50990075Sobrien    BRCOND,
51090075Sobrien
51190075Sobrien    // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
51290075Sobrien    // that the condition is represented as condition code, and two nodes to
51390075Sobrien    // compare, rather than as a combined SetCC node.  The operands in order are
51490075Sobrien    // chain, cc, lhs, rhs, block to branch to if condition is true.
51590075Sobrien    BR_CC,
51690075Sobrien
51790075Sobrien    // RET - Return from function.  The first operand is the chain,
51890075Sobrien    // and any subsequent operands are pairs of return value and return value
51990075Sobrien    // attributes (see CALL for description of attributes) for the function.
52090075Sobrien    // This operation can have variable number of operands.
52190075Sobrien    RET,
52290075Sobrien
52390075Sobrien    // INLINEASM - Represents an inline asm block.  This node always has two
52490075Sobrien    // return values: a chain and a flag result.  The inputs are as follows:
52590075Sobrien    //   Operand #0   : Input chain.
52690075Sobrien    //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
52790075Sobrien    //   Operand #2n+2: A RegisterNode.
52890075Sobrien    //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
52990075Sobrien    //   Operand #last: Optional, an incoming flag.
53090075Sobrien    INLINEASM,
53190075Sobrien
53290075Sobrien    // DBG_LABEL, EH_LABEL - Represents a label in mid basic block used to track
53390075Sobrien    // locations needed for debug and exception handling tables.  These nodes
53490075Sobrien    // take a chain as input and return a chain.
53590075Sobrien    DBG_LABEL,
53690075Sobrien    EH_LABEL,
53790075Sobrien
53890075Sobrien    // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
53990075Sobrien    // local variable declarations for debugging information. First operand is
54090075Sobrien    // a chain, while the next two operands are first two arguments (address
54190075Sobrien    // and variable) of a llvm.dbg.declare instruction.
54290075Sobrien    DECLARE,
54390075Sobrien
54490075Sobrien    // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
54590075Sobrien    // value, the same type as the pointer type for the system, and an output
54690075Sobrien    // chain.
54790075Sobrien    STACKSAVE,
54890075Sobrien
54990075Sobrien    // STACKRESTORE has two operands, an input chain and a pointer to restore to
55090075Sobrien    // it returns an output chain.
55190075Sobrien    STACKRESTORE,
55290075Sobrien
55390075Sobrien    // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
55490075Sobrien    // a call sequence, and carry arbitrary information that target might want
55590075Sobrien    // to know.  The first operand is a chain, the rest are specified by the
55690075Sobrien    // target and not touched by the DAG optimizers.
55790075Sobrien    // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
55890075Sobrien    CALLSEQ_START,  // Beginning of a call sequence
55990075Sobrien    CALLSEQ_END,    // End of a call sequence
56090075Sobrien
56190075Sobrien    // VAARG - VAARG has three operands: an input chain, a pointer, and a
56290075Sobrien    // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
56390075Sobrien    VAARG,
56490075Sobrien
56590075Sobrien    // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
56690075Sobrien    // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
56790075Sobrien    // source.
56890075Sobrien    VACOPY,
56990075Sobrien
57090075Sobrien    // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
57190075Sobrien    // pointer, and a SRCVALUE.
57290075Sobrien    VAEND, VASTART,
57390075Sobrien
57490075Sobrien    // SRCVALUE - This is a node type that holds a Value* that is used to
57590075Sobrien    // make reference to a value in the LLVM IR.
57690075Sobrien    SRCVALUE,
57790075Sobrien
57890075Sobrien    // MEMOPERAND - This is a node that contains a MachineMemOperand which
57990075Sobrien    // records information about a memory reference. This is used to make
58090075Sobrien    // AliasAnalysis queries from the backend.
58190075Sobrien    MEMOPERAND,
58290075Sobrien
58390075Sobrien    // PCMARKER - This corresponds to the pcmarker intrinsic.
58490075Sobrien    PCMARKER,
58590075Sobrien
58690075Sobrien    // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
58790075Sobrien    // The only operand is a chain and a value and a chain are produced.  The
58890075Sobrien    // value is the contents of the architecture specific cycle counter like
58990075Sobrien    // register (or other high accuracy low latency clock source)
59090075Sobrien    READCYCLECOUNTER,
59190075Sobrien
59290075Sobrien    // HANDLENODE node - Used as a handle for various purposes.
59390075Sobrien    HANDLENODE,
59490075Sobrien
59590075Sobrien    // DBG_STOPPOINT - This node is used to represent a source location for
59690075Sobrien    // debug info.  It takes token chain as input, and carries a line number,
59790075Sobrien    // column number, and a pointer to a CompileUnit object identifying
59890075Sobrien    // the containing compilation unit.  It produces a token chain as output.
59990075Sobrien    DBG_STOPPOINT,
60090075Sobrien
60190075Sobrien    // DEBUG_LOC - This node is used to represent source line information
60290075Sobrien    // embedded in the code.  It takes a token chain as input, then a line
60390075Sobrien    // number, then a column then a file id (provided by MachineModuleInfo.) It
60490075Sobrien    // produces a token chain as output.
60590075Sobrien    DEBUG_LOC,
60690075Sobrien
60790075Sobrien    // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
60890075Sobrien    // It takes as input a token chain, the pointer to the trampoline,
60990075Sobrien    // the pointer to the nested function, the pointer to pass for the
61090075Sobrien    // 'nest' parameter, a SRCVALUE for the trampoline and another for
61190075Sobrien    // the nested function (allowing targets to access the original
61290075Sobrien    // Function*).  It produces the result of the intrinsic and a token
61390075Sobrien    // chain as output.
61490075Sobrien    TRAMPOLINE,
61590075Sobrien
61690075Sobrien    // TRAP - Trapping instruction
61790075Sobrien    TRAP,
61890075Sobrien
61990075Sobrien    // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
62090075Sobrien    // their first operand. The other operands are the address to prefetch,
62190075Sobrien    // read / write specifier, and locality specifier.
62290075Sobrien    PREFETCH,
62390075Sobrien
62490075Sobrien    // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
62590075Sobrien    //                       store-store, device)
62690075Sobrien    // This corresponds to the memory.barrier intrinsic.
62790075Sobrien    // it takes an input chain, 4 operands to specify the type of barrier, an
62890075Sobrien    // operand specifying if the barrier applies to device and uncached memory
62990075Sobrien    // and produces an output chain.
63090075Sobrien    MEMBARRIER,
63190075Sobrien
63290075Sobrien    // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
63390075Sobrien    // this corresponds to the atomic.lcs intrinsic.
63490075Sobrien    // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
63590075Sobrien    // the return is always the original value in *ptr
63690075Sobrien    ATOMIC_CMP_SWAP,
63790075Sobrien
63890075Sobrien    // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
63990075Sobrien    // this corresponds to the atomic.swap intrinsic.
64090075Sobrien    // amt is stored to *ptr atomically.
64190075Sobrien    // the return is always the original value in *ptr
64290075Sobrien    ATOMIC_SWAP,
64390075Sobrien
64490075Sobrien    // Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt)
64590075Sobrien    // this corresponds to the atomic.load.[OpName] intrinsic.
64690075Sobrien    // op(*ptr, amt) is stored to *ptr atomically.
64790075Sobrien    // the return is always the original value in *ptr
64890075Sobrien    ATOMIC_LOAD_ADD,
64990075Sobrien    ATOMIC_LOAD_SUB,
65090075Sobrien    ATOMIC_LOAD_AND,
65190075Sobrien    ATOMIC_LOAD_OR,
65290075Sobrien    ATOMIC_LOAD_XOR,
65390075Sobrien    ATOMIC_LOAD_NAND,
65490075Sobrien    ATOMIC_LOAD_MIN,
65590075Sobrien    ATOMIC_LOAD_MAX,
65690075Sobrien    ATOMIC_LOAD_UMIN,
65790075Sobrien    ATOMIC_LOAD_UMAX,
65890075Sobrien
65990075Sobrien    // BUILTIN_OP_END - This must be the last enum value in this list.
66090075Sobrien    BUILTIN_OP_END
66190075Sobrien  };
66290075Sobrien
66390075Sobrien  /// Node predicates
66490075Sobrien
66590075Sobrien  /// isBuildVectorAllOnes - Return true if the specified node is a
66690075Sobrien  /// BUILD_VECTOR where all of the elements are ~0 or undef.
66790075Sobrien  bool isBuildVectorAllOnes(const SDNode *N);
66890075Sobrien
66990075Sobrien  /// isBuildVectorAllZeros - Return true if the specified node is a
67090075Sobrien  /// BUILD_VECTOR where all of the elements are 0 or undef.
67190075Sobrien  bool isBuildVectorAllZeros(const SDNode *N);
67290075Sobrien
67390075Sobrien  /// isScalarToVector - Return true if the specified node is a
67490075Sobrien  /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
67590075Sobrien  /// element is not an undef.
67690075Sobrien  bool isScalarToVector(const SDNode *N);
67790075Sobrien
67890075Sobrien  /// isDebugLabel - Return true if the specified node represents a debug
67990075Sobrien  /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node).
68090075Sobrien  bool isDebugLabel(const SDNode *N);
68190075Sobrien
68290075Sobrien  //===--------------------------------------------------------------------===//
68390075Sobrien  /// MemIndexedMode enum - This enum defines the load / store indexed
68490075Sobrien  /// addressing modes.
68590075Sobrien  ///
68690075Sobrien  /// UNINDEXED    "Normal" load / store. The effective address is already
68790075Sobrien  ///              computed and is available in the base pointer. The offset
68890075Sobrien  ///              operand is always undefined. In addition to producing a
68990075Sobrien  ///              chain, an unindexed load produces one value (result of the
69090075Sobrien  ///              load); an unindexed store does not produce a value.
69190075Sobrien  ///
69290075Sobrien  /// PRE_INC      Similar to the unindexed mode where the effective address is
69390075Sobrien  /// PRE_DEC      the value of the base pointer add / subtract the offset.
69490075Sobrien  ///              It considers the computation as being folded into the load /
69590075Sobrien  ///              store operation (i.e. the load / store does the address
69690075Sobrien  ///              computation as well as performing the memory transaction).
69790075Sobrien  ///              The base operand is always undefined. In addition to
69890075Sobrien  ///              producing a chain, pre-indexed load produces two values
69990075Sobrien  ///              (result of the load and the result of the address
70090075Sobrien  ///              computation); a pre-indexed store produces one value (result
70190075Sobrien  ///              of the address computation).
70290075Sobrien  ///
70390075Sobrien  /// POST_INC     The effective address is the value of the base pointer. The
70490075Sobrien  /// POST_DEC     value of the offset operand is then added to / subtracted
70590075Sobrien  ///              from the base after memory transaction. In addition to
70690075Sobrien  ///              producing a chain, post-indexed load produces two values
70790075Sobrien  ///              (the result of the load and the result of the base +/- offset
70890075Sobrien  ///              computation); a post-indexed store produces one value (the
70990075Sobrien  ///              the result of the base +/- offset computation).
71090075Sobrien  ///
71190075Sobrien  enum MemIndexedMode {
71290075Sobrien    UNINDEXED = 0,
71390075Sobrien    PRE_INC,
71490075Sobrien    PRE_DEC,
71590075Sobrien    POST_INC,
71690075Sobrien    POST_DEC,
71790075Sobrien    LAST_INDEXED_MODE
71890075Sobrien  };
71990075Sobrien
72090075Sobrien  //===--------------------------------------------------------------------===//
72190075Sobrien  /// LoadExtType enum - This enum defines the three variants of LOADEXT
72290075Sobrien  /// (load with extension).
72390075Sobrien  ///
72490075Sobrien  /// SEXTLOAD loads the integer operand and sign extends it to a larger
72596263Sobrien  ///          integer result type.
72690075Sobrien  /// ZEXTLOAD loads the integer operand and zero extends it to a larger
72790075Sobrien  ///          integer result type.
72890075Sobrien  /// EXTLOAD  is used for three things: floating point extending loads,
72990075Sobrien  ///          integer extending loads [the top bits are undefined], and vector
73090075Sobrien  ///          extending loads [load into low elt].
73190075Sobrien  ///
73290075Sobrien  enum LoadExtType {
73390075Sobrien    NON_EXTLOAD = 0,
73490075Sobrien    EXTLOAD,
73590075Sobrien    SEXTLOAD,
73690075Sobrien    ZEXTLOAD,
73790075Sobrien    LAST_LOADEXT_TYPE
73890075Sobrien  };
73990075Sobrien
74090075Sobrien  //===--------------------------------------------------------------------===//
74190075Sobrien  /// ISD::CondCode enum - These are ordered carefully to make the bitfields
74290075Sobrien  /// below work out, when considering SETFALSE (something that never exists
74390075Sobrien  /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
74490075Sobrien  /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
74590075Sobrien  /// to.  If the "N" column is 1, the result of the comparison is undefined if
74690075Sobrien  /// the input is a NAN.
74790075Sobrien  ///
74890075Sobrien  /// All of these (except for the 'always folded ops') should be handled for
74990075Sobrien  /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
75090075Sobrien  /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
75190075Sobrien  ///
75290075Sobrien  /// Note that these are laid out in a specific order to allow bit-twiddling
75390075Sobrien  /// to transform conditions.
75490075Sobrien  enum CondCode {
75590075Sobrien    // Opcode          N U L G E       Intuitive operation
75690075Sobrien    SETFALSE,      //    0 0 0 0       Always false (always folded)
75790075Sobrien    SETOEQ,        //    0 0 0 1       True if ordered and equal
75890075Sobrien    SETOGT,        //    0 0 1 0       True if ordered and greater than
75990075Sobrien    SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
76090075Sobrien    SETOLT,        //    0 1 0 0       True if ordered and less than
76190075Sobrien    SETOLE,        //    0 1 0 1       True if ordered and less than or equal
76290075Sobrien    SETONE,        //    0 1 1 0       True if ordered and operands are unequal
76390075Sobrien    SETO,          //    0 1 1 1       True if ordered (no nans)
76490075Sobrien    SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
76590075Sobrien    SETUEQ,        //    1 0 0 1       True if unordered or equal
76690075Sobrien    SETUGT,        //    1 0 1 0       True if unordered or greater than
76790075Sobrien    SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
76890075Sobrien    SETULT,        //    1 1 0 0       True if unordered or less than
76990075Sobrien    SETULE,        //    1 1 0 1       True if unordered, less than, or equal
77090075Sobrien    SETUNE,        //    1 1 1 0       True if unordered or not equal
77190075Sobrien    SETTRUE,       //    1 1 1 1       Always true (always folded)
77290075Sobrien    // Don't care operations: undefined if the input is a nan.
77390075Sobrien    SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
77490075Sobrien    SETEQ,         //  1 X 0 0 1       True if equal
77590075Sobrien    SETGT,         //  1 X 0 1 0       True if greater than
77690075Sobrien    SETGE,         //  1 X 0 1 1       True if greater than or equal
77790075Sobrien    SETLT,         //  1 X 1 0 0       True if less than
77890075Sobrien    SETLE,         //  1 X 1 0 1       True if less than or equal
77990075Sobrien    SETNE,         //  1 X 1 1 0       True if not equal
78090075Sobrien    SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
78190075Sobrien
78290075Sobrien    SETCC_INVALID       // Marker value.
78390075Sobrien  };
78490075Sobrien
78590075Sobrien  /// isSignedIntSetCC - Return true if this is a setcc instruction that
78690075Sobrien  /// performs a signed comparison when used with integer operands.
78790075Sobrien  inline bool isSignedIntSetCC(CondCode Code) {
78890075Sobrien    return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
78990075Sobrien  }
79090075Sobrien
79190075Sobrien  /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
79290075Sobrien  /// performs an unsigned comparison when used with integer operands.
79390075Sobrien  inline bool isUnsignedIntSetCC(CondCode Code) {
79490075Sobrien    return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
79590075Sobrien  }
79690075Sobrien
79790075Sobrien  /// isTrueWhenEqual - Return true if the specified condition returns true if
79890075Sobrien  /// the two operands to the condition are equal.  Note that if one of the two
79990075Sobrien  /// operands is a NaN, this value is meaningless.
80090075Sobrien  inline bool isTrueWhenEqual(CondCode Cond) {
80190075Sobrien    return ((int)Cond & 1) != 0;
80290075Sobrien  }
80390075Sobrien
80490075Sobrien  /// getUnorderedFlavor - This function returns 0 if the condition is always
80590075Sobrien  /// false if an operand is a NaN, 1 if the condition is always true if the
80690075Sobrien  /// operand is a NaN, and 2 if the condition is undefined if the operand is a
80790075Sobrien  /// NaN.
80890075Sobrien  inline unsigned getUnorderedFlavor(CondCode Cond) {
80990075Sobrien    return ((int)Cond >> 3) & 3;
81090075Sobrien  }
81190075Sobrien
81290075Sobrien  /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
81390075Sobrien  /// 'op' is a valid SetCC operation.
81490075Sobrien  CondCode getSetCCInverse(CondCode Operation, bool isInteger);
81590075Sobrien
81690075Sobrien  /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
81790075Sobrien  /// when given the operation for (X op Y).
81890075Sobrien  CondCode getSetCCSwappedOperands(CondCode Operation);
81990075Sobrien
82090075Sobrien  /// getSetCCOrOperation - Return the result of a logical OR between different
82190075Sobrien  /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
82290075Sobrien  /// function returns SETCC_INVALID if it is not possible to represent the
82390075Sobrien  /// resultant comparison.
82490075Sobrien  CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
82590075Sobrien
82690075Sobrien  /// getSetCCAndOperation - Return the result of a logical AND between
82790075Sobrien  /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
82890075Sobrien  /// function returns SETCC_INVALID if it is not possible to represent the
82990075Sobrien  /// resultant comparison.
83090075Sobrien  CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
83190075Sobrien
83290075Sobrien  //===--------------------------------------------------------------------===//
83390075Sobrien  /// CvtCode enum - This enum defines the various converts CONVERT_RNDSAT
83490075Sobrien  /// supports.
83590075Sobrien  enum CvtCode {
83690075Sobrien    CVT_FF,     // Float from Float
83790075Sobrien    CVT_FS,     // Float from Signed
83890075Sobrien    CVT_FU,     // Float from Unsigned
83990075Sobrien    CVT_SF,     // Signed from Float
84090075Sobrien    CVT_UF,     // Unsigned from Float
84190075Sobrien    CVT_SS,     // Signed from Signed
84290075Sobrien    CVT_SU,     // Signed from Unsigned
84390075Sobrien    CVT_US,     // Unsigned from Signed
84490075Sobrien    CVT_UU,     // Unsigned from Unsigned
84590075Sobrien    CVT_INVALID // Marker - Invalid opcode
84690075Sobrien  };
84790075Sobrien}  // end llvm::ISD namespace
84890075Sobrien
84990075Sobrien
85090075Sobrien//===----------------------------------------------------------------------===//
85190075Sobrien/// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
85290075Sobrien/// values as the result of a computation.  Many nodes return multiple values,
85390075Sobrien/// from loads (which define a token and a return value) to ADDC (which returns
85490075Sobrien/// a result and a carry value), to calls (which may return an arbitrary number
85590075Sobrien/// of values).
85690075Sobrien///
85790075Sobrien/// As such, each use of a SelectionDAG computation must indicate the node that
85890075Sobrien/// computes it as well as which return value to use from that node.  This pair
85990075Sobrien/// of information is represented with the SDValue value type.
86090075Sobrien///
86190075Sobrienclass SDValue {
86290075Sobrien  SDNode *Node;       // The node defining the value we are using.
86390075Sobrien  unsigned ResNo;     // Which return value of the node we are using.
86490075Sobrienpublic:
86590075Sobrien  SDValue() : Node(0), ResNo(0) {}
86690075Sobrien  SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
86790075Sobrien
86890075Sobrien  /// get the index which selects a specific result in the SDNode
86990075Sobrien  unsigned getResNo() const { return ResNo; }
87090075Sobrien
87190075Sobrien  /// get the SDNode which holds the desired result
87290075Sobrien  SDNode *getNode() const { return Node; }
87390075Sobrien
87490075Sobrien  /// set the SDNode
87590075Sobrien  void setNode(SDNode *N) { Node = N; }
87690075Sobrien
87790075Sobrien  bool operator==(const SDValue &O) const {
87890075Sobrien    return Node == O.Node && ResNo == O.ResNo;
87990075Sobrien  }
88090075Sobrien  bool operator!=(const SDValue &O) const {
88190075Sobrien    return !operator==(O);
88290075Sobrien  }
88390075Sobrien  bool operator<(const SDValue &O) const {
88490075Sobrien    return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
88590075Sobrien  }
88690075Sobrien
88790075Sobrien  SDValue getValue(unsigned R) const {
88890075Sobrien    return SDValue(Node, R);
88990075Sobrien  }
89090075Sobrien
89190075Sobrien  // isOperandOf - Return true if this node is an operand of N.
89290075Sobrien  bool isOperandOf(SDNode *N) const;
89390075Sobrien
89490075Sobrien  /// getValueType - Return the ValueType of the referenced return value.
89590075Sobrien  ///
89690075Sobrien  inline MVT getValueType() const;
89790075Sobrien
89890075Sobrien  /// getValueSizeInBits - Returns the size of the value in bits.
89990075Sobrien  ///
90090075Sobrien  unsigned getValueSizeInBits() const {
90190075Sobrien    return getValueType().getSizeInBits();
90290075Sobrien  }
90390075Sobrien
90490075Sobrien  // Forwarding methods - These forward to the corresponding methods in SDNode.
90590075Sobrien  inline unsigned getOpcode() const;
90690075Sobrien  inline unsigned getNumOperands() const;
90790075Sobrien  inline const SDValue &getOperand(unsigned i) const;
90890075Sobrien  inline uint64_t getConstantOperandVal(unsigned i) const;
90990075Sobrien  inline bool isTargetOpcode() const;
91090075Sobrien  inline bool isMachineOpcode() const;
91190075Sobrien  inline unsigned getMachineOpcode() const;
91290075Sobrien  inline const DebugLoc getDebugLoc() const;
91390075Sobrien
91490075Sobrien
91590075Sobrien  /// reachesChainWithoutSideEffects - Return true if this operand (which must
91690075Sobrien  /// be a chain) reaches the specified operand without crossing any
91790075Sobrien  /// side-effecting instructions.  In practice, this looks through token
91890075Sobrien  /// factors and non-volatile loads.  In order to remain efficient, this only
91990075Sobrien  /// looks a couple of nodes in, it does not do an exhaustive search.
92090075Sobrien  bool reachesChainWithoutSideEffects(SDValue Dest,
92190075Sobrien                                      unsigned Depth = 2) const;
92290075Sobrien
92390075Sobrien  /// use_empty - Return true if there are no nodes using value ResNo
92490075Sobrien  /// of Node.
925104752Skan  ///
926104752Skan  inline bool use_empty() const;
927104752Skan
928104752Skan  /// hasOneUse - Return true if there is exactly one node using value
929104752Skan  /// ResNo of Node.
930104752Skan  ///
931104752Skan  inline bool hasOneUse() const;
932104752Skan};
933104752Skan
93490075Sobrien
93590075Sobrientemplate<> struct DenseMapInfo<SDValue> {
93690075Sobrien  static inline SDValue getEmptyKey() {
93790075Sobrien    return SDValue((SDNode*)-1, -1U);
93890075Sobrien  }
93990075Sobrien  static inline SDValue getTombstoneKey() {
94090075Sobrien    return SDValue((SDNode*)-1, 0);
94190075Sobrien  }
94290075Sobrien  static unsigned getHashValue(const SDValue &Val) {
94390075Sobrien    return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
94490075Sobrien            (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
94590075Sobrien  }
94690075Sobrien  static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
94790075Sobrien    return LHS == RHS;
94890075Sobrien  }
94990075Sobrien  static bool isPod() { return true; }
95090075Sobrien};
95190075Sobrien
95290075Sobrien/// simplify_type specializations - Allow casting operators to work directly on
95390075Sobrien/// SDValues as if they were SDNode*'s.
95490075Sobrientemplate<> struct simplify_type<SDValue> {
95590075Sobrien  typedef SDNode* SimpleType;
95690075Sobrien  static SimpleType getSimplifiedValue(const SDValue &Val) {
95790075Sobrien    return static_cast<SimpleType>(Val.getNode());
95890075Sobrien  }
95990075Sobrien};
96090075Sobrientemplate<> struct simplify_type<const SDValue> {
96190075Sobrien  typedef SDNode* SimpleType;
96290075Sobrien  static SimpleType getSimplifiedValue(const SDValue &Val) {
96390075Sobrien    return static_cast<SimpleType>(Val.getNode());
96490075Sobrien  }
96590075Sobrien};
96690075Sobrien
96790075Sobrien/// SDUse - Represents a use of a SDNode. This class holds an SDValue,
96890075Sobrien/// which records the SDNode being used and the result number, a
96990075Sobrien/// pointer to the SDNode using the value, and Next and Prev pointers,
97090075Sobrien/// which link together all the uses of an SDNode.
97190075Sobrien///
97290075Sobrienclass SDUse {
97390075Sobrien  /// Val - The value being used.
97490075Sobrien  SDValue Val;
97590075Sobrien  /// User - The user of this value.
97690075Sobrien  SDNode *User;
97790075Sobrien  /// Prev, Next - Pointers to the uses list of the SDNode referred by
97890075Sobrien  /// this operand.
97990075Sobrien  SDUse **Prev, *Next;
98090075Sobrien
98190075Sobrien  SDUse(const SDUse &U);          // Do not implement
98290075Sobrien  void operator=(const SDUse &U); // Do not implement
98390075Sobrien
98490075Sobrienpublic:
98590075Sobrien  SDUse() : Val(), User(NULL), Prev(NULL), Next(NULL) {}
98690075Sobrien
98790075Sobrien  /// Normally SDUse will just implicitly convert to an SDValue that it holds.
98890075Sobrien  operator const SDValue&() const { return Val; }
98990075Sobrien
99090075Sobrien  /// If implicit conversion to SDValue doesn't work, the get() method returns
99190075Sobrien  /// the SDValue.
99290075Sobrien  const SDValue &get() const { return Val; }
99390075Sobrien
99490075Sobrien  /// getUser - This returns the SDNode that contains this Use.
99590075Sobrien  SDNode *getUser() { return User; }
99690075Sobrien
99790075Sobrien  /// getNext - Get the next SDUse in the use list.
99890075Sobrien  SDUse *getNext() const { return Next; }
99990075Sobrien
100090075Sobrien  /// getNode - Convenience function for get().getNode().
100190075Sobrien  SDNode *getNode() const { return Val.getNode(); }
100290075Sobrien  /// getResNo - Convenience function for get().getResNo().
100390075Sobrien  unsigned getResNo() const { return Val.getResNo(); }
100490075Sobrien  /// getValueType - Convenience function for get().getValueType().
100590075Sobrien  MVT getValueType() const { return Val.getValueType(); }
100690075Sobrien
100790075Sobrien  /// operator== - Convenience function for get().operator==
100890075Sobrien  bool operator==(const SDValue &V) const {
100990075Sobrien    return Val == V;
101090075Sobrien  }
101190075Sobrien
101290075Sobrien  /// operator!= - Convenience function for get().operator!=
101390075Sobrien  bool operator!=(const SDValue &V) const {
101490075Sobrien    return Val != V;
101590075Sobrien  }
101690075Sobrien
101790075Sobrien  /// operator< - Convenience function for get().operator<
101890075Sobrien  bool operator<(const SDValue &V) const {
101990075Sobrien    return Val < V;
102090075Sobrien  }
102190075Sobrien
102290075Sobrienprivate:
102390075Sobrien  friend class SelectionDAG;
102490075Sobrien  friend class SDNode;
102590075Sobrien
102690075Sobrien  void setUser(SDNode *p) { User = p; }
102790075Sobrien
102890075Sobrien  /// set - Remove this use from its existing use list, assign it the
102990075Sobrien  /// given value, and add it to the new value's node's use list.
103090075Sobrien  inline void set(const SDValue &V);
103190075Sobrien  /// setInitial - like set, but only supports initializing a newly-allocated
103290075Sobrien  /// SDUse with a non-null value.
103390075Sobrien  inline void setInitial(const SDValue &V);
103490075Sobrien  /// setNode - like set, but only sets the Node portion of the value,
103590075Sobrien  /// leaving the ResNo portion unmodified.
103690075Sobrien  inline void setNode(SDNode *N);
103790075Sobrien
103890075Sobrien  void addToList(SDUse **List) {
103990075Sobrien    Next = *List;
104090075Sobrien    if (Next) Next->Prev = &Next;
104190075Sobrien    Prev = List;
1042117395Skan    *List = this;
104390075Sobrien  }
104490075Sobrien
104590075Sobrien  void removeFromList() {
104690075Sobrien    *Prev = Next;
104790075Sobrien    if (Next) Next->Prev = Prev;
104890075Sobrien  }
104990075Sobrien};
105090075Sobrien
105190075Sobrien/// simplify_type specializations - Allow casting operators to work directly on
105290075Sobrien/// SDValues as if they were SDNode*'s.
105390075Sobrientemplate<> struct simplify_type<SDUse> {
105490075Sobrien  typedef SDNode* SimpleType;
105590075Sobrien  static SimpleType getSimplifiedValue(const SDUse &Val) {
105690075Sobrien    return static_cast<SimpleType>(Val.getNode());
105790075Sobrien  }
105890075Sobrien};
105990075Sobrientemplate<> struct simplify_type<const SDUse> {
106090075Sobrien  typedef SDNode* SimpleType;
106190075Sobrien  static SimpleType getSimplifiedValue(const SDUse &Val) {
106290075Sobrien    return static_cast<SimpleType>(Val.getNode());
106390075Sobrien  }
106490075Sobrien};
106590075Sobrien
106690075Sobrien
106790075Sobrien/// SDNode - Represents one node in the SelectionDAG.
106890075Sobrien///
106990075Sobrienclass SDNode : public FoldingSetNode, public ilist_node<SDNode> {
107090075Sobrienprivate:
107190075Sobrien  /// NodeType - The operation that this node performs.
107290075Sobrien  ///
107390075Sobrien  short NodeType;
107490075Sobrien
107590075Sobrien  /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
107690075Sobrien  /// then they will be delete[]'d when the node is destroyed.
107790075Sobrien  unsigned short OperandsNeedDelete : 1;
107890075Sobrien
107990075Sobrienprotected:
108090075Sobrien  /// SubclassData - This member is defined by this class, but is not used for
108190075Sobrien  /// anything.  Subclasses can use it to hold whatever state they find useful.
108290075Sobrien  /// This field is initialized to zero by the ctor.
108390075Sobrien  unsigned short SubclassData : 15;
108490075Sobrien
108590075Sobrienprivate:
108690075Sobrien  /// NodeId - Unique id per SDNode in the DAG.
108790075Sobrien  int NodeId;
108890075Sobrien
108990075Sobrien  /// OperandList - The values that are used by this operation.
109090075Sobrien  ///
109190075Sobrien  SDUse *OperandList;
109290075Sobrien
109390075Sobrien  /// ValueList - The types of the values this node defines.  SDNode's may
109490075Sobrien  /// define multiple values simultaneously.
109590075Sobrien  const MVT *ValueList;
109690075Sobrien
109790075Sobrien  /// UseList - List of uses for this SDNode.
109890075Sobrien  SDUse *UseList;
109990075Sobrien
110090075Sobrien  /// NumOperands/NumValues - The number of entries in the Operand/Value list.
110190075Sobrien  unsigned short NumOperands, NumValues;
110290075Sobrien
110390075Sobrien  /// debugLoc - source line information.
110490075Sobrien  DebugLoc debugLoc;
110590075Sobrien
110690075Sobrien  /// getValueTypeList - Return a pointer to the specified value type.
110790075Sobrien  static const MVT *getValueTypeList(MVT VT);
110890075Sobrien
110990075Sobrien  friend class SelectionDAG;
111090075Sobrien  friend struct ilist_traits<SDNode>;
111190075Sobrien
111290075Sobrienpublic:
111390075Sobrien  //===--------------------------------------------------------------------===//
111490075Sobrien  //  Accessors
111590075Sobrien  //
111690075Sobrien
111790075Sobrien  /// getOpcode - Return the SelectionDAG opcode value for this node. For
111890075Sobrien  /// pre-isel nodes (those for which isMachineOpcode returns false), these
111990075Sobrien  /// are the opcode values in the ISD and <target>ISD namespaces. For
112090075Sobrien  /// post-isel opcodes, see getMachineOpcode.
112190075Sobrien  unsigned getOpcode()  const { return (unsigned short)NodeType; }
112290075Sobrien
112390075Sobrien  /// isTargetOpcode - Test if this node has a target-specific opcode (in the
112490075Sobrien  /// \<target\>ISD namespace).
112590075Sobrien  bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
112690075Sobrien
112790075Sobrien  /// isMachineOpcode - Test if this node has a post-isel opcode, directly
112890075Sobrien  /// corresponding to a MachineInstr opcode.
112990075Sobrien  bool isMachineOpcode() const { return NodeType < 0; }
113090075Sobrien
113190075Sobrien  /// getMachineOpcode - This may only be called if isMachineOpcode returns
113290075Sobrien  /// true. It returns the MachineInstr opcode value that the node's opcode
113390075Sobrien  /// corresponds to.
113490075Sobrien  unsigned getMachineOpcode() const {
113590075Sobrien    assert(isMachineOpcode() && "Not a MachineInstr opcode!");
113690075Sobrien    return ~NodeType;
1137103445Skan  }
113890075Sobrien
113990075Sobrien  /// use_empty - Return true if there are no uses of this node.
114090075Sobrien  ///
114190075Sobrien  bool use_empty() const { return UseList == NULL; }
114290075Sobrien
114390075Sobrien  /// hasOneUse - Return true if there is exactly one use of this node.
114490075Sobrien  ///
114590075Sobrien  bool hasOneUse() const {
114690075Sobrien    return !use_empty() && next(use_begin()) == use_end();
114790075Sobrien  }
114890075Sobrien
114990075Sobrien  /// use_size - Return the number of uses of this node. This method takes
115090075Sobrien  /// time proportional to the number of uses.
115190075Sobrien  ///
115290075Sobrien  size_t use_size() const { return std::distance(use_begin(), use_end()); }
115390075Sobrien
115490075Sobrien  /// getNodeId - Return the unique node id.
115590075Sobrien  ///
115690075Sobrien  int getNodeId() const { return NodeId; }
115790075Sobrien
115890075Sobrien  /// setNodeId - Set unique node id.
115990075Sobrien  void setNodeId(int Id) { NodeId = Id; }
116090075Sobrien
116190075Sobrien  /// getDebugLoc - Return the source location info.
116290075Sobrien  const DebugLoc getDebugLoc() const { return debugLoc; }
116390075Sobrien
116490075Sobrien  /// setDebugLoc - Set source location info.  Try to avoid this, putting
116590075Sobrien  /// it in the constructor is preferable.
116690075Sobrien  void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
116790075Sobrien
116890075Sobrien  /// use_iterator - This class provides iterator support for SDUse
116990075Sobrien  /// operands that use a specific SDNode.
117090075Sobrien  class use_iterator
117190075Sobrien    : public forward_iterator<SDUse, ptrdiff_t> {
1172102780Skan    SDUse *Op;
1173102780Skan    explicit use_iterator(SDUse *op) : Op(op) {
1174102780Skan    }
1175102780Skan    friend class SDNode;
1176102780Skan  public:
1177102780Skan    typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
1178102780Skan    typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1179102780Skan
1180102780Skan    use_iterator(const use_iterator &I) : Op(I.Op) {}
1181102780Skan    use_iterator() : Op(0) {}
118290075Sobrien
118390075Sobrien    bool operator==(const use_iterator &x) const {
118490075Sobrien      return Op == x.Op;
118590075Sobrien    }
118690075Sobrien    bool operator!=(const use_iterator &x) const {
118790075Sobrien      return !operator==(x);
118890075Sobrien    }
118990075Sobrien
119090075Sobrien    /// atEnd - return true if this iterator is at the end of uses list.
119190075Sobrien    bool atEnd() const { return Op == 0; }
119290075Sobrien
119390075Sobrien    // Iterator traversal: forward iteration only.
119490075Sobrien    use_iterator &operator++() {          // Preincrement
119590075Sobrien      assert(Op && "Cannot increment end iterator!");
119690075Sobrien      Op = Op->getNext();
119790075Sobrien      return *this;
119890075Sobrien    }
119990075Sobrien
120090075Sobrien    use_iterator operator++(int) {        // Postincrement
120190075Sobrien      use_iterator tmp = *this; ++*this; return tmp;
120290075Sobrien    }
120390075Sobrien
120490075Sobrien    /// Retrieve a pointer to the current user node.
120590075Sobrien    SDNode *operator*() const {
120690075Sobrien      assert(Op && "Cannot dereference end iterator!");
120790075Sobrien      return Op->getUser();
120890075Sobrien    }
120990075Sobrien
121090075Sobrien    SDNode *operator->() const { return operator*(); }
121190075Sobrien
121290075Sobrien    SDUse &getUse() const { return *Op; }
121390075Sobrien
121490075Sobrien    /// getOperandNo - Retrieve the operand # of this use in its user.
121590075Sobrien    ///
121690075Sobrien    unsigned getOperandNo() const {
121790075Sobrien      assert(Op && "Cannot dereference end iterator!");
121890075Sobrien      return (unsigned)(Op - Op->getUser()->OperandList);
121990075Sobrien    }
122090075Sobrien  };
122190075Sobrien
122290075Sobrien  /// use_begin/use_end - Provide iteration support to walk over all uses
122390075Sobrien  /// of an SDNode.
122490075Sobrien
122590075Sobrien  use_iterator use_begin() const {
122690075Sobrien    return use_iterator(UseList);
122790075Sobrien  }
122890075Sobrien
122990075Sobrien  static use_iterator use_end() { return use_iterator(0); }
123090075Sobrien
123190075Sobrien
123290075Sobrien  /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
123390075Sobrien  /// indicated value.  This method ignores uses of other values defined by this
123490075Sobrien  /// operation.
123590075Sobrien  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
123690075Sobrien
123790075Sobrien  /// hasAnyUseOfValue - Return true if there are any use of the indicated
123890075Sobrien  /// value. This method ignores uses of other values defined by this operation.
123990075Sobrien  bool hasAnyUseOfValue(unsigned Value) const;
124090075Sobrien
124190075Sobrien  /// isOnlyUserOf - Return true if this node is the only use of N.
124290075Sobrien  ///
124390075Sobrien  bool isOnlyUserOf(SDNode *N) const;
124490075Sobrien
1245117395Skan  /// isOperandOf - Return true if this node is an operand of N.
1246102780Skan  ///
124790075Sobrien  bool isOperandOf(SDNode *N) const;
124890075Sobrien
124990075Sobrien  /// isPredecessorOf - Return true if this node is a predecessor of N. This
125090075Sobrien  /// node is either an operand of N or it can be reached by recursively
125190075Sobrien  /// traversing up the operands.
125290075Sobrien  /// NOTE: this is an expensive method. Use it carefully.
125390075Sobrien  bool isPredecessorOf(SDNode *N) const;
125490075Sobrien
125590075Sobrien  /// getNumOperands - Return the number of values used by this operation.
125690075Sobrien  ///
125790075Sobrien  unsigned getNumOperands() const { return NumOperands; }
125890075Sobrien
125990075Sobrien  /// getConstantOperandVal - Helper method returns the integer value of a
126090075Sobrien  /// ConstantSDNode operand.
126190075Sobrien  uint64_t getConstantOperandVal(unsigned Num) const;
126290075Sobrien
126390075Sobrien  const SDValue &getOperand(unsigned Num) const {
126490075Sobrien    assert(Num < NumOperands && "Invalid child # of SDNode!");
126590075Sobrien    return OperandList[Num];
126690075Sobrien  }
126790075Sobrien
126890075Sobrien  typedef SDUse* op_iterator;
126990075Sobrien  op_iterator op_begin() const { return OperandList; }
127090075Sobrien  op_iterator op_end() const { return OperandList+NumOperands; }
127190075Sobrien
127290075Sobrien  SDVTList getVTList() const {
127390075Sobrien    SDVTList X = { ValueList, NumValues };
127490075Sobrien    return X;
127590075Sobrien  };
127690075Sobrien
127790075Sobrien  /// getFlaggedNode - If this node has a flag operand, return the node
127890075Sobrien  /// to which the flag operand points. Otherwise return NULL.
127990075Sobrien  SDNode *getFlaggedNode() const {
128090075Sobrien    if (getNumOperands() != 0 &&
128190075Sobrien        getOperand(getNumOperands()-1).getValueType() == MVT::Flag)
128290075Sobrien      return getOperand(getNumOperands()-1).getNode();
128390075Sobrien    return 0;
128490075Sobrien  }
128590075Sobrien
128690075Sobrien  // If this is a pseudo op, like copyfromreg, look to see if there is a
128790075Sobrien  // real target node flagged to it.  If so, return the target node.
128890075Sobrien  const SDNode *getFlaggedMachineNode() const {
128990075Sobrien    const SDNode *FoundNode = this;
1290117395Skan
1291117395Skan    // Climb up flag edges until a machine-opcode node is found, or the
1292117395Skan    // end of the chain is reached.
1293117395Skan    while (!FoundNode->isMachineOpcode()) {
1294117395Skan      const SDNode *N = FoundNode->getFlaggedNode();
1295117395Skan      if (!N) break;
129690075Sobrien      FoundNode = N;
129790075Sobrien    }
129890075Sobrien
129990075Sobrien    return FoundNode;
130090075Sobrien  }
130190075Sobrien
130290075Sobrien  /// getNumValues - Return the number of values defined/returned by this
130390075Sobrien  /// operator.
130490075Sobrien  ///
130590075Sobrien  unsigned getNumValues() const { return NumValues; }
130690075Sobrien
130790075Sobrien  /// getValueType - Return the type of a specified result.
130890075Sobrien  ///
130990075Sobrien  MVT getValueType(unsigned ResNo) const {
131090075Sobrien    assert(ResNo < NumValues && "Illegal result number!");
131190075Sobrien    return ValueList[ResNo];
131290075Sobrien  }
131390075Sobrien
131490075Sobrien  /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
131590075Sobrien  ///
131690075Sobrien  unsigned getValueSizeInBits(unsigned ResNo) const {
131790075Sobrien    return getValueType(ResNo).getSizeInBits();
131890075Sobrien  }
131990075Sobrien
132090075Sobrien  typedef const MVT* value_iterator;
132190075Sobrien  value_iterator value_begin() const { return ValueList; }
132290075Sobrien  value_iterator value_end() const { return ValueList+NumValues; }
132390075Sobrien
132490075Sobrien  /// getOperationName - Return the opcode of this operation for printing.
132590075Sobrien  ///
132690075Sobrien  std::string getOperationName(const SelectionDAG *G = 0) const;
132790075Sobrien  static const char* getIndexedModeName(ISD::MemIndexedMode AM);
132890075Sobrien  void print_types(raw_ostream &OS, const SelectionDAG *G) const;
132990075Sobrien  void print_details(raw_ostream &OS, const SelectionDAG *G) const;
133090075Sobrien  void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
133190075Sobrien  void printr(raw_ostream &OS, const SelectionDAG *G = 0) const;
133290075Sobrien  void dump() const;
133390075Sobrien  void dumpr() const;
133490075Sobrien  void dump(const SelectionDAG *G) const;
133590075Sobrien
133690075Sobrien  static bool classof(const SDNode *) { return true; }
133790075Sobrien
133890075Sobrien  /// Profile - Gather unique data for the node.
133990075Sobrien  ///
1340117395Skan  void Profile(FoldingSetNodeID &ID) const;
134190075Sobrien
134290075Sobrien  /// addUse - This method should only be used by the SDUse class.
134390075Sobrien  ///
134490075Sobrien  void addUse(SDUse &U) { U.addToList(&UseList); }
134590075Sobrien
134690075Sobrienprotected:
134790075Sobrien  static SDVTList getSDVTList(MVT VT) {
134890075Sobrien    SDVTList Ret = { getValueTypeList(VT), 1 };
134990075Sobrien    return Ret;
135090075Sobrien  }
135190075Sobrien
135290075Sobrien  SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops,
135390075Sobrien         unsigned NumOps)
135490075Sobrien    : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
135590075Sobrien      NodeId(-1),
135690075Sobrien      OperandList(NumOps ? new SDUse[NumOps] : 0),
135790075Sobrien      ValueList(VTs.VTs), UseList(NULL),
135890075Sobrien      NumOperands(NumOps), NumValues(VTs.NumVTs),
135990075Sobrien      debugLoc(dl) {
136090075Sobrien    for (unsigned i = 0; i != NumOps; ++i) {
136190075Sobrien      OperandList[i].setUser(this);
136290075Sobrien      OperandList[i].setInitial(Ops[i]);
136390075Sobrien    }
136490075Sobrien  }
1365102780Skan
1366102780Skan  /// This constructor adds no operands itself; operands can be
1367102780Skan  /// set later with InitOperands.
1368102780Skan  SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs)
1369102780Skan    : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1370102780Skan      NodeId(-1), OperandList(0), ValueList(VTs.VTs), UseList(NULL),
1371102780Skan      NumOperands(0), NumValues(VTs.NumVTs),
1372102780Skan      debugLoc(dl) {}
1373102780Skan
1374102780Skan  /// InitOperands - Initialize the operands list of this with 1 operand.
1375102780Skan  void InitOperands(SDUse *Ops, const SDValue &Op0) {
1376102780Skan    Ops[0].setUser(this);
1377102780Skan    Ops[0].setInitial(Op0);
1378102780Skan    NumOperands = 1;
1379102780Skan    OperandList = Ops;
1380102780Skan  }
1381102780Skan
1382102780Skan  /// InitOperands - Initialize the operands list of this with 2 operands.
1383102780Skan  void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
1384102780Skan    Ops[0].setUser(this);
1385102780Skan    Ops[0].setInitial(Op0);
1386102780Skan    Ops[1].setUser(this);
1387102780Skan    Ops[1].setInitial(Op1);
1388102780Skan    NumOperands = 2;
1389102780Skan    OperandList = Ops;
1390102780Skan  }
1391102780Skan
1392102780Skan  /// InitOperands - Initialize the operands list of this with 3 operands.
1393102780Skan  void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
1394102780Skan                    const SDValue &Op2) {
1395102780Skan    Ops[0].setUser(this);
1396102780Skan    Ops[0].setInitial(Op0);
1397102780Skan    Ops[1].setUser(this);
1398102780Skan    Ops[1].setInitial(Op1);
1399102780Skan    Ops[2].setUser(this);
1400102780Skan    Ops[2].setInitial(Op2);
1401102780Skan    NumOperands = 3;
1402102780Skan    OperandList = Ops;
1403102780Skan  }
1404102780Skan
140590075Sobrien  /// InitOperands - Initialize the operands list of this with 4 operands.
140690075Sobrien  void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
140790075Sobrien                    const SDValue &Op2, const SDValue &Op3) {
140890075Sobrien    Ops[0].setUser(this);
140990075Sobrien    Ops[0].setInitial(Op0);
141090075Sobrien    Ops[1].setUser(this);
141190075Sobrien    Ops[1].setInitial(Op1);
141290075Sobrien    Ops[2].setUser(this);
141390075Sobrien    Ops[2].setInitial(Op2);
141490075Sobrien    Ops[3].setUser(this);
141590075Sobrien    Ops[3].setInitial(Op3);
141690075Sobrien    NumOperands = 4;
141790075Sobrien    OperandList = Ops;
141890075Sobrien  }
141990075Sobrien
142090075Sobrien  /// InitOperands - Initialize the operands list of this with N operands.
142190075Sobrien  void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
142290075Sobrien    for (unsigned i = 0; i != N; ++i) {
142390075Sobrien      Ops[i].setUser(this);
142490075Sobrien      Ops[i].setInitial(Vals[i]);
142590075Sobrien    }
142690075Sobrien    NumOperands = N;
142790075Sobrien    OperandList = Ops;
142890075Sobrien  }
142990075Sobrien
143090075Sobrien  /// DropOperands - Release the operands and set this node to have
143190075Sobrien  /// zero operands.
143290075Sobrien  void DropOperands();
143390075Sobrien};
143490075Sobrien
143590075Sobrien
143690075Sobrien// Define inline functions from the SDValue class.
143790075Sobrien
143890075Sobrieninline unsigned SDValue::getOpcode() const {
143990075Sobrien  return Node->getOpcode();
144090075Sobrien}
144190075Sobrieninline MVT SDValue::getValueType() const {
144290075Sobrien  return Node->getValueType(ResNo);
144390075Sobrien}
144490075Sobrieninline unsigned SDValue::getNumOperands() const {
144590075Sobrien  return Node->getNumOperands();
144690075Sobrien}
144790075Sobrieninline const SDValue &SDValue::getOperand(unsigned i) const {
144890075Sobrien  return Node->getOperand(i);
144990075Sobrien}
145090075Sobrieninline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
145190075Sobrien  return Node->getConstantOperandVal(i);
145290075Sobrien}
145390075Sobrieninline bool SDValue::isTargetOpcode() const {
145490075Sobrien  return Node->isTargetOpcode();
145590075Sobrien}
145690075Sobrieninline bool SDValue::isMachineOpcode() const {
145790075Sobrien  return Node->isMachineOpcode();
145890075Sobrien}
145990075Sobrieninline unsigned SDValue::getMachineOpcode() const {
146090075Sobrien  return Node->getMachineOpcode();
146190075Sobrien}
146290075Sobrieninline bool SDValue::use_empty() const {
146390075Sobrien  return !Node->hasAnyUseOfValue(ResNo);
146490075Sobrien}
146590075Sobrieninline bool SDValue::hasOneUse() const {
146690075Sobrien  return Node->hasNUsesOfValue(1, ResNo);
146790075Sobrien}
146890075Sobrieninline const DebugLoc SDValue::getDebugLoc() const {
146990075Sobrien  return Node->getDebugLoc();
147090075Sobrien}
147190075Sobrien
147290075Sobrien// Define inline functions from the SDUse class.
147390075Sobrien
147490075Sobrieninline void SDUse::set(const SDValue &V) {
147590075Sobrien  if (Val.getNode()) removeFromList();
147690075Sobrien  Val = V;
147790075Sobrien  if (V.getNode()) V.getNode()->addUse(*this);
147890075Sobrien}
147990075Sobrien
148090075Sobrieninline void SDUse::setInitial(const SDValue &V) {
148190075Sobrien  Val = V;
148290075Sobrien  V.getNode()->addUse(*this);
148390075Sobrien}
148490075Sobrien
148590075Sobrieninline void SDUse::setNode(SDNode *N) {
148690075Sobrien  if (Val.getNode()) removeFromList();
148790075Sobrien  Val.setNode(N);
148890075Sobrien  if (N) N->addUse(*this);
148990075Sobrien}
149090075Sobrien
149190075Sobrien/// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
149290075Sobrien/// to allow co-allocation of node operands with the node itself.
149390075Sobrienclass UnarySDNode : public SDNode {
149490075Sobrien  SDUse Op;
149590075Sobrienpublic:
149690075Sobrien  UnarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X)
149790075Sobrien    : SDNode(Opc, dl, VTs) {
1498102780Skan    InitOperands(&Op, X);
149990075Sobrien  }
150090075Sobrien};
150190075Sobrien
150290075Sobrien/// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
150390075Sobrien/// to allow co-allocation of node operands with the node itself.
150490075Sobrienclass BinarySDNode : public SDNode {
150590075Sobrien  SDUse Ops[2];
150690075Sobrienpublic:
150790075Sobrien  BinarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y)
150890075Sobrien    : SDNode(Opc, dl, VTs) {
150990075Sobrien    InitOperands(Ops, X, Y);
151090075Sobrien  }
151190075Sobrien};
151290075Sobrien
151390075Sobrien/// TernarySDNode - This class is used for three-operand SDNodes. This is solely
151490075Sobrien/// to allow co-allocation of node operands with the node itself.
151590075Sobrienclass TernarySDNode : public SDNode {
151690075Sobrien  SDUse Ops[3];
151790075Sobrienpublic:
151890075Sobrien  TernarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y,
151990075Sobrien                SDValue Z)
152090075Sobrien    : SDNode(Opc, dl, VTs) {
1521117395Skan    InitOperands(Ops, X, Y, Z);
1522117395Skan  }
1523117395Skan};
1524117395Skan
1525117395Skan
1526117395Skan/// HandleSDNode - This class is used to form a handle around another node that
152790075Sobrien/// is persistant and is updated across invocations of replaceAllUsesWith on its
152890075Sobrien/// operand.  This node should be directly created by end-users and not added to
152990075Sobrien/// the AllNodes list.
153090075Sobrienclass HandleSDNode : public SDNode {
153190075Sobrien  SDUse Op;
153290075Sobrienpublic:
153390075Sobrien  // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
153490075Sobrien  // fixed.
153590075Sobrien#ifdef __GNUC__
153690075Sobrien  explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
153790075Sobrien#else
153890075Sobrien  explicit HandleSDNode(SDValue X)
153990075Sobrien#endif
154090075Sobrien    : SDNode(ISD::HANDLENODE, DebugLoc::getUnknownLoc(),
154190075Sobrien             getSDVTList(MVT::Other)) {
154290075Sobrien    InitOperands(&Op, X);
154390075Sobrien  }
154490075Sobrien  ~HandleSDNode();
154590075Sobrien  const SDValue &getValue() const { return Op; }
154690075Sobrien};
154790075Sobrien
154890075Sobrien/// Abstact virtual class for operations for memory operations
154990075Sobrienclass MemSDNode : public SDNode {
155090075Sobrienprivate:
155190075Sobrien  // MemoryVT - VT of in-memory value.
155290075Sobrien  MVT MemoryVT;
155390075Sobrien
155490075Sobrien  //! SrcValue - Memory location for alias analysis.
155590075Sobrien  const Value *SrcValue;
155690075Sobrien
155790075Sobrien  //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
155890075Sobrien  int SVOffset;
155990075Sobrien
156090075Sobrienpublic:
156190075Sobrien  MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, MVT MemoryVT,
156290075Sobrien            const Value *srcValue, int SVOff,
156390075Sobrien            unsigned alignment, bool isvolatile);
156490075Sobrien
156590075Sobrien  MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, const SDValue *Ops,
156690075Sobrien            unsigned NumOps, MVT MemoryVT, const Value *srcValue, int SVOff,
156790075Sobrien            unsigned alignment, bool isvolatile);
156890075Sobrien
156990075Sobrien  /// Returns alignment and volatility of the memory access
157090075Sobrien  unsigned getAlignment() const { return (1u << (SubclassData >> 6)) >> 1; }
157190075Sobrien  bool isVolatile() const { return (SubclassData >> 5) & 1; }
157290075Sobrien
157390075Sobrien  /// getRawSubclassData - Return the SubclassData value, which contains an
157490075Sobrien  /// encoding of the alignment and volatile information, as well as bits
157590075Sobrien  /// used by subclasses. This function should only be used to compute a
157690075Sobrien  /// FoldingSetNodeID value.
157790075Sobrien  unsigned getRawSubclassData() const {
157890075Sobrien    return SubclassData;
157990075Sobrien  }
158090075Sobrien
158190075Sobrien  /// Returns the SrcValue and offset that describes the location of the access
158290075Sobrien  const Value *getSrcValue() const { return SrcValue; }
158390075Sobrien  int getSrcValueOffset() const { return SVOffset; }
158490075Sobrien
158590075Sobrien  /// getMemoryVT - Return the type of the in-memory value.
158690075Sobrien  MVT getMemoryVT() const { return MemoryVT; }
158790075Sobrien
158890075Sobrien  /// getMemOperand - Return a MachineMemOperand object describing the memory
158990075Sobrien  /// reference performed by operation.
159090075Sobrien  MachineMemOperand getMemOperand() const;
159190075Sobrien
159290075Sobrien  const SDValue &getChain() const { return getOperand(0); }
159390075Sobrien  const SDValue &getBasePtr() const {
159490075Sobrien    return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
159590075Sobrien  }
159690075Sobrien
159790075Sobrien  // Methods to support isa and dyn_cast
159890075Sobrien  static bool classof(const MemSDNode *) { return true; }
159990075Sobrien  static bool classof(const SDNode *N) {
160090075Sobrien    // For some targets, we lower some target intrinsics to a MemIntrinsicNode
160190075Sobrien    // with either an intrinsic or a target opcode.
160290075Sobrien    return N->getOpcode() == ISD::LOAD                ||
1603           N->getOpcode() == ISD::STORE               ||
1604           N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
1605           N->getOpcode() == ISD::ATOMIC_SWAP         ||
1606           N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
1607           N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
1608           N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
1609           N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
1610           N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
1611           N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
1612           N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
1613           N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
1614           N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
1615           N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
1616           N->getOpcode() == ISD::INTRINSIC_W_CHAIN   ||
1617           N->getOpcode() == ISD::INTRINSIC_VOID      ||
1618           N->isTargetOpcode();
1619  }
1620};
1621
1622/// AtomicSDNode - A SDNode reprenting atomic operations.
1623///
1624class AtomicSDNode : public MemSDNode {
1625  SDUse Ops[4];
1626
1627public:
1628  // Opc:   opcode for atomic
1629  // VTL:    value type list
1630  // Chain:  memory chain for operaand
1631  // Ptr:    address to update as a SDValue
1632  // Cmp:    compare value
1633  // Swp:    swap value
1634  // SrcVal: address to update as a Value (used for MemOperand)
1635  // Align:  alignment of memory
1636  AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, MVT MemVT,
1637               SDValue Chain, SDValue Ptr,
1638               SDValue Cmp, SDValue Swp, const Value* SrcVal,
1639               unsigned Align=0)
1640    : MemSDNode(Opc, dl, VTL, MemVT, SrcVal, /*SVOffset=*/0,
1641                Align, /*isVolatile=*/true) {
1642    InitOperands(Ops, Chain, Ptr, Cmp, Swp);
1643  }
1644  AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, MVT MemVT,
1645               SDValue Chain, SDValue Ptr,
1646               SDValue Val, const Value* SrcVal, unsigned Align=0)
1647    : MemSDNode(Opc, dl, VTL, MemVT, SrcVal, /*SVOffset=*/0,
1648                Align, /*isVolatile=*/true) {
1649    InitOperands(Ops, Chain, Ptr, Val);
1650  }
1651
1652  const SDValue &getBasePtr() const { return getOperand(1); }
1653  const SDValue &getVal() const { return getOperand(2); }
1654
1655  bool isCompareAndSwap() const {
1656    unsigned Op = getOpcode();
1657    return Op == ISD::ATOMIC_CMP_SWAP;
1658  }
1659
1660  // Methods to support isa and dyn_cast
1661  static bool classof(const AtomicSDNode *) { return true; }
1662  static bool classof(const SDNode *N) {
1663    return N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
1664           N->getOpcode() == ISD::ATOMIC_SWAP         ||
1665           N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
1666           N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
1667           N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
1668           N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
1669           N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
1670           N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
1671           N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
1672           N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
1673           N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
1674           N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1675  }
1676};
1677
1678/// MemIntrinsicSDNode - This SDNode is used for target intrinsic that touches
1679/// memory and need an associated memory operand.
1680///
1681class MemIntrinsicSDNode : public MemSDNode {
1682  bool ReadMem;  // Intrinsic reads memory
1683  bool WriteMem; // Intrinsic writes memory
1684public:
1685  MemIntrinsicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs,
1686                     const SDValue *Ops, unsigned NumOps,
1687                     MVT MemoryVT, const Value *srcValue, int SVO,
1688                     unsigned Align, bool Vol, bool ReadMem, bool WriteMem)
1689    : MemSDNode(Opc, dl, VTs, Ops, NumOps, MemoryVT, srcValue, SVO, Align, Vol),
1690      ReadMem(ReadMem), WriteMem(WriteMem) {
1691  }
1692
1693  bool readMem() const { return ReadMem; }
1694  bool writeMem() const { return WriteMem; }
1695
1696  // Methods to support isa and dyn_cast
1697  static bool classof(const MemIntrinsicSDNode *) { return true; }
1698  static bool classof(const SDNode *N) {
1699    // We lower some target intrinsics to their target opcode
1700    // early a node with a target opcode can be of this class
1701    return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1702           N->getOpcode() == ISD::INTRINSIC_VOID ||
1703           N->isTargetOpcode();
1704  }
1705};
1706
1707/// ShuffleVectorSDNode - This SDNode is used to implement the code generator
1708/// support for the llvm IR shufflevector instruction.  It combines elements
1709/// from two input vectors into a new input vector, with the selection and
1710/// ordering of elements determined by an array of integers, referred to as
1711/// the shuffle mask.  For input vectors of width N, mask indices of 0..N-1
1712/// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1713/// An index of -1 is treated as undef, such that the code generator may put
1714/// any value in the corresponding element of the result.
1715class ShuffleVectorSDNode : public SDNode {
1716  SDUse Ops[2];
1717
1718  // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1719  // is freed when the SelectionDAG object is destroyed.
1720  const int *Mask;
1721protected:
1722  friend class SelectionDAG;
1723  ShuffleVectorSDNode(MVT VT, DebugLoc dl, SDValue N1, SDValue N2,
1724                      const int *M)
1725    : SDNode(ISD::VECTOR_SHUFFLE, dl, getSDVTList(VT)), Mask(M) {
1726    InitOperands(Ops, N1, N2);
1727  }
1728public:
1729
1730  void getMask(SmallVectorImpl<int> &M) const {
1731    MVT VT = getValueType(0);
1732    M.clear();
1733    for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i)
1734      M.push_back(Mask[i]);
1735  }
1736  int getMaskElt(unsigned Idx) const {
1737    assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1738    return Mask[Idx];
1739  }
1740
1741  bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1742  int  getSplatIndex() const {
1743    assert(isSplat() && "Cannot get splat index for non-splat!");
1744    return Mask[0];
1745  }
1746  static bool isSplatMask(const int *Mask, MVT VT);
1747
1748  static bool classof(const ShuffleVectorSDNode *) { return true; }
1749  static bool classof(const SDNode *N) {
1750    return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1751  }
1752};
1753
1754class ConstantSDNode : public SDNode {
1755  const ConstantInt *Value;
1756  friend class SelectionDAG;
1757  ConstantSDNode(bool isTarget, const ConstantInt *val, MVT VT)
1758    : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1759             DebugLoc::getUnknownLoc(), getSDVTList(VT)), Value(val) {
1760  }
1761public:
1762
1763  const ConstantInt *getConstantIntValue() const { return Value; }
1764  const APInt &getAPIntValue() const { return Value->getValue(); }
1765  uint64_t getZExtValue() const { return Value->getZExtValue(); }
1766  int64_t getSExtValue() const { return Value->getSExtValue(); }
1767
1768  bool isNullValue() const { return Value->isNullValue(); }
1769  bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1770
1771  static bool classof(const ConstantSDNode *) { return true; }
1772  static bool classof(const SDNode *N) {
1773    return N->getOpcode() == ISD::Constant ||
1774           N->getOpcode() == ISD::TargetConstant;
1775  }
1776};
1777
1778class ConstantFPSDNode : public SDNode {
1779  const ConstantFP *Value;
1780  friend class SelectionDAG;
1781  ConstantFPSDNode(bool isTarget, const ConstantFP *val, MVT VT)
1782    : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1783             DebugLoc::getUnknownLoc(), getSDVTList(VT)), Value(val) {
1784  }
1785public:
1786
1787  const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1788  const ConstantFP *getConstantFPValue() const { return Value; }
1789
1790  /// isExactlyValue - We don't rely on operator== working on double values, as
1791  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1792  /// As such, this method can be used to do an exact bit-for-bit comparison of
1793  /// two floating point values.
1794
1795  /// We leave the version with the double argument here because it's just so
1796  /// convenient to write "2.0" and the like.  Without this function we'd
1797  /// have to duplicate its logic everywhere it's called.
1798  bool isExactlyValue(double V) const {
1799    bool ignored;
1800    // convert is not supported on this type
1801    if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
1802      return false;
1803    APFloat Tmp(V);
1804    Tmp.convert(Value->getValueAPF().getSemantics(),
1805                APFloat::rmNearestTiesToEven, &ignored);
1806    return isExactlyValue(Tmp);
1807  }
1808  bool isExactlyValue(const APFloat& V) const;
1809
1810  bool isValueValidForType(MVT VT, const APFloat& Val);
1811
1812  static bool classof(const ConstantFPSDNode *) { return true; }
1813  static bool classof(const SDNode *N) {
1814    return N->getOpcode() == ISD::ConstantFP ||
1815           N->getOpcode() == ISD::TargetConstantFP;
1816  }
1817};
1818
1819class GlobalAddressSDNode : public SDNode {
1820  GlobalValue *TheGlobal;
1821  int64_t Offset;
1822  unsigned char TargetFlags;
1823  friend class SelectionDAG;
1824  GlobalAddressSDNode(unsigned Opc, const GlobalValue *GA, MVT VT,
1825                      int64_t o, unsigned char TargetFlags);
1826public:
1827
1828  GlobalValue *getGlobal() const { return TheGlobal; }
1829  int64_t getOffset() const { return Offset; }
1830  unsigned char getTargetFlags() const { return TargetFlags; }
1831  // Return the address space this GlobalAddress belongs to.
1832  unsigned getAddressSpace() const;
1833
1834  static bool classof(const GlobalAddressSDNode *) { return true; }
1835  static bool classof(const SDNode *N) {
1836    return N->getOpcode() == ISD::GlobalAddress ||
1837           N->getOpcode() == ISD::TargetGlobalAddress ||
1838           N->getOpcode() == ISD::GlobalTLSAddress ||
1839           N->getOpcode() == ISD::TargetGlobalTLSAddress;
1840  }
1841};
1842
1843class FrameIndexSDNode : public SDNode {
1844  int FI;
1845  friend class SelectionDAG;
1846  FrameIndexSDNode(int fi, MVT VT, bool isTarg)
1847    : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1848      DebugLoc::getUnknownLoc(), getSDVTList(VT)), FI(fi) {
1849  }
1850public:
1851
1852  int getIndex() const { return FI; }
1853
1854  static bool classof(const FrameIndexSDNode *) { return true; }
1855  static bool classof(const SDNode *N) {
1856    return N->getOpcode() == ISD::FrameIndex ||
1857           N->getOpcode() == ISD::TargetFrameIndex;
1858  }
1859};
1860
1861class JumpTableSDNode : public SDNode {
1862  int JTI;
1863  unsigned char TargetFlags;
1864  friend class SelectionDAG;
1865  JumpTableSDNode(int jti, MVT VT, bool isTarg, unsigned char TF)
1866    : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1867      DebugLoc::getUnknownLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1868  }
1869public:
1870
1871  int getIndex() const { return JTI; }
1872  unsigned char getTargetFlags() const { return TargetFlags; }
1873
1874  static bool classof(const JumpTableSDNode *) { return true; }
1875  static bool classof(const SDNode *N) {
1876    return N->getOpcode() == ISD::JumpTable ||
1877           N->getOpcode() == ISD::TargetJumpTable;
1878  }
1879};
1880
1881class ConstantPoolSDNode : public SDNode {
1882  union {
1883    Constant *ConstVal;
1884    MachineConstantPoolValue *MachineCPVal;
1885  } Val;
1886  int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1887  unsigned Alignment;  // Minimum alignment requirement of CP (not log2 value).
1888  unsigned char TargetFlags;
1889  friend class SelectionDAG;
1890  ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o, unsigned Align,
1891                     unsigned char TF)
1892    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1893             DebugLoc::getUnknownLoc(),
1894             getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1895    assert((int)Offset >= 0 && "Offset is too large");
1896    Val.ConstVal = c;
1897  }
1898  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1899                     MVT VT, int o, unsigned Align, unsigned char TF)
1900    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1901             DebugLoc::getUnknownLoc(),
1902             getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1903    assert((int)Offset >= 0 && "Offset is too large");
1904    Val.MachineCPVal = v;
1905    Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1906  }
1907public:
1908
1909
1910  bool isMachineConstantPoolEntry() const {
1911    return (int)Offset < 0;
1912  }
1913
1914  Constant *getConstVal() const {
1915    assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1916    return Val.ConstVal;
1917  }
1918
1919  MachineConstantPoolValue *getMachineCPVal() const {
1920    assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1921    return Val.MachineCPVal;
1922  }
1923
1924  int getOffset() const {
1925    return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1926  }
1927
1928  // Return the alignment of this constant pool object, which is either 0 (for
1929  // default alignment) or the desired value.
1930  unsigned getAlignment() const { return Alignment; }
1931  unsigned char getTargetFlags() const { return TargetFlags; }
1932
1933  const Type *getType() const;
1934
1935  static bool classof(const ConstantPoolSDNode *) { return true; }
1936  static bool classof(const SDNode *N) {
1937    return N->getOpcode() == ISD::ConstantPool ||
1938           N->getOpcode() == ISD::TargetConstantPool;
1939  }
1940};
1941
1942class BasicBlockSDNode : public SDNode {
1943  MachineBasicBlock *MBB;
1944  friend class SelectionDAG;
1945  /// Debug info is meaningful and potentially useful here, but we create
1946  /// blocks out of order when they're jumped to, which makes it a bit
1947  /// harder.  Let's see if we need it first.
1948  explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1949    : SDNode(ISD::BasicBlock, DebugLoc::getUnknownLoc(),
1950             getSDVTList(MVT::Other)), MBB(mbb) {
1951  }
1952public:
1953
1954  MachineBasicBlock *getBasicBlock() const { return MBB; }
1955
1956  static bool classof(const BasicBlockSDNode *) { return true; }
1957  static bool classof(const SDNode *N) {
1958    return N->getOpcode() == ISD::BasicBlock;
1959  }
1960};
1961
1962/// BuildVectorSDNode - A "pseudo-class" with methods for operating on
1963/// BUILD_VECTORs.
1964class BuildVectorSDNode : public SDNode {
1965  // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1966  explicit BuildVectorSDNode();        // Do not implement
1967public:
1968  /// isConstantSplat - Check if this is a constant splat, and if so, find the
1969  /// smallest element size that splats the vector.  If MinSplatBits is
1970  /// nonzero, the element size must be at least that large.  Note that the
1971  /// splat element may be the entire vector (i.e., a one element vector).
1972  /// Returns the splat element value in SplatValue.  Any undefined bits in
1973  /// that value are zero, and the corresponding bits in the SplatUndef mask
1974  /// are set.  The SplatBitSize value is set to the splat element size in
1975  /// bits.  HasAnyUndefs is set to true if any bits in the vector are
1976  /// undefined.
1977  bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1978                       unsigned &SplatBitSize, bool &HasAnyUndefs,
1979                       unsigned MinSplatBits = 0);
1980
1981  static inline bool classof(const BuildVectorSDNode *) { return true; }
1982  static inline bool classof(const SDNode *N) {
1983    return N->getOpcode() == ISD::BUILD_VECTOR;
1984  }
1985};
1986
1987/// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1988/// used when the SelectionDAG needs to make a simple reference to something
1989/// in the LLVM IR representation.
1990///
1991/// Note that this is not used for carrying alias information; that is done
1992/// with MemOperandSDNode, which includes a Value which is required to be a
1993/// pointer, and several other fields specific to memory references.
1994///
1995class SrcValueSDNode : public SDNode {
1996  const Value *V;
1997  friend class SelectionDAG;
1998  /// Create a SrcValue for a general value.
1999  explicit SrcValueSDNode(const Value *v)
2000    : SDNode(ISD::SRCVALUE, DebugLoc::getUnknownLoc(),
2001             getSDVTList(MVT::Other)), V(v) {}
2002
2003public:
2004  /// getValue - return the contained Value.
2005  const Value *getValue() const { return V; }
2006
2007  static bool classof(const SrcValueSDNode *) { return true; }
2008  static bool classof(const SDNode *N) {
2009    return N->getOpcode() == ISD::SRCVALUE;
2010  }
2011};
2012
2013
2014/// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
2015/// used to represent a reference to memory after ISD::LOAD
2016/// and ISD::STORE have been lowered.
2017///
2018class MemOperandSDNode : public SDNode {
2019  friend class SelectionDAG;
2020  /// Create a MachineMemOperand node
2021  explicit MemOperandSDNode(const MachineMemOperand &mo)
2022    : SDNode(ISD::MEMOPERAND, DebugLoc::getUnknownLoc(),
2023             getSDVTList(MVT::Other)), MO(mo) {}
2024
2025public:
2026  /// MO - The contained MachineMemOperand.
2027  const MachineMemOperand MO;
2028
2029  static bool classof(const MemOperandSDNode *) { return true; }
2030  static bool classof(const SDNode *N) {
2031    return N->getOpcode() == ISD::MEMOPERAND;
2032  }
2033};
2034
2035
2036class RegisterSDNode : public SDNode {
2037  unsigned Reg;
2038  friend class SelectionDAG;
2039  RegisterSDNode(unsigned reg, MVT VT)
2040    : SDNode(ISD::Register, DebugLoc::getUnknownLoc(),
2041             getSDVTList(VT)), Reg(reg) {
2042  }
2043public:
2044
2045  unsigned getReg() const { return Reg; }
2046
2047  static bool classof(const RegisterSDNode *) { return true; }
2048  static bool classof(const SDNode *N) {
2049    return N->getOpcode() == ISD::Register;
2050  }
2051};
2052
2053class DbgStopPointSDNode : public SDNode {
2054  SDUse Chain;
2055  unsigned Line;
2056  unsigned Column;
2057  Value *CU;
2058  friend class SelectionDAG;
2059  DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
2060                     Value *cu)
2061    : SDNode(ISD::DBG_STOPPOINT, DebugLoc::getUnknownLoc(),
2062      getSDVTList(MVT::Other)), Line(l), Column(c), CU(cu) {
2063    InitOperands(&Chain, ch);
2064  }
2065public:
2066  unsigned getLine() const { return Line; }
2067  unsigned getColumn() const { return Column; }
2068  Value *getCompileUnit() const { return CU; }
2069
2070  static bool classof(const DbgStopPointSDNode *) { return true; }
2071  static bool classof(const SDNode *N) {
2072    return N->getOpcode() == ISD::DBG_STOPPOINT;
2073  }
2074};
2075
2076class LabelSDNode : public SDNode {
2077  SDUse Chain;
2078  unsigned LabelID;
2079  friend class SelectionDAG;
2080LabelSDNode(unsigned NodeTy, DebugLoc dl, SDValue ch, unsigned id)
2081    : SDNode(NodeTy, dl, getSDVTList(MVT::Other)), LabelID(id) {
2082    InitOperands(&Chain, ch);
2083  }
2084public:
2085  unsigned getLabelID() const { return LabelID; }
2086
2087  static bool classof(const LabelSDNode *) { return true; }
2088  static bool classof(const SDNode *N) {
2089    return N->getOpcode() == ISD::DBG_LABEL ||
2090           N->getOpcode() == ISD::EH_LABEL;
2091  }
2092};
2093
2094class ExternalSymbolSDNode : public SDNode {
2095  const char *Symbol;
2096  unsigned char TargetFlags;
2097
2098  friend class SelectionDAG;
2099  ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, MVT VT)
2100    : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
2101             DebugLoc::getUnknownLoc(),
2102             getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
2103  }
2104public:
2105
2106  const char *getSymbol() const { return Symbol; }
2107  unsigned char getTargetFlags() const { return TargetFlags; }
2108
2109  static bool classof(const ExternalSymbolSDNode *) { return true; }
2110  static bool classof(const SDNode *N) {
2111    return N->getOpcode() == ISD::ExternalSymbol ||
2112           N->getOpcode() == ISD::TargetExternalSymbol;
2113  }
2114};
2115
2116class CondCodeSDNode : public SDNode {
2117  ISD::CondCode Condition;
2118  friend class SelectionDAG;
2119  explicit CondCodeSDNode(ISD::CondCode Cond)
2120    : SDNode(ISD::CONDCODE, DebugLoc::getUnknownLoc(),
2121             getSDVTList(MVT::Other)), Condition(Cond) {
2122  }
2123public:
2124
2125  ISD::CondCode get() const { return Condition; }
2126
2127  static bool classof(const CondCodeSDNode *) { return true; }
2128  static bool classof(const SDNode *N) {
2129    return N->getOpcode() == ISD::CONDCODE;
2130  }
2131};
2132
2133/// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
2134/// future and most targets don't support it.
2135class CvtRndSatSDNode : public SDNode {
2136  ISD::CvtCode CvtCode;
2137  friend class SelectionDAG;
2138  explicit CvtRndSatSDNode(MVT VT, DebugLoc dl, const SDValue *Ops,
2139                           unsigned NumOps, ISD::CvtCode Code)
2140    : SDNode(ISD::CONVERT_RNDSAT, dl, getSDVTList(VT), Ops, NumOps),
2141      CvtCode(Code) {
2142    assert(NumOps == 5 && "wrong number of operations");
2143  }
2144public:
2145  ISD::CvtCode getCvtCode() const { return CvtCode; }
2146
2147  static bool classof(const CvtRndSatSDNode *) { return true; }
2148  static bool classof(const SDNode *N) {
2149    return N->getOpcode() == ISD::CONVERT_RNDSAT;
2150  }
2151};
2152
2153namespace ISD {
2154  struct ArgFlagsTy {
2155  private:
2156    static const uint64_t NoFlagSet      = 0ULL;
2157    static const uint64_t ZExt           = 1ULL<<0;  ///< Zero extended
2158    static const uint64_t ZExtOffs       = 0;
2159    static const uint64_t SExt           = 1ULL<<1;  ///< Sign extended
2160    static const uint64_t SExtOffs       = 1;
2161    static const uint64_t InReg          = 1ULL<<2;  ///< Passed in register
2162    static const uint64_t InRegOffs      = 2;
2163    static const uint64_t SRet           = 1ULL<<3;  ///< Hidden struct-ret ptr
2164    static const uint64_t SRetOffs       = 3;
2165    static const uint64_t ByVal          = 1ULL<<4;  ///< Struct passed by value
2166    static const uint64_t ByValOffs      = 4;
2167    static const uint64_t Nest           = 1ULL<<5;  ///< Nested fn static chain
2168    static const uint64_t NestOffs       = 5;
2169    static const uint64_t ByValAlign     = 0xFULL << 6; //< Struct alignment
2170    static const uint64_t ByValAlignOffs = 6;
2171    static const uint64_t Split          = 1ULL << 10;
2172    static const uint64_t SplitOffs      = 10;
2173    static const uint64_t OrigAlign      = 0x1FULL<<27;
2174    static const uint64_t OrigAlignOffs  = 27;
2175    static const uint64_t ByValSize      = 0xffffffffULL << 32; //< Struct size
2176    static const uint64_t ByValSizeOffs  = 32;
2177
2178    static const uint64_t One            = 1ULL; //< 1 of this type, for shifts
2179
2180    uint64_t Flags;
2181  public:
2182    ArgFlagsTy() : Flags(0) { }
2183
2184    bool isZExt()   const { return Flags & ZExt; }
2185    void setZExt()  { Flags |= One << ZExtOffs; }
2186
2187    bool isSExt()   const { return Flags & SExt; }
2188    void setSExt()  { Flags |= One << SExtOffs; }
2189
2190    bool isInReg()  const { return Flags & InReg; }
2191    void setInReg() { Flags |= One << InRegOffs; }
2192
2193    bool isSRet()   const { return Flags & SRet; }
2194    void setSRet()  { Flags |= One << SRetOffs; }
2195
2196    bool isByVal()  const { return Flags & ByVal; }
2197    void setByVal() { Flags |= One << ByValOffs; }
2198
2199    bool isNest()   const { return Flags & Nest; }
2200    void setNest()  { Flags |= One << NestOffs; }
2201
2202    unsigned getByValAlign() const {
2203      return (unsigned)
2204        ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
2205    }
2206    void setByValAlign(unsigned A) {
2207      Flags = (Flags & ~ByValAlign) |
2208        (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
2209    }
2210
2211    bool isSplit()   const { return Flags & Split; }
2212    void setSplit()  { Flags |= One << SplitOffs; }
2213
2214    unsigned getOrigAlign() const {
2215      return (unsigned)
2216        ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
2217    }
2218    void setOrigAlign(unsigned A) {
2219      Flags = (Flags & ~OrigAlign) |
2220        (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
2221    }
2222
2223    unsigned getByValSize() const {
2224      return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
2225    }
2226    void setByValSize(unsigned S) {
2227      Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
2228    }
2229
2230    /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
2231    std::string getArgFlagsString();
2232
2233    /// getRawBits - Represent the flags as a bunch of bits.
2234    uint64_t getRawBits() const { return Flags; }
2235  };
2236}
2237
2238/// ARG_FLAGSSDNode - Leaf node holding parameter flags.
2239class ARG_FLAGSSDNode : public SDNode {
2240  ISD::ArgFlagsTy TheFlags;
2241  friend class SelectionDAG;
2242  explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
2243    : SDNode(ISD::ARG_FLAGS, DebugLoc::getUnknownLoc(),
2244             getSDVTList(MVT::Other)), TheFlags(Flags) {
2245  }
2246public:
2247  ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
2248
2249  static bool classof(const ARG_FLAGSSDNode *) { return true; }
2250  static bool classof(const SDNode *N) {
2251    return N->getOpcode() == ISD::ARG_FLAGS;
2252  }
2253};
2254
2255/// CallSDNode - Node for calls -- ISD::CALL.
2256class CallSDNode : public SDNode {
2257  unsigned CallingConv;
2258  bool IsVarArg;
2259  bool IsTailCall;
2260  // We might eventually want a full-blown Attributes for the result; that
2261  // will expand the size of the representation.  At the moment we only
2262  // need Inreg.
2263  bool Inreg;
2264  friend class SelectionDAG;
2265  CallSDNode(unsigned cc, DebugLoc dl, bool isvararg, bool istailcall,
2266             bool isinreg, SDVTList VTs, const SDValue *Operands,
2267             unsigned numOperands)
2268    : SDNode(ISD::CALL, dl, VTs, Operands, numOperands),
2269      CallingConv(cc), IsVarArg(isvararg), IsTailCall(istailcall),
2270      Inreg(isinreg) {}
2271public:
2272  unsigned getCallingConv() const { return CallingConv; }
2273  unsigned isVarArg() const { return IsVarArg; }
2274  unsigned isTailCall() const { return IsTailCall; }
2275  unsigned isInreg() const { return Inreg; }
2276
2277  /// Set this call to not be marked as a tail call. Normally setter
2278  /// methods in SDNodes are unsafe because it breaks the CSE map,
2279  /// but we don't include the tail call flag for calls so it's ok
2280  /// in this case.
2281  void setNotTailCall() { IsTailCall = false; }
2282
2283  SDValue getChain() const { return getOperand(0); }
2284  SDValue getCallee() const { return getOperand(1); }
2285
2286  unsigned getNumArgs() const { return (getNumOperands() - 2) / 2; }
2287  SDValue getArg(unsigned i) const { return getOperand(2+2*i); }
2288  SDValue getArgFlagsVal(unsigned i) const {
2289    return getOperand(3+2*i);
2290  }
2291  ISD::ArgFlagsTy getArgFlags(unsigned i) const {
2292    return cast<ARG_FLAGSSDNode>(getArgFlagsVal(i).getNode())->getArgFlags();
2293  }
2294
2295  unsigned getNumRetVals() const { return getNumValues() - 1; }
2296  MVT getRetValType(unsigned i) const { return getValueType(i); }
2297
2298  static bool classof(const CallSDNode *) { return true; }
2299  static bool classof(const SDNode *N) {
2300    return N->getOpcode() == ISD::CALL;
2301  }
2302};
2303
2304/// VTSDNode - This class is used to represent MVT's, which are used
2305/// to parameterize some operations.
2306class VTSDNode : public SDNode {
2307  MVT ValueType;
2308  friend class SelectionDAG;
2309  explicit VTSDNode(MVT VT)
2310    : SDNode(ISD::VALUETYPE, DebugLoc::getUnknownLoc(),
2311             getSDVTList(MVT::Other)), ValueType(VT) {
2312  }
2313public:
2314
2315  MVT getVT() const { return ValueType; }
2316
2317  static bool classof(const VTSDNode *) { return true; }
2318  static bool classof(const SDNode *N) {
2319    return N->getOpcode() == ISD::VALUETYPE;
2320  }
2321};
2322
2323/// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
2324///
2325class LSBaseSDNode : public MemSDNode {
2326  //! Operand array for load and store
2327  /*!
2328    \note Moving this array to the base class captures more
2329    common functionality shared between LoadSDNode and
2330    StoreSDNode
2331   */
2332  SDUse Ops[4];
2333public:
2334  LSBaseSDNode(ISD::NodeType NodeTy, DebugLoc dl, SDValue *Operands,
2335               unsigned numOperands, SDVTList VTs, ISD::MemIndexedMode AM,
2336               MVT VT, const Value *SV, int SVO, unsigned Align, bool Vol)
2337    : MemSDNode(NodeTy, dl, VTs, VT, SV, SVO, Align, Vol) {
2338    assert(Align != 0 && "Loads and stores should have non-zero aligment");
2339    SubclassData |= AM << 2;
2340    assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
2341    InitOperands(Ops, Operands, numOperands);
2342    assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
2343           "Only indexed loads and stores have a non-undef offset operand");
2344  }
2345
2346  const SDValue &getOffset() const {
2347    return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2348  }
2349
2350  /// getAddressingMode - Return the addressing mode for this load or store:
2351  /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2352  ISD::MemIndexedMode getAddressingMode() const {
2353    return ISD::MemIndexedMode((SubclassData >> 2) & 7);
2354  }
2355
2356  /// isIndexed - Return true if this is a pre/post inc/dec load/store.
2357  bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2358
2359  /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
2360  bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2361
2362  static bool classof(const LSBaseSDNode *) { return true; }
2363  static bool classof(const SDNode *N) {
2364    return N->getOpcode() == ISD::LOAD ||
2365           N->getOpcode() == ISD::STORE;
2366  }
2367};
2368
2369/// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2370///
2371class LoadSDNode : public LSBaseSDNode {
2372  friend class SelectionDAG;
2373  LoadSDNode(SDValue *ChainPtrOff, DebugLoc dl, SDVTList VTs,
2374             ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT,
2375             const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2376    : LSBaseSDNode(ISD::LOAD, dl, ChainPtrOff, 3,
2377                   VTs, AM, LVT, SV, O, Align, Vol) {
2378    SubclassData |= (unsigned short)ETy;
2379    assert(getExtensionType() == ETy && "LoadExtType encoding error!");
2380  }
2381public:
2382
2383  /// getExtensionType - Return whether this is a plain node,
2384  /// or one of the varieties of value-extending loads.
2385  ISD::LoadExtType getExtensionType() const {
2386    return ISD::LoadExtType(SubclassData & 3);
2387  }
2388
2389  const SDValue &getBasePtr() const { return getOperand(1); }
2390  const SDValue &getOffset() const { return getOperand(2); }
2391
2392  static bool classof(const LoadSDNode *) { return true; }
2393  static bool classof(const SDNode *N) {
2394    return N->getOpcode() == ISD::LOAD;
2395  }
2396};
2397
2398/// StoreSDNode - This class is used to represent ISD::STORE nodes.
2399///
2400class StoreSDNode : public LSBaseSDNode {
2401  friend class SelectionDAG;
2402  StoreSDNode(SDValue *ChainValuePtrOff, DebugLoc dl, SDVTList VTs,
2403              ISD::MemIndexedMode AM, bool isTrunc, MVT SVT,
2404              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2405    : LSBaseSDNode(ISD::STORE, dl, ChainValuePtrOff, 4,
2406                   VTs, AM, SVT, SV, O, Align, Vol) {
2407    SubclassData |= (unsigned short)isTrunc;
2408    assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
2409  }
2410public:
2411
2412  /// isTruncatingStore - Return true if the op does a truncation before store.
2413  /// For integers this is the same as doing a TRUNCATE and storing the result.
2414  /// For floats, it is the same as doing an FP_ROUND and storing the result.
2415  bool isTruncatingStore() const { return SubclassData & 1; }
2416
2417  const SDValue &getValue() const { return getOperand(1); }
2418  const SDValue &getBasePtr() const { return getOperand(2); }
2419  const SDValue &getOffset() const { return getOperand(3); }
2420
2421  static bool classof(const StoreSDNode *) { return true; }
2422  static bool classof(const SDNode *N) {
2423    return N->getOpcode() == ISD::STORE;
2424  }
2425};
2426
2427
2428class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
2429  SDNode *Node;
2430  unsigned Operand;
2431
2432  SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2433public:
2434  bool operator==(const SDNodeIterator& x) const {
2435    return Operand == x.Operand;
2436  }
2437  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2438
2439  const SDNodeIterator &operator=(const SDNodeIterator &I) {
2440    assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2441    Operand = I.Operand;
2442    return *this;
2443  }
2444
2445  pointer operator*() const {
2446    return Node->getOperand(Operand).getNode();
2447  }
2448  pointer operator->() const { return operator*(); }
2449
2450  SDNodeIterator& operator++() {                // Preincrement
2451    ++Operand;
2452    return *this;
2453  }
2454  SDNodeIterator operator++(int) { // Postincrement
2455    SDNodeIterator tmp = *this; ++*this; return tmp;
2456  }
2457
2458  static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2459  static SDNodeIterator end  (SDNode *N) {
2460    return SDNodeIterator(N, N->getNumOperands());
2461  }
2462
2463  unsigned getOperand() const { return Operand; }
2464  const SDNode *getNode() const { return Node; }
2465};
2466
2467template <> struct GraphTraits<SDNode*> {
2468  typedef SDNode NodeType;
2469  typedef SDNodeIterator ChildIteratorType;
2470  static inline NodeType *getEntryNode(SDNode *N) { return N; }
2471  static inline ChildIteratorType child_begin(NodeType *N) {
2472    return SDNodeIterator::begin(N);
2473  }
2474  static inline ChildIteratorType child_end(NodeType *N) {
2475    return SDNodeIterator::end(N);
2476  }
2477};
2478
2479/// LargestSDNode - The largest SDNode class.
2480///
2481typedef LoadSDNode LargestSDNode;
2482
2483/// MostAlignedSDNode - The SDNode class with the greatest alignment
2484/// requirement.
2485///
2486typedef ARG_FLAGSSDNode MostAlignedSDNode;
2487
2488namespace ISD {
2489  /// isNormalLoad - Returns true if the specified node is a non-extending
2490  /// and unindexed load.
2491  inline bool isNormalLoad(const SDNode *N) {
2492    const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2493    return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2494      Ld->getAddressingMode() == ISD::UNINDEXED;
2495  }
2496
2497  /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2498  /// load.
2499  inline bool isNON_EXTLoad(const SDNode *N) {
2500    return isa<LoadSDNode>(N) &&
2501      cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2502  }
2503
2504  /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2505  ///
2506  inline bool isEXTLoad(const SDNode *N) {
2507    return isa<LoadSDNode>(N) &&
2508      cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2509  }
2510
2511  /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2512  ///
2513  inline bool isSEXTLoad(const SDNode *N) {
2514    return isa<LoadSDNode>(N) &&
2515      cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2516  }
2517
2518  /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2519  ///
2520  inline bool isZEXTLoad(const SDNode *N) {
2521    return isa<LoadSDNode>(N) &&
2522      cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2523  }
2524
2525  /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2526  ///
2527  inline bool isUNINDEXEDLoad(const SDNode *N) {
2528    return isa<LoadSDNode>(N) &&
2529      cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2530  }
2531
2532  /// isNormalStore - Returns true if the specified node is a non-truncating
2533  /// and unindexed store.
2534  inline bool isNormalStore(const SDNode *N) {
2535    const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2536    return St && !St->isTruncatingStore() &&
2537      St->getAddressingMode() == ISD::UNINDEXED;
2538  }
2539
2540  /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2541  /// store.
2542  inline bool isNON_TRUNCStore(const SDNode *N) {
2543    return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2544  }
2545
2546  /// isTRUNCStore - Returns true if the specified node is a truncating
2547  /// store.
2548  inline bool isTRUNCStore(const SDNode *N) {
2549    return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2550  }
2551
2552  /// isUNINDEXEDStore - Returns true if the specified node is an
2553  /// unindexed store.
2554  inline bool isUNINDEXEDStore(const SDNode *N) {
2555    return isa<StoreSDNode>(N) &&
2556      cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2557  }
2558}
2559
2560
2561} // end llvm namespace
2562
2563#endif
2564