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_ANALYSIS_H_ | 5 #ifndef V8_COMPILER_BYTECODE_ANALYSIS_H_ |
| 6 #define V8_COMPILER_BYTECODE_ANALYSIS_H_ | 6 #define V8_COMPILER_BYTECODE_ANALYSIS_H_ |
| 7 | 7 |
| 8 #include "src/base/hashmap.h" | 8 #include "src/base/hashmap.h" |
| 9 #include "src/bit-vector.h" | 9 #include "src/bit-vector.h" |
| 10 #include "src/compiler/bytecode-liveness-map.h" | 10 #include "src/compiler/bytecode-liveness-map.h" |
| 11 #include "src/handles.h" | 11 #include "src/handles.h" |
| 12 #include "src/interpreter/bytecode-register.h" | |
| 12 #include "src/zone/zone-containers.h" | 13 #include "src/zone/zone-containers.h" |
| 13 | 14 |
| 14 namespace v8 { | 15 namespace v8 { |
| 15 namespace internal { | 16 namespace internal { |
| 16 | 17 |
| 17 class BytecodeArray; | 18 class BytecodeArray; |
| 18 | 19 |
| 19 namespace compiler { | 20 namespace compiler { |
| 20 | 21 |
| 22 class V8_EXPORT_PRIVATE BytecodeLoopAssignments { | |
| 23 public: | |
| 24 BytecodeLoopAssignments(int parameter_count, int register_count, Zone* zone); | |
| 25 | |
| 26 void Add(interpreter::Register r); | |
| 27 void AddPair(interpreter::Register r); | |
| 28 void AddTriple(interpreter::Register r); | |
| 29 void AddAll(); | |
| 30 void Union(const BytecodeLoopAssignments& other); | |
| 31 | |
| 32 bool ContainsParameter(int index) const; | |
| 33 bool ContainsLocal(int index) const; | |
| 34 | |
| 35 private: | |
| 36 int parameter_count_; | |
| 37 BitVector* bit_vector_; | |
| 38 }; | |
| 39 | |
| 40 struct V8_EXPORT_PRIVATE LoopInfo { | |
| 41 public: | |
| 42 LoopInfo(int parent_offset, int parameter_count, int register_count, | |
| 43 Zone* zone) | |
| 44 : parent_offset_(parent_offset), | |
| 45 assignments_(parameter_count, register_count, zone) {} | |
| 46 | |
| 47 int parent_offset() const { return parent_offset_; } | |
| 48 | |
| 49 BytecodeLoopAssignments& assignments() { return assignments_; } | |
| 50 const BytecodeLoopAssignments& assignments() const { return assignments_; } | |
| 51 | |
| 52 private: | |
| 53 // The offset to the parent loop, or -1 if there is no parent. | |
| 54 int parent_offset_; | |
| 55 BytecodeLoopAssignments assignments_; | |
| 56 }; | |
| 57 | |
| 21 class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED { | 58 class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED { |
| 22 public: | 59 public: |
| 23 BytecodeAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone, | 60 BytecodeAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone, |
| 24 bool do_liveness_analysis); | 61 bool do_liveness_analysis); |
| 25 | 62 |
| 26 // Analyze the bytecodes to find the loop ranges and nesting. No other | 63 // Analyze the bytecodes to find the loop ranges and nesting. No other |
| 27 // methods in this class return valid information until this has been called. | 64 // methods in this class return valid information until this has been called. |
| 28 void Analyze(); | 65 void Analyze(BailoutId osr_bailout_id); |
|
Jarin
2016/12/12 06:53:37
Please explain in the comment what is the paramete
| |
| 29 | 66 |
| 30 // Return true if the given offset is a loop header | 67 // Return true if the given offset is a loop header |
| 31 bool IsLoopHeader(int offset) const; | 68 bool IsLoopHeader(int offset) const; |
| 32 // Get the loop header offset of the containing loop for arbitrary | 69 // Get the loop header offset of the containing loop for arbitrary |
| 33 // {offset}, or -1 if the {offset} is not inside any loop. | 70 // {offset}, or -1 if the {offset} is not inside any loop. |
| 34 int GetLoopOffsetFor(int offset) const; | 71 int GetLoopOffsetFor(int offset) const; |
| 35 // Gets the loop header offset of the parent loop of the loop header | 72 // Get the loop info of the loop header at {header_offset}. |
| 36 // at {header_offset}, or -1 for outer-most loops. | 73 const LoopInfo& GetLoopInfoFor(int header_offset) const; |
| 37 int GetParentLoopFor(int header_offset) const; | |
| 38 | 74 |
| 39 // Gets the in-liveness for the bytecode at {offset}. | 75 // Gets the in-liveness for the bytecode at {offset}. |
| 40 const BytecodeLivenessState* GetInLivenessFor(int offset) const; | 76 const BytecodeLivenessState* GetInLivenessFor(int offset) const; |
| 41 | 77 |
| 42 // Gets the out-liveness for the bytecode at {offset}. | 78 // Gets the out-liveness for the bytecode at {offset}. |
| 43 const BytecodeLivenessState* GetOutLivenessFor(int offset) const; | 79 const BytecodeLivenessState* GetOutLivenessFor(int offset) const; |
| 44 | 80 |
| 45 std::ostream& PrintLivenessTo(std::ostream& os) const; | 81 std::ostream& PrintLivenessTo(std::ostream& os) const; |
| 46 | 82 |
| 47 private: | 83 private: |
| 84 struct LoopStackEntry { | |
| 85 int header_offset; | |
| 86 LoopInfo* loop_info; | |
| 87 }; | |
| 88 | |
| 89 Handle<BytecodeArray> bytecode_array_; | |
| 90 bool do_liveness_analysis_; | |
| 91 Zone* zone_; | |
| 92 | |
| 93 ZoneStack<LoopStackEntry> loop_stack_; | |
| 94 ZoneVector<int> loop_end_index_queue_; | |
| 95 | |
| 96 ZoneMap<int, int> end_to_header_; | |
| 97 ZoneMap<int, LoopInfo> header_to_info_; | |
| 98 | |
| 99 BytecodeLivenessMap liveness_map_; | |
| 100 | |
| 48 void PushLoop(int loop_header, int loop_end); | 101 void PushLoop(int loop_header, int loop_end); |
| 49 | 102 |
| 50 #if DEBUG | 103 #if DEBUG |
| 51 bool LivenessIsValid(); | 104 bool LivenessIsValid(); |
| 52 #endif | 105 #endif |
| 53 | 106 |
| 54 Zone* zone() const { return zone_; } | 107 Zone* zone() const { return zone_; } |
| 55 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } | 108 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } |
| 56 | 109 |
| 57 private: | |
| 58 Handle<BytecodeArray> bytecode_array_; | |
| 59 bool do_liveness_analysis_; | |
| 60 Zone* zone_; | |
| 61 | |
| 62 ZoneStack<int> loop_stack_; | |
| 63 ZoneVector<int> loop_end_index_queue_; | |
| 64 | |
| 65 ZoneMap<int, int> end_to_header_; | |
| 66 ZoneMap<int, int> header_to_parent_; | |
| 67 | |
| 68 BytecodeLivenessMap liveness_map_; | |
| 69 | |
| 70 DISALLOW_COPY_AND_ASSIGN(BytecodeAnalysis); | 110 DISALLOW_COPY_AND_ASSIGN(BytecodeAnalysis); |
| 71 }; | 111 }; |
| 72 | 112 |
| 73 } // namespace compiler | 113 } // namespace compiler |
| 74 } // namespace internal | 114 } // namespace internal |
| 75 } // namespace v8 | 115 } // namespace v8 |
| 76 | 116 |
| 77 #endif // V8_COMPILER_BYTECODE_ANALYSIS_H_ | 117 #endif // V8_COMPILER_BYTECODE_ANALYSIS_H_ |
| OLD | NEW |