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