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 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 | 781 |
782 | 782 |
783 AstGraphBuilder::Environment* | 783 AstGraphBuilder::Environment* |
784 AstGraphBuilder::Environment::CopyAsUnreachable() { | 784 AstGraphBuilder::Environment::CopyAsUnreachable() { |
785 Environment* env = new (zone()) Environment(this, nullptr); | 785 Environment* env = new (zone()) Environment(this, nullptr); |
786 env->MarkAsUnreachable(); | 786 env->MarkAsUnreachable(); |
787 return env; | 787 return env; |
788 } | 788 } |
789 | 789 |
790 AstGraphBuilder::Environment* AstGraphBuilder::Environment::CopyForOsrEntry() { | 790 AstGraphBuilder::Environment* AstGraphBuilder::Environment::CopyForOsrEntry() { |
791 return new (zone()) | 791 LivenessAnalyzerBlock* copy_block = |
792 Environment(this, builder_->liveness_analyzer()->NewBlock()); | 792 liveness_block() == nullptr ? nullptr |
| 793 : builder_->liveness_analyzer()->NewBlock(); |
| 794 return new (zone()) Environment(this, copy_block); |
793 } | 795 } |
794 | 796 |
795 AstGraphBuilder::Environment* | 797 AstGraphBuilder::Environment* |
796 AstGraphBuilder::Environment::CopyAndShareLiveness() { | 798 AstGraphBuilder::Environment::CopyAndShareLiveness() { |
797 if (liveness_block() != nullptr) { | 799 if (liveness_block() != nullptr) { |
798 // Finish the current liveness block before copying. | 800 // Finish the current liveness block before copying. |
799 liveness_block_ = builder_->liveness_analyzer()->NewBlock(liveness_block()); | 801 liveness_block_ = builder_->liveness_analyzer()->NewBlock(liveness_block()); |
800 } | 802 } |
801 Environment* env = new (zone()) Environment(this, liveness_block()); | 803 Environment* env = new (zone()) Environment(this, liveness_block()); |
802 return env; | 804 return env; |
(...skipping 3392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4195 | 4197 |
4196 void AstGraphBuilder::Environment::PrepareForOsrEntry() { | 4198 void AstGraphBuilder::Environment::PrepareForOsrEntry() { |
4197 int size = static_cast<int>(values()->size()); | 4199 int size = static_cast<int>(values()->size()); |
4198 Graph* graph = builder_->graph(); | 4200 Graph* graph = builder_->graph(); |
4199 | 4201 |
4200 // Set the control and effect to the OSR loop entry. | 4202 // Set the control and effect to the OSR loop entry. |
4201 Node* osr_loop_entry = graph->NewNode(builder_->common()->OsrLoopEntry(), | 4203 Node* osr_loop_entry = graph->NewNode(builder_->common()->OsrLoopEntry(), |
4202 graph->start(), graph->start()); | 4204 graph->start(), graph->start()); |
4203 UpdateControlDependency(osr_loop_entry); | 4205 UpdateControlDependency(osr_loop_entry); |
4204 UpdateEffectDependency(osr_loop_entry); | 4206 UpdateEffectDependency(osr_loop_entry); |
| 4207 |
4205 // Set OSR values. | 4208 // Set OSR values. |
4206 for (int i = 0; i < size; ++i) { | 4209 for (int i = 0; i < size; ++i) { |
4207 values()->at(i) = | 4210 values()->at(i) = |
4208 graph->NewNode(builder_->common()->OsrValue(i), osr_loop_entry); | 4211 graph->NewNode(builder_->common()->OsrValue(i), osr_loop_entry); |
4209 } | 4212 } |
4210 | 4213 |
4211 // Set the contexts. | 4214 // Set the innermost context. |
| 4215 const Operator* op_inner = |
| 4216 builder_->common()->OsrValue(Linkage::kOsrContextSpillSlotIndex); |
| 4217 contexts()->back() = graph->NewNode(op_inner, osr_loop_entry); |
| 4218 |
| 4219 // Create a checkpoint. |
| 4220 Node* frame_state = Checkpoint(builder_->info()->osr_ast_id()); |
| 4221 Node* checkpoint = graph->NewNode(common()->Checkpoint(), frame_state, |
| 4222 osr_loop_entry, osr_loop_entry); |
| 4223 UpdateEffectDependency(checkpoint); |
| 4224 |
| 4225 // Create the OSR guard nodes. |
| 4226 const Operator* guard_op = |
| 4227 builder_->info()->is_deoptimization_enabled() |
| 4228 ? builder_->common()->OsrGuard(OsrGuardType::kUninitialized) |
| 4229 : builder_->common()->OsrGuard(OsrGuardType::kAny); |
| 4230 Node* effect = checkpoint; |
| 4231 for (int i = 0; i < size; ++i) { |
| 4232 values()->at(i) = effect = |
| 4233 graph->NewNode(guard_op, values()->at(i), effect, osr_loop_entry); |
| 4234 } |
| 4235 contexts()->back() = effect = |
| 4236 graph->NewNode(guard_op, contexts()->back(), effect, osr_loop_entry); |
| 4237 |
4212 // The innermost context is the OSR value, and the outer contexts are | 4238 // The innermost context is the OSR value, and the outer contexts are |
4213 // reconstructed by dynamically walking up the context chain. | 4239 // reconstructed by dynamically walking up the context chain. |
4214 Node* osr_context = nullptr; | 4240 const Operator* load_op = |
4215 const Operator* op = | |
4216 builder_->javascript()->LoadContext(0, Context::PREVIOUS_INDEX, true); | 4241 builder_->javascript()->LoadContext(0, Context::PREVIOUS_INDEX, true); |
4217 const Operator* op_inner = | 4242 Node* osr_context = effect = contexts()->back(); |
4218 builder_->common()->OsrValue(Linkage::kOsrContextSpillSlotIndex); | |
4219 int last = static_cast<int>(contexts()->size() - 1); | 4243 int last = static_cast<int>(contexts()->size() - 1); |
4220 for (int i = last; i >= 0; i--) { | 4244 for (int i = last - 1; i >= 0; i--) { |
4221 osr_context = (i == last) ? graph->NewNode(op_inner, osr_loop_entry) | 4245 osr_context = effect = |
4222 : graph->NewNode(op, osr_context, osr_context, | 4246 graph->NewNode(load_op, osr_context, osr_context, effect); |
4223 osr_loop_entry); | |
4224 contexts()->at(i) = osr_context; | 4247 contexts()->at(i) = osr_context; |
4225 } | 4248 } |
| 4249 UpdateEffectDependency(effect); |
4226 } | 4250 } |
4227 | 4251 |
4228 void AstGraphBuilder::Environment::PrepareForLoop(BitVector* assigned) { | 4252 void AstGraphBuilder::Environment::PrepareForLoop(BitVector* assigned) { |
4229 int size = static_cast<int>(values()->size()); | 4253 int size = static_cast<int>(values()->size()); |
4230 | 4254 |
4231 Node* control = builder_->NewLoop(); | 4255 Node* control = builder_->NewLoop(); |
4232 if (assigned == nullptr) { | 4256 if (assigned == nullptr) { |
4233 // Assume that everything is updated in the loop. | 4257 // Assume that everything is updated in the loop. |
4234 for (int i = 0; i < size; ++i) { | 4258 for (int i = 0; i < size; ++i) { |
4235 values()->at(i) = builder_->NewPhi(1, values()->at(i), control); | 4259 values()->at(i) = builder_->NewPhi(1, values()->at(i), control); |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4331 // Phi does not exist yet, introduce one. | 4355 // Phi does not exist yet, introduce one. |
4332 value = NewPhi(inputs, value, control); | 4356 value = NewPhi(inputs, value, control); |
4333 value->ReplaceInput(inputs - 1, other); | 4357 value->ReplaceInput(inputs - 1, other); |
4334 } | 4358 } |
4335 return value; | 4359 return value; |
4336 } | 4360 } |
4337 | 4361 |
4338 } // namespace compiler | 4362 } // namespace compiler |
4339 } // namespace internal | 4363 } // namespace internal |
4340 } // namespace v8 | 4364 } // namespace v8 |
OLD | NEW |