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/ast/compile-time-value.h" | 7 #include "src/ast/compile-time-value.h" |
8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
9 #include "src/compilation-info.h" | 9 #include "src/compilation-info.h" |
10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 break; | 261 break; |
262 } | 262 } |
263 return false; | 263 return false; |
264 } | 264 } |
265 | 265 |
266 private: | 266 private: |
267 BreakableStatement* target_; | 267 BreakableStatement* target_; |
268 LoopBuilder* control_; | 268 LoopBuilder* control_; |
269 }; | 269 }; |
270 | 270 |
271 | |
272 AstGraphBuilder::AstGraphBuilder(Zone* local_zone, CompilationInfo* info, | 271 AstGraphBuilder::AstGraphBuilder(Zone* local_zone, CompilationInfo* info, |
273 JSGraph* jsgraph, float invocation_frequency, | 272 JSGraph* jsgraph, |
| 273 CallFrequency invocation_frequency, |
274 LoopAssignmentAnalysis* loop) | 274 LoopAssignmentAnalysis* loop) |
275 : isolate_(info->isolate()), | 275 : isolate_(info->isolate()), |
276 local_zone_(local_zone), | 276 local_zone_(local_zone), |
277 info_(info), | 277 info_(info), |
278 jsgraph_(jsgraph), | 278 jsgraph_(jsgraph), |
279 invocation_frequency_(invocation_frequency), | 279 invocation_frequency_(invocation_frequency), |
280 environment_(nullptr), | 280 environment_(nullptr), |
281 ast_context_(nullptr), | 281 ast_context_(nullptr), |
282 globals_(0, local_zone), | 282 globals_(0, local_zone), |
283 execution_control_(nullptr), | 283 execution_control_(nullptr), |
(...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1685 // The callee and the receiver both have to be pushed onto the operand stack | 1685 // The callee and the receiver both have to be pushed onto the operand stack |
1686 // before arguments are being evaluated. | 1686 // before arguments are being evaluated. |
1687 environment()->Push(callee_value); | 1687 environment()->Push(callee_value); |
1688 environment()->Push(receiver_value); | 1688 environment()->Push(receiver_value); |
1689 | 1689 |
1690 // Evaluate all arguments to the function call, | 1690 // Evaluate all arguments to the function call, |
1691 ZoneList<Expression*>* args = expr->arguments(); | 1691 ZoneList<Expression*>* args = expr->arguments(); |
1692 VisitForValues(args); | 1692 VisitForValues(args); |
1693 | 1693 |
1694 // Create node to perform the function call. | 1694 // Create node to perform the function call. |
1695 float const frequency = ComputeCallFrequency(expr->CallFeedbackICSlot()); | 1695 CallFrequency frequency = ComputeCallFrequency(expr->CallFeedbackICSlot()); |
1696 VectorSlotPair feedback = CreateVectorSlotPair(expr->CallFeedbackICSlot()); | 1696 VectorSlotPair feedback = CreateVectorSlotPair(expr->CallFeedbackICSlot()); |
1697 const Operator* call = | 1697 const Operator* call = |
1698 javascript()->Call(args->length() + 2, frequency, feedback, receiver_hint, | 1698 javascript()->Call(args->length() + 2, frequency, feedback, receiver_hint, |
1699 expr->tail_call_mode()); | 1699 expr->tail_call_mode()); |
1700 PrepareEagerCheckpoint(expr->CallId()); | 1700 PrepareEagerCheckpoint(expr->CallId()); |
1701 Node* value = ProcessArguments(call, args->length() + 2); | 1701 Node* value = ProcessArguments(call, args->length() + 2); |
1702 // The callee passed to the call, we just need to push something here to | 1702 // The callee passed to the call, we just need to push something here to |
1703 // satisfy the bailout location contract. The fullcodegen code will not | 1703 // satisfy the bailout location contract. The fullcodegen code will not |
1704 // ever look at this value, so we just push optimized_out here. | 1704 // ever look at this value, so we just push optimized_out here. |
1705 environment()->Push(jsgraph()->OptimizedOutConstant()); | 1705 environment()->Push(jsgraph()->OptimizedOutConstant()); |
1706 PrepareFrameState(value, expr->ReturnId(), OutputFrameStateCombine::Push()); | 1706 PrepareFrameState(value, expr->ReturnId(), OutputFrameStateCombine::Push()); |
1707 environment()->Drop(1); | 1707 environment()->Drop(1); |
1708 ast_context()->ProduceValue(expr, value); | 1708 ast_context()->ProduceValue(expr, value); |
1709 } | 1709 } |
1710 | 1710 |
1711 | 1711 |
1712 void AstGraphBuilder::VisitCallNew(CallNew* expr) { | 1712 void AstGraphBuilder::VisitCallNew(CallNew* expr) { |
1713 VisitForValue(expr->expression()); | 1713 VisitForValue(expr->expression()); |
1714 | 1714 |
1715 // Evaluate all arguments to the construct call. | 1715 // Evaluate all arguments to the construct call. |
1716 ZoneList<Expression*>* args = expr->arguments(); | 1716 ZoneList<Expression*>* args = expr->arguments(); |
1717 VisitForValues(args); | 1717 VisitForValues(args); |
1718 | 1718 |
1719 // The new target is the same as the callee. | 1719 // The new target is the same as the callee. |
1720 environment()->Push(environment()->Peek(args->length())); | 1720 environment()->Push(environment()->Peek(args->length())); |
1721 | 1721 |
1722 // Create node to perform the construct call. | 1722 // Create node to perform the construct call. |
1723 float const frequency = ComputeCallFrequency(expr->CallNewFeedbackSlot()); | 1723 CallFrequency frequency = ComputeCallFrequency(expr->CallNewFeedbackSlot()); |
1724 VectorSlotPair feedback = CreateVectorSlotPair(expr->CallNewFeedbackSlot()); | 1724 VectorSlotPair feedback = CreateVectorSlotPair(expr->CallNewFeedbackSlot()); |
1725 const Operator* call = | 1725 const Operator* call = |
1726 javascript()->Construct(args->length() + 2, frequency, feedback); | 1726 javascript()->Construct(args->length() + 2, frequency, feedback); |
1727 Node* value = ProcessArguments(call, args->length() + 2); | 1727 Node* value = ProcessArguments(call, args->length() + 2); |
1728 PrepareFrameState(value, expr->ReturnId(), OutputFrameStateCombine::Push()); | 1728 PrepareFrameState(value, expr->ReturnId(), OutputFrameStateCombine::Push()); |
1729 ast_context()->ProduceValue(expr, value); | 1729 ast_context()->ProduceValue(expr, value); |
1730 } | 1730 } |
1731 | 1731 |
1732 | 1732 |
1733 void AstGraphBuilder::VisitCallJSRuntime(CallRuntime* expr) { | 1733 void AstGraphBuilder::VisitCallJSRuntime(CallRuntime* expr) { |
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2233 | 2233 |
2234 VectorSlotPair AstGraphBuilder::CreateVectorSlotPair(FeedbackSlot slot) const { | 2234 VectorSlotPair AstGraphBuilder::CreateVectorSlotPair(FeedbackSlot slot) const { |
2235 return VectorSlotPair(handle(info()->closure()->feedback_vector()), slot); | 2235 return VectorSlotPair(handle(info()->closure()->feedback_vector()), slot); |
2236 } | 2236 } |
2237 | 2237 |
2238 | 2238 |
2239 void AstGraphBuilder::VisitRewritableExpression(RewritableExpression* node) { | 2239 void AstGraphBuilder::VisitRewritableExpression(RewritableExpression* node) { |
2240 Visit(node->expression()); | 2240 Visit(node->expression()); |
2241 } | 2241 } |
2242 | 2242 |
2243 float AstGraphBuilder::ComputeCallFrequency(FeedbackSlot slot) const { | 2243 CallFrequency AstGraphBuilder::ComputeCallFrequency(FeedbackSlot slot) const { |
2244 if (slot.IsInvalid()) return 0.0f; | 2244 if (invocation_frequency_.IsUnknown() || slot.IsInvalid()) { |
| 2245 return CallFrequency(); |
| 2246 } |
2245 Handle<FeedbackVector> feedback_vector(info()->closure()->feedback_vector(), | 2247 Handle<FeedbackVector> feedback_vector(info()->closure()->feedback_vector(), |
2246 isolate()); | 2248 isolate()); |
2247 CallICNexus nexus(feedback_vector, slot); | 2249 CallICNexus nexus(feedback_vector, slot); |
2248 return nexus.ComputeCallFrequency() * invocation_frequency_; | 2250 return CallFrequency(nexus.ComputeCallFrequency() * |
| 2251 invocation_frequency_.value()); |
2249 } | 2252 } |
2250 | 2253 |
2251 Node* AstGraphBuilder::ProcessArguments(const Operator* op, int arity) { | 2254 Node* AstGraphBuilder::ProcessArguments(const Operator* op, int arity) { |
2252 DCHECK(environment()->stack_height() >= arity); | 2255 DCHECK(environment()->stack_height() >= arity); |
2253 Node** all = info()->zone()->NewArray<Node*>(arity); | 2256 Node** all = info()->zone()->NewArray<Node*>(arity); |
2254 for (int i = arity - 1; i >= 0; --i) { | 2257 for (int i = arity - 1; i >= 0; --i) { |
2255 all[i] = environment()->Pop(); | 2258 all[i] = environment()->Pop(); |
2256 } | 2259 } |
2257 Node* value = NewNode(op, arity, all); | 2260 Node* value = NewNode(op, arity, all); |
2258 return value; | 2261 return value; |
(...skipping 890 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3149 } else if (value != other) { | 3152 } else if (value != other) { |
3150 // Phi does not exist yet, introduce one. | 3153 // Phi does not exist yet, introduce one. |
3151 value = NewPhi(inputs, value, control); | 3154 value = NewPhi(inputs, value, control); |
3152 value->ReplaceInput(inputs - 1, other); | 3155 value->ReplaceInput(inputs - 1, other); |
3153 } | 3156 } |
3154 return value; | 3157 return value; |
3155 } | 3158 } |
3156 | 3159 |
3157 AstGraphBuilderWithPositions::AstGraphBuilderWithPositions( | 3160 AstGraphBuilderWithPositions::AstGraphBuilderWithPositions( |
3158 Zone* local_zone, CompilationInfo* info, JSGraph* jsgraph, | 3161 Zone* local_zone, CompilationInfo* info, JSGraph* jsgraph, |
3159 float invocation_frequency, LoopAssignmentAnalysis* loop_assignment, | 3162 CallFrequency invocation_frequency, LoopAssignmentAnalysis* loop_assignment, |
3160 SourcePositionTable* source_positions, int inlining_id) | 3163 SourcePositionTable* source_positions, int inlining_id) |
3161 : AstGraphBuilder(local_zone, info, jsgraph, invocation_frequency, | 3164 : AstGraphBuilder(local_zone, info, jsgraph, invocation_frequency, |
3162 loop_assignment), | 3165 loop_assignment), |
3163 source_positions_(source_positions), | 3166 source_positions_(source_positions), |
3164 start_position_(info->shared_info()->start_position(), inlining_id) {} | 3167 start_position_(info->shared_info()->start_position(), inlining_id) {} |
3165 | 3168 |
3166 } // namespace compiler | 3169 } // namespace compiler |
3167 } // namespace internal | 3170 } // namespace internal |
3168 } // namespace v8 | 3171 } // namespace v8 |
OLD | NEW |