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