bytecode-branch-analysis.cc 1.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
// 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.

#include "src/compiler/bytecode-branch-analysis.h"

#include "src/interpreter/bytecode-array-iterator.h"
#include "src/objects-inl.h"

namespace v8 {
namespace internal {
namespace compiler {

BytecodeBranchAnalysis::BytecodeBranchAnalysis(
    Handle<BytecodeArray> bytecode_array, Zone* zone)
16 17 18
    : bytecode_array_(bytecode_array),
      is_backward_target_(bytecode_array->length(), zone),
      is_forward_target_(bytecode_array->length(), zone),
19 20 21 22 23 24 25
      zone_(zone) {}

void BytecodeBranchAnalysis::Analyze() {
  interpreter::BytecodeArrayIterator iterator(bytecode_array());
  while (!iterator.done()) {
    interpreter::Bytecode bytecode = iterator.current_bytecode();
    int current_offset = iterator.current_offset();
26 27
    if (interpreter::Bytecodes::IsJump(bytecode)) {
      AddBranch(current_offset, iterator.GetJumpTargetOffset());
28 29 30 31 32 33
    }
    iterator.Advance();
  }
}

void BytecodeBranchAnalysis::AddBranch(int source_offset, int target_offset) {
34 35
  if (source_offset < target_offset) {
    is_forward_target_.Add(target_offset);
36
  } else {
37
    is_backward_target_.Add(target_offset);
38 39 40 41 42 43
  }
}

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