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" |
| 25 | #include "llvm/ADT/GraphTraits.h" |
| 26 | #include "llvm/ADT/iterator" |
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> |
| 29 | #include <vector> |
| 30 | |
| 31 | namespace llvm { |
| 32 | |
| 33 | class SelectionDAG; |
| 34 | class GlobalValue; |
| 35 | class MachineBasicBlock; |
| 36 | class SDNode; |
| 37 | template <typename T> struct simplify_type; |
| 38 | |
| 39 | /// ISD namespace - This namespace contains an enum which represents all of the |
| 40 | /// SelectionDAG node types and value types. |
| 41 | /// |
| 42 | namespace ISD { |
| 43 | //===--------------------------------------------------------------------===// |
| 44 | /// ISD::NodeType enum - This enum defines all of the operators valid in a |
| 45 | /// SelectionDAG. |
| 46 | /// |
| 47 | enum NodeType { |
Chris Lattner | 8a496fc | 2005-01-13 17:58:35 +0000 | [diff] [blame] | 48 | // EntryToken - This is the marker used to indicate the start of the region. |
| 49 | EntryToken, |
| 50 | |
| 51 | // Token factor - This node is takes multiple tokens as input and produces a |
| 52 | // single token result. This is used to represent the fact that the operand |
| 53 | // operators are independent of each other. |
| 54 | TokenFactor, |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 55 | |
Chris Lattner | 8a496fc | 2005-01-13 17:58:35 +0000 | [diff] [blame] | 56 | // Various leaf nodes. |
| 57 | Constant, ConstantFP, GlobalAddress, FrameIndex, ConstantPool, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 58 | BasicBlock, ExternalSymbol, |
| 59 | |
| 60 | // CopyToReg - This node has chain and child nodes, and an associated |
| 61 | // register number. The instruction selector must guarantee that the value |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 62 | // of the value node is available in the register stored in the RegSDNode |
| 63 | // object. |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 64 | CopyToReg, |
| 65 | |
| 66 | // CopyFromReg - This node indicates that the input value is a virtual or |
| 67 | // physical register that is defined outside of the scope of this |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 68 | // SelectionDAG. The register is available from the RegSDNode object. |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 69 | CopyFromReg, |
| 70 | |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 71 | // ImplicitDef - This node indicates that the specified register is |
| 72 | // implicitly defined by some operation (e.g. its a live-in argument). This |
| 73 | // register is indicated in the RegSDNode object. The only operand to this |
| 74 | // is the token chain coming in, the only result is the token chain going |
| 75 | // out. |
| 76 | ImplicitDef, |
| 77 | |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 78 | // UNDEF - An undefined node |
| 79 | UNDEF, |
| 80 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 81 | // EXTRACT_ELEMENT - This is used to get the first or second (determined by |
| 82 | // a Constant, which is required to be operand #1), element of the aggregate |
| 83 | // value specified as operand #0. This is only for use before legalization, |
| 84 | // for values that will be broken into multiple registers. |
| 85 | EXTRACT_ELEMENT, |
| 86 | |
| 87 | // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given |
| 88 | // two values of the same integer value type, this produces a value twice as |
| 89 | // big. Like EXTRACT_ELEMENT, this can only be used before legalization. |
| 90 | BUILD_PAIR, |
| 91 | |
| 92 | |
| 93 | // Simple binary arithmetic operators. |
Chris Lattner | bede0b7 | 2005-04-06 04:21:29 +0000 | [diff] [blame] | 94 | ADD, SUB, MUL, SDIV, UDIV, SREM, UREM, |
| 95 | |
| 96 | // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing |
| 97 | // an unsigned/signed value of type i[2*n], then return the top part. |
| 98 | MULHU, MULHS, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 99 | |
| 100 | // Bitwise operators. |
| 101 | AND, OR, XOR, SHL, SRA, SRL, |
| 102 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 103 | // Counting operators |
| 104 | CTTZ, CTLZ, CTPOP, |
| 105 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 106 | // Select operator. |
| 107 | SELECT, |
| 108 | |
| 109 | // SetCC operator - This evaluates to a boolean (i1) true value if the |
| 110 | // condition is true. These nodes are instances of the |
| 111 | // SetCCSDNode class, which contains the condition code as extra |
| 112 | // state. |
| 113 | SETCC, |
| 114 | |
Chris Lattner | 5880b9f | 2005-01-20 18:50:39 +0000 | [diff] [blame] | 115 | // ADD_PARTS/SUB_PARTS - These operators take two logical operands which are |
| 116 | // broken into a multiple pieces each, and return the resulting pieces of |
| 117 | // doing an atomic add/sub operation. This is used to handle add/sub of |
| 118 | // expanded types. The operation ordering is: |
| 119 | // [Lo,Hi] = op [LoLHS,HiLHS], [LoRHS,HiRHS] |
| 120 | ADD_PARTS, SUB_PARTS, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 121 | |
Chris Lattner | 14c5b53 | 2005-04-02 03:30:33 +0000 | [diff] [blame] | 122 | // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded |
| 123 | // integer shift operations, just like ADD/SUB_PARTS. The operation |
| 124 | // ordering is: |
Chris Lattner | 6b8f2d6 | 2005-04-02 03:59:45 +0000 | [diff] [blame] | 125 | // [Lo,Hi] = op [LoLHS,HiLHS], Amt |
Chris Lattner | 14c5b53 | 2005-04-02 03:30:33 +0000 | [diff] [blame] | 126 | SHL_PARTS, SRA_PARTS, SRL_PARTS, |
| 127 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 128 | // Conversion operators. These are all single input single output |
| 129 | // operations. For all of these, the result type must be strictly |
| 130 | // wider or narrower (depending on the operation) than the source |
| 131 | // type. |
| 132 | |
| 133 | // SIGN_EXTEND - Used for integer types, replicating the sign bit |
| 134 | // into new bits. |
| 135 | SIGN_EXTEND, |
| 136 | |
| 137 | // ZERO_EXTEND - Used for integer types, zeroing the new bits. |
| 138 | ZERO_EXTEND, |
| 139 | |
| 140 | // TRUNCATE - Completely drop the high bits. |
| 141 | TRUNCATE, |
| 142 | |
Chris Lattner | 1645ed0 | 2005-01-08 08:08:49 +0000 | [diff] [blame] | 143 | // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign |
| 144 | // depends on the first letter) to floating point. |
| 145 | SINT_TO_FP, |
| 146 | UINT_TO_FP, |
| 147 | |
Chris Lattner | ea57610 | 2005-04-13 02:36:41 +0000 | [diff] [blame] | 148 | // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to |
| 149 | // sign extend a small value in a large integer register (e.g. sign |
| 150 | // extending the low 8 bits of a 32-bit register to fill the top 24 bits |
| 151 | // with the 7th bit). The size of the smaller type is indicated by the |
| 152 | // ExtraValueType in the MVTSDNode for the operator. |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 153 | SIGN_EXTEND_INREG, |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 154 | |
Chris Lattner | 1645ed0 | 2005-01-08 08:08:49 +0000 | [diff] [blame] | 155 | // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned |
| 156 | // integer. |
| 157 | FP_TO_SINT, |
| 158 | FP_TO_UINT, |
| 159 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 160 | // FP_ROUND - Perform a rounding operation from the current |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 161 | // precision down to the specified precision (currently always 64->32). |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 162 | FP_ROUND, |
| 163 | |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 164 | // FP_ROUND_INREG - This operator takes a floating point register, and |
| 165 | // rounds it to a floating point value. It then promotes it and returns it |
| 166 | // in a register of the same size. This operation effectively just discards |
| 167 | // excess precision. The type to round down to is specified by the |
| 168 | // ExtraValueType in the MVTSDNode (currently always 64->32->64). |
| 169 | FP_ROUND_INREG, |
| 170 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 171 | // FP_EXTEND - Extend a smaller FP type into a larger FP type. |
| 172 | FP_EXTEND, |
| 173 | |
Chris Lattner | 7f64464 | 2005-04-28 21:44:03 +0000 | [diff] [blame] | 174 | // FNEG, FABS, FSQRT, FSIN, FCOS - Perform unary floating point negation, |
| 175 | // absolute value, square root, sine and cosine operations. |
| 176 | FNEG, FABS, FSQRT, FSIN, FCOS, |
Chris Lattner | 7366fd3 | 2005-04-02 04:58:28 +0000 | [diff] [blame] | 177 | |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 178 | // Other operators. LOAD and STORE have token chains as their first |
| 179 | // operand, then the same operands as an LLVM load/store instruction. |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 180 | LOAD, STORE, |
| 181 | |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 182 | // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators are instances of the |
| 183 | // MVTSDNode. All of these load a value from memory and extend them to a |
| 184 | // larger value (e.g. load a byte into a word register). All three of these |
| 185 | // have two operands, a chain and a pointer to load from. The extra value |
| 186 | // type is the source type being loaded. |
| 187 | // |
| 188 | // SEXTLOAD loads the integer operand and sign extends it to a larger |
| 189 | // integer result type. |
| 190 | // ZEXTLOAD loads the integer operand and zero extends it to a larger |
| 191 | // integer result type. |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 192 | // EXTLOAD is used for two things: floating point extending loads, and |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 193 | // integer extending loads where it doesn't matter what the high |
| 194 | // bits are set to. The code generator is allowed to codegen this |
| 195 | // into whichever operation is more efficient. |
| 196 | EXTLOAD, SEXTLOAD, ZEXTLOAD, |
| 197 | |
| 198 | // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a |
| 199 | // value and stores it to memory in one operation. This can be used for |
| 200 | // either integer or floating point operands, and the stored type |
| 201 | // represented as the 'extra' value type in the MVTSDNode representing the |
| 202 | // operator. This node has the same three operands as a standard store. |
| 203 | TRUNCSTORE, |
| 204 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 205 | // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned |
| 206 | // to a specified boundary. The first operand is the token chain, the |
| 207 | // second is the number of bytes to allocate, and the third is the alignment |
| 208 | // boundary. |
| 209 | DYNAMIC_STACKALLOC, |
| 210 | |
| 211 | // Control flow instructions. These all have token chains. |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 212 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 213 | // BR - Unconditional branch. The first operand is the chain |
| 214 | // operand, the second is the MBB to branch to. |
| 215 | BR, |
| 216 | |
| 217 | // BRCOND - Conditional branch. The first operand is the chain, |
| 218 | // the second is the condition, the third is the block to branch |
| 219 | // to if the condition is true. |
| 220 | BRCOND, |
| 221 | |
Chris Lattner | 1df6338 | 2005-04-09 03:21:50 +0000 | [diff] [blame] | 222 | // BRCONDTWOWAY - Two-way conditional branch. The first operand is the |
| 223 | // chain, the second is the condition, the third is the block to branch to |
| 224 | // if true, and the forth is the block to branch to if false. Targets |
| 225 | // usually do not implement this, preferring to have legalize demote the |
| 226 | // operation to BRCOND/BR pairs when necessary. |
| 227 | BRCONDTWOWAY, |
| 228 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 229 | // RET - Return from function. The first operand is the chain, |
| 230 | // and any subsequent operands are the return values for the |
| 231 | // function. This operation can have variable number of operands. |
| 232 | RET, |
| 233 | |
| 234 | // CALL - Call to a function pointer. The first operand is the chain, the |
| 235 | // second is the destination function pointer (a GlobalAddress for a direct |
| 236 | // call). Arguments have already been lowered to explicit DAGs according to |
Chris Lattner | 4c1eae9 | 2005-05-13 18:40:17 +0000 | [diff] [blame^] | 237 | // the calling convention in effect here. TAILCALL is the same as CALL, but |
| 238 | // the callee is known not to access the stack of the caller. |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 239 | CALL, |
Chris Lattner | 4c1eae9 | 2005-05-13 18:40:17 +0000 | [diff] [blame^] | 240 | TAILCALL, |
Chris Lattner | ef36aa7 | 2005-01-11 05:56:17 +0000 | [diff] [blame] | 241 | |
| 242 | // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest |
| 243 | // correspond to the operands of the LLVM intrinsic functions. The only |
| 244 | // result is a token chain. The alignment argument is guaranteed to be a |
| 245 | // Constant node. |
| 246 | MEMSET, |
| 247 | MEMMOVE, |
| 248 | MEMCPY, |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 249 | |
Chris Lattner | 16cd04d | 2005-05-12 23:24:06 +0000 | [diff] [blame] | 250 | // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of |
| 251 | // a call sequence, and carry arbitrary information that target might want |
| 252 | // to know. The first operand is a chain, the rest are specified by the |
| 253 | // target and not touched by the DAG optimizers. |
| 254 | CALLSEQ_START, // Beginning of a call sequence |
| 255 | CALLSEQ_END, // End of a call sequence |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 256 | |
Chris Lattner | 21074f4 | 2005-05-09 20:21:27 +0000 | [diff] [blame] | 257 | // SRCVALUE - This corresponds to a Value*, and is used to associate memory |
| 258 | // locations with their value. This allows one use alias analysis |
| 259 | // information in the backend. |
| 260 | SRCVALUE, |
| 261 | |
Misha Brukman | e3f570c | 2005-03-31 21:30:35 +0000 | [diff] [blame] | 262 | // PCMARKER - This corresponds to the pcmarker intrinsic. |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 263 | PCMARKER, |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 264 | |
Chris Lattner | 21074f4 | 2005-05-09 20:21:27 +0000 | [diff] [blame] | 265 | // READPORT, WRITEPORT, READIO, WRITEIO - These correspond to the LLVM |
| 266 | // intrinsics of the same name. The first operand is a token chain, the |
| 267 | // other operands match the intrinsic. These produce a token chain in |
| 268 | // addition to a value (if any). |
| 269 | READPORT, WRITEPORT, READIO, WRITEIO, |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 270 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 271 | // BUILTIN_OP_END - This must be the last enum value in this list. |
| 272 | BUILTIN_OP_END, |
| 273 | }; |
| 274 | |
| 275 | //===--------------------------------------------------------------------===// |
| 276 | /// ISD::CondCode enum - These are ordered carefully to make the bitfields |
| 277 | /// below work out, when considering SETFALSE (something that never exists |
| 278 | /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered |
| 279 | /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal |
| 280 | /// to. If the "N" column is 1, the result of the comparison is undefined if |
| 281 | /// the input is a NAN. |
| 282 | /// |
| 283 | /// All of these (except for the 'always folded ops') should be handled for |
| 284 | /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT, |
| 285 | /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used. |
| 286 | /// |
| 287 | /// Note that these are laid out in a specific order to allow bit-twiddling |
| 288 | /// to transform conditions. |
| 289 | enum CondCode { |
| 290 | // Opcode N U L G E Intuitive operation |
| 291 | SETFALSE, // 0 0 0 0 Always false (always folded) |
| 292 | SETOEQ, // 0 0 0 1 True if ordered and equal |
| 293 | SETOGT, // 0 0 1 0 True if ordered and greater than |
| 294 | SETOGE, // 0 0 1 1 True if ordered and greater than or equal |
| 295 | SETOLT, // 0 1 0 0 True if ordered and less than |
| 296 | SETOLE, // 0 1 0 1 True if ordered and less than or equal |
| 297 | SETONE, // 0 1 1 0 True if ordered and operands are unequal |
| 298 | SETO, // 0 1 1 1 True if ordered (no nans) |
| 299 | SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y) |
| 300 | SETUEQ, // 1 0 0 1 True if unordered or equal |
| 301 | SETUGT, // 1 0 1 0 True if unordered or greater than |
| 302 | SETUGE, // 1 0 1 1 True if unordered, greater than, or equal |
| 303 | SETULT, // 1 1 0 0 True if unordered or less than |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 304 | SETULE, // 1 1 0 1 True if unordered, less than, or equal |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 305 | SETUNE, // 1 1 1 0 True if unordered or not equal |
| 306 | SETTRUE, // 1 1 1 1 Always true (always folded) |
| 307 | // Don't care operations: undefined if the input is a nan. |
| 308 | SETFALSE2, // 1 X 0 0 0 Always false (always folded) |
| 309 | SETEQ, // 1 X 0 0 1 True if equal |
| 310 | SETGT, // 1 X 0 1 0 True if greater than |
| 311 | SETGE, // 1 X 0 1 1 True if greater than or equal |
| 312 | SETLT, // 1 X 1 0 0 True if less than |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 313 | SETLE, // 1 X 1 0 1 True if less than or equal |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 314 | SETNE, // 1 X 1 1 0 True if not equal |
| 315 | SETTRUE2, // 1 X 1 1 1 Always true (always folded) |
| 316 | |
| 317 | SETCC_INVALID, // Marker value. |
| 318 | }; |
| 319 | |
| 320 | /// isSignedIntSetCC - Return true if this is a setcc instruction that |
| 321 | /// performs a signed comparison when used with integer operands. |
| 322 | inline bool isSignedIntSetCC(CondCode Code) { |
| 323 | return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE; |
| 324 | } |
| 325 | |
| 326 | /// isUnsignedIntSetCC - Return true if this is a setcc instruction that |
| 327 | /// performs an unsigned comparison when used with integer operands. |
| 328 | inline bool isUnsignedIntSetCC(CondCode Code) { |
| 329 | return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE; |
| 330 | } |
| 331 | |
| 332 | /// isTrueWhenEqual - Return true if the specified condition returns true if |
| 333 | /// the two operands to the condition are equal. Note that if one of the two |
| 334 | /// operands is a NaN, this value is meaningless. |
| 335 | inline bool isTrueWhenEqual(CondCode Cond) { |
| 336 | return ((int)Cond & 1) != 0; |
| 337 | } |
| 338 | |
| 339 | /// getUnorderedFlavor - This function returns 0 if the condition is always |
| 340 | /// false if an operand is a NaN, 1 if the condition is always true if the |
| 341 | /// operand is a NaN, and 2 if the condition is undefined if the operand is a |
| 342 | /// NaN. |
| 343 | inline unsigned getUnorderedFlavor(CondCode Cond) { |
| 344 | return ((int)Cond >> 3) & 3; |
| 345 | } |
| 346 | |
| 347 | /// getSetCCInverse - Return the operation corresponding to !(X op Y), where |
| 348 | /// 'op' is a valid SetCC operation. |
| 349 | CondCode getSetCCInverse(CondCode Operation, bool isInteger); |
| 350 | |
| 351 | /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X) |
| 352 | /// when given the operation for (X op Y). |
| 353 | CondCode getSetCCSwappedOperands(CondCode Operation); |
| 354 | |
| 355 | /// getSetCCOrOperation - Return the result of a logical OR between different |
| 356 | /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This |
| 357 | /// function returns SETCC_INVALID if it is not possible to represent the |
| 358 | /// resultant comparison. |
| 359 | CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger); |
| 360 | |
| 361 | /// getSetCCAndOperation - Return the result of a logical AND between |
| 362 | /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This |
| 363 | /// function returns SETCC_INVALID if it is not possible to represent the |
| 364 | /// resultant comparison. |
| 365 | CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger); |
| 366 | } // end llvm::ISD namespace |
| 367 | |
| 368 | |
| 369 | //===----------------------------------------------------------------------===// |
| 370 | /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple |
| 371 | /// values as the result of a computation. Many nodes return multiple values, |
| 372 | /// from loads (which define a token and a return value) to ADDC (which returns |
| 373 | /// a result and a carry value), to calls (which may return an arbitrary number |
| 374 | /// of values). |
| 375 | /// |
| 376 | /// As such, each use of a SelectionDAG computation must indicate the node that |
| 377 | /// computes it as well as which return value to use from that node. This pair |
| 378 | /// of information is represented with the SDOperand value type. |
| 379 | /// |
Chris Lattner | f26bc8e | 2005-01-08 19:52:31 +0000 | [diff] [blame] | 380 | class SDOperand { |
| 381 | public: |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 382 | SDNode *Val; // The node defining the value we are using. |
| 383 | unsigned ResNo; // Which return value of the node we are using. |
| 384 | |
| 385 | SDOperand() : Val(0) {} |
| 386 | SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {} |
| 387 | |
| 388 | bool operator==(const SDOperand &O) const { |
| 389 | return Val == O.Val && ResNo == O.ResNo; |
| 390 | } |
| 391 | bool operator!=(const SDOperand &O) const { |
| 392 | return !operator==(O); |
| 393 | } |
| 394 | bool operator<(const SDOperand &O) const { |
| 395 | return Val < O.Val || (Val == O.Val && ResNo < O.ResNo); |
| 396 | } |
| 397 | |
| 398 | SDOperand getValue(unsigned R) const { |
| 399 | return SDOperand(Val, R); |
| 400 | } |
| 401 | |
| 402 | /// getValueType - Return the ValueType of the referenced return value. |
| 403 | /// |
| 404 | inline MVT::ValueType getValueType() const; |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 405 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 406 | // Forwarding methods - These forward to the corresponding methods in SDNode. |
| 407 | inline unsigned getOpcode() const; |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 408 | inline unsigned getNodeDepth() const; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 409 | inline unsigned getNumOperands() const; |
| 410 | inline const SDOperand &getOperand(unsigned i) const; |
Chris Lattner | a44f4ae | 2005-01-13 22:58:50 +0000 | [diff] [blame] | 411 | |
| 412 | /// hasOneUse - Return true if there is exactly one operation using this |
| 413 | /// result value of the defining operator. |
| 414 | inline bool hasOneUse() const; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 415 | }; |
| 416 | |
| 417 | |
| 418 | /// simplify_type specializations - Allow casting operators to work directly on |
| 419 | /// SDOperands as if they were SDNode*'s. |
| 420 | template<> struct simplify_type<SDOperand> { |
| 421 | typedef SDNode* SimpleType; |
| 422 | static SimpleType getSimplifiedValue(const SDOperand &Val) { |
| 423 | return static_cast<SimpleType>(Val.Val); |
| 424 | } |
| 425 | }; |
| 426 | template<> struct simplify_type<const SDOperand> { |
| 427 | typedef SDNode* SimpleType; |
| 428 | static SimpleType getSimplifiedValue(const SDOperand &Val) { |
| 429 | return static_cast<SimpleType>(Val.Val); |
| 430 | } |
| 431 | }; |
| 432 | |
| 433 | |
| 434 | /// SDNode - Represents one node in the SelectionDAG. |
| 435 | /// |
| 436 | class SDNode { |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 437 | /// NodeType - The operation that this node performs. |
| 438 | /// |
| 439 | unsigned short NodeType; |
| 440 | |
| 441 | /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1. This |
| 442 | /// means that leaves have a depth of 1, things that use only leaves have a |
| 443 | /// depth of 2, etc. |
| 444 | unsigned short NodeDepth; |
| 445 | |
| 446 | /// Operands - The values that are used by this operation. |
| 447 | /// |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 448 | std::vector<SDOperand> Operands; |
| 449 | |
| 450 | /// Values - The types of the values this node defines. SDNode's may define |
| 451 | /// multiple values simultaneously. |
| 452 | std::vector<MVT::ValueType> Values; |
| 453 | |
| 454 | /// Uses - These are all of the SDNode's that use a value produced by this |
| 455 | /// node. |
| 456 | std::vector<SDNode*> Uses; |
| 457 | public: |
| 458 | |
| 459 | //===--------------------------------------------------------------------===// |
| 460 | // Accessors |
| 461 | // |
| 462 | unsigned getOpcode() const { return NodeType; } |
| 463 | |
| 464 | size_t use_size() const { return Uses.size(); } |
| 465 | bool use_empty() const { return Uses.empty(); } |
| 466 | bool hasOneUse() const { return Uses.size() == 1; } |
| 467 | |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 468 | /// getNodeDepth - Return the distance from this node to the leaves in the |
| 469 | /// graph. The leaves have a depth of 1. |
| 470 | unsigned getNodeDepth() const { return NodeDepth; } |
| 471 | |
Chris Lattner | 7ece380 | 2005-01-17 02:24:59 +0000 | [diff] [blame] | 472 | typedef std::vector<SDNode*>::const_iterator use_iterator; |
| 473 | use_iterator use_begin() const { return Uses.begin(); } |
| 474 | use_iterator use_end() const { return Uses.end(); } |
| 475 | |
Chris Lattner | b18a2f8 | 2005-01-12 18:37:33 +0000 | [diff] [blame] | 476 | /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the |
| 477 | /// indicated value. This method ignores uses of other values defined by this |
| 478 | /// operation. |
| 479 | bool hasNUsesOfValue(unsigned NUses, unsigned Value); |
| 480 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 481 | /// getNumOperands - Return the number of values used by this operation. |
| 482 | /// |
| 483 | unsigned getNumOperands() const { return Operands.size(); } |
| 484 | |
| 485 | const SDOperand &getOperand(unsigned Num) { |
| 486 | assert(Num < Operands.size() && "Invalid child # of SDNode!"); |
| 487 | return Operands[Num]; |
| 488 | } |
| 489 | |
| 490 | const SDOperand &getOperand(unsigned Num) const { |
| 491 | assert(Num < Operands.size() && "Invalid child # of SDNode!"); |
| 492 | return Operands[Num]; |
| 493 | } |
| 494 | |
| 495 | /// getNumValues - Return the number of values defined/returned by this |
| 496 | /// operator. |
| 497 | /// |
| 498 | unsigned getNumValues() const { return Values.size(); } |
| 499 | |
| 500 | /// getValueType - Return the type of a specified result. |
| 501 | /// |
| 502 | MVT::ValueType getValueType(unsigned ResNo) const { |
| 503 | assert(ResNo < Values.size() && "Illegal result number!"); |
| 504 | return Values[ResNo]; |
| 505 | } |
| 506 | |
Chris Lattner | 6e6e3ce | 2005-01-10 23:25:04 +0000 | [diff] [blame] | 507 | /// getOperationName - Return the opcode of this operation for printing. |
| 508 | /// |
| 509 | const char* getOperationName() const; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 510 | void dump() const; |
| 511 | |
| 512 | static bool classof(const SDNode *) { return true; } |
| 513 | |
Chris Lattner | 73b3537 | 2005-05-11 18:56:45 +0000 | [diff] [blame] | 514 | |
| 515 | /// setAdjCallChain - This method should only be used by the legalizer. |
| 516 | void setAdjCallChain(SDOperand N); |
| 517 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 518 | protected: |
| 519 | friend class SelectionDAG; |
| 520 | |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 521 | SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 522 | Values.reserve(1); |
| 523 | Values.push_back(VT); |
| 524 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 525 | SDNode(unsigned NT, SDOperand Op) |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 526 | : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 527 | Operands.reserve(1); Operands.push_back(Op); |
| 528 | Op.Val->Uses.push_back(this); |
| 529 | } |
| 530 | SDNode(unsigned NT, SDOperand N1, SDOperand N2) |
| 531 | : NodeType(NT) { |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 532 | if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth()) |
| 533 | NodeDepth = N1.Val->getNodeDepth()+1; |
| 534 | else |
| 535 | NodeDepth = N2.Val->getNodeDepth()+1; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 536 | Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2); |
| 537 | N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); |
| 538 | } |
| 539 | SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3) |
| 540 | : NodeType(NT) { |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 541 | unsigned ND = N1.Val->getNodeDepth(); |
| 542 | if (ND < N2.Val->getNodeDepth()) |
| 543 | ND = N2.Val->getNodeDepth(); |
| 544 | if (ND < N3.Val->getNodeDepth()) |
| 545 | ND = N3.Val->getNodeDepth(); |
| 546 | NodeDepth = ND+1; |
| 547 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 548 | Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2); |
| 549 | Operands.push_back(N3); |
| 550 | N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); |
| 551 | N3.Val->Uses.push_back(this); |
| 552 | } |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 553 | SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4) |
| 554 | : NodeType(NT) { |
| 555 | unsigned ND = N1.Val->getNodeDepth(); |
| 556 | if (ND < N2.Val->getNodeDepth()) |
| 557 | ND = N2.Val->getNodeDepth(); |
| 558 | if (ND < N3.Val->getNodeDepth()) |
| 559 | ND = N3.Val->getNodeDepth(); |
| 560 | if (ND < N4.Val->getNodeDepth()) |
| 561 | ND = N4.Val->getNodeDepth(); |
| 562 | NodeDepth = ND+1; |
| 563 | |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 564 | Operands.reserve(4); Operands.push_back(N1); Operands.push_back(N2); |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 565 | Operands.push_back(N3); Operands.push_back(N4); |
| 566 | N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); |
| 567 | N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this); |
| 568 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 569 | SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) { |
| 570 | Operands.swap(Nodes); |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 571 | unsigned ND = 0; |
| 572 | for (unsigned i = 0, e = Operands.size(); i != e; ++i) { |
Chris Lattner | ef36aa7 | 2005-01-11 05:56:17 +0000 | [diff] [blame] | 573 | Operands[i].Val->Uses.push_back(this); |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 574 | if (ND < Operands[i].Val->getNodeDepth()) |
| 575 | ND = Operands[i].Val->getNodeDepth(); |
| 576 | } |
| 577 | NodeDepth = ND+1; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | virtual ~SDNode() { |
| 581 | // FIXME: Drop uses. |
| 582 | } |
| 583 | |
| 584 | void setValueTypes(MVT::ValueType VT) { |
| 585 | Values.reserve(1); |
| 586 | Values.push_back(VT); |
| 587 | } |
| 588 | void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) { |
| 589 | Values.reserve(2); |
| 590 | Values.push_back(VT1); |
| 591 | Values.push_back(VT2); |
| 592 | } |
| 593 | /// Note: this method destroys the vector passed in. |
| 594 | void setValueTypes(std::vector<MVT::ValueType> &VTs) { |
| 595 | std::swap(Values, VTs); |
| 596 | } |
Chris Lattner | d1fc964 | 2005-01-07 21:08:55 +0000 | [diff] [blame] | 597 | |
| 598 | void removeUser(SDNode *User) { |
| 599 | // Remove this user from the operand's use list. |
| 600 | for (unsigned i = Uses.size(); ; --i) { |
| 601 | assert(i != 0 && "Didn't find user!"); |
| 602 | if (Uses[i-1] == User) { |
| 603 | Uses.erase(Uses.begin()+i-1); |
| 604 | break; |
| 605 | } |
| 606 | } |
| 607 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 608 | }; |
| 609 | |
| 610 | |
| 611 | // Define inline functions from the SDOperand class. |
| 612 | |
| 613 | inline unsigned SDOperand::getOpcode() const { |
| 614 | return Val->getOpcode(); |
| 615 | } |
Chris Lattner | 0442fbf | 2005-01-21 21:39:38 +0000 | [diff] [blame] | 616 | inline unsigned SDOperand::getNodeDepth() const { |
| 617 | return Val->getNodeDepth(); |
| 618 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 619 | inline MVT::ValueType SDOperand::getValueType() const { |
| 620 | return Val->getValueType(ResNo); |
| 621 | } |
| 622 | inline unsigned SDOperand::getNumOperands() const { |
| 623 | return Val->getNumOperands(); |
| 624 | } |
| 625 | inline const SDOperand &SDOperand::getOperand(unsigned i) const { |
| 626 | return Val->getOperand(i); |
| 627 | } |
Chris Lattner | a44f4ae | 2005-01-13 22:58:50 +0000 | [diff] [blame] | 628 | inline bool SDOperand::hasOneUse() const { |
| 629 | return Val->hasNUsesOfValue(1, ResNo); |
| 630 | } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 631 | |
| 632 | |
| 633 | class ConstantSDNode : public SDNode { |
| 634 | uint64_t Value; |
| 635 | protected: |
| 636 | friend class SelectionDAG; |
| 637 | ConstantSDNode(uint64_t val, MVT::ValueType VT) |
| 638 | : SDNode(ISD::Constant, VT), Value(val) { |
| 639 | } |
| 640 | public: |
| 641 | |
| 642 | uint64_t getValue() const { return Value; } |
| 643 | |
| 644 | int64_t getSignExtended() const { |
| 645 | unsigned Bits = MVT::getSizeInBits(getValueType(0)); |
Chris Lattner | f26bc8e | 2005-01-08 19:52:31 +0000 | [diff] [blame] | 646 | return ((int64_t)Value << (64-Bits)) >> (64-Bits); |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 647 | } |
| 648 | |
| 649 | bool isNullValue() const { return Value == 0; } |
| 650 | bool isAllOnesValue() const { |
Chris Lattner | 2bffad3 | 2005-04-08 21:31:29 +0000 | [diff] [blame] | 651 | int NumBits = MVT::getSizeInBits(getValueType(0)); |
| 652 | if (NumBits == 64) return Value+1 == 0; |
| 653 | return Value == (1ULL << NumBits)-1; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 654 | } |
| 655 | |
| 656 | static bool classof(const ConstantSDNode *) { return true; } |
| 657 | static bool classof(const SDNode *N) { |
| 658 | return N->getOpcode() == ISD::Constant; |
| 659 | } |
| 660 | }; |
| 661 | |
| 662 | class ConstantFPSDNode : public SDNode { |
| 663 | double Value; |
| 664 | protected: |
| 665 | friend class SelectionDAG; |
| 666 | ConstantFPSDNode(double val, MVT::ValueType VT) |
| 667 | : SDNode(ISD::ConstantFP, VT), Value(val) { |
| 668 | } |
| 669 | public: |
| 670 | |
| 671 | double getValue() const { return Value; } |
| 672 | |
| 673 | /// isExactlyValue - We don't rely on operator== working on double values, as |
| 674 | /// it returns true for things that are clearly not equal, like -0.0 and 0.0. |
| 675 | /// As such, this method can be used to do an exact bit-for-bit comparison of |
| 676 | /// two floating point values. |
| 677 | bool isExactlyValue(double V) const { |
| 678 | union { |
| 679 | double V; |
| 680 | uint64_t I; |
| 681 | } T1; |
| 682 | T1.V = Value; |
| 683 | union { |
| 684 | double V; |
| 685 | uint64_t I; |
| 686 | } T2; |
| 687 | T2.V = V; |
| 688 | return T1.I == T2.I; |
| 689 | } |
| 690 | |
| 691 | static bool classof(const ConstantFPSDNode *) { return true; } |
| 692 | static bool classof(const SDNode *N) { |
| 693 | return N->getOpcode() == ISD::ConstantFP; |
| 694 | } |
| 695 | }; |
| 696 | |
| 697 | class GlobalAddressSDNode : public SDNode { |
| 698 | GlobalValue *TheGlobal; |
| 699 | protected: |
| 700 | friend class SelectionDAG; |
| 701 | GlobalAddressSDNode(const GlobalValue *GA, MVT::ValueType VT) |
| 702 | : SDNode(ISD::GlobalAddress, VT) { |
| 703 | TheGlobal = const_cast<GlobalValue*>(GA); |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 704 | } |
| 705 | public: |
| 706 | |
| 707 | GlobalValue *getGlobal() const { return TheGlobal; } |
| 708 | |
| 709 | static bool classof(const GlobalAddressSDNode *) { return true; } |
| 710 | static bool classof(const SDNode *N) { |
| 711 | return N->getOpcode() == ISD::GlobalAddress; |
| 712 | } |
| 713 | }; |
| 714 | |
| 715 | |
| 716 | class FrameIndexSDNode : public SDNode { |
| 717 | int FI; |
| 718 | protected: |
| 719 | friend class SelectionDAG; |
| 720 | FrameIndexSDNode(int fi, MVT::ValueType VT) |
| 721 | : SDNode(ISD::FrameIndex, VT), FI(fi) {} |
| 722 | public: |
| 723 | |
| 724 | int getIndex() const { return FI; } |
| 725 | |
| 726 | static bool classof(const FrameIndexSDNode *) { return true; } |
| 727 | static bool classof(const SDNode *N) { |
| 728 | return N->getOpcode() == ISD::FrameIndex; |
| 729 | } |
| 730 | }; |
| 731 | |
| 732 | class ConstantPoolSDNode : public SDNode { |
| 733 | unsigned CPI; |
| 734 | protected: |
| 735 | friend class SelectionDAG; |
| 736 | ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT) |
| 737 | : SDNode(ISD::ConstantPool, VT), CPI(cpi) {} |
| 738 | public: |
| 739 | |
| 740 | unsigned getIndex() const { return CPI; } |
| 741 | |
| 742 | static bool classof(const ConstantPoolSDNode *) { return true; } |
| 743 | static bool classof(const SDNode *N) { |
| 744 | return N->getOpcode() == ISD::ConstantPool; |
| 745 | } |
| 746 | }; |
| 747 | |
| 748 | class BasicBlockSDNode : public SDNode { |
| 749 | MachineBasicBlock *MBB; |
| 750 | protected: |
| 751 | friend class SelectionDAG; |
| 752 | BasicBlockSDNode(MachineBasicBlock *mbb) |
| 753 | : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {} |
| 754 | public: |
| 755 | |
| 756 | MachineBasicBlock *getBasicBlock() const { return MBB; } |
| 757 | |
| 758 | static bool classof(const BasicBlockSDNode *) { return true; } |
| 759 | static bool classof(const SDNode *N) { |
| 760 | return N->getOpcode() == ISD::BasicBlock; |
| 761 | } |
| 762 | }; |
| 763 | |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 764 | class SrcValueSDNode : public SDNode { |
| 765 | const Value *V; |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 766 | int offset; |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 767 | protected: |
| 768 | friend class SelectionDAG; |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 769 | SrcValueSDNode(const Value* v, int o) |
| 770 | : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {} |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 771 | |
| 772 | public: |
| 773 | const Value *getValue() const { return V; } |
Andrew Lenharth | 691ef2b | 2005-05-03 17:19:30 +0000 | [diff] [blame] | 774 | int getOffset() const { return offset; } |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 775 | |
| 776 | static bool classof(const SrcValueSDNode *) { return true; } |
| 777 | static bool classof(const SDNode *N) { |
| 778 | return N->getOpcode() == ISD::SRCVALUE; |
| 779 | } |
| 780 | }; |
| 781 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 782 | |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 783 | class RegSDNode : public SDNode { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 784 | unsigned Reg; |
| 785 | protected: |
| 786 | friend class SelectionDAG; |
Chris Lattner | 60e4878 | 2005-01-14 22:37:20 +0000 | [diff] [blame] | 787 | RegSDNode(unsigned Opc, SDOperand Chain, SDOperand Src, unsigned reg) |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 788 | : SDNode(Opc, Chain, Src), Reg(reg) { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 789 | } |
Chris Lattner | 60e4878 | 2005-01-14 22:37:20 +0000 | [diff] [blame] | 790 | RegSDNode(unsigned Opc, SDOperand Chain, unsigned reg) |
| 791 | : SDNode(Opc, Chain), Reg(reg) {} |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 792 | public: |
| 793 | |
| 794 | unsigned getReg() const { return Reg; } |
| 795 | |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 796 | static bool classof(const RegSDNode *) { return true; } |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 797 | static bool classof(const SDNode *N) { |
| 798 | return N->getOpcode() == ISD::CopyToReg || |
Chris Lattner | 18c2f13 | 2005-01-13 20:50:02 +0000 | [diff] [blame] | 799 | N->getOpcode() == ISD::CopyFromReg || |
| 800 | N->getOpcode() == ISD::ImplicitDef; |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 801 | } |
| 802 | }; |
| 803 | |
| 804 | class ExternalSymbolSDNode : public SDNode { |
| 805 | const char *Symbol; |
| 806 | protected: |
| 807 | friend class SelectionDAG; |
| 808 | ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT) |
| 809 | : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) { |
| 810 | } |
| 811 | public: |
| 812 | |
| 813 | const char *getSymbol() const { return Symbol; } |
| 814 | |
| 815 | static bool classof(const ExternalSymbolSDNode *) { return true; } |
| 816 | static bool classof(const SDNode *N) { |
| 817 | return N->getOpcode() == ISD::ExternalSymbol; |
| 818 | } |
| 819 | }; |
| 820 | |
| 821 | class SetCCSDNode : public SDNode { |
| 822 | ISD::CondCode Condition; |
| 823 | protected: |
| 824 | friend class SelectionDAG; |
| 825 | SetCCSDNode(ISD::CondCode Cond, SDOperand LHS, SDOperand RHS) |
| 826 | : SDNode(ISD::SETCC, LHS, RHS), Condition(Cond) { |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 827 | } |
| 828 | public: |
| 829 | |
| 830 | ISD::CondCode getCondition() const { return Condition; } |
| 831 | |
| 832 | static bool classof(const SetCCSDNode *) { return true; } |
| 833 | static bool classof(const SDNode *N) { |
| 834 | return N->getOpcode() == ISD::SETCC; |
| 835 | } |
| 836 | }; |
| 837 | |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 838 | /// MVTSDNode - This class is used for operators that require an extra |
| 839 | /// value-type to be kept with the node. |
| 840 | class MVTSDNode : public SDNode { |
| 841 | MVT::ValueType ExtraValueType; |
| 842 | protected: |
| 843 | friend class SelectionDAG; |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 844 | MVTSDNode(unsigned Opc, MVT::ValueType VT1, SDOperand Op0, MVT::ValueType EVT) |
| 845 | : SDNode(Opc, Op0), ExtraValueType(EVT) { |
| 846 | setValueTypes(VT1); |
| 847 | } |
Chris Lattner | 60e4878 | 2005-01-14 22:37:20 +0000 | [diff] [blame] | 848 | MVTSDNode(unsigned Opc, MVT::ValueType VT1, MVT::ValueType VT2, |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 849 | SDOperand Op0, SDOperand Op1, SDOperand Op2, MVT::ValueType EVT) |
| 850 | : SDNode(Opc, Op0, Op1, Op2), ExtraValueType(EVT) { |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 851 | setValueTypes(VT1, VT2); |
| 852 | } |
| 853 | |
| 854 | MVTSDNode(unsigned Opc, MVT::ValueType VT, |
| 855 | SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3, MVT::ValueType EVT) |
| 856 | : SDNode(Opc, Op0, Op1, Op2, Op3), ExtraValueType(EVT) { |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 857 | setValueTypes(VT); |
| 858 | } |
| 859 | public: |
| 860 | |
| 861 | MVT::ValueType getExtraValueType() const { return ExtraValueType; } |
| 862 | |
| 863 | static bool classof(const MVTSDNode *) { return true; } |
| 864 | static bool classof(const SDNode *N) { |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 865 | return |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 866 | N->getOpcode() == ISD::SIGN_EXTEND_INREG || |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 867 | N->getOpcode() == ISD::FP_ROUND_INREG || |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 868 | N->getOpcode() == ISD::EXTLOAD || |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 869 | N->getOpcode() == ISD::SEXTLOAD || |
Chris Lattner | 1cff05c | 2005-01-14 22:07:46 +0000 | [diff] [blame] | 870 | N->getOpcode() == ISD::ZEXTLOAD || |
| 871 | N->getOpcode() == ISD::TRUNCSTORE; |
| 872 | } |
| 873 | }; |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 874 | |
| 875 | class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> { |
| 876 | SDNode *Node; |
| 877 | unsigned Operand; |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 878 | |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 879 | SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {} |
| 880 | public: |
| 881 | bool operator==(const SDNodeIterator& x) const { |
| 882 | return Operand == x.Operand; |
| 883 | } |
| 884 | bool operator!=(const SDNodeIterator& x) const { return !operator==(x); } |
| 885 | |
| 886 | const SDNodeIterator &operator=(const SDNodeIterator &I) { |
| 887 | assert(I.Node == Node && "Cannot assign iterators to two different nodes!"); |
| 888 | Operand = I.Operand; |
| 889 | return *this; |
| 890 | } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 891 | |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 892 | pointer operator*() const { |
| 893 | return Node->getOperand(Operand).Val; |
| 894 | } |
| 895 | pointer operator->() const { return operator*(); } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 896 | |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 897 | SDNodeIterator& operator++() { // Preincrement |
| 898 | ++Operand; |
| 899 | return *this; |
| 900 | } |
| 901 | SDNodeIterator operator++(int) { // Postincrement |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 902 | SDNodeIterator tmp = *this; ++*this; return tmp; |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 903 | } |
| 904 | |
| 905 | static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); } |
| 906 | static SDNodeIterator end (SDNode *N) { |
| 907 | return SDNodeIterator(N, N->getNumOperands()); |
| 908 | } |
| 909 | |
| 910 | unsigned getOperand() const { return Operand; } |
| 911 | const SDNode *getNode() const { return Node; } |
| 912 | }; |
| 913 | |
| 914 | template <> struct GraphTraits<SDNode*> { |
| 915 | typedef SDNode NodeType; |
| 916 | typedef SDNodeIterator ChildIteratorType; |
| 917 | static inline NodeType *getEntryNode(SDNode *N) { return N; } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 918 | static inline ChildIteratorType child_begin(NodeType *N) { |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 919 | return SDNodeIterator::begin(N); |
| 920 | } |
Misha Brukman | ea61c35 | 2005-04-21 20:39:54 +0000 | [diff] [blame] | 921 | static inline ChildIteratorType child_end(NodeType *N) { |
Chris Lattner | 1080b9e | 2005-01-10 23:05:53 +0000 | [diff] [blame] | 922 | return SDNodeIterator::end(N); |
| 923 | } |
| 924 | }; |
| 925 | |
| 926 | |
| 927 | |
| 928 | |
Chris Lattner | 63b570d | 2005-01-07 07:45:27 +0000 | [diff] [blame] | 929 | } // end llvm namespace |
| 930 | |
| 931 | #endif |