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 bool ContainsAccumulator() const; |
| 35 |
| 36 int parameter_count() const { return parameter_count_; } |
| 37 int local_count() const { return bit_vector_->length() - parameter_count_; } |
| 38 |
| 39 private: |
| 40 int parameter_count_; |
| 41 BitVector* bit_vector_; |
| 42 }; |
| 43 |
| 44 struct V8_EXPORT_PRIVATE LoopInfo { |
| 45 public: |
| 46 LoopInfo(int parent_offset, int parameter_count, int register_count, |
| 47 Zone* zone) |
| 48 : parent_offset_(parent_offset), |
| 49 assignments_(parameter_count, register_count, zone) {} |
| 50 |
| 51 int parent_offset() const { return parent_offset_; } |
| 52 |
| 53 BytecodeLoopAssignments& assignments() { return assignments_; } |
| 54 const BytecodeLoopAssignments& assignments() const { return assignments_; } |
| 55 |
| 56 private: |
| 57 // The offset to the parent loop, or -1 if there is no parent. |
| 58 int parent_offset_; |
| 59 BytecodeLoopAssignments assignments_; |
| 60 }; |
| 61 |
21 class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED { | 62 class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED { |
22 public: | 63 public: |
23 BytecodeAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone, | 64 BytecodeAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone, |
24 bool do_liveness_analysis); | 65 bool do_liveness_analysis); |
25 | 66 |
26 // Analyze the bytecodes to find the loop ranges and nesting. No other | 67 // Analyze the bytecodes to find the loop ranges, loop nesting, loop |
27 // methods in this class return valid information until this has been called. | 68 // assignments and liveness, under the assumption that there is an OSR bailout |
28 void Analyze(); | 69 // at {osr_bailout_id}. |
| 70 // |
| 71 // No other methods in this class return valid information until this has been |
| 72 // called. |
| 73 void Analyze(BailoutId osr_bailout_id); |
29 | 74 |
30 // Return true if the given offset is a loop header | 75 // Return true if the given offset is a loop header |
31 bool IsLoopHeader(int offset) const; | 76 bool IsLoopHeader(int offset) const; |
32 // Get the loop header offset of the containing loop for arbitrary | 77 // Get the loop header offset of the containing loop for arbitrary |
33 // {offset}, or -1 if the {offset} is not inside any loop. | 78 // {offset}, or -1 if the {offset} is not inside any loop. |
34 int GetLoopOffsetFor(int offset) const; | 79 int GetLoopOffsetFor(int offset) const; |
35 // Gets the loop header offset of the parent loop of the loop header | 80 // Get the loop info of the loop header at {header_offset}. |
36 // at {header_offset}, or -1 for outer-most loops. | 81 const LoopInfo& GetLoopInfoFor(int header_offset) const; |
37 int GetParentLoopFor(int header_offset) const; | |
38 | 82 |
39 // Gets the in-liveness for the bytecode at {offset}. | 83 // Gets the in-liveness for the bytecode at {offset}. |
40 const BytecodeLivenessState* GetInLivenessFor(int offset) const; | 84 const BytecodeLivenessState* GetInLivenessFor(int offset) const; |
41 | 85 |
42 // Gets the out-liveness for the bytecode at {offset}. | 86 // Gets the out-liveness for the bytecode at {offset}. |
43 const BytecodeLivenessState* GetOutLivenessFor(int offset) const; | 87 const BytecodeLivenessState* GetOutLivenessFor(int offset) const; |
44 | 88 |
45 std::ostream& PrintLivenessTo(std::ostream& os) const; | 89 std::ostream& PrintLivenessTo(std::ostream& os) const; |
46 | 90 |
47 private: | 91 private: |
| 92 struct LoopStackEntry { |
| 93 int header_offset; |
| 94 LoopInfo* loop_info; |
| 95 }; |
| 96 |
48 void PushLoop(int loop_header, int loop_end); | 97 void PushLoop(int loop_header, int loop_end); |
49 | 98 |
50 #if DEBUG | 99 #if DEBUG |
51 bool LivenessIsValid(); | 100 bool LivenessIsValid(); |
52 #endif | 101 #endif |
53 | 102 |
54 Zone* zone() const { return zone_; } | 103 Zone* zone() const { return zone_; } |
55 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } | 104 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } |
56 | 105 |
57 private: | 106 private: |
58 Handle<BytecodeArray> bytecode_array_; | 107 Handle<BytecodeArray> bytecode_array_; |
59 bool do_liveness_analysis_; | 108 bool do_liveness_analysis_; |
60 Zone* zone_; | 109 Zone* zone_; |
61 | 110 |
62 ZoneStack<int> loop_stack_; | 111 ZoneStack<LoopStackEntry> loop_stack_; |
63 ZoneVector<int> loop_end_index_queue_; | 112 ZoneVector<int> loop_end_index_queue_; |
64 | 113 |
65 ZoneMap<int, int> end_to_header_; | 114 ZoneMap<int, int> end_to_header_; |
66 ZoneMap<int, int> header_to_parent_; | 115 ZoneMap<int, LoopInfo> header_to_info_; |
67 | 116 |
68 BytecodeLivenessMap liveness_map_; | 117 BytecodeLivenessMap liveness_map_; |
69 | 118 |
70 DISALLOW_COPY_AND_ASSIGN(BytecodeAnalysis); | 119 DISALLOW_COPY_AND_ASSIGN(BytecodeAnalysis); |
71 }; | 120 }; |
72 | 121 |
73 } // namespace compiler | 122 } // namespace compiler |
74 } // namespace internal | 123 } // namespace internal |
75 } // namespace v8 | 124 } // namespace v8 |
76 | 125 |
77 #endif // V8_COMPILER_BYTECODE_ANALYSIS_H_ | 126 #endif // V8_COMPILER_BYTECODE_ANALYSIS_H_ |
OLD | NEW |