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