SelectionDAGNodes.h revision 681ee1c1c3f7c3558c29a5bf3a668c1d0784c399
1//===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source 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/CodeGen/ValueTypes.h"
23#include "llvm/Value.h"
24#include "llvm/ADT/GraphTraits.h"
25#include "llvm/ADT/iterator"
26#include "llvm/Support/DataTypes.h"
27#include <cassert>
28#include <vector>
29
30namespace llvm {
31
32class SelectionDAG;
33class GlobalValue;
34class MachineBasicBlock;
35class SDNode;
36template <typename T> struct simplify_type;
37template <typename T> struct ilist_traits;
38template<typename NodeTy, typename Traits> class iplist;
39template<typename NodeTy> class ilist_iterator;
40
41/// ISD namespace - This namespace contains an enum which represents all of the
42/// SelectionDAG node types and value types.
43///
44namespace ISD {
45  //===--------------------------------------------------------------------===//
46  /// ISD::NodeType enum - This enum defines all of the operators valid in a
47  /// SelectionDAG.
48  ///
49  enum NodeType {
50    // EntryToken - This is the marker used to indicate the start of the region.
51    EntryToken,
52
53    // Token factor - This node takes multiple tokens as input and produces a
54    // single token result.  This is used to represent the fact that the operand
55    // operators are independent of each other.
56    TokenFactor,
57
58    // AssertSext, AssertZext - These nodes record if a register contains a
59    // value that has already been zero or sign extended from a narrower type.
60    // These nodes take two operands.  The first is the node that has already
61    // been extended, and the second is a value type node indicating the width
62    // of the extension
63    AssertSext, AssertZext,
64
65    // Various leaf nodes.
66    STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
67    Constant, ConstantFP,
68    GlobalAddress, FrameIndex, ConstantPool, ExternalSymbol,
69
70    // TargetConstant* - Like Constant*, but the DAG does not do any folding or
71    // simplification of the constant.
72    TargetConstant,
73    TargetConstantFP,
74
75    // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
76    // anything else with this node, and this is valid in the target-specific
77    // dag, turning into a GlobalAddress operand.
78    TargetGlobalAddress,
79    TargetFrameIndex,
80    TargetConstantPool,
81    TargetExternalSymbol,
82
83    /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
84    /// This node represents a target intrinsic function with no side effects.
85    /// The first operand is the ID number of the intrinsic from the
86    /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
87    /// node has returns the result of the intrinsic.
88    INTRINSIC_WO_CHAIN,
89
90    /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
91    /// This node represents a target intrinsic function with side effects that
92    /// returns a result.  The first operand is a chain pointer.  The second is
93    /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
94    /// operands to the intrinsic follow.  The node has two results, the result
95    /// of the intrinsic and an output chain.
96    INTRINSIC_W_CHAIN,
97
98    /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
99    /// This node represents a target intrinsic function with side effects that
100    /// does not return a result.  The first operand is a chain pointer.  The
101    /// second is the ID number of the intrinsic from the llvm::Intrinsic
102    /// namespace.  The operands to the intrinsic follow.
103    INTRINSIC_VOID,
104
105    // CopyToReg - This node has three operands: a chain, a register number to
106    // set to this value, and a value.
107    CopyToReg,
108
109    // CopyFromReg - This node indicates that the input value is a virtual or
110    // physical register that is defined outside of the scope of this
111    // SelectionDAG.  The register is available from the RegSDNode object.
112    CopyFromReg,
113
114    // UNDEF - An undefined node
115    UNDEF,
116
117    /// FORMAL_ARGUMENTS(CC#, ISVARARG) - This node represents the formal
118    /// arguments for a function.  CC# is a Constant value indicating the
119    /// calling convention of the function, and ISVARARG is a flag that
120    /// indicates whether the function is varargs or not.  This node has one
121    /// result value for each incoming argument, and is typically custom
122    /// legalized.
123    FORMAL_ARGUMENTS,
124
125    // EXTRACT_ELEMENT - This is used to get the first or second (determined by
126    // a Constant, which is required to be operand #1), element of the aggregate
127    // value specified as operand #0.  This is only for use before legalization,
128    // for values that will be broken into multiple registers.
129    EXTRACT_ELEMENT,
130
131    // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
132    // two values of the same integer value type, this produces a value twice as
133    // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
134    BUILD_PAIR,
135
136    // MERGE_VALUES - This node takes multiple discrete operands and returns
137    // them all as its individual results.  This nodes has exactly the same
138    // number of inputs and outputs, and is only valid before legalization.
139    // This node is useful for some pieces of the code generator that want to
140    // think about a single node with multiple results, not multiple nodes.
141    MERGE_VALUES,
142
143    // Simple integer binary arithmetic operators.
144    ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
145
146    // Carry-setting nodes for multiple precision addition and subtraction.
147    // These nodes take two operands of the same value type, and produce two
148    // results.  The first result is the normal add or sub result, the second
149    // result is the carry flag result.
150    ADDC, SUBC,
151
152    // Carry-using nodes for multiple precision addition and subtraction.  These
153    // nodes take three operands: The first two are the normal lhs and rhs to
154    // the add or sub, and the third is the input carry flag.  These nodes
155    // produce two results; the normal result of the add or sub, and the output
156    // carry flag.  These nodes both read and write a carry flag to allow them
157    // to them to be chained together for add and sub of arbitrarily large
158    // values.
159    ADDE, SUBE,
160
161    // Simple binary floating point operators.
162    FADD, FSUB, FMUL, FDIV, FREM,
163
164    // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
165    // DAG node does not require that X and Y have the same type, just that they
166    // are both floating point.  X and the result must have the same type.
167    // FCOPYSIGN(f32, f64) is allowed.
168    FCOPYSIGN,
169
170    /// VBUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,...,  COUNT,TYPE) - Return a vector
171    /// with the specified, possibly variable, elements.  The number of elements
172    /// is required to be a power of two.
173    VBUILD_VECTOR,
174
175    /// BUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,...) - Return a vector
176    /// with the specified, possibly variable, elements.  The number of elements
177    /// is required to be a power of two.
178    BUILD_VECTOR,
179
180    /// VINSERT_VECTOR_ELT(VECTOR, VAL, IDX,  COUNT,TYPE) - Given a vector
181    /// VECTOR, an element ELEMENT, and a (potentially variable) index IDX,
182    /// return an vector with the specified element of VECTOR replaced with VAL.
183    /// COUNT and TYPE specify the type of vector, as is standard for V* nodes.
184    VINSERT_VECTOR_ELT,
185
186    /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR (a legal packed
187    /// type) with the element at IDX replaced with VAL.
188    INSERT_VECTOR_ELT,
189
190    /// VEXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
191    /// (an MVT::Vector value) identified by the (potentially variable) element
192    /// number IDX.
193    VEXTRACT_VECTOR_ELT,
194
195    /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
196    /// (a legal packed type vector) identified by the (potentially variable)
197    /// element number IDX.
198    EXTRACT_VECTOR_ELT,
199
200    /// VVECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC, COUNT,TYPE) - Returns a vector,
201    /// of the same type as VEC1/VEC2.  SHUFFLEVEC is a VBUILD_VECTOR of
202    /// constant int values that indicate which value each result element will
203    /// get.  The elements of VEC1/VEC2 are enumerated in order.  This is quite
204    /// similar to the Altivec 'vperm' instruction, except that the indices must
205    /// be constants and are in terms of the element size of VEC1/VEC2, not in
206    /// terms of bytes.
207    VVECTOR_SHUFFLE,
208
209    /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
210    /// type as VEC1/VEC2.  SHUFFLEVEC is a BUILD_VECTOR of constant int values
211    /// (regardless of whether its datatype is legal or not) that indicate
212    /// which value each result element will get.  The elements of VEC1/VEC2 are
213    /// enumerated in order.  This is quite similar to the Altivec 'vperm'
214    /// instruction, except that the indices must be constants and are in terms
215    /// of the element size of VEC1/VEC2, not in terms of bytes.
216    VECTOR_SHUFFLE,
217
218    /// X = VBIT_CONVERT(Y)  and X = VBIT_CONVERT(Y, COUNT,TYPE) - This node
219    /// represents a conversion from or to an ISD::Vector type.
220    ///
221    /// This is lowered to a BIT_CONVERT of the appropriate input/output types.
222    /// The input and output are required to have the same size and at least one
223    /// is required to be a vector (if neither is a vector, just use
224    /// BIT_CONVERT).
225    ///
226    /// If the result is a vector, this takes three operands (like any other
227    /// vector producer) which indicate the size and type of the vector result.
228    /// Otherwise it takes one input.
229    VBIT_CONVERT,
230
231    /// BINOP(LHS, RHS,  COUNT,TYPE)
232    /// Simple abstract vector operators.  Unlike the integer and floating point
233    /// binary operators, these nodes also take two additional operands:
234    /// a constant element count, and a value type node indicating the type of
235    /// the elements.  The order is count, type, op0, op1.  All vector opcodes,
236    /// including VLOAD and VConstant must currently have count and type as
237    /// their last two operands.
238    VADD, VSUB, VMUL, VSDIV, VUDIV,
239    VAND, VOR, VXOR,
240
241    /// VSELECT(COND,LHS,RHS,  COUNT,TYPE) - Select for MVT::Vector values.
242    /// COND is a boolean value.  This node return LHS if COND is true, RHS if
243    /// COND is false.
244    VSELECT,
245
246    /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
247    /// scalar value into the low element of the resultant vector type.  The top
248    /// elements of the vector are undefined.
249    SCALAR_TO_VECTOR,
250
251    // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
252    // an unsigned/signed value of type i[2*n], then return the top part.
253    MULHU, MULHS,
254
255    // Bitwise operators - logical and, logical or, logical xor, shift left,
256    // shift right algebraic (shift in sign bits), shift right logical (shift in
257    // zeroes), rotate left, rotate right, and byteswap.
258    AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
259
260    // Counting operators
261    CTTZ, CTLZ, CTPOP,
262
263    // Select(COND, TRUEVAL, FALSEVAL)
264    SELECT,
265
266    // Select with condition operator - This selects between a true value and
267    // a false value (ops #2 and #3) based on the boolean result of comparing
268    // the lhs and rhs (ops #0 and #1) of a conditional expression with the
269    // condition code in op #4, a CondCodeSDNode.
270    SELECT_CC,
271
272    // SetCC operator - This evaluates to a boolean (i1) true value if the
273    // condition is true.  The operands to this are the left and right operands
274    // to compare (ops #0, and #1) and the condition code to compare them with
275    // (op #2) as a CondCodeSDNode.
276    SETCC,
277
278    // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
279    // integer shift operations, just like ADD/SUB_PARTS.  The operation
280    // ordering is:
281    //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
282    SHL_PARTS, SRA_PARTS, SRL_PARTS,
283
284    // Conversion operators.  These are all single input single output
285    // operations.  For all of these, the result type must be strictly
286    // wider or narrower (depending on the operation) than the source
287    // type.
288
289    // SIGN_EXTEND - Used for integer types, replicating the sign bit
290    // into new bits.
291    SIGN_EXTEND,
292
293    // ZERO_EXTEND - Used for integer types, zeroing the new bits.
294    ZERO_EXTEND,
295
296    // ANY_EXTEND - Used for integer types.  The high bits are undefined.
297    ANY_EXTEND,
298
299    // TRUNCATE - Completely drop the high bits.
300    TRUNCATE,
301
302    // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
303    // depends on the first letter) to floating point.
304    SINT_TO_FP,
305    UINT_TO_FP,
306
307    // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
308    // sign extend a small value in a large integer register (e.g. sign
309    // extending the low 8 bits of a 32-bit register to fill the top 24 bits
310    // with the 7th bit).  The size of the smaller type is indicated by the 1th
311    // operand, a ValueType node.
312    SIGN_EXTEND_INREG,
313
314    // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
315    // integer.
316    FP_TO_SINT,
317    FP_TO_UINT,
318
319    // FP_ROUND - Perform a rounding operation from the current
320    // precision down to the specified precision (currently always 64->32).
321    FP_ROUND,
322
323    // FP_ROUND_INREG - This operator takes a floating point register, and
324    // rounds it to a floating point value.  It then promotes it and returns it
325    // in a register of the same size.  This operation effectively just discards
326    // excess precision.  The type to round down to is specified by the 1th
327    // operation, a VTSDNode (currently always 64->32->64).
328    FP_ROUND_INREG,
329
330    // FP_EXTEND - Extend a smaller FP type into a larger FP type.
331    FP_EXTEND,
332
333    // BIT_CONVERT - Theis operator converts between integer and FP values, as
334    // if one was stored to memory as integer and the other was loaded from the
335    // same address (or equivalently for vector format conversions, etc).  The
336    // source and result are required to have the same bit size (e.g.
337    // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp
338    // conversions, but that is a noop, deleted by getNode().
339    BIT_CONVERT,
340
341    // FNEG, FABS, FSQRT, FSIN, FCOS - Perform unary floating point negation,
342    // absolute value, square root, sine and cosine operations.
343    FNEG, FABS, FSQRT, FSIN, FCOS,
344
345    // Other operators.  LOAD and STORE have token chains as their first
346    // operand, then the same operands as an LLVM load/store instruction, then a
347    // SRCVALUE node that provides alias analysis information.
348    LOAD, STORE,
349
350    // Abstract vector version of LOAD.  VLOAD has a constant element count as
351    // the first operand, followed by a value type node indicating the type of
352    // the elements, a token chain, a pointer operand, and a SRCVALUE node.
353    VLOAD,
354
355    // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators all load a value from
356    // memory and extend them to a larger value (e.g. load a byte into a word
357    // register).  All three of these have four operands, a token chain, a
358    // pointer to load from, a SRCVALUE for alias analysis, and a VALUETYPE node
359    // indicating the type to load.
360    //
361    // SEXTLOAD loads the integer operand and sign extends it to a larger
362    //          integer result type.
363    // ZEXTLOAD loads the integer operand and zero extends it to a larger
364    //          integer result type.
365    // EXTLOAD  is used for three things: floating point extending loads,
366    //          integer extending loads [the top bits are undefined], and vector
367    //          extending loads [load into low elt].
368    EXTLOAD, SEXTLOAD, ZEXTLOAD,
369
370    // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
371    // value and stores it to memory in one operation.  This can be used for
372    // either integer or floating point operands.  The first four operands of
373    // this are the same as a standard store.  The fifth is the ValueType to
374    // store it as (which will be smaller than the source value).
375    TRUNCSTORE,
376
377    // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
378    // to a specified boundary.  The first operand is the token chain, the
379    // second is the number of bytes to allocate, and the third is the alignment
380    // boundary.  The size is guaranteed to be a multiple of the stack
381    // alignment, and the alignment is guaranteed to be bigger than the stack
382    // alignment (if required) or 0 to get standard stack alignment.
383    DYNAMIC_STACKALLOC,
384
385    // Control flow instructions.  These all have token chains.
386
387    // BR - Unconditional branch.  The first operand is the chain
388    // operand, the second is the MBB to branch to.
389    BR,
390
391    // BRCOND - Conditional branch.  The first operand is the chain,
392    // the second is the condition, the third is the block to branch
393    // to if the condition is true.
394    BRCOND,
395
396    // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
397    // that the condition is represented as condition code, and two nodes to
398    // compare, rather than as a combined SetCC node.  The operands in order are
399    // chain, cc, lhs, rhs, block to branch to if condition is true.
400    BR_CC,
401
402    // RET - Return from function.  The first operand is the chain,
403    // and any subsequent operands are the return values for the
404    // function.  This operation can have variable number of operands.
405    RET,
406
407    // INLINEASM - Represents an inline asm block.  This node always has two
408    // return values: a chain and a flag result.  The inputs are as follows:
409    //   Operand #0   : Input chain.
410    //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
411    //   Operand #2n+2: A RegisterNode.
412    //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
413    //   Operand #last: Optional, an incoming flag.
414    INLINEASM,
415
416    // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
417    // value, the same type as the pointer type for the system, and an output
418    // chain.
419    STACKSAVE,
420
421    // STACKRESTORE has two operands, an input chain and a pointer to restore to
422    // it returns an output chain.
423    STACKRESTORE,
424
425    // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
426    // correspond to the operands of the LLVM intrinsic functions.  The only
427    // result is a token chain.  The alignment argument is guaranteed to be a
428    // Constant node.
429    MEMSET,
430    MEMMOVE,
431    MEMCPY,
432
433    // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
434    // a call sequence, and carry arbitrary information that target might want
435    // to know.  The first operand is a chain, the rest are specified by the
436    // target and not touched by the DAG optimizers.
437    CALLSEQ_START,  // Beginning of a call sequence
438    CALLSEQ_END,    // End of a call sequence
439
440    // VAARG - VAARG has three operands: an input chain, a pointer, and a
441    // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
442    VAARG,
443
444    // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
445    // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
446    // source.
447    VACOPY,
448
449    // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
450    // pointer, and a SRCVALUE.
451    VAEND, VASTART,
452
453    // SRCVALUE - This corresponds to a Value*, and is used to associate memory
454    // locations with their value.  This allows one use alias analysis
455    // information in the backend.
456    SRCVALUE,
457
458    // PCMARKER - This corresponds to the pcmarker intrinsic.
459    PCMARKER,
460
461    // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
462    // The only operand is a chain and a value and a chain are produced.  The
463    // value is the contents of the architecture specific cycle counter like
464    // register (or other high accuracy low latency clock source)
465    READCYCLECOUNTER,
466
467    // HANDLENODE node - Used as a handle for various purposes.
468    HANDLENODE,
469
470    // LOCATION - This node is used to represent a source location for debug
471    // info.  It takes token chain as input, then a line number, then a column
472    // number, then a filename, then a working dir.  It produces a token chain
473    // as output.
474    LOCATION,
475
476    // DEBUG_LOC - This node is used to represent source line information
477    // embedded in the code.  It takes a token chain as input, then a line
478    // number, then a column then a file id (provided by MachineDebugInfo.) It
479    // produces a token chain as output.
480    DEBUG_LOC,
481
482    // DEBUG_LABEL - This node is used to mark a location in the code where a
483    // label should be generated for use by the debug information.  It takes a
484    // token chain as input and then a unique id (provided by MachineDebugInfo.)
485    // It produces a token chain as output.
486    DEBUG_LABEL,
487
488    // BUILTIN_OP_END - This must be the last enum value in this list.
489    BUILTIN_OP_END
490  };
491
492  /// Node predicates
493
494  /// isBuildVectorAllOnes - Return true if the specified node is a
495  /// BUILD_VECTOR where all of the elements are ~0 or undef.
496  bool isBuildVectorAllOnes(const SDNode *N);
497
498  /// isBuildVectorAllZeros - Return true if the specified node is a
499  /// BUILD_VECTOR where all of the elements are 0 or undef.
500  bool isBuildVectorAllZeros(const SDNode *N);
501
502  //===--------------------------------------------------------------------===//
503  /// ISD::CondCode enum - These are ordered carefully to make the bitfields
504  /// below work out, when considering SETFALSE (something that never exists
505  /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
506  /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
507  /// to.  If the "N" column is 1, the result of the comparison is undefined if
508  /// the input is a NAN.
509  ///
510  /// All of these (except for the 'always folded ops') should be handled for
511  /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
512  /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
513  ///
514  /// Note that these are laid out in a specific order to allow bit-twiddling
515  /// to transform conditions.
516  enum CondCode {
517    // Opcode          N U L G E       Intuitive operation
518    SETFALSE,      //    0 0 0 0       Always false (always folded)
519    SETOEQ,        //    0 0 0 1       True if ordered and equal
520    SETOGT,        //    0 0 1 0       True if ordered and greater than
521    SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
522    SETOLT,        //    0 1 0 0       True if ordered and less than
523    SETOLE,        //    0 1 0 1       True if ordered and less than or equal
524    SETONE,        //    0 1 1 0       True if ordered and operands are unequal
525    SETO,          //    0 1 1 1       True if ordered (no nans)
526    SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
527    SETUEQ,        //    1 0 0 1       True if unordered or equal
528    SETUGT,        //    1 0 1 0       True if unordered or greater than
529    SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
530    SETULT,        //    1 1 0 0       True if unordered or less than
531    SETULE,        //    1 1 0 1       True if unordered, less than, or equal
532    SETUNE,        //    1 1 1 0       True if unordered or not equal
533    SETTRUE,       //    1 1 1 1       Always true (always folded)
534    // Don't care operations: undefined if the input is a nan.
535    SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
536    SETEQ,         //  1 X 0 0 1       True if equal
537    SETGT,         //  1 X 0 1 0       True if greater than
538    SETGE,         //  1 X 0 1 1       True if greater than or equal
539    SETLT,         //  1 X 1 0 0       True if less than
540    SETLE,         //  1 X 1 0 1       True if less than or equal
541    SETNE,         //  1 X 1 1 0       True if not equal
542    SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
543
544    SETCC_INVALID       // Marker value.
545  };
546
547  /// isSignedIntSetCC - Return true if this is a setcc instruction that
548  /// performs a signed comparison when used with integer operands.
549  inline bool isSignedIntSetCC(CondCode Code) {
550    return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
551  }
552
553  /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
554  /// performs an unsigned comparison when used with integer operands.
555  inline bool isUnsignedIntSetCC(CondCode Code) {
556    return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
557  }
558
559  /// isTrueWhenEqual - Return true if the specified condition returns true if
560  /// the two operands to the condition are equal.  Note that if one of the two
561  /// operands is a NaN, this value is meaningless.
562  inline bool isTrueWhenEqual(CondCode Cond) {
563    return ((int)Cond & 1) != 0;
564  }
565
566  /// getUnorderedFlavor - This function returns 0 if the condition is always
567  /// false if an operand is a NaN, 1 if the condition is always true if the
568  /// operand is a NaN, and 2 if the condition is undefined if the operand is a
569  /// NaN.
570  inline unsigned getUnorderedFlavor(CondCode Cond) {
571    return ((int)Cond >> 3) & 3;
572  }
573
574  /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
575  /// 'op' is a valid SetCC operation.
576  CondCode getSetCCInverse(CondCode Operation, bool isInteger);
577
578  /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
579  /// when given the operation for (X op Y).
580  CondCode getSetCCSwappedOperands(CondCode Operation);
581
582  /// getSetCCOrOperation - Return the result of a logical OR between different
583  /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
584  /// function returns SETCC_INVALID if it is not possible to represent the
585  /// resultant comparison.
586  CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
587
588  /// getSetCCAndOperation - Return the result of a logical AND between
589  /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
590  /// function returns SETCC_INVALID if it is not possible to represent the
591  /// resultant comparison.
592  CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
593}  // end llvm::ISD namespace
594
595
596//===----------------------------------------------------------------------===//
597/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
598/// values as the result of a computation.  Many nodes return multiple values,
599/// from loads (which define a token and a return value) to ADDC (which returns
600/// a result and a carry value), to calls (which may return an arbitrary number
601/// of values).
602///
603/// As such, each use of a SelectionDAG computation must indicate the node that
604/// computes it as well as which return value to use from that node.  This pair
605/// of information is represented with the SDOperand value type.
606///
607class SDOperand {
608public:
609  SDNode *Val;        // The node defining the value we are using.
610  unsigned ResNo;     // Which return value of the node we are using.
611
612  SDOperand() : Val(0) {}
613  SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
614
615  bool operator==(const SDOperand &O) const {
616    return Val == O.Val && ResNo == O.ResNo;
617  }
618  bool operator!=(const SDOperand &O) const {
619    return !operator==(O);
620  }
621  bool operator<(const SDOperand &O) const {
622    return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
623  }
624
625  SDOperand getValue(unsigned R) const {
626    return SDOperand(Val, R);
627  }
628
629  // isOperand - Return true if this node is an operand of N.
630  bool isOperand(SDNode *N) const;
631
632  /// getValueType - Return the ValueType of the referenced return value.
633  ///
634  inline MVT::ValueType getValueType() const;
635
636  // Forwarding methods - These forward to the corresponding methods in SDNode.
637  inline unsigned getOpcode() const;
638  inline unsigned getNodeDepth() const;
639  inline unsigned getNumOperands() const;
640  inline const SDOperand &getOperand(unsigned i) const;
641  inline bool isTargetOpcode() const;
642  inline unsigned getTargetOpcode() const;
643
644  /// hasOneUse - Return true if there is exactly one operation using this
645  /// result value of the defining operator.
646  inline bool hasOneUse() const;
647};
648
649
650/// simplify_type specializations - Allow casting operators to work directly on
651/// SDOperands as if they were SDNode*'s.
652template<> struct simplify_type<SDOperand> {
653  typedef SDNode* SimpleType;
654  static SimpleType getSimplifiedValue(const SDOperand &Val) {
655    return static_cast<SimpleType>(Val.Val);
656  }
657};
658template<> struct simplify_type<const SDOperand> {
659  typedef SDNode* SimpleType;
660  static SimpleType getSimplifiedValue(const SDOperand &Val) {
661    return static_cast<SimpleType>(Val.Val);
662  }
663};
664
665
666/// SDNode - Represents one node in the SelectionDAG.
667///
668class SDNode {
669  /// NodeType - The operation that this node performs.
670  ///
671  unsigned short NodeType;
672
673  /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1.  This
674  /// means that leaves have a depth of 1, things that use only leaves have a
675  /// depth of 2, etc.
676  unsigned short NodeDepth;
677
678  /// OperandList - The values that are used by this operation.
679  ///
680  SDOperand *OperandList;
681
682  /// ValueList - The types of the values this node defines.  SDNode's may
683  /// define multiple values simultaneously.
684  MVT::ValueType *ValueList;
685
686  /// NumOperands/NumValues - The number of entries in the Operand/Value list.
687  unsigned short NumOperands, NumValues;
688
689  /// Prev/Next pointers - These pointers form the linked list of of the
690  /// AllNodes list in the current DAG.
691  SDNode *Prev, *Next;
692  friend struct ilist_traits<SDNode>;
693
694  /// Uses - These are all of the SDNode's that use a value produced by this
695  /// node.
696  std::vector<SDNode*> Uses;
697public:
698  virtual ~SDNode() {
699    assert(NumOperands == 0 && "Operand list not cleared before deletion");
700  }
701
702  //===--------------------------------------------------------------------===//
703  //  Accessors
704  //
705  unsigned getOpcode()  const { return NodeType; }
706  bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
707  unsigned getTargetOpcode() const {
708    assert(isTargetOpcode() && "Not a target opcode!");
709    return NodeType - ISD::BUILTIN_OP_END;
710  }
711
712  size_t use_size() const { return Uses.size(); }
713  bool use_empty() const { return Uses.empty(); }
714  bool hasOneUse() const { return Uses.size() == 1; }
715
716  /// getNodeDepth - Return the distance from this node to the leaves in the
717  /// graph.  The leaves have a depth of 1.
718  unsigned getNodeDepth() const { return NodeDepth; }
719
720  typedef std::vector<SDNode*>::const_iterator use_iterator;
721  use_iterator use_begin() const { return Uses.begin(); }
722  use_iterator use_end() const { return Uses.end(); }
723
724  /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
725  /// indicated value.  This method ignores uses of other values defined by this
726  /// operation.
727  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
728
729  // isOnlyUse - Return true if this node is the only use of N.
730  bool isOnlyUse(SDNode *N) const;
731
732  // isOperand - Return true if this node is an operand of N.
733  bool isOperand(SDNode *N) const;
734
735  /// getNumOperands - Return the number of values used by this operation.
736  ///
737  unsigned getNumOperands() const { return NumOperands; }
738
739  const SDOperand &getOperand(unsigned Num) const {
740    assert(Num < NumOperands && "Invalid child # of SDNode!");
741    return OperandList[Num];
742  }
743  typedef const SDOperand* op_iterator;
744  op_iterator op_begin() const { return OperandList; }
745  op_iterator op_end() const { return OperandList+NumOperands; }
746
747
748  /// getNumValues - Return the number of values defined/returned by this
749  /// operator.
750  ///
751  unsigned getNumValues() const { return NumValues; }
752
753  /// getValueType - Return the type of a specified result.
754  ///
755  MVT::ValueType getValueType(unsigned ResNo) const {
756    assert(ResNo < NumValues && "Illegal result number!");
757    return ValueList[ResNo];
758  }
759
760  typedef const MVT::ValueType* value_iterator;
761  value_iterator value_begin() const { return ValueList; }
762  value_iterator value_end() const { return ValueList+NumValues; }
763
764  /// getOperationName - Return the opcode of this operation for printing.
765  ///
766  const char* getOperationName(const SelectionDAG *G = 0) const;
767  void dump() const;
768  void dump(const SelectionDAG *G) const;
769
770  static bool classof(const SDNode *) { return true; }
771
772protected:
773  friend class SelectionDAG;
774
775  /// getValueTypeList - Return a pointer to the specified value type.
776  ///
777  static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
778
779  SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) {
780    OperandList = 0; NumOperands = 0;
781    ValueList = getValueTypeList(VT);
782    NumValues = 1;
783    Prev = 0; Next = 0;
784  }
785  SDNode(unsigned NT, SDOperand Op)
786    : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) {
787    OperandList = new SDOperand[1];
788    OperandList[0] = Op;
789    NumOperands = 1;
790    Op.Val->Uses.push_back(this);
791    ValueList = 0;
792    NumValues = 0;
793    Prev = 0; Next = 0;
794  }
795  SDNode(unsigned NT, SDOperand N1, SDOperand N2)
796    : NodeType(NT) {
797    if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth())
798      NodeDepth = N1.Val->getNodeDepth()+1;
799    else
800      NodeDepth = N2.Val->getNodeDepth()+1;
801    OperandList = new SDOperand[2];
802    OperandList[0] = N1;
803    OperandList[1] = N2;
804    NumOperands = 2;
805    N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
806    ValueList = 0;
807    NumValues = 0;
808    Prev = 0; Next = 0;
809  }
810  SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
811    : NodeType(NT) {
812    unsigned ND = N1.Val->getNodeDepth();
813    if (ND < N2.Val->getNodeDepth())
814      ND = N2.Val->getNodeDepth();
815    if (ND < N3.Val->getNodeDepth())
816      ND = N3.Val->getNodeDepth();
817    NodeDepth = ND+1;
818
819    OperandList = new SDOperand[3];
820    OperandList[0] = N1;
821    OperandList[1] = N2;
822    OperandList[2] = N3;
823    NumOperands = 3;
824
825    N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
826    N3.Val->Uses.push_back(this);
827    ValueList = 0;
828    NumValues = 0;
829    Prev = 0; Next = 0;
830  }
831  SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4)
832    : NodeType(NT) {
833    unsigned ND = N1.Val->getNodeDepth();
834    if (ND < N2.Val->getNodeDepth())
835      ND = N2.Val->getNodeDepth();
836    if (ND < N3.Val->getNodeDepth())
837      ND = N3.Val->getNodeDepth();
838    if (ND < N4.Val->getNodeDepth())
839      ND = N4.Val->getNodeDepth();
840    NodeDepth = ND+1;
841
842    OperandList = new SDOperand[4];
843    OperandList[0] = N1;
844    OperandList[1] = N2;
845    OperandList[2] = N3;
846    OperandList[3] = N4;
847    NumOperands = 4;
848
849    N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
850    N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this);
851    ValueList = 0;
852    NumValues = 0;
853    Prev = 0; Next = 0;
854  }
855  SDNode(unsigned Opc, const std::vector<SDOperand> &Nodes) : NodeType(Opc) {
856    NumOperands = Nodes.size();
857    OperandList = new SDOperand[NumOperands];
858
859    unsigned ND = 0;
860    for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
861      OperandList[i] = Nodes[i];
862      SDNode *N = OperandList[i].Val;
863      N->Uses.push_back(this);
864      if (ND < N->getNodeDepth()) ND = N->getNodeDepth();
865    }
866    NodeDepth = ND+1;
867    ValueList = 0;
868    NumValues = 0;
869    Prev = 0; Next = 0;
870  }
871
872  /// MorphNodeTo - This clears the return value and operands list, and sets the
873  /// opcode of the node to the specified value.  This should only be used by
874  /// the SelectionDAG class.
875  void MorphNodeTo(unsigned Opc) {
876    NodeType = Opc;
877    ValueList = 0;
878    NumValues = 0;
879
880    // Clear the operands list, updating used nodes to remove this from their
881    // use list.
882    for (op_iterator I = op_begin(), E = op_end(); I != E; ++I)
883      I->Val->removeUser(this);
884    delete [] OperandList;
885    OperandList = 0;
886    NumOperands = 0;
887  }
888
889  void setValueTypes(MVT::ValueType VT) {
890    assert(NumValues == 0 && "Should not have values yet!");
891    ValueList = getValueTypeList(VT);
892    NumValues = 1;
893  }
894  void setValueTypes(MVT::ValueType *List, unsigned NumVal) {
895    assert(NumValues == 0 && "Should not have values yet!");
896    ValueList = List;
897    NumValues = NumVal;
898  }
899
900  void setOperands(SDOperand Op0) {
901    assert(NumOperands == 0 && "Should not have operands yet!");
902    OperandList = new SDOperand[1];
903    OperandList[0] = Op0;
904    NumOperands = 1;
905    Op0.Val->Uses.push_back(this);
906  }
907  void setOperands(SDOperand Op0, SDOperand Op1) {
908    assert(NumOperands == 0 && "Should not have operands yet!");
909    OperandList = new SDOperand[2];
910    OperandList[0] = Op0;
911    OperandList[1] = Op1;
912    NumOperands = 2;
913    Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
914  }
915  void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) {
916    assert(NumOperands == 0 && "Should not have operands yet!");
917    OperandList = new SDOperand[3];
918    OperandList[0] = Op0;
919    OperandList[1] = Op1;
920    OperandList[2] = Op2;
921    NumOperands = 3;
922    Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
923    Op2.Val->Uses.push_back(this);
924  }
925  void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3) {
926    assert(NumOperands == 0 && "Should not have operands yet!");
927    OperandList = new SDOperand[4];
928    OperandList[0] = Op0;
929    OperandList[1] = Op1;
930    OperandList[2] = Op2;
931    OperandList[3] = Op3;
932    NumOperands = 4;
933    Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
934    Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
935  }
936  void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
937                   SDOperand Op4) {
938    assert(NumOperands == 0 && "Should not have operands yet!");
939    OperandList = new SDOperand[5];
940    OperandList[0] = Op0;
941    OperandList[1] = Op1;
942    OperandList[2] = Op2;
943    OperandList[3] = Op3;
944    OperandList[4] = Op4;
945    NumOperands = 5;
946    Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
947    Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
948    Op4.Val->Uses.push_back(this);
949  }
950  void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
951                   SDOperand Op4, SDOperand Op5) {
952    assert(NumOperands == 0 && "Should not have operands yet!");
953    OperandList = new SDOperand[6];
954    OperandList[0] = Op0;
955    OperandList[1] = Op1;
956    OperandList[2] = Op2;
957    OperandList[3] = Op3;
958    OperandList[4] = Op4;
959    OperandList[5] = Op5;
960    NumOperands = 6;
961    Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
962    Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
963    Op4.Val->Uses.push_back(this); Op5.Val->Uses.push_back(this);
964  }
965  void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
966                   SDOperand Op4, SDOperand Op5, SDOperand Op6) {
967    assert(NumOperands == 0 && "Should not have operands yet!");
968    OperandList = new SDOperand[7];
969    OperandList[0] = Op0;
970    OperandList[1] = Op1;
971    OperandList[2] = Op2;
972    OperandList[3] = Op3;
973    OperandList[4] = Op4;
974    OperandList[5] = Op5;
975    OperandList[6] = Op6;
976    NumOperands = 7;
977    Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
978    Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
979    Op4.Val->Uses.push_back(this); Op5.Val->Uses.push_back(this);
980    Op6.Val->Uses.push_back(this);
981  }
982  void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
983                   SDOperand Op4, SDOperand Op5, SDOperand Op6, SDOperand Op7) {
984    assert(NumOperands == 0 && "Should not have operands yet!");
985    OperandList = new SDOperand[8];
986    OperandList[0] = Op0;
987    OperandList[1] = Op1;
988    OperandList[2] = Op2;
989    OperandList[3] = Op3;
990    OperandList[4] = Op4;
991    OperandList[5] = Op5;
992    OperandList[6] = Op6;
993    OperandList[7] = Op7;
994    NumOperands = 8;
995    Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
996    Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
997    Op4.Val->Uses.push_back(this); Op5.Val->Uses.push_back(this);
998    Op6.Val->Uses.push_back(this); Op7.Val->Uses.push_back(this);
999  }
1000
1001  void addUser(SDNode *User) {
1002    Uses.push_back(User);
1003  }
1004  void removeUser(SDNode *User) {
1005    // Remove this user from the operand's use list.
1006    for (unsigned i = Uses.size(); ; --i) {
1007      assert(i != 0 && "Didn't find user!");
1008      if (Uses[i-1] == User) {
1009        Uses[i-1] = Uses.back();
1010        Uses.pop_back();
1011        return;
1012      }
1013    }
1014  }
1015};
1016
1017
1018// Define inline functions from the SDOperand class.
1019
1020inline unsigned SDOperand::getOpcode() const {
1021  return Val->getOpcode();
1022}
1023inline unsigned SDOperand::getNodeDepth() const {
1024  return Val->getNodeDepth();
1025}
1026inline MVT::ValueType SDOperand::getValueType() const {
1027  return Val->getValueType(ResNo);
1028}
1029inline unsigned SDOperand::getNumOperands() const {
1030  return Val->getNumOperands();
1031}
1032inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1033  return Val->getOperand(i);
1034}
1035inline bool SDOperand::isTargetOpcode() const {
1036  return Val->isTargetOpcode();
1037}
1038inline unsigned SDOperand::getTargetOpcode() const {
1039  return Val->getTargetOpcode();
1040}
1041inline bool SDOperand::hasOneUse() const {
1042  return Val->hasNUsesOfValue(1, ResNo);
1043}
1044
1045/// HandleSDNode - This class is used to form a handle around another node that
1046/// is persistant and is updated across invocations of replaceAllUsesWith on its
1047/// operand.  This node should be directly created by end-users and not added to
1048/// the AllNodes list.
1049class HandleSDNode : public SDNode {
1050public:
1051  HandleSDNode(SDOperand X) : SDNode(ISD::HANDLENODE, X) {}
1052  ~HandleSDNode() {
1053    MorphNodeTo(ISD::HANDLENODE);  // Drops operand uses.
1054  }
1055
1056  SDOperand getValue() const { return getOperand(0); }
1057};
1058
1059class StringSDNode : public SDNode {
1060  std::string Value;
1061protected:
1062  friend class SelectionDAG;
1063  StringSDNode(const std::string &val)
1064    : SDNode(ISD::STRING, MVT::Other), Value(val) {
1065  }
1066public:
1067  const std::string &getValue() const { return Value; }
1068  static bool classof(const StringSDNode *) { return true; }
1069  static bool classof(const SDNode *N) {
1070    return N->getOpcode() == ISD::STRING;
1071  }
1072};
1073
1074class ConstantSDNode : public SDNode {
1075  uint64_t Value;
1076protected:
1077  friend class SelectionDAG;
1078  ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1079    : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, VT), Value(val) {
1080  }
1081public:
1082
1083  uint64_t getValue() const { return Value; }
1084
1085  int64_t getSignExtended() const {
1086    unsigned Bits = MVT::getSizeInBits(getValueType(0));
1087    return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1088  }
1089
1090  bool isNullValue() const { return Value == 0; }
1091  bool isAllOnesValue() const {
1092    return Value == MVT::getIntVTBitMask(getValueType(0));
1093  }
1094
1095  static bool classof(const ConstantSDNode *) { return true; }
1096  static bool classof(const SDNode *N) {
1097    return N->getOpcode() == ISD::Constant ||
1098           N->getOpcode() == ISD::TargetConstant;
1099  }
1100};
1101
1102class ConstantFPSDNode : public SDNode {
1103  double Value;
1104protected:
1105  friend class SelectionDAG;
1106  ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1107    : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, VT),
1108      Value(val) {
1109  }
1110public:
1111
1112  double getValue() const { return Value; }
1113
1114  /// isExactlyValue - We don't rely on operator== working on double values, as
1115  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1116  /// As such, this method can be used to do an exact bit-for-bit comparison of
1117  /// two floating point values.
1118  bool isExactlyValue(double V) const;
1119
1120  static bool classof(const ConstantFPSDNode *) { return true; }
1121  static bool classof(const SDNode *N) {
1122    return N->getOpcode() == ISD::ConstantFP ||
1123           N->getOpcode() == ISD::TargetConstantFP;
1124  }
1125};
1126
1127class GlobalAddressSDNode : public SDNode {
1128  GlobalValue *TheGlobal;
1129  int Offset;
1130protected:
1131  friend class SelectionDAG;
1132  GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1133                      int o=0)
1134    : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT),
1135      Offset(o) {
1136    TheGlobal = const_cast<GlobalValue*>(GA);
1137  }
1138public:
1139
1140  GlobalValue *getGlobal() const { return TheGlobal; }
1141  int getOffset() const { return Offset; }
1142
1143  static bool classof(const GlobalAddressSDNode *) { return true; }
1144  static bool classof(const SDNode *N) {
1145    return N->getOpcode() == ISD::GlobalAddress ||
1146           N->getOpcode() == ISD::TargetGlobalAddress;
1147  }
1148};
1149
1150
1151class FrameIndexSDNode : public SDNode {
1152  int FI;
1153protected:
1154  friend class SelectionDAG;
1155  FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1156    : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, VT), FI(fi) {}
1157public:
1158
1159  int getIndex() const { return FI; }
1160
1161  static bool classof(const FrameIndexSDNode *) { return true; }
1162  static bool classof(const SDNode *N) {
1163    return N->getOpcode() == ISD::FrameIndex ||
1164           N->getOpcode() == ISD::TargetFrameIndex;
1165  }
1166};
1167
1168class ConstantPoolSDNode : public SDNode {
1169  Constant *C;
1170  int Offset;
1171  unsigned Alignment;
1172protected:
1173  friend class SelectionDAG;
1174  ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1175                     int o=0)
1176    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
1177      C(c), Offset(o), Alignment(0) {}
1178  ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1179                     unsigned Align)
1180    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
1181      C(c), Offset(o), Alignment(Align) {}
1182public:
1183
1184  Constant *get() const { return C; }
1185  int getOffset() const { return Offset; }
1186
1187  // Return the alignment of this constant pool object, which is either 0 (for
1188  // default alignment) or log2 of the desired value.
1189  unsigned getAlignment() const { return Alignment; }
1190
1191  static bool classof(const ConstantPoolSDNode *) { return true; }
1192  static bool classof(const SDNode *N) {
1193    return N->getOpcode() == ISD::ConstantPool ||
1194           N->getOpcode() == ISD::TargetConstantPool;
1195  }
1196};
1197
1198class BasicBlockSDNode : public SDNode {
1199  MachineBasicBlock *MBB;
1200protected:
1201  friend class SelectionDAG;
1202  BasicBlockSDNode(MachineBasicBlock *mbb)
1203    : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
1204public:
1205
1206  MachineBasicBlock *getBasicBlock() const { return MBB; }
1207
1208  static bool classof(const BasicBlockSDNode *) { return true; }
1209  static bool classof(const SDNode *N) {
1210    return N->getOpcode() == ISD::BasicBlock;
1211  }
1212};
1213
1214class SrcValueSDNode : public SDNode {
1215  const Value *V;
1216  int offset;
1217protected:
1218  friend class SelectionDAG;
1219  SrcValueSDNode(const Value* v, int o)
1220    : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {}
1221
1222public:
1223  const Value *getValue() const { return V; }
1224  int getOffset() const { return offset; }
1225
1226  static bool classof(const SrcValueSDNode *) { return true; }
1227  static bool classof(const SDNode *N) {
1228    return N->getOpcode() == ISD::SRCVALUE;
1229  }
1230};
1231
1232
1233class RegisterSDNode : public SDNode {
1234  unsigned Reg;
1235protected:
1236  friend class SelectionDAG;
1237  RegisterSDNode(unsigned reg, MVT::ValueType VT)
1238    : SDNode(ISD::Register, VT), Reg(reg) {}
1239public:
1240
1241  unsigned getReg() const { return Reg; }
1242
1243  static bool classof(const RegisterSDNode *) { return true; }
1244  static bool classof(const SDNode *N) {
1245    return N->getOpcode() == ISD::Register;
1246  }
1247};
1248
1249class ExternalSymbolSDNode : public SDNode {
1250  const char *Symbol;
1251protected:
1252  friend class SelectionDAG;
1253  ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1254    : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, VT),
1255      Symbol(Sym) {
1256    }
1257public:
1258
1259  const char *getSymbol() const { return Symbol; }
1260
1261  static bool classof(const ExternalSymbolSDNode *) { return true; }
1262  static bool classof(const SDNode *N) {
1263    return N->getOpcode() == ISD::ExternalSymbol ||
1264           N->getOpcode() == ISD::TargetExternalSymbol;
1265  }
1266};
1267
1268class CondCodeSDNode : public SDNode {
1269  ISD::CondCode Condition;
1270protected:
1271  friend class SelectionDAG;
1272  CondCodeSDNode(ISD::CondCode Cond)
1273    : SDNode(ISD::CONDCODE, MVT::Other), Condition(Cond) {
1274  }
1275public:
1276
1277  ISD::CondCode get() const { return Condition; }
1278
1279  static bool classof(const CondCodeSDNode *) { return true; }
1280  static bool classof(const SDNode *N) {
1281    return N->getOpcode() == ISD::CONDCODE;
1282  }
1283};
1284
1285/// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1286/// to parameterize some operations.
1287class VTSDNode : public SDNode {
1288  MVT::ValueType ValueType;
1289protected:
1290  friend class SelectionDAG;
1291  VTSDNode(MVT::ValueType VT)
1292    : SDNode(ISD::VALUETYPE, MVT::Other), ValueType(VT) {}
1293public:
1294
1295  MVT::ValueType getVT() const { return ValueType; }
1296
1297  static bool classof(const VTSDNode *) { return true; }
1298  static bool classof(const SDNode *N) {
1299    return N->getOpcode() == ISD::VALUETYPE;
1300  }
1301};
1302
1303
1304class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1305  SDNode *Node;
1306  unsigned Operand;
1307
1308  SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1309public:
1310  bool operator==(const SDNodeIterator& x) const {
1311    return Operand == x.Operand;
1312  }
1313  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1314
1315  const SDNodeIterator &operator=(const SDNodeIterator &I) {
1316    assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1317    Operand = I.Operand;
1318    return *this;
1319  }
1320
1321  pointer operator*() const {
1322    return Node->getOperand(Operand).Val;
1323  }
1324  pointer operator->() const { return operator*(); }
1325
1326  SDNodeIterator& operator++() {                // Preincrement
1327    ++Operand;
1328    return *this;
1329  }
1330  SDNodeIterator operator++(int) { // Postincrement
1331    SDNodeIterator tmp = *this; ++*this; return tmp;
1332  }
1333
1334  static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1335  static SDNodeIterator end  (SDNode *N) {
1336    return SDNodeIterator(N, N->getNumOperands());
1337  }
1338
1339  unsigned getOperand() const { return Operand; }
1340  const SDNode *getNode() const { return Node; }
1341};
1342
1343template <> struct GraphTraits<SDNode*> {
1344  typedef SDNode NodeType;
1345  typedef SDNodeIterator ChildIteratorType;
1346  static inline NodeType *getEntryNode(SDNode *N) { return N; }
1347  static inline ChildIteratorType child_begin(NodeType *N) {
1348    return SDNodeIterator::begin(N);
1349  }
1350  static inline ChildIteratorType child_end(NodeType *N) {
1351    return SDNodeIterator::end(N);
1352  }
1353};
1354
1355template<>
1356struct ilist_traits<SDNode> {
1357  static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1358  static SDNode *getNext(const SDNode *N) { return N->Next; }
1359
1360  static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1361  static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1362
1363  static SDNode *createSentinel() {
1364    return new SDNode(ISD::EntryToken, MVT::Other);
1365  }
1366  static void destroySentinel(SDNode *N) { delete N; }
1367  //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1368
1369
1370  void addNodeToList(SDNode *NTy) {}
1371  void removeNodeFromList(SDNode *NTy) {}
1372  void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1373                             const ilist_iterator<SDNode> &X,
1374                             const ilist_iterator<SDNode> &Y) {}
1375};
1376
1377} // end llvm namespace
1378
1379#endif
1380