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