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