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