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