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