a1c1ec9f159249144cad46688749e8ef07d11ce7
[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 is distributed under the University of Illinois Open Source
6 // 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/ADT/APInt.h"
28 #include "llvm/CodeGen/ValueTypes.h"
29 #include "llvm/CodeGen/MachineMemOperand.h"
30 #include "llvm/Support/DataTypes.h"
31 #include <cassert>
32
33 namespace llvm {
34
35 class SelectionDAG;
36 class GlobalValue;
37 class MachineBasicBlock;
38 class MachineConstantPoolValue;
39 class SDNode;
40 template <typename T> struct DenseMapInfo;
41 template <typename T> struct simplify_type;
42 template <typename T> struct ilist_traits;
43 template<typename NodeTy, typename Traits> class iplist;
44 template<typename NodeTy> class ilist_iterator;
45
46 /// SDVTList - This represents a list of ValueType's that has been intern'd by
47 /// a SelectionDAG.  Instances of this simple value class are returned by
48 /// SelectionDAG::getVTList(...).
49 ///
50 struct SDVTList {
51   const MVT::ValueType *VTs;
52   unsigned short NumVTs;
53 };
54
55 /// ISD namespace - This namespace contains an enum which represents all of the
56 /// SelectionDAG node types and value types.
57 ///
58 namespace ISD {
59
60   //===--------------------------------------------------------------------===//
61   /// ISD::NodeType enum - This enum defines all of the operators valid in a
62   /// SelectionDAG.
63   ///
64   enum NodeType {
65     // DELETED_NODE - This is an illegal flag value that is used to catch
66     // errors.  This opcode is not a legal opcode for any node.
67     DELETED_NODE,
68     
69     // EntryToken - This is the marker used to indicate the start of the region.
70     EntryToken,
71
72     // Token factor - This node takes multiple tokens as input and produces a
73     // single token result.  This is used to represent the fact that the operand
74     // operators are independent of each other.
75     TokenFactor,
76     
77     // AssertSext, AssertZext - These nodes record if a register contains a 
78     // value that has already been zero or sign extended from a narrower type.  
79     // These nodes take two operands.  The first is the node that has already 
80     // been extended, and the second is a value type node indicating the width
81     // of the extension
82     AssertSext, AssertZext,
83
84     // Various leaf nodes.
85     STRING, BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
86     Constant, ConstantFP,
87     GlobalAddress, GlobalTLSAddress, FrameIndex,
88     JumpTable, ConstantPool, ExternalSymbol,
89
90     // The address of the GOT
91     GLOBAL_OFFSET_TABLE,
92     
93     // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
94     // llvm.returnaddress on the DAG.  These nodes take one operand, the index
95     // of the frame or return address to return.  An index of zero corresponds
96     // to the current function's frame or return address, an index of one to the
97     // parent's frame or return address, and so on.
98     FRAMEADDR, RETURNADDR,
99
100     // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
101     // first (possible) on-stack argument. This is needed for correct stack
102     // adjustment during unwind.
103     FRAME_TO_ARGS_OFFSET,
104     
105     // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
106     // address of the exception block on entry to an landing pad block.
107     EXCEPTIONADDR,
108     
109     // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
110     // the selection index of the exception thrown.
111     EHSELECTION,
112
113     // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
114     // 'eh_return' gcc dwarf builtin, which is used to return from
115     // exception. The general meaning is: adjust stack by OFFSET and pass
116     // execution to HANDLER. Many platform-related details also :)
117     EH_RETURN,
118
119     // TargetConstant* - Like Constant*, but the DAG does not do any folding or
120     // simplification of the constant.
121     TargetConstant,
122     TargetConstantFP,
123     
124     // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
125     // anything else with this node, and this is valid in the target-specific
126     // dag, turning into a GlobalAddress operand.
127     TargetGlobalAddress,
128     TargetGlobalTLSAddress,
129     TargetFrameIndex,
130     TargetJumpTable,
131     TargetConstantPool,
132     TargetExternalSymbol,
133     
134     /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
135     /// This node represents a target intrinsic function with no side effects.
136     /// The first operand is the ID number of the intrinsic from the
137     /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
138     /// node has returns the result of the intrinsic.
139     INTRINSIC_WO_CHAIN,
140     
141     /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
142     /// This node represents a target intrinsic function with side effects that
143     /// returns a result.  The first operand is a chain pointer.  The second is
144     /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
145     /// operands to the intrinsic follow.  The node has two results, the result
146     /// of the intrinsic and an output chain.
147     INTRINSIC_W_CHAIN,
148
149     /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
150     /// This node represents a target intrinsic function with side effects that
151     /// does not return a result.  The first operand is a chain pointer.  The
152     /// second is the ID number of the intrinsic from the llvm::Intrinsic
153     /// namespace.  The operands to the intrinsic follow.
154     INTRINSIC_VOID,
155     
156     // CopyToReg - This node has three operands: a chain, a register number to
157     // set to this value, and a value.  
158     CopyToReg,
159
160     // CopyFromReg - This node indicates that the input value is a virtual or
161     // physical register that is defined outside of the scope of this
162     // SelectionDAG.  The register is available from the RegisterSDNode object.
163     CopyFromReg,
164
165     // UNDEF - An undefined node
166     UNDEF,
167     
168     /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
169     /// represents the formal arguments for a function.  CC# is a Constant value
170     /// indicating the calling convention of the function, and ISVARARG is a
171     /// flag that indicates whether the function is varargs or not. This node
172     /// has one result value for each incoming argument, plus one for the output
173     /// chain. It must be custom legalized. See description of CALL node for
174     /// FLAG argument contents explanation.
175     /// 
176     FORMAL_ARGUMENTS,
177     
178     /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
179     ///                              ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
180     /// This node represents a fully general function call, before the legalizer
181     /// runs.  This has one result value for each argument / flag pair, plus
182     /// a chain result. It must be custom legalized. Flag argument indicates
183     /// misc. argument attributes. Currently:
184     /// Bit 0 - signness
185     /// Bit 1 - 'inreg' attribute
186     /// Bit 2 - 'sret' attribute
187     /// Bit 4 - 'byval' attribute
188     /// Bit 5 - 'nest' attribute
189     /// Bit 6-9 - alignment of byval structures
190     /// Bit 10-26 - size of byval structures
191     /// Bits 31:27 - argument ABI alignment in the first argument piece and
192     /// alignment '1' in other argument pieces.
193     CALL,
194
195     // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
196     // a Constant, which is required to be operand #1) half of the integer value
197     // specified as operand #0.  This is only for use before legalization, for
198     // values that will be broken into multiple registers.
199     EXTRACT_ELEMENT,
200
201     // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
202     // two values of the same integer value type, this produces a value twice as
203     // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
204     BUILD_PAIR,
205     
206     // MERGE_VALUES - This node takes multiple discrete operands and returns
207     // them all as its individual results.  This nodes has exactly the same
208     // number of inputs and outputs, and is only valid before legalization.
209     // This node is useful for some pieces of the code generator that want to
210     // think about a single node with multiple results, not multiple nodes.
211     MERGE_VALUES,
212
213     // Simple integer binary arithmetic operators.
214     ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
215
216     // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
217     // a signed/unsigned value of type i[2*N], and return the full value as
218     // two results, each of type iN.
219     SMUL_LOHI, UMUL_LOHI,
220
221     // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
222     // remainder result.
223     SDIVREM, UDIVREM,
224     
225     // CARRY_FALSE - This node is used when folding other nodes,
226     // like ADDC/SUBC, which indicate the carry result is always false.
227     CARRY_FALSE,
228     
229     // Carry-setting nodes for multiple precision addition and subtraction.
230     // These nodes take two operands of the same value type, and produce two
231     // results.  The first result is the normal add or sub result, the second
232     // result is the carry flag result.
233     ADDC, SUBC,
234     
235     // Carry-using nodes for multiple precision addition and subtraction.  These
236     // nodes take three operands: The first two are the normal lhs and rhs to
237     // the add or sub, and the third is the input carry flag.  These nodes
238     // produce two results; the normal result of the add or sub, and the output
239     // carry flag.  These nodes both read and write a carry flag to allow them
240     // to them to be chained together for add and sub of arbitrarily large
241     // values.
242     ADDE, SUBE,
243     
244     // Simple binary floating point operators.
245     FADD, FSUB, FMUL, FDIV, FREM,
246
247     // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
248     // DAG node does not require that X and Y have the same type, just that they
249     // are both floating point.  X and the result must have the same type.
250     // FCOPYSIGN(f32, f64) is allowed.
251     FCOPYSIGN,
252
253     // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
254     // value as an integer 0/1 value.
255     FGETSIGN,
256     
257     /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
258     /// with the specified, possibly variable, elements.  The number of elements
259     /// is required to be a power of two.
260     BUILD_VECTOR,
261     
262     /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
263     /// at IDX replaced with VAL.  If the type of VAL is larger than the vector
264     /// element type then VAL is truncated before replacement.
265     INSERT_VECTOR_ELT,
266
267     /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
268     /// identified by the (potentially variable) element number IDX.
269     EXTRACT_VECTOR_ELT,
270     
271     /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
272     /// vector type with the same length and element type, this produces a
273     /// concatenated vector result value, with length equal to the sum of the
274     /// lengths of the input vectors.
275     CONCAT_VECTORS,
276     
277     /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
278     /// vector value) starting with the (potentially variable) element number
279     /// IDX, which must be a multiple of the result vector length.
280     EXTRACT_SUBVECTOR,
281
282     /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
283     /// type as VEC1/VEC2.  SHUFFLEVEC is a BUILD_VECTOR of constant int values
284     /// (maybe of an illegal datatype) or undef that indicate which value each
285     /// result element will get.  The elements of VEC1/VEC2 are enumerated in
286     /// order.  This is quite similar to the Altivec 'vperm' instruction, except
287     /// that the indices must be constants and are in terms of the element size
288     /// of VEC1/VEC2, not in terms of bytes.
289     VECTOR_SHUFFLE,
290
291     /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
292     /// scalar value into element 0 of the resultant vector type.  The top
293     /// elements 1 to N-1 of the N-element vector are undefined.
294     SCALAR_TO_VECTOR,
295     
296     // EXTRACT_SUBREG - This node is used to extract a sub-register value. 
297     // This node takes a superreg and a constant sub-register index as operands.
298     // Note sub-register indices must be increasing. That is, if the
299     // sub-register index of a 8-bit sub-register is N, then the index for a
300     // 16-bit sub-register must be at least N+1.
301     EXTRACT_SUBREG,
302     
303     // INSERT_SUBREG - This node is used to insert a sub-register value. 
304     // This node takes a superreg, a subreg value, and a constant sub-register
305     // index as operands.
306     INSERT_SUBREG,
307     
308     // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
309     // an unsigned/signed value of type i[2*N], then return the top part.
310     MULHU, MULHS,
311
312     // Bitwise operators - logical and, logical or, logical xor, shift left,
313     // shift right algebraic (shift in sign bits), shift right logical (shift in
314     // zeroes), rotate left, rotate right, and byteswap.
315     AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
316
317     // Counting operators
318     CTTZ, CTLZ, CTPOP,
319
320     // Select(COND, TRUEVAL, FALSEVAL)
321     SELECT, 
322     
323     // Select with condition operator - This selects between a true value and 
324     // a false value (ops #2 and #3) based on the boolean result of comparing
325     // the lhs and rhs (ops #0 and #1) of a conditional expression with the 
326     // condition code in op #4, a CondCodeSDNode.
327     SELECT_CC,
328
329     // SetCC operator - This evaluates to a boolean (i1) true value if the
330     // condition is true.  The operands to this are the left and right operands
331     // to compare (ops #0, and #1) and the condition code to compare them with
332     // (op #2) as a CondCodeSDNode.
333     SETCC,
334
335     // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
336     // integer shift operations, just like ADD/SUB_PARTS.  The operation
337     // ordering is:
338     //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
339     SHL_PARTS, SRA_PARTS, SRL_PARTS,
340
341     // Conversion operators.  These are all single input single output
342     // operations.  For all of these, the result type must be strictly
343     // wider or narrower (depending on the operation) than the source
344     // type.
345
346     // SIGN_EXTEND - Used for integer types, replicating the sign bit
347     // into new bits.
348     SIGN_EXTEND,
349
350     // ZERO_EXTEND - Used for integer types, zeroing the new bits.
351     ZERO_EXTEND,
352
353     // ANY_EXTEND - Used for integer types.  The high bits are undefined.
354     ANY_EXTEND,
355     
356     // TRUNCATE - Completely drop the high bits.
357     TRUNCATE,
358
359     // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
360     // depends on the first letter) to floating point.
361     SINT_TO_FP,
362     UINT_TO_FP,
363
364     // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
365     // sign extend a small value in a large integer register (e.g. sign
366     // extending the low 8 bits of a 32-bit register to fill the top 24 bits
367     // with the 7th bit).  The size of the smaller type is indicated by the 1th
368     // operand, a ValueType node.
369     SIGN_EXTEND_INREG,
370
371     /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
372     /// integer.
373     FP_TO_SINT,
374     FP_TO_UINT,
375
376     /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
377     /// down to the precision of the destination VT.  TRUNC is a flag, which is
378     /// always an integer that is zero or one.  If TRUNC is 0, this is a
379     /// normal rounding, if it is 1, this FP_ROUND is known to not change the
380     /// value of Y.
381     ///
382     /// The TRUNC = 1 case is used in cases where we know that the value will
383     /// not be modified by the node, because Y is not using any of the extra
384     /// precision of source type.  This allows certain transformations like
385     /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for 
386     /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
387     FP_ROUND,
388     
389     // FLT_ROUNDS_ - Returns current rounding mode:
390     // -1 Undefined
391     //  0 Round to 0
392     //  1 Round to nearest
393     //  2 Round to +inf
394     //  3 Round to -inf
395     FLT_ROUNDS_,
396
397     /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
398     /// rounds it to a floating point value.  It then promotes it and returns it
399     /// in a register of the same size.  This operation effectively just
400     /// discards excess precision.  The type to round down to is specified by
401     /// the VT operand, a VTSDNode.
402     FP_ROUND_INREG,
403
404     /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
405     FP_EXTEND,
406
407     // BIT_CONVERT - Theis operator converts between integer and FP values, as
408     // if one was stored to memory as integer and the other was loaded from the
409     // same address (or equivalently for vector format conversions, etc).  The 
410     // source and result are required to have the same bit size (e.g. 
411     // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp 
412     // conversions, but that is a noop, deleted by getNode().
413     BIT_CONVERT,
414     
415     // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
416     // negation, absolute value, square root, sine and cosine, powi, and pow
417     // operations.
418     FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
419     
420     // LOAD and STORE have token chains as their first operand, then the same
421     // operands as an LLVM load/store instruction, then an offset node that
422     // is added / subtracted from the base pointer to form the address (for
423     // indexed memory ops).
424     LOAD, STORE,
425
426     // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
427     // to a specified boundary.  This node always has two return values: a new
428     // stack pointer value and a chain. The first operand is the token chain,
429     // the second is the number of bytes to allocate, and the third is the
430     // alignment boundary.  The size is guaranteed to be a multiple of the stack
431     // alignment, and the alignment is guaranteed to be bigger than the stack
432     // alignment (if required) or 0 to get standard stack alignment.
433     DYNAMIC_STACKALLOC,
434
435     // Control flow instructions.  These all have token chains.
436
437     // BR - Unconditional branch.  The first operand is the chain
438     // operand, the second is the MBB to branch to.
439     BR,
440
441     // BRIND - Indirect branch.  The first operand is the chain, the second
442     // is the value to branch to, which must be of the same type as the target's
443     // pointer type.
444     BRIND,
445
446     // BR_JT - Jumptable branch. The first operand is the chain, the second
447     // is the jumptable index, the last one is the jumptable entry index.
448     BR_JT,
449     
450     // BRCOND - Conditional branch.  The first operand is the chain,
451     // the second is the condition, the third is the block to branch
452     // to if the condition is true.
453     BRCOND,
454
455     // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
456     // that the condition is represented as condition code, and two nodes to
457     // compare, rather than as a combined SetCC node.  The operands in order are
458     // chain, cc, lhs, rhs, block to branch to if condition is true.
459     BR_CC,
460     
461     // RET - Return from function.  The first operand is the chain,
462     // and any subsequent operands are pairs of return value and return value
463     // signness for the function.  This operation can have variable number of
464     // operands.
465     RET,
466
467     // INLINEASM - Represents an inline asm block.  This node always has two
468     // return values: a chain and a flag result.  The inputs are as follows:
469     //   Operand #0   : Input chain.
470     //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
471     //   Operand #2n+2: A RegisterNode.
472     //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
473     //   Operand #last: Optional, an incoming flag.
474     INLINEASM,
475     
476     // LABEL - Represents a label in mid basic block used to track
477     // locations needed for debug and exception handling tables.  This node
478     // returns a chain.
479     //   Operand #0 : input chain.
480     //   Operand #1 : module unique number use to identify the label.
481     //   Operand #2 : 0 indicates a debug label (e.g. stoppoint), 1 indicates
482     //                a EH label, 2 indicates unknown label type.
483     LABEL,
484
485     // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
486     // local variable declarations for debugging information. First operand is
487     // a chain, while the next two operands are first two arguments (address
488     // and variable) of a llvm.dbg.declare instruction.
489     DECLARE,
490     
491     // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
492     // value, the same type as the pointer type for the system, and an output
493     // chain.
494     STACKSAVE,
495     
496     // STACKRESTORE has two operands, an input chain and a pointer to restore to
497     // it returns an output chain.
498     STACKRESTORE,
499     
500     // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
501     // a call sequence, and carry arbitrary information that target might want
502     // to know.  The first operand is a chain, the rest are specified by the
503     // target and not touched by the DAG optimizers.
504     // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
505     CALLSEQ_START,  // Beginning of a call sequence
506     CALLSEQ_END,    // End of a call sequence
507     
508     // VAARG - VAARG has three operands: an input chain, a pointer, and a 
509     // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
510     VAARG,
511     
512     // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
513     // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
514     // source.
515     VACOPY,
516     
517     // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
518     // pointer, and a SRCVALUE.
519     VAEND, VASTART,
520
521     // SRCVALUE - This is a node type that holds a Value* that is used to
522     // make reference to a value in the LLVM IR.
523     SRCVALUE,
524
525     // MEMOPERAND - This is a node that contains a MachineMemOperand which
526     // records information about a memory reference. This is used to make
527     // AliasAnalysis queries from the backend.
528     MEMOPERAND,
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     // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
555     // It takes as input a token chain, the pointer to the trampoline,
556     // the pointer to the nested function, the pointer to pass for the
557     // 'nest' parameter, a SRCVALUE for the trampoline and another for
558     // the nested function (allowing targets to access the original
559     // Function*).  It produces the result of the intrinsic and a token
560     // chain as output.
561     TRAMPOLINE,
562
563     // TRAP - Trapping instruction
564     TRAP,
565
566     // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
567     // their first operand. The other operands are the address to prefetch,
568     // read / write specifier, and locality specifier.
569     PREFETCH,
570
571     // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load, 
572     //                       store-store, device)
573     // This corresponds to the memory.barrier intrinsic.
574     // it takes an input chain, 4 operands to specify the type of barrier, an
575     // operand specifying if the barrier applies to device and uncached memory
576     // and produces an output chain.
577     MEMBARRIER,
578
579     // Val, OUTCHAIN = ATOMIC_LCS(INCHAIN, ptr, cmp, swap)
580     // this corresponds to the atomic.lcs intrinsic.
581     // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
582     // the return is always the original value in *ptr
583     ATOMIC_LCS,
584
585     // Val, OUTCHAIN = ATOMIC_LAS(INCHAIN, ptr, amt)
586     // this corresponds to the atomic.las intrinsic.
587     // *ptr + amt is stored to *ptr atomically.
588     // the return is always the original value in *ptr
589     ATOMIC_LAS,
590
591     // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
592     // this corresponds to the atomic.swap intrinsic.
593     // amt is stored to *ptr atomically.
594     // the return is always the original value in *ptr
595     ATOMIC_SWAP,
596
597     // BUILTIN_OP_END - This must be the last enum value in this list.
598     BUILTIN_OP_END
599   };
600
601   /// Node predicates
602
603   /// isBuildVectorAllOnes - Return true if the specified node is a
604   /// BUILD_VECTOR where all of the elements are ~0 or undef.
605   bool isBuildVectorAllOnes(const SDNode *N);
606
607   /// isBuildVectorAllZeros - Return true if the specified node is a
608   /// BUILD_VECTOR where all of the elements are 0 or undef.
609   bool isBuildVectorAllZeros(const SDNode *N);
610
611   /// isScalarToVector - Return true if the specified node is a
612   /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
613   /// element is not an undef.
614   bool isScalarToVector(const SDNode *N);
615
616   /// isDebugLabel - Return true if the specified node represents a debug
617   /// label (i.e. ISD::LABEL or TargetInstrInfo::LABEL node and third operand
618   /// is 0).
619   bool isDebugLabel(const SDNode *N);
620   
621   //===--------------------------------------------------------------------===//
622   /// MemIndexedMode enum - This enum defines the load / store indexed 
623   /// addressing modes.
624   ///
625   /// UNINDEXED    "Normal" load / store. The effective address is already
626   ///              computed and is available in the base pointer. The offset
627   ///              operand is always undefined. In addition to producing a
628   ///              chain, an unindexed load produces one value (result of the
629   ///              load); an unindexed store does not produce a value.
630   ///
631   /// PRE_INC      Similar to the unindexed mode where the effective address is
632   /// PRE_DEC      the value of the base pointer add / subtract the offset.
633   ///              It considers the computation as being folded into the load /
634   ///              store operation (i.e. the load / store does the address
635   ///              computation as well as performing the memory transaction).
636   ///              The base operand is always undefined. In addition to
637   ///              producing a chain, pre-indexed load produces two values
638   ///              (result of the load and the result of the address
639   ///              computation); a pre-indexed store produces one value (result
640   ///              of the address computation).
641   ///
642   /// POST_INC     The effective address is the value of the base pointer. The
643   /// POST_DEC     value of the offset operand is then added to / subtracted
644   ///              from the base after memory transaction. In addition to
645   ///              producing a chain, post-indexed load produces two values
646   ///              (the result of the load and the result of the base +/- offset
647   ///              computation); a post-indexed store produces one value (the
648   ///              the result of the base +/- offset computation).
649   ///
650   enum MemIndexedMode {
651     UNINDEXED = 0,
652     PRE_INC,
653     PRE_DEC,
654     POST_INC,
655     POST_DEC,
656     LAST_INDEXED_MODE
657   };
658
659   //===--------------------------------------------------------------------===//
660   /// LoadExtType enum - This enum defines the three variants of LOADEXT
661   /// (load with extension).
662   ///
663   /// SEXTLOAD loads the integer operand and sign extends it to a larger
664   ///          integer result type.
665   /// ZEXTLOAD loads the integer operand and zero extends it to a larger
666   ///          integer result type.
667   /// EXTLOAD  is used for three things: floating point extending loads, 
668   ///          integer extending loads [the top bits are undefined], and vector
669   ///          extending loads [load into low elt].
670   ///
671   enum LoadExtType {
672     NON_EXTLOAD = 0,
673     EXTLOAD,
674     SEXTLOAD,
675     ZEXTLOAD,
676     LAST_LOADX_TYPE
677   };
678
679   //===--------------------------------------------------------------------===//
680   /// ISD::CondCode enum - These are ordered carefully to make the bitfields
681   /// below work out, when considering SETFALSE (something that never exists
682   /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
683   /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
684   /// to.  If the "N" column is 1, the result of the comparison is undefined if
685   /// the input is a NAN.
686   ///
687   /// All of these (except for the 'always folded ops') should be handled for
688   /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
689   /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
690   ///
691   /// Note that these are laid out in a specific order to allow bit-twiddling
692   /// to transform conditions.
693   enum CondCode {
694     // Opcode          N U L G E       Intuitive operation
695     SETFALSE,      //    0 0 0 0       Always false (always folded)
696     SETOEQ,        //    0 0 0 1       True if ordered and equal
697     SETOGT,        //    0 0 1 0       True if ordered and greater than
698     SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
699     SETOLT,        //    0 1 0 0       True if ordered and less than
700     SETOLE,        //    0 1 0 1       True if ordered and less than or equal
701     SETONE,        //    0 1 1 0       True if ordered and operands are unequal
702     SETO,          //    0 1 1 1       True if ordered (no nans)
703     SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
704     SETUEQ,        //    1 0 0 1       True if unordered or equal
705     SETUGT,        //    1 0 1 0       True if unordered or greater than
706     SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
707     SETULT,        //    1 1 0 0       True if unordered or less than
708     SETULE,        //    1 1 0 1       True if unordered, less than, or equal
709     SETUNE,        //    1 1 1 0       True if unordered or not equal
710     SETTRUE,       //    1 1 1 1       Always true (always folded)
711     // Don't care operations: undefined if the input is a nan.
712     SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
713     SETEQ,         //  1 X 0 0 1       True if equal
714     SETGT,         //  1 X 0 1 0       True if greater than
715     SETGE,         //  1 X 0 1 1       True if greater than or equal
716     SETLT,         //  1 X 1 0 0       True if less than
717     SETLE,         //  1 X 1 0 1       True if less than or equal
718     SETNE,         //  1 X 1 1 0       True if not equal
719     SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
720
721     SETCC_INVALID       // Marker value.
722   };
723
724   /// isSignedIntSetCC - Return true if this is a setcc instruction that
725   /// performs a signed comparison when used with integer operands.
726   inline bool isSignedIntSetCC(CondCode Code) {
727     return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
728   }
729
730   /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
731   /// performs an unsigned comparison when used with integer operands.
732   inline bool isUnsignedIntSetCC(CondCode Code) {
733     return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
734   }
735
736   /// isTrueWhenEqual - Return true if the specified condition returns true if
737   /// the two operands to the condition are equal.  Note that if one of the two
738   /// operands is a NaN, this value is meaningless.
739   inline bool isTrueWhenEqual(CondCode Cond) {
740     return ((int)Cond & 1) != 0;
741   }
742
743   /// getUnorderedFlavor - This function returns 0 if the condition is always
744   /// false if an operand is a NaN, 1 if the condition is always true if the
745   /// operand is a NaN, and 2 if the condition is undefined if the operand is a
746   /// NaN.
747   inline unsigned getUnorderedFlavor(CondCode Cond) {
748     return ((int)Cond >> 3) & 3;
749   }
750
751   /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
752   /// 'op' is a valid SetCC operation.
753   CondCode getSetCCInverse(CondCode Operation, bool isInteger);
754
755   /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
756   /// when given the operation for (X op Y).
757   CondCode getSetCCSwappedOperands(CondCode Operation);
758
759   /// getSetCCOrOperation - Return the result of a logical OR between different
760   /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
761   /// function returns SETCC_INVALID if it is not possible to represent the
762   /// resultant comparison.
763   CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
764
765   /// getSetCCAndOperation - Return the result of a logical AND between
766   /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
767   /// function returns SETCC_INVALID if it is not possible to represent the
768   /// resultant comparison.
769   CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
770 }  // end llvm::ISD namespace
771
772
773 //===----------------------------------------------------------------------===//
774 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
775 /// values as the result of a computation.  Many nodes return multiple values,
776 /// from loads (which define a token and a return value) to ADDC (which returns
777 /// a result and a carry value), to calls (which may return an arbitrary number
778 /// of values).
779 ///
780 /// As such, each use of a SelectionDAG computation must indicate the node that
781 /// computes it as well as which return value to use from that node.  This pair
782 /// of information is represented with the SDOperand value type.
783 ///
784 class SDOperand {
785 public:
786   SDNode *Val;        // The node defining the value we are using.
787   unsigned ResNo;     // Which return value of the node we are using.
788
789   SDOperand() : Val(0), ResNo(0) {}
790   SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
791
792   bool operator==(const SDOperand &O) const {
793     return Val == O.Val && ResNo == O.ResNo;
794   }
795   bool operator!=(const SDOperand &O) const {
796     return !operator==(O);
797   }
798   bool operator<(const SDOperand &O) const {
799     return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
800   }
801
802   SDOperand getValue(unsigned R) const {
803     return SDOperand(Val, R);
804   }
805
806   // isOperandOf - Return true if this node is an operand of N.
807   bool isOperandOf(SDNode *N) const;
808
809   /// getValueType - Return the ValueType of the referenced return value.
810   ///
811   inline MVT::ValueType getValueType() const;
812
813   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType()).
814   ///
815   unsigned getValueSizeInBits() const {
816     return MVT::getSizeInBits(getValueType());
817   }
818
819   // Forwarding methods - These forward to the corresponding methods in SDNode.
820   inline unsigned getOpcode() const;
821   inline unsigned getNumOperands() const;
822   inline const SDOperand &getOperand(unsigned i) const;
823   inline uint64_t getConstantOperandVal(unsigned i) const;
824   inline bool isTargetOpcode() const;
825   inline unsigned getTargetOpcode() const;
826
827   
828   /// reachesChainWithoutSideEffects - Return true if this operand (which must
829   /// be a chain) reaches the specified operand without crossing any 
830   /// side-effecting instructions.  In practice, this looks through token
831   /// factors and non-volatile loads.  In order to remain efficient, this only
832   /// looks a couple of nodes in, it does not do an exhaustive search.
833   bool reachesChainWithoutSideEffects(SDOperand Dest, 
834                                       unsigned Depth = 2) const;
835   
836   /// hasOneUse - Return true if there is exactly one operation using this
837   /// result value of the defining operator.
838   inline bool hasOneUse() const;
839
840   /// use_empty - Return true if there are no operations using this
841   /// result value of the defining operator.
842   inline bool use_empty() const;
843 };
844
845
846 template<> struct DenseMapInfo<SDOperand> {
847   static inline SDOperand getEmptyKey() { 
848     return SDOperand((SDNode*)-1, -1U); 
849   }
850   static inline SDOperand getTombstoneKey() { 
851     return SDOperand((SDNode*)-1, 0);
852   }
853   static unsigned getHashValue(const SDOperand &Val) {
854     return ((unsigned)((uintptr_t)Val.Val >> 4) ^
855             (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo;
856   }
857   static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
858     return LHS == RHS;
859   }
860   static bool isPod() { return true; }
861 };
862
863 /// simplify_type specializations - Allow casting operators to work directly on
864 /// SDOperands as if they were SDNode*'s.
865 template<> struct simplify_type<SDOperand> {
866   typedef SDNode* SimpleType;
867   static SimpleType getSimplifiedValue(const SDOperand &Val) {
868     return static_cast<SimpleType>(Val.Val);
869   }
870 };
871 template<> struct simplify_type<const SDOperand> {
872   typedef SDNode* SimpleType;
873   static SimpleType getSimplifiedValue(const SDOperand &Val) {
874     return static_cast<SimpleType>(Val.Val);
875   }
876 };
877
878 /// SDUse - Represents a use of the SDNode referred by
879 /// the SDOperand.
880 class SDUse {
881   SDOperand Operand;
882   /// User - Parent node of this operand.
883   SDNode    *User;
884   /// Prev, next - Pointers to the uses list of the SDNode referred by 
885   /// this operand.
886   SDUse **Prev, *Next;
887 public:
888   friend class SDNode;
889   SDUse(): Operand(), User(NULL), Prev(NULL), Next(NULL) {}
890
891   SDUse(SDNode *val, unsigned resno) : 
892     Operand(val,resno), User(NULL), Prev(NULL), Next(NULL) {}
893
894   SDUse& operator= (const SDOperand& Op) {
895       Operand = Op;
896       Next = NULL;
897       Prev = NULL;
898       return *this;
899   }
900
901   SDUse& operator= (const SDUse& Op) {
902       Operand = Op;
903       Next = NULL;
904       Prev = NULL;
905       return *this;
906   }
907
908   SDUse * getNext() { return Next; }
909
910   SDNode *getUser() { return User; }
911
912   void setUser(SDNode *p) { User = p; }
913
914   operator SDOperand() const { return Operand; }
915
916   const SDOperand& getSDOperand() const { return Operand; }
917
918   SDNode* &getVal () { return Operand.Val; }
919
920   bool operator==(const SDOperand &O) const {
921     return Operand == O;
922   }
923
924   bool operator!=(const SDOperand &O) const {
925     return !(Operand == O);
926   }
927
928   bool operator<(const SDOperand &O) const {
929     return Operand < O;
930   }
931
932 protected:
933   void addToList(SDUse **List) {
934     Next = *List;
935     if (Next) Next->Prev = &Next;
936     Prev = List;
937     *List = this;
938   }
939
940   void removeFromList() {
941     *Prev = Next;
942     if (Next) Next->Prev = Prev;
943   }
944 };
945
946
947 /// simplify_type specializations - Allow casting operators to work directly on
948 /// SDOperands as if they were SDNode*'s.
949 template<> struct simplify_type<SDUse> {
950   typedef SDNode* SimpleType;
951   static SimpleType getSimplifiedValue(const SDUse &Val) {
952     return static_cast<SimpleType>(Val.getSDOperand().Val);
953   }
954 };
955 template<> struct simplify_type<const SDUse> {
956   typedef SDNode* SimpleType;
957   static SimpleType getSimplifiedValue(const SDUse &Val) {
958     return static_cast<SimpleType>(Val.getSDOperand().Val);
959   }
960 };
961
962
963 /// SDOperandPtr - A helper SDOperand pointer class, that can handle
964 /// arrays of SDUse and arrays of SDOperand objects. This is required
965 /// in many places inside the SelectionDAG.
966 /// 
967 class SDOperandPtr {
968   const SDOperand *ptr; // The pointer to the SDOperand object
969   int object_size;      // The size of the object containg the SDOperand
970 public:
971   SDOperandPtr(SDUse * use_ptr) { 
972     ptr = &use_ptr->getSDOperand(); 
973     object_size = sizeof(SDUse); 
974   }
975
976   SDOperandPtr(const SDOperand * op_ptr) { 
977     ptr = op_ptr; 
978     object_size = sizeof(SDOperand); 
979   }
980
981   operator const SDOperand *() const {
982     assert(object_size == sizeof(SDOperand) && 
983            "Only SDOperand can be converted");
984     return ptr;
985   }
986
987   const SDOperand operator *() { return *ptr; }
988   const SDOperand *operator ->() { return ptr; }
989   SDOperandPtr operator ++ () { 
990     ptr = (SDOperand*)((char *)ptr + object_size); 
991     return *this; 
992   }
993
994   SDOperandPtr operator ++ (int) { 
995     SDOperandPtr tmp = *this;
996     ptr = (SDOperand*)((char *)ptr + object_size); 
997     return tmp; 
998   }
999
1000   SDOperand operator[] (int idx) const {
1001     return *(SDOperand*)((char*) ptr + object_size * idx);
1002   } 
1003 };
1004
1005 /// SDNode - Represents one node in the SelectionDAG.
1006 ///
1007 class SDNode : public FoldingSetNode {
1008 private:
1009   /// NodeType - The operation that this node performs.
1010   ///
1011   unsigned short NodeType;
1012   
1013   /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
1014   /// then they will be delete[]'d when the node is destroyed.
1015   bool OperandsNeedDelete : 1;
1016
1017   /// NodeId - Unique id per SDNode in the DAG.
1018   int NodeId;
1019
1020   /// OperandList - The values that are used by this operation.
1021   ///
1022   SDUse *OperandList;
1023   
1024   /// ValueList - The types of the values this node defines.  SDNode's may
1025   /// define multiple values simultaneously.
1026   const MVT::ValueType *ValueList;
1027
1028   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1029   unsigned short NumOperands, NumValues;
1030   
1031   /// Prev/Next pointers - These pointers form the linked list of of the
1032   /// AllNodes list in the current DAG.
1033   SDNode *Prev, *Next;
1034   friend struct ilist_traits<SDNode>;
1035
1036   /// UsesSize - The size of the uses list.
1037   unsigned UsesSize;
1038
1039   /// Uses - List of uses for this SDNode.
1040   SDUse *Uses;
1041
1042   /// addUse - add SDUse to the list of uses.
1043   void addUse(SDUse &U) { U.addToList(&Uses); }
1044
1045   // Out-of-line virtual method to give class a home.
1046   virtual void ANCHOR();
1047 public:
1048   virtual ~SDNode() {
1049     assert(NumOperands == 0 && "Operand list not cleared before deletion");
1050     NodeType = ISD::DELETED_NODE;
1051   }
1052   
1053   //===--------------------------------------------------------------------===//
1054   //  Accessors
1055   //
1056   unsigned getOpcode()  const { return NodeType; }
1057   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
1058   unsigned getTargetOpcode() const {
1059     assert(isTargetOpcode() && "Not a target opcode!");
1060     return NodeType - ISD::BUILTIN_OP_END;
1061   }
1062
1063   size_t use_size() const { return UsesSize; }
1064   bool use_empty() const { return Uses == NULL; }
1065   bool hasOneUse() const { return use_size() == 1; }
1066
1067   /// getNodeId - Return the unique node id.
1068   ///
1069   int getNodeId() const { return NodeId; }
1070
1071   /// setNodeId - Set unique node id.
1072   void setNodeId(int Id) { NodeId = Id; }
1073
1074   /// use_iterator - This class provides iterator support for SDUse
1075   /// operands that use a specific SDNode. 
1076   class use_iterator
1077     : public forward_iterator<SDUse, ptrdiff_t> {
1078     SDUse *Op;
1079     explicit use_iterator(SDUse *op) : Op(op) {
1080     }
1081     friend class SDNode;
1082   public:
1083     typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
1084     typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1085
1086     use_iterator(const use_iterator &I) : Op(I.Op) {}
1087     use_iterator() : Op(0) {}
1088
1089     bool operator==(const use_iterator &x) const {
1090       return Op == x.Op;
1091     }
1092     bool operator!=(const use_iterator &x) const {
1093       return !operator==(x);
1094     }
1095  
1096     /// atEnd - return true if this iterator is at the end of uses list.
1097     bool atEnd() const { return Op == 0; }
1098
1099     // Iterator traversal: forward iteration only.
1100     use_iterator &operator++() {          // Preincrement
1101       assert(Op && "Cannot increment end iterator!");
1102       Op = Op->getNext();
1103       return *this;
1104     }
1105
1106     use_iterator operator++(int) {        // Postincrement
1107       use_iterator tmp = *this; ++*this; return tmp;
1108     }
1109
1110
1111     /// getOperandNum - Retrive a number of a current operand.
1112     unsigned getOperandNum() const {
1113       assert(Op && "Cannot dereference end iterator!");
1114       return (Op - Op->getUser()->OperandList);
1115     }
1116
1117     /// Retrieve a reference to the current operand.
1118     SDUse &operator*() const {
1119       assert(Op && "Cannot dereference end iterator!");
1120       return *Op;
1121     }
1122
1123     /// Retrieve a pointer to the current operand.
1124     SDUse *operator->() const {
1125       assert(Op && "Cannot dereference end iterator!");
1126       return Op;
1127     }
1128   };
1129
1130   /// use_begin/use_end - Provide iteration support to walk over all uses
1131   /// of an SDNode.
1132
1133   use_iterator use_begin(SDNode *node) const {
1134     return use_iterator(node->Uses);
1135   }
1136
1137   use_iterator use_begin() const {
1138     return use_iterator(Uses);
1139   }
1140
1141   static use_iterator use_end() { return use_iterator(0); }
1142
1143
1144   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1145   /// indicated value.  This method ignores uses of other values defined by this
1146   /// operation.
1147   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
1148
1149   /// hasAnyUseOfValue - Return true if there are any use of the indicated
1150   /// value. This method ignores uses of other values defined by this operation.
1151   bool hasAnyUseOfValue(unsigned Value) const;
1152
1153   /// isOnlyUseOf - Return true if this node is the only use of N.
1154   ///
1155   bool isOnlyUseOf(SDNode *N) const;
1156
1157   /// isOperandOf - Return true if this node is an operand of N.
1158   ///
1159   bool isOperandOf(SDNode *N) const;
1160
1161   /// isPredecessorOf - Return true if this node is a predecessor of N. This
1162   /// node is either an operand of N or it can be reached by recursively
1163   /// traversing up the operands.
1164   /// NOTE: this is an expensive method. Use it carefully.
1165   bool isPredecessorOf(SDNode *N) const;
1166
1167   /// getNumOperands - Return the number of values used by this operation.
1168   ///
1169   unsigned getNumOperands() const { return NumOperands; }
1170
1171   /// getConstantOperandVal - Helper method returns the integer value of a 
1172   /// ConstantSDNode operand.
1173   uint64_t getConstantOperandVal(unsigned Num) const;
1174
1175   const SDOperand &getOperand(unsigned Num) const {
1176     assert(Num < NumOperands && "Invalid child # of SDNode!");
1177     return OperandList[Num].getSDOperand();
1178   }
1179
1180   typedef SDUse* op_iterator;
1181   op_iterator op_begin() const { return OperandList; }
1182   op_iterator op_end() const { return OperandList+NumOperands; }
1183
1184
1185   SDVTList getVTList() const {
1186     SDVTList X = { ValueList, NumValues };
1187     return X;
1188   };
1189   
1190   /// getNumValues - Return the number of values defined/returned by this
1191   /// operator.
1192   ///
1193   unsigned getNumValues() const { return NumValues; }
1194
1195   /// getValueType - Return the type of a specified result.
1196   ///
1197   MVT::ValueType getValueType(unsigned ResNo) const {
1198     assert(ResNo < NumValues && "Illegal result number!");
1199     return ValueList[ResNo];
1200   }
1201
1202   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
1203   ///
1204   unsigned getValueSizeInBits(unsigned ResNo) const {
1205     return MVT::getSizeInBits(getValueType(ResNo));
1206   }
1207
1208   typedef const MVT::ValueType* value_iterator;
1209   value_iterator value_begin() const { return ValueList; }
1210   value_iterator value_end() const { return ValueList+NumValues; }
1211
1212   /// getOperationName - Return the opcode of this operation for printing.
1213   ///
1214   std::string getOperationName(const SelectionDAG *G = 0) const;
1215   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
1216   void dump() const;
1217   void dump(const SelectionDAG *G) const;
1218
1219   static bool classof(const SDNode *) { return true; }
1220
1221   /// Profile - Gather unique data for the node.
1222   ///
1223   void Profile(FoldingSetNodeID &ID);
1224
1225 protected:
1226   friend class SelectionDAG;
1227   
1228   /// getValueTypeList - Return a pointer to the specified value type.
1229   ///
1230   static const MVT::ValueType *getValueTypeList(MVT::ValueType VT);
1231   static SDVTList getSDVTList(MVT::ValueType VT) {
1232     SDVTList Ret = { getValueTypeList(VT), 1 };
1233     return Ret;
1234   }
1235
1236   SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
1237     : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
1238     OperandsNeedDelete = true;
1239     NumOperands = NumOps;
1240     OperandList = NumOps ? new SDUse[NumOperands] : 0;
1241     
1242     for (unsigned i = 0; i != NumOps; ++i) {
1243       OperandList[i] = Ops[i];
1244       OperandList[i].setUser(this);
1245       Ops[i].Val->addUse(OperandList[i]);
1246       ++Ops[i].Val->UsesSize;
1247     }
1248     
1249     ValueList = VTs.VTs;
1250     NumValues = VTs.NumVTs;
1251     Prev = 0; Next = 0;
1252   }
1253
1254   SDNode(unsigned Opc, SDVTList VTs, SDOperandPtr Ops, unsigned NumOps)
1255     : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
1256     OperandsNeedDelete = true;
1257     NumOperands = NumOps;
1258     OperandList = NumOps ? new SDUse[NumOperands] : 0;
1259     
1260     for (unsigned i = 0; i != NumOps; ++i) {
1261       OperandList[i] = Ops[i];
1262       OperandList[i].setUser(this);
1263       Ops[i].Val->addUse(OperandList[i]);
1264       ++Ops[i].Val->UsesSize;
1265     }
1266     
1267     ValueList = VTs.VTs;
1268     NumValues = VTs.NumVTs;
1269     Prev = 0; Next = 0;
1270   }
1271
1272   SDNode(unsigned Opc, SDVTList VTs)
1273     : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
1274     OperandsNeedDelete = false;  // Operands set with InitOperands.
1275     NumOperands = 0;
1276     OperandList = 0;
1277     ValueList = VTs.VTs;
1278     NumValues = VTs.NumVTs;
1279     Prev = 0; Next = 0;
1280   }
1281   
1282   /// InitOperands - Initialize the operands list of this node with the
1283   /// specified values, which are part of the node (thus they don't need to be
1284   /// copied in or allocated).
1285   void InitOperands(SDUse *Ops, unsigned NumOps) {
1286     assert(OperandList == 0 && "Operands already set!");
1287     NumOperands = NumOps;
1288     OperandList = Ops;
1289     UsesSize = 0;
1290     Uses = NULL;
1291     
1292     for (unsigned i = 0; i != NumOps; ++i) {
1293       OperandList[i].setUser(this);
1294       Ops[i].getVal()->addUse(OperandList[i]);
1295       ++Ops[i].getVal()->UsesSize;
1296     }
1297   }
1298   
1299   /// MorphNodeTo - This frees the operands of the current node, resets the
1300   /// opcode, types, and operands to the specified value.  This should only be
1301   /// used by the SelectionDAG class.
1302   void MorphNodeTo(unsigned Opc, SDVTList L,
1303                    const SDOperand *Ops, unsigned NumOps);
1304   
1305   void addUser(unsigned i, SDNode *User) {
1306     assert(User->OperandList[i].getUser() && "Node without parent");
1307     addUse(User->OperandList[i]);
1308     ++UsesSize;
1309   }
1310
1311   void removeUser(unsigned i, SDNode *User) {
1312     assert(User->OperandList[i].getUser() && "Node without parent");
1313     SDUse &Op = User->OperandList[i];
1314     Op.removeFromList();
1315     --UsesSize;
1316   }
1317 };
1318
1319
1320 // Define inline functions from the SDOperand class.
1321
1322 inline unsigned SDOperand::getOpcode() const {
1323   return Val->getOpcode();
1324 }
1325 inline MVT::ValueType SDOperand::getValueType() const {
1326   return Val->getValueType(ResNo);
1327 }
1328 inline unsigned SDOperand::getNumOperands() const {
1329   return Val->getNumOperands();
1330 }
1331 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1332   return Val->getOperand(i);
1333 }
1334 inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1335   return Val->getConstantOperandVal(i);
1336 }
1337 inline bool SDOperand::isTargetOpcode() const {
1338   return Val->isTargetOpcode();
1339 }
1340 inline unsigned SDOperand::getTargetOpcode() const {
1341   return Val->getTargetOpcode();
1342 }
1343 inline bool SDOperand::hasOneUse() const {
1344   return Val->hasNUsesOfValue(1, ResNo);
1345 }
1346 inline bool SDOperand::use_empty() const {
1347   return !Val->hasAnyUseOfValue(ResNo);
1348 }
1349
1350 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
1351 /// to allow co-allocation of node operands with the node itself.
1352 class UnarySDNode : public SDNode {
1353   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1354   SDUse Op;
1355 public:
1356   UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1357     : SDNode(Opc, VTs) {
1358     Op = X;
1359     InitOperands(&Op, 1);
1360   }
1361 };
1362
1363 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
1364 /// to allow co-allocation of node operands with the node itself.
1365 class BinarySDNode : public SDNode {
1366   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1367   SDUse Ops[2];
1368 public:
1369   BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1370     : SDNode(Opc, VTs) {
1371     Ops[0] = X;
1372     Ops[1] = Y;
1373     InitOperands(Ops, 2);
1374   }
1375 };
1376
1377 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1378 /// to allow co-allocation of node operands with the node itself.
1379 class TernarySDNode : public SDNode {
1380   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1381   SDUse Ops[3];
1382 public:
1383   TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1384                 SDOperand Z)
1385     : SDNode(Opc, VTs) {
1386     Ops[0] = X;
1387     Ops[1] = Y;
1388     Ops[2] = Z;
1389     InitOperands(Ops, 3);
1390   }
1391 };
1392
1393
1394 /// HandleSDNode - This class is used to form a handle around another node that
1395 /// is persistant and is updated across invocations of replaceAllUsesWith on its
1396 /// operand.  This node should be directly created by end-users and not added to
1397 /// the AllNodes list.
1398 class HandleSDNode : public SDNode {
1399   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1400   SDUse Op;
1401 public:
1402   explicit HandleSDNode(SDOperand X)
1403     : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
1404     Op = X;
1405     InitOperands(&Op, 1);
1406   }
1407   ~HandleSDNode();  
1408   SDUse getValue() const { return Op; }
1409 };
1410
1411 class AtomicSDNode : public SDNode {
1412   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1413   SDUse Ops[4];
1414   MVT::ValueType OrigVT;
1415 public:
1416   AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, 
1417                SDOperand Cmp, SDOperand Swp, MVT::ValueType VT)
1418     : SDNode(Opc, VTL) {
1419     Ops[0] = Chain;
1420     Ops[1] = Ptr;
1421     Ops[2] = Swp;
1422     Ops[3] = Cmp;
1423     InitOperands(Ops, 4);
1424     OrigVT=VT;
1425   }
1426   AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, 
1427                SDOperand Val, MVT::ValueType VT)
1428     : SDNode(Opc, VTL) {
1429     Ops[0] = Chain;
1430     Ops[1] = Ptr;
1431     Ops[2] = Val;
1432     InitOperands(Ops, 3);
1433     OrigVT=VT;
1434   }
1435   MVT::ValueType getVT() const { return OrigVT; }
1436   bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_LCS; }
1437 };
1438
1439 class StringSDNode : public SDNode {
1440   std::string Value;
1441   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1442 protected:
1443   friend class SelectionDAG;
1444   explicit StringSDNode(const std::string &val)
1445     : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1446   }
1447 public:
1448   const std::string &getValue() const { return Value; }
1449   static bool classof(const StringSDNode *) { return true; }
1450   static bool classof(const SDNode *N) {
1451     return N->getOpcode() == ISD::STRING;
1452   }
1453 };  
1454
1455 class ConstantSDNode : public SDNode {
1456   APInt Value;
1457   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1458 protected:
1459   friend class SelectionDAG;
1460   ConstantSDNode(bool isTarget, const APInt &val, MVT::ValueType VT)
1461     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1462       Value(val) {
1463   }
1464 public:
1465
1466   const APInt &getAPIntValue() const { return Value; }
1467   uint64_t getValue() const { return Value.getZExtValue(); }
1468
1469   int64_t getSignExtended() const {
1470     unsigned Bits = MVT::getSizeInBits(getValueType(0));
1471     return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
1472   }
1473
1474   bool isNullValue() const { return Value == 0; }
1475   bool isAllOnesValue() const {
1476     return Value == MVT::getIntVTBitMask(getValueType(0));
1477   }
1478
1479   static bool classof(const ConstantSDNode *) { return true; }
1480   static bool classof(const SDNode *N) {
1481     return N->getOpcode() == ISD::Constant ||
1482            N->getOpcode() == ISD::TargetConstant;
1483   }
1484 };
1485
1486 class ConstantFPSDNode : public SDNode {
1487   APFloat Value;
1488   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1489 protected:
1490   friend class SelectionDAG;
1491   ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT)
1492     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1493              getSDVTList(VT)), Value(val) {
1494   }
1495 public:
1496
1497   const APFloat& getValueAPF() const { return Value; }
1498
1499   /// isExactlyValue - We don't rely on operator== working on double values, as
1500   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1501   /// As such, this method can be used to do an exact bit-for-bit comparison of
1502   /// two floating point values.
1503
1504   /// We leave the version with the double argument here because it's just so
1505   /// convenient to write "2.0" and the like.  Without this function we'd 
1506   /// have to duplicate its logic everywhere it's called.
1507   bool isExactlyValue(double V) const { 
1508     APFloat Tmp(V);
1509     Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
1510     return isExactlyValue(Tmp);
1511   }
1512   bool isExactlyValue(const APFloat& V) const;
1513
1514   bool isValueValidForType(MVT::ValueType VT, const APFloat& Val);
1515
1516   static bool classof(const ConstantFPSDNode *) { return true; }
1517   static bool classof(const SDNode *N) {
1518     return N->getOpcode() == ISD::ConstantFP || 
1519            N->getOpcode() == ISD::TargetConstantFP;
1520   }
1521 };
1522
1523 class GlobalAddressSDNode : public SDNode {
1524   GlobalValue *TheGlobal;
1525   int Offset;
1526   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1527 protected:
1528   friend class SelectionDAG;
1529   GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1530                       int o = 0);
1531 public:
1532
1533   GlobalValue *getGlobal() const { return TheGlobal; }
1534   int getOffset() const { return Offset; }
1535
1536   static bool classof(const GlobalAddressSDNode *) { return true; }
1537   static bool classof(const SDNode *N) {
1538     return N->getOpcode() == ISD::GlobalAddress ||
1539            N->getOpcode() == ISD::TargetGlobalAddress ||
1540            N->getOpcode() == ISD::GlobalTLSAddress ||
1541            N->getOpcode() == ISD::TargetGlobalTLSAddress;
1542   }
1543 };
1544
1545 class FrameIndexSDNode : public SDNode {
1546   int FI;
1547   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1548 protected:
1549   friend class SelectionDAG;
1550   FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1551     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1552       FI(fi) {
1553   }
1554 public:
1555
1556   int getIndex() const { return FI; }
1557
1558   static bool classof(const FrameIndexSDNode *) { return true; }
1559   static bool classof(const SDNode *N) {
1560     return N->getOpcode() == ISD::FrameIndex ||
1561            N->getOpcode() == ISD::TargetFrameIndex;
1562   }
1563 };
1564
1565 class JumpTableSDNode : public SDNode {
1566   int JTI;
1567   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1568 protected:
1569   friend class SelectionDAG;
1570   JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1571     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1572       JTI(jti) {
1573   }
1574 public:
1575     
1576   int getIndex() const { return JTI; }
1577   
1578   static bool classof(const JumpTableSDNode *) { return true; }
1579   static bool classof(const SDNode *N) {
1580     return N->getOpcode() == ISD::JumpTable ||
1581            N->getOpcode() == ISD::TargetJumpTable;
1582   }
1583 };
1584
1585 class ConstantPoolSDNode : public SDNode {
1586   union {
1587     Constant *ConstVal;
1588     MachineConstantPoolValue *MachineCPVal;
1589   } Val;
1590   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1591   unsigned Alignment;
1592   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1593 protected:
1594   friend class SelectionDAG;
1595   ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1596                      int o=0)
1597     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1598              getSDVTList(VT)), Offset(o), Alignment(0) {
1599     assert((int)Offset >= 0 && "Offset is too large");
1600     Val.ConstVal = c;
1601   }
1602   ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1603                      unsigned Align)
1604     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1605              getSDVTList(VT)), Offset(o), Alignment(Align) {
1606     assert((int)Offset >= 0 && "Offset is too large");
1607     Val.ConstVal = c;
1608   }
1609   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1610                      MVT::ValueType VT, int o=0)
1611     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 
1612              getSDVTList(VT)), Offset(o), Alignment(0) {
1613     assert((int)Offset >= 0 && "Offset is too large");
1614     Val.MachineCPVal = v;
1615     Offset |= 1 << (sizeof(unsigned)*8-1);
1616   }
1617   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1618                      MVT::ValueType VT, int o, unsigned Align)
1619     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1620              getSDVTList(VT)), Offset(o), Alignment(Align) {
1621     assert((int)Offset >= 0 && "Offset is too large");
1622     Val.MachineCPVal = v;
1623     Offset |= 1 << (sizeof(unsigned)*8-1);
1624   }
1625 public:
1626
1627   bool isMachineConstantPoolEntry() const {
1628     return (int)Offset < 0;
1629   }
1630
1631   Constant *getConstVal() const {
1632     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1633     return Val.ConstVal;
1634   }
1635
1636   MachineConstantPoolValue *getMachineCPVal() const {
1637     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1638     return Val.MachineCPVal;
1639   }
1640
1641   int getOffset() const {
1642     return Offset & ~(1 << (sizeof(unsigned)*8-1));
1643   }
1644   
1645   // Return the alignment of this constant pool object, which is either 0 (for
1646   // default alignment) or log2 of the desired value.
1647   unsigned getAlignment() const { return Alignment; }
1648
1649   const Type *getType() const;
1650
1651   static bool classof(const ConstantPoolSDNode *) { return true; }
1652   static bool classof(const SDNode *N) {
1653     return N->getOpcode() == ISD::ConstantPool ||
1654            N->getOpcode() == ISD::TargetConstantPool;
1655   }
1656 };
1657
1658 class BasicBlockSDNode : public SDNode {
1659   MachineBasicBlock *MBB;
1660   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1661 protected:
1662   friend class SelectionDAG;
1663   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1664     : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1665   }
1666 public:
1667
1668   MachineBasicBlock *getBasicBlock() const { return MBB; }
1669
1670   static bool classof(const BasicBlockSDNode *) { return true; }
1671   static bool classof(const SDNode *N) {
1672     return N->getOpcode() == ISD::BasicBlock;
1673   }
1674 };
1675
1676 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1677 /// used when the SelectionDAG needs to make a simple reference to something
1678 /// in the LLVM IR representation.
1679 ///
1680 /// Note that this is not used for carrying alias information; that is done
1681 /// with MemOperandSDNode, which includes a Value which is required to be a
1682 /// pointer, and several other fields specific to memory references.
1683 ///
1684 class SrcValueSDNode : public SDNode {
1685   const Value *V;
1686   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1687 protected:
1688   friend class SelectionDAG;
1689   /// Create a SrcValue for a general value.
1690   explicit SrcValueSDNode(const Value *v)
1691     : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
1692
1693 public:
1694   /// getValue - return the contained Value.
1695   const Value *getValue() const { return V; }
1696
1697   static bool classof(const SrcValueSDNode *) { return true; }
1698   static bool classof(const SDNode *N) {
1699     return N->getOpcode() == ISD::SRCVALUE;
1700   }
1701 };
1702
1703
1704 /// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
1705 /// used to represent a reference to memory after ISD::LOAD
1706 /// and ISD::STORE have been lowered.
1707 ///
1708 class MemOperandSDNode : public SDNode {
1709   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1710 protected:
1711   friend class SelectionDAG;
1712   /// Create a MachineMemOperand node
1713   explicit MemOperandSDNode(const MachineMemOperand &mo)
1714     : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
1715
1716 public:
1717   /// MO - The contained MachineMemOperand.
1718   const MachineMemOperand MO;
1719
1720   static bool classof(const MemOperandSDNode *) { return true; }
1721   static bool classof(const SDNode *N) {
1722     return N->getOpcode() == ISD::MEMOPERAND;
1723   }
1724 };
1725
1726
1727 class RegisterSDNode : public SDNode {
1728   unsigned Reg;
1729   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1730 protected:
1731   friend class SelectionDAG;
1732   RegisterSDNode(unsigned reg, MVT::ValueType VT)
1733     : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1734   }
1735 public:
1736
1737   unsigned getReg() const { return Reg; }
1738
1739   static bool classof(const RegisterSDNode *) { return true; }
1740   static bool classof(const SDNode *N) {
1741     return N->getOpcode() == ISD::Register;
1742   }
1743 };
1744
1745 class ExternalSymbolSDNode : public SDNode {
1746   const char *Symbol;
1747   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1748 protected:
1749   friend class SelectionDAG;
1750   ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1751     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1752              getSDVTList(VT)), Symbol(Sym) {
1753   }
1754 public:
1755
1756   const char *getSymbol() const { return Symbol; }
1757
1758   static bool classof(const ExternalSymbolSDNode *) { return true; }
1759   static bool classof(const SDNode *N) {
1760     return N->getOpcode() == ISD::ExternalSymbol ||
1761            N->getOpcode() == ISD::TargetExternalSymbol;
1762   }
1763 };
1764
1765 class CondCodeSDNode : public SDNode {
1766   ISD::CondCode Condition;
1767   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1768 protected:
1769   friend class SelectionDAG;
1770   explicit CondCodeSDNode(ISD::CondCode Cond)
1771     : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1772   }
1773 public:
1774
1775   ISD::CondCode get() const { return Condition; }
1776
1777   static bool classof(const CondCodeSDNode *) { return true; }
1778   static bool classof(const SDNode *N) {
1779     return N->getOpcode() == ISD::CONDCODE;
1780   }
1781 };
1782
1783 namespace ISD {
1784   struct ArgFlagsTy {
1785   private:
1786     static const uint64_t NoFlagSet      = 0ULL;
1787     static const uint64_t ZExt           = 1ULL<<0;  ///< Zero extended
1788     static const uint64_t ZExtOffs       = 0;
1789     static const uint64_t SExt           = 1ULL<<1;  ///< Sign extended
1790     static const uint64_t SExtOffs       = 1;
1791     static const uint64_t InReg          = 1ULL<<2;  ///< Passed in register
1792     static const uint64_t InRegOffs      = 2;
1793     static const uint64_t SRet           = 1ULL<<3;  ///< Hidden struct-ret ptr
1794     static const uint64_t SRetOffs       = 3;
1795     static const uint64_t ByVal          = 1ULL<<4;  ///< Struct passed by value
1796     static const uint64_t ByValOffs      = 4;
1797     static const uint64_t Nest           = 1ULL<<5;  ///< Nested fn static chain
1798     static const uint64_t NestOffs       = 5;
1799     static const uint64_t ByValAlign     = 0xFULL << 6; //< Struct alignment
1800     static const uint64_t ByValAlignOffs = 6;
1801     static const uint64_t Split          = 1ULL << 10;
1802     static const uint64_t SplitOffs      = 10;
1803     static const uint64_t OrigAlign      = 0x1FULL<<27;
1804     static const uint64_t OrigAlignOffs  = 27;
1805     static const uint64_t ByValSize      = 0xffffffffULL << 32; //< Struct size
1806     static const uint64_t ByValSizeOffs  = 32;
1807
1808     static const uint64_t One            = 1ULL; //< 1 of this type, for shifts
1809
1810     uint64_t Flags;
1811   public:
1812     ArgFlagsTy() : Flags(0) { }
1813
1814     bool isZExt()   const { return Flags & ZExt; }
1815     void setZExt()  { Flags |= One << ZExtOffs; }
1816
1817     bool isSExt()   const { return Flags & SExt; }
1818     void setSExt()  { Flags |= One << SExtOffs; }
1819
1820     bool isInReg()  const { return Flags & InReg; }
1821     void setInReg() { Flags |= One << InRegOffs; }
1822
1823     bool isSRet()   const { return Flags & SRet; }
1824     void setSRet()  { Flags |= One << SRetOffs; }
1825
1826     bool isByVal()  const { return Flags & ByVal; }
1827     void setByVal() { Flags |= One << ByValOffs; }
1828
1829     bool isNest()   const { return Flags & Nest; }
1830     void setNest()  { Flags |= One << NestOffs; }
1831
1832     unsigned getByValAlign() const {
1833       return (unsigned) 
1834         ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
1835     }
1836     void setByValAlign(unsigned A) {
1837       Flags = (Flags & ~ByValAlign) |
1838         (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
1839     }
1840             
1841     bool isSplit()   const { return Flags & Split; }
1842     void setSplit()  { Flags |= One << SplitOffs; }
1843
1844     unsigned getOrigAlign() const {
1845       return (unsigned)
1846         ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
1847     }
1848     void setOrigAlign(unsigned A) {
1849       Flags = (Flags & ~OrigAlign) |
1850         (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
1851     }
1852
1853     unsigned getByValSize() const {
1854       return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
1855     }
1856     void setByValSize(unsigned S) {
1857       Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
1858     }
1859
1860     /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
1861     std::string getArgFlagsString();
1862
1863     /// getRawBits - Represent the flags as a bunch of bits.
1864     uint64_t getRawBits() const { return Flags; }
1865   };
1866 }
1867
1868 /// ARG_FLAGSSDNode - Leaf node holding parameter flags.
1869 class ARG_FLAGSSDNode : public SDNode {
1870   ISD::ArgFlagsTy TheFlags;
1871   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1872 protected:
1873   friend class SelectionDAG;
1874   explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
1875     : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
1876   }
1877 public:
1878   ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
1879
1880   static bool classof(const ARG_FLAGSSDNode *) { return true; }
1881   static bool classof(const SDNode *N) {
1882     return N->getOpcode() == ISD::ARG_FLAGS;
1883   }
1884 };
1885
1886 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1887 /// to parameterize some operations.
1888 class VTSDNode : public SDNode {
1889   MVT::ValueType ValueType;
1890   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1891 protected:
1892   friend class SelectionDAG;
1893   explicit VTSDNode(MVT::ValueType VT)
1894     : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1895   }
1896 public:
1897
1898   MVT::ValueType getVT() const { return ValueType; }
1899
1900   static bool classof(const VTSDNode *) { return true; }
1901   static bool classof(const SDNode *N) {
1902     return N->getOpcode() == ISD::VALUETYPE;
1903   }
1904 };
1905
1906 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1907 ///
1908 class LSBaseSDNode : public SDNode {
1909 private:
1910   // AddrMode - unindexed, pre-indexed, post-indexed.
1911   ISD::MemIndexedMode AddrMode;
1912
1913   // MemoryVT - VT of in-memory value.
1914   MVT::ValueType MemoryVT;
1915
1916   //! SrcValue - Memory location for alias analysis.
1917   const Value *SrcValue;
1918
1919   //! SVOffset - Memory location offset.
1920   int SVOffset;
1921
1922   //! Alignment - Alignment of memory location in bytes.
1923   unsigned Alignment;
1924
1925   //! IsVolatile - True if the store is volatile.
1926   bool IsVolatile;
1927 protected:
1928   //! Operand array for load and store
1929   /*!
1930     \note Moving this array to the base class captures more
1931     common functionality shared between LoadSDNode and
1932     StoreSDNode
1933    */
1934   SDUse Ops[4];
1935 public:
1936   LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned NumOperands,
1937                SDVTList VTs, ISD::MemIndexedMode AM, MVT::ValueType VT, 
1938                const Value *SV, int SVO, unsigned Align, bool Vol)
1939     : SDNode(NodeTy, VTs),
1940       AddrMode(AM), MemoryVT(VT),
1941       SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol) {
1942     for (unsigned i = 0; i != NumOperands; ++i)
1943       Ops[i] = Operands[i];
1944     InitOperands(Ops, NumOperands);
1945     assert(Align != 0 && "Loads and stores should have non-zero aligment");
1946     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1947            "Only indexed loads and stores have a non-undef offset operand");
1948   }
1949
1950   const SDOperand &getChain() const { return getOperand(0); }
1951   const SDOperand &getBasePtr() const {
1952     return getOperand(getOpcode() == ISD::LOAD ? 1 : 2);
1953   }
1954   const SDOperand &getOffset() const {
1955     return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1956   }
1957
1958   const Value *getSrcValue() const { return SrcValue; }
1959   int getSrcValueOffset() const { return SVOffset; }
1960   unsigned getAlignment() const { return Alignment; }
1961   MVT::ValueType getMemoryVT() const { return MemoryVT; }
1962   bool isVolatile() const { return IsVolatile; }
1963
1964   ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1965
1966   /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1967   bool isIndexed() const { return AddrMode != ISD::UNINDEXED; }
1968
1969   /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1970   bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; }
1971
1972   /// getMemOperand - Return a MachineMemOperand object describing the memory
1973   /// reference performed by this load or store.
1974   MachineMemOperand getMemOperand() const;
1975
1976   static bool classof(const LSBaseSDNode *N) { return true; }
1977   static bool classof(const SDNode *N) {
1978     return N->getOpcode() == ISD::LOAD ||
1979            N->getOpcode() == ISD::STORE;
1980   }
1981 };
1982
1983 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1984 ///
1985 class LoadSDNode : public LSBaseSDNode {
1986   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1987   
1988   // ExtType - non-ext, anyext, sext, zext.
1989   ISD::LoadExtType ExtType;
1990
1991 protected:
1992   friend class SelectionDAG;
1993   LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1994              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1995              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1996     : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
1997                    VTs, AM, LVT, SV, O, Align, Vol),
1998       ExtType(ETy) {}
1999 public:
2000
2001   ISD::LoadExtType getExtensionType() const { return ExtType; }
2002   const SDOperand &getBasePtr() const { return getOperand(1); }
2003   const SDOperand &getOffset() const { return getOperand(2); }
2004   
2005   static bool classof(const LoadSDNode *) { return true; }
2006   static bool classof(const SDNode *N) {
2007     return N->getOpcode() == ISD::LOAD;
2008   }
2009 };
2010
2011 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
2012 ///
2013 class StoreSDNode : public LSBaseSDNode {
2014   virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2015     
2016   // IsTruncStore - True if the op does a truncation before store.
2017   bool IsTruncStore;
2018 protected:
2019   friend class SelectionDAG;
2020   StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
2021               ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
2022               const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2023     : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
2024                    VTs, AM, SVT, SV, O, Align, Vol),
2025       IsTruncStore(isTrunc) {}
2026 public:
2027
2028   bool isTruncatingStore() const { return IsTruncStore; }
2029   const SDOperand &getValue() const { return getOperand(1); }
2030   const SDOperand &getBasePtr() const { return getOperand(2); }
2031   const SDOperand &getOffset() const { return getOperand(3); }
2032   
2033   static bool classof(const StoreSDNode *) { return true; }
2034   static bool classof(const SDNode *N) {
2035     return N->getOpcode() == ISD::STORE;
2036   }
2037 };
2038
2039
2040 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
2041   SDNode *Node;
2042   unsigned Operand;
2043
2044   SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
2045 public:
2046   bool operator==(const SDNodeIterator& x) const {
2047     return Operand == x.Operand;
2048   }
2049   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
2050
2051   const SDNodeIterator &operator=(const SDNodeIterator &I) {
2052     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
2053     Operand = I.Operand;
2054     return *this;
2055   }
2056
2057   pointer operator*() const {
2058     return Node->getOperand(Operand).Val;
2059   }
2060   pointer operator->() const { return operator*(); }
2061
2062   SDNodeIterator& operator++() {                // Preincrement
2063     ++Operand;
2064     return *this;
2065   }
2066   SDNodeIterator operator++(int) { // Postincrement
2067     SDNodeIterator tmp = *this; ++*this; return tmp;
2068   }
2069
2070   static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
2071   static SDNodeIterator end  (SDNode *N) {
2072     return SDNodeIterator(N, N->getNumOperands());
2073   }
2074
2075   unsigned getOperand() const { return Operand; }
2076   const SDNode *getNode() const { return Node; }
2077 };
2078
2079 template <> struct GraphTraits<SDNode*> {
2080   typedef SDNode NodeType;
2081   typedef SDNodeIterator ChildIteratorType;
2082   static inline NodeType *getEntryNode(SDNode *N) { return N; }
2083   static inline ChildIteratorType child_begin(NodeType *N) {
2084     return SDNodeIterator::begin(N);
2085   }
2086   static inline ChildIteratorType child_end(NodeType *N) {
2087     return SDNodeIterator::end(N);
2088   }
2089 };
2090
2091 template<>
2092 struct ilist_traits<SDNode> {
2093   static SDNode *getPrev(const SDNode *N) { return N->Prev; }
2094   static SDNode *getNext(const SDNode *N) { return N->Next; }
2095   
2096   static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
2097   static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
2098   
2099   static SDNode *createSentinel() {
2100     return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
2101   }
2102   static void destroySentinel(SDNode *N) { delete N; }
2103   //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
2104   
2105   
2106   void addNodeToList(SDNode *NTy) {}
2107   void removeNodeFromList(SDNode *NTy) {}
2108   void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
2109                              const ilist_iterator<SDNode> &X,
2110                              const ilist_iterator<SDNode> &Y) {}
2111 };
2112
2113 namespace ISD {
2114   /// isNormalLoad - Returns true if the specified node is a non-extending
2115   /// and unindexed load.
2116   inline bool isNormalLoad(const SDNode *N) {
2117     if (N->getOpcode() != ISD::LOAD)
2118       return false;
2119     const LoadSDNode *Ld = cast<LoadSDNode>(N);
2120     return Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2121       Ld->getAddressingMode() == ISD::UNINDEXED;
2122   }
2123
2124   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
2125   /// load.
2126   inline bool isNON_EXTLoad(const SDNode *N) {
2127     return N->getOpcode() == ISD::LOAD &&
2128       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
2129   }
2130
2131   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2132   ///
2133   inline bool isEXTLoad(const SDNode *N) {
2134     return N->getOpcode() == ISD::LOAD &&
2135       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2136   }
2137
2138   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2139   ///
2140   inline bool isSEXTLoad(const SDNode *N) {
2141     return N->getOpcode() == ISD::LOAD &&
2142       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2143   }
2144
2145   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2146   ///
2147   inline bool isZEXTLoad(const SDNode *N) {
2148     return N->getOpcode() == ISD::LOAD &&
2149       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2150   }
2151
2152   /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
2153   ///
2154   inline bool isUNINDEXEDLoad(const SDNode *N) {
2155     return N->getOpcode() == ISD::LOAD &&
2156       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
2157   }
2158
2159   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
2160   /// store.
2161   inline bool isNON_TRUNCStore(const SDNode *N) {
2162     return N->getOpcode() == ISD::STORE &&
2163       !cast<StoreSDNode>(N)->isTruncatingStore();
2164   }
2165
2166   /// isTRUNCStore - Returns true if the specified node is a truncating
2167   /// store.
2168   inline bool isTRUNCStore(const SDNode *N) {
2169     return N->getOpcode() == ISD::STORE &&
2170       cast<StoreSDNode>(N)->isTruncatingStore();
2171   }
2172 }
2173
2174
2175 } // end llvm namespace
2176
2177 #endif