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