LLVM API Documentation

SelectionDAGNodes.h

Go to the documentation of this file.
00001 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the SDNode class and derived classes, which are used to
00011 // represent the nodes and operations present in a SelectionDAG.  These nodes
00012 // and operations are machine code level operations, with some similarities to
00013 // the GCC RTL representation.
00014 //
00015 // Clients should include the SelectionDAG.h file instead of this file directly.
00016 //
00017 //===----------------------------------------------------------------------===//
00018 
00019 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
00020 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
00021 
00022 #include "llvm/Constants.h"
00023 #include "llvm/ADT/FoldingSet.h"
00024 #include "llvm/ADT/GraphTraits.h"
00025 #include "llvm/ADT/iterator.h"
00026 #include "llvm/ADT/ilist_node.h"
00027 #include "llvm/ADT/STLExtras.h"
00028 #include "llvm/CodeGen/ValueTypes.h"
00029 #include "llvm/CodeGen/MachineMemOperand.h"
00030 #include "llvm/Support/Allocator.h"
00031 #include "llvm/Support/RecyclingAllocator.h"
00032 #include "llvm/Support/DataTypes.h"
00033 #include "llvm/CodeGen/DebugLoc.h"
00034 #include <cassert>
00035 
00036 namespace llvm {
00037 
00038 class SelectionDAG;
00039 class GlobalValue;
00040 class MachineBasicBlock;
00041 class MachineConstantPoolValue;
00042 class SDNode;
00043 class Value;
00044 template <typename T> struct DenseMapInfo;
00045 template <typename T> struct simplify_type;
00046 template <typename T> struct ilist_traits;
00047 
00048 /// SDVTList - This represents a list of ValueType's that has been intern'd by
00049 /// a SelectionDAG.  Instances of this simple value class are returned by
00050 /// SelectionDAG::getVTList(...).
00051 ///
00052 struct SDVTList {
00053   const MVT *VTs;
00054   unsigned short NumVTs;
00055 };
00056 
00057 /// ISD namespace - This namespace contains an enum which represents all of the
00058 /// SelectionDAG node types and value types.
00059 ///
00060 namespace ISD {
00061 
00062   //===--------------------------------------------------------------------===//
00063   /// ISD::NodeType enum - This enum defines the target-independent operators
00064   /// for a SelectionDAG.
00065   ///
00066   /// Targets may also define target-dependent operator codes for SDNodes. For
00067   /// example, on x86, these are the enum values in the X86ISD namespace.
00068   /// Targets should aim to use target-independent operators to model their
00069   /// instruction sets as much as possible, and only use target-dependent
00070   /// operators when they have special requirements.
00071   ///
00072   /// Finally, during and after selection proper, SNodes may use special
00073   /// operator codes that correspond directly with MachineInstr opcodes. These
00074   /// are used to represent selected instructions. See the isMachineOpcode()
00075   /// and getMachineOpcode() member functions of SDNode.
00076   ///
00077   enum NodeType {
00078     // DELETED_NODE - This is an illegal flag value that is used to catch
00079     // errors.  This opcode is not a legal opcode for any node.
00080     DELETED_NODE,
00081     
00082     // EntryToken - This is the marker used to indicate the start of the region.
00083     EntryToken,
00084 
00085     // TokenFactor - This node takes multiple tokens as input and produces a
00086     // single token result.  This is used to represent the fact that the operand
00087     // operators are independent of each other.
00088     TokenFactor,
00089     
00090     // AssertSext, AssertZext - These nodes record if a register contains a 
00091     // value that has already been zero or sign extended from a narrower type.  
00092     // These nodes take two operands.  The first is the node that has already 
00093     // been extended, and the second is a value type node indicating the width
00094     // of the extension
00095     AssertSext, AssertZext,
00096 
00097     // Various leaf nodes.
00098     BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
00099     Constant, ConstantFP,
00100     GlobalAddress, GlobalTLSAddress, FrameIndex,
00101     JumpTable, ConstantPool, ExternalSymbol,
00102 
00103     // The address of the GOT
00104     GLOBAL_OFFSET_TABLE,
00105     
00106     // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
00107     // llvm.returnaddress on the DAG.  These nodes take one operand, the index
00108     // of the frame or return address to return.  An index of zero corresponds
00109     // to the current function's frame or return address, an index of one to the
00110     // parent's frame or return address, and so on.
00111     FRAMEADDR, RETURNADDR,
00112 
00113     // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
00114     // first (possible) on-stack argument. This is needed for correct stack
00115     // adjustment during unwind.
00116     FRAME_TO_ARGS_OFFSET,
00117     
00118     // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
00119     // address of the exception block on entry to an landing pad block.
00120     EXCEPTIONADDR,
00121     
00122     // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
00123     // the selection index of the exception thrown.
00124     EHSELECTION,
00125 
00126     // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
00127     // 'eh_return' gcc dwarf builtin, which is used to return from
00128     // exception. The general meaning is: adjust stack by OFFSET and pass
00129     // execution to HANDLER. Many platform-related details also :)
00130     EH_RETURN,
00131 
00132     // TargetConstant* - Like Constant*, but the DAG does not do any folding or
00133     // simplification of the constant.
00134     TargetConstant,
00135     TargetConstantFP,
00136     
00137     // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
00138     // anything else with this node, and this is valid in the target-specific
00139     // dag, turning into a GlobalAddress operand.
00140     TargetGlobalAddress,
00141     TargetGlobalTLSAddress,
00142     TargetFrameIndex,
00143     TargetJumpTable,
00144     TargetConstantPool,
00145     TargetExternalSymbol,
00146     
00147     /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
00148     /// This node represents a target intrinsic function with no side effects.
00149     /// The first operand is the ID number of the intrinsic from the
00150     /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
00151     /// node has returns the result of the intrinsic.
00152     INTRINSIC_WO_CHAIN,
00153     
00154     /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
00155     /// This node represents a target intrinsic function with side effects that
00156     /// returns a result.  The first operand is a chain pointer.  The second is
00157     /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
00158     /// operands to the intrinsic follow.  The node has two results, the result
00159     /// of the intrinsic and an output chain.
00160     INTRINSIC_W_CHAIN,
00161 
00162     /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
00163     /// This node represents a target intrinsic function with side effects that
00164     /// does not return a result.  The first operand is a chain pointer.  The
00165     /// second is the ID number of the intrinsic from the llvm::Intrinsic
00166     /// namespace.  The operands to the intrinsic follow.
00167     INTRINSIC_VOID,
00168     
00169     // CopyToReg - This node has three operands: a chain, a register number to
00170     // set to this value, and a value.  
00171     CopyToReg,
00172 
00173     // CopyFromReg - This node indicates that the input value is a virtual or
00174     // physical register that is defined outside of the scope of this
00175     // SelectionDAG.  The register is available from the RegisterSDNode object.
00176     CopyFromReg,
00177 
00178     // UNDEF - An undefined node
00179     UNDEF,
00180     
00181     /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
00182     /// represents the formal arguments for a function.  CC# is a Constant value
00183     /// indicating the calling convention of the function, and ISVARARG is a
00184     /// flag that indicates whether the function is varargs or not. This node
00185     /// has one result value for each incoming argument, plus one for the output
00186     /// chain. It must be custom legalized. See description of CALL node for
00187     /// FLAG argument contents explanation.
00188     /// 
00189     FORMAL_ARGUMENTS,
00190     
00191     /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CALLEE,
00192     ///                              ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
00193     /// This node represents a fully general function call, before the legalizer
00194     /// runs.  This has one result value for each argument / flag pair, plus
00195     /// a chain result. It must be custom legalized. Flag argument indicates
00196     /// misc. argument attributes. Currently:
00197     /// Bit 0 - signness
00198     /// Bit 1 - 'inreg' attribute
00199     /// Bit 2 - 'sret' attribute
00200     /// Bit 4 - 'byval' attribute
00201     /// Bit 5 - 'nest' attribute
00202     /// Bit 6-9 - alignment of byval structures
00203     /// Bit 10-26 - size of byval structures
00204     /// Bits 31:27 - argument ABI alignment in the first argument piece and
00205     /// alignment '1' in other argument pieces.
00206     ///
00207     /// CALL nodes use the CallSDNode subclass of SDNode, which
00208     /// additionally carries information about the calling convention,
00209     /// whether the call is varargs, and if it's marked as a tail call.
00210     ///
00211     CALL,
00212 
00213     // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
00214     // a Constant, which is required to be operand #1) half of the integer or
00215     // float value specified as operand #0.  This is only for use before
00216     // legalization, for values that will be broken into multiple registers.
00217     EXTRACT_ELEMENT,
00218 
00219     // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
00220     // two values of the same integer value type, this produces a value twice as
00221     // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
00222     BUILD_PAIR,
00223 
00224     // MERGE_VALUES - This node takes multiple discrete operands and returns
00225     // them all as its individual results.  This nodes has exactly the same
00226     // number of inputs and outputs, and is only valid before legalization.
00227     // This node is useful for some pieces of the code generator that want to
00228     // think about a single node with multiple results, not multiple nodes.
00229     MERGE_VALUES,
00230 
00231     // Simple integer binary arithmetic operators.
00232     ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
00233 
00234     // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
00235     // a signed/unsigned value of type i[2*N], and return the full value as
00236     // two results, each of type iN.
00237     SMUL_LOHI, UMUL_LOHI,
00238 
00239     // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
00240     // remainder result.
00241     SDIVREM, UDIVREM,
00242     
00243     // CARRY_FALSE - This node is used when folding other nodes,
00244     // like ADDC/SUBC, which indicate the carry result is always false.
00245     CARRY_FALSE,
00246     
00247     // Carry-setting nodes for multiple precision addition and subtraction.
00248     // These nodes take two operands of the same value type, and produce two
00249     // results.  The first result is the normal add or sub result, the second
00250     // result is the carry flag result.
00251     ADDC, SUBC,
00252     
00253     // Carry-using nodes for multiple precision addition and subtraction.  These
00254     // nodes take three operands: The first two are the normal lhs and rhs to
00255     // the add or sub, and the third is the input carry flag.  These nodes
00256     // produce two results; the normal result of the add or sub, and the output
00257     // carry flag.  These nodes both read and write a carry flag to allow them
00258     // to them to be chained together for add and sub of arbitrarily large
00259     // values.
00260     ADDE, SUBE,
00261 
00262     // RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
00263     // These nodes take two operands: the normal LHS and RHS to the add. They
00264     // produce two results: the normal result of the add, and a boolean that
00265     // indicates if an overflow occured (*not* a flag, because it may be stored
00266     // to memory, etc.).  If the type of the boolean is not i1 then the high
00267     // bits conform to getBooleanContents.
00268     // These nodes are generated from the llvm.[su]add.with.overflow intrinsics.
00269     SADDO, UADDO,
00270 
00271     // Same for subtraction
00272     SSUBO, USUBO,
00273 
00274     // Same for multiplication
00275     SMULO, UMULO,
00276 
00277     // Simple binary floating point operators.
00278     FADD, FSUB, FMUL, FDIV, FREM,
00279 
00280     // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
00281     // DAG node does not require that X and Y have the same type, just that they
00282     // are both floating point.  X and the result must have the same type.
00283     // FCOPYSIGN(f32, f64) is allowed.
00284     FCOPYSIGN,
00285 
00286     // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
00287     // value as an integer 0/1 value.
00288     FGETSIGN,
00289     
00290     /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
00291     /// with the specified, possibly variable, elements.  The number of elements
00292     /// is required to be a power of two.
00293     BUILD_VECTOR,
00294     
00295     /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
00296     /// at IDX replaced with VAL.  If the type of VAL is larger than the vector
00297     /// element type then VAL is truncated before replacement.
00298     INSERT_VECTOR_ELT,
00299 
00300     /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
00301     /// identified by the (potentially variable) element number IDX.
00302     EXTRACT_VECTOR_ELT,
00303     
00304     /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
00305     /// vector type with the same length and element type, this produces a
00306     /// concatenated vector result value, with length equal to the sum of the
00307     /// lengths of the input vectors.
00308     CONCAT_VECTORS,
00309     
00310     /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
00311     /// vector value) starting with the (potentially variable) element number
00312     /// IDX, which must be a multiple of the result vector length.
00313     EXTRACT_SUBVECTOR,
00314 
00315     /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
00316     /// type as VEC1/VEC2.  SHUFFLEVEC is a BUILD_VECTOR of constant int values
00317     /// (maybe of an illegal datatype) or undef that indicate which value each
00318     /// result element will get.  The elements of VEC1/VEC2 are enumerated in
00319     /// order.  This is quite similar to the Altivec 'vperm' instruction, except
00320     /// that the indices must be constants and are in terms of the element size
00321     /// of VEC1/VEC2, not in terms of bytes.
00322     VECTOR_SHUFFLE,
00323 
00324     /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
00325     /// scalar value into element 0 of the resultant vector type.  The top
00326     /// elements 1 to N-1 of the N-element vector are undefined.
00327     SCALAR_TO_VECTOR,
00328     
00329     // EXTRACT_SUBREG - This node is used to extract a sub-register value. 
00330     // This node takes a superreg and a constant sub-register index as operands.
00331     // Note sub-register indices must be increasing. That is, if the
00332     // sub-register index of a 8-bit sub-register is N, then the index for a
00333     // 16-bit sub-register must be at least N+1.
00334     EXTRACT_SUBREG,
00335     
00336     // INSERT_SUBREG - This node is used to insert a sub-register value. 
00337     // This node takes a superreg, a subreg value, and a constant sub-register
00338     // index as operands.
00339     INSERT_SUBREG,
00340     
00341     // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
00342     // an unsigned/signed value of type i[2*N], then return the top part.
00343     MULHU, MULHS,
00344 
00345     // Bitwise operators - logical and, logical or, logical xor, shift left,
00346     // shift right algebraic (shift in sign bits), shift right logical (shift in
00347     // zeroes), rotate left, rotate right, and byteswap.
00348     AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
00349 
00350     // Counting operators
00351     CTTZ, CTLZ, CTPOP,
00352 
00353     // Select(COND, TRUEVAL, FALSEVAL).  If the type of the boolean COND is not
00354     // i1 then the high bits must conform to getBooleanContents.
00355     SELECT,
00356 
00357     // Select with condition operator - This selects between a true value and 
00358     // a false value (ops #2 and #3) based on the boolean result of comparing
00359     // the lhs and rhs (ops #0 and #1) of a conditional expression with the 
00360     // condition code in op #4, a CondCodeSDNode.
00361     SELECT_CC,
00362 
00363     // SetCC operator - This evaluates to a true value iff the condition is
00364     // true.  If the result value type is not i1 then the high bits conform
00365     // to getBooleanContents.  The operands to this are the left and right
00366     // operands to compare (ops #0, and #1) and the condition code to compare
00367     // them with (op #2) as a CondCodeSDNode.
00368     SETCC,
00369 
00370     // Vector SetCC operator - This evaluates to a vector of integer elements
00371     // with the high bit in each element set to true if the comparison is true
00372     // and false if the comparison is false.  All other bits in each element 
00373     // are undefined.  The operands to this are the left and right operands
00374     // to compare (ops #0, and #1) and the condition code to compare them with
00375     // (op #2) as a CondCodeSDNode.
00376     VSETCC,
00377 
00378     // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
00379     // integer shift operations, just like ADD/SUB_PARTS.  The operation
00380     // ordering is:
00381     //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
00382     SHL_PARTS, SRA_PARTS, SRL_PARTS,
00383 
00384     // Conversion operators.  These are all single input single output
00385     // operations.  For all of these, the result type must be strictly
00386     // wider or narrower (depending on the operation) than the source
00387     // type.
00388 
00389     // SIGN_EXTEND - Used for integer types, replicating the sign bit
00390     // into new bits.
00391     SIGN_EXTEND,
00392 
00393     // ZERO_EXTEND - Used for integer types, zeroing the new bits.
00394     ZERO_EXTEND,
00395 
00396     // ANY_EXTEND - Used for integer types.  The high bits are undefined.
00397     ANY_EXTEND,
00398     
00399     // TRUNCATE - Completely drop the high bits.
00400     TRUNCATE,
00401 
00402     // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
00403     // depends on the first letter) to floating point.
00404     SINT_TO_FP,
00405     UINT_TO_FP,
00406 
00407     // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
00408     // sign extend a small value in a large integer register (e.g. sign
00409     // extending the low 8 bits of a 32-bit register to fill the top 24 bits
00410     // with the 7th bit).  The size of the smaller type is indicated by the 1th
00411     // operand, a ValueType node.
00412     SIGN_EXTEND_INREG,
00413 
00414     /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
00415     /// integer.
00416     FP_TO_SINT,
00417     FP_TO_UINT,
00418 
00419     /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
00420     /// down to the precision of the destination VT.  TRUNC is a flag, which is
00421     /// always an integer that is zero or one.  If TRUNC is 0, this is a
00422     /// normal rounding, if it is 1, this FP_ROUND is known to not change the
00423     /// value of Y.
00424     ///
00425     /// The TRUNC = 1 case is used in cases where we know that the value will
00426     /// not be modified by the node, because Y is not using any of the extra
00427     /// precision of source type.  This allows certain transformations like
00428     /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for 
00429     /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
00430     FP_ROUND,
00431     
00432     // FLT_ROUNDS_ - Returns current rounding mode:
00433     // -1 Undefined
00434     //  0 Round to 0
00435     //  1 Round to nearest
00436     //  2 Round to +inf
00437     //  3 Round to -inf
00438     FLT_ROUNDS_,
00439 
00440     /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
00441     /// rounds it to a floating point value.  It then promotes it and returns it
00442     /// in a register of the same size.  This operation effectively just
00443     /// discards excess precision.  The type to round down to is specified by
00444     /// the VT operand, a VTSDNode.
00445     FP_ROUND_INREG,
00446 
00447     /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
00448     FP_EXTEND,
00449 
00450     // BIT_CONVERT - Theis operator converts between integer and FP values, as
00451     // if one was stored to memory as integer and the other was loaded from the
00452     // same address (or equivalently for vector format conversions, etc).  The 
00453     // source and result are required to have the same bit size (e.g. 
00454     // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp 
00455     // conversions, but that is a noop, deleted by getNode().
00456     BIT_CONVERT,
00457     
00458     // CONVERT_RNDSAT - This operator is used to support various conversions
00459     // between various types (float, signed, unsigned and vectors of those
00460     // types) with rounding and saturation. NOTE: Avoid using this operator as
00461     // most target don't support it and the operator might be removed in the
00462     // future. It takes the following arguments:
00463     //   0) value
00464     //   1) dest type (type to convert to)
00465     //   2) src type (type to convert from)
00466     //   3) rounding imm
00467     //   4) saturation imm
00468     //   5) ISD::CvtCode indicating the type of conversion to do
00469     CONVERT_RNDSAT,
00470     
00471     // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
00472     // FLOG, FLOG2, FLOG10, FEXP, FEXP2,
00473     // FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary floating
00474     // point operations. These are inspired by libm.
00475     FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
00476     FLOG, FLOG2, FLOG10, FEXP, FEXP2,
00477     FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR,
00478     
00479     // LOAD and STORE have token chains as their first operand, then the same
00480     // operands as an LLVM load/store instruction, then an offset node that
00481     // is added / subtracted from the base pointer to form the address (for
00482     // indexed memory ops).
00483     LOAD, STORE,
00484 
00485     // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
00486     // to a specified boundary.  This node always has two return values: a new
00487     // stack pointer value and a chain. The first operand is the token chain,
00488     // the second is the number of bytes to allocate, and the third is the
00489     // alignment boundary.  The size is guaranteed to be a multiple of the stack
00490     // alignment, and the alignment is guaranteed to be bigger than the stack
00491     // alignment (if required) or 0 to get standard stack alignment.
00492     DYNAMIC_STACKALLOC,
00493 
00494     // Control flow instructions.  These all have token chains.
00495 
00496     // BR - Unconditional branch.  The first operand is the chain
00497     // operand, the second is the MBB to branch to.
00498     BR,
00499 
00500     // BRIND - Indirect branch.  The first operand is the chain, the second
00501     // is the value to branch to, which must be of the same type as the target's
00502     // pointer type.
00503     BRIND,
00504 
00505     // BR_JT - Jumptable branch. The first operand is the chain, the second
00506     // is the jumptable index, the last one is the jumptable entry index.
00507     BR_JT,
00508 
00509     // BRCOND - Conditional branch.  The first operand is the chain, the
00510     // second is the condition, the third is the block to branch to if the
00511     // condition is true.  If the type of the condition is not i1, then the
00512     // high bits must conform to getBooleanContents.
00513     BRCOND,
00514 
00515     // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
00516     // that the condition is represented as condition code, and two nodes to
00517     // compare, rather than as a combined SetCC node.  The operands in order are
00518     // chain, cc, lhs, rhs, block to branch to if condition is true.
00519     BR_CC,
00520     
00521     // RET - Return from function.  The first operand is the chain,
00522     // and any subsequent operands are pairs of return value and return value
00523     // attributes (see CALL for description of attributes) for the function.
00524     // This operation can have variable number of operands.
00525     RET,
00526 
00527     // INLINEASM - Represents an inline asm block.  This node always has two
00528     // return values: a chain and a flag result.  The inputs are as follows:
00529     //   Operand #0   : Input chain.
00530     //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
00531     //   Operand #2n+2: A RegisterNode.
00532     //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
00533     //   Operand #last: Optional, an incoming flag.
00534     INLINEASM,
00535     
00536     // DBG_LABEL, EH_LABEL - Represents a label in mid basic block used to track
00537     // locations needed for debug and exception handling tables.  These nodes
00538     // take a chain as input and return a chain.
00539     DBG_LABEL,
00540     EH_LABEL,
00541 
00542     // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
00543     // local variable declarations for debugging information. First operand is
00544     // a chain, while the next two operands are first two arguments (address
00545     // and variable) of a llvm.dbg.declare instruction.
00546     DECLARE,
00547     
00548     // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
00549     // value, the same type as the pointer type for the system, and an output
00550     // chain.
00551     STACKSAVE,
00552     
00553     // STACKRESTORE has two operands, an input chain and a pointer to restore to
00554     // it returns an output chain.
00555     STACKRESTORE,
00556     
00557     // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
00558     // a call sequence, and carry arbitrary information that target might want
00559     // to know.  The first operand is a chain, the rest are specified by the
00560     // target and not touched by the DAG optimizers.
00561     // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
00562     CALLSEQ_START,  // Beginning of a call sequence
00563     CALLSEQ_END,    // End of a call sequence
00564     
00565     // VAARG - VAARG has three operands: an input chain, a pointer, and a 
00566     // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
00567     VAARG,
00568     
00569     // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
00570     // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
00571     // source.
00572     VACOPY,
00573     
00574     // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
00575     // pointer, and a SRCVALUE.
00576     VAEND, VASTART,
00577 
00578     // SRCVALUE - This is a node type that holds a Value* that is used to
00579     // make reference to a value in the LLVM IR.
00580     SRCVALUE,
00581 
00582     // MEMOPERAND - This is a node that contains a MachineMemOperand which
00583     // records information about a memory reference. This is used to make
00584     // AliasAnalysis queries from the backend.
00585     MEMOPERAND,
00586 
00587     // PCMARKER - This corresponds to the pcmarker intrinsic.
00588     PCMARKER,
00589 
00590     // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
00591     // The only operand is a chain and a value and a chain are produced.  The
00592     // value is the contents of the architecture specific cycle counter like 
00593     // register (or other high accuracy low latency clock source)
00594     READCYCLECOUNTER,
00595 
00596     // HANDLENODE node - Used as a handle for various purposes.
00597     HANDLENODE,
00598 
00599     // DBG_STOPPOINT - This node is used to represent a source location for
00600     // debug info.  It takes token chain as input, and carries a line number,
00601     // column number, and a pointer to a CompileUnit object identifying
00602     // the containing compilation unit.  It produces a token chain as output.
00603     DBG_STOPPOINT,
00604     
00605     // DEBUG_LOC - This node is used to represent source line information
00606     // embedded in the code.  It takes a token chain as input, then a line
00607     // number, then a column then a file id (provided by MachineModuleInfo.) It
00608     // produces a token chain as output.
00609     DEBUG_LOC,
00610 
00611     // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
00612     // It takes as input a token chain, the pointer to the trampoline,
00613     // the pointer to the nested function, the pointer to pass for the
00614     // 'nest' parameter, a SRCVALUE for the trampoline and another for
00615     // the nested function (allowing targets to access the original
00616     // Function*).  It produces the result of the intrinsic and a token
00617     // chain as output.
00618     TRAMPOLINE,
00619 
00620     // TRAP - Trapping instruction
00621     TRAP,
00622 
00623     // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
00624     // their first operand. The other operands are the address to prefetch,
00625     // read / write specifier, and locality specifier.
00626     PREFETCH,
00627 
00628     // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load, 
00629     //                       store-store, device)
00630     // This corresponds to the memory.barrier intrinsic.
00631     // it takes an input chain, 4 operands to specify the type of barrier, an
00632     // operand specifying if the barrier applies to device and uncached memory
00633     // and produces an output chain.
00634     MEMBARRIER,
00635 
00636     // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
00637     // this corresponds to the atomic.lcs intrinsic.
00638     // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
00639     // the return is always the original value in *ptr
00640     ATOMIC_CMP_SWAP,
00641 
00642     // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
00643     // this corresponds to the atomic.swap intrinsic.
00644     // amt is stored to *ptr atomically.
00645     // the return is always the original value in *ptr
00646     ATOMIC_SWAP,
00647 
00648     // Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt)
00649     // this corresponds to the atomic.load.[OpName] intrinsic.
00650     // op(*ptr, amt) is stored to *ptr atomically.
00651     // the return is always the original value in *ptr
00652     ATOMIC_LOAD_ADD,
00653     ATOMIC_LOAD_SUB,
00654     ATOMIC_LOAD_AND,
00655     ATOMIC_LOAD_OR,
00656     ATOMIC_LOAD_XOR,
00657     ATOMIC_LOAD_NAND,
00658     ATOMIC_LOAD_MIN,
00659     ATOMIC_LOAD_MAX,
00660     ATOMIC_LOAD_UMIN,
00661     ATOMIC_LOAD_UMAX,
00662     
00663     // BUILTIN_OP_END - This must be the last enum value in this list.
00664     BUILTIN_OP_END
00665   };
00666 
00667   /// Node predicates
00668 
00669   /// isBuildVectorAllOnes - Return true if the specified node is a
00670   /// BUILD_VECTOR where all of the elements are ~0 or undef.
00671   bool isBuildVectorAllOnes(const SDNode *N);
00672 
00673   /// isBuildVectorAllZeros - Return true if the specified node is a
00674   /// BUILD_VECTOR where all of the elements are 0 or undef.
00675   bool isBuildVectorAllZeros(const SDNode *N);
00676 
00677   /// isScalarToVector - Return true if the specified node is a
00678   /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
00679   /// element is not an undef.
00680   bool isScalarToVector(const SDNode *N);
00681 
00682   /// isDebugLabel - Return true if the specified node represents a debug
00683   /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node).
00684   bool isDebugLabel(const SDNode *N);
00685   
00686   //===--------------------------------------------------------------------===//
00687   /// MemIndexedMode enum - This enum defines the load / store indexed 
00688   /// addressing modes.
00689   ///
00690   /// UNINDEXED    "Normal" load / store. The effective address is already
00691   ///              computed and is available in the base pointer. The offset
00692   ///              operand is always undefined. In addition to producing a
00693   ///              chain, an unindexed load produces one value (result of the
00694   ///              load); an unindexed store does not produce a value.
00695   ///
00696   /// PRE_INC      Similar to the unindexed mode where the effective address is
00697   /// PRE_DEC      the value of the base pointer add / subtract the offset.
00698   ///              It considers the computation as being folded into the load /
00699   ///              store operation (i.e. the load / store does the address
00700   ///              computation as well as performing the memory transaction).
00701   ///              The base operand is always undefined. In addition to
00702   ///              producing a chain, pre-indexed load produces two values
00703   ///              (result of the load and the result of the address
00704   ///              computation); a pre-indexed store produces one value (result
00705   ///              of the address computation).
00706   ///
00707   /// POST_INC     The effective address is the value of the base pointer. The
00708   /// POST_DEC     value of the offset operand is then added to / subtracted
00709   ///              from the base after memory transaction. In addition to
00710   ///              producing a chain, post-indexed load produces two values
00711   ///              (the result of the load and the result of the base +/- offset
00712   ///              computation); a post-indexed store produces one value (the
00713   ///              the result of the base +/- offset computation).
00714   ///
00715   enum MemIndexedMode {
00716     UNINDEXED = 0,
00717     PRE_INC,
00718     PRE_DEC,
00719     POST_INC,
00720     POST_DEC,
00721     LAST_INDEXED_MODE
00722   };
00723 
00724   //===--------------------------------------------------------------------===//
00725   /// LoadExtType enum - This enum defines the three variants of LOADEXT
00726   /// (load with extension).
00727   ///
00728   /// SEXTLOAD loads the integer operand and sign extends it to a larger
00729   ///          integer result type.
00730   /// ZEXTLOAD loads the integer operand and zero extends it to a larger
00731   ///          integer result type.
00732   /// EXTLOAD  is used for three things: floating point extending loads, 
00733   ///          integer extending loads [the top bits are undefined], and vector
00734   ///          extending loads [load into low elt].
00735   ///
00736   enum LoadExtType {
00737     NON_EXTLOAD = 0,
00738     EXTLOAD,
00739     SEXTLOAD,
00740     ZEXTLOAD,
00741     LAST_LOADEXT_TYPE
00742   };
00743 
00744   //===--------------------------------------------------------------------===//
00745   /// ISD::CondCode enum - These are ordered carefully to make the bitfields
00746   /// below work out, when considering SETFALSE (something that never exists
00747   /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
00748   /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
00749   /// to.  If the "N" column is 1, the result of the comparison is undefined if
00750   /// the input is a NAN.
00751   ///
00752   /// All of these (except for the 'always folded ops') should be handled for
00753   /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
00754   /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
00755   ///
00756   /// Note that these are laid out in a specific order to allow bit-twiddling
00757   /// to transform conditions.
00758   enum CondCode {
00759     // Opcode          N U L G E       Intuitive operation
00760     SETFALSE,      //    0 0 0 0       Always false (always folded)
00761     SETOEQ,        //    0 0 0 1       True if ordered and equal
00762     SETOGT,        //    0 0 1 0       True if ordered and greater than
00763     SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
00764     SETOLT,        //    0 1 0 0       True if ordered and less than
00765     SETOLE,        //    0 1 0 1       True if ordered and less than or equal
00766     SETONE,        //    0 1 1 0       True if ordered and operands are unequal
00767     SETO,          //    0 1 1 1       True if ordered (no nans)
00768     SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
00769     SETUEQ,        //    1 0 0 1       True if unordered or equal
00770     SETUGT,        //    1 0 1 0       True if unordered or greater than
00771     SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
00772     SETULT,        //    1 1 0 0       True if unordered or less than
00773     SETULE,        //    1 1 0 1       True if unordered, less than, or equal
00774     SETUNE,        //    1 1 1 0       True if unordered or not equal
00775     SETTRUE,       //    1 1 1 1       Always true (always folded)
00776     // Don't care operations: undefined if the input is a nan.
00777     SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
00778     SETEQ,         //  1 X 0 0 1       True if equal
00779     SETGT,         //  1 X 0 1 0       True if greater than
00780     SETGE,         //  1 X 0 1 1       True if greater than or equal
00781     SETLT,         //  1 X 1 0 0       True if less than
00782     SETLE,         //  1 X 1 0 1       True if less than or equal
00783     SETNE,         //  1 X 1 1 0       True if not equal
00784     SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
00785 
00786     SETCC_INVALID       // Marker value.
00787   };
00788 
00789   /// isSignedIntSetCC - Return true if this is a setcc instruction that
00790   /// performs a signed comparison when used with integer operands.
00791   inline bool isSignedIntSetCC(CondCode Code) {
00792     return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
00793   }
00794 
00795   /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
00796   /// performs an unsigned comparison when used with integer operands.
00797   inline bool isUnsignedIntSetCC(CondCode Code) {
00798     return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
00799   }
00800 
00801   /// isTrueWhenEqual - Return true if the specified condition returns true if
00802   /// the two operands to the condition are equal.  Note that if one of the two
00803   /// operands is a NaN, this value is meaningless.
00804   inline bool isTrueWhenEqual(CondCode Cond) {
00805     return ((int)Cond & 1) != 0;
00806   }
00807 
00808   /// getUnorderedFlavor - This function returns 0 if the condition is always
00809   /// false if an operand is a NaN, 1 if the condition is always true if the
00810   /// operand is a NaN, and 2 if the condition is undefined if the operand is a
00811   /// NaN.
00812   inline unsigned getUnorderedFlavor(CondCode Cond) {
00813     return ((int)Cond >> 3) & 3;
00814   }
00815 
00816   /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
00817   /// 'op' is a valid SetCC operation.
00818   CondCode getSetCCInverse(CondCode Operation, bool isInteger);
00819 
00820   /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
00821   /// when given the operation for (X op Y).
00822   CondCode getSetCCSwappedOperands(CondCode Operation);
00823 
00824   /// getSetCCOrOperation - Return the result of a logical OR between different
00825   /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
00826   /// function returns SETCC_INVALID if it is not possible to represent the
00827   /// resultant comparison.
00828   CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
00829 
00830   /// getSetCCAndOperation - Return the result of a logical AND between
00831   /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
00832   /// function returns SETCC_INVALID if it is not possible to represent the
00833   /// resultant comparison.
00834   CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
00835 
00836   //===--------------------------------------------------------------------===//
00837   /// CvtCode enum - This enum defines the various converts CONVERT_RNDSAT 
00838   /// supports.
00839   enum CvtCode {
00840     CVT_FF,     // Float from Float
00841     CVT_FS,     // Float from Signed
00842     CVT_FU,     // Float from Unsigned
00843     CVT_SF,     // Signed from Float
00844     CVT_UF,     // Unsigned from Float
00845     CVT_SS,     // Signed from Signed
00846     CVT_SU,     // Signed from Unsigned
00847     CVT_US,     // Unsigned from Signed
00848     CVT_UU,     // Unsigned from Unsigned
00849     CVT_INVALID // Marker - Invalid opcode
00850   };
00851 }  // end llvm::ISD namespace
00852 
00853 
00854 //===----------------------------------------------------------------------===//
00855 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
00856 /// values as the result of a computation.  Many nodes return multiple values,
00857 /// from loads (which define a token and a return value) to ADDC (which returns
00858 /// a result and a carry value), to calls (which may return an arbitrary number
00859 /// of values).
00860 ///
00861 /// As such, each use of a SelectionDAG computation must indicate the node that
00862 /// computes it as well as which return value to use from that node.  This pair
00863 /// of information is represented with the SDValue value type.
00864 ///
00865 class SDValue {
00866   SDNode *Node;       // The node defining the value we are using.
00867   unsigned ResNo;     // Which return value of the node we are using.
00868 public:
00869   SDValue() : Node(0), ResNo(0) {}
00870   SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
00871 
00872   /// get the index which selects a specific result in the SDNode
00873   unsigned getResNo() const { return ResNo; }
00874 
00875   /// get the SDNode which holds the desired result
00876   SDNode *getNode() const { return Node; }
00877 
00878   /// set the SDNode
00879   void setNode(SDNode *N) { Node = N; }
00880 
00881   bool operator==(const SDValue &O) const {
00882     return Node == O.Node && ResNo == O.ResNo;
00883   }
00884   bool operator!=(const SDValue &O) const {
00885     return !operator==(O);
00886   }
00887   bool operator<(const SDValue &O) const {
00888     return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
00889   }
00890 
00891   SDValue getValue(unsigned R) const {
00892     return SDValue(Node, R);
00893   }
00894 
00895   // isOperandOf - Return true if this node is an operand of N.
00896   bool isOperandOf(SDNode *N) const;
00897 
00898   /// getValueType - Return the ValueType of the referenced return value.
00899   ///
00900   inline MVT getValueType() const;
00901 
00902   /// getValueSizeInBits - Returns the size of the value in bits.
00903   ///
00904   unsigned getValueSizeInBits() const {
00905     return getValueType().getSizeInBits();
00906   }
00907 
00908   // Forwarding methods - These forward to the corresponding methods in SDNode.
00909   inline unsigned getOpcode() const;
00910   inline unsigned getNumOperands() const;
00911   inline const SDValue &getOperand(unsigned i) const;
00912   inline uint64_t getConstantOperandVal(unsigned i) const;
00913   inline bool isTargetOpcode() const;
00914   inline bool isMachineOpcode() const;
00915   inline unsigned getMachineOpcode() const;
00916   inline const DebugLoc getDebugLoc() const;
00917 
00918   
00919   /// reachesChainWithoutSideEffects - Return true if this operand (which must
00920   /// be a chain) reaches the specified operand without crossing any 
00921   /// side-effecting instructions.  In practice, this looks through token
00922   /// factors and non-volatile loads.  In order to remain efficient, this only
00923   /// looks a couple of nodes in, it does not do an exhaustive search.
00924   bool reachesChainWithoutSideEffects(SDValue Dest, 
00925                                       unsigned Depth = 2) const;
00926   
00927   /// use_empty - Return true if there are no nodes using value ResNo
00928   /// of Node.
00929   ///
00930   inline bool use_empty() const;
00931 
00932   /// hasOneUse - Return true if there is exactly one node using value
00933   /// ResNo of Node.
00934   ///
00935   inline bool hasOneUse() const;
00936 };
00937 
00938 
00939 template<> struct DenseMapInfo<SDValue> {
00940   static inline SDValue getEmptyKey() { 
00941     return SDValue((SDNode*)-1, -1U); 
00942   }
00943   static inline SDValue getTombstoneKey() { 
00944     return SDValue((SDNode*)-1, 0);
00945   }
00946   static unsigned getHashValue(const SDValue &Val) {
00947     return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
00948             (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
00949   }
00950   static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
00951     return LHS == RHS;
00952   }
00953   static bool isPod() { return true; }
00954 };
00955 
00956 /// simplify_type specializations - Allow casting operators to work directly on
00957 /// SDValues as if they were SDNode*'s.
00958 template<> struct simplify_type<SDValue> {
00959   typedef SDNode* SimpleType;
00960   static SimpleType getSimplifiedValue(const SDValue &Val) {
00961     return static_cast<SimpleType>(Val.getNode());
00962   }
00963 };
00964 template<> struct simplify_type<const SDValue> {
00965   typedef SDNode* SimpleType;
00966   static SimpleType getSimplifiedValue(const SDValue &Val) {
00967     return static_cast<SimpleType>(Val.getNode());
00968   }
00969 };
00970 
00971 /// SDUse - Represents a use of a SDNode. This class holds an SDValue,
00972 /// which records the SDNode being used and the result number, a
00973 /// pointer to the SDNode using the value, and Next and Prev pointers,
00974 /// which link together all the uses of an SDNode.
00975 ///
00976 class SDUse {
00977   /// Val - The value being used.
00978   SDValue Val;
00979   /// User - The user of this value.
00980   SDNode *User;
00981   /// Prev, Next - Pointers to the uses list of the SDNode referred by 
00982   /// this operand.
00983   SDUse **Prev, *Next;
00984 
00985   SDUse(const SDUse &U);          // Do not implement
00986   void operator=(const SDUse &U); // Do not implement
00987 
00988 public:
00989   SDUse() : Val(), User(NULL), Prev(NULL), Next(NULL) {}
00990 
00991   /// Normally SDUse will just implicitly convert to an SDValue that it holds.
00992   operator const SDValue&() const { return Val; }
00993 
00994   /// If implicit conversion to SDValue doesn't work, the get() method returns
00995   /// the SDValue.
00996   const SDValue &get() const { return Val; }
00997   
00998   /// getUser - This returns the SDNode that contains this Use.
00999   SDNode *getUser() { return User; }
01000 
01001   /// getNext - Get the next SDUse in the use list.
01002   SDUse *getNext() const { return Next; }
01003 
01004   /// getNode - Convenience function for get().getNode().
01005   SDNode *getNode() const { return Val.getNode(); }
01006   /// getResNo - Convenience function for get().getResNo().
01007   unsigned getResNo() const { return Val.getResNo(); }
01008   /// getValueType - Convenience function for get().getValueType().
01009   MVT getValueType() const { return Val.getValueType(); }
01010 
01011   /// operator== - Convenience function for get().operator==
01012   bool operator==(const SDValue &V) const {
01013     return Val == V;
01014   }
01015   
01016   /// operator!= - Convenience function for get().operator!=
01017   bool operator!=(const SDValue &V) const {
01018     return Val != V;
01019   }
01020 
01021   /// operator< - Convenience function for get().operator<
01022   bool operator<(const SDValue &V) const {
01023     return Val < V;
01024   }
01025 
01026 private:
01027   friend class SelectionDAG;
01028   friend class SDNode;
01029 
01030   void setUser(SDNode *p) { User = p; }
01031 
01032   /// set - Remove this use from its existing use list, assign it the
01033   /// given value, and add it to the new value's node's use list.
01034   inline void set(const SDValue &V);
01035   /// setInitial - like set, but only supports initializing a newly-allocated
01036   /// SDUse with a non-null value.
01037   inline void setInitial(const SDValue &V);
01038   /// setNode - like set, but only sets the Node portion of the value,
01039   /// leaving the ResNo portion unmodified.
01040   inline void setNode(SDNode *N);
01041 
01042   void addToList(SDUse **List) {
01043     Next = *List;
01044     if (Next) Next->Prev = &Next;
01045     Prev = List;
01046     *List = this;
01047   }
01048 
01049   void removeFromList() {
01050     *Prev = Next;
01051     if (Next) Next->Prev = Prev;
01052   }
01053 };
01054 
01055 /// simplify_type specializations - Allow casting operators to work directly on
01056 /// SDValues as if they were SDNode*'s.
01057 template<> struct simplify_type<SDUse> {
01058   typedef SDNode* SimpleType;
01059   static SimpleType getSimplifiedValue(const SDUse &Val) {
01060     return static_cast<SimpleType>(Val.getNode());
01061   }
01062 };
01063 template<> struct simplify_type<const SDUse> {
01064   typedef SDNode* SimpleType;
01065   static SimpleType getSimplifiedValue(const SDUse &Val) {
01066     return static_cast<SimpleType>(Val.getNode());
01067   }
01068 };
01069 
01070 
01071 /// SDNode - Represents one node in the SelectionDAG.
01072 ///
01073 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
01074 private:
01075   /// NodeType - The operation that this node performs.
01076   ///
01077   short NodeType;
01078   
01079   /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
01080   /// then they will be delete[]'d when the node is destroyed.
01081   unsigned short OperandsNeedDelete : 1;
01082 
01083 protected:
01084   /// SubclassData - This member is defined by this class, but is not used for
01085   /// anything.  Subclasses can use it to hold whatever state they find useful.
01086   /// This field is initialized to zero by the ctor.
01087   unsigned short SubclassData : 15;
01088 
01089 private:
01090   /// NodeId - Unique id per SDNode in the DAG.
01091   int NodeId;
01092 
01093   /// OperandList - The values that are used by this operation.
01094   ///
01095   SDUse *OperandList;
01096   
01097   /// ValueList - The types of the values this node defines.  SDNode's may
01098   /// define multiple values simultaneously.
01099   const MVT *ValueList;
01100 
01101   /// UseList - List of uses for this SDNode.
01102   SDUse *UseList;
01103 
01104   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
01105   unsigned short NumOperands, NumValues;
01106 
01107   /// debugLoc - source line information.
01108   DebugLoc debugLoc;
01109 
01110   /// getValueTypeList - Return a pointer to the specified value type.
01111   static const MVT *getValueTypeList(MVT VT);
01112 
01113   friend class SelectionDAG;
01114   friend struct ilist_traits<SDNode>;
01115 
01116 public:
01117   //===--------------------------------------------------------------------===//
01118   //  Accessors
01119   //
01120 
01121   /// getOpcode - Return the SelectionDAG opcode value for this node. For
01122   /// pre-isel nodes (those for which isMachineOpcode returns false), these
01123   /// are the opcode values in the ISD and <target>ISD namespaces. For
01124   /// post-isel opcodes, see getMachineOpcode.
01125   unsigned getOpcode()  const { return (unsigned short)NodeType; }
01126 
01127   /// isTargetOpcode - Test if this node has a target-specific opcode (in the
01128   /// <target>ISD namespace).
01129   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
01130 
01131   /// isMachineOpcode - Test if this node has a post-isel opcode, directly
01132   /// corresponding to a MachineInstr opcode.
01133   bool isMachineOpcode() const { return NodeType < 0; }
01134 
01135   /// getMachineOpcode - This may only be called if isMachineOpcode returns
01136   /// true. It returns the MachineInstr opcode value that the node's opcode
01137   /// corresponds to.
01138   unsigned getMachineOpcode() const {
01139     assert(isMachineOpcode() && "Not a MachineInstr opcode!");
01140     return ~NodeType;
01141   }
01142 
01143   /// use_empty - Return true if there are no uses of this node.
01144   ///
01145   bool use_empty() const { return UseList == NULL; }
01146 
01147   /// hasOneUse - Return true if there is exactly one use of this node.
01148   ///
01149   bool hasOneUse() const {
01150     return !use_empty() && next(use_begin()) == use_end();
01151   }
01152 
01153   /// use_size - Return the number of uses of this node. This method takes
01154   /// time proportional to the number of uses.
01155   ///
01156   size_t use_size() const { return std::distance(use_begin(), use_end()); }
01157 
01158   /// getNodeId - Return the unique node id.
01159   ///
01160   int getNodeId() const { return NodeId; }
01161 
01162   /// setNodeId - Set unique node id.
01163   void setNodeId(int Id) { NodeId = Id; }
01164 
01165   /// getDebugLoc - Return the source location info.
01166   const DebugLoc getDebugLoc() const { return debugLoc; }
01167 
01168   /// setDebugLoc - Set source location info.  Try to avoid this, putting
01169   /// it in the constructor is preferable.
01170   void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
01171 
01172   /// use_iterator - This class provides iterator support for SDUse
01173   /// operands that use a specific SDNode. 
01174   class use_iterator
01175     : public forward_iterator<SDUse, ptrdiff_t> {
01176     SDUse *Op;
01177     explicit use_iterator(SDUse *op) : Op(op) {
01178     }
01179     friend class SDNode;
01180   public:
01181     typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
01182     typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
01183 
01184     use_iterator(const use_iterator &I) : Op(I.Op) {}
01185     use_iterator() : Op(0) {}
01186 
01187     bool operator==(const use_iterator &x) const {
01188       return Op == x.Op;
01189     }
01190     bool operator!=(const use_iterator &x) const {
01191       return !operator==(x);
01192     }
01193  
01194     /// atEnd - return true if this iterator is at the end of uses list.
01195     bool atEnd() const { return Op == 0; }
01196 
01197     // Iterator traversal: forward iteration only.
01198     use_iterator &operator++() {          // Preincrement
01199       assert(Op && "Cannot increment end iterator!");
01200       Op = Op->getNext();
01201       return *this;
01202     }
01203 
01204     use_iterator operator++(int) {        // Postincrement
01205       use_iterator tmp = *this; ++*this; return tmp;
01206     }
01207 
01208     /// Retrieve a pointer to the current user node.
01209     SDNode *operator*() const {
01210       assert(Op && "Cannot dereference end iterator!");
01211       return Op->getUser();
01212     }
01213 
01214     SDNode *operator->() const { return operator*(); }
01215 
01216     SDUse &getUse() const { return *Op; }
01217 
01218     /// getOperandNo - Retrieve the operand # of this use in its user.
01219     ///
01220     unsigned getOperandNo() const {
01221       assert(Op && "Cannot dereference end iterator!");
01222       return (unsigned)(Op - Op->getUser()->OperandList);
01223     }
01224   };
01225 
01226   /// use_begin/use_end - Provide iteration support to walk over all uses
01227   /// of an SDNode.
01228 
01229   use_iterator use_begin() const {
01230     return use_iterator(UseList);
01231   }
01232 
01233   static use_iterator use_end() { return use_iterator(0); }
01234 
01235 
01236   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
01237   /// indicated value.  This method ignores uses of other values defined by this
01238   /// operation.
01239   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
01240 
01241   /// hasAnyUseOfValue - Return true if there are any use of the indicated
01242   /// value. This method ignores uses of other values defined by this operation.
01243   bool hasAnyUseOfValue(unsigned Value) const;
01244 
01245   /// isOnlyUserOf - Return true if this node is the only use of N.
01246   ///
01247   bool isOnlyUserOf(SDNode *N) const;
01248 
01249   /// isOperandOf - Return true if this node is an operand of N.
01250   ///
01251   bool isOperandOf(SDNode *N) const;
01252 
01253   /// isPredecessorOf - Return true if this node is a predecessor of N. This
01254   /// node is either an operand of N or it can be reached by recursively
01255   /// traversing up the operands.
01256   /// NOTE: this is an expensive method. Use it carefully.
01257   bool isPredecessorOf(SDNode *N) const;
01258 
01259   /// getNumOperands - Return the number of values used by this operation.
01260   ///
01261   unsigned getNumOperands() const { return NumOperands; }
01262 
01263   /// getConstantOperandVal - Helper method returns the integer value of a 
01264   /// ConstantSDNode operand.
01265   uint64_t getConstantOperandVal(unsigned Num) const;
01266 
01267   const SDValue &getOperand(unsigned Num) const {
01268     assert(Num < NumOperands && "Invalid child # of SDNode!");
01269     return OperandList[Num];
01270   }
01271 
01272   typedef SDUse* op_iterator;
01273   op_iterator op_begin() const { return OperandList; }
01274   op_iterator op_end() const { return OperandList+NumOperands; }
01275 
01276   SDVTList getVTList() const {
01277     SDVTList X = { ValueList, NumValues };
01278     return X;
01279   };
01280 
01281   /// getFlaggedNode - If this node has a flag operand, return the node
01282   /// to which the flag operand points. Otherwise return NULL.
01283   SDNode *getFlaggedNode() const {
01284     if (getNumOperands() != 0 &&
01285         getOperand(getNumOperands()-1).getValueType() == MVT::Flag)
01286       return getOperand(getNumOperands()-1).getNode();
01287     return 0;
01288   }
01289 
01290   // If this is a pseudo op, like copyfromreg, look to see if there is a
01291   // real target node flagged to it.  If so, return the target node.
01292   const SDNode *getFlaggedMachineNode() const {
01293     const SDNode *FoundNode = this;
01294 
01295     // Climb up flag edges until a machine-opcode node is found, or the
01296     // end of the chain is reached.
01297     while (!FoundNode->isMachineOpcode()) {
01298       const SDNode *N = FoundNode->getFlaggedNode();
01299       if (!N) break;
01300       FoundNode = N;
01301     }
01302 
01303     return FoundNode;
01304   }
01305 
01306   /// getNumValues - Return the number of values defined/returned by this
01307   /// operator.
01308   ///
01309   unsigned getNumValues() const { return NumValues; }
01310 
01311   /// getValueType - Return the type of a specified result.
01312   ///
01313   MVT getValueType(unsigned ResNo) const {
01314     assert(ResNo < NumValues && "Illegal result number!");
01315     return ValueList[ResNo];
01316   }
01317 
01318   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
01319   ///
01320   unsigned getValueSizeInBits(unsigned ResNo) const {
01321     return getValueType(ResNo).getSizeInBits();
01322   }
01323 
01324   typedef const MVT* value_iterator;
01325   value_iterator value_begin() const { return ValueList; }
01326   value_iterator value_end() const { return ValueList+NumValues; }
01327 
01328   /// getOperationName - Return the opcode of this operation for printing.
01329   ///
01330   std::string getOperationName(const SelectionDAG *G = 0) const;
01331   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
01332   void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
01333   void dump() const;
01334   void dump(const SelectionDAG *G) const;
01335 
01336   static bool classof(const SDNode *) { return true; }
01337 
01338   /// Profile - Gather unique data for the node.
01339   ///
01340   void Profile(FoldingSetNodeID &ID) const;
01341 
01342   /// addUse - This method should only be used by the SDUse class.
01343   ///
01344   void addUse(SDUse &U) { U.addToList(&UseList); }
01345 
01346 protected:
01347   static SDVTList getSDVTList(MVT VT) {
01348     SDVTList Ret = { getValueTypeList(VT), 1 };
01349     return Ret;
01350   }
01351 
01352   /// The constructors that supply DebugLoc explicitly should be preferred
01353   /// for new code.
01354   SDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps)
01355     : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
01356       NodeId(-1),
01357       OperandList(NumOps ? new SDUse[NumOps] : 0),
01358       ValueList(VTs.VTs),
01359       UseList(NULL),
01360       NumOperands(NumOps), NumValues(VTs.NumVTs),
01361       debugLoc(DebugLoc::getUnknownLoc()) {
01362     for (unsigned i = 0; i != NumOps; ++i) {
01363       OperandList[i].setUser(this);
01364       OperandList[i].setInitial(Ops[i]);
01365     }
01366   }
01367 
01368   /// This constructor adds no operands itself; operands can be
01369   /// set later with InitOperands.
01370   SDNode(unsigned Opc, SDVTList VTs)
01371     : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
01372       NodeId(-1), OperandList(0), ValueList(VTs.VTs), UseList(NULL),
01373       NumOperands(0), NumValues(VTs.NumVTs),
01374       debugLoc(DebugLoc::getUnknownLoc()) {}
01375 
01376   /// The next two constructors specify DebugLoc explicitly; the intent
01377   /// is that they will replace the above two over time, and eventually
01378   /// the ones above can be removed.
01379   SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops, 
01380          unsigned NumOps)
01381     : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
01382       NodeId(-1),
01383       OperandList(NumOps ? new SDUse[NumOps] : 0),
01384       ValueList(VTs.VTs), UseList(NULL),
01385       NumOperands(NumOps), NumValues(VTs.NumVTs),
01386       debugLoc(dl) {
01387     for (unsigned i = 0; i != NumOps; ++i) {
01388       OperandList[i].setUser(this);
01389       OperandList[i].setInitial(Ops[i]);
01390     }
01391   }
01392 
01393   /// This constructor adds no operands itself; operands can be
01394   /// set later with InitOperands.
01395   SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs)
01396     : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
01397       NodeId(-1), OperandList(0), ValueList(VTs.VTs), UseList(NULL),
01398       NumOperands(0), NumValues(VTs.NumVTs),
01399       debugLoc(dl) {}
01400   
01401   /// InitOperands - Initialize the operands list of this with 1 operand.
01402   void InitOperands(SDUse *Ops, const SDValue &Op0) {
01403     Ops[0].setUser(this);
01404     Ops[0].setInitial(Op0);
01405     NumOperands = 1;
01406     OperandList = Ops;
01407   }
01408 
01409   /// InitOperands - Initialize the operands list of this with 2 operands.
01410   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
01411     Ops[0].setUser(this);
01412     Ops[0].setInitial(Op0);
01413     Ops[1].setUser(this);
01414     Ops[1].setInitial(Op1);
01415     NumOperands = 2;
01416     OperandList = Ops;
01417   }
01418 
01419   /// InitOperands - Initialize the operands list of this with 3 operands.
01420   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
01421                     const SDValue &Op2) {
01422     Ops[0].setUser(this);
01423     Ops[0].setInitial(Op0);
01424     Ops[1].setUser(this);
01425     Ops[1].setInitial(Op1);
01426     Ops[2].setUser(this);
01427     Ops[2].setInitial(Op2);
01428     NumOperands = 3;
01429     OperandList = Ops;
01430   }
01431 
01432   /// InitOperands - Initialize the operands list of this with 4 operands.
01433   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
01434                     const SDValue &Op2, const SDValue &Op3) {
01435     Ops[0].setUser(this);
01436     Ops[0].setInitial(Op0);
01437     Ops[1].setUser(this);
01438     Ops[1].setInitial(Op1);
01439     Ops[2].setUser(this);
01440     Ops[2].setInitial(Op2);
01441     Ops[3].setUser(this);
01442     Ops[3].setInitial(Op3);
01443     NumOperands = 4;
01444     OperandList = Ops;
01445   }
01446 
01447   /// InitOperands - Initialize the operands list of this with N operands.
01448   void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
01449     for (unsigned i = 0; i != N; ++i) {
01450       Ops[i].setUser(this);
01451       Ops[i].setInitial(Vals[i]);
01452     }
01453     NumOperands = N;
01454     OperandList = Ops;
01455   }
01456 
01457   /// DropOperands - Release the operands and set this node to have
01458   /// zero operands.
01459   void DropOperands();
01460 };
01461 
01462 
01463 // Define inline functions from the SDValue class.
01464 
01465 inline unsigned SDValue::getOpcode() const {
01466   return Node->getOpcode();
01467 }
01468 inline MVT SDValue::getValueType() const {
01469   return Node->getValueType(ResNo);
01470 }
01471 inline unsigned SDValue::getNumOperands() const {
01472   return Node->getNumOperands();
01473 }
01474 inline const SDValue &SDValue::getOperand(unsigned i) const {
01475   return Node->getOperand(i);
01476 }
01477 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
01478   return Node->getConstantOperandVal(i);
01479 }
01480 inline bool SDValue::isTargetOpcode() const {
01481   return Node->isTargetOpcode();
01482 }
01483 inline bool SDValue::isMachineOpcode() const {
01484   return Node->isMachineOpcode();
01485 }
01486 inline unsigned SDValue::getMachineOpcode() const {
01487   return Node->getMachineOpcode();
01488 }
01489 inline bool SDValue::use_empty() const {
01490   return !Node->hasAnyUseOfValue(ResNo);
01491 }
01492 inline bool SDValue::hasOneUse() const {
01493   return Node->hasNUsesOfValue(1, ResNo);
01494 }
01495 inline const DebugLoc SDValue::getDebugLoc() const {
01496   return Node->getDebugLoc();
01497 }
01498 
01499 // Define inline functions from the SDUse class.
01500 
01501 inline void SDUse::set(const SDValue &V) {
01502   if (Val.getNode()) removeFromList();
01503   Val = V;
01504   if (V.getNode()) V.getNode()->addUse(*this);
01505 }
01506 
01507 inline void SDUse::setInitial(const SDValue &V) {
01508   Val = V;
01509   V.getNode()->addUse(*this);
01510 }
01511 
01512 inline void SDUse::setNode(SDNode *N) {
01513   if (Val.getNode()) removeFromList();
01514   Val.setNode(N);
01515   if (N) N->addUse(*this);
01516 }
01517 
01518 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
01519 /// to allow co-allocation of node operands with the node itself.
01520 class UnarySDNode : public SDNode {
01521   SDUse Op;
01522 public:
01523   UnarySDNode(unsigned Opc, SDVTList VTs, SDValue X)
01524     : SDNode(Opc, VTs) {
01525     InitOperands(&Op, X);
01526   }
01527   UnarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X)
01528     : SDNode(Opc, dl, VTs) {
01529     InitOperands(&Op, X);
01530   }
01531 };
01532 
01533 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
01534 /// to allow co-allocation of node operands with the node itself.
01535 class BinarySDNode : public SDNode {
01536   SDUse Ops[2];
01537 public:
01538   BinarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y)
01539     : SDNode(Opc, VTs) {
01540     InitOperands(Ops, X, Y);
01541   }
01542   BinarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y)
01543     : SDNode(Opc, dl, VTs) {
01544     InitOperands(Ops, X, Y);
01545   }
01546 };
01547 
01548 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
01549 /// to allow co-allocation of node operands with the node itself.
01550 class TernarySDNode : public SDNode {
01551   SDUse Ops[3];
01552 public:
01553   TernarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y,
01554                 SDValue Z)
01555     : SDNode(Opc, VTs) {
01556     InitOperands(Ops, X, Y, Z);
01557   }
01558   TernarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y,
01559                 SDValue Z)
01560     : SDNode(Opc, dl, VTs) {
01561     InitOperands(Ops, X, Y, Z);
01562   }
01563 };
01564 
01565 
01566 /// HandleSDNode - This class is used to form a handle around another node that
01567 /// is persistant and is updated across invocations of replaceAllUsesWith on its
01568 /// operand.  This node should be directly created by end-users and not added to
01569 /// the AllNodes list.
01570 class HandleSDNode : public SDNode {
01571   SDUse Op;
01572 public:
01573   // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
01574   // fixed.
01575 #ifdef __GNUC__
01576   explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
01577 #else
01578   explicit HandleSDNode(SDValue X)
01579 #endif
01580     : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
01581     InitOperands(&Op, X);
01582   }
01583   ~HandleSDNode();  
01584   const SDValue &getValue() const { return Op; }
01585 };
01586 
01587 /// Abstact virtual class for operations for memory operations
01588 class MemSDNode : public SDNode {
01589 private:
01590   // MemoryVT - VT of in-memory value.
01591   MVT MemoryVT;
01592 
01593   //! SrcValue - Memory location for alias analysis.
01594   const Value *SrcValue;
01595 
01596   //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
01597   int SVOffset;
01598 
01599 public:
01600   MemSDNode(unsigned Opc, SDVTList VTs, MVT MemoryVT,
01601             const Value *srcValue, int SVOff,
01602             unsigned alignment, bool isvolatile);
01603 
01604   MemSDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps,
01605             MVT MemoryVT, const Value *srcValue, int SVOff,
01606             unsigned alignment, bool isvolatile);
01607 
01608   MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, MVT MemoryVT,
01609             const Value *srcValue, int SVOff,
01610             unsigned alignment, bool isvolatile);
01611 
01612   MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, const SDValue *Ops, 
01613             unsigned NumOps, MVT MemoryVT, const Value *srcValue, int SVOff,
01614             unsigned alignment, bool isvolatile);
01615 
01616   /// Returns alignment and volatility of the memory access
01617   unsigned getAlignment() const { return (1u << (SubclassData >> 6)) >> 1; }
01618   bool isVolatile() const { return (SubclassData >> 5) & 1; }
01619   
01620   /// getRawSubclassData - Return the SubclassData value, which contains an
01621   /// encoding of the alignment and volatile information, as well as bits
01622   /// used by subclasses. This function should only be used to compute a
01623   /// FoldingSetNodeID value.
01624   unsigned getRawSubclassData() const {
01625     return SubclassData;
01626   }
01627 
01628   /// Returns the SrcValue and offset that describes the location of the access
01629   const Value *getSrcValue() const { return SrcValue; }
01630   int getSrcValueOffset() const { return SVOffset; }
01631   
01632   /// getMemoryVT - Return the type of the in-memory value.
01633   MVT getMemoryVT() const { return MemoryVT; }
01634     
01635   /// getMemOperand - Return a MachineMemOperand object describing the memory
01636   /// reference performed by operation.
01637   MachineMemOperand getMemOperand() const;
01638 
01639   const SDValue &getChain() const { return getOperand(0); }
01640   const SDValue &getBasePtr() const {
01641     return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
01642   }
01643 
01644   // Methods to support isa and dyn_cast
01645   static bool classof(const MemSDNode *) { return true; }
01646   static bool classof(const SDNode *N) {
01647     // For some targets, we lower some target intrinsics to a MemIntrinsicNode
01648     // with either an intrinsic or a target opcode.
01649     return N->getOpcode() == ISD::LOAD                ||
01650            N->getOpcode() == ISD::STORE               ||
01651            N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
01652            N->getOpcode() == ISD::ATOMIC_SWAP         ||
01653            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
01654            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
01655            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
01656            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
01657            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
01658            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
01659            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
01660            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
01661            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
01662            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
01663            N->getOpcode() == ISD::INTRINSIC_W_CHAIN   ||
01664            N->getOpcode() == ISD::INTRINSIC_VOID      ||
01665            N->isTargetOpcode();
01666   }  
01667 };
01668 
01669 /// AtomicSDNode - A SDNode reprenting atomic operations.
01670 ///
01671 class AtomicSDNode : public MemSDNode {
01672   SDUse Ops[4];
01673   
01674 public:
01675   // Opc:   opcode for atomic
01676   // VTL:    value type list
01677   // Chain:  memory chain for operaand
01678   // Ptr:    address to update as a SDValue
01679   // Cmp:    compare value
01680   // Swp:    swap value
01681   // SrcVal: address to update as a Value (used for MemOperand)
01682   // Align:  alignment of memory
01683   AtomicSDNode(unsigned Opc, SDVTList VTL, MVT MemVT,
01684                SDValue Chain, SDValue Ptr,
01685                SDValue Cmp, SDValue Swp, const Value* SrcVal,
01686                unsigned Align=0)
01687     : MemSDNode(Opc, VTL, MemVT, SrcVal, /*SVOffset=*/0,
01688                 Align, /*isVolatile=*/true) {
01689     InitOperands(Ops, Chain, Ptr, Cmp, Swp);
01690   }
01691   AtomicSDNode(unsigned Opc, SDVTList VTL, MVT MemVT,
01692                SDValue Chain, SDValue Ptr, 
01693                SDValue Val, const Value* SrcVal, unsigned Align=0)
01694     : MemSDNode(Opc, VTL, MemVT, SrcVal, /*SVOffset=*/0,
01695                 Align, /*isVolatile=*/true) {
01696     InitOperands(Ops, Chain, Ptr, Val);
01697   }
01698   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, MVT MemVT,
01699                SDValue Chain, SDValue Ptr,
01700                SDValue Cmp, SDValue Swp, const Value* SrcVal,
01701                unsigned Align=0)
01702     : MemSDNode(Opc, dl, VTL, MemVT, SrcVal, /*SVOffset=*/0,
01703                 Align, /*isVolatile=*/true) {
01704     InitOperands(Ops, Chain, Ptr, Cmp, Swp);
01705   }
01706   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, MVT MemVT,
01707                SDValue Chain, SDValue Ptr, 
01708                SDValue Val, const Value* SrcVal, unsigned Align=0)
01709     : MemSDNode(Opc, dl, VTL, MemVT, SrcVal, /*SVOffset=*/0,
01710                 Align, /*isVolatile=*/true) {
01711     InitOperands(Ops, Chain, Ptr, Val);
01712   }
01713   
01714   const SDValue &getBasePtr() const { return getOperand(1); }
01715   const SDValue &getVal() const { return getOperand(2); }
01716 
01717   bool isCompareAndSwap() const { 
01718     unsigned Op = getOpcode(); 
01719     return Op == ISD::ATOMIC_CMP_SWAP;
01720   }
01721 
01722   // Methods to support isa and dyn_cast
01723   static bool classof(const AtomicSDNode *) { return true; }
01724   static bool classof(const SDNode *N) {
01725     return N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
01726            N->getOpcode() == ISD::ATOMIC_SWAP         ||
01727            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
01728            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
01729            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
01730            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
01731            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
01732            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
01733            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
01734            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
01735            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
01736            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
01737   }
01738 };
01739 
01740 /// MemIntrinsicSDNode - This SDNode is used for target intrinsic that touches
01741 /// memory and need an associated memory operand.
01742 ///
01743 class MemIntrinsicSDNode : public MemSDNode {
01744   bool ReadMem;  // Intrinsic reads memory
01745   bool WriteMem; // Intrinsic writes memory
01746 public:
01747   MemIntrinsicSDNode(unsigned Opc, SDVTList VTs,
01748                      const SDValue *Ops, unsigned NumOps,
01749                      MVT MemoryVT, const Value *srcValue, int SVO,
01750                      unsigned Align, bool Vol, bool ReadMem, bool WriteMem)
01751     : MemSDNode(Opc, VTs, Ops, NumOps, MemoryVT, srcValue, SVO, Align, Vol),
01752       ReadMem(ReadMem), WriteMem(WriteMem) {
01753   }
01754   MemIntrinsicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs,
01755                      const SDValue *Ops, unsigned NumOps,
01756                      MVT MemoryVT, const Value *srcValue, int SVO,
01757                      unsigned Align, bool Vol, bool ReadMem, bool WriteMem)
01758     : MemSDNode(Opc, dl, VTs, Ops, NumOps, MemoryVT, srcValue, SVO, Align, Vol),
01759       ReadMem(ReadMem), WriteMem(WriteMem) {
01760   }
01761 
01762   bool readMem() const { return ReadMem; }
01763   bool writeMem() const { return WriteMem; }
01764 
01765   // Methods to support isa and dyn_cast
01766   static bool classof(const MemIntrinsicSDNode *) { return true; }
01767   static bool classof(const SDNode *N) {
01768     // We lower some target intrinsics to their target opcode
01769     // early a node with a target opcode can be of this class
01770     return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
01771            N->getOpcode() == ISD::INTRINSIC_VOID ||
01772            N->isTargetOpcode();
01773   }
01774 };
01775 
01776 class ConstantSDNode : public SDNode {
01777   const ConstantInt *Value;
01778 protected:
01779   friend class SelectionDAG;
01780   ConstantSDNode(bool isTarget, const ConstantInt *val, MVT VT)
01781     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
01782       Value(val) {
01783   }
01784 public:
01785 
01786   const ConstantInt *getConstantIntValue() const { return Value; }
01787   const APInt &getAPIntValue() const { return Value->getValue(); }
01788   uint64_t getZExtValue() const { return Value->getZExtValue(); }
01789   int64_t getSExtValue() const { return Value->getSExtValue(); }
01790 
01791   bool isNullValue() const { return Value->isNullValue(); }
01792   bool isAllOnesValue() const { return Value->isAllOnesValue(); }
01793 
01794   static bool classof(const ConstantSDNode *) { return true; }
01795   static bool classof(const SDNode *N) {
01796     return N->getOpcode() == ISD::Constant ||
01797            N->getOpcode() == ISD::TargetConstant;
01798   }
01799 };
01800 
01801 class ConstantFPSDNode : public SDNode {
01802   const ConstantFP *Value;
01803 protected:
01804   friend class SelectionDAG;
01805   ConstantFPSDNode(bool isTarget, const ConstantFP *val, MVT VT)
01806     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
01807              getSDVTList(VT)), Value(val) {
01808   }
01809 public:
01810 
01811   const APFloat& getValueAPF() const { return Value->getValueAPF(); }
01812   const ConstantFP *getConstantFPValue() const { return Value; }
01813 
01814   /// isExactlyValue - We don't rely on operator== working on double values, as
01815   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
01816   /// As such, this method can be used to do an exact bit-for-bit comparison of
01817   /// two floating point values.
01818 
01819   /// We leave the version with the double argument here because it's just so
01820   /// convenient to write "2.0" and the like.  Without this function we'd 
01821   /// have to duplicate its logic everywhere it's called.
01822   bool isExactlyValue(double V) const {
01823     bool ignored;
01824     // convert is not supported on this type
01825     if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
01826       return false;
01827     APFloat Tmp(V);
01828     Tmp.convert(Value->getValueAPF().getSemantics(),
01829                 APFloat::rmNearestTiesToEven, &ignored);
01830     return isExactlyValue(Tmp);
01831   }
01832   bool isExactlyValue(const APFloat& V) const;
01833 
01834   bool isValueValidForType(MVT VT, const APFloat& Val);
01835 
01836   static bool classof(const ConstantFPSDNode *) { return true; }
01837   static bool classof(const SDNode *N) {
01838     return N->getOpcode() == ISD::ConstantFP || 
01839            N->getOpcode() == ISD::TargetConstantFP;
01840   }
01841 };
01842 
01843 class GlobalAddressSDNode : public SDNode {
01844   GlobalValue *TheGlobal;
01845   int64_t Offset;
01846 protected:
01847   friend class SelectionDAG;
01848   GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT,
01849                       int64_t o = 0);
01850 public:
01851 
01852   GlobalValue *getGlobal() const { return TheGlobal; }
01853   int64_t getOffset() const { return Offset; }
01854 
01855   static bool classof(const GlobalAddressSDNode *) { return true; }
01856   static bool classof(const SDNode *N) {
01857     return N->getOpcode() == ISD::GlobalAddress ||
01858            N->getOpcode() == ISD::TargetGlobalAddress ||
01859            N->getOpcode() == ISD::GlobalTLSAddress ||
01860            N->getOpcode() == ISD::TargetGlobalTLSAddress;
01861   }
01862 };
01863 
01864 class FrameIndexSDNode : public SDNode {
01865   int FI;
01866 protected:
01867   friend class SelectionDAG;
01868   FrameIndexSDNode(int fi, MVT VT, bool isTarg)
01869     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
01870       FI(fi) {
01871   }
01872 public:
01873 
01874   int getIndex() const { return FI; }
01875 
01876   static bool classof(const FrameIndexSDNode *) { return true; }
01877   static bool classof(const SDNode *N) {
01878     return N->getOpcode() == ISD::FrameIndex ||
01879            N->getOpcode() == ISD::TargetFrameIndex;
01880   }
01881 };
01882 
01883 class JumpTableSDNode : public SDNode {
01884   int JTI;
01885 protected:
01886   friend class SelectionDAG;
01887   JumpTableSDNode(int jti, MVT VT, bool isTarg)
01888     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
01889       JTI(jti) {
01890   }
01891 public:
01892     
01893   int getIndex() const { return JTI; }
01894   
01895   static bool classof(const JumpTableSDNode *) { return true; }
01896   static bool classof(const SDNode *N) {
01897     return N->getOpcode() == ISD::JumpTable ||
01898            N->getOpcode() == ISD::TargetJumpTable;
01899   }
01900 };
01901 
01902 class ConstantPoolSDNode : public SDNode {
01903   union {
01904     Constant *ConstVal;
01905     MachineConstantPoolValue *MachineCPVal;
01906   } Val;
01907   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
01908   unsigned Alignment;
01909 protected:
01910   friend class SelectionDAG;
01911   ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0)
01912     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
01913              getSDVTList(VT)), Offset(o), Alignment(0) {
01914     assert((int)Offset >= 0 && "Offset is too large");
01915     Val.ConstVal = c;
01916   }
01917   ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o, unsigned Align)
01918     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
01919              getSDVTList(VT)), Offset(o), Alignment(Align) {
01920     assert((int)Offset >= 0 && "Offset is too large");
01921     Val.ConstVal = c;
01922   }
01923   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
01924                      MVT VT, int o=0)
01925     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
01926              getSDVTList(VT)), Offset(o), Alignment(0) {
01927     assert((int)Offset >= 0 && "Offset is too large");
01928     Val.MachineCPVal = v;
01929     Offset |= 1 << (sizeof(unsigned)*8-1);
01930   }
01931   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
01932                      MVT VT, int o, unsigned Align)
01933     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
01934              getSDVTList(VT)), Offset(o), Alignment(Align) {
01935     assert((int)Offset >= 0 && "Offset is too large");
01936     Val.MachineCPVal = v;
01937     Offset |= 1 << (sizeof(unsigned)*8-1);
01938   }
01939 public:
01940 
01941   bool isMachineConstantPoolEntry() const {
01942     return (int)Offset < 0;
01943   }
01944 
01945   Constant *getConstVal() const {
01946     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
01947     return Val.ConstVal;
01948   }
01949 
01950   MachineConstantPoolValue *getMachineCPVal() const {
01951     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
01952     return Val.MachineCPVal;
01953   }
01954 
01955   int getOffset() const {
01956     return Offset & ~(1 << (sizeof(unsigned)*8-1));
01957   }
01958   
01959   // Return the alignment of this constant pool object, which is either 0 (for
01960   // default alignment) or log2 of the desired value.
01961   unsigned getAlignment() const { return Alignment; }
01962 
01963   const Type *getType() const;
01964 
01965   static bool classof(const ConstantPoolSDNode *) { return true; }
01966   static bool classof(const SDNode *N) {
01967     return N->getOpcode() == ISD::ConstantPool ||
01968            N->getOpcode() == ISD::TargetConstantPool;
01969   }
01970 };
01971 
01972 class BasicBlockSDNode : public SDNode {
01973   MachineBasicBlock *MBB;
01974 protected:
01975   friend class SelectionDAG;
01976   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
01977     : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
01978   }
01979   explicit BasicBlockSDNode(MachineBasicBlock *mbb, DebugLoc dl)
01980     : SDNode(ISD::BasicBlock, dl, getSDVTList(MVT::Other)), MBB(mbb) {
01981   }
01982 public:
01983 
01984   MachineBasicBlock *getBasicBlock() const { return MBB; }
01985 
01986   static bool classof(const BasicBlockSDNode *) { return true; }
01987   static bool classof(const SDNode *N) {
01988     return N->getOpcode() == ISD::BasicBlock;
01989   }
01990 };
01991 
01992 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
01993 /// used when the SelectionDAG needs to make a simple reference to something
01994 /// in the LLVM IR representation.
01995 ///
01996 /// Note that this is not used for carrying alias information; that is done
01997 /// with MemOperandSDNode, which includes a Value which is required to be a
01998 /// pointer, and several other fields specific to memory references.
01999 ///
02000 class SrcValueSDNode : public SDNode {
02001   const Value *V;
02002 protected:
02003   friend class SelectionDAG;
02004   /// Create a SrcValue for a general value.
02005   explicit SrcValueSDNode(const Value *v)
02006     : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
02007 
02008 public:
02009   /// getValue - return the contained Value.
02010   const Value *getValue() const { return V; }
02011 
02012   static bool classof(const SrcValueSDNode *) { return true; }
02013   static bool classof(const SDNode *N) {
02014     return N->getOpcode() == ISD::SRCVALUE;
02015   }
02016 };
02017 
02018 
02019 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
02020 /// used to represent a reference to memory after ISD::LOAD
02021 /// and ISD::STORE have been lowered.
02022 ///
02023 class MemOperandSDNode : public SDNode {
02024 protected:
02025   friend class SelectionDAG;
02026   /// Create a MachineMemOperand node
02027   explicit MemOperandSDNode(const MachineMemOperand &mo)
02028     : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
02029 
02030 public:
02031   /// MO - The contained MachineMemOperand.
02032   const MachineMemOperand MO;
02033 
02034   static bool classof(const MemOperandSDNode *) { return true; }
02035   static bool classof(const SDNode *N) {
02036     return N->getOpcode() == ISD::MEMOPERAND;
02037   }
02038 };
02039 
02040 
02041 class RegisterSDNode : public SDNode {
02042   unsigned Reg;
02043 protected:
02044   friend class SelectionDAG;
02045   RegisterSDNode(unsigned reg, MVT VT)
02046     : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
02047   }
02048 public:
02049 
02050   unsigned getReg() const { return Reg; }
02051 
02052   static bool classof(const RegisterSDNode *) { return true; }
02053   static bool classof(const SDNode *N) {
02054     return N->getOpcode() == ISD::Register;
02055   }
02056 };
02057 
02058 class DbgStopPointSDNode : public SDNode {
02059   SDUse Chain;
02060   unsigned Line;
02061   unsigned Column;
02062   Value *CU;
02063 protected:
02064   friend class SelectionDAG;
02065   DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
02066                      Value *cu)
02067     : SDNode(ISD::DBG_STOPPOINT, getSDVTList(MVT::Other)),
02068       Line(l), Column(c), CU(cu) {
02069     InitOperands(&Chain, ch);
02070   }
02071 public:
02072   unsigned getLine() const { return Line; }
02073   unsigned getColumn() const { return Column; }
02074   Value *getCompileUnit() const { return CU; }
02075 
02076   static bool classof(const DbgStopPointSDNode *) { return true; }
02077   static bool classof(const SDNode *N) {
02078     return N->getOpcode() == ISD::DBG_STOPPOINT;
02079   }
02080 };
02081 
02082 class LabelSDNode : public SDNode {
02083   SDUse Chain;
02084   unsigned LabelID;
02085 protected:
02086   friend class SelectionDAG;
02087   LabelSDNode(unsigned NodeTy, SDValue ch, unsigned id)
02088     : SDNode(NodeTy, getSDVTList(MVT::Other)), LabelID(id) {
02089     InitOperands(&Chain, ch);
02090   }
02091   LabelSDNode(unsigned NodeTy, DebugLoc dl, SDValue ch, unsigned id)
02092     : SDNode(NodeTy, dl, getSDVTList(MVT::Other)), LabelID(id) {
02093     InitOperands(&Chain, ch);
02094   }
02095 public:
02096   unsigned getLabelID() const { return LabelID; }
02097 
02098   static bool classof(const LabelSDNode *) { return true; }
02099   static bool classof(const SDNode *N) {
02100     return N->getOpcode() == ISD::DBG_LABEL ||
02101            N->getOpcode() == ISD::EH_LABEL;
02102   }
02103 };
02104 
02105 class ExternalSymbolSDNode : public SDNode {
02106   const char *Symbol;
02107 protected:
02108   friend class SelectionDAG;
02109   ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT VT)
02110     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
02111              getSDVTList(VT)), Symbol(Sym) {
02112   }
02113   ExternalSymbolSDNode(bool isTarget, DebugLoc dl, const char *Sym, MVT VT)
02114     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, dl,
02115              getSDVTList(VT)), Symbol(Sym) {
02116   }
02117 public:
02118 
02119   const char *getSymbol() const { return Symbol; }
02120 
02121   static bool classof(const ExternalSymbolSDNode *) { return true; }
02122   static bool classof(const SDNode *N) {
02123     return N->getOpcode() == ISD::ExternalSymbol ||
02124            N->getOpcode() == ISD::TargetExternalSymbol;
02125   }
02126 };
02127 
02128 class CondCodeSDNode : public SDNode {
02129   ISD::CondCode Condition;
02130 protected:
02131   friend class SelectionDAG;
02132   explicit CondCodeSDNode(ISD::CondCode Cond)
02133     : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
02134   }
02135 public:
02136 
02137   ISD::CondCode get() const { return Condition; }
02138 
02139   static bool classof(const CondCodeSDNode *) { return true; }
02140   static bool classof(const SDNode *N) {
02141     return N->getOpcode() == ISD::CONDCODE;
02142   }
02143 };
02144 
02145 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
02146 /// future and most targets don't support it.
02147 class CvtRndSatSDNode : public SDNode {
02148   ISD::CvtCode CvtCode;
02149 protected:
02150   friend class SelectionDAG;
02151   explicit CvtRndSatSDNode(MVT VT, const SDValue *Ops, unsigned NumOps,
02152                            ISD::CvtCode Code)
02153     : SDNode(ISD::CONVERT_RNDSAT, getSDVTList(VT), Ops, NumOps), CvtCode(Code) {
02154     assert(NumOps == 5 && "wrong number of operations");
02155   }
02156 public:
02157   ISD::CvtCode getCvtCode() const { return CvtCode; }
02158 
02159   static bool classof(const CvtRndSatSDNode *) { return true; }
02160   static bool classof(const SDNode *N) {
02161     return N->getOpcode() == ISD::CONVERT_RNDSAT;
02162   }
02163 };
02164 
02165 namespace ISD {
02166   struct ArgFlagsTy {
02167   private:
02168     static const uint64_t NoFlagSet      = 0ULL;
02169     static const uint64_t ZExt           = 1ULL<<0;  ///< Zero extended
02170     static const uint64_t ZExtOffs       = 0;
02171     static const uint64_t SExt           = 1ULL<<1;  ///< Sign extended
02172     static const uint64_t SExtOffs       = 1;
02173     static const uint64_t InReg          = 1ULL<<2;  ///< Passed in register
02174     static const uint64_t InRegOffs      = 2;
02175     static const uint64_t SRet           = 1ULL<<3;  ///< Hidden struct-ret ptr
02176     static const uint64_t SRetOffs       = 3;
02177     static const uint64_t ByVal          = 1ULL<<4;  ///< Struct passed by value
02178     static const uint64_t ByValOffs      = 4;
02179     static const uint64_t Nest           = 1ULL<<5;  ///< Nested fn static chain
02180     static const uint64_t NestOffs       = 5;
02181     static const uint64_t ByValAlign     = 0xFULL << 6; //< Struct alignment
02182     static const uint64_t ByValAlignOffs = 6;
02183     static const uint64_t Split          = 1ULL << 10;
02184     static const uint64_t SplitOffs      = 10;
02185     static const uint64_t OrigAlign      = 0x1FULL<<27;
02186     static const uint64_t OrigAlignOffs  = 27;
02187     static const uint64_t ByValSize      = 0xffffffffULL << 32; //< Struct size
02188     static const uint64_t ByValSizeOffs  = 32;
02189 
02190     static const uint64_t One            = 1ULL; //< 1 of this type, for shifts
02191 
02192     uint64_t Flags;
02193   public:
02194     ArgFlagsTy() : Flags(0) { }
02195 
02196     bool isZExt()   const { return Flags & ZExt; }
02197     void setZExt()  { Flags |= One << ZExtOffs; }
02198 
02199     bool isSExt()   const { return Flags & SExt; }
02200     void setSExt()  { Flags |= One << SExtOffs; }
02201 
02202     bool isInReg()  const { return Flags & InReg; }
02203     void setInReg() { Flags |= One << InRegOffs; }
02204 
02205     bool isSRet()   const { return Flags & SRet; }
02206     void setSRet()  { Flags |= One << SRetOffs; }
02207 
02208     bool isByVal()  const { return Flags & ByVal; }
02209     void setByVal() { Flags |= One << ByValOffs; }
02210 
02211     bool isNest()   const { return Flags & Nest; }
02212     void setNest()  { Flags |= One << NestOffs; }
02213 
02214     unsigned getByValAlign() const {
02215       return (unsigned) 
02216         ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
02217     }
02218     void setByValAlign(unsigned A) {
02219       Flags = (Flags & ~ByValAlign) |
02220         (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
02221     }
02222             
02223     bool isSplit()   const { return Flags & Split; }
02224     void setSplit()  { Flags |= One << SplitOffs; }
02225 
02226     unsigned getOrigAlign() const {
02227       return (unsigned)
02228         ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
02229     }
02230     void setOrigAlign(unsigned A) {
02231       Flags = (Flags & ~OrigAlign) |
02232         (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
02233     }
02234 
02235     unsigned getByValSize() const {
02236       return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
02237     }
02238     void setByValSize(unsigned S) {
02239       Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
02240     }
02241 
02242     /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
02243     std::string getArgFlagsString();
02244 
02245     /// getRawBits - Represent the flags as a bunch of bits.
02246     uint64_t getRawBits() const { return Flags; }
02247   };
02248 }
02249 
02250 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
02251 class ARG_FLAGSSDNode : public SDNode {
02252   ISD::ArgFlagsTy TheFlags;
02253 protected:
02254   friend class SelectionDAG;
02255   explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
02256     : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
02257   }
02258 public:
02259   ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
02260 
02261   static bool classof(const ARG_FLAGSSDNode *) { return true; }
02262   static bool classof(const SDNode *N) {
02263     return N->getOpcode() == ISD::ARG_FLAGS;
02264   }
02265 };
02266 
02267 /// CallSDNode - Node for calls -- ISD::CALL.
02268 class CallSDNode : public SDNode {
02269   unsigned CallingConv;
02270   bool IsVarArg;
02271   bool IsTailCall;
02272   // We might eventually want a full-blown Attributes for the result; that
02273   // will expand the size of the representation.  At the moment we only
02274   // need Inreg.
02275   bool Inreg;
02276 protected:
02277   friend class SelectionDAG;
02278   CallSDNode(unsigned cc, bool isvararg, bool istailcall, bool isinreg,
02279              SDVTList VTs, const SDValue *Operands, unsigned numOperands)
02280     : SDNode(ISD::CALL, VTs, Operands, numOperands),
02281       CallingConv(cc), IsVarArg(isvararg), IsTailCall(istailcall),
02282       Inreg(isinreg) {}
02283   CallSDNode(unsigned cc, DebugLoc dl, bool isvararg, bool istailcall, 
02284              bool isinreg, SDVTList VTs, const SDValue *Operands, 
02285              unsigned numOperands)
02286     : SDNode(ISD::CALL, dl, VTs, Operands, numOperands),
02287       CallingConv(cc), IsVarArg(isvararg), IsTailCall(istailcall),
02288       Inreg(isinreg) {}
02289 public:
02290   unsigned getCallingConv() const { return CallingConv; }
02291   unsigned isVarArg() const { return IsVarArg; }
02292   unsigned isTailCall() const { return IsTailCall; }
02293   unsigned isInreg() const { return Inreg; }
02294 
02295   /// Set this call to not be marked as a tail call. Normally setter
02296   /// methods in SDNodes are unsafe because it breaks the CSE map,
02297   /// but we don't include the tail call flag for calls so it's ok
02298   /// in this case.
02299   void setNotTailCall() { IsTailCall = false; }
02300 
02301   SDValue getChain() const { return getOperand(0); }
02302   SDValue getCallee() const { return getOperand(1); }
02303 
02304   unsigned getNumArgs() const { return (getNumOperands() - 2) / 2; }
02305   SDValue getArg(unsigned i) const { return getOperand(2+2*i); }
02306   SDValue getArgFlagsVal(unsigned i) const {
02307     return getOperand(3+2*i);
02308   }
02309   ISD::ArgFlagsTy getArgFlags(unsigned i) const {
02310     return cast<ARG_FLAGSSDNode>(getArgFlagsVal(i).getNode())->getArgFlags();
02311   }
02312 
02313   unsigned getNumRetVals() const { return getNumValues() - 1; }
02314   MVT getRetValType(unsigned i) const { return getValueType(i); }
02315 
02316   static bool classof(const CallSDNode *) { return true; }
02317   static bool classof(const SDNode *N) {
02318     return N->getOpcode() == ISD::CALL;
02319   }
02320 };
02321 
02322 /// VTSDNode - This class is used to represent MVT's, which are used
02323 /// to parameterize some operations.
02324 class VTSDNode : public SDNode {
02325   MVT ValueType;
02326 protected:
02327   friend class SelectionDAG;
02328   explicit VTSDNode(MVT VT)
02329     : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
02330   }
02331 public:
02332 
02333   MVT getVT() const { return ValueType; }
02334 
02335   static bool classof(const VTSDNode *) { return true; }
02336   static bool classof(const SDNode *N) {
02337     return N->getOpcode() == ISD::VALUETYPE;
02338   }
02339 };
02340 
02341 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
02342 ///
02343 class LSBaseSDNode : public MemSDNode {
02344 protected:
02345   //! Operand array for load and store
02346   /*!
02347     \note Moving this array to the base class captures more
02348     common functionality shared between LoadSDNode and
02349     StoreSDNode
02350    */
02351   SDUse Ops[4];
02352 public:
02353   LSBaseSDNode(ISD::NodeType NodeTy, SDValue *Operands, unsigned numOperands,
02354                SDVTList VTs, ISD::MemIndexedMode AM, MVT VT,
02355                const Value *SV, int SVO, unsigned Align, bool Vol)
02356     : MemSDNode(NodeTy, VTs, VT, SV, SVO, Align, Vol) {
02357     assert(Align != 0 && "Loads and stores should have non-zero aligment");
02358     SubclassData |= AM << 2;
02359     assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
02360     InitOperands(Ops, Operands, numOperands);
02361     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
02362            "Only indexed loads and stores have a non-undef offset operand");
02363   }
02364   LSBaseSDNode(ISD::NodeType NodeTy, DebugLoc dl, SDValue *Operands, 
02365                unsigned numOperands, SDVTList VTs, ISD::MemIndexedMode AM, 
02366                MVT VT, const Value *SV, int SVO, unsigned Align, bool Vol)
02367     : MemSDNode(NodeTy, dl, VTs, VT, SV, SVO, Align, Vol) {
02368     assert(Align != 0 && "Loads and stores should have non-zero aligment");
02369     SubclassData |= AM << 2;
02370     assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
02371     InitOperands(Ops, Operands, numOperands);
02372     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
02373            "Only indexed loads and stores have a non-undef offset operand");
02374   }
02375 
02376   const SDValue &getOffset() const {
02377     return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
02378   }
02379 
02380   /// getAddressingMode - Return the addressing mode for this load or store:
02381   /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
02382   ISD::MemIndexedMode getAddressingMode() const {
02383     return ISD::MemIndexedMode((SubclassData >> 2) & 7);
02384   }
02385 
02386   /// isIndexed - Return true if this is a pre/post inc/dec load/store.
02387   bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
02388 
02389   /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
02390   bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
02391 
02392   static bool classof(const LSBaseSDNode *) { return true; }
02393   static bool classof(const SDNode *N) {
02394     return N->getOpcode() == ISD::LOAD ||
02395            N->getOpcode() == ISD::STORE;
02396   }
02397 };
02398 
02399 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
02400 ///
02401 class LoadSDNode : public LSBaseSDNode {
02402 protected:
02403   friend class SelectionDAG;
02404   LoadSDNode(SDValue *ChainPtrOff, SDVTList VTs,
02405              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT,
02406              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
02407     : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
02408                    VTs, AM, LVT, SV, O, Align, Vol) {
02409     SubclassData |= (unsigned short)ETy;
02410     assert(getExtensionType() == ETy && "LoadExtType encoding error!");
02411   }
02412   LoadSDNode(SDValue *ChainPtrOff, DebugLoc dl, SDVTList VTs,
02413              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT,
02414              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
02415     : LSBaseSDNode(ISD::LOAD, dl, ChainPtrOff, 3,
02416                    VTs, AM, LVT, SV, O, Align, Vol) {
02417     SubclassData |= (unsigned short)ETy;
02418     assert(getExtensionType() == ETy && "LoadExtType encoding error!");
02419   }
02420 public:
02421 
02422   /// getExtensionType - Return whether this is a plain node,
02423   /// or one of the varieties of value-extending loads.
02424   ISD::LoadExtType getExtensionType() const {
02425     return ISD::LoadExtType(SubclassData & 3);
02426   }
02427 
02428   const SDValue &getBasePtr() const { return getOperand(1); }
02429   const SDValue &getOffset() const { return getOperand(2); }
02430   
02431   static bool classof(const LoadSDNode *) { return true; }
02432   static bool classof(const SDNode *N) {
02433     return N->getOpcode() == ISD::LOAD;
02434   }
02435 };
02436 
02437 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
02438 ///
02439 class StoreSDNode : public LSBaseSDNode {
02440 protected:
02441   friend class SelectionDAG;
02442   StoreSDNode(SDValue *ChainValuePtrOff, SDVTList VTs,
02443               ISD::MemIndexedMode AM, bool isTrunc, MVT SVT,
02444               const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
02445     : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
02446                    VTs, AM, SVT, SV, O, Align, Vol) {
02447     SubclassData |= (unsigned short)isTrunc;
02448     assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
02449   }
02450   StoreSDNode(SDValue *ChainValuePtrOff, DebugLoc dl, SDVTList VTs,
02451               ISD::MemIndexedMode AM, bool isTrunc, MVT SVT,
02452               const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
02453     : LSBaseSDNode(ISD::STORE, dl, ChainValuePtrOff, 4,
02454                    VTs, AM, SVT, SV, O, Align, Vol) {
02455     SubclassData |= (unsigned short)isTrunc;
02456     assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
02457   }
02458 public:
02459 
02460   /// isTruncatingStore - Return true if the op does a truncation before store.
02461   /// For integers this is the same as doing a TRUNCATE and storing the result.
02462   /// For floats, it is the same as doing an FP_ROUND and storing the result.
02463   bool isTruncatingStore() const { return SubclassData & 1; }
02464 
02465   const SDValue &getValue() const { return getOperand(1); }
02466   const SDValue &getBasePtr() const { return getOperand(2); }
02467   const SDValue &getOffset() const { return getOperand(3); }
02468   
02469   static bool classof(const StoreSDNode *) { return true; }
02470   static bool classof(const SDNode *N) {
02471     return N->getOpcode() == ISD::STORE;
02472   }
02473 };
02474 
02475 
02476 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
02477   SDNode *Node;
02478   unsigned Operand;
02479 
02480   SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
02481 public:
02482   bool operator==(const SDNodeIterator& x) const {
02483     return Operand == x.Operand;
02484   }
02485   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
02486 
02487   const SDNodeIterator &operator=(const SDNodeIterator &I) {
02488     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
02489     Operand = I.Operand;
02490     return *this;
02491   }
02492 
02493   pointer operator*() const {
02494     return Node->getOperand(Operand).getNode();
02495   }
02496   pointer operator->() const { return operator*(); }
02497 
02498   SDNodeIterator& operator++() {                // Preincrement
02499     ++Operand;
02500     return *this;
02501   }
02502   SDNodeIterator operator++(int) { // Postincrement
02503     SDNodeIterator tmp = *this; ++*this; return tmp;
02504   }
02505 
02506   static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
02507   static SDNodeIterator end  (SDNode *N) {
02508     return SDNodeIterator(N, N->getNumOperands());
02509   }
02510 
02511   unsigned getOperand() const { return Operand; }
02512   const SDNode *getNode() const { return Node; }
02513 };
02514 
02515 template <> struct GraphTraits<SDNode*> {
02516   typedef SDNode NodeType;
02517   typedef SDNodeIterator ChildIteratorType;
02518   static inline NodeType *getEntryNode(SDNode *N) { return N; }
02519   static inline ChildIteratorType child_begin(NodeType *N) {
02520     return SDNodeIterator::begin(N);
02521   }
02522   static inline ChildIteratorType child_end(NodeType *N) {
02523     return SDNodeIterator::end(N);
02524   }
02525 };
02526 
02527 /// LargestSDNode - The largest SDNode class.
02528 ///
02529 typedef LoadSDNode LargestSDNode;
02530 
02531 /// MostAlignedSDNode - The SDNode class with the greatest alignment
02532 /// requirement.
02533 ///
02534 typedef ARG_FLAGSSDNode MostAlignedSDNode;
02535 
02536 namespace ISD {
02537   /// isNormalLoad - Returns true if the specified node is a non-extending
02538   /// and unindexed load.
02539   inline bool isNormalLoad(const SDNode *N) {
02540     const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
02541     return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
02542       Ld->getAddressingMode() == ISD::UNINDEXED;
02543   }
02544 
02545   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
02546   /// load.
02547   inline bool isNON_EXTLoad(const SDNode *N) {
02548     return isa<LoadSDNode>(N) &&
02549       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
02550   }
02551 
02552   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
02553   ///
02554   inline bool isEXTLoad(const SDNode *N) {
02555     return isa<LoadSDNode>(N) &&
02556       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
02557   }
02558 
02559   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
02560   ///
02561   inline bool isSEXTLoad(const SDNode *N) {
02562     return isa<LoadSDNode>(N) &&
02563       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
02564   }
02565 
02566   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
02567   ///
02568   inline bool isZEXTLoad(const SDNode *N) {
02569     return isa<LoadSDNode>(N) &&
02570       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
02571   }
02572 
02573   /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
02574   ///
02575   inline bool isUNINDEXEDLoad(const SDNode *N) {
02576     return isa<LoadSDNode>(N) &&
02577       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
02578   }
02579 
02580   /// isNormalStore - Returns true if the specified node is a non-truncating
02581   /// and unindexed store.
02582   inline bool isNormalStore(const SDNode *N) {
02583     const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
02584     return St && !St->isTruncatingStore() &&
02585       St->getAddressingMode() == ISD::UNINDEXED;
02586   }
02587 
02588   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
02589   /// store.
02590   inline bool isNON_TRUNCStore(const SDNode *N) {
02591     return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
02592   }
02593 
02594   /// isTRUNCStore - Returns true if the specified node is a truncating
02595   /// store.
02596   inline bool isTRUNCStore(const SDNode *N) {
02597     return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
02598   }
02599 
02600   /// isUNINDEXEDStore - Returns true if the specified node is an
02601   /// unindexed store.
02602   inline bool isUNINDEXEDStore(const SDNode *N) {
02603     return isa<StoreSDNode>(N) &&
02604       cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
02605   }
02606 }
02607 
02608 
02609 } // end llvm namespace
02610 
02611 #endif