bytecode-branch-analysis.h 1.89 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
// Copyright 2015 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_
#define V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_

#include "src/bit-vector.h"
#include "src/handles.h"

namespace v8 {
namespace internal {

class BytecodeArray;

namespace compiler {

18 19 20
// A class for identifying branch targets within a bytecode array.
// This information can be used to construct the local control flow
// logic for high-level IR graphs built from bytecode.
21
//
22 23 24
// N.B. If this class is used to determine loop headers, then such a
// usage relies on the only backwards branches in bytecode being jumps
// back to loop headers.
25 26 27 28 29 30 31 32 33 34 35 36
class BytecodeBranchAnalysis BASE_EMBEDDED {
 public:
  BytecodeBranchAnalysis(Handle<BytecodeArray> bytecode_array, Zone* zone);

  // Analyze the bytecodes to find the branch sites and their
  // targets. No other methods in this class return valid information
  // until this has been called.
  void Analyze();

  // Returns true if there are any forward branches to the bytecode at
  // |offset|.
  bool forward_branches_target(int offset) const {
37
    return is_forward_target_.Contains(offset);
38 39 40 41 42
  }

  // Returns true if there are any backward branches to the bytecode
  // at |offset|.
  bool backward_branches_target(int offset) const {
43
    return is_backward_target_.Contains(offset);
44 45 46 47 48 49 50 51 52
  }

 private:
  void AddBranch(int origin_offset, int target_offset);

  Zone* zone() const { return zone_; }
  Handle<BytecodeArray> bytecode_array() const { return bytecode_array_; }

  Handle<BytecodeArray> bytecode_array_;
53 54
  BitVector is_backward_target_;
  BitVector is_forward_target_;
55 56 57 58 59 60 61 62 63 64 65
  Zone* zone_;

  DISALLOW_COPY_AND_ASSIGN(BytecodeBranchAnalysis);
};


}  // namespace compiler
}  // namespace internal
}  // namespace v8

#endif  // V8_COMPILER_BYTECODE_BRANCH_ANALYSIS_H_