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