OLD | NEW |
| (Empty) |
1 // Copyright 2015 the V8 project authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_ | |
6 #define V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_ | |
7 | |
8 #include "src/bit-vector.h" | |
9 #include "src/handles.h" | |
10 | |
11 namespace v8 { | |
12 namespace internal { | |
13 | |
14 class BytecodeArray; | |
15 | |
16 namespace compiler { | |
17 | |
18 // A class for identifying branch targets within a bytecode array. | |
19 // This information can be used to construct the local control flow | |
20 // logic for high-level IR graphs built from bytecode. | |
21 // | |
22 // N.B. If this class is used to determine loop headers, then such a | |
23 // usage relies on the only backwards branches in bytecode being jumps | |
24 // back to loop headers. | |
25 class BytecodeBranchAnalysis BASE_EMBEDDED { | |
26 public: | |
27 BytecodeBranchAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone); | |
28 | |
29 // Analyze the bytecodes to find the branch sites and their | |
30 // targets. No other methods in this class return valid information | |
31 // until this has been called. | |
32 void Analyze(); | |
33 | |
34 // Returns true if there are any forward branches to the bytecode at | |
35 // |offset|. | |
36 bool forward_branches_target(int offset) const { | |
37 return is_forward_target_.Contains(offset); | |
38 } | |
39 | |
40 // Returns true if there are any backward branches to the bytecode | |
41 // at |offset|. | |
42 bool backward_branches_target(int offset) const { | |
43 return is_backward_target_.Contains(offset); | |
44 } | |
45 | |
46 private: | |
47 void AddBranch(int origin_offset, int target_offset); | |
48 | |
49 Zone* zone() const { return zone_; } | |
50 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } | |
51 | |
52 Handle<BytecodeArray> bytecode_array_; | |
53 BitVector is_backward_target_; | |
54 BitVector is_forward_target_; | |
55 Zone* zone_; | |
56 | |
57 DISALLOW_COPY_AND_ASSIGN(BytecodeBranchAnalysis); | |
58 }; | |
59 | |
60 | |
61 } // namespace compiler | |
62 } // namespace internal | |
63 } // namespace v8 | |
64 | |
65 #endif // V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_ | |
OLD | NEW |