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" | |
10 #include "src/zone-containers.h" | |
11 | |
12 namespace v8 { | |
13 namespace internal { | |
14 namespace compiler { | |
15 | |
16 class BytecodeBranchInfo; | |
17 | |
18 class BytecodeBranchAnalysis BASE_EMBEDDED { | |
rmcilroy
2015/12/15 17:35:43
A comment on what the class does would be good
oth
2015/12/15 22:42:17
Done.
| |
19 public: | |
20 BytecodeBranchAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone) | |
21 : branch_infos_(zone), | |
22 bytecode_array_(bytecode_array), | |
23 reachable_(bytecode_array->length(), zone), | |
24 zone_(zone) {} | |
25 | |
26 void Analyze(); | |
rmcilroy
2015/12/15 17:35:43
Comment?
oth
2015/12/15 22:42:17
Done.
| |
27 | |
28 // Offsets of bytecodes having a backward branch to the bytecode at |offset|. | |
29 const ZoneVector<int>* BackwardBranchesTargetting(int offset) const; | |
30 | |
31 // Offsets of bytecodes having a foreward branch to the bytecode at |offset|. | |
rmcilroy
2015/12/15 17:35:43
/s/foreward/forward
oth
2015/12/15 22:42:17
Done.
| |
32 const ZoneVector<int>* ForwardBranchesTargetting(int offset) const; | |
33 | |
34 // Returns true if the bytecode at |offset| is reachable. | |
35 bool is_reachable(int offset) const { return reachable_.Contains(offset); } | |
36 | |
37 // Returns true if there are any forward branches to the bytecode at | |
38 // |offset|. | |
39 bool forward_branches_target(int offset) const { | |
40 const ZoneVector<int>* sites = ForwardBranchesTargetting(offset); | |
41 return sites != nullptr && sites->size() > 0; | |
42 } | |
43 | |
44 // Returns true if there are any backward branches to the bytecode | |
45 // at |offset|. | |
46 bool backward_branches_target(int offset) const { | |
47 const ZoneVector<int>* sites = BackwardBranchesTargetting(offset); | |
48 return sites != nullptr && sites->size() > 0; | |
49 } | |
50 | |
51 // Returns true if the bytecode at |offset| is the last backwards branch to | |
52 // |branch_target|. | |
53 bool IsLastBackwardBranchTo(int branch_target, int offset) const; | |
54 | |
55 private: | |
56 void AddBranch(int origin_offset, int target_offset); | |
57 | |
58 Zone* zone() const { return zone_; } | |
59 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } | |
60 | |
61 ZoneMap<int, BytecodeBranchInfo*> branch_infos_; | |
62 Handle<BytecodeArray> bytecode_array_; | |
63 BitVector reachable_; | |
64 Zone* zone_; | |
65 | |
66 DISALLOW_COPY_AND_ASSIGN(BytecodeBranchAnalysis); | |
67 }; | |
68 | |
69 | |
70 } // namespace compiler | |
71 } // namespace internal | |
72 } // namespace v8 | |
73 | |
74 #endif // V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_ | |
OLD | NEW |