OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/compiler/ast-graph-builder.h" | 5 #include "src/compiler/ast-graph-builder.h" |
6 | 6 |
7 #include "src/compiler.h" | 7 #include "src/compiler.h" |
8 #include "src/compiler/control-builders.h" | 8 #include "src/compiler/control-builders.h" |
9 #include "src/compiler/node-properties.h" | 9 #include "src/compiler/node-properties.h" |
10 #include "src/compiler/node-properties-inl.h" | 10 #include "src/compiler/node-properties-inl.h" |
11 #include "src/full-codegen.h" | 11 #include "src/full-codegen.h" |
12 #include "src/parser.h" | 12 #include "src/parser.h" |
13 #include "src/scopes.h" | 13 #include "src/scopes.h" |
14 | 14 |
15 namespace v8 { | 15 namespace v8 { |
16 namespace internal { | 16 namespace internal { |
17 namespace compiler { | 17 namespace compiler { |
18 | 18 |
19 AstGraphBuilder::AstGraphBuilder(CompilationInfo* info, JSGraph* jsgraph, | 19 AstGraphBuilder::AstGraphBuilder(CompilationInfo* info, JSGraph* jsgraph) |
20 SourcePositionTable* source_positions) | |
21 : StructuredGraphBuilder(jsgraph->graph(), jsgraph->common()), | 20 : StructuredGraphBuilder(jsgraph->graph(), jsgraph->common()), |
22 info_(info), | 21 info_(info), |
23 jsgraph_(jsgraph), | 22 jsgraph_(jsgraph), |
24 source_positions_(source_positions), | |
25 globals_(0, info->zone()), | 23 globals_(0, info->zone()), |
26 breakable_(NULL), | 24 breakable_(NULL), |
27 execution_context_(NULL) { | 25 execution_context_(NULL) { |
28 InitializeAstVisitor(info->zone()); | 26 InitializeAstVisitor(info->zone()); |
29 } | 27 } |
30 | 28 |
31 | 29 |
32 Node* AstGraphBuilder::GetFunctionClosure() { | 30 Node* AstGraphBuilder::GetFunctionClosure() { |
33 if (!function_closure_.is_set()) { | 31 if (!function_closure_.is_set()) { |
34 // Parameter -1 is special for the function closure | 32 // Parameter -1 is special for the function closure |
(...skipping 13 matching lines...) Expand all Loading... |
48 function_context_.set(node); | 46 function_context_.set(node); |
49 } | 47 } |
50 return function_context_.get(); | 48 return function_context_.get(); |
51 } | 49 } |
52 | 50 |
53 | 51 |
54 bool AstGraphBuilder::CreateGraph() { | 52 bool AstGraphBuilder::CreateGraph() { |
55 Scope* scope = info()->scope(); | 53 Scope* scope = info()->scope(); |
56 DCHECK(graph() != NULL); | 54 DCHECK(graph() != NULL); |
57 | 55 |
58 SourcePositionTable::Scope start_pos( | |
59 source_positions(), | |
60 SourcePosition(info()->shared_info()->start_position())); | |
61 | |
62 // Set up the basic structure of the graph. | 56 // Set up the basic structure of the graph. |
63 graph()->SetStart( | 57 int parameter_count = info()->num_parameters(); |
64 graph()->NewNode(common()->Start(info()->num_parameters()))); | 58 graph()->SetStart(graph()->NewNode(common()->Start(parameter_count))); |
65 | 59 |
66 // Initialize the top-level environment. | 60 // Initialize the top-level environment. |
67 Environment env(this, scope, graph()->start()); | 61 Environment env(this, scope, graph()->start()); |
68 set_environment(&env); | 62 set_environment(&env); |
69 | 63 |
70 // Build node to initialize local function context. | 64 // Build node to initialize local function context. |
71 Node* closure = GetFunctionClosure(); | 65 Node* closure = GetFunctionClosure(); |
72 Node* outer = GetFunctionContext(); | 66 Node* outer = GetFunctionContext(); |
73 Node* inner = BuildLocalFunctionContext(outer, closure); | 67 Node* inner = BuildLocalFunctionContext(outer, closure); |
74 | 68 |
(...skipping 16 matching lines...) Expand all Loading... |
91 // Visit declarations within the function scope. | 85 // Visit declarations within the function scope. |
92 VisitDeclarations(scope->declarations()); | 86 VisitDeclarations(scope->declarations()); |
93 | 87 |
94 // TODO(mstarzinger): This should do an inlined stack check. | 88 // TODO(mstarzinger): This should do an inlined stack check. |
95 NewNode(javascript()->Runtime(Runtime::kStackGuard, 0)); | 89 NewNode(javascript()->Runtime(Runtime::kStackGuard, 0)); |
96 | 90 |
97 // Visit statements in the function body. | 91 // Visit statements in the function body. |
98 VisitStatements(info()->function()->body()); | 92 VisitStatements(info()->function()->body()); |
99 if (HasStackOverflow()) return false; | 93 if (HasStackOverflow()) return false; |
100 | 94 |
101 SourcePositionTable::Scope end_pos( | |
102 source_positions(), | |
103 SourcePosition(info()->shared_info()->end_position() - 1)); | |
104 | |
105 // Emit tracing call if requested to do so. | 95 // Emit tracing call if requested to do so. |
106 if (FLAG_trace) { | 96 if (FLAG_trace) { |
107 // TODO(mstarzinger): Only traces implicit return. | 97 // TODO(mstarzinger): Only traces implicit return. |
108 Node* return_value = jsgraph()->UndefinedConstant(); | 98 Node* return_value = jsgraph()->UndefinedConstant(); |
109 NewNode(javascript()->Runtime(Runtime::kTraceExit, 1), return_value); | 99 NewNode(javascript()->Runtime(Runtime::kTraceExit, 1), return_value); |
110 } | 100 } |
111 | 101 |
112 // Return 'undefined' in case we can fall off the end. | 102 // Return 'undefined' in case we can fall off the end. |
113 Node* control = NewNode(common()->Return(), jsgraph()->UndefinedConstant()); | 103 Node* control = NewNode(common()->Return(), jsgraph()->UndefinedConstant()); |
114 UpdateControlDependencyToLeaveFunction(control); | 104 UpdateControlDependencyToLeaveFunction(control); |
(...skipping 1836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1951 UNREACHABLE(); | 1941 UNREACHABLE(); |
1952 js_op = NULL; | 1942 js_op = NULL; |
1953 } | 1943 } |
1954 return NewNode(js_op, left, right); | 1944 return NewNode(js_op, left, right); |
1955 } | 1945 } |
1956 | 1946 |
1957 | 1947 |
1958 void AstGraphBuilder::BuildLazyBailout(Node* node, BailoutId ast_id) { | 1948 void AstGraphBuilder::BuildLazyBailout(Node* node, BailoutId ast_id) { |
1959 if (OperatorProperties::CanLazilyDeoptimize(node->op())) { | 1949 if (OperatorProperties::CanLazilyDeoptimize(node->op())) { |
1960 // The deopting node should have an outgoing control dependency. | 1950 // The deopting node should have an outgoing control dependency. |
1961 DCHECK(GetControlDependency() == node); | 1951 DCHECK(environment()->GetControlDependency() == node); |
1962 | 1952 |
1963 StructuredGraphBuilder::Environment* continuation_env = | 1953 StructuredGraphBuilder::Environment* continuation_env = environment(); |
1964 environment_internal(); | |
1965 // Create environment for the deoptimization block, and build the block. | 1954 // Create environment for the deoptimization block, and build the block. |
1966 StructuredGraphBuilder::Environment* deopt_env = | 1955 StructuredGraphBuilder::Environment* deopt_env = |
1967 CopyEnvironment(continuation_env); | 1956 CopyEnvironment(continuation_env); |
1968 set_environment(deopt_env); | 1957 set_environment(deopt_env); |
1969 | 1958 |
1970 NewNode(common()->LazyDeoptimization()); | 1959 NewNode(common()->LazyDeoptimization()); |
1971 | 1960 |
1972 Node* state_node = environment()->Checkpoint(ast_id); | 1961 Node* state_node = environment()->Checkpoint(ast_id); |
1973 | 1962 |
1974 Node* deoptimize_node = NewNode(common()->Deoptimize(), state_node); | 1963 Node* deoptimize_node = NewNode(common()->Deoptimize(), state_node); |
1975 | 1964 |
1976 UpdateControlDependencyToLeaveFunction(deoptimize_node); | 1965 UpdateControlDependencyToLeaveFunction(deoptimize_node); |
1977 | 1966 |
1978 // Continue with the original environment. | 1967 // Continue with the original environment. |
1979 set_environment(continuation_env); | 1968 set_environment(continuation_env); |
1980 | 1969 |
1981 NewNode(common()->Continuation()); | 1970 NewNode(common()->Continuation()); |
1982 } | 1971 } |
1983 } | 1972 } |
1984 } | 1973 } |
1985 } | 1974 } |
1986 } // namespace v8::internal::compiler | 1975 } // namespace v8::internal::compiler |
OLD | NEW |