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