Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===// |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 2 | // |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file was developed by the LLVM research group and is distributed under |
| 6 | // the University of Illinois Open Source License. See LICENSE.TXT for details. |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 7 | // |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 10 | // This file declares the SDNode class and derived classes, which are used to |
| 11 | // represent the nodes and operations present in a SelectionDAG. These nodes |
| 12 | // and operations are machine code level operations, with some similarities to |
| 13 | // the GCC RTL representation. |
| 14 | // |
| 15 | // Clients should include the SelectionDAG.h file instead of this file directly. |
| 16 | // |
| 17 | //===----------------------------------------------------------------------===// |
| 18 | |
| 19 | #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H |
| 20 | #define LLVM_CODEGEN_SELECTIONDAGNODES_H |
| 21 | |
| 22 | #include "llvm/CodeGen/ValueTypes.h" |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 23 | #include "llvm/Value.h" |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 24 | #include "llvm/ADT/GraphTraits.h" |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/iterator" |
Jeff Cohen | 39931a3 | 2005-01-07 19:21:49 +0000 | [diff] [blame] | 26 | #include "llvm/Support/DataTypes.h" |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 27 | #include <cassert> |
| 28 | #include <vector> |
| 29 | |
| 30 | namespace llvm { |
| 31 | |
| 32 | class SelectionDAG; |
| 33 | class GlobalValue; |
| 34 | class MachineBasicBlock; |
| 35 | class SDNode; |
| 36 | template <typename T> struct simplify_type; |
Chris Lattner | b80e2be | 2005-11-09 23:46:43 +0000 | [diff] [blame] | 37 | template <typename T> struct ilist_traits; |
| 38 | template<typename NodeTy, typename Traits> class iplist; |
| 39 | template<typename NodeTy> class ilist_iterator; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 40 | |
| 41 | /// ISD namespace - This namespace contains an enum which represents all of the |
| 42 | /// SelectionDAG node types and value types. |
| 43 | /// |
| 44 | namespace ISD { |
| 45 | //===--------------------------------------------------------------------===// |
| 46 | /// ISD::NodeType enum - This enum defines all of the operators valid in a |
| 47 | /// SelectionDAG. |
| 48 | /// |
| 49 | enum NodeType { |
Chris Lattner | 8a496fc | 2005-01-13 17:58:35 +0000 | [diff] [blame] | 50 | // EntryToken - This is the marker used to indicate the start of the region. |
| 51 | EntryToken, |
| 52 | |
Reid Spencer | 8c4bde3 | 2005-08-27 19:06:05 +0000 | [diff] [blame] | 53 | // Token factor - This node takes multiple tokens as input and produces a |
Chris Lattner | 8a496fc | 2005-01-13 17:58:35 +0000 | [diff] [blame] | 54 | // single token result. This is used to represent the fact that the operand |
| 55 | // operators are independent of each other. |
| 56 | TokenFactor, |
Nate Begeman | f7f3d32 | 2005-08-30 02:39:32 +0000 | [diff] [blame] | 57 | |
| 58 | // AssertSext, AssertZext - These nodes record if a register contains a |
| 59 | // value that has already been zero or sign extended from a narrower type. |
| 60 | // These nodes take two operands. The first is the node that has already |
| 61 | // been extended, and the second is a value type node indicating the width |
| 62 | // of the extension |
| 63 | AssertSext, AssertZext, |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 64 | |
Chris Lattner | 8a496fc | 2005-01-13 17:58:35 +0000 | [diff] [blame] | 65 | // Various leaf nodes. |
| 66 | Constant, ConstantFP, GlobalAddress, FrameIndex, ConstantPool, |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 67 | BasicBlock, ExternalSymbol, VALUETYPE, CONDCODE, Register, |
Chris Lattner | 056f9f6 | 2005-08-17 00:33:30 +0000 | [diff] [blame] | 68 | |
| 69 | // TargetConstant - Like Constant, but the DAG does not do any folding or |
| 70 | // simplification of the constant. This is used by the DAG->DAG selector. |
| 71 | TargetConstant, |
Chris Lattner | f6b1849 | 2005-08-19 22:31:34 +0000 | [diff] [blame] | 72 | |
| 73 | // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or |
| 74 | // anything else with this node, and this is valid in the target-specific |
| 75 | // dag, turning into a GlobalAddress operand. |
| 76 | TargetGlobalAddress, |
Chris Lattner | afb2dd4 | 2005-08-25 00:43:01 +0000 | [diff] [blame] | 77 | TargetFrameIndex, |
Chris Lattner | aaaaf79 | 2005-08-25 05:02:41 +0000 | [diff] [blame] | 78 | TargetConstantPool, |
Andrew Lenharth | 2a2de66 | 2005-10-23 03:40:17 +0000 | [diff] [blame] | 79 | TargetExternalSymbol, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 80 | |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 81 | // CopyToReg - This node has three operands: a chain, a register number to |
| 82 | // set to this value, and a value. |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 83 | CopyToReg, |
| 84 | |
| 85 | // CopyFromReg - This node indicates that the input value is a virtual or |
| 86 | // physical register that is defined outside of the scope of this |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 87 | // SelectionDAG. The register is available from the RegSDNode object. |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 88 | CopyFromReg, |
| 89 | |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 90 | // ImplicitDef - This node indicates that the specified register is |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 91 | // implicitly defined by some operation (e.g. its a live-in argument). The |
| 92 | // two operands to this are the token chain coming in and the register. |
| 93 | // The only result is the token chain going out. |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 94 | ImplicitDef, |
| 95 | |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 96 | // UNDEF - An undefined node |
| 97 | UNDEF, |
| 98 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 99 | // EXTRACT_ELEMENT - This is used to get the first or second (determined by |
| 100 | // a Constant, which is required to be operand #1), element of the aggregate |
| 101 | // value specified as operand #0. This is only for use before legalization, |
| 102 | // for values that will be broken into multiple registers. |
| 103 | EXTRACT_ELEMENT, |
| 104 | |
| 105 | // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given |
| 106 | // two values of the same integer value type, this produces a value twice as |
| 107 | // big. Like EXTRACT_ELEMENT, this can only be used before legalization. |
| 108 | BUILD_PAIR, |
Chris Lattner | 006e3e3 | 2005-11-20 22:55:57 +0000 | [diff] [blame^] | 109 | |
| 110 | // MERGE_VALUES - This node takes multiple discrete operands and returns |
| 111 | // them all as its individual results. This nodes has exactly the same |
| 112 | // number of inputs and outputs, and is only valid before legalization. |
| 113 | // This node is useful for some pieces of the code generator that want to |
| 114 | // think about a single node with multiple results, not multiple nodes. |
| 115 | MERGE_VALUES, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 116 | |
Chris Lattner | 615c2d0 | 2005-09-28 22:29:58 +0000 | [diff] [blame] | 117 | // Simple integer binary arithmetic operators. |
Chris Lattner | bede0b7 | 2005-04-06 04:21:29 +0000 | [diff] [blame] | 118 | ADD, SUB, MUL, SDIV, UDIV, SREM, UREM, |
Chris Lattner | 615c2d0 | 2005-09-28 22:29:58 +0000 | [diff] [blame] | 119 | |
| 120 | // Simple binary floating point operators. |
| 121 | FADD, FSUB, FMUL, FDIV, FREM, |
Nate Begeman | 5fbb5d2 | 2005-11-19 00:36:38 +0000 | [diff] [blame] | 122 | |
| 123 | // Simple abstract vector operators. Unlike the integer and floating point |
| 124 | // binary operators, these nodes also take two additional operands: |
| 125 | // a constant element count, and a value type node indicating the type of |
| 126 | // the elements. The order is count, type, op0, op1. |
| 127 | VADD, VSUB, VMUL, |
Chris Lattner | bede0b7 | 2005-04-06 04:21:29 +0000 | [diff] [blame] | 128 | |
| 129 | // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing |
| 130 | // an unsigned/signed value of type i[2*n], then return the top part. |
| 131 | MULHU, MULHS, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 132 | |
| 133 | // Bitwise operators. |
| 134 | AND, OR, XOR, SHL, SRA, SRL, |
| 135 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 136 | // Counting operators |
| 137 | CTTZ, CTLZ, CTPOP, |
| 138 | |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 139 | // Select |
| 140 | SELECT, |
| 141 | |
| 142 | // Select with condition operator - This selects between a true value and |
| 143 | // a false value (ops #2 and #3) based on the boolean result of comparing |
| 144 | // the lhs and rhs (ops #0 and #1) of a conditional expression with the |
| 145 | // condition code in op #4, a CondCodeSDNode. |
| 146 | SELECT_CC, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 147 | |
| 148 | // SetCC operator - This evaluates to a boolean (i1) true value if the |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 149 | // condition is true. The operands to this are the left and right operands |
| 150 | // to compare (ops #0, and #1) and the condition code to compare them with |
| 151 | // (op #2) as a CondCodeSDNode. |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 152 | SETCC, |
| 153 | |
Chris Lattner | 5880b9f | 2005-01-20 18:50:39 +0000 | [diff] [blame] | 154 | // ADD_PARTS/SUB_PARTS - These operators take two logical operands which are |
| 155 | // broken into a multiple pieces each, and return the resulting pieces of |
| 156 | // doing an atomic add/sub operation. This is used to handle add/sub of |
| 157 | // expanded types. The operation ordering is: |
| 158 | // [Lo,Hi] = op [LoLHS,HiLHS], [LoRHS,HiRHS] |
| 159 | ADD_PARTS, SUB_PARTS, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 160 | |
Chris Lattner | 14c5b53 | 2005-04-02 03:30:33 +0000 | [diff] [blame] | 161 | // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded |
| 162 | // integer shift operations, just like ADD/SUB_PARTS. The operation |
| 163 | // ordering is: |
Chris Lattner | 6b8f2d6 | 2005-04-02 03:59:45 +0000 | [diff] [blame] | 164 | // [Lo,Hi] = op [LoLHS,HiLHS], Amt |
Chris Lattner | 14c5b53 | 2005-04-02 03:30:33 +0000 | [diff] [blame] | 165 | SHL_PARTS, SRA_PARTS, SRL_PARTS, |
| 166 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 167 | // Conversion operators. These are all single input single output |
| 168 | // operations. For all of these, the result type must be strictly |
| 169 | // wider or narrower (depending on the operation) than the source |
| 170 | // type. |
| 171 | |
| 172 | // SIGN_EXTEND - Used for integer types, replicating the sign bit |
| 173 | // into new bits. |
| 174 | SIGN_EXTEND, |
| 175 | |
| 176 | // ZERO_EXTEND - Used for integer types, zeroing the new bits. |
| 177 | ZERO_EXTEND, |
| 178 | |
Chris Lattner | 7e122db | 2005-09-02 00:14:40 +0000 | [diff] [blame] | 179 | // ANY_EXTEND - Used for integer types. The high bits are undefined. |
| 180 | ANY_EXTEND, |
| 181 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 182 | // TRUNCATE - Completely drop the high bits. |
| 183 | TRUNCATE, |
| 184 | |
Chris Lattner | 1645ed0 | 2005-01-08 08:08:49 +0000 | [diff] [blame] | 185 | // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign |
| 186 | // depends on the first letter) to floating point. |
| 187 | SINT_TO_FP, |
| 188 | UINT_TO_FP, |
| 189 | |
Chris Lattner | ea57610 | 2005-04-13 02:36:41 +0000 | [diff] [blame] | 190 | // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to |
| 191 | // sign extend a small value in a large integer register (e.g. sign |
| 192 | // extending the low 8 bits of a 32-bit register to fill the top 24 bits |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 193 | // with the 7th bit). The size of the smaller type is indicated by the 1th |
| 194 | // operand, a ValueType node. |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 195 | SIGN_EXTEND_INREG, |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 196 | |
Chris Lattner | 1645ed0 | 2005-01-08 08:08:49 +0000 | [diff] [blame] | 197 | // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned |
| 198 | // integer. |
| 199 | FP_TO_SINT, |
| 200 | FP_TO_UINT, |
| 201 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 202 | // FP_ROUND - Perform a rounding operation from the current |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 203 | // precision down to the specified precision (currently always 64->32). |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 204 | FP_ROUND, |
| 205 | |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 206 | // FP_ROUND_INREG - This operator takes a floating point register, and |
| 207 | // rounds it to a floating point value. It then promotes it and returns it |
| 208 | // in a register of the same size. This operation effectively just discards |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 209 | // excess precision. The type to round down to is specified by the 1th |
| 210 | // operation, a VTSDNode (currently always 64->32->64). |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 211 | FP_ROUND_INREG, |
| 212 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 213 | // FP_EXTEND - Extend a smaller FP type into a larger FP type. |
| 214 | FP_EXTEND, |
| 215 | |
Chris Lattner | 7f64464 | 2005-04-28 21:44:03 +0000 | [diff] [blame] | 216 | // FNEG, FABS, FSQRT, FSIN, FCOS - Perform unary floating point negation, |
| 217 | // absolute value, square root, sine and cosine operations. |
| 218 | FNEG, FABS, FSQRT, FSIN, FCOS, |
Chris Lattner | 7366fd3 | 2005-04-02 04:58:28 +0000 | [diff] [blame] | 219 | |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 220 | // Other operators. LOAD and STORE have token chains as their first |
Chris Lattner | f7db8c6 | 2005-07-10 00:28:25 +0000 | [diff] [blame] | 221 | // operand, then the same operands as an LLVM load/store instruction, then a |
| 222 | // SRCVALUE node that provides alias analysis information. |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 223 | LOAD, STORE, |
Nate Begeman | 5fbb5d2 | 2005-11-19 00:36:38 +0000 | [diff] [blame] | 224 | |
| 225 | // Abstract vector version of LOAD. VLOAD has a token chain as the first |
| 226 | // operand, followed by a pointer operand, a constant element count, a value |
| 227 | // type node indicating the type of the elements, and a SRCVALUE node. |
| 228 | VLOAD, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 229 | |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 230 | // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators all load a value from |
| 231 | // memory and extend them to a larger value (e.g. load a byte into a word |
| 232 | // register). All three of these have four operands, a token chain, a |
| 233 | // pointer to load from, a SRCVALUE for alias analysis, and a VALUETYPE node |
| 234 | // indicating the type to load. |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 235 | // |
| 236 | // SEXTLOAD loads the integer operand and sign extends it to a larger |
| 237 | // integer result type. |
| 238 | // ZEXTLOAD loads the integer operand and zero extends it to a larger |
| 239 | // integer result type. |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 240 | // EXTLOAD is used for two things: floating point extending loads, and |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 241 | // integer extending loads where it doesn't matter what the high |
| 242 | // bits are set to. The code generator is allowed to codegen this |
| 243 | // into whichever operation is more efficient. |
| 244 | EXTLOAD, SEXTLOAD, ZEXTLOAD, |
| 245 | |
| 246 | // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a |
| 247 | // value and stores it to memory in one operation. This can be used for |
Chris Lattner | f7db8c6 | 2005-07-10 00:28:25 +0000 | [diff] [blame] | 248 | // either integer or floating point operands. The first four operands of |
| 249 | // this are the same as a standard store. The fifth is the ValueType to |
| 250 | // store it as (which will be smaller than the source value). |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 251 | TRUNCSTORE, |
| 252 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 253 | // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned |
| 254 | // to a specified boundary. The first operand is the token chain, the |
| 255 | // second is the number of bytes to allocate, and the third is the alignment |
Chris Lattner | 74fe063 | 2005-08-29 22:48:32 +0000 | [diff] [blame] | 256 | // boundary. The size is guaranteed to be a multiple of the stack |
| 257 | // alignment, and the alignment is guaranteed to be bigger than the stack |
| 258 | // alignment (if required) or 0 to get standard stack alignment. |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 259 | DYNAMIC_STACKALLOC, |
| 260 | |
| 261 | // Control flow instructions. These all have token chains. |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 262 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 263 | // BR - Unconditional branch. The first operand is the chain |
| 264 | // operand, the second is the MBB to branch to. |
| 265 | BR, |
| 266 | |
| 267 | // BRCOND - Conditional branch. The first operand is the chain, |
| 268 | // the second is the condition, the third is the block to branch |
| 269 | // to if the condition is true. |
| 270 | BRCOND, |
| 271 | |
Chris Lattner | 1df6338 | 2005-04-09 03:21:50 +0000 | [diff] [blame] | 272 | // BRCONDTWOWAY - Two-way conditional branch. The first operand is the |
| 273 | // chain, the second is the condition, the third is the block to branch to |
| 274 | // if true, and the forth is the block to branch to if false. Targets |
| 275 | // usually do not implement this, preferring to have legalize demote the |
| 276 | // operation to BRCOND/BR pairs when necessary. |
| 277 | BRCONDTWOWAY, |
| 278 | |
Nate Begeman | 7cbd525 | 2005-08-16 19:49:35 +0000 | [diff] [blame] | 279 | // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in |
| 280 | // that the condition is represented as condition code, and two nodes to |
| 281 | // compare, rather than as a combined SetCC node. The operands in order are |
| 282 | // chain, cc, lhs, rhs, block to branch to if condition is true. |
| 283 | BR_CC, |
| 284 | |
| 285 | // BRTWOWAY_CC - Two-way conditional branch. The operands in order are |
| 286 | // chain, cc, lhs, rhs, block to branch to if condition is true, block to |
| 287 | // branch to if condition is false. Targets usually do not implement this, |
| 288 | // preferring to have legalize demote the operation to BRCOND/BR pairs. |
| 289 | BRTWOWAY_CC, |
| 290 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 291 | // RET - Return from function. The first operand is the chain, |
| 292 | // and any subsequent operands are the return values for the |
| 293 | // function. This operation can have variable number of operands. |
| 294 | RET, |
| 295 | |
| 296 | // CALL - Call to a function pointer. The first operand is the chain, the |
| 297 | // second is the destination function pointer (a GlobalAddress for a direct |
| 298 | // call). Arguments have already been lowered to explicit DAGs according to |
Chris Lattner | 4c1eae9 | 2005-05-13 18:40:17 +0000 | [diff] [blame] | 299 | // the calling convention in effect here. TAILCALL is the same as CALL, but |
| 300 | // the callee is known not to access the stack of the caller. |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 301 | CALL, |
Chris Lattner | 4c1eae9 | 2005-05-13 18:40:17 +0000 | [diff] [blame] | 302 | TAILCALL, |
Chris Lattner | ef36aa7 | 2005-01-11 05:56:17 +0000 | [diff] [blame] | 303 | |
| 304 | // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest |
| 305 | // correspond to the operands of the LLVM intrinsic functions. The only |
| 306 | // result is a token chain. The alignment argument is guaranteed to be a |
| 307 | // Constant node. |
| 308 | MEMSET, |
| 309 | MEMMOVE, |
| 310 | MEMCPY, |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 311 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 312 | // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of |
| 313 | // a call sequence, and carry arbitrary information that target might want |
| 314 | // to know. The first operand is a chain, the rest are specified by the |
| 315 | // target and not touched by the DAG optimizers. |
| 316 | CALLSEQ_START, // Beginning of a call sequence |
| 317 | CALLSEQ_END, // End of a call sequence |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 318 | |
Chris Lattner | 21074f4 | 2005-05-09 20:21:27 +0000 | [diff] [blame] | 319 | // SRCVALUE - This corresponds to a Value*, and is used to associate memory |
| 320 | // locations with their value. This allows one use alias analysis |
| 321 | // information in the backend. |
| 322 | SRCVALUE, |
| 323 | |
Misha Brukman | e3f570c | 2005-03-31 21:30:35 +0000 | [diff] [blame] | 324 | // PCMARKER - This corresponds to the pcmarker intrinsic. |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 325 | PCMARKER, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 326 | |
Andrew Lenharth | aeef8fc | 2005-11-11 16:45:18 +0000 | [diff] [blame] | 327 | // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic. |
Andrew Lenharth | 8b91c77 | 2005-11-11 22:48:54 +0000 | [diff] [blame] | 328 | // The only operand is a chain and a value and a chain are produced. The |
| 329 | // value is the contents of the architecture specific cycle counter like |
| 330 | // register (or other high accuracy low latency clock source) |
Andrew Lenharth | aeef8fc | 2005-11-11 16:45:18 +0000 | [diff] [blame] | 331 | READCYCLECOUNTER, |
| 332 | |
Chris Lattner | 21074f4 | 2005-05-09 20:21:27 +0000 | [diff] [blame] | 333 | // READPORT, WRITEPORT, READIO, WRITEIO - These correspond to the LLVM |
| 334 | // intrinsics of the same name. The first operand is a token chain, the |
| 335 | // other operands match the intrinsic. These produce a token chain in |
| 336 | // addition to a value (if any). |
| 337 | READPORT, WRITEPORT, READIO, WRITEIO, |
Chris Lattner | d623e95 | 2005-10-05 06:34:34 +0000 | [diff] [blame] | 338 | |
| 339 | // HANDLENODE node - Used as a handle for various purposes. |
| 340 | HANDLENODE, |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 341 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 342 | // BUILTIN_OP_END - This must be the last enum value in this list. |
| 343 | BUILTIN_OP_END, |
| 344 | }; |
| 345 | |
| 346 | //===--------------------------------------------------------------------===// |
| 347 | /// ISD::CondCode enum - These are ordered carefully to make the bitfields |
| 348 | /// below work out, when considering SETFALSE (something that never exists |
| 349 | /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered |
| 350 | /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal |
| 351 | /// to. If the "N" column is 1, the result of the comparison is undefined if |
| 352 | /// the input is a NAN. |
| 353 | /// |
| 354 | /// All of these (except for the 'always folded ops') should be handled for |
| 355 | /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT, |
| 356 | /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used. |
| 357 | /// |
| 358 | /// Note that these are laid out in a specific order to allow bit-twiddling |
| 359 | /// to transform conditions. |
| 360 | enum CondCode { |
| 361 | // Opcode N U L G E Intuitive operation |
| 362 | SETFALSE, // 0 0 0 0 Always false (always folded) |
| 363 | SETOEQ, // 0 0 0 1 True if ordered and equal |
| 364 | SETOGT, // 0 0 1 0 True if ordered and greater than |
| 365 | SETOGE, // 0 0 1 1 True if ordered and greater than or equal |
| 366 | SETOLT, // 0 1 0 0 True if ordered and less than |
| 367 | SETOLE, // 0 1 0 1 True if ordered and less than or equal |
| 368 | SETONE, // 0 1 1 0 True if ordered and operands are unequal |
| 369 | SETO, // 0 1 1 1 True if ordered (no nans) |
| 370 | SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y) |
| 371 | SETUEQ, // 1 0 0 1 True if unordered or equal |
| 372 | SETUGT, // 1 0 1 0 True if unordered or greater than |
| 373 | SETUGE, // 1 0 1 1 True if unordered, greater than, or equal |
| 374 | SETULT, // 1 1 0 0 True if unordered or less than |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 375 | SETULE, // 1 1 0 1 True if unordered, less than, or equal |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 376 | SETUNE, // 1 1 1 0 True if unordered or not equal |
| 377 | SETTRUE, // 1 1 1 1 Always true (always folded) |
| 378 | // Don't care operations: undefined if the input is a nan. |
| 379 | SETFALSE2, // 1 X 0 0 0 Always false (always folded) |
| 380 | SETEQ, // 1 X 0 0 1 True if equal |
| 381 | SETGT, // 1 X 0 1 0 True if greater than |
| 382 | SETGE, // 1 X 0 1 1 True if greater than or equal |
| 383 | SETLT, // 1 X 1 0 0 True if less than |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 384 | SETLE, // 1 X 1 0 1 True if less than or equal |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 385 | SETNE, // 1 X 1 1 0 True if not equal |
| 386 | SETTRUE2, // 1 X 1 1 1 Always true (always folded) |
| 387 | |
| 388 | SETCC_INVALID, // Marker value. |
| 389 | }; |
| 390 | |
| 391 | /// isSignedIntSetCC - Return true if this is a setcc instruction that |
| 392 | /// performs a signed comparison when used with integer operands. |
| 393 | inline bool isSignedIntSetCC(CondCode Code) { |
| 394 | return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE; |
| 395 | } |
| 396 | |
| 397 | /// isUnsignedIntSetCC - Return true if this is a setcc instruction that |
| 398 | /// performs an unsigned comparison when used with integer operands. |
| 399 | inline bool isUnsignedIntSetCC(CondCode Code) { |
| 400 | return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE; |
| 401 | } |
| 402 | |
| 403 | /// isTrueWhenEqual - Return true if the specified condition returns true if |
| 404 | /// the two operands to the condition are equal. Note that if one of the two |
| 405 | /// operands is a NaN, this value is meaningless. |
| 406 | inline bool isTrueWhenEqual(CondCode Cond) { |
| 407 | return ((int)Cond & 1) != 0; |
| 408 | } |
| 409 | |
| 410 | /// getUnorderedFlavor - This function returns 0 if the condition is always |
| 411 | /// false if an operand is a NaN, 1 if the condition is always true if the |
| 412 | /// operand is a NaN, and 2 if the condition is undefined if the operand is a |
| 413 | /// NaN. |
| 414 | inline unsigned getUnorderedFlavor(CondCode Cond) { |
| 415 | return ((int)Cond >> 3) & 3; |
| 416 | } |
| 417 | |
| 418 | /// getSetCCInverse - Return the operation corresponding to !(X op Y), where |
| 419 | /// 'op' is a valid SetCC operation. |
| 420 | CondCode getSetCCInverse(CondCode Operation, bool isInteger); |
| 421 | |
| 422 | /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X) |
| 423 | /// when given the operation for (X op Y). |
| 424 | CondCode getSetCCSwappedOperands(CondCode Operation); |
| 425 | |
| 426 | /// getSetCCOrOperation - Return the result of a logical OR between different |
| 427 | /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This |
| 428 | /// function returns SETCC_INVALID if it is not possible to represent the |
| 429 | /// resultant comparison. |
| 430 | CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger); |
| 431 | |
| 432 | /// getSetCCAndOperation - Return the result of a logical AND between |
| 433 | /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This |
| 434 | /// function returns SETCC_INVALID if it is not possible to represent the |
| 435 | /// resultant comparison. |
| 436 | CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger); |
| 437 | } // end llvm::ISD namespace |
| 438 | |
| 439 | |
| 440 | //===----------------------------------------------------------------------===// |
| 441 | /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple |
| 442 | /// values as the result of a computation. Many nodes return multiple values, |
| 443 | /// from loads (which define a token and a return value) to ADDC (which returns |
| 444 | /// a result and a carry value), to calls (which may return an arbitrary number |
| 445 | /// of values). |
| 446 | /// |
| 447 | /// As such, each use of a SelectionDAG computation must indicate the node that |
| 448 | /// computes it as well as which return value to use from that node. This pair |
| 449 | /// of information is represented with the SDOperand value type. |
| 450 | /// |
Chris Lattner | f26bc8e | 2005-01-08 19:52:31 +0000 | [diff] [blame] | 451 | class SDOperand { |
| 452 | public: |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 453 | SDNode *Val; // The node defining the value we are using. |
| 454 | unsigned ResNo; // Which return value of the node we are using. |
| 455 | |
| 456 | SDOperand() : Val(0) {} |
| 457 | SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {} |
| 458 | |
| 459 | bool operator==(const SDOperand &O) const { |
| 460 | return Val == O.Val && ResNo == O.ResNo; |
| 461 | } |
| 462 | bool operator!=(const SDOperand &O) const { |
| 463 | return !operator==(O); |
| 464 | } |
| 465 | bool operator<(const SDOperand &O) const { |
| 466 | return Val < O.Val || (Val == O.Val && ResNo < O.ResNo); |
| 467 | } |
| 468 | |
| 469 | SDOperand getValue(unsigned R) const { |
| 470 | return SDOperand(Val, R); |
| 471 | } |
| 472 | |
| 473 | /// getValueType - Return the ValueType of the referenced return value. |
| 474 | /// |
| 475 | inline MVT::ValueType getValueType() const; |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 476 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 477 | // Forwarding methods - These forward to the corresponding methods in SDNode. |
| 478 | inline unsigned getOpcode() const; |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 479 | inline unsigned getNodeDepth() const; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 480 | inline unsigned getNumOperands() const; |
| 481 | inline const SDOperand &getOperand(unsigned i) const; |
Nate Begeman | 0f66a91 | 2005-08-17 23:44:54 +0000 | [diff] [blame] | 482 | inline bool isTargetOpcode() const; |
| 483 | inline unsigned getTargetOpcode() const; |
Chris Lattner | a44f4ae | 2005-01-13 22:58:50 +0000 | [diff] [blame] | 484 | |
| 485 | /// hasOneUse - Return true if there is exactly one operation using this |
| 486 | /// result value of the defining operator. |
| 487 | inline bool hasOneUse() const; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 488 | }; |
| 489 | |
| 490 | |
| 491 | /// simplify_type specializations - Allow casting operators to work directly on |
| 492 | /// SDOperands as if they were SDNode*'s. |
| 493 | template<> struct simplify_type<SDOperand> { |
| 494 | typedef SDNode* SimpleType; |
| 495 | static SimpleType getSimplifiedValue(const SDOperand &Val) { |
| 496 | return static_cast<SimpleType>(Val.Val); |
| 497 | } |
| 498 | }; |
| 499 | template<> struct simplify_type<const SDOperand> { |
| 500 | typedef SDNode* SimpleType; |
| 501 | static SimpleType getSimplifiedValue(const SDOperand &Val) { |
| 502 | return static_cast<SimpleType>(Val.Val); |
| 503 | } |
| 504 | }; |
| 505 | |
| 506 | |
| 507 | /// SDNode - Represents one node in the SelectionDAG. |
| 508 | /// |
| 509 | class SDNode { |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 510 | /// NodeType - The operation that this node performs. |
| 511 | /// |
| 512 | unsigned short NodeType; |
| 513 | |
| 514 | /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1. This |
| 515 | /// means that leaves have a depth of 1, things that use only leaves have a |
| 516 | /// depth of 2, etc. |
| 517 | unsigned short NodeDepth; |
| 518 | |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 519 | /// OperandList - The values that are used by this operation. |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 520 | /// |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 521 | SDOperand *OperandList; |
| 522 | |
| 523 | /// ValueList - The types of the values this node defines. SDNode's may |
| 524 | /// define multiple values simultaneously. |
| 525 | MVT::ValueType *ValueList; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 526 | |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 527 | /// NumOperands/NumValues - The number of entries in the Operand/Value list. |
| 528 | unsigned short NumOperands, NumValues; |
Chris Lattner | b80e2be | 2005-11-09 23:46:43 +0000 | [diff] [blame] | 529 | |
| 530 | /// Prev/Next pointers - These pointers form the linked list of of the |
| 531 | /// AllNodes list in the current DAG. |
| 532 | SDNode *Prev, *Next; |
| 533 | friend struct ilist_traits<SDNode>; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 534 | |
| 535 | /// Uses - These are all of the SDNode's that use a value produced by this |
| 536 | /// node. |
| 537 | std::vector<SDNode*> Uses; |
| 538 | public: |
Chris Lattner | b80e2be | 2005-11-09 23:46:43 +0000 | [diff] [blame] | 539 | virtual ~SDNode() { |
| 540 | assert(NumOperands == 0 && "Operand list not cleared before deletion"); |
| 541 | } |
| 542 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 543 | //===--------------------------------------------------------------------===// |
| 544 | // Accessors |
| 545 | // |
| 546 | unsigned getOpcode() const { return NodeType; } |
Nate Begeman | 0f66a91 | 2005-08-17 23:44:54 +0000 | [diff] [blame] | 547 | bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; } |
| 548 | unsigned getTargetOpcode() const { |
| 549 | assert(isTargetOpcode() && "Not a target opcode!"); |
| 550 | return NodeType - ISD::BUILTIN_OP_END; |
| 551 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 552 | |
| 553 | size_t use_size() const { return Uses.size(); } |
| 554 | bool use_empty() const { return Uses.empty(); } |
| 555 | bool hasOneUse() const { return Uses.size() == 1; } |
| 556 | |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 557 | /// getNodeDepth - Return the distance from this node to the leaves in the |
| 558 | /// graph. The leaves have a depth of 1. |
| 559 | unsigned getNodeDepth() const { return NodeDepth; } |
| 560 | |
Chris Lattner | 7ece380 | 2005-01-17 02:24:59 +0000 | [diff] [blame] | 561 | typedef std::vector<SDNode*>::const_iterator use_iterator; |
| 562 | use_iterator use_begin() const { return Uses.begin(); } |
| 563 | use_iterator use_end() const { return Uses.end(); } |
| 564 | |
Chris Lattner | b18a2f8 | 2005-01-12 18:37:33 +0000 | [diff] [blame] | 565 | /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the |
| 566 | /// indicated value. This method ignores uses of other values defined by this |
| 567 | /// operation. |
| 568 | bool hasNUsesOfValue(unsigned NUses, unsigned Value); |
| 569 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 570 | /// getNumOperands - Return the number of values used by this operation. |
| 571 | /// |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 572 | unsigned getNumOperands() const { return NumOperands; } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 573 | |
| 574 | const SDOperand &getOperand(unsigned Num) const { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 575 | assert(Num < NumOperands && "Invalid child # of SDNode!"); |
| 576 | return OperandList[Num]; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 577 | } |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 578 | typedef const SDOperand* op_iterator; |
| 579 | op_iterator op_begin() const { return OperandList; } |
| 580 | op_iterator op_end() const { return OperandList+NumOperands; } |
Chris Lattner | 50f5a51 | 2005-05-14 06:19:11 +0000 | [diff] [blame] | 581 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 582 | |
| 583 | /// getNumValues - Return the number of values defined/returned by this |
| 584 | /// operator. |
| 585 | /// |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 586 | unsigned getNumValues() const { return NumValues; } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 587 | |
| 588 | /// getValueType - Return the type of a specified result. |
| 589 | /// |
| 590 | MVT::ValueType getValueType(unsigned ResNo) const { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 591 | assert(ResNo < NumValues && "Illegal result number!"); |
| 592 | return ValueList[ResNo]; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 593 | } |
Jeff Cohen | 9eb59ec | 2005-07-27 05:53:44 +0000 | [diff] [blame] | 594 | |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 595 | typedef const MVT::ValueType* value_iterator; |
| 596 | value_iterator value_begin() const { return ValueList; } |
| 597 | value_iterator value_end() const { return ValueList+NumValues; } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 598 | |
Chris Lattner | 6e6e3ce | 2005-01-10 23:25:04 +0000 | [diff] [blame] | 599 | /// getOperationName - Return the opcode of this operation for printing. |
| 600 | /// |
Chris Lattner | efe5869 | 2005-08-16 18:32:18 +0000 | [diff] [blame] | 601 | const char* getOperationName(const SelectionDAG *G = 0) const; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 602 | void dump() const; |
Chris Lattner | efe5869 | 2005-08-16 18:32:18 +0000 | [diff] [blame] | 603 | void dump(const SelectionDAG *G) const; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 604 | |
| 605 | static bool classof(const SDNode *) { return true; } |
| 606 | |
Chris Lattner | 73b3537 | 2005-05-11 18:56:45 +0000 | [diff] [blame] | 607 | |
| 608 | /// setAdjCallChain - This method should only be used by the legalizer. |
| 609 | void setAdjCallChain(SDOperand N); |
Jeff Cohen | 9eb59ec | 2005-07-27 05:53:44 +0000 | [diff] [blame] | 610 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 611 | protected: |
| 612 | friend class SelectionDAG; |
Chris Lattner | 109654f | 2005-11-08 23:30:11 +0000 | [diff] [blame] | 613 | |
| 614 | /// getValueTypeList - Return a pointer to the specified value type. |
| 615 | /// |
| 616 | static MVT::ValueType *getValueTypeList(MVT::ValueType VT); |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 617 | |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 618 | SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 619 | OperandList = 0; NumOperands = 0; |
Chris Lattner | 109654f | 2005-11-08 23:30:11 +0000 | [diff] [blame] | 620 | ValueList = getValueTypeList(VT); |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 621 | NumValues = 1; |
Chris Lattner | b80e2be | 2005-11-09 23:46:43 +0000 | [diff] [blame] | 622 | Prev = 0; Next = 0; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 623 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 624 | SDNode(unsigned NT, SDOperand Op) |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 625 | : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 626 | OperandList = new SDOperand[1]; |
| 627 | OperandList[0] = Op; |
| 628 | NumOperands = 1; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 629 | Op.Val->Uses.push_back(this); |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 630 | ValueList = 0; |
| 631 | NumValues = 0; |
Chris Lattner | b80e2be | 2005-11-09 23:46:43 +0000 | [diff] [blame] | 632 | Prev = 0; Next = 0; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 633 | } |
| 634 | SDNode(unsigned NT, SDOperand N1, SDOperand N2) |
| 635 | : NodeType(NT) { |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 636 | if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth()) |
| 637 | NodeDepth = N1.Val->getNodeDepth()+1; |
| 638 | else |
| 639 | NodeDepth = N2.Val->getNodeDepth()+1; |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 640 | OperandList = new SDOperand[2]; |
| 641 | OperandList[0] = N1; |
| 642 | OperandList[1] = N2; |
| 643 | NumOperands = 2; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 644 | N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 645 | ValueList = 0; |
| 646 | NumValues = 0; |
Chris Lattner | b80e2be | 2005-11-09 23:46:43 +0000 | [diff] [blame] | 647 | Prev = 0; Next = 0; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 648 | } |
| 649 | SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3) |
| 650 | : NodeType(NT) { |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 651 | unsigned ND = N1.Val->getNodeDepth(); |
| 652 | if (ND < N2.Val->getNodeDepth()) |
| 653 | ND = N2.Val->getNodeDepth(); |
| 654 | if (ND < N3.Val->getNodeDepth()) |
| 655 | ND = N3.Val->getNodeDepth(); |
| 656 | NodeDepth = ND+1; |
| 657 | |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 658 | OperandList = new SDOperand[3]; |
| 659 | OperandList[0] = N1; |
| 660 | OperandList[1] = N2; |
| 661 | OperandList[2] = N3; |
| 662 | NumOperands = 3; |
| 663 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 664 | N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); |
| 665 | N3.Val->Uses.push_back(this); |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 666 | ValueList = 0; |
| 667 | NumValues = 0; |
Chris Lattner | b80e2be | 2005-11-09 23:46:43 +0000 | [diff] [blame] | 668 | Prev = 0; Next = 0; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 669 | } |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 670 | SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4) |
| 671 | : NodeType(NT) { |
| 672 | unsigned ND = N1.Val->getNodeDepth(); |
| 673 | if (ND < N2.Val->getNodeDepth()) |
| 674 | ND = N2.Val->getNodeDepth(); |
| 675 | if (ND < N3.Val->getNodeDepth()) |
| 676 | ND = N3.Val->getNodeDepth(); |
| 677 | if (ND < N4.Val->getNodeDepth()) |
| 678 | ND = N4.Val->getNodeDepth(); |
| 679 | NodeDepth = ND+1; |
| 680 | |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 681 | OperandList = new SDOperand[4]; |
| 682 | OperandList[0] = N1; |
| 683 | OperandList[1] = N2; |
| 684 | OperandList[2] = N3; |
| 685 | OperandList[3] = N4; |
| 686 | NumOperands = 4; |
| 687 | |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 688 | N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); |
| 689 | N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this); |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 690 | ValueList = 0; |
| 691 | NumValues = 0; |
Chris Lattner | b80e2be | 2005-11-09 23:46:43 +0000 | [diff] [blame] | 692 | Prev = 0; Next = 0; |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 693 | } |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 694 | SDNode(unsigned Opc, const std::vector<SDOperand> &Nodes) : NodeType(Opc) { |
| 695 | NumOperands = Nodes.size(); |
| 696 | OperandList = new SDOperand[NumOperands]; |
| 697 | |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 698 | unsigned ND = 0; |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 699 | for (unsigned i = 0, e = Nodes.size(); i != e; ++i) { |
| 700 | OperandList[i] = Nodes[i]; |
| 701 | SDNode *N = OperandList[i].Val; |
| 702 | N->Uses.push_back(this); |
| 703 | if (ND < N->getNodeDepth()) ND = N->getNodeDepth(); |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 704 | } |
| 705 | NodeDepth = ND+1; |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 706 | ValueList = 0; |
| 707 | NumValues = 0; |
Chris Lattner | b80e2be | 2005-11-09 23:46:43 +0000 | [diff] [blame] | 708 | Prev = 0; Next = 0; |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 709 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 710 | |
Chris Lattner | 1b95095 | 2005-08-16 18:16:24 +0000 | [diff] [blame] | 711 | /// MorphNodeTo - This clears the return value and operands list, and sets the |
| 712 | /// opcode of the node to the specified value. This should only be used by |
| 713 | /// the SelectionDAG class. |
| 714 | void MorphNodeTo(unsigned Opc) { |
| 715 | NodeType = Opc; |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 716 | ValueList = 0; |
| 717 | NumValues = 0; |
Chris Lattner | b467f8a | 2005-08-17 01:54:00 +0000 | [diff] [blame] | 718 | |
| 719 | // Clear the operands list, updating used nodes to remove this from their |
| 720 | // use list. |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 721 | for (op_iterator I = op_begin(), E = op_end(); I != E; ++I) |
| 722 | I->Val->removeUser(this); |
| 723 | delete [] OperandList; |
| 724 | OperandList = 0; |
| 725 | NumOperands = 0; |
Chris Lattner | 1b95095 | 2005-08-16 18:16:24 +0000 | [diff] [blame] | 726 | } |
| 727 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 728 | void setValueTypes(MVT::ValueType VT) { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 729 | assert(NumValues == 0 && "Should not have values yet!"); |
Chris Lattner | 109654f | 2005-11-08 23:30:11 +0000 | [diff] [blame] | 730 | ValueList = getValueTypeList(VT); |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 731 | NumValues = 1; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 732 | } |
Chris Lattner | 109654f | 2005-11-08 23:30:11 +0000 | [diff] [blame] | 733 | void setValueTypes(MVT::ValueType *List, unsigned NumVal) { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 734 | assert(NumValues == 0 && "Should not have values yet!"); |
Chris Lattner | 109654f | 2005-11-08 23:30:11 +0000 | [diff] [blame] | 735 | ValueList = List; |
| 736 | NumValues = NumVal; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 737 | } |
Chris Lattner | 1b95095 | 2005-08-16 18:16:24 +0000 | [diff] [blame] | 738 | |
| 739 | void setOperands(SDOperand Op0) { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 740 | assert(NumOperands == 0 && "Should not have operands yet!"); |
| 741 | OperandList = new SDOperand[1]; |
| 742 | OperandList[0] = Op0; |
| 743 | NumOperands = 1; |
Chris Lattner | 8c3484c | 2005-08-17 18:58:38 +0000 | [diff] [blame] | 744 | Op0.Val->Uses.push_back(this); |
Chris Lattner | 1b95095 | 2005-08-16 18:16:24 +0000 | [diff] [blame] | 745 | } |
| 746 | void setOperands(SDOperand Op0, SDOperand Op1) { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 747 | assert(NumOperands == 0 && "Should not have operands yet!"); |
| 748 | OperandList = new SDOperand[2]; |
| 749 | OperandList[0] = Op0; |
| 750 | OperandList[1] = Op1; |
| 751 | NumOperands = 2; |
Chris Lattner | 8c3484c | 2005-08-17 18:58:38 +0000 | [diff] [blame] | 752 | Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); |
Chris Lattner | 1b95095 | 2005-08-16 18:16:24 +0000 | [diff] [blame] | 753 | } |
| 754 | void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 755 | assert(NumOperands == 0 && "Should not have operands yet!"); |
| 756 | OperandList = new SDOperand[3]; |
| 757 | OperandList[0] = Op0; |
| 758 | OperandList[1] = Op1; |
| 759 | OperandList[2] = Op2; |
| 760 | NumOperands = 3; |
Chris Lattner | 8c3484c | 2005-08-17 18:58:38 +0000 | [diff] [blame] | 761 | Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); |
| 762 | Op2.Val->Uses.push_back(this); |
| 763 | } |
Nate Begeman | 294a0a1 | 2005-08-18 07:30:15 +0000 | [diff] [blame] | 764 | void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3) { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 765 | assert(NumOperands == 0 && "Should not have operands yet!"); |
| 766 | OperandList = new SDOperand[4]; |
| 767 | OperandList[0] = Op0; |
| 768 | OperandList[1] = Op1; |
| 769 | OperandList[2] = Op2; |
| 770 | OperandList[3] = Op3; |
| 771 | NumOperands = 4; |
Nate Begeman | 294a0a1 | 2005-08-18 07:30:15 +0000 | [diff] [blame] | 772 | Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); |
| 773 | Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this); |
| 774 | } |
Chris Lattner | d54209f | 2005-08-21 18:49:58 +0000 | [diff] [blame] | 775 | void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3, |
| 776 | SDOperand Op4) { |
Chris Lattner | f71e843 | 2005-11-08 22:06:23 +0000 | [diff] [blame] | 777 | assert(NumOperands == 0 && "Should not have operands yet!"); |
| 778 | OperandList = new SDOperand[5]; |
| 779 | OperandList[0] = Op0; |
| 780 | OperandList[1] = Op1; |
| 781 | OperandList[2] = Op2; |
| 782 | OperandList[3] = Op3; |
| 783 | OperandList[4] = Op4; |
| 784 | NumOperands = 5; |
Chris Lattner | d54209f | 2005-08-21 18:49:58 +0000 | [diff] [blame] | 785 | Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); |
| 786 | Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this); |
| 787 | Op4.Val->Uses.push_back(this); |
| 788 | } |
Chris Lattner | 8c3484c | 2005-08-17 18:58:38 +0000 | [diff] [blame] | 789 | void addUser(SDNode *User) { |
| 790 | Uses.push_back(User); |
Chris Lattner | 1b95095 | 2005-08-16 18:16:24 +0000 | [diff] [blame] | 791 | } |
Chris Lattner | d1fc964 | 2005-01-07 21:08:55 +0000 | [diff] [blame] | 792 | void removeUser(SDNode *User) { |
| 793 | // Remove this user from the operand's use list. |
| 794 | for (unsigned i = Uses.size(); ; --i) { |
| 795 | assert(i != 0 && "Didn't find user!"); |
| 796 | if (Uses[i-1] == User) { |
Chris Lattner | 8c3484c | 2005-08-17 18:58:38 +0000 | [diff] [blame] | 797 | Uses[i-1] = Uses.back(); |
| 798 | Uses.pop_back(); |
| 799 | return; |
Chris Lattner | d1fc964 | 2005-01-07 21:08:55 +0000 | [diff] [blame] | 800 | } |
| 801 | } |
| 802 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 803 | }; |
| 804 | |
| 805 | |
| 806 | // Define inline functions from the SDOperand class. |
| 807 | |
| 808 | inline unsigned SDOperand::getOpcode() const { |
| 809 | return Val->getOpcode(); |
| 810 | } |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 811 | inline unsigned SDOperand::getNodeDepth() const { |
| 812 | return Val->getNodeDepth(); |
| 813 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 814 | inline MVT::ValueType SDOperand::getValueType() const { |
| 815 | return Val->getValueType(ResNo); |
| 816 | } |
| 817 | inline unsigned SDOperand::getNumOperands() const { |
| 818 | return Val->getNumOperands(); |
| 819 | } |
| 820 | inline const SDOperand &SDOperand::getOperand(unsigned i) const { |
| 821 | return Val->getOperand(i); |
| 822 | } |
Nate Begeman | 0f66a91 | 2005-08-17 23:44:54 +0000 | [diff] [blame] | 823 | inline bool SDOperand::isTargetOpcode() const { |
| 824 | return Val->isTargetOpcode(); |
| 825 | } |
| 826 | inline unsigned SDOperand::getTargetOpcode() const { |
| 827 | return Val->getTargetOpcode(); |
| 828 | } |
Chris Lattner | a44f4ae | 2005-01-13 22:58:50 +0000 | [diff] [blame] | 829 | inline bool SDOperand::hasOneUse() const { |
| 830 | return Val->hasNUsesOfValue(1, ResNo); |
| 831 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 832 | |
Chris Lattner | d623e95 | 2005-10-05 06:34:34 +0000 | [diff] [blame] | 833 | /// HandleSDNode - This class is used to form a handle around another node that |
| 834 | /// is persistant and is updated across invocations of replaceAllUsesWith on its |
| 835 | /// operand. This node should be directly created by end-users and not added to |
| 836 | /// the AllNodes list. |
| 837 | class HandleSDNode : public SDNode { |
| 838 | public: |
| 839 | HandleSDNode(SDOperand X) : SDNode(ISD::HANDLENODE, X) {} |
| 840 | ~HandleSDNode() { |
| 841 | MorphNodeTo(ISD::HANDLENODE); // Drops operand uses. |
| 842 | } |
| 843 | |
| 844 | SDOperand getValue() const { return getOperand(0); } |
| 845 | }; |
| 846 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 847 | |
| 848 | class ConstantSDNode : public SDNode { |
| 849 | uint64_t Value; |
| 850 | protected: |
| 851 | friend class SelectionDAG; |
Chris Lattner | 056f9f6 | 2005-08-17 00:33:30 +0000 | [diff] [blame] | 852 | ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT) |
| 853 | : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, VT), Value(val) { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 854 | } |
| 855 | public: |
| 856 | |
| 857 | uint64_t getValue() const { return Value; } |
| 858 | |
| 859 | int64_t getSignExtended() const { |
| 860 | unsigned Bits = MVT::getSizeInBits(getValueType(0)); |
Chris Lattner | f26bc8e | 2005-01-08 19:52:31 +0000 | [diff] [blame] | 861 | return ((int64_t)Value << (64-Bits)) >> (64-Bits); |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 862 | } |
| 863 | |
| 864 | bool isNullValue() const { return Value == 0; } |
| 865 | bool isAllOnesValue() const { |
Chris Lattner | 2bffad3 | 2005-04-08 21:31:29 +0000 | [diff] [blame] | 866 | int NumBits = MVT::getSizeInBits(getValueType(0)); |
| 867 | if (NumBits == 64) return Value+1 == 0; |
| 868 | return Value == (1ULL << NumBits)-1; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 869 | } |
| 870 | |
| 871 | static bool classof(const ConstantSDNode *) { return true; } |
| 872 | static bool classof(const SDNode *N) { |
Chris Lattner | 056f9f6 | 2005-08-17 00:33:30 +0000 | [diff] [blame] | 873 | return N->getOpcode() == ISD::Constant || |
| 874 | N->getOpcode() == ISD::TargetConstant; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 875 | } |
| 876 | }; |
| 877 | |
| 878 | class ConstantFPSDNode : public SDNode { |
| 879 | double Value; |
| 880 | protected: |
| 881 | friend class SelectionDAG; |
| 882 | ConstantFPSDNode(double val, MVT::ValueType VT) |
| 883 | : SDNode(ISD::ConstantFP, VT), Value(val) { |
| 884 | } |
| 885 | public: |
| 886 | |
| 887 | double getValue() const { return Value; } |
| 888 | |
| 889 | /// isExactlyValue - We don't rely on operator== working on double values, as |
| 890 | /// it returns true for things that are clearly not equal, like -0.0 and 0.0. |
| 891 | /// As such, this method can be used to do an exact bit-for-bit comparison of |
| 892 | /// two floating point values. |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 893 | bool isExactlyValue(double V) const; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 894 | |
| 895 | static bool classof(const ConstantFPSDNode *) { return true; } |
| 896 | static bool classof(const SDNode *N) { |
| 897 | return N->getOpcode() == ISD::ConstantFP; |
| 898 | } |
| 899 | }; |
| 900 | |
| 901 | class GlobalAddressSDNode : public SDNode { |
| 902 | GlobalValue *TheGlobal; |
| 903 | protected: |
| 904 | friend class SelectionDAG; |
Chris Lattner | f6b1849 | 2005-08-19 22:31:34 +0000 | [diff] [blame] | 905 | GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT) |
| 906 | : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT) { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 907 | TheGlobal = const_cast<GlobalValue*>(GA); |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 908 | } |
| 909 | public: |
| 910 | |
| 911 | GlobalValue *getGlobal() const { return TheGlobal; } |
| 912 | |
| 913 | static bool classof(const GlobalAddressSDNode *) { return true; } |
| 914 | static bool classof(const SDNode *N) { |
Chris Lattner | f6b1849 | 2005-08-19 22:31:34 +0000 | [diff] [blame] | 915 | return N->getOpcode() == ISD::GlobalAddress || |
| 916 | N->getOpcode() == ISD::TargetGlobalAddress; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 917 | } |
| 918 | }; |
| 919 | |
| 920 | |
| 921 | class FrameIndexSDNode : public SDNode { |
| 922 | int FI; |
| 923 | protected: |
| 924 | friend class SelectionDAG; |
Chris Lattner | afb2dd4 | 2005-08-25 00:43:01 +0000 | [diff] [blame] | 925 | FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg) |
| 926 | : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, VT), FI(fi) {} |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 927 | public: |
| 928 | |
| 929 | int getIndex() const { return FI; } |
| 930 | |
| 931 | static bool classof(const FrameIndexSDNode *) { return true; } |
| 932 | static bool classof(const SDNode *N) { |
Chris Lattner | afb2dd4 | 2005-08-25 00:43:01 +0000 | [diff] [blame] | 933 | return N->getOpcode() == ISD::FrameIndex || |
| 934 | N->getOpcode() == ISD::TargetFrameIndex; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 935 | } |
| 936 | }; |
| 937 | |
| 938 | class ConstantPoolSDNode : public SDNode { |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 939 | Constant *C; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 940 | protected: |
| 941 | friend class SelectionDAG; |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 942 | ConstantPoolSDNode(Constant *c, MVT::ValueType VT, bool isTarget) |
Chris Lattner | aaaaf79 | 2005-08-25 05:02:41 +0000 | [diff] [blame] | 943 | : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT), |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 944 | C(c) {} |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 945 | public: |
| 946 | |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 947 | Constant *get() const { return C; } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 948 | |
| 949 | static bool classof(const ConstantPoolSDNode *) { return true; } |
| 950 | static bool classof(const SDNode *N) { |
Chris Lattner | aaaaf79 | 2005-08-25 05:02:41 +0000 | [diff] [blame] | 951 | return N->getOpcode() == ISD::ConstantPool || |
| 952 | N->getOpcode() == ISD::TargetConstantPool; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 953 | } |
| 954 | }; |
| 955 | |
| 956 | class BasicBlockSDNode : public SDNode { |
| 957 | MachineBasicBlock *MBB; |
| 958 | protected: |
| 959 | friend class SelectionDAG; |
| 960 | BasicBlockSDNode(MachineBasicBlock *mbb) |
| 961 | : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {} |
| 962 | public: |
| 963 | |
| 964 | MachineBasicBlock *getBasicBlock() const { return MBB; } |
| 965 | |
| 966 | static bool classof(const BasicBlockSDNode *) { return true; } |
| 967 | static bool classof(const SDNode *N) { |
| 968 | return N->getOpcode() == ISD::BasicBlock; |
| 969 | } |
| 970 | }; |
| 971 | |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 972 | class SrcValueSDNode : public SDNode { |
| 973 | const Value *V; |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 974 | int offset; |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 975 | protected: |
| 976 | friend class SelectionDAG; |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 977 | SrcValueSDNode(const Value* v, int o) |
| 978 | : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {} |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 979 | |
| 980 | public: |
| 981 | const Value *getValue() const { return V; } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 982 | int getOffset() const { return offset; } |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 983 | |
| 984 | static bool classof(const SrcValueSDNode *) { return true; } |
| 985 | static bool classof(const SDNode *N) { |
| 986 | return N->getOpcode() == ISD::SRCVALUE; |
| 987 | } |
| 988 | }; |
| 989 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 990 | |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 991 | class RegisterSDNode : public SDNode { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 992 | unsigned Reg; |
| 993 | protected: |
| 994 | friend class SelectionDAG; |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 995 | RegisterSDNode(unsigned reg, MVT::ValueType VT) |
| 996 | : SDNode(ISD::Register, VT), Reg(reg) {} |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 997 | public: |
| 998 | |
| 999 | unsigned getReg() const { return Reg; } |
| 1000 | |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 1001 | static bool classof(const RegisterSDNode *) { return true; } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1002 | static bool classof(const SDNode *N) { |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 1003 | return N->getOpcode() == ISD::Register; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1004 | } |
| 1005 | }; |
| 1006 | |
| 1007 | class ExternalSymbolSDNode : public SDNode { |
| 1008 | const char *Symbol; |
| 1009 | protected: |
| 1010 | friend class SelectionDAG; |
Andrew Lenharth | 2a2de66 | 2005-10-23 03:40:17 +0000 | [diff] [blame] | 1011 | ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT) |
| 1012 | : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, VT), |
| 1013 | Symbol(Sym) { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1014 | } |
| 1015 | public: |
| 1016 | |
| 1017 | const char *getSymbol() const { return Symbol; } |
| 1018 | |
| 1019 | static bool classof(const ExternalSymbolSDNode *) { return true; } |
| 1020 | static bool classof(const SDNode *N) { |
Andrew Lenharth | 2a2de66 | 2005-10-23 03:40:17 +0000 | [diff] [blame] | 1021 | return N->getOpcode() == ISD::ExternalSymbol || |
| 1022 | N->getOpcode() == ISD::TargetExternalSymbol; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1023 | } |
| 1024 | }; |
| 1025 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1026 | class CondCodeSDNode : public SDNode { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1027 | ISD::CondCode Condition; |
| 1028 | protected: |
| 1029 | friend class SelectionDAG; |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1030 | CondCodeSDNode(ISD::CondCode Cond) |
| 1031 | : SDNode(ISD::CONDCODE, MVT::Other), Condition(Cond) { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1032 | } |
| 1033 | public: |
| 1034 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1035 | ISD::CondCode get() const { return Condition; } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1036 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1037 | static bool classof(const CondCodeSDNode *) { return true; } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1038 | static bool classof(const SDNode *N) { |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1039 | return N->getOpcode() == ISD::CONDCODE; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1040 | } |
| 1041 | }; |
| 1042 | |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1043 | /// VTSDNode - This class is used to represent MVT::ValueType's, which are used |
| 1044 | /// to parameterize some operations. |
| 1045 | class VTSDNode : public SDNode { |
| 1046 | MVT::ValueType ValueType; |
| 1047 | protected: |
| 1048 | friend class SelectionDAG; |
| 1049 | VTSDNode(MVT::ValueType VT) |
| 1050 | : SDNode(ISD::VALUETYPE, MVT::Other), ValueType(VT) {} |
| 1051 | public: |
| 1052 | |
| 1053 | MVT::ValueType getVT() const { return ValueType; } |
| 1054 | |
| 1055 | static bool classof(const VTSDNode *) { return true; } |
| 1056 | static bool classof(const SDNode *N) { |
| 1057 | return N->getOpcode() == ISD::VALUETYPE; |
| 1058 | } |
| 1059 | }; |
| 1060 | |
| 1061 | |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 1062 | class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> { |
| 1063 | SDNode *Node; |
| 1064 | unsigned Operand; |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 1065 | |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 1066 | SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {} |
| 1067 | public: |
| 1068 | bool operator==(const SDNodeIterator& x) const { |
| 1069 | return Operand == x.Operand; |
| 1070 | } |
| 1071 | bool operator!=(const SDNodeIterator& x) const { return !operator==(x); } |
| 1072 | |
| 1073 | const SDNodeIterator &operator=(const SDNodeIterator &I) { |
| 1074 | assert(I.Node == Node && "Cannot assign iterators to two different nodes!"); |
| 1075 | Operand = I.Operand; |
| 1076 | return *this; |
| 1077 | } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 1078 | |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 1079 | pointer operator*() const { |
| 1080 | return Node->getOperand(Operand).Val; |
| 1081 | } |
| 1082 | pointer operator->() const { return operator*(); } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 1083 | |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 1084 | SDNodeIterator& operator++() { // Preincrement |
| 1085 | ++Operand; |
| 1086 | return *this; |
| 1087 | } |
| 1088 | SDNodeIterator operator++(int) { // Postincrement |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 1089 | SDNodeIterator tmp = *this; ++*this; return tmp; |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 1090 | } |
| 1091 | |
| 1092 | static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); } |
| 1093 | static SDNodeIterator end (SDNode *N) { |
| 1094 | return SDNodeIterator(N, N->getNumOperands()); |
| 1095 | } |
| 1096 | |
| 1097 | unsigned getOperand() const { return Operand; } |
| 1098 | const SDNode *getNode() const { return Node; } |
| 1099 | }; |
| 1100 | |
| 1101 | template <> struct GraphTraits<SDNode*> { |
| 1102 | typedef SDNode NodeType; |
| 1103 | typedef SDNodeIterator ChildIteratorType; |
| 1104 | static inline NodeType *getEntryNode(SDNode *N) { return N; } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 1105 | static inline ChildIteratorType child_begin(NodeType *N) { |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 1106 | return SDNodeIterator::begin(N); |
| 1107 | } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 1108 | static inline ChildIteratorType child_end(NodeType *N) { |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 1109 | return SDNodeIterator::end(N); |
| 1110 | } |
| 1111 | }; |
| 1112 | |
Chris Lattner | b80e2be | 2005-11-09 23:46:43 +0000 | [diff] [blame] | 1113 | template<> |
| 1114 | struct ilist_traits<SDNode> { |
| 1115 | static SDNode *getPrev(const SDNode *N) { return N->Prev; } |
| 1116 | static SDNode *getNext(const SDNode *N) { return N->Next; } |
| 1117 | |
| 1118 | static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; } |
| 1119 | static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; } |
| 1120 | |
| 1121 | static SDNode *createSentinel() { |
| 1122 | return new SDNode(ISD::EntryToken, MVT::Other); |
| 1123 | } |
| 1124 | static void destroySentinel(SDNode *N) { delete N; } |
| 1125 | //static SDNode *createNode(const SDNode &V) { return new SDNode(V); } |
| 1126 | |
| 1127 | |
| 1128 | void addNodeToList(SDNode *NTy) {} |
| 1129 | void removeNodeFromList(SDNode *NTy) {} |
| 1130 | void transferNodesFromList(iplist<SDNode, ilist_traits> &L2, |
| 1131 | const ilist_iterator<SDNode> &X, |
| 1132 | const ilist_iterator<SDNode> &Y) {} |
| 1133 | }; |
| 1134 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 1135 | } // end llvm namespace |
| 1136 | |
| 1137 | #endif |