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