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

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

Issue 363323003: More OStreamsUse OStreams more often. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Rebased and polished. Created 6 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
« 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
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_HYDROGEN_GVN_H_ 5 #ifndef V8_HYDROGEN_GVN_H_
6 #define V8_HYDROGEN_GVN_H_ 6 #define V8_HYDROGEN_GVN_H_
7 7
8 #include "src/compiler.h"
8 #include "src/hydrogen.h" 9 #include "src/hydrogen.h"
9 #include "src/hydrogen-instructions.h" 10 #include "src/hydrogen-instructions.h"
10 #include "src/compiler.h" 11 #include "src/ostreams.h"
11 #include "src/zone.h" 12 #include "src/zone.h"
12 13
13 namespace v8 { 14 namespace v8 {
14 namespace internal { 15 namespace internal {
15 16
16 // This class extends GVNFlagSet with additional "special" dynamic side effects, 17 // This class extends GVNFlagSet with additional "special" dynamic side effects,
17 // which can be used to represent side effects that cannot be expressed using 18 // which can be used to represent side effects that cannot be expressed using
18 // the GVNFlags of an HInstruction. These special side effects are tracked by a 19 // the GVNFlags of an HInstruction. These special side effects are tracked by a
19 // SideEffectsTracker (see below). 20 // SideEffectsTracker (see below).
20 class SideEffects V8_FINAL { 21 class SideEffects V8_FINAL {
(...skipping 10 matching lines...) Expand all
31 } 32 }
32 bool ContainsSpecial(int special) const { 33 bool ContainsSpecial(int special) const {
33 return (bits_ & MaskSpecial(special)) != 0; 34 return (bits_ & MaskSpecial(special)) != 0;
34 } 35 }
35 bool ContainsAnyOf(SideEffects set) const { return (bits_ & set.bits_) != 0; } 36 bool ContainsAnyOf(SideEffects set) const { return (bits_ & set.bits_) != 0; }
36 void Add(SideEffects set) { bits_ |= set.bits_; } 37 void Add(SideEffects set) { bits_ |= set.bits_; }
37 void AddSpecial(int special) { bits_ |= MaskSpecial(special); } 38 void AddSpecial(int special) { bits_ |= MaskSpecial(special); }
38 void RemoveFlag(GVNFlag flag) { bits_ &= ~MaskFlag(flag); } 39 void RemoveFlag(GVNFlag flag) { bits_ &= ~MaskFlag(flag); }
39 void RemoveAll() { bits_ = 0; } 40 void RemoveAll() { bits_ = 0; }
40 uint64_t ToIntegral() const { return bits_; } 41 uint64_t ToIntegral() const { return bits_; }
41 void PrintTo(StringStream* stream) const;
42 42
43 private: 43 private:
44 uint64_t MaskFlag(GVNFlag flag) const { 44 uint64_t MaskFlag(GVNFlag flag) const {
45 return static_cast<uint64_t>(1) << static_cast<unsigned>(flag); 45 return static_cast<uint64_t>(1) << static_cast<unsigned>(flag);
46 } 46 }
47 uint64_t MaskSpecial(int special) const { 47 uint64_t MaskSpecial(int special) const {
48 ASSERT(special >= 0); 48 ASSERT(special >= 0);
49 ASSERT(special < kNumberOfSpecials); 49 ASSERT(special < kNumberOfSpecials);
50 return static_cast<uint64_t>(1) << static_cast<unsigned>( 50 return static_cast<uint64_t>(1) << static_cast<unsigned>(
51 special + kNumberOfFlags); 51 special + kNumberOfFlags);
52 } 52 }
53 53
54 uint64_t bits_; 54 uint64_t bits_;
55 }; 55 };
56 56
57 57
58 class TrackedEffects;
59
58 // Tracks global variable and inobject field loads/stores in a fine grained 60 // Tracks global variable and inobject field loads/stores in a fine grained
59 // fashion, and represents them using the "special" dynamic side effects of the 61 // fashion, and represents them using the "special" dynamic side effects of the
60 // SideEffects class (see above). This way unrelated global variable/inobject 62 // SideEffects class (see above). This way unrelated global variable/inobject
61 // field stores don't prevent hoisting and merging of global variable/inobject 63 // field stores don't prevent hoisting and merging of global variable/inobject
62 // field loads. 64 // field loads.
63 class SideEffectsTracker V8_FINAL BASE_EMBEDDED { 65 class SideEffectsTracker V8_FINAL BASE_EMBEDDED {
64 public: 66 public:
65 SideEffectsTracker() : num_global_vars_(0), num_inobject_fields_(0) {} 67 SideEffectsTracker() : num_global_vars_(0), num_inobject_fields_(0) {}
66 SideEffects ComputeChanges(HInstruction* instr); 68 SideEffects ComputeChanges(HInstruction* instr);
67 SideEffects ComputeDependsOn(HInstruction* instr); 69 SideEffects ComputeDependsOn(HInstruction* instr);
68 void PrintSideEffectsTo(StringStream* stream, SideEffects side_effects) const;
69 70
70 private: 71 private:
72 friend OStream& operator<<(OStream& os, const TrackedEffects& f);
71 bool ComputeGlobalVar(Unique<Cell> cell, int* index); 73 bool ComputeGlobalVar(Unique<Cell> cell, int* index);
72 bool ComputeInobjectField(HObjectAccess access, int* index); 74 bool ComputeInobjectField(HObjectAccess access, int* index);
73 75
74 static int GlobalVar(int index) { 76 static int GlobalVar(int index) {
75 ASSERT(index >= 0); 77 ASSERT(index >= 0);
76 ASSERT(index < kNumberOfGlobalVars); 78 ASSERT(index < kNumberOfGlobalVars);
77 return index; 79 return index;
78 } 80 }
79 static int InobjectField(int index) { 81 static int InobjectField(int index) {
80 ASSERT(index >= 0); 82 ASSERT(index >= 0);
81 ASSERT(index < kNumberOfInobjectFields); 83 ASSERT(index < kNumberOfInobjectFields);
82 return index + kNumberOfGlobalVars; 84 return index + kNumberOfGlobalVars;
83 } 85 }
84 86
85 // Track up to four global vars. 87 // Track up to four global vars.
86 static const int kNumberOfGlobalVars = 4; 88 static const int kNumberOfGlobalVars = 4;
87 Unique<Cell> global_vars_[kNumberOfGlobalVars]; 89 Unique<Cell> global_vars_[kNumberOfGlobalVars];
88 int num_global_vars_; 90 int num_global_vars_;
89 91
90 // Track up to n inobject fields. 92 // Track up to n inobject fields.
91 static const int kNumberOfInobjectFields = 93 static const int kNumberOfInobjectFields =
92 SideEffects::kNumberOfSpecials - kNumberOfGlobalVars; 94 SideEffects::kNumberOfSpecials - kNumberOfGlobalVars;
93 HObjectAccess inobject_fields_[kNumberOfInobjectFields]; 95 HObjectAccess inobject_fields_[kNumberOfInobjectFields];
94 int num_inobject_fields_; 96 int num_inobject_fields_;
95 }; 97 };
96 98
97 99
100 // Helper class for printing, because the effects don't know their tracker.
101 struct TrackedEffects {
102 TrackedEffects(SideEffectsTracker* t, SideEffects e)
103 : tracker(t), effects(e) {}
104 SideEffectsTracker* tracker;
105 SideEffects effects;
106 };
107
108
109 OStream& operator<<(OStream& os, const TrackedEffects& f);
110
111
98 // Perform common subexpression elimination and loop-invariant code motion. 112 // Perform common subexpression elimination and loop-invariant code motion.
99 class HGlobalValueNumberingPhase V8_FINAL : public HPhase { 113 class HGlobalValueNumberingPhase V8_FINAL : public HPhase {
100 public: 114 public:
101 explicit HGlobalValueNumberingPhase(HGraph* graph); 115 explicit HGlobalValueNumberingPhase(HGraph* graph);
102 116
103 void Run(); 117 void Run();
104 118
105 private: 119 private:
106 SideEffects CollectSideEffectsOnPathsToDominatedBlock( 120 SideEffects CollectSideEffectsOnPathsToDominatedBlock(
107 HBasicBlock* dominator, 121 HBasicBlock* dominator,
108 HBasicBlock* dominated); 122 HBasicBlock* dominated);
109 void AnalyzeGraph(); 123 void AnalyzeGraph();
110 void ComputeBlockSideEffects(); 124 void ComputeBlockSideEffects();
111 void LoopInvariantCodeMotion(); 125 void LoopInvariantCodeMotion();
112 void ProcessLoopBlock(HBasicBlock* block, 126 void ProcessLoopBlock(HBasicBlock* block,
113 HBasicBlock* before_loop, 127 HBasicBlock* before_loop,
114 SideEffects loop_kills); 128 SideEffects loop_kills);
115 bool AllowCodeMotion(); 129 bool AllowCodeMotion();
116 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header); 130 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header);
131 TrackedEffects Print(SideEffects side_effects) {
132 return TrackedEffects(&side_effects_tracker_, side_effects);
133 }
117 134
118 SideEffectsTracker side_effects_tracker_; 135 SideEffectsTracker side_effects_tracker_;
119 bool removed_side_effects_; 136 bool removed_side_effects_;
120 137
121 // A map of block IDs to their side effects. 138 // A map of block IDs to their side effects.
122 ZoneList<SideEffects> block_side_effects_; 139 ZoneList<SideEffects> block_side_effects_;
123 140
124 // A map of loop header block IDs to their loop's side effects. 141 // A map of loop header block IDs to their loop's side effects.
125 ZoneList<SideEffects> loop_side_effects_; 142 ZoneList<SideEffects> loop_side_effects_;
126 143
127 // Used when collecting side effects on paths from dominator to 144 // Used when collecting side effects on paths from dominator to
128 // dominated. 145 // dominated.
129 BitVector visited_on_paths_; 146 BitVector visited_on_paths_;
130 147
131 DISALLOW_COPY_AND_ASSIGN(HGlobalValueNumberingPhase); 148 DISALLOW_COPY_AND_ASSIGN(HGlobalValueNumberingPhase);
132 }; 149 };
133 150
134 } } // namespace v8::internal 151 } } // namespace v8::internal
135 152
136 #endif // V8_HYDROGEN_GVN_H_ 153 #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