blob: 8d5cf1065623b0ac811658930c9d0dfb241a51b6 [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"
25#include "llvm/ADT/GraphTraits.h"
26#include "llvm/ADT/iterator"
Jeff Cohen39931a32005-01-07 19:21:49 +000027#include "llvm/Support/DataTypes.h"
Chris Lattner63b570d2005-01-07 07:45:27 +000028#include <cassert>
29#include <vector>
30
31namespace llvm {
32
33class SelectionDAG;
34class GlobalValue;
35class MachineBasicBlock;
36class SDNode;
37template <typename T> struct simplify_type;
38
39/// ISD namespace - This namespace contains an enum which represents all of the
40/// SelectionDAG node types and value types.
41///
42namespace ISD {
43 //===--------------------------------------------------------------------===//
44 /// ISD::NodeType enum - This enum defines all of the operators valid in a
45 /// SelectionDAG.
46 ///
47 enum NodeType {
Chris Lattner8a496fc2005-01-13 17:58:35 +000048 // EntryToken - This is the marker used to indicate the start of the region.
49 EntryToken,
50
Reid Spencer8c4bde32005-08-27 19:06:05 +000051 // Token factor - This node takes multiple tokens as input and produces a
Chris Lattner8a496fc2005-01-13 17:58:35 +000052 // single token result. This is used to represent the fact that the operand
53 // operators are independent of each other.
54 TokenFactor,
Nate Begemanf7f3d322005-08-30 02:39:32 +000055
56 // AssertSext, AssertZext - These nodes record if a register contains a
57 // value that has already been zero or sign extended from a narrower type.
58 // These nodes take two operands. The first is the node that has already
59 // been extended, and the second is a value type node indicating the width
60 // of the extension
61 AssertSext, AssertZext,
Misha Brukmanea61c352005-04-21 20:39:54 +000062
Chris Lattner8a496fc2005-01-13 17:58:35 +000063 // Various leaf nodes.
64 Constant, ConstantFP, GlobalAddress, FrameIndex, ConstantPool,
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +000065 BasicBlock, ExternalSymbol, VALUETYPE, CONDCODE, Register,
Chris Lattner056f9f62005-08-17 00:33:30 +000066
67 // TargetConstant - Like Constant, but the DAG does not do any folding or
68 // simplification of the constant. This is used by the DAG->DAG selector.
69 TargetConstant,
Chris Lattnerf6b18492005-08-19 22:31:34 +000070
71 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
72 // anything else with this node, and this is valid in the target-specific
73 // dag, turning into a GlobalAddress operand.
74 TargetGlobalAddress,
Chris Lattnerafb2dd42005-08-25 00:43:01 +000075 TargetFrameIndex,
Chris Lattneraaaaf792005-08-25 05:02:41 +000076 TargetConstantPool,
Chris Lattner63b570d2005-01-07 07:45:27 +000077
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +000078 // CopyToReg - This node has three operands: a chain, a register number to
79 // set to this value, and a value.
Chris Lattner63b570d2005-01-07 07:45:27 +000080 CopyToReg,
81
82 // CopyFromReg - This node indicates that the input value is a virtual or
83 // physical register that is defined outside of the scope of this
Chris Lattner18c2f132005-01-13 20:50:02 +000084 // SelectionDAG. The register is available from the RegSDNode object.
Chris Lattner63b570d2005-01-07 07:45:27 +000085 CopyFromReg,
86
Chris Lattner18c2f132005-01-13 20:50:02 +000087 // ImplicitDef - This node indicates that the specified register is
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +000088 // implicitly defined by some operation (e.g. its a live-in argument). The
89 // two operands to this are the token chain coming in and the register.
90 // The only result is the token chain going out.
Chris Lattner18c2f132005-01-13 20:50:02 +000091 ImplicitDef,
92
Nate Begemanfc1b1da2005-04-01 22:34:39 +000093 // UNDEF - An undefined node
94 UNDEF,
95
Chris Lattner63b570d2005-01-07 07:45:27 +000096 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
97 // a Constant, which is required to be operand #1), element of the aggregate
98 // value specified as operand #0. This is only for use before legalization,
99 // for values that will be broken into multiple registers.
100 EXTRACT_ELEMENT,
101
102 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
103 // two values of the same integer value type, this produces a value twice as
104 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
105 BUILD_PAIR,
106
107
108 // Simple binary arithmetic operators.
Chris Lattnerbede0b72005-04-06 04:21:29 +0000109 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
110
111 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
112 // an unsigned/signed value of type i[2*n], then return the top part.
113 MULHU, MULHS,
Chris Lattner63b570d2005-01-07 07:45:27 +0000114
115 // Bitwise operators.
116 AND, OR, XOR, SHL, SRA, SRL,
117
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000118 // Counting operators
119 CTTZ, CTLZ, CTPOP,
120
Nate Begeman9373a812005-08-10 20:51:12 +0000121 // Select
122 SELECT,
123
124 // Select with condition operator - This selects between a true value and
125 // a false value (ops #2 and #3) based on the boolean result of comparing
126 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
127 // condition code in op #4, a CondCodeSDNode.
128 SELECT_CC,
Chris Lattner63b570d2005-01-07 07:45:27 +0000129
130 // SetCC operator - This evaluates to a boolean (i1) true value if the
Chris Lattner7cf7e3f2005-08-09 20:20:18 +0000131 // condition is true. The operands to this are the left and right operands
132 // to compare (ops #0, and #1) and the condition code to compare them with
133 // (op #2) as a CondCodeSDNode.
Chris Lattner63b570d2005-01-07 07:45:27 +0000134 SETCC,
135
Chris Lattner5880b9f2005-01-20 18:50:39 +0000136 // ADD_PARTS/SUB_PARTS - These operators take two logical operands which are
137 // broken into a multiple pieces each, and return the resulting pieces of
138 // doing an atomic add/sub operation. This is used to handle add/sub of
139 // expanded types. The operation ordering is:
140 // [Lo,Hi] = op [LoLHS,HiLHS], [LoRHS,HiRHS]
141 ADD_PARTS, SUB_PARTS,
Chris Lattner63b570d2005-01-07 07:45:27 +0000142
Chris Lattner14c5b532005-04-02 03:30:33 +0000143 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
144 // integer shift operations, just like ADD/SUB_PARTS. The operation
145 // ordering is:
Chris Lattner6b8f2d62005-04-02 03:59:45 +0000146 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
Chris Lattner14c5b532005-04-02 03:30:33 +0000147 SHL_PARTS, SRA_PARTS, SRL_PARTS,
148
Chris Lattner63b570d2005-01-07 07:45:27 +0000149 // Conversion operators. These are all single input single output
150 // operations. For all of these, the result type must be strictly
151 // wider or narrower (depending on the operation) than the source
152 // type.
153
154 // SIGN_EXTEND - Used for integer types, replicating the sign bit
155 // into new bits.
156 SIGN_EXTEND,
157
158 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
159 ZERO_EXTEND,
160
161 // TRUNCATE - Completely drop the high bits.
162 TRUNCATE,
163
Chris Lattner1645ed02005-01-08 08:08:49 +0000164 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
165 // depends on the first letter) to floating point.
166 SINT_TO_FP,
167 UINT_TO_FP,
168
Chris Lattnerea576102005-04-13 02:36:41 +0000169 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
170 // sign extend a small value in a large integer register (e.g. sign
171 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
Chris Lattner15e4b012005-07-10 00:07:11 +0000172 // with the 7th bit). The size of the smaller type is indicated by the 1th
173 // operand, a ValueType node.
Chris Lattner859157d2005-01-15 06:17:04 +0000174 SIGN_EXTEND_INREG,
Chris Lattner859157d2005-01-15 06:17:04 +0000175
Chris Lattner1645ed02005-01-08 08:08:49 +0000176 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
177 // integer.
178 FP_TO_SINT,
179 FP_TO_UINT,
180
Chris Lattner63b570d2005-01-07 07:45:27 +0000181 // FP_ROUND - Perform a rounding operation from the current
Chris Lattner859157d2005-01-15 06:17:04 +0000182 // precision down to the specified precision (currently always 64->32).
Chris Lattner63b570d2005-01-07 07:45:27 +0000183 FP_ROUND,
184
Chris Lattner859157d2005-01-15 06:17:04 +0000185 // FP_ROUND_INREG - This operator takes a floating point register, and
186 // rounds it to a floating point value. It then promotes it and returns it
187 // in a register of the same size. This operation effectively just discards
Chris Lattner15e4b012005-07-10 00:07:11 +0000188 // excess precision. The type to round down to is specified by the 1th
189 // operation, a VTSDNode (currently always 64->32->64).
Chris Lattner859157d2005-01-15 06:17:04 +0000190 FP_ROUND_INREG,
191
Chris Lattner63b570d2005-01-07 07:45:27 +0000192 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
193 FP_EXTEND,
194
Chris Lattner7f644642005-04-28 21:44:03 +0000195 // FNEG, FABS, FSQRT, FSIN, FCOS - Perform unary floating point negation,
196 // absolute value, square root, sine and cosine operations.
197 FNEG, FABS, FSQRT, FSIN, FCOS,
Chris Lattner7366fd32005-04-02 04:58:28 +0000198
Chris Lattner1cff05c2005-01-14 22:07:46 +0000199 // Other operators. LOAD and STORE have token chains as their first
Chris Lattnerf7db8c62005-07-10 00:28:25 +0000200 // operand, then the same operands as an LLVM load/store instruction, then a
201 // SRCVALUE node that provides alias analysis information.
Chris Lattner63b570d2005-01-07 07:45:27 +0000202 LOAD, STORE,
203
Chris Lattner5f056bf2005-07-10 01:55:33 +0000204 // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators all load a value from
205 // memory and extend them to a larger value (e.g. load a byte into a word
206 // register). All three of these have four operands, a token chain, a
207 // pointer to load from, a SRCVALUE for alias analysis, and a VALUETYPE node
208 // indicating the type to load.
Chris Lattner1cff05c2005-01-14 22:07:46 +0000209 //
210 // SEXTLOAD loads the integer operand and sign extends it to a larger
211 // integer result type.
212 // ZEXTLOAD loads the integer operand and zero extends it to a larger
213 // integer result type.
Misha Brukmanea61c352005-04-21 20:39:54 +0000214 // EXTLOAD is used for two things: floating point extending loads, and
Chris Lattner1cff05c2005-01-14 22:07:46 +0000215 // integer extending loads where it doesn't matter what the high
216 // bits are set to. The code generator is allowed to codegen this
217 // into whichever operation is more efficient.
218 EXTLOAD, SEXTLOAD, ZEXTLOAD,
219
220 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
221 // value and stores it to memory in one operation. This can be used for
Chris Lattnerf7db8c62005-07-10 00:28:25 +0000222 // either integer or floating point operands. The first four operands of
223 // this are the same as a standard store. The fifth is the ValueType to
224 // store it as (which will be smaller than the source value).
Chris Lattner1cff05c2005-01-14 22:07:46 +0000225 TRUNCSTORE,
226
Chris Lattner63b570d2005-01-07 07:45:27 +0000227 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
228 // to a specified boundary. The first operand is the token chain, the
229 // second is the number of bytes to allocate, and the third is the alignment
Chris Lattner74fe0632005-08-29 22:48:32 +0000230 // boundary. The size is guaranteed to be a multiple of the stack
231 // alignment, and the alignment is guaranteed to be bigger than the stack
232 // alignment (if required) or 0 to get standard stack alignment.
Chris Lattner63b570d2005-01-07 07:45:27 +0000233 DYNAMIC_STACKALLOC,
234
235 // Control flow instructions. These all have token chains.
Misha Brukmanea61c352005-04-21 20:39:54 +0000236
Chris Lattner63b570d2005-01-07 07:45:27 +0000237 // BR - Unconditional branch. The first operand is the chain
238 // operand, the second is the MBB to branch to.
239 BR,
240
241 // BRCOND - Conditional branch. The first operand is the chain,
242 // the second is the condition, the third is the block to branch
243 // to if the condition is true.
244 BRCOND,
245
Chris Lattner1df63382005-04-09 03:21:50 +0000246 // BRCONDTWOWAY - Two-way conditional branch. The first operand is the
247 // chain, the second is the condition, the third is the block to branch to
248 // if true, and the forth is the block to branch to if false. Targets
249 // usually do not implement this, preferring to have legalize demote the
250 // operation to BRCOND/BR pairs when necessary.
251 BRCONDTWOWAY,
252
Nate Begeman7cbd5252005-08-16 19:49:35 +0000253 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
254 // that the condition is represented as condition code, and two nodes to
255 // compare, rather than as a combined SetCC node. The operands in order are
256 // chain, cc, lhs, rhs, block to branch to if condition is true.
257 BR_CC,
258
259 // BRTWOWAY_CC - Two-way conditional branch. The operands in order are
260 // chain, cc, lhs, rhs, block to branch to if condition is true, block to
261 // branch to if condition is false. Targets usually do not implement this,
262 // preferring to have legalize demote the operation to BRCOND/BR pairs.
263 BRTWOWAY_CC,
264
Chris Lattner63b570d2005-01-07 07:45:27 +0000265 // RET - Return from function. The first operand is the chain,
266 // and any subsequent operands are the return values for the
267 // function. This operation can have variable number of operands.
268 RET,
269
270 // CALL - Call to a function pointer. The first operand is the chain, the
271 // second is the destination function pointer (a GlobalAddress for a direct
272 // call). Arguments have already been lowered to explicit DAGs according to
Chris Lattner4c1eae92005-05-13 18:40:17 +0000273 // the calling convention in effect here. TAILCALL is the same as CALL, but
274 // the callee is known not to access the stack of the caller.
Chris Lattner63b570d2005-01-07 07:45:27 +0000275 CALL,
Chris Lattner4c1eae92005-05-13 18:40:17 +0000276 TAILCALL,
Chris Lattneref36aa72005-01-11 05:56:17 +0000277
278 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
279 // correspond to the operands of the LLVM intrinsic functions. The only
280 // result is a token chain. The alignment argument is guaranteed to be a
281 // Constant node.
282 MEMSET,
283 MEMMOVE,
284 MEMCPY,
Misha Brukmanea61c352005-04-21 20:39:54 +0000285
Chris Lattner16cd04d2005-05-12 23:24:06 +0000286 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
287 // a call sequence, and carry arbitrary information that target might want
288 // to know. The first operand is a chain, the rest are specified by the
289 // target and not touched by the DAG optimizers.
290 CALLSEQ_START, // Beginning of a call sequence
291 CALLSEQ_END, // End of a call sequence
Chris Lattner63b570d2005-01-07 07:45:27 +0000292
Chris Lattner21074f42005-05-09 20:21:27 +0000293 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
294 // locations with their value. This allows one use alias analysis
295 // information in the backend.
296 SRCVALUE,
297
Misha Brukmane3f570c2005-03-31 21:30:35 +0000298 // PCMARKER - This corresponds to the pcmarker intrinsic.
Andrew Lenharth95762122005-03-31 21:24:06 +0000299 PCMARKER,
Chris Lattner63b570d2005-01-07 07:45:27 +0000300
Chris Lattner21074f42005-05-09 20:21:27 +0000301 // READPORT, WRITEPORT, READIO, WRITEIO - These correspond to the LLVM
302 // intrinsics of the same name. The first operand is a token chain, the
303 // other operands match the intrinsic. These produce a token chain in
304 // addition to a value (if any).
305 READPORT, WRITEPORT, READIO, WRITEIO,
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000306
Chris Lattner63b570d2005-01-07 07:45:27 +0000307 // BUILTIN_OP_END - This must be the last enum value in this list.
308 BUILTIN_OP_END,
309 };
310
311 //===--------------------------------------------------------------------===//
312 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
313 /// below work out, when considering SETFALSE (something that never exists
314 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
315 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
316 /// to. If the "N" column is 1, the result of the comparison is undefined if
317 /// the input is a NAN.
318 ///
319 /// All of these (except for the 'always folded ops') should be handled for
320 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
321 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
322 ///
323 /// Note that these are laid out in a specific order to allow bit-twiddling
324 /// to transform conditions.
325 enum CondCode {
326 // Opcode N U L G E Intuitive operation
327 SETFALSE, // 0 0 0 0 Always false (always folded)
328 SETOEQ, // 0 0 0 1 True if ordered and equal
329 SETOGT, // 0 0 1 0 True if ordered and greater than
330 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
331 SETOLT, // 0 1 0 0 True if ordered and less than
332 SETOLE, // 0 1 0 1 True if ordered and less than or equal
333 SETONE, // 0 1 1 0 True if ordered and operands are unequal
334 SETO, // 0 1 1 1 True if ordered (no nans)
335 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
336 SETUEQ, // 1 0 0 1 True if unordered or equal
337 SETUGT, // 1 0 1 0 True if unordered or greater than
338 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
339 SETULT, // 1 1 0 0 True if unordered or less than
Misha Brukmanea61c352005-04-21 20:39:54 +0000340 SETULE, // 1 1 0 1 True if unordered, less than, or equal
Chris Lattner63b570d2005-01-07 07:45:27 +0000341 SETUNE, // 1 1 1 0 True if unordered or not equal
342 SETTRUE, // 1 1 1 1 Always true (always folded)
343 // Don't care operations: undefined if the input is a nan.
344 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
345 SETEQ, // 1 X 0 0 1 True if equal
346 SETGT, // 1 X 0 1 0 True if greater than
347 SETGE, // 1 X 0 1 1 True if greater than or equal
348 SETLT, // 1 X 1 0 0 True if less than
Misha Brukmanea61c352005-04-21 20:39:54 +0000349 SETLE, // 1 X 1 0 1 True if less than or equal
Chris Lattner63b570d2005-01-07 07:45:27 +0000350 SETNE, // 1 X 1 1 0 True if not equal
351 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
352
353 SETCC_INVALID, // Marker value.
354 };
355
356 /// isSignedIntSetCC - Return true if this is a setcc instruction that
357 /// performs a signed comparison when used with integer operands.
358 inline bool isSignedIntSetCC(CondCode Code) {
359 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
360 }
361
362 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
363 /// performs an unsigned comparison when used with integer operands.
364 inline bool isUnsignedIntSetCC(CondCode Code) {
365 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
366 }
367
368 /// isTrueWhenEqual - Return true if the specified condition returns true if
369 /// the two operands to the condition are equal. Note that if one of the two
370 /// operands is a NaN, this value is meaningless.
371 inline bool isTrueWhenEqual(CondCode Cond) {
372 return ((int)Cond & 1) != 0;
373 }
374
375 /// getUnorderedFlavor - This function returns 0 if the condition is always
376 /// false if an operand is a NaN, 1 if the condition is always true if the
377 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
378 /// NaN.
379 inline unsigned getUnorderedFlavor(CondCode Cond) {
380 return ((int)Cond >> 3) & 3;
381 }
382
383 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
384 /// 'op' is a valid SetCC operation.
385 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
386
387 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
388 /// when given the operation for (X op Y).
389 CondCode getSetCCSwappedOperands(CondCode Operation);
390
391 /// getSetCCOrOperation - Return the result of a logical OR between different
392 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
393 /// function returns SETCC_INVALID if it is not possible to represent the
394 /// resultant comparison.
395 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
396
397 /// getSetCCAndOperation - Return the result of a logical AND between
398 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
399 /// function returns SETCC_INVALID if it is not possible to represent the
400 /// resultant comparison.
401 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
402} // end llvm::ISD namespace
403
404
405//===----------------------------------------------------------------------===//
406/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
407/// values as the result of a computation. Many nodes return multiple values,
408/// from loads (which define a token and a return value) to ADDC (which returns
409/// a result and a carry value), to calls (which may return an arbitrary number
410/// of values).
411///
412/// As such, each use of a SelectionDAG computation must indicate the node that
413/// computes it as well as which return value to use from that node. This pair
414/// of information is represented with the SDOperand value type.
415///
Chris Lattnerf26bc8e2005-01-08 19:52:31 +0000416class SDOperand {
417public:
Chris Lattner63b570d2005-01-07 07:45:27 +0000418 SDNode *Val; // The node defining the value we are using.
419 unsigned ResNo; // Which return value of the node we are using.
420
421 SDOperand() : Val(0) {}
422 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
423
424 bool operator==(const SDOperand &O) const {
425 return Val == O.Val && ResNo == O.ResNo;
426 }
427 bool operator!=(const SDOperand &O) const {
428 return !operator==(O);
429 }
430 bool operator<(const SDOperand &O) const {
431 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
432 }
433
434 SDOperand getValue(unsigned R) const {
435 return SDOperand(Val, R);
436 }
437
438 /// getValueType - Return the ValueType of the referenced return value.
439 ///
440 inline MVT::ValueType getValueType() const;
Misha Brukmanea61c352005-04-21 20:39:54 +0000441
Chris Lattner63b570d2005-01-07 07:45:27 +0000442 // Forwarding methods - These forward to the corresponding methods in SDNode.
443 inline unsigned getOpcode() const;
Chris Lattner0442fbf2005-01-21 21:39:38 +0000444 inline unsigned getNodeDepth() const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000445 inline unsigned getNumOperands() const;
446 inline const SDOperand &getOperand(unsigned i) const;
Nate Begeman0f66a912005-08-17 23:44:54 +0000447 inline bool isTargetOpcode() const;
448 inline unsigned getTargetOpcode() const;
Chris Lattnera44f4ae2005-01-13 22:58:50 +0000449
450 /// hasOneUse - Return true if there is exactly one operation using this
451 /// result value of the defining operator.
452 inline bool hasOneUse() const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000453};
454
455
456/// simplify_type specializations - Allow casting operators to work directly on
457/// SDOperands as if they were SDNode*'s.
458template<> struct simplify_type<SDOperand> {
459 typedef SDNode* SimpleType;
460 static SimpleType getSimplifiedValue(const SDOperand &Val) {
461 return static_cast<SimpleType>(Val.Val);
462 }
463};
464template<> struct simplify_type<const SDOperand> {
465 typedef SDNode* SimpleType;
466 static SimpleType getSimplifiedValue(const SDOperand &Val) {
467 return static_cast<SimpleType>(Val.Val);
468 }
469};
470
471
472/// SDNode - Represents one node in the SelectionDAG.
473///
474class SDNode {
Chris Lattner0442fbf2005-01-21 21:39:38 +0000475 /// NodeType - The operation that this node performs.
476 ///
477 unsigned short NodeType;
478
479 /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1. This
480 /// means that leaves have a depth of 1, things that use only leaves have a
481 /// depth of 2, etc.
482 unsigned short NodeDepth;
483
484 /// Operands - The values that are used by this operation.
485 ///
Chris Lattner63b570d2005-01-07 07:45:27 +0000486 std::vector<SDOperand> Operands;
487
488 /// Values - The types of the values this node defines. SDNode's may define
489 /// multiple values simultaneously.
490 std::vector<MVT::ValueType> Values;
491
492 /// Uses - These are all of the SDNode's that use a value produced by this
493 /// node.
494 std::vector<SDNode*> Uses;
495public:
496
497 //===--------------------------------------------------------------------===//
498 // Accessors
499 //
500 unsigned getOpcode() const { return NodeType; }
Nate Begeman0f66a912005-08-17 23:44:54 +0000501 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
502 unsigned getTargetOpcode() const {
503 assert(isTargetOpcode() && "Not a target opcode!");
504 return NodeType - ISD::BUILTIN_OP_END;
505 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000506
507 size_t use_size() const { return Uses.size(); }
508 bool use_empty() const { return Uses.empty(); }
509 bool hasOneUse() const { return Uses.size() == 1; }
510
Chris Lattner0442fbf2005-01-21 21:39:38 +0000511 /// getNodeDepth - Return the distance from this node to the leaves in the
512 /// graph. The leaves have a depth of 1.
513 unsigned getNodeDepth() const { return NodeDepth; }
514
Chris Lattner7ece3802005-01-17 02:24:59 +0000515 typedef std::vector<SDNode*>::const_iterator use_iterator;
516 use_iterator use_begin() const { return Uses.begin(); }
517 use_iterator use_end() const { return Uses.end(); }
518
Chris Lattnerb18a2f82005-01-12 18:37:33 +0000519 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
520 /// indicated value. This method ignores uses of other values defined by this
521 /// operation.
522 bool hasNUsesOfValue(unsigned NUses, unsigned Value);
523
Chris Lattner63b570d2005-01-07 07:45:27 +0000524 /// getNumOperands - Return the number of values used by this operation.
525 ///
526 unsigned getNumOperands() const { return Operands.size(); }
527
528 const SDOperand &getOperand(unsigned Num) {
529 assert(Num < Operands.size() && "Invalid child # of SDNode!");
530 return Operands[Num];
531 }
532
533 const SDOperand &getOperand(unsigned Num) const {
534 assert(Num < Operands.size() && "Invalid child # of SDNode!");
535 return Operands[Num];
536 }
Chris Lattner50f5a512005-05-14 06:19:11 +0000537 typedef std::vector<SDOperand>::const_iterator op_iterator;
538 op_iterator op_begin() const { return Operands.begin(); }
539 op_iterator op_end() const { return Operands.end(); }
540
Chris Lattner63b570d2005-01-07 07:45:27 +0000541
542 /// getNumValues - Return the number of values defined/returned by this
543 /// operator.
544 ///
545 unsigned getNumValues() const { return Values.size(); }
546
547 /// getValueType - Return the type of a specified result.
548 ///
549 MVT::ValueType getValueType(unsigned ResNo) const {
550 assert(ResNo < Values.size() && "Illegal result number!");
551 return Values[ResNo];
552 }
Jeff Cohen9eb59ec2005-07-27 05:53:44 +0000553
Chris Lattner50f5a512005-05-14 06:19:11 +0000554 typedef std::vector<MVT::ValueType>::const_iterator value_iterator;
555 value_iterator value_begin() const { return Values.begin(); }
556 value_iterator value_end() const { return Values.end(); }
Chris Lattner63b570d2005-01-07 07:45:27 +0000557
Chris Lattner6e6e3ce2005-01-10 23:25:04 +0000558 /// getOperationName - Return the opcode of this operation for printing.
559 ///
Chris Lattnerefe58692005-08-16 18:32:18 +0000560 const char* getOperationName(const SelectionDAG *G = 0) const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000561 void dump() const;
Chris Lattnerefe58692005-08-16 18:32:18 +0000562 void dump(const SelectionDAG *G) const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000563
564 static bool classof(const SDNode *) { return true; }
565
Chris Lattner73b35372005-05-11 18:56:45 +0000566
567 /// setAdjCallChain - This method should only be used by the legalizer.
568 void setAdjCallChain(SDOperand N);
Jeff Cohen9eb59ec2005-07-27 05:53:44 +0000569
Chris Lattner63b570d2005-01-07 07:45:27 +0000570protected:
571 friend class SelectionDAG;
572
Chris Lattner0442fbf2005-01-21 21:39:38 +0000573 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) {
Chris Lattner63b570d2005-01-07 07:45:27 +0000574 Values.reserve(1);
575 Values.push_back(VT);
576 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000577 SDNode(unsigned NT, SDOperand Op)
Chris Lattner0442fbf2005-01-21 21:39:38 +0000578 : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) {
Chris Lattner63b570d2005-01-07 07:45:27 +0000579 Operands.reserve(1); Operands.push_back(Op);
580 Op.Val->Uses.push_back(this);
581 }
582 SDNode(unsigned NT, SDOperand N1, SDOperand N2)
583 : NodeType(NT) {
Chris Lattner0442fbf2005-01-21 21:39:38 +0000584 if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth())
585 NodeDepth = N1.Val->getNodeDepth()+1;
586 else
587 NodeDepth = N2.Val->getNodeDepth()+1;
Chris Lattner63b570d2005-01-07 07:45:27 +0000588 Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2);
589 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
590 }
591 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
592 : NodeType(NT) {
Chris Lattner0442fbf2005-01-21 21:39:38 +0000593 unsigned ND = N1.Val->getNodeDepth();
594 if (ND < N2.Val->getNodeDepth())
595 ND = N2.Val->getNodeDepth();
596 if (ND < N3.Val->getNodeDepth())
597 ND = N3.Val->getNodeDepth();
598 NodeDepth = ND+1;
599
Chris Lattner63b570d2005-01-07 07:45:27 +0000600 Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2);
601 Operands.push_back(N3);
602 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
603 N3.Val->Uses.push_back(this);
604 }
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000605 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4)
606 : NodeType(NT) {
607 unsigned ND = N1.Val->getNodeDepth();
608 if (ND < N2.Val->getNodeDepth())
609 ND = N2.Val->getNodeDepth();
610 if (ND < N3.Val->getNodeDepth())
611 ND = N3.Val->getNodeDepth();
612 if (ND < N4.Val->getNodeDepth())
613 ND = N4.Val->getNodeDepth();
614 NodeDepth = ND+1;
615
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000616 Operands.reserve(4); Operands.push_back(N1); Operands.push_back(N2);
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000617 Operands.push_back(N3); Operands.push_back(N4);
618 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
619 N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this);
620 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000621 SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) {
622 Operands.swap(Nodes);
Chris Lattner0442fbf2005-01-21 21:39:38 +0000623 unsigned ND = 0;
624 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
Chris Lattneref36aa72005-01-11 05:56:17 +0000625 Operands[i].Val->Uses.push_back(this);
Chris Lattner0442fbf2005-01-21 21:39:38 +0000626 if (ND < Operands[i].Val->getNodeDepth())
627 ND = Operands[i].Val->getNodeDepth();
628 }
629 NodeDepth = ND+1;
Chris Lattner63b570d2005-01-07 07:45:27 +0000630 }
631
Chris Lattner1b950952005-08-16 18:16:24 +0000632 virtual ~SDNode() {}
Chris Lattner63b570d2005-01-07 07:45:27 +0000633
Chris Lattner1b950952005-08-16 18:16:24 +0000634 /// MorphNodeTo - This clears the return value and operands list, and sets the
635 /// opcode of the node to the specified value. This should only be used by
636 /// the SelectionDAG class.
637 void MorphNodeTo(unsigned Opc) {
638 NodeType = Opc;
639 Values.clear();
Chris Lattnerb467f8a2005-08-17 01:54:00 +0000640
641 // Clear the operands list, updating used nodes to remove this from their
642 // use list.
643 while (!Operands.empty()) {
644 SDNode *O = Operands.back().Val;
645 Operands.pop_back();
646 O->removeUser(this);
647 }
Chris Lattner1b950952005-08-16 18:16:24 +0000648 }
649
Chris Lattner63b570d2005-01-07 07:45:27 +0000650 void setValueTypes(MVT::ValueType VT) {
651 Values.reserve(1);
652 Values.push_back(VT);
653 }
654 void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) {
655 Values.reserve(2);
656 Values.push_back(VT1);
657 Values.push_back(VT2);
658 }
659 /// Note: this method destroys the vector passed in.
660 void setValueTypes(std::vector<MVT::ValueType> &VTs) {
661 std::swap(Values, VTs);
662 }
Chris Lattner1b950952005-08-16 18:16:24 +0000663
664 void setOperands(SDOperand Op0) {
665 Operands.reserve(1);
666 Operands.push_back(Op0);
Chris Lattner8c3484c2005-08-17 18:58:38 +0000667 Op0.Val->Uses.push_back(this);
Chris Lattner1b950952005-08-16 18:16:24 +0000668 }
669 void setOperands(SDOperand Op0, SDOperand Op1) {
670 Operands.reserve(2);
671 Operands.push_back(Op0);
672 Operands.push_back(Op1);
Chris Lattner8c3484c2005-08-17 18:58:38 +0000673 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
Chris Lattner1b950952005-08-16 18:16:24 +0000674 }
675 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) {
676 Operands.reserve(3);
677 Operands.push_back(Op0);
678 Operands.push_back(Op1);
679 Operands.push_back(Op2);
Chris Lattner8c3484c2005-08-17 18:58:38 +0000680 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
681 Op2.Val->Uses.push_back(this);
682 }
Nate Begeman294a0a12005-08-18 07:30:15 +0000683 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3) {
684 Operands.reserve(4);
685 Operands.push_back(Op0);
686 Operands.push_back(Op1);
687 Operands.push_back(Op2);
688 Operands.push_back(Op3);
689 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
690 Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
691 }
Chris Lattnerd54209f2005-08-21 18:49:58 +0000692 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3,
693 SDOperand Op4) {
694 Operands.reserve(5);
695 Operands.push_back(Op0);
696 Operands.push_back(Op1);
697 Operands.push_back(Op2);
698 Operands.push_back(Op3);
699 Operands.push_back(Op4);
700 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
701 Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
702 Op4.Val->Uses.push_back(this);
703 }
Chris Lattner8c3484c2005-08-17 18:58:38 +0000704 void addUser(SDNode *User) {
705 Uses.push_back(User);
Chris Lattner1b950952005-08-16 18:16:24 +0000706 }
Chris Lattnerd1fc9642005-01-07 21:08:55 +0000707 void removeUser(SDNode *User) {
708 // Remove this user from the operand's use list.
709 for (unsigned i = Uses.size(); ; --i) {
710 assert(i != 0 && "Didn't find user!");
711 if (Uses[i-1] == User) {
Chris Lattner8c3484c2005-08-17 18:58:38 +0000712 Uses[i-1] = Uses.back();
713 Uses.pop_back();
714 return;
Chris Lattnerd1fc9642005-01-07 21:08:55 +0000715 }
716 }
717 }
Chris Lattner63b570d2005-01-07 07:45:27 +0000718};
719
720
721// Define inline functions from the SDOperand class.
722
723inline unsigned SDOperand::getOpcode() const {
724 return Val->getOpcode();
725}
Chris Lattner0442fbf2005-01-21 21:39:38 +0000726inline unsigned SDOperand::getNodeDepth() const {
727 return Val->getNodeDepth();
728}
Chris Lattner63b570d2005-01-07 07:45:27 +0000729inline MVT::ValueType SDOperand::getValueType() const {
730 return Val->getValueType(ResNo);
731}
732inline unsigned SDOperand::getNumOperands() const {
733 return Val->getNumOperands();
734}
735inline const SDOperand &SDOperand::getOperand(unsigned i) const {
736 return Val->getOperand(i);
737}
Nate Begeman0f66a912005-08-17 23:44:54 +0000738inline bool SDOperand::isTargetOpcode() const {
739 return Val->isTargetOpcode();
740}
741inline unsigned SDOperand::getTargetOpcode() const {
742 return Val->getTargetOpcode();
743}
Chris Lattnera44f4ae2005-01-13 22:58:50 +0000744inline bool SDOperand::hasOneUse() const {
745 return Val->hasNUsesOfValue(1, ResNo);
746}
Chris Lattner63b570d2005-01-07 07:45:27 +0000747
748
749class ConstantSDNode : public SDNode {
750 uint64_t Value;
751protected:
752 friend class SelectionDAG;
Chris Lattner056f9f62005-08-17 00:33:30 +0000753 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
754 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, VT), Value(val) {
Chris Lattner63b570d2005-01-07 07:45:27 +0000755 }
756public:
757
758 uint64_t getValue() const { return Value; }
759
760 int64_t getSignExtended() const {
761 unsigned Bits = MVT::getSizeInBits(getValueType(0));
Chris Lattnerf26bc8e2005-01-08 19:52:31 +0000762 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
Chris Lattner63b570d2005-01-07 07:45:27 +0000763 }
764
765 bool isNullValue() const { return Value == 0; }
766 bool isAllOnesValue() const {
Chris Lattner2bffad32005-04-08 21:31:29 +0000767 int NumBits = MVT::getSizeInBits(getValueType(0));
768 if (NumBits == 64) return Value+1 == 0;
769 return Value == (1ULL << NumBits)-1;
Chris Lattner63b570d2005-01-07 07:45:27 +0000770 }
771
772 static bool classof(const ConstantSDNode *) { return true; }
773 static bool classof(const SDNode *N) {
Chris Lattner056f9f62005-08-17 00:33:30 +0000774 return N->getOpcode() == ISD::Constant ||
775 N->getOpcode() == ISD::TargetConstant;
Chris Lattner63b570d2005-01-07 07:45:27 +0000776 }
777};
778
779class ConstantFPSDNode : public SDNode {
780 double Value;
781protected:
782 friend class SelectionDAG;
783 ConstantFPSDNode(double val, MVT::ValueType VT)
784 : SDNode(ISD::ConstantFP, VT), Value(val) {
785 }
786public:
787
788 double getValue() const { return Value; }
789
790 /// isExactlyValue - We don't rely on operator== working on double values, as
791 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
792 /// As such, this method can be used to do an exact bit-for-bit comparison of
793 /// two floating point values.
Jim Laskey58b968b2005-08-17 20:08:02 +0000794 bool isExactlyValue(double V) const;
Chris Lattner63b570d2005-01-07 07:45:27 +0000795
796 static bool classof(const ConstantFPSDNode *) { return true; }
797 static bool classof(const SDNode *N) {
798 return N->getOpcode() == ISD::ConstantFP;
799 }
800};
801
802class GlobalAddressSDNode : public SDNode {
803 GlobalValue *TheGlobal;
804protected:
805 friend class SelectionDAG;
Chris Lattnerf6b18492005-08-19 22:31:34 +0000806 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT)
807 : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT) {
Chris Lattner63b570d2005-01-07 07:45:27 +0000808 TheGlobal = const_cast<GlobalValue*>(GA);
Chris Lattner63b570d2005-01-07 07:45:27 +0000809 }
810public:
811
812 GlobalValue *getGlobal() const { return TheGlobal; }
813
814 static bool classof(const GlobalAddressSDNode *) { return true; }
815 static bool classof(const SDNode *N) {
Chris Lattnerf6b18492005-08-19 22:31:34 +0000816 return N->getOpcode() == ISD::GlobalAddress ||
817 N->getOpcode() == ISD::TargetGlobalAddress;
Chris Lattner63b570d2005-01-07 07:45:27 +0000818 }
819};
820
821
822class FrameIndexSDNode : public SDNode {
823 int FI;
824protected:
825 friend class SelectionDAG;
Chris Lattnerafb2dd42005-08-25 00:43:01 +0000826 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
827 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, VT), FI(fi) {}
Chris Lattner63b570d2005-01-07 07:45:27 +0000828public:
829
830 int getIndex() const { return FI; }
831
832 static bool classof(const FrameIndexSDNode *) { return true; }
833 static bool classof(const SDNode *N) {
Chris Lattnerafb2dd42005-08-25 00:43:01 +0000834 return N->getOpcode() == ISD::FrameIndex ||
835 N->getOpcode() == ISD::TargetFrameIndex;
Chris Lattner63b570d2005-01-07 07:45:27 +0000836 }
837};
838
839class ConstantPoolSDNode : public SDNode {
Chris Lattner5839bf22005-08-26 17:15:30 +0000840 Constant *C;
Chris Lattner63b570d2005-01-07 07:45:27 +0000841protected:
842 friend class SelectionDAG;
Chris Lattner5839bf22005-08-26 17:15:30 +0000843 ConstantPoolSDNode(Constant *c, MVT::ValueType VT, bool isTarget)
Chris Lattneraaaaf792005-08-25 05:02:41 +0000844 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT),
Chris Lattner5839bf22005-08-26 17:15:30 +0000845 C(c) {}
Chris Lattner63b570d2005-01-07 07:45:27 +0000846public:
847
Chris Lattner5839bf22005-08-26 17:15:30 +0000848 Constant *get() const { return C; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000849
850 static bool classof(const ConstantPoolSDNode *) { return true; }
851 static bool classof(const SDNode *N) {
Chris Lattneraaaaf792005-08-25 05:02:41 +0000852 return N->getOpcode() == ISD::ConstantPool ||
853 N->getOpcode() == ISD::TargetConstantPool;
Chris Lattner63b570d2005-01-07 07:45:27 +0000854 }
855};
856
857class BasicBlockSDNode : public SDNode {
858 MachineBasicBlock *MBB;
859protected:
860 friend class SelectionDAG;
861 BasicBlockSDNode(MachineBasicBlock *mbb)
862 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
863public:
864
865 MachineBasicBlock *getBasicBlock() const { return MBB; }
866
867 static bool classof(const BasicBlockSDNode *) { return true; }
868 static bool classof(const SDNode *N) {
869 return N->getOpcode() == ISD::BasicBlock;
870 }
871};
872
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000873class SrcValueSDNode : public SDNode {
874 const Value *V;
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000875 int offset;
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000876protected:
877 friend class SelectionDAG;
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000878 SrcValueSDNode(const Value* v, int o)
879 : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {}
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000880
881public:
882 const Value *getValue() const { return V; }
Andrew Lenharth691ef2b2005-05-03 17:19:30 +0000883 int getOffset() const { return offset; }
Andrew Lenharth2d86ea22005-04-27 20:10:01 +0000884
885 static bool classof(const SrcValueSDNode *) { return true; }
886 static bool classof(const SDNode *N) {
887 return N->getOpcode() == ISD::SRCVALUE;
888 }
889};
890
Chris Lattner63b570d2005-01-07 07:45:27 +0000891
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +0000892class RegisterSDNode : public SDNode {
Chris Lattner63b570d2005-01-07 07:45:27 +0000893 unsigned Reg;
894protected:
895 friend class SelectionDAG;
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +0000896 RegisterSDNode(unsigned reg, MVT::ValueType VT)
897 : SDNode(ISD::Register, VT), Reg(reg) {}
Chris Lattner63b570d2005-01-07 07:45:27 +0000898public:
899
900 unsigned getReg() const { return Reg; }
901
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +0000902 static bool classof(const RegisterSDNode *) { return true; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000903 static bool classof(const SDNode *N) {
Chris Lattnerd5d0f9b2005-08-16 21:55:35 +0000904 return N->getOpcode() == ISD::Register;
Chris Lattner63b570d2005-01-07 07:45:27 +0000905 }
906};
907
908class ExternalSymbolSDNode : public SDNode {
909 const char *Symbol;
910protected:
911 friend class SelectionDAG;
912 ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT)
913 : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) {
914 }
915public:
916
917 const char *getSymbol() const { return Symbol; }
918
919 static bool classof(const ExternalSymbolSDNode *) { return true; }
920 static bool classof(const SDNode *N) {
921 return N->getOpcode() == ISD::ExternalSymbol;
922 }
923};
924
Chris Lattner7cf7e3f2005-08-09 20:20:18 +0000925class CondCodeSDNode : public SDNode {
Chris Lattner63b570d2005-01-07 07:45:27 +0000926 ISD::CondCode Condition;
927protected:
928 friend class SelectionDAG;
Chris Lattner7cf7e3f2005-08-09 20:20:18 +0000929 CondCodeSDNode(ISD::CondCode Cond)
930 : SDNode(ISD::CONDCODE, MVT::Other), Condition(Cond) {
Chris Lattner63b570d2005-01-07 07:45:27 +0000931 }
932public:
933
Chris Lattner7cf7e3f2005-08-09 20:20:18 +0000934 ISD::CondCode get() const { return Condition; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000935
Chris Lattner7cf7e3f2005-08-09 20:20:18 +0000936 static bool classof(const CondCodeSDNode *) { return true; }
Chris Lattner63b570d2005-01-07 07:45:27 +0000937 static bool classof(const SDNode *N) {
Chris Lattner7cf7e3f2005-08-09 20:20:18 +0000938 return N->getOpcode() == ISD::CONDCODE;
Chris Lattner63b570d2005-01-07 07:45:27 +0000939 }
940};
941
Chris Lattner15e4b012005-07-10 00:07:11 +0000942/// VTSDNode - This class is used to represent MVT::ValueType's, which are used
943/// to parameterize some operations.
944class VTSDNode : public SDNode {
945 MVT::ValueType ValueType;
946protected:
947 friend class SelectionDAG;
948 VTSDNode(MVT::ValueType VT)
949 : SDNode(ISD::VALUETYPE, MVT::Other), ValueType(VT) {}
950public:
951
952 MVT::ValueType getVT() const { return ValueType; }
953
954 static bool classof(const VTSDNode *) { return true; }
955 static bool classof(const SDNode *N) {
956 return N->getOpcode() == ISD::VALUETYPE;
957 }
958};
959
960
Chris Lattner1080b9e2005-01-10 23:05:53 +0000961class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
962 SDNode *Node;
963 unsigned Operand;
Misha Brukmanea61c352005-04-21 20:39:54 +0000964
Chris Lattner1080b9e2005-01-10 23:05:53 +0000965 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
966public:
967 bool operator==(const SDNodeIterator& x) const {
968 return Operand == x.Operand;
969 }
970 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
971
972 const SDNodeIterator &operator=(const SDNodeIterator &I) {
973 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
974 Operand = I.Operand;
975 return *this;
976 }
Misha Brukmanea61c352005-04-21 20:39:54 +0000977
Chris Lattner1080b9e2005-01-10 23:05:53 +0000978 pointer operator*() const {
979 return Node->getOperand(Operand).Val;
980 }
981 pointer operator->() const { return operator*(); }
Misha Brukmanea61c352005-04-21 20:39:54 +0000982
Chris Lattner1080b9e2005-01-10 23:05:53 +0000983 SDNodeIterator& operator++() { // Preincrement
984 ++Operand;
985 return *this;
986 }
987 SDNodeIterator operator++(int) { // Postincrement
Misha Brukmanea61c352005-04-21 20:39:54 +0000988 SDNodeIterator tmp = *this; ++*this; return tmp;
Chris Lattner1080b9e2005-01-10 23:05:53 +0000989 }
990
991 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
992 static SDNodeIterator end (SDNode *N) {
993 return SDNodeIterator(N, N->getNumOperands());
994 }
995
996 unsigned getOperand() const { return Operand; }
997 const SDNode *getNode() const { return Node; }
998};
999
1000template <> struct GraphTraits<SDNode*> {
1001 typedef SDNode NodeType;
1002 typedef SDNodeIterator ChildIteratorType;
1003 static inline NodeType *getEntryNode(SDNode *N) { return N; }
Misha Brukmanea61c352005-04-21 20:39:54 +00001004 static inline ChildIteratorType child_begin(NodeType *N) {
Chris Lattner1080b9e2005-01-10 23:05:53 +00001005 return SDNodeIterator::begin(N);
1006 }
Misha Brukmanea61c352005-04-21 20:39:54 +00001007 static inline ChildIteratorType child_end(NodeType *N) {
Chris Lattner1080b9e2005-01-10 23:05:53 +00001008 return SDNodeIterator::end(N);
1009 }
1010};
1011
Chris Lattner63b570d2005-01-07 07:45:27 +00001012} // end llvm namespace
1013
1014#endif