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

Side by Side Diff: src/hydrogen-deoptimizing-mark.cc

Issue 19150002: Turn propagate deoptimizing mark into a proper HPhase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 5 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
(Empty)
1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 #include "hydrogen-deoptimizing-mark.h"
29
30 namespace v8 {
31 namespace internal {
32
33 void HPropagateDeoptimizingMarkPhase::MarkAsDeoptimizing() {
34 HBasicBlock* block = graph()->entry_block();
35 ZoneList<HBasicBlock*> stack(graph()->blocks()->length(), zone());
36 for (;;) {
Dmitry Lomov (no reviews) 2013/07/15 09:14:27 Can we make the terminating condition for this loo
Benedikt Meurer 2013/07/15 09:22:53 Done.
37 const ZoneList<HBasicBlock*>* dominated_blocks(block->dominated_blocks());
38 if (!dominated_blocks->is_empty()) {
39 if (block->IsDeoptimizing()) {
40 for (int i = 0; i < dominated_blocks->length(); ++i) {
41 dominated_blocks->at(i)->MarkAsDeoptimizing();
42 }
43 }
44 for (int i = dominated_blocks->length(); --i > 0; ) {
45 stack.Add(dominated_blocks->at(i), zone());
46 }
47 block = dominated_blocks->at(0);
48 } else if (stack.is_empty()) {
49 break;
50 } else {
51 block = stack.RemoveLast();
52 }
53 }
54 }
55
56
57 void HPropagateDeoptimizingMarkPhase::NullifyUnreachableInstructions() {
58 if (!FLAG_unreachable_code_elimination) return;
59 for (int i = 0; i < graph()->blocks()->length(); ++i) {
60 HBasicBlock* block = graph()->blocks()->at(i);
61 bool nullify = false;
62 const ZoneList<HBasicBlock*>* predecessors = block->predecessors();
63 int predecessors_length = predecessors->length();
64 bool all_predecessors_deoptimizing = (predecessors_length > 0);
65 for (int j = 0; j < predecessors_length; ++j) {
66 if (!predecessors->at(j)->IsDeoptimizing()) {
67 all_predecessors_deoptimizing = false;
68 break;
69 }
70 }
71 if (all_predecessors_deoptimizing) nullify = true;
72 for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
73 HInstruction* instr = it.Current();
74 // Leave the basic structure of the graph intact.
75 if (instr->IsBlockEntry()) continue;
76 if (instr->IsControlInstruction()) continue;
77 if (instr->IsSimulate()) continue;
78 if (instr->IsEnterInlined()) continue;
79 if (instr->IsLeaveInlined()) continue;
80 if (nullify) {
81 HInstruction* last_dummy = NULL;
82 for (int j = 0; j < instr->OperandCount(); ++j) {
83 HValue* operand = instr->OperandAt(j);
84 // Insert an HDummyUse for each operand, unless the operand
85 // is an HDummyUse itself. If it's even from the same block,
86 // remember it as a potential replacement for the instruction.
87 if (operand->IsDummyUse()) {
88 if (operand->block() == instr->block() &&
89 last_dummy == NULL) {
90 last_dummy = HInstruction::cast(operand);
91 }
92 continue;
93 }
94 if (operand->IsControlInstruction()) {
95 // Inserting a dummy use for a value that's not defined anywhere
96 // will fail. Some instructions define fake inputs on such
97 // values as control flow dependencies.
98 continue;
99 }
100 HDummyUse* dummy = new(graph()->zone()) HDummyUse(operand);
101 dummy->InsertBefore(instr);
102 last_dummy = dummy;
103 }
104 if (last_dummy == NULL) last_dummy = graph()->GetConstant1();
105 instr->DeleteAndReplaceWith(last_dummy);
106 continue;
107 }
108 if (instr->IsSoftDeoptimize()) {
109 ASSERT(block->IsDeoptimizing());
110 nullify = true;
111 }
112 }
113 }
114 }
115
116
117 void HPropagateDeoptimizingMarkPhase::Run() {
118 // Skip this phase if there is nothing to be done anyway.
119 if (!graph()->has_soft_deoptimize()) return;
120 MarkAsDeoptimizing();
121 NullifyUnreachableInstructions();
122 }
123
124 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698