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