Fix an issue where a use might be selected before a def, and then we didn't respect...
[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     // FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR - Perform various unary floating
430     // point operations. These are inspired by libm.
431     FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
432     FCEIL, FTRUNC, FRINT, FNEARBYINT, FFLOOR,
433     
434     // LOAD and STORE have token chains as their first operand, then the same
435     // operands as an LLVM load/store instruction, then an offset node that
436     // is added / subtracted from the base pointer to form the address (for
437     // indexed memory ops).
438     LOAD, STORE,
439
440     // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
441     // to a specified boundary.  This node always has two return values: a new
442     // stack pointer value and a chain. The first operand is the token chain,
443     // the second is the number of bytes to allocate, and the third is the
444     // alignment boundary.  The size is guaranteed to be a multiple of the stack
445     // alignment, and the alignment is guaranteed to be bigger than the stack
446     // alignment (if required) or 0 to get standard stack alignment.
447     DYNAMIC_STACKALLOC,
448
449     // Control flow instructions.  These all have token chains.
450
451     // BR - Unconditional branch.  The first operand is the chain
452     // operand, the second is the MBB to branch to.
453     BR,
454
455     // BRIND - Indirect branch.  The first operand is the chain, the second
456     // is the value to branch to, which must be of the same type as the target's
457     // pointer type.
458     BRIND,
459
460     // BR_JT - Jumptable branch. The first operand is the chain, the second
461     // is the jumptable index, the last one is the jumptable entry index.
462     BR_JT,
463     
464     // BRCOND - Conditional branch.  The first operand is the chain,
465     // the second is the condition, the third is the block to branch
466     // to if the condition is true.
467     BRCOND,
468
469     // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
470     // that the condition is represented as condition code, and two nodes to
471     // compare, rather than as a combined SetCC node.  The operands in order are
472     // chain, cc, lhs, rhs, block to branch to if condition is true.
473     BR_CC,
474     
475     // RET - Return from function.  The first operand is the chain,
476     // and any subsequent operands are pairs of return value and return value
477     // signness for the function.  This operation can have variable number of
478     // operands.
479     RET,
480
481     // INLINEASM - Represents an inline asm block.  This node always has two
482     // return values: a chain and a flag result.  The inputs are as follows:
483     //   Operand #0   : Input chain.
484     //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
485     //   Operand #2n+2: A RegisterNode.
486     //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
487     //   Operand #last: Optional, an incoming flag.
488     INLINEASM,
489     
490     // DBG_LABEL, EH_LABEL - Represents a label in mid basic block used to track
491     // locations needed for debug and exception handling tables.  These nodes
492     // take a chain as input and return a chain.
493     DBG_LABEL,
494     EH_LABEL,
495
496     // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
497     // local variable declarations for debugging information. First operand is
498     // a chain, while the next two operands are first two arguments (address
499     // and variable) of a llvm.dbg.declare instruction.
500     DECLARE,
501     
502     // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
503     // value, the same type as the pointer type for the system, and an output
504     // chain.
505     STACKSAVE,
506     
507     // STACKRESTORE has two operands, an input chain and a pointer to restore to
508     // it returns an output chain.
509     STACKRESTORE,
510     
511     // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
512     // a call sequence, and carry arbitrary information that target might want
513     // to know.  The first operand is a chain, the rest are specified by the
514     // target and not touched by the DAG optimizers.
515     // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
516     CALLSEQ_START,  // Beginning of a call sequence
517     CALLSEQ_END,    // End of a call sequence
518     
519     // VAARG - VAARG has three operands: an input chain, a pointer, and a 
520     // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
521     VAARG,
522     
523     // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
524     // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
525     // source.
526     VACOPY,
527     
528     // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
529     // pointer, and a SRCVALUE.
530     VAEND, VASTART,
531
532     // SRCVALUE - This is a node type that holds a Value* that is used to
533     // make reference to a value in the LLVM IR.
534     SRCVALUE,
535
536     // MEMOPERAND - This is a node that contains a MachineMemOperand which
537     // records information about a memory reference. This is used to make
538     // AliasAnalysis queries from the backend.
539     MEMOPERAND,
540
541     // PCMARKER - This corresponds to the pcmarker intrinsic.
542     PCMARKER,
543
544     // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
545     // The only operand is a chain and a value and a chain are produced.  The
546     // value is the contents of the architecture specific cycle counter like 
547     // register (or other high accuracy low latency clock source)
548     READCYCLECOUNTER,
549
550     // HANDLENODE node - Used as a handle for various purposes.
551     HANDLENODE,
552
553     // DBG_STOPPOINT - This node is used to represent a source location for
554     // debug info.  It takes token chain as input, and carries a line number,
555     // column number, and a pointer to a CompileUnitDesc object identifying
556     // the containing compilation unit.  It produces a token chain as output.
557     DBG_STOPPOINT,
558     
559     // DEBUG_LOC - This node is used to represent source line information
560     // embedded in the code.  It takes a token chain as input, then a line
561     // number, then a column then a file id (provided by MachineModuleInfo.) It
562     // produces a token chain as output.
563     DEBUG_LOC,
564
565     // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
566     // It takes as input a token chain, the pointer to the trampoline,
567     // the pointer to the nested function, the pointer to pass for the
568     // 'nest' parameter, a SRCVALUE for the trampoline and another for
569     // the nested function (allowing targets to access the original
570     // Function*).  It produces the result of the intrinsic and a token
571     // chain as output.
572     TRAMPOLINE,
573
574     // TRAP - Trapping instruction
575     TRAP,
576
577     // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
578     // their first operand. The other operands are the address to prefetch,
579     // read / write specifier, and locality specifier.
580     PREFETCH,
581
582     // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load, 
583     //                       store-store, device)
584     // This corresponds to the memory.barrier intrinsic.
585     // it takes an input chain, 4 operands to specify the type of barrier, an
586     // operand specifying if the barrier applies to device and uncached memory
587     // and produces an output chain.
588     MEMBARRIER,
589
590     // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap)
591     // this corresponds to the atomic.lcs intrinsic.
592     // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
593     // the return is always the original value in *ptr
594     ATOMIC_CMP_SWAP_8,
595     ATOMIC_CMP_SWAP_16,
596     ATOMIC_CMP_SWAP_32,
597     ATOMIC_CMP_SWAP_64,
598
599     // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
600     // this corresponds to the atomic.swap intrinsic.
601     // amt is stored to *ptr atomically.
602     // the return is always the original value in *ptr
603     ATOMIC_SWAP_8,
604     ATOMIC_SWAP_16,
605     ATOMIC_SWAP_32,
606     ATOMIC_SWAP_64,
607
608     // Val, OUTCHAIN = ATOMIC_L[OpName]S(INCHAIN, ptr, amt)
609     // this corresponds to the atomic.[OpName] intrinsic.
610     // op(*ptr, amt) is stored to *ptr atomically.
611     // the return is always the original value in *ptr
612     ATOMIC_LOAD_ADD_8,
613     ATOMIC_LOAD_SUB_8,
614     ATOMIC_LOAD_AND_8,
615     ATOMIC_LOAD_OR_8,
616     ATOMIC_LOAD_XOR_8,
617     ATOMIC_LOAD_NAND_8,
618     ATOMIC_LOAD_MIN_8,
619     ATOMIC_LOAD_MAX_8,
620     ATOMIC_LOAD_UMIN_8,
621     ATOMIC_LOAD_UMAX_8,
622     ATOMIC_LOAD_ADD_16,
623     ATOMIC_LOAD_SUB_16,
624     ATOMIC_LOAD_AND_16,
625     ATOMIC_LOAD_OR_16,
626     ATOMIC_LOAD_XOR_16,
627     ATOMIC_LOAD_NAND_16,
628     ATOMIC_LOAD_MIN_16,
629     ATOMIC_LOAD_MAX_16,
630     ATOMIC_LOAD_UMIN_16,
631     ATOMIC_LOAD_UMAX_16,
632     ATOMIC_LOAD_ADD_32,
633     ATOMIC_LOAD_SUB_32,
634     ATOMIC_LOAD_AND_32,
635     ATOMIC_LOAD_OR_32,
636     ATOMIC_LOAD_XOR_32,
637     ATOMIC_LOAD_NAND_32,
638     ATOMIC_LOAD_MIN_32,
639     ATOMIC_LOAD_MAX_32,
640     ATOMIC_LOAD_UMIN_32,
641     ATOMIC_LOAD_UMAX_32,
642     ATOMIC_LOAD_ADD_64,
643     ATOMIC_LOAD_SUB_64,
644     ATOMIC_LOAD_AND_64,
645     ATOMIC_LOAD_OR_64,
646     ATOMIC_LOAD_XOR_64,
647     ATOMIC_LOAD_NAND_64,
648     ATOMIC_LOAD_MIN_64,
649     ATOMIC_LOAD_MAX_64,
650     ATOMIC_LOAD_UMIN_64,
651     ATOMIC_LOAD_UMAX_64,
652     
653     // BUILTIN_OP_END - This must be the last enum value in this list.
654     BUILTIN_OP_END
655   };
656
657   /// Node predicates
658
659   /// isBuildVectorAllOnes - Return true if the specified node is a
660   /// BUILD_VECTOR where all of the elements are ~0 or undef.
661   bool isBuildVectorAllOnes(const SDNode *N);
662
663   /// isBuildVectorAllZeros - Return true if the specified node is a
664   /// BUILD_VECTOR where all of the elements are 0 or undef.
665   bool isBuildVectorAllZeros(const SDNode *N);
666
667   /// isScalarToVector - Return true if the specified node is a
668   /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
669   /// element is not an undef.
670   bool isScalarToVector(const SDNode *N);
671
672   /// isDebugLabel - Return true if the specified node represents a debug
673   /// label (i.e. ISD::DBG_LABEL or TargetInstrInfo::DBG_LABEL node).
674   bool isDebugLabel(const SDNode *N);
675   
676   //===--------------------------------------------------------------------===//
677   /// MemIndexedMode enum - This enum defines the load / store indexed 
678   /// addressing modes.
679   ///
680   /// UNINDEXED    "Normal" load / store. The effective address is already
681   ///              computed and is available in the base pointer. The offset
682   ///              operand is always undefined. In addition to producing a
683   ///              chain, an unindexed load produces one value (result of the
684   ///              load); an unindexed store does not produce a value.
685   ///
686   /// PRE_INC      Similar to the unindexed mode where the effective address is
687   /// PRE_DEC      the value of the base pointer add / subtract the offset.
688   ///              It considers the computation as being folded into the load /
689   ///              store operation (i.e. the load / store does the address
690   ///              computation as well as performing the memory transaction).
691   ///              The base operand is always undefined. In addition to
692   ///              producing a chain, pre-indexed load produces two values
693   ///              (result of the load and the result of the address
694   ///              computation); a pre-indexed store produces one value (result
695   ///              of the address computation).
696   ///
697   /// POST_INC     The effective address is the value of the base pointer. The
698   /// POST_DEC     value of the offset operand is then added to / subtracted
699   ///              from the base after memory transaction. In addition to
700   ///              producing a chain, post-indexed load produces two values
701   ///              (the result of the load and the result of the base +/- offset
702   ///              computation); a post-indexed store produces one value (the
703   ///              the result of the base +/- offset computation).
704   ///
705   enum MemIndexedMode {
706     UNINDEXED = 0,
707     PRE_INC,
708     PRE_DEC,
709     POST_INC,
710     POST_DEC,
711     LAST_INDEXED_MODE
712   };
713
714   //===--------------------------------------------------------------------===//
715   /// LoadExtType enum - This enum defines the three variants of LOADEXT
716   /// (load with extension).
717   ///
718   /// SEXTLOAD loads the integer operand and sign extends it to a larger
719   ///          integer result type.
720   /// ZEXTLOAD loads the integer operand and zero extends it to a larger
721   ///          integer result type.
722   /// EXTLOAD  is used for three things: floating point extending loads, 
723   ///          integer extending loads [the top bits are undefined], and vector
724   ///          extending loads [load into low elt].
725   ///
726   enum LoadExtType {
727     NON_EXTLOAD = 0,
728     EXTLOAD,
729     SEXTLOAD,
730     ZEXTLOAD,
731     LAST_LOADX_TYPE
732   };
733
734   //===--------------------------------------------------------------------===//
735   /// ISD::CondCode enum - These are ordered carefully to make the bitfields
736   /// below work out, when considering SETFALSE (something that never exists
737   /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
738   /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
739   /// to.  If the "N" column is 1, the result of the comparison is undefined if
740   /// the input is a NAN.
741   ///
742   /// All of these (except for the 'always folded ops') should be handled for
743   /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
744   /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
745   ///
746   /// Note that these are laid out in a specific order to allow bit-twiddling
747   /// to transform conditions.
748   enum CondCode {
749     // Opcode          N U L G E       Intuitive operation
750     SETFALSE,      //    0 0 0 0       Always false (always folded)
751     SETOEQ,        //    0 0 0 1       True if ordered and equal
752     SETOGT,        //    0 0 1 0       True if ordered and greater than
753     SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
754     SETOLT,        //    0 1 0 0       True if ordered and less than
755     SETOLE,        //    0 1 0 1       True if ordered and less than or equal
756     SETONE,        //    0 1 1 0       True if ordered and operands are unequal
757     SETO,          //    0 1 1 1       True if ordered (no nans)
758     SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
759     SETUEQ,        //    1 0 0 1       True if unordered or equal
760     SETUGT,        //    1 0 1 0       True if unordered or greater than
761     SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
762     SETULT,        //    1 1 0 0       True if unordered or less than
763     SETULE,        //    1 1 0 1       True if unordered, less than, or equal
764     SETUNE,        //    1 1 1 0       True if unordered or not equal
765     SETTRUE,       //    1 1 1 1       Always true (always folded)
766     // Don't care operations: undefined if the input is a nan.
767     SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
768     SETEQ,         //  1 X 0 0 1       True if equal
769     SETGT,         //  1 X 0 1 0       True if greater than
770     SETGE,         //  1 X 0 1 1       True if greater than or equal
771     SETLT,         //  1 X 1 0 0       True if less than
772     SETLE,         //  1 X 1 0 1       True if less than or equal
773     SETNE,         //  1 X 1 1 0       True if not equal
774     SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
775
776     SETCC_INVALID       // Marker value.
777   };
778
779   /// isSignedIntSetCC - Return true if this is a setcc instruction that
780   /// performs a signed comparison when used with integer operands.
781   inline bool isSignedIntSetCC(CondCode Code) {
782     return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
783   }
784
785   /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
786   /// performs an unsigned comparison when used with integer operands.
787   inline bool isUnsignedIntSetCC(CondCode Code) {
788     return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
789   }
790
791   /// isTrueWhenEqual - Return true if the specified condition returns true if
792   /// the two operands to the condition are equal.  Note that if one of the two
793   /// operands is a NaN, this value is meaningless.
794   inline bool isTrueWhenEqual(CondCode Cond) {
795     return ((int)Cond & 1) != 0;
796   }
797
798   /// getUnorderedFlavor - This function returns 0 if the condition is always
799   /// false if an operand is a NaN, 1 if the condition is always true if the
800   /// operand is a NaN, and 2 if the condition is undefined if the operand is a
801   /// NaN.
802   inline unsigned getUnorderedFlavor(CondCode Cond) {
803     return ((int)Cond >> 3) & 3;
804   }
805
806   /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
807   /// 'op' is a valid SetCC operation.
808   CondCode getSetCCInverse(CondCode Operation, bool isInteger);
809
810   /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
811   /// when given the operation for (X op Y).
812   CondCode getSetCCSwappedOperands(CondCode Operation);
813
814   /// getSetCCOrOperation - Return the result of a logical OR between different
815   /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
816   /// function returns SETCC_INVALID if it is not possible to represent the
817   /// resultant comparison.
818   CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
819
820   /// getSetCCAndOperation - Return the result of a logical AND between
821   /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
822   /// function returns SETCC_INVALID if it is not possible to represent the
823   /// resultant comparison.
824   CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
825 }  // end llvm::ISD namespace
826
827
828 //===----------------------------------------------------------------------===//
829 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
830 /// values as the result of a computation.  Many nodes return multiple values,
831 /// from loads (which define a token and a return value) to ADDC (which returns
832 /// a result and a carry value), to calls (which may return an arbitrary number
833 /// of values).
834 ///
835 /// As such, each use of a SelectionDAG computation must indicate the node that
836 /// computes it as well as which return value to use from that node.  This pair
837 /// of information is represented with the SDValue value type.
838 ///
839 class SDValue {
840   SDNode *Node;       // The node defining the value we are using.
841   unsigned ResNo;     // Which return value of the node we are using.
842 public:
843   SDValue() : Node(0), ResNo(0) {}
844   SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
845
846   /// get the index which selects a specific result in the SDNode
847   unsigned getResNo() const { return ResNo; }
848
849   /// get the SDNode which holds the desired result
850   SDNode *getNode() const { return Node; }
851
852   /// set the SDNode
853   void setNode(SDNode *N) { Node = N; }
854
855   bool operator==(const SDValue &O) const {
856     return Node == O.Node && ResNo == O.ResNo;
857   }
858   bool operator!=(const SDValue &O) const {
859     return !operator==(O);
860   }
861   bool operator<(const SDValue &O) const {
862     return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
863   }
864
865   SDValue getValue(unsigned R) const {
866     return SDValue(Node, R);
867   }
868
869   // isOperandOf - Return true if this node is an operand of N.
870   bool isOperandOf(SDNode *N) const;
871
872   /// getValueType - Return the ValueType of the referenced return value.
873   ///
874   inline MVT getValueType() const;
875
876   /// getValueSizeInBits - Returns the size of the value in bits.
877   ///
878   unsigned getValueSizeInBits() const {
879     return getValueType().getSizeInBits();
880   }
881
882   // Forwarding methods - These forward to the corresponding methods in SDNode.
883   inline unsigned getOpcode() const;
884   inline unsigned getNumOperands() const;
885   inline const SDValue &getOperand(unsigned i) const;
886   inline uint64_t getConstantOperandVal(unsigned i) const;
887   inline bool isTargetOpcode() const;
888   inline bool isMachineOpcode() const;
889   inline unsigned getMachineOpcode() const;
890
891   
892   /// reachesChainWithoutSideEffects - Return true if this operand (which must
893   /// be a chain) reaches the specified operand without crossing any 
894   /// side-effecting instructions.  In practice, this looks through token
895   /// factors and non-volatile loads.  In order to remain efficient, this only
896   /// looks a couple of nodes in, it does not do an exhaustive search.
897   bool reachesChainWithoutSideEffects(SDValue Dest, 
898                                       unsigned Depth = 2) const;
899   
900   /// use_empty - Return true if there are no nodes using value ResNo
901   /// of Node.
902   ///
903   inline bool use_empty() const;
904
905   /// hasOneUse - Return true if there is exactly one node using value
906   /// ResNo of Node.
907   ///
908   inline bool hasOneUse() const;
909 };
910
911
912 template<> struct DenseMapInfo<SDValue> {
913   static inline SDValue getEmptyKey() { 
914     return SDValue((SDNode*)-1, -1U); 
915   }
916   static inline SDValue getTombstoneKey() { 
917     return SDValue((SDNode*)-1, 0);
918   }
919   static unsigned getHashValue(const SDValue &Val) {
920     return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
921             (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
922   }
923   static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
924     return LHS == RHS;
925   }
926   static bool isPod() { return true; }
927 };
928
929 /// simplify_type specializations - Allow casting operators to work directly on
930 /// SDValues as if they were SDNode*'s.
931 template<> struct simplify_type<SDValue> {
932   typedef SDNode* SimpleType;
933   static SimpleType getSimplifiedValue(const SDValue &Val) {
934     return static_cast<SimpleType>(Val.getNode());
935   }
936 };
937 template<> struct simplify_type<const SDValue> {
938   typedef SDNode* SimpleType;
939   static SimpleType getSimplifiedValue(const SDValue &Val) {
940     return static_cast<SimpleType>(Val.getNode());
941   }
942 };
943
944 /// SDUse - Represents a use of the SDNode referred by
945 /// the SDValue.
946 class SDUse {
947   SDValue Operand;
948   /// User - Parent node of this operand.
949   SDNode    *User;
950   /// Prev, next - Pointers to the uses list of the SDNode referred by 
951   /// this operand.
952   SDUse **Prev, *Next;
953 public:
954   friend class SDNode;
955   SDUse(): Operand(), User(NULL), Prev(NULL), Next(NULL) {}
956
957   SDUse(SDNode *val, unsigned resno) : 
958     Operand(val,resno), User(NULL), Prev(NULL), Next(NULL) {}
959
960   SDUse& operator= (const SDValue& Op) {
961       Operand = Op;
962       Next = NULL;
963       Prev = NULL;
964       return *this;
965   }
966
967   SDUse& operator= (const SDUse& Op) {
968       Operand = Op;
969       Next = NULL;
970       Prev = NULL;
971       return *this;
972   }
973
974   SDUse *getNext() { return Next; }
975
976   SDNode *getUser() { return User; }
977
978   void setUser(SDNode *p) { User = p; }
979
980   operator SDValue() const { return Operand; }
981
982   const SDValue& getSDValue() const { return Operand; }
983
984   SDValue &getSDValue() { return Operand; }
985   SDNode *getVal() { return Operand.getNode(); }
986   SDNode *getVal() const { return Operand.getNode(); } // FIXME: const correct?
987
988   bool operator==(const SDValue &O) const {
989     return Operand == O;
990   }
991
992   bool operator!=(const SDValue &O) const {
993     return !(Operand == O);
994   }
995
996   bool operator<(const SDValue &O) const {
997     return Operand < O;
998   }
999
1000 protected:
1001   void addToList(SDUse **List) {
1002     Next = *List;
1003     if (Next) Next->Prev = &Next;
1004     Prev = List;
1005     *List = this;
1006   }
1007
1008   void removeFromList() {
1009     *Prev = Next;
1010     if (Next) Next->Prev = Prev;
1011   }
1012 };
1013
1014
1015 /// simplify_type specializations - Allow casting operators to work directly on
1016 /// SDValues as if they were SDNode*'s.
1017 template<> struct simplify_type<SDUse> {
1018   typedef SDNode* SimpleType;
1019   static SimpleType getSimplifiedValue(const SDUse &Val) {
1020     return static_cast<SimpleType>(Val.getVal());
1021   }
1022 };
1023 template<> struct simplify_type<const SDUse> {
1024   typedef SDNode* SimpleType;
1025   static SimpleType getSimplifiedValue(const SDUse &Val) {
1026     return static_cast<SimpleType>(Val.getVal());
1027   }
1028 };
1029
1030
1031 /// SDOperandPtr - A helper SDValue pointer class, that can handle
1032 /// arrays of SDUse and arrays of SDValue objects. This is required
1033 /// in many places inside the SelectionDAG.
1034 /// 
1035 class SDOperandPtr {
1036   const SDValue *ptr; // The pointer to the SDValue object
1037   int object_size;      // The size of the object containg the SDValue
1038 public:
1039   SDOperandPtr() : ptr(0), object_size(0) {}
1040
1041   SDOperandPtr(SDUse * use_ptr) { 
1042     ptr = &use_ptr->getSDValue(); 
1043     object_size = (int)sizeof(SDUse); 
1044   }
1045
1046   SDOperandPtr(const SDValue * op_ptr) { 
1047     ptr = op_ptr; 
1048     object_size = (int)sizeof(SDValue); 
1049   }
1050
1051   const SDValue operator *() { return *ptr; }
1052   const SDValue *operator ->() { return ptr; }
1053   SDOperandPtr operator ++ () { 
1054     ptr = (SDValue*)((char *)ptr + object_size); 
1055     return *this; 
1056   }
1057
1058   SDOperandPtr operator ++ (int) { 
1059     SDOperandPtr tmp = *this;
1060     ptr = (SDValue*)((char *)ptr + object_size); 
1061     return tmp; 
1062   }
1063
1064   SDValue operator[] (int idx) const {
1065     return *(SDValue*)((char*) ptr + object_size * idx);
1066   } 
1067 };
1068
1069 /// SDNode - Represents one node in the SelectionDAG.
1070 ///
1071 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
1072 private:
1073   /// NodeType - The operation that this node performs.
1074   ///
1075   short NodeType;
1076   
1077   /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
1078   /// then they will be delete[]'d when the node is destroyed.
1079   unsigned short OperandsNeedDelete : 1;
1080
1081 protected:
1082   /// SubclassData - This member is defined by this class, but is not used for
1083   /// anything.  Subclasses can use it to hold whatever state they find useful.
1084   /// This field is initialized to zero by the ctor.
1085   unsigned short SubclassData : 15;
1086
1087 private:
1088   /// NodeId - Unique id per SDNode in the DAG.
1089   int NodeId;
1090
1091   /// OperandList - The values that are used by this operation.
1092   ///
1093   SDUse *OperandList;
1094   
1095   /// ValueList - The types of the values this node defines.  SDNode's may
1096   /// define multiple values simultaneously.
1097   const MVT *ValueList;
1098
1099   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1100   unsigned short NumOperands, NumValues;
1101   
1102   /// Uses - List of uses for this SDNode.
1103   SDUse *Uses;
1104
1105   /// addUse - add SDUse to the list of uses.
1106   void addUse(SDUse &U) { U.addToList(&Uses); }
1107
1108   // Out-of-line virtual method to give class a home.
1109   virtual void ANCHOR();
1110 public:
1111   virtual ~SDNode() {
1112     assert(NumOperands == 0 && "Operand list not cleared before deletion");
1113     NodeType = ISD::DELETED_NODE;
1114   }
1115   
1116   //===--------------------------------------------------------------------===//
1117   //  Accessors
1118   //
1119
1120   /// getOpcode - Return the SelectionDAG opcode value for this node. For
1121   /// pre-isel nodes (those for which isMachineOpcode returns false), these
1122   /// are the opcode values in the ISD and <target>ISD namespaces. For
1123   /// post-isel opcodes, see getMachineOpcode.
1124   unsigned getOpcode()  const { return (unsigned short)NodeType; }
1125
1126   /// isTargetOpcode - Test if this node has a target-specific opcode (in the
1127   /// <target>ISD namespace).
1128   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1129
1130   /// isMachineOpcode - Test if this node has a post-isel opcode, directly
1131   /// corresponding to a MachineInstr opcode.
1132   bool isMachineOpcode() const { return NodeType < 0; }
1133
1134   /// getMachineOpcode - This may only be called if isMachineOpcode returns
1135   /// true. It returns the MachineInstr opcode value that the node's opcode
1136   /// corresponds to.
1137   unsigned getMachineOpcode() const {
1138     assert(isMachineOpcode() && "Not a MachineInstr opcode!");
1139     return ~NodeType;
1140   }
1141
1142   /// use_empty - Return true if there are no uses of this node.
1143   ///
1144   bool use_empty() const { return Uses == NULL; }
1145
1146   /// hasOneUse - Return true if there is exactly one use of this node.
1147   ///
1148   bool hasOneUse() const {
1149     return !use_empty() && next(use_begin()) == use_end();
1150   }
1151
1152   /// use_size - Return the number of uses of this node. This method takes
1153   /// time proportional to the number of uses.
1154   ///
1155   size_t use_size() const { return std::distance(use_begin(), use_end()); }
1156
1157   /// getNodeId - Return the unique node id.
1158   ///
1159   int getNodeId() const { return NodeId; }
1160
1161   /// setNodeId - Set unique node id.
1162   void setNodeId(int Id) { NodeId = Id; }
1163
1164   /// use_iterator - This class provides iterator support for SDUse
1165   /// operands that use a specific SDNode. 
1166   class use_iterator
1167     : public forward_iterator<SDUse, ptrdiff_t> {
1168     SDUse *Op;
1169     explicit use_iterator(SDUse *op) : Op(op) {
1170     }
1171     friend class SDNode;
1172   public:
1173     typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
1174     typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1175
1176     use_iterator(const use_iterator &I) : Op(I.Op) {}
1177     use_iterator() : Op(0) {}
1178
1179     bool operator==(const use_iterator &x) const {
1180       return Op == x.Op;
1181     }
1182     bool operator!=(const use_iterator &x) const {
1183       return !operator==(x);
1184     }
1185  
1186     /// atEnd - return true if this iterator is at the end of uses list.
1187     bool atEnd() const { return Op == 0; }
1188
1189     // Iterator traversal: forward iteration only.
1190     use_iterator &operator++() {          // Preincrement
1191       assert(Op && "Cannot increment end iterator!");
1192       Op = Op->getNext();
1193       return *this;
1194     }
1195
1196     use_iterator operator++(int) {        // Postincrement
1197       use_iterator tmp = *this; ++*this; return tmp;
1198     }
1199
1200     /// Retrieve a pointer to the current user node.
1201     SDNode *operator*() const {
1202       assert(Op && "Cannot dereference end iterator!");
1203       return Op->getUser();
1204     }
1205
1206     SDNode *operator->() const { return operator*(); }
1207
1208     SDUse &getUse() const { return *Op; }
1209
1210     /// getOperandNo - Retrive the operand # of this use in its user.
1211     ///
1212     unsigned getOperandNo() const {
1213       assert(Op && "Cannot dereference end iterator!");
1214       return (unsigned)(Op - Op->getUser()->OperandList);
1215     }
1216   };
1217
1218   /// use_begin/use_end - Provide iteration support to walk over all uses
1219   /// of an SDNode.
1220
1221   use_iterator use_begin() const {
1222     return use_iterator(Uses);
1223   }
1224
1225   static use_iterator use_end() { return use_iterator(0); }
1226
1227
1228   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1229   /// indicated value.  This method ignores uses of other values defined by this
1230   /// operation.
1231   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1232
1233   /// hasAnyUseOfValue - Return true if there are any use of the indicated
1234   /// value. This method ignores uses of other values defined by this operation.
1235   bool hasAnyUseOfValue(unsigned Value) const;
1236
1237   /// isOnlyUserOf - Return true if this node is the only use of N.
1238   ///
1239   bool isOnlyUserOf(SDNode *N) const;
1240
1241   /// isOperandOf - Return true if this node is an operand of N.
1242   ///
1243   bool isOperandOf(SDNode *N) const;
1244
1245   /// isPredecessorOf - Return true if this node is a predecessor of N. This
1246   /// node is either an operand of N or it can be reached by recursively
1247   /// traversing up the operands.
1248   /// NOTE: this is an expensive method. Use it carefully.
1249   bool isPredecessorOf(SDNode *N) const;
1250
1251   /// getNumOperands - Return the number of values used by this operation.
1252   ///
1253   unsigned getNumOperands() const { return NumOperands; }
1254
1255   /// getConstantOperandVal - Helper method returns the integer value of a 
1256   /// ConstantSDNode operand.
1257   uint64_t getConstantOperandVal(unsigned Num) const;
1258
1259   const SDValue &getOperand(unsigned Num) const {
1260     assert(Num < NumOperands && "Invalid child # of SDNode!");
1261     return OperandList[Num].getSDValue();
1262   }
1263
1264   typedef SDUse* op_iterator;
1265   op_iterator op_begin() const { return OperandList; }
1266   op_iterator op_end() const { return OperandList+NumOperands; }
1267
1268
1269   SDVTList getVTList() const {
1270     SDVTList X = { ValueList, NumValues };
1271     return X;
1272   };
1273   
1274   /// getNumValues - Return the number of values defined/returned by this
1275   /// operator.
1276   ///
1277   unsigned getNumValues() const { return NumValues; }
1278
1279   /// getValueType - Return the type of a specified result.
1280   ///
1281   MVT getValueType(unsigned ResNo) const {
1282     assert(ResNo < NumValues && "Illegal result number!");
1283     return ValueList[ResNo];
1284   }
1285
1286   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1287   ///
1288   unsigned getValueSizeInBits(unsigned ResNo) const {
1289     return getValueType(ResNo).getSizeInBits();
1290   }
1291
1292   typedef const MVT* value_iterator;
1293   value_iterator value_begin() const { return ValueList; }
1294   value_iterator value_end() const { return ValueList+NumValues; }
1295
1296   /// getOperationName - Return the opcode of this operation for printing.
1297   ///
1298   std::string getOperationName(const SelectionDAG *G = 0) const;
1299   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1300   void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
1301   void dump() const;
1302   void dump(const SelectionDAG *G) const;
1303
1304   static bool classof(const SDNode *) { return true; }
1305
1306   /// Profile - Gather unique data for the node.
1307   ///
1308   void Profile(FoldingSetNodeID &ID) const;
1309
1310 protected:
1311   friend class SelectionDAG;
1312   friend class ilist_traits<SDNode>;
1313   
1314   /// getValueTypeList - Return a pointer to the specified value type.
1315   ///
1316   static const MVT *getValueTypeList(MVT VT);
1317   static SDVTList getSDVTList(MVT VT) {
1318     SDVTList Ret = { getValueTypeList(VT), 1 };
1319     return Ret;
1320   }
1321
1322   SDNode(unsigned Opc, SDVTList VTs, const SDValue *Ops, unsigned NumOps)
1323     : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1324       NodeId(-1), Uses(NULL) {
1325     NumOperands = NumOps;
1326     OperandList = NumOps ? new SDUse[NumOperands] : 0;
1327     
1328     for (unsigned i = 0; i != NumOps; ++i) {
1329       OperandList[i] = Ops[i];
1330       OperandList[i].setUser(this);
1331       Ops[i].getNode()->addUse(OperandList[i]);
1332     }
1333     
1334     ValueList = VTs.VTs;
1335     NumValues = VTs.NumVTs;
1336   }
1337
1338   SDNode(unsigned Opc, SDVTList VTs, const SDUse *Ops, unsigned NumOps)
1339     : NodeType(Opc), OperandsNeedDelete(true), SubclassData(0),
1340       NodeId(-1), Uses(NULL) {
1341     OperandsNeedDelete = true;
1342     NumOperands = NumOps;
1343     OperandList = NumOps ? new SDUse[NumOperands] : 0;
1344     
1345     for (unsigned i = 0; i != NumOps; ++i) {
1346       OperandList[i] = Ops[i];
1347       OperandList[i].setUser(this);
1348       Ops[i].getVal()->addUse(OperandList[i]);
1349     }
1350     
1351     ValueList = VTs.VTs;
1352     NumValues = VTs.NumVTs;
1353   }
1354
1355   /// This constructor adds no operands itself; operands can be
1356   /// set later with InitOperands.
1357   SDNode(unsigned Opc, SDVTList VTs)
1358     : NodeType(Opc), OperandsNeedDelete(false), SubclassData(0),
1359       NodeId(-1), Uses(NULL) {
1360     NumOperands = 0;
1361     OperandList = 0;
1362     ValueList = VTs.VTs;
1363     NumValues = VTs.NumVTs;
1364   }
1365   
1366   /// InitOperands - Initialize the operands list of this node with the
1367   /// specified values, which are part of the node (thus they don't need to be
1368   /// copied in or allocated).
1369   void InitOperands(SDUse *Ops, unsigned NumOps) {
1370     assert(OperandList == 0 && "Operands already set!");
1371     NumOperands = NumOps;
1372     OperandList = Ops;
1373     Uses = NULL;
1374     
1375     for (unsigned i = 0; i != NumOps; ++i) {
1376       OperandList[i].setUser(this);
1377       Ops[i].getVal()->addUse(OperandList[i]);
1378     }
1379   }
1380
1381   /// DropOperands - Release the operands and set this node to have
1382   /// zero operands.
1383   void DropOperands();
1384   
1385   void addUser(unsigned i, SDNode *User) {
1386     assert(User->OperandList[i].getUser() && "Node without parent");
1387     addUse(User->OperandList[i]);
1388   }
1389
1390   void removeUser(unsigned i, SDNode *User) {
1391     assert(User->OperandList[i].getUser() && "Node without parent");
1392     SDUse &Op = User->OperandList[i];
1393     Op.removeFromList();
1394   }
1395 };
1396
1397
1398 // Define inline functions from the SDValue class.
1399
1400 inline unsigned SDValue::getOpcode() const {
1401   return Node->getOpcode();
1402 }
1403 inline MVT SDValue::getValueType() const {
1404   return Node->getValueType(ResNo);
1405 }
1406 inline unsigned SDValue::getNumOperands() const {
1407   return Node->getNumOperands();
1408 }
1409 inline const SDValue &SDValue::getOperand(unsigned i) const {
1410   return Node->getOperand(i);
1411 }
1412 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
1413   return Node->getConstantOperandVal(i);
1414 }
1415 inline bool SDValue::isTargetOpcode() const {
1416   return Node->isTargetOpcode();
1417 }
1418 inline bool SDValue::isMachineOpcode() const {
1419   return Node->isMachineOpcode();
1420 }
1421 inline unsigned SDValue::getMachineOpcode() const {
1422   return Node->getMachineOpcode();
1423 }
1424 inline bool SDValue::use_empty() const {
1425   return !Node->hasAnyUseOfValue(ResNo);
1426 }
1427 inline bool SDValue::hasOneUse() const {
1428   return Node->hasNUsesOfValue(1, ResNo);
1429 }
1430
1431 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
1432 /// to allow co-allocation of node operands with the node itself.
1433 class UnarySDNode : public SDNode {
1434   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1435   SDUse Op;
1436 public:
1437   UnarySDNode(unsigned Opc, SDVTList VTs, SDValue X)
1438     : SDNode(Opc, VTs) {
1439     Op = X;
1440     InitOperands(&Op, 1);
1441   }
1442 };
1443
1444 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
1445 /// to allow co-allocation of node operands with the node itself.
1446 class BinarySDNode : public SDNode {
1447   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1448   SDUse Ops[2];
1449 public:
1450   BinarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y)
1451     : SDNode(Opc, VTs) {
1452     Ops[0] = X;
1453     Ops[1] = Y;
1454     InitOperands(Ops, 2);
1455   }
1456 };
1457
1458 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1459 /// to allow co-allocation of node operands with the node itself.
1460 class TernarySDNode : public SDNode {
1461   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1462   SDUse Ops[3];
1463 public:
1464   TernarySDNode(unsigned Opc, SDVTList VTs, SDValue X, SDValue Y,
1465                 SDValue Z)
1466     : SDNode(Opc, VTs) {
1467     Ops[0] = X;
1468     Ops[1] = Y;
1469     Ops[2] = Z;
1470     InitOperands(Ops, 3);
1471   }
1472 };
1473
1474
1475 /// HandleSDNode - This class is used to form a handle around another node that
1476 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1477 /// operand.  This node should be directly created by end-users and not added to
1478 /// the AllNodes list.
1479 class HandleSDNode : public SDNode {
1480   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1481   SDUse Op;
1482 public:
1483   // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1484   // fixed.
1485 #ifdef __GNUC__
1486   explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
1487 #else
1488   explicit HandleSDNode(SDValue X)
1489 #endif
1490     : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
1491     Op = X;
1492     InitOperands(&Op, 1);
1493   }
1494   ~HandleSDNode();  
1495   const SDValue &getValue() const { return Op.getSDValue(); }
1496 };
1497
1498 /// Abstact virtual class for operations for memory operations
1499 class MemSDNode : public SDNode {
1500   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1501
1502 private:
1503   // MemoryVT - VT of in-memory value.
1504   MVT MemoryVT;
1505
1506   //! SrcValue - Memory location for alias analysis.
1507   const Value *SrcValue;
1508
1509   //! SVOffset - Memory location offset. Note that base is defined in MemSDNode
1510   int SVOffset;
1511
1512   /// Flags - the low bit indicates whether this is a volatile reference;
1513   /// the remainder is a log2 encoding of the alignment in bytes.
1514   unsigned Flags;
1515
1516 public:
1517   MemSDNode(unsigned Opc, SDVTList VTs, MVT MemoryVT,
1518             const Value *srcValue, int SVOff,
1519             unsigned alignment, bool isvolatile);
1520
1521   /// Returns alignment and volatility of the memory access
1522   unsigned getAlignment() const { return (1u << (Flags >> 1)) >> 1; }
1523   bool isVolatile() const { return Flags & 1; }
1524   
1525   /// Returns the SrcValue and offset that describes the location of the access
1526   const Value *getSrcValue() const { return SrcValue; }
1527   int getSrcValueOffset() const { return SVOffset; }
1528   
1529   /// getMemoryVT - Return the type of the in-memory value.
1530   MVT getMemoryVT() const { return MemoryVT; }
1531     
1532   /// getMemOperand - Return a MachineMemOperand object describing the memory
1533   /// reference performed by operation.
1534   MachineMemOperand getMemOperand() const;
1535
1536   const SDValue &getChain() const { return getOperand(0); }
1537   const SDValue &getBasePtr() const {
1538     return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
1539   }
1540
1541   /// getRawFlags - Represent the flags as a bunch of bits.
1542   ///
1543   unsigned getRawFlags() const { return Flags; }
1544
1545   // Methods to support isa and dyn_cast
1546   static bool classof(const MemSDNode *) { return true; }
1547   static bool classof(const SDNode *N) {
1548     return N->getOpcode() == ISD::LOAD                ||
1549            N->getOpcode() == ISD::STORE               ||
1550            N->getOpcode() == ISD::ATOMIC_CMP_SWAP_8   ||
1551            N->getOpcode() == ISD::ATOMIC_SWAP_8       ||
1552            N->getOpcode() == ISD::ATOMIC_LOAD_ADD_8   ||
1553            N->getOpcode() == ISD::ATOMIC_LOAD_SUB_8   ||
1554            N->getOpcode() == ISD::ATOMIC_LOAD_AND_8   ||
1555            N->getOpcode() == ISD::ATOMIC_LOAD_OR_8    ||
1556            N->getOpcode() == ISD::ATOMIC_LOAD_XOR_8   ||
1557            N->getOpcode() == ISD::ATOMIC_LOAD_NAND_8  ||
1558            N->getOpcode() == ISD::ATOMIC_LOAD_MIN_8   ||
1559            N->getOpcode() == ISD::ATOMIC_LOAD_MAX_8   ||
1560            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_8  ||
1561            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_8  ||
1562
1563            N->getOpcode() == ISD::ATOMIC_CMP_SWAP_16  ||
1564            N->getOpcode() == ISD::ATOMIC_SWAP_16      ||
1565            N->getOpcode() == ISD::ATOMIC_LOAD_ADD_16  ||
1566            N->getOpcode() == ISD::ATOMIC_LOAD_SUB_16  ||
1567            N->getOpcode() == ISD::ATOMIC_LOAD_AND_16  ||
1568            N->getOpcode() == ISD::ATOMIC_LOAD_OR_16   ||
1569            N->getOpcode() == ISD::ATOMIC_LOAD_XOR_16  ||
1570            N->getOpcode() == ISD::ATOMIC_LOAD_NAND_16 ||
1571            N->getOpcode() == ISD::ATOMIC_LOAD_MIN_16  ||
1572            N->getOpcode() == ISD::ATOMIC_LOAD_MAX_16  ||
1573            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_16 ||
1574            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_16 ||
1575
1576            N->getOpcode() == ISD::ATOMIC_CMP_SWAP_32  ||
1577            N->getOpcode() == ISD::ATOMIC_SWAP_32      ||
1578            N->getOpcode() == ISD::ATOMIC_LOAD_ADD_32  ||
1579            N->getOpcode() == ISD::ATOMIC_LOAD_SUB_32  ||
1580            N->getOpcode() == ISD::ATOMIC_LOAD_AND_32  ||
1581            N->getOpcode() == ISD::ATOMIC_LOAD_OR_32   ||
1582            N->getOpcode() == ISD::ATOMIC_LOAD_XOR_32  ||
1583            N->getOpcode() == ISD::ATOMIC_LOAD_NAND_32 ||
1584            N->getOpcode() == ISD::ATOMIC_LOAD_MIN_32  ||
1585            N->getOpcode() == ISD::ATOMIC_LOAD_MAX_32  ||
1586            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_32 ||
1587            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_32 ||
1588
1589            N->getOpcode() == ISD::ATOMIC_CMP_SWAP_64  ||
1590            N->getOpcode() == ISD::ATOMIC_SWAP_64      ||
1591            N->getOpcode() == ISD::ATOMIC_LOAD_ADD_64  ||
1592            N->getOpcode() == ISD::ATOMIC_LOAD_SUB_64  ||
1593            N->getOpcode() == ISD::ATOMIC_LOAD_AND_64  ||
1594            N->getOpcode() == ISD::ATOMIC_LOAD_OR_64   ||
1595            N->getOpcode() == ISD::ATOMIC_LOAD_XOR_64  ||
1596            N->getOpcode() == ISD::ATOMIC_LOAD_NAND_64 ||
1597            N->getOpcode() == ISD::ATOMIC_LOAD_MIN_64  ||
1598            N->getOpcode() == ISD::ATOMIC_LOAD_MAX_64  ||
1599            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_64 ||
1600            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_64;
1601   }  
1602 };
1603
1604 /// Atomic operations node
1605 class AtomicSDNode : public MemSDNode {
1606   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1607   SDUse Ops[4];
1608   
1609  public:
1610   // Opc:   opcode for atomic
1611   // VTL:    value type list
1612   // Chain:  memory chain for operaand
1613   // Ptr:    address to update as a SDValue
1614   // Cmp:    compare value
1615   // Swp:    swap value
1616   // SrcVal: address to update as a Value (used for MemOperand)
1617   // Align:  alignment of memory
1618   AtomicSDNode(unsigned Opc, SDVTList VTL, SDValue Chain, SDValue Ptr, 
1619                SDValue Cmp, SDValue Swp, const Value* SrcVal,
1620                unsigned Align=0)
1621     : MemSDNode(Opc, VTL, Cmp.getValueType(), SrcVal, /*SVOffset=*/0,
1622                 Align, /*isVolatile=*/true) {
1623     Ops[0] = Chain;
1624     Ops[1] = Ptr;
1625     Ops[2] = Swp;
1626     Ops[3] = Cmp;
1627     InitOperands(Ops, 4);
1628   }
1629   AtomicSDNode(unsigned Opc, SDVTList VTL, SDValue Chain, SDValue Ptr, 
1630                SDValue Val, const Value* SrcVal, unsigned Align=0)
1631     : MemSDNode(Opc, VTL, Val.getValueType(), SrcVal, /*SVOffset=*/0,
1632                 Align, /*isVolatile=*/true) {
1633     Ops[0] = Chain;
1634     Ops[1] = Ptr;
1635     Ops[2] = Val;
1636     InitOperands(Ops, 3);
1637   }
1638   
1639   const SDValue &getBasePtr() const { return getOperand(1); }
1640   const SDValue &getVal() const { return getOperand(2); }
1641
1642   bool isCompareAndSwap() const { 
1643     unsigned Op = getOpcode(); 
1644     return Op == ISD::ATOMIC_CMP_SWAP_8 ||
1645            Op == ISD::ATOMIC_CMP_SWAP_16 ||
1646            Op == ISD::ATOMIC_CMP_SWAP_32 ||
1647            Op == ISD::ATOMIC_CMP_SWAP_64;
1648   }
1649
1650   // Methods to support isa and dyn_cast
1651   static bool classof(const AtomicSDNode *) { return true; }
1652   static bool classof(const SDNode *N) {
1653     return N->getOpcode() == ISD::ATOMIC_CMP_SWAP_8   ||
1654            N->getOpcode() == ISD::ATOMIC_SWAP_8       ||
1655            N->getOpcode() == ISD::ATOMIC_LOAD_ADD_8   ||
1656            N->getOpcode() == ISD::ATOMIC_LOAD_SUB_8   ||
1657            N->getOpcode() == ISD::ATOMIC_LOAD_AND_8   ||
1658            N->getOpcode() == ISD::ATOMIC_LOAD_OR_8    ||
1659            N->getOpcode() == ISD::ATOMIC_LOAD_XOR_8   ||
1660            N->getOpcode() == ISD::ATOMIC_LOAD_NAND_8  ||
1661            N->getOpcode() == ISD::ATOMIC_LOAD_MIN_8   ||
1662            N->getOpcode() == ISD::ATOMIC_LOAD_MAX_8   ||
1663            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_8  ||
1664            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_8  ||
1665            N->getOpcode() == ISD::ATOMIC_CMP_SWAP_16  ||
1666            N->getOpcode() == ISD::ATOMIC_SWAP_16      ||
1667            N->getOpcode() == ISD::ATOMIC_LOAD_ADD_16  ||
1668            N->getOpcode() == ISD::ATOMIC_LOAD_SUB_16  ||
1669            N->getOpcode() == ISD::ATOMIC_LOAD_AND_16  ||
1670            N->getOpcode() == ISD::ATOMIC_LOAD_OR_16   ||
1671            N->getOpcode() == ISD::ATOMIC_LOAD_XOR_16  ||
1672            N->getOpcode() == ISD::ATOMIC_LOAD_NAND_16 ||
1673            N->getOpcode() == ISD::ATOMIC_LOAD_MIN_16  ||
1674            N->getOpcode() == ISD::ATOMIC_LOAD_MAX_16  ||
1675            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_16 ||
1676            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_16 ||
1677            N->getOpcode() == ISD::ATOMIC_CMP_SWAP_32  ||
1678            N->getOpcode() == ISD::ATOMIC_SWAP_32      ||
1679            N->getOpcode() == ISD::ATOMIC_LOAD_ADD_32  ||
1680            N->getOpcode() == ISD::ATOMIC_LOAD_SUB_32  ||
1681            N->getOpcode() == ISD::ATOMIC_LOAD_AND_32  ||
1682            N->getOpcode() == ISD::ATOMIC_LOAD_OR_32   ||
1683            N->getOpcode() == ISD::ATOMIC_LOAD_XOR_32  ||
1684            N->getOpcode() == ISD::ATOMIC_LOAD_NAND_32 ||
1685            N->getOpcode() == ISD::ATOMIC_LOAD_MIN_32  ||
1686            N->getOpcode() == ISD::ATOMIC_LOAD_MAX_32  ||
1687            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_32 ||
1688            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_32 ||
1689            N->getOpcode() == ISD::ATOMIC_CMP_SWAP_64  ||
1690            N->getOpcode() == ISD::ATOMIC_SWAP_64      ||
1691            N->getOpcode() == ISD::ATOMIC_LOAD_ADD_64  ||
1692            N->getOpcode() == ISD::ATOMIC_LOAD_SUB_64  ||
1693            N->getOpcode() == ISD::ATOMIC_LOAD_AND_64  ||
1694            N->getOpcode() == ISD::ATOMIC_LOAD_OR_64   ||
1695            N->getOpcode() == ISD::ATOMIC_LOAD_XOR_64  ||
1696            N->getOpcode() == ISD::ATOMIC_LOAD_NAND_64 ||
1697            N->getOpcode() == ISD::ATOMIC_LOAD_MIN_64  ||
1698            N->getOpcode() == ISD::ATOMIC_LOAD_MAX_64  ||
1699            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN_64 ||
1700            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX_64;
1701   }
1702 };
1703
1704 class ConstantSDNode : public SDNode {
1705   APInt Value;
1706   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1707 protected:
1708   friend class SelectionDAG;
1709   ConstantSDNode(bool isTarget, const APInt &val, MVT VT)
1710     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1711       Value(val) {
1712   }
1713 public:
1714
1715   const APInt &getAPIntValue() const { return Value; }
1716   uint64_t getValue() const { return Value.getZExtValue(); }
1717
1718   int64_t getSignExtended() const {
1719     unsigned Bits = getValueType(0).getSizeInBits();
1720     return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1721   }
1722
1723   bool isNullValue() const { return Value == 0; }
1724   bool isAllOnesValue() const {
1725     return Value == getValueType(0).getIntegerVTBitMask();
1726   }
1727
1728   static bool classof(const ConstantSDNode *) { return true; }
1729   static bool classof(const SDNode *N) {
1730     return N->getOpcode() == ISD::Constant ||
1731            N->getOpcode() == ISD::TargetConstant;
1732   }
1733 };
1734
1735 class ConstantFPSDNode : public SDNode {
1736   APFloat Value;
1737   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1738 protected:
1739   friend class SelectionDAG;
1740   ConstantFPSDNode(bool isTarget, const APFloat& val, MVT VT)
1741     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1742              getSDVTList(VT)), Value(val) {
1743   }
1744 public:
1745
1746   const APFloat& getValueAPF() const { return Value; }
1747
1748   /// isExactlyValue - We don't rely on operator== working on double values, as
1749   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1750   /// As such, this method can be used to do an exact bit-for-bit comparison of
1751   /// two floating point values.
1752
1753   /// We leave the version with the double argument here because it's just so
1754   /// convenient to write "2.0" and the like.  Without this function we'd 
1755   /// have to duplicate its logic everywhere it's called.
1756   bool isExactlyValue(double V) const {
1757     // convert is not supported on this type
1758     if (&Value.getSemantics() == &APFloat::PPCDoubleDouble)
1759       return false;
1760     APFloat Tmp(V);
1761     Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1762     return isExactlyValue(Tmp);
1763   }
1764   bool isExactlyValue(const APFloat& V) const;
1765
1766   bool isValueValidForType(MVT VT, const APFloat& Val);
1767
1768   static bool classof(const ConstantFPSDNode *) { return true; }
1769   static bool classof(const SDNode *N) {
1770     return N->getOpcode() == ISD::ConstantFP || 
1771            N->getOpcode() == ISD::TargetConstantFP;
1772   }
1773 };
1774
1775 class GlobalAddressSDNode : public SDNode {
1776   GlobalValue *TheGlobal;
1777   int Offset;
1778   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1779 protected:
1780   friend class SelectionDAG;
1781   GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT, int o = 0);
1782 public:
1783
1784   GlobalValue *getGlobal() const { return TheGlobal; }
1785   int getOffset() const { return Offset; }
1786
1787   static bool classof(const GlobalAddressSDNode *) { return true; }
1788   static bool classof(const SDNode *N) {
1789     return N->getOpcode() == ISD::GlobalAddress ||
1790            N->getOpcode() == ISD::TargetGlobalAddress ||
1791            N->getOpcode() == ISD::GlobalTLSAddress ||
1792            N->getOpcode() == ISD::TargetGlobalTLSAddress;
1793   }
1794 };
1795
1796 class FrameIndexSDNode : public SDNode {
1797   int FI;
1798   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1799 protected:
1800   friend class SelectionDAG;
1801   FrameIndexSDNode(int fi, MVT VT, bool isTarg)
1802     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1803       FI(fi) {
1804   }
1805 public:
1806
1807   int getIndex() const { return FI; }
1808
1809   static bool classof(const FrameIndexSDNode *) { return true; }
1810   static bool classof(const SDNode *N) {
1811     return N->getOpcode() == ISD::FrameIndex ||
1812            N->getOpcode() == ISD::TargetFrameIndex;
1813   }
1814 };
1815
1816 class JumpTableSDNode : public SDNode {
1817   int JTI;
1818   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1819 protected:
1820   friend class SelectionDAG;
1821   JumpTableSDNode(int jti, MVT VT, bool isTarg)
1822     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1823       JTI(jti) {
1824   }
1825 public:
1826     
1827   int getIndex() const { return JTI; }
1828   
1829   static bool classof(const JumpTableSDNode *) { return true; }
1830   static bool classof(const SDNode *N) {
1831     return N->getOpcode() == ISD::JumpTable ||
1832            N->getOpcode() == ISD::TargetJumpTable;
1833   }
1834 };
1835
1836 class ConstantPoolSDNode : public SDNode {
1837   union {
1838     Constant *ConstVal;
1839     MachineConstantPoolValue *MachineCPVal;
1840   } Val;
1841   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1842   unsigned Alignment;
1843   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1844 protected:
1845   friend class SelectionDAG;
1846   ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0)
1847     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1848              getSDVTList(VT)), Offset(o), Alignment(0) {
1849     assert((int)Offset >= 0 && "Offset is too large");
1850     Val.ConstVal = c;
1851   }
1852   ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o, unsigned Align)
1853     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1854              getSDVTList(VT)), Offset(o), Alignment(Align) {
1855     assert((int)Offset >= 0 && "Offset is too large");
1856     Val.ConstVal = c;
1857   }
1858   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1859                      MVT VT, int o=0)
1860     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1861              getSDVTList(VT)), Offset(o), Alignment(0) {
1862     assert((int)Offset >= 0 && "Offset is too large");
1863     Val.MachineCPVal = v;
1864     Offset |= 1 << (sizeof(unsigned)*8-1);
1865   }
1866   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1867                      MVT VT, int o, unsigned Align)
1868     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1869              getSDVTList(VT)), Offset(o), Alignment(Align) {
1870     assert((int)Offset >= 0 && "Offset is too large");
1871     Val.MachineCPVal = v;
1872     Offset |= 1 << (sizeof(unsigned)*8-1);
1873   }
1874 public:
1875
1876   bool isMachineConstantPoolEntry() const {
1877     return (int)Offset < 0;
1878   }
1879
1880   Constant *getConstVal() const {
1881     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1882     return Val.ConstVal;
1883   }
1884
1885   MachineConstantPoolValue *getMachineCPVal() const {
1886     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1887     return Val.MachineCPVal;
1888   }
1889
1890   int getOffset() const {
1891     return Offset & ~(1 << (sizeof(unsigned)*8-1));
1892   }
1893   
1894   // Return the alignment of this constant pool object, which is either 0 (for
1895   // default alignment) or log2 of the desired value.
1896   unsigned getAlignment() const { return Alignment; }
1897
1898   const Type *getType() const;
1899
1900   static bool classof(const ConstantPoolSDNode *) { return true; }
1901   static bool classof(const SDNode *N) {
1902     return N->getOpcode() == ISD::ConstantPool ||
1903            N->getOpcode() == ISD::TargetConstantPool;
1904   }
1905 };
1906
1907 class BasicBlockSDNode : public SDNode {
1908   MachineBasicBlock *MBB;
1909   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1910 protected:
1911   friend class SelectionDAG;
1912   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1913     : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1914   }
1915 public:
1916
1917   MachineBasicBlock *getBasicBlock() const { return MBB; }
1918
1919   static bool classof(const BasicBlockSDNode *) { return true; }
1920   static bool classof(const SDNode *N) {
1921     return N->getOpcode() == ISD::BasicBlock;
1922   }
1923 };
1924
1925 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1926 /// used when the SelectionDAG needs to make a simple reference to something
1927 /// in the LLVM IR representation.
1928 ///
1929 /// Note that this is not used for carrying alias information; that is done
1930 /// with MemOperandSDNode, which includes a Value which is required to be a
1931 /// pointer, and several other fields specific to memory references.
1932 ///
1933 class SrcValueSDNode : public SDNode {
1934   const Value *V;
1935   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1936 protected:
1937   friend class SelectionDAG;
1938   /// Create a SrcValue for a general value.
1939   explicit SrcValueSDNode(const Value *v)
1940     : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1941
1942 public:
1943   /// getValue - return the contained Value.
1944   const Value *getValue() const { return V; }
1945
1946   static bool classof(const SrcValueSDNode *) { return true; }
1947   static bool classof(const SDNode *N) {
1948     return N->getOpcode() == ISD::SRCVALUE;
1949   }
1950 };
1951
1952
1953 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
1954 /// used to represent a reference to memory after ISD::LOAD
1955 /// and ISD::STORE have been lowered.
1956 ///
1957 class MemOperandSDNode : public SDNode {
1958   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1959 protected:
1960   friend class SelectionDAG;
1961   /// Create a MachineMemOperand node
1962   explicit MemOperandSDNode(const MachineMemOperand &mo)
1963     : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1964
1965 public:
1966   /// MO - The contained MachineMemOperand.
1967   const MachineMemOperand MO;
1968
1969   static bool classof(const MemOperandSDNode *) { return true; }
1970   static bool classof(const SDNode *N) {
1971     return N->getOpcode() == ISD::MEMOPERAND;
1972   }
1973 };
1974
1975
1976 class RegisterSDNode : public SDNode {
1977   unsigned Reg;
1978   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1979 protected:
1980   friend class SelectionDAG;
1981   RegisterSDNode(unsigned reg, MVT VT)
1982     : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1983   }
1984 public:
1985
1986   unsigned getReg() const { return Reg; }
1987
1988   static bool classof(const RegisterSDNode *) { return true; }
1989   static bool classof(const SDNode *N) {
1990     return N->getOpcode() == ISD::Register;
1991   }
1992 };
1993
1994 class DbgStopPointSDNode : public SDNode {
1995   SDUse Chain;
1996   unsigned Line;
1997   unsigned Column;
1998   const CompileUnitDesc *CU;
1999   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2000 protected:
2001   friend class SelectionDAG;
2002   DbgStopPointSDNode(SDValue ch, unsigned l, unsigned c,
2003                      const CompileUnitDesc *cu)
2004     : SDNode(ISD::DBG_STOPPOINT, getSDVTList(MVT::Other)),
2005       Line(l), Column(c), CU(cu) {
2006     Chain = ch;
2007     InitOperands(&Chain, 1);
2008   }
2009 public:
2010   unsigned getLine() const { return Line; }
2011   unsigned getColumn() const { return Column; }
2012   const CompileUnitDesc *getCompileUnit() const { return CU; }
2013
2014   static bool classof(const DbgStopPointSDNode *) { return true; }
2015   static bool classof(const SDNode *N) {
2016     return N->getOpcode() == ISD::DBG_STOPPOINT;
2017   }
2018 };
2019
2020 class LabelSDNode : public SDNode {
2021   SDUse Chain;
2022   unsigned LabelID;
2023   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2024 protected:
2025   friend class SelectionDAG;
2026   LabelSDNode(unsigned NodeTy, SDValue ch, unsigned id)
2027     : SDNode(NodeTy, getSDVTList(MVT::Other)), LabelID(id) {
2028     Chain = ch;
2029     InitOperands(&Chain, 1);
2030   }
2031 public:
2032   unsigned getLabelID() const { return LabelID; }
2033
2034   static bool classof(const LabelSDNode *) { return true; }
2035   static bool classof(const SDNode *N) {
2036     return N->getOpcode() == ISD::DBG_LABEL ||
2037            N->getOpcode() == ISD::EH_LABEL;
2038   }
2039 };
2040
2041 class ExternalSymbolSDNode : public SDNode {
2042   const char *Symbol;
2043   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2044 protected:
2045   friend class SelectionDAG;
2046   ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT VT)
2047     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
2048              getSDVTList(VT)), Symbol(Sym) {
2049   }
2050 public:
2051
2052   const char *getSymbol() const { return Symbol; }
2053
2054   static bool classof(const ExternalSymbolSDNode *) { return true; }
2055   static bool classof(const SDNode *N) {
2056     return N->getOpcode() == ISD::ExternalSymbol ||
2057            N->getOpcode() == ISD::TargetExternalSymbol;
2058   }
2059 };
2060
2061 class CondCodeSDNode : public SDNode {
2062   ISD::CondCode Condition;
2063   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2064 protected:
2065   friend class SelectionDAG;
2066   explicit CondCodeSDNode(ISD::CondCode Cond)
2067     : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
2068   }
2069 public:
2070
2071   ISD::CondCode get() const { return Condition; }
2072
2073   static bool classof(const CondCodeSDNode *) { return true; }
2074   static bool classof(const SDNode *N) {
2075     return N->getOpcode() == ISD::CONDCODE;
2076   }
2077 };
2078
2079 namespace ISD {
2080   struct ArgFlagsTy {
2081   private:
2082     static const uint64_t NoFlagSet      = 0ULL;
2083     static const uint64_t ZExt           = 1ULL<<0;  ///< Zero extended
2084     static const uint64_t ZExtOffs       = 0;
2085     static const uint64_t SExt           = 1ULL<<1;  ///< Sign extended
2086     static const uint64_t SExtOffs       = 1;
2087     static const uint64_t InReg          = 1ULL<<2;  ///< Passed in register
2088     static const uint64_t InRegOffs      = 2;
2089     static const uint64_t SRet           = 1ULL<<3;  ///< Hidden struct-ret ptr
2090     static const uint64_t SRetOffs       = 3;
2091     static const uint64_t ByVal          = 1ULL<<4;  ///< Struct passed by value
2092     static const uint64_t ByValOffs      = 4;
2093     static const uint64_t Nest           = 1ULL<<5;  ///< Nested fn static chain
2094     static const uint64_t NestOffs       = 5;
2095     static const uint64_t ByValAlign     = 0xFULL << 6; //< Struct alignment
2096     static const uint64_t ByValAlignOffs = 6;
2097     static const uint64_t Split          = 1ULL << 10;
2098     static const uint64_t SplitOffs      = 10;
2099     static const uint64_t OrigAlign      = 0x1FULL<<27;
2100     static const uint64_t OrigAlignOffs  = 27;
2101     static const uint64_t ByValSize      = 0xffffffffULL << 32; //< Struct size
2102     static const uint64_t ByValSizeOffs  = 32;
2103
2104     static const uint64_t One            = 1ULL; //< 1 of this type, for shifts
2105
2106     uint64_t Flags;
2107   public:
2108     ArgFlagsTy() : Flags(0) { }
2109
2110     bool isZExt()   const { return Flags & ZExt; }
2111     void setZExt()  { Flags |= One << ZExtOffs; }
2112
2113     bool isSExt()   const { return Flags & SExt; }
2114     void setSExt()  { Flags |= One << SExtOffs; }
2115
2116     bool isInReg()  const { return Flags & InReg; }
2117     void setInReg() { Flags |= One << InRegOffs; }
2118
2119     bool isSRet()   const { return Flags & SRet; }
2120     void setSRet()  { Flags |= One << SRetOffs; }
2121
2122     bool isByVal()  const { return Flags & ByVal; }
2123     void setByVal() { Flags |= One << ByValOffs; }
2124
2125     bool isNest()   const { return Flags & Nest; }
2126     void setNest()  { Flags |= One << NestOffs; }
2127
2128     unsigned getByValAlign() const {
2129       return (unsigned) 
2130         ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
2131     }
2132     void setByValAlign(unsigned A) {
2133       Flags = (Flags & ~ByValAlign) |
2134         (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
2135     }
2136             
2137     bool isSplit()   const { return Flags & Split; }
2138     void setSplit()  { Flags |= One << SplitOffs; }
2139
2140     unsigned getOrigAlign() const {
2141       return (unsigned)
2142         ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
2143     }
2144     void setOrigAlign(unsigned A) {
2145       Flags = (Flags & ~OrigAlign) |
2146         (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
2147     }
2148
2149     unsigned getByValSize() const {
2150       return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
2151     }
2152     void setByValSize(unsigned S) {
2153       Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
2154     }
2155
2156     /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
2157     std::string getArgFlagsString();
2158
2159     /// getRawBits - Represent the flags as a bunch of bits.
2160     uint64_t getRawBits() const { return Flags; }
2161   };
2162 }
2163
2164 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
2165 class ARG_FLAGSSDNode : public SDNode {
2166   ISD::ArgFlagsTy TheFlags;
2167   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2168 protected:
2169   friend class SelectionDAG;
2170   explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
2171     : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
2172   }
2173 public:
2174   ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
2175
2176   static bool classof(const ARG_FLAGSSDNode *) { return true; }
2177   static bool classof(const SDNode *N) {
2178     return N->getOpcode() == ISD::ARG_FLAGS;
2179   }
2180 };
2181
2182 /// VTSDNode - This class is used to represent MVT's, which are used
2183 /// to parameterize some operations.
2184 class VTSDNode : public SDNode {
2185   MVT ValueType;
2186   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2187 protected:
2188   friend class SelectionDAG;
2189   explicit VTSDNode(MVT VT)
2190     : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
2191   }
2192 public:
2193
2194   MVT getVT() const { return ValueType; }
2195
2196   static bool classof(const VTSDNode *) { return true; }
2197   static bool classof(const SDNode *N) {
2198     return N->getOpcode() == ISD::VALUETYPE;
2199   }
2200 };
2201
2202 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
2203 ///
2204 class LSBaseSDNode : public MemSDNode {
2205 protected:
2206   //! Operand array for load and store
2207   /*!
2208     \note Moving this array to the base class captures more
2209     common functionality shared between LoadSDNode and
2210     StoreSDNode
2211    */
2212   SDUse Ops[4];
2213 public:
2214   LSBaseSDNode(ISD::NodeType NodeTy, SDValue *Operands, unsigned numOperands,
2215                SDVTList VTs, ISD::MemIndexedMode AM, MVT VT,
2216                const Value *SV, int SVO, unsigned Align, bool Vol)
2217     : MemSDNode(NodeTy, VTs, VT, SV, SVO, Align, Vol) {
2218     SubclassData = AM;
2219     for (unsigned i = 0; i != numOperands; ++i)
2220       Ops[i] = Operands[i];
2221     InitOperands(Ops, numOperands);
2222     assert(Align != 0 && "Loads and stores should have non-zero aligment");
2223     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
2224            "Only indexed loads and stores have a non-undef offset operand");
2225   }
2226
2227   const SDValue &getOffset() const {
2228     return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
2229   }
2230
2231   /// getAddressingMode - Return the addressing mode for this load or store:
2232   /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
2233   ISD::MemIndexedMode getAddressingMode() const {
2234     return ISD::MemIndexedMode(SubclassData & 7);
2235   }
2236
2237   /// isIndexed - Return true if this is a pre/post inc/dec load/store.
2238   bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
2239
2240   /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
2241   bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
2242
2243   static bool classof(const LSBaseSDNode *) { return true; }
2244   static bool classof(const SDNode *N) {
2245     return N->getOpcode() == ISD::LOAD ||
2246            N->getOpcode() == ISD::STORE;
2247   }
2248 };
2249
2250 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
2251 ///
2252 class LoadSDNode : public LSBaseSDNode {
2253   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2254 protected:
2255   friend class SelectionDAG;
2256   LoadSDNode(SDValue *ChainPtrOff, SDVTList VTs,
2257              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT,
2258              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2259     : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
2260                    VTs, AM, LVT, SV, O, Align, Vol) {
2261     SubclassData |= (unsigned short)ETy << 3;
2262   }
2263 public:
2264
2265   /// getExtensionType - Return whether this is a plain node,
2266   /// or one of the varieties of value-extending loads.
2267   ISD::LoadExtType getExtensionType() const {
2268     return ISD::LoadExtType((SubclassData >> 3) & 3);
2269   }
2270
2271   const SDValue &getBasePtr() const { return getOperand(1); }
2272   const SDValue &getOffset() const { return getOperand(2); }
2273   
2274   static bool classof(const LoadSDNode *) { return true; }
2275   static bool classof(const SDNode *N) {
2276     return N->getOpcode() == ISD::LOAD;
2277   }
2278 };
2279
2280 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2281 ///
2282 class StoreSDNode : public LSBaseSDNode {
2283   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2284 protected:
2285   friend class SelectionDAG;
2286   StoreSDNode(SDValue *ChainValuePtrOff, SDVTList VTs,
2287               ISD::MemIndexedMode AM, bool isTrunc, MVT SVT,
2288               const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2289     : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
2290                    VTs, AM, SVT, SV, O, Align, Vol) {
2291     SubclassData |= (unsigned short)isTrunc << 3;
2292   }
2293 public:
2294
2295   /// isTruncatingStore - Return true if the op does a truncation before store.
2296   /// For integers this is the same as doing a TRUNCATE and storing the result.
2297   /// For floats, it is the same as doing an FP_ROUND and storing the result.
2298   bool isTruncatingStore() const { return (SubclassData >> 3) & 1; }
2299
2300   const SDValue &getValue() const { return getOperand(1); }
2301   const SDValue &getBasePtr() const { return getOperand(2); }
2302   const SDValue &getOffset() const { return getOperand(3); }
2303   
2304   static bool classof(const StoreSDNode *) { return true; }
2305   static bool classof(const SDNode *N) {
2306     return N->getOpcode() == ISD::STORE;
2307   }
2308 };
2309
2310
2311 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
2312   SDNode *Node;
2313   unsigned Operand;
2314
2315   SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2316 public:
2317   bool operator==(const SDNodeIterator& x) const {
2318     return Operand == x.Operand;
2319   }
2320   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2321
2322   const SDNodeIterator &operator=(const SDNodeIterator &I) {
2323     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2324     Operand = I.Operand;
2325     return *this;
2326   }
2327
2328   pointer operator*() const {
2329     return Node->getOperand(Operand).getNode();
2330   }
2331   pointer operator->() const { return operator*(); }
2332
2333   SDNodeIterator& operator++() {                // Preincrement
2334     ++Operand;
2335     return *this;
2336   }
2337   SDNodeIterator operator++(int) { // Postincrement
2338     SDNodeIterator tmp = *this; ++*this; return tmp;
2339   }
2340
2341   static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2342   static SDNodeIterator end  (SDNode *N) {
2343     return SDNodeIterator(N, N->getNumOperands());
2344   }
2345
2346   unsigned getOperand() const { return Operand; }
2347   const SDNode *getNode() const { return Node; }
2348 };
2349
2350 template <> struct GraphTraits<SDNode*> {
2351   typedef SDNode NodeType;
2352   typedef SDNodeIterator ChildIteratorType;
2353   static inline NodeType *getEntryNode(SDNode *N) { return N; }
2354   static inline ChildIteratorType child_begin(NodeType *N) {
2355     return SDNodeIterator::begin(N);
2356   }
2357   static inline ChildIteratorType child_end(NodeType *N) {
2358     return SDNodeIterator::end(N);
2359   }
2360 };
2361
2362 /// LargestSDNode - The largest SDNode class.
2363 ///
2364 typedef LoadSDNode LargestSDNode;
2365
2366 /// MostAlignedSDNode - The SDNode class with the greatest alignment
2367 /// requirement.
2368 ///
2369 typedef ConstantSDNode MostAlignedSDNode;
2370
2371 namespace ISD {
2372   /// isNormalLoad - Returns true if the specified node is a non-extending
2373   /// and unindexed load.
2374   inline bool isNormalLoad(const SDNode *N) {
2375     const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
2376     return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2377       Ld->getAddressingMode() == ISD::UNINDEXED;
2378   }
2379
2380   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2381   /// load.
2382   inline bool isNON_EXTLoad(const SDNode *N) {
2383     return isa<LoadSDNode>(N) &&
2384       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2385   }
2386
2387   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2388   ///
2389   inline bool isEXTLoad(const SDNode *N) {
2390     return isa<LoadSDNode>(N) &&
2391       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2392   }
2393
2394   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2395   ///
2396   inline bool isSEXTLoad(const SDNode *N) {
2397     return isa<LoadSDNode>(N) &&
2398       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2399   }
2400
2401   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2402   ///
2403   inline bool isZEXTLoad(const SDNode *N) {
2404     return isa<LoadSDNode>(N) &&
2405       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2406   }
2407
2408   /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
2409   ///
2410   inline bool isUNINDEXEDLoad(const SDNode *N) {
2411     return isa<LoadSDNode>(N) &&
2412       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2413   }
2414
2415   /// isNormalStore - Returns true if the specified node is a non-truncating
2416   /// and unindexed store.
2417   inline bool isNormalStore(const SDNode *N) {
2418     const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
2419     return St && !St->isTruncatingStore() &&
2420       St->getAddressingMode() == ISD::UNINDEXED;
2421   }
2422
2423   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2424   /// store.
2425   inline bool isNON_TRUNCStore(const SDNode *N) {
2426     return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
2427   }
2428
2429   /// isTRUNCStore - Returns true if the specified node is a truncating
2430   /// store.
2431   inline bool isTRUNCStore(const SDNode *N) {
2432     return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
2433   }
2434
2435   /// isUNINDEXEDStore - Returns true if the specified node is an
2436   /// unindexed store.
2437   inline bool isUNINDEXEDStore(const SDNode *N) {
2438     return isa<StoreSDNode>(N) &&
2439       cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2440   }
2441 }
2442
2443
2444 } // end llvm namespace
2445
2446 #endif