blob: f7c7535eb6369be3a692d79812a2eb47eef869f1 [file] [log] [blame]
Chris Lattner63b570d2005-01-07 07:45:27 +00001//===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
Misha Brukmanea61c352005-04-21 20:39:54 +00002//
Chris Lattner63b570d2005-01-07 07:45:27 +00003// 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.
Misha Brukmanea61c352005-04-21 20:39:54 +00007//
Chris Lattner63b570d2005-01-07 07:45:27 +00008//===----------------------------------------------------------------------===//
Misha Brukmanea61c352005-04-21 20:39:54 +00009//
Chris Lattner63b570d2005-01-07 07:45:27 +000010// 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
Andrew Lenharth2d86ea22005-04-27 20:10:01 +000022#include "llvm/Value.h"
Jim Laskey583bd472006-10-27 23:46:08 +000023#include "llvm/ADT/FoldingSet.h"
Chris Lattner1080b9e2005-01-10 23:05:53 +000024#include "llvm/ADT/GraphTraits.h"
Chris Lattner1080b9e2005-01-10 23:05:53 +000025#include "llvm/ADT/iterator"
Evan Chengd6594ae2006-09-12 21:00:35 +000026#include "llvm/CodeGen/ValueTypes.h"
Jeff Cohen39931a32005-01-07 19:21:49 +000027#include "llvm/Support/DataTypes.h"
Chris Lattner63b570d2005-01-07 07:45:27 +000028#include <cassert>
Chris Lattner63b570d2005-01-07 07:45:27 +000029
30namespace llvm {
31
32class SelectionDAG;
33class GlobalValue;
34class MachineBasicBlock;
Evan Chengd6594ae2006-09-12 21:00:35 +000035class MachineConstantPoolValue;
Chris Lattner63b570d2005-01-07 07:45:27 +000036class SDNode;
37template <typename T> struct simplify_type;
Chris Lattnerb80e2be2005-11-09 23:46:43 +000038template <typename T> struct ilist_traits;
39template<typename NodeTy, typename Traits> class iplist;
40template<typename NodeTy> class ilist_iterator;
Chris Lattner63b570d2005-01-07 07:45:27 +000041
Chris Lattner0b3e5252006-08-15 19:11:05 +000042/// SDVTList - This represents a list of ValueType's that has been intern'd by
43/// a SelectionDAG. Instances of this simple value class are returned by
44/// SelectionDAG::getVTList(...).
45///
46struct SDVTList {
47 const MVT::ValueType *VTs;
48 unsigned short NumVTs;
49};
50
51
Chris Lattner63b570d2005-01-07 07:45:27 +000052/// ISD namespace - This namespace contains an enum which represents all of the
53/// SelectionDAG node types and value types.
54///
55namespace ISD {
56 //===--------------------------------------------------------------------===//
57 /// ISD::NodeType enum - This enum defines all of the operators valid in a
58 /// SelectionDAG.
59 ///
60 enum NodeType {
Chris Lattner3258ed62006-05-27 00:40:15 +000061 // DELETED_NODE - This is an illegal flag value that is used to catch
62 // errors. This opcode is not a legal opcode for any node.
63 DELETED_NODE,
64
Chris Lattner8a496fc2005-01-13 17:58:35 +000065 // EntryToken - This is the marker used to indicate the start of the region.
66 EntryToken,
67
Reid Spencer8c4bde32005-08-27 19:06:05 +000068 // Token factor - This node takes multiple tokens as input and produces a
Chris Lattner8a496fc2005-01-13 17:58:35 +000069 // single token result. This is used to represent the fact that the operand
70 // operators are independent of each other.
71 TokenFactor,
Nate Begemanf7f3d322005-08-30 02:39:32 +000072
73 // AssertSext, AssertZext - These nodes record if a register contains a
74 // value that has already been zero or sign extended from a narrower type.
75 // These nodes take two operands. The first is the node that has already
76 // been extended, and the second is a value type node indicating the width
77 // of the extension
78 AssertSext, AssertZext,
Misha Brukmanea61c352005-04-21 20:39:54 +000079
Chris Lattner8a496fc2005-01-13 17:58:35 +000080 // Various leaf nodes.
Evan Cheng1ab7d852006-03-01 00:51:13 +000081 STRING, BasicBlock, VALUETYPE, CONDCODE, Register,
82 Constant, ConstantFP,
Nate Begeman37efe672006-04-22 18:53:45 +000083 GlobalAddress, FrameIndex, JumpTable, ConstantPool, ExternalSymbol,
Evan Cheng1ab7d852006-03-01 00:51:13 +000084
Andrew Lenharth82c3d8f2006-10-11 04:29:42 +000085 // The address of the GOT
86 GLOBAL_OFFSET_TABLE,
Andrew Lenharthbeec30e2006-09-24 19:45:58 +000087
Chris Lattnerac0d7232006-01-29 06:24:40 +000088 // TargetConstant* - Like Constant*, but the DAG does not do any folding or
89 // simplification of the constant.
Chris Lattner056f9f62005-08-17 00:33:30 +000090 TargetConstant,
Chris Lattnerac0d7232006-01-29 06:24:40 +000091 TargetConstantFP,
Chris Lattnerf6b18492005-08-19 22:31:34 +000092
93 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
94 // anything else with this node, and this is valid in the target-specific
95 // dag, turning into a GlobalAddress operand.
96 TargetGlobalAddress,
Chris Lattnerafb2dd42005-08-25 00:43:01 +000097 TargetFrameIndex,
Nate Begeman37efe672006-04-22 18:53:45 +000098 TargetJumpTable,
Chris Lattneraaaaf792005-08-25 05:02:41 +000099 TargetConstantPool,
Andrew Lenharth2a2de662005-10-23 03:40:17 +0000100 TargetExternalSymbol,
Chris Lattner72601ca2006-03-24 01:03:55 +0000101
Chris Lattneref8ef912006-03-28 00:39:06 +0000102 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
103 /// This node represents a target intrinsic function with no side effects.
104 /// The first operand is the ID number of the intrinsic from the
105 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The
106 /// node has returns the result of the intrinsic.
107 INTRINSIC_WO_CHAIN,
108
109 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
110 /// This node represents a target intrinsic function with side effects that
111 /// returns a result. The first operand is a chain pointer. The second is
112 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The
113 /// operands to the intrinsic follow. The node has two results, the result
114 /// of the intrinsic and an output chain.
115 INTRINSIC_W_CHAIN,
Chris Lattner63b570d2005-01-07 07:45:27 +0000116
Chris Lattneref8ef912006-03-28 00:39:06 +0000117 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
118 /// This node represents a target intrinsic function with side effects that
119 /// does not return a result. The first operand is a chain pointer. The
120 /// second is the ID number of the intrinsic from the llvm::Intrinsic
121 /// namespace. The operands to the intrinsic follow.
122 INTRINSIC_VOID,
123
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +0000124 // CopyToReg - This node has three operands: a chain, a register number to
125 // set to this value, and a value.
Chris Lattner63b570d2005-01-07 07:45:27 +0000126 CopyToReg,
127
128 // CopyFromReg - This node indicates that the input value is a virtual or
129 // physical register that is defined outside of the scope of this
Chris Lattner18c2f132005-01-13 20:50:02 +0000130 // SelectionDAG. The register is available from the RegSDNode object.
Chris Lattner63b570d2005-01-07 07:45:27 +0000131 CopyFromReg,
132
Nate Begemanfc1b1da2005-04-01 22:34:39 +0000133 // UNDEF - An undefined node
134 UNDEF,
Chris Lattner681ee1c2006-04-11 21:30:42 +0000135
Chris Lattnerc1a8ad72006-05-16 06:43:59 +0000136 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG) - This node represents the formal
Chris Lattner681ee1c2006-04-11 21:30:42 +0000137 /// arguments for a function. CC# is a Constant value indicating the
138 /// calling convention of the function, and ISVARARG is a flag that
139 /// indicates whether the function is varargs or not. This node has one
Chris Lattnerc1a8ad72006-05-16 06:43:59 +0000140 /// result value for each incoming argument, plus one for the output chain.
141 /// It must be custom legalized.
142 ///
Chris Lattner681ee1c2006-04-11 21:30:42 +0000143 FORMAL_ARGUMENTS,
Chris Lattner6c0bfc72006-05-16 22:52:27 +0000144
145 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
Evan Cheng9657eac2006-05-25 00:54:33 +0000146 /// ARG0, SIGN0, ARG1, SIGN1, ... ARGn, SIGNn)
Chris Lattner6c0bfc72006-05-16 22:52:27 +0000147 /// This node represents a fully general function call, before the legalizer
Evan Cheng9657eac2006-05-25 00:54:33 +0000148 /// runs. This has one result value for each argument / signness pair, plus
149 /// a chain result. It must be custom legalized.
Chris Lattner6c0bfc72006-05-16 22:52:27 +0000150 CALL,
Nate Begemanfc1b1da2005-04-01 22:34:39 +0000151
Chris Lattner63b570d2005-01-07 07:45:27 +0000152 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
153 // a Constant, which is required to be operand #1), element of the aggregate
154 // value specified as operand #0. This is only for use before legalization,
155 // for values that will be broken into multiple registers.
156 EXTRACT_ELEMENT,
157
158 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
159 // two values of the same integer value type, this produces a value twice as
160 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
161 BUILD_PAIR,
Chris Lattner006e3e32005-11-20 22:55:57 +0000162
163 // MERGE_VALUES - This node takes multiple discrete operands and returns
164 // them all as its individual results. This nodes has exactly the same
165 // number of inputs and outputs, and is only valid before legalization.
166 // This node is useful for some pieces of the code generator that want to
167 // think about a single node with multiple results, not multiple nodes.
168 MERGE_VALUES,
Chris Lattner63b570d2005-01-07 07:45:27 +0000169
Chris Lattner615c2d02005-09-28 22:29:58 +0000170 // Simple integer binary arithmetic operators.
Chris Lattnerbede0b72005-04-06 04:21:29 +0000171 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
Chris Lattner615c2d02005-09-28 22:29:58 +0000172
Nate Begeman551bf3f2006-02-17 05:43:56 +0000173 // Carry-setting nodes for multiple precision addition and subtraction.
174 // These nodes take two operands of the same value type, and produce two
175 // results. The first result is the normal add or sub result, the second
176 // result is the carry flag result.
177 ADDC, SUBC,
178
179 // Carry-using nodes for multiple precision addition and subtraction. These
180 // nodes take three operands: The first two are the normal lhs and rhs to
181 // the add or sub, and the third is the input carry flag. These nodes
182 // produce two results; the normal result of the add or sub, and the output
183 // carry flag. These nodes both read and write a carry flag to allow them
184 // to them to be chained together for add and sub of arbitrarily large
185 // values.
186 ADDE, SUBE,
187
Chris Lattner615c2d02005-09-28 22:29:58 +0000188 // Simple binary floating point operators.
189 FADD, FSUB, FMUL, FDIV, FREM,
Chris Lattner38bf3bf2006-03-05 05:06:40 +0000190
191 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This
192 // DAG node does not require that X and Y have the same type, just that they
193 // are both floating point. X and the result must have the same type.
194 // FCOPYSIGN(f32, f64) is allowed.
195 FCOPYSIGN,
Chris Lattnerfa984b62006-03-17 19:53:41 +0000196
Chris Lattner22232f62006-03-19 00:52:25 +0000197 /// VBUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,..., COUNT,TYPE) - Return a vector
198 /// with the specified, possibly variable, elements. The number of elements
199 /// is required to be a power of two.
200 VBUILD_VECTOR,
Chris Lattnerbede0b72005-04-06 04:21:29 +0000201
Chris Lattner22232f62006-03-19 00:52:25 +0000202 /// BUILD_VECTOR(ELT1, ELT2, ELT3, ELT4,...) - Return a vector
203 /// with the specified, possibly variable, elements. The number of elements
204 /// is required to be a power of two.
205 BUILD_VECTOR,
206
Chris Lattnerfa984b62006-03-17 19:53:41 +0000207 /// VINSERT_VECTOR_ELT(VECTOR, VAL, IDX, COUNT,TYPE) - Given a vector
208 /// VECTOR, an element ELEMENT, and a (potentially variable) index IDX,
209 /// return an vector with the specified element of VECTOR replaced with VAL.
210 /// COUNT and TYPE specify the type of vector, as is standard for V* nodes.
211 VINSERT_VECTOR_ELT,
212
Chris Lattner22232f62006-03-19 00:52:25 +0000213 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR (a legal packed
214 /// type) with the element at IDX replaced with VAL.
215 INSERT_VECTOR_ELT,
Chris Lattner4b8db6c2006-03-21 20:43:08 +0000216
217 /// VEXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
218 /// (an MVT::Vector value) identified by the (potentially variable) element
219 /// number IDX.
220 VEXTRACT_VECTOR_ELT,
221
222 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
223 /// (a legal packed type vector) identified by the (potentially variable)
224 /// element number IDX.
225 EXTRACT_VECTOR_ELT,
Chris Lattner22232f62006-03-19 00:52:25 +0000226
Chris Lattnereda6dfd2006-03-28 19:54:11 +0000227 /// VVECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC, COUNT,TYPE) - Returns a vector,
228 /// of the same type as VEC1/VEC2. SHUFFLEVEC is a VBUILD_VECTOR of
229 /// constant int values that indicate which value each result element will
230 /// get. The elements of VEC1/VEC2 are enumerated in order. This is quite
231 /// similar to the Altivec 'vperm' instruction, except that the indices must
232 /// be constants and are in terms of the element size of VEC1/VEC2, not in
233 /// terms of bytes.
234 VVECTOR_SHUFFLE,
235
Chris Lattner49c6d3e2006-03-19 23:42:51 +0000236 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
237 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values
238 /// (regardless of whether its datatype is legal or not) that indicate
239 /// which value each result element will get. The elements of VEC1/VEC2 are
240 /// enumerated in order. This is quite similar to the Altivec 'vperm'
241 /// instruction, except that the indices must be constants and are in terms
242 /// of the element size of VEC1/VEC2, not in terms of bytes.
243 VECTOR_SHUFFLE,
244
Chris Lattner762f2ae2006-03-22 19:56:46 +0000245 /// X = VBIT_CONVERT(Y) and X = VBIT_CONVERT(Y, COUNT,TYPE) - This node
246 /// represents a conversion from or to an ISD::Vector type.
247 ///
248 /// This is lowered to a BIT_CONVERT of the appropriate input/output types.
249 /// The input and output are required to have the same size and at least one
Chris Lattner313f13c2006-03-22 20:09:04 +0000250 /// is required to be a vector (if neither is a vector, just use
251 /// BIT_CONVERT).
Chris Lattner762f2ae2006-03-22 19:56:46 +0000252 ///
Chris Lattner313f13c2006-03-22 20:09:04 +0000253 /// If the result is a vector, this takes three operands (like any other
254 /// vector producer) which indicate the size and type of the vector result.
Chris Lattner762f2ae2006-03-22 19:56:46 +0000255 /// Otherwise it takes one input.
256 VBIT_CONVERT,
257
Chris Lattner22232f62006-03-19 00:52:25 +0000258 /// BINOP(LHS, RHS, COUNT,TYPE)
259 /// Simple abstract vector operators. Unlike the integer and floating point
260 /// binary operators, these nodes also take two additional operands:
261 /// a constant element count, and a value type node indicating the type of
262 /// the elements. The order is count, type, op0, op1. All vector opcodes,
263 /// including VLOAD and VConstant must currently have count and type as
264 /// their last two operands.
265 VADD, VSUB, VMUL, VSDIV, VUDIV,
266 VAND, VOR, VXOR,
Chris Lattner210721a2006-03-19 05:26:45 +0000267
Chris Lattner49027e62006-04-08 22:16:01 +0000268 /// VSELECT(COND,LHS,RHS, COUNT,TYPE) - Select for MVT::Vector values.
269 /// COND is a boolean value. This node return LHS if COND is true, RHS if
270 /// COND is false.
271 VSELECT,
272
Chris Lattner210721a2006-03-19 05:26:45 +0000273 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
274 /// scalar value into the low element of the resultant vector type. The top
275 /// elements of the vector are undefined.
276 SCALAR_TO_VECTOR,
277
Chris Lattnerbede0b72005-04-06 04:21:29 +0000278 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
279 // an unsigned/signed value of type i[2*n], then return the top part.
280 MULHU, MULHS,
Chris Lattner63b570d2005-01-07 07:45:27 +0000281
Nate Begeman35ef9132006-01-11 21:21:00 +0000282 // Bitwise operators - logical and, logical or, logical xor, shift left,
283 // shift right algebraic (shift in sign bits), shift right logical (shift in
284 // zeroes), rotate left, rotate right, and byteswap.
285 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
Chris Lattner63b570d2005-01-07 07:45:27 +0000286
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000287 // Counting operators
288 CTTZ, CTLZ, CTPOP,
289
Chris Lattnerfa984b62006-03-17 19:53:41 +0000290 // Select(COND, TRUEVAL, FALSEVAL)
Nate Begeman9373a812005-08-10 20:51:12 +0000291 SELECT,
292
293 // Select with condition operator - This selects between a true value and
294 // a false value (ops #2 and #3) based on the boolean result of comparing
295 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
296 // condition code in op #4, a CondCodeSDNode.
297 SELECT_CC,
Chris Lattner63b570d2005-01-07 07:45:27 +0000298
299 // SetCC operator - This evaluates to a boolean (i1) true value if the
Chris Lattner7cf7e3f2005-08-09 20:20:18 +0000300 // condition is true. The operands to this are the left and right operands
301 // to compare (ops #0, and #1) and the condition code to compare them with
302 // (op #2) as a CondCodeSDNode.
Chris Lattner63b570d2005-01-07 07:45:27 +0000303 SETCC,
304
Chris Lattner14c5b532005-04-02 03:30:33 +0000305 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
306 // integer shift operations, just like ADD/SUB_PARTS. The operation
307 // ordering is:
Chris Lattner6b8f2d62005-04-02 03:59:45 +0000308 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
Chris Lattner14c5b532005-04-02 03:30:33 +0000309 SHL_PARTS, SRA_PARTS, SRL_PARTS,
310
Chris Lattner63b570d2005-01-07 07:45:27 +0000311 // Conversion operators. These are all single input single output
312 // operations. For all of these, the result type must be strictly
313 // wider or narrower (depending on the operation) than the source
314 // type.
315
316 // SIGN_EXTEND - Used for integer types, replicating the sign bit
317 // into new bits.
318 SIGN_EXTEND,
319
320 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
321 ZERO_EXTEND,
322
Chris Lattner7e122db2005-09-02 00:14:40 +0000323 // ANY_EXTEND - Used for integer types. The high bits are undefined.
324 ANY_EXTEND,
325
Chris Lattner63b570d2005-01-07 07:45:27 +0000326 // TRUNCATE - Completely drop the high bits.
327 TRUNCATE,
328
Chris Lattner1645ed02005-01-08 08:08:49 +0000329 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
330 // depends on the first letter) to floating point.
331 SINT_TO_FP,
332 UINT_TO_FP,
333
Chris Lattnerea576102005-04-13 02:36:41 +0000334 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
335 // sign extend a small value in a large integer register (e.g. sign
336 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
Chris Lattner15e4b012005-07-10 00:07:11 +0000337 // with the 7th bit). The size of the smaller type is indicated by the 1th
338 // operand, a ValueType node.
Chris Lattner859157d2005-01-15 06:17:04 +0000339 SIGN_EXTEND_INREG,
Chris Lattner859157d2005-01-15 06:17:04 +0000340
Chris Lattner1645ed02005-01-08 08:08:49 +0000341 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
342 // integer.
343 FP_TO_SINT,
344 FP_TO_UINT,
345
Chris Lattner63b570d2005-01-07 07:45:27 +0000346 // FP_ROUND - Perform a rounding operation from the current
Chris Lattner859157d2005-01-15 06:17:04 +0000347 // precision down to the specified precision (currently always 64->32).
Chris Lattner63b570d2005-01-07 07:45:27 +0000348 FP_ROUND,
349
Chris Lattner859157d2005-01-15 06:17:04 +0000350 // FP_ROUND_INREG - This operator takes a floating point register, and
351 // rounds it to a floating point value. It then promotes it and returns it
352 // in a register of the same size. This operation effectively just discards
Chris Lattner15e4b012005-07-10 00:07:11 +0000353 // excess precision. The type to round down to is specified by the 1th
354 // operation, a VTSDNode (currently always 64->32->64).
Chris Lattner859157d2005-01-15 06:17:04 +0000355 FP_ROUND_INREG,
356
Chris Lattner63b570d2005-01-07 07:45:27 +0000357 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
358 FP_EXTEND,
359
Chris Lattner1ac1c4b2005-12-23 00:15:59 +0000360 // BIT_CONVERT - Theis operator converts between integer and FP values, as
361 // if one was stored to memory as integer and the other was loaded from the
Chris Lattner80f55ab2005-12-23 00:46:10 +0000362 // same address (or equivalently for vector format conversions, etc). The
363 // source and result are required to have the same bit size (e.g.
364 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp
365 // conversions, but that is a noop, deleted by getNode().
Chris Lattner1ac1c4b2005-12-23 00:15:59 +0000366 BIT_CONVERT,
367
Chris Lattnerdd2afb02006-09-09 05:55:44 +0000368 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI - Perform unary floating point
369 // negation, absolute value, square root, sine and cosine, and powi
370 // operations.
371 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI,
Chris Lattner38bf3bf2006-03-05 05:06:40 +0000372
Evan Cheng8862ef12006-10-26 21:52:24 +0000373 // LOAD and STORE have token chains as their first operand, then the same
374 // operands as an LLVM load/store instruction, then an offset node that
375 // is added / subtracted from the base pointer to form the address (for
376 // indexed memory ops).
Chris Lattner63b570d2005-01-07 07:45:27 +0000377 LOAD, STORE,
Nate Begeman5fbb5d22005-11-19 00:36:38 +0000378
Evan Cheng1ab7d852006-03-01 00:51:13 +0000379 // Abstract vector version of LOAD. VLOAD has a constant element count as
380 // the first operand, followed by a value type node indicating the type of
381 // the elements, a token chain, a pointer operand, and a SRCVALUE node.
Nate Begeman5fbb5d22005-11-19 00:36:38 +0000382 VLOAD,
Chris Lattner63b570d2005-01-07 07:45:27 +0000383
Chris Lattner1cff05c2005-01-14 22:07:46 +0000384 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
385 // value and stores it to memory in one operation. This can be used for
Chris Lattnerf7db8c62005-07-10 00:28:25 +0000386 // either integer or floating point operands. The first four operands of
387 // this are the same as a standard store. The fifth is the ValueType to
388 // store it as (which will be smaller than the source value).
Chris Lattner1cff05c2005-01-14 22:07:46 +0000389 TRUNCSTORE,
390
Chris Lattner63b570d2005-01-07 07:45:27 +0000391 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
392 // to a specified boundary. The first operand is the token chain, the
393 // second is the number of bytes to allocate, and the third is the alignment
Chris Lattner74fe0632005-08-29 22:48:32 +0000394 // boundary. The size is guaranteed to be a multiple of the stack
395 // alignment, and the alignment is guaranteed to be bigger than the stack
396 // alignment (if required) or 0 to get standard stack alignment.
Chris Lattner63b570d2005-01-07 07:45:27 +0000397 DYNAMIC_STACKALLOC,
398
399 // Control flow instructions. These all have token chains.
Misha Brukmanea61c352005-04-21 20:39:54 +0000400
Chris Lattner63b570d2005-01-07 07:45:27 +0000401 // BR - Unconditional branch. The first operand is the chain
402 // operand, the second is the MBB to branch to.
403 BR,
404
Nate Begeman37efe672006-04-22 18:53:45 +0000405 // BRIND - Indirect branch. The first operand is the chain, the second
406 // is the value to branch to, which must be of the same type as the target's
407 // pointer type.
408 BRIND,
Evan Chengc41cd9c2006-10-30 07:59:36 +0000409
410 // BR_JT - Jumptable branch. The first operand is the chain, the second
411 // is the jumptable index, the last one is the jumptable entry index.
412 BR_JT,
Nate Begeman37efe672006-04-22 18:53:45 +0000413
Chris Lattner63b570d2005-01-07 07:45:27 +0000414 // BRCOND - Conditional branch. The first operand is the chain,
415 // the second is the condition, the third is the block to branch
416 // to if the condition is true.
417 BRCOND,
418
Nate Begeman7cbd5252005-08-16 19:49:35 +0000419 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
420 // that the condition is represented as condition code, and two nodes to
421 // compare, rather than as a combined SetCC node. The operands in order are
422 // chain, cc, lhs, rhs, block to branch to if condition is true.
423 BR_CC,
424
Chris Lattner63b570d2005-01-07 07:45:27 +0000425 // RET - Return from function. The first operand is the chain,
Evan Cheng8e7d0562006-05-26 23:09:09 +0000426 // and any subsequent operands are pairs of return value and return value
427 // signness for the function. This operation can have variable number of
428 // operands.
Chris Lattner63b570d2005-01-07 07:45:27 +0000429 RET,
430
Chris Lattner7572eb82006-01-26 22:23:45 +0000431 // INLINEASM - Represents an inline asm block. This node always has two
432 // return values: a chain and a flag result. The inputs are as follows:
433 // Operand #0 : Input chain.
434 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string.
435 // Operand #2n+2: A RegisterNode.
436 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
437 // Operand #last: Optional, an incoming flag.
438 INLINEASM,
Chris Lattneref36aa72005-01-11 05:56:17 +0000439
Chris Lattner5a67afc2006-01-13 02:39:42 +0000440 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a
441 // value, the same type as the pointer type for the system, and an output
442 // chain.
443 STACKSAVE,
444
445 // STACKRESTORE has two operands, an input chain and a pointer to restore to
446 // it returns an output chain.
447 STACKRESTORE,
448
Chris Lattneref36aa72005-01-11 05:56:17 +0000449 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
450 // correspond to the operands of the LLVM intrinsic functions. The only
451 // result is a token chain. The alignment argument is guaranteed to be a
452 // Constant node.
453 MEMSET,
454 MEMMOVE,
455 MEMCPY,
Misha Brukmanea61c352005-04-21 20:39:54 +0000456
Chris Lattner16cd04d2005-05-12 23:24:06 +0000457 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
458 // a call sequence, and carry arbitrary information that target might want
459 // to know. The first operand is a chain, the rest are specified by the
460 // target and not touched by the DAG optimizers.
461 CALLSEQ_START, // Beginning of a call sequence
462 CALLSEQ_END, // End of a call sequence
Nate Begemanacc398c2006-01-25 18:21:52 +0000463
464 // VAARG - VAARG has three operands: an input chain, a pointer, and a
465 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain.
466 VAARG,
467
468 // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
469 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
470 // source.
471 VACOPY,
472
473 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
474 // pointer, and a SRCVALUE.
475 VAEND, VASTART,
Chris Lattner63b570d2005-01-07 07:45:27 +0000476
Chris Lattner21074f42005-05-09 20:21:27 +0000477 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
478 // locations with their value. This allows one use alias analysis
479 // information in the backend.
480 SRCVALUE,
481
Misha Brukmane3f570c2005-03-31 21:30:35 +0000482 // PCMARKER - This corresponds to the pcmarker intrinsic.
Andrew Lenharth95762122005-03-31 21:24:06 +0000483 PCMARKER,
Chris Lattner63b570d2005-01-07 07:45:27 +0000484
Andrew Lenharthaeef8fc2005-11-11 16:45:18 +0000485 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
Andrew Lenharth8b91c772005-11-11 22:48:54 +0000486 // The only operand is a chain and a value and a chain are produced. The
487 // value is the contents of the architecture specific cycle counter like
488 // register (or other high accuracy low latency clock source)
Andrew Lenharthaeef8fc2005-11-11 16:45:18 +0000489 READCYCLECOUNTER,
490
Chris Lattnerd623e952005-10-05 06:34:34 +0000491 // HANDLENODE node - Used as a handle for various purposes.
492 HANDLENODE,
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000493
Chris Lattner47725d02005-11-29 06:15:39 +0000494 // LOCATION - This node is used to represent a source location for debug
495 // info. It takes token chain as input, then a line number, then a column
496 // number, then a filename, then a working dir. It produces a token chain
497 // as output.
498 LOCATION,
499
Jim Laskeyf5395ce2005-12-16 22:45:29 +0000500 // DEBUG_LOC - This node is used to represent source line information
Jim Laskeyabf6d172006-01-05 01:25:28 +0000501 // embedded in the code. It takes a token chain as input, then a line
502 // number, then a column then a file id (provided by MachineDebugInfo.) It
503 // produces a token chain as output.
Jim Laskeyf5395ce2005-12-16 22:45:29 +0000504 DEBUG_LOC,
505
Jim Laskeyabf6d172006-01-05 01:25:28 +0000506 // DEBUG_LABEL - This node is used to mark a location in the code where a
507 // label should be generated for use by the debug information. It takes a
Jim Laskeydf0f6592006-01-05 01:53:28 +0000508 // token chain as input and then a unique id (provided by MachineDebugInfo.)
509 // It produces a token chain as output.
Jim Laskeyabf6d172006-01-05 01:25:28 +0000510 DEBUG_LABEL,
511
Chris Lattner63b570d2005-01-07 07:45:27 +0000512 // BUILTIN_OP_END - This must be the last enum value in this list.
Chris Lattner410354f2006-02-22 16:23:43 +0000513 BUILTIN_OP_END
Chris Lattner63b570d2005-01-07 07:45:27 +0000514 };
515
Chris Lattner322dcd32006-03-25 22:56:35 +0000516 /// Node predicates
517
Evan Chenga8df1662006-03-27 06:58:47 +0000518 /// isBuildVectorAllOnes - Return true if the specified node is a
Chris Lattner322dcd32006-03-25 22:56:35 +0000519 /// BUILD_VECTOR where all of the elements are ~0 or undef.
Evan Chenga8df1662006-03-27 06:58:47 +0000520 bool isBuildVectorAllOnes(const SDNode *N);
Evan Cheng4a147842006-03-26 09:50:58 +0000521
522 /// isBuildVectorAllZeros - Return true if the specified node is a
523 /// BUILD_VECTOR where all of the elements are 0 or undef.
524 bool isBuildVectorAllZeros(const SDNode *N);
Chris Lattner322dcd32006-03-25 22:56:35 +0000525
Chris Lattner63b570d2005-01-07 07:45:27 +0000526 //===--------------------------------------------------------------------===//
Evan Cheng144d8f02006-11-09 17:55:04 +0000527 /// MemIndexedMode enum - This enum defines the load / store indexed
528 /// addressing modes.
Evan Cheng24446e22006-10-09 20:55:20 +0000529 ///
530 /// UNINDEXED "Normal" load / store. The effective address is already
531 /// computed and is available in the base pointer. The offset
Evan Cheng81c38452006-10-10 01:44:58 +0000532 /// operand is always undefined. In addition to producing a
533 /// chain, an unindexed load produces one value (result of the
534 /// load); an unindexed store does not produces a value.
Evan Cheng24446e22006-10-09 20:55:20 +0000535 ///
Evan Cheng35acd302006-10-17 21:12:56 +0000536 /// PRE_INC Similar to the unindexed mode where the effective address is
Evan Cheng8862ef12006-10-26 21:52:24 +0000537 /// PRE_DEC the value of the base pointer add / subtract the offset.
538 /// It considers the computation as being folded into the load /
Evan Cheng24446e22006-10-09 20:55:20 +0000539 /// store operation (i.e. the load / store does the address
540 /// computation as well as performing the memory transaction).
Evan Cheng81c38452006-10-10 01:44:58 +0000541 /// The base operand is always undefined. In addition to
542 /// producing a chain, pre-indexed load produces two values
543 /// (result of the load and the result of the address
544 /// computation); a pre-indexed store produces one value (result
545 /// of the address computation).
Evan Cheng24446e22006-10-09 20:55:20 +0000546 ///
Evan Cheng35acd302006-10-17 21:12:56 +0000547 /// POST_INC The effective address is the value of the base pointer. The
Evan Cheng8862ef12006-10-26 21:52:24 +0000548 /// POST_DEC value of the offset operand is then added to / subtracted
549 /// from the base after memory transaction. In addition to
550 /// producing a chain, post-indexed load produces two values
551 /// (the result of the load and the result of the base +/- offset
552 /// computation); a post-indexed store produces one value (the
553 /// the result of the base +/- offset computation).
Evan Cheng24446e22006-10-09 20:55:20 +0000554 ///
Evan Cheng144d8f02006-11-09 17:55:04 +0000555 enum MemIndexedMode {
Evan Cheng24446e22006-10-09 20:55:20 +0000556 UNINDEXED = 0,
Evan Cheng35acd302006-10-17 21:12:56 +0000557 PRE_INC,
558 PRE_DEC,
559 POST_INC,
Evan Cheng144d8f02006-11-09 17:55:04 +0000560 POST_DEC,
561 LAST_INDEXED_MODE
Evan Cheng24446e22006-10-09 20:55:20 +0000562 };
563
564 //===--------------------------------------------------------------------===//
Evan Chengc5484282006-10-04 00:56:09 +0000565 /// LoadExtType enum - This enum defines the three variants of LOADEXT
566 /// (load with extension).
567 ///
Evan Cheng24446e22006-10-09 20:55:20 +0000568 /// SEXTLOAD loads the integer operand and sign extends it to a larger
569 /// integer result type.
570 /// ZEXTLOAD loads the integer operand and zero extends it to a larger
571 /// integer result type.
572 /// EXTLOAD is used for three things: floating point extending loads,
573 /// integer extending loads [the top bits are undefined], and vector
574 /// extending loads [load into low elt].
575 ///
Evan Chengc5484282006-10-04 00:56:09 +0000576 enum LoadExtType {
Evan Cheng24446e22006-10-09 20:55:20 +0000577 NON_EXTLOAD = 0,
Evan Chengc5484282006-10-04 00:56:09 +0000578 EXTLOAD,
579 SEXTLOAD,
580 ZEXTLOAD,
581 LAST_LOADX_TYPE
582 };
583
584 //===--------------------------------------------------------------------===//
Chris Lattner63b570d2005-01-07 07:45:27 +0000585 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
586 /// below work out, when considering SETFALSE (something that never exists
587 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
588 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
589 /// to. If the "N" column is 1, the result of the comparison is undefined if
590 /// the input is a NAN.
591 ///
592 /// All of these (except for the 'always folded ops') should be handled for
593 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
594 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
595 ///
596 /// Note that these are laid out in a specific order to allow bit-twiddling
597 /// to transform conditions.
598 enum CondCode {
599 // Opcode N U L G E Intuitive operation
600 SETFALSE, // 0 0 0 0 Always false (always folded)
601 SETOEQ, // 0 0 0 1 True if ordered and equal
602 SETOGT, // 0 0 1 0 True if ordered and greater than
603 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
604 SETOLT, // 0 1 0 0 True if ordered and less than
605 SETOLE, // 0 1 0 1 True if ordered and less than or equal
606 SETONE, // 0 1 1 0 True if ordered and operands are unequal
607 SETO, // 0 1 1 1 True if ordered (no nans)
608 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
609 SETUEQ, // 1 0 0 1 True if unordered or equal
610 SETUGT, // 1 0 1 0 True if unordered or greater than
611 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
612 SETULT, // 1 1 0 0 True if unordered or less than
Misha Brukmanea61c352005-04-21 20:39:54 +0000613 SETULE, // 1 1 0 1 True if unordered, less than, or equal
Chris Lattner63b570d2005-01-07 07:45:27 +0000614 SETUNE, // 1 1 1 0 True if unordered or not equal
615 SETTRUE, // 1 1 1 1 Always true (always folded)
616 // Don't care operations: undefined if the input is a nan.
617 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
618 SETEQ, // 1 X 0 0 1 True if equal
619 SETGT, // 1 X 0 1 0 True if greater than
620 SETGE, // 1 X 0 1 1 True if greater than or equal
621 SETLT, // 1 X 1 0 0 True if less than
Misha Brukmanea61c352005-04-21 20:39:54 +0000622 SETLE, // 1 X 1 0 1 True if less than or equal
Chris Lattner63b570d2005-01-07 07:45:27 +0000623 SETNE, // 1 X 1 1 0 True if not equal
624 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
625
Chris Lattner410354f2006-02-22 16:23:43 +0000626 SETCC_INVALID // Marker value.
Chris Lattner63b570d2005-01-07 07:45:27 +0000627 };
628
629 /// isSignedIntSetCC - Return true if this is a setcc instruction that
630 /// performs a signed comparison when used with integer operands.
631 inline bool isSignedIntSetCC(CondCode Code) {
632 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
633 }
634
635 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
636 /// performs an unsigned comparison when used with integer operands.
637 inline bool isUnsignedIntSetCC(CondCode Code) {
638 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
639 }
640
641 /// isTrueWhenEqual - Return true if the specified condition returns true if
642 /// the two operands to the condition are equal. Note that if one of the two
643 /// operands is a NaN, this value is meaningless.
644 inline bool isTrueWhenEqual(CondCode Cond) {
645 return ((int)Cond & 1) != 0;
646 }
647
648 /// getUnorderedFlavor - This function returns 0 if the condition is always
649 /// false if an operand is a NaN, 1 if the condition is always true if the
650 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
651 /// NaN.
652 inline unsigned getUnorderedFlavor(CondCode Cond) {
653 return ((int)Cond >> 3) & 3;
654 }
655
656 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
657 /// 'op' is a valid SetCC operation.
658 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
659
660 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
661 /// when given the operation for (X op Y).
662 CondCode getSetCCSwappedOperands(CondCode Operation);
663
664 /// getSetCCOrOperation - Return the result of a logical OR between different
665 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
666 /// function returns SETCC_INVALID if it is not possible to represent the
667 /// resultant comparison.
668 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
669
670 /// getSetCCAndOperation - Return the result of a logical AND between
671 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
672 /// function returns SETCC_INVALID if it is not possible to represent the
673 /// resultant comparison.
674 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
675} // end llvm::ISD namespace
676
677
678//===----------------------------------------------------------------------===//
679/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
680/// values as the result of a computation. Many nodes return multiple values,
681/// from loads (which define a token and a return value) to ADDC (which returns
682/// a result and a carry value), to calls (which may return an arbitrary number
683/// of values).
684///
685/// As such, each use of a SelectionDAG computation must indicate the node that
686/// computes it as well as which return value to use from that node. This pair
687/// of information is represented with the SDOperand value type.
688///
Chris Lattnerf26bc8e2005-01-08 19:52:31 +0000689class SDOperand {
690public:
Chris Lattner63b570d2005-01-07 07:45:27 +0000691 SDNode *Val; // The node defining the value we are using.
692 unsigned ResNo; // Which return value of the node we are using.
693
Reid Spencerace44db2006-04-12 16:44:15 +0000694 SDOperand() : Val(0), ResNo(0) {}
Chris Lattner63b570d2005-01-07 07:45:27 +0000695 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
696
697 bool operator==(const SDOperand &O) const {
698 return Val == O.Val && ResNo == O.ResNo;
699 }
700 bool operator!=(const SDOperand &O) const {
701 return !operator==(O);
702 }
703 bool operator<(const SDOperand &O) const {
704 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
705 }
706
707 SDOperand getValue(unsigned R) const {
708 return SDOperand(Val, R);
709 }
710
Evan Chengbfa284f2006-03-03 06:42:32 +0000711 // isOperand - Return true if this node is an operand of N.
712 bool isOperand(SDNode *N) const;
713
Chris Lattner63b570d2005-01-07 07:45:27 +0000714 /// getValueType - Return the ValueType of the referenced return value.
715 ///
716 inline MVT::ValueType getValueType() const;
Misha Brukmanea61c352005-04-21 20:39:54 +0000717
Chris Lattner63b570d2005-01-07 07:45:27 +0000718 // Forwarding methods - These forward to the corresponding methods in SDNode.
719 inline unsigned getOpcode() const;
720 inline unsigned getNumOperands() const;
721 inline const SDOperand &getOperand(unsigned i) const;
Evan Chengc5484282006-10-04 00:56:09 +0000722 inline uint64_t getConstantOperandVal(unsigned i) const;
Nate Begeman0f66a912005-08-17 23:44:54 +0000723 inline bool isTargetOpcode() const;
724 inline unsigned getTargetOpcode() const;
Chris Lattnera44f4ae2005-01-13 22:58:50 +0000725
726 /// hasOneUse - Return true if there is exactly one operation using this
727 /// result value of the defining operator.
728 inline bool hasOneUse() const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000729};
730
731
732/// simplify_type specializations - Allow casting operators to work directly on
733/// SDOperands as if they were SDNode*'s.
734template<> struct simplify_type<SDOperand> {
735 typedef SDNode* SimpleType;
736 static SimpleType getSimplifiedValue(const SDOperand &Val) {
737 return static_cast<SimpleType>(Val.Val);
738 }
739};
740template<> struct simplify_type<const SDOperand> {
741 typedef SDNode* SimpleType;
742 static SimpleType getSimplifiedValue(const SDOperand &Val) {
743 return static_cast<SimpleType>(Val.Val);
744 }
745};
746
747
748/// SDNode - Represents one node in the SelectionDAG.
749///
Jim Laskey583bd472006-10-27 23:46:08 +0000750class SDNode : public FoldingSetNode {
Chris Lattner0442fbf2005-01-21 21:39:38 +0000751 /// NodeType - The operation that this node performs.
752 ///
753 unsigned short NodeType;
754
Evan Chengb9ee9e62006-07-27 06:38:21 +0000755 /// NodeId - Unique id per SDNode in the DAG.
756 int NodeId;
Chris Lattner0442fbf2005-01-21 21:39:38 +0000757
Chris Lattnerf71e8432005-11-08 22:06:23 +0000758 /// OperandList - The values that are used by this operation.
Chris Lattner0442fbf2005-01-21 21:39:38 +0000759 ///
Chris Lattnerf71e8432005-11-08 22:06:23 +0000760 SDOperand *OperandList;
761
762 /// ValueList - The types of the values this node defines. SDNode's may
763 /// define multiple values simultaneously.
Chris Lattner2fa6d3b2006-08-14 23:31:51 +0000764 const MVT::ValueType *ValueList;
Chris Lattner63b570d2005-01-07 07:45:27 +0000765
Chris Lattnerf71e8432005-11-08 22:06:23 +0000766 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
767 unsigned short NumOperands, NumValues;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000768
769 /// Prev/Next pointers - These pointers form the linked list of of the
770 /// AllNodes list in the current DAG.
771 SDNode *Prev, *Next;
772 friend struct ilist_traits<SDNode>;
Chris Lattner63b570d2005-01-07 07:45:27 +0000773
774 /// Uses - These are all of the SDNode's that use a value produced by this
775 /// node.
Chris Lattner5892d472006-08-16 21:01:10 +0000776 SmallVector<SDNode*,3> Uses;
Chris Lattner917d2c92006-07-19 00:00:37 +0000777
778 // Out-of-line virtual method to give class a home.
779 virtual void ANCHOR();
Chris Lattner63b570d2005-01-07 07:45:27 +0000780public:
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000781 virtual ~SDNode() {
782 assert(NumOperands == 0 && "Operand list not cleared before deletion");
Chris Lattner3258ed62006-05-27 00:40:15 +0000783 NodeType = ISD::DELETED_NODE;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000784 }
785
Chris Lattner63b570d2005-01-07 07:45:27 +0000786 //===--------------------------------------------------------------------===//
787 // Accessors
788 //
789 unsigned getOpcode() const { return NodeType; }
Nate Begeman0f66a912005-08-17 23:44:54 +0000790 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
791 unsigned getTargetOpcode() const {
792 assert(isTargetOpcode() && "Not a target opcode!");
793 return NodeType - ISD::BUILTIN_OP_END;
794 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000795
796 size_t use_size() const { return Uses.size(); }
797 bool use_empty() const { return Uses.empty(); }
798 bool hasOneUse() const { return Uses.size() == 1; }
799
Evan Chengb9ee9e62006-07-27 06:38:21 +0000800 /// getNodeId - Return the unique node id.
801 ///
802 int getNodeId() const { return NodeId; }
Chris Lattner0442fbf2005-01-21 21:39:38 +0000803
Chris Lattner5892d472006-08-16 21:01:10 +0000804 typedef SmallVector<SDNode*,3>::const_iterator use_iterator;
Chris Lattner7ece3802005-01-17 02:24:59 +0000805 use_iterator use_begin() const { return Uses.begin(); }
806 use_iterator use_end() const { return Uses.end(); }
807
Chris Lattnerb18a2f82005-01-12 18:37:33 +0000808 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
809 /// indicated value. This method ignores uses of other values defined by this
810 /// operation.
Evan Cheng4ee62112006-02-05 06:29:23 +0000811 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
812
Evan Chenge6e97e62006-11-03 07:31:32 +0000813 /// isOnlyUse - Return true if this node is the only use of N.
814 ///
Evan Cheng4ee62112006-02-05 06:29:23 +0000815 bool isOnlyUse(SDNode *N) const;
Chris Lattnerb18a2f82005-01-12 18:37:33 +0000816
Evan Chenge6e97e62006-11-03 07:31:32 +0000817 /// isOperand - Return true if this node is an operand of N.
818 ///
Evan Cheng80d8eaa2006-03-03 06:24:54 +0000819 bool isOperand(SDNode *N) const;
820
Evan Chenge6e97e62006-11-03 07:31:32 +0000821 /// isPredecessor - Return true if this node is a predecessor of N. This node
822 /// is either an operand of N or it can be reached by recursively traversing
823 /// up the operands.
824 /// NOTE: this is an expensive method. Use it carefully.
Evan Cheng7ceebb42006-11-03 03:02:18 +0000825 bool isPredecessor(SDNode *N) const;
826
Chris Lattner63b570d2005-01-07 07:45:27 +0000827 /// getNumOperands - Return the number of values used by this operation.
828 ///
Chris Lattnerf71e8432005-11-08 22:06:23 +0000829 unsigned getNumOperands() const { return NumOperands; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000830
Evan Chengc5484282006-10-04 00:56:09 +0000831 /// getConstantOperandVal - Helper method returns the integer value of a
832 /// ConstantSDNode operand.
833 uint64_t getConstantOperandVal(unsigned Num) const;
834
Chris Lattner63b570d2005-01-07 07:45:27 +0000835 const SDOperand &getOperand(unsigned Num) const {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000836 assert(Num < NumOperands && "Invalid child # of SDNode!");
837 return OperandList[Num];
Chris Lattner63b570d2005-01-07 07:45:27 +0000838 }
Evan Chengc5484282006-10-04 00:56:09 +0000839
Chris Lattnerf71e8432005-11-08 22:06:23 +0000840 typedef const SDOperand* op_iterator;
841 op_iterator op_begin() const { return OperandList; }
842 op_iterator op_end() const { return OperandList+NumOperands; }
Chris Lattner50f5a512005-05-14 06:19:11 +0000843
Chris Lattner63b570d2005-01-07 07:45:27 +0000844
Chris Lattner0b3e5252006-08-15 19:11:05 +0000845 SDVTList getVTList() const {
846 SDVTList X = { ValueList, NumValues };
847 return X;
848 };
849
Chris Lattner63b570d2005-01-07 07:45:27 +0000850 /// getNumValues - Return the number of values defined/returned by this
851 /// operator.
852 ///
Chris Lattnerf71e8432005-11-08 22:06:23 +0000853 unsigned getNumValues() const { return NumValues; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000854
855 /// getValueType - Return the type of a specified result.
856 ///
857 MVT::ValueType getValueType(unsigned ResNo) const {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000858 assert(ResNo < NumValues && "Illegal result number!");
859 return ValueList[ResNo];
Chris Lattner63b570d2005-01-07 07:45:27 +0000860 }
Jeff Cohen9eb59ec2005-07-27 05:53:44 +0000861
Chris Lattnerf71e8432005-11-08 22:06:23 +0000862 typedef const MVT::ValueType* value_iterator;
863 value_iterator value_begin() const { return ValueList; }
864 value_iterator value_end() const { return ValueList+NumValues; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000865
Chris Lattner6e6e3ce2005-01-10 23:25:04 +0000866 /// getOperationName - Return the opcode of this operation for printing.
867 ///
Chris Lattnerefe58692005-08-16 18:32:18 +0000868 const char* getOperationName(const SelectionDAG *G = 0) const;
Evan Cheng144d8f02006-11-09 17:55:04 +0000869 static const char* getIndexedModeName(ISD::MemIndexedMode AM);
Chris Lattner63b570d2005-01-07 07:45:27 +0000870 void dump() const;
Chris Lattnerefe58692005-08-16 18:32:18 +0000871 void dump(const SelectionDAG *G) const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000872
873 static bool classof(const SDNode *) { return true; }
874
Jim Laskey583bd472006-10-27 23:46:08 +0000875 /// Profile - Gather unique data for the node.
876 ///
877 void Profile(FoldingSetNodeID &ID);
878
Chris Lattner63b570d2005-01-07 07:45:27 +0000879protected:
880 friend class SelectionDAG;
Chris Lattner109654f2005-11-08 23:30:11 +0000881
882 /// getValueTypeList - Return a pointer to the specified value type.
883 ///
884 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
Chris Lattner63b570d2005-01-07 07:45:27 +0000885
Evan Chengb9ee9e62006-07-27 06:38:21 +0000886 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeId(-1) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000887 OperandList = 0; NumOperands = 0;
Chris Lattner109654f2005-11-08 23:30:11 +0000888 ValueList = getValueTypeList(VT);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000889 NumValues = 1;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000890 Prev = 0; Next = 0;
Chris Lattner63b570d2005-01-07 07:45:27 +0000891 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000892 SDNode(unsigned NT, SDOperand Op)
Evan Chengb9ee9e62006-07-27 06:38:21 +0000893 : NodeType(NT), NodeId(-1) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000894 OperandList = new SDOperand[1];
895 OperandList[0] = Op;
896 NumOperands = 1;
Chris Lattner63b570d2005-01-07 07:45:27 +0000897 Op.Val->Uses.push_back(this);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000898 ValueList = 0;
899 NumValues = 0;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000900 Prev = 0; Next = 0;
Chris Lattner63b570d2005-01-07 07:45:27 +0000901 }
902 SDNode(unsigned NT, SDOperand N1, SDOperand N2)
Evan Chengb9ee9e62006-07-27 06:38:21 +0000903 : NodeType(NT), NodeId(-1) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000904 OperandList = new SDOperand[2];
905 OperandList[0] = N1;
906 OperandList[1] = N2;
907 NumOperands = 2;
Chris Lattner63b570d2005-01-07 07:45:27 +0000908 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000909 ValueList = 0;
910 NumValues = 0;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000911 Prev = 0; Next = 0;
Chris Lattner63b570d2005-01-07 07:45:27 +0000912 }
913 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
Evan Chengb9ee9e62006-07-27 06:38:21 +0000914 : NodeType(NT), NodeId(-1) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000915 OperandList = new SDOperand[3];
916 OperandList[0] = N1;
917 OperandList[1] = N2;
918 OperandList[2] = N3;
919 NumOperands = 3;
920
Chris Lattner63b570d2005-01-07 07:45:27 +0000921 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
922 N3.Val->Uses.push_back(this);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000923 ValueList = 0;
924 NumValues = 0;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000925 Prev = 0; Next = 0;
Chris Lattner63b570d2005-01-07 07:45:27 +0000926 }
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000927 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4)
Evan Chengb9ee9e62006-07-27 06:38:21 +0000928 : NodeType(NT), NodeId(-1) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000929 OperandList = new SDOperand[4];
930 OperandList[0] = N1;
931 OperandList[1] = N2;
932 OperandList[2] = N3;
933 OperandList[3] = N4;
934 NumOperands = 4;
935
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000936 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
937 N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000938 ValueList = 0;
939 NumValues = 0;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000940 Prev = 0; Next = 0;
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000941 }
Chris Lattnerf06f35e2006-08-08 01:09:31 +0000942 SDNode(unsigned Opc, const SDOperand *Ops, unsigned NumOps)
Evan Chengb9ee9e62006-07-27 06:38:21 +0000943 : NodeType(Opc), NodeId(-1) {
Chris Lattnerf06f35e2006-08-08 01:09:31 +0000944 NumOperands = NumOps;
Chris Lattnerf71e8432005-11-08 22:06:23 +0000945 OperandList = new SDOperand[NumOperands];
946
Chris Lattnerf06f35e2006-08-08 01:09:31 +0000947 for (unsigned i = 0, e = NumOps; i != e; ++i) {
948 OperandList[i] = Ops[i];
Chris Lattnerf71e8432005-11-08 22:06:23 +0000949 SDNode *N = OperandList[i].Val;
950 N->Uses.push_back(this);
Chris Lattner0442fbf2005-01-21 21:39:38 +0000951 }
Chris Lattnerf71e8432005-11-08 22:06:23 +0000952 ValueList = 0;
953 NumValues = 0;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000954 Prev = 0; Next = 0;
Chris Lattnerf71e8432005-11-08 22:06:23 +0000955 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000956
Chris Lattner1b950952005-08-16 18:16:24 +0000957 /// MorphNodeTo - This clears the return value and operands list, and sets the
958 /// opcode of the node to the specified value. This should only be used by
959 /// the SelectionDAG class.
960 void MorphNodeTo(unsigned Opc) {
961 NodeType = Opc;
Chris Lattnerf71e8432005-11-08 22:06:23 +0000962 ValueList = 0;
963 NumValues = 0;
Chris Lattnerb467f8a2005-08-17 01:54:00 +0000964
965 // Clear the operands list, updating used nodes to remove this from their
966 // use list.
Chris Lattnerf71e8432005-11-08 22:06:23 +0000967 for (op_iterator I = op_begin(), E = op_end(); I != E; ++I)
968 I->Val->removeUser(this);
969 delete [] OperandList;
970 OperandList = 0;
971 NumOperands = 0;
Chris Lattner1b950952005-08-16 18:16:24 +0000972 }
973
Chris Lattner0b3e5252006-08-15 19:11:05 +0000974 void setValueTypes(SDVTList L) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000975 assert(NumValues == 0 && "Should not have values yet!");
Chris Lattner0b3e5252006-08-15 19:11:05 +0000976 ValueList = L.VTs;
977 NumValues = L.NumVTs;
Chris Lattner63b570d2005-01-07 07:45:27 +0000978 }
Chris Lattner1b950952005-08-16 18:16:24 +0000979
980 void setOperands(SDOperand Op0) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000981 assert(NumOperands == 0 && "Should not have operands yet!");
982 OperandList = new SDOperand[1];
983 OperandList[0] = Op0;
984 NumOperands = 1;
Chris Lattner8c3484c2005-08-17 18:58:38 +0000985 Op0.Val->Uses.push_back(this);
Chris Lattner1b950952005-08-16 18:16:24 +0000986 }
987 void setOperands(SDOperand Op0, SDOperand Op1) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000988 assert(NumOperands == 0 && "Should not have operands yet!");
989 OperandList = new SDOperand[2];
990 OperandList[0] = Op0;
991 OperandList[1] = Op1;
992 NumOperands = 2;
Chris Lattner8c3484c2005-08-17 18:58:38 +0000993 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
Chris Lattner1b950952005-08-16 18:16:24 +0000994 }
995 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000996 assert(NumOperands == 0 && "Should not have operands yet!");
997 OperandList = new SDOperand[3];
998 OperandList[0] = Op0;
999 OperandList[1] = Op1;
1000 OperandList[2] = Op2;
1001 NumOperands = 3;
Chris Lattner8c3484c2005-08-17 18:58:38 +00001002 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
1003 Op2.Val->Uses.push_back(this);
1004 }
Evan Cheng694481e2006-08-27 08:08:54 +00001005 void setOperands(const SDOperand *Ops, unsigned NumOps) {
Chris Lattnerf71e8432005-11-08 22:06:23 +00001006 assert(NumOperands == 0 && "Should not have operands yet!");
Evan Cheng694481e2006-08-27 08:08:54 +00001007 NumOperands = NumOps;
1008 OperandList = new SDOperand[NumOperands];
1009
1010 for (unsigned i = 0, e = NumOps; i != e; ++i) {
1011 OperandList[i] = Ops[i];
1012 SDNode *N = OperandList[i].Val;
1013 N->Uses.push_back(this);
1014 }
Andrew Lenharth7cf11b42006-01-23 21:51:14 +00001015 }
Andrew Lenharth8c6f1ee2006-01-23 20:59:12 +00001016
Chris Lattner8c3484c2005-08-17 18:58:38 +00001017 void addUser(SDNode *User) {
1018 Uses.push_back(User);
Chris Lattner1b950952005-08-16 18:16:24 +00001019 }
Chris Lattnerd1fc9642005-01-07 21:08:55 +00001020 void removeUser(SDNode *User) {
1021 // Remove this user from the operand's use list.
1022 for (unsigned i = Uses.size(); ; --i) {
1023 assert(i != 0 && "Didn't find user!");
1024 if (Uses[i-1] == User) {
Chris Lattner8c3484c2005-08-17 18:58:38 +00001025 Uses[i-1] = Uses.back();
1026 Uses.pop_back();
1027 return;
Chris Lattnerd1fc9642005-01-07 21:08:55 +00001028 }
1029 }
1030 }
Evan Chengb9ee9e62006-07-27 06:38:21 +00001031
1032 void setNodeId(int Id) {
1033 NodeId = Id;
1034 }
Chris Lattner63b570d2005-01-07 07:45:27 +00001035};
1036
1037
1038// Define inline functions from the SDOperand class.
1039
1040inline unsigned SDOperand::getOpcode() const {
1041 return Val->getOpcode();
1042}
1043inline MVT::ValueType SDOperand::getValueType() const {
1044 return Val->getValueType(ResNo);
1045}
1046inline unsigned SDOperand::getNumOperands() const {
1047 return Val->getNumOperands();
1048}
1049inline const SDOperand &SDOperand::getOperand(unsigned i) const {
1050 return Val->getOperand(i);
1051}
Evan Chengc5484282006-10-04 00:56:09 +00001052inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1053 return Val->getConstantOperandVal(i);
1054}
Nate Begeman0f66a912005-08-17 23:44:54 +00001055inline bool SDOperand::isTargetOpcode() const {
1056 return Val->isTargetOpcode();
1057}
1058inline unsigned SDOperand::getTargetOpcode() const {
1059 return Val->getTargetOpcode();
1060}
Chris Lattnera44f4ae2005-01-13 22:58:50 +00001061inline bool SDOperand::hasOneUse() const {
1062 return Val->hasNUsesOfValue(1, ResNo);
1063}
Chris Lattner63b570d2005-01-07 07:45:27 +00001064
Chris Lattnerd623e952005-10-05 06:34:34 +00001065/// HandleSDNode - This class is used to form a handle around another node that
1066/// is persistant and is updated across invocations of replaceAllUsesWith on its
1067/// operand. This node should be directly created by end-users and not added to
1068/// the AllNodes list.
1069class HandleSDNode : public SDNode {
1070public:
1071 HandleSDNode(SDOperand X) : SDNode(ISD::HANDLENODE, X) {}
1072 ~HandleSDNode() {
1073 MorphNodeTo(ISD::HANDLENODE); // Drops operand uses.
1074 }
1075
1076 SDOperand getValue() const { return getOperand(0); }
1077};
1078
Chris Lattner47725d02005-11-29 06:15:39 +00001079class StringSDNode : public SDNode {
1080 std::string Value;
1081protected:
1082 friend class SelectionDAG;
1083 StringSDNode(const std::string &val)
1084 : SDNode(ISD::STRING, MVT::Other), Value(val) {
1085 }
1086public:
1087 const std::string &getValue() const { return Value; }
1088 static bool classof(const StringSDNode *) { return true; }
1089 static bool classof(const SDNode *N) {
1090 return N->getOpcode() == ISD::STRING;
1091 }
1092};
Chris Lattner63b570d2005-01-07 07:45:27 +00001093
1094class ConstantSDNode : public SDNode {
1095 uint64_t Value;
1096protected:
1097 friend class SelectionDAG;
Chris Lattner056f9f62005-08-17 00:33:30 +00001098 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
1099 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, VT), Value(val) {
Chris Lattner63b570d2005-01-07 07:45:27 +00001100 }
1101public:
1102
1103 uint64_t getValue() const { return Value; }
1104
1105 int64_t getSignExtended() const {
1106 unsigned Bits = MVT::getSizeInBits(getValueType(0));
Chris Lattnerf26bc8e2005-01-08 19:52:31 +00001107 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
Chris Lattner63b570d2005-01-07 07:45:27 +00001108 }
1109
1110 bool isNullValue() const { return Value == 0; }
1111 bool isAllOnesValue() const {
Chris Lattner885a87e2006-04-02 02:28:52 +00001112 return Value == MVT::getIntVTBitMask(getValueType(0));
Chris Lattner63b570d2005-01-07 07:45:27 +00001113 }
1114
1115 static bool classof(const ConstantSDNode *) { return true; }
1116 static bool classof(const SDNode *N) {
Chris Lattner056f9f62005-08-17 00:33:30 +00001117 return N->getOpcode() == ISD::Constant ||
1118 N->getOpcode() == ISD::TargetConstant;
Chris Lattner63b570d2005-01-07 07:45:27 +00001119 }
1120};
1121
1122class ConstantFPSDNode : public SDNode {
1123 double Value;
1124protected:
1125 friend class SelectionDAG;
Chris Lattnerac0d7232006-01-29 06:24:40 +00001126 ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT)
1127 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, VT),
1128 Value(val) {
Chris Lattner63b570d2005-01-07 07:45:27 +00001129 }
1130public:
1131
1132 double getValue() const { return Value; }
1133
1134 /// isExactlyValue - We don't rely on operator== working on double values, as
1135 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1136 /// As such, this method can be used to do an exact bit-for-bit comparison of
1137 /// two floating point values.
Jim Laskey58b968b2005-08-17 20:08:02 +00001138 bool isExactlyValue(double V) const;
Chris Lattner63b570d2005-01-07 07:45:27 +00001139
1140 static bool classof(const ConstantFPSDNode *) { return true; }
1141 static bool classof(const SDNode *N) {
Chris Lattnerac0d7232006-01-29 06:24:40 +00001142 return N->getOpcode() == ISD::ConstantFP ||
1143 N->getOpcode() == ISD::TargetConstantFP;
Chris Lattner63b570d2005-01-07 07:45:27 +00001144 }
1145};
1146
1147class GlobalAddressSDNode : public SDNode {
1148 GlobalValue *TheGlobal;
Evan Cheng404cb4f2006-02-25 09:54:52 +00001149 int Offset;
Chris Lattner63b570d2005-01-07 07:45:27 +00001150protected:
1151 friend class SelectionDAG;
Evan Cheng61ca74b2005-11-30 02:04:11 +00001152 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
1153 int o=0)
Evan Cheng404cb4f2006-02-25 09:54:52 +00001154 : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT),
1155 Offset(o) {
Chris Lattner63b570d2005-01-07 07:45:27 +00001156 TheGlobal = const_cast<GlobalValue*>(GA);
Chris Lattner63b570d2005-01-07 07:45:27 +00001157 }
1158public:
1159
1160 GlobalValue *getGlobal() const { return TheGlobal; }
Evan Cheng404cb4f2006-02-25 09:54:52 +00001161 int getOffset() const { return Offset; }
Chris Lattner63b570d2005-01-07 07:45:27 +00001162
1163 static bool classof(const GlobalAddressSDNode *) { return true; }
1164 static bool classof(const SDNode *N) {
Chris Lattnerf6b18492005-08-19 22:31:34 +00001165 return N->getOpcode() == ISD::GlobalAddress ||
1166 N->getOpcode() == ISD::TargetGlobalAddress;
Chris Lattner63b570d2005-01-07 07:45:27 +00001167 }
1168};
1169
1170
1171class FrameIndexSDNode : public SDNode {
1172 int FI;
1173protected:
1174 friend class SelectionDAG;
Chris Lattnerafb2dd42005-08-25 00:43:01 +00001175 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1176 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, VT), FI(fi) {}
Chris Lattner63b570d2005-01-07 07:45:27 +00001177public:
1178
1179 int getIndex() const { return FI; }
1180
1181 static bool classof(const FrameIndexSDNode *) { return true; }
1182 static bool classof(const SDNode *N) {
Chris Lattnerafb2dd42005-08-25 00:43:01 +00001183 return N->getOpcode() == ISD::FrameIndex ||
1184 N->getOpcode() == ISD::TargetFrameIndex;
Chris Lattner63b570d2005-01-07 07:45:27 +00001185 }
1186};
1187
Nate Begeman37efe672006-04-22 18:53:45 +00001188class JumpTableSDNode : public SDNode {
1189 int JTI;
1190protected:
1191 friend class SelectionDAG;
1192 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1193 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, VT),
1194 JTI(jti) {}
1195public:
1196
1197 int getIndex() const { return JTI; }
1198
1199 static bool classof(const JumpTableSDNode *) { return true; }
1200 static bool classof(const SDNode *N) {
1201 return N->getOpcode() == ISD::JumpTable ||
1202 N->getOpcode() == ISD::TargetJumpTable;
1203 }
1204};
1205
Chris Lattner63b570d2005-01-07 07:45:27 +00001206class ConstantPoolSDNode : public SDNode {
Evan Chengd6594ae2006-09-12 21:00:35 +00001207 union {
1208 Constant *ConstVal;
1209 MachineConstantPoolValue *MachineCPVal;
1210 } Val;
Evan Chengbaf45002006-09-14 07:30:48 +00001211 int Offset; // It's a MachineConstantPoolValue if top bit is set.
Evan Chengb8973bd2006-01-31 22:23:14 +00001212 unsigned Alignment;
Chris Lattner63b570d2005-01-07 07:45:27 +00001213protected:
1214 friend class SelectionDAG;
Evan Cheng404cb4f2006-02-25 09:54:52 +00001215 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1216 int o=0)
Chris Lattneraaaaf792005-08-25 05:02:41 +00001217 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
Evan Chengd6594ae2006-09-12 21:00:35 +00001218 Offset(o), Alignment(0) {
1219 assert((int)Offset >= 0 && "Offset is too large");
1220 Val.ConstVal = c;
1221 }
Evan Cheng404cb4f2006-02-25 09:54:52 +00001222 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1223 unsigned Align)
Evan Chengb8973bd2006-01-31 22:23:14 +00001224 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
Evan Chengd6594ae2006-09-12 21:00:35 +00001225 Offset(o), Alignment(Align) {
1226 assert((int)Offset >= 0 && "Offset is too large");
1227 Val.ConstVal = c;
1228 }
1229 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1230 MVT::ValueType VT, int o=0)
1231 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
1232 Offset(o), Alignment(0) {
1233 assert((int)Offset >= 0 && "Offset is too large");
1234 Val.MachineCPVal = v;
1235 Offset |= 1 << (sizeof(unsigned)*8-1);
1236 }
1237 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1238 MVT::ValueType VT, int o, unsigned Align)
1239 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
1240 Offset(o), Alignment(Align) {
1241 assert((int)Offset >= 0 && "Offset is too large");
1242 Val.MachineCPVal = v;
1243 Offset |= 1 << (sizeof(unsigned)*8-1);
1244 }
Chris Lattner63b570d2005-01-07 07:45:27 +00001245public:
1246
Evan Chengd6594ae2006-09-12 21:00:35 +00001247 bool isMachineConstantPoolEntry() const {
1248 return (int)Offset < 0;
1249 }
1250
1251 Constant *getConstVal() const {
1252 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1253 return Val.ConstVal;
1254 }
1255
1256 MachineConstantPoolValue *getMachineCPVal() const {
1257 assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1258 return Val.MachineCPVal;
1259 }
1260
Evan Chengbaf45002006-09-14 07:30:48 +00001261 int getOffset() const {
1262 return Offset & ~(1 << (sizeof(unsigned)*8-1));
1263 }
Chris Lattneref3640a2006-02-09 02:10:15 +00001264
1265 // Return the alignment of this constant pool object, which is either 0 (for
1266 // default alignment) or log2 of the desired value.
Evan Chengb8973bd2006-01-31 22:23:14 +00001267 unsigned getAlignment() const { return Alignment; }
Chris Lattner63b570d2005-01-07 07:45:27 +00001268
Evan Chengd6594ae2006-09-12 21:00:35 +00001269 const Type *getType() const;
1270
Chris Lattner63b570d2005-01-07 07:45:27 +00001271 static bool classof(const ConstantPoolSDNode *) { return true; }
1272 static bool classof(const SDNode *N) {
Chris Lattneraaaaf792005-08-25 05:02:41 +00001273 return N->getOpcode() == ISD::ConstantPool ||
1274 N->getOpcode() == ISD::TargetConstantPool;
Chris Lattner63b570d2005-01-07 07:45:27 +00001275 }
1276};
1277
1278class BasicBlockSDNode : public SDNode {
1279 MachineBasicBlock *MBB;
1280protected:
1281 friend class SelectionDAG;
1282 BasicBlockSDNode(MachineBasicBlock *mbb)
1283 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
1284public:
1285
1286 MachineBasicBlock *getBasicBlock() const { return MBB; }
1287
1288 static bool classof(const BasicBlockSDNode *) { return true; }
1289 static bool classof(const SDNode *N) {
1290 return N->getOpcode() == ISD::BasicBlock;
1291 }
1292};
1293
Andrew Lenharth2d86ea22005-04-27 20:10:01 +00001294class SrcValueSDNode : public SDNode {
1295 const Value *V;
Andrew Lenharth691ef2b2005-05-03 17:19:30 +00001296 int offset;
Andrew Lenharth2d86ea22005-04-27 20:10:01 +00001297protected:
1298 friend class SelectionDAG;
Andrew Lenharth691ef2b2005-05-03 17:19:30 +00001299 SrcValueSDNode(const Value* v, int o)
1300 : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {}
Andrew Lenharth2d86ea22005-04-27 20:10:01 +00001301
1302public:
1303 const Value *getValue() const { return V; }
Andrew Lenharth691ef2b2005-05-03 17:19:30 +00001304 int getOffset() const { return offset; }
Andrew Lenharth2d86ea22005-04-27 20:10:01 +00001305
1306 static bool classof(const SrcValueSDNode *) { return true; }
1307 static bool classof(const SDNode *N) {
1308 return N->getOpcode() == ISD::SRCVALUE;
1309 }
1310};
1311
Chris Lattner63b570d2005-01-07 07:45:27 +00001312
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +00001313class RegisterSDNode : public SDNode {
Chris Lattner63b570d2005-01-07 07:45:27 +00001314 unsigned Reg;
1315protected:
1316 friend class SelectionDAG;
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +00001317 RegisterSDNode(unsigned reg, MVT::ValueType VT)
1318 : SDNode(ISD::Register, VT), Reg(reg) {}
Chris Lattner63b570d2005-01-07 07:45:27 +00001319public:
1320
1321 unsigned getReg() const { return Reg; }
1322
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +00001323 static bool classof(const RegisterSDNode *) { return true; }
Chris Lattner63b570d2005-01-07 07:45:27 +00001324 static bool classof(const SDNode *N) {
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +00001325 return N->getOpcode() == ISD::Register;
Chris Lattner63b570d2005-01-07 07:45:27 +00001326 }
1327};
1328
1329class ExternalSymbolSDNode : public SDNode {
1330 const char *Symbol;
1331protected:
1332 friend class SelectionDAG;
Andrew Lenharth2a2de662005-10-23 03:40:17 +00001333 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1334 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, VT),
1335 Symbol(Sym) {
Chris Lattner63b570d2005-01-07 07:45:27 +00001336 }
1337public:
1338
1339 const char *getSymbol() const { return Symbol; }
1340
1341 static bool classof(const ExternalSymbolSDNode *) { return true; }
1342 static bool classof(const SDNode *N) {
Andrew Lenharth2a2de662005-10-23 03:40:17 +00001343 return N->getOpcode() == ISD::ExternalSymbol ||
1344 N->getOpcode() == ISD::TargetExternalSymbol;
Chris Lattner63b570d2005-01-07 07:45:27 +00001345 }
1346};
1347
Chris Lattner7cf7e3f2005-08-09 20:20:18 +00001348class CondCodeSDNode : public SDNode {
Chris Lattner63b570d2005-01-07 07:45:27 +00001349 ISD::CondCode Condition;
1350protected:
1351 friend class SelectionDAG;
Chris Lattner7cf7e3f2005-08-09 20:20:18 +00001352 CondCodeSDNode(ISD::CondCode Cond)
1353 : SDNode(ISD::CONDCODE, MVT::Other), Condition(Cond) {
Chris Lattner63b570d2005-01-07 07:45:27 +00001354 }
1355public:
1356
Chris Lattner7cf7e3f2005-08-09 20:20:18 +00001357 ISD::CondCode get() const { return Condition; }
Chris Lattner63b570d2005-01-07 07:45:27 +00001358
Chris Lattner7cf7e3f2005-08-09 20:20:18 +00001359 static bool classof(const CondCodeSDNode *) { return true; }
Chris Lattner63b570d2005-01-07 07:45:27 +00001360 static bool classof(const SDNode *N) {
Chris Lattner7cf7e3f2005-08-09 20:20:18 +00001361 return N->getOpcode() == ISD::CONDCODE;
Chris Lattner63b570d2005-01-07 07:45:27 +00001362 }
1363};
1364
Chris Lattner15e4b012005-07-10 00:07:11 +00001365/// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1366/// to parameterize some operations.
1367class VTSDNode : public SDNode {
1368 MVT::ValueType ValueType;
1369protected:
1370 friend class SelectionDAG;
1371 VTSDNode(MVT::ValueType VT)
1372 : SDNode(ISD::VALUETYPE, MVT::Other), ValueType(VT) {}
1373public:
1374
1375 MVT::ValueType getVT() const { return ValueType; }
1376
1377 static bool classof(const VTSDNode *) { return true; }
1378 static bool classof(const SDNode *N) {
1379 return N->getOpcode() == ISD::VALUETYPE;
1380 }
1381};
1382
Evan Cheng24446e22006-10-09 20:55:20 +00001383/// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1384///
1385class LoadSDNode : public SDNode {
Evan Cheng81c38452006-10-10 01:44:58 +00001386 // AddrMode - unindexed, pre-indexed, post-indexed.
Evan Cheng144d8f02006-11-09 17:55:04 +00001387 ISD::MemIndexedMode AddrMode;
Evan Cheng81c38452006-10-10 01:44:58 +00001388
1389 // ExtType - non-ext, anyext, sext, zext.
1390 ISD::LoadExtType ExtType;
1391
Evan Cheng2e49f092006-10-11 07:10:22 +00001392 // LoadedVT - VT of loaded value before extension.
1393 MVT::ValueType LoadedVT;
Evan Cheng81c38452006-10-10 01:44:58 +00001394
1395 // SrcValue - Memory location for alias analysis.
Evan Cheng24446e22006-10-09 20:55:20 +00001396 const Value *SrcValue;
Evan Cheng81c38452006-10-10 01:44:58 +00001397
1398 // SVOffset - Memory location offset.
Evan Cheng24446e22006-10-09 20:55:20 +00001399 int SVOffset;
Evan Cheng81c38452006-10-10 01:44:58 +00001400
1401 // Alignment - Alignment of memory location in bytes.
Evan Cheng24446e22006-10-09 20:55:20 +00001402 unsigned Alignment;
Evan Cheng81c38452006-10-10 01:44:58 +00001403
1404 // IsVolatile - True if the load is volatile.
Evan Cheng24446e22006-10-09 20:55:20 +00001405 bool IsVolatile;
1406protected:
1407 friend class SelectionDAG;
1408 LoadSDNode(SDOperand Chain, SDOperand Ptr, SDOperand Off,
Evan Cheng144d8f02006-11-09 17:55:04 +00001409 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
Evan Cheng24446e22006-10-09 20:55:20 +00001410 const Value *SV, int O=0, unsigned Align=1, bool Vol=false)
1411 : SDNode(ISD::LOAD, Chain, Ptr, Off),
Evan Cheng2e49f092006-10-11 07:10:22 +00001412 AddrMode(AM), ExtType(ETy), LoadedVT(LVT), SrcValue(SV), SVOffset(O),
Evan Cheng24446e22006-10-09 20:55:20 +00001413 Alignment(Align), IsVolatile(Vol) {
Evan Cheng8862ef12006-10-26 21:52:24 +00001414 assert((Off.getOpcode() == ISD::UNDEF || AddrMode != ISD::UNINDEXED) &&
1415 "Only indexed load has a non-undef offset operand");
Evan Cheng24446e22006-10-09 20:55:20 +00001416 }
Evan Cheng24446e22006-10-09 20:55:20 +00001417public:
1418
Evan Cheng81c38452006-10-10 01:44:58 +00001419 const SDOperand getChain() const { return getOperand(0); }
1420 const SDOperand getBasePtr() const { return getOperand(1); }
1421 const SDOperand getOffset() const { return getOperand(2); }
Evan Cheng144d8f02006-11-09 17:55:04 +00001422 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
Evan Cheng24446e22006-10-09 20:55:20 +00001423 ISD::LoadExtType getExtensionType() const { return ExtType; }
Evan Cheng2e49f092006-10-11 07:10:22 +00001424 MVT::ValueType getLoadedVT() const { return LoadedVT; }
Evan Cheng24446e22006-10-09 20:55:20 +00001425 const Value *getSrcValue() const { return SrcValue; }
1426 int getSrcValueOffset() const { return SVOffset; }
1427 unsigned getAlignment() const { return Alignment; }
1428 bool isVolatile() const { return IsVolatile; }
1429
1430 static bool classof(const LoadSDNode *) { return true; }
1431 static bool classof(const SDNode *N) {
1432 return N->getOpcode() == ISD::LOAD;
1433 }
1434};
1435
1436/// StoreSDNode - This class is used to represent ISD::STORE nodes.
1437///
1438class StoreSDNode : public SDNode {
Evan Cheng81c38452006-10-10 01:44:58 +00001439 // AddrMode - unindexed, pre-indexed, post-indexed.
Evan Cheng144d8f02006-11-09 17:55:04 +00001440 ISD::MemIndexedMode AddrMode;
Evan Cheng81c38452006-10-10 01:44:58 +00001441
1442 // IsTruncStore - True is the op does a truncation before store.
1443 bool IsTruncStore;
1444
Evan Cheng2e49f092006-10-11 07:10:22 +00001445 // StoredVT - VT of the value after truncation.
Evan Cheng81c38452006-10-10 01:44:58 +00001446 MVT::ValueType StoredVT;
1447
1448 // SrcValue - Memory location for alias analysis.
Evan Cheng24446e22006-10-09 20:55:20 +00001449 const Value *SrcValue;
Evan Cheng81c38452006-10-10 01:44:58 +00001450
1451 // SVOffset - Memory location offset.
Evan Cheng24446e22006-10-09 20:55:20 +00001452 int SVOffset;
Evan Cheng81c38452006-10-10 01:44:58 +00001453
1454 // Alignment - Alignment of memory location in bytes.
Evan Cheng24446e22006-10-09 20:55:20 +00001455 unsigned Alignment;
Evan Cheng81c38452006-10-10 01:44:58 +00001456
1457 // IsVolatile - True if the store is volatile.
Evan Cheng24446e22006-10-09 20:55:20 +00001458 bool IsVolatile;
1459protected:
1460 friend class SelectionDAG;
Evan Cheng8b2794a2006-10-13 21:14:26 +00001461 StoreSDNode(SDOperand Chain, SDOperand Value, SDOperand Ptr, SDOperand Off,
Evan Cheng144d8f02006-11-09 17:55:04 +00001462 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
Evan Cheng24446e22006-10-09 20:55:20 +00001463 const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
Evan Cheng8b2794a2006-10-13 21:14:26 +00001464 : SDNode(ISD::STORE, Chain, Value, Ptr, Off),
Evan Cheng24446e22006-10-09 20:55:20 +00001465 AddrMode(AM), IsTruncStore(isTrunc), StoredVT(SVT), SrcValue(SV),
1466 SVOffset(O), Alignment(Align), IsVolatile(Vol) {
Evan Cheng8862ef12006-10-26 21:52:24 +00001467 assert((Off.getOpcode() == ISD::UNDEF || AddrMode != ISD::UNINDEXED) &&
1468 "Only indexed store has a non-undef offset operand");
Evan Cheng24446e22006-10-09 20:55:20 +00001469 }
1470public:
1471
Evan Cheng81c38452006-10-10 01:44:58 +00001472 const SDOperand getChain() const { return getOperand(0); }
Evan Cheng8b2794a2006-10-13 21:14:26 +00001473 const SDOperand getValue() const { return getOperand(1); }
1474 const SDOperand getBasePtr() const { return getOperand(2); }
1475 const SDOperand getOffset() const { return getOperand(3); }
Evan Cheng144d8f02006-11-09 17:55:04 +00001476 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
Evan Cheng24446e22006-10-09 20:55:20 +00001477 bool isTruncatingStore() const { return IsTruncStore; }
1478 MVT::ValueType getStoredVT() const { return StoredVT; }
1479 const Value *getSrcValue() const { return SrcValue; }
1480 int getSrcValueOffset() const { return SVOffset; }
1481 unsigned getAlignment() const { return Alignment; }
1482 bool isVolatile() const { return IsVolatile; }
1483
Evan Cheng6d0b3292006-12-16 06:21:55 +00001484 static bool classof(const StoreSDNode *) { return true; }
Evan Cheng24446e22006-10-09 20:55:20 +00001485 static bool classof(const SDNode *N) {
1486 return N->getOpcode() == ISD::STORE;
1487 }
1488};
1489
Chris Lattner15e4b012005-07-10 00:07:11 +00001490
Chris Lattner1080b9e2005-01-10 23:05:53 +00001491class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1492 SDNode *Node;
1493 unsigned Operand;
Misha Brukmanea61c352005-04-21 20:39:54 +00001494
Chris Lattner1080b9e2005-01-10 23:05:53 +00001495 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1496public:
1497 bool operator==(const SDNodeIterator& x) const {
1498 return Operand == x.Operand;
1499 }
1500 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1501
1502 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1503 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1504 Operand = I.Operand;
1505 return *this;
1506 }
Misha Brukmanea61c352005-04-21 20:39:54 +00001507
Chris Lattner1080b9e2005-01-10 23:05:53 +00001508 pointer operator*() const {
1509 return Node->getOperand(Operand).Val;
1510 }
1511 pointer operator->() const { return operator*(); }
Misha Brukmanea61c352005-04-21 20:39:54 +00001512
Chris Lattner1080b9e2005-01-10 23:05:53 +00001513 SDNodeIterator& operator++() { // Preincrement
1514 ++Operand;
1515 return *this;
1516 }
1517 SDNodeIterator operator++(int) { // Postincrement
Misha Brukmanea61c352005-04-21 20:39:54 +00001518 SDNodeIterator tmp = *this; ++*this; return tmp;
Chris Lattner1080b9e2005-01-10 23:05:53 +00001519 }
1520
1521 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1522 static SDNodeIterator end (SDNode *N) {
1523 return SDNodeIterator(N, N->getNumOperands());
1524 }
1525
1526 unsigned getOperand() const { return Operand; }
1527 const SDNode *getNode() const { return Node; }
1528};
1529
1530template <> struct GraphTraits<SDNode*> {
1531 typedef SDNode NodeType;
1532 typedef SDNodeIterator ChildIteratorType;
1533 static inline NodeType *getEntryNode(SDNode *N) { return N; }
Misha Brukmanea61c352005-04-21 20:39:54 +00001534 static inline ChildIteratorType child_begin(NodeType *N) {
Chris Lattner1080b9e2005-01-10 23:05:53 +00001535 return SDNodeIterator::begin(N);
1536 }
Misha Brukmanea61c352005-04-21 20:39:54 +00001537 static inline ChildIteratorType child_end(NodeType *N) {
Chris Lattner1080b9e2005-01-10 23:05:53 +00001538 return SDNodeIterator::end(N);
1539 }
1540};
1541
Chris Lattnerb80e2be2005-11-09 23:46:43 +00001542template<>
1543struct ilist_traits<SDNode> {
1544 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1545 static SDNode *getNext(const SDNode *N) { return N->Next; }
1546
1547 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1548 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1549
1550 static SDNode *createSentinel() {
1551 return new SDNode(ISD::EntryToken, MVT::Other);
1552 }
1553 static void destroySentinel(SDNode *N) { delete N; }
1554 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1555
1556
1557 void addNodeToList(SDNode *NTy) {}
1558 void removeNodeFromList(SDNode *NTy) {}
1559 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1560 const ilist_iterator<SDNode> &X,
1561 const ilist_iterator<SDNode> &Y) {}
1562};
1563
Evan Chengc5484282006-10-04 00:56:09 +00001564namespace ISD {
Evan Cheng24446e22006-10-09 20:55:20 +00001565 /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1566 /// load.
1567 inline bool isNON_EXTLoad(const SDNode *N) {
1568 return N->getOpcode() == ISD::LOAD &&
1569 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1570 }
1571
Evan Chengc5484282006-10-04 00:56:09 +00001572 /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1573 ///
1574 inline bool isEXTLoad(const SDNode *N) {
Evan Cheng24446e22006-10-09 20:55:20 +00001575 return N->getOpcode() == ISD::LOAD &&
1576 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
Evan Chengc5484282006-10-04 00:56:09 +00001577 }
1578
1579 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1580 ///
1581 inline bool isSEXTLoad(const SDNode *N) {
Evan Cheng24446e22006-10-09 20:55:20 +00001582 return N->getOpcode() == ISD::LOAD &&
1583 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
Evan Chengc5484282006-10-04 00:56:09 +00001584 }
1585
1586 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1587 ///
1588 inline bool isZEXTLoad(const SDNode *N) {
Evan Cheng24446e22006-10-09 20:55:20 +00001589 return N->getOpcode() == ISD::LOAD &&
1590 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
Evan Chengc5484282006-10-04 00:56:09 +00001591 }
Evan Cheng8b2794a2006-10-13 21:14:26 +00001592
1593 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1594 /// store.
1595 inline bool isNON_TRUNCStore(const SDNode *N) {
1596 return N->getOpcode() == ISD::STORE &&
1597 !cast<StoreSDNode>(N)->isTruncatingStore();
1598 }
1599
1600 /// isTRUNCStore - Returns true if the specified node is a truncating
1601 /// store.
1602 inline bool isTRUNCStore(const SDNode *N) {
1603 return N->getOpcode() == ISD::STORE &&
1604 cast<StoreSDNode>(N)->isTruncatingStore();
1605 }
Evan Chengc5484282006-10-04 00:56:09 +00001606}
1607
1608
Chris Lattner63b570d2005-01-07 07:45:27 +00001609} // end llvm namespace
1610
1611#endif