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