OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 private: | 69 private: |
70 int capacity_; | 70 int capacity_; |
71 int length_; | 71 int length_; |
72 int* dense_; | 72 int* dense_; |
73 int* sparse_; | 73 int* sparse_; |
74 | 74 |
75 DISALLOW_COPY_AND_ASSIGN(SparseSet); | 75 DISALLOW_COPY_AND_ASSIGN(SparseSet); |
76 }; | 76 }; |
77 | 77 |
78 | 78 |
79 class HGlobalValueNumberer BASE_EMBEDDED { | 79 // Perform common subexpression elimination and loop-invariant code motion. |
| 80 class HGlobalValueNumberingPhase : public HPhase { |
80 public: | 81 public: |
81 HGlobalValueNumberer(HGraph* graph, CompilationInfo* info); | 82 explicit HGlobalValueNumberingPhase(HGraph* graph); |
82 | 83 |
83 // Returns true if values with side effects are removed. | 84 void Run() { |
84 bool Analyze(); | 85 Analyze(); |
| 86 // Trigger a second analysis pass to further eliminate duplicate values |
| 87 // that could only be discovered by removing side-effect-generating |
| 88 // instructions during the first pass. |
| 89 if (FLAG_smi_only_arrays && removed_side_effects_) { |
| 90 Analyze(); |
| 91 ASSERT(!removed_side_effects_); |
| 92 } |
| 93 } |
85 | 94 |
86 private: | 95 private: |
| 96 void Analyze(); |
87 GVNFlagSet CollectSideEffectsOnPathsToDominatedBlock( | 97 GVNFlagSet CollectSideEffectsOnPathsToDominatedBlock( |
88 HBasicBlock* dominator, | 98 HBasicBlock* dominator, |
89 HBasicBlock* dominated); | 99 HBasicBlock* dominated); |
90 void AnalyzeGraph(); | 100 void AnalyzeGraph(); |
91 void ComputeBlockSideEffects(); | 101 void ComputeBlockSideEffects(); |
92 void LoopInvariantCodeMotion(); | 102 void LoopInvariantCodeMotion(); |
93 void ProcessLoopBlock(HBasicBlock* block, | 103 void ProcessLoopBlock(HBasicBlock* block, |
94 HBasicBlock* before_loop, | 104 HBasicBlock* before_loop, |
95 GVNFlagSet loop_kills, | 105 GVNFlagSet loop_kills, |
96 GVNFlagSet* accumulated_first_time_depends, | 106 GVNFlagSet* accumulated_first_time_depends, |
97 GVNFlagSet* accumulated_first_time_changes); | 107 GVNFlagSet* accumulated_first_time_changes); |
98 bool AllowCodeMotion(); | 108 bool AllowCodeMotion(); |
99 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header); | 109 bool ShouldMove(HInstruction* instr, HBasicBlock* loop_header); |
100 | 110 |
101 HGraph* graph() { return graph_; } | |
102 CompilationInfo* info() { return info_; } | |
103 Zone* zone() { return &zone_; } | |
104 | |
105 HGraph* graph_; | |
106 CompilationInfo* info_; | |
107 bool removed_side_effects_; | 111 bool removed_side_effects_; |
108 | 112 |
109 Zone zone_; | |
110 | |
111 // A map of block IDs to their side effects. | 113 // A map of block IDs to their side effects. |
112 ZoneList<GVNFlagSet> block_side_effects_; | 114 ZoneList<GVNFlagSet> block_side_effects_; |
113 | 115 |
114 // A map of loop header block IDs to their loop's side effects. | 116 // A map of loop header block IDs to their loop's side effects. |
115 ZoneList<GVNFlagSet> loop_side_effects_; | 117 ZoneList<GVNFlagSet> loop_side_effects_; |
116 | 118 |
117 // Used when collecting side effects on paths from dominator to | 119 // Used when collecting side effects on paths from dominator to |
118 // dominated. | 120 // dominated. |
119 SparseSet visited_on_paths_; | 121 SparseSet visited_on_paths_; |
| 122 |
| 123 DISALLOW_COPY_AND_ASSIGN(HGlobalValueNumberingPhase); |
120 }; | 124 }; |
121 | 125 |
122 | 126 |
123 } } // namespace v8::internal | 127 } } // namespace v8::internal |
124 | 128 |
125 #endif // V8_HYDROGEN_GVN_H_ | 129 #endif // V8_HYDROGEN_GVN_H_ |
OLD | NEW |