792859a9b1746f10d8e345c8fbd66f78c88d3026
[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/Value.h"
23 #include "llvm/ADT/FoldingSet.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/iterator"
26 #include "llvm/CodeGen/ValueTypes.h"
27 #include "llvm/Support/DataTypes.h"
28 #include <cassert>
29
30 namespace llvm {
31
32 class SelectionDAG;
33 class GlobalValue;
34 class MachineBasicBlock;
35 class MachineConstantPoolValue;
36 class SDNode;
37 template <typename T> struct simplify_type;
38 template <typename T> struct ilist_traits;
39 template<typename NodeTy, typename Traits> class iplist;
40 template<typename NodeTy> class ilist_iterator;
41
42 /// SDVTList - This represents a list of ValueType's that has been intern'd by
43 /// a SelectionDAG.  Instances of this simple value class are returned by
44 /// SelectionDAG::getVTList(...).
45 ///
46 struct SDVTList {
47   const MVT::ValueType *VTs;
48   unsigned short NumVTs;
49 };
50
51 /// ISD namespace - This namespace contains an enum which represents all of the
52 /// SelectionDAG node types and value types.
53 ///
54 namespace ISD {
55   namespace ParamFlags {    
56   enum Flags {
57     NoFlagSet         = 0,
58     ZExt              = 1<<0,  ///< Parameter should be zero extended
59     ZExtOffs          = 0,
60     SExt              = 1<<1,  ///< Parameter should be sign extended
61     SExtOffs          = 1,
62     InReg             = 1<<2,  ///< Parameter should be passed in register
63     InRegOffs         = 2,
64     StructReturn      = 1<<3,  ///< Hidden struct-return pointer
65     StructReturnOffs  = 3,
66     OrigAlignment     = 0x1F<<27,
67     OrigAlignmentOffs = 27
68   };
69   }
70
71   //===--------------------------------------------------------------------===//
72   /// ISD::NodeType enum - This enum defines all of the operators valid in a
73   /// SelectionDAG.
74   ///
75   enum NodeType {
76     // DELETED_NODE - This is an illegal flag value that is used to catch
77     // errors.  This opcode is not a legal opcode for any node.
78     DELETED_NODE,
79     
80     // EntryToken - This is the marker used to indicate the start of the region.
81     EntryToken,
82
83     // Token factor - This node takes multiple tokens as input and produces a
84     // single token result.  This is used to represent the fact that the operand
85     // operators are independent of each other.
86     TokenFactor,
87     
88     // AssertSext, AssertZext - These nodes record if a register contains a 
89     // value that has already been zero or sign extended from a narrower type.  
90     // These nodes take two operands.  The first is the node that has already 
91     // been extended, and the second is a value type node indicating the width
92     // of the extension
93     AssertSext, AssertZext,
94
95     // Various leaf nodes.
96     STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
97     Constant, ConstantFP,
98     GlobalAddress, GlobalTLSAddress, FrameIndex,
99     JumpTable, ConstantPool, ExternalSymbol,
100
101     // The address of the GOT
102     GLOBAL_OFFSET_TABLE,
103     
104     // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
105     // llvm.returnaddress on the DAG.  These nodes take one operand, the index
106     // of the frame or return address to return.  An index of zero corresponds
107     // to the current function's frame or return address, an index of one to the
108     // parent's frame or return address, and so on.
109     FRAMEADDR, RETURNADDR,
110     
111     // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
112     // address of the exception block on entry to an landing pad block.
113     EXCEPTIONADDR,
114     
115     // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
116     // the selection index of the exception thrown.
117     EHSELECTION,
118
119     // TargetConstant* - Like Constant*, but the DAG does not do any folding or
120     // simplification of the constant.
121     TargetConstant,
122     TargetConstantFP,
123     
124     // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
125     // anything else with this node, and this is valid in the target-specific
126     // dag, turning into a GlobalAddress operand.
127     TargetGlobalAddress,
128     TargetGlobalTLSAddress,
129     TargetFrameIndex,
130     TargetJumpTable,
131     TargetConstantPool,
132     TargetExternalSymbol,
133     
134     /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
135     /// This node represents a target intrinsic function with no side effects.
136     /// The first operand is the ID number of the intrinsic from the
137     /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
138     /// node has returns the result of the intrinsic.
139     INTRINSIC_WO_CHAIN,
140     
141     /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
142     /// This node represents a target intrinsic function with side effects that
143     /// returns a result.  The first operand is a chain pointer.  The second is
144     /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
145     /// operands to the intrinsic follow.  The node has two results, the result
146     /// of the intrinsic and an output chain.
147     INTRINSIC_W_CHAIN,
148
149     /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
150     /// This node represents a target intrinsic function with side effects that
151     /// does not return a result.  The first operand is a chain pointer.  The
152     /// second is the ID number of the intrinsic from the llvm::Intrinsic
153     /// namespace.  The operands to the intrinsic follow.
154     INTRINSIC_VOID,
155     
156     // CopyToReg - This node has three operands: a chain, a register number to
157     // set to this value, and a value.  
158     CopyToReg,
159
160     // CopyFromReg - This node indicates that the input value is a virtual or
161     // physical register that is defined outside of the scope of this
162     // SelectionDAG.  The register is available from the RegSDNode object.
163     CopyFromReg,
164
165     // UNDEF - An undefined node
166     UNDEF,
167     
168     /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
169     /// represents the formal arguments for a function.  CC# is a Constant value
170     /// indicating the calling convention of the function, and ISVARARG is a
171     /// flag that indicates whether the function is varargs or not. This node
172     /// has one result value for each incoming argument, plus one for the output
173     /// chain. It must be custom legalized. See description of CALL node for
174     /// FLAG argument contents explanation.
175     /// 
176     FORMAL_ARGUMENTS,
177     
178     /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
179     ///                              ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
180     /// This node represents a fully general function call, before the legalizer
181     /// runs.  This has one result value for each argument / flag pair, plus
182     /// a chain result. It must be custom legalized. Flag argument indicates
183     /// misc. argument attributes. Currently:
184     /// Bit 0 - signness
185     /// Bit 1 - 'inreg' attribute
186     /// Bit 2 - 'sret' attribute
187     /// Bits 31:27 - argument ABI alignment in the first argument piece and
188     /// alignment '1' in other argument pieces.
189     CALL,
190
191     // EXTRACT_ELEMENT - This is used to get the first or second (determined by
192     // a Constant, which is required to be operand #1), element of the aggregate
193     // value specified as operand #0.  This is only for use before legalization,
194     // for values that will be broken into multiple registers.
195     EXTRACT_ELEMENT,
196
197     // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
198     // two values of the same integer value type, this produces a value twice as
199     // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
200     BUILD_PAIR,
201     
202     // MERGE_VALUES - This node takes multiple discrete operands and returns
203     // them all as its individual results.  This nodes has exactly the same
204     // number of inputs and outputs, and is only valid before legalization.
205     // This node is useful for some pieces of the code generator that want to
206     // think about a single node with multiple results, not multiple nodes.
207     MERGE_VALUES,
208
209     // Simple integer binary arithmetic operators.
210     ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
211     
212     // CARRY_FALSE - This node is used when folding other nodes,
213     // like ADDC/SUBC, which indicate the carry result is always false.
214     CARRY_FALSE,
215     
216     // Carry-setting nodes for multiple precision addition and subtraction.
217     // These nodes take two operands of the same value type, and produce two
218     // results.  The first result is the normal add or sub result, the second
219     // result is the carry flag result.
220     ADDC, SUBC,
221     
222     // Carry-using nodes for multiple precision addition and subtraction.  These
223     // nodes take three operands: The first two are the normal lhs and rhs to
224     // the add or sub, and the third is the input carry flag.  These nodes
225     // produce two results; the normal result of the add or sub, and the output
226     // carry flag.  These nodes both read and write a carry flag to allow them
227     // to them to be chained together for add and sub of arbitrarily large
228     // values.
229     ADDE, SUBE,
230     
231     // Simple binary floating point operators.
232     FADD, FSUB, FMUL, FDIV, FREM,
233
234     // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
235     // DAG node does not require that X and Y have the same type, just that they
236     // are both floating point.  X and the result must have the same type.
237     // FCOPYSIGN(f32, f64) is allowed.
238     FCOPYSIGN,
239
240     /// BUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,...) - Return a vector
241     /// with the specified, possibly variable, elements.  The number of elements
242     /// is required to be a power of two.
243     BUILD_VECTOR,
244     
245     /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
246     /// at IDX replaced with VAL.
247     INSERT_VECTOR_ELT,
248
249     /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
250     /// identified by the (potentially variable) element number IDX.
251     EXTRACT_VECTOR_ELT,
252     
253     /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
254     /// vector type with the same length and element type, this produces a
255     /// concatenated vector result value, with length equal to the sum of the
256     /// input vectors.
257     CONCAT_VECTORS,
258     
259     /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
260     /// vector value) starting with the (potentially variable) element number
261     /// IDX, which must be a multiple of the result vector length.
262     EXTRACT_SUBVECTOR,
263     
264     /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
265     /// type as VEC1/VEC2.  SHUFFLEVEC is a BUILD_VECTOR of constant int values
266     /// (regardless of whether its datatype is legal or not) that indicate
267     /// which value each result element will get.  The elements of VEC1/VEC2 are
268     /// enumerated in order.  This is quite similar to the Altivec 'vperm'
269     /// instruction, except that the indices must be constants and are in terms
270     /// of the element size of VEC1/VEC2, not in terms of bytes.
271     VECTOR_SHUFFLE,
272     
273     /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
274     /// scalar value into the low element of the resultant vector type.  The top
275     /// elements of the vector are undefined.
276     SCALAR_TO_VECTOR,
277     
278     // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
279     // an unsigned/signed value of type i[2*n], then return the top part.
280     MULHU, MULHS,
281
282     // Bitwise operators - logical and, logical or, logical xor, shift left,
283     // shift right algebraic (shift in sign bits), shift right logical (shift in
284     // zeroes), rotate left, rotate right, and byteswap.
285     AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
286
287     // Counting operators
288     CTTZ, CTLZ, CTPOP,
289
290     // Select(COND, TRUEVAL, FALSEVAL)
291     SELECT, 
292     
293     // Select with condition operator - This selects between a true value and 
294     // a false value (ops #2 and #3) based on the boolean result of comparing
295     // the lhs and rhs (ops #0 and #1) of a conditional expression with the 
296     // condition code in op #4, a CondCodeSDNode.
297     SELECT_CC,
298
299     // SetCC operator - This evaluates to a boolean (i1) true value if the
300     // condition is true.  The operands to this are the left and right operands
301     // to compare (ops #0, and #1) and the condition code to compare them with
302     // (op #2) as a CondCodeSDNode.
303     SETCC,
304
305     // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
306     // integer shift operations, just like ADD/SUB_PARTS.  The operation
307     // ordering is:
308     //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
309     SHL_PARTS, SRA_PARTS, SRL_PARTS,
310
311     // Conversion operators.  These are all single input single output
312     // operations.  For all of these, the result type must be strictly
313     // wider or narrower (depending on the operation) than the source
314     // type.
315
316     // SIGN_EXTEND - Used for integer types, replicating the sign bit
317     // into new bits.
318     SIGN_EXTEND,
319
320     // ZERO_EXTEND - Used for integer types, zeroing the new bits.
321     ZERO_EXTEND,
322
323     // ANY_EXTEND - Used for integer types.  The high bits are undefined.
324     ANY_EXTEND,
325     
326     // TRUNCATE - Completely drop the high bits.
327     TRUNCATE,
328
329     // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
330     // depends on the first letter) to floating point.
331     SINT_TO_FP,
332     UINT_TO_FP,
333
334     // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
335     // sign extend a small value in a large integer register (e.g. sign
336     // extending the low 8 bits of a 32-bit register to fill the top 24 bits
337     // with the 7th bit).  The size of the smaller type is indicated by the 1th
338     // operand, a ValueType node.
339     SIGN_EXTEND_INREG,
340
341     // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
342     // integer.
343     FP_TO_SINT,
344     FP_TO_UINT,
345
346     // FP_ROUND - Perform a rounding operation from the current
347     // precision down to the specified precision (currently always 64->32).
348     FP_ROUND,
349
350     // FP_ROUND_INREG - This operator takes a floating point register, and
351     // rounds it to a floating point value.  It then promotes it and returns it
352     // in a register of the same size.  This operation effectively just discards
353     // excess precision.  The type to round down to is specified by the 1th
354     // operation, a VTSDNode (currently always 64->32->64).
355     FP_ROUND_INREG,
356
357     // FP_EXTEND - Extend a smaller FP type into a larger FP type.
358     FP_EXTEND,
359
360     // BIT_CONVERT - Theis operator converts between integer and FP values, as
361     // if one was stored to memory as integer and the other was loaded from the
362     // same address (or equivalently for vector format conversions, etc).  The 
363     // source and result are required to have the same bit size (e.g. 
364     // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp 
365     // conversions, but that is a noop, deleted by getNode().
366     BIT_CONVERT,
367     
368     // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI - Perform unary floating point
369     // negation, absolute value, square root, sine and cosine, and powi
370     // operations.
371     FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI,
372     
373     // LOAD and STORE have token chains as their first operand, then the same
374     // operands as an LLVM load/store instruction, then an offset node that
375     // is added / subtracted from the base pointer to form the address (for
376     // indexed memory ops).
377     LOAD, STORE,
378     
379     // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
380     // value and stores it to memory in one operation.  This can be used for
381     // either integer or floating point operands.  The first four operands of
382     // this are the same as a standard store.  The fifth is the ValueType to
383     // store it as (which will be smaller than the source value).
384     TRUNCSTORE,
385
386     // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
387     // to a specified boundary.  This node always has two return values: a new
388     // stack pointer value and a chain. The first operand is the token chain,
389     // the second is the number of bytes to allocate, and the third is the
390     // alignment boundary.  The size is guaranteed to be a multiple of the stack
391     // alignment, and the alignment is guaranteed to be bigger than the stack
392     // alignment (if required) or 0 to get standard stack alignment.
393     DYNAMIC_STACKALLOC,
394
395     // Control flow instructions.  These all have token chains.
396
397     // BR - Unconditional branch.  The first operand is the chain
398     // operand, the second is the MBB to branch to.
399     BR,
400
401     // BRIND - Indirect branch.  The first operand is the chain, the second
402     // is the value to branch to, which must be of the same type as the target's
403     // pointer type.
404     BRIND,
405
406     // BR_JT - Jumptable branch. The first operand is the chain, the second
407     // is the jumptable index, the last one is the jumptable entry index.
408     BR_JT,
409     
410     // BRCOND - Conditional branch.  The first operand is the chain,
411     // the second is the condition, the third is the block to branch
412     // to if the condition is true.
413     BRCOND,
414
415     // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
416     // that the condition is represented as condition code, and two nodes to
417     // compare, rather than as a combined SetCC node.  The operands in order are
418     // chain, cc, lhs, rhs, block to branch to if condition is true.
419     BR_CC,
420     
421     // RET - Return from function.  The first operand is the chain,
422     // and any subsequent operands are pairs of return value and return value
423     // signness for the function.  This operation can have variable number of
424     // operands.
425     RET,
426
427     // INLINEASM - Represents an inline asm block.  This node always has two
428     // return values: a chain and a flag result.  The inputs are as follows:
429     //   Operand #0   : Input chain.
430     //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
431     //   Operand #2n+2: A RegisterNode.
432     //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
433     //   Operand #last: Optional, an incoming flag.
434     INLINEASM,
435     
436     // LABEL - Represents a label in mid basic block used to track
437     // locations needed for debug and exception handling tables.  This node
438     // returns a chain.
439     //   Operand #0 : input chain.
440     //   Operand #1 : module unique number use to identify the label.
441     LABEL,
442     
443     // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
444     // value, the same type as the pointer type for the system, and an output
445     // chain.
446     STACKSAVE,
447     
448     // STACKRESTORE has two operands, an input chain and a pointer to restore to
449     // it returns an output chain.
450     STACKRESTORE,
451     
452     // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
453     // correspond to the operands of the LLVM intrinsic functions.  The only
454     // result is a token chain.  The alignment argument is guaranteed to be a
455     // Constant node.
456     MEMSET,
457     MEMMOVE,
458     MEMCPY,
459
460     // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
461     // a call sequence, and carry arbitrary information that target might want
462     // to know.  The first operand is a chain, the rest are specified by the
463     // target and not touched by the DAG optimizers.
464     CALLSEQ_START,  // Beginning of a call sequence
465     CALLSEQ_END,    // End of a call sequence
466     
467     // VAARG - VAARG has three operands: an input chain, a pointer, and a 
468     // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
469     VAARG,
470     
471     // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
472     // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
473     // source.
474     VACOPY,
475     
476     // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
477     // pointer, and a SRCVALUE.
478     VAEND, VASTART,
479
480     // SRCVALUE - This corresponds to a Value*, and is used to associate memory
481     // locations with their value.  This allows one use alias analysis
482     // information in the backend.
483     SRCVALUE,
484
485     // PCMARKER - This corresponds to the pcmarker intrinsic.
486     PCMARKER,
487
488     // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
489     // The only operand is a chain and a value and a chain are produced.  The
490     // value is the contents of the architecture specific cycle counter like 
491     // register (or other high accuracy low latency clock source)
492     READCYCLECOUNTER,
493
494     // HANDLENODE node - Used as a handle for various purposes.
495     HANDLENODE,
496
497     // LOCATION - This node is used to represent a source location for debug
498     // info.  It takes token chain as input, then a line number, then a column
499     // number, then a filename, then a working dir.  It produces a token chain
500     // as output.
501     LOCATION,
502     
503     // DEBUG_LOC - This node is used to represent source line information
504     // embedded in the code.  It takes a token chain as input, then a line
505     // number, then a column then a file id (provided by MachineModuleInfo.) It
506     // produces a token chain as output.
507     DEBUG_LOC,
508     
509     // BUILTIN_OP_END - This must be the last enum value in this list.
510     BUILTIN_OP_END
511   };
512
513   /// Node predicates
514
515   /// isBuildVectorAllOnes - Return true if the specified node is a
516   /// BUILD_VECTOR where all of the elements are ~0 or undef.
517   bool isBuildVectorAllOnes(const SDNode *N);
518
519   /// isBuildVectorAllZeros - Return true if the specified node is a
520   /// BUILD_VECTOR where all of the elements are 0 or undef.
521   bool isBuildVectorAllZeros(const SDNode *N);
522   
523   //===--------------------------------------------------------------------===//
524   /// MemIndexedMode enum - This enum defines the load / store indexed 
525   /// addressing modes.
526   ///
527   /// UNINDEXED    "Normal" load / store. The effective address is already
528   ///              computed and is available in the base pointer. The offset
529   ///              operand is always undefined. In addition to producing a
530   ///              chain, an unindexed load produces one value (result of the
531   ///              load); an unindexed store does not produces a value.
532   ///
533   /// PRE_INC      Similar to the unindexed mode where the effective address is
534   /// PRE_DEC      the value of the base pointer add / subtract the offset.
535   ///              It considers the computation as being folded into the load /
536   ///              store operation (i.e. the load / store does the address
537   ///              computation as well as performing the memory transaction).
538   ///              The base operand is always undefined. In addition to
539   ///              producing a chain, pre-indexed load produces two values
540   ///              (result of the load and the result of the address
541   ///              computation); a pre-indexed store produces one value (result
542   ///              of the address computation).
543   ///
544   /// POST_INC     The effective address is the value of the base pointer. The
545   /// POST_DEC     value of the offset operand is then added to / subtracted
546   ///              from the base after memory transaction. In addition to
547   ///              producing a chain, post-indexed load produces two values
548   ///              (the result of the load and the result of the base +/- offset
549   ///              computation); a post-indexed store produces one value (the
550   ///              the result of the base +/- offset computation).
551   ///
552   enum MemIndexedMode {
553     UNINDEXED = 0,
554     PRE_INC,
555     PRE_DEC,
556     POST_INC,
557     POST_DEC,
558     LAST_INDEXED_MODE
559   };
560
561   //===--------------------------------------------------------------------===//
562   /// LoadExtType enum - This enum defines the three variants of LOADEXT
563   /// (load with extension).
564   ///
565   /// SEXTLOAD loads the integer operand and sign extends it to a larger
566   ///          integer result type.
567   /// ZEXTLOAD loads the integer operand and zero extends it to a larger
568   ///          integer result type.
569   /// EXTLOAD  is used for three things: floating point extending loads, 
570   ///          integer extending loads [the top bits are undefined], and vector
571   ///          extending loads [load into low elt].
572   ///
573   enum LoadExtType {
574     NON_EXTLOAD = 0,
575     EXTLOAD,
576     SEXTLOAD,
577     ZEXTLOAD,
578     LAST_LOADX_TYPE
579   };
580
581   //===--------------------------------------------------------------------===//
582   /// ISD::CondCode enum - These are ordered carefully to make the bitfields
583   /// below work out, when considering SETFALSE (something that never exists
584   /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
585   /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
586   /// to.  If the "N" column is 1, the result of the comparison is undefined if
587   /// the input is a NAN.
588   ///
589   /// All of these (except for the 'always folded ops') should be handled for
590   /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
591   /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
592   ///
593   /// Note that these are laid out in a specific order to allow bit-twiddling
594   /// to transform conditions.
595   enum CondCode {
596     // Opcode          N U L G E       Intuitive operation
597     SETFALSE,      //    0 0 0 0       Always false (always folded)
598     SETOEQ,        //    0 0 0 1       True if ordered and equal
599     SETOGT,        //    0 0 1 0       True if ordered and greater than
600     SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
601     SETOLT,        //    0 1 0 0       True if ordered and less than
602     SETOLE,        //    0 1 0 1       True if ordered and less than or equal
603     SETONE,        //    0 1 1 0       True if ordered and operands are unequal
604     SETO,          //    0 1 1 1       True if ordered (no nans)
605     SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
606     SETUEQ,        //    1 0 0 1       True if unordered or equal
607     SETUGT,        //    1 0 1 0       True if unordered or greater than
608     SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
609     SETULT,        //    1 1 0 0       True if unordered or less than
610     SETULE,        //    1 1 0 1       True if unordered, less than, or equal
611     SETUNE,        //    1 1 1 0       True if unordered or not equal
612     SETTRUE,       //    1 1 1 1       Always true (always folded)
613     // Don't care operations: undefined if the input is a nan.
614     SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
615     SETEQ,         //  1 X 0 0 1       True if equal
616     SETGT,         //  1 X 0 1 0       True if greater than
617     SETGE,         //  1 X 0 1 1       True if greater than or equal
618     SETLT,         //  1 X 1 0 0       True if less than
619     SETLE,         //  1 X 1 0 1       True if less than or equal
620     SETNE,         //  1 X 1 1 0       True if not equal
621     SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
622
623     SETCC_INVALID       // Marker value.
624   };
625
626   /// isSignedIntSetCC - Return true if this is a setcc instruction that
627   /// performs a signed comparison when used with integer operands.
628   inline bool isSignedIntSetCC(CondCode Code) {
629     return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
630   }
631
632   /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
633   /// performs an unsigned comparison when used with integer operands.
634   inline bool isUnsignedIntSetCC(CondCode Code) {
635     return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
636   }
637
638   /// isTrueWhenEqual - Return true if the specified condition returns true if
639   /// the two operands to the condition are equal.  Note that if one of the two
640   /// operands is a NaN, this value is meaningless.
641   inline bool isTrueWhenEqual(CondCode Cond) {
642     return ((int)Cond & 1) != 0;
643   }
644
645   /// getUnorderedFlavor - This function returns 0 if the condition is always
646   /// false if an operand is a NaN, 1 if the condition is always true if the
647   /// operand is a NaN, and 2 if the condition is undefined if the operand is a
648   /// NaN.
649   inline unsigned getUnorderedFlavor(CondCode Cond) {
650     return ((int)Cond >> 3) & 3;
651   }
652
653   /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
654   /// 'op' is a valid SetCC operation.
655   CondCode getSetCCInverse(CondCode Operation, bool isInteger);
656
657   /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
658   /// when given the operation for (X op Y).
659   CondCode getSetCCSwappedOperands(CondCode Operation);
660
661   /// getSetCCOrOperation - Return the result of a logical OR between different
662   /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
663   /// function returns SETCC_INVALID if it is not possible to represent the
664   /// resultant comparison.
665   CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
666
667   /// getSetCCAndOperation - Return the result of a logical AND between
668   /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
669   /// function returns SETCC_INVALID if it is not possible to represent the
670   /// resultant comparison.
671   CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
672 }  // end llvm::ISD namespace
673
674
675 //===----------------------------------------------------------------------===//
676 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
677 /// values as the result of a computation.  Many nodes return multiple values,
678 /// from loads (which define a token and a return value) to ADDC (which returns
679 /// a result and a carry value), to calls (which may return an arbitrary number
680 /// of values).
681 ///
682 /// As such, each use of a SelectionDAG computation must indicate the node that
683 /// computes it as well as which return value to use from that node.  This pair
684 /// of information is represented with the SDOperand value type.
685 ///
686 class SDOperand {
687 public:
688   SDNode *Val;        // The node defining the value we are using.
689   unsigned ResNo;     // Which return value of the node we are using.
690
691   SDOperand() : Val(0), ResNo(0) {}
692   SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
693
694   bool operator==(const SDOperand &O) const {
695     return Val == O.Val && ResNo == O.ResNo;
696   }
697   bool operator!=(const SDOperand &O) const {
698     return !operator==(O);
699   }
700   bool operator<(const SDOperand &O) const {
701     return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
702   }
703
704   SDOperand getValue(unsigned R) const {
705     return SDOperand(Val, R);
706   }
707
708   // isOperand - Return true if this node is an operand of N.
709   bool isOperand(SDNode *N) const;
710
711   /// getValueType - Return the ValueType of the referenced return value.
712   ///
713   inline MVT::ValueType getValueType() const;
714
715   // Forwarding methods - These forward to the corresponding methods in SDNode.
716   inline unsigned getOpcode() const;
717   inline unsigned getNumOperands() const;
718   inline const SDOperand &getOperand(unsigned i) const;
719   inline uint64_t getConstantOperandVal(unsigned i) const;
720   inline bool isTargetOpcode() const;
721   inline unsigned getTargetOpcode() const;
722
723   /// hasOneUse - Return true if there is exactly one operation using this
724   /// result value of the defining operator.
725   inline bool hasOneUse() const;
726 };
727
728
729 /// simplify_type specializations - Allow casting operators to work directly on
730 /// SDOperands as if they were SDNode*'s.
731 template<> struct simplify_type<SDOperand> {
732   typedef SDNode* SimpleType;
733   static SimpleType getSimplifiedValue(const SDOperand &Val) {
734     return static_cast<SimpleType>(Val.Val);
735   }
736 };
737 template<> struct simplify_type<const SDOperand> {
738   typedef SDNode* SimpleType;
739   static SimpleType getSimplifiedValue(const SDOperand &Val) {
740     return static_cast<SimpleType>(Val.Val);
741   }
742 };
743
744
745 /// SDNode - Represents one node in the SelectionDAG.
746 ///
747 class SDNode : public FoldingSetNode {
748   /// NodeType - The operation that this node performs.
749   ///
750   unsigned short NodeType;
751   
752   /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
753   /// then they will be delete[]'d when the node is destroyed.
754   bool OperandsNeedDelete : 1;
755
756   /// NodeId - Unique id per SDNode in the DAG.
757   int NodeId;
758
759   /// OperandList - The values that are used by this operation.
760   ///
761   SDOperand *OperandList;
762   
763   /// ValueList - The types of the values this node defines.  SDNode's may
764   /// define multiple values simultaneously.
765   const MVT::ValueType *ValueList;
766
767   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
768   unsigned short NumOperands, NumValues;
769   
770   /// Prev/Next pointers - These pointers form the linked list of of the
771   /// AllNodes list in the current DAG.
772   SDNode *Prev, *Next;
773   friend struct ilist_traits<SDNode>;
774
775   /// Uses - These are all of the SDNode's that use a value produced by this
776   /// node.
777   SmallVector<SDNode*,3> Uses;
778   
779   // Out-of-line virtual method to give class a home.
780   virtual void ANCHOR();
781 public:
782   virtual ~SDNode() {
783     assert(NumOperands == 0 && "Operand list not cleared before deletion");
784     NodeType = ISD::DELETED_NODE;
785   }
786   
787   //===--------------------------------------------------------------------===//
788   //  Accessors
789   //
790   unsigned getOpcode()  const { return NodeType; }
791   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
792   unsigned getTargetOpcode() const {
793     assert(isTargetOpcode() && "Not a target opcode!");
794     return NodeType - ISD::BUILTIN_OP_END;
795   }
796
797   size_t use_size() const { return Uses.size(); }
798   bool use_empty() const { return Uses.empty(); }
799   bool hasOneUse() const { return Uses.size() == 1; }
800
801   /// getNodeId - Return the unique node id.
802   ///
803   int getNodeId() const { return NodeId; }
804
805   typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
806   use_iterator use_begin() const { return Uses.begin(); }
807   use_iterator use_end() const { return Uses.end(); }
808
809   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
810   /// indicated value.  This method ignores uses of other values defined by this
811   /// operation.
812   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
813
814   /// isOnlyUse - Return true if this node is the only use of N.
815   ///
816   bool isOnlyUse(SDNode *N) const;
817
818   /// isOperand - Return true if this node is an operand of N.
819   ///
820   bool isOperand(SDNode *N) const;
821
822   /// isPredecessor - Return true if this node is a predecessor of N. This node
823   /// is either an operand of N or it can be reached by recursively traversing
824   /// up the operands.
825   /// NOTE: this is an expensive method. Use it carefully.
826   bool isPredecessor(SDNode *N) const;
827
828   /// getNumOperands - Return the number of values used by this operation.
829   ///
830   unsigned getNumOperands() const { return NumOperands; }
831
832   /// getConstantOperandVal - Helper method returns the integer value of a 
833   /// ConstantSDNode operand.
834   uint64_t getConstantOperandVal(unsigned Num) const;
835
836   const SDOperand &getOperand(unsigned Num) const {
837     assert(Num < NumOperands && "Invalid child # of SDNode!");
838     return OperandList[Num];
839   }
840
841   typedef const SDOperand* op_iterator;
842   op_iterator op_begin() const { return OperandList; }
843   op_iterator op_end() const { return OperandList+NumOperands; }
844
845
846   SDVTList getVTList() const {
847     SDVTList X = { ValueList, NumValues };
848     return X;
849   };
850   
851   /// getNumValues - Return the number of values defined/returned by this
852   /// operator.
853   ///
854   unsigned getNumValues() const { return NumValues; }
855
856   /// getValueType - Return the type of a specified result.
857   ///
858   MVT::ValueType getValueType(unsigned ResNo) const {
859     assert(ResNo < NumValues && "Illegal result number!");
860     return ValueList[ResNo];
861   }
862
863   typedef const MVT::ValueType* value_iterator;
864   value_iterator value_begin() const { return ValueList; }
865   value_iterator value_end() const { return ValueList+NumValues; }
866
867   /// getOperationName - Return the opcode of this operation for printing.
868   ///
869   std::string getOperationName(const SelectionDAG *G = 0) const;
870   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
871   void dump() const;
872   void dump(const SelectionDAG *G) const;
873
874   static bool classof(const SDNode *) { return true; }
875
876   /// Profile - Gather unique data for the node.
877   ///
878   void Profile(FoldingSetNodeID &ID);
879
880 protected:
881   friend class SelectionDAG;
882   
883   /// getValueTypeList - Return a pointer to the specified value type.
884   ///
885   static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
886   static SDVTList getSDVTList(MVT::ValueType VT) {
887     SDVTList Ret = { getValueTypeList(VT), 1 };
888     return Ret;
889   }
890
891   SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
892     : NodeType(Opc), NodeId(-1) {
893     OperandsNeedDelete = true;
894     NumOperands = NumOps;
895     OperandList = NumOps ? new SDOperand[NumOperands] : 0;
896     
897     for (unsigned i = 0; i != NumOps; ++i) {
898       OperandList[i] = Ops[i];
899       Ops[i].Val->Uses.push_back(this);
900     }
901     
902     ValueList = VTs.VTs;
903     NumValues = VTs.NumVTs;
904     Prev = 0; Next = 0;
905   }
906   SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
907     OperandsNeedDelete = false;  // Operands set with InitOperands.
908     NumOperands = 0;
909     OperandList = 0;
910     
911     ValueList = VTs.VTs;
912     NumValues = VTs.NumVTs;
913     Prev = 0; Next = 0;
914   }
915   
916   /// InitOperands - Initialize the operands list of this node with the
917   /// specified values, which are part of the node (thus they don't need to be
918   /// copied in or allocated).
919   void InitOperands(SDOperand *Ops, unsigned NumOps) {
920     assert(OperandList == 0 && "Operands already set!");
921     NumOperands = NumOps;
922     OperandList = Ops;
923     
924     for (unsigned i = 0; i != NumOps; ++i)
925       Ops[i].Val->Uses.push_back(this);
926   }
927   
928   /// MorphNodeTo - This frees the operands of the current node, resets the
929   /// opcode, types, and operands to the specified value.  This should only be
930   /// used by the SelectionDAG class.
931   void MorphNodeTo(unsigned Opc, SDVTList L,
932                    const SDOperand *Ops, unsigned NumOps);
933   
934   void addUser(SDNode *User) {
935     Uses.push_back(User);
936   }
937   void removeUser(SDNode *User) {
938     // Remove this user from the operand's use list.
939     for (unsigned i = Uses.size(); ; --i) {
940       assert(i != 0 && "Didn't find user!");
941       if (Uses[i-1] == User) {
942         Uses[i-1] = Uses.back();
943         Uses.pop_back();
944         return;
945       }
946     }
947   }
948
949   void setNodeId(int Id) {
950     NodeId = Id;
951   }
952 };
953
954
955 // Define inline functions from the SDOperand class.
956
957 inline unsigned SDOperand::getOpcode() const {
958   return Val->getOpcode();
959 }
960 inline MVT::ValueType SDOperand::getValueType() const {
961   return Val->getValueType(ResNo);
962 }
963 inline unsigned SDOperand::getNumOperands() const {
964   return Val->getNumOperands();
965 }
966 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
967   return Val->getOperand(i);
968 }
969 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
970   return Val->getConstantOperandVal(i);
971 }
972 inline bool SDOperand::isTargetOpcode() const {
973   return Val->isTargetOpcode();
974 }
975 inline unsigned SDOperand::getTargetOpcode() const {
976   return Val->getTargetOpcode();
977 }
978 inline bool SDOperand::hasOneUse() const {
979   return Val->hasNUsesOfValue(1, ResNo);
980 }
981
982 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
983 /// to allow co-allocation of node operands with the node itself.
984 class UnarySDNode : public SDNode {
985   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
986   SDOperand Op;
987 public:
988   UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
989     : SDNode(Opc, VTs), Op(X) {
990     InitOperands(&Op, 1);
991   }
992 };
993
994 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
995 /// to allow co-allocation of node operands with the node itself.
996 class BinarySDNode : public SDNode {
997   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
998   SDOperand Ops[2];
999 public:
1000   BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1001     : SDNode(Opc, VTs) {
1002     Ops[0] = X;
1003     Ops[1] = Y;
1004     InitOperands(Ops, 2);
1005   }
1006 };
1007
1008 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1009 /// to allow co-allocation of node operands with the node itself.
1010 class TernarySDNode : public SDNode {
1011   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1012   SDOperand Ops[3];
1013 public:
1014   TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1015                 SDOperand Z)
1016     : SDNode(Opc, VTs) {
1017     Ops[0] = X;
1018     Ops[1] = Y;
1019     Ops[2] = Z;
1020     InitOperands(Ops, 3);
1021   }
1022 };
1023
1024
1025 /// HandleSDNode - This class is used to form a handle around another node that
1026 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1027 /// operand.  This node should be directly created by end-users and not added to
1028 /// the AllNodes list.
1029 class HandleSDNode : public SDNode {
1030   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1031   SDOperand Op;
1032 public:
1033   explicit HandleSDNode(SDOperand X)
1034     : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1035     InitOperands(&Op, 1);
1036   }
1037   ~HandleSDNode();  
1038   SDOperand getValue() const { return Op; }
1039 };
1040
1041 class StringSDNode : public SDNode {
1042   std::string Value;
1043   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1044 protected:
1045   friend class SelectionDAG;
1046   explicit StringSDNode(const std::string &val)
1047     : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1048   }
1049 public:
1050   const std::string &getValue() const { return Value; }
1051   static bool classof(const StringSDNode *) { return true; }
1052   static bool classof(const SDNode *N) {
1053     return N->getOpcode() == ISD::STRING;
1054   }
1055 };  
1056
1057 class ConstantSDNode : public SDNode {
1058   uint64_t Value;
1059   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1060 protected:
1061   friend class SelectionDAG;
1062   ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1063     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1064       Value(val) {
1065   }
1066 public:
1067
1068   uint64_t getValue() const { return Value; }
1069
1070   int64_t getSignExtended() const {
1071     unsigned Bits = MVT::getSizeInBits(getValueType(0));
1072     return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1073   }
1074
1075   bool isNullValue() const { return Value == 0; }
1076   bool isAllOnesValue() const {
1077     return Value == MVT::getIntVTBitMask(getValueType(0));
1078   }
1079
1080   static bool classof(const ConstantSDNode *) { return true; }
1081   static bool classof(const SDNode *N) {
1082     return N->getOpcode() == ISD::Constant ||
1083            N->getOpcode() == ISD::TargetConstant;
1084   }
1085 };
1086
1087 class ConstantFPSDNode : public SDNode {
1088   double Value;
1089   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1090 protected:
1091   friend class SelectionDAG;
1092   ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1093     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1094              getSDVTList(VT)), Value(val) {
1095   }
1096 public:
1097
1098   double getValue() const { return Value; }
1099
1100   /// isExactlyValue - We don't rely on operator== working on double values, as
1101   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1102   /// As such, this method can be used to do an exact bit-for-bit comparison of
1103   /// two floating point values.
1104   bool isExactlyValue(double V) const;
1105
1106   static bool classof(const ConstantFPSDNode *) { return true; }
1107   static bool classof(const SDNode *N) {
1108     return N->getOpcode() == ISD::ConstantFP || 
1109            N->getOpcode() == ISD::TargetConstantFP;
1110   }
1111 };
1112
1113 class GlobalAddressSDNode : public SDNode {
1114   GlobalValue *TheGlobal;
1115   int Offset;
1116   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1117 protected:
1118   friend class SelectionDAG;
1119   GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1120                       int o = 0);
1121 public:
1122
1123   GlobalValue *getGlobal() const { return TheGlobal; }
1124   int getOffset() const { return Offset; }
1125
1126   static bool classof(const GlobalAddressSDNode *) { return true; }
1127   static bool classof(const SDNode *N) {
1128     return N->getOpcode() == ISD::GlobalAddress ||
1129            N->getOpcode() == ISD::TargetGlobalAddress ||
1130            N->getOpcode() == ISD::GlobalTLSAddress ||
1131            N->getOpcode() == ISD::TargetGlobalTLSAddress;
1132   }
1133 };
1134
1135 class FrameIndexSDNode : public SDNode {
1136   int FI;
1137   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1138 protected:
1139   friend class SelectionDAG;
1140   FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1141     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1142       FI(fi) {
1143   }
1144 public:
1145
1146   int getIndex() const { return FI; }
1147
1148   static bool classof(const FrameIndexSDNode *) { return true; }
1149   static bool classof(const SDNode *N) {
1150     return N->getOpcode() == ISD::FrameIndex ||
1151            N->getOpcode() == ISD::TargetFrameIndex;
1152   }
1153 };
1154
1155 class JumpTableSDNode : public SDNode {
1156   int JTI;
1157   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1158 protected:
1159   friend class SelectionDAG;
1160   JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1161     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1162       JTI(jti) {
1163   }
1164 public:
1165     
1166     int getIndex() const { return JTI; }
1167   
1168   static bool classof(const JumpTableSDNode *) { return true; }
1169   static bool classof(const SDNode *N) {
1170     return N->getOpcode() == ISD::JumpTable ||
1171            N->getOpcode() == ISD::TargetJumpTable;
1172   }
1173 };
1174
1175 class ConstantPoolSDNode : public SDNode {
1176   union {
1177     Constant *ConstVal;
1178     MachineConstantPoolValue *MachineCPVal;
1179   } Val;
1180   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1181   unsigned Alignment;
1182   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1183 protected:
1184   friend class SelectionDAG;
1185   ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1186                      int o=0)
1187     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1188              getSDVTList(VT)), Offset(o), Alignment(0) {
1189     assert((int)Offset >= 0 && "Offset is too large");
1190     Val.ConstVal = c;
1191   }
1192   ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1193                      unsigned Align)
1194     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1195              getSDVTList(VT)), Offset(o), Alignment(Align) {
1196     assert((int)Offset >= 0 && "Offset is too large");
1197     Val.ConstVal = c;
1198   }
1199   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1200                      MVT::ValueType VT, int o=0)
1201     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1202              getSDVTList(VT)), Offset(o), Alignment(0) {
1203     assert((int)Offset >= 0 && "Offset is too large");
1204     Val.MachineCPVal = v;
1205     Offset |= 1 << (sizeof(unsigned)*8-1);
1206   }
1207   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1208                      MVT::ValueType VT, int o, unsigned Align)
1209     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1210              getSDVTList(VT)), Offset(o), Alignment(Align) {
1211     assert((int)Offset >= 0 && "Offset is too large");
1212     Val.MachineCPVal = v;
1213     Offset |= 1 << (sizeof(unsigned)*8-1);
1214   }
1215 public:
1216
1217   bool isMachineConstantPoolEntry() const {
1218     return (int)Offset < 0;
1219   }
1220
1221   Constant *getConstVal() const {
1222     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1223     return Val.ConstVal;
1224   }
1225
1226   MachineConstantPoolValue *getMachineCPVal() const {
1227     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1228     return Val.MachineCPVal;
1229   }
1230
1231   int getOffset() const {
1232     return Offset & ~(1 << (sizeof(unsigned)*8-1));
1233   }
1234   
1235   // Return the alignment of this constant pool object, which is either 0 (for
1236   // default alignment) or log2 of the desired value.
1237   unsigned getAlignment() const { return Alignment; }
1238
1239   const Type *getType() const;
1240
1241   static bool classof(const ConstantPoolSDNode *) { return true; }
1242   static bool classof(const SDNode *N) {
1243     return N->getOpcode() == ISD::ConstantPool ||
1244            N->getOpcode() == ISD::TargetConstantPool;
1245   }
1246 };
1247
1248 class BasicBlockSDNode : public SDNode {
1249   MachineBasicBlock *MBB;
1250   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1251 protected:
1252   friend class SelectionDAG;
1253   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1254     : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1255   }
1256 public:
1257
1258   MachineBasicBlock *getBasicBlock() const { return MBB; }
1259
1260   static bool classof(const BasicBlockSDNode *) { return true; }
1261   static bool classof(const SDNode *N) {
1262     return N->getOpcode() == ISD::BasicBlock;
1263   }
1264 };
1265
1266 class SrcValueSDNode : public SDNode {
1267   const Value *V;
1268   int offset;
1269   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1270 protected:
1271   friend class SelectionDAG;
1272   SrcValueSDNode(const Value* v, int o)
1273     : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v), offset(o) {
1274   }
1275
1276 public:
1277   const Value *getValue() const { return V; }
1278   int getOffset() const { return offset; }
1279
1280   static bool classof(const SrcValueSDNode *) { return true; }
1281   static bool classof(const SDNode *N) {
1282     return N->getOpcode() == ISD::SRCVALUE;
1283   }
1284 };
1285
1286
1287 class RegisterSDNode : public SDNode {
1288   unsigned Reg;
1289   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1290 protected:
1291   friend class SelectionDAG;
1292   RegisterSDNode(unsigned reg, MVT::ValueType VT)
1293     : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1294   }
1295 public:
1296
1297   unsigned getReg() const { return Reg; }
1298
1299   static bool classof(const RegisterSDNode *) { return true; }
1300   static bool classof(const SDNode *N) {
1301     return N->getOpcode() == ISD::Register;
1302   }
1303 };
1304
1305 class ExternalSymbolSDNode : public SDNode {
1306   const char *Symbol;
1307   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1308 protected:
1309   friend class SelectionDAG;
1310   ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1311     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1312              getSDVTList(VT)), Symbol(Sym) {
1313   }
1314 public:
1315
1316   const char *getSymbol() const { return Symbol; }
1317
1318   static bool classof(const ExternalSymbolSDNode *) { return true; }
1319   static bool classof(const SDNode *N) {
1320     return N->getOpcode() == ISD::ExternalSymbol ||
1321            N->getOpcode() == ISD::TargetExternalSymbol;
1322   }
1323 };
1324
1325 class CondCodeSDNode : public SDNode {
1326   ISD::CondCode Condition;
1327   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1328 protected:
1329   friend class SelectionDAG;
1330   explicit CondCodeSDNode(ISD::CondCode Cond)
1331     : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1332   }
1333 public:
1334
1335   ISD::CondCode get() const { return Condition; }
1336
1337   static bool classof(const CondCodeSDNode *) { return true; }
1338   static bool classof(const SDNode *N) {
1339     return N->getOpcode() == ISD::CONDCODE;
1340   }
1341 };
1342
1343 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1344 /// to parameterize some operations.
1345 class VTSDNode : public SDNode {
1346   MVT::ValueType ValueType;
1347   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1348 protected:
1349   friend class SelectionDAG;
1350   explicit VTSDNode(MVT::ValueType VT)
1351     : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1352   }
1353 public:
1354
1355   MVT::ValueType getVT() const { return ValueType; }
1356
1357   static bool classof(const VTSDNode *) { return true; }
1358   static bool classof(const SDNode *N) {
1359     return N->getOpcode() == ISD::VALUETYPE;
1360   }
1361 };
1362
1363 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1364 ///
1365 class LoadSDNode : public SDNode {
1366   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1367   SDOperand Ops[3];
1368   
1369   // AddrMode - unindexed, pre-indexed, post-indexed.
1370   ISD::MemIndexedMode AddrMode;
1371
1372   // ExtType - non-ext, anyext, sext, zext.
1373   ISD::LoadExtType ExtType;
1374
1375   // LoadedVT - VT of loaded value before extension.
1376   MVT::ValueType LoadedVT;
1377
1378   // SrcValue - Memory location for alias analysis.
1379   const Value *SrcValue;
1380
1381   // SVOffset - Memory location offset.
1382   int SVOffset;
1383
1384   // Alignment - Alignment of memory location in bytes.
1385   unsigned Alignment;
1386
1387   // IsVolatile - True if the load is volatile.
1388   bool IsVolatile;
1389 protected:
1390   friend class SelectionDAG;
1391   LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1392              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1393              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1394     : SDNode(ISD::LOAD, VTs),
1395       AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
1396       Alignment(Align), IsVolatile(Vol) {
1397     Ops[0] = ChainPtrOff[0]; // Chain
1398     Ops[1] = ChainPtrOff[1]; // Ptr
1399     Ops[2] = ChainPtrOff[2]; // Off
1400     InitOperands(Ops, 3);
1401     assert(Align != 0 && "Loads should have non-zero aligment");
1402     assert((getOffset().getOpcode() == ISD::UNDEF ||
1403             AddrMode != ISD::UNINDEXED) &&
1404            "Only indexed load has a non-undef offset operand");
1405   }
1406 public:
1407
1408   const SDOperand getChain() const { return getOperand(0); }
1409   const SDOperand getBasePtr() const { return getOperand(1); }
1410   const SDOperand getOffset() const { return getOperand(2); }
1411   ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1412   ISD::LoadExtType getExtensionType() const { return ExtType; }
1413   MVT::ValueType getLoadedVT() const { return LoadedVT; }
1414   const Value *getSrcValue() const { return SrcValue; }
1415   int getSrcValueOffset() const { return SVOffset; }
1416   unsigned getAlignment() const { return Alignment; }
1417   bool isVolatile() const { return IsVolatile; }
1418
1419   static bool classof(const LoadSDNode *) { return true; }
1420   static bool classof(const SDNode *N) {
1421     return N->getOpcode() == ISD::LOAD;
1422   }
1423 };
1424
1425 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1426 ///
1427 class StoreSDNode : public SDNode {
1428   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1429   SDOperand Ops[4];
1430     
1431   // AddrMode - unindexed, pre-indexed, post-indexed.
1432   ISD::MemIndexedMode AddrMode;
1433
1434   // IsTruncStore - True is the op does a truncation before store.
1435   bool IsTruncStore;
1436
1437   // StoredVT - VT of the value after truncation.
1438   MVT::ValueType StoredVT;
1439
1440   // SrcValue - Memory location for alias analysis.
1441   const Value *SrcValue;
1442
1443   // SVOffset - Memory location offset.
1444   int SVOffset;
1445
1446   // Alignment - Alignment of memory location in bytes.
1447   unsigned Alignment;
1448
1449   // IsVolatile - True if the store is volatile.
1450   bool IsVolatile;
1451 protected:
1452   friend class SelectionDAG;
1453   StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1454               ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1455               const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1456     : SDNode(ISD::STORE, VTs),
1457       AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT), SrcValue(SV),
1458       SVOffset(O), Alignment(Align), IsVolatile(Vol) {
1459     Ops[0] = ChainValuePtrOff[0]; // Chain
1460     Ops[1] = ChainValuePtrOff[1]; // Value
1461     Ops[2] = ChainValuePtrOff[2]; // Ptr
1462     Ops[3] = ChainValuePtrOff[3]; // Off
1463     InitOperands(Ops, 4);
1464     assert(Align != 0 && "Stores should have non-zero aligment");
1465     assert((getOffset().getOpcode() == ISD::UNDEF || 
1466             AddrMode != ISD::UNINDEXED) &&
1467            "Only indexed store has a non-undef offset operand");
1468   }
1469 public:
1470
1471   const SDOperand getChain() const { return getOperand(0); }
1472   const SDOperand getValue() const { return getOperand(1); }
1473   const SDOperand getBasePtr() const { return getOperand(2); }
1474   const SDOperand getOffset() const { return getOperand(3); }
1475   ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1476   bool isTruncatingStore() const { return IsTruncStore; }
1477   MVT::ValueType getStoredVT() const { return StoredVT; }
1478   const Value *getSrcValue() const { return SrcValue; }
1479   int getSrcValueOffset() const { return SVOffset; }
1480   unsigned getAlignment() const { return Alignment; }
1481   bool isVolatile() const { return IsVolatile; }
1482
1483   static bool classof(const StoreSDNode *) { return true; }
1484   static bool classof(const SDNode *N) {
1485     return N->getOpcode() == ISD::STORE;
1486   }
1487 };
1488
1489
1490 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1491   SDNode *Node;
1492   unsigned Operand;
1493
1494   SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1495 public:
1496   bool operator==(const SDNodeIterator& x) const {
1497     return Operand == x.Operand;
1498   }
1499   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1500
1501   const SDNodeIterator &operator=(const SDNodeIterator &I) {
1502     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1503     Operand = I.Operand;
1504     return *this;
1505   }
1506
1507   pointer operator*() const {
1508     return Node->getOperand(Operand).Val;
1509   }
1510   pointer operator->() const { return operator*(); }
1511
1512   SDNodeIterator& operator++() {                // Preincrement
1513     ++Operand;
1514     return *this;
1515   }
1516   SDNodeIterator operator++(int) { // Postincrement
1517     SDNodeIterator tmp = *this; ++*this; return tmp;
1518   }
1519
1520   static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1521   static SDNodeIterator end  (SDNode *N) {
1522     return SDNodeIterator(N, N->getNumOperands());
1523   }
1524
1525   unsigned getOperand() const { return Operand; }
1526   const SDNode *getNode() const { return Node; }
1527 };
1528
1529 template <> struct GraphTraits<SDNode*> {
1530   typedef SDNode NodeType;
1531   typedef SDNodeIterator ChildIteratorType;
1532   static inline NodeType *getEntryNode(SDNode *N) { return N; }
1533   static inline ChildIteratorType child_begin(NodeType *N) {
1534     return SDNodeIterator::begin(N);
1535   }
1536   static inline ChildIteratorType child_end(NodeType *N) {
1537     return SDNodeIterator::end(N);
1538   }
1539 };
1540
1541 template<>
1542 struct ilist_traits<SDNode> {
1543   static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1544   static SDNode *getNext(const SDNode *N) { return N->Next; }
1545   
1546   static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1547   static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1548   
1549   static SDNode *createSentinel() {
1550     return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1551   }
1552   static void destroySentinel(SDNode *N) { delete N; }
1553   //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1554   
1555   
1556   void addNodeToList(SDNode *NTy) {}
1557   void removeNodeFromList(SDNode *NTy) {}
1558   void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1559                              const ilist_iterator<SDNode> &X,
1560                              const ilist_iterator<SDNode> &Y) {}
1561 };
1562
1563 namespace ISD {
1564   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1565   /// load.
1566   inline bool isNON_EXTLoad(const SDNode *N) {
1567     return N->getOpcode() == ISD::LOAD &&
1568       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1569   }
1570
1571   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1572   ///
1573   inline bool isEXTLoad(const SDNode *N) {
1574     return N->getOpcode() == ISD::LOAD &&
1575       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1576   }
1577
1578   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1579   ///
1580   inline bool isSEXTLoad(const SDNode *N) {
1581     return N->getOpcode() == ISD::LOAD &&
1582       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1583   }
1584
1585   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1586   ///
1587   inline bool isZEXTLoad(const SDNode *N) {
1588     return N->getOpcode() == ISD::LOAD &&
1589       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1590   }
1591
1592   /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1593   ///
1594   inline bool isUNINDEXEDLoad(const SDNode *N) {
1595     return N->getOpcode() == ISD::LOAD &&
1596       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1597   }
1598
1599   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1600   /// store.
1601   inline bool isNON_TRUNCStore(const SDNode *N) {
1602     return N->getOpcode() == ISD::STORE &&
1603       !cast<StoreSDNode>(N)->isTruncatingStore();
1604   }
1605
1606   /// isTRUNCStore - Returns true if the specified node is a truncating
1607   /// store.
1608   inline bool isTRUNCStore(const SDNode *N) {
1609     return N->getOpcode() == ISD::STORE &&
1610       cast<StoreSDNode>(N)->isTruncatingStore();
1611   }
1612 }
1613
1614
1615 } // end llvm namespace
1616
1617 #endif