Revert 48125, 48126, and 48130 for now to unbreak some x86-64 tests.
[oota-llvm.git] / include / llvm / CodeGen / SelectionDAGNodes.h
1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG.  These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
14 //
15 // Clients should include the SelectionDAG.h file instead of this file directly.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
21
22 #include "llvm/Value.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator"
26 #include "llvm/ADT/APFloat.h"
27 #include "llvm/ADT/APInt.h"
28 #include "llvm/CodeGen/ValueTypes.h"
29 #include "llvm/CodeGen/MemOperand.h"
30 #include "llvm/Support/DataTypes.h"
31 #include <cassert>
32
33 namespace llvm {
34
35 class SelectionDAG;
36 class GlobalValue;
37 class MachineBasicBlock;
38 class MachineConstantPoolValue;
39 class SDNode;
40 template <typename T> struct DenseMapInfo;
41 template <typename T> struct simplify_type;
42 template <typename T> struct ilist_traits;
43 template<typename NodeTy, typename Traits> class iplist;
44 template<typename NodeTy> class ilist_iterator;
45
46 /// SDVTList - This represents a list of ValueType's that has been intern'd by
47 /// a SelectionDAG.  Instances of this simple value class are returned by
48 /// SelectionDAG::getVTList(...).
49 ///
50 struct SDVTList {
51   const MVT::ValueType *VTs;
52   unsigned short NumVTs;
53 };
54
55 /// ISD namespace - This namespace contains an enum which represents all of the
56 /// SelectionDAG node types and value types.
57 ///
58 namespace ISD {
59   namespace ParamFlags {    
60     typedef uint64_t ParamFlagsTy;
61
62     const ParamFlagsTy NoFlagSet         = 0ULL;
63     const ParamFlagsTy ZExt              = 1ULL<<0;  ///< Zero extended
64     const ParamFlagsTy ZExtOffs          = 0;
65     const ParamFlagsTy SExt              = 1ULL<<1;  ///< Sign extended
66     const ParamFlagsTy SExtOffs          = 1;
67     const ParamFlagsTy InReg             = 1ULL<<2;  ///< Passed in register
68     const ParamFlagsTy InRegOffs         = 2;
69     const ParamFlagsTy StructReturn      = 1ULL<<3;  ///< Hidden struct-ret ptr
70     const ParamFlagsTy StructReturnOffs  = 3;
71     const ParamFlagsTy ByVal             = 1ULL<<4;  ///< Struct passed by value
72     const ParamFlagsTy ByValOffs         = 4;
73     const ParamFlagsTy Nest              = 1ULL<<5;  ///< Nested fn static chain
74     const ParamFlagsTy NestOffs          = 5;
75     const ParamFlagsTy ByValAlign        = 0xFULL << 6; //< Struct alignment
76     const ParamFlagsTy ByValAlignOffs    = 6;
77     const ParamFlagsTy OrigAlignment     = 0x1FULL<<27;
78     const ParamFlagsTy OrigAlignmentOffs = 27;
79     const ParamFlagsTy ByValSize         = 0xffffffffULL << 32; //< Struct size 
80     const ParamFlagsTy ByValSizeOffs     = 32;
81
82     const ParamFlagsTy One               = 1LL; //< 1 of this type, for shifts
83   }
84
85   //===--------------------------------------------------------------------===//
86   /// ISD::NodeType enum - This enum defines all of the operators valid in a
87   /// SelectionDAG.
88   ///
89   enum NodeType {
90     // DELETED_NODE - This is an illegal flag value that is used to catch
91     // errors.  This opcode is not a legal opcode for any node.
92     DELETED_NODE,
93     
94     // EntryToken - This is the marker used to indicate the start of the region.
95     EntryToken,
96
97     // Token factor - This node takes multiple tokens as input and produces a
98     // single token result.  This is used to represent the fact that the operand
99     // operators are independent of each other.
100     TokenFactor,
101     
102     // AssertSext, AssertZext - These nodes record if a register contains a 
103     // value that has already been zero or sign extended from a narrower type.  
104     // These nodes take two operands.  The first is the node that has already 
105     // been extended, and the second is a value type node indicating the width
106     // of the extension
107     AssertSext, AssertZext,
108
109     // Various leaf nodes.
110     STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
111     Constant, ConstantFP,
112     GlobalAddress, GlobalTLSAddress, FrameIndex,
113     JumpTable, ConstantPool, ExternalSymbol,
114
115     // The address of the GOT
116     GLOBAL_OFFSET_TABLE,
117     
118     // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
119     // llvm.returnaddress on the DAG.  These nodes take one operand, the index
120     // of the frame or return address to return.  An index of zero corresponds
121     // to the current function's frame or return address, an index of one to the
122     // parent's frame or return address, and so on.
123     FRAMEADDR, RETURNADDR,
124
125     // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
126     // first (possible) on-stack argument. This is needed for correct stack
127     // adjustment during unwind.
128     FRAME_TO_ARGS_OFFSET,
129     
130     // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
131     // address of the exception block on entry to an landing pad block.
132     EXCEPTIONADDR,
133     
134     // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
135     // the selection index of the exception thrown.
136     EHSELECTION,
137
138     // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
139     // 'eh_return' gcc dwarf builtin, which is used to return from
140     // exception. The general meaning is: adjust stack by OFFSET and pass
141     // execution to HANDLER. Many platform-related details also :)
142     EH_RETURN,
143
144     // TargetConstant* - Like Constant*, but the DAG does not do any folding or
145     // simplification of the constant.
146     TargetConstant,
147     TargetConstantFP,
148     
149     // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
150     // anything else with this node, and this is valid in the target-specific
151     // dag, turning into a GlobalAddress operand.
152     TargetGlobalAddress,
153     TargetGlobalTLSAddress,
154     TargetFrameIndex,
155     TargetJumpTable,
156     TargetConstantPool,
157     TargetExternalSymbol,
158     
159     /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
160     /// This node represents a target intrinsic function with no side effects.
161     /// The first operand is the ID number of the intrinsic from the
162     /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
163     /// node has returns the result of the intrinsic.
164     INTRINSIC_WO_CHAIN,
165     
166     /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
167     /// This node represents a target intrinsic function with side effects that
168     /// returns a result.  The first operand is a chain pointer.  The second is
169     /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
170     /// operands to the intrinsic follow.  The node has two results, the result
171     /// of the intrinsic and an output chain.
172     INTRINSIC_W_CHAIN,
173
174     /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
175     /// This node represents a target intrinsic function with side effects that
176     /// does not return a result.  The first operand is a chain pointer.  The
177     /// second is the ID number of the intrinsic from the llvm::Intrinsic
178     /// namespace.  The operands to the intrinsic follow.
179     INTRINSIC_VOID,
180     
181     // CopyToReg - This node has three operands: a chain, a register number to
182     // set to this value, and a value.  
183     CopyToReg,
184
185     // CopyFromReg - This node indicates that the input value is a virtual or
186     // physical register that is defined outside of the scope of this
187     // SelectionDAG.  The register is available from the RegisterSDNode object.
188     CopyFromReg,
189
190     // UNDEF - An undefined node
191     UNDEF,
192     
193     /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
194     /// represents the formal arguments for a function.  CC# is a Constant value
195     /// indicating the calling convention of the function, and ISVARARG is a
196     /// flag that indicates whether the function is varargs or not. This node
197     /// has one result value for each incoming argument, plus one for the output
198     /// chain. It must be custom legalized. See description of CALL node for
199     /// FLAG argument contents explanation.
200     /// 
201     FORMAL_ARGUMENTS,
202     
203     /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
204     ///                              ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
205     /// This node represents a fully general function call, before the legalizer
206     /// runs.  This has one result value for each argument / flag pair, plus
207     /// a chain result. It must be custom legalized. Flag argument indicates
208     /// misc. argument attributes. Currently:
209     /// Bit 0 - signness
210     /// Bit 1 - 'inreg' attribute
211     /// Bit 2 - 'sret' attribute
212     /// Bit 4 - 'byval' attribute
213     /// Bit 5 - 'nest' attribute
214     /// Bit 6-9 - alignment of byval structures
215     /// Bit 10-26 - size of byval structures
216     /// Bits 31:27 - argument ABI alignment in the first argument piece and
217     /// alignment '1' in other argument pieces.
218     CALL,
219
220     // EXTRACT_ELEMENT - This is used to get the first or second (determined by
221     // a Constant, which is required to be operand #1), element of the aggregate
222     // value specified as operand #0.  This is only for use before legalization,
223     // for values that will be broken into multiple registers.
224     EXTRACT_ELEMENT,
225
226     // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
227     // two values of the same integer value type, this produces a value twice as
228     // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
229     BUILD_PAIR,
230     
231     // MERGE_VALUES - This node takes multiple discrete operands and returns
232     // them all as its individual results.  This nodes has exactly the same
233     // number of inputs and outputs, and is only valid before legalization.
234     // This node is useful for some pieces of the code generator that want to
235     // think about a single node with multiple results, not multiple nodes.
236     MERGE_VALUES,
237
238     // Simple integer binary arithmetic operators.
239     ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
240
241     // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
242     // a signed/unsigned value of type i[2*N], and return the full value as
243     // two results, each of type iN.
244     SMUL_LOHI, UMUL_LOHI,
245
246     // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
247     // remainder result.
248     SDIVREM, UDIVREM,
249     
250     // CARRY_FALSE - This node is used when folding other nodes,
251     // like ADDC/SUBC, which indicate the carry result is always false.
252     CARRY_FALSE,
253     
254     // Carry-setting nodes for multiple precision addition and subtraction.
255     // These nodes take two operands of the same value type, and produce two
256     // results.  The first result is the normal add or sub result, the second
257     // result is the carry flag result.
258     ADDC, SUBC,
259     
260     // Carry-using nodes for multiple precision addition and subtraction.  These
261     // nodes take three operands: The first two are the normal lhs and rhs to
262     // the add or sub, and the third is the input carry flag.  These nodes
263     // produce two results; the normal result of the add or sub, and the output
264     // carry flag.  These nodes both read and write a carry flag to allow them
265     // to them to be chained together for add and sub of arbitrarily large
266     // values.
267     ADDE, SUBE,
268     
269     // Simple binary floating point operators.
270     FADD, FSUB, FMUL, FDIV, FREM,
271
272     // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
273     // DAG node does not require that X and Y have the same type, just that they
274     // are both floating point.  X and the result must have the same type.
275     // FCOPYSIGN(f32, f64) is allowed.
276     FCOPYSIGN,
277
278     // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
279     // value as an integer 0/1 value.
280     FGETSIGN,
281     
282     /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
283     /// with the specified, possibly variable, elements.  The number of elements
284     /// is required to be a power of two.
285     BUILD_VECTOR,
286     
287     /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
288     /// at IDX replaced with VAL.  If the type of VAL is larger than the vector
289     /// element type then VAL is truncated before replacement.
290     INSERT_VECTOR_ELT,
291
292     /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
293     /// identified by the (potentially variable) element number IDX.
294     EXTRACT_VECTOR_ELT,
295     
296     /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
297     /// vector type with the same length and element type, this produces a
298     /// concatenated vector result value, with length equal to the sum of the
299     /// lengths of the input vectors.
300     CONCAT_VECTORS,
301     
302     /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
303     /// vector value) starting with the (potentially variable) element number
304     /// IDX, which must be a multiple of the result vector length.
305     EXTRACT_SUBVECTOR,
306
307     /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
308     /// type as VEC1/VEC2.  SHUFFLEVEC is a BUILD_VECTOR of constant int values
309     /// (maybe of an illegal datatype) or undef that indicate which value each
310     /// result element will get.  The elements of VEC1/VEC2 are enumerated in
311     /// order.  This is quite similar to the Altivec 'vperm' instruction, except
312     /// that the indices must be constants and are in terms of the element size
313     /// of VEC1/VEC2, not in terms of bytes.
314     VECTOR_SHUFFLE,
315
316     /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
317     /// scalar value into element 0 of the resultant vector type.  The top
318     /// elements 1 to N-1 of the N-element vector are undefined.
319     SCALAR_TO_VECTOR,
320     
321     // EXTRACT_SUBREG - This node is used to extract a sub-register value. 
322     // This node takes a superreg and a constant sub-register index as operands.
323     EXTRACT_SUBREG,
324     
325     // INSERT_SUBREG - This node is used to insert a sub-register value. 
326     // This node takes a superreg, a subreg value, and a constant sub-register
327     // index as operands.
328     INSERT_SUBREG,
329     
330     // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
331     // an unsigned/signed value of type i[2*N], then return the top part.
332     MULHU, MULHS,
333
334     // Bitwise operators - logical and, logical or, logical xor, shift left,
335     // shift right algebraic (shift in sign bits), shift right logical (shift in
336     // zeroes), rotate left, rotate right, and byteswap.
337     AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
338
339     // Counting operators
340     CTTZ, CTLZ, CTPOP,
341
342     // Select(COND, TRUEVAL, FALSEVAL)
343     SELECT, 
344     
345     // Select with condition operator - This selects between a true value and 
346     // a false value (ops #2 and #3) based on the boolean result of comparing
347     // the lhs and rhs (ops #0 and #1) of a conditional expression with the 
348     // condition code in op #4, a CondCodeSDNode.
349     SELECT_CC,
350
351     // SetCC operator - This evaluates to a boolean (i1) true value if the
352     // condition is true.  The operands to this are the left and right operands
353     // to compare (ops #0, and #1) and the condition code to compare them with
354     // (op #2) as a CondCodeSDNode.
355     SETCC,
356
357     // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
358     // integer shift operations, just like ADD/SUB_PARTS.  The operation
359     // ordering is:
360     //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
361     SHL_PARTS, SRA_PARTS, SRL_PARTS,
362
363     // Conversion operators.  These are all single input single output
364     // operations.  For all of these, the result type must be strictly
365     // wider or narrower (depending on the operation) than the source
366     // type.
367
368     // SIGN_EXTEND - Used for integer types, replicating the sign bit
369     // into new bits.
370     SIGN_EXTEND,
371
372     // ZERO_EXTEND - Used for integer types, zeroing the new bits.
373     ZERO_EXTEND,
374
375     // ANY_EXTEND - Used for integer types.  The high bits are undefined.
376     ANY_EXTEND,
377     
378     // TRUNCATE - Completely drop the high bits.
379     TRUNCATE,
380
381     // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
382     // depends on the first letter) to floating point.
383     SINT_TO_FP,
384     UINT_TO_FP,
385
386     // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
387     // sign extend a small value in a large integer register (e.g. sign
388     // extending the low 8 bits of a 32-bit register to fill the top 24 bits
389     // with the 7th bit).  The size of the smaller type is indicated by the 1th
390     // operand, a ValueType node.
391     SIGN_EXTEND_INREG,
392
393     /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
394     /// integer.
395     FP_TO_SINT,
396     FP_TO_UINT,
397
398     /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
399     /// down to the precision of the destination VT.  TRUNC is a flag, which is
400     /// always an integer that is zero or one.  If TRUNC is 0, this is a
401     /// normal rounding, if it is 1, this FP_ROUND is known to not change the
402     /// value of Y.
403     ///
404     /// The TRUNC = 1 case is used in cases where we know that the value will
405     /// not be modified by the node, because Y is not using any of the extra
406     /// precision of source type.  This allows certain transformations like
407     /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for 
408     /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
409     FP_ROUND,
410     
411     // FLT_ROUNDS_ - Returns current rounding mode:
412     // -1 Undefined
413     //  0 Round to 0
414     //  1 Round to nearest
415     //  2 Round to +inf
416     //  3 Round to -inf
417     FLT_ROUNDS_,
418
419     /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
420     /// rounds it to a floating point value.  It then promotes it and returns it
421     /// in a register of the same size.  This operation effectively just
422     /// discards excess precision.  The type to round down to is specified by
423     /// the VT operand, a VTSDNode.
424     FP_ROUND_INREG,
425
426     /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
427     FP_EXTEND,
428
429     // BIT_CONVERT - Theis operator converts between integer and FP values, as
430     // if one was stored to memory as integer and the other was loaded from the
431     // same address (or equivalently for vector format conversions, etc).  The 
432     // source and result are required to have the same bit size (e.g. 
433     // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp 
434     // conversions, but that is a noop, deleted by getNode().
435     BIT_CONVERT,
436     
437     // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
438     // negation, absolute value, square root, sine and cosine, powi, and pow
439     // operations.
440     FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
441     
442     // LOAD and STORE have token chains as their first operand, then the same
443     // operands as an LLVM load/store instruction, then an offset node that
444     // is added / subtracted from the base pointer to form the address (for
445     // indexed memory ops).
446     LOAD, STORE,
447
448     // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
449     // to a specified boundary.  This node always has two return values: a new
450     // stack pointer value and a chain. The first operand is the token chain,
451     // the second is the number of bytes to allocate, and the third is the
452     // alignment boundary.  The size is guaranteed to be a multiple of the stack
453     // alignment, and the alignment is guaranteed to be bigger than the stack
454     // alignment (if required) or 0 to get standard stack alignment.
455     DYNAMIC_STACKALLOC,
456
457     // Control flow instructions.  These all have token chains.
458
459     // BR - Unconditional branch.  The first operand is the chain
460     // operand, the second is the MBB to branch to.
461     BR,
462
463     // BRIND - Indirect branch.  The first operand is the chain, the second
464     // is the value to branch to, which must be of the same type as the target's
465     // pointer type.
466     BRIND,
467
468     // BR_JT - Jumptable branch. The first operand is the chain, the second
469     // is the jumptable index, the last one is the jumptable entry index.
470     BR_JT,
471     
472     // BRCOND - Conditional branch.  The first operand is the chain,
473     // the second is the condition, the third is the block to branch
474     // to if the condition is true.
475     BRCOND,
476
477     // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
478     // that the condition is represented as condition code, and two nodes to
479     // compare, rather than as a combined SetCC node.  The operands in order are
480     // chain, cc, lhs, rhs, block to branch to if condition is true.
481     BR_CC,
482     
483     // RET - Return from function.  The first operand is the chain,
484     // and any subsequent operands are pairs of return value and return value
485     // signness for the function.  This operation can have variable number of
486     // operands.
487     RET,
488
489     // INLINEASM - Represents an inline asm block.  This node always has two
490     // return values: a chain and a flag result.  The inputs are as follows:
491     //   Operand #0   : Input chain.
492     //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
493     //   Operand #2n+2: A RegisterNode.
494     //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
495     //   Operand #last: Optional, an incoming flag.
496     INLINEASM,
497     
498     // LABEL - Represents a label in mid basic block used to track
499     // locations needed for debug and exception handling tables.  This node
500     // returns a chain.
501     //   Operand #0 : input chain.
502     //   Operand #1 : module unique number use to identify the label.
503     //   Operand #2 : 0 indicates a debug label (e.g. stoppoint), 1 indicates
504     //                a EH label, 2 indicates unknown label type.
505     LABEL,
506
507     // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
508     // local variable declarations for debugging information. First operand is
509     // a chain, while the next two operands are first two arguments (address
510     // and variable) of a llvm.dbg.declare instruction.
511     DECLARE,
512     
513     // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
514     // value, the same type as the pointer type for the system, and an output
515     // chain.
516     STACKSAVE,
517     
518     // STACKRESTORE has two operands, an input chain and a pointer to restore to
519     // it returns an output chain.
520     STACKRESTORE,
521     
522     // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain. The following
523     // correspond to the operands of the LLVM intrinsic functions and the last
524     // one is AlwaysInline.  The only result is a token chain.  The alignment
525     // argument is guaranteed to be a Constant node.
526     MEMSET,
527     MEMMOVE,
528     MEMCPY,
529
530     // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
531     // a call sequence, and carry arbitrary information that target might want
532     // to know.  The first operand is a chain, the rest are specified by the
533     // target and not touched by the DAG optimizers.
534     // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
535     CALLSEQ_START,  // Beginning of a call sequence
536     CALLSEQ_END,    // End of a call sequence
537     
538     // VAARG - VAARG has three operands: an input chain, a pointer, and a 
539     // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
540     VAARG,
541     
542     // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
543     // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
544     // source.
545     VACOPY,
546     
547     // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
548     // pointer, and a SRCVALUE.
549     VAEND, VASTART,
550
551     // SRCVALUE - This is a node type that holds a Value* that is used to
552     // make reference to a value in the LLVM IR.
553     SRCVALUE,
554
555     // MEMOPERAND - This is a node that contains a MemOperand which records
556     // information about a memory reference. This is used to make AliasAnalysis
557     // queries from the backend.
558     MEMOPERAND,
559
560     // PCMARKER - This corresponds to the pcmarker intrinsic.
561     PCMARKER,
562
563     // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
564     // The only operand is a chain and a value and a chain are produced.  The
565     // value is the contents of the architecture specific cycle counter like 
566     // register (or other high accuracy low latency clock source)
567     READCYCLECOUNTER,
568
569     // HANDLENODE node - Used as a handle for various purposes.
570     HANDLENODE,
571
572     // LOCATION - This node is used to represent a source location for debug
573     // info.  It takes token chain as input, then a line number, then a column
574     // number, then a filename, then a working dir.  It produces a token chain
575     // as output.
576     LOCATION,
577     
578     // DEBUG_LOC - This node is used to represent source line information
579     // embedded in the code.  It takes a token chain as input, then a line
580     // number, then a column then a file id (provided by MachineModuleInfo.) It
581     // produces a token chain as output.
582     DEBUG_LOC,
583
584     // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
585     // It takes as input a token chain, the pointer to the trampoline,
586     // the pointer to the nested function, the pointer to pass for the
587     // 'nest' parameter, a SRCVALUE for the trampoline and another for
588     // the nested function (allowing targets to access the original
589     // Function*).  It produces the result of the intrinsic and a token
590     // chain as output.
591     TRAMPOLINE,
592
593     // TRAP - Trapping instruction
594     TRAP,
595
596     // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
597     // their first operand. The other operands are the address to prefetch,
598     // read / write specifier, and locality specifier.
599     PREFETCH,
600
601     // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load, 
602     //                       store-store, device)
603     // This corresponds to the memory.barrier intrinsic.
604     // it takes an input chain, 4 operands to specify the type of barrier, an
605     // operand specifying if the barrier applies to device and uncached memory
606     // and produces an output chain.
607     MEMBARRIER,
608
609     // Val, OUTCHAIN = ATOMIC_LCS(INCHAIN, ptr, cmp, swap)
610     // this corresponds to the atomic.lcs intrinsic.
611     // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
612     // the return is always the original value in *ptr
613     ATOMIC_LCS,
614
615     // Val, OUTCHAIN = ATOMIC_LAS(INCHAIN, ptr, amt)
616     // this corresponds to the atomic.las intrinsic.
617     // *ptr + amt is stored to *ptr atomically.
618     // the return is always the original value in *ptr
619     ATOMIC_LAS,
620
621     // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
622     // this corresponds to the atomic.swap intrinsic.
623     // amt is stored to *ptr atomically.
624     // the return is always the original value in *ptr
625     ATOMIC_SWAP,
626
627     // BUILTIN_OP_END - This must be the last enum value in this list.
628     BUILTIN_OP_END
629   };
630
631   /// Node predicates
632
633   /// isBuildVectorAllOnes - Return true if the specified node is a
634   /// BUILD_VECTOR where all of the elements are ~0 or undef.
635   bool isBuildVectorAllOnes(const SDNode *N);
636
637   /// isBuildVectorAllZeros - Return true if the specified node is a
638   /// BUILD_VECTOR where all of the elements are 0 or undef.
639   bool isBuildVectorAllZeros(const SDNode *N);
640
641   /// isScalarToVector - Return true if the specified node is a
642   /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
643   /// element is not an undef.
644   bool isScalarToVector(const SDNode *N);
645
646   /// isDebugLabel - Return true if the specified node represents a debug
647   /// label (i.e. ISD::LABEL or TargetInstrInfo::LABEL node and third operand
648   /// is 0).
649   bool isDebugLabel(const SDNode *N);
650   
651   //===--------------------------------------------------------------------===//
652   /// MemIndexedMode enum - This enum defines the load / store indexed 
653   /// addressing modes.
654   ///
655   /// UNINDEXED    "Normal" load / store. The effective address is already
656   ///              computed and is available in the base pointer. The offset
657   ///              operand is always undefined. In addition to producing a
658   ///              chain, an unindexed load produces one value (result of the
659   ///              load); an unindexed store does not produces a value.
660   ///
661   /// PRE_INC      Similar to the unindexed mode where the effective address is
662   /// PRE_DEC      the value of the base pointer add / subtract the offset.
663   ///              It considers the computation as being folded into the load /
664   ///              store operation (i.e. the load / store does the address
665   ///              computation as well as performing the memory transaction).
666   ///              The base operand is always undefined. In addition to
667   ///              producing a chain, pre-indexed load produces two values
668   ///              (result of the load and the result of the address
669   ///              computation); a pre-indexed store produces one value (result
670   ///              of the address computation).
671   ///
672   /// POST_INC     The effective address is the value of the base pointer. The
673   /// POST_DEC     value of the offset operand is then added to / subtracted
674   ///              from the base after memory transaction. In addition to
675   ///              producing a chain, post-indexed load produces two values
676   ///              (the result of the load and the result of the base +/- offset
677   ///              computation); a post-indexed store produces one value (the
678   ///              the result of the base +/- offset computation).
679   ///
680   enum MemIndexedMode {
681     UNINDEXED = 0,
682     PRE_INC,
683     PRE_DEC,
684     POST_INC,
685     POST_DEC,
686     LAST_INDEXED_MODE
687   };
688
689   //===--------------------------------------------------------------------===//
690   /// LoadExtType enum - This enum defines the three variants of LOADEXT
691   /// (load with extension).
692   ///
693   /// SEXTLOAD loads the integer operand and sign extends it to a larger
694   ///          integer result type.
695   /// ZEXTLOAD loads the integer operand and zero extends it to a larger
696   ///          integer result type.
697   /// EXTLOAD  is used for three things: floating point extending loads, 
698   ///          integer extending loads [the top bits are undefined], and vector
699   ///          extending loads [load into low elt].
700   ///
701   enum LoadExtType {
702     NON_EXTLOAD = 0,
703     EXTLOAD,
704     SEXTLOAD,
705     ZEXTLOAD,
706     LAST_LOADX_TYPE
707   };
708
709   //===--------------------------------------------------------------------===//
710   /// ISD::CondCode enum - These are ordered carefully to make the bitfields
711   /// below work out, when considering SETFALSE (something that never exists
712   /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
713   /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
714   /// to.  If the "N" column is 1, the result of the comparison is undefined if
715   /// the input is a NAN.
716   ///
717   /// All of these (except for the 'always folded ops') should be handled for
718   /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
719   /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
720   ///
721   /// Note that these are laid out in a specific order to allow bit-twiddling
722   /// to transform conditions.
723   enum CondCode {
724     // Opcode          N U L G E       Intuitive operation
725     SETFALSE,      //    0 0 0 0       Always false (always folded)
726     SETOEQ,        //    0 0 0 1       True if ordered and equal
727     SETOGT,        //    0 0 1 0       True if ordered and greater than
728     SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
729     SETOLT,        //    0 1 0 0       True if ordered and less than
730     SETOLE,        //    0 1 0 1       True if ordered and less than or equal
731     SETONE,        //    0 1 1 0       True if ordered and operands are unequal
732     SETO,          //    0 1 1 1       True if ordered (no nans)
733     SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
734     SETUEQ,        //    1 0 0 1       True if unordered or equal
735     SETUGT,        //    1 0 1 0       True if unordered or greater than
736     SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
737     SETULT,        //    1 1 0 0       True if unordered or less than
738     SETULE,        //    1 1 0 1       True if unordered, less than, or equal
739     SETUNE,        //    1 1 1 0       True if unordered or not equal
740     SETTRUE,       //    1 1 1 1       Always true (always folded)
741     // Don't care operations: undefined if the input is a nan.
742     SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
743     SETEQ,         //  1 X 0 0 1       True if equal
744     SETGT,         //  1 X 0 1 0       True if greater than
745     SETGE,         //  1 X 0 1 1       True if greater than or equal
746     SETLT,         //  1 X 1 0 0       True if less than
747     SETLE,         //  1 X 1 0 1       True if less than or equal
748     SETNE,         //  1 X 1 1 0       True if not equal
749     SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
750
751     SETCC_INVALID       // Marker value.
752   };
753
754   /// isSignedIntSetCC - Return true if this is a setcc instruction that
755   /// performs a signed comparison when used with integer operands.
756   inline bool isSignedIntSetCC(CondCode Code) {
757     return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
758   }
759
760   /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
761   /// performs an unsigned comparison when used with integer operands.
762   inline bool isUnsignedIntSetCC(CondCode Code) {
763     return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
764   }
765
766   /// isTrueWhenEqual - Return true if the specified condition returns true if
767   /// the two operands to the condition are equal.  Note that if one of the two
768   /// operands is a NaN, this value is meaningless.
769   inline bool isTrueWhenEqual(CondCode Cond) {
770     return ((int)Cond & 1) != 0;
771   }
772
773   /// getUnorderedFlavor - This function returns 0 if the condition is always
774   /// false if an operand is a NaN, 1 if the condition is always true if the
775   /// operand is a NaN, and 2 if the condition is undefined if the operand is a
776   /// NaN.
777   inline unsigned getUnorderedFlavor(CondCode Cond) {
778     return ((int)Cond >> 3) & 3;
779   }
780
781   /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
782   /// 'op' is a valid SetCC operation.
783   CondCode getSetCCInverse(CondCode Operation, bool isInteger);
784
785   /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
786   /// when given the operation for (X op Y).
787   CondCode getSetCCSwappedOperands(CondCode Operation);
788
789   /// getSetCCOrOperation - Return the result of a logical OR between different
790   /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
791   /// function returns SETCC_INVALID if it is not possible to represent the
792   /// resultant comparison.
793   CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
794
795   /// getSetCCAndOperation - Return the result of a logical AND between
796   /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
797   /// function returns SETCC_INVALID if it is not possible to represent the
798   /// resultant comparison.
799   CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
800 }  // end llvm::ISD namespace
801
802
803 //===----------------------------------------------------------------------===//
804 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
805 /// values as the result of a computation.  Many nodes return multiple values,
806 /// from loads (which define a token and a return value) to ADDC (which returns
807 /// a result and a carry value), to calls (which may return an arbitrary number
808 /// of values).
809 ///
810 /// As such, each use of a SelectionDAG computation must indicate the node that
811 /// computes it as well as which return value to use from that node.  This pair
812 /// of information is represented with the SDOperand value type.
813 ///
814 class SDOperand {
815 public:
816   SDNode *Val;        // The node defining the value we are using.
817   unsigned ResNo;     // Which return value of the node we are using.
818
819   SDOperand() : Val(0), ResNo(0) {}
820   SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
821
822   bool operator==(const SDOperand &O) const {
823     return Val == O.Val && ResNo == O.ResNo;
824   }
825   bool operator!=(const SDOperand &O) const {
826     return !operator==(O);
827   }
828   bool operator<(const SDOperand &O) const {
829     return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
830   }
831
832   SDOperand getValue(unsigned R) const {
833     return SDOperand(Val, R);
834   }
835
836   // isOperandOf - Return true if this node is an operand of N.
837   bool isOperandOf(SDNode *N) const;
838
839   /// getValueType - Return the ValueType of the referenced return value.
840   ///
841   inline MVT::ValueType getValueType() const;
842
843   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType()).
844   ///
845   unsigned getValueSizeInBits() const {
846     return MVT::getSizeInBits(getValueType());
847   }
848
849   // Forwarding methods - These forward to the corresponding methods in SDNode.
850   inline unsigned getOpcode() const;
851   inline unsigned getNumOperands() const;
852   inline const SDOperand &getOperand(unsigned i) const;
853   inline uint64_t getConstantOperandVal(unsigned i) const;
854   inline bool isTargetOpcode() const;
855   inline unsigned getTargetOpcode() const;
856
857   
858   /// reachesChainWithoutSideEffects - Return true if this operand (which must
859   /// be a chain) reaches the specified operand without crossing any 
860   /// side-effecting instructions.  In practice, this looks through token
861   /// factors and non-volatile loads.  In order to remain efficient, this only
862   /// looks a couple of nodes in, it does not do an exhaustive search.
863   bool reachesChainWithoutSideEffects(SDOperand Dest, unsigned Depth = 2) const;
864   
865   /// hasOneUse - Return true if there is exactly one operation using this
866   /// result value of the defining operator.
867   inline bool hasOneUse() const;
868
869   /// use_empty - Return true if there are no operations using this
870   /// result value of the defining operator.
871   inline bool use_empty() const;
872 };
873
874
875 template<> struct DenseMapInfo<SDOperand> {
876   static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); }
877   static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);}
878   static unsigned getHashValue(const SDOperand &Val) {
879     return ((unsigned)((uintptr_t)Val.Val >> 4) ^
880             (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo;
881   }
882   static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
883     return LHS == RHS;
884   }
885   static bool isPod() { return true; }
886 };
887
888 /// simplify_type specializations - Allow casting operators to work directly on
889 /// SDOperands as if they were SDNode*'s.
890 template<> struct simplify_type<SDOperand> {
891   typedef SDNode* SimpleType;
892   static SimpleType getSimplifiedValue(const SDOperand &Val) {
893     return static_cast<SimpleType>(Val.Val);
894   }
895 };
896 template<> struct simplify_type<const SDOperand> {
897   typedef SDNode* SimpleType;
898   static SimpleType getSimplifiedValue(const SDOperand &Val) {
899     return static_cast<SimpleType>(Val.Val);
900   }
901 };
902
903
904 /// SDNode - Represents one node in the SelectionDAG.
905 ///
906 class SDNode : public FoldingSetNode {
907   /// NodeType - The operation that this node performs.
908   ///
909   unsigned short NodeType;
910   
911   /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
912   /// then they will be delete[]'d when the node is destroyed.
913   bool OperandsNeedDelete : 1;
914
915   /// NodeId - Unique id per SDNode in the DAG.
916   int NodeId;
917
918   /// OperandList - The values that are used by this operation.
919   ///
920   SDOperand *OperandList;
921   
922   /// ValueList - The types of the values this node defines.  SDNode's may
923   /// define multiple values simultaneously.
924   const MVT::ValueType *ValueList;
925
926   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
927   unsigned short NumOperands, NumValues;
928   
929   /// Prev/Next pointers - These pointers form the linked list of of the
930   /// AllNodes list in the current DAG.
931   SDNode *Prev, *Next;
932   friend struct ilist_traits<SDNode>;
933
934   /// Uses - These are all of the SDNode's that use a value produced by this
935   /// node.
936   SmallVector<SDNode*,3> Uses;
937   
938   // Out-of-line virtual method to give class a home.
939   virtual void ANCHOR();
940 public:
941   virtual ~SDNode() {
942     assert(NumOperands == 0 && "Operand list not cleared before deletion");
943     NodeType = ISD::DELETED_NODE;
944   }
945   
946   //===--------------------------------------------------------------------===//
947   //  Accessors
948   //
949   unsigned getOpcode()  const { return NodeType; }
950   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
951   unsigned getTargetOpcode() const {
952     assert(isTargetOpcode() && "Not a target opcode!");
953     return NodeType - ISD::BUILTIN_OP_END;
954   }
955
956   size_t use_size() const { return Uses.size(); }
957   bool use_empty() const { return Uses.empty(); }
958   bool hasOneUse() const { return Uses.size() == 1; }
959
960   /// getNodeId - Return the unique node id.
961   ///
962   int getNodeId() const { return NodeId; }
963
964   /// setNodeId - Set unique node id.
965   void setNodeId(int Id) { NodeId = Id; }
966
967   typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
968   use_iterator use_begin() const { return Uses.begin(); }
969   use_iterator use_end() const { return Uses.end(); }
970
971   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
972   /// indicated value.  This method ignores uses of other values defined by this
973   /// operation.
974   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
975
976   /// hasAnyUseOfValue - Return true if there are any use of the indicated
977   /// value. This method ignores uses of other values defined by this operation.
978   bool hasAnyUseOfValue(unsigned Value) const;
979
980   /// isOnlyUseOf - Return true if this node is the only use of N.
981   ///
982   bool isOnlyUseOf(SDNode *N) const;
983
984   /// isOperandOf - Return true if this node is an operand of N.
985   ///
986   bool isOperandOf(SDNode *N) const;
987
988   /// isPredecessorOf - Return true if this node is a predecessor of N. This
989   /// node is either an operand of N or it can be reached by recursively
990   /// traversing up the operands.
991   /// NOTE: this is an expensive method. Use it carefully.
992   bool isPredecessorOf(SDNode *N) const;
993
994   /// getNumOperands - Return the number of values used by this operation.
995   ///
996   unsigned getNumOperands() const { return NumOperands; }
997
998   /// getConstantOperandVal - Helper method returns the integer value of a 
999   /// ConstantSDNode operand.
1000   uint64_t getConstantOperandVal(unsigned Num) const;
1001
1002   const SDOperand &getOperand(unsigned Num) const {
1003     assert(Num < NumOperands && "Invalid child # of SDNode!");
1004     return OperandList[Num];
1005   }
1006
1007   typedef const SDOperand* op_iterator;
1008   op_iterator op_begin() const { return OperandList; }
1009   op_iterator op_end() const { return OperandList+NumOperands; }
1010
1011
1012   SDVTList getVTList() const {
1013     SDVTList X = { ValueList, NumValues };
1014     return X;
1015   };
1016   
1017   /// getNumValues - Return the number of values defined/returned by this
1018   /// operator.
1019   ///
1020   unsigned getNumValues() const { return NumValues; }
1021
1022   /// getValueType - Return the type of a specified result.
1023   ///
1024   MVT::ValueType getValueType(unsigned ResNo) const {
1025     assert(ResNo < NumValues && "Illegal result number!");
1026     return ValueList[ResNo];
1027   }
1028
1029   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1030   ///
1031   unsigned getValueSizeInBits(unsigned ResNo) const {
1032     return MVT::getSizeInBits(getValueType(ResNo));
1033   }
1034
1035   typedef const MVT::ValueType* value_iterator;
1036   value_iterator value_begin() const { return ValueList; }
1037   value_iterator value_end() const { return ValueList+NumValues; }
1038
1039   /// getOperationName - Return the opcode of this operation for printing.
1040   ///
1041   std::string getOperationName(const SelectionDAG *G = 0) const;
1042   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1043   void dump() const;
1044   void dump(const SelectionDAG *G) const;
1045
1046   static bool classof(const SDNode *) { return true; }
1047
1048   /// Profile - Gather unique data for the node.
1049   ///
1050   void Profile(FoldingSetNodeID &ID);
1051
1052 protected:
1053   friend class SelectionDAG;
1054   
1055   /// getValueTypeList - Return a pointer to the specified value type.
1056   ///
1057   static const MVT::ValueType *getValueTypeList(MVT::ValueType VT);
1058   static SDVTList getSDVTList(MVT::ValueType VT) {
1059     SDVTList Ret = { getValueTypeList(VT), 1 };
1060     return Ret;
1061   }
1062
1063   SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
1064     : NodeType(Opc), NodeId(-1) {
1065     OperandsNeedDelete = true;
1066     NumOperands = NumOps;
1067     OperandList = NumOps ? new SDOperand[NumOperands] : 0;
1068     
1069     for (unsigned i = 0; i != NumOps; ++i) {
1070       OperandList[i] = Ops[i];
1071       Ops[i].Val->Uses.push_back(this);
1072     }
1073     
1074     ValueList = VTs.VTs;
1075     NumValues = VTs.NumVTs;
1076     Prev = 0; Next = 0;
1077   }
1078   SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
1079     OperandsNeedDelete = false;  // Operands set with InitOperands.
1080     NumOperands = 0;
1081     OperandList = 0;
1082     
1083     ValueList = VTs.VTs;
1084     NumValues = VTs.NumVTs;
1085     Prev = 0; Next = 0;
1086   }
1087   
1088   /// InitOperands - Initialize the operands list of this node with the
1089   /// specified values, which are part of the node (thus they don't need to be
1090   /// copied in or allocated).
1091   void InitOperands(SDOperand *Ops, unsigned NumOps) {
1092     assert(OperandList == 0 && "Operands already set!");
1093     NumOperands = NumOps;
1094     OperandList = Ops;
1095     
1096     for (unsigned i = 0; i != NumOps; ++i)
1097       Ops[i].Val->Uses.push_back(this);
1098   }
1099   
1100   /// MorphNodeTo - This frees the operands of the current node, resets the
1101   /// opcode, types, and operands to the specified value.  This should only be
1102   /// used by the SelectionDAG class.
1103   void MorphNodeTo(unsigned Opc, SDVTList L,
1104                    const SDOperand *Ops, unsigned NumOps);
1105   
1106   void addUser(SDNode *User) {
1107     Uses.push_back(User);
1108   }
1109   void removeUser(SDNode *User) {
1110     // Remove this user from the operand's use list.
1111     for (unsigned i = Uses.size(); ; --i) {
1112       assert(i != 0 && "Didn't find user!");
1113       if (Uses[i-1] == User) {
1114         Uses[i-1] = Uses.back();
1115         Uses.pop_back();
1116         return;
1117       }
1118     }
1119   }
1120 };
1121
1122
1123 // Define inline functions from the SDOperand class.
1124
1125 inline unsigned SDOperand::getOpcode() const {
1126   return Val->getOpcode();
1127 }
1128 inline MVT::ValueType SDOperand::getValueType() const {
1129   return Val->getValueType(ResNo);
1130 }
1131 inline unsigned SDOperand::getNumOperands() const {
1132   return Val->getNumOperands();
1133 }
1134 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1135   return Val->getOperand(i);
1136 }
1137 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1138   return Val->getConstantOperandVal(i);
1139 }
1140 inline bool SDOperand::isTargetOpcode() const {
1141   return Val->isTargetOpcode();
1142 }
1143 inline unsigned SDOperand::getTargetOpcode() const {
1144   return Val->getTargetOpcode();
1145 }
1146 inline bool SDOperand::hasOneUse() const {
1147   return Val->hasNUsesOfValue(1, ResNo);
1148 }
1149 inline bool SDOperand::use_empty() const {
1150   return !Val->hasAnyUseOfValue(ResNo);
1151 }
1152
1153 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
1154 /// to allow co-allocation of node operands with the node itself.
1155 class UnarySDNode : public SDNode {
1156   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1157   SDOperand Op;
1158 public:
1159   UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1160     : SDNode(Opc, VTs), Op(X) {
1161     InitOperands(&Op, 1);
1162   }
1163 };
1164
1165 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
1166 /// to allow co-allocation of node operands with the node itself.
1167 class BinarySDNode : public SDNode {
1168   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1169   SDOperand Ops[2];
1170 public:
1171   BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1172     : SDNode(Opc, VTs) {
1173     Ops[0] = X;
1174     Ops[1] = Y;
1175     InitOperands(Ops, 2);
1176   }
1177 };
1178
1179 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1180 /// to allow co-allocation of node operands with the node itself.
1181 class TernarySDNode : public SDNode {
1182   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1183   SDOperand Ops[3];
1184 public:
1185   TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1186                 SDOperand Z)
1187     : SDNode(Opc, VTs) {
1188     Ops[0] = X;
1189     Ops[1] = Y;
1190     Ops[2] = Z;
1191     InitOperands(Ops, 3);
1192   }
1193 };
1194
1195
1196 /// HandleSDNode - This class is used to form a handle around another node that
1197 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1198 /// operand.  This node should be directly created by end-users and not added to
1199 /// the AllNodes list.
1200 class HandleSDNode : public SDNode {
1201   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1202   SDOperand Op;
1203 public:
1204   explicit HandleSDNode(SDOperand X)
1205     : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1206     InitOperands(&Op, 1);
1207   }
1208   ~HandleSDNode();  
1209   SDOperand getValue() const { return Op; }
1210 };
1211
1212 class AtomicSDNode : public SDNode {
1213   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1214   SDOperand Ops[4];
1215   MVT::ValueType OrigVT;
1216 public:
1217   AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, 
1218                SDOperand Cmp, SDOperand Swp, MVT::ValueType VT)
1219     : SDNode(Opc, VTL) {
1220     Ops[0] = Chain;
1221     Ops[1] = Ptr;
1222     Ops[2] = Swp;
1223     Ops[3] = Cmp;
1224     InitOperands(Ops, 4);
1225     OrigVT=VT;
1226   }
1227   AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, 
1228                SDOperand Val, MVT::ValueType VT)
1229     : SDNode(Opc, VTL) {
1230     Ops[0] = Chain;
1231     Ops[1] = Ptr;
1232     Ops[2] = Val;
1233     InitOperands(Ops, 3);
1234     OrigVT=VT;
1235   }
1236   MVT::ValueType getVT() const { return OrigVT; }
1237   bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_LCS; }
1238 };
1239
1240 class StringSDNode : public SDNode {
1241   std::string Value;
1242   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1243 protected:
1244   friend class SelectionDAG;
1245   explicit StringSDNode(const std::string &val)
1246     : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1247   }
1248 public:
1249   const std::string &getValue() const { return Value; }
1250   static bool classof(const StringSDNode *) { return true; }
1251   static bool classof(const SDNode *N) {
1252     return N->getOpcode() == ISD::STRING;
1253   }
1254 };  
1255
1256 class ConstantSDNode : public SDNode {
1257   APInt Value;
1258   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1259 protected:
1260   friend class SelectionDAG;
1261   ConstantSDNode(bool isTarget, const APInt &val, MVT::ValueType VT)
1262     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1263       Value(val) {
1264   }
1265 public:
1266
1267   const APInt &getAPIntValue() const { return Value; }
1268   uint64_t getValue() const { return Value.getZExtValue(); }
1269
1270   int64_t getSignExtended() const {
1271     unsigned Bits = MVT::getSizeInBits(getValueType(0));
1272     return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1273   }
1274
1275   bool isNullValue() const { return Value == 0; }
1276   bool isAllOnesValue() const {
1277     return Value == MVT::getIntVTBitMask(getValueType(0));
1278   }
1279
1280   static bool classof(const ConstantSDNode *) { return true; }
1281   static bool classof(const SDNode *N) {
1282     return N->getOpcode() == ISD::Constant ||
1283            N->getOpcode() == ISD::TargetConstant;
1284   }
1285 };
1286
1287 class ConstantFPSDNode : public SDNode {
1288   APFloat Value;
1289   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1290 protected:
1291   friend class SelectionDAG;
1292   ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT)
1293     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1294              getSDVTList(VT)), Value(val) {
1295   }
1296 public:
1297
1298   const APFloat& getValueAPF() const { return Value; }
1299
1300   /// isExactlyValue - We don't rely on operator== working on double values, as
1301   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1302   /// As such, this method can be used to do an exact bit-for-bit comparison of
1303   /// two floating point values.
1304
1305   /// We leave the version with the double argument here because it's just so
1306   /// convenient to write "2.0" and the like.  Without this function we'd 
1307   /// have to duplicate its logic everywhere it's called.
1308   bool isExactlyValue(double V) const { 
1309     APFloat Tmp(V);
1310     Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1311     return isExactlyValue(Tmp);
1312   }
1313   bool isExactlyValue(const APFloat& V) const;
1314
1315   bool isValueValidForType(MVT::ValueType VT, const APFloat& Val);
1316
1317   static bool classof(const ConstantFPSDNode *) { return true; }
1318   static bool classof(const SDNode *N) {
1319     return N->getOpcode() == ISD::ConstantFP || 
1320            N->getOpcode() == ISD::TargetConstantFP;
1321   }
1322 };
1323
1324 class GlobalAddressSDNode : public SDNode {
1325   GlobalValue *TheGlobal;
1326   int Offset;
1327   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1328 protected:
1329   friend class SelectionDAG;
1330   GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1331                       int o = 0);
1332 public:
1333
1334   GlobalValue *getGlobal() const { return TheGlobal; }
1335   int getOffset() const { return Offset; }
1336
1337   static bool classof(const GlobalAddressSDNode *) { return true; }
1338   static bool classof(const SDNode *N) {
1339     return N->getOpcode() == ISD::GlobalAddress ||
1340            N->getOpcode() == ISD::TargetGlobalAddress ||
1341            N->getOpcode() == ISD::GlobalTLSAddress ||
1342            N->getOpcode() == ISD::TargetGlobalTLSAddress;
1343   }
1344 };
1345
1346 class FrameIndexSDNode : public SDNode {
1347   int FI;
1348   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1349 protected:
1350   friend class SelectionDAG;
1351   FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1352     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1353       FI(fi) {
1354   }
1355 public:
1356
1357   int getIndex() const { return FI; }
1358
1359   static bool classof(const FrameIndexSDNode *) { return true; }
1360   static bool classof(const SDNode *N) {
1361     return N->getOpcode() == ISD::FrameIndex ||
1362            N->getOpcode() == ISD::TargetFrameIndex;
1363   }
1364 };
1365
1366 class JumpTableSDNode : public SDNode {
1367   int JTI;
1368   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1369 protected:
1370   friend class SelectionDAG;
1371   JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1372     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1373       JTI(jti) {
1374   }
1375 public:
1376     
1377   int getIndex() const { return JTI; }
1378   
1379   static bool classof(const JumpTableSDNode *) { return true; }
1380   static bool classof(const SDNode *N) {
1381     return N->getOpcode() == ISD::JumpTable ||
1382            N->getOpcode() == ISD::TargetJumpTable;
1383   }
1384 };
1385
1386 class ConstantPoolSDNode : public SDNode {
1387   union {
1388     Constant *ConstVal;
1389     MachineConstantPoolValue *MachineCPVal;
1390   } Val;
1391   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1392   unsigned Alignment;
1393   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1394 protected:
1395   friend class SelectionDAG;
1396   ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1397                      int o=0)
1398     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1399              getSDVTList(VT)), Offset(o), Alignment(0) {
1400     assert((int)Offset >= 0 && "Offset is too large");
1401     Val.ConstVal = c;
1402   }
1403   ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1404                      unsigned Align)
1405     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1406              getSDVTList(VT)), Offset(o), Alignment(Align) {
1407     assert((int)Offset >= 0 && "Offset is too large");
1408     Val.ConstVal = c;
1409   }
1410   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1411                      MVT::ValueType VT, int o=0)
1412     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1413              getSDVTList(VT)), Offset(o), Alignment(0) {
1414     assert((int)Offset >= 0 && "Offset is too large");
1415     Val.MachineCPVal = v;
1416     Offset |= 1 << (sizeof(unsigned)*8-1);
1417   }
1418   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1419                      MVT::ValueType VT, int o, unsigned Align)
1420     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1421              getSDVTList(VT)), Offset(o), Alignment(Align) {
1422     assert((int)Offset >= 0 && "Offset is too large");
1423     Val.MachineCPVal = v;
1424     Offset |= 1 << (sizeof(unsigned)*8-1);
1425   }
1426 public:
1427
1428   bool isMachineConstantPoolEntry() const {
1429     return (int)Offset < 0;
1430   }
1431
1432   Constant *getConstVal() const {
1433     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1434     return Val.ConstVal;
1435   }
1436
1437   MachineConstantPoolValue *getMachineCPVal() const {
1438     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1439     return Val.MachineCPVal;
1440   }
1441
1442   int getOffset() const {
1443     return Offset & ~(1 << (sizeof(unsigned)*8-1));
1444   }
1445   
1446   // Return the alignment of this constant pool object, which is either 0 (for
1447   // default alignment) or log2 of the desired value.
1448   unsigned getAlignment() const { return Alignment; }
1449
1450   const Type *getType() const;
1451
1452   static bool classof(const ConstantPoolSDNode *) { return true; }
1453   static bool classof(const SDNode *N) {
1454     return N->getOpcode() == ISD::ConstantPool ||
1455            N->getOpcode() == ISD::TargetConstantPool;
1456   }
1457 };
1458
1459 class BasicBlockSDNode : public SDNode {
1460   MachineBasicBlock *MBB;
1461   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1462 protected:
1463   friend class SelectionDAG;
1464   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1465     : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1466   }
1467 public:
1468
1469   MachineBasicBlock *getBasicBlock() const { return MBB; }
1470
1471   static bool classof(const BasicBlockSDNode *) { return true; }
1472   static bool classof(const SDNode *N) {
1473     return N->getOpcode() == ISD::BasicBlock;
1474   }
1475 };
1476
1477 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1478 /// used when the SelectionDAG needs to make a simple reference to something
1479 /// in the LLVM IR representation.
1480 ///
1481 /// Note that this is not used for carrying alias information; that is done
1482 /// with MemOperandSDNode, which includes a Value which is required to be a
1483 /// pointer, and several other fields specific to memory references.
1484 ///
1485 class SrcValueSDNode : public SDNode {
1486   const Value *V;
1487   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1488 protected:
1489   friend class SelectionDAG;
1490   /// Create a SrcValue for a general value.
1491   explicit SrcValueSDNode(const Value *v)
1492     : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1493
1494 public:
1495   /// getValue - return the contained Value.
1496   const Value *getValue() const { return V; }
1497
1498   static bool classof(const SrcValueSDNode *) { return true; }
1499   static bool classof(const SDNode *N) {
1500     return N->getOpcode() == ISD::SRCVALUE;
1501   }
1502 };
1503
1504
1505 /// MemOperandSDNode - An SDNode that holds a MemOperand. This is
1506 /// used to represent a reference to memory after ISD::LOAD
1507 /// and ISD::STORE have been lowered.
1508 ///
1509 class MemOperandSDNode : public SDNode {
1510   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1511 protected:
1512   friend class SelectionDAG;
1513   /// Create a MemOperand node
1514   explicit MemOperandSDNode(const MemOperand &mo)
1515     : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1516
1517 public:
1518   /// MO - The contained MemOperand.
1519   const MemOperand MO;
1520
1521   static bool classof(const MemOperandSDNode *) { return true; }
1522   static bool classof(const SDNode *N) {
1523     return N->getOpcode() == ISD::MEMOPERAND;
1524   }
1525 };
1526
1527
1528 class RegisterSDNode : public SDNode {
1529   unsigned Reg;
1530   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1531 protected:
1532   friend class SelectionDAG;
1533   RegisterSDNode(unsigned reg, MVT::ValueType VT)
1534     : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1535   }
1536 public:
1537
1538   unsigned getReg() const { return Reg; }
1539
1540   static bool classof(const RegisterSDNode *) { return true; }
1541   static bool classof(const SDNode *N) {
1542     return N->getOpcode() == ISD::Register;
1543   }
1544 };
1545
1546 class ExternalSymbolSDNode : public SDNode {
1547   const char *Symbol;
1548   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1549 protected:
1550   friend class SelectionDAG;
1551   ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1552     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1553              getSDVTList(VT)), Symbol(Sym) {
1554   }
1555 public:
1556
1557   const char *getSymbol() const { return Symbol; }
1558
1559   static bool classof(const ExternalSymbolSDNode *) { return true; }
1560   static bool classof(const SDNode *N) {
1561     return N->getOpcode() == ISD::ExternalSymbol ||
1562            N->getOpcode() == ISD::TargetExternalSymbol;
1563   }
1564 };
1565
1566 class CondCodeSDNode : public SDNode {
1567   ISD::CondCode Condition;
1568   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1569 protected:
1570   friend class SelectionDAG;
1571   explicit CondCodeSDNode(ISD::CondCode Cond)
1572     : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1573   }
1574 public:
1575
1576   ISD::CondCode get() const { return Condition; }
1577
1578   static bool classof(const CondCodeSDNode *) { return true; }
1579   static bool classof(const SDNode *N) {
1580     return N->getOpcode() == ISD::CONDCODE;
1581   }
1582 };
1583
1584 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1585 /// to parameterize some operations.
1586 class VTSDNode : public SDNode {
1587   MVT::ValueType ValueType;
1588   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1589 protected:
1590   friend class SelectionDAG;
1591   explicit VTSDNode(MVT::ValueType VT)
1592     : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1593   }
1594 public:
1595
1596   MVT::ValueType getVT() const { return ValueType; }
1597
1598   static bool classof(const VTSDNode *) { return true; }
1599   static bool classof(const SDNode *N) {
1600     return N->getOpcode() == ISD::VALUETYPE;
1601   }
1602 };
1603
1604 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1605 ///
1606 class LSBaseSDNode : public SDNode {
1607 private:
1608   // AddrMode - unindexed, pre-indexed, post-indexed.
1609   ISD::MemIndexedMode AddrMode;
1610
1611   // MemoryVT - VT of in-memory value.
1612   MVT::ValueType MemoryVT;
1613
1614   //! SrcValue - Memory location for alias analysis.
1615   const Value *SrcValue;
1616
1617   //! SVOffset - Memory location offset.
1618   int SVOffset;
1619
1620   //! Alignment - Alignment of memory location in bytes.
1621   unsigned Alignment;
1622
1623   //! IsVolatile - True if the store is volatile.
1624   bool IsVolatile;
1625 protected:
1626   //! Operand array for load and store
1627   /*!
1628     \note Moving this array to the base class captures more
1629     common functionality shared between LoadSDNode and
1630     StoreSDNode
1631    */
1632   SDOperand Ops[4];
1633 public:
1634   LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned NumOperands,
1635                SDVTList VTs, ISD::MemIndexedMode AM, MVT::ValueType VT, 
1636                const Value *SV, int SVO, unsigned Align, bool Vol)
1637     : SDNode(NodeTy, VTs),
1638       AddrMode(AM), MemoryVT(VT),
1639       SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol) {
1640     for (unsigned i = 0; i != NumOperands; ++i)
1641       Ops[i] = Operands[i];
1642     InitOperands(Ops, NumOperands);
1643     assert(Align != 0 && "Loads and stores should have non-zero aligment");
1644     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1645            "Only indexed loads and stores have a non-undef offset operand");
1646   }
1647
1648   const SDOperand &getChain() const { return getOperand(0); }
1649   const SDOperand &getBasePtr() const {
1650     return getOperand(getOpcode() == ISD::LOAD ? 1 : 2);
1651   }
1652   const SDOperand &getOffset() const {
1653     return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1654   }
1655
1656   const Value *getSrcValue() const { return SrcValue; }
1657   int getSrcValueOffset() const { return SVOffset; }
1658   unsigned getAlignment() const { return Alignment; }
1659   MVT::ValueType getMemoryVT() const { return MemoryVT; }
1660   bool isVolatile() const { return IsVolatile; }
1661
1662   ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1663
1664   /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1665   bool isIndexed() const { return AddrMode != ISD::UNINDEXED; }
1666
1667   /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1668   bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; }
1669
1670   /// getMemOperand - Return a MemOperand object describing the memory
1671   /// reference performed by this load or store.
1672   MemOperand getMemOperand() const;
1673
1674   static bool classof(const LSBaseSDNode *N) { return true; }
1675   static bool classof(const SDNode *N) {
1676     return N->getOpcode() == ISD::LOAD ||
1677            N->getOpcode() == ISD::STORE;
1678   }
1679 };
1680
1681 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1682 ///
1683 class LoadSDNode : public LSBaseSDNode {
1684   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1685   
1686   // ExtType - non-ext, anyext, sext, zext.
1687   ISD::LoadExtType ExtType;
1688
1689 protected:
1690   friend class SelectionDAG;
1691   LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1692              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1693              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1694     : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
1695                    VTs, AM, LVT, SV, O, Align, Vol),
1696       ExtType(ETy) {}
1697 public:
1698
1699   ISD::LoadExtType getExtensionType() const { return ExtType; }
1700   const SDOperand &getBasePtr() const { return getOperand(1); }
1701   const SDOperand &getOffset() const { return getOperand(2); }
1702   
1703   static bool classof(const LoadSDNode *) { return true; }
1704   static bool classof(const SDNode *N) {
1705     return N->getOpcode() == ISD::LOAD;
1706   }
1707 };
1708
1709 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1710 ///
1711 class StoreSDNode : public LSBaseSDNode {
1712   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1713     
1714   // IsTruncStore - True if the op does a truncation before store.
1715   bool IsTruncStore;
1716 protected:
1717   friend class SelectionDAG;
1718   StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1719               ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1720               const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1721     : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
1722                    VTs, AM, SVT, SV, O, Align, Vol),
1723       IsTruncStore(isTrunc) {}
1724 public:
1725
1726   bool isTruncatingStore() const { return IsTruncStore; }
1727   const SDOperand &getValue() const { return getOperand(1); }
1728   const SDOperand &getBasePtr() const { return getOperand(2); }
1729   const SDOperand &getOffset() const { return getOperand(3); }
1730   
1731   static bool classof(const StoreSDNode *) { return true; }
1732   static bool classof(const SDNode *N) {
1733     return N->getOpcode() == ISD::STORE;
1734   }
1735 };
1736
1737
1738 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1739   SDNode *Node;
1740   unsigned Operand;
1741
1742   SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1743 public:
1744   bool operator==(const SDNodeIterator& x) const {
1745     return Operand == x.Operand;
1746   }
1747   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1748
1749   const SDNodeIterator &operator=(const SDNodeIterator &I) {
1750     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1751     Operand = I.Operand;
1752     return *this;
1753   }
1754
1755   pointer operator*() const {
1756     return Node->getOperand(Operand).Val;
1757   }
1758   pointer operator->() const { return operator*(); }
1759
1760   SDNodeIterator& operator++() {                // Preincrement
1761     ++Operand;
1762     return *this;
1763   }
1764   SDNodeIterator operator++(int) { // Postincrement
1765     SDNodeIterator tmp = *this; ++*this; return tmp;
1766   }
1767
1768   static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1769   static SDNodeIterator end  (SDNode *N) {
1770     return SDNodeIterator(N, N->getNumOperands());
1771   }
1772
1773   unsigned getOperand() const { return Operand; }
1774   const SDNode *getNode() const { return Node; }
1775 };
1776
1777 template <> struct GraphTraits<SDNode*> {
1778   typedef SDNode NodeType;
1779   typedef SDNodeIterator ChildIteratorType;
1780   static inline NodeType *getEntryNode(SDNode *N) { return N; }
1781   static inline ChildIteratorType child_begin(NodeType *N) {
1782     return SDNodeIterator::begin(N);
1783   }
1784   static inline ChildIteratorType child_end(NodeType *N) {
1785     return SDNodeIterator::end(N);
1786   }
1787 };
1788
1789 template<>
1790 struct ilist_traits<SDNode> {
1791   static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1792   static SDNode *getNext(const SDNode *N) { return N->Next; }
1793   
1794   static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1795   static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1796   
1797   static SDNode *createSentinel() {
1798     return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1799   }
1800   static void destroySentinel(SDNode *N) { delete N; }
1801   //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1802   
1803   
1804   void addNodeToList(SDNode *NTy) {}
1805   void removeNodeFromList(SDNode *NTy) {}
1806   void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1807                              const ilist_iterator<SDNode> &X,
1808                              const ilist_iterator<SDNode> &Y) {}
1809 };
1810
1811 namespace ISD {
1812   /// isNormalLoad - Returns true if the specified node is a non-extending
1813   /// and unindexed load.
1814   inline bool isNormalLoad(const SDNode *N) {
1815     if (N->getOpcode() != ISD::LOAD)
1816       return false;
1817     const LoadSDNode *Ld = cast<LoadSDNode>(N);
1818     return Ld->getExtensionType() == ISD::NON_EXTLOAD &&
1819       Ld->getAddressingMode() == ISD::UNINDEXED;
1820   }
1821
1822   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1823   /// load.
1824   inline bool isNON_EXTLoad(const SDNode *N) {
1825     return N->getOpcode() == ISD::LOAD &&
1826       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1827   }
1828
1829   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1830   ///
1831   inline bool isEXTLoad(const SDNode *N) {
1832     return N->getOpcode() == ISD::LOAD &&
1833       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1834   }
1835
1836   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1837   ///
1838   inline bool isSEXTLoad(const SDNode *N) {
1839     return N->getOpcode() == ISD::LOAD &&
1840       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1841   }
1842
1843   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1844   ///
1845   inline bool isZEXTLoad(const SDNode *N) {
1846     return N->getOpcode() == ISD::LOAD &&
1847       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1848   }
1849
1850   /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1851   ///
1852   inline bool isUNINDEXEDLoad(const SDNode *N) {
1853     return N->getOpcode() == ISD::LOAD &&
1854       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1855   }
1856
1857   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1858   /// store.
1859   inline bool isNON_TRUNCStore(const SDNode *N) {
1860     return N->getOpcode() == ISD::STORE &&
1861       !cast<StoreSDNode>(N)->isTruncatingStore();
1862   }
1863
1864   /// isTRUNCStore - Returns true if the specified node is a truncating
1865   /// store.
1866   inline bool isTRUNCStore(const SDNode *N) {
1867     return N->getOpcode() == ISD::STORE &&
1868       cast<StoreSDNode>(N)->isTruncatingStore();
1869   }
1870 }
1871
1872
1873 } // end llvm namespace
1874
1875 #endif