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