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