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