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

Side by Side Diff: src/hydrogen-gvn.h

Issue 16095004: Extract GlobalValueNumberer and helper classes from hydrogen.cc and move to hydrogen-gvn.cc. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Introduce hydrogen-gvn.h as well. Created 7 years, 7 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.cc ('k') | src/hydrogen-gvn.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef V8_HYDROGEN_GVN_H_
29 #define V8_HYDROGEN_GVN_H_
30
31 #include "hydrogen.h"
32 #include "hydrogen-instructions.h"
33 #include "compiler.h"
34 #include "zone.h"
35
36 namespace v8 {
37 namespace internal {
38
39 // Simple sparse set with O(1) add, contains, and clear.
40 class SparseSet {
41 public:
42 SparseSet(Zone* zone, int capacity)
43 : capacity_(capacity),
44 length_(0),
45 dense_(zone->NewArray<int>(capacity)),
46 sparse_(zone->NewArray<int>(capacity)) {
47 #ifndef NVALGRIND
48 // Initialize the sparse array to make valgrind happy.
49 memset(sparse_, 0, sizeof(sparse_[0]) * capacity);
50 #endif
51 }
52
53 bool Contains(int n) const {
54 ASSERT(0 <= n && n < capacity_);
55 int d = sparse_[n];
56 return 0 <= d && d < length_ && dense_[d] == n;
57 }
58
59 bool Add(int n) {
60 if (Contains(n)) return false;
61 dense_[length_] = n;
62 sparse_[n] = length_;
63 ++length_;
64 return true;
65 }
66
67 void Clear() { length_ = 0; }
68
69 private:
70 int capacity_;
71 int length_;
72 int* dense_;
73 int* sparse_;
74
75 DISALLOW_COPY_AND_ASSIGN(SparseSet);
76 };
77
78
79 class HGlobalValueNumberer BASE_EMBEDDED {
80 public:
81 HGlobalValueNumberer(HGraph* graph, CompilationInfo* info);
82
83 // Returns true if values with side effects are removed.
84 bool Analyze();
85
86 private:
87 GVNFlagSet CollectSideEffectsOnPathsToDominatedBlock(
88 HBasicBlock* dominator,
89 HBasicBlock* dominated);
90 void AnalyzeGraph();
91 void ComputeBlockSideEffects();
92 void LoopInvariantCodeMotion();
93 void ProcessLoopBlock(HBasicBlock* block,
94 HBasicBlock* before_loop,
95 GVNFlagSet loop_kills,
96 GVNFlagSet* accumulated_first_time_depends,
97 GVNFlagSet* accumulated_first_time_changes);
98 bool AllowCodeMotion();
99 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header);
100
101 HGraph* graph() { return graph_; }
102 CompilationInfo* info() { return info_; }
103 Zone* zone() const { return graph_->zone(); }
104
105 HGraph* graph_;
106 CompilationInfo* info_;
107 bool removed_side_effects_;
108
109 // A map of block IDs to their side effects.
110 ZoneList<GVNFlagSet> block_side_effects_;
111
112 // A map of loop header block IDs to their loop's side effects.
113 ZoneList<GVNFlagSet> loop_side_effects_;
114
115 // Used when collecting side effects on paths from dominator to
116 // dominated.
117 SparseSet visited_on_paths_;
118 };
119
120
121 } } // namespace v8::internal
122
123 #endif // V8_HYDROGEN_GVN_H_
OLDNEW
« no previous file with comments | « src/hydrogen.cc ('k') | src/hydrogen-gvn.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698