Backing out 48222 temporarily.
[oota-llvm.git] / include / llvm / CodeGen / SelectionDAGNodes.h
1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG.  These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
14 //
15 // Clients should include the SelectionDAG.h file instead of this file directly.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
21
22 #include "llvm/Value.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator"
26 #include "llvm/ADT/APFloat.h"
27 #include "llvm/ADT/APInt.h"
28 #include "llvm/CodeGen/ValueTypes.h"
29 #include "llvm/CodeGen/MemOperand.h"
30 #include "llvm/Support/DataTypes.h"
31 #include <cassert>
32
33 namespace llvm {
34
35 class SelectionDAG;
36 class GlobalValue;
37 class MachineBasicBlock;
38 class MachineConstantPoolValue;
39 class SDNode;
40 template <typename T> struct DenseMapInfo;
41 template <typename T> struct simplify_type;
42 template <typename T> struct ilist_traits;
43 template<typename NodeTy, typename Traits> class iplist;
44 template<typename NodeTy> class ilist_iterator;
45
46 /// SDVTList - This represents a list of ValueType's that has been intern'd by
47 /// a SelectionDAG.  Instances of this simple value class are returned by
48 /// SelectionDAG::getVTList(...).
49 ///
50 struct SDVTList {
51   const MVT::ValueType *VTs;
52   unsigned short NumVTs;
53 };
54
55 /// ISD namespace - This namespace contains an enum which represents all of the
56 /// SelectionDAG node types and value types.
57 ///
58 namespace ISD {
59
60   //===--------------------------------------------------------------------===//
61   /// ISD::NodeType enum - This enum defines all of the operators valid in a
62   /// SelectionDAG.
63   ///
64   enum NodeType {
65     // DELETED_NODE - This is an illegal flag value that is used to catch
66     // errors.  This opcode is not a legal opcode for any node.
67     DELETED_NODE,
68     
69     // EntryToken - This is the marker used to indicate the start of the region.
70     EntryToken,
71
72     // Token factor - This node takes multiple tokens as input and produces a
73     // single token result.  This is used to represent the fact that the operand
74     // operators are independent of each other.
75     TokenFactor,
76     
77     // AssertSext, AssertZext - These nodes record if a register contains a 
78     // value that has already been zero or sign extended from a narrower type.  
79     // These nodes take two operands.  The first is the node that has already 
80     // been extended, and the second is a value type node indicating the width
81     // of the extension
82     AssertSext, AssertZext,
83
84     // Various leaf nodes.
85     STRING, BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
86     Constant, ConstantFP,
87     GlobalAddress, GlobalTLSAddress, FrameIndex,
88     JumpTable, ConstantPool, ExternalSymbol,
89
90     // The address of the GOT
91     GLOBAL_OFFSET_TABLE,
92     
93     // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
94     // llvm.returnaddress on the DAG.  These nodes take one operand, the index
95     // of the frame or return address to return.  An index of zero corresponds
96     // to the current function's frame or return address, an index of one to the
97     // parent's frame or return address, and so on.
98     FRAMEADDR, RETURNADDR,
99
100     // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
101     // first (possible) on-stack argument. This is needed for correct stack
102     // adjustment during unwind.
103     FRAME_TO_ARGS_OFFSET,
104     
105     // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
106     // address of the exception block on entry to an landing pad block.
107     EXCEPTIONADDR,
108     
109     // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
110     // the selection index of the exception thrown.
111     EHSELECTION,
112
113     // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
114     // 'eh_return' gcc dwarf builtin, which is used to return from
115     // exception. The general meaning is: adjust stack by OFFSET and pass
116     // execution to HANDLER. Many platform-related details also :)
117     EH_RETURN,
118
119     // TargetConstant* - Like Constant*, but the DAG does not do any folding or
120     // simplification of the constant.
121     TargetConstant,
122     TargetConstantFP,
123     
124     // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
125     // anything else with this node, and this is valid in the target-specific
126     // dag, turning into a GlobalAddress operand.
127     TargetGlobalAddress,
128     TargetGlobalTLSAddress,
129     TargetFrameIndex,
130     TargetJumpTable,
131     TargetConstantPool,
132     TargetExternalSymbol,
133     
134     /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
135     /// This node represents a target intrinsic function with no side effects.
136     /// The first operand is the ID number of the intrinsic from the
137     /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
138     /// node has returns the result of the intrinsic.
139     INTRINSIC_WO_CHAIN,
140     
141     /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
142     /// This node represents a target intrinsic function with side effects that
143     /// returns a result.  The first operand is a chain pointer.  The second is
144     /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
145     /// operands to the intrinsic follow.  The node has two results, the result
146     /// of the intrinsic and an output chain.
147     INTRINSIC_W_CHAIN,
148
149     /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
150     /// This node represents a target intrinsic function with side effects that
151     /// does not return a result.  The first operand is a chain pointer.  The
152     /// second is the ID number of the intrinsic from the llvm::Intrinsic
153     /// namespace.  The operands to the intrinsic follow.
154     INTRINSIC_VOID,
155     
156     // CopyToReg - This node has three operands: a chain, a register number to
157     // set to this value, and a value.  
158     CopyToReg,
159
160     // CopyFromReg - This node indicates that the input value is a virtual or
161     // physical register that is defined outside of the scope of this
162     // SelectionDAG.  The register is available from the RegisterSDNode object.
163     CopyFromReg,
164
165     // UNDEF - An undefined node
166     UNDEF,
167     
168     /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
169     /// represents the formal arguments for a function.  CC# is a Constant value
170     /// indicating the calling convention of the function, and ISVARARG is a
171     /// flag that indicates whether the function is varargs or not. This node
172     /// has one result value for each incoming argument, plus one for the output
173     /// chain. It must be custom legalized. See description of CALL node for
174     /// FLAG argument contents explanation.
175     /// 
176     FORMAL_ARGUMENTS,
177     
178     /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
179     ///                              ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
180     /// This node represents a fully general function call, before the legalizer
181     /// runs.  This has one result value for each argument / flag pair, plus
182     /// a chain result. It must be custom legalized. Flag argument indicates
183     /// misc. argument attributes. Currently:
184     /// Bit 0 - signness
185     /// Bit 1 - 'inreg' attribute
186     /// Bit 2 - 'sret' attribute
187     /// Bit 4 - 'byval' attribute
188     /// Bit 5 - 'nest' attribute
189     /// Bit 6-9 - alignment of byval structures
190     /// Bit 10-26 - size of byval structures
191     /// Bits 31:27 - argument ABI alignment in the first argument piece and
192     /// alignment '1' in other argument pieces.
193     CALL,
194
195     // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
196     // a Constant, which is required to be operand #1) half of the integer value
197     // specified as operand #0.  This is only for use before legalization, for
198     // values that will be broken into multiple registers.
199     EXTRACT_ELEMENT,
200
201     // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
202     // two values of the same integer value type, this produces a value twice as
203     // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
204     BUILD_PAIR,
205     
206     // MERGE_VALUES - This node takes multiple discrete operands and returns
207     // them all as its individual results.  This nodes has exactly the same
208     // number of inputs and outputs, and is only valid before legalization.
209     // This node is useful for some pieces of the code generator that want to
210     // think about a single node with multiple results, not multiple nodes.
211     MERGE_VALUES,
212
213     // Simple integer binary arithmetic operators.
214     ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
215
216     // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
217     // a signed/unsigned value of type i[2*N], and return the full value as
218     // two results, each of type iN.
219     SMUL_LOHI, UMUL_LOHI,
220
221     // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
222     // remainder result.
223     SDIVREM, UDIVREM,
224     
225     // CARRY_FALSE - This node is used when folding other nodes,
226     // like ADDC/SUBC, which indicate the carry result is always false.
227     CARRY_FALSE,
228     
229     // Carry-setting nodes for multiple precision addition and subtraction.
230     // These nodes take two operands of the same value type, and produce two
231     // results.  The first result is the normal add or sub result, the second
232     // result is the carry flag result.
233     ADDC, SUBC,
234     
235     // Carry-using nodes for multiple precision addition and subtraction.  These
236     // nodes take three operands: The first two are the normal lhs and rhs to
237     // the add or sub, and the third is the input carry flag.  These nodes
238     // produce two results; the normal result of the add or sub, and the output
239     // carry flag.  These nodes both read and write a carry flag to allow them
240     // to them to be chained together for add and sub of arbitrarily large
241     // values.
242     ADDE, SUBE,
243     
244     // Simple binary floating point operators.
245     FADD, FSUB, FMUL, FDIV, FREM,
246
247     // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
248     // DAG node does not require that X and Y have the same type, just that they
249     // are both floating point.  X and the result must have the same type.
250     // FCOPYSIGN(f32, f64) is allowed.
251     FCOPYSIGN,
252
253     // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
254     // value as an integer 0/1 value.
255     FGETSIGN,
256     
257     /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
258     /// with the specified, possibly variable, elements.  The number of elements
259     /// is required to be a power of two.
260     BUILD_VECTOR,
261     
262     /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
263     /// at IDX replaced with VAL.  If the type of VAL is larger than the vector
264     /// element type then VAL is truncated before replacement.
265     INSERT_VECTOR_ELT,
266
267     /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
268     /// identified by the (potentially variable) element number IDX.
269     EXTRACT_VECTOR_ELT,
270     
271     /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
272     /// vector type with the same length and element type, this produces a
273     /// concatenated vector result value, with length equal to the sum of the
274     /// lengths of the input vectors.
275     CONCAT_VECTORS,
276     
277     /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
278     /// vector value) starting with the (potentially variable) element number
279     /// IDX, which must be a multiple of the result vector length.
280     EXTRACT_SUBVECTOR,
281
282     /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
283     /// type as VEC1/VEC2.  SHUFFLEVEC is a BUILD_VECTOR of constant int values
284     /// (maybe of an illegal datatype) or undef that indicate which value each
285     /// result element will get.  The elements of VEC1/VEC2 are enumerated in
286     /// order.  This is quite similar to the Altivec 'vperm' instruction, except
287     /// that the indices must be constants and are in terms of the element size
288     /// of VEC1/VEC2, not in terms of bytes.
289     VECTOR_SHUFFLE,
290
291     /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
292     /// scalar value into element 0 of the resultant vector type.  The top
293     /// elements 1 to N-1 of the N-element vector are undefined.
294     SCALAR_TO_VECTOR,
295     
296     // EXTRACT_SUBREG - This node is used to extract a sub-register value. 
297     // This node takes a superreg and a constant sub-register index as operands.
298     // Note sub-register indices must be increasing. That is, if the
299     // sub-register index of a 8-bit sub-register is N, then the index for a
300     // 16-bit sub-register must be at least N+1.
301     EXTRACT_SUBREG,
302     
303     // INSERT_SUBREG - This node is used to insert a sub-register value. 
304     // This node takes a superreg, a subreg value, and a constant sub-register
305     // index as operands.
306     INSERT_SUBREG,
307     
308     // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
309     // an unsigned/signed value of type i[2*N], then return the top part.
310     MULHU, MULHS,
311
312     // Bitwise operators - logical and, logical or, logical xor, shift left,
313     // shift right algebraic (shift in sign bits), shift right logical (shift in
314     // zeroes), rotate left, rotate right, and byteswap.
315     AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
316
317     // Counting operators
318     CTTZ, CTLZ, CTPOP,
319
320     // Select(COND, TRUEVAL, FALSEVAL)
321     SELECT, 
322     
323     // Select with condition operator - This selects between a true value and 
324     // a false value (ops #2 and #3) based on the boolean result of comparing
325     // the lhs and rhs (ops #0 and #1) of a conditional expression with the 
326     // condition code in op #4, a CondCodeSDNode.
327     SELECT_CC,
328
329     // SetCC operator - This evaluates to a boolean (i1) true value if the
330     // condition is true.  The operands to this are the left and right operands
331     // to compare (ops #0, and #1) and the condition code to compare them with
332     // (op #2) as a CondCodeSDNode.
333     SETCC,
334
335     // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
336     // integer shift operations, just like ADD/SUB_PARTS.  The operation
337     // ordering is:
338     //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
339     SHL_PARTS, SRA_PARTS, SRL_PARTS,
340
341     // Conversion operators.  These are all single input single output
342     // operations.  For all of these, the result type must be strictly
343     // wider or narrower (depending on the operation) than the source
344     // type.
345
346     // SIGN_EXTEND - Used for integer types, replicating the sign bit
347     // into new bits.
348     SIGN_EXTEND,
349
350     // ZERO_EXTEND - Used for integer types, zeroing the new bits.
351     ZERO_EXTEND,
352
353     // ANY_EXTEND - Used for integer types.  The high bits are undefined.
354     ANY_EXTEND,
355     
356     // TRUNCATE - Completely drop the high bits.
357     TRUNCATE,
358
359     // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
360     // depends on the first letter) to floating point.
361     SINT_TO_FP,
362     UINT_TO_FP,
363
364     // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
365     // sign extend a small value in a large integer register (e.g. sign
366     // extending the low 8 bits of a 32-bit register to fill the top 24 bits
367     // with the 7th bit).  The size of the smaller type is indicated by the 1th
368     // operand, a ValueType node.
369     SIGN_EXTEND_INREG,
370
371     /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
372     /// integer.
373     FP_TO_SINT,
374     FP_TO_UINT,
375
376     /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
377     /// down to the precision of the destination VT.  TRUNC is a flag, which is
378     /// always an integer that is zero or one.  If TRUNC is 0, this is a
379     /// normal rounding, if it is 1, this FP_ROUND is known to not change the
380     /// value of Y.
381     ///
382     /// The TRUNC = 1 case is used in cases where we know that the value will
383     /// not be modified by the node, because Y is not using any of the extra
384     /// precision of source type.  This allows certain transformations like
385     /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for 
386     /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
387     FP_ROUND,
388     
389     // FLT_ROUNDS_ - Returns current rounding mode:
390     // -1 Undefined
391     //  0 Round to 0
392     //  1 Round to nearest
393     //  2 Round to +inf
394     //  3 Round to -inf
395     FLT_ROUNDS_,
396
397     /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
398     /// rounds it to a floating point value.  It then promotes it and returns it
399     /// in a register of the same size.  This operation effectively just
400     /// discards excess precision.  The type to round down to is specified by
401     /// the VT operand, a VTSDNode.
402     FP_ROUND_INREG,
403
404     /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
405     FP_EXTEND,
406
407     // BIT_CONVERT - Theis operator converts between integer and FP values, as
408     // if one was stored to memory as integer and the other was loaded from the
409     // same address (or equivalently for vector format conversions, etc).  The 
410     // source and result are required to have the same bit size (e.g. 
411     // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp 
412     // conversions, but that is a noop, deleted by getNode().
413     BIT_CONVERT,
414     
415     // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
416     // negation, absolute value, square root, sine and cosine, powi, and pow
417     // operations.
418     FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
419     
420     // LOAD and STORE have token chains as their first operand, then the same
421     // operands as an LLVM load/store instruction, then an offset node that
422     // is added / subtracted from the base pointer to form the address (for
423     // indexed memory ops).
424     LOAD, STORE,
425
426     // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
427     // to a specified boundary.  This node always has two return values: a new
428     // stack pointer value and a chain. The first operand is the token chain,
429     // the second is the number of bytes to allocate, and the third is the
430     // alignment boundary.  The size is guaranteed to be a multiple of the stack
431     // alignment, and the alignment is guaranteed to be bigger than the stack
432     // alignment (if required) or 0 to get standard stack alignment.
433     DYNAMIC_STACKALLOC,
434
435     // Control flow instructions.  These all have token chains.
436
437     // BR - Unconditional branch.  The first operand is the chain
438     // operand, the second is the MBB to branch to.
439     BR,
440
441     // BRIND - Indirect branch.  The first operand is the chain, the second
442     // is the value to branch to, which must be of the same type as the target's
443     // pointer type.
444     BRIND,
445
446     // BR_JT - Jumptable branch. The first operand is the chain, the second
447     // is the jumptable index, the last one is the jumptable entry index.
448     BR_JT,
449     
450     // BRCOND - Conditional branch.  The first operand is the chain,
451     // the second is the condition, the third is the block to branch
452     // to if the condition is true.
453     BRCOND,
454
455     // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
456     // that the condition is represented as condition code, and two nodes to
457     // compare, rather than as a combined SetCC node.  The operands in order are
458     // chain, cc, lhs, rhs, block to branch to if condition is true.
459     BR_CC,
460     
461     // RET - Return from function.  The first operand is the chain,
462     // and any subsequent operands are pairs of return value and return value
463     // signness for the function.  This operation can have variable number of
464     // operands.
465     RET,
466
467     // INLINEASM - Represents an inline asm block.  This node always has two
468     // return values: a chain and a flag result.  The inputs are as follows:
469     //   Operand #0   : Input chain.
470     //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
471     //   Operand #2n+2: A RegisterNode.
472     //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
473     //   Operand #last: Optional, an incoming flag.
474     INLINEASM,
475     
476     // LABEL - Represents a label in mid basic block used to track
477     // locations needed for debug and exception handling tables.  This node
478     // returns a chain.
479     //   Operand #0 : input chain.
480     //   Operand #1 : module unique number use to identify the label.
481     //   Operand #2 : 0 indicates a debug label (e.g. stoppoint), 1 indicates
482     //                a EH label, 2 indicates unknown label type.
483     LABEL,
484
485     // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
486     // local variable declarations for debugging information. First operand is
487     // a chain, while the next two operands are first two arguments (address
488     // and variable) of a llvm.dbg.declare instruction.
489     DECLARE,
490     
491     // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
492     // value, the same type as the pointer type for the system, and an output
493     // chain.
494     STACKSAVE,
495     
496     // STACKRESTORE has two operands, an input chain and a pointer to restore to
497     // it returns an output chain.
498     STACKRESTORE,
499     
500     // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain. The following
501     // correspond to the operands of the LLVM intrinsic functions and the last
502     // one is AlwaysInline.  The only result is a token chain.  The alignment
503     // argument is guaranteed to be a Constant node.
504     MEMSET,
505     MEMMOVE,
506     MEMCPY,
507
508     // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
509     // a call sequence, and carry arbitrary information that target might want
510     // to know.  The first operand is a chain, the rest are specified by the
511     // target and not touched by the DAG optimizers.
512     // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
513     CALLSEQ_START,  // Beginning of a call sequence
514     CALLSEQ_END,    // End of a call sequence
515     
516     // VAARG - VAARG has three operands: an input chain, a pointer, and a 
517     // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
518     VAARG,
519     
520     // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
521     // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
522     // source.
523     VACOPY,
524     
525     // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
526     // pointer, and a SRCVALUE.
527     VAEND, VASTART,
528
529     // SRCVALUE - This is a node type that holds a Value* that is used to
530     // make reference to a value in the LLVM IR.
531     SRCVALUE,
532
533     // MEMOPERAND - This is a node that contains a MemOperand which records
534     // information about a memory reference. This is used to make AliasAnalysis
535     // queries from the backend.
536     MEMOPERAND,
537
538     // PCMARKER - This corresponds to the pcmarker intrinsic.
539     PCMARKER,
540
541     // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
542     // The only operand is a chain and a value and a chain are produced.  The
543     // value is the contents of the architecture specific cycle counter like 
544     // register (or other high accuracy low latency clock source)
545     READCYCLECOUNTER,
546
547     // HANDLENODE node - Used as a handle for various purposes.
548     HANDLENODE,
549
550     // LOCATION - This node is used to represent a source location for debug
551     // info.  It takes token chain as input, then a line number, then a column
552     // number, then a filename, then a working dir.  It produces a token chain
553     // as output.
554     LOCATION,
555     
556     // DEBUG_LOC - This node is used to represent source line information
557     // embedded in the code.  It takes a token chain as input, then a line
558     // number, then a column then a file id (provided by MachineModuleInfo.) It
559     // produces a token chain as output.
560     DEBUG_LOC,
561
562     // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
563     // It takes as input a token chain, the pointer to the trampoline,
564     // the pointer to the nested function, the pointer to pass for the
565     // 'nest' parameter, a SRCVALUE for the trampoline and another for
566     // the nested function (allowing targets to access the original
567     // Function*).  It produces the result of the intrinsic and a token
568     // chain as output.
569     TRAMPOLINE,
570
571     // TRAP - Trapping instruction
572     TRAP,
573
574     // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
575     // their first operand. The other operands are the address to prefetch,
576     // read / write specifier, and locality specifier.
577     PREFETCH,
578
579     // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load, 
580     //                       store-store, device)
581     // This corresponds to the memory.barrier intrinsic.
582     // it takes an input chain, 4 operands to specify the type of barrier, an
583     // operand specifying if the barrier applies to device and uncached memory
584     // and produces an output chain.
585     MEMBARRIER,
586
587     // Val, OUTCHAIN = ATOMIC_LCS(INCHAIN, ptr, cmp, swap)
588     // this corresponds to the atomic.lcs intrinsic.
589     // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
590     // the return is always the original value in *ptr
591     ATOMIC_LCS,
592
593     // Val, OUTCHAIN = ATOMIC_LAS(INCHAIN, ptr, amt)
594     // this corresponds to the atomic.las intrinsic.
595     // *ptr + amt is stored to *ptr atomically.
596     // the return is always the original value in *ptr
597     ATOMIC_LAS,
598
599     // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
600     // this corresponds to the atomic.swap intrinsic.
601     // amt is stored to *ptr atomically.
602     // the return is always the original value in *ptr
603     ATOMIC_SWAP,
604
605     // BUILTIN_OP_END - This must be the last enum value in this list.
606     BUILTIN_OP_END
607   };
608
609   /// Node predicates
610
611   /// isBuildVectorAllOnes - Return true if the specified node is a
612   /// BUILD_VECTOR where all of the elements are ~0 or undef.
613   bool isBuildVectorAllOnes(const SDNode *N);
614
615   /// isBuildVectorAllZeros - Return true if the specified node is a
616   /// BUILD_VECTOR where all of the elements are 0 or undef.
617   bool isBuildVectorAllZeros(const SDNode *N);
618
619   /// isScalarToVector - Return true if the specified node is a
620   /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
621   /// element is not an undef.
622   bool isScalarToVector(const SDNode *N);
623
624   /// isDebugLabel - Return true if the specified node represents a debug
625   /// label (i.e. ISD::LABEL or TargetInstrInfo::LABEL node and third operand
626   /// is 0).
627   bool isDebugLabel(const SDNode *N);
628   
629   //===--------------------------------------------------------------------===//
630   /// MemIndexedMode enum - This enum defines the load / store indexed 
631   /// addressing modes.
632   ///
633   /// UNINDEXED    "Normal" load / store. The effective address is already
634   ///              computed and is available in the base pointer. The offset
635   ///              operand is always undefined. In addition to producing a
636   ///              chain, an unindexed load produces one value (result of the
637   ///              load); an unindexed store does not produce a value.
638   ///
639   /// PRE_INC      Similar to the unindexed mode where the effective address is
640   /// PRE_DEC      the value of the base pointer add / subtract the offset.
641   ///              It considers the computation as being folded into the load /
642   ///              store operation (i.e. the load / store does the address
643   ///              computation as well as performing the memory transaction).
644   ///              The base operand is always undefined. In addition to
645   ///              producing a chain, pre-indexed load produces two values
646   ///              (result of the load and the result of the address
647   ///              computation); a pre-indexed store produces one value (result
648   ///              of the address computation).
649   ///
650   /// POST_INC     The effective address is the value of the base pointer. The
651   /// POST_DEC     value of the offset operand is then added to / subtracted
652   ///              from the base after memory transaction. In addition to
653   ///              producing a chain, post-indexed load produces two values
654   ///              (the result of the load and the result of the base +/- offset
655   ///              computation); a post-indexed store produces one value (the
656   ///              the result of the base +/- offset computation).
657   ///
658   enum MemIndexedMode {
659     UNINDEXED = 0,
660     PRE_INC,
661     PRE_DEC,
662     POST_INC,
663     POST_DEC,
664     LAST_INDEXED_MODE
665   };
666
667   //===--------------------------------------------------------------------===//
668   /// LoadExtType enum - This enum defines the three variants of LOADEXT
669   /// (load with extension).
670   ///
671   /// SEXTLOAD loads the integer operand and sign extends it to a larger
672   ///          integer result type.
673   /// ZEXTLOAD loads the integer operand and zero extends it to a larger
674   ///          integer result type.
675   /// EXTLOAD  is used for three things: floating point extending loads, 
676   ///          integer extending loads [the top bits are undefined], and vector
677   ///          extending loads [load into low elt].
678   ///
679   enum LoadExtType {
680     NON_EXTLOAD = 0,
681     EXTLOAD,
682     SEXTLOAD,
683     ZEXTLOAD,
684     LAST_LOADX_TYPE
685   };
686
687   //===--------------------------------------------------------------------===//
688   /// ISD::CondCode enum - These are ordered carefully to make the bitfields
689   /// below work out, when considering SETFALSE (something that never exists
690   /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
691   /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
692   /// to.  If the "N" column is 1, the result of the comparison is undefined if
693   /// the input is a NAN.
694   ///
695   /// All of these (except for the 'always folded ops') should be handled for
696   /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
697   /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
698   ///
699   /// Note that these are laid out in a specific order to allow bit-twiddling
700   /// to transform conditions.
701   enum CondCode {
702     // Opcode          N U L G E       Intuitive operation
703     SETFALSE,      //    0 0 0 0       Always false (always folded)
704     SETOEQ,        //    0 0 0 1       True if ordered and equal
705     SETOGT,        //    0 0 1 0       True if ordered and greater than
706     SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
707     SETOLT,        //    0 1 0 0       True if ordered and less than
708     SETOLE,        //    0 1 0 1       True if ordered and less than or equal
709     SETONE,        //    0 1 1 0       True if ordered and operands are unequal
710     SETO,          //    0 1 1 1       True if ordered (no nans)
711     SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
712     SETUEQ,        //    1 0 0 1       True if unordered or equal
713     SETUGT,        //    1 0 1 0       True if unordered or greater than
714     SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
715     SETULT,        //    1 1 0 0       True if unordered or less than
716     SETULE,        //    1 1 0 1       True if unordered, less than, or equal
717     SETUNE,        //    1 1 1 0       True if unordered or not equal
718     SETTRUE,       //    1 1 1 1       Always true (always folded)
719     // Don't care operations: undefined if the input is a nan.
720     SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
721     SETEQ,         //  1 X 0 0 1       True if equal
722     SETGT,         //  1 X 0 1 0       True if greater than
723     SETGE,         //  1 X 0 1 1       True if greater than or equal
724     SETLT,         //  1 X 1 0 0       True if less than
725     SETLE,         //  1 X 1 0 1       True if less than or equal
726     SETNE,         //  1 X 1 1 0       True if not equal
727     SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
728
729     SETCC_INVALID       // Marker value.
730   };
731
732   /// isSignedIntSetCC - Return true if this is a setcc instruction that
733   /// performs a signed comparison when used with integer operands.
734   inline bool isSignedIntSetCC(CondCode Code) {
735     return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
736   }
737
738   /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
739   /// performs an unsigned comparison when used with integer operands.
740   inline bool isUnsignedIntSetCC(CondCode Code) {
741     return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
742   }
743
744   /// isTrueWhenEqual - Return true if the specified condition returns true if
745   /// the two operands to the condition are equal.  Note that if one of the two
746   /// operands is a NaN, this value is meaningless.
747   inline bool isTrueWhenEqual(CondCode Cond) {
748     return ((int)Cond & 1) != 0;
749   }
750
751   /// getUnorderedFlavor - This function returns 0 if the condition is always
752   /// false if an operand is a NaN, 1 if the condition is always true if the
753   /// operand is a NaN, and 2 if the condition is undefined if the operand is a
754   /// NaN.
755   inline unsigned getUnorderedFlavor(CondCode Cond) {
756     return ((int)Cond >> 3) & 3;
757   }
758
759   /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
760   /// 'op' is a valid SetCC operation.
761   CondCode getSetCCInverse(CondCode Operation, bool isInteger);
762
763   /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
764   /// when given the operation for (X op Y).
765   CondCode getSetCCSwappedOperands(CondCode Operation);
766
767   /// getSetCCOrOperation - Return the result of a logical OR between different
768   /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
769   /// function returns SETCC_INVALID if it is not possible to represent the
770   /// resultant comparison.
771   CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
772
773   /// getSetCCAndOperation - Return the result of a logical AND between
774   /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
775   /// function returns SETCC_INVALID if it is not possible to represent the
776   /// resultant comparison.
777   CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
778 }  // end llvm::ISD namespace
779
780
781 //===----------------------------------------------------------------------===//
782 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
783 /// values as the result of a computation.  Many nodes return multiple values,
784 /// from loads (which define a token and a return value) to ADDC (which returns
785 /// a result and a carry value), to calls (which may return an arbitrary number
786 /// of values).
787 ///
788 /// As such, each use of a SelectionDAG computation must indicate the node that
789 /// computes it as well as which return value to use from that node.  This pair
790 /// of information is represented with the SDOperand value type.
791 ///
792 class SDOperand {
793 public:
794   SDNode *Val;        // The node defining the value we are using.
795   unsigned ResNo;     // Which return value of the node we are using.
796
797   SDOperand() : Val(0), ResNo(0) {}
798   SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
799
800   bool operator==(const SDOperand &O) const {
801     return Val == O.Val && ResNo == O.ResNo;
802   }
803   bool operator!=(const SDOperand &O) const {
804     return !operator==(O);
805   }
806   bool operator<(const SDOperand &O) const {
807     return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
808   }
809
810   SDOperand getValue(unsigned R) const {
811     return SDOperand(Val, R);
812   }
813
814   // isOperandOf - Return true if this node is an operand of N.
815   bool isOperandOf(SDNode *N) const;
816
817   /// getValueType - Return the ValueType of the referenced return value.
818   ///
819   inline MVT::ValueType getValueType() const;
820
821   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType()).
822   ///
823   unsigned getValueSizeInBits() const {
824     return MVT::getSizeInBits(getValueType());
825   }
826
827   // Forwarding methods - These forward to the corresponding methods in SDNode.
828   inline unsigned getOpcode() const;
829   inline unsigned getNumOperands() const;
830   inline const SDOperand &getOperand(unsigned i) const;
831   inline uint64_t getConstantOperandVal(unsigned i) const;
832   inline bool isTargetOpcode() const;
833   inline unsigned getTargetOpcode() const;
834
835   
836   /// reachesChainWithoutSideEffects - Return true if this operand (which must
837   /// be a chain) reaches the specified operand without crossing any 
838   /// side-effecting instructions.  In practice, this looks through token
839   /// factors and non-volatile loads.  In order to remain efficient, this only
840   /// looks a couple of nodes in, it does not do an exhaustive search.
841   bool reachesChainWithoutSideEffects(SDOperand Dest, unsigned Depth = 2) const;
842   
843   /// hasOneUse - Return true if there is exactly one operation using this
844   /// result value of the defining operator.
845   inline bool hasOneUse() const;
846
847   /// use_empty - Return true if there are no operations using this
848   /// result value of the defining operator.
849   inline bool use_empty() const;
850 };
851
852
853 template<> struct DenseMapInfo<SDOperand> {
854   static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); }
855   static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);}
856   static unsigned getHashValue(const SDOperand &Val) {
857     return ((unsigned)((uintptr_t)Val.Val >> 4) ^
858             (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo;
859   }
860   static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
861     return LHS == RHS;
862   }
863   static bool isPod() { return true; }
864 };
865
866 /// simplify_type specializations - Allow casting operators to work directly on
867 /// SDOperands as if they were SDNode*'s.
868 template<> struct simplify_type<SDOperand> {
869   typedef SDNode* SimpleType;
870   static SimpleType getSimplifiedValue(const SDOperand &Val) {
871     return static_cast<SimpleType>(Val.Val);
872   }
873 };
874 template<> struct simplify_type<const SDOperand> {
875   typedef SDNode* SimpleType;
876   static SimpleType getSimplifiedValue(const SDOperand &Val) {
877     return static_cast<SimpleType>(Val.Val);
878   }
879 };
880
881
882 /// SDNode - Represents one node in the SelectionDAG.
883 ///
884 class SDNode : public FoldingSetNode {
885   /// NodeType - The operation that this node performs.
886   ///
887   unsigned short NodeType;
888   
889   /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
890   /// then they will be delete[]'d when the node is destroyed.
891   bool OperandsNeedDelete : 1;
892
893   /// NodeId - Unique id per SDNode in the DAG.
894   int NodeId;
895
896   /// OperandList - The values that are used by this operation.
897   ///
898   SDOperand *OperandList;
899   
900   /// ValueList - The types of the values this node defines.  SDNode's may
901   /// define multiple values simultaneously.
902   const MVT::ValueType *ValueList;
903
904   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
905   unsigned short NumOperands, NumValues;
906   
907   /// Prev/Next pointers - These pointers form the linked list of of the
908   /// AllNodes list in the current DAG.
909   SDNode *Prev, *Next;
910   friend struct ilist_traits<SDNode>;
911
912   /// Uses - These are all of the SDNode's that use a value produced by this
913   /// node.
914   SmallVector<SDNode*,3> Uses;
915   
916   // Out-of-line virtual method to give class a home.
917   virtual void ANCHOR();
918 public:
919   virtual ~SDNode() {
920     assert(NumOperands == 0 && "Operand list not cleared before deletion");
921     NodeType = ISD::DELETED_NODE;
922   }
923   
924   //===--------------------------------------------------------------------===//
925   //  Accessors
926   //
927   unsigned getOpcode()  const { return NodeType; }
928   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
929   unsigned getTargetOpcode() const {
930     assert(isTargetOpcode() && "Not a target opcode!");
931     return NodeType - ISD::BUILTIN_OP_END;
932   }
933
934   size_t use_size() const { return Uses.size(); }
935   bool use_empty() const { return Uses.empty(); }
936   bool hasOneUse() const { return Uses.size() == 1; }
937
938   /// getNodeId - Return the unique node id.
939   ///
940   int getNodeId() const { return NodeId; }
941
942   /// setNodeId - Set unique node id.
943   void setNodeId(int Id) { NodeId = Id; }
944
945   typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
946   use_iterator use_begin() const { return Uses.begin(); }
947   use_iterator use_end() const { return Uses.end(); }
948
949   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
950   /// indicated value.  This method ignores uses of other values defined by this
951   /// operation.
952   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
953
954   /// hasAnyUseOfValue - Return true if there are any use of the indicated
955   /// value. This method ignores uses of other values defined by this operation.
956   bool hasAnyUseOfValue(unsigned Value) const;
957
958   /// isOnlyUseOf - Return true if this node is the only use of N.
959   ///
960   bool isOnlyUseOf(SDNode *N) const;
961
962   /// isOperandOf - Return true if this node is an operand of N.
963   ///
964   bool isOperandOf(SDNode *N) const;
965
966   /// isPredecessorOf - Return true if this node is a predecessor of N. This
967   /// node is either an operand of N or it can be reached by recursively
968   /// traversing up the operands.
969   /// NOTE: this is an expensive method. Use it carefully.
970   bool isPredecessorOf(SDNode *N) const;
971
972   /// getNumOperands - Return the number of values used by this operation.
973   ///
974   unsigned getNumOperands() const { return NumOperands; }
975
976   /// getConstantOperandVal - Helper method returns the integer value of a 
977   /// ConstantSDNode operand.
978   uint64_t getConstantOperandVal(unsigned Num) const;
979
980   const SDOperand &getOperand(unsigned Num) const {
981     assert(Num < NumOperands && "Invalid child # of SDNode!");
982     return OperandList[Num];
983   }
984
985   typedef const SDOperand* op_iterator;
986   op_iterator op_begin() const { return OperandList; }
987   op_iterator op_end() const { return OperandList+NumOperands; }
988
989
990   SDVTList getVTList() const {
991     SDVTList X = { ValueList, NumValues };
992     return X;
993   };
994   
995   /// getNumValues - Return the number of values defined/returned by this
996   /// operator.
997   ///
998   unsigned getNumValues() const { return NumValues; }
999
1000   /// getValueType - Return the type of a specified result.
1001   ///
1002   MVT::ValueType getValueType(unsigned ResNo) const {
1003     assert(ResNo < NumValues && "Illegal result number!");
1004     return ValueList[ResNo];
1005   }
1006
1007   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1008   ///
1009   unsigned getValueSizeInBits(unsigned ResNo) const {
1010     return MVT::getSizeInBits(getValueType(ResNo));
1011   }
1012
1013   typedef const MVT::ValueType* value_iterator;
1014   value_iterator value_begin() const { return ValueList; }
1015   value_iterator value_end() const { return ValueList+NumValues; }
1016
1017   /// getOperationName - Return the opcode of this operation for printing.
1018   ///
1019   std::string getOperationName(const SelectionDAG *G = 0) const;
1020   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1021   void dump() const;
1022   void dump(const SelectionDAG *G) const;
1023
1024   static bool classof(const SDNode *) { return true; }
1025
1026   /// Profile - Gather unique data for the node.
1027   ///
1028   void Profile(FoldingSetNodeID &ID);
1029
1030 protected:
1031   friend class SelectionDAG;
1032   
1033   /// getValueTypeList - Return a pointer to the specified value type.
1034   ///
1035   static const MVT::ValueType *getValueTypeList(MVT::ValueType VT);
1036   static SDVTList getSDVTList(MVT::ValueType VT) {
1037     SDVTList Ret = { getValueTypeList(VT), 1 };
1038     return Ret;
1039   }
1040
1041   SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
1042     : NodeType(Opc), NodeId(-1) {
1043     OperandsNeedDelete = true;
1044     NumOperands = NumOps;
1045     OperandList = NumOps ? new SDOperand[NumOperands] : 0;
1046     
1047     for (unsigned i = 0; i != NumOps; ++i) {
1048       OperandList[i] = Ops[i];
1049       Ops[i].Val->Uses.push_back(this);
1050     }
1051     
1052     ValueList = VTs.VTs;
1053     NumValues = VTs.NumVTs;
1054     Prev = 0; Next = 0;
1055   }
1056   SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
1057     OperandsNeedDelete = false;  // Operands set with InitOperands.
1058     NumOperands = 0;
1059     OperandList = 0;
1060     
1061     ValueList = VTs.VTs;
1062     NumValues = VTs.NumVTs;
1063     Prev = 0; Next = 0;
1064   }
1065   
1066   /// InitOperands - Initialize the operands list of this node with the
1067   /// specified values, which are part of the node (thus they don't need to be
1068   /// copied in or allocated).
1069   void InitOperands(SDOperand *Ops, unsigned NumOps) {
1070     assert(OperandList == 0 && "Operands already set!");
1071     NumOperands = NumOps;
1072     OperandList = Ops;
1073     
1074     for (unsigned i = 0; i != NumOps; ++i)
1075       Ops[i].Val->Uses.push_back(this);
1076   }
1077   
1078   /// MorphNodeTo - This frees the operands of the current node, resets the
1079   /// opcode, types, and operands to the specified value.  This should only be
1080   /// used by the SelectionDAG class.
1081   void MorphNodeTo(unsigned Opc, SDVTList L,
1082                    const SDOperand *Ops, unsigned NumOps);
1083   
1084   void addUser(SDNode *User) {
1085     Uses.push_back(User);
1086   }
1087   void removeUser(SDNode *User) {
1088     // Remove this user from the operand's use list.
1089     for (unsigned i = Uses.size(); ; --i) {
1090       assert(i != 0 && "Didn't find user!");
1091       if (Uses[i-1] == User) {
1092         Uses[i-1] = Uses.back();
1093         Uses.pop_back();
1094         return;
1095       }
1096     }
1097   }
1098 };
1099
1100
1101 // Define inline functions from the SDOperand class.
1102
1103 inline unsigned SDOperand::getOpcode() const {
1104   return Val->getOpcode();
1105 }
1106 inline MVT::ValueType SDOperand::getValueType() const {
1107   return Val->getValueType(ResNo);
1108 }
1109 inline unsigned SDOperand::getNumOperands() const {
1110   return Val->getNumOperands();
1111 }
1112 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1113   return Val->getOperand(i);
1114 }
1115 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1116   return Val->getConstantOperandVal(i);
1117 }
1118 inline bool SDOperand::isTargetOpcode() const {
1119   return Val->isTargetOpcode();
1120 }
1121 inline unsigned SDOperand::getTargetOpcode() const {
1122   return Val->getTargetOpcode();
1123 }
1124 inline bool SDOperand::hasOneUse() const {
1125   return Val->hasNUsesOfValue(1, ResNo);
1126 }
1127 inline bool SDOperand::use_empty() const {
1128   return !Val->hasAnyUseOfValue(ResNo);
1129 }
1130
1131 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
1132 /// to allow co-allocation of node operands with the node itself.
1133 class UnarySDNode : public SDNode {
1134   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1135   SDOperand Op;
1136 public:
1137   UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1138     : SDNode(Opc, VTs), Op(X) {
1139     InitOperands(&Op, 1);
1140   }
1141 };
1142
1143 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
1144 /// to allow co-allocation of node operands with the node itself.
1145 class BinarySDNode : public SDNode {
1146   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1147   SDOperand Ops[2];
1148 public:
1149   BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1150     : SDNode(Opc, VTs) {
1151     Ops[0] = X;
1152     Ops[1] = Y;
1153     InitOperands(Ops, 2);
1154   }
1155 };
1156
1157 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1158 /// to allow co-allocation of node operands with the node itself.
1159 class TernarySDNode : public SDNode {
1160   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1161   SDOperand Ops[3];
1162 public:
1163   TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1164                 SDOperand Z)
1165     : SDNode(Opc, VTs) {
1166     Ops[0] = X;
1167     Ops[1] = Y;
1168     Ops[2] = Z;
1169     InitOperands(Ops, 3);
1170   }
1171 };
1172
1173
1174 /// HandleSDNode - This class is used to form a handle around another node that
1175 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1176 /// operand.  This node should be directly created by end-users and not added to
1177 /// the AllNodes list.
1178 class HandleSDNode : public SDNode {
1179   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1180   SDOperand Op;
1181 public:
1182   explicit HandleSDNode(SDOperand X)
1183     : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1184     InitOperands(&Op, 1);
1185   }
1186   ~HandleSDNode();  
1187   SDOperand getValue() const { return Op; }
1188 };
1189
1190 class AtomicSDNode : public SDNode {
1191   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1192   SDOperand Ops[4];
1193   MVT::ValueType OrigVT;
1194 public:
1195   AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, 
1196                SDOperand Cmp, SDOperand Swp, MVT::ValueType VT)
1197     : SDNode(Opc, VTL) {
1198     Ops[0] = Chain;
1199     Ops[1] = Ptr;
1200     Ops[2] = Swp;
1201     Ops[3] = Cmp;
1202     InitOperands(Ops, 4);
1203     OrigVT=VT;
1204   }
1205   AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, 
1206                SDOperand Val, MVT::ValueType VT)
1207     : SDNode(Opc, VTL) {
1208     Ops[0] = Chain;
1209     Ops[1] = Ptr;
1210     Ops[2] = Val;
1211     InitOperands(Ops, 3);
1212     OrigVT=VT;
1213   }
1214   MVT::ValueType getVT() const { return OrigVT; }
1215   bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_LCS; }
1216 };
1217
1218 class StringSDNode : public SDNode {
1219   std::string Value;
1220   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1221 protected:
1222   friend class SelectionDAG;
1223   explicit StringSDNode(const std::string &val)
1224     : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1225   }
1226 public:
1227   const std::string &getValue() const { return Value; }
1228   static bool classof(const StringSDNode *) { return true; }
1229   static bool classof(const SDNode *N) {
1230     return N->getOpcode() == ISD::STRING;
1231   }
1232 };  
1233
1234 class ConstantSDNode : public SDNode {
1235   APInt Value;
1236   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1237 protected:
1238   friend class SelectionDAG;
1239   ConstantSDNode(bool isTarget, const APInt &val, MVT::ValueType VT)
1240     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1241       Value(val) {
1242   }
1243 public:
1244
1245   const APInt &getAPIntValue() const { return Value; }
1246   uint64_t getValue() const { return Value.getZExtValue(); }
1247
1248   int64_t getSignExtended() const {
1249     unsigned Bits = MVT::getSizeInBits(getValueType(0));
1250     return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1251   }
1252
1253   bool isNullValue() const { return Value == 0; }
1254   bool isAllOnesValue() const {
1255     return Value == MVT::getIntVTBitMask(getValueType(0));
1256   }
1257
1258   static bool classof(const ConstantSDNode *) { return true; }
1259   static bool classof(const SDNode *N) {
1260     return N->getOpcode() == ISD::Constant ||
1261            N->getOpcode() == ISD::TargetConstant;
1262   }
1263 };
1264
1265 class ConstantFPSDNode : public SDNode {
1266   APFloat Value;
1267   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1268 protected:
1269   friend class SelectionDAG;
1270   ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT)
1271     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1272              getSDVTList(VT)), Value(val) {
1273   }
1274 public:
1275
1276   const APFloat& getValueAPF() const { return Value; }
1277
1278   /// isExactlyValue - We don't rely on operator== working on double values, as
1279   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1280   /// As such, this method can be used to do an exact bit-for-bit comparison of
1281   /// two floating point values.
1282
1283   /// We leave the version with the double argument here because it's just so
1284   /// convenient to write "2.0" and the like.  Without this function we'd 
1285   /// have to duplicate its logic everywhere it's called.
1286   bool isExactlyValue(double V) const { 
1287     APFloat Tmp(V);
1288     Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1289     return isExactlyValue(Tmp);
1290   }
1291   bool isExactlyValue(const APFloat& V) const;
1292
1293   bool isValueValidForType(MVT::ValueType VT, const APFloat& Val);
1294
1295   static bool classof(const ConstantFPSDNode *) { return true; }
1296   static bool classof(const SDNode *N) {
1297     return N->getOpcode() == ISD::ConstantFP || 
1298            N->getOpcode() == ISD::TargetConstantFP;
1299   }
1300 };
1301
1302 class GlobalAddressSDNode : public SDNode {
1303   GlobalValue *TheGlobal;
1304   int Offset;
1305   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1306 protected:
1307   friend class SelectionDAG;
1308   GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1309                       int o = 0);
1310 public:
1311
1312   GlobalValue *getGlobal() const { return TheGlobal; }
1313   int getOffset() const { return Offset; }
1314
1315   static bool classof(const GlobalAddressSDNode *) { return true; }
1316   static bool classof(const SDNode *N) {
1317     return N->getOpcode() == ISD::GlobalAddress ||
1318            N->getOpcode() == ISD::TargetGlobalAddress ||
1319            N->getOpcode() == ISD::GlobalTLSAddress ||
1320            N->getOpcode() == ISD::TargetGlobalTLSAddress;
1321   }
1322 };
1323
1324 class FrameIndexSDNode : public SDNode {
1325   int FI;
1326   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1327 protected:
1328   friend class SelectionDAG;
1329   FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1330     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1331       FI(fi) {
1332   }
1333 public:
1334
1335   int getIndex() const { return FI; }
1336
1337   static bool classof(const FrameIndexSDNode *) { return true; }
1338   static bool classof(const SDNode *N) {
1339     return N->getOpcode() == ISD::FrameIndex ||
1340            N->getOpcode() == ISD::TargetFrameIndex;
1341   }
1342 };
1343
1344 class JumpTableSDNode : public SDNode {
1345   int JTI;
1346   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1347 protected:
1348   friend class SelectionDAG;
1349   JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1350     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1351       JTI(jti) {
1352   }
1353 public:
1354     
1355   int getIndex() const { return JTI; }
1356   
1357   static bool classof(const JumpTableSDNode *) { return true; }
1358   static bool classof(const SDNode *N) {
1359     return N->getOpcode() == ISD::JumpTable ||
1360            N->getOpcode() == ISD::TargetJumpTable;
1361   }
1362 };
1363
1364 class ConstantPoolSDNode : public SDNode {
1365   union {
1366     Constant *ConstVal;
1367     MachineConstantPoolValue *MachineCPVal;
1368   } Val;
1369   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1370   unsigned Alignment;
1371   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1372 protected:
1373   friend class SelectionDAG;
1374   ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1375                      int o=0)
1376     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1377              getSDVTList(VT)), Offset(o), Alignment(0) {
1378     assert((int)Offset >= 0 && "Offset is too large");
1379     Val.ConstVal = c;
1380   }
1381   ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1382                      unsigned Align)
1383     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1384              getSDVTList(VT)), Offset(o), Alignment(Align) {
1385     assert((int)Offset >= 0 && "Offset is too large");
1386     Val.ConstVal = c;
1387   }
1388   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1389                      MVT::ValueType VT, int o=0)
1390     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1391              getSDVTList(VT)), Offset(o), Alignment(0) {
1392     assert((int)Offset >= 0 && "Offset is too large");
1393     Val.MachineCPVal = v;
1394     Offset |= 1 << (sizeof(unsigned)*8-1);
1395   }
1396   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1397                      MVT::ValueType VT, int o, unsigned Align)
1398     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1399              getSDVTList(VT)), Offset(o), Alignment(Align) {
1400     assert((int)Offset >= 0 && "Offset is too large");
1401     Val.MachineCPVal = v;
1402     Offset |= 1 << (sizeof(unsigned)*8-1);
1403   }
1404 public:
1405
1406   bool isMachineConstantPoolEntry() const {
1407     return (int)Offset < 0;
1408   }
1409
1410   Constant *getConstVal() const {
1411     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1412     return Val.ConstVal;
1413   }
1414
1415   MachineConstantPoolValue *getMachineCPVal() const {
1416     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1417     return Val.MachineCPVal;
1418   }
1419
1420   int getOffset() const {
1421     return Offset & ~(1 << (sizeof(unsigned)*8-1));
1422   }
1423   
1424   // Return the alignment of this constant pool object, which is either 0 (for
1425   // default alignment) or log2 of the desired value.
1426   unsigned getAlignment() const { return Alignment; }
1427
1428   const Type *getType() const;
1429
1430   static bool classof(const ConstantPoolSDNode *) { return true; }
1431   static bool classof(const SDNode *N) {
1432     return N->getOpcode() == ISD::ConstantPool ||
1433            N->getOpcode() == ISD::TargetConstantPool;
1434   }
1435 };
1436
1437 class BasicBlockSDNode : public SDNode {
1438   MachineBasicBlock *MBB;
1439   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1440 protected:
1441   friend class SelectionDAG;
1442   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1443     : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1444   }
1445 public:
1446
1447   MachineBasicBlock *getBasicBlock() const { return MBB; }
1448
1449   static bool classof(const BasicBlockSDNode *) { return true; }
1450   static bool classof(const SDNode *N) {
1451     return N->getOpcode() == ISD::BasicBlock;
1452   }
1453 };
1454
1455 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1456 /// used when the SelectionDAG needs to make a simple reference to something
1457 /// in the LLVM IR representation.
1458 ///
1459 /// Note that this is not used for carrying alias information; that is done
1460 /// with MemOperandSDNode, which includes a Value which is required to be a
1461 /// pointer, and several other fields specific to memory references.
1462 ///
1463 class SrcValueSDNode : public SDNode {
1464   const Value *V;
1465   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1466 protected:
1467   friend class SelectionDAG;
1468   /// Create a SrcValue for a general value.
1469   explicit SrcValueSDNode(const Value *v)
1470     : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1471
1472 public:
1473   /// getValue - return the contained Value.
1474   const Value *getValue() const { return V; }
1475
1476   static bool classof(const SrcValueSDNode *) { return true; }
1477   static bool classof(const SDNode *N) {
1478     return N->getOpcode() == ISD::SRCVALUE;
1479   }
1480 };
1481
1482
1483 /// MemOperandSDNode - An SDNode that holds a MemOperand. This is
1484 /// used to represent a reference to memory after ISD::LOAD
1485 /// and ISD::STORE have been lowered.
1486 ///
1487 class MemOperandSDNode : public SDNode {
1488   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1489 protected:
1490   friend class SelectionDAG;
1491   /// Create a MemOperand node
1492   explicit MemOperandSDNode(const MemOperand &mo)
1493     : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1494
1495 public:
1496   /// MO - The contained MemOperand.
1497   const MemOperand MO;
1498
1499   static bool classof(const MemOperandSDNode *) { return true; }
1500   static bool classof(const SDNode *N) {
1501     return N->getOpcode() == ISD::MEMOPERAND;
1502   }
1503 };
1504
1505
1506 class RegisterSDNode : public SDNode {
1507   unsigned Reg;
1508   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1509 protected:
1510   friend class SelectionDAG;
1511   RegisterSDNode(unsigned reg, MVT::ValueType VT)
1512     : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1513   }
1514 public:
1515
1516   unsigned getReg() const { return Reg; }
1517
1518   static bool classof(const RegisterSDNode *) { return true; }
1519   static bool classof(const SDNode *N) {
1520     return N->getOpcode() == ISD::Register;
1521   }
1522 };
1523
1524 class ExternalSymbolSDNode : public SDNode {
1525   const char *Symbol;
1526   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1527 protected:
1528   friend class SelectionDAG;
1529   ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1530     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1531              getSDVTList(VT)), Symbol(Sym) {
1532   }
1533 public:
1534
1535   const char *getSymbol() const { return Symbol; }
1536
1537   static bool classof(const ExternalSymbolSDNode *) { return true; }
1538   static bool classof(const SDNode *N) {
1539     return N->getOpcode() == ISD::ExternalSymbol ||
1540            N->getOpcode() == ISD::TargetExternalSymbol;
1541   }
1542 };
1543
1544 class CondCodeSDNode : public SDNode {
1545   ISD::CondCode Condition;
1546   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1547 protected:
1548   friend class SelectionDAG;
1549   explicit CondCodeSDNode(ISD::CondCode Cond)
1550     : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1551   }
1552 public:
1553
1554   ISD::CondCode get() const { return Condition; }
1555
1556   static bool classof(const CondCodeSDNode *) { return true; }
1557   static bool classof(const SDNode *N) {
1558     return N->getOpcode() == ISD::CONDCODE;
1559   }
1560 };
1561
1562 namespace ISD {
1563   struct ArgFlagsTy {
1564   private:
1565     static const uint64_t NoFlagSet      = 0ULL;
1566     static const uint64_t ZExt           = 1ULL<<0;  ///< Zero extended
1567     static const uint64_t ZExtOffs       = 0;
1568     static const uint64_t SExt           = 1ULL<<1;  ///< Sign extended
1569     static const uint64_t SExtOffs       = 1;
1570     static const uint64_t InReg          = 1ULL<<2;  ///< Passed in register
1571     static const uint64_t InRegOffs      = 2;
1572     static const uint64_t SRet           = 1ULL<<3;  ///< Hidden struct-ret ptr
1573     static const uint64_t SRetOffs       = 3;
1574     static const uint64_t ByVal          = 1ULL<<4;  ///< Struct passed by value
1575     static const uint64_t ByValOffs      = 4;
1576     static const uint64_t Nest           = 1ULL<<5;  ///< Nested fn static chain
1577     static const uint64_t NestOffs       = 5;
1578     static const uint64_t ByValAlign     = 0xFULL << 6; //< Struct alignment
1579     static const uint64_t ByValAlignOffs = 6;
1580     static const uint64_t OrigAlign      = 0x1FULL<<27;
1581     static const uint64_t OrigAlignOffs  = 27;
1582     static const uint64_t ByValSize      = 0xffffffffULL << 32; //< Struct size
1583     static const uint64_t ByValSizeOffs  = 32;
1584
1585     static const uint64_t One            = 1ULL; //< 1 of this type, for shifts
1586
1587     uint64_t Flags;
1588   public:
1589     ArgFlagsTy() : Flags(0) { }
1590
1591     bool isZExt()   const { return Flags & ZExt; }
1592     void setZExt()  { Flags |= One << ZExtOffs; }
1593
1594     bool isSExt()   const { return Flags & SExt; }
1595     void setSExt()  { Flags |= One << SExtOffs; }
1596
1597     bool isInReg()  const { return Flags & InReg; }
1598     void setInReg() { Flags |= One << InRegOffs; }
1599
1600     bool isSRet()   const { return Flags & SRet; }
1601     void setSRet()  { Flags |= One << SRetOffs; }
1602
1603     bool isByVal()  const { return Flags & ByVal; }
1604     void setByVal() { Flags |= One << ByValOffs; }
1605
1606     bool isNest()   const { return Flags & Nest; }
1607     void setNest()  { Flags |= One << NestOffs; }
1608
1609     unsigned getByValAlign() const {
1610       return (One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2;
1611     }
1612     void setByValAlign(unsigned A) {
1613       Flags = (Flags & ~ByValAlign) |
1614         (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
1615     }
1616
1617     unsigned getOrigAlign() const {
1618       return (One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2;
1619     }
1620     void setOrigAlign(unsigned A) {
1621       Flags = (Flags & ~OrigAlign) |
1622         (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
1623     }
1624
1625     unsigned getByValSize() const {
1626       return (Flags & ByValSize) >> ByValSizeOffs;
1627     }
1628     void setByValSize(unsigned S) {
1629       Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
1630     }
1631
1632     /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
1633     std::string getArgFlagsString();
1634
1635     /// getRawBits - Represent the flags as a bunch of bits.
1636     uint64_t getRawBits() const { return Flags; }
1637   };
1638 }
1639
1640 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
1641 class ARG_FLAGSSDNode : public SDNode {
1642   ISD::ArgFlagsTy TheFlags;
1643   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1644 protected:
1645   friend class SelectionDAG;
1646   explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
1647     : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
1648   }
1649 public:
1650   ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
1651
1652   static bool classof(const ARG_FLAGSSDNode *) { return true; }
1653   static bool classof(const SDNode *N) {
1654     return N->getOpcode() == ISD::ARG_FLAGS;
1655   }
1656 };
1657
1658 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1659 /// to parameterize some operations.
1660 class VTSDNode : public SDNode {
1661   MVT::ValueType ValueType;
1662   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1663 protected:
1664   friend class SelectionDAG;
1665   explicit VTSDNode(MVT::ValueType VT)
1666     : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1667   }
1668 public:
1669
1670   MVT::ValueType getVT() const { return ValueType; }
1671
1672   static bool classof(const VTSDNode *) { return true; }
1673   static bool classof(const SDNode *N) {
1674     return N->getOpcode() == ISD::VALUETYPE;
1675   }
1676 };
1677
1678 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1679 ///
1680 class LSBaseSDNode : public SDNode {
1681 private:
1682   // AddrMode - unindexed, pre-indexed, post-indexed.
1683   ISD::MemIndexedMode AddrMode;
1684
1685   // MemoryVT - VT of in-memory value.
1686   MVT::ValueType MemoryVT;
1687
1688   //! SrcValue - Memory location for alias analysis.
1689   const Value *SrcValue;
1690
1691   //! SVOffset - Memory location offset.
1692   int SVOffset;
1693
1694   //! Alignment - Alignment of memory location in bytes.
1695   unsigned Alignment;
1696
1697   //! IsVolatile - True if the store is volatile.
1698   bool IsVolatile;
1699 protected:
1700   //! Operand array for load and store
1701   /*!
1702     \note Moving this array to the base class captures more
1703     common functionality shared between LoadSDNode and
1704     StoreSDNode
1705    */
1706   SDOperand Ops[4];
1707 public:
1708   LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned NumOperands,
1709                SDVTList VTs, ISD::MemIndexedMode AM, MVT::ValueType VT, 
1710                const Value *SV, int SVO, unsigned Align, bool Vol)
1711     : SDNode(NodeTy, VTs),
1712       AddrMode(AM), MemoryVT(VT),
1713       SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol) {
1714     for (unsigned i = 0; i != NumOperands; ++i)
1715       Ops[i] = Operands[i];
1716     InitOperands(Ops, NumOperands);
1717     assert(Align != 0 && "Loads and stores should have non-zero aligment");
1718     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1719            "Only indexed loads and stores have a non-undef offset operand");
1720   }
1721
1722   const SDOperand &getChain() const { return getOperand(0); }
1723   const SDOperand &getBasePtr() const {
1724     return getOperand(getOpcode() == ISD::LOAD ? 1 : 2);
1725   }
1726   const SDOperand &getOffset() const {
1727     return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1728   }
1729
1730   const Value *getSrcValue() const { return SrcValue; }
1731   int getSrcValueOffset() const { return SVOffset; }
1732   unsigned getAlignment() const { return Alignment; }
1733   MVT::ValueType getMemoryVT() const { return MemoryVT; }
1734   bool isVolatile() const { return IsVolatile; }
1735
1736   ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1737
1738   /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1739   bool isIndexed() const { return AddrMode != ISD::UNINDEXED; }
1740
1741   /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1742   bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; }
1743
1744   /// getMemOperand - Return a MemOperand object describing the memory
1745   /// reference performed by this load or store.
1746   MemOperand getMemOperand() const;
1747
1748   static bool classof(const LSBaseSDNode *N) { return true; }
1749   static bool classof(const SDNode *N) {
1750     return N->getOpcode() == ISD::LOAD ||
1751            N->getOpcode() == ISD::STORE;
1752   }
1753 };
1754
1755 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1756 ///
1757 class LoadSDNode : public LSBaseSDNode {
1758   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1759   
1760   // ExtType - non-ext, anyext, sext, zext.
1761   ISD::LoadExtType ExtType;
1762
1763 protected:
1764   friend class SelectionDAG;
1765   LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1766              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1767              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1768     : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
1769                    VTs, AM, LVT, SV, O, Align, Vol),
1770       ExtType(ETy) {}
1771 public:
1772
1773   ISD::LoadExtType getExtensionType() const { return ExtType; }
1774   const SDOperand &getBasePtr() const { return getOperand(1); }
1775   const SDOperand &getOffset() const { return getOperand(2); }
1776   
1777   static bool classof(const LoadSDNode *) { return true; }
1778   static bool classof(const SDNode *N) {
1779     return N->getOpcode() == ISD::LOAD;
1780   }
1781 };
1782
1783 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1784 ///
1785 class StoreSDNode : public LSBaseSDNode {
1786   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1787     
1788   // IsTruncStore - True if the op does a truncation before store.
1789   bool IsTruncStore;
1790 protected:
1791   friend class SelectionDAG;
1792   StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1793               ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1794               const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1795     : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
1796                    VTs, AM, SVT, SV, O, Align, Vol),
1797       IsTruncStore(isTrunc) {}
1798 public:
1799
1800   bool isTruncatingStore() const { return IsTruncStore; }
1801   const SDOperand &getValue() const { return getOperand(1); }
1802   const SDOperand &getBasePtr() const { return getOperand(2); }
1803   const SDOperand &getOffset() const { return getOperand(3); }
1804   
1805   static bool classof(const StoreSDNode *) { return true; }
1806   static bool classof(const SDNode *N) {
1807     return N->getOpcode() == ISD::STORE;
1808   }
1809 };
1810
1811
1812 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1813   SDNode *Node;
1814   unsigned Operand;
1815
1816   SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1817 public:
1818   bool operator==(const SDNodeIterator& x) const {
1819     return Operand == x.Operand;
1820   }
1821   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1822
1823   const SDNodeIterator &operator=(const SDNodeIterator &I) {
1824     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1825     Operand = I.Operand;
1826     return *this;
1827   }
1828
1829   pointer operator*() const {
1830     return Node->getOperand(Operand).Val;
1831   }
1832   pointer operator->() const { return operator*(); }
1833
1834   SDNodeIterator& operator++() {                // Preincrement
1835     ++Operand;
1836     return *this;
1837   }
1838   SDNodeIterator operator++(int) { // Postincrement
1839     SDNodeIterator tmp = *this; ++*this; return tmp;
1840   }
1841
1842   static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1843   static SDNodeIterator end  (SDNode *N) {
1844     return SDNodeIterator(N, N->getNumOperands());
1845   }
1846
1847   unsigned getOperand() const { return Operand; }
1848   const SDNode *getNode() const { return Node; }
1849 };
1850
1851 template <> struct GraphTraits<SDNode*> {
1852   typedef SDNode NodeType;
1853   typedef SDNodeIterator ChildIteratorType;
1854   static inline NodeType *getEntryNode(SDNode *N) { return N; }
1855   static inline ChildIteratorType child_begin(NodeType *N) {
1856     return SDNodeIterator::begin(N);
1857   }
1858   static inline ChildIteratorType child_end(NodeType *N) {
1859     return SDNodeIterator::end(N);
1860   }
1861 };
1862
1863 template<>
1864 struct ilist_traits<SDNode> {
1865   static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1866   static SDNode *getNext(const SDNode *N) { return N->Next; }
1867   
1868   static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1869   static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1870   
1871   static SDNode *createSentinel() {
1872     return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1873   }
1874   static void destroySentinel(SDNode *N) { delete N; }
1875   //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1876   
1877   
1878   void addNodeToList(SDNode *NTy) {}
1879   void removeNodeFromList(SDNode *NTy) {}
1880   void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1881                              const ilist_iterator<SDNode> &X,
1882                              const ilist_iterator<SDNode> &Y) {}
1883 };
1884
1885 namespace ISD {
1886   /// isNormalLoad - Returns true if the specified node is a non-extending
1887   /// and unindexed load.
1888   inline bool isNormalLoad(const SDNode *N) {
1889     if (N->getOpcode() != ISD::LOAD)
1890       return false;
1891     const LoadSDNode *Ld = cast<LoadSDNode>(N);
1892     return Ld->getExtensionType() == ISD::NON_EXTLOAD &&
1893       Ld->getAddressingMode() == ISD::UNINDEXED;
1894   }
1895
1896   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1897   /// load.
1898   inline bool isNON_EXTLoad(const SDNode *N) {
1899     return N->getOpcode() == ISD::LOAD &&
1900       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1901   }
1902
1903   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1904   ///
1905   inline bool isEXTLoad(const SDNode *N) {
1906     return N->getOpcode() == ISD::LOAD &&
1907       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1908   }
1909
1910   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1911   ///
1912   inline bool isSEXTLoad(const SDNode *N) {
1913     return N->getOpcode() == ISD::LOAD &&
1914       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1915   }
1916
1917   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1918   ///
1919   inline bool isZEXTLoad(const SDNode *N) {
1920     return N->getOpcode() == ISD::LOAD &&
1921       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1922   }
1923
1924   /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1925   ///
1926   inline bool isUNINDEXEDLoad(const SDNode *N) {
1927     return N->getOpcode() == ISD::LOAD &&
1928       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1929   }
1930
1931   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1932   /// store.
1933   inline bool isNON_TRUNCStore(const SDNode *N) {
1934     return N->getOpcode() == ISD::STORE &&
1935       !cast<StoreSDNode>(N)->isTruncatingStore();
1936   }
1937
1938   /// isTRUNCStore - Returns true if the specified node is a truncating
1939   /// store.
1940   inline bool isTRUNCStore(const SDNode *N) {
1941     return N->getOpcode() == ISD::STORE &&
1942       cast<StoreSDNode>(N)->isTruncatingStore();
1943   }
1944 }
1945
1946
1947 } // end llvm namespace
1948
1949 #endif