fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1 | /* |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 2 | * Copyright (C) 2011, 2012 Apple Inc. All rights reserved. |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #include "config.h" |
| 27 | #include "DFGAbstractState.h" |
| 28 | |
| 29 | #if ENABLE(DFG_JIT) |
| 30 | |
| 31 | #include "CodeBlock.h" |
| 32 | #include "DFGBasicBlock.h" |
| 33 | |
| 34 | namespace JSC { namespace DFG { |
| 35 | |
| 36 | #define CFA_PROFILING 0 |
| 37 | |
| 38 | #if CFA_PROFILING |
| 39 | #define PROFILE(flag) SamplingFlags::ScopedFlag scopedFlag(flag) |
| 40 | #else |
| 41 | #define PROFILE(flag) do { } while (false) |
| 42 | #endif |
| 43 | |
| 44 | // Profiling flags |
| 45 | #define FLAG_FOR_BLOCK_INITIALIZATION 17 |
| 46 | #define FLAG_FOR_BLOCK_END 18 |
| 47 | #define FLAG_FOR_EXECUTION 19 |
| 48 | #define FLAG_FOR_MERGE_TO_SUCCESSORS 20 |
| 49 | #define FLAG_FOR_STRUCTURE_CLOBBERING 21 |
| 50 | |
fpizlo@apple.com | adf274c | 2012-02-18 07:56:10 +0000 | [diff] [blame] | 51 | AbstractState::AbstractState(Graph& graph) |
| 52 | : m_codeBlock(graph.m_codeBlock) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 53 | , m_graph(graph) |
fpizlo@apple.com | adf274c | 2012-02-18 07:56:10 +0000 | [diff] [blame] | 54 | , m_variables(m_codeBlock->numParameters(), graph.m_localVars) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 55 | , m_block(0) |
| 56 | { |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 57 | m_nodes.resize(graph.size()); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | AbstractState::~AbstractState() { } |
| 61 | |
| 62 | void AbstractState::beginBasicBlock(BasicBlock* basicBlock) |
| 63 | { |
| 64 | PROFILE(FLAG_FOR_BLOCK_INITIALIZATION); |
| 65 | |
| 66 | ASSERT(!m_block); |
| 67 | |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 68 | ASSERT(basicBlock->variablesAtHead.numberOfLocals() == basicBlock->valuesAtHead.numberOfLocals()); |
| 69 | ASSERT(basicBlock->variablesAtTail.numberOfLocals() == basicBlock->valuesAtTail.numberOfLocals()); |
| 70 | ASSERT(basicBlock->variablesAtHead.numberOfLocals() == basicBlock->variablesAtTail.numberOfLocals()); |
| 71 | |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 72 | for (size_t i = 0; i < basicBlock->size(); i++) |
| 73 | m_nodes[basicBlock->at(i)].clear(); |
| 74 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 75 | m_variables = basicBlock->valuesAtHead; |
| 76 | m_haveStructures = false; |
| 77 | for (size_t i = 0; i < m_variables.numberOfArguments(); ++i) { |
| 78 | if (m_variables.argument(i).m_structure.isNeitherClearNorTop()) { |
| 79 | m_haveStructures = true; |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | for (size_t i = 0; i < m_variables.numberOfLocals(); ++i) { |
| 84 | if (m_variables.local(i).m_structure.isNeitherClearNorTop()) { |
| 85 | m_haveStructures = true; |
| 86 | break; |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | basicBlock->cfaShouldRevisit = false; |
| 91 | basicBlock->cfaHasVisited = true; |
| 92 | m_block = basicBlock; |
| 93 | m_isValid = true; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 94 | m_foundConstants = false; |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 95 | m_branchDirection = InvalidBranchDirection; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | void AbstractState::initialize(Graph& graph) |
| 99 | { |
| 100 | PROFILE(FLAG_FOR_BLOCK_INITIALIZATION); |
| 101 | BasicBlock* root = graph.m_blocks[0].get(); |
| 102 | root->cfaShouldRevisit = true; |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 103 | root->cfaHasVisited = false; |
| 104 | root->cfaFoundConstants = false; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 105 | for (size_t i = 0; i < root->valuesAtHead.numberOfArguments(); ++i) { |
fpizlo@apple.com | 4f536126 | 2012-02-16 10:06:28 +0000 | [diff] [blame] | 106 | Node& node = graph[root->variablesAtHead.argument(i)]; |
fpizlo@apple.com | d7897b1 | 2012-03-12 23:15:45 +0000 | [diff] [blame] | 107 | ASSERT(node.op() == SetArgument); |
fpizlo@apple.com | 4f536126 | 2012-02-16 10:06:28 +0000 | [diff] [blame] | 108 | if (!node.shouldGenerate()) { |
| 109 | // The argument is dead. We don't do any checks for such arguments, and so |
| 110 | // for the purpose of the analysis, they contain no value. |
| 111 | root->valuesAtHead.argument(i).clear(); |
| 112 | continue; |
| 113 | } |
| 114 | |
fpizlo@apple.com | 1688cc1 | 2012-05-23 07:29:02 +0000 | [diff] [blame] | 115 | if (node.variableAccessData()->isCaptured()) { |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 116 | root->valuesAtHead.argument(i).makeTop(); |
| 117 | continue; |
| 118 | } |
| 119 | |
fpizlo@apple.com | 4f536126 | 2012-02-16 10:06:28 +0000 | [diff] [blame] | 120 | PredictedType prediction = node.variableAccessData()->prediction(); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 121 | if (isInt32Prediction(prediction)) |
| 122 | root->valuesAtHead.argument(i).set(PredictInt32); |
| 123 | else if (isArrayPrediction(prediction)) |
| 124 | root->valuesAtHead.argument(i).set(PredictArray); |
| 125 | else if (isBooleanPrediction(prediction)) |
| 126 | root->valuesAtHead.argument(i).set(PredictBoolean); |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 127 | else if (isInt8ArrayPrediction(prediction)) |
| 128 | root->valuesAtHead.argument(i).set(PredictInt8Array); |
| 129 | else if (isInt16ArrayPrediction(prediction)) |
| 130 | root->valuesAtHead.argument(i).set(PredictInt16Array); |
| 131 | else if (isInt32ArrayPrediction(prediction)) |
| 132 | root->valuesAtHead.argument(i).set(PredictInt32Array); |
| 133 | else if (isUint8ArrayPrediction(prediction)) |
| 134 | root->valuesAtHead.argument(i).set(PredictUint8Array); |
caio.oliveira@openbossa.org | 992fc37 | 2012-01-18 01:11:16 +0000 | [diff] [blame] | 135 | else if (isUint8ClampedArrayPrediction(prediction)) |
| 136 | root->valuesAtHead.argument(i).set(PredictUint8ClampedArray); |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 137 | else if (isUint16ArrayPrediction(prediction)) |
| 138 | root->valuesAtHead.argument(i).set(PredictUint16Array); |
| 139 | else if (isUint32ArrayPrediction(prediction)) |
| 140 | root->valuesAtHead.argument(i).set(PredictUint32Array); |
| 141 | else if (isFloat32ArrayPrediction(prediction)) |
| 142 | root->valuesAtHead.argument(i).set(PredictFloat32Array); |
| 143 | else if (isFloat64ArrayPrediction(prediction)) |
| 144 | root->valuesAtHead.argument(i).set(PredictFloat64Array); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 145 | else |
| 146 | root->valuesAtHead.argument(i).makeTop(); |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 147 | |
| 148 | root->valuesAtTail.argument(i).clear(); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 149 | } |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 150 | for (size_t i = 0; i < root->valuesAtHead.numberOfLocals(); ++i) { |
fpizlo@apple.com | 1688cc1 | 2012-05-23 07:29:02 +0000 | [diff] [blame] | 151 | NodeIndex nodeIndex = root->variablesAtHead.local(i); |
| 152 | if (nodeIndex != NoNode && graph[nodeIndex].variableAccessData()->isCaptured()) |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 153 | root->valuesAtHead.local(i).makeTop(); |
| 154 | else |
| 155 | root->valuesAtHead.local(i).clear(); |
| 156 | root->valuesAtTail.local(i).clear(); |
| 157 | } |
| 158 | for (BlockIndex blockIndex = 1 ; blockIndex < graph.m_blocks.size(); ++blockIndex) { |
| 159 | BasicBlock* block = graph.m_blocks[blockIndex].get(); |
| 160 | if (!block) |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 161 | continue; |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 162 | if (!block->isReachable) |
| 163 | continue; |
| 164 | block->cfaShouldRevisit = false; |
| 165 | block->cfaHasVisited = false; |
| 166 | block->cfaFoundConstants = false; |
| 167 | for (size_t i = 0; i < block->valuesAtHead.numberOfArguments(); ++i) { |
| 168 | block->valuesAtHead.argument(i).clear(); |
| 169 | block->valuesAtTail.argument(i).clear(); |
| 170 | } |
| 171 | for (size_t i = 0; i < block->valuesAtHead.numberOfLocals(); ++i) { |
| 172 | block->valuesAtHead.local(i).clear(); |
| 173 | block->valuesAtTail.local(i).clear(); |
| 174 | } |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 175 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 176 | } |
| 177 | |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 178 | bool AbstractState::endBasicBlock(MergeMode mergeMode, BranchDirection* branchDirectionPtr) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 179 | { |
| 180 | PROFILE(FLAG_FOR_BLOCK_END); |
| 181 | ASSERT(m_block); |
| 182 | |
| 183 | BasicBlock* block = m_block; // Save the block for successor merging. |
| 184 | |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 185 | block->cfaFoundConstants = m_foundConstants; |
| 186 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 187 | if (!m_isValid) { |
| 188 | reset(); |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | bool changed = false; |
| 193 | |
| 194 | if (mergeMode != DontMerge || !ASSERT_DISABLED) { |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 195 | for (size_t argument = 0; argument < block->variablesAtTail.numberOfArguments(); ++argument) { |
| 196 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
fpizlo@apple.com | d095b24 | 2012-02-12 03:21:32 +0000 | [diff] [blame] | 197 | dataLog(" Merging state for argument %zu.\n", argument); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 198 | #endif |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 199 | AbstractValue& destination = block->valuesAtTail.argument(argument); |
fpizlo@apple.com | 1688cc1 | 2012-05-23 07:29:02 +0000 | [diff] [blame] | 200 | NodeIndex nodeIndex = block->variablesAtTail.argument(argument); |
| 201 | if (nodeIndex != NoNode && m_graph[nodeIndex].variableAccessData()->isCaptured()) { |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 202 | if (!destination.isTop()) { |
| 203 | destination.makeTop(); |
| 204 | changed = true; |
| 205 | } |
| 206 | } else |
| 207 | changed |= mergeStateAtTail(destination, m_variables.argument(argument), block->variablesAtTail.argument(argument)); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 208 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 209 | |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 210 | for (size_t local = 0; local < block->variablesAtTail.numberOfLocals(); ++local) { |
| 211 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
fpizlo@apple.com | d095b24 | 2012-02-12 03:21:32 +0000 | [diff] [blame] | 212 | dataLog(" Merging state for local %zu.\n", local); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 213 | #endif |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 214 | AbstractValue& destination = block->valuesAtTail.local(local); |
fpizlo@apple.com | 1688cc1 | 2012-05-23 07:29:02 +0000 | [diff] [blame] | 215 | NodeIndex nodeIndex = block->variablesAtTail.local(local); |
| 216 | if (nodeIndex != NoNode && m_graph[nodeIndex].variableAccessData()->isCaptured()) { |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 217 | if (!destination.isTop()) { |
| 218 | destination.makeTop(); |
| 219 | changed = true; |
| 220 | } |
| 221 | } else |
| 222 | changed |= mergeStateAtTail(destination, m_variables.local(local), block->variablesAtTail.local(local)); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 223 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | ASSERT(mergeMode != DontMerge || !changed); |
| 227 | |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 228 | BranchDirection branchDirection = m_branchDirection; |
| 229 | if (branchDirectionPtr) |
| 230 | *branchDirectionPtr = branchDirection; |
| 231 | |
| 232 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
| 233 | dataLog(" Branch direction = %s\n", branchDirectionToString(branchDirection)); |
| 234 | #endif |
| 235 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 236 | reset(); |
| 237 | |
| 238 | if (mergeMode != MergeToSuccessors) |
| 239 | return changed; |
| 240 | |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 241 | return mergeToSuccessors(m_graph, block, branchDirection); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | void AbstractState::reset() |
| 245 | { |
| 246 | m_block = 0; |
| 247 | m_isValid = false; |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 248 | m_branchDirection = InvalidBranchDirection; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 249 | } |
| 250 | |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 251 | bool AbstractState::execute(unsigned indexInBlock) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 252 | { |
| 253 | PROFILE(FLAG_FOR_EXECUTION); |
| 254 | ASSERT(m_block); |
| 255 | ASSERT(m_isValid); |
| 256 | |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 257 | NodeIndex nodeIndex = m_block->at(indexInBlock); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 258 | Node& node = m_graph[nodeIndex]; |
| 259 | |
| 260 | if (!node.shouldGenerate()) |
| 261 | return true; |
| 262 | |
fpizlo@apple.com | d7897b1 | 2012-03-12 23:15:45 +0000 | [diff] [blame] | 263 | switch (node.op()) { |
fpizlo@apple.com | 53aa8dc | 2011-11-15 21:54:38 +0000 | [diff] [blame] | 264 | case JSConstant: |
| 265 | case WeakJSConstant: { |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 266 | forNode(nodeIndex).set(m_graph.valueOfJSConstant(nodeIndex)); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 267 | break; |
| 268 | } |
| 269 | |
| 270 | case GetLocal: { |
fpizlo@apple.com | 1688cc1 | 2012-05-23 07:29:02 +0000 | [diff] [blame] | 271 | if (node.variableAccessData()->isCaptured()) |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 272 | forNode(nodeIndex).makeTop(); |
| 273 | else |
| 274 | forNode(nodeIndex) = m_variables.operand(node.local()); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 275 | break; |
| 276 | } |
| 277 | |
fpizlo@apple.com | 9b92872 | 2012-05-24 00:18:55 +0000 | [diff] [blame] | 278 | case GetLocalUnlinked: { |
| 279 | forNode(nodeIndex).makeTop(); |
| 280 | break; |
| 281 | } |
| 282 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 283 | case SetLocal: { |
fpizlo@apple.com | 1688cc1 | 2012-05-23 07:29:02 +0000 | [diff] [blame] | 284 | if (node.variableAccessData()->isCaptured()) |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 285 | break; |
| 286 | |
fpizlo@apple.com | 10f22fc | 2011-12-14 07:16:36 +0000 | [diff] [blame] | 287 | if (node.variableAccessData()->shouldUseDoubleFormat()) { |
| 288 | forNode(node.child1()).filter(PredictNumber); |
| 289 | m_variables.operand(node.local()).set(PredictDouble); |
| 290 | break; |
| 291 | } |
| 292 | |
fpizlo@apple.com | af8940b | 2012-04-11 00:37:04 +0000 | [diff] [blame] | 293 | PredictedType predictedType = node.variableAccessData()->argumentAwarePrediction(); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 294 | if (isInt32Prediction(predictedType)) |
| 295 | forNode(node.child1()).filter(PredictInt32); |
| 296 | else if (isArrayPrediction(predictedType)) |
| 297 | forNode(node.child1()).filter(PredictArray); |
| 298 | else if (isBooleanPrediction(predictedType)) |
| 299 | forNode(node.child1()).filter(PredictBoolean); |
| 300 | |
| 301 | m_variables.operand(node.local()) = forNode(node.child1()); |
| 302 | break; |
| 303 | } |
| 304 | |
| 305 | case SetArgument: |
| 306 | // Assert that the state of arguments has been set. |
| 307 | ASSERT(!m_block->valuesAtHead.operand(node.local()).isClear()); |
| 308 | break; |
| 309 | |
| 310 | case BitAnd: |
| 311 | case BitOr: |
| 312 | case BitXor: |
| 313 | case BitRShift: |
| 314 | case BitLShift: |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 315 | case BitURShift: { |
| 316 | JSValue left = forNode(node.child1()).value(); |
| 317 | JSValue right = forNode(node.child2()).value(); |
| 318 | if (left && right && left.isInt32() && right.isInt32()) { |
| 319 | int32_t a = left.asInt32(); |
| 320 | int32_t b = right.asInt32(); |
| 321 | switch (node.op()) { |
| 322 | case BitAnd: |
| 323 | forNode(nodeIndex).set(JSValue(a & b)); |
| 324 | break; |
| 325 | case BitOr: |
| 326 | forNode(nodeIndex).set(JSValue(a | b)); |
| 327 | break; |
| 328 | case BitXor: |
| 329 | forNode(nodeIndex).set(JSValue(a ^ b)); |
| 330 | break; |
| 331 | case BitRShift: |
| 332 | forNode(nodeIndex).set(JSValue(a >> static_cast<uint32_t>(b))); |
| 333 | break; |
| 334 | case BitLShift: |
| 335 | forNode(nodeIndex).set(JSValue(a << static_cast<uint32_t>(b))); |
| 336 | break; |
| 337 | case BitURShift: |
| 338 | forNode(nodeIndex).set(JSValue(static_cast<uint32_t>(a) >> static_cast<uint32_t>(b))); |
| 339 | break; |
| 340 | default: |
| 341 | ASSERT_NOT_REACHED(); |
| 342 | } |
| 343 | m_foundConstants = true; |
| 344 | break; |
| 345 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 346 | forNode(node.child1()).filter(PredictInt32); |
| 347 | forNode(node.child2()).filter(PredictInt32); |
| 348 | forNode(nodeIndex).set(PredictInt32); |
| 349 | break; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 350 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 351 | |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 352 | case UInt32ToNumber: { |
| 353 | JSValue child = forNode(node.child1()).value(); |
| 354 | if (child && child.isNumber()) { |
| 355 | ASSERT(child.isInt32()); |
| 356 | forNode(nodeIndex).set(JSValue(child.asUInt32())); |
| 357 | m_foundConstants = true; |
| 358 | break; |
| 359 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 360 | if (!node.canSpeculateInteger()) |
| 361 | forNode(nodeIndex).set(PredictDouble); |
| 362 | else |
| 363 | forNode(nodeIndex).set(PredictInt32); |
| 364 | break; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 365 | } |
| 366 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 367 | |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 368 | case DoubleAsInt32: { |
| 369 | JSValue child = forNode(node.child1()).value(); |
| 370 | if (child && child.isNumber()) { |
| 371 | double asDouble = child.asNumber(); |
| 372 | int32_t asInt = JSC::toInt32(asDouble); |
| 373 | if (bitwise_cast<int64_t>(static_cast<double>(asInt)) == bitwise_cast<int64_t>(asDouble)) { |
| 374 | forNode(nodeIndex).set(JSValue(asInt)); |
| 375 | m_foundConstants = true; |
| 376 | break; |
| 377 | } |
| 378 | } |
fpizlo@apple.com | 3d22338 | 2012-04-24 19:19:35 +0000 | [diff] [blame] | 379 | forNode(node.child1()).filter(PredictNumber); |
| 380 | forNode(nodeIndex).set(PredictInt32); |
| 381 | break; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 382 | } |
fpizlo@apple.com | 3d22338 | 2012-04-24 19:19:35 +0000 | [diff] [blame] | 383 | |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 384 | case ValueToInt32: { |
| 385 | JSValue child = forNode(node.child1()).value(); |
| 386 | if (child && child.isNumber()) { |
| 387 | if (child.isInt32()) |
| 388 | forNode(nodeIndex).set(child); |
| 389 | else |
| 390 | forNode(nodeIndex).set(JSValue(JSC::toInt32(child.asDouble()))); |
| 391 | m_foundConstants = true; |
| 392 | break; |
| 393 | } |
fpizlo@apple.com | 2fc3dbd | 2012-03-14 02:54:58 +0000 | [diff] [blame] | 394 | if (m_graph[node.child1()].shouldSpeculateInteger()) |
fpizlo@apple.com | 9c7addf | 2012-03-08 10:01:32 +0000 | [diff] [blame] | 395 | forNode(node.child1()).filter(PredictInt32); |
fpizlo@apple.com | 2fc3dbd | 2012-03-14 02:54:58 +0000 | [diff] [blame] | 396 | else if (m_graph[node.child1()].shouldSpeculateNumber()) |
| 397 | forNode(node.child1()).filter(PredictNumber); |
| 398 | else if (m_graph[node.child1()].shouldSpeculateBoolean()) |
| 399 | forNode(node.child1()).filter(PredictBoolean); |
fpizlo@apple.com | 9c7addf | 2012-03-08 10:01:32 +0000 | [diff] [blame] | 400 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 401 | forNode(nodeIndex).set(PredictInt32); |
| 402 | break; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 403 | } |
fpizlo@apple.com | 96cfc6b | 2012-03-25 23:50:24 +0000 | [diff] [blame] | 404 | |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 405 | case Int32ToDouble: { |
| 406 | JSValue child = forNode(node.child1()).value(); |
| 407 | if (child && child.isNumber()) { |
| 408 | forNode(nodeIndex).set(JSValue(JSValue::EncodeAsDouble, child.asNumber())); |
| 409 | m_foundConstants = true; |
| 410 | break; |
| 411 | } |
fpizlo@apple.com | 96cfc6b | 2012-03-25 23:50:24 +0000 | [diff] [blame] | 412 | forNode(node.child1()).filter(PredictNumber); |
| 413 | forNode(nodeIndex).set(PredictDouble); |
| 414 | break; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 415 | } |
fpizlo@apple.com | a1cc0fd | 2012-04-24 20:43:01 +0000 | [diff] [blame] | 416 | |
| 417 | case CheckNumber: |
| 418 | forNode(node.child1()).filter(PredictNumber); |
| 419 | break; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 420 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 421 | case ValueAdd: |
| 422 | case ArithAdd: { |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 423 | JSValue left = forNode(node.child1()).value(); |
| 424 | JSValue right = forNode(node.child2()).value(); |
| 425 | if (left && right && left.isNumber() && right.isNumber()) { |
| 426 | forNode(nodeIndex).set(JSValue(left.asNumber() + right.asNumber())); |
| 427 | m_foundConstants = true; |
| 428 | break; |
| 429 | } |
fpizlo@apple.com | adf274c | 2012-02-18 07:56:10 +0000 | [diff] [blame] | 430 | if (m_graph.addShouldSpeculateInteger(node)) { |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 431 | forNode(node.child1()).filter(PredictInt32); |
| 432 | forNode(node.child2()).filter(PredictInt32); |
| 433 | forNode(nodeIndex).set(PredictInt32); |
| 434 | break; |
| 435 | } |
| 436 | if (Node::shouldSpeculateNumber(m_graph[node.child1()], m_graph[node.child2()])) { |
| 437 | forNode(node.child1()).filter(PredictNumber); |
| 438 | forNode(node.child2()).filter(PredictNumber); |
| 439 | forNode(nodeIndex).set(PredictDouble); |
| 440 | break; |
| 441 | } |
fpizlo@apple.com | d7897b1 | 2012-03-12 23:15:45 +0000 | [diff] [blame] | 442 | if (node.op() == ValueAdd) { |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 443 | clobberStructures(indexInBlock); |
fpizlo@apple.com | c0d2191 | 2012-02-14 21:26:26 +0000 | [diff] [blame] | 444 | forNode(nodeIndex).set(PredictString | PredictInt32 | PredictNumber); |
| 445 | break; |
| 446 | } |
| 447 | // We don't handle this yet. :-( |
| 448 | m_isValid = false; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 449 | break; |
| 450 | } |
| 451 | |
fpizlo@apple.com | 0c31ace | 2012-02-01 23:08:54 +0000 | [diff] [blame] | 452 | case ArithSub: { |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 453 | JSValue left = forNode(node.child1()).value(); |
| 454 | JSValue right = forNode(node.child2()).value(); |
| 455 | if (left && right && left.isNumber() && right.isNumber()) { |
| 456 | forNode(nodeIndex).set(JSValue(left.asNumber() - right.asNumber())); |
| 457 | m_foundConstants = true; |
| 458 | break; |
| 459 | } |
fpizlo@apple.com | adf274c | 2012-02-18 07:56:10 +0000 | [diff] [blame] | 460 | if (m_graph.addShouldSpeculateInteger(node)) { |
fpizlo@apple.com | 0c31ace | 2012-02-01 23:08:54 +0000 | [diff] [blame] | 461 | forNode(node.child1()).filter(PredictInt32); |
| 462 | forNode(node.child2()).filter(PredictInt32); |
| 463 | forNode(nodeIndex).set(PredictInt32); |
| 464 | break; |
| 465 | } |
| 466 | forNode(node.child1()).filter(PredictNumber); |
| 467 | forNode(node.child2()).filter(PredictNumber); |
| 468 | forNode(nodeIndex).set(PredictDouble); |
| 469 | break; |
| 470 | } |
| 471 | |
barraclough@apple.com | 8ff7e8c | 2012-02-28 00:31:28 +0000 | [diff] [blame] | 472 | case ArithNegate: { |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 473 | JSValue child = forNode(node.child1()).value(); |
| 474 | if (child && child.isNumber()) { |
| 475 | forNode(nodeIndex).set(JSValue(-child.asNumber())); |
| 476 | m_foundConstants = true; |
| 477 | break; |
| 478 | } |
barraclough@apple.com | 8ff7e8c | 2012-02-28 00:31:28 +0000 | [diff] [blame] | 479 | if (m_graph.negateShouldSpeculateInteger(node)) { |
| 480 | forNode(node.child1()).filter(PredictInt32); |
| 481 | forNode(nodeIndex).set(PredictInt32); |
| 482 | break; |
| 483 | } |
| 484 | forNode(node.child1()).filter(PredictNumber); |
| 485 | forNode(nodeIndex).set(PredictDouble); |
| 486 | break; |
| 487 | } |
| 488 | |
fpizlo@apple.com | fa9f10c | 2012-05-22 17:18:21 +0000 | [diff] [blame] | 489 | case ArithMul: { |
| 490 | JSValue left = forNode(node.child1()).value(); |
| 491 | JSValue right = forNode(node.child2()).value(); |
| 492 | if (left && right && left.isNumber() && right.isNumber()) { |
| 493 | forNode(nodeIndex).set(JSValue(left.asNumber() * right.asNumber())); |
| 494 | m_foundConstants = true; |
| 495 | break; |
| 496 | } |
| 497 | if (m_graph.mulShouldSpeculateInteger(node)) { |
| 498 | forNode(node.child1()).filter(PredictInt32); |
| 499 | forNode(node.child2()).filter(PredictInt32); |
| 500 | forNode(nodeIndex).set(PredictInt32); |
| 501 | break; |
| 502 | } |
| 503 | forNode(node.child1()).filter(PredictNumber); |
| 504 | forNode(node.child2()).filter(PredictNumber); |
| 505 | forNode(nodeIndex).set(PredictDouble); |
| 506 | break; |
| 507 | } |
| 508 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 509 | case ArithDiv: |
| 510 | case ArithMin: |
fpizlo@apple.com | 19a17279 | 2012-03-24 20:15:57 +0000 | [diff] [blame] | 511 | case ArithMax: |
| 512 | case ArithMod: { |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 513 | JSValue left = forNode(node.child1()).value(); |
| 514 | JSValue right = forNode(node.child2()).value(); |
| 515 | if (left && right && left.isNumber() && right.isNumber()) { |
| 516 | double a = left.asNumber(); |
| 517 | double b = right.asNumber(); |
| 518 | switch (node.op()) { |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 519 | case ArithDiv: |
| 520 | forNode(nodeIndex).set(JSValue(a / b)); |
| 521 | break; |
| 522 | case ArithMin: |
| 523 | forNode(nodeIndex).set(JSValue(a < b ? a : (b <= a ? b : a + b))); |
| 524 | break; |
| 525 | case ArithMax: |
| 526 | forNode(nodeIndex).set(JSValue(a > b ? a : (b >= a ? b : a + b))); |
| 527 | break; |
| 528 | case ArithMod: |
| 529 | forNode(nodeIndex).set(JSValue(fmod(a, b))); |
| 530 | break; |
| 531 | default: |
| 532 | ASSERT_NOT_REACHED(); |
| 533 | break; |
| 534 | } |
| 535 | m_foundConstants = true; |
| 536 | break; |
| 537 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 538 | if (Node::shouldSpeculateInteger(m_graph[node.child1()], m_graph[node.child2()]) && node.canSpeculateInteger()) { |
| 539 | forNode(node.child1()).filter(PredictInt32); |
| 540 | forNode(node.child2()).filter(PredictInt32); |
| 541 | forNode(nodeIndex).set(PredictInt32); |
| 542 | break; |
| 543 | } |
| 544 | forNode(node.child1()).filter(PredictNumber); |
| 545 | forNode(node.child2()).filter(PredictNumber); |
| 546 | forNode(nodeIndex).set(PredictDouble); |
| 547 | break; |
| 548 | } |
| 549 | |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 550 | case ArithAbs: { |
| 551 | JSValue child = forNode(node.child1()).value(); |
| 552 | if (child && child.isNumber()) { |
| 553 | forNode(nodeIndex).set(JSValue(fabs(child.asNumber()))); |
| 554 | m_foundConstants = true; |
| 555 | break; |
| 556 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 557 | if (m_graph[node.child1()].shouldSpeculateInteger() && node.canSpeculateInteger()) { |
| 558 | forNode(node.child1()).filter(PredictInt32); |
| 559 | forNode(nodeIndex).set(PredictInt32); |
| 560 | break; |
| 561 | } |
| 562 | forNode(node.child1()).filter(PredictNumber); |
| 563 | forNode(nodeIndex).set(PredictDouble); |
| 564 | break; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 565 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 566 | |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 567 | case ArithSqrt: { |
| 568 | JSValue child = forNode(node.child1()).value(); |
| 569 | if (child && child.isNumber()) { |
| 570 | forNode(nodeIndex).set(JSValue(sqrt(child.asNumber()))); |
| 571 | m_foundConstants = true; |
| 572 | break; |
| 573 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 574 | forNode(node.child1()).filter(PredictNumber); |
| 575 | forNode(nodeIndex).set(PredictDouble); |
| 576 | break; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 577 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 578 | |
| 579 | case LogicalNot: { |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 580 | JSValue childConst = forNode(node.child1()).value(); |
| 581 | if (childConst) { |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 582 | forNode(nodeIndex).set(jsBoolean(!childConst.toBoolean())); |
| 583 | break; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 584 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 585 | Node& child = m_graph[node.child1()]; |
fpizlo@apple.com | ad60ef3 | 2012-03-22 03:47:55 +0000 | [diff] [blame] | 586 | if (isBooleanPrediction(child.prediction())) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 587 | forNode(node.child1()).filter(PredictBoolean); |
| 588 | else if (child.shouldSpeculateFinalObjectOrOther()) |
| 589 | forNode(node.child1()).filter(PredictFinalObject | PredictOther); |
| 590 | else if (child.shouldSpeculateArrayOrOther()) |
| 591 | forNode(node.child1()).filter(PredictArray | PredictOther); |
| 592 | else if (child.shouldSpeculateInteger()) |
| 593 | forNode(node.child1()).filter(PredictInt32); |
| 594 | else if (child.shouldSpeculateNumber()) |
| 595 | forNode(node.child1()).filter(PredictNumber); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 596 | forNode(nodeIndex).set(PredictBoolean); |
| 597 | break; |
| 598 | } |
fpizlo@apple.com | 1d21689 | 2012-04-12 00:55:44 +0000 | [diff] [blame] | 599 | |
| 600 | case IsUndefined: |
| 601 | case IsBoolean: |
| 602 | case IsNumber: |
| 603 | case IsString: |
| 604 | case IsObject: |
| 605 | case IsFunction: { |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 606 | JSValue child = forNode(node.child1()).value(); |
| 607 | if (child) { |
| 608 | bool foundConstant = true; |
| 609 | switch (node.op()) { |
| 610 | case IsUndefined: |
| 611 | forNode(nodeIndex).set(jsBoolean( |
| 612 | child.isCell() |
| 613 | ? child.asCell()->structure()->typeInfo().masqueradesAsUndefined() |
| 614 | : child.isUndefined())); |
| 615 | break; |
| 616 | case IsBoolean: |
| 617 | forNode(nodeIndex).set(jsBoolean(child.isBoolean())); |
| 618 | break; |
| 619 | case IsNumber: |
| 620 | forNode(nodeIndex).set(jsBoolean(child.isNumber())); |
| 621 | break; |
| 622 | case IsString: |
| 623 | forNode(nodeIndex).set(jsBoolean(isJSString(child))); |
| 624 | break; |
| 625 | default: |
| 626 | break; |
| 627 | } |
| 628 | if (foundConstant) { |
| 629 | m_foundConstants = true; |
| 630 | break; |
| 631 | } |
| 632 | } |
fpizlo@apple.com | 1d21689 | 2012-04-12 00:55:44 +0000 | [diff] [blame] | 633 | forNode(nodeIndex).set(PredictBoolean); |
| 634 | break; |
| 635 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 636 | |
| 637 | case CompareLess: |
| 638 | case CompareLessEq: |
| 639 | case CompareGreater: |
| 640 | case CompareGreaterEq: |
| 641 | case CompareEq: { |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 642 | JSValue leftConst = forNode(node.child1()).value(); |
| 643 | JSValue rightConst = forNode(node.child2()).value(); |
| 644 | if (leftConst && rightConst && leftConst.isNumber() && rightConst.isNumber()) { |
| 645 | double a = leftConst.asNumber(); |
| 646 | double b = rightConst.asNumber(); |
| 647 | switch (node.op()) { |
| 648 | case CompareLess: |
| 649 | forNode(nodeIndex).set(jsBoolean(a < b)); |
| 650 | break; |
| 651 | case CompareLessEq: |
| 652 | forNode(nodeIndex).set(jsBoolean(a <= b)); |
| 653 | break; |
| 654 | case CompareGreater: |
| 655 | forNode(nodeIndex).set(jsBoolean(a > b)); |
| 656 | break; |
| 657 | case CompareGreaterEq: |
| 658 | forNode(nodeIndex).set(jsBoolean(a >= b)); |
| 659 | break; |
| 660 | case CompareEq: |
| 661 | forNode(nodeIndex).set(jsBoolean(a == b)); |
| 662 | break; |
| 663 | default: |
| 664 | ASSERT_NOT_REACHED(); |
| 665 | break; |
| 666 | } |
| 667 | m_foundConstants = true; |
| 668 | break; |
| 669 | } |
| 670 | |
fpizlo@apple.com | 8b7cf38 | 2012-03-31 02:21:35 +0000 | [diff] [blame] | 671 | forNode(nodeIndex).set(PredictBoolean); |
| 672 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 673 | Node& left = m_graph[node.child1()]; |
| 674 | Node& right = m_graph[node.child2()]; |
| 675 | PredictedType filter; |
| 676 | if (Node::shouldSpeculateInteger(left, right)) |
| 677 | filter = PredictInt32; |
| 678 | else if (Node::shouldSpeculateNumber(left, right)) |
| 679 | filter = PredictNumber; |
fpizlo@apple.com | 8b7cf38 | 2012-03-31 02:21:35 +0000 | [diff] [blame] | 680 | else if (node.op() == CompareEq) { |
| 681 | if ((m_graph.isConstant(node.child1().index()) |
| 682 | && m_graph.valueOfJSConstant(node.child1().index()).isNull()) |
| 683 | || (m_graph.isConstant(node.child2().index()) |
| 684 | && m_graph.valueOfJSConstant(node.child2().index()).isNull())) { |
| 685 | // We know that this won't clobber the world. But that's all we know. |
| 686 | break; |
| 687 | } |
| 688 | |
| 689 | if (Node::shouldSpeculateFinalObject(left, right)) |
| 690 | filter = PredictFinalObject; |
| 691 | else if (Node::shouldSpeculateArray(left, right)) |
| 692 | filter = PredictArray; |
| 693 | else if (left.shouldSpeculateFinalObject() && right.shouldSpeculateFinalObjectOrOther()) { |
| 694 | forNode(node.child1()).filter(PredictFinalObject); |
| 695 | forNode(node.child2()).filter(PredictFinalObject | PredictOther); |
| 696 | break; |
| 697 | } else if (right.shouldSpeculateFinalObject() && left.shouldSpeculateFinalObjectOrOther()) { |
| 698 | forNode(node.child1()).filter(PredictFinalObject | PredictOther); |
| 699 | forNode(node.child2()).filter(PredictFinalObject); |
| 700 | break; |
| 701 | } else if (left.shouldSpeculateArray() && right.shouldSpeculateArrayOrOther()) { |
| 702 | forNode(node.child1()).filter(PredictFinalObject); |
| 703 | forNode(node.child2()).filter(PredictFinalObject | PredictOther); |
| 704 | break; |
| 705 | } else if (right.shouldSpeculateArray() && left.shouldSpeculateArrayOrOther()) { |
| 706 | forNode(node.child1()).filter(PredictFinalObject | PredictOther); |
| 707 | forNode(node.child2()).filter(PredictFinalObject); |
| 708 | break; |
| 709 | } else { |
| 710 | filter = PredictTop; |
| 711 | clobberStructures(indexInBlock); |
| 712 | } |
| 713 | } else { |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 714 | filter = PredictTop; |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 715 | clobberStructures(indexInBlock); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 716 | } |
| 717 | forNode(node.child1()).filter(filter); |
| 718 | forNode(node.child2()).filter(filter); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 719 | break; |
| 720 | } |
| 721 | |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 722 | case CompareStrictEq: { |
| 723 | JSValue left = forNode(node.child1()).value(); |
| 724 | JSValue right = forNode(node.child2()).value(); |
| 725 | if (left && right && left.isNumber() && right.isNumber()) { |
| 726 | forNode(nodeIndex).set(jsBoolean(left.asNumber() == right.asNumber())); |
| 727 | m_foundConstants = true; |
| 728 | break; |
| 729 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 730 | forNode(nodeIndex).set(PredictBoolean); |
| 731 | break; |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 732 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 733 | |
| 734 | case StringCharCodeAt: |
| 735 | forNode(node.child1()).filter(PredictString); |
| 736 | forNode(node.child2()).filter(PredictInt32); |
| 737 | forNode(nodeIndex).set(PredictInt32); |
| 738 | break; |
| 739 | |
| 740 | case StringCharAt: |
| 741 | forNode(node.child1()).filter(PredictString); |
| 742 | forNode(node.child2()).filter(PredictInt32); |
| 743 | forNode(nodeIndex).set(PredictString); |
| 744 | break; |
| 745 | |
| 746 | case GetByVal: { |
fpizlo@apple.com | 6306b565 | 2011-12-23 05:47:17 +0000 | [diff] [blame] | 747 | if (!node.prediction() || !m_graph[node.child1()].prediction() || !m_graph[node.child2()].prediction()) { |
| 748 | m_isValid = false; |
| 749 | break; |
| 750 | } |
| 751 | if (!isActionableArrayPrediction(m_graph[node.child1()].prediction()) || !m_graph[node.child2()].shouldSpeculateInteger()) { |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 752 | clobberStructures(indexInBlock); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 753 | forNode(nodeIndex).makeTop(); |
| 754 | break; |
| 755 | } |
fpizlo@apple.com | f860f9b | 2012-05-22 20:02:25 +0000 | [diff] [blame] | 756 | if (m_graph[node.child1()].shouldSpeculateArguments()) { |
| 757 | forNode(node.child1()).filter(PredictArguments); |
| 758 | forNode(node.child2()).filter(PredictInt32); |
| 759 | forNode(nodeIndex).makeTop(); |
| 760 | break; |
| 761 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 762 | if (m_graph[node.child1()].prediction() == PredictString) { |
| 763 | forNode(node.child1()).filter(PredictString); |
| 764 | forNode(node.child2()).filter(PredictInt32); |
| 765 | forNode(nodeIndex).set(PredictString); |
| 766 | break; |
| 767 | } |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 768 | |
| 769 | if (m_graph[node.child1()].shouldSpeculateInt8Array()) { |
| 770 | forNode(node.child1()).filter(PredictInt8Array); |
| 771 | forNode(node.child2()).filter(PredictInt32); |
| 772 | forNode(nodeIndex).set(PredictInt32); |
| 773 | break; |
| 774 | } |
| 775 | if (m_graph[node.child1()].shouldSpeculateInt16Array()) { |
| 776 | forNode(node.child1()).filter(PredictInt16Array); |
| 777 | forNode(node.child2()).filter(PredictInt32); |
| 778 | forNode(nodeIndex).set(PredictInt32); |
| 779 | break; |
| 780 | } |
| 781 | if (m_graph[node.child1()].shouldSpeculateInt32Array()) { |
| 782 | forNode(node.child1()).filter(PredictInt32Array); |
| 783 | forNode(node.child2()).filter(PredictInt32); |
| 784 | forNode(nodeIndex).set(PredictInt32); |
| 785 | break; |
| 786 | } |
| 787 | if (m_graph[node.child1()].shouldSpeculateUint8Array()) { |
| 788 | forNode(node.child1()).filter(PredictUint8Array); |
| 789 | forNode(node.child2()).filter(PredictInt32); |
| 790 | forNode(nodeIndex).set(PredictInt32); |
| 791 | break; |
| 792 | } |
caio.oliveira@openbossa.org | 992fc37 | 2012-01-18 01:11:16 +0000 | [diff] [blame] | 793 | if (m_graph[node.child1()].shouldSpeculateUint8ClampedArray()) { |
| 794 | forNode(node.child1()).filter(PredictUint8ClampedArray); |
| 795 | forNode(node.child2()).filter(PredictInt32); |
| 796 | forNode(nodeIndex).set(PredictInt32); |
| 797 | break; |
| 798 | } |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 799 | if (m_graph[node.child1()].shouldSpeculateUint16Array()) { |
| 800 | forNode(node.child1()).filter(PredictUint16Array); |
| 801 | forNode(node.child2()).filter(PredictInt32); |
| 802 | forNode(nodeIndex).set(PredictInt32); |
| 803 | break; |
| 804 | } |
| 805 | if (m_graph[node.child1()].shouldSpeculateUint32Array()) { |
| 806 | forNode(node.child1()).filter(PredictUint32Array); |
| 807 | forNode(node.child2()).filter(PredictInt32); |
fpizlo@apple.com | 691ac79 | 2012-03-13 22:59:43 +0000 | [diff] [blame] | 808 | if (node.shouldSpeculateInteger()) |
| 809 | forNode(nodeIndex).set(PredictInt32); |
| 810 | else |
| 811 | forNode(nodeIndex).set(PredictDouble); |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 812 | break; |
| 813 | } |
oliver@apple.com | 07d7573 | 2011-12-03 01:47:27 +0000 | [diff] [blame] | 814 | if (m_graph[node.child1()].shouldSpeculateFloat32Array()) { |
| 815 | forNode(node.child1()).filter(PredictFloat32Array); |
| 816 | forNode(node.child2()).filter(PredictInt32); |
| 817 | forNode(nodeIndex).set(PredictDouble); |
| 818 | break; |
| 819 | } |
| 820 | if (m_graph[node.child1()].shouldSpeculateFloat64Array()) { |
| 821 | forNode(node.child1()).filter(PredictFloat64Array); |
| 822 | forNode(node.child2()).filter(PredictInt32); |
| 823 | forNode(nodeIndex).set(PredictDouble); |
| 824 | break; |
| 825 | } |
fpizlo@apple.com | 6306b565 | 2011-12-23 05:47:17 +0000 | [diff] [blame] | 826 | ASSERT(m_graph[node.child1()].shouldSpeculateArray()); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 827 | forNode(node.child1()).filter(PredictArray); |
| 828 | forNode(node.child2()).filter(PredictInt32); |
| 829 | forNode(nodeIndex).makeTop(); |
| 830 | break; |
| 831 | } |
| 832 | |
| 833 | case PutByVal: |
| 834 | case PutByValAlias: { |
fpizlo@apple.com | 6306b565 | 2011-12-23 05:47:17 +0000 | [diff] [blame] | 835 | if (!m_graph[node.child1()].prediction() || !m_graph[node.child2()].prediction()) { |
| 836 | m_isValid = false; |
| 837 | break; |
| 838 | } |
fpizlo@apple.com | f860f9b | 2012-05-22 20:02:25 +0000 | [diff] [blame] | 839 | if (!m_graph[node.child2()].shouldSpeculateInteger() || !isActionableMutableArrayPrediction(m_graph[node.child1()].prediction()) |
| 840 | #if USE(JSVALUE32_64) |
| 841 | || m_graph[node.child1()].shouldSpeculateArguments() |
| 842 | #endif |
| 843 | ) { |
fpizlo@apple.com | d7897b1 | 2012-03-12 23:15:45 +0000 | [diff] [blame] | 844 | ASSERT(node.op() == PutByVal); |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 845 | clobberStructures(indexInBlock); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 846 | forNode(nodeIndex).makeTop(); |
| 847 | break; |
| 848 | } |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 849 | |
fpizlo@apple.com | f860f9b | 2012-05-22 20:02:25 +0000 | [diff] [blame] | 850 | if (m_graph[node.child1()].shouldSpeculateArguments()) { |
| 851 | forNode(node.child1()).filter(PredictArguments); |
| 852 | forNode(node.child2()).filter(PredictInt32); |
| 853 | break; |
| 854 | } |
commit-queue@webkit.org | 8a040d9 | 2011-12-19 20:22:31 +0000 | [diff] [blame] | 855 | if (m_graph[node.child1()].shouldSpeculateInt8Array()) { |
| 856 | forNode(node.child1()).filter(PredictInt8Array); |
| 857 | forNode(node.child2()).filter(PredictInt32); |
fpizlo@apple.com | 19a17279 | 2012-03-24 20:15:57 +0000 | [diff] [blame] | 858 | if (m_graph[node.child3()].shouldSpeculateInteger()) |
| 859 | forNode(node.child3()).filter(PredictInt32); |
| 860 | else |
| 861 | forNode(node.child3()).filter(PredictNumber); |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 862 | break; |
| 863 | } |
commit-queue@webkit.org | 8a040d9 | 2011-12-19 20:22:31 +0000 | [diff] [blame] | 864 | if (m_graph[node.child1()].shouldSpeculateInt16Array()) { |
| 865 | forNode(node.child1()).filter(PredictInt16Array); |
| 866 | forNode(node.child2()).filter(PredictInt32); |
fpizlo@apple.com | 19a17279 | 2012-03-24 20:15:57 +0000 | [diff] [blame] | 867 | if (m_graph[node.child3()].shouldSpeculateInteger()) |
| 868 | forNode(node.child3()).filter(PredictInt32); |
| 869 | else |
| 870 | forNode(node.child3()).filter(PredictNumber); |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 871 | break; |
| 872 | } |
commit-queue@webkit.org | 8a040d9 | 2011-12-19 20:22:31 +0000 | [diff] [blame] | 873 | if (m_graph[node.child1()].shouldSpeculateInt32Array()) { |
| 874 | forNode(node.child1()).filter(PredictInt32Array); |
| 875 | forNode(node.child2()).filter(PredictInt32); |
fpizlo@apple.com | 19a17279 | 2012-03-24 20:15:57 +0000 | [diff] [blame] | 876 | if (m_graph[node.child3()].shouldSpeculateInteger()) |
| 877 | forNode(node.child3()).filter(PredictInt32); |
| 878 | else |
| 879 | forNode(node.child3()).filter(PredictNumber); |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 880 | break; |
| 881 | } |
commit-queue@webkit.org | 8a040d9 | 2011-12-19 20:22:31 +0000 | [diff] [blame] | 882 | if (m_graph[node.child1()].shouldSpeculateUint8Array()) { |
| 883 | forNode(node.child1()).filter(PredictUint8Array); |
| 884 | forNode(node.child2()).filter(PredictInt32); |
fpizlo@apple.com | 19a17279 | 2012-03-24 20:15:57 +0000 | [diff] [blame] | 885 | if (m_graph[node.child3()].shouldSpeculateInteger()) |
| 886 | forNode(node.child3()).filter(PredictInt32); |
| 887 | else |
| 888 | forNode(node.child3()).filter(PredictNumber); |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 889 | break; |
| 890 | } |
caio.oliveira@openbossa.org | 992fc37 | 2012-01-18 01:11:16 +0000 | [diff] [blame] | 891 | if (m_graph[node.child1()].shouldSpeculateUint8ClampedArray()) { |
| 892 | forNode(node.child1()).filter(PredictUint8ClampedArray); |
| 893 | forNode(node.child2()).filter(PredictInt32); |
fpizlo@apple.com | 19a17279 | 2012-03-24 20:15:57 +0000 | [diff] [blame] | 894 | if (m_graph[node.child3()].shouldSpeculateInteger()) |
| 895 | forNode(node.child3()).filter(PredictInt32); |
| 896 | else |
| 897 | forNode(node.child3()).filter(PredictNumber); |
caio.oliveira@openbossa.org | 992fc37 | 2012-01-18 01:11:16 +0000 | [diff] [blame] | 898 | break; |
| 899 | } |
commit-queue@webkit.org | 8a040d9 | 2011-12-19 20:22:31 +0000 | [diff] [blame] | 900 | if (m_graph[node.child1()].shouldSpeculateUint16Array()) { |
| 901 | forNode(node.child1()).filter(PredictUint16Array); |
| 902 | forNode(node.child2()).filter(PredictInt32); |
fpizlo@apple.com | 19a17279 | 2012-03-24 20:15:57 +0000 | [diff] [blame] | 903 | if (m_graph[node.child3()].shouldSpeculateInteger()) |
| 904 | forNode(node.child3()).filter(PredictInt32); |
| 905 | else |
| 906 | forNode(node.child3()).filter(PredictNumber); |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 907 | break; |
| 908 | } |
commit-queue@webkit.org | 8a040d9 | 2011-12-19 20:22:31 +0000 | [diff] [blame] | 909 | if (m_graph[node.child1()].shouldSpeculateUint32Array()) { |
| 910 | forNode(node.child1()).filter(PredictUint32Array); |
| 911 | forNode(node.child2()).filter(PredictInt32); |
fpizlo@apple.com | 19a17279 | 2012-03-24 20:15:57 +0000 | [diff] [blame] | 912 | if (m_graph[node.child3()].shouldSpeculateInteger()) |
| 913 | forNode(node.child3()).filter(PredictInt32); |
| 914 | else |
| 915 | forNode(node.child3()).filter(PredictNumber); |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 916 | break; |
| 917 | } |
commit-queue@webkit.org | 8a040d9 | 2011-12-19 20:22:31 +0000 | [diff] [blame] | 918 | if (m_graph[node.child1()].shouldSpeculateFloat32Array()) { |
| 919 | forNode(node.child1()).filter(PredictFloat32Array); |
| 920 | forNode(node.child2()).filter(PredictInt32); |
| 921 | forNode(node.child3()).filter(PredictNumber); |
oliver@apple.com | 07d7573 | 2011-12-03 01:47:27 +0000 | [diff] [blame] | 922 | break; |
| 923 | } |
commit-queue@webkit.org | 8a040d9 | 2011-12-19 20:22:31 +0000 | [diff] [blame] | 924 | if (m_graph[node.child1()].shouldSpeculateFloat64Array()) { |
| 925 | forNode(node.child1()).filter(PredictFloat64Array); |
| 926 | forNode(node.child2()).filter(PredictInt32); |
| 927 | forNode(node.child3()).filter(PredictNumber); |
oliver@apple.com | 07d7573 | 2011-12-03 01:47:27 +0000 | [diff] [blame] | 928 | break; |
| 929 | } |
fpizlo@apple.com | 6306b565 | 2011-12-23 05:47:17 +0000 | [diff] [blame] | 930 | ASSERT(m_graph[node.child1()].shouldSpeculateArray()); |
commit-queue@webkit.org | 8a040d9 | 2011-12-19 20:22:31 +0000 | [diff] [blame] | 931 | forNode(node.child1()).filter(PredictArray); |
| 932 | forNode(node.child2()).filter(PredictInt32); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 933 | break; |
| 934 | } |
| 935 | |
| 936 | case ArrayPush: |
| 937 | forNode(node.child1()).filter(PredictArray); |
| 938 | forNode(nodeIndex).set(PredictNumber); |
| 939 | break; |
| 940 | |
| 941 | case ArrayPop: |
| 942 | forNode(node.child1()).filter(PredictArray); |
| 943 | forNode(nodeIndex).makeTop(); |
| 944 | break; |
| 945 | |
barraclough@apple.com | 077fdd4 | 2012-03-18 01:08:16 +0000 | [diff] [blame] | 946 | case RegExpExec: |
| 947 | case RegExpTest: |
| 948 | forNode(node.child1()).filter(PredictCell); |
| 949 | forNode(node.child2()).filter(PredictCell); |
| 950 | forNode(nodeIndex).makeTop(); |
| 951 | break; |
| 952 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 953 | case Jump: |
| 954 | break; |
| 955 | |
| 956 | case Branch: { |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 957 | JSValue value = forNode(node.child1()).value(); |
| 958 | if (value) { |
| 959 | bool booleanValue = value.toBoolean(); |
| 960 | if (booleanValue) |
| 961 | m_branchDirection = TakeTrue; |
| 962 | else |
| 963 | m_branchDirection = TakeFalse; |
| 964 | break; |
| 965 | } |
| 966 | // FIXME: The above handles the trivial cases of sparse conditional |
| 967 | // constant propagation, but we can do better: |
| 968 | // 1) If the abstract value does not have a concrete value but describes |
| 969 | // something that is known to evaluate true (or false) then we ought |
| 970 | // to sparse conditional that. |
| 971 | // 2) We can specialize the source variable's value on each direction of |
| 972 | // the branch. |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 973 | Node& child = m_graph[node.child1()]; |
fpizlo@apple.com | ad60ef3 | 2012-03-22 03:47:55 +0000 | [diff] [blame] | 974 | if (child.shouldSpeculateBoolean()) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 975 | forNode(node.child1()).filter(PredictBoolean); |
| 976 | else if (child.shouldSpeculateFinalObjectOrOther()) |
| 977 | forNode(node.child1()).filter(PredictFinalObject | PredictOther); |
| 978 | else if (child.shouldSpeculateArrayOrOther()) |
| 979 | forNode(node.child1()).filter(PredictArray | PredictOther); |
| 980 | else if (child.shouldSpeculateInteger()) |
| 981 | forNode(node.child1()).filter(PredictInt32); |
| 982 | else if (child.shouldSpeculateNumber()) |
| 983 | forNode(node.child1()).filter(PredictNumber); |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 984 | m_branchDirection = TakeBoth; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 985 | break; |
| 986 | } |
| 987 | |
| 988 | case Return: |
| 989 | case Throw: |
| 990 | case ThrowReferenceError: |
| 991 | m_isValid = false; |
| 992 | break; |
| 993 | |
| 994 | case ToPrimitive: { |
fpizlo@apple.com | 3187c92 | 2012-05-18 21:47:53 +0000 | [diff] [blame] | 995 | JSValue childConst = forNode(node.child1()).value(); |
| 996 | if (childConst && childConst.isNumber()) { |
| 997 | forNode(nodeIndex).set(childConst); |
| 998 | m_foundConstants = true; |
| 999 | break; |
| 1000 | } |
| 1001 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1002 | Node& child = m_graph[node.child1()]; |
| 1003 | if (child.shouldSpeculateInteger()) { |
| 1004 | forNode(node.child1()).filter(PredictInt32); |
| 1005 | forNode(nodeIndex).set(PredictInt32); |
| 1006 | break; |
| 1007 | } |
| 1008 | |
| 1009 | AbstractValue& source = forNode(node.child1()); |
| 1010 | AbstractValue& destination = forNode(nodeIndex); |
| 1011 | |
| 1012 | PredictedType type = source.m_type; |
| 1013 | if (type & ~(PredictNumber | PredictString | PredictBoolean)) { |
| 1014 | type &= (PredictNumber | PredictString | PredictBoolean); |
| 1015 | type |= PredictString; |
| 1016 | } |
| 1017 | destination.set(type); |
| 1018 | break; |
| 1019 | } |
| 1020 | |
| 1021 | case StrCat: |
| 1022 | forNode(nodeIndex).set(PredictString); |
| 1023 | break; |
| 1024 | |
| 1025 | case NewArray: |
| 1026 | case NewArrayBuffer: |
| 1027 | forNode(nodeIndex).set(m_codeBlock->globalObject()->arrayStructure()); |
| 1028 | m_haveStructures = true; |
| 1029 | break; |
| 1030 | |
| 1031 | case NewRegexp: |
| 1032 | forNode(nodeIndex).set(m_codeBlock->globalObject()->regExpStructure()); |
| 1033 | m_haveStructures = true; |
| 1034 | break; |
| 1035 | |
| 1036 | case ConvertThis: { |
| 1037 | Node& child = m_graph[node.child1()]; |
| 1038 | AbstractValue& source = forNode(node.child1()); |
| 1039 | AbstractValue& destination = forNode(nodeIndex); |
| 1040 | |
| 1041 | if (isObjectPrediction(source.m_type)) { |
| 1042 | // This is the simple case. We already know that the source is an |
| 1043 | // object, so there's nothing to do. I don't think this case will |
| 1044 | // be hit, but then again, you never know. |
| 1045 | destination = source; |
| 1046 | break; |
| 1047 | } |
fpizlo@apple.com | 1ca63d0 | 2011-11-10 23:59:31 +0000 | [diff] [blame] | 1048 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1049 | if (isOtherPrediction(child.prediction())) { |
| 1050 | source.filter(PredictOther); |
| 1051 | destination.set(PredictObjectOther); |
| 1052 | break; |
| 1053 | } |
| 1054 | |
| 1055 | if (isObjectPrediction(child.prediction())) { |
| 1056 | source.filter(PredictObjectMask); |
| 1057 | destination = source; |
| 1058 | break; |
| 1059 | } |
| 1060 | |
| 1061 | destination = source; |
| 1062 | destination.merge(PredictObjectOther); |
| 1063 | break; |
| 1064 | } |
barraclough@apple.com | cef11dc | 2012-05-10 18:40:29 +0000 | [diff] [blame] | 1065 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1066 | case CreateThis: { |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1067 | AbstractValue& source = forNode(node.child1()); |
| 1068 | AbstractValue& destination = forNode(nodeIndex); |
| 1069 | |
barraclough@apple.com | cef11dc | 2012-05-10 18:40:29 +0000 | [diff] [blame] | 1070 | source.filter(PredictFunction); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1071 | destination.set(PredictFinalObject); |
| 1072 | break; |
| 1073 | } |
barraclough@apple.com | cef11dc | 2012-05-10 18:40:29 +0000 | [diff] [blame] | 1074 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1075 | case NewObject: |
fpizlo@apple.com | 17da7f3 | 2012-02-25 23:05:38 +0000 | [diff] [blame] | 1076 | forNode(nodeIndex).set(m_codeBlock->globalObjectFor(node.codeOrigin)->emptyObjectStructure()); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1077 | m_haveStructures = true; |
| 1078 | break; |
fpizlo@apple.com | 17da7f3 | 2012-02-25 23:05:38 +0000 | [diff] [blame] | 1079 | |
| 1080 | case CreateActivation: |
| 1081 | forNode(nodeIndex).set(m_graph.m_globalData.activationStructure.get()); |
| 1082 | m_haveStructures = true; |
| 1083 | break; |
| 1084 | |
fpizlo@apple.com | f860f9b | 2012-05-22 20:02:25 +0000 | [diff] [blame] | 1085 | case CreateArguments: |
| 1086 | forNode(nodeIndex).set(m_codeBlock->globalObjectFor(node.codeOrigin)->argumentsStructure()); |
| 1087 | m_haveStructures = true; |
| 1088 | break; |
| 1089 | |
fpizlo@apple.com | 17da7f3 | 2012-02-25 23:05:38 +0000 | [diff] [blame] | 1090 | case TearOffActivation: |
fpizlo@apple.com | 15c03c7 | 2012-05-23 02:34:13 +0000 | [diff] [blame] | 1091 | case TearOffArguments: |
fpizlo@apple.com | 5e3852d | 2012-05-24 00:05:21 +0000 | [diff] [blame] | 1092 | case CheckArgumentsNotCreated: |
fpizlo@apple.com | 17da7f3 | 2012-02-25 23:05:38 +0000 | [diff] [blame] | 1093 | // Does nothing that is user-visible. |
| 1094 | break; |
| 1095 | |
fpizlo@apple.com | 6d4456e | 2012-05-23 03:48:52 +0000 | [diff] [blame] | 1096 | case GetMyArgumentsLength: |
fpizlo@apple.com | 9b92872 | 2012-05-24 00:18:55 +0000 | [diff] [blame] | 1097 | if (!m_graph.m_executablesWhoseArgumentsEscaped.contains( |
| 1098 | m_graph.executableFor(node.codeOrigin))) { |
| 1099 | // We know that this executable does not escape its arguments, so we can optimize |
| 1100 | // the arguments a bit. Note that this is not sufficient to force constant folding |
| 1101 | // of GetMyArgumentsLength, because GetMyArgumentsLength is a clobbering operation. |
| 1102 | // We perform further optimizations on this later on. |
| 1103 | if (node.codeOrigin.inlineCallFrame) { |
| 1104 | forNode(nodeIndex).set(jsNumber(node.codeOrigin.inlineCallFrame->arguments.size() - 1)); |
| 1105 | break; |
| 1106 | } |
| 1107 | forNode(nodeIndex).set(PredictInt32); |
| 1108 | break; |
| 1109 | } |
fpizlo@apple.com | 6d4456e | 2012-05-23 03:48:52 +0000 | [diff] [blame] | 1110 | // This potentially clobbers all structures if the arguments object had a getter |
| 1111 | // installed on the length property. |
| 1112 | clobberStructures(indexInBlock); |
| 1113 | // We currently make no guarantee about what this returns because it does not |
| 1114 | // speculate that the length property is actually a length. |
| 1115 | forNode(nodeIndex).makeTop(); |
| 1116 | break; |
| 1117 | |
| 1118 | case GetMyArgumentByVal: |
fpizlo@apple.com | 9b92872 | 2012-05-24 00:18:55 +0000 | [diff] [blame] | 1119 | if (!m_graph.m_executablesWhoseArgumentsEscaped.contains( |
| 1120 | m_graph.executableFor(node.codeOrigin))) { |
| 1121 | // We know that this executable does not escape its arguments, so we can optimize |
| 1122 | // the arguments a bit. Note that this ends up being further optimized by the |
| 1123 | // ArgumentsSimplificationPhase. |
| 1124 | forNode(node.child1()).filter(PredictInt32); |
| 1125 | forNode(nodeIndex).makeTop(); |
| 1126 | break; |
| 1127 | } |
fpizlo@apple.com | 6d4456e | 2012-05-23 03:48:52 +0000 | [diff] [blame] | 1128 | // This potentially clobbers all structures if the property we're accessing has |
| 1129 | // a getter. We don't speculate against this. |
| 1130 | clobberStructures(indexInBlock); |
| 1131 | // But we do speculate that the index is an integer. |
| 1132 | forNode(node.child1()).filter(PredictInt32); |
| 1133 | // And the result is unknown. |
| 1134 | forNode(nodeIndex).makeTop(); |
| 1135 | break; |
| 1136 | |
fpizlo@apple.com | 17da7f3 | 2012-02-25 23:05:38 +0000 | [diff] [blame] | 1137 | case NewFunction: |
| 1138 | case NewFunctionExpression: |
| 1139 | case NewFunctionNoCheck: |
| 1140 | forNode(nodeIndex).set(m_codeBlock->globalObjectFor(node.codeOrigin)->functionStructure()); |
| 1141 | break; |
| 1142 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1143 | case GetCallee: |
fpizlo@apple.com | 1ca63d0 | 2011-11-10 23:59:31 +0000 | [diff] [blame] | 1144 | forNode(nodeIndex).set(PredictFunction); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1145 | break; |
| 1146 | |
| 1147 | case GetScopeChain: |
| 1148 | forNode(nodeIndex).set(PredictCellOther); |
| 1149 | break; |
| 1150 | |
| 1151 | case GetScopedVar: |
| 1152 | forNode(nodeIndex).makeTop(); |
| 1153 | break; |
| 1154 | |
| 1155 | case PutScopedVar: |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 1156 | clobberStructures(indexInBlock); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1157 | break; |
| 1158 | |
| 1159 | case GetById: |
fpizlo@apple.com | dc03dc5 | 2012-01-17 00:53:40 +0000 | [diff] [blame] | 1160 | case GetByIdFlush: |
fpizlo@apple.com | 49bfe57 | 2011-10-31 23:50:57 +0000 | [diff] [blame] | 1161 | if (!node.prediction()) { |
| 1162 | m_isValid = false; |
| 1163 | break; |
| 1164 | } |
fpizlo@apple.com | f696754 | 2011-11-28 23:51:51 +0000 | [diff] [blame] | 1165 | if (isCellPrediction(m_graph[node.child1()].prediction())) |
| 1166 | forNode(node.child1()).filter(PredictCell); |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 1167 | clobberStructures(indexInBlock); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1168 | forNode(nodeIndex).makeTop(); |
| 1169 | break; |
| 1170 | |
| 1171 | case GetArrayLength: |
| 1172 | forNode(node.child1()).filter(PredictArray); |
| 1173 | forNode(nodeIndex).set(PredictInt32); |
| 1174 | break; |
oliver@apple.com | f4596ca | 2011-10-19 21:25:10 +0000 | [diff] [blame] | 1175 | |
fpizlo@apple.com | f860f9b | 2012-05-22 20:02:25 +0000 | [diff] [blame] | 1176 | case GetArgumentsLength: |
| 1177 | forNode(node.child1()).filter(PredictArguments); |
| 1178 | forNode(nodeIndex).set(PredictInt32); |
| 1179 | break; |
| 1180 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1181 | case GetStringLength: |
| 1182 | forNode(node.child1()).filter(PredictString); |
| 1183 | forNode(nodeIndex).set(PredictInt32); |
| 1184 | break; |
oliver@apple.com | f4596ca | 2011-10-19 21:25:10 +0000 | [diff] [blame] | 1185 | |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 1186 | case GetInt8ArrayLength: |
| 1187 | forNode(node.child1()).filter(PredictInt8Array); |
| 1188 | forNode(nodeIndex).set(PredictInt32); |
| 1189 | break; |
| 1190 | case GetInt16ArrayLength: |
| 1191 | forNode(node.child1()).filter(PredictInt16Array); |
| 1192 | forNode(nodeIndex).set(PredictInt32); |
| 1193 | break; |
| 1194 | case GetInt32ArrayLength: |
| 1195 | forNode(node.child1()).filter(PredictInt32Array); |
| 1196 | forNode(nodeIndex).set(PredictInt32); |
| 1197 | break; |
| 1198 | case GetUint8ArrayLength: |
| 1199 | forNode(node.child1()).filter(PredictUint8Array); |
| 1200 | forNode(nodeIndex).set(PredictInt32); |
| 1201 | break; |
caio.oliveira@openbossa.org | 992fc37 | 2012-01-18 01:11:16 +0000 | [diff] [blame] | 1202 | case GetUint8ClampedArrayLength: |
| 1203 | forNode(node.child1()).filter(PredictUint8ClampedArray); |
| 1204 | forNode(nodeIndex).set(PredictInt32); |
| 1205 | break; |
oliver@apple.com | aeec3d8 | 2011-12-02 01:56:53 +0000 | [diff] [blame] | 1206 | case GetUint16ArrayLength: |
| 1207 | forNode(node.child1()).filter(PredictUint16Array); |
| 1208 | forNode(nodeIndex).set(PredictInt32); |
| 1209 | break; |
| 1210 | case GetUint32ArrayLength: |
| 1211 | forNode(node.child1()).filter(PredictUint32Array); |
| 1212 | forNode(nodeIndex).set(PredictInt32); |
| 1213 | break; |
| 1214 | case GetFloat32ArrayLength: |
| 1215 | forNode(node.child1()).filter(PredictFloat32Array); |
| 1216 | forNode(nodeIndex).set(PredictInt32); |
| 1217 | break; |
| 1218 | case GetFloat64ArrayLength: |
| 1219 | forNode(node.child1()).filter(PredictFloat64Array); |
| 1220 | forNode(nodeIndex).set(PredictInt32); |
| 1221 | break; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1222 | |
| 1223 | case CheckStructure: |
| 1224 | // FIXME: We should be able to propagate the structure sets of constants (i.e. prototypes). |
| 1225 | forNode(node.child1()).filter(node.structureSet()); |
| 1226 | m_haveStructures = true; |
| 1227 | break; |
| 1228 | |
| 1229 | case PutStructure: |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 1230 | clobberStructures(indexInBlock); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1231 | forNode(node.child1()).set(node.structureTransitionData().newStructure); |
| 1232 | m_haveStructures = true; |
| 1233 | break; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1234 | case GetPropertyStorage: |
| 1235 | forNode(node.child1()).filter(PredictCell); |
| 1236 | forNode(nodeIndex).clear(); // The result is not a JS value. |
| 1237 | break; |
oliver@apple.com | 43e511c | 2011-12-09 08:45:46 +0000 | [diff] [blame] | 1238 | case GetIndexedPropertyStorage: { |
| 1239 | PredictedType basePrediction = m_graph[node.child2()].prediction(); |
| 1240 | if (!(basePrediction & PredictInt32) && basePrediction) { |
| 1241 | forNode(nodeIndex).clear(); |
| 1242 | break; |
| 1243 | } |
fpizlo@apple.com | f860f9b | 2012-05-22 20:02:25 +0000 | [diff] [blame] | 1244 | if (m_graph[node.child1()].shouldSpeculateArguments()) { |
| 1245 | ASSERT_NOT_REACHED(); |
| 1246 | break; |
| 1247 | } |
oliver@apple.com | 43e511c | 2011-12-09 08:45:46 +0000 | [diff] [blame] | 1248 | if (m_graph[node.child1()].prediction() == PredictString) { |
| 1249 | forNode(node.child1()).filter(PredictString); |
| 1250 | forNode(nodeIndex).clear(); |
| 1251 | break; |
| 1252 | } |
oliver@apple.com | 43e511c | 2011-12-09 08:45:46 +0000 | [diff] [blame] | 1253 | |
| 1254 | if (m_graph[node.child1()].shouldSpeculateInt8Array()) { |
| 1255 | forNode(node.child1()).filter(PredictInt8Array); |
| 1256 | forNode(nodeIndex).clear(); |
| 1257 | break; |
| 1258 | } |
| 1259 | if (m_graph[node.child1()].shouldSpeculateInt16Array()) { |
| 1260 | forNode(node.child1()).filter(PredictInt16Array); |
| 1261 | forNode(nodeIndex).clear(); |
| 1262 | break; |
| 1263 | } |
| 1264 | if (m_graph[node.child1()].shouldSpeculateInt32Array()) { |
| 1265 | forNode(node.child1()).filter(PredictInt32Array); |
| 1266 | forNode(nodeIndex).clear(); |
| 1267 | break; |
| 1268 | } |
| 1269 | if (m_graph[node.child1()].shouldSpeculateUint8Array()) { |
| 1270 | forNode(node.child1()).filter(PredictUint8Array); |
| 1271 | forNode(nodeIndex).clear(); |
| 1272 | break; |
| 1273 | } |
caio.oliveira@openbossa.org | 992fc37 | 2012-01-18 01:11:16 +0000 | [diff] [blame] | 1274 | if (m_graph[node.child1()].shouldSpeculateUint8ClampedArray()) { |
| 1275 | forNode(node.child1()).filter(PredictUint8ClampedArray); |
| 1276 | forNode(nodeIndex).clear(); |
| 1277 | break; |
| 1278 | } |
oliver@apple.com | 43e511c | 2011-12-09 08:45:46 +0000 | [diff] [blame] | 1279 | if (m_graph[node.child1()].shouldSpeculateUint16Array()) { |
| 1280 | forNode(node.child1()).filter(PredictUint16Array); |
| 1281 | forNode(nodeIndex).set(PredictOther); |
| 1282 | break; |
| 1283 | } |
| 1284 | if (m_graph[node.child1()].shouldSpeculateUint32Array()) { |
| 1285 | forNode(node.child1()).filter(PredictUint32Array); |
| 1286 | forNode(nodeIndex).clear(); |
| 1287 | break; |
| 1288 | } |
| 1289 | if (m_graph[node.child1()].shouldSpeculateFloat32Array()) { |
| 1290 | forNode(node.child1()).filter(PredictFloat32Array); |
| 1291 | forNode(nodeIndex).clear(); |
| 1292 | break; |
| 1293 | } |
| 1294 | if (m_graph[node.child1()].shouldSpeculateFloat64Array()) { |
| 1295 | forNode(node.child1()).filter(PredictFloat64Array); |
| 1296 | forNode(nodeIndex).clear(); |
| 1297 | break; |
| 1298 | } |
| 1299 | forNode(node.child1()).filter(PredictArray); |
| 1300 | forNode(nodeIndex).clear(); |
| 1301 | break; |
| 1302 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1303 | case GetByOffset: |
| 1304 | forNode(node.child1()).filter(PredictCell); |
| 1305 | forNode(nodeIndex).makeTop(); |
| 1306 | break; |
| 1307 | |
| 1308 | case PutByOffset: |
| 1309 | forNode(node.child1()).filter(PredictCell); |
| 1310 | break; |
| 1311 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1312 | case CheckFunction: |
fpizlo@apple.com | 1ca63d0 | 2011-11-10 23:59:31 +0000 | [diff] [blame] | 1313 | forNode(node.child1()).filter(PredictFunction); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1314 | // FIXME: Should be able to propagate the fact that we know what the function is. |
| 1315 | break; |
| 1316 | |
| 1317 | case PutById: |
| 1318 | case PutByIdDirect: |
| 1319 | forNode(node.child1()).filter(PredictCell); |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 1320 | clobberStructures(indexInBlock); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1321 | break; |
| 1322 | |
| 1323 | case GetGlobalVar: |
| 1324 | forNode(nodeIndex).makeTop(); |
| 1325 | break; |
| 1326 | |
| 1327 | case PutGlobalVar: |
| 1328 | break; |
| 1329 | |
| 1330 | case CheckHasInstance: |
| 1331 | forNode(node.child1()).filter(PredictCell); |
| 1332 | // Sadly, we don't propagate the fact that we've done CheckHasInstance |
| 1333 | break; |
| 1334 | |
| 1335 | case InstanceOf: |
| 1336 | // Again, sadly, we don't propagate the fact that we've done InstanceOf |
fpizlo@apple.com | 03c374f | 2011-11-19 01:00:34 +0000 | [diff] [blame] | 1337 | if (!(m_graph[node.child1()].prediction() & ~PredictCell) && !(forNode(node.child1()).m_type & ~PredictCell)) |
| 1338 | forNode(node.child1()).filter(PredictCell); |
| 1339 | forNode(node.child3()).filter(PredictCell); |
| 1340 | forNode(nodeIndex).set(PredictBoolean); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1341 | break; |
| 1342 | |
| 1343 | case Phi: |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 1344 | case Flush: |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1345 | break; |
| 1346 | |
| 1347 | case Breakpoint: |
| 1348 | break; |
| 1349 | |
| 1350 | case Call: |
| 1351 | case Construct: |
| 1352 | case Resolve: |
| 1353 | case ResolveBase: |
| 1354 | case ResolveBaseStrictPut: |
| 1355 | case ResolveGlobal: |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 1356 | clobberStructures(indexInBlock); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1357 | forNode(nodeIndex).makeTop(); |
| 1358 | break; |
| 1359 | |
| 1360 | case ForceOSRExit: |
| 1361 | m_isValid = false; |
| 1362 | break; |
| 1363 | |
| 1364 | case Phantom: |
fpizlo@apple.com | 116a089 | 2011-11-03 08:06:42 +0000 | [diff] [blame] | 1365 | case InlineStart: |
fpizlo@apple.com | 390f57c | 2011-12-19 06:36:05 +0000 | [diff] [blame] | 1366 | case Nop: |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1367 | break; |
fpizlo@apple.com | d7897b1 | 2012-03-12 23:15:45 +0000 | [diff] [blame] | 1368 | |
| 1369 | case LastNodeType: |
| 1370 | ASSERT_NOT_REACHED(); |
| 1371 | break; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1372 | } |
| 1373 | |
| 1374 | return m_isValid; |
| 1375 | } |
| 1376 | |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 1377 | inline void AbstractState::clobberStructures(unsigned indexInBlock) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1378 | { |
| 1379 | PROFILE(FLAG_FOR_STRUCTURE_CLOBBERING); |
| 1380 | if (!m_haveStructures) |
| 1381 | return; |
yuqiang.xian@intel.com | fa12f4e | 2012-03-07 04:56:05 +0000 | [diff] [blame] | 1382 | for (size_t i = indexInBlock + 1; i--;) |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 1383 | forNode(m_block->at(i)).clobberStructures(); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1384 | for (size_t i = 0; i < m_variables.numberOfArguments(); ++i) |
| 1385 | m_variables.argument(i).clobberStructures(); |
| 1386 | for (size_t i = 0; i < m_variables.numberOfLocals(); ++i) |
| 1387 | m_variables.local(i).clobberStructures(); |
| 1388 | m_haveStructures = false; |
| 1389 | } |
| 1390 | |
| 1391 | inline bool AbstractState::mergeStateAtTail(AbstractValue& destination, AbstractValue& inVariable, NodeIndex nodeIndex) |
| 1392 | { |
| 1393 | if (nodeIndex == NoNode) |
| 1394 | return false; |
| 1395 | |
fpizlo@apple.com | cd3adcc | 2012-03-08 09:02:48 +0000 | [diff] [blame] | 1396 | AbstractValue source; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1397 | |
| 1398 | Node& node = m_graph[nodeIndex]; |
| 1399 | if (!node.refCount()) |
| 1400 | return false; |
| 1401 | |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1402 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
fpizlo@apple.com | d7897b1 | 2012-03-12 23:15:45 +0000 | [diff] [blame] | 1403 | dataLog(" It's live, node @%u.\n", nodeIndex); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1404 | #endif |
fpizlo@apple.com | d7897b1 | 2012-03-12 23:15:45 +0000 | [diff] [blame] | 1405 | |
| 1406 | switch (node.op()) { |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1407 | case Phi: |
| 1408 | case SetArgument: |
fpizlo@apple.com | d9ded3b | 2011-10-22 01:22:46 +0000 | [diff] [blame] | 1409 | case Flush: |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1410 | // The block transfers the value from head to tail. |
fpizlo@apple.com | cd3adcc | 2012-03-08 09:02:48 +0000 | [diff] [blame] | 1411 | source = inVariable; |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1412 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 1413 | dataLog(" Transfering "); |
| 1414 | source.dump(WTF::dataFile()); |
| 1415 | dataLog(" from head to tail.\n"); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1416 | #endif |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1417 | break; |
| 1418 | |
| 1419 | case GetLocal: |
| 1420 | // The block refines the value with additional speculations. |
fpizlo@apple.com | cd3adcc | 2012-03-08 09:02:48 +0000 | [diff] [blame] | 1421 | source = forNode(nodeIndex); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1422 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 1423 | dataLog(" Refining to "); |
| 1424 | source.dump(WTF::dataFile()); |
| 1425 | dataLog("\n"); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1426 | #endif |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1427 | break; |
| 1428 | |
| 1429 | case SetLocal: |
| 1430 | // The block sets the variable, and potentially refines it, both |
| 1431 | // before and after setting it. |
fpizlo@apple.com | cd3adcc | 2012-03-08 09:02:48 +0000 | [diff] [blame] | 1432 | if (node.variableAccessData()->shouldUseDoubleFormat()) |
| 1433 | source.set(PredictDouble); |
| 1434 | else |
| 1435 | source = forNode(node.child1()); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1436 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 1437 | dataLog(" Setting to "); |
| 1438 | source.dump(WTF::dataFile()); |
| 1439 | dataLog("\n"); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1440 | #endif |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1441 | break; |
| 1442 | |
| 1443 | default: |
| 1444 | ASSERT_NOT_REACHED(); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1445 | break; |
| 1446 | } |
| 1447 | |
fpizlo@apple.com | cd3adcc | 2012-03-08 09:02:48 +0000 | [diff] [blame] | 1448 | if (destination == source) { |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1449 | // Abstract execution did not change the output value of the variable, for this |
| 1450 | // basic block, on this iteration. |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1451 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
fpizlo@apple.com | d095b24 | 2012-02-12 03:21:32 +0000 | [diff] [blame] | 1452 | dataLog(" Not changed!\n"); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1453 | #endif |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1454 | return false; |
| 1455 | } |
| 1456 | |
| 1457 | // Abstract execution reached a new conclusion about the speculations reached about |
| 1458 | // this variable after execution of this basic block. Update the state, and return |
| 1459 | // true to indicate that the fixpoint must go on! |
fpizlo@apple.com | cd3adcc | 2012-03-08 09:02:48 +0000 | [diff] [blame] | 1460 | destination = source; |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1461 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
fpizlo@apple.com | d095b24 | 2012-02-12 03:21:32 +0000 | [diff] [blame] | 1462 | dataLog(" Changed!\n"); |
fpizlo@apple.com | fab6605 | 2011-11-22 03:02:33 +0000 | [diff] [blame] | 1463 | #endif |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1464 | return true; |
| 1465 | } |
| 1466 | |
| 1467 | inline bool AbstractState::merge(BasicBlock* from, BasicBlock* to) |
| 1468 | { |
| 1469 | ASSERT(from->variablesAtTail.numberOfArguments() == to->variablesAtHead.numberOfArguments()); |
| 1470 | ASSERT(from->variablesAtTail.numberOfLocals() == to->variablesAtHead.numberOfLocals()); |
| 1471 | |
| 1472 | bool changed = false; |
| 1473 | |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 1474 | for (size_t argument = 0; argument < from->variablesAtTail.numberOfArguments(); ++argument) { |
| 1475 | AbstractValue& destination = to->valuesAtHead.argument(argument); |
fpizlo@apple.com | 1688cc1 | 2012-05-23 07:29:02 +0000 | [diff] [blame] | 1476 | NodeIndex nodeIndex = from->variablesAtTail.argument(argument); |
| 1477 | if (nodeIndex != NoNode && m_graph[nodeIndex].variableAccessData()->isCaptured()) { |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 1478 | if (destination.isTop()) |
| 1479 | continue; |
| 1480 | destination.makeTop(); |
| 1481 | changed = true; |
| 1482 | continue; |
| 1483 | } |
| 1484 | changed |= mergeVariableBetweenBlocks(destination, from->valuesAtTail.argument(argument), to->variablesAtHead.argument(argument), from->variablesAtTail.argument(argument)); |
| 1485 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1486 | |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 1487 | for (size_t local = 0; local < from->variablesAtTail.numberOfLocals(); ++local) { |
| 1488 | AbstractValue& destination = to->valuesAtHead.local(local); |
fpizlo@apple.com | 1688cc1 | 2012-05-23 07:29:02 +0000 | [diff] [blame] | 1489 | NodeIndex nodeIndex = from->variablesAtTail.local(local); |
| 1490 | if (nodeIndex != NoNode && m_graph[nodeIndex].variableAccessData()->isCaptured()) { |
fpizlo@apple.com | b0da6b6 | 2012-02-24 21:31:37 +0000 | [diff] [blame] | 1491 | if (destination.isTop()) |
| 1492 | continue; |
| 1493 | destination.makeTop(); |
| 1494 | changed = true; |
| 1495 | continue; |
| 1496 | } |
| 1497 | changed |= mergeVariableBetweenBlocks(destination, from->valuesAtTail.local(local), to->variablesAtHead.local(local), from->variablesAtTail.local(local)); |
| 1498 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1499 | |
| 1500 | if (!to->cfaHasVisited) |
| 1501 | changed = true; |
| 1502 | |
| 1503 | to->cfaShouldRevisit |= changed; |
| 1504 | |
| 1505 | return changed; |
| 1506 | } |
| 1507 | |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 1508 | inline bool AbstractState::mergeToSuccessors( |
| 1509 | Graph& graph, BasicBlock* basicBlock, BranchDirection branchDirection) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1510 | { |
| 1511 | PROFILE(FLAG_FOR_MERGE_TO_SUCCESSORS); |
| 1512 | |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 1513 | Node& terminal = graph[basicBlock->last()]; |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1514 | |
| 1515 | ASSERT(terminal.isTerminal()); |
| 1516 | |
fpizlo@apple.com | d7897b1 | 2012-03-12 23:15:45 +0000 | [diff] [blame] | 1517 | switch (terminal.op()) { |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 1518 | case Jump: { |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 1519 | ASSERT(branchDirection == InvalidBranchDirection); |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 1520 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
| 1521 | dataLog(" Merging to block #%u.\n", terminal.takenBlockIndex()); |
| 1522 | #endif |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1523 | return merge(basicBlock, graph.m_blocks[terminal.takenBlockIndex()].get()); |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 1524 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1525 | |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 1526 | case Branch: { |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 1527 | ASSERT(branchDirection != InvalidBranchDirection); |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 1528 | bool changed = false; |
| 1529 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
| 1530 | dataLog(" Merging to block #%u.\n", terminal.takenBlockIndex()); |
| 1531 | #endif |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 1532 | if (branchDirection != TakeFalse) |
| 1533 | changed |= merge(basicBlock, graph.m_blocks[terminal.takenBlockIndex()].get()); |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 1534 | #if DFG_ENABLE(DEBUG_PROPAGATION_VERBOSE) |
| 1535 | dataLog(" Merging to block #%u.\n", terminal.notTakenBlockIndex()); |
| 1536 | #endif |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 1537 | if (branchDirection != TakeTrue) |
| 1538 | changed |= merge(basicBlock, graph.m_blocks[terminal.notTakenBlockIndex()].get()); |
fpizlo@apple.com | 79c51ee | 2012-05-18 22:30:24 +0000 | [diff] [blame] | 1539 | return changed; |
| 1540 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1541 | |
| 1542 | case Return: |
| 1543 | case Throw: |
| 1544 | case ThrowReferenceError: |
fpizlo@apple.com | db7ba19 | 2012-05-24 02:28:52 +0000 | [diff] [blame] | 1545 | ASSERT(branchDirection == InvalidBranchDirection); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1546 | return false; |
| 1547 | |
| 1548 | default: |
| 1549 | ASSERT_NOT_REACHED(); |
| 1550 | return false; |
| 1551 | } |
| 1552 | } |
| 1553 | |
| 1554 | inline bool AbstractState::mergeVariableBetweenBlocks(AbstractValue& destination, AbstractValue& source, NodeIndex destinationNodeIndex, NodeIndex sourceNodeIndex) |
| 1555 | { |
| 1556 | if (destinationNodeIndex == NoNode) |
| 1557 | return false; |
| 1558 | |
| 1559 | ASSERT_UNUSED(sourceNodeIndex, sourceNodeIndex != NoNode); |
| 1560 | |
| 1561 | // FIXME: We could do some sparse conditional propagation here! |
| 1562 | |
| 1563 | return destination.merge(source); |
| 1564 | } |
| 1565 | |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1566 | void AbstractState::dump(FILE* out) |
| 1567 | { |
| 1568 | bool first = true; |
yuqiang.xian@intel.com | fa12f4e | 2012-03-07 04:56:05 +0000 | [diff] [blame] | 1569 | for (size_t i = 0; i < m_block->size(); ++i) { |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 1570 | NodeIndex index = m_block->at(i); |
| 1571 | AbstractValue& value = m_nodes[index]; |
| 1572 | if (value.isClear()) |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1573 | continue; |
| 1574 | if (first) |
| 1575 | first = false; |
| 1576 | else |
| 1577 | fprintf(out, " "); |
yuqiang.xian@intel.com | 861d918 | 2012-03-01 07:39:31 +0000 | [diff] [blame] | 1578 | fprintf(out, "@%lu:", static_cast<unsigned long>(index)); |
| 1579 | value.dump(out); |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1580 | } |
| 1581 | } |
fpizlo@apple.com | 4ffd395 | 2011-10-12 02:05:53 +0000 | [diff] [blame] | 1582 | |
| 1583 | } } // namespace JSC::DFG |
| 1584 | |
| 1585 | #endif // ENABLE(DFG_JIT) |
| 1586 | |