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