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