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