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

Side by Side Diff: src/hydrogen-store-elimination.cc

Issue 100253004: First implementation of store elimination. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed review comments. Created 6 years, 10 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-store-elimination.h"
29 #include "hydrogen-instructions.h"
30
31 namespace v8 {
32 namespace internal {
33
34 #define TRACE(x) if (FLAG_trace_store_elimination) PrintF x
35
36 // Performs a block-by-block local analysis for removable stores.
37 void HStoreEliminationPhase::Run() {
38 GVNFlagSet flags; // Use GVN flags as an approximation for some instructions.
39 flags.RemoveAll();
40
41 flags.Add(kDependsOnArrayElements);
42 flags.Add(kDependsOnArrayLengths);
43 flags.Add(kDependsOnStringLengths);
44 flags.Add(kDependsOnBackingStoreFields);
45 flags.Add(kDependsOnDoubleArrayElements);
46 flags.Add(kDependsOnDoubleFields);
47 flags.Add(kDependsOnElementsPointer);
48 flags.Add(kDependsOnInobjectFields);
49 flags.Add(kDependsOnExternalMemory);
50
51 for (int i = 0; i < graph()->blocks()->length(); i++) {
52 unobserved_.Rewind(0);
53 HBasicBlock* block = graph()->blocks()->at(i);
54 for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
55 HInstruction* instr = it.Current();
56
57 // TODO(titzer): eliminate unobserved HStoreKeyed instructions too.
58 switch (instr->opcode()) {
59 case HValue::kStoreNamedField:
60 // Remove any unobserved stores overwritten by this store.
61 ProcessStore(HStoreNamedField::cast(instr));
62 break;
63 case HValue::kLoadNamedField:
64 // Observe any unobserved stores on this object + field.
65 ProcessLoad(HLoadNamedField::cast(instr));
66 break;
67 default:
68 ProcessInstr(instr, flags);
69 break;
70 }
71 }
72 }
73 }
74
75
76 void HStoreEliminationPhase::ProcessStore(HStoreNamedField* store) {
77 HValue* object = store->object()->ActualValue();
78 int i = 0;
79 while (i < unobserved_.length()) {
80 HStoreNamedField* prev = unobserved_.at(i);
81 if (aliasing_->MustAlias(object, prev->object()->ActualValue()) &&
82 store->access().Equals(prev->access())) {
83 // This store is guaranteed to overwrite the previous store.
84 prev->DeleteAndReplaceWith(NULL);
85 TRACE(("++ Unobserved store S%d overwritten by S%d\n",
86 prev->id(), store->id()));
87 unobserved_.Remove(i);
88 } else {
89 // TODO(titzer): remove map word clearing from folded allocations.
90 i++;
91 }
92 }
93 // Only non-transitioning stores are removable.
94 if (!store->has_transition()) {
95 TRACE(("-- Might remove store S%d\n", store->id()));
96 unobserved_.Add(store, zone());
97 }
98 }
99
100
101 void HStoreEliminationPhase::ProcessLoad(HLoadNamedField* load) {
102 HValue* object = load->object()->ActualValue();
103 int i = 0;
104 while (i < unobserved_.length()) {
105 HStoreNamedField* prev = unobserved_.at(i);
106 if (aliasing_->MayAlias(object, prev->object()->ActualValue()) &&
107 load->access().Equals(prev->access())) {
108 TRACE(("-- Observed store S%d by load L%d\n", prev->id(), load->id()));
109 unobserved_.Remove(i);
110 } else {
111 i++;
112 }
113 }
114 }
115
116
117 void HStoreEliminationPhase::ProcessInstr(HInstruction* instr,
118 GVNFlagSet flags) {
119 if (unobserved_.length() == 0) return; // Nothing to do.
120 if (instr->CanDeoptimize()) {
121 TRACE(("-- Observed stores at I%d (might deoptimize)\n", instr->id()));
122 unobserved_.Rewind(0);
123 return;
124 }
125 if (instr->CheckGVNFlag(kChangesNewSpacePromotion)) {
126 TRACE(("-- Observed stores at I%d (might GC)\n", instr->id()));
127 unobserved_.Rewind(0);
128 return;
129 }
130 if (instr->gvn_flags().ContainsAnyOf(flags)) {
131 TRACE(("-- Observed stores at I%d (GVN flags)\n", instr->id()));
132 unobserved_.Rewind(0);
133 return;
134 }
135 }
136
137 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698