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