SelectionDAGNodes.h revision 594d37e21aea4ef841d9ee5d9c328c4bf1c6bed7
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/Value.h"
23#include "llvm/ADT/FoldingSet.h"
24#include "llvm/ADT/GraphTraits.h"
25#include "llvm/ADT/iterator"
26#include "llvm/CodeGen/ValueTypes.h"
27#include "llvm/Support/DataTypes.h"
28#include <cassert>
29
30namespace llvm {
31
32class SelectionDAG;
33class GlobalValue;
34class MachineBasicBlock;
35class MachineConstantPoolValue;
36class SDNode;
37template <typename T> struct DenseMapKeyInfo;
38template <typename T> struct simplify_type;
39template <typename T> struct ilist_traits;
40template<typename NodeTy, typename Traits> class iplist;
41template<typename NodeTy> class ilist_iterator;
42
43/// SDVTList - This represents a list of ValueType's that has been intern'd by
44/// a SelectionDAG.  Instances of this simple value class are returned by
45/// SelectionDAG::getVTList(...).
46///
47struct SDVTList {
48  const MVT::ValueType *VTs;
49  unsigned short NumVTs;
50};
51
52/// ISD namespace - This namespace contains an enum which represents all of the
53/// SelectionDAG node types and value types.
54///
55namespace ISD {
56  namespace ParamFlags {
57  enum Flags {
58    NoFlagSet         = 0,
59    ZExt              = 1<<0,  ///< Parameter should be zero extended
60    ZExtOffs          = 0,
61    SExt              = 1<<1,  ///< Parameter should be sign extended
62    SExtOffs          = 1,
63    InReg             = 1<<2,  ///< Parameter should be passed in register
64    InRegOffs         = 2,
65    StructReturn      = 1<<3,  ///< Hidden struct-return pointer
66    StructReturnOffs  = 3,
67    ByVal             = 1<<4,  ///< Struct passed by value
68    ByValOffs         = 4,
69    Nest              = 1<<5,  ///< Parameter is nested function static chain
70    NestOffs          = 5,
71    ByValAlign        = 0xF << 6, //< The alignment of the struct
72    ByValAlignOffs    = 6,
73    ByValSize         = 0x1ffff << 10, //< The size of the struct
74    ByValSizeOffs     = 10,
75    OrigAlignment     = 0x1F<<27,
76    OrigAlignmentOffs = 27
77  };
78  }
79
80  //===--------------------------------------------------------------------===//
81  /// ISD::NodeType enum - This enum defines all of the operators valid in a
82  /// SelectionDAG.
83  ///
84  enum NodeType {
85    // DELETED_NODE - This is an illegal flag value that is used to catch
86    // errors.  This opcode is not a legal opcode for any node.
87    DELETED_NODE,
88
89    // EntryToken - This is the marker used to indicate the start of the region.
90    EntryToken,
91
92    // Token factor - This node takes multiple tokens as input and produces a
93    // single token result.  This is used to represent the fact that the operand
94    // operators are independent of each other.
95    TokenFactor,
96
97    // AssertSext, AssertZext - These nodes record if a register contains a
98    // value that has already been zero or sign extended from a narrower type.
99    // These nodes take two operands.  The first is the node that has already
100    // been extended, and the second is a value type node indicating the width
101    // of the extension
102    AssertSext, AssertZext,
103
104    // Various leaf nodes.
105    STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
106    Constant, ConstantFP,
107    GlobalAddress, GlobalTLSAddress, FrameIndex,
108    JumpTable, ConstantPool, ExternalSymbol,
109
110    // The address of the GOT
111    GLOBAL_OFFSET_TABLE,
112
113    // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
114    // llvm.returnaddress on the DAG.  These nodes take one operand, the index
115    // of the frame or return address to return.  An index of zero corresponds
116    // to the current function's frame or return address, an index of one to the
117    // parent's frame or return address, and so on.
118    FRAMEADDR, RETURNADDR,
119
120    // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
121    // first (possible) on-stack argument. This is needed for correct stack
122    // adjustment during unwind.
123    FRAME_TO_ARGS_OFFSET,
124
125    // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
126    // address of the exception block on entry to an landing pad block.
127    EXCEPTIONADDR,
128
129    // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
130    // the selection index of the exception thrown.
131    EHSELECTION,
132
133    // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
134    // 'eh_return' gcc dwarf builtin, which is used to return from
135    // exception. The general meaning is: adjust stack by OFFSET and pass
136    // execution to HANDLER. Many platform-related details also :)
137    EH_RETURN,
138
139    // TargetConstant* - Like Constant*, but the DAG does not do any folding or
140    // simplification of the constant.
141    TargetConstant,
142    TargetConstantFP,
143
144    // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
145    // anything else with this node, and this is valid in the target-specific
146    // dag, turning into a GlobalAddress operand.
147    TargetGlobalAddress,
148    TargetGlobalTLSAddress,
149    TargetFrameIndex,
150    TargetJumpTable,
151    TargetConstantPool,
152    TargetExternalSymbol,
153
154    /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
155    /// This node represents a target intrinsic function with no side effects.
156    /// The first operand is the ID number of the intrinsic from the
157    /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
158    /// node has returns the result of the intrinsic.
159    INTRINSIC_WO_CHAIN,
160
161    /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
162    /// This node represents a target intrinsic function with side effects that
163    /// returns a result.  The first operand is a chain pointer.  The second is
164    /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
165    /// operands to the intrinsic follow.  The node has two results, the result
166    /// of the intrinsic and an output chain.
167    INTRINSIC_W_CHAIN,
168
169    /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
170    /// This node represents a target intrinsic function with side effects that
171    /// does not return a result.  The first operand is a chain pointer.  The
172    /// second is the ID number of the intrinsic from the llvm::Intrinsic
173    /// namespace.  The operands to the intrinsic follow.
174    INTRINSIC_VOID,
175
176    // CopyToReg - This node has three operands: a chain, a register number to
177    // set to this value, and a value.
178    CopyToReg,
179
180    // CopyFromReg - This node indicates that the input value is a virtual or
181    // physical register that is defined outside of the scope of this
182    // SelectionDAG.  The register is available from the RegSDNode object.
183    CopyFromReg,
184
185    // UNDEF - An undefined node
186    UNDEF,
187
188    /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
189    /// represents the formal arguments for a function.  CC# is a Constant value
190    /// indicating the calling convention of the function, and ISVARARG is a
191    /// flag that indicates whether the function is varargs or not. This node
192    /// has one result value for each incoming argument, plus one for the output
193    /// chain. It must be custom legalized. See description of CALL node for
194    /// FLAG argument contents explanation.
195    ///
196    FORMAL_ARGUMENTS,
197
198    /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
199    ///                              ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
200    /// This node represents a fully general function call, before the legalizer
201    /// runs.  This has one result value for each argument / flag pair, plus
202    /// a chain result. It must be custom legalized. Flag argument indicates
203    /// misc. argument attributes. Currently:
204    /// Bit 0 - signness
205    /// Bit 1 - 'inreg' attribute
206    /// Bit 2 - 'sret' attribute
207    /// Bit 4 - 'byval' attribute
208    /// Bit 5 - 'nest' attribute
209    /// Bit 6-9 - alignment of byval structures
210    /// Bit 10-26 - size of byval structures
211    /// Bits 31:27 - argument ABI alignment in the first argument piece and
212    /// alignment '1' in other argument pieces.
213    CALL,
214
215    // EXTRACT_ELEMENT - This is used to get the first or second (determined by
216    // a Constant, which is required to be operand #1), element of the aggregate
217    // value specified as operand #0.  This is only for use before legalization,
218    // for values that will be broken into multiple registers.
219    EXTRACT_ELEMENT,
220
221    // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
222    // two values of the same integer value type, this produces a value twice as
223    // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
224    BUILD_PAIR,
225
226    // MERGE_VALUES - This node takes multiple discrete operands and returns
227    // them all as its individual results.  This nodes has exactly the same
228    // number of inputs and outputs, and is only valid before legalization.
229    // This node is useful for some pieces of the code generator that want to
230    // think about a single node with multiple results, not multiple nodes.
231    MERGE_VALUES,
232
233    // Simple integer binary arithmetic operators.
234    ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
235
236    // CARRY_FALSE - This node is used when folding other nodes,
237    // like ADDC/SUBC, which indicate the carry result is always false.
238    CARRY_FALSE,
239
240    // Carry-setting nodes for multiple precision addition and subtraction.
241    // These nodes take two operands of the same value type, and produce two
242    // results.  The first result is the normal add or sub result, the second
243    // result is the carry flag result.
244    ADDC, SUBC,
245
246    // Carry-using nodes for multiple precision addition and subtraction.  These
247    // nodes take three operands: The first two are the normal lhs and rhs to
248    // the add or sub, and the third is the input carry flag.  These nodes
249    // produce two results; the normal result of the add or sub, and the output
250    // carry flag.  These nodes both read and write a carry flag to allow them
251    // to them to be chained together for add and sub of arbitrarily large
252    // values.
253    ADDE, SUBE,
254
255    // Simple binary floating point operators.
256    FADD, FSUB, FMUL, FDIV, FREM,
257
258    // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
259    // DAG node does not require that X and Y have the same type, just that they
260    // are both floating point.  X and the result must have the same type.
261    // FCOPYSIGN(f32, f64) is allowed.
262    FCOPYSIGN,
263
264    /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
265    /// with the specified, possibly variable, elements.  The number of elements
266    /// is required to be a power of two.
267    BUILD_VECTOR,
268
269    /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
270    /// at IDX replaced with VAL.
271    INSERT_VECTOR_ELT,
272
273    /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
274    /// identified by the (potentially variable) element number IDX.
275    EXTRACT_VECTOR_ELT,
276
277    /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
278    /// vector type with the same length and element type, this produces a
279    /// concatenated vector result value, with length equal to the sum of the
280    /// lengths of the input vectors.
281    CONCAT_VECTORS,
282
283    /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
284    /// vector value) starting with the (potentially variable) element number
285    /// IDX, which must be a multiple of the result vector length.
286    EXTRACT_SUBVECTOR,
287
288    /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
289    /// type as VEC1/VEC2.  SHUFFLEVEC is a BUILD_VECTOR of constant int values
290    /// (regardless of whether its datatype is legal or not) that indicate
291    /// which value each result element will get.  The elements of VEC1/VEC2 are
292    /// enumerated in order.  This is quite similar to the Altivec 'vperm'
293    /// instruction, except that the indices must be constants and are in terms
294    /// of the element size of VEC1/VEC2, not in terms of bytes.
295    VECTOR_SHUFFLE,
296
297    /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
298    /// scalar value into the low element of the resultant vector type.  The top
299    /// elements of the vector are undefined.
300    SCALAR_TO_VECTOR,
301
302    // EXTRACT_SUBREG - This node is used to extract a sub-register value.
303    // This node takes a superreg and a constant sub-register index as operands.
304    EXTRACT_SUBREG,
305
306    // INSERT_SUBREG - This node is used to insert a sub-register value.
307    // This node takes a superreg, a subreg value, and a constant sub-register
308    // index as operands.
309    INSERT_SUBREG,
310
311    // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
312    // an unsigned/signed value of type i[2*n], then return the top part.
313    MULHU, MULHS,
314
315    // Bitwise operators - logical and, logical or, logical xor, shift left,
316    // shift right algebraic (shift in sign bits), shift right logical (shift in
317    // zeroes), rotate left, rotate right, and byteswap.
318    AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
319
320    // Counting operators
321    CTTZ, CTLZ, CTPOP,
322
323    // Select(COND, TRUEVAL, FALSEVAL)
324    SELECT,
325
326    // Select with condition operator - This selects between a true value and
327    // a false value (ops #2 and #3) based on the boolean result of comparing
328    // the lhs and rhs (ops #0 and #1) of a conditional expression with the
329    // condition code in op #4, a CondCodeSDNode.
330    SELECT_CC,
331
332    // SetCC operator - This evaluates to a boolean (i1) true value if the
333    // condition is true.  The operands to this are the left and right operands
334    // to compare (ops #0, and #1) and the condition code to compare them with
335    // (op #2) as a CondCodeSDNode.
336    SETCC,
337
338    // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
339    // integer shift operations, just like ADD/SUB_PARTS.  The operation
340    // ordering is:
341    //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
342    SHL_PARTS, SRA_PARTS, SRL_PARTS,
343
344    // Conversion operators.  These are all single input single output
345    // operations.  For all of these, the result type must be strictly
346    // wider or narrower (depending on the operation) than the source
347    // type.
348
349    // SIGN_EXTEND - Used for integer types, replicating the sign bit
350    // into new bits.
351    SIGN_EXTEND,
352
353    // ZERO_EXTEND - Used for integer types, zeroing the new bits.
354    ZERO_EXTEND,
355
356    // ANY_EXTEND - Used for integer types.  The high bits are undefined.
357    ANY_EXTEND,
358
359    // TRUNCATE - Completely drop the high bits.
360    TRUNCATE,
361
362    // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
363    // depends on the first letter) to floating point.
364    SINT_TO_FP,
365    UINT_TO_FP,
366
367    // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
368    // sign extend a small value in a large integer register (e.g. sign
369    // extending the low 8 bits of a 32-bit register to fill the top 24 bits
370    // with the 7th bit).  The size of the smaller type is indicated by the 1th
371    // operand, a ValueType node.
372    SIGN_EXTEND_INREG,
373
374    // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
375    // integer.
376    FP_TO_SINT,
377    FP_TO_UINT,
378
379    // FP_ROUND - Perform a rounding operation from the current
380    // precision down to the specified precision (currently always 64->32).
381    FP_ROUND,
382
383    // FP_ROUND_INREG - This operator takes a floating point register, and
384    // rounds it to a floating point value.  It then promotes it and returns it
385    // in a register of the same size.  This operation effectively just discards
386    // excess precision.  The type to round down to is specified by the 1th
387    // operation, a VTSDNode (currently always 64->32->64).
388    FP_ROUND_INREG,
389
390    // FP_EXTEND - Extend a smaller FP type into a larger FP type.
391    FP_EXTEND,
392
393    // BIT_CONVERT - Theis operator converts between integer and FP values, as
394    // if one was stored to memory as integer and the other was loaded from the
395    // same address (or equivalently for vector format conversions, etc).  The
396    // source and result are required to have the same bit size (e.g.
397    // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp
398    // conversions, but that is a noop, deleted by getNode().
399    BIT_CONVERT,
400
401    // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI - Perform unary floating point
402    // negation, absolute value, square root, sine and cosine, and powi
403    // operations.
404    FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI,
405
406    // LOAD and STORE have token chains as their first operand, then the same
407    // operands as an LLVM load/store instruction, then an offset node that
408    // is added / subtracted from the base pointer to form the address (for
409    // indexed memory ops).
410    LOAD, STORE,
411
412    // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
413    // value and stores it to memory in one operation.  This can be used for
414    // either integer or floating point operands.  The first four operands of
415    // this are the same as a standard store.  The fifth is the ValueType to
416    // store it as (which will be smaller than the source value).
417    TRUNCSTORE,
418
419    // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
420    // to a specified boundary.  This node always has two return values: a new
421    // stack pointer value and a chain. The first operand is the token chain,
422    // the second is the number of bytes to allocate, and the third is the
423    // alignment boundary.  The size is guaranteed to be a multiple of the stack
424    // alignment, and the alignment is guaranteed to be bigger than the stack
425    // alignment (if required) or 0 to get standard stack alignment.
426    DYNAMIC_STACKALLOC,
427
428    // Control flow instructions.  These all have token chains.
429
430    // BR - Unconditional branch.  The first operand is the chain
431    // operand, the second is the MBB to branch to.
432    BR,
433
434    // BRIND - Indirect branch.  The first operand is the chain, the second
435    // is the value to branch to, which must be of the same type as the target's
436    // pointer type.
437    BRIND,
438
439    // BR_JT - Jumptable branch. The first operand is the chain, the second
440    // is the jumptable index, the last one is the jumptable entry index.
441    BR_JT,
442
443    // BRCOND - Conditional branch.  The first operand is the chain,
444    // the second is the condition, the third is the block to branch
445    // to if the condition is true.
446    BRCOND,
447
448    // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
449    // that the condition is represented as condition code, and two nodes to
450    // compare, rather than as a combined SetCC node.  The operands in order are
451    // chain, cc, lhs, rhs, block to branch to if condition is true.
452    BR_CC,
453
454    // RET - Return from function.  The first operand is the chain,
455    // and any subsequent operands are pairs of return value and return value
456    // signness for the function.  This operation can have variable number of
457    // operands.
458    RET,
459
460    // INLINEASM - Represents an inline asm block.  This node always has two
461    // return values: a chain and a flag result.  The inputs are as follows:
462    //   Operand #0   : Input chain.
463    //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
464    //   Operand #2n+2: A RegisterNode.
465    //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
466    //   Operand #last: Optional, an incoming flag.
467    INLINEASM,
468
469    // LABEL - Represents a label in mid basic block used to track
470    // locations needed for debug and exception handling tables.  This node
471    // returns a chain.
472    //   Operand #0 : input chain.
473    //   Operand #1 : module unique number use to identify the label.
474    LABEL,
475
476    // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
477    // value, the same type as the pointer type for the system, and an output
478    // chain.
479    STACKSAVE,
480
481    // STACKRESTORE has two operands, an input chain and a pointer to restore to
482    // it returns an output chain.
483    STACKRESTORE,
484
485    // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
486    // correspond to the operands of the LLVM intrinsic functions.  The only
487    // result is a token chain.  The alignment argument is guaranteed to be a
488    // Constant node.
489    MEMSET,
490    MEMMOVE,
491    MEMCPY,
492
493    // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
494    // a call sequence, and carry arbitrary information that target might want
495    // to know.  The first operand is a chain, the rest are specified by the
496    // target and not touched by the DAG optimizers.
497    CALLSEQ_START,  // Beginning of a call sequence
498    CALLSEQ_END,    // End of a call sequence
499
500    // VAARG - VAARG has three operands: an input chain, a pointer, and a
501    // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
502    VAARG,
503
504    // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
505    // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
506    // source.
507    VACOPY,
508
509    // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
510    // pointer, and a SRCVALUE.
511    VAEND, VASTART,
512
513    // SRCVALUE - This corresponds to a Value*, and is used to associate memory
514    // locations with their value.  This allows one use alias analysis
515    // information in the backend.
516    SRCVALUE,
517
518    // PCMARKER - This corresponds to the pcmarker intrinsic.
519    PCMARKER,
520
521    // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
522    // The only operand is a chain and a value and a chain are produced.  The
523    // value is the contents of the architecture specific cycle counter like
524    // register (or other high accuracy low latency clock source)
525    READCYCLECOUNTER,
526
527    // HANDLENODE node - Used as a handle for various purposes.
528    HANDLENODE,
529
530    // LOCATION - This node is used to represent a source location for debug
531    // info.  It takes token chain as input, then a line number, then a column
532    // number, then a filename, then a working dir.  It produces a token chain
533    // as output.
534    LOCATION,
535
536    // DEBUG_LOC - This node is used to represent source line information
537    // embedded in the code.  It takes a token chain as input, then a line
538    // number, then a column then a file id (provided by MachineModuleInfo.) It
539    // produces a token chain as output.
540    DEBUG_LOC,
541
542    // ADJUST_TRAMP - This corresponds to the adjust_trampoline intrinsic.
543    // It takes a value as input and returns a value as output.
544    ADJUST_TRAMP,
545
546    // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
547    // It takes as input a token chain, the pointer to the trampoline,
548    // the pointer to the nested function, the pointer to pass for the
549    // 'nest' parameter, a SRCVALUE for the trampoline and another for
550    // the nested function (allowing targets to access the original
551    // Function*).  It produces a token chain as output.
552    TRAMPOLINE,
553
554    // BUILTIN_OP_END - This must be the last enum value in this list.
555    BUILTIN_OP_END
556  };
557
558  /// Node predicates
559
560  /// isBuildVectorAllOnes - Return true if the specified node is a
561  /// BUILD_VECTOR where all of the elements are ~0 or undef.
562  bool isBuildVectorAllOnes(const SDNode *N);
563
564  /// isBuildVectorAllZeros - Return true if the specified node is a
565  /// BUILD_VECTOR where all of the elements are 0 or undef.
566  bool isBuildVectorAllZeros(const SDNode *N);
567
568  //===--------------------------------------------------------------------===//
569  /// MemIndexedMode enum - This enum defines the load / store indexed
570  /// addressing modes.
571  ///
572  /// UNINDEXED    "Normal" load / store. The effective address is already
573  ///              computed and is available in the base pointer. The offset
574  ///              operand is always undefined. In addition to producing a
575  ///              chain, an unindexed load produces one value (result of the
576  ///              load); an unindexed store does not produces a value.
577  ///
578  /// PRE_INC      Similar to the unindexed mode where the effective address is
579  /// PRE_DEC      the value of the base pointer add / subtract the offset.
580  ///              It considers the computation as being folded into the load /
581  ///              store operation (i.e. the load / store does the address
582  ///              computation as well as performing the memory transaction).
583  ///              The base operand is always undefined. In addition to
584  ///              producing a chain, pre-indexed load produces two values
585  ///              (result of the load and the result of the address
586  ///              computation); a pre-indexed store produces one value (result
587  ///              of the address computation).
588  ///
589  /// POST_INC     The effective address is the value of the base pointer. The
590  /// POST_DEC     value of the offset operand is then added to / subtracted
591  ///              from the base after memory transaction. In addition to
592  ///              producing a chain, post-indexed load produces two values
593  ///              (the result of the load and the result of the base +/- offset
594  ///              computation); a post-indexed store produces one value (the
595  ///              the result of the base +/- offset computation).
596  ///
597  enum MemIndexedMode {
598    UNINDEXED = 0,
599    PRE_INC,
600    PRE_DEC,
601    POST_INC,
602    POST_DEC,
603    LAST_INDEXED_MODE
604  };
605
606  //===--------------------------------------------------------------------===//
607  /// LoadExtType enum - This enum defines the three variants of LOADEXT
608  /// (load with extension).
609  ///
610  /// SEXTLOAD loads the integer operand and sign extends it to a larger
611  ///          integer result type.
612  /// ZEXTLOAD loads the integer operand and zero extends it to a larger
613  ///          integer result type.
614  /// EXTLOAD  is used for three things: floating point extending loads,
615  ///          integer extending loads [the top bits are undefined], and vector
616  ///          extending loads [load into low elt].
617  ///
618  enum LoadExtType {
619    NON_EXTLOAD = 0,
620    EXTLOAD,
621    SEXTLOAD,
622    ZEXTLOAD,
623    LAST_LOADX_TYPE
624  };
625
626  //===--------------------------------------------------------------------===//
627  /// ISD::CondCode enum - These are ordered carefully to make the bitfields
628  /// below work out, when considering SETFALSE (something that never exists
629  /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
630  /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
631  /// to.  If the "N" column is 1, the result of the comparison is undefined if
632  /// the input is a NAN.
633  ///
634  /// All of these (except for the 'always folded ops') should be handled for
635  /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
636  /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
637  ///
638  /// Note that these are laid out in a specific order to allow bit-twiddling
639  /// to transform conditions.
640  enum CondCode {
641    // Opcode          N U L G E       Intuitive operation
642    SETFALSE,      //    0 0 0 0       Always false (always folded)
643    SETOEQ,        //    0 0 0 1       True if ordered and equal
644    SETOGT,        //    0 0 1 0       True if ordered and greater than
645    SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
646    SETOLT,        //    0 1 0 0       True if ordered and less than
647    SETOLE,        //    0 1 0 1       True if ordered and less than or equal
648    SETONE,        //    0 1 1 0       True if ordered and operands are unequal
649    SETO,          //    0 1 1 1       True if ordered (no nans)
650    SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
651    SETUEQ,        //    1 0 0 1       True if unordered or equal
652    SETUGT,        //    1 0 1 0       True if unordered or greater than
653    SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
654    SETULT,        //    1 1 0 0       True if unordered or less than
655    SETULE,        //    1 1 0 1       True if unordered, less than, or equal
656    SETUNE,        //    1 1 1 0       True if unordered or not equal
657    SETTRUE,       //    1 1 1 1       Always true (always folded)
658    // Don't care operations: undefined if the input is a nan.
659    SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
660    SETEQ,         //  1 X 0 0 1       True if equal
661    SETGT,         //  1 X 0 1 0       True if greater than
662    SETGE,         //  1 X 0 1 1       True if greater than or equal
663    SETLT,         //  1 X 1 0 0       True if less than
664    SETLE,         //  1 X 1 0 1       True if less than or equal
665    SETNE,         //  1 X 1 1 0       True if not equal
666    SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
667
668    SETCC_INVALID       // Marker value.
669  };
670
671  /// isSignedIntSetCC - Return true if this is a setcc instruction that
672  /// performs a signed comparison when used with integer operands.
673  inline bool isSignedIntSetCC(CondCode Code) {
674    return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
675  }
676
677  /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
678  /// performs an unsigned comparison when used with integer operands.
679  inline bool isUnsignedIntSetCC(CondCode Code) {
680    return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
681  }
682
683  /// isTrueWhenEqual - Return true if the specified condition returns true if
684  /// the two operands to the condition are equal.  Note that if one of the two
685  /// operands is a NaN, this value is meaningless.
686  inline bool isTrueWhenEqual(CondCode Cond) {
687    return ((int)Cond & 1) != 0;
688  }
689
690  /// getUnorderedFlavor - This function returns 0 if the condition is always
691  /// false if an operand is a NaN, 1 if the condition is always true if the
692  /// operand is a NaN, and 2 if the condition is undefined if the operand is a
693  /// NaN.
694  inline unsigned getUnorderedFlavor(CondCode Cond) {
695    return ((int)Cond >> 3) & 3;
696  }
697
698  /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
699  /// 'op' is a valid SetCC operation.
700  CondCode getSetCCInverse(CondCode Operation, bool isInteger);
701
702  /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
703  /// when given the operation for (X op Y).
704  CondCode getSetCCSwappedOperands(CondCode Operation);
705
706  /// getSetCCOrOperation - Return the result of a logical OR between different
707  /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
708  /// function returns SETCC_INVALID if it is not possible to represent the
709  /// resultant comparison.
710  CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
711
712  /// getSetCCAndOperation - Return the result of a logical AND between
713  /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
714  /// function returns SETCC_INVALID if it is not possible to represent the
715  /// resultant comparison.
716  CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
717}  // end llvm::ISD namespace
718
719
720//===----------------------------------------------------------------------===//
721/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
722/// values as the result of a computation.  Many nodes return multiple values,
723/// from loads (which define a token and a return value) to ADDC (which returns
724/// a result and a carry value), to calls (which may return an arbitrary number
725/// of values).
726///
727/// As such, each use of a SelectionDAG computation must indicate the node that
728/// computes it as well as which return value to use from that node.  This pair
729/// of information is represented with the SDOperand value type.
730///
731class SDOperand {
732public:
733  SDNode *Val;        // The node defining the value we are using.
734  unsigned ResNo;     // Which return value of the node we are using.
735
736  SDOperand() : Val(0), ResNo(0) {}
737  SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
738
739  bool operator==(const SDOperand &O) const {
740    return Val == O.Val && ResNo == O.ResNo;
741  }
742  bool operator!=(const SDOperand &O) const {
743    return !operator==(O);
744  }
745  bool operator<(const SDOperand &O) const {
746    return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
747  }
748
749  SDOperand getValue(unsigned R) const {
750    return SDOperand(Val, R);
751  }
752
753  // isOperand - Return true if this node is an operand of N.
754  bool isOperand(SDNode *N) const;
755
756  /// getValueType - Return the ValueType of the referenced return value.
757  ///
758  inline MVT::ValueType getValueType() const;
759
760  // Forwarding methods - These forward to the corresponding methods in SDNode.
761  inline unsigned getOpcode() const;
762  inline unsigned getNumOperands() const;
763  inline const SDOperand &getOperand(unsigned i) const;
764  inline uint64_t getConstantOperandVal(unsigned i) const;
765  inline bool isTargetOpcode() const;
766  inline unsigned getTargetOpcode() const;
767
768  /// hasOneUse - Return true if there is exactly one operation using this
769  /// result value of the defining operator.
770  inline bool hasOneUse() const;
771};
772
773
774template<> struct DenseMapKeyInfo<SDOperand> {
775  static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); }
776  static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);}
777  static unsigned getHashValue(const SDOperand &Val) {
778    return (unsigned)((uintptr_t)Val.Val >> 4) ^
779           (unsigned)((uintptr_t)Val.Val >> 9) + Val.ResNo;
780  }
781  static bool isPod() { return true; }
782};
783
784/// simplify_type specializations - Allow casting operators to work directly on
785/// SDOperands as if they were SDNode*'s.
786template<> struct simplify_type<SDOperand> {
787  typedef SDNode* SimpleType;
788  static SimpleType getSimplifiedValue(const SDOperand &Val) {
789    return static_cast<SimpleType>(Val.Val);
790  }
791};
792template<> struct simplify_type<const SDOperand> {
793  typedef SDNode* SimpleType;
794  static SimpleType getSimplifiedValue(const SDOperand &Val) {
795    return static_cast<SimpleType>(Val.Val);
796  }
797};
798
799
800/// SDNode - Represents one node in the SelectionDAG.
801///
802class SDNode : public FoldingSetNode {
803  /// NodeType - The operation that this node performs.
804  ///
805  unsigned short NodeType;
806
807  /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
808  /// then they will be delete[]'d when the node is destroyed.
809  bool OperandsNeedDelete : 1;
810
811  /// NodeId - Unique id per SDNode in the DAG.
812  int NodeId;
813
814  /// OperandList - The values that are used by this operation.
815  ///
816  SDOperand *OperandList;
817
818  /// ValueList - The types of the values this node defines.  SDNode's may
819  /// define multiple values simultaneously.
820  const MVT::ValueType *ValueList;
821
822  /// NumOperands/NumValues - The number of entries in the Operand/Value list.
823  unsigned short NumOperands, NumValues;
824
825  /// Prev/Next pointers - These pointers form the linked list of of the
826  /// AllNodes list in the current DAG.
827  SDNode *Prev, *Next;
828  friend struct ilist_traits<SDNode>;
829
830  /// Uses - These are all of the SDNode's that use a value produced by this
831  /// node.
832  SmallVector<SDNode*,3> Uses;
833
834  // Out-of-line virtual method to give class a home.
835  virtual void ANCHOR();
836public:
837  virtual ~SDNode() {
838    assert(NumOperands == 0 && "Operand list not cleared before deletion");
839    NodeType = ISD::DELETED_NODE;
840  }
841
842  //===--------------------------------------------------------------------===//
843  //  Accessors
844  //
845  unsigned getOpcode()  const { return NodeType; }
846  bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
847  unsigned getTargetOpcode() const {
848    assert(isTargetOpcode() && "Not a target opcode!");
849    return NodeType - ISD::BUILTIN_OP_END;
850  }
851
852  size_t use_size() const { return Uses.size(); }
853  bool use_empty() const { return Uses.empty(); }
854  bool hasOneUse() const { return Uses.size() == 1; }
855
856  /// getNodeId - Return the unique node id.
857  ///
858  int getNodeId() const { return NodeId; }
859
860  typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
861  use_iterator use_begin() const { return Uses.begin(); }
862  use_iterator use_end() const { return Uses.end(); }
863
864  /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
865  /// indicated value.  This method ignores uses of other values defined by this
866  /// operation.
867  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
868
869  /// hasAnyUseOfValue - Return true if there are any use of the indicated
870  /// value. This method ignores uses of other values defined by this operation.
871  bool hasAnyUseOfValue(unsigned Value) const;
872
873  /// isOnlyUse - Return true if this node is the only use of N.
874  ///
875  bool isOnlyUse(SDNode *N) const;
876
877  /// isOperand - Return true if this node is an operand of N.
878  ///
879  bool isOperand(SDNode *N) const;
880
881  /// isPredecessor - Return true if this node is a predecessor of N. This node
882  /// is either an operand of N or it can be reached by recursively traversing
883  /// up the operands.
884  /// NOTE: this is an expensive method. Use it carefully.
885  bool isPredecessor(SDNode *N) const;
886
887  /// getNumOperands - Return the number of values used by this operation.
888  ///
889  unsigned getNumOperands() const { return NumOperands; }
890
891  /// getConstantOperandVal - Helper method returns the integer value of a
892  /// ConstantSDNode operand.
893  uint64_t getConstantOperandVal(unsigned Num) const;
894
895  const SDOperand &getOperand(unsigned Num) const {
896    assert(Num < NumOperands && "Invalid child # of SDNode!");
897    return OperandList[Num];
898  }
899
900  typedef const SDOperand* op_iterator;
901  op_iterator op_begin() const { return OperandList; }
902  op_iterator op_end() const { return OperandList+NumOperands; }
903
904
905  SDVTList getVTList() const {
906    SDVTList X = { ValueList, NumValues };
907    return X;
908  };
909
910  /// getNumValues - Return the number of values defined/returned by this
911  /// operator.
912  ///
913  unsigned getNumValues() const { return NumValues; }
914
915  /// getValueType - Return the type of a specified result.
916  ///
917  MVT::ValueType getValueType(unsigned ResNo) const {
918    assert(ResNo < NumValues && "Illegal result number!");
919    return ValueList[ResNo];
920  }
921
922  typedef const MVT::ValueType* value_iterator;
923  value_iterator value_begin() const { return ValueList; }
924  value_iterator value_end() const { return ValueList+NumValues; }
925
926  /// getOperationName - Return the opcode of this operation for printing.
927  ///
928  std::string getOperationName(const SelectionDAG *G = 0) const;
929  static const char* getIndexedModeName(ISD::MemIndexedMode AM);
930  void dump() const;
931  void dump(const SelectionDAG *G) const;
932
933  static bool classof(const SDNode *) { return true; }
934
935  /// Profile - Gather unique data for the node.
936  ///
937  void Profile(FoldingSetNodeID &ID);
938
939protected:
940  friend class SelectionDAG;
941
942  /// getValueTypeList - Return a pointer to the specified value type.
943  ///
944  static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
945  static SDVTList getSDVTList(MVT::ValueType VT) {
946    SDVTList Ret = { getValueTypeList(VT), 1 };
947    return Ret;
948  }
949
950  SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
951    : NodeType(Opc), NodeId(-1) {
952    OperandsNeedDelete = true;
953    NumOperands = NumOps;
954    OperandList = NumOps ? new SDOperand[NumOperands] : 0;
955
956    for (unsigned i = 0; i != NumOps; ++i) {
957      OperandList[i] = Ops[i];
958      Ops[i].Val->Uses.push_back(this);
959    }
960
961    ValueList = VTs.VTs;
962    NumValues = VTs.NumVTs;
963    Prev = 0; Next = 0;
964  }
965  SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) {
966    OperandsNeedDelete = false;  // Operands set with InitOperands.
967    NumOperands = 0;
968    OperandList = 0;
969
970    ValueList = VTs.VTs;
971    NumValues = VTs.NumVTs;
972    Prev = 0; Next = 0;
973  }
974
975  /// InitOperands - Initialize the operands list of this node with the
976  /// specified values, which are part of the node (thus they don't need to be
977  /// copied in or allocated).
978  void InitOperands(SDOperand *Ops, unsigned NumOps) {
979    assert(OperandList == 0 && "Operands already set!");
980    NumOperands = NumOps;
981    OperandList = Ops;
982
983    for (unsigned i = 0; i != NumOps; ++i)
984      Ops[i].Val->Uses.push_back(this);
985  }
986
987  /// MorphNodeTo - This frees the operands of the current node, resets the
988  /// opcode, types, and operands to the specified value.  This should only be
989  /// used by the SelectionDAG class.
990  void MorphNodeTo(unsigned Opc, SDVTList L,
991                   const SDOperand *Ops, unsigned NumOps);
992
993  void addUser(SDNode *User) {
994    Uses.push_back(User);
995  }
996  void removeUser(SDNode *User) {
997    // Remove this user from the operand's use list.
998    for (unsigned i = Uses.size(); ; --i) {
999      assert(i != 0 && "Didn't find user!");
1000      if (Uses[i-1] == User) {
1001        Uses[i-1] = Uses.back();
1002        Uses.pop_back();
1003        return;
1004      }
1005    }
1006  }
1007
1008  void setNodeId(int Id) {
1009    NodeId = Id;
1010  }
1011};
1012
1013
1014// Define inline functions from the SDOperand class.
1015
1016inline unsigned SDOperand::getOpcode() const {
1017  return Val->getOpcode();
1018}
1019inline MVT::ValueType SDOperand::getValueType() const {
1020  return Val->getValueType(ResNo);
1021}
1022inline unsigned SDOperand::getNumOperands() const {
1023  return Val->getNumOperands();
1024}
1025inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1026  return Val->getOperand(i);
1027}
1028inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1029  return Val->getConstantOperandVal(i);
1030}
1031inline bool SDOperand::isTargetOpcode() const {
1032  return Val->isTargetOpcode();
1033}
1034inline unsigned SDOperand::getTargetOpcode() const {
1035  return Val->getTargetOpcode();
1036}
1037inline bool SDOperand::hasOneUse() const {
1038  return Val->hasNUsesOfValue(1, ResNo);
1039}
1040
1041/// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
1042/// to allow co-allocation of node operands with the node itself.
1043class UnarySDNode : public SDNode {
1044  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1045  SDOperand Op;
1046public:
1047  UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
1048    : SDNode(Opc, VTs), Op(X) {
1049    InitOperands(&Op, 1);
1050  }
1051};
1052
1053/// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
1054/// to allow co-allocation of node operands with the node itself.
1055class BinarySDNode : public SDNode {
1056  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1057  SDOperand Ops[2];
1058public:
1059  BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
1060    : SDNode(Opc, VTs) {
1061    Ops[0] = X;
1062    Ops[1] = Y;
1063    InitOperands(Ops, 2);
1064  }
1065};
1066
1067/// TernarySDNode - This class is used for three-operand SDNodes. This is solely
1068/// to allow co-allocation of node operands with the node itself.
1069class TernarySDNode : public SDNode {
1070  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1071  SDOperand Ops[3];
1072public:
1073  TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
1074                SDOperand Z)
1075    : SDNode(Opc, VTs) {
1076    Ops[0] = X;
1077    Ops[1] = Y;
1078    Ops[2] = Z;
1079    InitOperands(Ops, 3);
1080  }
1081};
1082
1083
1084/// HandleSDNode - This class is used to form a handle around another node that
1085/// is persistant and is updated across invocations of replaceAllUsesWith on its
1086/// operand.  This node should be directly created by end-users and not added to
1087/// the AllNodes list.
1088class HandleSDNode : public SDNode {
1089  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1090  SDOperand Op;
1091public:
1092  explicit HandleSDNode(SDOperand X)
1093    : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) {
1094    InitOperands(&Op, 1);
1095  }
1096  ~HandleSDNode();
1097  SDOperand getValue() const { return Op; }
1098};
1099
1100class StringSDNode : public SDNode {
1101  std::string Value;
1102  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1103protected:
1104  friend class SelectionDAG;
1105  explicit StringSDNode(const std::string &val)
1106    : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
1107  }
1108public:
1109  const std::string &getValue() const { return Value; }
1110  static bool classof(const StringSDNode *) { return true; }
1111  static bool classof(const SDNode *N) {
1112    return N->getOpcode() == ISD::STRING;
1113  }
1114};
1115
1116class ConstantSDNode : public SDNode {
1117  uint64_t Value;
1118  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1119protected:
1120  friend class SelectionDAG;
1121  ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1122    : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1123      Value(val) {
1124  }
1125public:
1126
1127  uint64_t getValue() const { return Value; }
1128
1129  int64_t getSignExtended() const {
1130    unsigned Bits = MVT::getSizeInBits(getValueType(0));
1131    return ((int64_t)Value << (64-Bits)) >> (64-Bits);
1132  }
1133
1134  bool isNullValue() const { return Value == 0; }
1135  bool isAllOnesValue() const {
1136    return Value == MVT::getIntVTBitMask(getValueType(0));
1137  }
1138
1139  static bool classof(const ConstantSDNode *) { return true; }
1140  static bool classof(const SDNode *N) {
1141    return N->getOpcode() == ISD::Constant ||
1142           N->getOpcode() == ISD::TargetConstant;
1143  }
1144};
1145
1146class ConstantFPSDNode : public SDNode {
1147  double Value;
1148  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1149protected:
1150  friend class SelectionDAG;
1151  ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1152    : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1153             getSDVTList(VT)), Value(val) {
1154  }
1155public:
1156
1157  double getValue() const { return Value; }
1158
1159  /// isExactlyValue - We don't rely on operator== working on double values, as
1160  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1161  /// As such, this method can be used to do an exact bit-for-bit comparison of
1162  /// two floating point values.
1163  bool isExactlyValue(double V) const;
1164
1165  static bool classof(const ConstantFPSDNode *) { return true; }
1166  static bool classof(const SDNode *N) {
1167    return N->getOpcode() == ISD::ConstantFP ||
1168           N->getOpcode() == ISD::TargetConstantFP;
1169  }
1170};
1171
1172class GlobalAddressSDNode : public SDNode {
1173  GlobalValue *TheGlobal;
1174  int Offset;
1175  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1176protected:
1177  friend class SelectionDAG;
1178  GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1179                      int o = 0);
1180public:
1181
1182  GlobalValue *getGlobal() const { return TheGlobal; }
1183  int getOffset() const { return Offset; }
1184
1185  static bool classof(const GlobalAddressSDNode *) { return true; }
1186  static bool classof(const SDNode *N) {
1187    return N->getOpcode() == ISD::GlobalAddress ||
1188           N->getOpcode() == ISD::TargetGlobalAddress ||
1189           N->getOpcode() == ISD::GlobalTLSAddress ||
1190           N->getOpcode() == ISD::TargetGlobalTLSAddress;
1191  }
1192};
1193
1194class FrameIndexSDNode : public SDNode {
1195  int FI;
1196  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1197protected:
1198  friend class SelectionDAG;
1199  FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1200    : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1201      FI(fi) {
1202  }
1203public:
1204
1205  int getIndex() const { return FI; }
1206
1207  static bool classof(const FrameIndexSDNode *) { return true; }
1208  static bool classof(const SDNode *N) {
1209    return N->getOpcode() == ISD::FrameIndex ||
1210           N->getOpcode() == ISD::TargetFrameIndex;
1211  }
1212};
1213
1214class JumpTableSDNode : public SDNode {
1215  int JTI;
1216  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1217protected:
1218  friend class SelectionDAG;
1219  JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1220    : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1221      JTI(jti) {
1222  }
1223public:
1224
1225    int getIndex() const { return JTI; }
1226
1227  static bool classof(const JumpTableSDNode *) { return true; }
1228  static bool classof(const SDNode *N) {
1229    return N->getOpcode() == ISD::JumpTable ||
1230           N->getOpcode() == ISD::TargetJumpTable;
1231  }
1232};
1233
1234class ConstantPoolSDNode : public SDNode {
1235  union {
1236    Constant *ConstVal;
1237    MachineConstantPoolValue *MachineCPVal;
1238  } Val;
1239  int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1240  unsigned Alignment;
1241  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1242protected:
1243  friend class SelectionDAG;
1244  ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1245                     int o=0)
1246    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1247             getSDVTList(VT)), Offset(o), Alignment(0) {
1248    assert((int)Offset >= 0 && "Offset is too large");
1249    Val.ConstVal = c;
1250  }
1251  ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1252                     unsigned Align)
1253    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1254             getSDVTList(VT)), Offset(o), Alignment(Align) {
1255    assert((int)Offset >= 0 && "Offset is too large");
1256    Val.ConstVal = c;
1257  }
1258  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1259                     MVT::ValueType VT, int o=0)
1260    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1261             getSDVTList(VT)), Offset(o), Alignment(0) {
1262    assert((int)Offset >= 0 && "Offset is too large");
1263    Val.MachineCPVal = v;
1264    Offset |= 1 << (sizeof(unsigned)*8-1);
1265  }
1266  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1267                     MVT::ValueType VT, int o, unsigned Align)
1268    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1269             getSDVTList(VT)), Offset(o), Alignment(Align) {
1270    assert((int)Offset >= 0 && "Offset is too large");
1271    Val.MachineCPVal = v;
1272    Offset |= 1 << (sizeof(unsigned)*8-1);
1273  }
1274public:
1275
1276  bool isMachineConstantPoolEntry() const {
1277    return (int)Offset < 0;
1278  }
1279
1280  Constant *getConstVal() const {
1281    assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1282    return Val.ConstVal;
1283  }
1284
1285  MachineConstantPoolValue *getMachineCPVal() const {
1286    assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1287    return Val.MachineCPVal;
1288  }
1289
1290  int getOffset() const {
1291    return Offset & ~(1 << (sizeof(unsigned)*8-1));
1292  }
1293
1294  // Return the alignment of this constant pool object, which is either 0 (for
1295  // default alignment) or log2 of the desired value.
1296  unsigned getAlignment() const { return Alignment; }
1297
1298  const Type *getType() const;
1299
1300  static bool classof(const ConstantPoolSDNode *) { return true; }
1301  static bool classof(const SDNode *N) {
1302    return N->getOpcode() == ISD::ConstantPool ||
1303           N->getOpcode() == ISD::TargetConstantPool;
1304  }
1305};
1306
1307class BasicBlockSDNode : public SDNode {
1308  MachineBasicBlock *MBB;
1309  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1310protected:
1311  friend class SelectionDAG;
1312  explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1313    : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
1314  }
1315public:
1316
1317  MachineBasicBlock *getBasicBlock() const { return MBB; }
1318
1319  static bool classof(const BasicBlockSDNode *) { return true; }
1320  static bool classof(const SDNode *N) {
1321    return N->getOpcode() == ISD::BasicBlock;
1322  }
1323};
1324
1325class SrcValueSDNode : public SDNode {
1326  const Value *V;
1327  int offset;
1328  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1329protected:
1330  friend class SelectionDAG;
1331  SrcValueSDNode(const Value* v, int o)
1332    : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v), offset(o) {
1333  }
1334
1335public:
1336  const Value *getValue() const { return V; }
1337  int getOffset() const { return offset; }
1338
1339  static bool classof(const SrcValueSDNode *) { return true; }
1340  static bool classof(const SDNode *N) {
1341    return N->getOpcode() == ISD::SRCVALUE;
1342  }
1343};
1344
1345
1346class RegisterSDNode : public SDNode {
1347  unsigned Reg;
1348  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1349protected:
1350  friend class SelectionDAG;
1351  RegisterSDNode(unsigned reg, MVT::ValueType VT)
1352    : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
1353  }
1354public:
1355
1356  unsigned getReg() const { return Reg; }
1357
1358  static bool classof(const RegisterSDNode *) { return true; }
1359  static bool classof(const SDNode *N) {
1360    return N->getOpcode() == ISD::Register;
1361  }
1362};
1363
1364class ExternalSymbolSDNode : public SDNode {
1365  const char *Symbol;
1366  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1367protected:
1368  friend class SelectionDAG;
1369  ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1370    : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1371             getSDVTList(VT)), Symbol(Sym) {
1372  }
1373public:
1374
1375  const char *getSymbol() const { return Symbol; }
1376
1377  static bool classof(const ExternalSymbolSDNode *) { return true; }
1378  static bool classof(const SDNode *N) {
1379    return N->getOpcode() == ISD::ExternalSymbol ||
1380           N->getOpcode() == ISD::TargetExternalSymbol;
1381  }
1382};
1383
1384class CondCodeSDNode : public SDNode {
1385  ISD::CondCode Condition;
1386  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1387protected:
1388  friend class SelectionDAG;
1389  explicit CondCodeSDNode(ISD::CondCode Cond)
1390    : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
1391  }
1392public:
1393
1394  ISD::CondCode get() const { return Condition; }
1395
1396  static bool classof(const CondCodeSDNode *) { return true; }
1397  static bool classof(const SDNode *N) {
1398    return N->getOpcode() == ISD::CONDCODE;
1399  }
1400};
1401
1402/// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1403/// to parameterize some operations.
1404class VTSDNode : public SDNode {
1405  MVT::ValueType ValueType;
1406  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1407protected:
1408  friend class SelectionDAG;
1409  explicit VTSDNode(MVT::ValueType VT)
1410    : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
1411  }
1412public:
1413
1414  MVT::ValueType getVT() const { return ValueType; }
1415
1416  static bool classof(const VTSDNode *) { return true; }
1417  static bool classof(const SDNode *N) {
1418    return N->getOpcode() == ISD::VALUETYPE;
1419  }
1420};
1421
1422/// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1423///
1424class LoadSDNode : public SDNode {
1425  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1426  SDOperand Ops[3];
1427
1428  // AddrMode - unindexed, pre-indexed, post-indexed.
1429  ISD::MemIndexedMode AddrMode;
1430
1431  // ExtType - non-ext, anyext, sext, zext.
1432  ISD::LoadExtType ExtType;
1433
1434  // LoadedVT - VT of loaded value before extension.
1435  MVT::ValueType LoadedVT;
1436
1437  // SrcValue - Memory location for alias analysis.
1438  const Value *SrcValue;
1439
1440  // SVOffset - Memory location offset.
1441  int SVOffset;
1442
1443  // Alignment - Alignment of memory location in bytes.
1444  unsigned Alignment;
1445
1446  // IsVolatile - True if the load is volatile.
1447  bool IsVolatile;
1448protected:
1449  friend class SelectionDAG;
1450  LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
1451             ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
1452             const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1453    : SDNode(ISD::LOAD, VTs),
1454      AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
1455      Alignment(Align), IsVolatile(Vol) {
1456    Ops[0] = ChainPtrOff[0]; // Chain
1457    Ops[1] = ChainPtrOff[1]; // Ptr
1458    Ops[2] = ChainPtrOff[2]; // Off
1459    InitOperands(Ops, 3);
1460    assert(Align != 0 && "Loads should have non-zero aligment");
1461    assert((getOffset().getOpcode() == ISD::UNDEF ||
1462            AddrMode != ISD::UNINDEXED) &&
1463           "Only indexed load has a non-undef offset operand");
1464  }
1465public:
1466
1467  const SDOperand getChain() const { return getOperand(0); }
1468  const SDOperand getBasePtr() const { return getOperand(1); }
1469  const SDOperand getOffset() const { return getOperand(2); }
1470  ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1471  ISD::LoadExtType getExtensionType() const { return ExtType; }
1472  MVT::ValueType getLoadedVT() const { return LoadedVT; }
1473  const Value *getSrcValue() const { return SrcValue; }
1474  int getSrcValueOffset() const { return SVOffset; }
1475  unsigned getAlignment() const { return Alignment; }
1476  bool isVolatile() const { return IsVolatile; }
1477
1478  static bool classof(const LoadSDNode *) { return true; }
1479  static bool classof(const SDNode *N) {
1480    return N->getOpcode() == ISD::LOAD;
1481  }
1482};
1483
1484/// StoreSDNode - This class is used to represent ISD::STORE nodes.
1485///
1486class StoreSDNode : public SDNode {
1487  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1488  SDOperand Ops[4];
1489
1490  // AddrMode - unindexed, pre-indexed, post-indexed.
1491  ISD::MemIndexedMode AddrMode;
1492
1493  // IsTruncStore - True is the op does a truncation before store.
1494  bool IsTruncStore;
1495
1496  // StoredVT - VT of the value after truncation.
1497  MVT::ValueType StoredVT;
1498
1499  // SrcValue - Memory location for alias analysis.
1500  const Value *SrcValue;
1501
1502  // SVOffset - Memory location offset.
1503  int SVOffset;
1504
1505  // Alignment - Alignment of memory location in bytes.
1506  unsigned Alignment;
1507
1508  // IsVolatile - True if the store is volatile.
1509  bool IsVolatile;
1510protected:
1511  friend class SelectionDAG;
1512  StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
1513              ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
1514              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
1515    : SDNode(ISD::STORE, VTs),
1516      AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT), SrcValue(SV),
1517      SVOffset(O), Alignment(Align), IsVolatile(Vol) {
1518    Ops[0] = ChainValuePtrOff[0]; // Chain
1519    Ops[1] = ChainValuePtrOff[1]; // Value
1520    Ops[2] = ChainValuePtrOff[2]; // Ptr
1521    Ops[3] = ChainValuePtrOff[3]; // Off
1522    InitOperands(Ops, 4);
1523    assert(Align != 0 && "Stores should have non-zero aligment");
1524    assert((getOffset().getOpcode() == ISD::UNDEF ||
1525            AddrMode != ISD::UNINDEXED) &&
1526           "Only indexed store has a non-undef offset operand");
1527  }
1528public:
1529
1530  const SDOperand getChain() const { return getOperand(0); }
1531  const SDOperand getValue() const { return getOperand(1); }
1532  const SDOperand getBasePtr() const { return getOperand(2); }
1533  const SDOperand getOffset() const { return getOperand(3); }
1534  ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1535  bool isTruncatingStore() const { return IsTruncStore; }
1536  MVT::ValueType getStoredVT() const { return StoredVT; }
1537  const Value *getSrcValue() const { return SrcValue; }
1538  int getSrcValueOffset() const { return SVOffset; }
1539  unsigned getAlignment() const { return Alignment; }
1540  bool isVolatile() const { return IsVolatile; }
1541
1542  static bool classof(const StoreSDNode *) { return true; }
1543  static bool classof(const SDNode *N) {
1544    return N->getOpcode() == ISD::STORE;
1545  }
1546};
1547
1548
1549class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1550  SDNode *Node;
1551  unsigned Operand;
1552
1553  SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1554public:
1555  bool operator==(const SDNodeIterator& x) const {
1556    return Operand == x.Operand;
1557  }
1558  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1559
1560  const SDNodeIterator &operator=(const SDNodeIterator &I) {
1561    assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1562    Operand = I.Operand;
1563    return *this;
1564  }
1565
1566  pointer operator*() const {
1567    return Node->getOperand(Operand).Val;
1568  }
1569  pointer operator->() const { return operator*(); }
1570
1571  SDNodeIterator& operator++() {                // Preincrement
1572    ++Operand;
1573    return *this;
1574  }
1575  SDNodeIterator operator++(int) { // Postincrement
1576    SDNodeIterator tmp = *this; ++*this; return tmp;
1577  }
1578
1579  static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1580  static SDNodeIterator end  (SDNode *N) {
1581    return SDNodeIterator(N, N->getNumOperands());
1582  }
1583
1584  unsigned getOperand() const { return Operand; }
1585  const SDNode *getNode() const { return Node; }
1586};
1587
1588template <> struct GraphTraits<SDNode*> {
1589  typedef SDNode NodeType;
1590  typedef SDNodeIterator ChildIteratorType;
1591  static inline NodeType *getEntryNode(SDNode *N) { return N; }
1592  static inline ChildIteratorType child_begin(NodeType *N) {
1593    return SDNodeIterator::begin(N);
1594  }
1595  static inline ChildIteratorType child_end(NodeType *N) {
1596    return SDNodeIterator::end(N);
1597  }
1598};
1599
1600template<>
1601struct ilist_traits<SDNode> {
1602  static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1603  static SDNode *getNext(const SDNode *N) { return N->Next; }
1604
1605  static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1606  static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1607
1608  static SDNode *createSentinel() {
1609    return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
1610  }
1611  static void destroySentinel(SDNode *N) { delete N; }
1612  //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1613
1614
1615  void addNodeToList(SDNode *NTy) {}
1616  void removeNodeFromList(SDNode *NTy) {}
1617  void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1618                             const ilist_iterator<SDNode> &X,
1619                             const ilist_iterator<SDNode> &Y) {}
1620};
1621
1622namespace ISD {
1623  /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1624  /// load.
1625  inline bool isNON_EXTLoad(const SDNode *N) {
1626    return N->getOpcode() == ISD::LOAD &&
1627      cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1628  }
1629
1630  /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1631  ///
1632  inline bool isEXTLoad(const SDNode *N) {
1633    return N->getOpcode() == ISD::LOAD &&
1634      cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1635  }
1636
1637  /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1638  ///
1639  inline bool isSEXTLoad(const SDNode *N) {
1640    return N->getOpcode() == ISD::LOAD &&
1641      cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1642  }
1643
1644  /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1645  ///
1646  inline bool isZEXTLoad(const SDNode *N) {
1647    return N->getOpcode() == ISD::LOAD &&
1648      cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1649  }
1650
1651  /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
1652  ///
1653  inline bool isUNINDEXEDLoad(const SDNode *N) {
1654    return N->getOpcode() == ISD::LOAD &&
1655      cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1656  }
1657
1658  /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1659  /// store.
1660  inline bool isNON_TRUNCStore(const SDNode *N) {
1661    return N->getOpcode() == ISD::STORE &&
1662      !cast<StoreSDNode>(N)->isTruncatingStore();
1663  }
1664
1665  /// isTRUNCStore - Returns true if the specified node is a truncating
1666  /// store.
1667  inline bool isTRUNCStore(const SDNode *N) {
1668    return N->getOpcode() == ISD::STORE &&
1669      cast<StoreSDNode>(N)->isTruncatingStore();
1670  }
1671}
1672
1673
1674} // end llvm namespace
1675
1676#endif
1677