Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(989)

Side by Side Diff: runtime/vm/flow_graph.cc

Issue 141163009: Revert r31601 (Use constants from the frame at OSR entry...). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/flow_graph.h ('k') | runtime/vm/flow_graph_allocator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/flow_graph.h" 5 #include "vm/flow_graph.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/flow_graph_builder.h" 8 #include "vm/flow_graph_builder.h"
9 #include "vm/growable_array.h"
10 #include "vm/intermediate_language.h" 9 #include "vm/intermediate_language.h"
11 #include "vm/longjump.h" 10 #include "vm/longjump.h"
12 #include "vm/stack_frame.h" 11 #include "vm/growable_array.h"
13 12
14 namespace dart { 13 namespace dart {
15 14
16 DECLARE_FLAG(bool, reorder_basic_blocks); 15 DECLARE_FLAG(bool, reorder_basic_blocks);
17 DECLARE_FLAG(bool, trace_optimization); 16 DECLARE_FLAG(bool, trace_optimization);
18 DECLARE_FLAG(bool, verify_compiler); 17 DECLARE_FLAG(bool, verify_compiler);
19 DEFINE_FLAG(bool, optimize_try_catch, true, "Optimization of try-catch"); 18 DEFINE_FLAG(bool, optimize_try_catch, true, "Optimization of try-catch");
20 19
21 20
22 FlowGraph::FlowGraph(const FlowGraphBuilder& builder, 21 FlowGraph::FlowGraph(const FlowGraphBuilder& builder,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 70
72 GrowableArray<BlockEntryInstr*>* FlowGraph::CodegenBlockOrder( 71 GrowableArray<BlockEntryInstr*>* FlowGraph::CodegenBlockOrder(
73 bool is_optimized) { 72 bool is_optimized) {
74 return ShouldReorderBlocks(parsed_function().function(), is_optimized) 73 return ShouldReorderBlocks(parsed_function().function(), is_optimized)
75 ? &optimized_block_order_ 74 ? &optimized_block_order_
76 : &reverse_postorder_; 75 : &reverse_postorder_;
77 } 76 }
78 77
79 78
80 ConstantInstr* FlowGraph::GetConstant(const Object& object) { 79 ConstantInstr* FlowGraph::GetConstant(const Object& object) {
81 // Not all objects can be embedded in code.
82 ASSERT(object.IsSmi() || object.InVMHeap() || object.IsOld());
83 // Check if the constant is already in the pool. 80 // Check if the constant is already in the pool.
84 GrowableArray<Definition*>* pool = graph_entry_->initial_definitions(); 81 GrowableArray<Definition*>* pool = graph_entry_->initial_definitions();
85 for (intptr_t i = 0; i < pool->length(); ++i) { 82 for (intptr_t i = 0; i < pool->length(); ++i) {
86 ConstantInstr* constant = (*pool)[i]->AsConstant(); 83 ConstantInstr* constant = (*pool)[i]->AsConstant();
87 if ((constant != NULL) && (constant->value().raw() == object.raw())) { 84 if ((constant != NULL) && (constant->value().raw() == object.raw())) {
88 return constant; 85 return constant;
89 } 86 }
90 } 87 }
91 // Otherwise, allocate and add it to the pool. 88 // Otherwise, allocate and add it to the pool.
92 ConstantInstr* constant = new ConstantInstr(object); 89 ConstantInstr* constant = new ConstantInstr(object);
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after
691 work[index] = var_index; 688 work[index] = var_index;
692 worklist.Add(block); 689 worklist.Add(block);
693 } 690 }
694 } 691 }
695 } 692 }
696 } 693 }
697 } 694 }
698 } 695 }
699 696
700 697
701 void FlowGraph::InitializeOsrLocalRange(GrowableArray<Definition*>* env,
702 RawObject** base,
703 intptr_t count) {
704 for (intptr_t i = 0; i < count; ++i) {
705 // Variables go from high to low addresses as they go from left to
706 // right.
707 const Object& value = Object::ZoneHandle(base[-i]);
708 Definition* definition = NULL;
709 if (value.IsSmi() || value.InVMHeap() || value.IsOld()) {
710 definition = GetConstant(value);
711 } else {
712 definition = new ParameterInstr(env->length(), graph_entry());
713 definition->set_ssa_temp_index(alloc_ssa_temp_index());
714 AddToInitialDefinitions(definition);
715 }
716 env->Add(definition);
717 }
718 }
719
720
721 void FlowGraph::InitializeOsrLocals(GrowableArray<Definition*>* env) {
722 DartFrameIterator iterator;
723 StackFrame* frame = iterator.NextFrame();
724 const Code& code = Code::Handle(frame->LookupDartCode());
725 ASSERT(!code.is_optimized());
726 ASSERT(frame->LookupDartFunction() == parsed_function().function().raw());
727
728 // Initialize parameters and locals in the order they appear in the
729 // environment (left-to-right, parameters first).
730 intptr_t count = num_non_copied_params();
731 RawObject** base = reinterpret_cast<RawObject**>(frame->fp())
732 + kParamEndSlotFromFp // One past the last parameter.
733 + count;
734 InitializeOsrLocalRange(env, base, count);
735
736 count = num_copied_params() + num_stack_locals();
737 base = reinterpret_cast<RawObject**>(frame->fp()) + kFirstLocalSlotFromFp;
738 InitializeOsrLocalRange(env, base, count);
739 }
740
741
742 void FlowGraph::Rename(GrowableArray<PhiInstr*>* live_phis, 698 void FlowGraph::Rename(GrowableArray<PhiInstr*>* live_phis,
743 VariableLivenessAnalysis* variable_liveness, 699 VariableLivenessAnalysis* variable_liveness,
744 ZoneGrowableArray<Definition*>* inlining_parameters) { 700 ZoneGrowableArray<Definition*>* inlining_parameters) {
745 GraphEntryInstr* entry = graph_entry(); 701 GraphEntryInstr* entry = graph_entry();
746 if (!FLAG_optimize_try_catch && (entry->SuccessorCount() > 1)) { 702 if (!FLAG_optimize_try_catch && (entry->SuccessorCount() > 1)) {
747 Bailout("Catch-entry support in SSA."); 703 Bailout("Catch-entry support in SSA.");
748 } 704 }
749 705
750 // Initial renaming environment. 706 // Initial renaming environment.
751 GrowableArray<Definition*> env(variable_count()); 707 GrowableArray<Definition*> env(variable_count());
752 708
753 // Add global constants to the initial definitions. 709 // Add global constants to the initial definitions.
754 constant_null_ = GetConstant(Object::ZoneHandle()); 710 constant_null_ = GetConstant(Object::ZoneHandle());
755 constant_dead_ = GetConstant(Symbols::OptimizedOut()); 711 constant_dead_ = GetConstant(Symbols::OptimizedOut());
756 712
757 // Add parameters to the initial definitions and renaming environment. 713 // Add parameters to the initial definitions and renaming environment.
758 if (inlining_parameters != NULL) { 714 if (inlining_parameters != NULL) {
759 // When inlining, use the known parameter definitions. 715 // Use known parameters.
760 ASSERT(parameter_count() == inlining_parameters->length()); 716 ASSERT(parameter_count() == inlining_parameters->length());
761 for (intptr_t i = 0; i < parameter_count(); ++i) { 717 for (intptr_t i = 0; i < parameter_count(); ++i) {
762 Definition* defn = (*inlining_parameters)[i]; 718 Definition* defn = (*inlining_parameters)[i];
763 defn->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. 719 defn->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp.
764 AddToInitialDefinitions(defn); 720 AddToInitialDefinitions(defn);
765 env.Add(defn); 721 env.Add(defn);
766 } 722 }
767 } else if (IsCompiledForOsr()) {
768 // For functions compiled for OSR, use the constants found in the
769 // unoptimized frame.
770 InitializeOsrLocals(&env);
771 } else { 723 } else {
772 // Create fresh (unknown) parameters. 724 // Create new parameters. For functions compiled for OSR, the locals
773 for (intptr_t i = 0; i < parameter_count(); ++i) { 725 // are unknown and so treated like parameters.
726 intptr_t count = IsCompiledForOsr() ? variable_count() : parameter_count();
727 for (intptr_t i = 0; i < count; ++i) {
774 ParameterInstr* param = new ParameterInstr(i, entry); 728 ParameterInstr* param = new ParameterInstr(i, entry);
775 param->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp. 729 param->set_ssa_temp_index(alloc_ssa_temp_index()); // New SSA temp.
776 AddToInitialDefinitions(param); 730 AddToInitialDefinitions(param);
777 env.Add(param); 731 env.Add(param);
778 } 732 }
779 } 733 }
780 734
781 // Initialize all locals with #null in the renaming environment. For OSR, 735 // Initialize all locals with #null in the renaming environment. For OSR,
782 // the locals have already been handled as parameters. 736 // the locals have already been handled as parameters.
783 if (!IsCompiledForOsr()) { 737 if (!IsCompiledForOsr()) {
784 for (intptr_t i = parameter_count(); i < variable_count(); ++i) { 738 for (intptr_t i = parameter_count(); i < variable_count(); ++i) {
785 env.Add(constant_null()); 739 env.Add(constant_null());
786 } 740 }
787 } 741 }
788 742
743 if (entry->SuccessorCount() > 1) {
744 // Functions with try-catch have a fixed area of stack slots reserved
745 // so that all local variables are stored at a known location when
746 // on entry to the catch.
747 entry->set_fixed_slot_count(num_stack_locals() + num_copied_params());
748 }
789 RenameRecursive(entry, &env, live_phis, variable_liveness); 749 RenameRecursive(entry, &env, live_phis, variable_liveness);
790 } 750 }
791 751
792 752
793 void FlowGraph::AttachEnvironment(Instruction* instr, 753 void FlowGraph::AttachEnvironment(Instruction* instr,
794 GrowableArray<Definition*>* env) { 754 GrowableArray<Definition*>* env) {
795 Environment* deopt_env = 755 Environment* deopt_env =
796 Environment::From(*env, 756 Environment::From(*env,
797 num_non_copied_params_, 757 num_non_copied_params_,
798 Code::Handle(parsed_function_.code())); 758 Code::Handle(parsed_function_.code()));
(...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after
1238 } 1198 }
1239 1199
1240 1200
1241 bool BlockEffects::IsSideEffectFreePath(BlockEntryInstr* from, 1201 bool BlockEffects::IsSideEffectFreePath(BlockEntryInstr* from,
1242 BlockEntryInstr* to) const { 1202 BlockEntryInstr* to) const {
1243 return available_at_[to->postorder_number()]->Contains( 1203 return available_at_[to->postorder_number()]->Contains(
1244 from->postorder_number()); 1204 from->postorder_number());
1245 } 1205 }
1246 1206
1247 } // namespace dart 1207 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/flow_graph.h ('k') | runtime/vm/flow_graph_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698