9f866316eb5646c525b7bf358a245f1b90d5a6c6
[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/Constants.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator.h"
26 #include "llvm/ADT/ilist_node.h"
27 #include "llvm/ADT/STLExtras.h"
28 #include "llvm/CodeGen/ValueTypes.h"
29 #include "llvm/CodeGen/MachineMemOperand.h"
30 #include "llvm/Support/Allocator.h"
31 #include "llvm/Support/RecyclingAllocator.h"
32 #include "llvm/Support/DataTypes.h"
33 #include <cassert>
34
35 namespace llvm {
36
37 class SelectionDAG;
38 class GlobalValue;
39 class MachineBasicBlock;
40 class MachineConstantPoolValue;
41 class SDNode;
42 class CompileUnitDesc;
43 template <typename T> struct DenseMapInfo;
44 template <typename T> struct simplify_type;
45 template <typename T> struct ilist_traits;
46
47 /// SDVTList - This represents a list of ValueType's that has been intern'd by
48 /// a SelectionDAG.  Instances of this simple value class are returned by
49 /// SelectionDAG::getVTList(...).
50 ///
51 struct SDVTList {
52   const MVT *VTs;
53   unsigned short NumVTs;
54 };
55
56 /// ISD namespace - This namespace contains an enum which represents all of the
57 /// SelectionDAG node types and value types.
58 ///
59 namespace ISD {
60
61   //===--------------------------------------------------------------------===//
62   /// ISD::NodeType enum - This enum defines all of the operators valid in a
63   /// SelectionDAG.
64   ///
65   enum NodeType {
66     // DELETED_NODE - This is an illegal flag value that is used to catch
67     // errors.  This opcode is not a legal opcode for any node.
68     DELETED_NODE,
69     
70     // EntryToken - This is the marker used to indicate the start of the region.
71     EntryToken,
72
73     // TokenFactor - This node takes multiple tokens as input and produces a
74     // single token result.  This is used to represent the fact that the operand
75     // operators are independent of each other.
76     TokenFactor,
77     
78     // AssertSext, AssertZext - These nodes record if a register contains a 
79     // value that has already been zero or sign extended from a narrower type.  
80     // These nodes take two operands.  The first is the node that has already 
81     // been extended, and the second is a value type node indicating the width
82     // of the extension
83     AssertSext, AssertZext,
84
85     // Various leaf nodes.
86     BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
87     Constant, ConstantFP,
88     GlobalAddress, GlobalTLSAddress, FrameIndex,
89     JumpTable, ConstantPool, ExternalSymbol,
90
91     // The address of the GOT
92     GLOBAL_OFFSET_TABLE,
93     
94     // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
95     // llvm.returnaddress on the DAG.  These nodes take one operand, the index
96     // of the frame or return address to return.  An index of zero corresponds
97     // to the current function's frame or return address, an index of one to the
98     // parent's frame or return address, and so on.
99     FRAMEADDR, RETURNADDR,
100
101     // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
102     // first (possible) on-stack argument. This is needed for correct stack
103     // adjustment during unwind.
104     FRAME_TO_ARGS_OFFSET,
105     
106     // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
107     // address of the exception block on entry to an landing pad block.
108     EXCEPTIONADDR,
109     
110     // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
111     // the selection index of the exception thrown.
112     EHSELECTION,
113
114     // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
115     // 'eh_return' gcc dwarf builtin, which is used to return from
116     // exception. The general meaning is: adjust stack by OFFSET and pass
117     // execution to HANDLER. Many platform-related details also :)
118     EH_RETURN,
119
120     // TargetConstant* - Like Constant*, but the DAG does not do any folding or
121     // simplification of the constant.
122     TargetConstant,
123     TargetConstantFP,
124     
125     // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
126     // anything else with this node, and this is valid in the target-specific
127     // dag, turning into a GlobalAddress operand.
128     TargetGlobalAddress,
129     TargetGlobalTLSAddress,
130     TargetFrameIndex,
131     TargetJumpTable,
132     TargetConstantPool,
133     TargetExternalSymbol,
134     
135     /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
136     /// This node represents a target intrinsic function with no side effects.
137     /// The first operand is the ID number of the intrinsic from the
138     /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
139     /// node has returns the result of the intrinsic.
140     INTRINSIC_WO_CHAIN,
141     
142     /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
143     /// This node represents a target intrinsic function with side effects that
144     /// returns a result.  The first operand is a chain pointer.  The second is
145     /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
146     /// operands to the intrinsic follow.  The node has two results, the result
147     /// of the intrinsic and an output chain.
148     INTRINSIC_W_CHAIN,
149
150     /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
151     /// This node represents a target intrinsic function with side effects that
152     /// does not return a result.  The first operand is a chain pointer.  The
153     /// second is the ID number of the intrinsic from the llvm::Intrinsic
154     /// namespace.  The operands to the intrinsic follow.
155     INTRINSIC_VOID,
156     
157     // CopyToReg - This node has three operands: a chain, a register number to
158     // set to this value, and a value.  
159     CopyToReg,
160
161     // CopyFromReg - This node indicates that the input value is a virtual or
162     // physical register that is defined outside of the scope of this
163     // SelectionDAG.  The register is available from the RegisterSDNode object.
164     CopyFromReg,
165
166     // UNDEF - An undefined node
167     UNDEF,
168     
169     /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
170     /// represents the formal arguments for a function.  CC# is a Constant value
171     /// indicating the calling convention of the function, and ISVARARG is a
172     /// flag that indicates whether the function is varargs or not. This node
173     /// has one result value for each incoming argument, plus one for the output
174     /// chain. It must be custom legalized. See description of CALL node for
175     /// FLAG argument contents explanation.
176     /// 
177     FORMAL_ARGUMENTS,
178     
179     /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CALLEE,
180     ///                              ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
181     /// This node represents a fully general function call, before the legalizer
182     /// runs.  This has one result value for each argument / flag pair, plus
183     /// a chain result. It must be custom legalized. Flag argument indicates
184     /// misc. argument attributes. Currently:
185     /// Bit 0 - signness
186     /// Bit 1 - 'inreg' attribute
187     /// Bit 2 - 'sret' attribute
188     /// Bit 4 - 'byval' attribute
189     /// Bit 5 - 'nest' attribute
190     /// Bit 6-9 - alignment of byval structures
191     /// Bit 10-26 - size of byval structures
192     /// Bits 31:27 - argument ABI alignment in the first argument piece and
193     /// alignment '1' in other argument pieces.
194     ///
195     /// CALL nodes use the CallSDNode subclass of SDNode, which
196     /// additionally carries information about the calling convention,
197     /// whether the call is varargs, and if it's marked as a tail call.
198     ///
199     CALL,
200
201     // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
202     // a Constant, which is required to be operand #1) half of the integer or
203     // float value specified as operand #0.  This is only for use before
204     // legalization, for values that will be broken into multiple registers.
205     EXTRACT_ELEMENT,
206
207     // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
208     // two values of the same integer value type, this produces a value twice as
209     // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
210     BUILD_PAIR,
211
212     // MERGE_VALUES - This node takes multiple discrete operands and returns
213     // them all as its individual results.  This nodes has exactly the same
214     // number of inputs and outputs, and is only valid before legalization.
215     // This node is useful for some pieces of the code generator that want to
216     // think about a single node with multiple results, not multiple nodes.
217     MERGE_VALUES,
218
219     // Simple integer binary arithmetic operators.
220     ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
221
222     // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
223     // a signed/unsigned value of type i[2*N], and return the full value as
224     // two results, each of type iN.
225     SMUL_LOHI, UMUL_LOHI,
226
227     // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
228     // remainder result.
229     SDIVREM, UDIVREM,
230     
231     // CARRY_FALSE - This node is used when folding other nodes,
232     // like ADDC/SUBC, which indicate the carry result is always false.
233     CARRY_FALSE,
234     
235     // Carry-setting nodes for multiple precision addition and subtraction.
236     // These nodes take two operands of the same value type, and produce two
237     // results.  The first result is the normal add or sub result, the second
238     // result is the carry flag result.
239     ADDC, SUBC,
240     
241     // Carry-using nodes for multiple precision addition and subtraction.  These
242     // nodes take three operands: The first two are the normal lhs and rhs to
243     // the add or sub, and the third is the input carry flag.  These nodes
244     // produce two results; the normal result of the add or sub, and the output
245     // carry flag.  These nodes both read and write a carry flag to allow them
246     // to them to be chained together for add and sub of arbitrarily large
247     // values.
248     ADDE, SUBE,
249
250     // RESULT, BOOL = [SU]ADDO(LHS, RHS) - Overflow-aware nodes for addition.
251     // These nodes take two operands: the normal LHS and RHS to the add. They
252     // produce two results: the normal result of the add, and a boolean that
253     // indicates if an overflow occured (*not* a flag, because it may be stored
254     // to memory, etc.).  If the type of the boolean is not i1 then the high
255     // bits conform to getBooleanContents.
256     // These nodes are generated from the llvm.[su]add.with.overflow intrinsics.
257     SADDO, UADDO,
258
259     // Same for subtraction
260     SSUBO, USUBO,
261
262     // Same for multiplication
263     SMULO, UMULO,
264
265     // Simple binary floating point operators.
266     FADD, FSUB, FMUL, FDIV, FREM,
267
268     // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
269     // DAG node does not require that X and Y have the same type, just that they
270     // are both floating point.  X and the result must have the same type.
271     // FCOPYSIGN(f32, f64) is allowed.
272     FCOPYSIGN,
273
274     // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
275     // value as an integer 0/1 value.
276     FGETSIGN,
277     
278     /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
279     /// with the specified, possibly variable, elements.  The number of elements
280     /// is required to be a power of two.
281     BUILD_VECTOR,
282     
283     /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
284     /// at IDX replaced with VAL.  If the type of VAL is larger than the vector
285     /// element type then VAL is truncated before replacement.
286     INSERT_VECTOR_ELT,
287
288     /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
289     /// identified by the (potentially variable) element number IDX.
290     EXTRACT_VECTOR_ELT,
291     
292     /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
293     /// vector type with the same length and element type, this produces a
294     /// concatenated vector result value, with length equal to the sum of the
295     /// lengths of the input vectors.
296     CONCAT_VECTORS,
297     
298     /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
299     /// vector value) starting with the (potentially variable) element number
300     /// IDX, which must be a multiple of the result vector length.
301     EXTRACT_SUBVECTOR,
302
303     /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
304     /// type as VEC1/VEC2.  SHUFFLEVEC is a BUILD_VECTOR of constant int values
305     /// (maybe of an illegal datatype) or undef that indicate which value each
306     /// result element will get.  The elements of VEC1/VEC2 are enumerated in
307     /// order.  This is quite similar to the Altivec 'vperm' instruction, except
308     /// that the indices must be constants and are in terms of the element size
309     /// of VEC1/VEC2, not in terms of bytes.
310     VECTOR_SHUFFLE,
311
312     /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
313     /// scalar value into element 0 of the resultant vector type.  The top
314     /// elements 1 to N-1 of the N-element vector are undefined.
315     SCALAR_TO_VECTOR,
316     
317     // EXTRACT_SUBREG - This node is used to extract a sub-register value. 
318     // This node takes a superreg and a constant sub-register index as operands.
319     // Note sub-register indices must be increasing. That is, if the
320     // sub-register index of a 8-bit sub-register is N, then the index for a
321     // 16-bit sub-register must be at least N+1.
322     EXTRACT_SUBREG,
323     
324     // INSERT_SUBREG - This node is used to insert a sub-register value. 
325     // This node takes a superreg, a subreg value, and a constant sub-register
326     // index as operands.
327     INSERT_SUBREG,
328     
329     // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
330     // an unsigned/signed value of type i[2*N], then return the top part.
331     MULHU, MULHS,
332
333     // Bitwise operators - logical and, logical or, logical xor, shift left,
334     // shift right algebraic (shift in sign bits), shift right logical (shift in
335     // zeroes), rotate left, rotate right, and byteswap.
336     AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
337
338     // Counting operators
339     CTTZ, CTLZ, CTPOP,
340
341     // Select(COND, TRUEVAL, FALSEVAL).  If the type of the boolean COND is not
342     // i1 then the high bits must conform to getBooleanContents.
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 true value iff the condition is
352     // true.  If the result value type is not i1 then the high bits conform
353     // to getBooleanContents.  The operands to this are the left and right
354     // operands to compare (ops #0, and #1) and the condition code to compare
355     // them with (op #2) as a CondCodeSDNode.
356     SETCC,
357
358     // Vector SetCC operator - This evaluates to a vector of integer elements
359     // with the high bit in each element set to true if the comparison is true
360     // and false if the comparison is false.  All other bits in each element 
361     // are undefined.  The operands to this are the left and right operands
362     // to compare (ops #0, and #1) and the condition code to compare them with
363     // (op #2) as a CondCodeSDNode.
364     VSETCC,
365
366     // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
367     // integer shift operations, just like ADD/SUB_PARTS.  The operation
368     // ordering is:
369     //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
370     SHL_PARTS, SRA_PARTS, SRL_PARTS,
371
372     // Conversion operators.  These are all single input single output
373     // operations.  For all of these, the result type must be strictly
374     // wider or narrower (depending on the operation) than the source
375     // type.
376
377     // SIGN_EXTEND - Used for integer types, replicating the sign bit
378     // into new bits.
379     SIGN_EXTEND,
380
381     // ZERO_EXTEND - Used for integer types, zeroing the new bits.
382     ZERO_EXTEND,
383
384     // ANY_EXTEND - Used for integer types.  The high bits are undefined.
385     ANY_EXTEND,
386     
387     // TRUNCATE - Completely drop the high bits.
388     TRUNCATE,
389
390     // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
391     // depends on the first letter) to floating point.
392     SINT_TO_FP,
393     UINT_TO_FP,
394
395     // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
396     // sign extend a small value in a large integer register (e.g. sign
397     // extending the low 8 bits of a 32-bit register to fill the top 24 bits
398     // with the 7th bit).  The size of the smaller type is indicated by the 1th
399     // operand, a ValueType node.
400     SIGN_EXTEND_INREG,
401
402     /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
403     /// integer.
404     FP_TO_SINT,
405     FP_TO_UINT,
406
407     /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
408     /// down to the precision of the destination VT.  TRUNC is a flag, which is
409     /// always an integer that is zero or one.  If TRUNC is 0, this is a
410     /// normal rounding, if it is 1, this FP_ROUND is known to not change the
411     /// value of Y.
412     ///
413     /// The TRUNC = 1 case is used in cases where we know that the value will
414     /// not be modified by the node, because Y is not using any of the extra
415     /// precision of source type.  This allows certain transformations like
416     /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for 
417     /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
418     FP_ROUND,
419     
420     // FLT_ROUNDS_ - Returns current rounding mode:
421     // -1 Undefined
422     //  0 Round to 0
423     //  1 Round to nearest
424     //  2 Round to +inf
425     //  3 Round to -inf
426     FLT_ROUNDS_,
427
428     /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
429     /// rounds it to a floating point value.  It then promotes it and returns it
430     /// in a register of the same size.  This operation effectively just
431     /// discards excess precision.  The type to round down to is specified by
432     /// the VT operand, a VTSDNode.
433     FP_ROUND_INREG,
434
435     /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
436     FP_EXTEND,
437
438     // BIT_CONVERT - Theis operator converts between integer and FP values, as
439     // if one was stored to memory as integer and the other was loaded from the
440     // same address (or equivalently for vector format conversions, etc).  The 
441     // source and result are required to have the same bit size (e.g. 
442     // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp 
443     // conversions, but that is a noop, deleted by getNode().
444     BIT_CONVERT,
445     
446     // CONVERT_RNDSAT - This operator is used to support various conversions
447     // between various types (float, signed, unsigned and vectors of those
448     // types) with rounding and saturation. NOTE: Avoid using this operator as
449     // most target don't support it and the operator might be removed in the
450     // future. It takes the following arguments:
451     //   0) value
452     //   1) dest type (type to convert to)
453     //   2) src type (type to convert from)
454     //   3) rounding imm
455     //   4) saturation imm
456     //   5) ISD::CvtCode indicating the type of conversion to do
457     CONVERT_RNDSAT,
458     
459     // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
460     // FLOG, FLOG2, FLOG10, FEXP, FEXP2,
461     // FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary floating
462     // point operations. These are inspired by libm.
463     FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
464     FLOG, FLOG2, FLOG10, FEXP, FEXP2,
465     FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR,
466     
467     // LOAD and STORE have token chains as their first operand, then the same
468     // operands as an LLVM load/store instruction, then an offset node that
469     // is added / subtracted from the base pointer to form the address (for
470     // indexed memory ops).
471     LOAD, STORE,
472
473     // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
474     // to a specified boundary.  This node always has two return values: a new
475     // stack pointer value and a chain. The first operand is the token chain,
476     // the second is the number of bytes to allocate, and the third is the
477     // alignment boundary.  The size is guaranteed to be a multiple of the stack
478     // alignment, and the alignment is guaranteed to be bigger than the stack
479     // alignment (if required) or 0 to get standard stack alignment.
480     DYNAMIC_STACKALLOC,
481
482     // Control flow instructions.  These all have token chains.
483
484     // BR - Unconditional branch.  The first operand is the chain
485     // operand, the second is the MBB to branch to.
486     BR,
487
488     // BRIND - Indirect branch.  The first operand is the chain, the second
489     // is the value to branch to, which must be of the same type as the target's
490     // pointer type.
491     BRIND,
492
493     // BR_JT - Jumptable branch. The first operand is the chain, the second
494     // is the jumptable index, the last one is the jumptable entry index.
495     BR_JT,
496
497     // BRCOND - Conditional branch.  The first operand is the chain, the
498     // second is the condition, the third is the block to branch to if the
499     // condition is true.  If the type of the condition is not i1, then the
500     // high bits must conform to getBooleanContents.
501     BRCOND,
502
503     // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
504     // that the condition is represented as condition code, and two nodes to
505     // compare, rather than as a combined SetCC node.  The operands in order are
506     // chain, cc, lhs, rhs, block to branch to if condition is true.
507     BR_CC,
508     
509     // RET - Return from function.  The first operand is the chain,
510     // and any subsequent operands are pairs of return value and return value
511     // attributes (see CALL for description of attributes) for the function.
512     // This operation can have variable number of operands.
513     RET,
514
515     // INLINEASM - Represents an inline asm block.  This node always has two
516     // return values: a chain and a flag result.  The inputs are as follows:
517     //   Operand #0   : Input chain.
518     //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
519     //   Operand #2n+2: A RegisterNode.
520     //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
521     //   Operand #last: Optional, an incoming flag.
522     INLINEASM,
523     
524     // DBG_LABEL, EH_LABEL - Represents a label in mid basic block used to track
525     // locations needed for debug and exception handling tables.  These nodes
526     // take a chain as input and return a chain.
527     DBG_LABEL,
528     EH_LABEL,
529
530     // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
531     // local variable declarations for debugging information. First operand is
532     // a chain, while the next two operands are first two arguments (address
533     // and variable) of a llvm.dbg.declare instruction.
534     DECLARE,
535     
536     // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
537     // value, the same type as the pointer type for the system, and an output
538     // chain.
539     STACKSAVE,
540     
541     // STACKRESTORE has two operands, an input chain and a pointer to restore to
542     // it returns an output chain.
543     STACKRESTORE,
544     
545     // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
546     // a call sequence, and carry arbitrary information that target might want
547     // to know.  The first operand is a chain, the rest are specified by the
548     // target and not touched by the DAG optimizers.
549     // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
550     CALLSEQ_START,  // Beginning of a call sequence
551     CALLSEQ_END,    // End of a call sequence
552     
553     // VAARG - VAARG has three operands: an input chain, a pointer, and a 
554     // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
555     VAARG,
556     
557     // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
558     // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
559     // source.
560     VACOPY,
561     
562     // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
563     // pointer, and a SRCVALUE.
564     VAEND, VASTART,
565
566     // SRCVALUE - This is a node type that holds a Value* that is used to
567     // make reference to a value in the LLVM IR.
568     SRCVALUE,
569
570     // MEMOPERAND - This is a node that contains a MachineMemOperand which
571     // records information about a memory reference. This is used to make
572     // AliasAnalysis queries from the backend.
573     MEMOPERAND,
574
575     // PCMARKER - This corresponds to the pcmarker intrinsic.
576     PCMARKER,
577
578     // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
579     // The only operand is a chain and a value and a chain are produced.  The
580     // value is the contents of the architecture specific cycle counter like 
581     // register (or other high accuracy low latency clock source)
582     READCYCLECOUNTER,
583
584     // HANDLENODE node - Used as a handle for various purposes.
585     HANDLENODE,
586
587     // DBG_STOPPOINT - This node is used to represent a source location for
588     // debug info.  It takes token chain as input, and carries a line number,
589     // column number, and a pointer to a CompileUnitDesc object identifying
590     // the containing compilation unit.  It produces a token chain as output.
591     DBG_STOPPOINT,
592     
593     // DEBUG_LOC - This node is used to represent source line information
594     // embedded in the code.  It takes a token chain as input, then a line
595     // number, then a column then a file id (provided by MachineModuleInfo.) It
596     // produces a token chain as output.
597     DEBUG_LOC,
598
599     // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
600     // It takes as input a token chain, the pointer to the trampoline,
601     // the pointer to the nested function, the pointer to pass for the
602     // 'nest' parameter, a SRCVALUE for the trampoline and another for
603     // the nested function (allowing targets to access the original
604     // Function*).  It produces the result of the intrinsic and a token
605     // chain as output.
606     TRAMPOLINE,
607
608     // TRAP - Trapping instruction
609     TRAP,
610
611     // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
612     // their first operand. The other operands are the address to prefetch,
613     // read / write specifier, and locality specifier.
614     PREFETCH,
615
616     // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load, 
617     //                       store-store, device)
618     // This corresponds to the memory.barrier intrinsic.
619     // it takes an input chain, 4 operands to specify the type of barrier, an
620     // operand specifying if the barrier applies to device and uncached memory
621     // and produces an output chain.
622     MEMBARRIER,
623
624     // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
625     // this corresponds to the atomic.lcs intrinsic.
626     // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
627     // the return is always the original value in *ptr
628     ATOMIC_CMP_SWAP,
629
630     // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
631     // this corresponds to the atomic.swap intrinsic.
632     // amt is stored to *ptr atomically.
633     // the return is always the original value in *ptr
634     ATOMIC_SWAP,
635
636     // Val, OUTCHAIN = ATOMIC_LOAD_[OpName](INCHAIN, ptr, amt)
637     // this corresponds to the atomic.load.[OpName] intrinsic.
638     // op(*ptr, amt) is stored to *ptr atomically.
639     // the return is always the original value in *ptr
640     ATOMIC_LOAD_ADD,
641     ATOMIC_LOAD_SUB,
642     ATOMIC_LOAD_AND,
643     ATOMIC_LOAD_OR,
644     ATOMIC_LOAD_XOR,
645     ATOMIC_LOAD_NAND,
646     ATOMIC_LOAD_MIN,
647     ATOMIC_LOAD_MAX,
648     ATOMIC_LOAD_UMIN,
649     ATOMIC_LOAD_UMAX,
650     
651     // BUILTIN_OP_END - This must be the last enum value in this list.
652     BUILTIN_OP_END
653   };
654
655   /// Node predicates
656
657   /// isBuildVectorAllOnes - Return true if the specified node is a
658   /// BUILD_VECTOR where all of the elements are ~0 or undef.
659   bool isBuildVectorAllOnes(const SDNode *N);
660
661   /// isBuildVectorAllZeros - Return true if the specified node is a
662   /// BUILD_VECTOR where all of the elements are 0 or undef.
663   bool isBuildVectorAllZeros(const SDNode *N);
664
665   /// isScalarToVector - Return true if the specified node is a
666   /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
667   /// element is not an undef.
668   bool isScalarToVector(const SDNode *N);
669
670   /// isDebugLabel - Return true if the specified node represents a debug
671   /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node).
672   bool isDebugLabel(const SDNode *N);
673   
674   //===--------------------------------------------------------------------===//
675   /// MemIndexedMode enum - This enum defines the load / store indexed 
676   /// addressing modes.
677   ///
678   /// UNINDEXED    "Normal" load / store. The effective address is already
679   ///              computed and is available in the base pointer. The offset
680   ///              operand is always undefined. In addition to producing a
681   ///              chain, an unindexed load produces one value (result of the
682   ///              load); an unindexed store does not produce a value.
683   ///
684   /// PRE_INC      Similar to the unindexed mode where the effective address is
685   /// PRE_DEC      the value of the base pointer add / subtract the offset.
686   ///              It considers the computation as being folded into the load /
687   ///              store operation (i.e. the load / store does the address
688   ///              computation as well as performing the memory transaction).
689   ///              The base operand is always undefined. In addition to
690   ///              producing a chain, pre-indexed load produces two values
691   ///              (result of the load and the result of the address
692   ///              computation); a pre-indexed store produces one value (result
693   ///              of the address computation).
694   ///
695   /// POST_INC     The effective address is the value of the base pointer. The
696   /// POST_DEC     value of the offset operand is then added to / subtracted
697   ///              from the base after memory transaction. In addition to
698   ///              producing a chain, post-indexed load produces two values
699   ///              (the result of the load and the result of the base +/- offset
700   ///              computation); a post-indexed store produces one value (the
701   ///              the result of the base +/- offset computation).
702   ///
703   enum MemIndexedMode {
704     UNINDEXED = 0,
705     PRE_INC,
706     PRE_DEC,
707     POST_INC,
708     POST_DEC,
709     LAST_INDEXED_MODE
710   };
711
712   //===--------------------------------------------------------------------===//
713   /// LoadExtType enum - This enum defines the three variants of LOADEXT
714   /// (load with extension).
715   ///
716   /// SEXTLOAD loads the integer operand and sign extends it to a larger
717   ///          integer result type.
718   /// ZEXTLOAD loads the integer operand and zero extends it to a larger
719   ///          integer result type.
720   /// EXTLOAD  is used for three things: floating point extending loads, 
721   ///          integer extending loads [the top bits are undefined], and vector
722   ///          extending loads [load into low elt].
723   ///
724   enum LoadExtType {
725     NON_EXTLOAD = 0,
726     EXTLOAD,
727     SEXTLOAD,
728     ZEXTLOAD,
729     LAST_LOADEXT_TYPE
730   };
731
732   //===--------------------------------------------------------------------===//
733   /// ISD::CondCode enum - These are ordered carefully to make the bitfields
734   /// below work out, when considering SETFALSE (something that never exists
735   /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
736   /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
737   /// to.  If the "N" column is 1, the result of the comparison is undefined if
738   /// the input is a NAN.
739   ///
740   /// All of these (except for the 'always folded ops') should be handled for
741   /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
742   /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
743   ///
744   /// Note that these are laid out in a specific order to allow bit-twiddling
745   /// to transform conditions.
746   enum CondCode {
747     // Opcode          N U L G E       Intuitive operation
748     SETFALSE,      //    0 0 0 0       Always false (always folded)
749     SETOEQ,        //    0 0 0 1       True if ordered and equal
750     SETOGT,        //    0 0 1 0       True if ordered and greater than
751     SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
752     SETOLT,        //    0 1 0 0       True if ordered and less than
753     SETOLE,        //    0 1 0 1       True if ordered and less than or equal
754     SETONE,        //    0 1 1 0       True if ordered and operands are unequal
755     SETO,          //    0 1 1 1       True if ordered (no nans)
756     SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
757     SETUEQ,        //    1 0 0 1       True if unordered or equal
758     SETUGT,        //    1 0 1 0       True if unordered or greater than
759     SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
760     SETULT,        //    1 1 0 0       True if unordered or less than
761     SETULE,        //    1 1 0 1       True if unordered, less than, or equal
762     SETUNE,        //    1 1 1 0       True if unordered or not equal
763     SETTRUE,       //    1 1 1 1       Always true (always folded)
764     // Don't care operations: undefined if the input is a nan.
765     SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
766     SETEQ,         //  1 X 0 0 1       True if equal
767     SETGT,         //  1 X 0 1 0       True if greater than
768     SETGE,         //  1 X 0 1 1       True if greater than or equal
769     SETLT,         //  1 X 1 0 0       True if less than
770     SETLE,         //  1 X 1 0 1       True if less than or equal
771     SETNE,         //  1 X 1 1 0       True if not equal
772     SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
773
774     SETCC_INVALID       // Marker value.
775   };
776
777   /// isSignedIntSetCC - Return true if this is a setcc instruction that
778   /// performs a signed comparison when used with integer operands.
779   inline bool isSignedIntSetCC(CondCode Code) {
780     return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
781   }
782
783   /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
784   /// performs an unsigned comparison when used with integer operands.
785   inline bool isUnsignedIntSetCC(CondCode Code) {
786     return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
787   }
788
789   /// isTrueWhenEqual - Return true if the specified condition returns true if
790   /// the two operands to the condition are equal.  Note that if one of the two
791   /// operands is a NaN, this value is meaningless.
792   inline bool isTrueWhenEqual(CondCode Cond) {
793     return ((int)Cond & 1) != 0;
794   }
795
796   /// getUnorderedFlavor - This function returns 0 if the condition is always
797   /// false if an operand is a NaN, 1 if the condition is always true if the
798   /// operand is a NaN, and 2 if the condition is undefined if the operand is a
799   /// NaN.
800   inline unsigned getUnorderedFlavor(CondCode Cond) {
801     return ((int)Cond >> 3) & 3;
802   }
803
804   /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
805   /// 'op' is a valid SetCC operation.
806   CondCode getSetCCInverse(CondCode Operation, bool isInteger);
807
808   /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
809   /// when given the operation for (X op Y).
810   CondCode getSetCCSwappedOperands(CondCode Operation);
811
812   /// getSetCCOrOperation - Return the result of a logical OR between different
813   /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
814   /// function returns SETCC_INVALID if it is not possible to represent the
815   /// resultant comparison.
816   CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
817
818   /// getSetCCAndOperation - Return the result of a logical AND between
819   /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
820   /// function returns SETCC_INVALID if it is not possible to represent the
821   /// resultant comparison.
822   CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
823
824   //===--------------------------------------------------------------------===//
825   /// CvtCode enum - This enum defines the various converts CONVERT_RNDSAT 
826   /// supports.
827   enum CvtCode {
828     CVT_FF,     // Float from Float
829     CVT_FS,     // Float from Signed
830     CVT_FU,     // Float from Unsigned
831     CVT_SF,     // Signed from Float
832     CVT_UF,     // Unsigned from Float
833     CVT_SS,     // Signed from Signed
834     CVT_SU,     // Signed from Unsigned
835     CVT_US,     // Unsigned from Signed
836     CVT_UU,     // Unsigned from Unsigned
837     CVT_INVALID // Marker - Invalid opcode
838   };
839 }  // end llvm::ISD namespace
840
841
842 //===----------------------------------------------------------------------===//
843 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
844 /// values as the result of a computation.  Many nodes return multiple values,
845 /// from loads (which define a token and a return value) to ADDC (which returns
846 /// a result and a carry value), to calls (which may return an arbitrary number
847 /// of values).
848 ///
849 /// As such, each use of a SelectionDAG computation must indicate the node that
850 /// computes it as well as which return value to use from that node.  This pair
851 /// of information is represented with the SDValue value type.
852 ///
853 class SDValue {
854   SDNode *Node;       // The node defining the value we are using.
855   unsigned ResNo;     // Which return value of the node we are using.
856 public:
857   SDValue() : Node(0), ResNo(0) {}
858   SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
859
860   /// get the index which selects a specific result in the SDNode
861   unsigned getResNo() const { return ResNo; }
862
863   /// get the SDNode which holds the desired result
864   SDNode *getNode() const { return Node; }
865
866   /// set the SDNode
867   void setNode(SDNode *N) { Node = N; }
868
869   bool operator==(const SDValue &O) const {
870     return Node == O.Node && ResNo == O.ResNo;
871   }
872   bool operator!=(const SDValue &O) const {
873     return !operator==(O);
874   }
875   bool operator<(const SDValue &O) const {
876     return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
877   }
878
879   SDValue getValue(unsigned R) const {
880     return SDValue(Node, R);
881   }
882
883   // isOperandOf - Return true if this node is an operand of N.
884   bool isOperandOf(SDNode *N) const;
885
886   /// getValueType - Return the ValueType of the referenced return value.
887   ///
888   inline MVT getValueType() const;
889
890   /// getValueSizeInBits - Returns the size of the value in bits.
891   ///
892   unsigned getValueSizeInBits() const {
893     return getValueType().getSizeInBits();
894   }
895
896   // Forwarding methods - These forward to the corresponding methods in SDNode.
897   inline unsigned getOpcode() const;
898   inline unsigned getNumOperands() const;
899   inline const SDValue &getOperand(unsigned i) const;
900   inline uint64_t getConstantOperandVal(unsigned i) const;
901   inline bool isTargetOpcode() const;
902   inline bool isMachineOpcode() const;
903   inline unsigned getMachineOpcode() const;
904
905   
906   /// reachesChainWithoutSideEffects - Return true if this operand (which must
907   /// be a chain) reaches the specified operand without crossing any 
908   /// side-effecting instructions.  In practice, this looks through token
909   /// factors and non-volatile loads.  In order to remain efficient, this only
910   /// looks a couple of nodes in, it does not do an exhaustive search.
911   bool reachesChainWithoutSideEffects(SDValue Dest, 
912                                       unsigned Depth = 2) const;
913   
914   /// use_empty - Return true if there are no nodes using value ResNo
915   /// of Node.
916   ///
917   inline bool use_empty() const;
918
919   /// hasOneUse - Return true if there is exactly one node using value
920   /// ResNo of Node.
921   ///
922   inline bool hasOneUse() const;
923 };
924
925
926 template<> struct DenseMapInfo<SDValue> {
927   static inline SDValue getEmptyKey() { 
928     return SDValue((SDNode*)-1, -1U); 
929   }
930   static inline SDValue getTombstoneKey() { 
931     return SDValue((SDNode*)-1, 0);
932   }
933   static unsigned getHashValue(const SDValue &Val) {
934     return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
935             (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
936   }
937   static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
938     return LHS == RHS;
939   }
940   static bool isPod() { return true; }
941 };
942
943 /// simplify_type specializations - Allow casting operators to work directly on
944 /// SDValues as if they were SDNode*'s.
945 template<> struct simplify_type<SDValue> {
946   typedef SDNode* SimpleType;
947   static SimpleType getSimplifiedValue(const SDValue &Val) {
948     return static_cast<SimpleType>(Val.getNode());
949   }
950 };
951 template<> struct simplify_type<const SDValue> {
952   typedef SDNode* SimpleType;
953   static SimpleType getSimplifiedValue(const SDValue &Val) {
954     return static_cast<SimpleType>(Val.getNode());
955   }
956 };
957
958 /// SDUse - Represents a use of the SDNode referred by
959 /// the SDValue.
960 class SDUse {
961   SDValue Operand;
962   /// User - Parent node of this operand.
963   SDNode    *User;
964   /// Prev, next - Pointers to the uses list of the SDNode referred by 
965   /// this operand.
966   SDUse **Prev, *Next;
967 public:
968   friend class SDNode;
969   SDUse(): Operand(), User(NULL), Prev(NULL), Next(NULL) {}
970
971   SDUse(SDNode *val, unsigned resno) : 
972     Operand(val,resno), User(NULL), Prev(NULL), Next(NULL) {}
973
974   SDUse& operator= (const SDValue& Op) {
975       Operand = Op;
976       Next = NULL;
977       Prev = NULL;
978       return *this;
979   }
980
981   SDUse& operator= (const SDUse& Op) {
982       Operand = Op;
983       Next = NULL;
984       Prev = NULL;
985       return *this;
986   }
987
988   SDUse *getNext() { return Next; }
989
990   SDNode *getUser() { return User; }
991
992   void setUser(SDNode *p) { User = p; }
993
994   operator SDValue() const { return Operand; }
995
996   const SDValue& getSDValue() const { return Operand; }
997
998   SDValue &getSDValue() { return Operand; }
999   SDNode *getVal() { return Operand.getNode(); }
1000   SDNode *getVal() const { return Operand.getNode(); } // FIXME: const correct?
1001
1002   bool operator==(const SDValue &O) const {
1003     return Operand == O;
1004   }
1005
1006   bool operator!=(const SDValue &O) const {
1007     return !(Operand == O);
1008   }
1009
1010   bool operator<(const SDValue &O) const {
1011     return Operand < O;
1012   }
1013
1014 protected:
1015   void addToList(SDUse **List) {
1016     Next = *List;
1017     if (Next) Next->Prev = &Next;
1018     Prev = List;
1019     *List = this;
1020   }
1021
1022   void removeFromList() {
1023     *Prev = Next;
1024     if (Next) Next->Prev = Prev;
1025   }
1026 };
1027
1028
1029 /// simplify_type specializations - Allow casting operators to work directly on
1030 /// SDValues as if they were SDNode*'s.
1031 template<> struct simplify_type<SDUse> {
1032   typedef SDNode* SimpleType;
1033   static SimpleType getSimplifiedValue(const SDUse &Val) {
1034     return static_cast<SimpleType>(Val.getVal());
1035   }
1036 };
1037 template<> struct simplify_type<const SDUse> {
1038   typedef SDNode* SimpleType;
1039   static SimpleType getSimplifiedValue(const SDUse &Val) {
1040     return static_cast<SimpleType>(Val.getVal());
1041   }
1042 };
1043
1044
1045 /// SDOperandPtr - A helper SDValue pointer class, that can handle
1046 /// arrays of SDUse and arrays of SDValue objects. This is required
1047 /// in many places inside the SelectionDAG.
1048 /// 
1049 class SDOperandPtr {
1050   const SDValue *ptr; // The pointer to the SDValue object
1051   int object_size;      // The size of the object containg the SDValue
1052 public:
1053   SDOperandPtr() : ptr(0), object_size(0) {}
1054
1055   SDOperandPtr(SDUse * use_ptr) { 
1056     ptr = &use_ptr->getSDValue(); 
1057     object_size = (int)sizeof(SDUse); 
1058   }
1059
1060   SDOperandPtr(const SDValue * op_ptr) { 
1061     ptr = op_ptr; 
1062     object_size = (int)sizeof(SDValue); 
1063   }
1064
1065   const SDValue operator *() { return *ptr; }
1066   const SDValue *operator ->() { return ptr; }
1067   SDOperandPtr operator ++ () { 
1068     ptr = (SDValue*)((char *)ptr + object_size); 
1069     return *this; 
1070   }
1071
1072   SDOperandPtr operator ++ (int) { 
1073     SDOperandPtr tmp = *this;
1074     ptr = (SDValue*)((char *)ptr + object_size); 
1075     return tmp; 
1076   }
1077
1078   SDValue operator[] (int idx) const {
1079     return *(SDValue*)((char*) ptr + object_size * idx);
1080   } 
1081 };
1082
1083 /// SDNode - Represents one node in the SelectionDAG.
1084 ///
1085 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
1086 private:
1087   /// NodeType - The operation that this node performs.
1088   ///
1089   short NodeType;
1090   
1091   /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
1092   /// then they will be delete[]'d when the node is destroyed.
1093   unsigned short OperandsNeedDelete : 1;
1094
1095 protected:
1096   /// SubclassData - This member is defined by this class, but is not used for
1097   /// anything.  Subclasses can use it to hold whatever state they find useful.
1098   /// This field is initialized to zero by the ctor.
1099   unsigned short SubclassData : 15;
1100
1101 private:
1102   /// NodeId - Unique id per SDNode in the DAG.
1103   int NodeId;
1104
1105   /// OperandList - The values that are used by this operation.
1106   ///
1107   SDUse *OperandList;
1108   
1109   /// ValueList - The types of the values this node defines.  SDNode's may
1110   /// define multiple values simultaneously.
1111   const MVT *ValueList;
1112
1113   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1114   unsigned short NumOperands, NumValues;
1115   
1116   /// Uses - List of uses for this SDNode.
1117   SDUse *Uses;
1118
1119   /// addUse - add SDUse to the list of uses.
1120   void addUse(SDUse &U) { U.addToList(&Uses); }
1121
1122   // Out-of-line virtual method to give class a home.
1123   virtual void ANCHOR();
1124 public:
1125   virtual ~SDNode() {
1126     assert(NumOperands == 0 && "Operand list not cleared before deletion");
1127     NodeType = ISD::DELETED_NODE;
1128   }
1129   
1130   //===--------------------------------------------------------------------===//
1131   //  Accessors
1132   //
1133
1134   /// getOpcode - Return the SelectionDAG opcode value for this node. For
1135   /// pre-isel nodes (those for which isMachineOpcode returns false), these
1136   /// are the opcode values in the ISD and <target>ISD namespaces. For
1137   /// post-isel opcodes, see getMachineOpcode.
1138   unsigned getOpcode()  const { return (unsigned short)NodeType; }
1139
1140   /// isTargetOpcode - Test if this node has a target-specific opcode (in the
1141   /// <target>ISD namespace).
1142   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1143
1144   /// isMachineOpcode - Test if this node has a post-isel opcode, directly
1145   /// corresponding to a MachineInstr opcode.
1146   bool isMachineOpcode() const { return NodeType < 0; }
1147
1148   /// getMachineOpcode - This may only be called if isMachineOpcode returns
1149   /// true. It returns the MachineInstr opcode value that the node's opcode
1150   /// corresponds to.
1151   unsigned getMachineOpcode() const {
1152     assert(isMachineOpcode() && "Not a MachineInstr opcode!");
1153     return ~NodeType;
1154   }
1155
1156   /// use_empty - Return true if there are no uses of this node.
1157   ///
1158   bool use_empty() const { return Uses == NULL; }
1159
1160   /// hasOneUse - Return true if there is exactly one use of this node.
1161   ///
1162   bool hasOneUse() const {
1163     return !use_empty() && next(use_begin()) == use_end();
1164   }
1165
1166   /// use_size - Return the number of uses of this node. This method takes
1167   /// time proportional to the number of uses.
1168   ///
1169   size_t use_size() const { return std::distance(use_begin(), use_end()); }
1170
1171   /// getNodeId - Return the unique node id.
1172   ///
1173   int getNodeId() const { return NodeId; }
1174
1175   /// setNodeId - Set unique node id.
1176   void setNodeId(int Id) { NodeId = Id; }
1177
1178   /// use_iterator - This class provides iterator support for SDUse
1179   /// operands that use a specific SDNode. 
1180   class use_iterator
1181     : public forward_iterator<SDUse, ptrdiff_t> {
1182     SDUse *Op;
1183     explicit use_iterator(SDUse *op) : Op(op) {
1184     }
1185     friend class SDNode;
1186   public:
1187     typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
1188     typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1189
1190     use_iterator(const use_iterator &I) : Op(I.Op) {}
1191     use_iterator() : Op(0) {}
1192
1193     bool operator==(const use_iterator &x) const {
1194       return Op == x.Op;
1195     }
1196     bool operator!=(const use_iterator &x) const {
1197       return !operator==(x);
1198     }
1199  
1200     /// atEnd - return true if this iterator is at the end of uses list.
1201     bool atEnd() const { return Op == 0; }
1202
1203     // Iterator traversal: forward iteration only.
1204     use_iterator &operator++() {          // Preincrement
1205       assert(Op && "Cannot increment end iterator!");
1206       Op = Op->getNext();
1207       return *this;
1208     }
1209
1210     use_iterator operator++(int) {        // Postincrement
1211       use_iterator tmp = *this; ++*this; return tmp;
1212     }
1213
1214     /// Retrieve a pointer to the current user node.
1215     SDNode *operator*() const {
1216       assert(Op && "Cannot dereference end iterator!");
1217       return Op->getUser();
1218     }
1219
1220     SDNode *operator->() const { return operator*(); }
1221
1222     SDUse &getUse() const { return *Op; }
1223
1224     /// getOperandNo - Retrieve the operand # of this use in its user.
1225     ///
1226     unsigned getOperandNo() const {
1227       assert(Op && "Cannot dereference end iterator!");
1228       return (unsigned)(Op - Op->getUser()->OperandList);
1229     }
1230   };
1231
1232   /// use_begin/use_end - Provide iteration support to walk over all uses
1233   /// of an SDNode.
1234
1235   use_iterator use_begin() const {
1236     return use_iterator(Uses);
1237   }
1238
1239   static use_iterator use_end() { return use_iterator(0); }
1240
1241
1242   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1243   /// indicated value.  This method ignores uses of other values defined by this
1244   /// operation.
1245   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1246
1247   /// hasAnyUseOfValue - Return true if there are any use of the indicated
1248   /// value. This method ignores uses of other values defined by this operation.
1249   bool hasAnyUseOfValue(unsigned Value) const;
1250
1251   /// isOnlyUserOf - Return true if this node is the only use of N.
1252   ///
1253   bool isOnlyUserOf(SDNode *N) const;
1254
1255   /// isOperandOf - Return true if this node is an operand of N.
1256   ///
1257   bool isOperandOf(SDNode *N) const;
1258
1259   /// isPredecessorOf - Return true if this node is a predecessor of N. This
1260   /// node is either an operand of N or it can be reached by recursively
1261   /// traversing up the operands.
1262   /// NOTE: this is an expensive method. Use it carefully.
1263   bool isPredecessorOf(SDNode *N) const;
1264
1265   /// getNumOperands - Return the number of values used by this operation.
1266   ///
1267   unsigned getNumOperands() const { return NumOperands; }
1268
1269   /// getConstantOperandVal - Helper method returns the integer value of a 
1270   /// ConstantSDNode operand.
1271   uint64_t getConstantOperandVal(unsigned Num) const;
1272
1273   const SDValue &getOperand(unsigned Num) const {
1274     assert(Num < NumOperands && "Invalid child # of SDNode!");
1275     return OperandList[Num].getSDValue();
1276   }
1277
1278   typedef SDUse* op_iterator;
1279   op_iterator op_begin() const { return OperandList; }
1280   op_iterator op_end() const { return OperandList+NumOperands; }
1281
1282
1283   SDVTList getVTList() const {
1284     SDVTList X = { ValueList, NumValues };
1285     return X;
1286   };
1287
1288   /// getFlaggedNode - If this node has a flag operand, return the node
1289   /// to which the flag operand points. Otherwise return NULL.
1290   SDNode *getFlaggedNode() const {
1291     if (getNumOperands() != 0 &&
1292         getOperand(getNumOperands()-1).getValueType() == MVT::Flag)
1293       return getOperand(getNumOperands()-1).getNode();
1294     return 0;
1295   }
1296   
1297   /// getNumValues - Return the number of values defined/returned by this
1298   /// operator.
1299   ///
1300   unsigned getNumValues() const { return NumValues; }
1301
1302   /// getValueType - Return the type of a specified result.
1303   ///
1304   MVT getValueType(unsigned ResNo) const {
1305     assert(ResNo < NumValues && "Illegal result number!");
1306     return ValueList[ResNo];
1307   }
1308
1309   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1310   ///
1311   unsigned getValueSizeInBits(unsigned ResNo) const {
1312     return getValueType(ResNo).getSizeInBits();
1313   }
1314
1315   typedef const MVT* value_iterator;
1316   value_iterator value_begin() const { return ValueList; }
1317   value_iterator value_end() const { return ValueList+NumValues; }
1318
1319   /// getOperationName - Return the opcode of this operation for printing.
1320   ///
1321   std::string getOperationName(const SelectionDAG *G = 0) const;
1322   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1323   void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
1324   void dump() const;
1325   void dump(const SelectionDAG *G) const;
1326
1327   static bool classof(const SDNode *) { return true; }
1328
1329   /// Profile - Gather unique data for the node.
1330   ///
1331   void Profile(FoldingSetNodeID &ID) const;
1332
1333 protected:
1334   friend class SelectionDAG;
1335   friend struct ilist_traits<SDNode>;
1336   
1337   /// getValueTypeList - Return a pointer to the specified value type.
1338   ///
1339   static const MVT *getValueTypeList(MVT VT);
1340   static SDVTList getSDVTList(MVT VT) {
1341     SDVTList Ret = { getValueTypeList(VT), 1 };
1342     return Ret;
1343   }
1344
1345   SDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps)
1346     : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1347       NodeId(-1), Uses(NULL) {
1348     NumOperands = NumOps;
1349     OperandList = NumOps ? new SDUse[NumOperands] : 0;
1350     
1351     for (unsigned i = 0; i != NumOps; ++i) {
1352       OperandList[i] = Ops[i];
1353       OperandList[i].setUser(this);
1354       Ops[i].getNode()->addUse(OperandList[i]);
1355     }
1356     
1357     ValueList = VTs.VTs;
1358     NumValues = VTs.NumVTs;
1359   }
1360
1361   SDNode(unsigned Opc, SDVTList VTs, const SDUse *Ops, unsigned NumOps)
1362     : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1363       NodeId(-1), Uses(NULL) {
1364     OperandsNeedDelete = true;
1365     NumOperands = NumOps;
1366     OperandList = NumOps ? new SDUse[NumOperands] : 0;
1367     
1368     for (unsigned i = 0; i != NumOps; ++i) {
1369       OperandList[i] = Ops[i];
1370       OperandList[i].setUser(this);
1371       Ops[i].getVal()->addUse(OperandList[i]);
1372     }
1373     
1374     ValueList = VTs.VTs;
1375     NumValues = VTs.NumVTs;
1376   }
1377
1378   /// This constructor adds no operands itself; operands can be
1379   /// set later with InitOperands.
1380   SDNode(unsigned Opc, SDVTList VTs)
1381     : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1382       NodeId(-1), Uses(NULL) {
1383     NumOperands = 0;
1384     OperandList = 0;
1385     ValueList = VTs.VTs;
1386     NumValues = VTs.NumVTs;
1387   }
1388   
1389   /// InitOperands - Initialize the operands list of this node with the
1390   /// specified values, which are part of the node (thus they don't need to be
1391   /// copied in or allocated).
1392   void InitOperands(SDUse *Ops, unsigned NumOps) {
1393     assert(OperandList == 0 && "Operands already set!");
1394     NumOperands = NumOps;
1395     OperandList = Ops;
1396     Uses = NULL;
1397     
1398     for (unsigned i = 0; i != NumOps; ++i) {
1399       OperandList[i].setUser(this);
1400       Ops[i].getVal()->addUse(OperandList[i]);
1401     }
1402   }
1403
1404   /// DropOperands - Release the operands and set this node to have
1405   /// zero operands.
1406   void DropOperands();
1407   
1408   void addUser(unsigned i, SDNode *User) {
1409     assert(User->OperandList[i].getUser() && "Node without parent");
1410     addUse(User->OperandList[i]);
1411   }
1412
1413   void removeUser(unsigned i, SDNode *User) {
1414     assert(User->OperandList[i].getUser() && "Node without parent");
1415     SDUse &Op = User->OperandList[i];
1416     Op.removeFromList();
1417   }
1418 };
1419
1420
1421 // Define inline functions from the SDValue class.
1422
1423 inline unsigned SDValue::getOpcode() const {
1424   return Node->getOpcode();
1425 }
1426 inline MVT SDValue::getValueType() const {
1427   return Node->getValueType(ResNo);
1428 }
1429 inline unsigned SDValue::getNumOperands() const {
1430   return Node->getNumOperands();
1431 }
1432 inline const SDValue &SDValue::getOperand(unsigned i) const {
1433   return Node->getOperand(i);
1434 }
1435 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1436   return Node->getConstantOperandVal(i);
1437 }
1438 inline bool SDValue::isTargetOpcode() const {
1439   return Node->isTargetOpcode();
1440 }
1441 inline bool SDValue::isMachineOpcode() const {
1442   return Node->isMachineOpcode();
1443 }
1444 inline unsigned SDValue::getMachineOpcode() const {
1445   return Node->getMachineOpcode();
1446 }
1447 inline bool SDValue::use_empty() const {
1448   return !Node->hasAnyUseOfValue(ResNo);
1449 }
1450 inline bool SDValue::hasOneUse() const {
1451   return Node->hasNUsesOfValue(1, ResNo);
1452 }
1453
1454 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
1455 /// to allow co-allocation of node operands with the node itself.
1456 class UnarySDNode : public SDNode {
1457   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1458   SDUse Op;
1459 public:
1460   UnarySDNode(unsigned Opc, SDVTList VTs, SDValue X)
1461     : SDNode(Opc, VTs) {
1462     Op = X;
1463     InitOperands(&Op, 1);
1464   }
1465 };
1466
1467 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
1468 /// to allow co-allocation of node operands with the node itself.
1469 class BinarySDNode : public SDNode {
1470   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1471   SDUse Ops[2];
1472 public:
1473   BinarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y)
1474     : SDNode(Opc, VTs) {
1475     Ops[0] = X;
1476     Ops[1] = Y;
1477     InitOperands(Ops, 2);
1478   }
1479 };
1480
1481 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1482 /// to allow co-allocation of node operands with the node itself.
1483 class TernarySDNode : public SDNode {
1484   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1485   SDUse Ops[3];
1486 public:
1487   TernarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y,
1488                 SDValue Z)
1489     : SDNode(Opc, VTs) {
1490     Ops[0] = X;
1491     Ops[1] = Y;
1492     Ops[2] = Z;
1493     InitOperands(Ops, 3);
1494   }
1495 };
1496
1497
1498 /// HandleSDNode - This class is used to form a handle around another node that
1499 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1500 /// operand.  This node should be directly created by end-users and not added to
1501 /// the AllNodes list.
1502 class HandleSDNode : public SDNode {
1503   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1504   SDUse Op;
1505 public:
1506   // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1507   // fixed.
1508 #ifdef __GNUC__
1509   explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
1510 #else
1511   explicit HandleSDNode(SDValue X)
1512 #endif
1513     : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
1514     Op = X;
1515     InitOperands(&Op, 1);
1516   }
1517   ~HandleSDNode();  
1518   const SDValue &getValue() const { return Op.getSDValue(); }
1519 };
1520
1521 /// Abstact virtual class for operations for memory operations
1522 class MemSDNode : public SDNode {
1523   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1524
1525 private:
1526   // MemoryVT - VT of in-memory value.
1527   MVT MemoryVT;
1528
1529   //! SrcValue - Memory location for alias analysis.
1530   const Value *SrcValue;
1531
1532   //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
1533   int SVOffset;
1534
1535   /// Flags - the low bit indicates whether this is a volatile reference;
1536   /// the remainder is a log2 encoding of the alignment in bytes.
1537   unsigned Flags;
1538
1539 public:
1540   MemSDNode(unsigned Opc, SDVTList VTs, MVT MemoryVT,
1541             const Value *srcValue, int SVOff,
1542             unsigned alignment, bool isvolatile);
1543
1544   MemSDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps,
1545             MVT MemoryVT, const Value *srcValue, int SVOff,
1546             unsigned alignment, bool isvolatile);
1547
1548   /// Returns alignment and volatility of the memory access
1549   unsigned getAlignment() const { return (1u << (Flags >> 1)) >> 1; }
1550   bool isVolatile() const { return Flags & 1; }
1551   
1552   /// Returns the SrcValue and offset that describes the location of the access
1553   const Value *getSrcValue() const { return SrcValue; }
1554   int getSrcValueOffset() const { return SVOffset; }
1555   
1556   /// getMemoryVT - Return the type of the in-memory value.
1557   MVT getMemoryVT() const { return MemoryVT; }
1558     
1559   /// getMemOperand - Return a MachineMemOperand object describing the memory
1560   /// reference performed by operation.
1561   MachineMemOperand getMemOperand() const;
1562
1563   const SDValue &getChain() const { return getOperand(0); }
1564   const SDValue &getBasePtr() const {
1565     return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1566   }
1567
1568   /// getRawFlags - Represent the flags as a bunch of bits.
1569   ///
1570   unsigned getRawFlags() const { return Flags; }
1571
1572   // Methods to support isa and dyn_cast
1573   static bool classof(const MemSDNode *) { return true; }
1574   static bool classof(const SDNode *N) {
1575     // For some targets, we lower some target intrinsics to a MemIntrinsicNode
1576     // with either an intrinsic or a target opcode.
1577     return N->getOpcode() == ISD::LOAD                ||
1578            N->getOpcode() == ISD::STORE               ||
1579            N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
1580            N->getOpcode() == ISD::ATOMIC_SWAP         ||
1581            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
1582            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
1583            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
1584            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
1585            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
1586            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
1587            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
1588            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
1589            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
1590            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
1591            N->getOpcode() == ISD::INTRINSIC_W_CHAIN   ||
1592            N->getOpcode() == ISD::INTRINSIC_VOID      ||
1593            N->isTargetOpcode();
1594   }  
1595 };
1596
1597 /// AtomicSDNode - A SDNode reprenting atomic operations.
1598 ///
1599 class AtomicSDNode : public MemSDNode {
1600   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1601   SDUse Ops[4];
1602   
1603  public:
1604   // Opc:   opcode for atomic
1605   // VTL:    value type list
1606   // Chain:  memory chain for operaand
1607   // Ptr:    address to update as a SDValue
1608   // Cmp:    compare value
1609   // Swp:    swap value
1610   // SrcVal: address to update as a Value (used for MemOperand)
1611   // Align:  alignment of memory
1612   AtomicSDNode(unsigned Opc, SDVTList VTL, MVT MemVT,
1613                SDValue Chain, SDValue Ptr,
1614                SDValue Cmp, SDValue Swp, const Value* SrcVal,
1615                unsigned Align=0)
1616     : MemSDNode(Opc, VTL, MemVT, SrcVal, /*SVOffset=*/0,
1617                 Align, /*isVolatile=*/true) {
1618     Ops[0] = Chain;
1619     Ops[1] = Ptr;
1620     Ops[2] = Cmp;
1621     Ops[3] = Swp;
1622     InitOperands(Ops, 4);
1623   }
1624   AtomicSDNode(unsigned Opc, SDVTList VTL, MVT MemVT,
1625                SDValue Chain, SDValue Ptr, 
1626                SDValue Val, const Value* SrcVal, unsigned Align=0)
1627     : MemSDNode(Opc, VTL, MemVT, SrcVal, /*SVOffset=*/0,
1628                 Align, /*isVolatile=*/true) {
1629     Ops[0] = Chain;
1630     Ops[1] = Ptr;
1631     Ops[2] = Val;
1632     InitOperands(Ops, 3);
1633   }
1634   
1635   const SDValue &getBasePtr() const { return getOperand(1); }
1636   const SDValue &getVal() const { return getOperand(2); }
1637
1638   bool isCompareAndSwap() const { 
1639     unsigned Op = getOpcode(); 
1640     return Op == ISD::ATOMIC_CMP_SWAP;
1641   }
1642
1643   // Methods to support isa and dyn_cast
1644   static bool classof(const AtomicSDNode *) { return true; }
1645   static bool classof(const SDNode *N) {
1646     return N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
1647            N->getOpcode() == ISD::ATOMIC_SWAP         ||
1648            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
1649            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
1650            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
1651            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
1652            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
1653            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
1654            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
1655            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
1656            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
1657            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX;
1658   }
1659 };
1660
1661 /// MemIntrinsicSDNode - This SDNode is used for target intrinsic that touches
1662 /// memory and need an associated memory operand.
1663 ///
1664 class MemIntrinsicSDNode : public MemSDNode {
1665   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.  
1666   bool ReadMem;  // Intrinsic reads memory
1667   bool WriteMem; // Intrinsic writes memory
1668 public:
1669   MemIntrinsicSDNode(unsigned Opc, SDVTList VTs,
1670                      const SDValue *Ops, unsigned NumOps,
1671                      MVT MemoryVT, const Value *srcValue, int SVO,
1672                      unsigned Align, bool Vol, bool ReadMem, bool WriteMem)
1673     : MemSDNode(Opc, VTs, Ops, NumOps, MemoryVT, srcValue, SVO, Align, Vol),
1674       ReadMem(ReadMem), WriteMem(WriteMem) {
1675   }
1676
1677   bool readMem() const { return ReadMem; }
1678   bool writeMem() const { return WriteMem; }
1679
1680   // Methods to support isa and dyn_cast
1681   static bool classof(const MemIntrinsicSDNode *) { return true; }
1682   static bool classof(const SDNode *N) {
1683     // We lower some target intrinsics to their target opcode
1684     // early a node with a target opcode can be of this class
1685     return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1686            N->getOpcode() == ISD::INTRINSIC_VOID ||
1687            N->isTargetOpcode();
1688   }
1689 };
1690
1691 class ConstantSDNode : public SDNode {
1692   const ConstantInt *Value;
1693   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1694 protected:
1695   friend class SelectionDAG;
1696   ConstantSDNode(bool isTarget, const ConstantInt *val, MVT VT)
1697     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1698       Value(val) {
1699   }
1700 public:
1701
1702   const ConstantInt *getConstantIntValue() const { return Value; }
1703   const APInt &getAPIntValue() const { return Value->getValue(); }
1704   uint64_t getZExtValue() const { return Value->getZExtValue(); }
1705   int64_t getSExtValue() const { return Value->getSExtValue(); }
1706
1707   bool isNullValue() const { return Value->isNullValue(); }
1708   bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1709
1710   static bool classof(const ConstantSDNode *) { return true; }
1711   static bool classof(const SDNode *N) {
1712     return N->getOpcode() == ISD::Constant ||
1713            N->getOpcode() == ISD::TargetConstant;
1714   }
1715 };
1716
1717 class ConstantFPSDNode : public SDNode {
1718   const ConstantFP *Value;
1719   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1720 protected:
1721   friend class SelectionDAG;
1722   ConstantFPSDNode(bool isTarget, const ConstantFP *val, MVT VT)
1723     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1724              getSDVTList(VT)), Value(val) {
1725   }
1726 public:
1727
1728   const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1729   const ConstantFP *getConstantFPValue() const { return Value; }
1730
1731   /// isExactlyValue - We don't rely on operator== working on double values, as
1732   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1733   /// As such, this method can be used to do an exact bit-for-bit comparison of
1734   /// two floating point values.
1735
1736   /// We leave the version with the double argument here because it's just so
1737   /// convenient to write "2.0" and the like.  Without this function we'd 
1738   /// have to duplicate its logic everywhere it's called.
1739   bool isExactlyValue(double V) const {
1740     bool ignored;
1741     // convert is not supported on this type
1742     if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
1743       return false;
1744     APFloat Tmp(V);
1745     Tmp.convert(Value->getValueAPF().getSemantics(),
1746                 APFloat::rmNearestTiesToEven, &ignored);
1747     return isExactlyValue(Tmp);
1748   }
1749   bool isExactlyValue(const APFloat& V) const;
1750
1751   bool isValueValidForType(MVT VT, const APFloat& Val);
1752
1753   static bool classof(const ConstantFPSDNode *) { return true; }
1754   static bool classof(const SDNode *N) {
1755     return N->getOpcode() == ISD::ConstantFP || 
1756            N->getOpcode() == ISD::TargetConstantFP;
1757   }
1758 };
1759
1760 class GlobalAddressSDNode : public SDNode {
1761   GlobalValue *TheGlobal;
1762   int64_t Offset;
1763   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1764 protected:
1765   friend class SelectionDAG;
1766   GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT,
1767                       int64_t o = 0);
1768 public:
1769
1770   GlobalValue *getGlobal() const { return TheGlobal; }
1771   int64_t getOffset() const { return Offset; }
1772
1773   static bool classof(const GlobalAddressSDNode *) { return true; }
1774   static bool classof(const SDNode *N) {
1775     return N->getOpcode() == ISD::GlobalAddress ||
1776            N->getOpcode() == ISD::TargetGlobalAddress ||
1777            N->getOpcode() == ISD::GlobalTLSAddress ||
1778            N->getOpcode() == ISD::TargetGlobalTLSAddress;
1779   }
1780 };
1781
1782 class FrameIndexSDNode : public SDNode {
1783   int FI;
1784   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1785 protected:
1786   friend class SelectionDAG;
1787   FrameIndexSDNode(int fi, MVT VT, bool isTarg)
1788     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1789       FI(fi) {
1790   }
1791 public:
1792
1793   int getIndex() const { return FI; }
1794
1795   static bool classof(const FrameIndexSDNode *) { return true; }
1796   static bool classof(const SDNode *N) {
1797     return N->getOpcode() == ISD::FrameIndex ||
1798            N->getOpcode() == ISD::TargetFrameIndex;
1799   }
1800 };
1801
1802 class JumpTableSDNode : public SDNode {
1803   int JTI;
1804   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1805 protected:
1806   friend class SelectionDAG;
1807   JumpTableSDNode(int jti, MVT VT, bool isTarg)
1808     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1809       JTI(jti) {
1810   }
1811 public:
1812     
1813   int getIndex() const { return JTI; }
1814   
1815   static bool classof(const JumpTableSDNode *) { return true; }
1816   static bool classof(const SDNode *N) {
1817     return N->getOpcode() == ISD::JumpTable ||
1818            N->getOpcode() == ISD::TargetJumpTable;
1819   }
1820 };
1821
1822 class ConstantPoolSDNode : public SDNode {
1823   union {
1824     Constant *ConstVal;
1825     MachineConstantPoolValue *MachineCPVal;
1826   } Val;
1827   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1828   unsigned Alignment;
1829   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1830 protected:
1831   friend class SelectionDAG;
1832   ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0)
1833     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1834              getSDVTList(VT)), Offset(o), Alignment(0) {
1835     assert((int)Offset >= 0 && "Offset is too large");
1836     Val.ConstVal = c;
1837   }
1838   ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o, unsigned Align)
1839     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1840              getSDVTList(VT)), Offset(o), Alignment(Align) {
1841     assert((int)Offset >= 0 && "Offset is too large");
1842     Val.ConstVal = c;
1843   }
1844   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1845                      MVT VT, int o=0)
1846     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1847              getSDVTList(VT)), Offset(o), Alignment(0) {
1848     assert((int)Offset >= 0 && "Offset is too large");
1849     Val.MachineCPVal = v;
1850     Offset |= 1 << (sizeof(unsigned)*8-1);
1851   }
1852   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1853                      MVT VT, int o, unsigned Align)
1854     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1855              getSDVTList(VT)), Offset(o), Alignment(Align) {
1856     assert((int)Offset >= 0 && "Offset is too large");
1857     Val.MachineCPVal = v;
1858     Offset |= 1 << (sizeof(unsigned)*8-1);
1859   }
1860 public:
1861
1862   bool isMachineConstantPoolEntry() const {
1863     return (int)Offset < 0;
1864   }
1865
1866   Constant *getConstVal() const {
1867     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1868     return Val.ConstVal;
1869   }
1870
1871   MachineConstantPoolValue *getMachineCPVal() const {
1872     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1873     return Val.MachineCPVal;
1874   }
1875
1876   int getOffset() const {
1877     return Offset & ~(1 << (sizeof(unsigned)*8-1));
1878   }
1879   
1880   // Return the alignment of this constant pool object, which is either 0 (for
1881   // default alignment) or log2 of the desired value.
1882   unsigned getAlignment() const { return Alignment; }
1883
1884   const Type *getType() const;
1885
1886   static bool classof(const ConstantPoolSDNode *) { return true; }
1887   static bool classof(const SDNode *N) {
1888     return N->getOpcode() == ISD::ConstantPool ||
1889            N->getOpcode() == ISD::TargetConstantPool;
1890   }
1891 };
1892
1893 class BasicBlockSDNode : public SDNode {
1894   MachineBasicBlock *MBB;
1895   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1896 protected:
1897   friend class SelectionDAG;
1898   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1899     : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1900   }
1901 public:
1902
1903   MachineBasicBlock *getBasicBlock() const { return MBB; }
1904
1905   static bool classof(const BasicBlockSDNode *) { return true; }
1906   static bool classof(const SDNode *N) {
1907     return N->getOpcode() == ISD::BasicBlock;
1908   }
1909 };
1910
1911 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1912 /// used when the SelectionDAG needs to make a simple reference to something
1913 /// in the LLVM IR representation.
1914 ///
1915 /// Note that this is not used for carrying alias information; that is done
1916 /// with MemOperandSDNode, which includes a Value which is required to be a
1917 /// pointer, and several other fields specific to memory references.
1918 ///
1919 class SrcValueSDNode : public SDNode {
1920   const Value *V;
1921   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1922 protected:
1923   friend class SelectionDAG;
1924   /// Create a SrcValue for a general value.
1925   explicit SrcValueSDNode(const Value *v)
1926     : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1927
1928 public:
1929   /// getValue - return the contained Value.
1930   const Value *getValue() const { return V; }
1931
1932   static bool classof(const SrcValueSDNode *) { return true; }
1933   static bool classof(const SDNode *N) {
1934     return N->getOpcode() == ISD::SRCVALUE;
1935   }
1936 };
1937
1938
1939 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
1940 /// used to represent a reference to memory after ISD::LOAD
1941 /// and ISD::STORE have been lowered.
1942 ///
1943 class MemOperandSDNode : public SDNode {
1944   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1945 protected:
1946   friend class SelectionDAG;
1947   /// Create a MachineMemOperand node
1948   explicit MemOperandSDNode(const MachineMemOperand &mo)
1949     : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1950
1951 public:
1952   /// MO - The contained MachineMemOperand.
1953   const MachineMemOperand MO;
1954
1955   static bool classof(const MemOperandSDNode *) { return true; }
1956   static bool classof(const SDNode *N) {
1957     return N->getOpcode() == ISD::MEMOPERAND;
1958   }
1959 };
1960
1961
1962 class RegisterSDNode : public SDNode {
1963   unsigned Reg;
1964   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1965 protected:
1966   friend class SelectionDAG;
1967   RegisterSDNode(unsigned reg, MVT VT)
1968     : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1969   }
1970 public:
1971
1972   unsigned getReg() const { return Reg; }
1973
1974   static bool classof(const RegisterSDNode *) { return true; }
1975   static bool classof(const SDNode *N) {
1976     return N->getOpcode() == ISD::Register;
1977   }
1978 };
1979
1980 class DbgStopPointSDNode : public SDNode {
1981   SDUse Chain;
1982   unsigned Line;
1983   unsigned Column;
1984   const CompileUnitDesc *CU;
1985   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1986 protected:
1987   friend class SelectionDAG;
1988   DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
1989                      const CompileUnitDesc *cu)
1990     : SDNode(ISD::DBG_STOPPOINT, getSDVTList(MVT::Other)),
1991       Line(l), Column(c), CU(cu) {
1992     Chain = ch;
1993     InitOperands(&Chain, 1);
1994   }
1995 public:
1996   unsigned getLine() const { return Line; }
1997   unsigned getColumn() const { return Column; }
1998   const CompileUnitDesc *getCompileUnit() const { return CU; }
1999
2000   static bool classof(const DbgStopPointSDNode *) { return true; }
2001   static bool classof(const SDNode *N) {
2002     return N->getOpcode() == ISD::DBG_STOPPOINT;
2003   }
2004 };
2005
2006 class LabelSDNode : public SDNode {
2007   SDUse Chain;
2008   unsigned LabelID;
2009   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2010 protected:
2011   friend class SelectionDAG;
2012   LabelSDNode(unsigned NodeTy, SDValue ch, unsigned id)
2013     : SDNode(NodeTy, getSDVTList(MVT::Other)), LabelID(id) {
2014     Chain = ch;
2015     InitOperands(&Chain, 1);
2016   }
2017 public:
2018   unsigned getLabelID() const { return LabelID; }
2019
2020   static bool classof(const LabelSDNode *) { return true; }
2021   static bool classof(const SDNode *N) {
2022     return N->getOpcode() == ISD::DBG_LABEL ||
2023            N->getOpcode() == ISD::EH_LABEL;
2024   }
2025 };
2026
2027 class ExternalSymbolSDNode : public SDNode {
2028   const char *Symbol;
2029   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2030 protected:
2031   friend class SelectionDAG;
2032   ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT VT)
2033     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
2034              getSDVTList(VT)), Symbol(Sym) {
2035   }
2036 public:
2037
2038   const char *getSymbol() const { return Symbol; }
2039
2040   static bool classof(const ExternalSymbolSDNode *) { return true; }
2041   static bool classof(const SDNode *N) {
2042     return N->getOpcode() == ISD::ExternalSymbol ||
2043            N->getOpcode() == ISD::TargetExternalSymbol;
2044   }
2045 };
2046
2047 class CondCodeSDNode : public SDNode {
2048   ISD::CondCode Condition;
2049   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2050 protected:
2051   friend class SelectionDAG;
2052   explicit CondCodeSDNode(ISD::CondCode Cond)
2053     : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
2054   }
2055 public:
2056
2057   ISD::CondCode get() const { return Condition; }
2058
2059   static bool classof(const CondCodeSDNode *) { return true; }
2060   static bool classof(const SDNode *N) {
2061     return N->getOpcode() == ISD::CONDCODE;
2062   }
2063 };
2064
2065 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
2066 /// future and most targets don't support it.
2067 class CvtRndSatSDNode : public SDNode {
2068   ISD::CvtCode CvtCode;
2069   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2070 protected:
2071   friend class SelectionDAG;
2072   explicit CvtRndSatSDNode(MVT VT, const SDValue *Ops, unsigned NumOps,
2073                            ISD::CvtCode Code)
2074     : SDNode(ISD::CONVERT_RNDSAT, getSDVTList(VT), Ops, NumOps), CvtCode(Code) {
2075     assert(NumOps == 5 && "wrong number of operations");
2076   }
2077 public:
2078   ISD::CvtCode getCvtCode() const { return CvtCode; }
2079
2080   static bool classof(const CvtRndSatSDNode *) { return true; }
2081   static bool classof(const SDNode *N) {
2082     return N->getOpcode() == ISD::CONVERT_RNDSAT;
2083   }
2084 };
2085
2086 namespace ISD {
2087   struct ArgFlagsTy {
2088   private:
2089     static const uint64_t NoFlagSet      = 0ULL;
2090     static const uint64_t ZExt           = 1ULL<<0;  ///< Zero extended
2091     static const uint64_t ZExtOffs       = 0;
2092     static const uint64_t SExt           = 1ULL<<1;  ///< Sign extended
2093     static const uint64_t SExtOffs       = 1;
2094     static const uint64_t InReg          = 1ULL<<2;  ///< Passed in register
2095     static const uint64_t InRegOffs      = 2;
2096     static const uint64_t SRet           = 1ULL<<3;  ///< Hidden struct-ret ptr
2097     static const uint64_t SRetOffs       = 3;
2098     static const uint64_t ByVal          = 1ULL<<4;  ///< Struct passed by value
2099     static const uint64_t ByValOffs      = 4;
2100     static const uint64_t Nest           = 1ULL<<5;  ///< Nested fn static chain
2101     static const uint64_t NestOffs       = 5;
2102     static const uint64_t ByValAlign     = 0xFULL << 6; //< Struct alignment
2103     static const uint64_t ByValAlignOffs = 6;
2104     static const uint64_t Split          = 1ULL << 10;
2105     static const uint64_t SplitOffs      = 10;
2106     static const uint64_t OrigAlign      = 0x1FULL<<27;
2107     static const uint64_t OrigAlignOffs  = 27;
2108     static const uint64_t ByValSize      = 0xffffffffULL << 32; //< Struct size
2109     static const uint64_t ByValSizeOffs  = 32;
2110
2111     static const uint64_t One            = 1ULL; //< 1 of this type, for shifts
2112
2113     uint64_t Flags;
2114   public:
2115     ArgFlagsTy() : Flags(0) { }
2116
2117     bool isZExt()   const { return Flags & ZExt; }
2118     void setZExt()  { Flags |= One << ZExtOffs; }
2119
2120     bool isSExt()   const { return Flags & SExt; }
2121     void setSExt()  { Flags |= One << SExtOffs; }
2122
2123     bool isInReg()  const { return Flags & InReg; }
2124     void setInReg() { Flags |= One << InRegOffs; }
2125
2126     bool isSRet()   const { return Flags & SRet; }
2127     void setSRet()  { Flags |= One << SRetOffs; }
2128
2129     bool isByVal()  const { return Flags & ByVal; }
2130     void setByVal() { Flags |= One << ByValOffs; }
2131
2132     bool isNest()   const { return Flags & Nest; }
2133     void setNest()  { Flags |= One << NestOffs; }
2134
2135     unsigned getByValAlign() const {
2136       return (unsigned) 
2137         ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
2138     }
2139     void setByValAlign(unsigned A) {
2140       Flags = (Flags & ~ByValAlign) |
2141         (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
2142     }
2143             
2144     bool isSplit()   const { return Flags & Split; }
2145     void setSplit()  { Flags |= One << SplitOffs; }
2146
2147     unsigned getOrigAlign() const {
2148       return (unsigned)
2149         ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
2150     }
2151     void setOrigAlign(unsigned A) {
2152       Flags = (Flags & ~OrigAlign) |
2153         (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
2154     }
2155
2156     unsigned getByValSize() const {
2157       return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
2158     }
2159     void setByValSize(unsigned S) {
2160       Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
2161     }
2162
2163     /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
2164     std::string getArgFlagsString();
2165
2166     /// getRawBits - Represent the flags as a bunch of bits.
2167     uint64_t getRawBits() const { return Flags; }
2168   };
2169 }
2170
2171 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
2172 class ARG_FLAGSSDNode : public SDNode {
2173   ISD::ArgFlagsTy TheFlags;
2174   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2175 protected:
2176   friend class SelectionDAG;
2177   explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
2178     : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
2179   }
2180 public:
2181   ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
2182
2183   static bool classof(const ARG_FLAGSSDNode *) { return true; }
2184   static bool classof(const SDNode *N) {
2185     return N->getOpcode() == ISD::ARG_FLAGS;
2186   }
2187 };
2188
2189 /// CallSDNode - Node for calls -- ISD::CALL.
2190 class CallSDNode : public SDNode {
2191   unsigned CallingConv;
2192   bool IsVarArg;
2193   bool IsTailCall;
2194   // We might eventually want a full-blown Attributes for the result; that
2195   // will expand the size of the representation.  At the moment we only
2196   // need Inreg.
2197   bool Inreg;
2198   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2199 protected:
2200   friend class SelectionDAG;
2201   CallSDNode(unsigned cc, bool isvararg, bool istailcall, bool isinreg,
2202              SDVTList VTs, const SDValue *Operands, unsigned numOperands)
2203     : SDNode(ISD::CALL, VTs, Operands, numOperands),
2204       CallingConv(cc), IsVarArg(isvararg), IsTailCall(istailcall),
2205       Inreg(isinreg) {}
2206 public:
2207   unsigned getCallingConv() const { return CallingConv; }
2208   unsigned isVarArg() const { return IsVarArg; }
2209   unsigned isTailCall() const { return IsTailCall; }
2210   unsigned isInreg() const { return Inreg; }
2211
2212   /// Set this call to not be marked as a tail call. Normally setter
2213   /// methods in SDNodes are unsafe because it breaks the CSE map,
2214   /// but we don't include the tail call flag for calls so it's ok
2215   /// in this case.
2216   void setNotTailCall() { IsTailCall = false; }
2217
2218   SDValue getChain() const { return getOperand(0); }
2219   SDValue getCallee() const { return getOperand(1); }
2220
2221   unsigned getNumArgs() const { return (getNumOperands() - 2) / 2; }
2222   SDValue getArg(unsigned i) const { return getOperand(2+2*i); }
2223   SDValue getArgFlagsVal(unsigned i) const {
2224     return getOperand(3+2*i);
2225   }
2226   ISD::ArgFlagsTy getArgFlags(unsigned i) const {
2227     return cast<ARG_FLAGSSDNode>(getArgFlagsVal(i).getNode())->getArgFlags();
2228   }
2229
2230   unsigned getNumRetVals() const { return getNumValues() - 1; }
2231   MVT getRetValType(unsigned i) const { return getValueType(i); }
2232
2233   static bool classof(const CallSDNode *) { return true; }
2234   static bool classof(const SDNode *N) {
2235     return N->getOpcode() == ISD::CALL;
2236   }
2237 };
2238
2239 /// VTSDNode - This class is used to represent MVT's, which are used
2240 /// to parameterize some operations.
2241 class VTSDNode : public SDNode {
2242   MVT ValueType;
2243   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2244 protected:
2245   friend class SelectionDAG;
2246   explicit VTSDNode(MVT VT)
2247     : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
2248   }
2249 public:
2250
2251   MVT getVT() const { return ValueType; }
2252
2253   static bool classof(const VTSDNode *) { return true; }
2254   static bool classof(const SDNode *N) {
2255     return N->getOpcode() == ISD::VALUETYPE;
2256   }
2257 };
2258
2259 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
2260 ///
2261 class LSBaseSDNode : public MemSDNode {
2262 protected:
2263   //! Operand array for load and store
2264   /*!
2265     \note Moving this array to the base class captures more
2266     common functionality shared between LoadSDNode and
2267     StoreSDNode
2268    */
2269   SDUse Ops[4];
2270 public:
2271   LSBaseSDNode(ISD::NodeType NodeTy, SDValue *Operands, unsigned numOperands,
2272                SDVTList VTs, ISD::MemIndexedMode AM, MVT VT,
2273                const Value *SV, int SVO, unsigned Align, bool Vol)
2274     : MemSDNode(NodeTy, VTs, VT, SV, SVO, Align, Vol) {
2275     SubclassData = AM;
2276     for (unsigned i = 0; i != numOperands; ++i)
2277       Ops[i] = Operands[i];
2278     InitOperands(Ops, numOperands);
2279     assert(Align != 0 && "Loads and stores should have non-zero aligment");
2280     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
2281            "Only indexed loads and stores have a non-undef offset operand");
2282   }
2283
2284   const SDValue &getOffset() const {
2285     return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2286   }
2287
2288   /// getAddressingMode - Return the addressing mode for this load or store:
2289   /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2290   ISD::MemIndexedMode getAddressingMode() const {
2291     return ISD::MemIndexedMode(SubclassData & 7);
2292   }
2293
2294   /// isIndexed - Return true if this is a pre/post inc/dec load/store.
2295   bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2296
2297   /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
2298   bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2299
2300   static bool classof(const LSBaseSDNode *) { return true; }
2301   static bool classof(const SDNode *N) {
2302     return N->getOpcode() == ISD::LOAD ||
2303            N->getOpcode() == ISD::STORE;
2304   }
2305 };
2306
2307 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2308 ///
2309 class LoadSDNode : public LSBaseSDNode {
2310   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2311 protected:
2312   friend class SelectionDAG;
2313   LoadSDNode(SDValue *ChainPtrOff, SDVTList VTs,
2314              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT,
2315              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2316     : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
2317                    VTs, AM, LVT, SV, O, Align, Vol) {
2318     SubclassData |= (unsigned short)ETy << 3;
2319   }
2320 public:
2321
2322   /// getExtensionType - Return whether this is a plain node,
2323   /// or one of the varieties of value-extending loads.
2324   ISD::LoadExtType getExtensionType() const {
2325     return ISD::LoadExtType((SubclassData >> 3) & 3);
2326   }
2327
2328   const SDValue &getBasePtr() const { return getOperand(1); }
2329   const SDValue &getOffset() const { return getOperand(2); }
2330   
2331   static bool classof(const LoadSDNode *) { return true; }
2332   static bool classof(const SDNode *N) {
2333     return N->getOpcode() == ISD::LOAD;
2334   }
2335 };
2336
2337 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2338 ///
2339 class StoreSDNode : public LSBaseSDNode {
2340   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2341 protected:
2342   friend class SelectionDAG;
2343   StoreSDNode(SDValue *ChainValuePtrOff, SDVTList VTs,
2344               ISD::MemIndexedMode AM, bool isTrunc, MVT SVT,
2345               const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2346     : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
2347                    VTs, AM, SVT, SV, O, Align, Vol) {
2348     SubclassData |= (unsigned short)isTrunc << 3;
2349   }
2350 public:
2351
2352   /// isTruncatingStore - Return true if the op does a truncation before store.
2353   /// For integers this is the same as doing a TRUNCATE and storing the result.
2354   /// For floats, it is the same as doing an FP_ROUND and storing the result.
2355   bool isTruncatingStore() const { return (SubclassData >> 3) & 1; }
2356
2357   const SDValue &getValue() const { return getOperand(1); }
2358   const SDValue &getBasePtr() const { return getOperand(2); }
2359   const SDValue &getOffset() const { return getOperand(3); }
2360   
2361   static bool classof(const StoreSDNode *) { return true; }
2362   static bool classof(const SDNode *N) {
2363     return N->getOpcode() == ISD::STORE;
2364   }
2365 };
2366
2367
2368 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
2369   SDNode *Node;
2370   unsigned Operand;
2371
2372   SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2373 public:
2374   bool operator==(const SDNodeIterator& x) const {
2375     return Operand == x.Operand;
2376   }
2377   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2378
2379   const SDNodeIterator &operator=(const SDNodeIterator &I) {
2380     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2381     Operand = I.Operand;
2382     return *this;
2383   }
2384
2385   pointer operator*() const {
2386     return Node->getOperand(Operand).getNode();
2387   }
2388   pointer operator->() const { return operator*(); }
2389
2390   SDNodeIterator& operator++() {                // Preincrement
2391     ++Operand;
2392     return *this;
2393   }
2394   SDNodeIterator operator++(int) { // Postincrement
2395     SDNodeIterator tmp = *this; ++*this; return tmp;
2396   }
2397
2398   static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2399   static SDNodeIterator end  (SDNode *N) {
2400     return SDNodeIterator(N, N->getNumOperands());
2401   }
2402
2403   unsigned getOperand() const { return Operand; }
2404   const SDNode *getNode() const { return Node; }
2405 };
2406
2407 template <> struct GraphTraits<SDNode*> {
2408   typedef SDNode NodeType;
2409   typedef SDNodeIterator ChildIteratorType;
2410   static inline NodeType *getEntryNode(SDNode *N) { return N; }
2411   static inline ChildIteratorType child_begin(NodeType *N) {
2412     return SDNodeIterator::begin(N);
2413   }
2414   static inline ChildIteratorType child_end(NodeType *N) {
2415     return SDNodeIterator::end(N);
2416   }
2417 };
2418
2419 /// LargestSDNode - The largest SDNode class.
2420 ///
2421 typedef LoadSDNode LargestSDNode;
2422
2423 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2424 /// requirement.
2425 ///
2426 typedef ARG_FLAGSSDNode MostAlignedSDNode;
2427
2428 namespace ISD {
2429   /// isNormalLoad - Returns true if the specified node is a non-extending
2430   /// and unindexed load.
2431   inline bool isNormalLoad(const SDNode *N) {
2432     const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2433     return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2434       Ld->getAddressingMode() == ISD::UNINDEXED;
2435   }
2436
2437   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2438   /// load.
2439   inline bool isNON_EXTLoad(const SDNode *N) {
2440     return isa<LoadSDNode>(N) &&
2441       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2442   }
2443
2444   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2445   ///
2446   inline bool isEXTLoad(const SDNode *N) {
2447     return isa<LoadSDNode>(N) &&
2448       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2449   }
2450
2451   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2452   ///
2453   inline bool isSEXTLoad(const SDNode *N) {
2454     return isa<LoadSDNode>(N) &&
2455       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2456   }
2457
2458   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2459   ///
2460   inline bool isZEXTLoad(const SDNode *N) {
2461     return isa<LoadSDNode>(N) &&
2462       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2463   }
2464
2465   /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2466   ///
2467   inline bool isUNINDEXEDLoad(const SDNode *N) {
2468     return isa<LoadSDNode>(N) &&
2469       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2470   }
2471
2472   /// isNormalStore - Returns true if the specified node is a non-truncating
2473   /// and unindexed store.
2474   inline bool isNormalStore(const SDNode *N) {
2475     const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2476     return St && !St->isTruncatingStore() &&
2477       St->getAddressingMode() == ISD::UNINDEXED;
2478   }
2479
2480   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2481   /// store.
2482   inline bool isNON_TRUNCStore(const SDNode *N) {
2483     return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2484   }
2485
2486   /// isTRUNCStore - Returns true if the specified node is a truncating
2487   /// store.
2488   inline bool isTRUNCStore(const SDNode *N) {
2489     return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2490   }
2491
2492   /// isUNINDEXEDStore - Returns true if the specified node is an
2493   /// unindexed store.
2494   inline bool isUNINDEXEDStore(const SDNode *N) {
2495     return isa<StoreSDNode>(N) &&
2496       cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2497   }
2498 }
2499
2500
2501 } // end llvm namespace
2502
2503 #endif