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