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