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