38 :
HPhase(
"H_Environment liveness analysis", graph),
39 block_count_(graph->blocks()->length()),
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()),
45 collect_markers_(
true),
47 went_live_since_last_simulate_(maximum_environment_size_, zone()) {
48 ASSERT(maximum_environment_size_ > 0);
49 for (
int i = 0; i < block_count_; ++i) {
50 live_at_block_start_.Add(
51 new(zone())
BitVector(maximum_environment_size_, zone()), zone());
52 first_simulate_.
Add(
NULL, zone());
53 first_simulate_invalid_for_index_.Add(
54 new(zone())
BitVector(maximum_environment_size_, zone()), zone());
59 void HEnvironmentLivenessAnalysisPhase::ZapEnvironmentSlot(
60 int index, HSimulate* simulate) {
61 int operand_index = simulate->ToOperandIndex(index);
62 if (operand_index == -1) {
63 simulate->AddAssignedValue(index,
graph()->GetConstantUndefined());
65 simulate->SetOperandAt(operand_index,
graph()->GetConstantUndefined());
70 void HEnvironmentLivenessAnalysisPhase::ZapEnvironmentSlotsInSuccessors(
71 HBasicBlock* block, BitVector* live) {
74 for (HSuccessorIterator it(block->end()); !it.Done(); it.Advance()) {
75 HBasicBlock* successor = it.Current();
76 int successor_id = successor->block_id();
77 BitVector* live_in_successor = live_at_block_start_[successor_id];
78 if (live_in_successor->Equals(*live))
continue;
79 for (
int i = 0; i < live->length(); ++i) {
80 if (!live->Contains(i))
continue;
81 if (live_in_successor->Contains(i))
continue;
82 if (first_simulate_invalid_for_index_.at(successor_id)->Contains(i)) {
85 HSimulate* simulate = first_simulate_.
at(successor_id);
86 if (simulate ==
NULL)
continue;
87 ASSERT(simulate->closure().is_identical_to(
88 block->last_environment()->closure()));
89 ZapEnvironmentSlot(i, simulate);
95 void HEnvironmentLivenessAnalysisPhase::ZapEnvironmentSlotsForInstruction(
96 HEnvironmentMarker* marker) {
98 HSimulate* simulate = marker->next_simulate();
99 if (simulate !=
NULL) {
100 ASSERT(simulate->closure().is_identical_to(marker->closure()));
101 ZapEnvironmentSlot(marker->index(), simulate);
106 void HEnvironmentLivenessAnalysisPhase::UpdateLivenessAtBlockEnd(
111 for (HSuccessorIterator it(block->end()); !it.Done(); it.Advance()) {
112 live->Union(*live_at_block_start_[it.Current()->block_id()]);
117 void HEnvironmentLivenessAnalysisPhase::UpdateLivenessAtInstruction(
120 switch (instr->opcode()) {
121 case HValue::kEnvironmentMarker: {
122 HEnvironmentMarker* marker = HEnvironmentMarker::cast(instr);
123 int index = marker->index();
124 if (!live->Contains(index)) {
129 if (!went_live_since_last_simulate_.
Contains(index)) {
130 marker->set_next_simulate(last_simulate_);
132 if (marker->kind() == HEnvironmentMarker::LOOKUP) {
135 ASSERT(marker->kind() == HEnvironmentMarker::BIND);
137 went_live_since_last_simulate_.
Add(index);
139 if (collect_markers_) {
141 markers_.
Add(marker, zone());
145 case HValue::kLeaveInlined:
148 last_simulate_ =
NULL;
152 ASSERT(instr->next()->IsSimulate());
153 ASSERT(instr->next()->next()->IsGoto());
156 case HValue::kEnterInlined: {
162 HEnterInlined* enter = HEnterInlined::cast(instr);
164 for (
int i = 0; i < enter->return_targets()->length(); ++i) {
165 int return_id = enter->return_targets()->at(i)->block_id();
166 live->Union(*live_at_block_start_[return_id]);
168 last_simulate_ =
NULL;
171 case HValue::kSimulate:
172 last_simulate_ = HSimulate::cast(instr);
173 went_live_since_last_simulate_.
Clear();
182 ASSERT(maximum_environment_size_ > 0);
188 BitVector live(maximum_environment_size_, zone());
189 BitVector worklist(block_count_, zone());
190 for (
int i = 0; i < block_count_; ++i) {
194 for (
int block_id = block_count_ - 1; block_id >= 0; --block_id) {
198 worklist.
Remove(block_id);
199 last_simulate_ =
NULL;
201 HBasicBlock* block =
graph()->blocks()->at(block_id);
202 UpdateLivenessAtBlockEnd(block, &live);
205 instr = instr->previous()) {
206 UpdateLivenessAtInstruction(instr, &live);
212 first_simulate_.
Set(block_id, last_simulate_);
213 first_simulate_invalid_for_index_[block_id]->CopyFrom(
214 went_live_since_last_simulate_);
215 if (live_at_block_start_[block_id]->UnionIsChanged(live)) {
216 for (
int i = 0; i < block->predecessors()->length(); ++i) {
217 worklist.
Add(block->predecessors()->at(i)->block_id());
219 if (block->IsInlineReturnTarget()) {
220 worklist.
Add(block->inlined_entry_block()->block_id());
225 collect_markers_ =
false;
229 for (
int i = 0; i < markers_.length(); ++i) {
230 ZapEnvironmentSlotsForInstruction(markers_[i]);
232 for (
int block_id = block_count_ - 1; block_id >= 0; --block_id) {
233 HBasicBlock* block =
graph()->blocks()->at(block_id);
234 UpdateLivenessAtBlockEnd(block, &live);
235 ZapEnvironmentSlotsInSuccessors(block, &live);
239 for (
int i = 0; i < markers_.length(); ++i) {
240 markers_[i]->DeleteAndReplaceWith(
NULL);
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths tracks arrays with only smi values Optimize object Array DOM strings and string pretenure call new trace pretenuring decisions of HAllocate instructions track fields with only smi values track fields with heap values track_fields track_fields Enables optimizations which favor memory size over execution speed use string slices optimization filter maximum number of GVN fix point iterations use function inlining use allocation folding eliminate write barriers targeting allocations in optimized code maximum source size in bytes considered for a single inlining maximum cumulative number of AST nodes considered for inlining crankshaft harvests type feedback from stub cache trace check elimination phase hydrogen tracing filter NULL
enable upcoming ES6 features enable harmony block scoping enable harmony enable harmony proxies enable harmony generators enable harmony numeric enable harmony string enable harmony math functions harmony_scoping harmony_symbols harmony_collections harmony_iteration harmony_strings harmony_scoping harmony_maths true
#define ASSERT(condition)
bool Contains(int i) const
void Set(int index, const T &element)
void Add(const T &element, AllocationPolicy allocator=AllocationPolicy())
HEnvironmentLivenessAnalysisPhase(HGraph *graph)