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/ast-loop-assignment-analyzer.h" | 8 #include "src/compiler/ast-loop-assignment-analyzer.h" |
9 #include "src/compiler/control-builders.h" | 9 #include "src/compiler/control-builders.h" |
10 #include "src/compiler/machine-operator.h" | 10 #include "src/compiler/machine-operator.h" |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 Property* property = expr->AsProperty(); | 141 Property* property = expr->AsProperty(); |
142 DCHECK(expr->IsValidReferenceExpression()); | 142 DCHECK(expr->IsValidReferenceExpression()); |
143 LhsKind lhs_kind = | 143 LhsKind lhs_kind = |
144 (property == NULL) ? VARIABLE : (property->key()->IsPropertyName()) | 144 (property == NULL) ? VARIABLE : (property->key()->IsPropertyName()) |
145 ? NAMED_PROPERTY | 145 ? NAMED_PROPERTY |
146 : KEYED_PROPERTY; | 146 : KEYED_PROPERTY; |
147 return lhs_kind; | 147 return lhs_kind; |
148 } | 148 } |
149 | 149 |
150 | 150 |
151 // Helper to find an existing shared function info in the baseline code for the | |
152 // given function literal. Used to canonicalize SharedFunctionInfo objects. | |
153 static Handle<SharedFunctionInfo> SearchSharedFunctionInfo( | |
154 Code* unoptimized_code, FunctionLiteral* expr) { | |
155 int start_position = expr->start_position(); | |
156 for (RelocIterator it(unoptimized_code); !it.done(); it.next()) { | |
157 RelocInfo* rinfo = it.rinfo(); | |
158 if (rinfo->rmode() != RelocInfo::EMBEDDED_OBJECT) continue; | |
159 Object* obj = rinfo->target_object(); | |
160 if (obj->IsSharedFunctionInfo()) { | |
161 SharedFunctionInfo* shared = SharedFunctionInfo::cast(obj); | |
162 if (shared->start_position() == start_position) { | |
163 return Handle<SharedFunctionInfo>(shared); | |
164 } | |
165 } | |
166 } | |
167 return Handle<SharedFunctionInfo>(); | |
168 } | |
169 | |
170 | |
171 StructuredGraphBuilder::Environment* AstGraphBuilder::CopyEnvironment( | 151 StructuredGraphBuilder::Environment* AstGraphBuilder::CopyEnvironment( |
172 StructuredGraphBuilder::Environment* env) { | 152 StructuredGraphBuilder::Environment* env) { |
173 return new (zone()) Environment(*reinterpret_cast<Environment*>(env)); | 153 return new (zone()) Environment(*reinterpret_cast<Environment*>(env)); |
174 } | 154 } |
175 | 155 |
176 | 156 |
177 AstGraphBuilder::Environment::Environment(AstGraphBuilder* builder, | 157 AstGraphBuilder::Environment::Environment(AstGraphBuilder* builder, |
178 Scope* scope, | 158 Scope* scope, |
179 Node* control_dependency) | 159 Node* control_dependency) |
180 : StructuredGraphBuilder::Environment(builder, control_dependency), | 160 : StructuredGraphBuilder::Environment(builder, control_dependency), |
(...skipping 647 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
828 Node* node = NewNode(javascript()->CallRuntime(Runtime::kDebugBreak, 0)); | 808 Node* node = NewNode(javascript()->CallRuntime(Runtime::kDebugBreak, 0)); |
829 PrepareFrameState(node, stmt->DebugBreakId()); | 809 PrepareFrameState(node, stmt->DebugBreakId()); |
830 } | 810 } |
831 | 811 |
832 | 812 |
833 void AstGraphBuilder::VisitFunctionLiteral(FunctionLiteral* expr) { | 813 void AstGraphBuilder::VisitFunctionLiteral(FunctionLiteral* expr) { |
834 Node* context = current_context(); | 814 Node* context = current_context(); |
835 | 815 |
836 // Build a new shared function info if we cannot find one in the baseline | 816 // Build a new shared function info if we cannot find one in the baseline |
837 // code. We also have a stack overflow if the recursive compilation did. | 817 // code. We also have a stack overflow if the recursive compilation did. |
838 Handle<SharedFunctionInfo> shared_info = | 818 expr->InitializeSharedInfo(handle(info()->shared_info()->code())); |
839 SearchSharedFunctionInfo(info()->shared_info()->code(), expr); | 819 Handle<SharedFunctionInfo> shared_info = expr->shared_info(); |
840 if (shared_info.is_null()) { | 820 if (shared_info.is_null()) { |
841 shared_info = Compiler::BuildFunctionInfo(expr, info()->script(), info()); | 821 shared_info = Compiler::BuildFunctionInfo(expr, info()->script(), info()); |
842 CHECK(!shared_info.is_null()); // TODO(mstarzinger): Set stack overflow? | 822 CHECK(!shared_info.is_null()); // TODO(mstarzinger): Set stack overflow? |
843 } | 823 } |
844 | 824 |
845 // Create node to instantiate a new closure. | 825 // Create node to instantiate a new closure. |
846 Node* info = jsgraph()->Constant(shared_info); | 826 Node* info = jsgraph()->Constant(shared_info); |
847 Node* pretenure = jsgraph()->BooleanConstant(expr->pretenure()); | 827 Node* pretenure = jsgraph()->BooleanConstant(expr->pretenure()); |
848 const Operator* op = javascript()->CallRuntime(Runtime::kNewClosure, 3); | 828 const Operator* op = javascript()->CallRuntime(Runtime::kNewClosure, 3); |
849 Node* value = NewNode(op, context, info, pretenure); | 829 Node* value = NewNode(op, context, info, pretenure); |
(...skipping 1398 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2248 | 2228 |
2249 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop( | 2229 BitVector* AstGraphBuilder::GetVariablesAssignedInLoop( |
2250 IterationStatement* stmt) { | 2230 IterationStatement* stmt) { |
2251 if (loop_assignment_analysis_ == NULL) return NULL; | 2231 if (loop_assignment_analysis_ == NULL) return NULL; |
2252 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt); | 2232 return loop_assignment_analysis_->GetVariablesAssignedInLoop(stmt); |
2253 } | 2233 } |
2254 | 2234 |
2255 } // namespace compiler | 2235 } // namespace compiler |
2256 } // namespace internal | 2236 } // namespace internal |
2257 } // namespace v8 | 2237 } // namespace v8 |
OLD | NEW |