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