| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 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 | 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_BRANCH_ANALYSIS_H_ | 5 #ifndef V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_ |
| 6 #define V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_ | 6 #define V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_ |
| 7 | 7 |
| 8 #include "src/bit-vector.h" | 8 #include "src/bit-vector.h" |
| 9 #include "src/handles.h" | 9 #include "src/handles.h" |
| 10 #include "src/zone-containers.h" | 10 #include "src/zone-containers.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 // being jumps back to loop headers. | 27 // being jumps back to loop headers. |
| 28 class BytecodeBranchAnalysis BASE_EMBEDDED { | 28 class BytecodeBranchAnalysis BASE_EMBEDDED { |
| 29 public: | 29 public: |
| 30 BytecodeBranchAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone); | 30 BytecodeBranchAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone); |
| 31 | 31 |
| 32 // Analyze the bytecodes to find the branch sites and their | 32 // Analyze the bytecodes to find the branch sites and their |
| 33 // targets. No other methods in this class return valid information | 33 // targets. No other methods in this class return valid information |
| 34 // until this has been called. | 34 // until this has been called. |
| 35 void Analyze(); | 35 void Analyze(); |
| 36 | 36 |
| 37 // Offsets of bytecodes having a backward branch to the bytecode at |offset|. | |
| 38 const ZoneVector<int>* BackwardBranchesTargetting(int offset) const; | |
| 39 | |
| 40 // Offsets of bytecodes having a forward branch to the bytecode at |offset|. | |
| 41 const ZoneVector<int>* ForwardBranchesTargetting(int offset) const; | |
| 42 | |
| 43 // Returns true if the bytecode at |offset| is reachable. | 37 // Returns true if the bytecode at |offset| is reachable. |
| 44 bool is_reachable(int offset) const { return reachable_.Contains(offset); } | 38 bool is_reachable(int offset) const { return reachable_.Contains(offset); } |
| 45 | 39 |
| 46 // Returns true if there are any forward branches to the bytecode at | 40 // Returns true if there are any forward branches to the bytecode at |
| 47 // |offset|. | 41 // |offset|. |
| 48 bool forward_branches_target(int offset) const { | 42 bool forward_branches_target(int offset) const { |
| 49 const ZoneVector<int>* sites = ForwardBranchesTargetting(offset); | 43 const ZoneVector<int>* sites = ForwardBranchesTargetting(offset); |
| 50 return sites != nullptr && sites->size() > 0; | 44 return sites != nullptr && sites->size() > 0; |
| 51 } | 45 } |
| 52 | 46 |
| 53 // Returns true if there are any backward branches to the bytecode | 47 // Returns true if there are any backward branches to the bytecode |
| 54 // at |offset|. | 48 // at |offset|. |
| 55 bool backward_branches_target(int offset) const { | 49 bool backward_branches_target(int offset) const { |
| 56 const ZoneVector<int>* sites = BackwardBranchesTargetting(offset); | 50 const ZoneVector<int>* sites = BackwardBranchesTargetting(offset); |
| 57 return sites != nullptr && sites->size() > 0; | 51 return sites != nullptr && sites->size() > 0; |
| 58 } | 52 } |
| 59 | 53 |
| 60 // Adds an additional implicit branch from a throw-site at {throw_offset} to | |
| 61 // the corresponding exception handler at {handler_offset}. Note that such a | |
| 62 // branch must be a forward branch and has to target a known handler. | |
| 63 void AddExceptionalBranch(int throw_offset, int handler_offset); | |
| 64 | |
| 65 private: | 54 private: |
| 66 void AddBranch(int origin_offset, int target_offset); | 55 void AddBranch(int origin_offset, int target_offset); |
| 67 void AnalyzeExceptionHandlers(); | 56 void AnalyzeExceptionHandlers(); |
| 68 | 57 |
| 58 // Offsets of bytecodes having a backward branch to the bytecode at |offset|. |
| 59 const ZoneVector<int>* BackwardBranchesTargetting(int offset) const; |
| 60 |
| 61 // Offsets of bytecodes having a forward branch to the bytecode at |offset|. |
| 62 const ZoneVector<int>* ForwardBranchesTargetting(int offset) const; |
| 63 |
| 69 Zone* zone() const { return zone_; } | 64 Zone* zone() const { return zone_; } |
| 70 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } | 65 Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; } |
| 71 | 66 |
| 72 ZoneMap<int, BytecodeBranchInfo*> branch_infos_; | 67 ZoneMap<int, BytecodeBranchInfo*> branch_infos_; |
| 73 Handle<BytecodeArray> bytecode_array_; | 68 Handle<BytecodeArray> bytecode_array_; |
| 74 BitVector reachable_; | 69 BitVector reachable_; |
| 75 Zone* zone_; | 70 Zone* zone_; |
| 76 | 71 |
| 77 DISALLOW_COPY_AND_ASSIGN(BytecodeBranchAnalysis); | 72 DISALLOW_COPY_AND_ASSIGN(BytecodeBranchAnalysis); |
| 78 }; | 73 }; |
| 79 | 74 |
| 80 | 75 |
| 81 } // namespace compiler | 76 } // namespace compiler |
| 82 } // namespace internal | 77 } // namespace internal |
| 83 } // namespace v8 | 78 } // namespace v8 |
| 84 | 79 |
| 85 #endif // V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_ | 80 #endif // V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_ |
| OLD | NEW |