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