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