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