| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/typing.h" | 5 #include "src/typing.h" |
| 6 | 6 |
| 7 #include "src/frames.h" | 7 #include "src/frames.h" |
| 8 #include "src/frames-inl.h" | 8 #include "src/frames-inl.h" |
| 9 #include "src/ostreams.h" | 9 #include "src/ostreams.h" |
| 10 #include "src/parser.h" // for CompileTimeValue; TODO(rossberg): should move | 10 #include "src/parser.h" // for CompileTimeValue; TODO(rossberg): should move |
| 11 #include "src/scopes.h" | 11 #include "src/scopes.h" |
| 12 #include "src/splay-tree-inl.h" | 12 #include "src/splay-tree-inl.h" |
| 13 | 13 |
| 14 namespace v8 { | 14 namespace v8 { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 | 17 |
| 18 AstTyper::AstTyper(CompilationInfo* info) | 18 AstTyper::AstTyper(Isolate* isolate, Zone* zone, Handle<JSFunction> closure, |
| 19 : info_(info), | 19 Scope* scope, BailoutId osr_ast_id, FunctionLiteral* root) |
| 20 oracle_(info->isolate(), info->zone(), | 20 : closure_(closure), |
| 21 handle(info->closure()->shared()->code()), | 21 scope_(scope), |
| 22 handle(info->closure()->shared()->feedback_vector()), | 22 osr_ast_id_(osr_ast_id), |
| 23 handle(info->closure()->context()->native_context())), | 23 root_(root), |
| 24 store_(info->zone()) { | 24 oracle_(isolate, zone, handle(closure->shared()->code()), |
| 25 InitializeAstVisitor(info->isolate(), info->zone()); | 25 handle(closure->shared()->feedback_vector()), |
| 26 handle(closure->context()->native_context())), |
| 27 store_(zone) { |
| 28 InitializeAstVisitor(isolate, zone); |
| 26 } | 29 } |
| 27 | 30 |
| 28 | 31 |
| 29 #ifdef OBJECT_PRINT | 32 #ifdef OBJECT_PRINT |
| 30 static void PrintObserved(Variable* var, Object* value, Type* type) { | 33 static void PrintObserved(Variable* var, Object* value, Type* type) { |
| 31 OFStream os(stdout); | 34 OFStream os(stdout); |
| 32 os << " observed " << (var->IsParameter() ? "param" : "local") << " "; | 35 os << " observed " << (var->IsParameter() ? "param" : "local") << " "; |
| 33 var->name()->Print(os); | 36 var->name()->Print(os); |
| 34 os << " : " << Brief(value) << " -> "; | 37 os << " : " << Brief(value) << " -> "; |
| 35 type->PrintTo(os); | 38 type->PrintTo(os); |
| 36 os << std::endl; | 39 os << std::endl; |
| 37 } | 40 } |
| 38 #endif // OBJECT_PRINT | 41 #endif // OBJECT_PRINT |
| 39 | 42 |
| 40 | 43 |
| 41 Effect AstTyper::ObservedOnStack(Object* value) { | 44 Effect AstTyper::ObservedOnStack(Object* value) { |
| 42 Type* lower = Type::NowOf(value, zone()); | 45 Type* lower = Type::NowOf(value, zone()); |
| 43 return Effect(Bounds(lower, Type::Any(zone()))); | 46 return Effect(Bounds(lower, Type::Any(zone()))); |
| 44 } | 47 } |
| 45 | 48 |
| 46 | 49 |
| 47 void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) { | 50 void AstTyper::ObserveTypesAtOsrEntry(IterationStatement* stmt) { |
| 48 if (stmt->OsrEntryId() != info_->osr_ast_id()) return; | 51 if (stmt->OsrEntryId() != osr_ast_id_) return; |
| 49 | 52 |
| 50 DisallowHeapAllocation no_gc; | 53 DisallowHeapAllocation no_gc; |
| 51 JavaScriptFrameIterator it(isolate()); | 54 JavaScriptFrameIterator it(isolate()); |
| 52 JavaScriptFrame* frame = it.frame(); | 55 JavaScriptFrame* frame = it.frame(); |
| 53 Scope* scope = info_->scope(); | |
| 54 | 56 |
| 55 // Assert that the frame on the stack belongs to the function we want to OSR. | 57 // Assert that the frame on the stack belongs to the function we want to OSR. |
| 56 DCHECK_EQ(*info_->closure(), frame->function()); | 58 DCHECK_EQ(*closure_, frame->function()); |
| 57 | 59 |
| 58 int params = scope->num_parameters(); | 60 int params = scope_->num_parameters(); |
| 59 int locals = scope->StackLocalCount(); | 61 int locals = scope_->StackLocalCount(); |
| 60 | 62 |
| 61 // Use sequential composition to achieve desired narrowing. | 63 // Use sequential composition to achieve desired narrowing. |
| 62 // The receiver is a parameter with index -1. | 64 // The receiver is a parameter with index -1. |
| 63 store_.Seq(parameter_index(-1), ObservedOnStack(frame->receiver())); | 65 store_.Seq(parameter_index(-1), ObservedOnStack(frame->receiver())); |
| 64 for (int i = 0; i < params; i++) { | 66 for (int i = 0; i < params; i++) { |
| 65 store_.Seq(parameter_index(i), ObservedOnStack(frame->GetParameter(i))); | 67 store_.Seq(parameter_index(i), ObservedOnStack(frame->GetParameter(i))); |
| 66 } | 68 } |
| 67 | 69 |
| 68 for (int i = 0; i < locals; i++) { | 70 for (int i = 0; i < locals; i++) { |
| 69 store_.Seq(stack_local_index(i), ObservedOnStack(frame->GetExpression(i))); | 71 store_.Seq(stack_local_index(i), ObservedOnStack(frame->GetExpression(i))); |
| 70 } | 72 } |
| 71 | 73 |
| 72 #ifdef OBJECT_PRINT | 74 #ifdef OBJECT_PRINT |
| 73 if (FLAG_trace_osr && FLAG_print_scopes) { | 75 if (FLAG_trace_osr && FLAG_print_scopes) { |
| 74 PrintObserved(scope->receiver(), | 76 PrintObserved(scope_->receiver(), frame->receiver(), |
| 75 frame->receiver(), | |
| 76 store_.LookupBounds(parameter_index(-1)).lower); | 77 store_.LookupBounds(parameter_index(-1)).lower); |
| 77 | 78 |
| 78 for (int i = 0; i < params; i++) { | 79 for (int i = 0; i < params; i++) { |
| 79 PrintObserved(scope->parameter(i), | 80 PrintObserved(scope_->parameter(i), frame->GetParameter(i), |
| 80 frame->GetParameter(i), | |
| 81 store_.LookupBounds(parameter_index(i)).lower); | 81 store_.LookupBounds(parameter_index(i)).lower); |
| 82 } | 82 } |
| 83 | 83 |
| 84 ZoneList<Variable*> local_vars(locals, zone()); | 84 ZoneList<Variable*> local_vars(locals, zone()); |
| 85 ZoneList<Variable*> context_vars(scope->ContextLocalCount(), zone()); | 85 ZoneList<Variable*> context_vars(scope_->ContextLocalCount(), zone()); |
| 86 ZoneList<Variable*> global_vars(scope->ContextGlobalCount(), zone()); | 86 ZoneList<Variable*> global_vars(scope_->ContextGlobalCount(), zone()); |
| 87 scope->CollectStackAndContextLocals(&local_vars, &context_vars, | 87 scope_->CollectStackAndContextLocals(&local_vars, &context_vars, |
| 88 &global_vars); | 88 &global_vars); |
| 89 for (int i = 0; i < locals; i++) { | 89 for (int i = 0; i < locals; i++) { |
| 90 PrintObserved(local_vars.at(i), | 90 PrintObserved(local_vars.at(i), |
| 91 frame->GetExpression(i), | 91 frame->GetExpression(i), |
| 92 store_.LookupBounds(stack_local_index(i)).lower); | 92 store_.LookupBounds(stack_local_index(i)).lower); |
| 93 } | 93 } |
| 94 } | 94 } |
| 95 #endif // OBJECT_PRINT | 95 #endif // OBJECT_PRINT |
| 96 } | 96 } |
| 97 | 97 |
| 98 | 98 |
| 99 #define RECURSE(call) \ | 99 #define RECURSE(call) \ |
| 100 do { \ | 100 do { \ |
| 101 DCHECK(!HasStackOverflow()); \ | 101 DCHECK(!HasStackOverflow()); \ |
| 102 call; \ | 102 call; \ |
| 103 if (HasStackOverflow()) return; \ | 103 if (HasStackOverflow()) return; \ |
| 104 } while (false) | 104 } while (false) |
| 105 | 105 |
| 106 | 106 |
| 107 void AstTyper::Run() { | 107 void AstTyper::Run() { |
| 108 Scope* scope = info_->scope(); | 108 RECURSE(VisitDeclarations(scope_->declarations())); |
| 109 RECURSE(VisitDeclarations(scope->declarations())); | 109 RECURSE(VisitStatements(root_->body())); |
| 110 RECURSE(VisitStatements(info_->literal()->body())); | |
| 111 } | 110 } |
| 112 | 111 |
| 113 | 112 |
| 114 void AstTyper::VisitStatements(ZoneList<Statement*>* stmts) { | 113 void AstTyper::VisitStatements(ZoneList<Statement*>* stmts) { |
| 115 for (int i = 0; i < stmts->length(); ++i) { | 114 for (int i = 0; i < stmts->length(); ++i) { |
| 116 Statement* stmt = stmts->at(i); | 115 Statement* stmt = stmts->at(i); |
| 117 RECURSE(Visit(stmt)); | 116 RECURSE(Visit(stmt)); |
| 118 if (stmt->IsJump()) break; | 117 if (stmt->IsJump()) break; |
| 119 } | 118 } |
| 120 } | 119 } |
| (...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 790 void AstTyper::VisitImportDeclaration(ImportDeclaration* declaration) { | 789 void AstTyper::VisitImportDeclaration(ImportDeclaration* declaration) { |
| 791 } | 790 } |
| 792 | 791 |
| 793 | 792 |
| 794 void AstTyper::VisitExportDeclaration(ExportDeclaration* declaration) { | 793 void AstTyper::VisitExportDeclaration(ExportDeclaration* declaration) { |
| 795 } | 794 } |
| 796 | 795 |
| 797 | 796 |
| 798 } // namespace internal | 797 } // namespace internal |
| 799 } // namespace v8 | 798 } // namespace v8 |
| OLD | NEW |