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

Side by Side Diff: vm/flow_graph_allocator.cc

Issue 10796108: Add a backward instruction iterator and use it in the liveness analysis. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 4 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
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_allocator.h" 5 #include "vm/flow_graph_allocator.h"
6 6
7 #include "vm/bit_vector.h" 7 #include "vm/bit_vector.h"
8 #include "vm/intermediate_language.h" 8 #include "vm/intermediate_language.h"
9 #include "vm/il_printer.h" 9 #include "vm/il_printer.h"
10 #include "vm/flow_graph_builder.h" 10 #include "vm/flow_graph_builder.h"
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 61
62 62
63 void FlowGraphAllocator::ComputeInitialSets() { 63 void FlowGraphAllocator::ComputeInitialSets() {
64 const intptr_t block_count = postorder_.length(); 64 const intptr_t block_count = postorder_.length();
65 for (intptr_t i = 0; i < block_count; i++) { 65 for (intptr_t i = 0; i < block_count; i++) {
66 BlockEntryInstr* block = postorder_[i]; 66 BlockEntryInstr* block = postorder_[i];
67 67
68 BitVector* kill = kill_[i]; 68 BitVector* kill = kill_[i];
69 BitVector* live_in = live_in_[i]; 69 BitVector* live_in = live_in_[i];
70 70
71 if (block->IsJoinEntry()) { 71 // Iterate backwards.
srdjan 2012/07/24 15:49:30 Add:, starting with the last instruction of block.
Florian Schneider 2012/07/25 08:31:29 Done.
72 JoinEntryInstr* join = block->AsJoinEntry(); 72 for (BackwardInstructionIterator it(block); !it.Done(); it.Advance()) {
73 if (join->phis() != NULL) { 73 Instruction* current = it.Current();
74 for (intptr_t j = 0; j < join->phis()->length(); j++) {
75 PhiInstr* phi = (*join->phis())[j];
76 if (phi == NULL) continue;
77 kill->Add(phi->ssa_temp_index());
78 74
79 for (intptr_t k = 0; k < phi->InputCount(); k++) { 75 // Handle definitions.
80 Value* val = phi->InputAt(k); 76 Definition* current_def = current->AsDefinition();
81 if (val->IsUse()) { 77 if ((current_def != NULL) && (current_def->ssa_temp_index() >= 0)) {
srdjan 2012/07/24 17:41:44 current_def->HasSSATemp()
Florian Schneider 2012/07/25 08:31:29 Done.
82 BlockEntryInstr* pred = block->PredecessorAt(k); 78 kill->Add(current_def->ssa_temp_index());
83 const intptr_t use = val->AsUse()->definition()->ssa_temp_index(); 79 live_in->Remove(current_def->ssa_temp_index());
84 live_out_[pred->postorder_number()]->Add(use);
85 }
86 }
87 }
88 } 80 }
89 }
90 81
91 // TODO(vegorov): iterate backwards. 82 // Handle uses.
92 for (ForwardInstructionIterator it(block); !it.Done(); it.Advance()) {
93 Instruction* current = it.Current();
94 for (intptr_t j = 0; j < current->InputCount(); j++) { 83 for (intptr_t j = 0; j < current->InputCount(); j++) {
95 Value* input = current->InputAt(j); 84 Value* input = current->InputAt(j);
96 if (input->IsUse()) { 85 if (input->IsUse()) {
97 const intptr_t use = input->AsUse()->definition()->ssa_temp_index(); 86 const intptr_t use = input->AsUse()->definition()->ssa_temp_index();
98 if (!kill->Contains(use)) live_in->Add(use); 87 live_in->Add(use);
99 } 88 }
100 } 89 }
101 90
102 // Add uses from the deoptimization environment. 91 // Add uses from the deoptimization environment.
103 if (current->env() != NULL) { 92 if (current->env() != NULL) {
104 const GrowableArray<Value*>& values = current->env()->values(); 93 const GrowableArray<Value*>& values = current->env()->values();
105 for (intptr_t j = 0; j < values.length(); j++) { 94 for (intptr_t j = 0; j < values.length(); j++) {
106 Value* val = values[j]; 95 Value* val = values[j];
107 if (val->IsUse()) { 96 if (val->IsUse()) {
108 const intptr_t use = val->AsUse()->definition()->ssa_temp_index(); 97 const intptr_t use = val->AsUse()->definition()->ssa_temp_index();
109 if (!kill->Contains(use)) live_in->Add(use); 98 live_in->Add(use);
110 } 99 }
111 } 100 }
112 } 101 }
102 }
113 103
114 Definition* current_def = current->AsDefinition(); 104 // Handle phis.
115 if ((current_def != NULL) && (current_def->ssa_temp_index() >= 0)) { 105 if (block->IsJoinEntry()) {
116 kill->Add(current_def->ssa_temp_index()); 106 JoinEntryInstr* join = block->AsJoinEntry();
107 if (join->phis() != NULL) {
108 for (intptr_t j = 0; j < join->phis()->length(); j++) {
109 PhiInstr* phi = (*join->phis())[j];
110 if (phi == NULL) continue;
111 kill->Add(phi->ssa_temp_index());
112 live_in->Remove(phi->ssa_temp_index());
113
114 for (intptr_t k = 0; k < phi->InputCount(); k++) {
115 Value* val = phi->InputAt(k);
116 if (val->IsUse()) {
117 BlockEntryInstr* pred = block->PredecessorAt(k);
118 const intptr_t use = val->AsUse()->definition()->ssa_temp_index();
119 live_out_[pred->postorder_number()]->Add(use);
120 }
121 }
122 }
117 } 123 }
118 } 124 }
119 } 125 }
120 126
121 // Update initial live_in sets to match live_out sets. Has to be 127 // Update initial live_in sets to match live_out sets. Has to be
122 // done in a separate path because of backwards branches. 128 // done in a separate path because of backwards branches.
123 for (intptr_t i = 0; i < block_count; i++) { 129 for (intptr_t i = 0; i < block_count; i++) {
124 UpdateLiveIn(*postorder_[i]); 130 UpdateLiveIn(*postorder_[i]);
125 } 131 }
126 } 132 }
(...skipping 821 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 954
949 if (FLAG_trace_ssa_allocator) { 955 if (FLAG_trace_ssa_allocator) {
950 OS::Print("-- ir after allocation -------------------------\n"); 956 OS::Print("-- ir after allocation -------------------------\n");
951 FlowGraphPrinter printer(Function::Handle(), block_order_, true); 957 FlowGraphPrinter printer(Function::Handle(), block_order_, true);
952 printer.PrintBlocks(); 958 printer.PrintBlocks();
953 } 959 }
954 } 960 }
955 961
956 962
957 } // namespace dart 963 } // namespace dart
OLDNEW
« no previous file with comments | « vm/bit_vector_test.cc ('k') | vm/intermediate_language.h » ('j') | vm/intermediate_language.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698