Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1 | //===-- SelectionDAG.cpp - Implement the SelectionDAG data structures -----===// |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +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 | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 7 | // |
John Criswell | b576c94 | 2003-10-20 19:43:21 +0000 | [diff] [blame] | 8 | //===----------------------------------------------------------------------===// |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 9 | // |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 10 | // This implements the SelectionDAG class. |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #include "llvm/CodeGen/SelectionDAG.h" |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 15 | #include "llvm/Constants.h" |
| 16 | #include "llvm/GlobalValue.h" |
Chris Lattner | 70a248d | 2006-03-27 06:45:25 +0000 | [diff] [blame] | 17 | #include "llvm/Intrinsics.h" |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 18 | #include "llvm/Assembly/Writer.h" |
| 19 | #include "llvm/CodeGen/MachineBasicBlock.h" |
Chris Lattner | 0561b3f | 2005-08-02 19:26:06 +0000 | [diff] [blame] | 20 | #include "llvm/Support/MathExtras.h" |
Chris Lattner | fa164b6 | 2005-08-19 21:34:13 +0000 | [diff] [blame] | 21 | #include "llvm/Target/MRegisterInfo.h" |
Chris Lattner | b48da39 | 2005-01-23 04:39:44 +0000 | [diff] [blame] | 22 | #include "llvm/Target/TargetLowering.h" |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 23 | #include "llvm/Target/TargetInstrInfo.h" |
| 24 | #include "llvm/Target/TargetMachine.h" |
Chris Lattner | 012f241 | 2006-02-17 21:58:01 +0000 | [diff] [blame] | 25 | #include "llvm/ADT/SetVector.h" |
Evan Cheng | 115c036 | 2005-12-19 23:11:49 +0000 | [diff] [blame] | 26 | #include "llvm/ADT/StringExtras.h" |
Reid Spencer | 954da37 | 2004-07-04 12:19:56 +0000 | [diff] [blame] | 27 | #include <iostream> |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 28 | #include <set> |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 29 | #include <cmath> |
Jeff Cohen | fd161e9 | 2005-01-09 20:41:56 +0000 | [diff] [blame] | 30 | #include <algorithm> |
Chris Lattner | e25738c | 2004-06-02 04:28:06 +0000 | [diff] [blame] | 31 | using namespace llvm; |
Brian Gaeke | d0fde30 | 2003-11-11 22:41:34 +0000 | [diff] [blame] | 32 | |
Chris Lattner | 5cdcc58 | 2005-01-09 20:52:51 +0000 | [diff] [blame] | 33 | static bool isCommutativeBinOp(unsigned Opcode) { |
| 34 | switch (Opcode) { |
| 35 | case ISD::ADD: |
| 36 | case ISD::MUL: |
Nate Begeman | 1b5db7a | 2006-01-16 08:07:10 +0000 | [diff] [blame] | 37 | case ISD::MULHU: |
| 38 | case ISD::MULHS: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 39 | case ISD::FADD: |
| 40 | case ISD::FMUL: |
Chris Lattner | 5cdcc58 | 2005-01-09 20:52:51 +0000 | [diff] [blame] | 41 | case ISD::AND: |
| 42 | case ISD::OR: |
| 43 | case ISD::XOR: return true; |
| 44 | default: return false; // FIXME: Need commutative info for user ops! |
| 45 | } |
| 46 | } |
| 47 | |
Chris Lattner | 5cdcc58 | 2005-01-09 20:52:51 +0000 | [diff] [blame] | 48 | // isInvertibleForFree - Return true if there is no cost to emitting the logical |
| 49 | // inverse of this node. |
| 50 | static bool isInvertibleForFree(SDOperand N) { |
| 51 | if (isa<ConstantSDNode>(N.Val)) return true; |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 52 | if (N.Val->getOpcode() == ISD::SETCC && N.Val->hasOneUse()) |
Chris Lattner | 5cdcc58 | 2005-01-09 20:52:51 +0000 | [diff] [blame] | 53 | return true; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 54 | return false; |
Chris Lattner | 5cdcc58 | 2005-01-09 20:52:51 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 57 | //===----------------------------------------------------------------------===// |
| 58 | // ConstantFPSDNode Class |
| 59 | //===----------------------------------------------------------------------===// |
| 60 | |
| 61 | /// isExactlyValue - We don't rely on operator== working on double values, as |
| 62 | /// it returns true for things that are clearly not equal, like -0.0 and 0.0. |
| 63 | /// As such, this method can be used to do an exact bit-for-bit comparison of |
| 64 | /// two floating point values. |
| 65 | bool ConstantFPSDNode::isExactlyValue(double V) const { |
| 66 | return DoubleToBits(V) == DoubleToBits(Value); |
| 67 | } |
| 68 | |
| 69 | //===----------------------------------------------------------------------===// |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 70 | // ISD Namespace |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 71 | //===----------------------------------------------------------------------===// |
Chris Lattner | 5cdcc58 | 2005-01-09 20:52:51 +0000 | [diff] [blame] | 72 | |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 73 | /// isBuildVectorAllOnes - Return true if the specified node is a |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 74 | /// BUILD_VECTOR where all of the elements are ~0 or undef. |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 75 | bool ISD::isBuildVectorAllOnes(const SDNode *N) { |
Chris Lattner | 547a16f | 2006-04-15 23:38:00 +0000 | [diff] [blame^] | 76 | // Look through a bit convert. |
| 77 | if (N->getOpcode() == ISD::BIT_CONVERT) |
| 78 | N = N->getOperand(0).Val; |
| 79 | |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 80 | if (N->getOpcode() != ISD::BUILD_VECTOR) return false; |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 81 | |
| 82 | unsigned i = 0, e = N->getNumOperands(); |
| 83 | |
| 84 | // Skip over all of the undef values. |
| 85 | while (i != e && N->getOperand(i).getOpcode() == ISD::UNDEF) |
| 86 | ++i; |
| 87 | |
| 88 | // Do not accept an all-undef vector. |
| 89 | if (i == e) return false; |
| 90 | |
| 91 | // Do not accept build_vectors that aren't all constants or which have non-~0 |
| 92 | // elements. |
Chris Lattner | 452e835 | 2006-03-25 22:59:28 +0000 | [diff] [blame] | 93 | SDOperand NotZero = N->getOperand(i); |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 94 | if (isa<ConstantSDNode>(NotZero)) { |
| 95 | if (!cast<ConstantSDNode>(NotZero)->isAllOnesValue()) |
| 96 | return false; |
| 97 | } else if (isa<ConstantFPSDNode>(NotZero)) { |
Evan Cheng | 23cc870 | 2006-03-27 08:10:26 +0000 | [diff] [blame] | 98 | MVT::ValueType VT = NotZero.getValueType(); |
| 99 | if (VT== MVT::f64) { |
| 100 | if (DoubleToBits(cast<ConstantFPSDNode>(NotZero)->getValue()) != |
| 101 | (uint64_t)-1) |
| 102 | return false; |
| 103 | } else { |
| 104 | if (FloatToBits(cast<ConstantFPSDNode>(NotZero)->getValue()) != |
| 105 | (uint32_t)-1) |
| 106 | return false; |
| 107 | } |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 108 | } else |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 109 | return false; |
| 110 | |
| 111 | // Okay, we have at least one ~0 value, check to see if the rest match or are |
| 112 | // undefs. |
Chris Lattner | 61d4399 | 2006-03-25 22:57:01 +0000 | [diff] [blame] | 113 | for (++i; i != e; ++i) |
| 114 | if (N->getOperand(i) != NotZero && |
| 115 | N->getOperand(i).getOpcode() != ISD::UNDEF) |
| 116 | return false; |
| 117 | return true; |
| 118 | } |
| 119 | |
| 120 | |
Evan Cheng | 4a14784 | 2006-03-26 09:50:58 +0000 | [diff] [blame] | 121 | /// isBuildVectorAllZeros - Return true if the specified node is a |
| 122 | /// BUILD_VECTOR where all of the elements are 0 or undef. |
| 123 | bool ISD::isBuildVectorAllZeros(const SDNode *N) { |
Chris Lattner | 547a16f | 2006-04-15 23:38:00 +0000 | [diff] [blame^] | 124 | // Look through a bit convert. |
| 125 | if (N->getOpcode() == ISD::BIT_CONVERT) |
| 126 | N = N->getOperand(0).Val; |
| 127 | |
Evan Cheng | 4a14784 | 2006-03-26 09:50:58 +0000 | [diff] [blame] | 128 | if (N->getOpcode() != ISD::BUILD_VECTOR) return false; |
Evan Cheng | a8df166 | 2006-03-27 06:58:47 +0000 | [diff] [blame] | 129 | |
| 130 | unsigned i = 0, e = N->getNumOperands(); |
| 131 | |
| 132 | // Skip over all of the undef values. |
| 133 | while (i != e && N->getOperand(i).getOpcode() == ISD::UNDEF) |
| 134 | ++i; |
| 135 | |
| 136 | // Do not accept an all-undef vector. |
| 137 | if (i == e) return false; |
| 138 | |
| 139 | // Do not accept build_vectors that aren't all constants or which have non-~0 |
| 140 | // elements. |
| 141 | SDOperand Zero = N->getOperand(i); |
| 142 | if (isa<ConstantSDNode>(Zero)) { |
| 143 | if (!cast<ConstantSDNode>(Zero)->isNullValue()) |
| 144 | return false; |
| 145 | } else if (isa<ConstantFPSDNode>(Zero)) { |
| 146 | if (!cast<ConstantFPSDNode>(Zero)->isExactlyValue(0.0)) |
| 147 | return false; |
| 148 | } else |
| 149 | return false; |
| 150 | |
| 151 | // Okay, we have at least one ~0 value, check to see if the rest match or are |
| 152 | // undefs. |
| 153 | for (++i; i != e; ++i) |
| 154 | if (N->getOperand(i) != Zero && |
| 155 | N->getOperand(i).getOpcode() != ISD::UNDEF) |
| 156 | return false; |
| 157 | return true; |
Evan Cheng | 4a14784 | 2006-03-26 09:50:58 +0000 | [diff] [blame] | 158 | } |
| 159 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 160 | /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X) |
| 161 | /// when given the operation for (X op Y). |
| 162 | ISD::CondCode ISD::getSetCCSwappedOperands(ISD::CondCode Operation) { |
| 163 | // To perform this operation, we just need to swap the L and G bits of the |
| 164 | // operation. |
| 165 | unsigned OldL = (Operation >> 2) & 1; |
| 166 | unsigned OldG = (Operation >> 1) & 1; |
| 167 | return ISD::CondCode((Operation & ~6) | // Keep the N, U, E bits |
| 168 | (OldL << 1) | // New G bit |
| 169 | (OldG << 2)); // New L bit. |
| 170 | } |
| 171 | |
| 172 | /// getSetCCInverse - Return the operation corresponding to !(X op Y), where |
| 173 | /// 'op' is a valid SetCC operation. |
| 174 | ISD::CondCode ISD::getSetCCInverse(ISD::CondCode Op, bool isInteger) { |
| 175 | unsigned Operation = Op; |
| 176 | if (isInteger) |
| 177 | Operation ^= 7; // Flip L, G, E bits, but not U. |
| 178 | else |
| 179 | Operation ^= 15; // Flip all of the condition bits. |
| 180 | if (Operation > ISD::SETTRUE2) |
| 181 | Operation &= ~8; // Don't let N and U bits get set. |
| 182 | return ISD::CondCode(Operation); |
| 183 | } |
| 184 | |
| 185 | |
| 186 | /// isSignedOp - For an integer comparison, return 1 if the comparison is a |
| 187 | /// signed operation and 2 if the result is an unsigned comparison. Return zero |
| 188 | /// if the operation does not depend on the sign of the input (setne and seteq). |
| 189 | static int isSignedOp(ISD::CondCode Opcode) { |
| 190 | switch (Opcode) { |
| 191 | default: assert(0 && "Illegal integer setcc operation!"); |
| 192 | case ISD::SETEQ: |
| 193 | case ISD::SETNE: return 0; |
| 194 | case ISD::SETLT: |
| 195 | case ISD::SETLE: |
| 196 | case ISD::SETGT: |
| 197 | case ISD::SETGE: return 1; |
| 198 | case ISD::SETULT: |
| 199 | case ISD::SETULE: |
| 200 | case ISD::SETUGT: |
| 201 | case ISD::SETUGE: return 2; |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | /// getSetCCOrOperation - Return the result of a logical OR between different |
| 206 | /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This function |
| 207 | /// returns SETCC_INVALID if it is not possible to represent the resultant |
| 208 | /// comparison. |
| 209 | ISD::CondCode ISD::getSetCCOrOperation(ISD::CondCode Op1, ISD::CondCode Op2, |
| 210 | bool isInteger) { |
| 211 | if (isInteger && (isSignedOp(Op1) | isSignedOp(Op2)) == 3) |
| 212 | // Cannot fold a signed integer setcc with an unsigned integer setcc. |
| 213 | return ISD::SETCC_INVALID; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 214 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 215 | unsigned Op = Op1 | Op2; // Combine all of the condition bits. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 216 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 217 | // If the N and U bits get set then the resultant comparison DOES suddenly |
| 218 | // care about orderedness, and is true when ordered. |
| 219 | if (Op > ISD::SETTRUE2) |
| 220 | Op &= ~16; // Clear the N bit. |
| 221 | return ISD::CondCode(Op); |
| 222 | } |
| 223 | |
| 224 | /// getSetCCAndOperation - Return the result of a logical AND between different |
| 225 | /// comparisons of identical values: ((X op1 Y) & (X op2 Y)). This |
| 226 | /// function returns zero if it is not possible to represent the resultant |
| 227 | /// comparison. |
| 228 | ISD::CondCode ISD::getSetCCAndOperation(ISD::CondCode Op1, ISD::CondCode Op2, |
| 229 | bool isInteger) { |
| 230 | if (isInteger && (isSignedOp(Op1) | isSignedOp(Op2)) == 3) |
| 231 | // Cannot fold a signed setcc with an unsigned setcc. |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 232 | return ISD::SETCC_INVALID; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 233 | |
| 234 | // Combine all of the condition bits. |
| 235 | return ISD::CondCode(Op1 & Op2); |
| 236 | } |
| 237 | |
Chris Lattner | b48da39 | 2005-01-23 04:39:44 +0000 | [diff] [blame] | 238 | const TargetMachine &SelectionDAG::getTarget() const { |
| 239 | return TLI.getTargetMachine(); |
| 240 | } |
| 241 | |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 242 | //===----------------------------------------------------------------------===// |
| 243 | // SelectionDAG Class |
| 244 | //===----------------------------------------------------------------------===// |
Chris Lattner | b48da39 | 2005-01-23 04:39:44 +0000 | [diff] [blame] | 245 | |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 246 | /// RemoveDeadNodes - This method deletes all unreachable nodes in the |
| 247 | /// SelectionDAG, including nodes (like loads) that have uses of their token |
| 248 | /// chain but no other uses and no side effect. If a node is passed in as an |
| 249 | /// argument, it is used as the seed for node deletion. |
| 250 | void SelectionDAG::RemoveDeadNodes(SDNode *N) { |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 251 | // Create a dummy node (which is not added to allnodes), that adds a reference |
| 252 | // to the root node, preventing it from being deleted. |
Chris Lattner | 9503859 | 2005-10-05 06:35:28 +0000 | [diff] [blame] | 253 | HandleSDNode Dummy(getRoot()); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 254 | |
Chris Lattner | f469cb6 | 2005-11-08 18:52:27 +0000 | [diff] [blame] | 255 | bool MadeChange = false; |
| 256 | |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 257 | // If we have a hint to start from, use it. |
Chris Lattner | f469cb6 | 2005-11-08 18:52:27 +0000 | [diff] [blame] | 258 | if (N && N->use_empty()) { |
| 259 | DestroyDeadNode(N); |
| 260 | MadeChange = true; |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 261 | } |
| 262 | |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 263 | for (allnodes_iterator I = allnodes_begin(), E = allnodes_end(); I != E; ++I) |
| 264 | if (I->use_empty() && I->getOpcode() != 65535) { |
| 265 | // Node is dead, recursively delete newly dead uses. |
| 266 | DestroyDeadNode(I); |
Chris Lattner | f469cb6 | 2005-11-08 18:52:27 +0000 | [diff] [blame] | 267 | MadeChange = true; |
| 268 | } |
Chris Lattner | f469cb6 | 2005-11-08 18:52:27 +0000 | [diff] [blame] | 269 | |
| 270 | // Walk the nodes list, removing the nodes we've marked as dead. |
| 271 | if (MadeChange) { |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 272 | for (allnodes_iterator I = allnodes_begin(), E = allnodes_end(); I != E; ) { |
| 273 | SDNode *N = I++; |
| 274 | if (N->use_empty()) |
| 275 | AllNodes.erase(N); |
| 276 | } |
Chris Lattner | f469cb6 | 2005-11-08 18:52:27 +0000 | [diff] [blame] | 277 | } |
| 278 | |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 279 | // If the root changed (e.g. it was a dead load, update the root). |
Chris Lattner | 9503859 | 2005-10-05 06:35:28 +0000 | [diff] [blame] | 280 | setRoot(Dummy.getValue()); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 281 | } |
| 282 | |
Chris Lattner | f469cb6 | 2005-11-08 18:52:27 +0000 | [diff] [blame] | 283 | /// DestroyDeadNode - We know that N is dead. Nuke it from the CSE maps for the |
| 284 | /// graph. If it is the last user of any of its operands, recursively process |
| 285 | /// them the same way. |
| 286 | /// |
| 287 | void SelectionDAG::DestroyDeadNode(SDNode *N) { |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 288 | // Okay, we really are going to delete this node. First take this out of the |
| 289 | // appropriate CSE map. |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 290 | RemoveNodeFromCSEMaps(N); |
| 291 | |
| 292 | // Next, brutally remove the operand list. This is safe to do, as there are |
| 293 | // no cycles in the graph. |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 294 | for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E; ++I) { |
| 295 | SDNode *O = I->Val; |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 296 | O->removeUser(N); |
| 297 | |
| 298 | // Now that we removed this operand, see if there are no uses of it left. |
Chris Lattner | f469cb6 | 2005-11-08 18:52:27 +0000 | [diff] [blame] | 299 | if (O->use_empty()) |
| 300 | DestroyDeadNode(O); |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 301 | } |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 302 | delete[] N->OperandList; |
| 303 | N->OperandList = 0; |
| 304 | N->NumOperands = 0; |
Chris Lattner | f469cb6 | 2005-11-08 18:52:27 +0000 | [diff] [blame] | 305 | |
| 306 | // Mark the node as dead. |
| 307 | N->MorphNodeTo(65535); |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Chris Lattner | c26aefa | 2005-08-29 21:59:31 +0000 | [diff] [blame] | 310 | void SelectionDAG::DeleteNode(SDNode *N) { |
| 311 | assert(N->use_empty() && "Cannot delete a node that is not dead!"); |
| 312 | |
| 313 | // First take this out of the appropriate CSE map. |
| 314 | RemoveNodeFromCSEMaps(N); |
| 315 | |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 316 | // Finally, remove uses due to operands of this node, remove from the |
| 317 | // AllNodes list, and delete the node. |
| 318 | DeleteNodeNotInCSEMaps(N); |
| 319 | } |
| 320 | |
| 321 | void SelectionDAG::DeleteNodeNotInCSEMaps(SDNode *N) { |
| 322 | |
Chris Lattner | c26aefa | 2005-08-29 21:59:31 +0000 | [diff] [blame] | 323 | // Remove it from the AllNodes list. |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 324 | AllNodes.remove(N); |
Chris Lattner | c26aefa | 2005-08-29 21:59:31 +0000 | [diff] [blame] | 325 | |
| 326 | // Drop all of the operands and decrement used nodes use counts. |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 327 | for (SDNode::op_iterator I = N->op_begin(), E = N->op_end(); I != E; ++I) |
| 328 | I->Val->removeUser(N); |
| 329 | delete[] N->OperandList; |
| 330 | N->OperandList = 0; |
| 331 | N->NumOperands = 0; |
Chris Lattner | c26aefa | 2005-08-29 21:59:31 +0000 | [diff] [blame] | 332 | |
| 333 | delete N; |
| 334 | } |
| 335 | |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 336 | /// RemoveNodeFromCSEMaps - Take the specified node out of the CSE map that |
| 337 | /// correspond to it. This is useful when we're about to delete or repurpose |
| 338 | /// the node. We don't want future request for structurally identical nodes |
| 339 | /// to return N anymore. |
| 340 | void SelectionDAG::RemoveNodeFromCSEMaps(SDNode *N) { |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 341 | bool Erased = false; |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 342 | switch (N->getOpcode()) { |
Chris Lattner | 9503859 | 2005-10-05 06:35:28 +0000 | [diff] [blame] | 343 | case ISD::HANDLENODE: return; // noop. |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 344 | case ISD::Constant: |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 345 | Erased = Constants.erase(std::make_pair(cast<ConstantSDNode>(N)->getValue(), |
| 346 | N->getValueType(0))); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 347 | break; |
Chris Lattner | 37bfbb4 | 2005-08-17 00:34:06 +0000 | [diff] [blame] | 348 | case ISD::TargetConstant: |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 349 | Erased = TargetConstants.erase(std::make_pair( |
| 350 | cast<ConstantSDNode>(N)->getValue(), |
| 351 | N->getValueType(0))); |
Chris Lattner | 37bfbb4 | 2005-08-17 00:34:06 +0000 | [diff] [blame] | 352 | break; |
Chris Lattner | d865861 | 2005-02-17 20:17:32 +0000 | [diff] [blame] | 353 | case ISD::ConstantFP: { |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 354 | uint64_t V = DoubleToBits(cast<ConstantFPSDNode>(N)->getValue()); |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 355 | Erased = ConstantFPs.erase(std::make_pair(V, N->getValueType(0))); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 356 | break; |
Chris Lattner | d865861 | 2005-02-17 20:17:32 +0000 | [diff] [blame] | 357 | } |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 358 | case ISD::TargetConstantFP: { |
| 359 | uint64_t V = DoubleToBits(cast<ConstantFPSDNode>(N)->getValue()); |
| 360 | Erased = TargetConstantFPs.erase(std::make_pair(V, N->getValueType(0))); |
| 361 | break; |
| 362 | } |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 363 | case ISD::STRING: |
| 364 | Erased = StringNodes.erase(cast<StringSDNode>(N)->getValue()); |
| 365 | break; |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 366 | case ISD::CONDCODE: |
| 367 | assert(CondCodeNodes[cast<CondCodeSDNode>(N)->get()] && |
| 368 | "Cond code doesn't exist!"); |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 369 | Erased = CondCodeNodes[cast<CondCodeSDNode>(N)->get()] != 0; |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 370 | CondCodeNodes[cast<CondCodeSDNode>(N)->get()] = 0; |
| 371 | break; |
Evan Cheng | 14229bb | 2005-11-30 02:49:21 +0000 | [diff] [blame] | 372 | case ISD::GlobalAddress: { |
| 373 | GlobalAddressSDNode *GN = cast<GlobalAddressSDNode>(N); |
| 374 | Erased = GlobalValues.erase(std::make_pair(GN->getGlobal(), |
| 375 | GN->getOffset())); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 376 | break; |
Evan Cheng | 14229bb | 2005-11-30 02:49:21 +0000 | [diff] [blame] | 377 | } |
| 378 | case ISD::TargetGlobalAddress: { |
| 379 | GlobalAddressSDNode *GN = cast<GlobalAddressSDNode>(N); |
| 380 | Erased =TargetGlobalValues.erase(std::make_pair(GN->getGlobal(), |
| 381 | GN->getOffset())); |
Chris Lattner | aaaa0b6 | 2005-08-19 22:31:04 +0000 | [diff] [blame] | 382 | break; |
Evan Cheng | 14229bb | 2005-11-30 02:49:21 +0000 | [diff] [blame] | 383 | } |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 384 | case ISD::FrameIndex: |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 385 | Erased = FrameIndices.erase(cast<FrameIndexSDNode>(N)->getIndex()); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 386 | break; |
Chris Lattner | afb2dd4 | 2005-08-25 00:43:01 +0000 | [diff] [blame] | 387 | case ISD::TargetFrameIndex: |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 388 | Erased = TargetFrameIndices.erase(cast<FrameIndexSDNode>(N)->getIndex()); |
Chris Lattner | afb2dd4 | 2005-08-25 00:43:01 +0000 | [diff] [blame] | 389 | break; |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 390 | case ISD::ConstantPool: |
Evan Cheng | b8973bd | 2006-01-31 22:23:14 +0000 | [diff] [blame] | 391 | Erased = ConstantPoolIndices. |
| 392 | erase(std::make_pair(cast<ConstantPoolSDNode>(N)->get(), |
Evan Cheng | 404cb4f | 2006-02-25 09:54:52 +0000 | [diff] [blame] | 393 | std::make_pair(cast<ConstantPoolSDNode>(N)->getOffset(), |
| 394 | cast<ConstantPoolSDNode>(N)->getAlignment()))); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 395 | break; |
Chris Lattner | 4025a9c | 2005-08-25 05:03:06 +0000 | [diff] [blame] | 396 | case ISD::TargetConstantPool: |
Evan Cheng | b8973bd | 2006-01-31 22:23:14 +0000 | [diff] [blame] | 397 | Erased = TargetConstantPoolIndices. |
| 398 | erase(std::make_pair(cast<ConstantPoolSDNode>(N)->get(), |
Evan Cheng | 404cb4f | 2006-02-25 09:54:52 +0000 | [diff] [blame] | 399 | std::make_pair(cast<ConstantPoolSDNode>(N)->getOffset(), |
| 400 | cast<ConstantPoolSDNode>(N)->getAlignment()))); |
Chris Lattner | 4025a9c | 2005-08-25 05:03:06 +0000 | [diff] [blame] | 401 | break; |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 402 | case ISD::BasicBlock: |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 403 | Erased = BBNodes.erase(cast<BasicBlockSDNode>(N)->getBasicBlock()); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 404 | break; |
| 405 | case ISD::ExternalSymbol: |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 406 | Erased = ExternalSymbols.erase(cast<ExternalSymbolSDNode>(N)->getSymbol()); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 407 | break; |
Andrew Lenharth | 2a2de66 | 2005-10-23 03:40:17 +0000 | [diff] [blame] | 408 | case ISD::TargetExternalSymbol: |
Chris Lattner | 809ec11 | 2006-01-28 10:09:25 +0000 | [diff] [blame] | 409 | Erased = |
| 410 | TargetExternalSymbols.erase(cast<ExternalSymbolSDNode>(N)->getSymbol()); |
Andrew Lenharth | 2a2de66 | 2005-10-23 03:40:17 +0000 | [diff] [blame] | 411 | break; |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 412 | case ISD::VALUETYPE: |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 413 | Erased = ValueTypeNodes[cast<VTSDNode>(N)->getVT()] != 0; |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 414 | ValueTypeNodes[cast<VTSDNode>(N)->getVT()] = 0; |
| 415 | break; |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 416 | case ISD::Register: |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 417 | Erased = RegNodes.erase(std::make_pair(cast<RegisterSDNode>(N)->getReg(), |
| 418 | N->getValueType(0))); |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 419 | break; |
Chris Lattner | c534395 | 2005-08-05 16:55:31 +0000 | [diff] [blame] | 420 | case ISD::SRCVALUE: { |
| 421 | SrcValueSDNode *SVN = cast<SrcValueSDNode>(N); |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 422 | Erased =ValueNodes.erase(std::make_pair(SVN->getValue(), SVN->getOffset())); |
Chris Lattner | c534395 | 2005-08-05 16:55:31 +0000 | [diff] [blame] | 423 | break; |
| 424 | } |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 425 | case ISD::LOAD: |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 426 | Erased = Loads.erase(std::make_pair(N->getOperand(1), |
| 427 | std::make_pair(N->getOperand(0), |
| 428 | N->getValueType(0)))); |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 429 | break; |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 430 | default: |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 431 | if (N->getNumValues() == 1) { |
Chris Lattner | 70b9b10 | 2005-09-02 19:36:17 +0000 | [diff] [blame] | 432 | if (N->getNumOperands() == 0) { |
| 433 | Erased = NullaryOps.erase(std::make_pair(N->getOpcode(), |
| 434 | N->getValueType(0))); |
| 435 | } else if (N->getNumOperands() == 1) { |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 436 | Erased = |
| 437 | UnaryOps.erase(std::make_pair(N->getOpcode(), |
| 438 | std::make_pair(N->getOperand(0), |
| 439 | N->getValueType(0)))); |
| 440 | } else if (N->getNumOperands() == 2) { |
| 441 | Erased = |
| 442 | BinaryOps.erase(std::make_pair(N->getOpcode(), |
| 443 | std::make_pair(N->getOperand(0), |
| 444 | N->getOperand(1)))); |
| 445 | } else { |
| 446 | std::vector<SDOperand> Ops(N->op_begin(), N->op_end()); |
| 447 | Erased = |
| 448 | OneResultNodes.erase(std::make_pair(N->getOpcode(), |
| 449 | std::make_pair(N->getValueType(0), |
| 450 | Ops))); |
| 451 | } |
Chris Lattner | 385328c | 2005-05-14 07:42:29 +0000 | [diff] [blame] | 452 | } else { |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 453 | // Remove the node from the ArbitraryNodes map. |
| 454 | std::vector<MVT::ValueType> RV(N->value_begin(), N->value_end()); |
| 455 | std::vector<SDOperand> Ops(N->op_begin(), N->op_end()); |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 456 | Erased = |
| 457 | ArbitraryNodes.erase(std::make_pair(N->getOpcode(), |
| 458 | std::make_pair(RV, Ops))); |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 459 | } |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 460 | break; |
| 461 | } |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 462 | #ifndef NDEBUG |
| 463 | // Verify that the node was actually in one of the CSE maps, unless it has a |
| 464 | // flag result (which cannot be CSE'd) or is one of the special cases that are |
| 465 | // not subject to CSE. |
| 466 | if (!Erased && N->getValueType(N->getNumValues()-1) != MVT::Flag && |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 467 | !N->isTargetOpcode()) { |
Chris Lattner | 6621e3b | 2005-09-02 19:15:44 +0000 | [diff] [blame] | 468 | N->dump(); |
| 469 | assert(0 && "Node is not in map!"); |
| 470 | } |
| 471 | #endif |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 472 | } |
| 473 | |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 474 | /// AddNonLeafNodeToCSEMaps - Add the specified node back to the CSE maps. It |
| 475 | /// has been taken out and modified in some way. If the specified node already |
| 476 | /// exists in the CSE maps, do not modify the maps, but return the existing node |
| 477 | /// instead. If it doesn't exist, add it and return null. |
| 478 | /// |
| 479 | SDNode *SelectionDAG::AddNonLeafNodeToCSEMaps(SDNode *N) { |
| 480 | assert(N->getNumOperands() && "This is a leaf node!"); |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 481 | if (N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) |
Chris Lattner | fe14b34 | 2005-12-01 23:14:50 +0000 | [diff] [blame] | 482 | return 0; // Never add these nodes. |
Chris Lattner | c85a9f3 | 2005-11-30 18:20:52 +0000 | [diff] [blame] | 483 | |
Chris Lattner | 9f8cc69 | 2005-12-19 22:21:21 +0000 | [diff] [blame] | 484 | // Check that remaining values produced are not flags. |
| 485 | for (unsigned i = 1, e = N->getNumValues(); i != e; ++i) |
| 486 | if (N->getValueType(i) == MVT::Flag) |
| 487 | return 0; // Never CSE anything that produces a flag. |
| 488 | |
Chris Lattner | fe14b34 | 2005-12-01 23:14:50 +0000 | [diff] [blame] | 489 | if (N->getNumValues() == 1) { |
| 490 | if (N->getNumOperands() == 1) { |
| 491 | SDNode *&U = UnaryOps[std::make_pair(N->getOpcode(), |
| 492 | std::make_pair(N->getOperand(0), |
| 493 | N->getValueType(0)))]; |
| 494 | if (U) return U; |
| 495 | U = N; |
| 496 | } else if (N->getNumOperands() == 2) { |
| 497 | SDNode *&B = BinaryOps[std::make_pair(N->getOpcode(), |
| 498 | std::make_pair(N->getOperand(0), |
| 499 | N->getOperand(1)))]; |
| 500 | if (B) return B; |
| 501 | B = N; |
| 502 | } else { |
| 503 | std::vector<SDOperand> Ops(N->op_begin(), N->op_end()); |
| 504 | SDNode *&ORN = OneResultNodes[std::make_pair(N->getOpcode(), |
Chris Lattner | 809ec11 | 2006-01-28 10:09:25 +0000 | [diff] [blame] | 505 | std::make_pair(N->getValueType(0), Ops))]; |
Chris Lattner | fe14b34 | 2005-12-01 23:14:50 +0000 | [diff] [blame] | 506 | if (ORN) return ORN; |
| 507 | ORN = N; |
| 508 | } |
| 509 | } else { |
| 510 | if (N->getOpcode() == ISD::LOAD) { |
| 511 | SDNode *&L = Loads[std::make_pair(N->getOperand(1), |
| 512 | std::make_pair(N->getOperand(0), |
| 513 | N->getValueType(0)))]; |
| 514 | if (L) return L; |
| 515 | L = N; |
| 516 | } else { |
| 517 | // Remove the node from the ArbitraryNodes map. |
| 518 | std::vector<MVT::ValueType> RV(N->value_begin(), N->value_end()); |
| 519 | std::vector<SDOperand> Ops(N->op_begin(), N->op_end()); |
| 520 | SDNode *&AN = ArbitraryNodes[std::make_pair(N->getOpcode(), |
| 521 | std::make_pair(RV, Ops))]; |
| 522 | if (AN) return AN; |
| 523 | AN = N; |
| 524 | } |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 525 | } |
| 526 | return 0; |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 527 | } |
| 528 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 529 | /// FindModifiedNodeSlot - Find a slot for the specified node if its operands |
| 530 | /// were replaced with those specified. If this node is never memoized, |
| 531 | /// return null, otherwise return a pointer to the slot it would take. If a |
| 532 | /// node already exists with these operands, the slot will be non-null. |
| 533 | SDNode **SelectionDAG::FindModifiedNodeSlot(SDNode *N, SDOperand Op) { |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 534 | if (N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 535 | return 0; // Never add these nodes. |
| 536 | |
| 537 | // Check that remaining values produced are not flags. |
| 538 | for (unsigned i = 1, e = N->getNumValues(); i != e; ++i) |
| 539 | if (N->getValueType(i) == MVT::Flag) |
| 540 | return 0; // Never CSE anything that produces a flag. |
| 541 | |
| 542 | if (N->getNumValues() == 1) { |
| 543 | return &UnaryOps[std::make_pair(N->getOpcode(), |
| 544 | std::make_pair(Op, N->getValueType(0)))]; |
| 545 | } else { |
| 546 | // Remove the node from the ArbitraryNodes map. |
| 547 | std::vector<MVT::ValueType> RV(N->value_begin(), N->value_end()); |
| 548 | std::vector<SDOperand> Ops; |
| 549 | Ops.push_back(Op); |
| 550 | return &ArbitraryNodes[std::make_pair(N->getOpcode(), |
| 551 | std::make_pair(RV, Ops))]; |
| 552 | } |
| 553 | return 0; |
| 554 | } |
| 555 | |
| 556 | /// FindModifiedNodeSlot - Find a slot for the specified node if its operands |
| 557 | /// were replaced with those specified. If this node is never memoized, |
| 558 | /// return null, otherwise return a pointer to the slot it would take. If a |
| 559 | /// node already exists with these operands, the slot will be non-null. |
| 560 | SDNode **SelectionDAG::FindModifiedNodeSlot(SDNode *N, |
| 561 | SDOperand Op1, SDOperand Op2) { |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 562 | if (N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 563 | return 0; // Never add these nodes. |
| 564 | |
| 565 | // Check that remaining values produced are not flags. |
| 566 | for (unsigned i = 1, e = N->getNumValues(); i != e; ++i) |
| 567 | if (N->getValueType(i) == MVT::Flag) |
| 568 | return 0; // Never CSE anything that produces a flag. |
| 569 | |
| 570 | if (N->getNumValues() == 1) { |
| 571 | return &BinaryOps[std::make_pair(N->getOpcode(), |
| 572 | std::make_pair(Op1, Op2))]; |
| 573 | } else { |
| 574 | std::vector<MVT::ValueType> RV(N->value_begin(), N->value_end()); |
| 575 | std::vector<SDOperand> Ops; |
| 576 | Ops.push_back(Op1); |
| 577 | Ops.push_back(Op2); |
| 578 | return &ArbitraryNodes[std::make_pair(N->getOpcode(), |
| 579 | std::make_pair(RV, Ops))]; |
| 580 | } |
| 581 | return 0; |
| 582 | } |
| 583 | |
| 584 | |
| 585 | /// FindModifiedNodeSlot - Find a slot for the specified node if its operands |
| 586 | /// were replaced with those specified. If this node is never memoized, |
| 587 | /// return null, otherwise return a pointer to the slot it would take. If a |
| 588 | /// node already exists with these operands, the slot will be non-null. |
| 589 | SDNode **SelectionDAG::FindModifiedNodeSlot(SDNode *N, |
| 590 | const std::vector<SDOperand> &Ops) { |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 591 | if (N->getOpcode() == ISD::HANDLENODE || N->getValueType(0) == MVT::Flag) |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 592 | return 0; // Never add these nodes. |
| 593 | |
| 594 | // Check that remaining values produced are not flags. |
| 595 | for (unsigned i = 1, e = N->getNumValues(); i != e; ++i) |
| 596 | if (N->getValueType(i) == MVT::Flag) |
| 597 | return 0; // Never CSE anything that produces a flag. |
| 598 | |
| 599 | if (N->getNumValues() == 1) { |
| 600 | if (N->getNumOperands() == 1) { |
| 601 | return &UnaryOps[std::make_pair(N->getOpcode(), |
| 602 | std::make_pair(Ops[0], |
| 603 | N->getValueType(0)))]; |
| 604 | } else if (N->getNumOperands() == 2) { |
| 605 | return &BinaryOps[std::make_pair(N->getOpcode(), |
| 606 | std::make_pair(Ops[0], Ops[1]))]; |
| 607 | } else { |
| 608 | return &OneResultNodes[std::make_pair(N->getOpcode(), |
| 609 | std::make_pair(N->getValueType(0), |
| 610 | Ops))]; |
| 611 | } |
| 612 | } else { |
| 613 | if (N->getOpcode() == ISD::LOAD) { |
| 614 | return &Loads[std::make_pair(Ops[1], |
| 615 | std::make_pair(Ops[0], N->getValueType(0)))]; |
| 616 | } else { |
| 617 | std::vector<MVT::ValueType> RV(N->value_begin(), N->value_end()); |
| 618 | return &ArbitraryNodes[std::make_pair(N->getOpcode(), |
| 619 | std::make_pair(RV, Ops))]; |
| 620 | } |
| 621 | } |
| 622 | return 0; |
| 623 | } |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 624 | |
Chris Lattner | 0e12e6e | 2005-01-07 21:09:16 +0000 | [diff] [blame] | 625 | |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 626 | SelectionDAG::~SelectionDAG() { |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 627 | while (!AllNodes.empty()) { |
| 628 | SDNode *N = AllNodes.begin(); |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 629 | delete [] N->OperandList; |
| 630 | N->OperandList = 0; |
| 631 | N->NumOperands = 0; |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 632 | AllNodes.pop_front(); |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 633 | } |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 634 | } |
| 635 | |
Chris Lattner | 0f2287b | 2005-04-13 02:38:18 +0000 | [diff] [blame] | 636 | SDOperand SelectionDAG::getZeroExtendInReg(SDOperand Op, MVT::ValueType VT) { |
Chris Lattner | 51679c4 | 2005-04-13 19:41:05 +0000 | [diff] [blame] | 637 | if (Op.getValueType() == VT) return Op; |
Jeff Cohen | 19bb228 | 2005-05-10 02:22:38 +0000 | [diff] [blame] | 638 | int64_t Imm = ~0ULL >> (64-MVT::getSizeInBits(VT)); |
Chris Lattner | 0f2287b | 2005-04-13 02:38:18 +0000 | [diff] [blame] | 639 | return getNode(ISD::AND, Op.getValueType(), Op, |
| 640 | getConstant(Imm, Op.getValueType())); |
| 641 | } |
| 642 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 643 | SDOperand SelectionDAG::getConstant(uint64_t Val, MVT::ValueType VT) { |
| 644 | assert(MVT::isInteger(VT) && "Cannot create FP integer constant!"); |
Chris Lattner | f35b297 | 2006-03-28 19:04:49 +0000 | [diff] [blame] | 645 | assert(!MVT::isVector(VT) && "Cannot create Vector ConstantSDNodes!"); |
| 646 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 647 | // Mask out any bits that are not valid for this constant. |
Chris Lattner | 623f70d | 2005-01-08 06:24:30 +0000 | [diff] [blame] | 648 | if (VT != MVT::i64) |
| 649 | Val &= ((uint64_t)1 << MVT::getSizeInBits(VT)) - 1; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 650 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 651 | SDNode *&N = Constants[std::make_pair(Val, VT)]; |
| 652 | if (N) return SDOperand(N, 0); |
Chris Lattner | 37bfbb4 | 2005-08-17 00:34:06 +0000 | [diff] [blame] | 653 | N = new ConstantSDNode(false, Val, VT); |
| 654 | AllNodes.push_back(N); |
| 655 | return SDOperand(N, 0); |
| 656 | } |
| 657 | |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 658 | SDOperand SelectionDAG::getString(const std::string &Val) { |
| 659 | StringSDNode *&N = StringNodes[Val]; |
| 660 | if (!N) { |
| 661 | N = new StringSDNode(Val); |
| 662 | AllNodes.push_back(N); |
| 663 | } |
| 664 | return SDOperand(N, 0); |
| 665 | } |
| 666 | |
Chris Lattner | 37bfbb4 | 2005-08-17 00:34:06 +0000 | [diff] [blame] | 667 | SDOperand SelectionDAG::getTargetConstant(uint64_t Val, MVT::ValueType VT) { |
| 668 | assert(MVT::isInteger(VT) && "Cannot create FP integer constant!"); |
| 669 | // Mask out any bits that are not valid for this constant. |
| 670 | if (VT != MVT::i64) |
| 671 | Val &= ((uint64_t)1 << MVT::getSizeInBits(VT)) - 1; |
| 672 | |
| 673 | SDNode *&N = TargetConstants[std::make_pair(Val, VT)]; |
| 674 | if (N) return SDOperand(N, 0); |
| 675 | N = new ConstantSDNode(true, Val, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 676 | AllNodes.push_back(N); |
| 677 | return SDOperand(N, 0); |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 678 | } |
| 679 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 680 | SDOperand SelectionDAG::getConstantFP(double Val, MVT::ValueType VT) { |
| 681 | assert(MVT::isFloatingPoint(VT) && "Cannot create integer FP constant!"); |
| 682 | if (VT == MVT::f32) |
| 683 | Val = (float)Val; // Mask out extra precision. |
| 684 | |
Chris Lattner | d865861 | 2005-02-17 20:17:32 +0000 | [diff] [blame] | 685 | // Do the map lookup using the actual bit pattern for the floating point |
| 686 | // value, so that we don't have problems with 0.0 comparing equal to -0.0, and |
| 687 | // we don't have issues with SNANs. |
Jim Laskey | cb6682f | 2005-08-17 19:34:49 +0000 | [diff] [blame] | 688 | SDNode *&N = ConstantFPs[std::make_pair(DoubleToBits(Val), VT)]; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 689 | if (N) return SDOperand(N, 0); |
Chris Lattner | 3181a77 | 2006-01-29 06:26:56 +0000 | [diff] [blame] | 690 | N = new ConstantFPSDNode(false, Val, VT); |
| 691 | AllNodes.push_back(N); |
| 692 | return SDOperand(N, 0); |
| 693 | } |
| 694 | |
| 695 | SDOperand SelectionDAG::getTargetConstantFP(double Val, MVT::ValueType VT) { |
| 696 | assert(MVT::isFloatingPoint(VT) && "Cannot create integer FP constant!"); |
| 697 | if (VT == MVT::f32) |
| 698 | Val = (float)Val; // Mask out extra precision. |
| 699 | |
| 700 | // Do the map lookup using the actual bit pattern for the floating point |
| 701 | // value, so that we don't have problems with 0.0 comparing equal to -0.0, and |
| 702 | // we don't have issues with SNANs. |
| 703 | SDNode *&N = TargetConstantFPs[std::make_pair(DoubleToBits(Val), VT)]; |
| 704 | if (N) return SDOperand(N, 0); |
| 705 | N = new ConstantFPSDNode(true, Val, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 706 | AllNodes.push_back(N); |
| 707 | return SDOperand(N, 0); |
| 708 | } |
| 709 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 710 | SDOperand SelectionDAG::getGlobalAddress(const GlobalValue *GV, |
Evan Cheng | 14229bb | 2005-11-30 02:49:21 +0000 | [diff] [blame] | 711 | MVT::ValueType VT, int offset) { |
| 712 | SDNode *&N = GlobalValues[std::make_pair(GV, offset)]; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 713 | if (N) return SDOperand(N, 0); |
Nate Begeman | 512beb9 | 2005-12-30 00:10:38 +0000 | [diff] [blame] | 714 | N = new GlobalAddressSDNode(false, GV, VT, offset); |
Chris Lattner | aaaa0b6 | 2005-08-19 22:31:04 +0000 | [diff] [blame] | 715 | AllNodes.push_back(N); |
| 716 | return SDOperand(N, 0); |
| 717 | } |
| 718 | |
| 719 | SDOperand SelectionDAG::getTargetGlobalAddress(const GlobalValue *GV, |
Evan Cheng | 61ca74b | 2005-11-30 02:04:11 +0000 | [diff] [blame] | 720 | MVT::ValueType VT, int offset) { |
Evan Cheng | 14229bb | 2005-11-30 02:49:21 +0000 | [diff] [blame] | 721 | SDNode *&N = TargetGlobalValues[std::make_pair(GV, offset)]; |
Chris Lattner | aaaa0b6 | 2005-08-19 22:31:04 +0000 | [diff] [blame] | 722 | if (N) return SDOperand(N, 0); |
Evan Cheng | 61ca74b | 2005-11-30 02:04:11 +0000 | [diff] [blame] | 723 | N = new GlobalAddressSDNode(true, GV, VT, offset); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 724 | AllNodes.push_back(N); |
| 725 | return SDOperand(N, 0); |
| 726 | } |
| 727 | |
| 728 | SDOperand SelectionDAG::getFrameIndex(int FI, MVT::ValueType VT) { |
| 729 | SDNode *&N = FrameIndices[FI]; |
| 730 | if (N) return SDOperand(N, 0); |
Chris Lattner | afb2dd4 | 2005-08-25 00:43:01 +0000 | [diff] [blame] | 731 | N = new FrameIndexSDNode(FI, VT, false); |
| 732 | AllNodes.push_back(N); |
| 733 | return SDOperand(N, 0); |
| 734 | } |
| 735 | |
| 736 | SDOperand SelectionDAG::getTargetFrameIndex(int FI, MVT::ValueType VT) { |
| 737 | SDNode *&N = TargetFrameIndices[FI]; |
| 738 | if (N) return SDOperand(N, 0); |
| 739 | N = new FrameIndexSDNode(FI, VT, true); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 740 | AllNodes.push_back(N); |
| 741 | return SDOperand(N, 0); |
| 742 | } |
| 743 | |
Evan Cheng | b8973bd | 2006-01-31 22:23:14 +0000 | [diff] [blame] | 744 | SDOperand SelectionDAG::getConstantPool(Constant *C, MVT::ValueType VT, |
Evan Cheng | 404cb4f | 2006-02-25 09:54:52 +0000 | [diff] [blame] | 745 | unsigned Alignment, int Offset) { |
| 746 | SDNode *&N = ConstantPoolIndices[std::make_pair(C, |
| 747 | std::make_pair(Offset, Alignment))]; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 748 | if (N) return SDOperand(N, 0); |
Evan Cheng | 404cb4f | 2006-02-25 09:54:52 +0000 | [diff] [blame] | 749 | N = new ConstantPoolSDNode(false, C, VT, Offset, Alignment); |
Chris Lattner | 4025a9c | 2005-08-25 05:03:06 +0000 | [diff] [blame] | 750 | AllNodes.push_back(N); |
| 751 | return SDOperand(N, 0); |
| 752 | } |
| 753 | |
Evan Cheng | b8973bd | 2006-01-31 22:23:14 +0000 | [diff] [blame] | 754 | SDOperand SelectionDAG::getTargetConstantPool(Constant *C, MVT::ValueType VT, |
Evan Cheng | 404cb4f | 2006-02-25 09:54:52 +0000 | [diff] [blame] | 755 | unsigned Alignment, int Offset) { |
| 756 | SDNode *&N = TargetConstantPoolIndices[std::make_pair(C, |
| 757 | std::make_pair(Offset, Alignment))]; |
Chris Lattner | 4025a9c | 2005-08-25 05:03:06 +0000 | [diff] [blame] | 758 | if (N) return SDOperand(N, 0); |
Evan Cheng | 404cb4f | 2006-02-25 09:54:52 +0000 | [diff] [blame] | 759 | N = new ConstantPoolSDNode(true, C, VT, Offset, Alignment); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 760 | AllNodes.push_back(N); |
| 761 | return SDOperand(N, 0); |
| 762 | } |
| 763 | |
| 764 | SDOperand SelectionDAG::getBasicBlock(MachineBasicBlock *MBB) { |
| 765 | SDNode *&N = BBNodes[MBB]; |
| 766 | if (N) return SDOperand(N, 0); |
| 767 | N = new BasicBlockSDNode(MBB); |
| 768 | AllNodes.push_back(N); |
| 769 | return SDOperand(N, 0); |
| 770 | } |
| 771 | |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 772 | SDOperand SelectionDAG::getValueType(MVT::ValueType VT) { |
| 773 | if ((unsigned)VT >= ValueTypeNodes.size()) |
| 774 | ValueTypeNodes.resize(VT+1); |
| 775 | if (ValueTypeNodes[VT] == 0) { |
| 776 | ValueTypeNodes[VT] = new VTSDNode(VT); |
| 777 | AllNodes.push_back(ValueTypeNodes[VT]); |
| 778 | } |
| 779 | |
| 780 | return SDOperand(ValueTypeNodes[VT], 0); |
| 781 | } |
| 782 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 783 | SDOperand SelectionDAG::getExternalSymbol(const char *Sym, MVT::ValueType VT) { |
| 784 | SDNode *&N = ExternalSymbols[Sym]; |
| 785 | if (N) return SDOperand(N, 0); |
Andrew Lenharth | 2a2de66 | 2005-10-23 03:40:17 +0000 | [diff] [blame] | 786 | N = new ExternalSymbolSDNode(false, Sym, VT); |
| 787 | AllNodes.push_back(N); |
| 788 | return SDOperand(N, 0); |
| 789 | } |
| 790 | |
Chris Lattner | 809ec11 | 2006-01-28 10:09:25 +0000 | [diff] [blame] | 791 | SDOperand SelectionDAG::getTargetExternalSymbol(const char *Sym, |
| 792 | MVT::ValueType VT) { |
Andrew Lenharth | 2a2de66 | 2005-10-23 03:40:17 +0000 | [diff] [blame] | 793 | SDNode *&N = TargetExternalSymbols[Sym]; |
| 794 | if (N) return SDOperand(N, 0); |
| 795 | N = new ExternalSymbolSDNode(true, Sym, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 796 | AllNodes.push_back(N); |
| 797 | return SDOperand(N, 0); |
| 798 | } |
| 799 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 800 | SDOperand SelectionDAG::getCondCode(ISD::CondCode Cond) { |
| 801 | if ((unsigned)Cond >= CondCodeNodes.size()) |
| 802 | CondCodeNodes.resize(Cond+1); |
| 803 | |
Chris Lattner | 079a27a | 2005-08-09 20:40:02 +0000 | [diff] [blame] | 804 | if (CondCodeNodes[Cond] == 0) { |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 805 | CondCodeNodes[Cond] = new CondCodeSDNode(Cond); |
Chris Lattner | 079a27a | 2005-08-09 20:40:02 +0000 | [diff] [blame] | 806 | AllNodes.push_back(CondCodeNodes[Cond]); |
| 807 | } |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 808 | return SDOperand(CondCodeNodes[Cond], 0); |
| 809 | } |
| 810 | |
Chris Lattner | 0fdd768 | 2005-08-30 22:38:38 +0000 | [diff] [blame] | 811 | SDOperand SelectionDAG::getRegister(unsigned RegNo, MVT::ValueType VT) { |
| 812 | RegisterSDNode *&Reg = RegNodes[std::make_pair(RegNo, VT)]; |
| 813 | if (!Reg) { |
| 814 | Reg = new RegisterSDNode(RegNo, VT); |
| 815 | AllNodes.push_back(Reg); |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 816 | } |
Chris Lattner | 0fdd768 | 2005-08-30 22:38:38 +0000 | [diff] [blame] | 817 | return SDOperand(Reg, 0); |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Chris Lattner | bd8625b | 2005-08-09 23:09:05 +0000 | [diff] [blame] | 820 | SDOperand SelectionDAG::SimplifySetCC(MVT::ValueType VT, SDOperand N1, |
| 821 | SDOperand N2, ISD::CondCode Cond) { |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 822 | // These setcc operations always fold. |
| 823 | switch (Cond) { |
| 824 | default: break; |
| 825 | case ISD::SETFALSE: |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 826 | case ISD::SETFALSE2: return getConstant(0, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 827 | case ISD::SETTRUE: |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 828 | case ISD::SETTRUE2: return getConstant(1, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 829 | } |
| 830 | |
Chris Lattner | 67255a1 | 2005-04-07 18:14:58 +0000 | [diff] [blame] | 831 | if (ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2.Val)) { |
| 832 | uint64_t C2 = N2C->getValue(); |
| 833 | if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val)) { |
| 834 | uint64_t C1 = N1C->getValue(); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 835 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 836 | // Sign extend the operands if required |
| 837 | if (ISD::isSignedIntSetCC(Cond)) { |
| 838 | C1 = N1C->getSignExtended(); |
| 839 | C2 = N2C->getSignExtended(); |
| 840 | } |
| 841 | |
| 842 | switch (Cond) { |
| 843 | default: assert(0 && "Unknown integer setcc!"); |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 844 | case ISD::SETEQ: return getConstant(C1 == C2, VT); |
| 845 | case ISD::SETNE: return getConstant(C1 != C2, VT); |
| 846 | case ISD::SETULT: return getConstant(C1 < C2, VT); |
| 847 | case ISD::SETUGT: return getConstant(C1 > C2, VT); |
| 848 | case ISD::SETULE: return getConstant(C1 <= C2, VT); |
| 849 | case ISD::SETUGE: return getConstant(C1 >= C2, VT); |
| 850 | case ISD::SETLT: return getConstant((int64_t)C1 < (int64_t)C2, VT); |
| 851 | case ISD::SETGT: return getConstant((int64_t)C1 > (int64_t)C2, VT); |
| 852 | case ISD::SETLE: return getConstant((int64_t)C1 <= (int64_t)C2, VT); |
| 853 | case ISD::SETGE: return getConstant((int64_t)C1 >= (int64_t)C2, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 854 | } |
Chris Lattner | 2467392 | 2005-04-07 18:58:54 +0000 | [diff] [blame] | 855 | } else { |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 856 | // If the LHS is a ZERO_EXTEND, perform the comparison on the input. |
Chris Lattner | 4a44c8d | 2005-04-18 04:30:45 +0000 | [diff] [blame] | 857 | if (N1.getOpcode() == ISD::ZERO_EXTEND) { |
| 858 | unsigned InSize = MVT::getSizeInBits(N1.getOperand(0).getValueType()); |
| 859 | |
| 860 | // If the comparison constant has bits in the upper part, the |
| 861 | // zero-extended value could never match. |
| 862 | if (C2 & (~0ULL << InSize)) { |
| 863 | unsigned VSize = MVT::getSizeInBits(N1.getValueType()); |
| 864 | switch (Cond) { |
| 865 | case ISD::SETUGT: |
| 866 | case ISD::SETUGE: |
| 867 | case ISD::SETEQ: return getConstant(0, VT); |
| 868 | case ISD::SETULT: |
| 869 | case ISD::SETULE: |
| 870 | case ISD::SETNE: return getConstant(1, VT); |
| 871 | case ISD::SETGT: |
| 872 | case ISD::SETGE: |
| 873 | // True if the sign bit of C2 is set. |
| 874 | return getConstant((C2 & (1ULL << VSize)) != 0, VT); |
| 875 | case ISD::SETLT: |
| 876 | case ISD::SETLE: |
| 877 | // True if the sign bit of C2 isn't set. |
| 878 | return getConstant((C2 & (1ULL << VSize)) == 0, VT); |
| 879 | default: |
| 880 | break; |
| 881 | } |
| 882 | } |
| 883 | |
| 884 | // Otherwise, we can perform the comparison with the low bits. |
| 885 | switch (Cond) { |
| 886 | case ISD::SETEQ: |
| 887 | case ISD::SETNE: |
| 888 | case ISD::SETUGT: |
| 889 | case ISD::SETUGE: |
| 890 | case ISD::SETULT: |
| 891 | case ISD::SETULE: |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 892 | return getSetCC(VT, N1.getOperand(0), |
| 893 | getConstant(C2, N1.getOperand(0).getValueType()), |
| 894 | Cond); |
Chris Lattner | 4a44c8d | 2005-04-18 04:30:45 +0000 | [diff] [blame] | 895 | default: |
| 896 | break; // todo, be more careful with signed comparisons |
| 897 | } |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 898 | } else if (N1.getOpcode() == ISD::SIGN_EXTEND_INREG && |
| 899 | (Cond == ISD::SETEQ || Cond == ISD::SETNE)) { |
| 900 | MVT::ValueType ExtSrcTy = cast<VTSDNode>(N1.getOperand(1))->getVT(); |
| 901 | unsigned ExtSrcTyBits = MVT::getSizeInBits(ExtSrcTy); |
| 902 | MVT::ValueType ExtDstTy = N1.getValueType(); |
| 903 | unsigned ExtDstTyBits = MVT::getSizeInBits(ExtDstTy); |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 904 | |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 905 | // If the extended part has any inconsistent bits, it cannot ever |
| 906 | // compare equal. In other words, they have to be all ones or all |
| 907 | // zeros. |
| 908 | uint64_t ExtBits = |
Jeff Cohen | 7383ce4 | 2005-08-31 02:47:06 +0000 | [diff] [blame] | 909 | (~0ULL >> (64-ExtSrcTyBits)) & (~0ULL << (ExtDstTyBits-1)); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 910 | if ((C2 & ExtBits) != 0 && (C2 & ExtBits) != ExtBits) |
| 911 | return getConstant(Cond == ISD::SETNE, VT); |
| 912 | |
| 913 | // Otherwise, make this a use of a zext. |
| 914 | return getSetCC(VT, getZeroExtendInReg(N1.getOperand(0), ExtSrcTy), |
Jeff Cohen | 7383ce4 | 2005-08-31 02:47:06 +0000 | [diff] [blame] | 915 | getConstant(C2 & (~0ULL>>(64-ExtSrcTyBits)), ExtDstTy), |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 916 | Cond); |
Chris Lattner | 4a44c8d | 2005-04-18 04:30:45 +0000 | [diff] [blame] | 917 | } |
| 918 | |
Chris Lattner | 67255a1 | 2005-04-07 18:14:58 +0000 | [diff] [blame] | 919 | uint64_t MinVal, MaxVal; |
| 920 | unsigned OperandBitSize = MVT::getSizeInBits(N2C->getValueType(0)); |
| 921 | if (ISD::isSignedIntSetCC(Cond)) { |
| 922 | MinVal = 1ULL << (OperandBitSize-1); |
| 923 | if (OperandBitSize != 1) // Avoid X >> 64, which is undefined. |
| 924 | MaxVal = ~0ULL >> (65-OperandBitSize); |
| 925 | else |
| 926 | MaxVal = 0; |
| 927 | } else { |
| 928 | MinVal = 0; |
| 929 | MaxVal = ~0ULL >> (64-OperandBitSize); |
| 930 | } |
| 931 | |
| 932 | // Canonicalize GE/LE comparisons to use GT/LT comparisons. |
| 933 | if (Cond == ISD::SETGE || Cond == ISD::SETUGE) { |
| 934 | if (C2 == MinVal) return getConstant(1, VT); // X >= MIN --> true |
| 935 | --C2; // X >= C1 --> X > (C1-1) |
Chris Lattner | bd8625b | 2005-08-09 23:09:05 +0000 | [diff] [blame] | 936 | return getSetCC(VT, N1, getConstant(C2, N2.getValueType()), |
| 937 | (Cond == ISD::SETGE) ? ISD::SETGT : ISD::SETUGT); |
Chris Lattner | 67255a1 | 2005-04-07 18:14:58 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | if (Cond == ISD::SETLE || Cond == ISD::SETULE) { |
| 941 | if (C2 == MaxVal) return getConstant(1, VT); // X <= MAX --> true |
| 942 | ++C2; // X <= C1 --> X < (C1+1) |
Chris Lattner | bd8625b | 2005-08-09 23:09:05 +0000 | [diff] [blame] | 943 | return getSetCC(VT, N1, getConstant(C2, N2.getValueType()), |
| 944 | (Cond == ISD::SETLE) ? ISD::SETLT : ISD::SETULT); |
Chris Lattner | 67255a1 | 2005-04-07 18:14:58 +0000 | [diff] [blame] | 945 | } |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 946 | |
Nate Begeman | 72ea281 | 2005-04-14 08:56:52 +0000 | [diff] [blame] | 947 | if ((Cond == ISD::SETLT || Cond == ISD::SETULT) && C2 == MinVal) |
| 948 | return getConstant(0, VT); // X < MIN --> false |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 949 | |
Nate Begeman | 72ea281 | 2005-04-14 08:56:52 +0000 | [diff] [blame] | 950 | // Canonicalize setgt X, Min --> setne X, Min |
| 951 | if ((Cond == ISD::SETGT || Cond == ISD::SETUGT) && C2 == MinVal) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 952 | return getSetCC(VT, N1, N2, ISD::SETNE); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 953 | |
Chris Lattner | 3b2c1d9 | 2005-04-12 00:28:49 +0000 | [diff] [blame] | 954 | // If we have setult X, 1, turn it into seteq X, 0 |
| 955 | if ((Cond == ISD::SETLT || Cond == ISD::SETULT) && C2 == MinVal+1) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 956 | return getSetCC(VT, N1, getConstant(MinVal, N1.getValueType()), |
| 957 | ISD::SETEQ); |
Nate Begeman | 72ea281 | 2005-04-14 08:56:52 +0000 | [diff] [blame] | 958 | // If we have setugt X, Max-1, turn it into seteq X, Max |
Chris Lattner | 3b2c1d9 | 2005-04-12 00:28:49 +0000 | [diff] [blame] | 959 | else if ((Cond == ISD::SETGT || Cond == ISD::SETUGT) && C2 == MaxVal-1) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 960 | return getSetCC(VT, N1, getConstant(MaxVal, N1.getValueType()), |
| 961 | ISD::SETEQ); |
Chris Lattner | 67255a1 | 2005-04-07 18:14:58 +0000 | [diff] [blame] | 962 | |
| 963 | // If we have "setcc X, C1", check to see if we can shrink the immediate |
| 964 | // by changing cc. |
| 965 | |
| 966 | // SETUGT X, SINTMAX -> SETLT X, 0 |
| 967 | if (Cond == ISD::SETUGT && OperandBitSize != 1 && |
| 968 | C2 == (~0ULL >> (65-OperandBitSize))) |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 969 | return getSetCC(VT, N1, getConstant(0, N2.getValueType()), ISD::SETLT); |
Chris Lattner | 67255a1 | 2005-04-07 18:14:58 +0000 | [diff] [blame] | 970 | |
| 971 | // FIXME: Implement the rest of these. |
| 972 | |
Chris Lattner | 1c2a9b9 | 2005-04-21 06:12:41 +0000 | [diff] [blame] | 973 | |
| 974 | // Fold bit comparisons when we can. |
| 975 | if ((Cond == ISD::SETEQ || Cond == ISD::SETNE) && |
| 976 | VT == N1.getValueType() && N1.getOpcode() == ISD::AND) |
| 977 | if (ConstantSDNode *AndRHS = |
| 978 | dyn_cast<ConstantSDNode>(N1.getOperand(1))) { |
| 979 | if (Cond == ISD::SETNE && C2 == 0) {// (X & 8) != 0 --> (X & 8) >> 3 |
| 980 | // Perform the xform if the AND RHS is a single bit. |
| 981 | if ((AndRHS->getValue() & (AndRHS->getValue()-1)) == 0) { |
| 982 | return getNode(ISD::SRL, VT, N1, |
Chris Lattner | 0561b3f | 2005-08-02 19:26:06 +0000 | [diff] [blame] | 983 | getConstant(Log2_64(AndRHS->getValue()), |
Chris Lattner | 1c2a9b9 | 2005-04-21 06:12:41 +0000 | [diff] [blame] | 984 | TLI.getShiftAmountTy())); |
| 985 | } |
| 986 | } else if (Cond == ISD::SETEQ && C2 == AndRHS->getValue()) { |
| 987 | // (X & 8) == 8 --> (X & 8) >> 3 |
| 988 | // Perform the xform if C2 is a single bit. |
| 989 | if ((C2 & (C2-1)) == 0) { |
| 990 | return getNode(ISD::SRL, VT, N1, |
Chris Lattner | 0561b3f | 2005-08-02 19:26:06 +0000 | [diff] [blame] | 991 | getConstant(Log2_64(C2),TLI.getShiftAmountTy())); |
Chris Lattner | 1c2a9b9 | 2005-04-21 06:12:41 +0000 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 995 | } |
Chris Lattner | 67255a1 | 2005-04-07 18:14:58 +0000 | [diff] [blame] | 996 | } else if (isa<ConstantSDNode>(N1.Val)) { |
| 997 | // Ensure that the constant occurs on the RHS. |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 998 | return getSetCC(VT, N2, N1, ISD::getSetCCSwappedOperands(Cond)); |
Chris Lattner | 67255a1 | 2005-04-07 18:14:58 +0000 | [diff] [blame] | 999 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1000 | |
| 1001 | if (ConstantFPSDNode *N1C = dyn_cast<ConstantFPSDNode>(N1.Val)) |
| 1002 | if (ConstantFPSDNode *N2C = dyn_cast<ConstantFPSDNode>(N2.Val)) { |
| 1003 | double C1 = N1C->getValue(), C2 = N2C->getValue(); |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1004 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1005 | switch (Cond) { |
| 1006 | default: break; // FIXME: Implement the rest of these! |
Chris Lattner | f30b73b | 2005-01-18 02:52:03 +0000 | [diff] [blame] | 1007 | case ISD::SETEQ: return getConstant(C1 == C2, VT); |
| 1008 | case ISD::SETNE: return getConstant(C1 != C2, VT); |
| 1009 | case ISD::SETLT: return getConstant(C1 < C2, VT); |
| 1010 | case ISD::SETGT: return getConstant(C1 > C2, VT); |
| 1011 | case ISD::SETLE: return getConstant(C1 <= C2, VT); |
| 1012 | case ISD::SETGE: return getConstant(C1 >= C2, VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1013 | } |
| 1014 | } else { |
| 1015 | // Ensure that the constant occurs on the RHS. |
Chris Lattner | bd8625b | 2005-08-09 23:09:05 +0000 | [diff] [blame] | 1016 | return getSetCC(VT, N2, N1, ISD::getSetCCSwappedOperands(Cond)); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1017 | } |
| 1018 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1019 | // Could not fold it. |
| 1020 | return SDOperand(); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1021 | } |
| 1022 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1023 | /// getNode - Gets or creates the specified node. |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 1024 | /// |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1025 | SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT) { |
Chris Lattner | 70b9b10 | 2005-09-02 19:36:17 +0000 | [diff] [blame] | 1026 | SDNode *&N = NullaryOps[std::make_pair(Opcode, VT)]; |
| 1027 | if (!N) { |
| 1028 | N = new SDNode(Opcode, VT); |
| 1029 | AllNodes.push_back(N); |
| 1030 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1031 | return SDOperand(N, 0); |
| 1032 | } |
| 1033 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1034 | SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT, |
| 1035 | SDOperand Operand) { |
Nate Begeman | 1b5db7a | 2006-01-16 08:07:10 +0000 | [diff] [blame] | 1036 | unsigned Tmp1; |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1037 | // Constant fold unary operations with an integer constant operand. |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1038 | if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Operand.Val)) { |
| 1039 | uint64_t Val = C->getValue(); |
| 1040 | switch (Opcode) { |
| 1041 | default: break; |
| 1042 | case ISD::SIGN_EXTEND: return getConstant(C->getSignExtended(), VT); |
Chris Lattner | 4ed11b4 | 2005-09-02 00:17:32 +0000 | [diff] [blame] | 1043 | case ISD::ANY_EXTEND: |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1044 | case ISD::ZERO_EXTEND: return getConstant(Val, VT); |
| 1045 | case ISD::TRUNCATE: return getConstant(Val, VT); |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 1046 | case ISD::SINT_TO_FP: return getConstantFP(C->getSignExtended(), VT); |
| 1047 | case ISD::UINT_TO_FP: return getConstantFP(C->getValue(), VT); |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1048 | case ISD::BIT_CONVERT: |
Chris Lattner | e8a30fd | 2006-03-24 02:20:47 +0000 | [diff] [blame] | 1049 | if (VT == MVT::f32 && C->getValueType(0) == MVT::i32) |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1050 | return getConstantFP(BitsToFloat(Val), VT); |
Chris Lattner | e8a30fd | 2006-03-24 02:20:47 +0000 | [diff] [blame] | 1051 | else if (VT == MVT::f64 && C->getValueType(0) == MVT::i64) |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1052 | return getConstantFP(BitsToDouble(Val), VT); |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1053 | break; |
Nate Begeman | 1b5db7a | 2006-01-16 08:07:10 +0000 | [diff] [blame] | 1054 | case ISD::BSWAP: |
| 1055 | switch(VT) { |
| 1056 | default: assert(0 && "Invalid bswap!"); break; |
| 1057 | case MVT::i16: return getConstant(ByteSwap_16((unsigned short)Val), VT); |
| 1058 | case MVT::i32: return getConstant(ByteSwap_32((unsigned)Val), VT); |
| 1059 | case MVT::i64: return getConstant(ByteSwap_64(Val), VT); |
| 1060 | } |
| 1061 | break; |
| 1062 | case ISD::CTPOP: |
| 1063 | switch(VT) { |
| 1064 | default: assert(0 && "Invalid ctpop!"); break; |
| 1065 | case MVT::i1: return getConstant(Val != 0, VT); |
| 1066 | case MVT::i8: |
| 1067 | Tmp1 = (unsigned)Val & 0xFF; |
| 1068 | return getConstant(CountPopulation_32(Tmp1), VT); |
| 1069 | case MVT::i16: |
| 1070 | Tmp1 = (unsigned)Val & 0xFFFF; |
| 1071 | return getConstant(CountPopulation_32(Tmp1), VT); |
| 1072 | case MVT::i32: |
| 1073 | return getConstant(CountPopulation_32((unsigned)Val), VT); |
| 1074 | case MVT::i64: |
| 1075 | return getConstant(CountPopulation_64(Val), VT); |
| 1076 | } |
| 1077 | case ISD::CTLZ: |
| 1078 | switch(VT) { |
| 1079 | default: assert(0 && "Invalid ctlz!"); break; |
| 1080 | case MVT::i1: return getConstant(Val == 0, VT); |
| 1081 | case MVT::i8: |
| 1082 | Tmp1 = (unsigned)Val & 0xFF; |
| 1083 | return getConstant(CountLeadingZeros_32(Tmp1)-24, VT); |
| 1084 | case MVT::i16: |
| 1085 | Tmp1 = (unsigned)Val & 0xFFFF; |
| 1086 | return getConstant(CountLeadingZeros_32(Tmp1)-16, VT); |
| 1087 | case MVT::i32: |
| 1088 | return getConstant(CountLeadingZeros_32((unsigned)Val), VT); |
| 1089 | case MVT::i64: |
| 1090 | return getConstant(CountLeadingZeros_64(Val), VT); |
| 1091 | } |
| 1092 | case ISD::CTTZ: |
| 1093 | switch(VT) { |
| 1094 | default: assert(0 && "Invalid cttz!"); break; |
| 1095 | case MVT::i1: return getConstant(Val == 0, VT); |
| 1096 | case MVT::i8: |
| 1097 | Tmp1 = (unsigned)Val | 0x100; |
| 1098 | return getConstant(CountTrailingZeros_32(Tmp1), VT); |
| 1099 | case MVT::i16: |
| 1100 | Tmp1 = (unsigned)Val | 0x10000; |
| 1101 | return getConstant(CountTrailingZeros_32(Tmp1), VT); |
| 1102 | case MVT::i32: |
| 1103 | return getConstant(CountTrailingZeros_32((unsigned)Val), VT); |
| 1104 | case MVT::i64: |
| 1105 | return getConstant(CountTrailingZeros_64(Val), VT); |
| 1106 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1107 | } |
| 1108 | } |
| 1109 | |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1110 | // Constant fold unary operations with an floating point constant operand. |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1111 | if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Operand.Val)) |
| 1112 | switch (Opcode) { |
Chris Lattner | 485df9b | 2005-04-09 03:02:46 +0000 | [diff] [blame] | 1113 | case ISD::FNEG: |
| 1114 | return getConstantFP(-C->getValue(), VT); |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1115 | case ISD::FABS: |
| 1116 | return getConstantFP(fabs(C->getValue()), VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1117 | case ISD::FP_ROUND: |
| 1118 | case ISD::FP_EXTEND: |
| 1119 | return getConstantFP(C->getValue(), VT); |
Chris Lattner | ae0aacb | 2005-01-08 08:08:56 +0000 | [diff] [blame] | 1120 | case ISD::FP_TO_SINT: |
| 1121 | return getConstant((int64_t)C->getValue(), VT); |
| 1122 | case ISD::FP_TO_UINT: |
| 1123 | return getConstant((uint64_t)C->getValue(), VT); |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1124 | case ISD::BIT_CONVERT: |
Chris Lattner | e8a30fd | 2006-03-24 02:20:47 +0000 | [diff] [blame] | 1125 | if (VT == MVT::i32 && C->getValueType(0) == MVT::f32) |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1126 | return getConstant(FloatToBits(C->getValue()), VT); |
Chris Lattner | e8a30fd | 2006-03-24 02:20:47 +0000 | [diff] [blame] | 1127 | else if (VT == MVT::i64 && C->getValueType(0) == MVT::f64) |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1128 | return getConstant(DoubleToBits(C->getValue()), VT); |
Chris Lattner | 9468377 | 2005-12-23 05:30:37 +0000 | [diff] [blame] | 1129 | break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1130 | } |
| 1131 | |
| 1132 | unsigned OpOpcode = Operand.Val->getOpcode(); |
| 1133 | switch (Opcode) { |
Chris Lattner | a93ec3e | 2005-01-21 18:01:22 +0000 | [diff] [blame] | 1134 | case ISD::TokenFactor: |
| 1135 | return Operand; // Factor of one node? No factor. |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1136 | case ISD::SIGN_EXTEND: |
| 1137 | if (Operand.getValueType() == VT) return Operand; // noop extension |
Nate Begeman | b0d04a7 | 2006-02-18 02:40:58 +0000 | [diff] [blame] | 1138 | assert(Operand.getValueType() < VT && "Invalid sext node, dst < src!"); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1139 | if (OpOpcode == ISD::SIGN_EXTEND || OpOpcode == ISD::ZERO_EXTEND) |
| 1140 | return getNode(OpOpcode, VT, Operand.Val->getOperand(0)); |
| 1141 | break; |
| 1142 | case ISD::ZERO_EXTEND: |
| 1143 | if (Operand.getValueType() == VT) return Operand; // noop extension |
Nate Begeman | b0d04a7 | 2006-02-18 02:40:58 +0000 | [diff] [blame] | 1144 | assert(Operand.getValueType() < VT && "Invalid zext node, dst < src!"); |
Chris Lattner | 5a6bace | 2005-04-07 19:43:53 +0000 | [diff] [blame] | 1145 | if (OpOpcode == ISD::ZERO_EXTEND) // (zext (zext x)) -> (zext x) |
Chris Lattner | 2f0ca79 | 2005-01-12 18:51:15 +0000 | [diff] [blame] | 1146 | return getNode(ISD::ZERO_EXTEND, VT, Operand.Val->getOperand(0)); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1147 | break; |
Chris Lattner | 4ed11b4 | 2005-09-02 00:17:32 +0000 | [diff] [blame] | 1148 | case ISD::ANY_EXTEND: |
| 1149 | if (Operand.getValueType() == VT) return Operand; // noop extension |
Nate Begeman | b0d04a7 | 2006-02-18 02:40:58 +0000 | [diff] [blame] | 1150 | assert(Operand.getValueType() < VT && "Invalid anyext node, dst < src!"); |
Chris Lattner | 4ed11b4 | 2005-09-02 00:17:32 +0000 | [diff] [blame] | 1151 | if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND) |
| 1152 | // (ext (zext x)) -> (zext x) and (ext (sext x)) -> (sext x) |
| 1153 | return getNode(OpOpcode, VT, Operand.Val->getOperand(0)); |
| 1154 | break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1155 | case ISD::TRUNCATE: |
| 1156 | if (Operand.getValueType() == VT) return Operand; // noop truncate |
Nate Begeman | b0d04a7 | 2006-02-18 02:40:58 +0000 | [diff] [blame] | 1157 | assert(Operand.getValueType() > VT && "Invalid truncate node, src < dst!"); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1158 | if (OpOpcode == ISD::TRUNCATE) |
| 1159 | return getNode(ISD::TRUNCATE, VT, Operand.Val->getOperand(0)); |
Chris Lattner | 4ed11b4 | 2005-09-02 00:17:32 +0000 | [diff] [blame] | 1160 | else if (OpOpcode == ISD::ZERO_EXTEND || OpOpcode == ISD::SIGN_EXTEND || |
| 1161 | OpOpcode == ISD::ANY_EXTEND) { |
Chris Lattner | fd8c39b | 2005-01-07 21:56:24 +0000 | [diff] [blame] | 1162 | // If the source is smaller than the dest, we still need an extend. |
| 1163 | if (Operand.Val->getOperand(0).getValueType() < VT) |
| 1164 | return getNode(OpOpcode, VT, Operand.Val->getOperand(0)); |
| 1165 | else if (Operand.Val->getOperand(0).getValueType() > VT) |
| 1166 | return getNode(ISD::TRUNCATE, VT, Operand.Val->getOperand(0)); |
| 1167 | else |
| 1168 | return Operand.Val->getOperand(0); |
| 1169 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1170 | break; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 1171 | case ISD::BIT_CONVERT: |
| 1172 | // Basic sanity checking. |
Chris Lattner | 70c2a61 | 2006-03-31 02:06:56 +0000 | [diff] [blame] | 1173 | assert(MVT::getSizeInBits(VT) == MVT::getSizeInBits(Operand.getValueType()) |
Chris Lattner | 28b5b1c | 2006-03-15 22:19:46 +0000 | [diff] [blame] | 1174 | && "Cannot BIT_CONVERT between two different types!"); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 1175 | if (VT == Operand.getValueType()) return Operand; // noop conversion. |
Chris Lattner | c8547d8 | 2005-12-23 05:37:50 +0000 | [diff] [blame] | 1176 | if (OpOpcode == ISD::BIT_CONVERT) // bitconv(bitconv(x)) -> bitconv(x) |
| 1177 | return getNode(ISD::BIT_CONVERT, VT, Operand.getOperand(0)); |
Chris Lattner | 08da55e | 2006-04-04 01:02:22 +0000 | [diff] [blame] | 1178 | if (OpOpcode == ISD::UNDEF) |
| 1179 | return getNode(ISD::UNDEF, VT); |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 1180 | break; |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1181 | case ISD::SCALAR_TO_VECTOR: |
| 1182 | assert(MVT::isVector(VT) && !MVT::isVector(Operand.getValueType()) && |
| 1183 | MVT::getVectorBaseType(VT) == Operand.getValueType() && |
| 1184 | "Illegal SCALAR_TO_VECTOR node!"); |
| 1185 | break; |
Chris Lattner | 485df9b | 2005-04-09 03:02:46 +0000 | [diff] [blame] | 1186 | case ISD::FNEG: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 1187 | if (OpOpcode == ISD::FSUB) // -(X-Y) -> (Y-X) |
| 1188 | return getNode(ISD::FSUB, VT, Operand.Val->getOperand(1), |
Chris Lattner | 485df9b | 2005-04-09 03:02:46 +0000 | [diff] [blame] | 1189 | Operand.Val->getOperand(0)); |
| 1190 | if (OpOpcode == ISD::FNEG) // --X -> X |
| 1191 | return Operand.Val->getOperand(0); |
| 1192 | break; |
| 1193 | case ISD::FABS: |
| 1194 | if (OpOpcode == ISD::FNEG) // abs(-X) -> abs(X) |
| 1195 | return getNode(ISD::FABS, VT, Operand.Val->getOperand(0)); |
| 1196 | break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1197 | } |
| 1198 | |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 1199 | SDNode *N; |
| 1200 | if (VT != MVT::Flag) { // Don't CSE flag producing nodes |
| 1201 | SDNode *&E = UnaryOps[std::make_pair(Opcode, std::make_pair(Operand, VT))]; |
Chris Lattner | f07d023 | 2005-08-26 00:13:12 +0000 | [diff] [blame] | 1202 | if (E) return SDOperand(E, 0); |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 1203 | E = N = new SDNode(Opcode, Operand); |
| 1204 | } else { |
| 1205 | N = new SDNode(Opcode, Operand); |
| 1206 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1207 | N->setValueTypes(VT); |
| 1208 | AllNodes.push_back(N); |
| 1209 | return SDOperand(N, 0); |
Chris Lattner | 78ec311 | 2003-08-11 14:57:33 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
Chris Lattner | 36019aa | 2005-04-18 03:48:41 +0000 | [diff] [blame] | 1212 | |
| 1213 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1214 | SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT, |
| 1215 | SDOperand N1, SDOperand N2) { |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 1216 | #ifndef NDEBUG |
| 1217 | switch (Opcode) { |
Chris Lattner | 39908e0 | 2005-01-19 18:01:40 +0000 | [diff] [blame] | 1218 | case ISD::TokenFactor: |
| 1219 | assert(VT == MVT::Other && N1.getValueType() == MVT::Other && |
| 1220 | N2.getValueType() == MVT::Other && "Invalid token factor!"); |
| 1221 | break; |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 1222 | case ISD::AND: |
| 1223 | case ISD::OR: |
| 1224 | case ISD::XOR: |
| 1225 | case ISD::UDIV: |
| 1226 | case ISD::UREM: |
Chris Lattner | e5eb6f8 | 2005-05-15 05:39:08 +0000 | [diff] [blame] | 1227 | case ISD::MULHU: |
| 1228 | case ISD::MULHS: |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 1229 | assert(MVT::isInteger(VT) && "This operator does not apply to FP types!"); |
| 1230 | // fall through |
| 1231 | case ISD::ADD: |
| 1232 | case ISD::SUB: |
| 1233 | case ISD::MUL: |
| 1234 | case ISD::SDIV: |
| 1235 | case ISD::SREM: |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 1236 | assert(MVT::isInteger(N1.getValueType()) && "Should use F* for FP ops"); |
| 1237 | // fall through. |
| 1238 | case ISD::FADD: |
| 1239 | case ISD::FSUB: |
| 1240 | case ISD::FMUL: |
| 1241 | case ISD::FDIV: |
| 1242 | case ISD::FREM: |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 1243 | assert(N1.getValueType() == N2.getValueType() && |
| 1244 | N1.getValueType() == VT && "Binary operator types must match!"); |
| 1245 | break; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 1246 | case ISD::FCOPYSIGN: // N1 and result must match. N1/N2 need not match. |
| 1247 | assert(N1.getValueType() == VT && |
| 1248 | MVT::isFloatingPoint(N1.getValueType()) && |
| 1249 | MVT::isFloatingPoint(N2.getValueType()) && |
| 1250 | "Invalid FCOPYSIGN!"); |
| 1251 | break; |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 1252 | case ISD::SHL: |
| 1253 | case ISD::SRA: |
| 1254 | case ISD::SRL: |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 1255 | case ISD::ROTL: |
| 1256 | case ISD::ROTR: |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 1257 | assert(VT == N1.getValueType() && |
| 1258 | "Shift operators return type must be the same as their first arg"); |
| 1259 | assert(MVT::isInteger(VT) && MVT::isInteger(N2.getValueType()) && |
Chris Lattner | 068a81e | 2005-01-17 17:15:02 +0000 | [diff] [blame] | 1260 | VT != MVT::i1 && "Shifts only work on integers"); |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 1261 | break; |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1262 | case ISD::FP_ROUND_INREG: { |
| 1263 | MVT::ValueType EVT = cast<VTSDNode>(N2)->getVT(); |
| 1264 | assert(VT == N1.getValueType() && "Not an inreg round!"); |
| 1265 | assert(MVT::isFloatingPoint(VT) && MVT::isFloatingPoint(EVT) && |
| 1266 | "Cannot FP_ROUND_INREG integer types"); |
| 1267 | assert(EVT <= VT && "Not rounding down!"); |
| 1268 | break; |
| 1269 | } |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 1270 | case ISD::AssertSext: |
| 1271 | case ISD::AssertZext: |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1272 | case ISD::SIGN_EXTEND_INREG: { |
| 1273 | MVT::ValueType EVT = cast<VTSDNode>(N2)->getVT(); |
| 1274 | assert(VT == N1.getValueType() && "Not an inreg extend!"); |
| 1275 | assert(MVT::isInteger(VT) && MVT::isInteger(EVT) && |
| 1276 | "Cannot *_EXTEND_INREG FP types"); |
| 1277 | assert(EVT <= VT && "Not extending!"); |
| 1278 | } |
| 1279 | |
Chris Lattner | 7636512 | 2005-01-16 02:23:22 +0000 | [diff] [blame] | 1280 | default: break; |
| 1281 | } |
| 1282 | #endif |
| 1283 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1284 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val); |
| 1285 | ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2.Val); |
| 1286 | if (N1C) { |
| 1287 | if (N2C) { |
| 1288 | uint64_t C1 = N1C->getValue(), C2 = N2C->getValue(); |
| 1289 | switch (Opcode) { |
| 1290 | case ISD::ADD: return getConstant(C1 + C2, VT); |
| 1291 | case ISD::SUB: return getConstant(C1 - C2, VT); |
| 1292 | case ISD::MUL: return getConstant(C1 * C2, VT); |
| 1293 | case ISD::UDIV: |
| 1294 | if (C2) return getConstant(C1 / C2, VT); |
| 1295 | break; |
| 1296 | case ISD::UREM : |
| 1297 | if (C2) return getConstant(C1 % C2, VT); |
| 1298 | break; |
| 1299 | case ISD::SDIV : |
| 1300 | if (C2) return getConstant(N1C->getSignExtended() / |
| 1301 | N2C->getSignExtended(), VT); |
| 1302 | break; |
| 1303 | case ISD::SREM : |
| 1304 | if (C2) return getConstant(N1C->getSignExtended() % |
| 1305 | N2C->getSignExtended(), VT); |
| 1306 | break; |
| 1307 | case ISD::AND : return getConstant(C1 & C2, VT); |
| 1308 | case ISD::OR : return getConstant(C1 | C2, VT); |
| 1309 | case ISD::XOR : return getConstant(C1 ^ C2, VT); |
Nate Begeman | b85dfab | 2005-08-31 00:27:53 +0000 | [diff] [blame] | 1310 | case ISD::SHL : return getConstant(C1 << C2, VT); |
| 1311 | case ISD::SRL : return getConstant(C1 >> C2, VT); |
Chris Lattner | 8136d1f | 2005-01-10 00:07:15 +0000 | [diff] [blame] | 1312 | case ISD::SRA : return getConstant(N1C->getSignExtended() >>(int)C2, VT); |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 1313 | case ISD::ROTL : |
| 1314 | return getConstant((C1 << C2) | (C1 >> (MVT::getSizeInBits(VT) - C2)), |
| 1315 | VT); |
| 1316 | case ISD::ROTR : |
| 1317 | return getConstant((C1 >> C2) | (C1 << (MVT::getSizeInBits(VT) - C2)), |
| 1318 | VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1319 | default: break; |
| 1320 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1321 | } else { // Cannonicalize constant to RHS if commutative |
| 1322 | if (isCommutativeBinOp(Opcode)) { |
| 1323 | std::swap(N1C, N2C); |
| 1324 | std::swap(N1, N2); |
| 1325 | } |
| 1326 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | ConstantFPSDNode *N1CFP = dyn_cast<ConstantFPSDNode>(N1.Val); |
| 1330 | ConstantFPSDNode *N2CFP = dyn_cast<ConstantFPSDNode>(N2.Val); |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1331 | if (N1CFP) { |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1332 | if (N2CFP) { |
| 1333 | double C1 = N1CFP->getValue(), C2 = N2CFP->getValue(); |
| 1334 | switch (Opcode) { |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 1335 | case ISD::FADD: return getConstantFP(C1 + C2, VT); |
| 1336 | case ISD::FSUB: return getConstantFP(C1 - C2, VT); |
| 1337 | case ISD::FMUL: return getConstantFP(C1 * C2, VT); |
| 1338 | case ISD::FDIV: |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1339 | if (C2) return getConstantFP(C1 / C2, VT); |
| 1340 | break; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 1341 | case ISD::FREM : |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1342 | if (C2) return getConstantFP(fmod(C1, C2), VT); |
| 1343 | break; |
Chris Lattner | 3c232c8 | 2006-03-05 23:57:58 +0000 | [diff] [blame] | 1344 | case ISD::FCOPYSIGN: { |
| 1345 | union { |
| 1346 | double F; |
| 1347 | uint64_t I; |
| 1348 | } u1; |
| 1349 | union { |
| 1350 | double F; |
| 1351 | int64_t I; |
| 1352 | } u2; |
| 1353 | u1.F = C1; |
| 1354 | u2.F = C2; |
| 1355 | if (u2.I < 0) // Sign bit of RHS set? |
| 1356 | u1.I |= 1ULL << 63; // Set the sign bit of the LHS. |
| 1357 | else |
| 1358 | u1.I &= (1ULL << 63)-1; // Clear the sign bit of the LHS. |
| 1359 | return getConstantFP(u1.F, VT); |
| 1360 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1361 | default: break; |
| 1362 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1363 | } else { // Cannonicalize constant to RHS if commutative |
| 1364 | if (isCommutativeBinOp(Opcode)) { |
| 1365 | std::swap(N1CFP, N2CFP); |
| 1366 | std::swap(N1, N2); |
| 1367 | } |
| 1368 | } |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1369 | } |
| 1370 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1371 | // Finally, fold operations that do not require constants. |
| 1372 | switch (Opcode) { |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1373 | case ISD::FP_ROUND_INREG: |
| 1374 | if (cast<VTSDNode>(N2)->getVT() == VT) return N1; // Not actually rounding. |
| 1375 | break; |
| 1376 | case ISD::SIGN_EXTEND_INREG: { |
| 1377 | MVT::ValueType EVT = cast<VTSDNode>(N2)->getVT(); |
| 1378 | if (EVT == VT) return N1; // Not actually extending |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1379 | break; |
| 1380 | } |
| 1381 | |
Nate Begeman | eea805e | 2005-04-13 21:23:31 +0000 | [diff] [blame] | 1382 | // FIXME: figure out how to safely handle things like |
| 1383 | // int foo(int x) { return 1 << (x & 255); } |
| 1384 | // int bar() { return foo(256); } |
| 1385 | #if 0 |
Nate Begeman | db81eba | 2005-04-12 23:32:28 +0000 | [diff] [blame] | 1386 | case ISD::SHL: |
| 1387 | case ISD::SRL: |
| 1388 | case ISD::SRA: |
Chris Lattner | e666fcf | 2005-04-13 02:58:13 +0000 | [diff] [blame] | 1389 | if (N2.getOpcode() == ISD::SIGN_EXTEND_INREG && |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1390 | cast<VTSDNode>(N2.getOperand(1))->getVT() != MVT::i1) |
Nate Begeman | db81eba | 2005-04-12 23:32:28 +0000 | [diff] [blame] | 1391 | return getNode(Opcode, VT, N1, N2.getOperand(0)); |
Chris Lattner | e666fcf | 2005-04-13 02:58:13 +0000 | [diff] [blame] | 1392 | else if (N2.getOpcode() == ISD::AND) |
| 1393 | if (ConstantSDNode *AndRHS = dyn_cast<ConstantSDNode>(N2.getOperand(1))) { |
| 1394 | // If the and is only masking out bits that cannot effect the shift, |
| 1395 | // eliminate the and. |
| 1396 | unsigned NumBits = MVT::getSizeInBits(VT); |
| 1397 | if ((AndRHS->getValue() & (NumBits-1)) == NumBits-1) |
| 1398 | return getNode(Opcode, VT, N1, N2.getOperand(0)); |
| 1399 | } |
Nate Begeman | db81eba | 2005-04-12 23:32:28 +0000 | [diff] [blame] | 1400 | break; |
Nate Begeman | eea805e | 2005-04-13 21:23:31 +0000 | [diff] [blame] | 1401 | #endif |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
Chris Lattner | 27e9b41 | 2005-05-11 18:57:39 +0000 | [diff] [blame] | 1404 | // Memoize this node if possible. |
| 1405 | SDNode *N; |
Chris Lattner | 70814bc | 2006-01-29 07:58:15 +0000 | [diff] [blame] | 1406 | if (VT != MVT::Flag) { |
Chris Lattner | 27e9b41 | 2005-05-11 18:57:39 +0000 | [diff] [blame] | 1407 | SDNode *&BON = BinaryOps[std::make_pair(Opcode, std::make_pair(N1, N2))]; |
| 1408 | if (BON) return SDOperand(BON, 0); |
| 1409 | |
| 1410 | BON = N = new SDNode(Opcode, N1, N2); |
| 1411 | } else { |
Chris Lattner | 88de6e7 | 2005-05-12 00:17:04 +0000 | [diff] [blame] | 1412 | N = new SDNode(Opcode, N1, N2); |
Chris Lattner | 27e9b41 | 2005-05-11 18:57:39 +0000 | [diff] [blame] | 1413 | } |
| 1414 | |
Chris Lattner | 3e01136 | 2005-05-14 07:45:46 +0000 | [diff] [blame] | 1415 | N->setValueTypes(VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1416 | AllNodes.push_back(N); |
| 1417 | return SDOperand(N, 0); |
| 1418 | } |
| 1419 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1420 | SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT, |
| 1421 | SDOperand N1, SDOperand N2, SDOperand N3) { |
| 1422 | // Perform various simplifications. |
| 1423 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val); |
| 1424 | ConstantSDNode *N2C = dyn_cast<ConstantSDNode>(N2.Val); |
| 1425 | ConstantSDNode *N3C = dyn_cast<ConstantSDNode>(N3.Val); |
| 1426 | switch (Opcode) { |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1427 | case ISD::SETCC: { |
| 1428 | // Use SimplifySetCC to simplify SETCC's. |
Chris Lattner | bd8625b | 2005-08-09 23:09:05 +0000 | [diff] [blame] | 1429 | SDOperand Simp = SimplifySetCC(VT, N1, N2, cast<CondCodeSDNode>(N3)->get()); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 1430 | if (Simp.Val) return Simp; |
| 1431 | break; |
| 1432 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1433 | case ISD::SELECT: |
| 1434 | if (N1C) |
| 1435 | if (N1C->getValue()) |
| 1436 | return N2; // select true, X, Y -> X |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 1437 | else |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1438 | return N3; // select false, X, Y -> Y |
| 1439 | |
| 1440 | if (N2 == N3) return N2; // select C, X, X -> X |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1441 | break; |
Chris Lattner | 5351e9b | 2005-01-07 22:49:57 +0000 | [diff] [blame] | 1442 | case ISD::BRCOND: |
| 1443 | if (N2C) |
| 1444 | if (N2C->getValue()) // Unconditional branch |
| 1445 | return getNode(ISD::BR, MVT::Other, N1, N3); |
| 1446 | else |
| 1447 | return N1; // Never-taken branch |
Chris Lattner | 7c68ec6 | 2005-01-07 23:32:00 +0000 | [diff] [blame] | 1448 | break; |
Chris Lattner | fb194b9 | 2006-03-19 23:56:04 +0000 | [diff] [blame] | 1449 | case ISD::VECTOR_SHUFFLE: |
| 1450 | assert(VT == N1.getValueType() && VT == N2.getValueType() && |
| 1451 | MVT::isVector(VT) && MVT::isVector(N3.getValueType()) && |
| 1452 | N3.getOpcode() == ISD::BUILD_VECTOR && |
| 1453 | MVT::getVectorNumElements(VT) == N3.getNumOperands() && |
| 1454 | "Illegal VECTOR_SHUFFLE node!"); |
| 1455 | break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1456 | } |
| 1457 | |
Chris Lattner | 385328c | 2005-05-14 07:42:29 +0000 | [diff] [blame] | 1458 | std::vector<SDOperand> Ops; |
| 1459 | Ops.reserve(3); |
| 1460 | Ops.push_back(N1); |
| 1461 | Ops.push_back(N2); |
| 1462 | Ops.push_back(N3); |
| 1463 | |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 1464 | // Memoize node if it doesn't produce a flag. |
| 1465 | SDNode *N; |
| 1466 | if (VT != MVT::Flag) { |
| 1467 | SDNode *&E = OneResultNodes[std::make_pair(Opcode,std::make_pair(VT, Ops))]; |
| 1468 | if (E) return SDOperand(E, 0); |
| 1469 | E = N = new SDNode(Opcode, N1, N2, N3); |
| 1470 | } else { |
| 1471 | N = new SDNode(Opcode, N1, N2, N3); |
| 1472 | } |
Chris Lattner | adf6c2a | 2005-05-14 07:29:57 +0000 | [diff] [blame] | 1473 | N->setValueTypes(VT); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1474 | AllNodes.push_back(N); |
| 1475 | return SDOperand(N, 0); |
| 1476 | } |
| 1477 | |
| 1478 | SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT, |
Jeff Cohen | 00b16889 | 2005-07-27 06:12:32 +0000 | [diff] [blame] | 1479 | SDOperand N1, SDOperand N2, SDOperand N3, |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1480 | SDOperand N4) { |
Chris Lattner | b7f7d51 | 2005-05-14 07:32:14 +0000 | [diff] [blame] | 1481 | std::vector<SDOperand> Ops; |
| 1482 | Ops.reserve(4); |
| 1483 | Ops.push_back(N1); |
| 1484 | Ops.push_back(N2); |
| 1485 | Ops.push_back(N3); |
| 1486 | Ops.push_back(N4); |
| 1487 | return getNode(Opcode, VT, Ops); |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1488 | } |
| 1489 | |
Chris Lattner | 9fadb4c | 2005-07-10 00:29:18 +0000 | [diff] [blame] | 1490 | SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT, |
| 1491 | SDOperand N1, SDOperand N2, SDOperand N3, |
| 1492 | SDOperand N4, SDOperand N5) { |
| 1493 | std::vector<SDOperand> Ops; |
| 1494 | Ops.reserve(5); |
| 1495 | Ops.push_back(N1); |
| 1496 | Ops.push_back(N2); |
| 1497 | Ops.push_back(N3); |
| 1498 | Ops.push_back(N4); |
| 1499 | Ops.push_back(N5); |
| 1500 | return getNode(Opcode, VT, Ops); |
| 1501 | } |
| 1502 | |
Evan Cheng | 7038daf | 2005-12-10 00:37:58 +0000 | [diff] [blame] | 1503 | SDOperand SelectionDAG::getLoad(MVT::ValueType VT, |
| 1504 | SDOperand Chain, SDOperand Ptr, |
| 1505 | SDOperand SV) { |
| 1506 | SDNode *&N = Loads[std::make_pair(Ptr, std::make_pair(Chain, VT))]; |
| 1507 | if (N) return SDOperand(N, 0); |
| 1508 | N = new SDNode(ISD::LOAD, Chain, Ptr, SV); |
| 1509 | |
| 1510 | // Loads have a token chain. |
| 1511 | setNodeValueTypes(N, VT, MVT::Other); |
| 1512 | AllNodes.push_back(N); |
| 1513 | return SDOperand(N, 0); |
| 1514 | } |
| 1515 | |
| 1516 | SDOperand SelectionDAG::getVecLoad(unsigned Count, MVT::ValueType EVT, |
| 1517 | SDOperand Chain, SDOperand Ptr, |
| 1518 | SDOperand SV) { |
Evan Cheng | 7038daf | 2005-12-10 00:37:58 +0000 | [diff] [blame] | 1519 | std::vector<SDOperand> Ops; |
| 1520 | Ops.reserve(5); |
Evan Cheng | 1ab7d85 | 2006-03-01 00:51:13 +0000 | [diff] [blame] | 1521 | Ops.push_back(Chain); |
| 1522 | Ops.push_back(Ptr); |
Evan Cheng | 7038daf | 2005-12-10 00:37:58 +0000 | [diff] [blame] | 1523 | Ops.push_back(SV); |
Chris Lattner | c702980 | 2006-03-18 01:44:44 +0000 | [diff] [blame] | 1524 | Ops.push_back(getConstant(Count, MVT::i32)); |
| 1525 | Ops.push_back(getValueType(EVT)); |
Evan Cheng | 7038daf | 2005-12-10 00:37:58 +0000 | [diff] [blame] | 1526 | std::vector<MVT::ValueType> VTs; |
| 1527 | VTs.reserve(2); |
| 1528 | VTs.push_back(MVT::Vector); VTs.push_back(MVT::Other); // Add token chain. |
| 1529 | return getNode(ISD::VLOAD, VTs, Ops); |
| 1530 | } |
| 1531 | |
| 1532 | SDOperand SelectionDAG::getExtLoad(unsigned Opcode, MVT::ValueType VT, |
| 1533 | SDOperand Chain, SDOperand Ptr, SDOperand SV, |
| 1534 | MVT::ValueType EVT) { |
| 1535 | std::vector<SDOperand> Ops; |
| 1536 | Ops.reserve(4); |
| 1537 | Ops.push_back(Chain); |
| 1538 | Ops.push_back(Ptr); |
| 1539 | Ops.push_back(SV); |
| 1540 | Ops.push_back(getValueType(EVT)); |
| 1541 | std::vector<MVT::ValueType> VTs; |
| 1542 | VTs.reserve(2); |
| 1543 | VTs.push_back(VT); VTs.push_back(MVT::Other); // Add token chain. |
| 1544 | return getNode(Opcode, VTs, Ops); |
| 1545 | } |
Chris Lattner | 9fadb4c | 2005-07-10 00:29:18 +0000 | [diff] [blame] | 1546 | |
Chris Lattner | 0437cdd | 2005-05-09 04:14:13 +0000 | [diff] [blame] | 1547 | SDOperand SelectionDAG::getSrcValue(const Value *V, int Offset) { |
Andrew Lenharth | 06ef884 | 2005-06-29 18:54:02 +0000 | [diff] [blame] | 1548 | assert((!V || isa<PointerType>(V->getType())) && |
| 1549 | "SrcValue is not a pointer?"); |
Chris Lattner | 0437cdd | 2005-05-09 04:14:13 +0000 | [diff] [blame] | 1550 | SDNode *&N = ValueNodes[std::make_pair(V, Offset)]; |
| 1551 | if (N) return SDOperand(N, 0); |
| 1552 | |
| 1553 | N = new SrcValueSDNode(V, Offset); |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1554 | AllNodes.push_back(N); |
| 1555 | return SDOperand(N, 0); |
| 1556 | } |
| 1557 | |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 1558 | SDOperand SelectionDAG::getVAArg(MVT::ValueType VT, |
| 1559 | SDOperand Chain, SDOperand Ptr, |
| 1560 | SDOperand SV) { |
| 1561 | std::vector<SDOperand> Ops; |
| 1562 | Ops.reserve(3); |
| 1563 | Ops.push_back(Chain); |
| 1564 | Ops.push_back(Ptr); |
| 1565 | Ops.push_back(SV); |
| 1566 | std::vector<MVT::ValueType> VTs; |
| 1567 | VTs.reserve(2); |
| 1568 | VTs.push_back(VT); VTs.push_back(MVT::Other); // Add token chain. |
| 1569 | return getNode(ISD::VAARG, VTs, Ops); |
| 1570 | } |
| 1571 | |
Andrew Lenharth | 2d86ea2 | 2005-04-27 20:10:01 +0000 | [diff] [blame] | 1572 | SDOperand SelectionDAG::getNode(unsigned Opcode, MVT::ValueType VT, |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 1573 | std::vector<SDOperand> &Ops) { |
| 1574 | switch (Ops.size()) { |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1575 | case 0: return getNode(Opcode, VT); |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 1576 | case 1: return getNode(Opcode, VT, Ops[0]); |
| 1577 | case 2: return getNode(Opcode, VT, Ops[0], Ops[1]); |
| 1578 | case 3: return getNode(Opcode, VT, Ops[0], Ops[1], Ops[2]); |
Chris Lattner | ef847df | 2005-04-09 03:27:28 +0000 | [diff] [blame] | 1579 | default: break; |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1580 | } |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 1581 | |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 1582 | ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(Ops[1].Val); |
Chris Lattner | ef847df | 2005-04-09 03:27:28 +0000 | [diff] [blame] | 1583 | switch (Opcode) { |
| 1584 | default: break; |
Chris Lattner | 9fadb4c | 2005-07-10 00:29:18 +0000 | [diff] [blame] | 1585 | case ISD::TRUNCSTORE: { |
| 1586 | assert(Ops.size() == 5 && "TRUNCSTORE takes 5 operands!"); |
| 1587 | MVT::ValueType EVT = cast<VTSDNode>(Ops[4])->getVT(); |
| 1588 | #if 0 // FIXME: If the target supports EVT natively, convert to a truncate/store |
| 1589 | // If this is a truncating store of a constant, convert to the desired type |
| 1590 | // and store it instead. |
| 1591 | if (isa<Constant>(Ops[0])) { |
| 1592 | SDOperand Op = getNode(ISD::TRUNCATE, EVT, N1); |
| 1593 | if (isa<Constant>(Op)) |
| 1594 | N1 = Op; |
| 1595 | } |
| 1596 | // Also for ConstantFP? |
| 1597 | #endif |
| 1598 | if (Ops[0].getValueType() == EVT) // Normal store? |
| 1599 | return getNode(ISD::STORE, VT, Ops[0], Ops[1], Ops[2], Ops[3]); |
| 1600 | assert(Ops[1].getValueType() > EVT && "Not a truncation?"); |
| 1601 | assert(MVT::isInteger(Ops[1].getValueType()) == MVT::isInteger(EVT) && |
| 1602 | "Can't do FP-INT conversion!"); |
| 1603 | break; |
| 1604 | } |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 1605 | case ISD::SELECT_CC: { |
Chris Lattner | ad13715 | 2005-10-05 06:37:22 +0000 | [diff] [blame] | 1606 | assert(Ops.size() == 5 && "SELECT_CC takes 5 operands!"); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 1607 | assert(Ops[0].getValueType() == Ops[1].getValueType() && |
| 1608 | "LHS and RHS of condition must have same type!"); |
| 1609 | assert(Ops[2].getValueType() == Ops[3].getValueType() && |
| 1610 | "True and False arms of SelectCC must have same type!"); |
| 1611 | assert(Ops[2].getValueType() == VT && |
| 1612 | "select_cc node must be of same type as true and false value!"); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 1613 | break; |
| 1614 | } |
| 1615 | case ISD::BR_CC: { |
Chris Lattner | ad13715 | 2005-10-05 06:37:22 +0000 | [diff] [blame] | 1616 | assert(Ops.size() == 5 && "BR_CC takes 5 operands!"); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 1617 | assert(Ops[2].getValueType() == Ops[3].getValueType() && |
| 1618 | "LHS/RHS of comparison should match types!"); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 1619 | break; |
| 1620 | } |
Chris Lattner | ef847df | 2005-04-09 03:27:28 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
Chris Lattner | 385328c | 2005-05-14 07:42:29 +0000 | [diff] [blame] | 1623 | // Memoize nodes. |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 1624 | SDNode *N; |
| 1625 | if (VT != MVT::Flag) { |
| 1626 | SDNode *&E = |
| 1627 | OneResultNodes[std::make_pair(Opcode, std::make_pair(VT, Ops))]; |
| 1628 | if (E) return SDOperand(E, 0); |
| 1629 | E = N = new SDNode(Opcode, Ops); |
| 1630 | } else { |
| 1631 | N = new SDNode(Opcode, Ops); |
| 1632 | } |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 1633 | N->setValueTypes(VT); |
Chris Lattner | ef847df | 2005-04-09 03:27:28 +0000 | [diff] [blame] | 1634 | AllNodes.push_back(N); |
| 1635 | return SDOperand(N, 0); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 1638 | SDOperand SelectionDAG::getNode(unsigned Opcode, |
| 1639 | std::vector<MVT::ValueType> &ResultTys, |
| 1640 | std::vector<SDOperand> &Ops) { |
| 1641 | if (ResultTys.size() == 1) |
| 1642 | return getNode(Opcode, ResultTys[0], Ops); |
| 1643 | |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 1644 | switch (Opcode) { |
| 1645 | case ISD::EXTLOAD: |
| 1646 | case ISD::SEXTLOAD: |
| 1647 | case ISD::ZEXTLOAD: { |
| 1648 | MVT::ValueType EVT = cast<VTSDNode>(Ops[3])->getVT(); |
| 1649 | assert(Ops.size() == 4 && ResultTys.size() == 2 && "Bad *EXTLOAD!"); |
| 1650 | // If they are asking for an extending load from/to the same thing, return a |
| 1651 | // normal load. |
| 1652 | if (ResultTys[0] == EVT) |
| 1653 | return getLoad(ResultTys[0], Ops[0], Ops[1], Ops[2]); |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1654 | if (MVT::isVector(ResultTys[0])) { |
| 1655 | assert(EVT == MVT::getVectorBaseType(ResultTys[0]) && |
| 1656 | "Invalid vector extload!"); |
| 1657 | } else { |
| 1658 | assert(EVT < ResultTys[0] && |
| 1659 | "Should only be an extending load, not truncating!"); |
| 1660 | } |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 1661 | assert((Opcode == ISD::EXTLOAD || MVT::isInteger(ResultTys[0])) && |
Chris Lattner | ce87215 | 2006-03-19 06:31:19 +0000 | [diff] [blame] | 1662 | "Cannot sign/zero extend a FP/Vector load!"); |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 1663 | assert(MVT::isInteger(ResultTys[0]) == MVT::isInteger(EVT) && |
| 1664 | "Cannot convert from FP to Int or Int -> FP!"); |
| 1665 | break; |
| 1666 | } |
| 1667 | |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 1668 | // FIXME: figure out how to safely handle things like |
| 1669 | // int foo(int x) { return 1 << (x & 255); } |
| 1670 | // int bar() { return foo(256); } |
| 1671 | #if 0 |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 1672 | case ISD::SRA_PARTS: |
| 1673 | case ISD::SRL_PARTS: |
| 1674 | case ISD::SHL_PARTS: |
| 1675 | if (N3.getOpcode() == ISD::SIGN_EXTEND_INREG && |
Chris Lattner | 15e4b01 | 2005-07-10 00:07:11 +0000 | [diff] [blame] | 1676 | cast<VTSDNode>(N3.getOperand(1))->getVT() != MVT::i1) |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 1677 | return getNode(Opcode, VT, N1, N2, N3.getOperand(0)); |
| 1678 | else if (N3.getOpcode() == ISD::AND) |
| 1679 | if (ConstantSDNode *AndRHS = dyn_cast<ConstantSDNode>(N3.getOperand(1))) { |
| 1680 | // If the and is only masking out bits that cannot effect the shift, |
| 1681 | // eliminate the and. |
| 1682 | unsigned NumBits = MVT::getSizeInBits(VT)*2; |
| 1683 | if ((AndRHS->getValue() & (NumBits-1)) == NumBits-1) |
| 1684 | return getNode(Opcode, VT, N1, N2, N3.getOperand(0)); |
| 1685 | } |
| 1686 | break; |
Chris Lattner | e89083a | 2005-05-14 07:25:05 +0000 | [diff] [blame] | 1687 | #endif |
Chris Lattner | 5f056bf | 2005-07-10 01:55:33 +0000 | [diff] [blame] | 1688 | } |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 1689 | |
Chris Lattner | 43247a1 | 2005-08-25 19:12:10 +0000 | [diff] [blame] | 1690 | // Memoize the node unless it returns a flag. |
| 1691 | SDNode *N; |
| 1692 | if (ResultTys.back() != MVT::Flag) { |
| 1693 | SDNode *&E = |
| 1694 | ArbitraryNodes[std::make_pair(Opcode, std::make_pair(ResultTys, Ops))]; |
| 1695 | if (E) return SDOperand(E, 0); |
| 1696 | E = N = new SDNode(Opcode, Ops); |
| 1697 | } else { |
| 1698 | N = new SDNode(Opcode, Ops); |
| 1699 | } |
Chris Lattner | a325511 | 2005-11-08 23:30:28 +0000 | [diff] [blame] | 1700 | setNodeValueTypes(N, ResultTys); |
Chris Lattner | 5fa4fa4 | 2005-05-14 06:42:57 +0000 | [diff] [blame] | 1701 | AllNodes.push_back(N); |
Chris Lattner | 89c3463 | 2005-05-14 06:20:26 +0000 | [diff] [blame] | 1702 | return SDOperand(N, 0); |
| 1703 | } |
| 1704 | |
Chris Lattner | a325511 | 2005-11-08 23:30:28 +0000 | [diff] [blame] | 1705 | void SelectionDAG::setNodeValueTypes(SDNode *N, |
| 1706 | std::vector<MVT::ValueType> &RetVals) { |
| 1707 | switch (RetVals.size()) { |
| 1708 | case 0: return; |
| 1709 | case 1: N->setValueTypes(RetVals[0]); return; |
| 1710 | case 2: setNodeValueTypes(N, RetVals[0], RetVals[1]); return; |
| 1711 | default: break; |
| 1712 | } |
| 1713 | |
| 1714 | std::list<std::vector<MVT::ValueType> >::iterator I = |
| 1715 | std::find(VTList.begin(), VTList.end(), RetVals); |
| 1716 | if (I == VTList.end()) { |
| 1717 | VTList.push_front(RetVals); |
| 1718 | I = VTList.begin(); |
| 1719 | } |
| 1720 | |
| 1721 | N->setValueTypes(&(*I)[0], I->size()); |
| 1722 | } |
| 1723 | |
| 1724 | void SelectionDAG::setNodeValueTypes(SDNode *N, MVT::ValueType VT1, |
| 1725 | MVT::ValueType VT2) { |
| 1726 | for (std::list<std::vector<MVT::ValueType> >::iterator I = VTList.begin(), |
| 1727 | E = VTList.end(); I != E; ++I) { |
| 1728 | if (I->size() == 2 && (*I)[0] == VT1 && (*I)[1] == VT2) { |
| 1729 | N->setValueTypes(&(*I)[0], 2); |
| 1730 | return; |
| 1731 | } |
| 1732 | } |
| 1733 | std::vector<MVT::ValueType> V; |
| 1734 | V.push_back(VT1); |
| 1735 | V.push_back(VT2); |
| 1736 | VTList.push_front(V); |
| 1737 | N->setValueTypes(&(*VTList.begin())[0], 2); |
| 1738 | } |
| 1739 | |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 1740 | /// UpdateNodeOperands - *Mutate* the specified node in-place to have the |
| 1741 | /// specified operands. If the resultant node already exists in the DAG, |
| 1742 | /// this does not modify the specified node, instead it returns the node that |
| 1743 | /// already exists. If the resultant node does not exist in the DAG, the |
| 1744 | /// input node is returned. As a degenerate case, if you specify the same |
| 1745 | /// input operands as the node already has, the input node is returned. |
| 1746 | SDOperand SelectionDAG:: |
| 1747 | UpdateNodeOperands(SDOperand InN, SDOperand Op) { |
| 1748 | SDNode *N = InN.Val; |
| 1749 | assert(N->getNumOperands() == 1 && "Update with wrong number of operands"); |
| 1750 | |
| 1751 | // Check to see if there is no change. |
| 1752 | if (Op == N->getOperand(0)) return InN; |
| 1753 | |
| 1754 | // See if the modified node already exists. |
| 1755 | SDNode **NewSlot = FindModifiedNodeSlot(N, Op); |
| 1756 | if (NewSlot && *NewSlot) |
| 1757 | return SDOperand(*NewSlot, InN.ResNo); |
| 1758 | |
| 1759 | // Nope it doesn't. Remove the node from it's current place in the maps. |
| 1760 | if (NewSlot) |
| 1761 | RemoveNodeFromCSEMaps(N); |
| 1762 | |
| 1763 | // Now we update the operands. |
| 1764 | N->OperandList[0].Val->removeUser(N); |
| 1765 | Op.Val->addUser(N); |
| 1766 | N->OperandList[0] = Op; |
| 1767 | |
| 1768 | // If this gets put into a CSE map, add it. |
| 1769 | if (NewSlot) *NewSlot = N; |
| 1770 | return InN; |
| 1771 | } |
| 1772 | |
| 1773 | SDOperand SelectionDAG:: |
| 1774 | UpdateNodeOperands(SDOperand InN, SDOperand Op1, SDOperand Op2) { |
| 1775 | SDNode *N = InN.Val; |
| 1776 | assert(N->getNumOperands() == 2 && "Update with wrong number of operands"); |
| 1777 | |
| 1778 | // Check to see if there is no change. |
| 1779 | bool AnyChange = false; |
| 1780 | if (Op1 == N->getOperand(0) && Op2 == N->getOperand(1)) |
| 1781 | return InN; // No operands changed, just return the input node. |
| 1782 | |
| 1783 | // See if the modified node already exists. |
| 1784 | SDNode **NewSlot = FindModifiedNodeSlot(N, Op1, Op2); |
| 1785 | if (NewSlot && *NewSlot) |
| 1786 | return SDOperand(*NewSlot, InN.ResNo); |
| 1787 | |
| 1788 | // Nope it doesn't. Remove the node from it's current place in the maps. |
| 1789 | if (NewSlot) |
| 1790 | RemoveNodeFromCSEMaps(N); |
| 1791 | |
| 1792 | // Now we update the operands. |
| 1793 | if (N->OperandList[0] != Op1) { |
| 1794 | N->OperandList[0].Val->removeUser(N); |
| 1795 | Op1.Val->addUser(N); |
| 1796 | N->OperandList[0] = Op1; |
| 1797 | } |
| 1798 | if (N->OperandList[1] != Op2) { |
| 1799 | N->OperandList[1].Val->removeUser(N); |
| 1800 | Op2.Val->addUser(N); |
| 1801 | N->OperandList[1] = Op2; |
| 1802 | } |
| 1803 | |
| 1804 | // If this gets put into a CSE map, add it. |
| 1805 | if (NewSlot) *NewSlot = N; |
| 1806 | return InN; |
| 1807 | } |
| 1808 | |
| 1809 | SDOperand SelectionDAG:: |
| 1810 | UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2, SDOperand Op3) { |
| 1811 | std::vector<SDOperand> Ops; |
| 1812 | Ops.push_back(Op1); |
| 1813 | Ops.push_back(Op2); |
| 1814 | Ops.push_back(Op3); |
| 1815 | return UpdateNodeOperands(N, Ops); |
| 1816 | } |
| 1817 | |
| 1818 | SDOperand SelectionDAG:: |
| 1819 | UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2, |
| 1820 | SDOperand Op3, SDOperand Op4) { |
| 1821 | std::vector<SDOperand> Ops; |
| 1822 | Ops.push_back(Op1); |
| 1823 | Ops.push_back(Op2); |
| 1824 | Ops.push_back(Op3); |
| 1825 | Ops.push_back(Op4); |
| 1826 | return UpdateNodeOperands(N, Ops); |
| 1827 | } |
| 1828 | |
| 1829 | SDOperand SelectionDAG:: |
Chris Lattner | 809ec11 | 2006-01-28 10:09:25 +0000 | [diff] [blame] | 1830 | UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2, |
| 1831 | SDOperand Op3, SDOperand Op4, SDOperand Op5) { |
| 1832 | std::vector<SDOperand> Ops; |
| 1833 | Ops.push_back(Op1); |
| 1834 | Ops.push_back(Op2); |
| 1835 | Ops.push_back(Op3); |
| 1836 | Ops.push_back(Op4); |
| 1837 | Ops.push_back(Op5); |
| 1838 | return UpdateNodeOperands(N, Ops); |
| 1839 | } |
| 1840 | |
| 1841 | |
| 1842 | SDOperand SelectionDAG:: |
Chris Lattner | df6eb30 | 2006-01-28 09:32:45 +0000 | [diff] [blame] | 1843 | UpdateNodeOperands(SDOperand InN, const std::vector<SDOperand> &Ops) { |
| 1844 | SDNode *N = InN.Val; |
| 1845 | assert(N->getNumOperands() == Ops.size() && |
| 1846 | "Update with wrong number of operands"); |
| 1847 | |
| 1848 | // Check to see if there is no change. |
| 1849 | unsigned NumOps = Ops.size(); |
| 1850 | bool AnyChange = false; |
| 1851 | for (unsigned i = 0; i != NumOps; ++i) { |
| 1852 | if (Ops[i] != N->getOperand(i)) { |
| 1853 | AnyChange = true; |
| 1854 | break; |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | // No operands changed, just return the input node. |
| 1859 | if (!AnyChange) return InN; |
| 1860 | |
| 1861 | // See if the modified node already exists. |
| 1862 | SDNode **NewSlot = FindModifiedNodeSlot(N, Ops); |
| 1863 | if (NewSlot && *NewSlot) |
| 1864 | return SDOperand(*NewSlot, InN.ResNo); |
| 1865 | |
| 1866 | // Nope it doesn't. Remove the node from it's current place in the maps. |
| 1867 | if (NewSlot) |
| 1868 | RemoveNodeFromCSEMaps(N); |
| 1869 | |
| 1870 | // Now we update the operands. |
| 1871 | for (unsigned i = 0; i != NumOps; ++i) { |
| 1872 | if (N->OperandList[i] != Ops[i]) { |
| 1873 | N->OperandList[i].Val->removeUser(N); |
| 1874 | Ops[i].Val->addUser(N); |
| 1875 | N->OperandList[i] = Ops[i]; |
| 1876 | } |
| 1877 | } |
| 1878 | |
| 1879 | // If this gets put into a CSE map, add it. |
| 1880 | if (NewSlot) *NewSlot = N; |
| 1881 | return InN; |
| 1882 | } |
| 1883 | |
| 1884 | |
| 1885 | |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 1886 | |
| 1887 | /// SelectNodeTo - These are used for target selectors to *mutate* the |
| 1888 | /// specified node to have the specified return type, Target opcode, and |
| 1889 | /// operands. Note that target opcodes are stored as |
| 1890 | /// ISD::BUILTIN_OP_END+TargetOpcode in the node opcode field. |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1891 | /// |
| 1892 | /// Note that SelectNodeTo returns the resultant node. If there is already a |
| 1893 | /// node of the specified opcode and operands, it returns that node instead of |
| 1894 | /// the current one. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1895 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 1896 | MVT::ValueType VT) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1897 | // If an identical node already exists, use it. |
| 1898 | SDNode *&ON = NullaryOps[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, VT)]; |
| 1899 | if (ON) return SDOperand(ON, 0); |
| 1900 | |
Chris Lattner | 7651fa4 | 2005-08-24 23:00:29 +0000 | [diff] [blame] | 1901 | RemoveNodeFromCSEMaps(N); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1902 | |
Chris Lattner | 7651fa4 | 2005-08-24 23:00:29 +0000 | [diff] [blame] | 1903 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 1904 | N->setValueTypes(VT); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1905 | |
| 1906 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1907 | return SDOperand(N, 0); |
Chris Lattner | 7651fa4 | 2005-08-24 23:00:29 +0000 | [diff] [blame] | 1908 | } |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 1909 | |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1910 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 1911 | MVT::ValueType VT, SDOperand Op1) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1912 | // If an identical node already exists, use it. |
| 1913 | SDNode *&ON = UnaryOps[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 1914 | std::make_pair(Op1, VT))]; |
| 1915 | if (ON) return SDOperand(ON, 0); |
| 1916 | |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 1917 | RemoveNodeFromCSEMaps(N); |
| 1918 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 1919 | N->setValueTypes(VT); |
| 1920 | N->setOperands(Op1); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1921 | |
| 1922 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1923 | return SDOperand(N, 0); |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 1924 | } |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 1925 | |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1926 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 1927 | MVT::ValueType VT, SDOperand Op1, |
| 1928 | SDOperand Op2) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1929 | // If an identical node already exists, use it. |
| 1930 | SDNode *&ON = BinaryOps[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 1931 | std::make_pair(Op1, Op2))]; |
| 1932 | if (ON) return SDOperand(ON, 0); |
| 1933 | |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 1934 | RemoveNodeFromCSEMaps(N); |
| 1935 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 1936 | N->setValueTypes(VT); |
| 1937 | N->setOperands(Op1, Op2); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1938 | |
| 1939 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1940 | return SDOperand(N, 0); |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 1941 | } |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 1942 | |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1943 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 1944 | MVT::ValueType VT, SDOperand Op1, |
| 1945 | SDOperand Op2, SDOperand Op3) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1946 | // If an identical node already exists, use it. |
| 1947 | std::vector<SDOperand> OpList; |
| 1948 | OpList.push_back(Op1); OpList.push_back(Op2); OpList.push_back(Op3); |
| 1949 | SDNode *&ON = OneResultNodes[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 1950 | std::make_pair(VT, OpList))]; |
| 1951 | if (ON) return SDOperand(ON, 0); |
| 1952 | |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 1953 | RemoveNodeFromCSEMaps(N); |
| 1954 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 1955 | N->setValueTypes(VT); |
| 1956 | N->setOperands(Op1, Op2, Op3); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1957 | |
| 1958 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1959 | return SDOperand(N, 0); |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 1960 | } |
Chris Lattner | c975e1d | 2005-08-21 22:30:30 +0000 | [diff] [blame] | 1961 | |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1962 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 1963 | MVT::ValueType VT, SDOperand Op1, |
| 1964 | SDOperand Op2, SDOperand Op3, |
| 1965 | SDOperand Op4) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1966 | // If an identical node already exists, use it. |
| 1967 | std::vector<SDOperand> OpList; |
| 1968 | OpList.push_back(Op1); OpList.push_back(Op2); OpList.push_back(Op3); |
| 1969 | OpList.push_back(Op4); |
| 1970 | SDNode *&ON = OneResultNodes[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 1971 | std::make_pair(VT, OpList))]; |
| 1972 | if (ON) return SDOperand(ON, 0); |
| 1973 | |
Nate Begeman | 294a0a1 | 2005-08-18 07:30:15 +0000 | [diff] [blame] | 1974 | RemoveNodeFromCSEMaps(N); |
| 1975 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 1976 | N->setValueTypes(VT); |
| 1977 | N->setOperands(Op1, Op2, Op3, Op4); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1978 | |
| 1979 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1980 | return SDOperand(N, 0); |
Nate Begeman | 294a0a1 | 2005-08-18 07:30:15 +0000 | [diff] [blame] | 1981 | } |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 1982 | |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 1983 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 1984 | MVT::ValueType VT, SDOperand Op1, |
| 1985 | SDOperand Op2, SDOperand Op3,SDOperand Op4, |
| 1986 | SDOperand Op5) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1987 | // If an identical node already exists, use it. |
| 1988 | std::vector<SDOperand> OpList; |
| 1989 | OpList.push_back(Op1); OpList.push_back(Op2); OpList.push_back(Op3); |
| 1990 | OpList.push_back(Op4); OpList.push_back(Op5); |
| 1991 | SDNode *&ON = OneResultNodes[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 1992 | std::make_pair(VT, OpList))]; |
| 1993 | if (ON) return SDOperand(ON, 0); |
| 1994 | |
Chris Lattner | 6b09a29 | 2005-08-21 18:49:33 +0000 | [diff] [blame] | 1995 | RemoveNodeFromCSEMaps(N); |
| 1996 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 1997 | N->setValueTypes(VT); |
| 1998 | N->setOperands(Op1, Op2, Op3, Op4, Op5); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 1999 | |
| 2000 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2001 | return SDOperand(N, 0); |
Chris Lattner | 6b09a29 | 2005-08-21 18:49:33 +0000 | [diff] [blame] | 2002 | } |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 2003 | |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2004 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 2005 | MVT::ValueType VT, SDOperand Op1, |
| 2006 | SDOperand Op2, SDOperand Op3,SDOperand Op4, |
| 2007 | SDOperand Op5, SDOperand Op6) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 2008 | // If an identical node already exists, use it. |
| 2009 | std::vector<SDOperand> OpList; |
| 2010 | OpList.push_back(Op1); OpList.push_back(Op2); OpList.push_back(Op3); |
| 2011 | OpList.push_back(Op4); OpList.push_back(Op5); OpList.push_back(Op6); |
| 2012 | SDNode *&ON = OneResultNodes[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 2013 | std::make_pair(VT, OpList))]; |
| 2014 | if (ON) return SDOperand(ON, 0); |
| 2015 | |
Evan Cheng | 61ca74b | 2005-11-30 02:04:11 +0000 | [diff] [blame] | 2016 | RemoveNodeFromCSEMaps(N); |
| 2017 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 2018 | N->setValueTypes(VT); |
| 2019 | N->setOperands(Op1, Op2, Op3, Op4, Op5, Op6); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 2020 | |
| 2021 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2022 | return SDOperand(N, 0); |
Evan Cheng | 61ca74b | 2005-11-30 02:04:11 +0000 | [diff] [blame] | 2023 | } |
| 2024 | |
Andrew Lenharth | 8c6f1ee | 2006-01-23 20:59:12 +0000 | [diff] [blame] | 2025 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 2026 | MVT::ValueType VT, SDOperand Op1, |
| 2027 | SDOperand Op2, SDOperand Op3,SDOperand Op4, |
| 2028 | SDOperand Op5, SDOperand Op6, |
| 2029 | SDOperand Op7) { |
| 2030 | // If an identical node already exists, use it. |
| 2031 | std::vector<SDOperand> OpList; |
| 2032 | OpList.push_back(Op1); OpList.push_back(Op2); OpList.push_back(Op3); |
| 2033 | OpList.push_back(Op4); OpList.push_back(Op5); OpList.push_back(Op6); |
| 2034 | OpList.push_back(Op7); |
| 2035 | SDNode *&ON = OneResultNodes[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 2036 | std::make_pair(VT, OpList))]; |
| 2037 | if (ON) return SDOperand(ON, 0); |
| 2038 | |
| 2039 | RemoveNodeFromCSEMaps(N); |
| 2040 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 2041 | N->setValueTypes(VT); |
| 2042 | N->setOperands(Op1, Op2, Op3, Op4, Op5, Op6, Op7); |
| 2043 | |
| 2044 | ON = N; // Memoize the new node. |
| 2045 | return SDOperand(N, 0); |
| 2046 | } |
Andrew Lenharth | 7cf11b4 | 2006-01-23 21:51:14 +0000 | [diff] [blame] | 2047 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 2048 | MVT::ValueType VT, SDOperand Op1, |
| 2049 | SDOperand Op2, SDOperand Op3,SDOperand Op4, |
| 2050 | SDOperand Op5, SDOperand Op6, |
| 2051 | SDOperand Op7, SDOperand Op8) { |
| 2052 | // If an identical node already exists, use it. |
| 2053 | std::vector<SDOperand> OpList; |
| 2054 | OpList.push_back(Op1); OpList.push_back(Op2); OpList.push_back(Op3); |
| 2055 | OpList.push_back(Op4); OpList.push_back(Op5); OpList.push_back(Op6); |
| 2056 | OpList.push_back(Op7); OpList.push_back(Op8); |
| 2057 | SDNode *&ON = OneResultNodes[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 2058 | std::make_pair(VT, OpList))]; |
| 2059 | if (ON) return SDOperand(ON, 0); |
| 2060 | |
| 2061 | RemoveNodeFromCSEMaps(N); |
| 2062 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 2063 | N->setValueTypes(VT); |
| 2064 | N->setOperands(Op1, Op2, Op3, Op4, Op5, Op6, Op7, Op8); |
| 2065 | |
| 2066 | ON = N; // Memoize the new node. |
| 2067 | return SDOperand(N, 0); |
| 2068 | } |
Andrew Lenharth | 8c6f1ee | 2006-01-23 20:59:12 +0000 | [diff] [blame] | 2069 | |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2070 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 2071 | MVT::ValueType VT1, MVT::ValueType VT2, |
| 2072 | SDOperand Op1, SDOperand Op2) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 2073 | // If an identical node already exists, use it. |
| 2074 | std::vector<SDOperand> OpList; |
| 2075 | OpList.push_back(Op1); OpList.push_back(Op2); |
| 2076 | std::vector<MVT::ValueType> VTList; |
| 2077 | VTList.push_back(VT1); VTList.push_back(VT2); |
| 2078 | SDNode *&ON = ArbitraryNodes[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 2079 | std::make_pair(VTList, OpList))]; |
| 2080 | if (ON) return SDOperand(ON, 0); |
| 2081 | |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 2082 | RemoveNodeFromCSEMaps(N); |
| 2083 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 2084 | setNodeValueTypes(N, VT1, VT2); |
| 2085 | N->setOperands(Op1, Op2); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 2086 | |
| 2087 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2088 | return SDOperand(N, 0); |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 2089 | } |
| 2090 | |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2091 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 2092 | MVT::ValueType VT1, MVT::ValueType VT2, |
| 2093 | SDOperand Op1, SDOperand Op2, |
| 2094 | SDOperand Op3) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 2095 | // If an identical node already exists, use it. |
| 2096 | std::vector<SDOperand> OpList; |
| 2097 | OpList.push_back(Op1); OpList.push_back(Op2); OpList.push_back(Op3); |
| 2098 | std::vector<MVT::ValueType> VTList; |
| 2099 | VTList.push_back(VT1); VTList.push_back(VT2); |
| 2100 | SDNode *&ON = ArbitraryNodes[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 2101 | std::make_pair(VTList, OpList))]; |
| 2102 | if (ON) return SDOperand(ON, 0); |
| 2103 | |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 2104 | RemoveNodeFromCSEMaps(N); |
| 2105 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 2106 | setNodeValueTypes(N, VT1, VT2); |
| 2107 | N->setOperands(Op1, Op2, Op3); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 2108 | |
| 2109 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2110 | return SDOperand(N, 0); |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 2111 | } |
| 2112 | |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2113 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 2114 | MVT::ValueType VT1, MVT::ValueType VT2, |
| 2115 | SDOperand Op1, SDOperand Op2, |
| 2116 | SDOperand Op3, SDOperand Op4) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 2117 | // If an identical node already exists, use it. |
| 2118 | std::vector<SDOperand> OpList; |
| 2119 | OpList.push_back(Op1); OpList.push_back(Op2); OpList.push_back(Op3); |
| 2120 | OpList.push_back(Op4); |
| 2121 | std::vector<MVT::ValueType> VTList; |
| 2122 | VTList.push_back(VT1); VTList.push_back(VT2); |
| 2123 | SDNode *&ON = ArbitraryNodes[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 2124 | std::make_pair(VTList, OpList))]; |
| 2125 | if (ON) return SDOperand(ON, 0); |
| 2126 | |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 2127 | RemoveNodeFromCSEMaps(N); |
| 2128 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 2129 | setNodeValueTypes(N, VT1, VT2); |
| 2130 | N->setOperands(Op1, Op2, Op3, Op4); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 2131 | |
| 2132 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2133 | return SDOperand(N, 0); |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2136 | SDOperand SelectionDAG::SelectNodeTo(SDNode *N, unsigned TargetOpc, |
| 2137 | MVT::ValueType VT1, MVT::ValueType VT2, |
| 2138 | SDOperand Op1, SDOperand Op2, |
| 2139 | SDOperand Op3, SDOperand Op4, |
| 2140 | SDOperand Op5) { |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 2141 | // If an identical node already exists, use it. |
| 2142 | std::vector<SDOperand> OpList; |
| 2143 | OpList.push_back(Op1); OpList.push_back(Op2); OpList.push_back(Op3); |
| 2144 | OpList.push_back(Op4); OpList.push_back(Op5); |
| 2145 | std::vector<MVT::ValueType> VTList; |
| 2146 | VTList.push_back(VT1); VTList.push_back(VT2); |
| 2147 | SDNode *&ON = ArbitraryNodes[std::make_pair(ISD::BUILTIN_OP_END+TargetOpc, |
| 2148 | std::make_pair(VTList, OpList))]; |
| 2149 | if (ON) return SDOperand(ON, 0); |
| 2150 | |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 2151 | RemoveNodeFromCSEMaps(N); |
| 2152 | N->MorphNodeTo(ISD::BUILTIN_OP_END+TargetOpc); |
| 2153 | setNodeValueTypes(N, VT1, VT2); |
| 2154 | N->setOperands(Op1, Op2, Op3, Op4, Op5); |
Chris Lattner | c5e6c64 | 2005-12-01 18:00:57 +0000 | [diff] [blame] | 2155 | |
| 2156 | ON = N; // Memoize the new node. |
Chris Lattner | eb19e40 | 2005-11-30 22:45:14 +0000 | [diff] [blame] | 2157 | return SDOperand(N, 0); |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
Evan Cheng | 6ae46c4 | 2006-02-09 07:15:23 +0000 | [diff] [blame] | 2160 | /// getTargetNode - These are used for target selectors to create a new node |
| 2161 | /// with specified return type(s), target opcode, and operands. |
| 2162 | /// |
| 2163 | /// Note that getTargetNode returns the resultant node. If there is already a |
| 2164 | /// node of the specified opcode and operands, it returns that node instead of |
| 2165 | /// the current one. |
| 2166 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT) { |
| 2167 | return getNode(ISD::BUILTIN_OP_END+Opcode, VT).Val; |
| 2168 | } |
| 2169 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT, |
| 2170 | SDOperand Op1) { |
| 2171 | return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1).Val; |
| 2172 | } |
| 2173 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT, |
| 2174 | SDOperand Op1, SDOperand Op2) { |
| 2175 | return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1, Op2).Val; |
| 2176 | } |
| 2177 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT, |
| 2178 | SDOperand Op1, SDOperand Op2, SDOperand Op3) { |
| 2179 | return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1, Op2, Op3).Val; |
| 2180 | } |
| 2181 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT, |
| 2182 | SDOperand Op1, SDOperand Op2, SDOperand Op3, |
| 2183 | SDOperand Op4) { |
| 2184 | return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1, Op2, Op3, Op4).Val; |
| 2185 | } |
| 2186 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT, |
| 2187 | SDOperand Op1, SDOperand Op2, SDOperand Op3, |
| 2188 | SDOperand Op4, SDOperand Op5) { |
| 2189 | return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Op1, Op2, Op3, Op4, Op5).Val; |
| 2190 | } |
| 2191 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT, |
| 2192 | SDOperand Op1, SDOperand Op2, SDOperand Op3, |
| 2193 | SDOperand Op4, SDOperand Op5, SDOperand Op6) { |
| 2194 | std::vector<SDOperand> Ops; |
| 2195 | Ops.reserve(6); |
| 2196 | Ops.push_back(Op1); |
| 2197 | Ops.push_back(Op2); |
| 2198 | Ops.push_back(Op3); |
| 2199 | Ops.push_back(Op4); |
| 2200 | Ops.push_back(Op5); |
| 2201 | Ops.push_back(Op6); |
| 2202 | return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Ops).Val; |
| 2203 | } |
| 2204 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT, |
| 2205 | SDOperand Op1, SDOperand Op2, SDOperand Op3, |
| 2206 | SDOperand Op4, SDOperand Op5, SDOperand Op6, |
| 2207 | SDOperand Op7) { |
| 2208 | std::vector<SDOperand> Ops; |
| 2209 | Ops.reserve(7); |
| 2210 | Ops.push_back(Op1); |
| 2211 | Ops.push_back(Op2); |
| 2212 | Ops.push_back(Op3); |
| 2213 | Ops.push_back(Op4); |
| 2214 | Ops.push_back(Op5); |
| 2215 | Ops.push_back(Op6); |
| 2216 | Ops.push_back(Op7); |
| 2217 | return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Ops).Val; |
| 2218 | } |
| 2219 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT, |
| 2220 | SDOperand Op1, SDOperand Op2, SDOperand Op3, |
| 2221 | SDOperand Op4, SDOperand Op5, SDOperand Op6, |
| 2222 | SDOperand Op7, SDOperand Op8) { |
| 2223 | std::vector<SDOperand> Ops; |
| 2224 | Ops.reserve(8); |
| 2225 | Ops.push_back(Op1); |
| 2226 | Ops.push_back(Op2); |
| 2227 | Ops.push_back(Op3); |
| 2228 | Ops.push_back(Op4); |
| 2229 | Ops.push_back(Op5); |
| 2230 | Ops.push_back(Op6); |
| 2231 | Ops.push_back(Op7); |
| 2232 | Ops.push_back(Op8); |
| 2233 | return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Ops).Val; |
| 2234 | } |
| 2235 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT, |
| 2236 | std::vector<SDOperand> &Ops) { |
| 2237 | return getNode(ISD::BUILTIN_OP_END+Opcode, VT, Ops).Val; |
| 2238 | } |
| 2239 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2240 | MVT::ValueType VT2, SDOperand Op1) { |
| 2241 | std::vector<MVT::ValueType> ResultTys; |
| 2242 | ResultTys.push_back(VT1); |
| 2243 | ResultTys.push_back(VT2); |
| 2244 | std::vector<SDOperand> Ops; |
| 2245 | Ops.push_back(Op1); |
| 2246 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2247 | } |
| 2248 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2249 | MVT::ValueType VT2, SDOperand Op1, SDOperand Op2) { |
| 2250 | std::vector<MVT::ValueType> ResultTys; |
| 2251 | ResultTys.push_back(VT1); |
| 2252 | ResultTys.push_back(VT2); |
| 2253 | std::vector<SDOperand> Ops; |
| 2254 | Ops.push_back(Op1); |
| 2255 | Ops.push_back(Op2); |
| 2256 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2257 | } |
| 2258 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2259 | MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, |
| 2260 | SDOperand Op3) { |
| 2261 | std::vector<MVT::ValueType> ResultTys; |
| 2262 | ResultTys.push_back(VT1); |
| 2263 | ResultTys.push_back(VT2); |
| 2264 | std::vector<SDOperand> Ops; |
| 2265 | Ops.push_back(Op1); |
| 2266 | Ops.push_back(Op2); |
| 2267 | Ops.push_back(Op3); |
| 2268 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2269 | } |
| 2270 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2271 | MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, |
| 2272 | SDOperand Op3, SDOperand Op4) { |
| 2273 | std::vector<MVT::ValueType> ResultTys; |
| 2274 | ResultTys.push_back(VT1); |
| 2275 | ResultTys.push_back(VT2); |
| 2276 | std::vector<SDOperand> Ops; |
| 2277 | Ops.push_back(Op1); |
| 2278 | Ops.push_back(Op2); |
| 2279 | Ops.push_back(Op3); |
| 2280 | Ops.push_back(Op4); |
| 2281 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2282 | } |
| 2283 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2284 | MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, |
| 2285 | SDOperand Op3, SDOperand Op4, SDOperand Op5) { |
| 2286 | std::vector<MVT::ValueType> ResultTys; |
| 2287 | ResultTys.push_back(VT1); |
| 2288 | ResultTys.push_back(VT2); |
| 2289 | std::vector<SDOperand> Ops; |
| 2290 | Ops.push_back(Op1); |
| 2291 | Ops.push_back(Op2); |
| 2292 | Ops.push_back(Op3); |
| 2293 | Ops.push_back(Op4); |
| 2294 | Ops.push_back(Op5); |
| 2295 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2296 | } |
| 2297 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2298 | MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, |
| 2299 | SDOperand Op3, SDOperand Op4, SDOperand Op5, |
| 2300 | SDOperand Op6) { |
| 2301 | std::vector<MVT::ValueType> ResultTys; |
| 2302 | ResultTys.push_back(VT1); |
| 2303 | ResultTys.push_back(VT2); |
| 2304 | std::vector<SDOperand> Ops; |
| 2305 | Ops.push_back(Op1); |
| 2306 | Ops.push_back(Op2); |
| 2307 | Ops.push_back(Op3); |
| 2308 | Ops.push_back(Op4); |
| 2309 | Ops.push_back(Op5); |
| 2310 | Ops.push_back(Op6); |
| 2311 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2312 | } |
| 2313 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2314 | MVT::ValueType VT2, SDOperand Op1, SDOperand Op2, |
| 2315 | SDOperand Op3, SDOperand Op4, SDOperand Op5, |
| 2316 | SDOperand Op6, SDOperand Op7) { |
| 2317 | std::vector<MVT::ValueType> ResultTys; |
| 2318 | ResultTys.push_back(VT1); |
| 2319 | ResultTys.push_back(VT2); |
| 2320 | std::vector<SDOperand> Ops; |
| 2321 | Ops.push_back(Op1); |
| 2322 | Ops.push_back(Op2); |
| 2323 | Ops.push_back(Op3); |
| 2324 | Ops.push_back(Op4); |
| 2325 | Ops.push_back(Op5); |
| 2326 | Ops.push_back(Op6); |
| 2327 | Ops.push_back(Op7); |
| 2328 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2329 | } |
| 2330 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2331 | MVT::ValueType VT2, MVT::ValueType VT3, |
| 2332 | SDOperand Op1, SDOperand Op2) { |
| 2333 | std::vector<MVT::ValueType> ResultTys; |
| 2334 | ResultTys.push_back(VT1); |
| 2335 | ResultTys.push_back(VT2); |
| 2336 | ResultTys.push_back(VT3); |
| 2337 | std::vector<SDOperand> Ops; |
| 2338 | Ops.push_back(Op1); |
| 2339 | Ops.push_back(Op2); |
| 2340 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2341 | } |
| 2342 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2343 | MVT::ValueType VT2, MVT::ValueType VT3, |
| 2344 | SDOperand Op1, SDOperand Op2, |
| 2345 | SDOperand Op3, SDOperand Op4, SDOperand Op5) { |
| 2346 | std::vector<MVT::ValueType> ResultTys; |
| 2347 | ResultTys.push_back(VT1); |
| 2348 | ResultTys.push_back(VT2); |
| 2349 | ResultTys.push_back(VT3); |
| 2350 | std::vector<SDOperand> Ops; |
| 2351 | Ops.push_back(Op1); |
| 2352 | Ops.push_back(Op2); |
| 2353 | Ops.push_back(Op3); |
| 2354 | Ops.push_back(Op4); |
| 2355 | Ops.push_back(Op5); |
| 2356 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2357 | } |
| 2358 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2359 | MVT::ValueType VT2, MVT::ValueType VT3, |
| 2360 | SDOperand Op1, SDOperand Op2, |
| 2361 | SDOperand Op3, SDOperand Op4, SDOperand Op5, |
| 2362 | SDOperand Op6) { |
| 2363 | std::vector<MVT::ValueType> ResultTys; |
| 2364 | ResultTys.push_back(VT1); |
| 2365 | ResultTys.push_back(VT2); |
| 2366 | ResultTys.push_back(VT3); |
| 2367 | std::vector<SDOperand> Ops; |
| 2368 | Ops.push_back(Op1); |
| 2369 | Ops.push_back(Op2); |
| 2370 | Ops.push_back(Op3); |
| 2371 | Ops.push_back(Op4); |
| 2372 | Ops.push_back(Op5); |
| 2373 | Ops.push_back(Op6); |
| 2374 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2375 | } |
| 2376 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2377 | MVT::ValueType VT2, MVT::ValueType VT3, |
| 2378 | SDOperand Op1, SDOperand Op2, |
| 2379 | SDOperand Op3, SDOperand Op4, SDOperand Op5, |
| 2380 | SDOperand Op6, SDOperand Op7) { |
| 2381 | std::vector<MVT::ValueType> ResultTys; |
| 2382 | ResultTys.push_back(VT1); |
| 2383 | ResultTys.push_back(VT2); |
| 2384 | ResultTys.push_back(VT3); |
| 2385 | std::vector<SDOperand> Ops; |
| 2386 | Ops.push_back(Op1); |
| 2387 | Ops.push_back(Op2); |
| 2388 | Ops.push_back(Op3); |
| 2389 | Ops.push_back(Op4); |
| 2390 | Ops.push_back(Op5); |
| 2391 | Ops.push_back(Op6); |
| 2392 | Ops.push_back(Op7); |
| 2393 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2394 | } |
| 2395 | SDNode *SelectionDAG::getTargetNode(unsigned Opcode, MVT::ValueType VT1, |
| 2396 | MVT::ValueType VT2, std::vector<SDOperand> &Ops) { |
| 2397 | std::vector<MVT::ValueType> ResultTys; |
| 2398 | ResultTys.push_back(VT1); |
| 2399 | ResultTys.push_back(VT2); |
| 2400 | return getNode(ISD::BUILTIN_OP_END+Opcode, ResultTys, Ops).Val; |
| 2401 | } |
| 2402 | |
Chris Lattner | 0fb094f | 2005-11-19 01:44:53 +0000 | [diff] [blame] | 2403 | // ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead. |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 2404 | /// This can cause recursive merging of nodes in the DAG. |
| 2405 | /// |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 2406 | /// This version assumes From/To have a single result value. |
| 2407 | /// |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 2408 | void SelectionDAG::ReplaceAllUsesWith(SDOperand FromN, SDOperand ToN, |
| 2409 | std::vector<SDNode*> *Deleted) { |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 2410 | SDNode *From = FromN.Val, *To = ToN.Val; |
| 2411 | assert(From->getNumValues() == 1 && To->getNumValues() == 1 && |
| 2412 | "Cannot replace with this method!"); |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 2413 | assert(From != To && "Cannot replace uses of with self"); |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 2414 | |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 2415 | while (!From->use_empty()) { |
| 2416 | // Process users until they are all gone. |
| 2417 | SDNode *U = *From->use_begin(); |
| 2418 | |
| 2419 | // This node is about to morph, remove its old self from the CSE maps. |
| 2420 | RemoveNodeFromCSEMaps(U); |
| 2421 | |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 2422 | for (SDOperand *I = U->OperandList, *E = U->OperandList+U->NumOperands; |
| 2423 | I != E; ++I) |
| 2424 | if (I->Val == From) { |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 2425 | From->removeUser(U); |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 2426 | I->Val = To; |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 2427 | To->addUser(U); |
| 2428 | } |
| 2429 | |
| 2430 | // Now that we have modified U, add it back to the CSE maps. If it already |
| 2431 | // exists there, recursively merge the results together. |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 2432 | if (SDNode *Existing = AddNonLeafNodeToCSEMaps(U)) { |
| 2433 | ReplaceAllUsesWith(U, Existing, Deleted); |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 2434 | // U is now dead. |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 2435 | if (Deleted) Deleted->push_back(U); |
| 2436 | DeleteNodeNotInCSEMaps(U); |
| 2437 | } |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 2438 | } |
| 2439 | } |
| 2440 | |
| 2441 | /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead. |
| 2442 | /// This can cause recursive merging of nodes in the DAG. |
| 2443 | /// |
| 2444 | /// This version assumes From/To have matching types and numbers of result |
| 2445 | /// values. |
| 2446 | /// |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 2447 | void SelectionDAG::ReplaceAllUsesWith(SDNode *From, SDNode *To, |
| 2448 | std::vector<SDNode*> *Deleted) { |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 2449 | assert(From != To && "Cannot replace uses of with self"); |
| 2450 | assert(From->getNumValues() == To->getNumValues() && |
| 2451 | "Cannot use this version of ReplaceAllUsesWith!"); |
| 2452 | if (From->getNumValues() == 1) { // If possible, use the faster version. |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 2453 | ReplaceAllUsesWith(SDOperand(From, 0), SDOperand(To, 0), Deleted); |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 2454 | return; |
| 2455 | } |
| 2456 | |
| 2457 | while (!From->use_empty()) { |
| 2458 | // Process users until they are all gone. |
| 2459 | SDNode *U = *From->use_begin(); |
| 2460 | |
| 2461 | // This node is about to morph, remove its old self from the CSE maps. |
| 2462 | RemoveNodeFromCSEMaps(U); |
| 2463 | |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 2464 | for (SDOperand *I = U->OperandList, *E = U->OperandList+U->NumOperands; |
| 2465 | I != E; ++I) |
| 2466 | if (I->Val == From) { |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 2467 | From->removeUser(U); |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 2468 | I->Val = To; |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 2469 | To->addUser(U); |
| 2470 | } |
| 2471 | |
| 2472 | // Now that we have modified U, add it back to the CSE maps. If it already |
| 2473 | // exists there, recursively merge the results together. |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 2474 | if (SDNode *Existing = AddNonLeafNodeToCSEMaps(U)) { |
| 2475 | ReplaceAllUsesWith(U, Existing, Deleted); |
| 2476 | // U is now dead. |
| 2477 | if (Deleted) Deleted->push_back(U); |
| 2478 | DeleteNodeNotInCSEMaps(U); |
| 2479 | } |
Chris Lattner | 8b8749f | 2005-08-17 19:00:20 +0000 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | |
Chris Lattner | 8b52f21 | 2005-08-26 18:36:28 +0000 | [diff] [blame] | 2483 | /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead. |
| 2484 | /// This can cause recursive merging of nodes in the DAG. |
| 2485 | /// |
| 2486 | /// This version can replace From with any result values. To must match the |
| 2487 | /// number and types of values returned by From. |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 2488 | void SelectionDAG::ReplaceAllUsesWith(SDNode *From, |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 2489 | const std::vector<SDOperand> &To, |
| 2490 | std::vector<SDNode*> *Deleted) { |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 2491 | assert(From->getNumValues() == To.size() && |
| 2492 | "Incorrect number of values to replace with!"); |
Chris Lattner | ff01698 | 2005-08-28 23:59:36 +0000 | [diff] [blame] | 2493 | if (To.size() == 1 && To[0].Val->getNumValues() == 1) { |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 2494 | // Degenerate case handled above. |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 2495 | ReplaceAllUsesWith(SDOperand(From, 0), To[0], Deleted); |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 2496 | return; |
| 2497 | } |
| 2498 | |
| 2499 | while (!From->use_empty()) { |
| 2500 | // Process users until they are all gone. |
| 2501 | SDNode *U = *From->use_begin(); |
| 2502 | |
| 2503 | // This node is about to morph, remove its old self from the CSE maps. |
| 2504 | RemoveNodeFromCSEMaps(U); |
| 2505 | |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 2506 | for (SDOperand *I = U->OperandList, *E = U->OperandList+U->NumOperands; |
| 2507 | I != E; ++I) |
| 2508 | if (I->Val == From) { |
| 2509 | const SDOperand &ToOp = To[I->ResNo]; |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 2510 | From->removeUser(U); |
Chris Lattner | 65113b2 | 2005-11-08 22:07:03 +0000 | [diff] [blame] | 2511 | *I = ToOp; |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 2512 | ToOp.Val->addUser(U); |
| 2513 | } |
| 2514 | |
| 2515 | // Now that we have modified U, add it back to the CSE maps. If it already |
| 2516 | // exists there, recursively merge the results together. |
Chris Lattner | 1e111c7 | 2005-09-07 05:37:01 +0000 | [diff] [blame] | 2517 | if (SDNode *Existing = AddNonLeafNodeToCSEMaps(U)) { |
| 2518 | ReplaceAllUsesWith(U, Existing, Deleted); |
| 2519 | // U is now dead. |
| 2520 | if (Deleted) Deleted->push_back(U); |
| 2521 | DeleteNodeNotInCSEMaps(U); |
| 2522 | } |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 2523 | } |
| 2524 | } |
| 2525 | |
Chris Lattner | 012f241 | 2006-02-17 21:58:01 +0000 | [diff] [blame] | 2526 | /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving |
| 2527 | /// uses of other values produced by From.Val alone. The Deleted vector is |
| 2528 | /// handled the same was as for ReplaceAllUsesWith. |
| 2529 | void SelectionDAG::ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To, |
| 2530 | std::vector<SDNode*> &Deleted) { |
| 2531 | assert(From != To && "Cannot replace a value with itself"); |
| 2532 | // Handle the simple, trivial, case efficiently. |
| 2533 | if (From.Val->getNumValues() == 1 && To.Val->getNumValues() == 1) { |
| 2534 | ReplaceAllUsesWith(From, To, &Deleted); |
| 2535 | return; |
| 2536 | } |
| 2537 | |
| 2538 | // Get all of the users in a nice, deterministically ordered, uniqued set. |
| 2539 | SetVector<SDNode*> Users(From.Val->use_begin(), From.Val->use_end()); |
| 2540 | |
| 2541 | while (!Users.empty()) { |
| 2542 | // We know that this user uses some value of From. If it is the right |
| 2543 | // value, update it. |
| 2544 | SDNode *User = Users.back(); |
| 2545 | Users.pop_back(); |
| 2546 | |
| 2547 | for (SDOperand *Op = User->OperandList, |
| 2548 | *E = User->OperandList+User->NumOperands; Op != E; ++Op) { |
| 2549 | if (*Op == From) { |
| 2550 | // Okay, we know this user needs to be updated. Remove its old self |
| 2551 | // from the CSE maps. |
| 2552 | RemoveNodeFromCSEMaps(User); |
| 2553 | |
| 2554 | // Update all operands that match "From". |
| 2555 | for (; Op != E; ++Op) { |
| 2556 | if (*Op == From) { |
| 2557 | From.Val->removeUser(User); |
| 2558 | *Op = To; |
| 2559 | To.Val->addUser(User); |
| 2560 | } |
| 2561 | } |
| 2562 | |
| 2563 | // Now that we have modified User, add it back to the CSE maps. If it |
| 2564 | // already exists there, recursively merge the results together. |
| 2565 | if (SDNode *Existing = AddNonLeafNodeToCSEMaps(User)) { |
| 2566 | unsigned NumDeleted = Deleted.size(); |
| 2567 | ReplaceAllUsesWith(User, Existing, &Deleted); |
| 2568 | |
| 2569 | // User is now dead. |
| 2570 | Deleted.push_back(User); |
| 2571 | DeleteNodeNotInCSEMaps(User); |
| 2572 | |
| 2573 | // We have to be careful here, because ReplaceAllUsesWith could have |
| 2574 | // deleted a user of From, which means there may be dangling pointers |
| 2575 | // in the "Users" setvector. Scan over the deleted node pointers and |
| 2576 | // remove them from the setvector. |
| 2577 | for (unsigned i = NumDeleted, e = Deleted.size(); i != e; ++i) |
| 2578 | Users.remove(Deleted[i]); |
| 2579 | } |
| 2580 | break; // Exit the operand scanning loop. |
| 2581 | } |
| 2582 | } |
| 2583 | } |
| 2584 | } |
| 2585 | |
Chris Lattner | 7b2880c | 2005-08-24 22:44:39 +0000 | [diff] [blame] | 2586 | |
Jim Laskey | 58b968b | 2005-08-17 20:08:02 +0000 | [diff] [blame] | 2587 | //===----------------------------------------------------------------------===// |
| 2588 | // SDNode Class |
| 2589 | //===----------------------------------------------------------------------===// |
Chris Lattner | 149c58c | 2005-08-16 18:17:10 +0000 | [diff] [blame] | 2590 | |
Chris Lattner | a325511 | 2005-11-08 23:30:28 +0000 | [diff] [blame] | 2591 | |
| 2592 | /// getValueTypeList - Return a pointer to the specified value type. |
| 2593 | /// |
| 2594 | MVT::ValueType *SDNode::getValueTypeList(MVT::ValueType VT) { |
| 2595 | static MVT::ValueType VTs[MVT::LAST_VALUETYPE]; |
| 2596 | VTs[VT] = VT; |
| 2597 | return &VTs[VT]; |
| 2598 | } |
| 2599 | |
Chris Lattner | 5c88456 | 2005-01-12 18:37:47 +0000 | [diff] [blame] | 2600 | /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the |
| 2601 | /// indicated value. This method ignores uses of other values defined by this |
| 2602 | /// operation. |
Evan Cheng | 4ee6211 | 2006-02-05 06:29:23 +0000 | [diff] [blame] | 2603 | bool SDNode::hasNUsesOfValue(unsigned NUses, unsigned Value) const { |
Chris Lattner | 5c88456 | 2005-01-12 18:37:47 +0000 | [diff] [blame] | 2604 | assert(Value < getNumValues() && "Bad value!"); |
| 2605 | |
| 2606 | // If there is only one value, this is easy. |
| 2607 | if (getNumValues() == 1) |
| 2608 | return use_size() == NUses; |
| 2609 | if (Uses.size() < NUses) return false; |
| 2610 | |
Evan Cheng | 4ee6211 | 2006-02-05 06:29:23 +0000 | [diff] [blame] | 2611 | SDOperand TheValue(const_cast<SDNode *>(this), Value); |
Chris Lattner | 5c88456 | 2005-01-12 18:37:47 +0000 | [diff] [blame] | 2612 | |
| 2613 | std::set<SDNode*> UsersHandled; |
| 2614 | |
Evan Cheng | 4ee6211 | 2006-02-05 06:29:23 +0000 | [diff] [blame] | 2615 | for (std::vector<SDNode*>::const_iterator UI = Uses.begin(), E = Uses.end(); |
Chris Lattner | 5c88456 | 2005-01-12 18:37:47 +0000 | [diff] [blame] | 2616 | UI != E; ++UI) { |
| 2617 | SDNode *User = *UI; |
| 2618 | if (User->getNumOperands() == 1 || |
| 2619 | UsersHandled.insert(User).second) // First time we've seen this? |
| 2620 | for (unsigned i = 0, e = User->getNumOperands(); i != e; ++i) |
| 2621 | if (User->getOperand(i) == TheValue) { |
| 2622 | if (NUses == 0) |
| 2623 | return false; // too many uses |
| 2624 | --NUses; |
| 2625 | } |
| 2626 | } |
| 2627 | |
| 2628 | // Found exactly the right number of uses? |
| 2629 | return NUses == 0; |
| 2630 | } |
| 2631 | |
| 2632 | |
Evan Cheng | 4ee6211 | 2006-02-05 06:29:23 +0000 | [diff] [blame] | 2633 | // isOnlyUse - Return true if this node is the only use of N. |
| 2634 | bool SDNode::isOnlyUse(SDNode *N) const { |
| 2635 | bool Seen = false; |
| 2636 | for (SDNode::use_iterator I = N->use_begin(), E = N->use_end(); I != E; ++I) { |
| 2637 | SDNode *User = *I; |
| 2638 | if (User == this) |
| 2639 | Seen = true; |
| 2640 | else |
| 2641 | return false; |
| 2642 | } |
| 2643 | |
| 2644 | return Seen; |
| 2645 | } |
| 2646 | |
Evan Cheng | 80d8eaa | 2006-03-03 06:24:54 +0000 | [diff] [blame] | 2647 | // isOperand - Return true if this node is an operand of N. |
Evan Cheng | bfa284f | 2006-03-03 06:42:32 +0000 | [diff] [blame] | 2648 | bool SDOperand::isOperand(SDNode *N) const { |
| 2649 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 2650 | if (*this == N->getOperand(i)) |
| 2651 | return true; |
| 2652 | return false; |
| 2653 | } |
| 2654 | |
Evan Cheng | 80d8eaa | 2006-03-03 06:24:54 +0000 | [diff] [blame] | 2655 | bool SDNode::isOperand(SDNode *N) const { |
| 2656 | for (unsigned i = 0, e = N->NumOperands; i != e; ++i) |
| 2657 | if (this == N->OperandList[i].Val) |
| 2658 | return true; |
| 2659 | return false; |
| 2660 | } |
Evan Cheng | 4ee6211 | 2006-02-05 06:29:23 +0000 | [diff] [blame] | 2661 | |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 2662 | const char *SDNode::getOperationName(const SelectionDAG *G) const { |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2663 | switch (getOpcode()) { |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 2664 | default: |
| 2665 | if (getOpcode() < ISD::BUILTIN_OP_END) |
| 2666 | return "<<Unknown DAG Node>>"; |
| 2667 | else { |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 2668 | if (G) { |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 2669 | if (const TargetInstrInfo *TII = G->getTarget().getInstrInfo()) |
Chris Lattner | 08addbd | 2005-09-09 22:35:03 +0000 | [diff] [blame] | 2670 | if (getOpcode()-ISD::BUILTIN_OP_END < TII->getNumOpcodes()) |
| 2671 | return TII->getName(getOpcode()-ISD::BUILTIN_OP_END); |
Evan Cheng | 115c036 | 2005-12-19 23:11:49 +0000 | [diff] [blame] | 2672 | |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 2673 | TargetLowering &TLI = G->getTargetLoweringInfo(); |
| 2674 | const char *Name = |
| 2675 | TLI.getTargetNodeName(getOpcode()); |
| 2676 | if (Name) return Name; |
| 2677 | } |
| 2678 | |
| 2679 | return "<<Unknown Target Node>>"; |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 2680 | } |
| 2681 | |
Andrew Lenharth | 9576212 | 2005-03-31 21:24:06 +0000 | [diff] [blame] | 2682 | case ISD::PCMARKER: return "PCMarker"; |
Andrew Lenharth | 51b8d54 | 2005-11-11 16:47:30 +0000 | [diff] [blame] | 2683 | case ISD::READCYCLECOUNTER: return "ReadCycleCounter"; |
Chris Lattner | 2bf3c26 | 2005-05-09 04:08:27 +0000 | [diff] [blame] | 2684 | case ISD::SRCVALUE: return "SrcValue"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2685 | case ISD::EntryToken: return "EntryToken"; |
Chris Lattner | 282c5ca | 2005-01-13 17:59:10 +0000 | [diff] [blame] | 2686 | case ISD::TokenFactor: return "TokenFactor"; |
Nate Begeman | 56eb868 | 2005-08-30 02:44:00 +0000 | [diff] [blame] | 2687 | case ISD::AssertSext: return "AssertSext"; |
| 2688 | case ISD::AssertZext: return "AssertZext"; |
Evan Cheng | 1ab7d85 | 2006-03-01 00:51:13 +0000 | [diff] [blame] | 2689 | |
| 2690 | case ISD::STRING: return "String"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2691 | case ISD::BasicBlock: return "BasicBlock"; |
Evan Cheng | 1ab7d85 | 2006-03-01 00:51:13 +0000 | [diff] [blame] | 2692 | case ISD::VALUETYPE: return "ValueType"; |
Chris Lattner | d5d0f9b | 2005-08-16 21:55:35 +0000 | [diff] [blame] | 2693 | case ISD::Register: return "Register"; |
Evan Cheng | 1ab7d85 | 2006-03-01 00:51:13 +0000 | [diff] [blame] | 2694 | |
| 2695 | case ISD::Constant: return "Constant"; |
| 2696 | case ISD::ConstantFP: return "ConstantFP"; |
| 2697 | case ISD::GlobalAddress: return "GlobalAddress"; |
| 2698 | case ISD::FrameIndex: return "FrameIndex"; |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 2699 | case ISD::ConstantPool: return "ConstantPool"; |
Evan Cheng | 1ab7d85 | 2006-03-01 00:51:13 +0000 | [diff] [blame] | 2700 | case ISD::ExternalSymbol: return "ExternalSymbol"; |
Chris Lattner | 48b61a7 | 2006-03-28 00:40:33 +0000 | [diff] [blame] | 2701 | case ISD::INTRINSIC_WO_CHAIN: { |
| 2702 | unsigned IID = cast<ConstantSDNode>(getOperand(0))->getValue(); |
| 2703 | return Intrinsic::getName((Intrinsic::ID)IID); |
| 2704 | } |
| 2705 | case ISD::INTRINSIC_VOID: |
| 2706 | case ISD::INTRINSIC_W_CHAIN: { |
| 2707 | unsigned IID = cast<ConstantSDNode>(getOperand(1))->getValue(); |
Chris Lattner | 70a248d | 2006-03-27 06:45:25 +0000 | [diff] [blame] | 2708 | return Intrinsic::getName((Intrinsic::ID)IID); |
Chris Lattner | 401ec7f | 2006-03-27 16:10:59 +0000 | [diff] [blame] | 2709 | } |
Evan Cheng | 1ab7d85 | 2006-03-01 00:51:13 +0000 | [diff] [blame] | 2710 | |
Chris Lattner | b2827b0 | 2006-03-19 00:52:58 +0000 | [diff] [blame] | 2711 | case ISD::BUILD_VECTOR: return "BUILD_VECTOR"; |
Evan Cheng | 1ab7d85 | 2006-03-01 00:51:13 +0000 | [diff] [blame] | 2712 | case ISD::TargetConstant: return "TargetConstant"; |
| 2713 | case ISD::TargetConstantFP:return "TargetConstantFP"; |
Evan Cheng | 1ab7d85 | 2006-03-01 00:51:13 +0000 | [diff] [blame] | 2714 | case ISD::TargetGlobalAddress: return "TargetGlobalAddress"; |
| 2715 | case ISD::TargetFrameIndex: return "TargetFrameIndex"; |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 2716 | case ISD::TargetConstantPool: return "TargetConstantPool"; |
Evan Cheng | 1ab7d85 | 2006-03-01 00:51:13 +0000 | [diff] [blame] | 2717 | case ISD::TargetExternalSymbol: return "TargetExternalSymbol"; |
Evan Cheng | 1ab7d85 | 2006-03-01 00:51:13 +0000 | [diff] [blame] | 2718 | |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2719 | case ISD::CopyToReg: return "CopyToReg"; |
| 2720 | case ISD::CopyFromReg: return "CopyFromReg"; |
Nate Begeman | fc1b1da | 2005-04-01 22:34:39 +0000 | [diff] [blame] | 2721 | case ISD::UNDEF: return "undef"; |
Chris Lattner | cc0aad2 | 2006-01-15 08:39:35 +0000 | [diff] [blame] | 2722 | case ISD::MERGE_VALUES: return "mergevalues"; |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 2723 | case ISD::INLINEASM: return "inlineasm"; |
Evan Cheng | 9fda2f9 | 2006-02-03 01:33:01 +0000 | [diff] [blame] | 2724 | case ISD::HANDLENODE: return "handlenode"; |
Chris Lattner | fdfded5 | 2006-04-12 16:20:43 +0000 | [diff] [blame] | 2725 | case ISD::FORMAL_ARGUMENTS: return "formal_arguments"; |
Chris Lattner | ce7518c | 2006-01-26 22:24:51 +0000 | [diff] [blame] | 2726 | |
Chris Lattner | ff9fd0a | 2005-04-02 04:58:41 +0000 | [diff] [blame] | 2727 | // Unary operators |
| 2728 | case ISD::FABS: return "fabs"; |
| 2729 | case ISD::FNEG: return "fneg"; |
Chris Lattner | 7f64464 | 2005-04-28 21:44:03 +0000 | [diff] [blame] | 2730 | case ISD::FSQRT: return "fsqrt"; |
| 2731 | case ISD::FSIN: return "fsin"; |
| 2732 | case ISD::FCOS: return "fcos"; |
Chris Lattner | ff9fd0a | 2005-04-02 04:58:41 +0000 | [diff] [blame] | 2733 | |
| 2734 | // Binary operators |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2735 | case ISD::ADD: return "add"; |
| 2736 | case ISD::SUB: return "sub"; |
| 2737 | case ISD::MUL: return "mul"; |
Nate Begeman | 1867054 | 2005-04-05 22:36:56 +0000 | [diff] [blame] | 2738 | case ISD::MULHU: return "mulhu"; |
| 2739 | case ISD::MULHS: return "mulhs"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2740 | case ISD::SDIV: return "sdiv"; |
| 2741 | case ISD::UDIV: return "udiv"; |
| 2742 | case ISD::SREM: return "srem"; |
| 2743 | case ISD::UREM: return "urem"; |
| 2744 | case ISD::AND: return "and"; |
| 2745 | case ISD::OR: return "or"; |
| 2746 | case ISD::XOR: return "xor"; |
| 2747 | case ISD::SHL: return "shl"; |
| 2748 | case ISD::SRA: return "sra"; |
| 2749 | case ISD::SRL: return "srl"; |
Nate Begeman | 35ef913 | 2006-01-11 21:21:00 +0000 | [diff] [blame] | 2750 | case ISD::ROTL: return "rotl"; |
| 2751 | case ISD::ROTR: return "rotr"; |
Chris Lattner | 01b3d73 | 2005-09-28 22:28:18 +0000 | [diff] [blame] | 2752 | case ISD::FADD: return "fadd"; |
| 2753 | case ISD::FSUB: return "fsub"; |
| 2754 | case ISD::FMUL: return "fmul"; |
| 2755 | case ISD::FDIV: return "fdiv"; |
| 2756 | case ISD::FREM: return "frem"; |
Chris Lattner | a09f848 | 2006-03-05 05:09:38 +0000 | [diff] [blame] | 2757 | case ISD::FCOPYSIGN: return "fcopysign"; |
Nate Begeman | 5fbb5d2 | 2005-11-19 00:36:38 +0000 | [diff] [blame] | 2758 | case ISD::VADD: return "vadd"; |
| 2759 | case ISD::VSUB: return "vsub"; |
| 2760 | case ISD::VMUL: return "vmul"; |
Chris Lattner | 97d2333 | 2006-04-02 02:41:18 +0000 | [diff] [blame] | 2761 | case ISD::VSDIV: return "vsdiv"; |
| 2762 | case ISD::VUDIV: return "vudiv"; |
| 2763 | case ISD::VAND: return "vand"; |
| 2764 | case ISD::VOR: return "vor"; |
| 2765 | case ISD::VXOR: return "vxor"; |
Chris Lattner | 0c486bd | 2006-03-17 19:53:59 +0000 | [diff] [blame] | 2766 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2767 | case ISD::SETCC: return "setcc"; |
| 2768 | case ISD::SELECT: return "select"; |
Nate Begeman | 9373a81 | 2005-08-10 20:51:12 +0000 | [diff] [blame] | 2769 | case ISD::SELECT_CC: return "select_cc"; |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 2770 | case ISD::VSELECT: return "vselect"; |
| 2771 | case ISD::INSERT_VECTOR_ELT: return "insert_vector_elt"; |
| 2772 | case ISD::VINSERT_VECTOR_ELT: return "vinsert_vector_elt"; |
| 2773 | case ISD::EXTRACT_VECTOR_ELT: return "extract_vector_elt"; |
Chris Lattner | 384504c | 2006-03-21 20:44:12 +0000 | [diff] [blame] | 2774 | case ISD::VEXTRACT_VECTOR_ELT: return "vextract_vector_elt"; |
Chris Lattner | b22e35a | 2006-04-08 22:22:57 +0000 | [diff] [blame] | 2775 | case ISD::SCALAR_TO_VECTOR: return "scalar_to_vector"; |
| 2776 | case ISD::VBUILD_VECTOR: return "vbuild_vector"; |
| 2777 | case ISD::VECTOR_SHUFFLE: return "vector_shuffle"; |
| 2778 | case ISD::VVECTOR_SHUFFLE: return "vvector_shuffle"; |
| 2779 | case ISD::VBIT_CONVERT: return "vbit_convert"; |
Nate Begeman | 551bf3f | 2006-02-17 05:43:56 +0000 | [diff] [blame] | 2780 | case ISD::ADDC: return "addc"; |
| 2781 | case ISD::ADDE: return "adde"; |
| 2782 | case ISD::SUBC: return "subc"; |
| 2783 | case ISD::SUBE: return "sube"; |
Chris Lattner | 41be951 | 2005-04-02 03:30:42 +0000 | [diff] [blame] | 2784 | case ISD::SHL_PARTS: return "shl_parts"; |
| 2785 | case ISD::SRA_PARTS: return "sra_parts"; |
| 2786 | case ISD::SRL_PARTS: return "srl_parts"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2787 | |
Chris Lattner | 7f64464 | 2005-04-28 21:44:03 +0000 | [diff] [blame] | 2788 | // Conversion operators. |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2789 | case ISD::SIGN_EXTEND: return "sign_extend"; |
| 2790 | case ISD::ZERO_EXTEND: return "zero_extend"; |
Chris Lattner | 4ed11b4 | 2005-09-02 00:17:32 +0000 | [diff] [blame] | 2791 | case ISD::ANY_EXTEND: return "any_extend"; |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 2792 | case ISD::SIGN_EXTEND_INREG: return "sign_extend_inreg"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2793 | case ISD::TRUNCATE: return "truncate"; |
| 2794 | case ISD::FP_ROUND: return "fp_round"; |
Chris Lattner | 859157d | 2005-01-15 06:17:04 +0000 | [diff] [blame] | 2795 | case ISD::FP_ROUND_INREG: return "fp_round_inreg"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2796 | case ISD::FP_EXTEND: return "fp_extend"; |
| 2797 | |
| 2798 | case ISD::SINT_TO_FP: return "sint_to_fp"; |
| 2799 | case ISD::UINT_TO_FP: return "uint_to_fp"; |
| 2800 | case ISD::FP_TO_SINT: return "fp_to_sint"; |
| 2801 | case ISD::FP_TO_UINT: return "fp_to_uint"; |
Chris Lattner | 3548189 | 2005-12-23 00:16:34 +0000 | [diff] [blame] | 2802 | case ISD::BIT_CONVERT: return "bit_convert"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2803 | |
| 2804 | // Control flow instructions |
| 2805 | case ISD::BR: return "br"; |
| 2806 | case ISD::BRCOND: return "brcond"; |
Nate Begeman | 81e8097 | 2006-03-17 01:40:33 +0000 | [diff] [blame] | 2807 | case ISD::BR_CC: return "br_cc"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2808 | case ISD::RET: return "ret"; |
Chris Lattner | a364fa1 | 2005-05-12 23:51:40 +0000 | [diff] [blame] | 2809 | case ISD::CALLSEQ_START: return "callseq_start"; |
| 2810 | case ISD::CALLSEQ_END: return "callseq_end"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2811 | |
| 2812 | // Other operators |
Nate Begeman | acc398c | 2006-01-25 18:21:52 +0000 | [diff] [blame] | 2813 | case ISD::LOAD: return "load"; |
| 2814 | case ISD::STORE: return "store"; |
| 2815 | case ISD::VLOAD: return "vload"; |
| 2816 | case ISD::EXTLOAD: return "extload"; |
| 2817 | case ISD::SEXTLOAD: return "sextload"; |
| 2818 | case ISD::ZEXTLOAD: return "zextload"; |
| 2819 | case ISD::TRUNCSTORE: return "truncstore"; |
| 2820 | case ISD::VAARG: return "vaarg"; |
| 2821 | case ISD::VACOPY: return "vacopy"; |
| 2822 | case ISD::VAEND: return "vaend"; |
| 2823 | case ISD::VASTART: return "vastart"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2824 | case ISD::DYNAMIC_STACKALLOC: return "dynamic_stackalloc"; |
Chris Lattner | 5a67afc | 2006-01-13 02:39:42 +0000 | [diff] [blame] | 2825 | case ISD::EXTRACT_ELEMENT: return "extract_element"; |
| 2826 | case ISD::BUILD_PAIR: return "build_pair"; |
| 2827 | case ISD::STACKSAVE: return "stacksave"; |
| 2828 | case ISD::STACKRESTORE: return "stackrestore"; |
| 2829 | |
| 2830 | // Block memory operations. |
Chris Lattner | 4c633e8 | 2005-01-11 05:57:01 +0000 | [diff] [blame] | 2831 | case ISD::MEMSET: return "memset"; |
| 2832 | case ISD::MEMCPY: return "memcpy"; |
| 2833 | case ISD::MEMMOVE: return "memmove"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2834 | |
Nate Begeman | 1b5db7a | 2006-01-16 08:07:10 +0000 | [diff] [blame] | 2835 | // Bit manipulation |
| 2836 | case ISD::BSWAP: return "bswap"; |
Chris Lattner | 276260b | 2005-05-11 04:50:30 +0000 | [diff] [blame] | 2837 | case ISD::CTPOP: return "ctpop"; |
| 2838 | case ISD::CTTZ: return "cttz"; |
| 2839 | case ISD::CTLZ: return "ctlz"; |
| 2840 | |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 2841 | // Debug info |
| 2842 | case ISD::LOCATION: return "location"; |
Jim Laskey | f5395ce | 2005-12-16 22:45:29 +0000 | [diff] [blame] | 2843 | case ISD::DEBUG_LOC: return "debug_loc"; |
Jim Laskey | abf6d17 | 2006-01-05 01:25:28 +0000 | [diff] [blame] | 2844 | case ISD::DEBUG_LABEL: return "debug_label"; |
Chris Lattner | 36ce691 | 2005-11-29 06:21:05 +0000 | [diff] [blame] | 2845 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2846 | case ISD::CONDCODE: |
| 2847 | switch (cast<CondCodeSDNode>(this)->get()) { |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2848 | default: assert(0 && "Unknown setcc condition!"); |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2849 | case ISD::SETOEQ: return "setoeq"; |
| 2850 | case ISD::SETOGT: return "setogt"; |
| 2851 | case ISD::SETOGE: return "setoge"; |
| 2852 | case ISD::SETOLT: return "setolt"; |
| 2853 | case ISD::SETOLE: return "setole"; |
| 2854 | case ISD::SETONE: return "setone"; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2855 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2856 | case ISD::SETO: return "seto"; |
| 2857 | case ISD::SETUO: return "setuo"; |
| 2858 | case ISD::SETUEQ: return "setue"; |
| 2859 | case ISD::SETUGT: return "setugt"; |
| 2860 | case ISD::SETUGE: return "setuge"; |
| 2861 | case ISD::SETULT: return "setult"; |
| 2862 | case ISD::SETULE: return "setule"; |
| 2863 | case ISD::SETUNE: return "setune"; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2864 | |
Chris Lattner | 7cf7e3f | 2005-08-09 20:20:18 +0000 | [diff] [blame] | 2865 | case ISD::SETEQ: return "seteq"; |
| 2866 | case ISD::SETGT: return "setgt"; |
| 2867 | case ISD::SETGE: return "setge"; |
| 2868 | case ISD::SETLT: return "setlt"; |
| 2869 | case ISD::SETLE: return "setle"; |
| 2870 | case ISD::SETNE: return "setne"; |
Chris Lattner | d75f19f | 2005-01-10 23:25:25 +0000 | [diff] [blame] | 2871 | } |
| 2872 | } |
| 2873 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2874 | |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 2875 | void SDNode::dump() const { dump(0); } |
| 2876 | void SDNode::dump(const SelectionDAG *G) const { |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2877 | std::cerr << (void*)this << ": "; |
| 2878 | |
| 2879 | for (unsigned i = 0, e = getNumValues(); i != e; ++i) { |
| 2880 | if (i) std::cerr << ","; |
Chris Lattner | 4ea6924 | 2005-01-15 07:14:32 +0000 | [diff] [blame] | 2881 | if (getValueType(i) == MVT::Other) |
| 2882 | std::cerr << "ch"; |
| 2883 | else |
| 2884 | std::cerr << MVT::getValueTypeString(getValueType(i)); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2885 | } |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 2886 | std::cerr << " = " << getOperationName(G); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2887 | |
| 2888 | std::cerr << " "; |
| 2889 | for (unsigned i = 0, e = getNumOperands(); i != e; ++i) { |
| 2890 | if (i) std::cerr << ", "; |
| 2891 | std::cerr << (void*)getOperand(i).Val; |
| 2892 | if (unsigned RN = getOperand(i).ResNo) |
| 2893 | std::cerr << ":" << RN; |
| 2894 | } |
| 2895 | |
| 2896 | if (const ConstantSDNode *CSDN = dyn_cast<ConstantSDNode>(this)) { |
| 2897 | std::cerr << "<" << CSDN->getValue() << ">"; |
| 2898 | } else if (const ConstantFPSDNode *CSDN = dyn_cast<ConstantFPSDNode>(this)) { |
| 2899 | std::cerr << "<" << CSDN->getValue() << ">"; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2900 | } else if (const GlobalAddressSDNode *GADN = |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2901 | dyn_cast<GlobalAddressSDNode>(this)) { |
Evan Cheng | 61ca74b | 2005-11-30 02:04:11 +0000 | [diff] [blame] | 2902 | int offset = GADN->getOffset(); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2903 | std::cerr << "<"; |
| 2904 | WriteAsOperand(std::cerr, GADN->getGlobal()) << ">"; |
Evan Cheng | 61ca74b | 2005-11-30 02:04:11 +0000 | [diff] [blame] | 2905 | if (offset > 0) |
| 2906 | std::cerr << " + " << offset; |
| 2907 | else |
| 2908 | std::cerr << " " << offset; |
Misha Brukman | dedf2bd | 2005-04-22 04:01:18 +0000 | [diff] [blame] | 2909 | } else if (const FrameIndexSDNode *FIDN = dyn_cast<FrameIndexSDNode>(this)) { |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2910 | std::cerr << "<" << FIDN->getIndex() << ">"; |
| 2911 | } else if (const ConstantPoolSDNode *CP = dyn_cast<ConstantPoolSDNode>(this)){ |
Evan Cheng | 38b7327 | 2006-02-26 08:36:57 +0000 | [diff] [blame] | 2912 | int offset = CP->getOffset(); |
Chris Lattner | 5839bf2 | 2005-08-26 17:15:30 +0000 | [diff] [blame] | 2913 | std::cerr << "<" << *CP->get() << ">"; |
Evan Cheng | 38b7327 | 2006-02-26 08:36:57 +0000 | [diff] [blame] | 2914 | if (offset > 0) |
| 2915 | std::cerr << " + " << offset; |
| 2916 | else |
| 2917 | std::cerr << " " << offset; |
Misha Brukman | dedf2bd | 2005-04-22 04:01:18 +0000 | [diff] [blame] | 2918 | } else if (const BasicBlockSDNode *BBDN = dyn_cast<BasicBlockSDNode>(this)) { |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2919 | std::cerr << "<"; |
| 2920 | const Value *LBB = (const Value*)BBDN->getBasicBlock()->getBasicBlock(); |
| 2921 | if (LBB) |
| 2922 | std::cerr << LBB->getName() << " "; |
| 2923 | std::cerr << (const void*)BBDN->getBasicBlock() << ">"; |
Chris Lattner | fa164b6 | 2005-08-19 21:34:13 +0000 | [diff] [blame] | 2924 | } else if (const RegisterSDNode *R = dyn_cast<RegisterSDNode>(this)) { |
Evan Cheng | 140e99b | 2006-01-11 22:13:48 +0000 | [diff] [blame] | 2925 | if (G && R->getReg() && MRegisterInfo::isPhysicalRegister(R->getReg())) { |
Chris Lattner | 7228aa7 | 2005-08-19 21:21:16 +0000 | [diff] [blame] | 2926 | std::cerr << " " <<G->getTarget().getRegisterInfo()->getName(R->getReg()); |
| 2927 | } else { |
| 2928 | std::cerr << " #" << R->getReg(); |
| 2929 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2930 | } else if (const ExternalSymbolSDNode *ES = |
| 2931 | dyn_cast<ExternalSymbolSDNode>(this)) { |
| 2932 | std::cerr << "'" << ES->getSymbol() << "'"; |
Chris Lattner | 2bf3c26 | 2005-05-09 04:08:27 +0000 | [diff] [blame] | 2933 | } else if (const SrcValueSDNode *M = dyn_cast<SrcValueSDNode>(this)) { |
| 2934 | if (M->getValue()) |
| 2935 | std::cerr << "<" << M->getValue() << ":" << M->getOffset() << ">"; |
| 2936 | else |
| 2937 | std::cerr << "<null:" << M->getOffset() << ">"; |
Chris Lattner | a23e815 | 2005-08-18 03:31:02 +0000 | [diff] [blame] | 2938 | } else if (const VTSDNode *N = dyn_cast<VTSDNode>(this)) { |
| 2939 | std::cerr << ":" << getValueTypeString(N->getVT()); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2940 | } |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2941 | } |
| 2942 | |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 2943 | static void DumpNodes(const SDNode *N, unsigned indent, const SelectionDAG *G) { |
Chris Lattner | ea946cd | 2005-01-09 20:38:33 +0000 | [diff] [blame] | 2944 | for (unsigned i = 0, e = N->getNumOperands(); i != e; ++i) |
| 2945 | if (N->getOperand(i).Val->hasOneUse()) |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 2946 | DumpNodes(N->getOperand(i).Val, indent+2, G); |
Chris Lattner | ea946cd | 2005-01-09 20:38:33 +0000 | [diff] [blame] | 2947 | else |
| 2948 | std::cerr << "\n" << std::string(indent+2, ' ') |
| 2949 | << (void*)N->getOperand(i).Val << ": <multiple use>"; |
Misha Brukman | edf128a | 2005-04-21 22:36:52 +0000 | [diff] [blame] | 2950 | |
Chris Lattner | ea946cd | 2005-01-09 20:38:33 +0000 | [diff] [blame] | 2951 | |
| 2952 | std::cerr << "\n" << std::string(indent, ' '); |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 2953 | N->dump(G); |
Chris Lattner | ea946cd | 2005-01-09 20:38:33 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2956 | void SelectionDAG::dump() const { |
| 2957 | std::cerr << "SelectionDAG has " << AllNodes.size() << " nodes:"; |
Chris Lattner | de202b3 | 2005-11-09 23:47:37 +0000 | [diff] [blame] | 2958 | std::vector<const SDNode*> Nodes; |
| 2959 | for (allnodes_const_iterator I = allnodes_begin(), E = allnodes_end(); |
| 2960 | I != E; ++I) |
| 2961 | Nodes.push_back(I); |
| 2962 | |
Chris Lattner | 49d2471 | 2005-01-09 20:26:36 +0000 | [diff] [blame] | 2963 | std::sort(Nodes.begin(), Nodes.end()); |
| 2964 | |
| 2965 | for (unsigned i = 0, e = Nodes.size(); i != e; ++i) { |
Chris Lattner | ea946cd | 2005-01-09 20:38:33 +0000 | [diff] [blame] | 2966 | if (!Nodes[i]->hasOneUse() && Nodes[i] != getRoot().Val) |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 2967 | DumpNodes(Nodes[i], 2, this); |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2968 | } |
Chris Lattner | ea946cd | 2005-01-09 20:38:33 +0000 | [diff] [blame] | 2969 | |
Chris Lattner | f3e133a | 2005-08-16 18:33:07 +0000 | [diff] [blame] | 2970 | DumpNodes(getRoot().Val, 2, this); |
Chris Lattner | ea946cd | 2005-01-09 20:38:33 +0000 | [diff] [blame] | 2971 | |
Chris Lattner | c3aae25 | 2005-01-07 07:46:32 +0000 | [diff] [blame] | 2972 | std::cerr << "\n\n"; |
| 2973 | } |
| 2974 | |
Evan Cheng | fae9f1c | 2006-02-09 22:11:03 +0000 | [diff] [blame] | 2975 | /// InsertISelMapEntry - A helper function to insert a key / element pair |
| 2976 | /// into a SDOperand to SDOperand map. This is added to avoid the map |
| 2977 | /// insertion operator from being inlined. |
| 2978 | void SelectionDAG::InsertISelMapEntry(std::map<SDOperand, SDOperand> &Map, |
| 2979 | SDNode *Key, unsigned KeyResNo, |
| 2980 | SDNode *Element, unsigned ElementResNo) { |
| 2981 | Map.insert(std::make_pair(SDOperand(Key, KeyResNo), |
| 2982 | SDOperand(Element, ElementResNo))); |
| 2983 | } |