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

Side by Side Diff: src/hydrogen-environment-liveness.cc

Issue 142813003: A64: Synchronize with r15358. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
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 | « src/hydrogen-environment-liveness.h ('k') | src/hydrogen-gvn.h » ('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 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 28
29 #include "hydrogen-environment-liveness.h" 29 #include "hydrogen-environment-liveness.h"
30 30
31 31
32 namespace v8 { 32 namespace v8 {
33 namespace internal { 33 namespace internal {
34 34
35 35
36 EnvironmentSlotLivenessAnalyzer::EnvironmentSlotLivenessAnalyzer( 36 HEnvironmentLivenessAnalysisPhase::HEnvironmentLivenessAnalysisPhase(
37 HGraph* graph) 37 HGraph* graph)
38 : graph_(graph), 38 : HPhase("H_Environment liveness analysis", graph),
39 zone_(graph->isolate()),
40 zone_scope_(&zone_, DELETE_ON_EXIT),
41 block_count_(graph->blocks()->length()), 39 block_count_(graph->blocks()->length()),
42 maximum_environment_size_(graph->maximum_environment_size()), 40 maximum_environment_size_(graph->maximum_environment_size()),
41 live_at_block_start_(block_count_, zone()),
42 first_simulate_(block_count_, zone()),
43 first_simulate_invalid_for_index_(block_count_, zone()),
44 markers_(maximum_environment_size_, zone()),
43 collect_markers_(true), 45 collect_markers_(true),
44 last_simulate_(NULL) { 46 last_simulate_(NULL),
45 if (maximum_environment_size_ == 0) return; 47 went_live_since_last_simulate_(maximum_environment_size_, zone()) {
46 48 ASSERT(maximum_environment_size_ > 0);
47 live_at_block_start_ =
48 new(zone()) ZoneList<BitVector*>(block_count_, zone());
49 first_simulate_ = new(zone()) ZoneList<HSimulate*>(block_count_, zone());
50 first_simulate_invalid_for_index_ =
51 new(zone()) ZoneList<BitVector*>(block_count_, zone());
52 markers_ = new(zone())
53 ZoneList<HEnvironmentMarker*>(maximum_environment_size_, zone());
54 went_live_since_last_simulate_ =
55 new(zone()) BitVector(maximum_environment_size_, zone());
56
57 for (int i = 0; i < block_count_; ++i) { 49 for (int i = 0; i < block_count_; ++i) {
58 live_at_block_start_->Add( 50 live_at_block_start_.Add(
59 new(zone()) BitVector(maximum_environment_size_, zone()), zone()); 51 new(zone()) BitVector(maximum_environment_size_, zone()), zone());
60 first_simulate_->Add(NULL, zone()); 52 first_simulate_.Add(NULL, zone());
61 first_simulate_invalid_for_index_->Add( 53 first_simulate_invalid_for_index_.Add(
62 new(zone()) BitVector(maximum_environment_size_, zone()), zone()); 54 new(zone()) BitVector(maximum_environment_size_, zone()), zone());
63 } 55 }
64 } 56 }
65 57
66 58
67 void EnvironmentSlotLivenessAnalyzer::ZapEnvironmentSlot(int index, 59 void HEnvironmentLivenessAnalysisPhase::ZapEnvironmentSlot(
68 HSimulate* simulate) { 60 int index, HSimulate* simulate) {
69 int operand_index = simulate->ToOperandIndex(index); 61 int operand_index = simulate->ToOperandIndex(index);
70 if (operand_index == -1) { 62 if (operand_index == -1) {
71 simulate->AddAssignedValue(index, graph_->GetConstantUndefined()); 63 simulate->AddAssignedValue(index, graph()->GetConstantUndefined());
72 } else { 64 } else {
73 simulate->SetOperandAt(operand_index, graph_->GetConstantUndefined()); 65 simulate->SetOperandAt(operand_index, graph()->GetConstantUndefined());
74 } 66 }
75 } 67 }
76 68
77 69
78 void EnvironmentSlotLivenessAnalyzer::ZapEnvironmentSlotsInSuccessors( 70 void HEnvironmentLivenessAnalysisPhase::ZapEnvironmentSlotsInSuccessors(
79 HBasicBlock* block, 71 HBasicBlock* block, BitVector* live) {
80 BitVector* live) {
81 // When a value is live in successor A but dead in B, we must 72 // When a value is live in successor A but dead in B, we must
82 // explicitly zap it in B. 73 // explicitly zap it in B.
83 for (HSuccessorIterator it(block->end()); !it.Done(); it.Advance()) { 74 for (HSuccessorIterator it(block->end()); !it.Done(); it.Advance()) {
84 HBasicBlock* successor = it.Current(); 75 HBasicBlock* successor = it.Current();
85 int successor_id = successor->block_id(); 76 int successor_id = successor->block_id();
86 BitVector* live_in_successor = live_at_block_start_->at(successor_id); 77 BitVector* live_in_successor = live_at_block_start_[successor_id];
87 if (live_in_successor->Equals(*live)) continue; 78 if (live_in_successor->Equals(*live)) continue;
88 for (int i = 0; i < live->length(); ++i) { 79 for (int i = 0; i < live->length(); ++i) {
89 if (!live->Contains(i)) continue; 80 if (!live->Contains(i)) continue;
90 if (live_in_successor->Contains(i)) continue; 81 if (live_in_successor->Contains(i)) continue;
91 if (first_simulate_invalid_for_index_->at(successor_id)->Contains(i)) { 82 if (first_simulate_invalid_for_index_.at(successor_id)->Contains(i)) {
92 continue; 83 continue;
93 } 84 }
94 HSimulate* simulate = first_simulate_->at(successor_id); 85 HSimulate* simulate = first_simulate_.at(successor_id);
95 if (simulate == NULL) continue; 86 if (simulate == NULL) continue;
96 ASSERT(simulate->closure().is_identical_to( 87 ASSERT(simulate->closure().is_identical_to(
97 block->last_environment()->closure())); 88 block->last_environment()->closure()));
98 ZapEnvironmentSlot(i, simulate); 89 ZapEnvironmentSlot(i, simulate);
99 } 90 }
100 } 91 }
101 } 92 }
102 93
103 94
104 void EnvironmentSlotLivenessAnalyzer::ZapEnvironmentSlotsForInstruction( 95 void HEnvironmentLivenessAnalysisPhase::ZapEnvironmentSlotsForInstruction(
105 HEnvironmentMarker* marker) { 96 HEnvironmentMarker* marker) {
106 if (!marker->CheckFlag(HValue::kEndsLiveRange)) return; 97 if (!marker->CheckFlag(HValue::kEndsLiveRange)) return;
107 HSimulate* simulate = marker->next_simulate(); 98 HSimulate* simulate = marker->next_simulate();
108 if (simulate != NULL) { 99 if (simulate != NULL) {
109 ASSERT(simulate->closure().is_identical_to(marker->closure())); 100 ASSERT(simulate->closure().is_identical_to(marker->closure()));
110 ZapEnvironmentSlot(marker->index(), simulate); 101 ZapEnvironmentSlot(marker->index(), simulate);
111 } 102 }
112 } 103 }
113 104
114 105
115 void EnvironmentSlotLivenessAnalyzer::UpdateLivenessAtBlockEnd( 106 void HEnvironmentLivenessAnalysisPhase::UpdateLivenessAtBlockEnd(
116 HBasicBlock* block, 107 HBasicBlock* block,
117 BitVector* live) { 108 BitVector* live) {
118 // Liveness at the end of each block: union of liveness in successors. 109 // Liveness at the end of each block: union of liveness in successors.
119 live->Clear(); 110 live->Clear();
120 for (HSuccessorIterator it(block->end()); !it.Done(); it.Advance()) { 111 for (HSuccessorIterator it(block->end()); !it.Done(); it.Advance()) {
121 live->Union(*live_at_block_start_->at(it.Current()->block_id())); 112 live->Union(*live_at_block_start_[it.Current()->block_id()]);
122 } 113 }
123 } 114 }
124 115
125 116
126 void EnvironmentSlotLivenessAnalyzer::UpdateLivenessAtInstruction( 117 void HEnvironmentLivenessAnalysisPhase::UpdateLivenessAtInstruction(
127 HInstruction* instr, 118 HInstruction* instr,
128 BitVector* live) { 119 BitVector* live) {
129 switch (instr->opcode()) { 120 switch (instr->opcode()) {
130 case HValue::kEnvironmentMarker: { 121 case HValue::kEnvironmentMarker: {
131 HEnvironmentMarker* marker = HEnvironmentMarker::cast(instr); 122 HEnvironmentMarker* marker = HEnvironmentMarker::cast(instr);
132 int index = marker->index(); 123 int index = marker->index();
133 if (!live->Contains(index)) { 124 if (!live->Contains(index)) {
134 marker->SetFlag(HValue::kEndsLiveRange); 125 marker->SetFlag(HValue::kEndsLiveRange);
135 } else { 126 } else {
136 marker->ClearFlag(HValue::kEndsLiveRange); 127 marker->ClearFlag(HValue::kEndsLiveRange);
137 } 128 }
138 if (!went_live_since_last_simulate_->Contains(index)) { 129 if (!went_live_since_last_simulate_.Contains(index)) {
139 marker->set_next_simulate(last_simulate_); 130 marker->set_next_simulate(last_simulate_);
140 } 131 }
141 if (marker->kind() == HEnvironmentMarker::LOOKUP) { 132 if (marker->kind() == HEnvironmentMarker::LOOKUP) {
142 live->Add(index); 133 live->Add(index);
143 } else { 134 } else {
144 ASSERT(marker->kind() == HEnvironmentMarker::BIND); 135 ASSERT(marker->kind() == HEnvironmentMarker::BIND);
145 live->Remove(index); 136 live->Remove(index);
146 went_live_since_last_simulate_->Add(index); 137 went_live_since_last_simulate_.Add(index);
147 } 138 }
148 if (collect_markers_) { 139 if (collect_markers_) {
149 // Populate |markers_| list during the first pass. 140 // Populate |markers_| list during the first pass.
150 markers_->Add(marker, &zone_); 141 markers_.Add(marker, zone());
151 } 142 }
152 break; 143 break;
153 } 144 }
154 case HValue::kLeaveInlined: 145 case HValue::kLeaveInlined:
155 // No environment values are live at the end of an inlined section. 146 // No environment values are live at the end of an inlined section.
156 live->Clear(); 147 live->Clear();
157 last_simulate_ = NULL; 148 last_simulate_ = NULL;
158 149
159 // The following ASSERTs guard the assumption used in case 150 // The following ASSERTs guard the assumption used in case
160 // kEnterInlined below: 151 // kEnterInlined below:
161 ASSERT(instr->next()->IsSimulate()); 152 ASSERT(instr->next()->IsSimulate());
162 ASSERT(instr->next()->next()->IsGoto()); 153 ASSERT(instr->next()->next()->IsGoto());
163 154
164 break; 155 break;
165 case HValue::kEnterInlined: { 156 case HValue::kEnterInlined: {
166 // Those environment values are live that are live at any return 157 // Those environment values are live that are live at any return
167 // target block. Here we make use of the fact that the end of an 158 // target block. Here we make use of the fact that the end of an
168 // inline sequence always looks like this: HLeaveInlined, HSimulate, 159 // inline sequence always looks like this: HLeaveInlined, HSimulate,
169 // HGoto (to return_target block), with no environment lookups in 160 // HGoto (to return_target block), with no environment lookups in
170 // between (see ASSERTs above). 161 // between (see ASSERTs above).
171 HEnterInlined* enter = HEnterInlined::cast(instr); 162 HEnterInlined* enter = HEnterInlined::cast(instr);
172 live->Clear(); 163 live->Clear();
173 for (int i = 0; i < enter->return_targets()->length(); ++i) { 164 for (int i = 0; i < enter->return_targets()->length(); ++i) {
174 int return_id = enter->return_targets()->at(i)->block_id(); 165 int return_id = enter->return_targets()->at(i)->block_id();
175 // When an AbnormalExit is involved, it can happen that the return 166 // When an AbnormalExit is involved, it can happen that the return
176 // target block doesn't actually exist. 167 // target block doesn't actually exist.
177 if (return_id < live_at_block_start_->length()) { 168 if (return_id < live_at_block_start_.length()) {
178 live->Union(*live_at_block_start_->at(return_id)); 169 live->Union(*live_at_block_start_[return_id]);
179 } 170 }
180 } 171 }
181 last_simulate_ = NULL; 172 last_simulate_ = NULL;
182 break; 173 break;
183 } 174 }
184 case HValue::kDeoptimize: { 175 case HValue::kDeoptimize: {
185 // Keep all environment slots alive. 176 // Keep all environment slots alive.
186 HDeoptimize* deopt = HDeoptimize::cast(instr); 177 HDeoptimize* deopt = HDeoptimize::cast(instr);
187 for (int i = deopt->first_local_index(); 178 for (int i = deopt->first_local_index();
188 i < deopt->first_expression_index(); ++i) { 179 i < deopt->first_expression_index(); ++i) {
189 live->Add(i); 180 live->Add(i);
190 } 181 }
191 break; 182 break;
192 } 183 }
193 case HValue::kSimulate: 184 case HValue::kSimulate:
194 last_simulate_ = HSimulate::cast(instr); 185 last_simulate_ = HSimulate::cast(instr);
195 went_live_since_last_simulate_->Clear(); 186 went_live_since_last_simulate_.Clear();
196 break; 187 break;
197 default: 188 default:
198 break; 189 break;
199 } 190 }
200 } 191 }
201 192
202 193
203 void EnvironmentSlotLivenessAnalyzer::AnalyzeAndTrim() { 194 void HEnvironmentLivenessAnalysisPhase::Run() {
204 HPhase phase("H_EnvironmentLivenessAnalysis", graph_); 195 ASSERT(maximum_environment_size_ > 0);
205 if (maximum_environment_size_ == 0) return;
206 196
207 // Main iteration. Compute liveness of environment slots, and store it 197 // Main iteration. Compute liveness of environment slots, and store it
208 // for each block until it doesn't change any more. For efficiency, visit 198 // for each block until it doesn't change any more. For efficiency, visit
209 // blocks in reverse order and walk backwards through each block. We 199 // blocks in reverse order and walk backwards through each block. We
210 // need several iterations to propagate liveness through nested loops. 200 // need several iterations to propagate liveness through nested loops.
211 BitVector* live = new(zone()) BitVector(maximum_environment_size_, zone()); 201 BitVector live(maximum_environment_size_, zone());
212 BitVector* worklist = new(zone()) BitVector(block_count_, zone()); 202 BitVector worklist(block_count_, zone());
213 for (int i = 0; i < block_count_; ++i) { 203 for (int i = 0; i < block_count_; ++i) {
214 worklist->Add(i); 204 worklist.Add(i);
215 } 205 }
216 while (!worklist->IsEmpty()) { 206 while (!worklist.IsEmpty()) {
217 for (int block_id = block_count_ - 1; block_id >= 0; --block_id) { 207 for (int block_id = block_count_ - 1; block_id >= 0; --block_id) {
218 if (!worklist->Contains(block_id)) { 208 if (!worklist.Contains(block_id)) {
219 continue; 209 continue;
220 } 210 }
221 worklist->Remove(block_id); 211 worklist.Remove(block_id);
222 last_simulate_ = NULL; 212 last_simulate_ = NULL;
223 213
224 HBasicBlock* block = graph_->blocks()->at(block_id); 214 HBasicBlock* block = graph()->blocks()->at(block_id);
225 UpdateLivenessAtBlockEnd(block, live); 215 UpdateLivenessAtBlockEnd(block, &live);
226 216
227 for (HInstruction* instr = block->last(); instr != NULL; 217 for (HInstruction* instr = block->last(); instr != NULL;
228 instr = instr->previous()) { 218 instr = instr->previous()) {
229 UpdateLivenessAtInstruction(instr, live); 219 UpdateLivenessAtInstruction(instr, &live);
230 } 220 }
231 221
232 // Reached the start of the block, do necessary bookkeeping: 222 // Reached the start of the block, do necessary bookkeeping:
233 // store computed information for this block and add predecessors 223 // store computed information for this block and add predecessors
234 // to the work list as necessary. 224 // to the work list as necessary.
235 first_simulate_->Set(block_id, last_simulate_); 225 first_simulate_.Set(block_id, last_simulate_);
236 first_simulate_invalid_for_index_->at(block_id)->CopyFrom( 226 first_simulate_invalid_for_index_[block_id]->CopyFrom(
237 *went_live_since_last_simulate_); 227 went_live_since_last_simulate_);
238 if (live_at_block_start_->at(block_id)->UnionIsChanged(*live)) { 228 if (live_at_block_start_[block_id]->UnionIsChanged(live)) {
239 for (int i = 0; i < block->predecessors()->length(); ++i) { 229 for (int i = 0; i < block->predecessors()->length(); ++i) {
240 worklist->Add(block->predecessors()->at(i)->block_id()); 230 worklist.Add(block->predecessors()->at(i)->block_id());
241 } 231 }
242 if (block->IsInlineReturnTarget()) { 232 if (block->IsInlineReturnTarget()) {
243 worklist->Add(block->inlined_entry_block()->block_id()); 233 worklist.Add(block->inlined_entry_block()->block_id());
244 } 234 }
245 } 235 }
246 } 236 }
247 // Only collect bind/lookup instructions during the first pass. 237 // Only collect bind/lookup instructions during the first pass.
248 collect_markers_ = false; 238 collect_markers_ = false;
249 } 239 }
250 240
251 // Analysis finished. Zap dead environment slots. 241 // Analysis finished. Zap dead environment slots.
252 for (int i = 0; i < markers_->length(); ++i) { 242 for (int i = 0; i < markers_.length(); ++i) {
253 ZapEnvironmentSlotsForInstruction(markers_->at(i)); 243 ZapEnvironmentSlotsForInstruction(markers_[i]);
254 } 244 }
255 for (int block_id = block_count_ - 1; block_id >= 0; --block_id) { 245 for (int block_id = block_count_ - 1; block_id >= 0; --block_id) {
256 HBasicBlock* block = graph_->blocks()->at(block_id); 246 HBasicBlock* block = graph()->blocks()->at(block_id);
257 UpdateLivenessAtBlockEnd(block, live); 247 UpdateLivenessAtBlockEnd(block, &live);
258 ZapEnvironmentSlotsInSuccessors(block, live); 248 ZapEnvironmentSlotsInSuccessors(block, &live);
259 } 249 }
260 250
261 // Finally, remove the HEnvironment{Bind,Lookup} markers. 251 // Finally, remove the HEnvironment{Bind,Lookup} markers.
262 for (int i = 0; i < markers_->length(); ++i) { 252 for (int i = 0; i < markers_.length(); ++i) {
263 markers_->at(i)->DeleteAndReplaceWith(NULL); 253 markers_[i]->DeleteAndReplaceWith(NULL);
264 } 254 }
265 } 255 }
266 256
267 } } // namespace v8::internal 257 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/hydrogen-environment-liveness.h ('k') | src/hydrogen-gvn.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698