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" | |
9 #include "src/bit-vector.h" | |
10 #include "src/compiler/bytecode-liveness-map.h" | |
11 #include "src/handles.h" | 8 #include "src/handles.h" |
12 #include "src/zone/zone-containers.h" | 9 #include "src/zone/zone-containers.h" |
13 | 10 |
14 namespace v8 { | 11 namespace v8 { |
15 namespace internal { | 12 namespace internal { |
16 | 13 |
17 class BytecodeArray; | 14 class BytecodeArray; |
18 | 15 |
19 namespace compiler { | 16 namespace compiler { |
20 | 17 |
21 class V8_EXPORT_PRIVATE BytecodeAnalysis BASE_EMBEDDED { | 18 class BytecodeAnalysis BASE_EMBEDDED { |
22 public: | 19 public: |
23 BytecodeAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone, | 20 BytecodeAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone); |
24 bool do_liveness_analysis); | |
25 | 21 |
26 // Analyze the bytecodes to find the loop ranges and nesting. No other | 22 // 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. | 23 // methods in this class return valid information until this has been called. |
28 void Analyze(); | 24 void Analyze(); |
29 | 25 |
30 // Return true if the given offset is a loop header | 26 // Return true if the given offset is a loop header |
31 bool IsLoopHeader(int offset) const; | 27 bool IsLoopHeader(int offset) const; |
32 // Get the loop header offset of the containing loop for arbitrary | 28 // Get the loop header offset of the containing loop for arbitrary |
33 // {offset}, or -1 if the {offset} is not inside any loop. | 29 // {offset}, or -1 if the {offset} is not inside any loop. |
34 int GetLoopOffsetFor(int offset) const; | 30 int GetLoopOffsetFor(int offset) const; |
35 // Gets the loop header offset of the parent loop of the loop header | 31 // Gets the loop header offset of the parent loop of the loop header |
36 // at {header_offset}, or -1 for outer-most loops. | 32 // at {header_offset}, or -1 for outer-most loops. |
37 int GetParentLoopFor(int header_offset) const; | 33 int GetParentLoopFor(int header_offset) const; |
38 | 34 |
39 // Gets the in-liveness for the bytecode at {offset}. The liveness bit vector | |
40 // represents the liveness of the registers and the accumulator, with the last | |
41 // bit being the accumulator liveness bit, and so is (register count + 1) bits | |
42 // long. | |
43 const BitVector* GetInLivenessFor(int offset) const; | |
44 | |
45 // Gets the out-liveness for the bytecode at {offset}. The liveness bit vector | |
46 // represents the liveness of the registers and the accumulator, with the last | |
47 // bit being the accumulator liveness bit, and so is (register count + 1) bits | |
48 // long. | |
49 const BitVector* GetOutLivenessFor(int offset) const; | |
50 | |
51 std::ostream& PrintLivenessTo(std::ostream& os) const; | |
52 | |
53 private: | 35 private: |
54 void PushLoop(int loop_header, int loop_end); | 36 void PushLoop(int loop_header, int loop_end); |
55 | 37 |
56 #if DEBUG | |
57 bool LivenessIsValid(); | |
58 #endif | |
59 | |
60 Zone* zone() const { return zone_; } | 38 Zone* zone() const { return zone_; } |
61 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } | 39 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } |
62 | 40 |
63 private: | |
64 Handle<BytecodeArray> bytecode_array_; | 41 Handle<BytecodeArray> bytecode_array_; |
65 bool do_liveness_analysis_; | |
66 Zone* zone_; | 42 Zone* zone_; |
67 | 43 |
68 ZoneStack<int> loop_stack_; | 44 ZoneStack<int> loop_stack_; |
69 | 45 |
70 ZoneMap<int, int> end_to_header_; | 46 ZoneMap<int, int> end_to_header_; |
71 ZoneMap<int, int> header_to_parent_; | 47 ZoneMap<int, int> header_to_parent_; |
72 | 48 |
73 BytecodeLivenessMap liveness_map_; | |
74 | |
75 DISALLOW_COPY_AND_ASSIGN(BytecodeAnalysis); | 49 DISALLOW_COPY_AND_ASSIGN(BytecodeAnalysis); |
76 }; | 50 }; |
77 | 51 |
78 } // namespace compiler | 52 } // namespace compiler |
79 } // namespace internal | 53 } // namespace internal |
80 } // namespace v8 | 54 } // namespace v8 |
81 | 55 |
82 #endif // V8_COMPILER_BYTECODE_ANALYSIS_H_ | 56 #endif // V8_COMPILER_BYTECODE_ANALYSIS_H_ |
OLD | NEW |