blob: b98a3f022bfd52a877628b84ce0b7638cb9fdccd [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
22#include "llvm/CodeGen/ValueTypes.h"
Andrew Lenharth2d86ea22005-04-27 20:10:01 +000023#include "llvm/Value.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"
Jeff Cohen39931a32005-01-07 19:21:49 +000026#include "llvm/Support/DataTypes.h"
Chris Lattner63b570d2005-01-07 07:45:27 +000027#include <cassert>
28#include <vector>
29
30namespace llvm {
31
32class SelectionDAG;
33class GlobalValue;
34class MachineBasicBlock;
35class SDNode;
36template <typename T> struct simplify_type;
Chris Lattnerb80e2be2005-11-09 23:46:43 +000037template <typename T> struct ilist_traits;
38template<typename NodeTy, typename Traits> class iplist;
39template<typename NodeTy> class ilist_iterator;
Chris Lattner63b570d2005-01-07 07:45:27 +000040
41/// ISD namespace - This namespace contains an enum which represents all of the
42/// SelectionDAG node types and value types.
43///
44namespace ISD {
45 //===--------------------------------------------------------------------===//
46 /// ISD::NodeType enum - This enum defines all of the operators valid in a
47 /// SelectionDAG.
48 ///
49 enum NodeType {
Chris Lattner8a496fc2005-01-13 17:58:35 +000050 // EntryToken - This is the marker used to indicate the start of the region.
51 EntryToken,
52
Reid Spencer8c4bde32005-08-27 19:06:05 +000053 // Token factor - This node takes multiple tokens as input and produces a
Chris Lattner8a496fc2005-01-13 17:58:35 +000054 // single token result. This is used to represent the fact that the operand
55 // operators are independent of each other.
56 TokenFactor,
Nate Begemanf7f3d322005-08-30 02:39:32 +000057
58 // AssertSext, AssertZext - These nodes record if a register contains a
59 // value that has already been zero or sign extended from a narrower type.
60 // These nodes take two operands. The first is the node that has already
61 // been extended, and the second is a value type node indicating the width
62 // of the extension
63 AssertSext, AssertZext,
Misha Brukmanea61c352005-04-21 20:39:54 +000064
Chris Lattner8a496fc2005-01-13 17:58:35 +000065 // Various leaf nodes.
66 Constant, ConstantFP, GlobalAddress, FrameIndex, ConstantPool,
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +000067 BasicBlock, ExternalSymbol, VALUETYPE, CONDCODE, Register,
Chris Lattner056f9f62005-08-17 00:33:30 +000068
69 // TargetConstant - Like Constant, but the DAG does not do any folding or
70 // simplification of the constant. This is used by the DAG->DAG selector.
71 TargetConstant,
Chris Lattnerf6b18492005-08-19 22:31:34 +000072
73 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
74 // anything else with this node, and this is valid in the target-specific
75 // dag, turning into a GlobalAddress operand.
76 TargetGlobalAddress,
Chris Lattnerafb2dd42005-08-25 00:43:01 +000077 TargetFrameIndex,
Chris Lattneraaaaf792005-08-25 05:02:41 +000078 TargetConstantPool,
Andrew Lenharth2a2de662005-10-23 03:40:17 +000079 TargetExternalSymbol,
Chris Lattner63b570d2005-01-07 07:45:27 +000080
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +000081 // CopyToReg - This node has three operands: a chain, a register number to
82 // set to this value, and a value.
Chris Lattner63b570d2005-01-07 07:45:27 +000083 CopyToReg,
84
85 // CopyFromReg - This node indicates that the input value is a virtual or
86 // physical register that is defined outside of the scope of this
Chris Lattner18c2f132005-01-13 20:50:02 +000087 // SelectionDAG. The register is available from the RegSDNode object.
Chris Lattner63b570d2005-01-07 07:45:27 +000088 CopyFromReg,
89
Chris Lattner18c2f132005-01-13 20:50:02 +000090 // ImplicitDef - This node indicates that the specified register is
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +000091 // implicitly defined by some operation (e.g. its a live-in argument). The
92 // two operands to this are the token chain coming in and the register.
93 // The only result is the token chain going out.
Chris Lattner18c2f132005-01-13 20:50:02 +000094 ImplicitDef,
95
Nate Begemanfc1b1da2005-04-01 22:34:39 +000096 // UNDEF - An undefined node
97 UNDEF,
98
Chris Lattner63b570d2005-01-07 07:45:27 +000099 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
100 // a Constant, which is required to be operand #1), element of the aggregate
101 // value specified as operand #0. This is only for use before legalization,
102 // for values that will be broken into multiple registers.
103 EXTRACT_ELEMENT,
104
105 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
106 // two values of the same integer value type, this produces a value twice as
107 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
108 BUILD_PAIR,
Chris Lattner006e3e32005-11-20 22:55:57 +0000109
110 // MERGE_VALUES - This node takes multiple discrete operands and returns
111 // them all as its individual results. This nodes has exactly the same
112 // number of inputs and outputs, and is only valid before legalization.
113 // This node is useful for some pieces of the code generator that want to
114 // think about a single node with multiple results, not multiple nodes.
115 MERGE_VALUES,
Chris Lattner63b570d2005-01-07 07:45:27 +0000116
Chris Lattner615c2d02005-09-28 22:29:58 +0000117 // Simple integer binary arithmetic operators.
Chris Lattnerbede0b72005-04-06 04:21:29 +0000118 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
Chris Lattner615c2d02005-09-28 22:29:58 +0000119
120 // Simple binary floating point operators.
121 FADD, FSUB, FMUL, FDIV, FREM,
Nate Begeman5fbb5d22005-11-19 00:36:38 +0000122
123 // Simple abstract vector operators. Unlike the integer and floating point
124 // binary operators, these nodes also take two additional operands:
125 // a constant element count, and a value type node indicating the type of
126 // the elements. The order is count, type, op0, op1.
127 VADD, VSUB, VMUL,
Chris Lattnerbede0b72005-04-06 04:21:29 +0000128
129 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
130 // an unsigned/signed value of type i[2*n], then return the top part.
131 MULHU, MULHS,
Chris Lattner63b570d2005-01-07 07:45:27 +0000132
133 // Bitwise operators.
134 AND, OR, XOR, SHL, SRA, SRL,
135
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000136 // Counting operators
137 CTTZ, CTLZ, CTPOP,
138
Nate Begeman9373a812005-08-10 20:51:12 +0000139 // Select
140 SELECT,
141
142 // Select with condition operator - This selects between a true value and
143 // a false value (ops #2 and #3) based on the boolean result of comparing
144 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
145 // condition code in op #4, a CondCodeSDNode.
146 SELECT_CC,
Chris Lattner63b570d2005-01-07 07:45:27 +0000147
148 // SetCC operator - This evaluates to a boolean (i1) true value if the
Chris Lattner7cf7e3f2005-08-09 20:20:18 +0000149 // condition is true. The operands to this are the left and right operands
150 // to compare (ops #0, and #1) and the condition code to compare them with
151 // (op #2) as a CondCodeSDNode.
Chris Lattner63b570d2005-01-07 07:45:27 +0000152 SETCC,
153
Chris Lattner5880b9f2005-01-20 18:50:39 +0000154 // ADD_PARTS/SUB_PARTS - These operators take two logical operands which are
155 // broken into a multiple pieces each, and return the resulting pieces of
156 // doing an atomic add/sub operation. This is used to handle add/sub of
157 // expanded types. The operation ordering is:
158 // [Lo,Hi] = op [LoLHS,HiLHS], [LoRHS,HiRHS]
159 ADD_PARTS, SUB_PARTS,
Chris Lattner63b570d2005-01-07 07:45:27 +0000160
Chris Lattner14c5b532005-04-02 03:30:33 +0000161 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
162 // integer shift operations, just like ADD/SUB_PARTS. The operation
163 // ordering is:
Chris Lattner6b8f2d62005-04-02 03:59:45 +0000164 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
Chris Lattner14c5b532005-04-02 03:30:33 +0000165 SHL_PARTS, SRA_PARTS, SRL_PARTS,
166
Chris Lattner63b570d2005-01-07 07:45:27 +0000167 // Conversion operators. These are all single input single output
168 // operations. For all of these, the result type must be strictly
169 // wider or narrower (depending on the operation) than the source
170 // type.
171
172 // SIGN_EXTEND - Used for integer types, replicating the sign bit
173 // into new bits.
174 SIGN_EXTEND,
175
176 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
177 ZERO_EXTEND,
178
Chris Lattner7e122db2005-09-02 00:14:40 +0000179 // ANY_EXTEND - Used for integer types. The high bits are undefined.
180 ANY_EXTEND,
181
Chris Lattner63b570d2005-01-07 07:45:27 +0000182 // TRUNCATE - Completely drop the high bits.
183 TRUNCATE,
184
Chris Lattner1645ed02005-01-08 08:08:49 +0000185 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
186 // depends on the first letter) to floating point.
187 SINT_TO_FP,
188 UINT_TO_FP,
189
Chris Lattnerea576102005-04-13 02:36:41 +0000190 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
191 // sign extend a small value in a large integer register (e.g. sign
192 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
Chris Lattner15e4b012005-07-10 00:07:11 +0000193 // with the 7th bit). The size of the smaller type is indicated by the 1th
194 // operand, a ValueType node.
Chris Lattner859157d2005-01-15 06:17:04 +0000195 SIGN_EXTEND_INREG,
Chris Lattner859157d2005-01-15 06:17:04 +0000196
Chris Lattner1645ed02005-01-08 08:08:49 +0000197 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
198 // integer.
199 FP_TO_SINT,
200 FP_TO_UINT,
201
Chris Lattner63b570d2005-01-07 07:45:27 +0000202 // FP_ROUND - Perform a rounding operation from the current
Chris Lattner859157d2005-01-15 06:17:04 +0000203 // precision down to the specified precision (currently always 64->32).
Chris Lattner63b570d2005-01-07 07:45:27 +0000204 FP_ROUND,
205
Chris Lattner859157d2005-01-15 06:17:04 +0000206 // FP_ROUND_INREG - This operator takes a floating point register, and
207 // rounds it to a floating point value. It then promotes it and returns it
208 // in a register of the same size. This operation effectively just discards
Chris Lattner15e4b012005-07-10 00:07:11 +0000209 // excess precision. The type to round down to is specified by the 1th
210 // operation, a VTSDNode (currently always 64->32->64).
Chris Lattner859157d2005-01-15 06:17:04 +0000211 FP_ROUND_INREG,
212
Chris Lattner63b570d2005-01-07 07:45:27 +0000213 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
214 FP_EXTEND,
215
Chris Lattner7f644642005-04-28 21:44:03 +0000216 // FNEG, FABS, FSQRT, FSIN, FCOS - Perform unary floating point negation,
217 // absolute value, square root, sine and cosine operations.
218 FNEG, FABS, FSQRT, FSIN, FCOS,
Chris Lattner7366fd32005-04-02 04:58:28 +0000219
Chris Lattner1cff05c2005-01-14 22:07:46 +0000220 // Other operators. LOAD and STORE have token chains as their first
Chris Lattnerf7db8c62005-07-10 00:28:25 +0000221 // operand, then the same operands as an LLVM load/store instruction, then a
222 // SRCVALUE node that provides alias analysis information.
Chris Lattner63b570d2005-01-07 07:45:27 +0000223 LOAD, STORE,
Nate Begeman5fbb5d22005-11-19 00:36:38 +0000224
225 // Abstract vector version of LOAD. VLOAD has a token chain as the first
226 // operand, followed by a pointer operand, a constant element count, a value
227 // type node indicating the type of the elements, and a SRCVALUE node.
228 VLOAD,
Chris Lattner63b570d2005-01-07 07:45:27 +0000229
Chris Lattner5f056bf2005-07-10 01:55:33 +0000230 // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators all load a value from
231 // memory and extend them to a larger value (e.g. load a byte into a word
232 // register). All three of these have four operands, a token chain, a
233 // pointer to load from, a SRCVALUE for alias analysis, and a VALUETYPE node
234 // indicating the type to load.
Chris Lattner1cff05c2005-01-14 22:07:46 +0000235 //
236 // SEXTLOAD loads the integer operand and sign extends it to a larger
237 // integer result type.
238 // ZEXTLOAD loads the integer operand and zero extends it to a larger
239 // integer result type.
Misha Brukmanea61c352005-04-21 20:39:54 +0000240 // EXTLOAD is used for two things: floating point extending loads, and
Chris Lattner1cff05c2005-01-14 22:07:46 +0000241 // integer extending loads where it doesn't matter what the high
242 // bits are set to. The code generator is allowed to codegen this
243 // into whichever operation is more efficient.
244 EXTLOAD, SEXTLOAD, ZEXTLOAD,
245
246 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
247 // value and stores it to memory in one operation. This can be used for
Chris Lattnerf7db8c62005-07-10 00:28:25 +0000248 // either integer or floating point operands. The first four operands of
249 // this are the same as a standard store. The fifth is the ValueType to
250 // store it as (which will be smaller than the source value).
Chris Lattner1cff05c2005-01-14 22:07:46 +0000251 TRUNCSTORE,
252
Chris Lattner63b570d2005-01-07 07:45:27 +0000253 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
254 // to a specified boundary. The first operand is the token chain, the
255 // second is the number of bytes to allocate, and the third is the alignment
Chris Lattner74fe0632005-08-29 22:48:32 +0000256 // boundary. The size is guaranteed to be a multiple of the stack
257 // alignment, and the alignment is guaranteed to be bigger than the stack
258 // alignment (if required) or 0 to get standard stack alignment.
Chris Lattner63b570d2005-01-07 07:45:27 +0000259 DYNAMIC_STACKALLOC,
260
261 // Control flow instructions. These all have token chains.
Misha Brukmanea61c352005-04-21 20:39:54 +0000262
Chris Lattner63b570d2005-01-07 07:45:27 +0000263 // BR - Unconditional branch. The first operand is the chain
264 // operand, the second is the MBB to branch to.
265 BR,
266
267 // BRCOND - Conditional branch. The first operand is the chain,
268 // the second is the condition, the third is the block to branch
269 // to if the condition is true.
270 BRCOND,
271
Chris Lattner1df63382005-04-09 03:21:50 +0000272 // BRCONDTWOWAY - Two-way conditional branch. The first operand is the
273 // chain, the second is the condition, the third is the block to branch to
274 // if true, and the forth is the block to branch to if false. Targets
275 // usually do not implement this, preferring to have legalize demote the
276 // operation to BRCOND/BR pairs when necessary.
277 BRCONDTWOWAY,
278
Nate Begeman7cbd5252005-08-16 19:49:35 +0000279 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
280 // that the condition is represented as condition code, and two nodes to
281 // compare, rather than as a combined SetCC node. The operands in order are
282 // chain, cc, lhs, rhs, block to branch to if condition is true.
283 BR_CC,
284
285 // BRTWOWAY_CC - Two-way conditional branch. The operands in order are
286 // chain, cc, lhs, rhs, block to branch to if condition is true, block to
287 // branch to if condition is false. Targets usually do not implement this,
288 // preferring to have legalize demote the operation to BRCOND/BR pairs.
289 BRTWOWAY_CC,
290
Chris Lattner63b570d2005-01-07 07:45:27 +0000291 // RET - Return from function. The first operand is the chain,
292 // and any subsequent operands are the return values for the
293 // function. This operation can have variable number of operands.
294 RET,
295
296 // CALL - Call to a function pointer. The first operand is the chain, the
297 // second is the destination function pointer (a GlobalAddress for a direct
298 // call). Arguments have already been lowered to explicit DAGs according to
Chris Lattner4c1eae92005-05-13 18:40:17 +0000299 // the calling convention in effect here. TAILCALL is the same as CALL, but
300 // the callee is known not to access the stack of the caller.
Chris Lattner63b570d2005-01-07 07:45:27 +0000301 CALL,
Chris Lattner4c1eae92005-05-13 18:40:17 +0000302 TAILCALL,
Chris Lattneref36aa72005-01-11 05:56:17 +0000303
304 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
305 // correspond to the operands of the LLVM intrinsic functions. The only
306 // result is a token chain. The alignment argument is guaranteed to be a
307 // Constant node.
308 MEMSET,
309 MEMMOVE,
310 MEMCPY,
Misha Brukmanea61c352005-04-21 20:39:54 +0000311
Chris Lattner16cd04d2005-05-12 23:24:06 +0000312 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
313 // a call sequence, and carry arbitrary information that target might want
314 // to know. The first operand is a chain, the rest are specified by the
315 // target and not touched by the DAG optimizers.
316 CALLSEQ_START, // Beginning of a call sequence
317 CALLSEQ_END, // End of a call sequence
Chris Lattner63b570d2005-01-07 07:45:27 +0000318
Chris Lattner21074f42005-05-09 20:21:27 +0000319 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
320 // locations with their value. This allows one use alias analysis
321 // information in the backend.
322 SRCVALUE,
323
Misha Brukmane3f570c2005-03-31 21:30:35 +0000324 // PCMARKER - This corresponds to the pcmarker intrinsic.
Andrew Lenharth95762122005-03-31 21:24:06 +0000325 PCMARKER,
Chris Lattner63b570d2005-01-07 07:45:27 +0000326
Andrew Lenharthaeef8fc2005-11-11 16:45:18 +0000327 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
Andrew Lenharth8b91c772005-11-11 22:48:54 +0000328 // The only operand is a chain and a value and a chain are produced. The
329 // value is the contents of the architecture specific cycle counter like
330 // register (or other high accuracy low latency clock source)
Andrew Lenharthaeef8fc2005-11-11 16:45:18 +0000331 READCYCLECOUNTER,
332
Chris Lattner21074f42005-05-09 20:21:27 +0000333 // READPORT, WRITEPORT, READIO, WRITEIO - These correspond to the LLVM
334 // intrinsics of the same name. The first operand is a token chain, the
335 // other operands match the intrinsic. These produce a token chain in
336 // addition to a value (if any).
337 READPORT, WRITEPORT, READIO, WRITEIO,
Chris Lattnerd623e952005-10-05 06:34:34 +0000338
339 // HANDLENODE node - Used as a handle for various purposes.
340 HANDLENODE,
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000341
Chris Lattner63b570d2005-01-07 07:45:27 +0000342 // BUILTIN_OP_END - This must be the last enum value in this list.
343 BUILTIN_OP_END,
344 };
345
346 //===--------------------------------------------------------------------===//
347 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
348 /// below work out, when considering SETFALSE (something that never exists
349 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
350 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
351 /// to. If the "N" column is 1, the result of the comparison is undefined if
352 /// the input is a NAN.
353 ///
354 /// All of these (except for the 'always folded ops') should be handled for
355 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
356 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
357 ///
358 /// Note that these are laid out in a specific order to allow bit-twiddling
359 /// to transform conditions.
360 enum CondCode {
361 // Opcode N U L G E Intuitive operation
362 SETFALSE, // 0 0 0 0 Always false (always folded)
363 SETOEQ, // 0 0 0 1 True if ordered and equal
364 SETOGT, // 0 0 1 0 True if ordered and greater than
365 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
366 SETOLT, // 0 1 0 0 True if ordered and less than
367 SETOLE, // 0 1 0 1 True if ordered and less than or equal
368 SETONE, // 0 1 1 0 True if ordered and operands are unequal
369 SETO, // 0 1 1 1 True if ordered (no nans)
370 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
371 SETUEQ, // 1 0 0 1 True if unordered or equal
372 SETUGT, // 1 0 1 0 True if unordered or greater than
373 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
374 SETULT, // 1 1 0 0 True if unordered or less than
Misha Brukmanea61c352005-04-21 20:39:54 +0000375 SETULE, // 1 1 0 1 True if unordered, less than, or equal
Chris Lattner63b570d2005-01-07 07:45:27 +0000376 SETUNE, // 1 1 1 0 True if unordered or not equal
377 SETTRUE, // 1 1 1 1 Always true (always folded)
378 // Don't care operations: undefined if the input is a nan.
379 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
380 SETEQ, // 1 X 0 0 1 True if equal
381 SETGT, // 1 X 0 1 0 True if greater than
382 SETGE, // 1 X 0 1 1 True if greater than or equal
383 SETLT, // 1 X 1 0 0 True if less than
Misha Brukmanea61c352005-04-21 20:39:54 +0000384 SETLE, // 1 X 1 0 1 True if less than or equal
Chris Lattner63b570d2005-01-07 07:45:27 +0000385 SETNE, // 1 X 1 1 0 True if not equal
386 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
387
388 SETCC_INVALID, // Marker value.
389 };
390
391 /// isSignedIntSetCC - Return true if this is a setcc instruction that
392 /// performs a signed comparison when used with integer operands.
393 inline bool isSignedIntSetCC(CondCode Code) {
394 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
395 }
396
397 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
398 /// performs an unsigned comparison when used with integer operands.
399 inline bool isUnsignedIntSetCC(CondCode Code) {
400 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
401 }
402
403 /// isTrueWhenEqual - Return true if the specified condition returns true if
404 /// the two operands to the condition are equal. Note that if one of the two
405 /// operands is a NaN, this value is meaningless.
406 inline bool isTrueWhenEqual(CondCode Cond) {
407 return ((int)Cond & 1) != 0;
408 }
409
410 /// getUnorderedFlavor - This function returns 0 if the condition is always
411 /// false if an operand is a NaN, 1 if the condition is always true if the
412 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
413 /// NaN.
414 inline unsigned getUnorderedFlavor(CondCode Cond) {
415 return ((int)Cond >> 3) & 3;
416 }
417
418 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
419 /// 'op' is a valid SetCC operation.
420 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
421
422 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
423 /// when given the operation for (X op Y).
424 CondCode getSetCCSwappedOperands(CondCode Operation);
425
426 /// getSetCCOrOperation - Return the result of a logical OR between different
427 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
428 /// function returns SETCC_INVALID if it is not possible to represent the
429 /// resultant comparison.
430 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
431
432 /// getSetCCAndOperation - Return the result of a logical AND between
433 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
434 /// function returns SETCC_INVALID if it is not possible to represent the
435 /// resultant comparison.
436 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
437} // end llvm::ISD namespace
438
439
440//===----------------------------------------------------------------------===//
441/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
442/// values as the result of a computation. Many nodes return multiple values,
443/// from loads (which define a token and a return value) to ADDC (which returns
444/// a result and a carry value), to calls (which may return an arbitrary number
445/// of values).
446///
447/// As such, each use of a SelectionDAG computation must indicate the node that
448/// computes it as well as which return value to use from that node. This pair
449/// of information is represented with the SDOperand value type.
450///
Chris Lattnerf26bc8e2005-01-08 19:52:31 +0000451class SDOperand {
452public:
Chris Lattner63b570d2005-01-07 07:45:27 +0000453 SDNode *Val; // The node defining the value we are using.
454 unsigned ResNo; // Which return value of the node we are using.
455
456 SDOperand() : Val(0) {}
457 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
458
459 bool operator==(const SDOperand &O) const {
460 return Val == O.Val && ResNo == O.ResNo;
461 }
462 bool operator!=(const SDOperand &O) const {
463 return !operator==(O);
464 }
465 bool operator<(const SDOperand &O) const {
466 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
467 }
468
469 SDOperand getValue(unsigned R) const {
470 return SDOperand(Val, R);
471 }
472
473 /// getValueType - Return the ValueType of the referenced return value.
474 ///
475 inline MVT::ValueType getValueType() const;
Misha Brukmanea61c352005-04-21 20:39:54 +0000476
Chris Lattner63b570d2005-01-07 07:45:27 +0000477 // Forwarding methods - These forward to the corresponding methods in SDNode.
478 inline unsigned getOpcode() const;
Chris Lattner0442fbf2005-01-21 21:39:38 +0000479 inline unsigned getNodeDepth() const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000480 inline unsigned getNumOperands() const;
481 inline const SDOperand &getOperand(unsigned i) const;
Nate Begeman0f66a912005-08-17 23:44:54 +0000482 inline bool isTargetOpcode() const;
483 inline unsigned getTargetOpcode() const;
Chris Lattnera44f4ae2005-01-13 22:58:50 +0000484
485 /// hasOneUse - Return true if there is exactly one operation using this
486 /// result value of the defining operator.
487 inline bool hasOneUse() const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000488};
489
490
491/// simplify_type specializations - Allow casting operators to work directly on
492/// SDOperands as if they were SDNode*'s.
493template<> struct simplify_type<SDOperand> {
494 typedef SDNode* SimpleType;
495 static SimpleType getSimplifiedValue(const SDOperand &Val) {
496 return static_cast<SimpleType>(Val.Val);
497 }
498};
499template<> struct simplify_type<const SDOperand> {
500 typedef SDNode* SimpleType;
501 static SimpleType getSimplifiedValue(const SDOperand &Val) {
502 return static_cast<SimpleType>(Val.Val);
503 }
504};
505
506
507/// SDNode - Represents one node in the SelectionDAG.
508///
509class SDNode {
Chris Lattner0442fbf2005-01-21 21:39:38 +0000510 /// NodeType - The operation that this node performs.
511 ///
512 unsigned short NodeType;
513
514 /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1. This
515 /// means that leaves have a depth of 1, things that use only leaves have a
516 /// depth of 2, etc.
517 unsigned short NodeDepth;
518
Chris Lattnerf71e8432005-11-08 22:06:23 +0000519 /// OperandList - The values that are used by this operation.
Chris Lattner0442fbf2005-01-21 21:39:38 +0000520 ///
Chris Lattnerf71e8432005-11-08 22:06:23 +0000521 SDOperand *OperandList;
522
523 /// ValueList - The types of the values this node defines. SDNode's may
524 /// define multiple values simultaneously.
525 MVT::ValueType *ValueList;
Chris Lattner63b570d2005-01-07 07:45:27 +0000526
Chris Lattnerf71e8432005-11-08 22:06:23 +0000527 /// NumOperands/NumValues - The number of entries in the Operand/Value list.
528 unsigned short NumOperands, NumValues;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000529
530 /// Prev/Next pointers - These pointers form the linked list of of the
531 /// AllNodes list in the current DAG.
532 SDNode *Prev, *Next;
533 friend struct ilist_traits<SDNode>;
Chris Lattner63b570d2005-01-07 07:45:27 +0000534
535 /// Uses - These are all of the SDNode's that use a value produced by this
536 /// node.
537 std::vector<SDNode*> Uses;
538public:
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000539 virtual ~SDNode() {
540 assert(NumOperands == 0 && "Operand list not cleared before deletion");
541 }
542
Chris Lattner63b570d2005-01-07 07:45:27 +0000543 //===--------------------------------------------------------------------===//
544 // Accessors
545 //
546 unsigned getOpcode() const { return NodeType; }
Nate Begeman0f66a912005-08-17 23:44:54 +0000547 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
548 unsigned getTargetOpcode() const {
549 assert(isTargetOpcode() && "Not a target opcode!");
550 return NodeType - ISD::BUILTIN_OP_END;
551 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000552
553 size_t use_size() const { return Uses.size(); }
554 bool use_empty() const { return Uses.empty(); }
555 bool hasOneUse() const { return Uses.size() == 1; }
556
Chris Lattner0442fbf2005-01-21 21:39:38 +0000557 /// getNodeDepth - Return the distance from this node to the leaves in the
558 /// graph. The leaves have a depth of 1.
559 unsigned getNodeDepth() const { return NodeDepth; }
560
Chris Lattner7ece3802005-01-17 02:24:59 +0000561 typedef std::vector<SDNode*>::const_iterator use_iterator;
562 use_iterator use_begin() const { return Uses.begin(); }
563 use_iterator use_end() const { return Uses.end(); }
564
Chris Lattnerb18a2f82005-01-12 18:37:33 +0000565 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
566 /// indicated value. This method ignores uses of other values defined by this
567 /// operation.
568 bool hasNUsesOfValue(unsigned NUses, unsigned Value);
569
Chris Lattner63b570d2005-01-07 07:45:27 +0000570 /// getNumOperands - Return the number of values used by this operation.
571 ///
Chris Lattnerf71e8432005-11-08 22:06:23 +0000572 unsigned getNumOperands() const { return NumOperands; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000573
574 const SDOperand &getOperand(unsigned Num) const {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000575 assert(Num < NumOperands && "Invalid child # of SDNode!");
576 return OperandList[Num];
Chris Lattner63b570d2005-01-07 07:45:27 +0000577 }
Chris Lattnerf71e8432005-11-08 22:06:23 +0000578 typedef const SDOperand* op_iterator;
579 op_iterator op_begin() const { return OperandList; }
580 op_iterator op_end() const { return OperandList+NumOperands; }
Chris Lattner50f5a512005-05-14 06:19:11 +0000581
Chris Lattner63b570d2005-01-07 07:45:27 +0000582
583 /// getNumValues - Return the number of values defined/returned by this
584 /// operator.
585 ///
Chris Lattnerf71e8432005-11-08 22:06:23 +0000586 unsigned getNumValues() const { return NumValues; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000587
588 /// getValueType - Return the type of a specified result.
589 ///
590 MVT::ValueType getValueType(unsigned ResNo) const {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000591 assert(ResNo < NumValues && "Illegal result number!");
592 return ValueList[ResNo];
Chris Lattner63b570d2005-01-07 07:45:27 +0000593 }
Jeff Cohen9eb59ec2005-07-27 05:53:44 +0000594
Chris Lattnerf71e8432005-11-08 22:06:23 +0000595 typedef const MVT::ValueType* value_iterator;
596 value_iterator value_begin() const { return ValueList; }
597 value_iterator value_end() const { return ValueList+NumValues; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000598
Chris Lattner6e6e3ce2005-01-10 23:25:04 +0000599 /// getOperationName - Return the opcode of this operation for printing.
600 ///
Chris Lattnerefe58692005-08-16 18:32:18 +0000601 const char* getOperationName(const SelectionDAG *G = 0) const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000602 void dump() const;
Chris Lattnerefe58692005-08-16 18:32:18 +0000603 void dump(const SelectionDAG *G) const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000604
605 static bool classof(const SDNode *) { return true; }
606
Chris Lattner73b35372005-05-11 18:56:45 +0000607
608 /// setAdjCallChain - This method should only be used by the legalizer.
609 void setAdjCallChain(SDOperand N);
Jeff Cohen9eb59ec2005-07-27 05:53:44 +0000610
Chris Lattner63b570d2005-01-07 07:45:27 +0000611protected:
612 friend class SelectionDAG;
Chris Lattner109654f2005-11-08 23:30:11 +0000613
614 /// getValueTypeList - Return a pointer to the specified value type.
615 ///
616 static MVT::ValueType *getValueTypeList(MVT::ValueType VT);
Chris Lattner63b570d2005-01-07 07:45:27 +0000617
Chris Lattner0442fbf2005-01-21 21:39:38 +0000618 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000619 OperandList = 0; NumOperands = 0;
Chris Lattner109654f2005-11-08 23:30:11 +0000620 ValueList = getValueTypeList(VT);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000621 NumValues = 1;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000622 Prev = 0; Next = 0;
Chris Lattner63b570d2005-01-07 07:45:27 +0000623 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000624 SDNode(unsigned NT, SDOperand Op)
Chris Lattner0442fbf2005-01-21 21:39:38 +0000625 : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000626 OperandList = new SDOperand[1];
627 OperandList[0] = Op;
628 NumOperands = 1;
Chris Lattner63b570d2005-01-07 07:45:27 +0000629 Op.Val->Uses.push_back(this);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000630 ValueList = 0;
631 NumValues = 0;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000632 Prev = 0; Next = 0;
Chris Lattner63b570d2005-01-07 07:45:27 +0000633 }
634 SDNode(unsigned NT, SDOperand N1, SDOperand N2)
635 : NodeType(NT) {
Chris Lattner0442fbf2005-01-21 21:39:38 +0000636 if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth())
637 NodeDepth = N1.Val->getNodeDepth()+1;
638 else
639 NodeDepth = N2.Val->getNodeDepth()+1;
Chris Lattnerf71e8432005-11-08 22:06:23 +0000640 OperandList = new SDOperand[2];
641 OperandList[0] = N1;
642 OperandList[1] = N2;
643 NumOperands = 2;
Chris Lattner63b570d2005-01-07 07:45:27 +0000644 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000645 ValueList = 0;
646 NumValues = 0;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000647 Prev = 0; Next = 0;
Chris Lattner63b570d2005-01-07 07:45:27 +0000648 }
649 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
650 : NodeType(NT) {
Chris Lattner0442fbf2005-01-21 21:39:38 +0000651 unsigned ND = N1.Val->getNodeDepth();
652 if (ND < N2.Val->getNodeDepth())
653 ND = N2.Val->getNodeDepth();
654 if (ND < N3.Val->getNodeDepth())
655 ND = N3.Val->getNodeDepth();
656 NodeDepth = ND+1;
657
Chris Lattnerf71e8432005-11-08 22:06:23 +0000658 OperandList = new SDOperand[3];
659 OperandList[0] = N1;
660 OperandList[1] = N2;
661 OperandList[2] = N3;
662 NumOperands = 3;
663
Chris Lattner63b570d2005-01-07 07:45:27 +0000664 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
665 N3.Val->Uses.push_back(this);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000666 ValueList = 0;
667 NumValues = 0;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000668 Prev = 0; Next = 0;
Chris Lattner63b570d2005-01-07 07:45:27 +0000669 }
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000670 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4)
671 : NodeType(NT) {
672 unsigned ND = N1.Val->getNodeDepth();
673 if (ND < N2.Val->getNodeDepth())
674 ND = N2.Val->getNodeDepth();
675 if (ND < N3.Val->getNodeDepth())
676 ND = N3.Val->getNodeDepth();
677 if (ND < N4.Val->getNodeDepth())
678 ND = N4.Val->getNodeDepth();
679 NodeDepth = ND+1;
680
Chris Lattnerf71e8432005-11-08 22:06:23 +0000681 OperandList = new SDOperand[4];
682 OperandList[0] = N1;
683 OperandList[1] = N2;
684 OperandList[2] = N3;
685 OperandList[3] = N4;
686 NumOperands = 4;
687
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000688 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
689 N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000690 ValueList = 0;
691 NumValues = 0;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000692 Prev = 0; Next = 0;
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000693 }
Chris Lattnerf71e8432005-11-08 22:06:23 +0000694 SDNode(unsigned Opc, const std::vector<SDOperand> &Nodes) : NodeType(Opc) {
695 NumOperands = Nodes.size();
696 OperandList = new SDOperand[NumOperands];
697
Chris Lattner0442fbf2005-01-21 21:39:38 +0000698 unsigned ND = 0;
Chris Lattnerf71e8432005-11-08 22:06:23 +0000699 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) {
700 OperandList[i] = Nodes[i];
701 SDNode *N = OperandList[i].Val;
702 N->Uses.push_back(this);
703 if (ND < N->getNodeDepth()) ND = N->getNodeDepth();
Chris Lattner0442fbf2005-01-21 21:39:38 +0000704 }
705 NodeDepth = ND+1;
Chris Lattnerf71e8432005-11-08 22:06:23 +0000706 ValueList = 0;
707 NumValues = 0;
Chris Lattnerb80e2be2005-11-09 23:46:43 +0000708 Prev = 0; Next = 0;
Chris Lattnerf71e8432005-11-08 22:06:23 +0000709 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000710
Chris Lattner1b950952005-08-16 18:16:24 +0000711 /// MorphNodeTo - This clears the return value and operands list, and sets the
712 /// opcode of the node to the specified value. This should only be used by
713 /// the SelectionDAG class.
714 void MorphNodeTo(unsigned Opc) {
715 NodeType = Opc;
Chris Lattnerf71e8432005-11-08 22:06:23 +0000716 ValueList = 0;
717 NumValues = 0;
Chris Lattnerb467f8a2005-08-17 01:54:00 +0000718
719 // Clear the operands list, updating used nodes to remove this from their
720 // use list.
Chris Lattnerf71e8432005-11-08 22:06:23 +0000721 for (op_iterator I = op_begin(), E = op_end(); I != E; ++I)
722 I->Val->removeUser(this);
723 delete [] OperandList;
724 OperandList = 0;
725 NumOperands = 0;
Chris Lattner1b950952005-08-16 18:16:24 +0000726 }
727
Chris Lattner63b570d2005-01-07 07:45:27 +0000728 void setValueTypes(MVT::ValueType VT) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000729 assert(NumValues == 0 && "Should not have values yet!");
Chris Lattner109654f2005-11-08 23:30:11 +0000730 ValueList = getValueTypeList(VT);
Chris Lattnerf71e8432005-11-08 22:06:23 +0000731 NumValues = 1;
Chris Lattner63b570d2005-01-07 07:45:27 +0000732 }
Chris Lattner109654f2005-11-08 23:30:11 +0000733 void setValueTypes(MVT::ValueType *List, unsigned NumVal) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000734 assert(NumValues == 0 && "Should not have values yet!");
Chris Lattner109654f2005-11-08 23:30:11 +0000735 ValueList = List;
736 NumValues = NumVal;
Chris Lattner63b570d2005-01-07 07:45:27 +0000737 }
Chris Lattner1b950952005-08-16 18:16:24 +0000738
739 void setOperands(SDOperand Op0) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000740 assert(NumOperands == 0 && "Should not have operands yet!");
741 OperandList = new SDOperand[1];
742 OperandList[0] = Op0;
743 NumOperands = 1;
Chris Lattner8c3484c2005-08-17 18:58:38 +0000744 Op0.Val->Uses.push_back(this);
Chris Lattner1b950952005-08-16 18:16:24 +0000745 }
746 void setOperands(SDOperand Op0, SDOperand Op1) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000747 assert(NumOperands == 0 && "Should not have operands yet!");
748 OperandList = new SDOperand[2];
749 OperandList[0] = Op0;
750 OperandList[1] = Op1;
751 NumOperands = 2;
Chris Lattner8c3484c2005-08-17 18:58:38 +0000752 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
Chris Lattner1b950952005-08-16 18:16:24 +0000753 }
754 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000755 assert(NumOperands == 0 && "Should not have operands yet!");
756 OperandList = new SDOperand[3];
757 OperandList[0] = Op0;
758 OperandList[1] = Op1;
759 OperandList[2] = Op2;
760 NumOperands = 3;
Chris Lattner8c3484c2005-08-17 18:58:38 +0000761 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
762 Op2.Val->Uses.push_back(this);
763 }
Nate Begeman294a0a12005-08-18 07:30:15 +0000764 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000765 assert(NumOperands == 0 && "Should not have operands yet!");
766 OperandList = new SDOperand[4];
767 OperandList[0] = Op0;
768 OperandList[1] = Op1;
769 OperandList[2] = Op2;
770 OperandList[3] = Op3;
771 NumOperands = 4;
Nate Begeman294a0a12005-08-18 07:30:15 +0000772 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
773 Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
774 }
Chris Lattnerd54209f2005-08-21 18:49:58 +0000775 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
776 SDOperand Op4) {
Chris Lattnerf71e8432005-11-08 22:06:23 +0000777 assert(NumOperands == 0 && "Should not have operands yet!");
778 OperandList = new SDOperand[5];
779 OperandList[0] = Op0;
780 OperandList[1] = Op1;
781 OperandList[2] = Op2;
782 OperandList[3] = Op3;
783 OperandList[4] = Op4;
784 NumOperands = 5;
Chris Lattnerd54209f2005-08-21 18:49:58 +0000785 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
786 Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
787 Op4.Val->Uses.push_back(this);
788 }
Chris Lattner8c3484c2005-08-17 18:58:38 +0000789 void addUser(SDNode *User) {
790 Uses.push_back(User);
Chris Lattner1b950952005-08-16 18:16:24 +0000791 }
Chris Lattnerd1fc9642005-01-07 21:08:55 +0000792 void removeUser(SDNode *User) {
793 // Remove this user from the operand's use list.
794 for (unsigned i = Uses.size(); ; --i) {
795 assert(i != 0 && "Didn't find user!");
796 if (Uses[i-1] == User) {
Chris Lattner8c3484c2005-08-17 18:58:38 +0000797 Uses[i-1] = Uses.back();
798 Uses.pop_back();
799 return;
Chris Lattnerd1fc9642005-01-07 21:08:55 +0000800 }
801 }
802 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000803};
804
805
806// Define inline functions from the SDOperand class.
807
808inline unsigned SDOperand::getOpcode() const {
809 return Val->getOpcode();
810}
Chris Lattner0442fbf2005-01-21 21:39:38 +0000811inline unsigned SDOperand::getNodeDepth() const {
812 return Val->getNodeDepth();
813}
Chris Lattner63b570d2005-01-07 07:45:27 +0000814inline MVT::ValueType SDOperand::getValueType() const {
815 return Val->getValueType(ResNo);
816}
817inline unsigned SDOperand::getNumOperands() const {
818 return Val->getNumOperands();
819}
820inline const SDOperand &SDOperand::getOperand(unsigned i) const {
821 return Val->getOperand(i);
822}
Nate Begeman0f66a912005-08-17 23:44:54 +0000823inline bool SDOperand::isTargetOpcode() const {
824 return Val->isTargetOpcode();
825}
826inline unsigned SDOperand::getTargetOpcode() const {
827 return Val->getTargetOpcode();
828}
Chris Lattnera44f4ae2005-01-13 22:58:50 +0000829inline bool SDOperand::hasOneUse() const {
830 return Val->hasNUsesOfValue(1, ResNo);
831}
Chris Lattner63b570d2005-01-07 07:45:27 +0000832
Chris Lattnerd623e952005-10-05 06:34:34 +0000833/// HandleSDNode - This class is used to form a handle around another node that
834/// is persistant and is updated across invocations of replaceAllUsesWith on its
835/// operand. This node should be directly created by end-users and not added to
836/// the AllNodes list.
837class HandleSDNode : public SDNode {
838public:
839 HandleSDNode(SDOperand X) : SDNode(ISD::HANDLENODE, X) {}
840 ~HandleSDNode() {
841 MorphNodeTo(ISD::HANDLENODE); // Drops operand uses.
842 }
843
844 SDOperand getValue() const { return getOperand(0); }
845};
846
Chris Lattner63b570d2005-01-07 07:45:27 +0000847
848class ConstantSDNode : public SDNode {
849 uint64_t Value;
850protected:
851 friend class SelectionDAG;
Chris Lattner056f9f62005-08-17 00:33:30 +0000852 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
853 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, VT), Value(val) {
Chris Lattner63b570d2005-01-07 07:45:27 +0000854 }
855public:
856
857 uint64_t getValue() const { return Value; }
858
859 int64_t getSignExtended() const {
860 unsigned Bits = MVT::getSizeInBits(getValueType(0));
Chris Lattnerf26bc8e2005-01-08 19:52:31 +0000861 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
Chris Lattner63b570d2005-01-07 07:45:27 +0000862 }
863
864 bool isNullValue() const { return Value == 0; }
865 bool isAllOnesValue() const {
Chris Lattner2bffad32005-04-08 21:31:29 +0000866 int NumBits = MVT::getSizeInBits(getValueType(0));
867 if (NumBits == 64) return Value+1 == 0;
868 return Value == (1ULL << NumBits)-1;
Chris Lattner63b570d2005-01-07 07:45:27 +0000869 }
870
871 static bool classof(const ConstantSDNode *) { return true; }
872 static bool classof(const SDNode *N) {
Chris Lattner056f9f62005-08-17 00:33:30 +0000873 return N->getOpcode() == ISD::Constant ||
874 N->getOpcode() == ISD::TargetConstant;
Chris Lattner63b570d2005-01-07 07:45:27 +0000875 }
876};
877
878class ConstantFPSDNode : public SDNode {
879 double Value;
880protected:
881 friend class SelectionDAG;
882 ConstantFPSDNode(double val, MVT::ValueType VT)
883 : SDNode(ISD::ConstantFP, VT), Value(val) {
884 }
885public:
886
887 double getValue() const { return Value; }
888
889 /// isExactlyValue - We don't rely on operator== working on double values, as
890 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
891 /// As such, this method can be used to do an exact bit-for-bit comparison of
892 /// two floating point values.
Jim Laskey58b968b2005-08-17 20:08:02 +0000893 bool isExactlyValue(double V) const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000894
895 static bool classof(const ConstantFPSDNode *) { return true; }
896 static bool classof(const SDNode *N) {
897 return N->getOpcode() == ISD::ConstantFP;
898 }
899};
900
901class GlobalAddressSDNode : public SDNode {
902 GlobalValue *TheGlobal;
903protected:
904 friend class SelectionDAG;
Chris Lattnerf6b18492005-08-19 22:31:34 +0000905 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT)
906 : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT) {
Chris Lattner63b570d2005-01-07 07:45:27 +0000907 TheGlobal = const_cast<GlobalValue*>(GA);
Chris Lattner63b570d2005-01-07 07:45:27 +0000908 }
909public:
910
911 GlobalValue *getGlobal() const { return TheGlobal; }
912
913 static bool classof(const GlobalAddressSDNode *) { return true; }
914 static bool classof(const SDNode *N) {
Chris Lattnerf6b18492005-08-19 22:31:34 +0000915 return N->getOpcode() == ISD::GlobalAddress ||
916 N->getOpcode() == ISD::TargetGlobalAddress;
Chris Lattner63b570d2005-01-07 07:45:27 +0000917 }
918};
919
920
921class FrameIndexSDNode : public SDNode {
922 int FI;
923protected:
924 friend class SelectionDAG;
Chris Lattnerafb2dd42005-08-25 00:43:01 +0000925 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
926 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, VT), FI(fi) {}
Chris Lattner63b570d2005-01-07 07:45:27 +0000927public:
928
929 int getIndex() const { return FI; }
930
931 static bool classof(const FrameIndexSDNode *) { return true; }
932 static bool classof(const SDNode *N) {
Chris Lattnerafb2dd42005-08-25 00:43:01 +0000933 return N->getOpcode() == ISD::FrameIndex ||
934 N->getOpcode() == ISD::TargetFrameIndex;
Chris Lattner63b570d2005-01-07 07:45:27 +0000935 }
936};
937
938class ConstantPoolSDNode : public SDNode {
Chris Lattner5839bf22005-08-26 17:15:30 +0000939 Constant *C;
Chris Lattner63b570d2005-01-07 07:45:27 +0000940protected:
941 friend class SelectionDAG;
Chris Lattner5839bf22005-08-26 17:15:30 +0000942 ConstantPoolSDNode(Constant *c, MVT::ValueType VT, bool isTarget)
Chris Lattneraaaaf792005-08-25 05:02:41 +0000943 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
Chris Lattner5839bf22005-08-26 17:15:30 +0000944 C(c) {}
Chris Lattner63b570d2005-01-07 07:45:27 +0000945public:
946
Chris Lattner5839bf22005-08-26 17:15:30 +0000947 Constant *get() const { return C; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000948
949 static bool classof(const ConstantPoolSDNode *) { return true; }
950 static bool classof(const SDNode *N) {
Chris Lattneraaaaf792005-08-25 05:02:41 +0000951 return N->getOpcode() == ISD::ConstantPool ||
952 N->getOpcode() == ISD::TargetConstantPool;
Chris Lattner63b570d2005-01-07 07:45:27 +0000953 }
954};
955
956class BasicBlockSDNode : public SDNode {
957 MachineBasicBlock *MBB;
958protected:
959 friend class SelectionDAG;
960 BasicBlockSDNode(MachineBasicBlock *mbb)
961 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
962public:
963
964 MachineBasicBlock *getBasicBlock() const { return MBB; }
965
966 static bool classof(const BasicBlockSDNode *) { return true; }
967 static bool classof(const SDNode *N) {
968 return N->getOpcode() == ISD::BasicBlock;
969 }
970};
971
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000972class SrcValueSDNode : public SDNode {
973 const Value *V;
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000974 int offset;
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000975protected:
976 friend class SelectionDAG;
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000977 SrcValueSDNode(const Value* v, int o)
978 : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {}
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000979
980public:
981 const Value *getValue() const { return V; }
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000982 int getOffset() const { return offset; }
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000983
984 static bool classof(const SrcValueSDNode *) { return true; }
985 static bool classof(const SDNode *N) {
986 return N->getOpcode() == ISD::SRCVALUE;
987 }
988};
989
Chris Lattner63b570d2005-01-07 07:45:27 +0000990
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +0000991class RegisterSDNode : public SDNode {
Chris Lattner63b570d2005-01-07 07:45:27 +0000992 unsigned Reg;
993protected:
994 friend class SelectionDAG;
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +0000995 RegisterSDNode(unsigned reg, MVT::ValueType VT)
996 : SDNode(ISD::Register, VT), Reg(reg) {}
Chris Lattner63b570d2005-01-07 07:45:27 +0000997public:
998
999 unsigned getReg() const { return Reg; }
1000
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +00001001 static bool classof(const RegisterSDNode *) { return true; }
Chris Lattner63b570d2005-01-07 07:45:27 +00001002 static bool classof(const SDNode *N) {
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +00001003 return N->getOpcode() == ISD::Register;
Chris Lattner63b570d2005-01-07 07:45:27 +00001004 }
1005};
1006
1007class ExternalSymbolSDNode : public SDNode {
1008 const char *Symbol;
1009protected:
1010 friend class SelectionDAG;
Andrew Lenharth2a2de662005-10-23 03:40:17 +00001011 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1012 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, VT),
1013 Symbol(Sym) {
Chris Lattner63b570d2005-01-07 07:45:27 +00001014 }
1015public:
1016
1017 const char *getSymbol() const { return Symbol; }
1018
1019 static bool classof(const ExternalSymbolSDNode *) { return true; }
1020 static bool classof(const SDNode *N) {
Andrew Lenharth2a2de662005-10-23 03:40:17 +00001021 return N->getOpcode() == ISD::ExternalSymbol ||
1022 N->getOpcode() == ISD::TargetExternalSymbol;
Chris Lattner63b570d2005-01-07 07:45:27 +00001023 }
1024};
1025
Chris Lattner7cf7e3f2005-08-09 20:20:18 +00001026class CondCodeSDNode : public SDNode {
Chris Lattner63b570d2005-01-07 07:45:27 +00001027 ISD::CondCode Condition;
1028protected:
1029 friend class SelectionDAG;
Chris Lattner7cf7e3f2005-08-09 20:20:18 +00001030 CondCodeSDNode(ISD::CondCode Cond)
1031 : SDNode(ISD::CONDCODE, MVT::Other), Condition(Cond) {
Chris Lattner63b570d2005-01-07 07:45:27 +00001032 }
1033public:
1034
Chris Lattner7cf7e3f2005-08-09 20:20:18 +00001035 ISD::CondCode get() const { return Condition; }
Chris Lattner63b570d2005-01-07 07:45:27 +00001036
Chris Lattner7cf7e3f2005-08-09 20:20:18 +00001037 static bool classof(const CondCodeSDNode *) { return true; }
Chris Lattner63b570d2005-01-07 07:45:27 +00001038 static bool classof(const SDNode *N) {
Chris Lattner7cf7e3f2005-08-09 20:20:18 +00001039 return N->getOpcode() == ISD::CONDCODE;
Chris Lattner63b570d2005-01-07 07:45:27 +00001040 }
1041};
1042
Chris Lattner15e4b012005-07-10 00:07:11 +00001043/// VTSDNode - This class is used to represent MVT::ValueType's, which are used
1044/// to parameterize some operations.
1045class VTSDNode : public SDNode {
1046 MVT::ValueType ValueType;
1047protected:
1048 friend class SelectionDAG;
1049 VTSDNode(MVT::ValueType VT)
1050 : SDNode(ISD::VALUETYPE, MVT::Other), ValueType(VT) {}
1051public:
1052
1053 MVT::ValueType getVT() const { return ValueType; }
1054
1055 static bool classof(const VTSDNode *) { return true; }
1056 static bool classof(const SDNode *N) {
1057 return N->getOpcode() == ISD::VALUETYPE;
1058 }
1059};
1060
1061
Chris Lattner1080b9e2005-01-10 23:05:53 +00001062class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
1063 SDNode *Node;
1064 unsigned Operand;
Misha Brukmanea61c352005-04-21 20:39:54 +00001065
Chris Lattner1080b9e2005-01-10 23:05:53 +00001066 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1067public:
1068 bool operator==(const SDNodeIterator& x) const {
1069 return Operand == x.Operand;
1070 }
1071 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1072
1073 const SDNodeIterator &operator=(const SDNodeIterator &I) {
1074 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1075 Operand = I.Operand;
1076 return *this;
1077 }
Misha Brukmanea61c352005-04-21 20:39:54 +00001078
Chris Lattner1080b9e2005-01-10 23:05:53 +00001079 pointer operator*() const {
1080 return Node->getOperand(Operand).Val;
1081 }
1082 pointer operator->() const { return operator*(); }
Misha Brukmanea61c352005-04-21 20:39:54 +00001083
Chris Lattner1080b9e2005-01-10 23:05:53 +00001084 SDNodeIterator& operator++() { // Preincrement
1085 ++Operand;
1086 return *this;
1087 }
1088 SDNodeIterator operator++(int) { // Postincrement
Misha Brukmanea61c352005-04-21 20:39:54 +00001089 SDNodeIterator tmp = *this; ++*this; return tmp;
Chris Lattner1080b9e2005-01-10 23:05:53 +00001090 }
1091
1092 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
1093 static SDNodeIterator end (SDNode *N) {
1094 return SDNodeIterator(N, N->getNumOperands());
1095 }
1096
1097 unsigned getOperand() const { return Operand; }
1098 const SDNode *getNode() const { return Node; }
1099};
1100
1101template <> struct GraphTraits<SDNode*> {
1102 typedef SDNode NodeType;
1103 typedef SDNodeIterator ChildIteratorType;
1104 static inline NodeType *getEntryNode(SDNode *N) { return N; }
Misha Brukmanea61c352005-04-21 20:39:54 +00001105 static inline ChildIteratorType child_begin(NodeType *N) {
Chris Lattner1080b9e2005-01-10 23:05:53 +00001106 return SDNodeIterator::begin(N);
1107 }
Misha Brukmanea61c352005-04-21 20:39:54 +00001108 static inline ChildIteratorType child_end(NodeType *N) {
Chris Lattner1080b9e2005-01-10 23:05:53 +00001109 return SDNodeIterator::end(N);
1110 }
1111};
1112
Chris Lattnerb80e2be2005-11-09 23:46:43 +00001113template<>
1114struct ilist_traits<SDNode> {
1115 static SDNode *getPrev(const SDNode *N) { return N->Prev; }
1116 static SDNode *getNext(const SDNode *N) { return N->Next; }
1117
1118 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
1119 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
1120
1121 static SDNode *createSentinel() {
1122 return new SDNode(ISD::EntryToken, MVT::Other);
1123 }
1124 static void destroySentinel(SDNode *N) { delete N; }
1125 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
1126
1127
1128 void addNodeToList(SDNode *NTy) {}
1129 void removeNodeFromList(SDNode *NTy) {}
1130 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
1131 const ilist_iterator<SDNode> &X,
1132 const ilist_iterator<SDNode> &Y) {}
1133};
1134
Chris Lattner63b570d2005-01-07 07:45:27 +00001135} // end llvm namespace
1136
1137#endif