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/compiler.h" | |
Michael Starzinger
2015/12/16 12:40:11
nit: Can we get by without including the compiler.
oth
2015/12/16 14:17:06
Done.
| |
10 #include "src/zone-containers.h" | |
11 | |
12 namespace v8 { | |
13 namespace internal { | |
14 namespace compiler { | |
15 | |
16 class BytecodeBranchInfo; | |
17 | |
18 // A class for identifying the branch targets and their branch sites | |
19 // within a bytecode array and also identifying which bytecodes are | |
20 // reachable. This information can be used to construct the local | |
21 // control flow logic for turbofan graphs built from bytecode. | |
Michael Starzinger
2015/12/16 12:40:11
nit: s/turbofan graphs/high-level IR graphs/
oth
2015/12/16 14:17:06
Done.
| |
22 // | |
23 // NB This class relies on the only backwards branches in bytecode | |
24 // being jumps back to loop headers. | |
25 class BytecodeBranchAnalysis BASE_EMBEDDED { | |
26 public: | |
27 BytecodeBranchAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone) | |
28 : branch_infos_(zone), | |
29 bytecode_array_(bytecode_array), | |
30 reachable_(bytecode_array->length(), zone), | |
Michael Starzinger
2015/12/16 12:40:11
nit: Can we move this constructor into the .cc fil
oth
2015/12/16 14:17:06
Done.
| |
31 zone_(zone) {} | |
32 | |
33 // Analyze the bytecodes to find the branch sites and their | |
34 // targets. No other methods in this class return valid information | |
35 // until this has been called. | |
36 void Analyze(); | |
37 | |
38 // Offsets of bytecodes having a backward branch to the bytecode at |offset|. | |
39 const ZoneVector<int>* BackwardBranchesTargetting(int offset) const; | |
40 | |
41 // Offsets of bytecodes having a forward branch to the bytecode at |offset|. | |
42 const ZoneVector<int>* ForwardBranchesTargetting(int offset) const; | |
43 | |
44 // Returns true if the bytecode at |offset| is reachable. | |
45 bool is_reachable(int offset) const { return reachable_.Contains(offset); } | |
46 | |
47 // Returns true if there are any forward branches to the bytecode at | |
48 // |offset|. | |
49 bool forward_branches_target(int offset) const { | |
50 const ZoneVector<int>* sites = ForwardBranchesTargetting(offset); | |
51 return sites != nullptr && sites->size() > 0; | |
52 } | |
53 | |
54 // Returns true if there are any backward branches to the bytecode | |
55 // at |offset|. | |
56 bool backward_branches_target(int offset) const { | |
57 const ZoneVector<int>* sites = BackwardBranchesTargetting(offset); | |
58 return sites != nullptr && sites->size() > 0; | |
59 } | |
60 | |
61 private: | |
62 void AddBranch(int origin_offset, int target_offset); | |
63 | |
64 Zone* zone() const { return zone_; } | |
65 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } | |
66 | |
67 ZoneMap<int, BytecodeBranchInfo*> branch_infos_; | |
68 Handle<BytecodeArray> bytecode_array_; | |
69 BitVector reachable_; | |
70 Zone* zone_; | |
71 | |
72 DISALLOW_COPY_AND_ASSIGN(BytecodeBranchAnalysis); | |
73 }; | |
74 | |
75 | |
76 } // namespace compiler | |
77 } // namespace internal | |
78 } // namespace v8 | |
79 | |
80 #endif // V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_ | |
OLD | NEW |