Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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_COMPILER_BYTECODE_LOOP_ANALYSIS_H_ | 5 #ifndef V8_COMPILER_BYTECODE_ANALYSIS_H_ |
| 6 #define V8_COMPILER_BYTECODE_LOOP_ANALYSIS_H_ | 6 #define V8_COMPILER_BYTECODE_ANALYSIS_H_ |
| 7 | 7 |
| 8 #include "src/handles.h" | 8 #include "src/handles.h" |
| 9 #include "src/zone/zone-containers.h" | 9 #include "src/zone/zone-containers.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 class BytecodeArray; | 14 class BytecodeArray; |
| 15 | 15 |
| 16 namespace compiler { | 16 namespace compiler { |
| 17 | 17 |
| 18 class BytecodeBranchAnalysis; | 18 class BytecodeAnalysis BASE_EMBEDDED { |
| 19 | |
| 20 class BytecodeLoopAnalysis BASE_EMBEDDED { | |
| 21 public: | 19 public: |
| 22 BytecodeLoopAnalysis(Handle<BytecodeArray> bytecode_array, | 20 BytecodeAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone); |
| 23 const BytecodeBranchAnalysis* branch_analysis, | |
| 24 Zone* zone); | |
| 25 | 21 |
| 26 // Analyze the bytecodes to find the branch sites and their | 22 // Analyze the bytecodes to find the branch sites and their |
|
rmcilroy
2016/11/22 11:02:07
nit - this comment should be updated to talk about
Leszek Swirski
2016/11/22 17:39:03
Done.
| |
| 27 // targets. No other methods in this class return valid information | 23 // targets. No other methods in this class return valid information |
| 28 // until this has been called. | 24 // until this has been called. |
| 29 void Analyze(); | 25 void Analyze(); |
| 30 | 26 |
| 27 // Return true if the given offset is a loop header | |
| 28 bool IsLoopHeader(int offset) const; | |
| 31 // Get the loop header offset of the containing loop for arbitrary | 29 // Get the loop header offset of the containing loop for arbitrary |
| 32 // {offset}, or -1 if the {offset} is not inside any loop. | 30 // {offset}, or -1 if the {offset} is not inside any loop. |
| 33 int GetLoopOffsetFor(int offset) const; | 31 int GetLoopOffsetFor(int offset) const; |
| 34 // Gets the loop header offset of the parent loop of the loop header | 32 // Gets the loop header offset of the parent loop of the loop header |
| 35 // at {header_offset}, or -1 for outer-most loops. | 33 // at {header_offset}, or -1 for outer-most loops. |
| 36 int GetParentLoopFor(int header_offset) const; | 34 int GetParentLoopFor(int header_offset) const; |
| 37 | 35 |
| 38 private: | 36 private: |
| 39 void AddLoopEntry(int entry_offset); | 37 void PushLoop(int loop_header, int loop_end); |
| 40 void AddBranch(int origin_offset, int target_offset); | |
| 41 | 38 |
| 42 Zone* zone() const { return zone_; } | 39 Zone* zone() const { return zone_; } |
| 43 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } | 40 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } |
| 44 | 41 |
| 45 Handle<BytecodeArray> bytecode_array_; | 42 Handle<BytecodeArray> bytecode_array_; |
| 46 const BytecodeBranchAnalysis* branch_analysis_; | |
| 47 Zone* zone_; | 43 Zone* zone_; |
| 48 | 44 |
| 49 int current_loop_offset_; | 45 ZoneStack<int> loop_stack_; |
| 50 bool found_current_backedge_; | |
| 51 | 46 |
| 52 // Map from the offset of a backedge jump to the offset of the corresponding | 47 ZoneMap<int, int> end_to_header_; |
| 53 // loop header. There might be multiple backedges for do-while loops. | 48 ZoneMap<int, int> header_to_parent_; |
| 54 ZoneMap<int, int> backedge_to_header_; | |
| 55 // Map from the offset of a loop header to the offset of its parent's loop | |
| 56 // header. This map will have as many entries as there are loops in the | |
| 57 // function. | |
| 58 ZoneMap<int, int> loop_header_to_parent_; | |
| 59 | 49 |
| 60 DISALLOW_COPY_AND_ASSIGN(BytecodeLoopAnalysis); | 50 DISALLOW_COPY_AND_ASSIGN(BytecodeAnalysis); |
| 61 }; | 51 }; |
| 62 | 52 |
| 63 } // namespace compiler | 53 } // namespace compiler |
| 64 } // namespace internal | 54 } // namespace internal |
| 65 } // namespace v8 | 55 } // namespace v8 |
| 66 | 56 |
| 67 #endif // V8_COMPILER_BYTECODE_LOOP_ANALYSIS_H_ | 57 #endif // V8_COMPILER_BYTECODE_ANALYSIS_H_ |
| OLD | NEW |