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