| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include "typing.h" | 28 #include "typing.h" |
| 29 | 29 |
| 30 #include "frames.h" |
| 31 #include "frames-inl.h" |
| 30 #include "parser.h" // for CompileTimeValue; TODO(rossberg): should move | 32 #include "parser.h" // for CompileTimeValue; TODO(rossberg): should move |
| 31 #include "scopes.h" | 33 #include "scopes.h" |
| 32 | 34 |
| 33 namespace v8 { | 35 namespace v8 { |
| 34 namespace internal { | 36 namespace internal { |
| 35 | 37 |
| 36 | 38 |
| 37 AstTyper::AstTyper(CompilationInfo* info) | 39 AstTyper::AstTyper(CompilationInfo* info) |
| 38 : info_(info), | 40 : info_(info), |
| 39 oracle_( | 41 oracle_( |
| (...skipping 21 matching lines...) Expand all Loading... |
| 61 // expressions before other declarations. | 63 // expressions before other declarations. |
| 62 if (scope->is_function_scope() && scope->function() != NULL) { | 64 if (scope->is_function_scope() && scope->function() != NULL) { |
| 63 RECURSE(visitor->VisitVariableDeclaration(scope->function())); | 65 RECURSE(visitor->VisitVariableDeclaration(scope->function())); |
| 64 } | 66 } |
| 65 RECURSE(visitor->VisitDeclarations(scope->declarations())); | 67 RECURSE(visitor->VisitDeclarations(scope->declarations())); |
| 66 RECURSE(visitor->VisitStatements(info->function()->body())); | 68 RECURSE(visitor->VisitStatements(info->function()->body())); |
| 67 } | 69 } |
| 68 | 70 |
| 69 #undef RECURSE | 71 #undef RECURSE |
| 70 | 72 |
| 73 |
| 74 Effect AstTyper::ObservedOnStack(Object* value) { |
| 75 Type* lower = Type::OfCurrently(Handle<Object>(value, isolate())); |
| 76 return Effect(Bounds(lower, Type::Any(), isolate())); |
| 77 } |
| 78 |
| 79 |
| 80 #ifdef OBJECT_PRINT |
| 81 static void PrintObserved(Variable* var, Object* value, Handle<Type> type) { |
| 82 PrintF(" observed %s ", var->IsParameter() ? "param" : "local"); |
| 83 var->name()->Print(); |
| 84 PrintF(" : "); |
| 85 value->ShortPrint(); |
| 86 PrintF(" -> "); |
| 87 type->TypePrint(); |
| 88 } |
| 89 #endif // OBJECT_PRINT |
| 90 |
| 91 |
| 92 void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) { |
| 93 if (stmt->OsrEntryId() != info_->osr_ast_id()) return; |
| 94 |
| 95 DisallowHeapAllocation no_gc; |
| 96 JavaScriptFrameIterator it(isolate()); |
| 97 JavaScriptFrame* frame = it.frame(); |
| 98 Scope* scope = info_->scope(); |
| 99 |
| 100 // Assert that the frame on the stack belongs to the function we want to OSR. |
| 101 ASSERT_EQ(*info_->closure(), frame->function()); |
| 102 |
| 103 int params = scope->num_parameters(); |
| 104 int locals = scope->StackLocalCount(); |
| 105 |
| 106 // Use sequential composition to achieve desired narrowing. |
| 107 // The receiver is a parameter with index -1. |
| 108 store_.Seq(parameter_index(-1), ObservedOnStack(frame->receiver())); |
| 109 for (int i = 0; i < params; i++) { |
| 110 store_.Seq(parameter_index(i), ObservedOnStack(frame->GetParameter(i))); |
| 111 } |
| 112 |
| 113 for (int i = 0; i < locals; i++) { |
| 114 store_.Seq(stack_local_index(i), ObservedOnStack(frame->GetExpression(i))); |
| 115 } |
| 116 |
| 117 #ifdef OBJECT_PRINT |
| 118 if (FLAG_trace_osr && FLAG_print_scopes) { |
| 119 PrintObserved(scope->receiver(), |
| 120 frame->receiver(), |
| 121 store_.LookupBounds(parameter_index(-1)).lower); |
| 122 |
| 123 for (int i = 0; i < params; i++) { |
| 124 PrintObserved(scope->parameter(i), |
| 125 frame->GetParameter(i), |
| 126 store_.LookupBounds(parameter_index(i)).lower); |
| 127 } |
| 128 |
| 129 ZoneList<Variable*> local_vars(locals, zone()); |
| 130 ZoneList<Variable*> context_vars(scope->ContextLocalCount(), zone()); |
| 131 scope->CollectStackAndContextLocals(&local_vars, &context_vars); |
| 132 for (int i = 0; i < locals; i++) { |
| 133 PrintObserved(local_vars.at(i), |
| 134 frame->GetExpression(i), |
| 135 store_.LookupBounds(stack_local_index(i)).lower); |
| 136 } |
| 137 } |
| 138 #endif // OBJECT_PRINT |
| 139 } |
| 140 |
| 141 |
| 71 #define RECURSE(call) \ | 142 #define RECURSE(call) \ |
| 72 do { \ | 143 do { \ |
| 73 ASSERT(!HasStackOverflow()); \ | 144 ASSERT(!HasStackOverflow()); \ |
| 74 call; \ | 145 call; \ |
| 75 if (HasStackOverflow()) return; \ | 146 if (HasStackOverflow()) return; \ |
| 76 } while (false) | 147 } while (false) |
| 77 | 148 |
| 78 | 149 |
| 79 void AstTyper::VisitStatements(ZoneList<Statement*>* stmts) { | 150 void AstTyper::VisitStatements(ZoneList<Statement*>* stmts) { |
| 80 for (int i = 0; i < stmts->length(); ++i) { | 151 for (int i = 0; i < stmts->length(); ++i) { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) { | 285 void AstTyper::VisitDoWhileStatement(DoWhileStatement* stmt) { |
| 215 // Collect type feedback. | 286 // Collect type feedback. |
| 216 if (!stmt->cond()->ToBooleanIsTrue()) { | 287 if (!stmt->cond()->ToBooleanIsTrue()) { |
| 217 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); | 288 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); |
| 218 } | 289 } |
| 219 | 290 |
| 220 // TODO(rossberg): refine the unconditional Forget (here and elsewhere) by | 291 // TODO(rossberg): refine the unconditional Forget (here and elsewhere) by |
| 221 // computing the set of variables assigned in only some of the origins of the | 292 // computing the set of variables assigned in only some of the origins of the |
| 222 // control transfer (such as the loop body here). | 293 // control transfer (such as the loop body here). |
| 223 store_.Forget(); // Control may transfer here via looping or 'continue'. | 294 store_.Forget(); // Control may transfer here via looping or 'continue'. |
| 295 ObserveTypesAtOsrEntry(stmt); |
| 224 RECURSE(Visit(stmt->body())); | 296 RECURSE(Visit(stmt->body())); |
| 225 RECURSE(Visit(stmt->cond())); | 297 RECURSE(Visit(stmt->cond())); |
| 226 store_.Forget(); // Control may transfer here via 'break'. | 298 store_.Forget(); // Control may transfer here via 'break'. |
| 227 } | 299 } |
| 228 | 300 |
| 229 | 301 |
| 230 void AstTyper::VisitWhileStatement(WhileStatement* stmt) { | 302 void AstTyper::VisitWhileStatement(WhileStatement* stmt) { |
| 231 // Collect type feedback. | 303 // Collect type feedback. |
| 232 if (!stmt->cond()->ToBooleanIsTrue()) { | 304 if (!stmt->cond()->ToBooleanIsTrue()) { |
| 233 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); | 305 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); |
| 234 } | 306 } |
| 235 | 307 |
| 236 store_.Forget(); // Control may transfer here via looping or 'continue'. | 308 store_.Forget(); // Control may transfer here via looping or 'continue'. |
| 237 RECURSE(Visit(stmt->cond())); | 309 RECURSE(Visit(stmt->cond())); |
| 310 ObserveTypesAtOsrEntry(stmt); |
| 238 RECURSE(Visit(stmt->body())); | 311 RECURSE(Visit(stmt->body())); |
| 239 store_.Forget(); // Control may transfer here via termination or 'break'. | 312 store_.Forget(); // Control may transfer here via termination or 'break'. |
| 240 } | 313 } |
| 241 | 314 |
| 242 | 315 |
| 243 void AstTyper::VisitForStatement(ForStatement* stmt) { | 316 void AstTyper::VisitForStatement(ForStatement* stmt) { |
| 244 if (stmt->init() != NULL) { | 317 if (stmt->init() != NULL) { |
| 245 RECURSE(Visit(stmt->init())); | 318 RECURSE(Visit(stmt->init())); |
| 246 } | 319 } |
| 247 store_.Forget(); // Control may transfer here via looping. | 320 store_.Forget(); // Control may transfer here via looping. |
| 248 if (stmt->cond() != NULL) { | 321 if (stmt->cond() != NULL) { |
| 249 // Collect type feedback. | 322 // Collect type feedback. |
| 250 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); | 323 stmt->cond()->RecordToBooleanTypeFeedback(oracle()); |
| 251 | 324 |
| 252 RECURSE(Visit(stmt->cond())); | 325 RECURSE(Visit(stmt->cond())); |
| 253 } | 326 } |
| 327 ObserveTypesAtOsrEntry(stmt); |
| 254 RECURSE(Visit(stmt->body())); | 328 RECURSE(Visit(stmt->body())); |
| 255 if (stmt->next() != NULL) { | 329 if (stmt->next() != NULL) { |
| 256 store_.Forget(); // Control may transfer here via 'continue'. | 330 store_.Forget(); // Control may transfer here via 'continue'. |
| 257 RECURSE(Visit(stmt->next())); | 331 RECURSE(Visit(stmt->next())); |
| 258 } | 332 } |
| 259 store_.Forget(); // Control may transfer here via termination or 'break'. | 333 store_.Forget(); // Control may transfer here via termination or 'break'. |
| 260 } | 334 } |
| 261 | 335 |
| 262 | 336 |
| 263 void AstTyper::VisitForInStatement(ForInStatement* stmt) { | 337 void AstTyper::VisitForInStatement(ForInStatement* stmt) { |
| 264 // Collect type feedback. | 338 // Collect type feedback. |
| 265 stmt->set_for_in_type(static_cast<ForInStatement::ForInType>( | 339 stmt->set_for_in_type(static_cast<ForInStatement::ForInType>( |
| 266 oracle()->ForInType(stmt->ForInFeedbackId()))); | 340 oracle()->ForInType(stmt->ForInFeedbackId()))); |
| 267 | 341 |
| 268 RECURSE(Visit(stmt->enumerable())); | 342 RECURSE(Visit(stmt->enumerable())); |
| 269 store_.Forget(); // Control may transfer here via looping or 'continue'. | 343 store_.Forget(); // Control may transfer here via looping or 'continue'. |
| 344 ObserveTypesAtOsrEntry(stmt); |
| 270 RECURSE(Visit(stmt->body())); | 345 RECURSE(Visit(stmt->body())); |
| 271 store_.Forget(); // Control may transfer here via 'break'. | 346 store_.Forget(); // Control may transfer here via 'break'. |
| 272 } | 347 } |
| 273 | 348 |
| 274 | 349 |
| 275 void AstTyper::VisitForOfStatement(ForOfStatement* stmt) { | 350 void AstTyper::VisitForOfStatement(ForOfStatement* stmt) { |
| 276 RECURSE(Visit(stmt->iterable())); | 351 RECURSE(Visit(stmt->iterable())); |
| 277 store_.Forget(); // Control may transfer here via looping or 'continue'. | 352 store_.Forget(); // Control may transfer here via looping or 'continue'. |
| 278 RECURSE(Visit(stmt->body())); | 353 RECURSE(Visit(stmt->body())); |
| 279 store_.Forget(); // Control may transfer here via 'break'. | 354 store_.Forget(); // Control may transfer here via 'break'. |
| (...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 void AstTyper::VisitModuleUrl(ModuleUrl* module) { | 807 void AstTyper::VisitModuleUrl(ModuleUrl* module) { |
| 733 } | 808 } |
| 734 | 809 |
| 735 | 810 |
| 736 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { | 811 void AstTyper::VisitModuleStatement(ModuleStatement* stmt) { |
| 737 RECURSE(Visit(stmt->body())); | 812 RECURSE(Visit(stmt->body())); |
| 738 } | 813 } |
| 739 | 814 |
| 740 | 815 |
| 741 } } // namespace v8::internal | 816 } } // namespace v8::internal |
| OLD | NEW |