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