Add an out-of-line virtual method for the sdnode class to give it a home.
[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 was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source 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/CodeGen/ValueTypes.h"
23 #include "llvm/Value.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator"
26 #include "llvm/Support/DataTypes.h"
27 #include <cassert>
28 #include <vector>
29
30 namespace llvm {
31
32 class SelectionDAG;
33 class GlobalValue;
34 class MachineBasicBlock;
35 class SDNode;
36 template <typename T> struct simplify_type;
37 template <typename T> struct ilist_traits;
38 template<typename NodeTy, typename Traits> class iplist;
39 template<typename NodeTy> class ilist_iterator;
40
41 /// ISD namespace - This namespace contains an enum which represents all of the
42 /// SelectionDAG node types and value types.
43 ///
44 namespace ISD {
45   //===--------------------------------------------------------------------===//
46   /// ISD::NodeType enum - This enum defines all of the operators valid in a
47   /// SelectionDAG.
48   ///
49   enum NodeType {
50     // DELETED_NODE - This is an illegal flag value that is used to catch
51     // errors.  This opcode is not a legal opcode for any node.
52     DELETED_NODE,
53     
54     // EntryToken - This is the marker used to indicate the start of the region.
55     EntryToken,
56
57     // Token factor - This node takes multiple tokens as input and produces a
58     // single token result.  This is used to represent the fact that the operand
59     // operators are independent of each other.
60     TokenFactor,
61     
62     // AssertSext, AssertZext - These nodes record if a register contains a 
63     // value that has already been zero or sign extended from a narrower type.  
64     // These nodes take two operands.  The first is the node that has already 
65     // been extended, and the second is a value type node indicating the width
66     // of the extension
67     AssertSext, AssertZext,
68
69     // Various leaf nodes.
70     STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
71     Constant, ConstantFP,
72     GlobalAddress, FrameIndex, JumpTable, ConstantPool, ExternalSymbol,
73
74     // TargetConstant* - Like Constant*, but the DAG does not do any folding or
75     // simplification of the constant.
76     TargetConstant,
77     TargetConstantFP,
78     
79     // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
80     // anything else with this node, and this is valid in the target-specific
81     // dag, turning into a GlobalAddress operand.
82     TargetGlobalAddress,
83     TargetFrameIndex,
84     TargetJumpTable,
85     TargetConstantPool,
86     TargetExternalSymbol,
87     
88     /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
89     /// This node represents a target intrinsic function with no side effects.
90     /// The first operand is the ID number of the intrinsic from the
91     /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
92     /// node has returns the result of the intrinsic.
93     INTRINSIC_WO_CHAIN,
94     
95     /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
96     /// This node represents a target intrinsic function with side effects that
97     /// returns a result.  The first operand is a chain pointer.  The second is
98     /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
99     /// operands to the intrinsic follow.  The node has two results, the result
100     /// of the intrinsic and an output chain.
101     INTRINSIC_W_CHAIN,
102
103     /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
104     /// This node represents a target intrinsic function with side effects that
105     /// does not return a result.  The first operand is a chain pointer.  The
106     /// second is the ID number of the intrinsic from the llvm::Intrinsic
107     /// namespace.  The operands to the intrinsic follow.
108     INTRINSIC_VOID,
109     
110     // CopyToReg - This node has three operands: a chain, a register number to
111     // set to this value, and a value.  
112     CopyToReg,
113
114     // CopyFromReg - This node indicates that the input value is a virtual or
115     // physical register that is defined outside of the scope of this
116     // SelectionDAG.  The register is available from the RegSDNode object.
117     CopyFromReg,
118
119     // UNDEF - An undefined node
120     UNDEF,
121     
122     /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG) - This node represents the formal
123     /// arguments for a function.  CC# is a Constant value indicating the
124     /// calling convention of the function, and ISVARARG is a flag that
125     /// indicates whether the function is varargs or not.  This node has one
126     /// result value for each incoming argument, plus one for the output chain.
127     /// It must be custom legalized.
128     /// 
129     FORMAL_ARGUMENTS,
130     
131     /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
132     ///                              ARG0, SIGN0, ARG1, SIGN1, ... ARGn, SIGNn)
133     /// This node represents a fully general function call, before the legalizer
134     /// runs.  This has one result value for each argument / signness pair, plus
135     /// a chain result. It must be custom legalized.
136     CALL,
137
138     // EXTRACT_ELEMENT - This is used to get the first or second (determined by
139     // a Constant, which is required to be operand #1), element of the aggregate
140     // value specified as operand #0.  This is only for use before legalization,
141     // for values that will be broken into multiple registers.
142     EXTRACT_ELEMENT,
143
144     // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
145     // two values of the same integer value type, this produces a value twice as
146     // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
147     BUILD_PAIR,
148     
149     // MERGE_VALUES - This node takes multiple discrete operands and returns
150     // them all as its individual results.  This nodes has exactly the same
151     // number of inputs and outputs, and is only valid before legalization.
152     // This node is useful for some pieces of the code generator that want to
153     // think about a single node with multiple results, not multiple nodes.
154     MERGE_VALUES,
155
156     // Simple integer binary arithmetic operators.
157     ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
158     
159     // Carry-setting nodes for multiple precision addition and subtraction.
160     // These nodes take two operands of the same value type, and produce two
161     // results.  The first result is the normal add or sub result, the second
162     // result is the carry flag result.
163     ADDC, SUBC,
164     
165     // Carry-using nodes for multiple precision addition and subtraction.  These
166     // nodes take three operands: The first two are the normal lhs and rhs to
167     // the add or sub, and the third is the input carry flag.  These nodes
168     // produce two results; the normal result of the add or sub, and the output
169     // carry flag.  These nodes both read and write a carry flag to allow them
170     // to them to be chained together for add and sub of arbitrarily large
171     // values.
172     ADDE, SUBE,
173     
174     // Simple binary floating point operators.
175     FADD, FSUB, FMUL, FDIV, FREM,
176
177     // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
178     // DAG node does not require that X and Y have the same type, just that they
179     // are both floating point.  X and the result must have the same type.
180     // FCOPYSIGN(f32, f64) is allowed.
181     FCOPYSIGN,
182
183     /// VBUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,...,  COUNT,TYPE) - Return a vector
184     /// with the specified, possibly variable, elements.  The number of elements
185     /// is required to be a power of two.
186     VBUILD_VECTOR,
187
188     /// BUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,...) - Return a vector
189     /// with the specified, possibly variable, elements.  The number of elements
190     /// is required to be a power of two.
191     BUILD_VECTOR,
192     
193     /// VINSERT_VECTOR_ELT(VECTOR, VAL, IDX,  COUNT,TYPE) - Given a vector
194     /// VECTOR, an element ELEMENT, and a (potentially variable) index IDX,
195     /// return an vector with the specified element of VECTOR replaced with VAL.
196     /// COUNT and TYPE specify the type of vector, as is standard for V* nodes.
197     VINSERT_VECTOR_ELT,
198     
199     /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR (a legal packed
200     /// type) with the element at IDX replaced with VAL.
201     INSERT_VECTOR_ELT,
202
203     /// VEXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
204     /// (an MVT::Vector value) identified by the (potentially variable) element
205     /// number IDX.
206     VEXTRACT_VECTOR_ELT,
207     
208     /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
209     /// (a legal packed type vector) identified by the (potentially variable)
210     /// element number IDX.
211     EXTRACT_VECTOR_ELT,
212     
213     /// VVECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC, COUNT,TYPE) - Returns a vector,
214     /// of the same type as VEC1/VEC2.  SHUFFLEVEC is a VBUILD_VECTOR of
215     /// constant int values that indicate which value each result element will
216     /// get.  The elements of VEC1/VEC2 are enumerated in order.  This is quite
217     /// similar to the Altivec 'vperm' instruction, except that the indices must
218     /// be constants and are in terms of the element size of VEC1/VEC2, not in
219     /// terms of bytes.
220     VVECTOR_SHUFFLE,
221
222     /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
223     /// type as VEC1/VEC2.  SHUFFLEVEC is a BUILD_VECTOR of constant int values
224     /// (regardless of whether its datatype is legal or not) that indicate
225     /// which value each result element will get.  The elements of VEC1/VEC2 are
226     /// enumerated in order.  This is quite similar to the Altivec 'vperm'
227     /// instruction, except that the indices must be constants and are in terms
228     /// of the element size of VEC1/VEC2, not in terms of bytes.
229     VECTOR_SHUFFLE,
230     
231     /// X = VBIT_CONVERT(Y)  and X = VBIT_CONVERT(Y, COUNT,TYPE) - This node
232     /// represents a conversion from or to an ISD::Vector type.
233     ///
234     /// This is lowered to a BIT_CONVERT of the appropriate input/output types.
235     /// The input and output are required to have the same size and at least one
236     /// is required to be a vector (if neither is a vector, just use
237     /// BIT_CONVERT).
238     ///
239     /// If the result is a vector, this takes three operands (like any other
240     /// vector producer) which indicate the size and type of the vector result.
241     /// Otherwise it takes one input.
242     VBIT_CONVERT,
243     
244     /// BINOP(LHS, RHS,  COUNT,TYPE)
245     /// Simple abstract vector operators.  Unlike the integer and floating point
246     /// binary operators, these nodes also take two additional operands:
247     /// a constant element count, and a value type node indicating the type of
248     /// the elements.  The order is count, type, op0, op1.  All vector opcodes,
249     /// including VLOAD and VConstant must currently have count and type as
250     /// their last two operands.
251     VADD, VSUB, VMUL, VSDIV, VUDIV,
252     VAND, VOR, VXOR,
253     
254     /// VSELECT(COND,LHS,RHS,  COUNT,TYPE) - Select for MVT::Vector values.
255     /// COND is a boolean value.  This node return LHS if COND is true, RHS if
256     /// COND is false.
257     VSELECT,
258     
259     /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
260     /// scalar value into the low element of the resultant vector type.  The top
261     /// elements of the vector are undefined.
262     SCALAR_TO_VECTOR,
263     
264     // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
265     // an unsigned/signed value of type i[2*n], then return the top part.
266     MULHU, MULHS,
267
268     // Bitwise operators - logical and, logical or, logical xor, shift left,
269     // shift right algebraic (shift in sign bits), shift right logical (shift in
270     // zeroes), rotate left, rotate right, and byteswap.
271     AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
272
273     // Counting operators
274     CTTZ, CTLZ, CTPOP,
275
276     // Select(COND, TRUEVAL, FALSEVAL)
277     SELECT, 
278     
279     // Select with condition operator - This selects between a true value and 
280     // a false value (ops #2 and #3) based on the boolean result of comparing
281     // the lhs and rhs (ops #0 and #1) of a conditional expression with the 
282     // condition code in op #4, a CondCodeSDNode.
283     SELECT_CC,
284
285     // SetCC operator - This evaluates to a boolean (i1) true value if the
286     // condition is true.  The operands to this are the left and right operands
287     // to compare (ops #0, and #1) and the condition code to compare them with
288     // (op #2) as a CondCodeSDNode.
289     SETCC,
290
291     // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
292     // integer shift operations, just like ADD/SUB_PARTS.  The operation
293     // ordering is:
294     //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
295     SHL_PARTS, SRA_PARTS, SRL_PARTS,
296
297     // Conversion operators.  These are all single input single output
298     // operations.  For all of these, the result type must be strictly
299     // wider or narrower (depending on the operation) than the source
300     // type.
301
302     // SIGN_EXTEND - Used for integer types, replicating the sign bit
303     // into new bits.
304     SIGN_EXTEND,
305
306     // ZERO_EXTEND - Used for integer types, zeroing the new bits.
307     ZERO_EXTEND,
308
309     // ANY_EXTEND - Used for integer types.  The high bits are undefined.
310     ANY_EXTEND,
311     
312     // TRUNCATE - Completely drop the high bits.
313     TRUNCATE,
314
315     // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
316     // depends on the first letter) to floating point.
317     SINT_TO_FP,
318     UINT_TO_FP,
319
320     // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
321     // sign extend a small value in a large integer register (e.g. sign
322     // extending the low 8 bits of a 32-bit register to fill the top 24 bits
323     // with the 7th bit).  The size of the smaller type is indicated by the 1th
324     // operand, a ValueType node.
325     SIGN_EXTEND_INREG,
326
327     // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
328     // integer.
329     FP_TO_SINT,
330     FP_TO_UINT,
331
332     // FP_ROUND - Perform a rounding operation from the current
333     // precision down to the specified precision (currently always 64->32).
334     FP_ROUND,
335
336     // FP_ROUND_INREG - This operator takes a floating point register, and
337     // rounds it to a floating point value.  It then promotes it and returns it
338     // in a register of the same size.  This operation effectively just discards
339     // excess precision.  The type to round down to is specified by the 1th
340     // operation, a VTSDNode (currently always 64->32->64).
341     FP_ROUND_INREG,
342
343     // FP_EXTEND - Extend a smaller FP type into a larger FP type.
344     FP_EXTEND,
345
346     // BIT_CONVERT - Theis operator converts between integer and FP values, as
347     // if one was stored to memory as integer and the other was loaded from the
348     // same address (or equivalently for vector format conversions, etc).  The 
349     // source and result are required to have the same bit size (e.g. 
350     // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp 
351     // conversions, but that is a noop, deleted by getNode().
352     BIT_CONVERT,
353     
354     // FNEG, FABS, FSQRT, FSIN, FCOS - Perform unary floating point negation,
355     // absolute value, square root, sine and cosine operations.
356     FNEG, FABS, FSQRT, FSIN, FCOS,
357     
358     // Other operators.  LOAD and STORE have token chains as their first
359     // operand, then the same operands as an LLVM load/store instruction, then a
360     // SRCVALUE node that provides alias analysis information.
361     LOAD, STORE,
362     
363     // Abstract vector version of LOAD.  VLOAD has a constant element count as
364     // the first operand, followed by a value type node indicating the type of
365     // the elements, a token chain, a pointer operand, and a SRCVALUE node.
366     VLOAD,
367
368     // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators all load a value from
369     // memory and extend them to a larger value (e.g. load a byte into a word
370     // register).  All three of these have four operands, a token chain, a
371     // pointer to load from, a SRCVALUE for alias analysis, and a VALUETYPE node
372     // indicating the type to load.
373     //
374     // SEXTLOAD loads the integer operand and sign extends it to a larger
375     //          integer result type.
376     // ZEXTLOAD loads the integer operand and zero extends it to a larger
377     //          integer result type.
378     // EXTLOAD  is used for three things: floating point extending loads, 
379     //          integer extending loads [the top bits are undefined], and vector
380     //          extending loads [load into low elt].
381     EXTLOAD, SEXTLOAD, ZEXTLOAD,
382
383     // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
384     // value and stores it to memory in one operation.  This can be used for
385     // either integer or floating point operands.  The first four operands of
386     // this are the same as a standard store.  The fifth is the ValueType to
387     // store it as (which will be smaller than the source value).
388     TRUNCSTORE,
389
390     // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
391     // to a specified boundary.  The first operand is the token chain, the
392     // second is the number of bytes to allocate, and the third is the alignment
393     // boundary.  The size is guaranteed to be a multiple of the stack 
394     // alignment, and the alignment is guaranteed to be bigger than the stack 
395     // alignment (if required) or 0 to get standard stack alignment.
396     DYNAMIC_STACKALLOC,
397
398     // Control flow instructions.  These all have token chains.
399
400     // BR - Unconditional branch.  The first operand is the chain
401     // operand, the second is the MBB to branch to.
402     BR,
403
404     // BRIND - Indirect branch.  The first operand is the chain, the second
405     // is the value to branch to, which must be of the same type as the target's
406     // pointer type.
407     BRIND,
408     
409     // BRCOND - Conditional branch.  The first operand is the chain,
410     // the second is the condition, the third is the block to branch
411     // to if the condition is true.
412     BRCOND,
413
414     // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
415     // that the condition is represented as condition code, and two nodes to
416     // compare, rather than as a combined SetCC node.  The operands in order are
417     // chain, cc, lhs, rhs, block to branch to if condition is true.
418     BR_CC,
419     
420     // RET - Return from function.  The first operand is the chain,
421     // and any subsequent operands are pairs of return value and return value
422     // signness for the function.  This operation can have variable number of
423     // operands.
424     RET,
425
426     // INLINEASM - Represents an inline asm block.  This node always has two
427     // return values: a chain and a flag result.  The inputs are as follows:
428     //   Operand #0   : Input chain.
429     //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
430     //   Operand #2n+2: A RegisterNode.
431     //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
432     //   Operand #last: Optional, an incoming flag.
433     INLINEASM,
434
435     // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
436     // value, the same type as the pointer type for the system, and an output
437     // chain.
438     STACKSAVE,
439     
440     // STACKRESTORE has two operands, an input chain and a pointer to restore to
441     // it returns an output chain.
442     STACKRESTORE,
443     
444     // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
445     // correspond to the operands of the LLVM intrinsic functions.  The only
446     // result is a token chain.  The alignment argument is guaranteed to be a
447     // Constant node.
448     MEMSET,
449     MEMMOVE,
450     MEMCPY,
451
452     // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
453     // a call sequence, and carry arbitrary information that target might want
454     // to know.  The first operand is a chain, the rest are specified by the
455     // target and not touched by the DAG optimizers.
456     CALLSEQ_START,  // Beginning of a call sequence
457     CALLSEQ_END,    // End of a call sequence
458     
459     // VAARG - VAARG has three operands: an input chain, a pointer, and a 
460     // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
461     VAARG,
462     
463     // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
464     // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
465     // source.
466     VACOPY,
467     
468     // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
469     // pointer, and a SRCVALUE.
470     VAEND, VASTART,
471
472     // SRCVALUE - This corresponds to a Value*, and is used to associate memory
473     // locations with their value.  This allows one use alias analysis
474     // information in the backend.
475     SRCVALUE,
476
477     // PCMARKER - This corresponds to the pcmarker intrinsic.
478     PCMARKER,
479
480     // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
481     // The only operand is a chain and a value and a chain are produced.  The
482     // value is the contents of the architecture specific cycle counter like 
483     // register (or other high accuracy low latency clock source)
484     READCYCLECOUNTER,
485
486     // HANDLENODE node - Used as a handle for various purposes.
487     HANDLENODE,
488
489     // LOCATION - This node is used to represent a source location for debug
490     // info.  It takes token chain as input, then a line number, then a column
491     // number, then a filename, then a working dir.  It produces a token chain
492     // as output.
493     LOCATION,
494     
495     // DEBUG_LOC - This node is used to represent source line information
496     // embedded in the code.  It takes a token chain as input, then a line
497     // number, then a column then a file id (provided by MachineDebugInfo.) It
498     // produces a token chain as output.
499     DEBUG_LOC,
500     
501     // DEBUG_LABEL - This node is used to mark a location in the code where a
502     // label should be generated for use by the debug information.  It takes a
503     // token chain as input and then a unique id (provided by MachineDebugInfo.)
504     // It produces a token chain as output.
505     DEBUG_LABEL,
506     
507     // BUILTIN_OP_END - This must be the last enum value in this list.
508     BUILTIN_OP_END
509   };
510
511   /// Node predicates
512
513   /// isBuildVectorAllOnes - Return true if the specified node is a
514   /// BUILD_VECTOR where all of the elements are ~0 or undef.
515   bool isBuildVectorAllOnes(const SDNode *N);
516
517   /// isBuildVectorAllZeros - Return true if the specified node is a
518   /// BUILD_VECTOR where all of the elements are 0 or undef.
519   bool isBuildVectorAllZeros(const SDNode *N);
520   
521   //===--------------------------------------------------------------------===//
522   /// ISD::CondCode enum - These are ordered carefully to make the bitfields
523   /// below work out, when considering SETFALSE (something that never exists
524   /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
525   /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
526   /// to.  If the "N" column is 1, the result of the comparison is undefined if
527   /// the input is a NAN.
528   ///
529   /// All of these (except for the 'always folded ops') should be handled for
530   /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
531   /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
532   ///
533   /// Note that these are laid out in a specific order to allow bit-twiddling
534   /// to transform conditions.
535   enum CondCode {
536     // Opcode          N U L G E       Intuitive operation
537     SETFALSE,      //    0 0 0 0       Always false (always folded)
538     SETOEQ,        //    0 0 0 1       True if ordered and equal
539     SETOGT,        //    0 0 1 0       True if ordered and greater than
540     SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
541     SETOLT,        //    0 1 0 0       True if ordered and less than
542     SETOLE,        //    0 1 0 1       True if ordered and less than or equal
543     SETONE,        //    0 1 1 0       True if ordered and operands are unequal
544     SETO,          //    0 1 1 1       True if ordered (no nans)
545     SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
546     SETUEQ,        //    1 0 0 1       True if unordered or equal
547     SETUGT,        //    1 0 1 0       True if unordered or greater than
548     SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
549     SETULT,        //    1 1 0 0       True if unordered or less than
550     SETULE,        //    1 1 0 1       True if unordered, less than, or equal
551     SETUNE,        //    1 1 1 0       True if unordered or not equal
552     SETTRUE,       //    1 1 1 1       Always true (always folded)
553     // Don't care operations: undefined if the input is a nan.
554     SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
555     SETEQ,         //  1 X 0 0 1       True if equal
556     SETGT,         //  1 X 0 1 0       True if greater than
557     SETGE,         //  1 X 0 1 1       True if greater than or equal
558     SETLT,         //  1 X 1 0 0       True if less than
559     SETLE,         //  1 X 1 0 1       True if less than or equal
560     SETNE,         //  1 X 1 1 0       True if not equal
561     SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
562
563     SETCC_INVALID       // Marker value.
564   };
565
566   /// isSignedIntSetCC - Return true if this is a setcc instruction that
567   /// performs a signed comparison when used with integer operands.
568   inline bool isSignedIntSetCC(CondCode Code) {
569     return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
570   }
571
572   /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
573   /// performs an unsigned comparison when used with integer operands.
574   inline bool isUnsignedIntSetCC(CondCode Code) {
575     return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
576   }
577
578   /// isTrueWhenEqual - Return true if the specified condition returns true if
579   /// the two operands to the condition are equal.  Note that if one of the two
580   /// operands is a NaN, this value is meaningless.
581   inline bool isTrueWhenEqual(CondCode Cond) {
582     return ((int)Cond & 1) != 0;
583   }
584
585   /// getUnorderedFlavor - This function returns 0 if the condition is always
586   /// false if an operand is a NaN, 1 if the condition is always true if the
587   /// operand is a NaN, and 2 if the condition is undefined if the operand is a
588   /// NaN.
589   inline unsigned getUnorderedFlavor(CondCode Cond) {
590     return ((int)Cond >> 3) & 3;
591   }
592
593   /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
594   /// 'op' is a valid SetCC operation.
595   CondCode getSetCCInverse(CondCode Operation, bool isInteger);
596
597   /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
598   /// when given the operation for (X op Y).
599   CondCode getSetCCSwappedOperands(CondCode Operation);
600
601   /// getSetCCOrOperation - Return the result of a logical OR between different
602   /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
603   /// function returns SETCC_INVALID if it is not possible to represent the
604   /// resultant comparison.
605   CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
606
607   /// getSetCCAndOperation - Return the result of a logical AND between
608   /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
609   /// function returns SETCC_INVALID if it is not possible to represent the
610   /// resultant comparison.
611   CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
612 }  // end llvm::ISD namespace
613
614
615 //===----------------------------------------------------------------------===//
616 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
617 /// values as the result of a computation.  Many nodes return multiple values,
618 /// from loads (which define a token and a return value) to ADDC (which returns
619 /// a result and a carry value), to calls (which may return an arbitrary number
620 /// of values).
621 ///
622 /// As such, each use of a SelectionDAG computation must indicate the node that
623 /// computes it as well as which return value to use from that node.  This pair
624 /// of information is represented with the SDOperand value type.
625 ///
626 class SDOperand {
627 public:
628   SDNode *Val;        // The node defining the value we are using.
629   unsigned ResNo;     // Which return value of the node we are using.
630
631   SDOperand() : Val(0), ResNo(0) {}
632   SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
633
634   bool operator==(const SDOperand &O) const {
635     return Val == O.Val && ResNo == O.ResNo;
636   }
637   bool operator!=(const SDOperand &O) const {
638     return !operator==(O);
639   }
640   bool operator<(const SDOperand &O) const {
641     return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
642   }
643
644   SDOperand getValue(unsigned R) const {
645     return SDOperand(Val, R);
646   }
647
648   // isOperand - Return true if this node is an operand of N.
649   bool isOperand(SDNode *N) const;
650
651   /// getValueType - Return the ValueType of the referenced return value.
652   ///
653   inline MVT::ValueType getValueType() const;
654
655   // Forwarding methods - These forward to the corresponding methods in SDNode.
656   inline unsigned getOpcode() const;
657   inline unsigned getNodeDepth() const;
658   inline unsigned getNumOperands() const;
659   inline const SDOperand &getOperand(unsigned i) const;
660   inline bool isTargetOpcode() const;
661   inline unsigned getTargetOpcode() const;
662
663   /// hasOneUse - Return true if there is exactly one operation using this
664   /// result value of the defining operator.
665   inline bool hasOneUse() const;
666 };
667
668
669 /// simplify_type specializations - Allow casting operators to work directly on
670 /// SDOperands as if they were SDNode*'s.
671 template<> struct simplify_type<SDOperand> {
672   typedef SDNode* SimpleType;
673   static SimpleType getSimplifiedValue(const SDOperand &Val) {
674     return static_cast<SimpleType>(Val.Val);
675   }
676 };
677 template<> struct simplify_type<const SDOperand> {
678   typedef SDNode* SimpleType;
679   static SimpleType getSimplifiedValue(const SDOperand &Val) {
680     return static_cast<SimpleType>(Val.Val);
681   }
682 };
683
684
685 /// SDNode - Represents one node in the SelectionDAG.
686 ///
687 class SDNode {
688   /// NodeType - The operation that this node performs.
689   ///
690   unsigned short NodeType;
691
692   /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1.  This
693   /// means that leaves have a depth of 1, things that use only leaves have a
694   /// depth of 2, etc.
695   unsigned short NodeDepth;
696
697   /// OperandList - The values that are used by this operation.
698   ///
699   SDOperand *OperandList;
700   
701   /// ValueList - The types of the values this node defines.  SDNode's may
702   /// define multiple values simultaneously.
703   MVT::ValueType *ValueList;
704
705   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
706   unsigned short NumOperands, NumValues;
707   
708   /// Prev/Next pointers - These pointers form the linked list of of the
709   /// AllNodes list in the current DAG.
710   SDNode *Prev, *Next;
711   friend struct ilist_traits<SDNode>;
712
713   /// Uses - These are all of the SDNode's that use a value produced by this
714   /// node.
715   std::vector<SDNode*> Uses;
716   
717   // Out-of-line virtual method to give class a home.
718   virtual void ANCHOR();
719 public:
720   virtual ~SDNode() {
721     assert(NumOperands == 0 && "Operand list not cleared before deletion");
722     NodeType = ISD::DELETED_NODE;
723   }
724   
725   //===--------------------------------------------------------------------===//
726   //  Accessors
727   //
728   unsigned getOpcode()  const { return NodeType; }
729   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
730   unsigned getTargetOpcode() const {
731     assert(isTargetOpcode() && "Not a target opcode!");
732     return NodeType - ISD::BUILTIN_OP_END;
733   }
734
735   size_t use_size() const { return Uses.size(); }
736   bool use_empty() const { return Uses.empty(); }
737   bool hasOneUse() const { return Uses.size() == 1; }
738
739   /// getNodeDepth - Return the distance from this node to the leaves in the
740   /// graph.  The leaves have a depth of 1.
741   unsigned getNodeDepth() const { return NodeDepth; }
742
743   typedef std::vector<SDNode*>::const_iterator use_iterator;
744   use_iterator use_begin() const { return Uses.begin(); }
745   use_iterator use_end() const { return Uses.end(); }
746
747   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
748   /// indicated value.  This method ignores uses of other values defined by this
749   /// operation.
750   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
751
752   // isOnlyUse - Return true if this node is the only use of N.
753   bool isOnlyUse(SDNode *N) const;
754
755   // isOperand - Return true if this node is an operand of N.
756   bool isOperand(SDNode *N) const;
757
758   /// getNumOperands - Return the number of values used by this operation.
759   ///
760   unsigned getNumOperands() const { return NumOperands; }
761
762   const SDOperand &getOperand(unsigned Num) const {
763     assert(Num < NumOperands && "Invalid child # of SDNode!");
764     return OperandList[Num];
765   }
766   typedef const SDOperand* op_iterator;
767   op_iterator op_begin() const { return OperandList; }
768   op_iterator op_end() const { return OperandList+NumOperands; }
769
770
771   /// getNumValues - Return the number of values defined/returned by this
772   /// operator.
773   ///
774   unsigned getNumValues() const { return NumValues; }
775
776   /// getValueType - Return the type of a specified result.
777   ///
778   MVT::ValueType getValueType(unsigned ResNo) const {
779     assert(ResNo < NumValues && "Illegal result number!");
780     return ValueList[ResNo];
781   }
782
783   typedef const MVT::ValueType* value_iterator;
784   value_iterator value_begin() const { return ValueList; }
785   value_iterator value_end() const { return ValueList+NumValues; }
786
787   /// getOperationName - Return the opcode of this operation for printing.
788   ///
789   const char* getOperationName(const SelectionDAG *G = 0) const;
790   void dump() const;
791   void dump(const SelectionDAG *G) const;
792
793   static bool classof(const SDNode *) { return true; }
794
795 protected:
796   friend class SelectionDAG;
797   
798   /// getValueTypeList - Return a pointer to the specified value type.
799   ///
800   static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
801
802   SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) {
803     OperandList = 0; NumOperands = 0;
804     ValueList = getValueTypeList(VT);
805     NumValues = 1;
806     Prev = 0; Next = 0;
807   }
808   SDNode(unsigned NT, SDOperand Op)
809     : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) {
810     OperandList = new SDOperand[1];
811     OperandList[0] = Op;
812     NumOperands = 1;
813     Op.Val->Uses.push_back(this);
814     ValueList = 0;
815     NumValues = 0;
816     Prev = 0; Next = 0;
817   }
818   SDNode(unsigned NT, SDOperand N1, SDOperand N2)
819     : NodeType(NT) {
820     if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth())
821       NodeDepth = N1.Val->getNodeDepth()+1;
822     else
823       NodeDepth = N2.Val->getNodeDepth()+1;
824     OperandList = new SDOperand[2];
825     OperandList[0] = N1;
826     OperandList[1] = N2;
827     NumOperands = 2;
828     N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
829     ValueList = 0;
830     NumValues = 0;
831     Prev = 0; Next = 0;
832   }
833   SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
834     : NodeType(NT) {
835     unsigned ND = N1.Val->getNodeDepth();
836     if (ND < N2.Val->getNodeDepth())
837       ND = N2.Val->getNodeDepth();
838     if (ND < N3.Val->getNodeDepth())
839       ND = N3.Val->getNodeDepth();
840     NodeDepth = ND+1;
841
842     OperandList = new SDOperand[3];
843     OperandList[0] = N1;
844     OperandList[1] = N2;
845     OperandList[2] = N3;
846     NumOperands = 3;
847     
848     N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
849     N3.Val->Uses.push_back(this);
850     ValueList = 0;
851     NumValues = 0;
852     Prev = 0; Next = 0;
853   }
854   SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4)
855     : NodeType(NT) {
856     unsigned ND = N1.Val->getNodeDepth();
857     if (ND < N2.Val->getNodeDepth())
858       ND = N2.Val->getNodeDepth();
859     if (ND < N3.Val->getNodeDepth())
860       ND = N3.Val->getNodeDepth();
861     if (ND < N4.Val->getNodeDepth())
862       ND = N4.Val->getNodeDepth();
863     NodeDepth = ND+1;
864
865     OperandList = new SDOperand[4];
866     OperandList[0] = N1;
867     OperandList[1] = N2;
868     OperandList[2] = N3;
869     OperandList[3] = N4;
870     NumOperands = 4;
871     
872     N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
873     N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this);
874     ValueList = 0;
875     NumValues = 0;
876     Prev = 0; Next = 0;
877   }
878   SDNode(unsigned Opc, const std::vector<SDOperand> &Nodes) : NodeType(Opc) {
879     NumOperands = Nodes.size();
880     OperandList = new SDOperand[NumOperands];
881     
882     unsigned ND = 0;
883     for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
884       OperandList[i] = Nodes[i];
885       SDNode *N = OperandList[i].Val;
886       N->Uses.push_back(this);
887       if (ND < N->getNodeDepth()) ND = N->getNodeDepth();
888     }
889     NodeDepth = ND+1;
890     ValueList = 0;
891     NumValues = 0;
892     Prev = 0; Next = 0;
893   }
894
895   /// MorphNodeTo - This clears the return value and operands list, and sets the
896   /// opcode of the node to the specified value.  This should only be used by
897   /// the SelectionDAG class.
898   void MorphNodeTo(unsigned Opc) {
899     NodeType = Opc;
900     ValueList = 0;
901     NumValues = 0;
902     
903     // Clear the operands list, updating used nodes to remove this from their
904     // use list.
905     for (op_iterator I = op_begin(), E = op_end(); I != E; ++I)
906       I->Val->removeUser(this);
907     delete [] OperandList;
908     OperandList = 0;
909     NumOperands = 0;
910   }
911   
912   void setValueTypes(MVT::ValueType VT) {
913     assert(NumValues == 0 && "Should not have values yet!");
914     ValueList = getValueTypeList(VT);
915     NumValues = 1;
916   }
917   void setValueTypes(MVT::ValueType *List, unsigned NumVal) {
918     assert(NumValues == 0 && "Should not have values yet!");
919     ValueList = List;
920     NumValues = NumVal;
921   }
922   
923   void setOperands(SDOperand Op0) {
924     assert(NumOperands == 0 && "Should not have operands yet!");
925     OperandList = new SDOperand[1];
926     OperandList[0] = Op0;
927     NumOperands = 1;
928     Op0.Val->Uses.push_back(this);
929   }
930   void setOperands(SDOperand Op0, SDOperand Op1) {
931     assert(NumOperands == 0 && "Should not have operands yet!");
932     OperandList = new SDOperand[2];
933     OperandList[0] = Op0;
934     OperandList[1] = Op1;
935     NumOperands = 2;
936     Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
937   }
938   void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) {
939     assert(NumOperands == 0 && "Should not have operands yet!");
940     OperandList = new SDOperand[3];
941     OperandList[0] = Op0;
942     OperandList[1] = Op1;
943     OperandList[2] = Op2;
944     NumOperands = 3;
945     Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
946     Op2.Val->Uses.push_back(this);
947   }
948   void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3) {
949     assert(NumOperands == 0 && "Should not have operands yet!");
950     OperandList = new SDOperand[4];
951     OperandList[0] = Op0;
952     OperandList[1] = Op1;
953     OperandList[2] = Op2;
954     OperandList[3] = Op3;
955     NumOperands = 4;
956     Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
957     Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
958   }
959   void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
960                    SDOperand Op4) {
961     assert(NumOperands == 0 && "Should not have operands yet!");
962     OperandList = new SDOperand[5];
963     OperandList[0] = Op0;
964     OperandList[1] = Op1;
965     OperandList[2] = Op2;
966     OperandList[3] = Op3;
967     OperandList[4] = Op4;
968     NumOperands = 5;
969     Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
970     Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
971     Op4.Val->Uses.push_back(this);
972   }
973   void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
974                    SDOperand Op4, SDOperand Op5) {
975     assert(NumOperands == 0 && "Should not have operands yet!");
976     OperandList = new SDOperand[6];
977     OperandList[0] = Op0;
978     OperandList[1] = Op1;
979     OperandList[2] = Op2;
980     OperandList[3] = Op3;
981     OperandList[4] = Op4;
982     OperandList[5] = Op5;
983     NumOperands = 6;
984     Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
985     Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
986     Op4.Val->Uses.push_back(this); Op5.Val->Uses.push_back(this);
987   }
988   void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
989                    SDOperand Op4, SDOperand Op5, SDOperand Op6) {
990     assert(NumOperands == 0 && "Should not have operands yet!");
991     OperandList = new SDOperand[7];
992     OperandList[0] = Op0;
993     OperandList[1] = Op1;
994     OperandList[2] = Op2;
995     OperandList[3] = Op3;
996     OperandList[4] = Op4;
997     OperandList[5] = Op5;
998     OperandList[6] = Op6;
999     NumOperands = 7;
1000     Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
1001     Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
1002     Op4.Val->Uses.push_back(this); Op5.Val->Uses.push_back(this);
1003     Op6.Val->Uses.push_back(this);
1004   }
1005   void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
1006                    SDOperand Op4, SDOperand Op5, SDOperand Op6, SDOperand Op7) {
1007     assert(NumOperands == 0 && "Should not have operands yet!");
1008     OperandList = new SDOperand[8];
1009     OperandList[0] = Op0;
1010     OperandList[1] = Op1;
1011     OperandList[2] = Op2;
1012     OperandList[3] = Op3;
1013     OperandList[4] = Op4;
1014     OperandList[5] = Op5;
1015     OperandList[6] = Op6;
1016     OperandList[7] = Op7;
1017     NumOperands = 8;
1018     Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
1019     Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
1020     Op4.Val->Uses.push_back(this); Op5.Val->Uses.push_back(this);
1021     Op6.Val->Uses.push_back(this); Op7.Val->Uses.push_back(this);
1022   }
1023
1024   void addUser(SDNode *User) {
1025     Uses.push_back(User);
1026   }
1027   void removeUser(SDNode *User) {
1028     // Remove this user from the operand's use list.
1029     for (unsigned i = Uses.size(); ; --i) {
1030       assert(i != 0 && "Didn't find user!");
1031       if (Uses[i-1] == User) {
1032         Uses[i-1] = Uses.back();
1033         Uses.pop_back();
1034         return;
1035       }
1036     }
1037   }
1038 };
1039
1040
1041 // Define inline functions from the SDOperand class.
1042
1043 inline unsigned SDOperand::getOpcode() const {
1044   return Val->getOpcode();
1045 }
1046 inline unsigned SDOperand::getNodeDepth() const {
1047   return Val->getNodeDepth();
1048 }
1049 inline MVT::ValueType SDOperand::getValueType() const {
1050   return Val->getValueType(ResNo);
1051 }
1052 inline unsigned SDOperand::getNumOperands() const {
1053   return Val->getNumOperands();
1054 }
1055 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1056   return Val->getOperand(i);
1057 }
1058 inline bool SDOperand::isTargetOpcode() const {
1059   return Val->isTargetOpcode();
1060 }
1061 inline unsigned SDOperand::getTargetOpcode() const {
1062   return Val->getTargetOpcode();
1063 }
1064 inline bool SDOperand::hasOneUse() const {
1065   return Val->hasNUsesOfValue(1, ResNo);
1066 }
1067
1068 /// HandleSDNode - This class is used to form a handle around another node that
1069 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1070 /// operand.  This node should be directly created by end-users and not added to
1071 /// the AllNodes list.
1072 class HandleSDNode : public SDNode {
1073 public:
1074   HandleSDNode(SDOperand X) : SDNode(ISD::HANDLENODE, X) {}
1075   ~HandleSDNode() {
1076     MorphNodeTo(ISD::HANDLENODE);  // Drops operand uses.
1077   }
1078   
1079   SDOperand getValue() const { return getOperand(0); }
1080 };
1081
1082 class StringSDNode : public SDNode {
1083   std::string Value;
1084 protected:
1085   friend class SelectionDAG;
1086   StringSDNode(const std::string &val)
1087     : SDNode(ISD::STRING, MVT::Other), Value(val) {
1088   }
1089 public:
1090   const std::string &getValue() const { return Value; }
1091   static bool classof(const StringSDNode *) { return true; }
1092   static bool classof(const SDNode *N) {
1093     return N->getOpcode() == ISD::STRING;
1094   }
1095 };  
1096
1097 class ConstantSDNode : public SDNode {
1098   uint64_t Value;
1099 protected:
1100   friend class SelectionDAG;
1101   ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1102     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, VT), Value(val) {
1103   }
1104 public:
1105
1106   uint64_t getValue() const { return Value; }
1107
1108   int64_t getSignExtended() const {
1109     unsigned Bits = MVT::getSizeInBits(getValueType(0));
1110     return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1111   }
1112
1113   bool isNullValue() const { return Value == 0; }
1114   bool isAllOnesValue() const {
1115     return Value == MVT::getIntVTBitMask(getValueType(0));
1116   }
1117
1118   static bool classof(const ConstantSDNode *) { return true; }
1119   static bool classof(const SDNode *N) {
1120     return N->getOpcode() == ISD::Constant ||
1121            N->getOpcode() == ISD::TargetConstant;
1122   }
1123 };
1124
1125 class ConstantFPSDNode : public SDNode {
1126   double Value;
1127 protected:
1128   friend class SelectionDAG;
1129   ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1130     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, VT), 
1131       Value(val) {
1132   }
1133 public:
1134
1135   double getValue() const { return Value; }
1136
1137   /// isExactlyValue - We don't rely on operator== working on double values, as
1138   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1139   /// As such, this method can be used to do an exact bit-for-bit comparison of
1140   /// two floating point values.
1141   bool isExactlyValue(double V) const;
1142
1143   static bool classof(const ConstantFPSDNode *) { return true; }
1144   static bool classof(const SDNode *N) {
1145     return N->getOpcode() == ISD::ConstantFP || 
1146            N->getOpcode() == ISD::TargetConstantFP;
1147   }
1148 };
1149
1150 class GlobalAddressSDNode : public SDNode {
1151   GlobalValue *TheGlobal;
1152   int Offset;
1153 protected:
1154   friend class SelectionDAG;
1155   GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1156                       int o=0)
1157     : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT),
1158       Offset(o) {
1159     TheGlobal = const_cast<GlobalValue*>(GA);
1160   }
1161 public:
1162
1163   GlobalValue *getGlobal() const { return TheGlobal; }
1164   int getOffset() const { return Offset; }
1165
1166   static bool classof(const GlobalAddressSDNode *) { return true; }
1167   static bool classof(const SDNode *N) {
1168     return N->getOpcode() == ISD::GlobalAddress ||
1169            N->getOpcode() == ISD::TargetGlobalAddress;
1170   }
1171 };
1172
1173
1174 class FrameIndexSDNode : public SDNode {
1175   int FI;
1176 protected:
1177   friend class SelectionDAG;
1178   FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1179     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, VT), FI(fi) {}
1180 public:
1181
1182   int getIndex() const { return FI; }
1183
1184   static bool classof(const FrameIndexSDNode *) { return true; }
1185   static bool classof(const SDNode *N) {
1186     return N->getOpcode() == ISD::FrameIndex ||
1187            N->getOpcode() == ISD::TargetFrameIndex;
1188   }
1189 };
1190
1191 class JumpTableSDNode : public SDNode {
1192   int JTI;
1193 protected:
1194   friend class SelectionDAG;
1195   JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1196     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, VT), 
1197     JTI(jti) {}
1198 public:
1199     
1200     int getIndex() const { return JTI; }
1201   
1202   static bool classof(const JumpTableSDNode *) { return true; }
1203   static bool classof(const SDNode *N) {
1204     return N->getOpcode() == ISD::JumpTable ||
1205            N->getOpcode() == ISD::TargetJumpTable;
1206   }
1207 };
1208
1209 class ConstantPoolSDNode : public SDNode {
1210   Constant *C;
1211   int Offset;
1212   unsigned Alignment;
1213 protected:
1214   friend class SelectionDAG;
1215   ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1216                      int o=0)
1217     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
1218       C(c), Offset(o), Alignment(0) {}
1219   ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1220                      unsigned Align)
1221     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
1222       C(c), Offset(o), Alignment(Align) {}
1223 public:
1224
1225   Constant *get() const { return C; }
1226   int getOffset() const { return Offset; }
1227   
1228   // Return the alignment of this constant pool object, which is either 0 (for
1229   // default alignment) or log2 of the desired value.
1230   unsigned getAlignment() const { return Alignment; }
1231
1232   static bool classof(const ConstantPoolSDNode *) { return true; }
1233   static bool classof(const SDNode *N) {
1234     return N->getOpcode() == ISD::ConstantPool ||
1235            N->getOpcode() == ISD::TargetConstantPool;
1236   }
1237 };
1238
1239 class BasicBlockSDNode : public SDNode {
1240   MachineBasicBlock *MBB;
1241 protected:
1242   friend class SelectionDAG;
1243   BasicBlockSDNode(MachineBasicBlock *mbb)
1244     : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
1245 public:
1246
1247   MachineBasicBlock *getBasicBlock() const { return MBB; }
1248
1249   static bool classof(const BasicBlockSDNode *) { return true; }
1250   static bool classof(const SDNode *N) {
1251     return N->getOpcode() == ISD::BasicBlock;
1252   }
1253 };
1254
1255 class SrcValueSDNode : public SDNode {
1256   const Value *V;
1257   int offset;
1258 protected:
1259   friend class SelectionDAG;
1260   SrcValueSDNode(const Value* v, int o)
1261     : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {}
1262
1263 public:
1264   const Value *getValue() const { return V; }
1265   int getOffset() const { return offset; }
1266
1267   static bool classof(const SrcValueSDNode *) { return true; }
1268   static bool classof(const SDNode *N) {
1269     return N->getOpcode() == ISD::SRCVALUE;
1270   }
1271 };
1272
1273
1274 class RegisterSDNode : public SDNode {
1275   unsigned Reg;
1276 protected:
1277   friend class SelectionDAG;
1278   RegisterSDNode(unsigned reg, MVT::ValueType VT)
1279     : SDNode(ISD::Register, VT), Reg(reg) {}
1280 public:
1281
1282   unsigned getReg() const { return Reg; }
1283
1284   static bool classof(const RegisterSDNode *) { return true; }
1285   static bool classof(const SDNode *N) {
1286     return N->getOpcode() == ISD::Register;
1287   }
1288 };
1289
1290 class ExternalSymbolSDNode : public SDNode {
1291   const char *Symbol;
1292 protected:
1293   friend class SelectionDAG;
1294   ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1295     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, VT),
1296       Symbol(Sym) {
1297     }
1298 public:
1299
1300   const char *getSymbol() const { return Symbol; }
1301
1302   static bool classof(const ExternalSymbolSDNode *) { return true; }
1303   static bool classof(const SDNode *N) {
1304     return N->getOpcode() == ISD::ExternalSymbol ||
1305            N->getOpcode() == ISD::TargetExternalSymbol;
1306   }
1307 };
1308
1309 class CondCodeSDNode : public SDNode {
1310   ISD::CondCode Condition;
1311 protected:
1312   friend class SelectionDAG;
1313   CondCodeSDNode(ISD::CondCode Cond)
1314     : SDNode(ISD::CONDCODE, MVT::Other), Condition(Cond) {
1315   }
1316 public:
1317
1318   ISD::CondCode get() const { return Condition; }
1319
1320   static bool classof(const CondCodeSDNode *) { return true; }
1321   static bool classof(const SDNode *N) {
1322     return N->getOpcode() == ISD::CONDCODE;
1323   }
1324 };
1325
1326 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1327 /// to parameterize some operations.
1328 class VTSDNode : public SDNode {
1329   MVT::ValueType ValueType;
1330 protected:
1331   friend class SelectionDAG;
1332   VTSDNode(MVT::ValueType VT)
1333     : SDNode(ISD::VALUETYPE, MVT::Other), ValueType(VT) {}
1334 public:
1335
1336   MVT::ValueType getVT() const { return ValueType; }
1337
1338   static bool classof(const VTSDNode *) { return true; }
1339   static bool classof(const SDNode *N) {
1340     return N->getOpcode() == ISD::VALUETYPE;
1341   }
1342 };
1343
1344
1345 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1346   SDNode *Node;
1347   unsigned Operand;
1348
1349   SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1350 public:
1351   bool operator==(const SDNodeIterator& x) const {
1352     return Operand == x.Operand;
1353   }
1354   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1355
1356   const SDNodeIterator &operator=(const SDNodeIterator &I) {
1357     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1358     Operand = I.Operand;
1359     return *this;
1360   }
1361
1362   pointer operator*() const {
1363     return Node->getOperand(Operand).Val;
1364   }
1365   pointer operator->() const { return operator*(); }
1366
1367   SDNodeIterator& operator++() {                // Preincrement
1368     ++Operand;
1369     return *this;
1370   }
1371   SDNodeIterator operator++(int) { // Postincrement
1372     SDNodeIterator tmp = *this; ++*this; return tmp;
1373   }
1374
1375   static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1376   static SDNodeIterator end  (SDNode *N) {
1377     return SDNodeIterator(N, N->getNumOperands());
1378   }
1379
1380   unsigned getOperand() const { return Operand; }
1381   const SDNode *getNode() const { return Node; }
1382 };
1383
1384 template <> struct GraphTraits<SDNode*> {
1385   typedef SDNode NodeType;
1386   typedef SDNodeIterator ChildIteratorType;
1387   static inline NodeType *getEntryNode(SDNode *N) { return N; }
1388   static inline ChildIteratorType child_begin(NodeType *N) {
1389     return SDNodeIterator::begin(N);
1390   }
1391   static inline ChildIteratorType child_end(NodeType *N) {
1392     return SDNodeIterator::end(N);
1393   }
1394 };
1395
1396 template<>
1397 struct ilist_traits<SDNode> {
1398   static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1399   static SDNode *getNext(const SDNode *N) { return N->Next; }
1400   
1401   static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1402   static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1403   
1404   static SDNode *createSentinel() {
1405     return new SDNode(ISD::EntryToken, MVT::Other);
1406   }
1407   static void destroySentinel(SDNode *N) { delete N; }
1408   //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1409   
1410   
1411   void addNodeToList(SDNode *NTy) {}
1412   void removeNodeFromList(SDNode *NTy) {}
1413   void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1414                              const ilist_iterator<SDNode> &X,
1415                              const ilist_iterator<SDNode> &Y) {}
1416 };
1417
1418 } // end llvm namespace
1419
1420 #endif