Chromium Code Reviews| Index: src/interpreter/bytecode-pipeline.cc |
| diff --git a/src/interpreter/bytecode-pipeline.cc b/src/interpreter/bytecode-pipeline.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b1452d230de1fb96e19c9abf731a808e15e92fa3 |
| --- /dev/null |
| +++ b/src/interpreter/bytecode-pipeline.cc |
| @@ -0,0 +1,155 @@ |
| +// 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/interpreter/bytecode-pipeline.h" |
| + |
| +#include <iomanip> |
| +#include "src/interpreter/source-position-table.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| +namespace interpreter { |
| + |
| +void BytecodeSourceInfo::Update(const BytecodeSourceInfo& entry) { |
| + DCHECK(entry.is_valid()); |
| + if (!is_valid() || (entry.is_statement() && !is_statement()) || |
| + (entry.is_statement() && is_statement() && |
| + entry.source_position() > source_position())) { |
| + // Position is updated if there is no existing position. Or the |
| + // incoming position is a statement and the current position is an |
| + // expression. Or we already have a statement and incoming |
| + // statement is later. This last piece is needed for the first |
| + // statement in a function. |
| + source_position_ = entry.source_position_; |
| + is_statement_ = entry.is_statement_; |
| + } |
| +} |
| + |
| +BytecodeNode::BytecodeNode(BytecodeNodeAllocator* allocator) |
| + : bytecode_(Bytecode::kIllegal), |
| + operand_scale_(OperandScale::kSingle), |
| + allocator_(allocator) {} |
| + |
| +void BytecodeNode::set_bytecode(Bytecode bytecode) { |
| + DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0); |
| + bytecode_ = bytecode; |
| + operand_scale_ = OperandScale::kSingle; |
| +} |
| + |
| +void BytecodeNode::set_bytecode(Bytecode bytecode, uint32_t operand0, |
| + OperandScale operand_scale) { |
| + DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 1); |
| + bytecode_ = bytecode; |
| + operands_[0] = operand0; |
| + operand_scale_ = operand_scale; |
| +} |
| + |
| +void BytecodeNode::set_bytecode(Bytecode bytecode, uint32_t operand0, |
| + uint32_t operand1, OperandScale operand_scale) { |
| + DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 2); |
| + bytecode_ = bytecode; |
| + operands_[0] = operand0; |
| + operands_[1] = operand1; |
| + operand_scale_ = operand_scale; |
| +} |
| + |
| +void BytecodeNode::set_bytecode(Bytecode bytecode, uint32_t operand0, |
| + uint32_t operand1, uint32_t operand2, |
| + OperandScale operand_scale) { |
| + DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 3); |
| + bytecode_ = bytecode; |
| + operands_[0] = operand0; |
| + operands_[1] = operand1; |
| + operands_[2] = operand2; |
| + operand_scale_ = operand_scale; |
| +} |
| + |
| +void BytecodeNode::set_bytecode(Bytecode bytecode, uint32_t operand0, |
| + uint32_t operand1, uint32_t operand2, |
| + uint32_t operand3, OperandScale operand_scale) { |
| + DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 4); |
| + bytecode_ = bytecode; |
| + operands_[0] = operand0; |
| + operands_[1] = operand1; |
| + operands_[2] = operand2; |
| + operands_[3] = operand3; |
| + operand_scale_ = operand_scale; |
| +} |
| + |
| +void BytecodeNode::replace_bytecode(Bytecode bytecode) { |
| + if (bytecode == Bytecode::kNop) { |
| + bytecode_ = bytecode; |
| + operand_scale_ = OperandScale::kSingle; |
| + return; |
| + } |
| + |
| + if (Bytecodes::IsJump(bytecode) && Bytecodes::IsJump(bytecode_) && |
| + Bytecodes::GetOperandType(bytecode, 0) == |
| + Bytecodes::GetOperandType(bytecode_, 0)) { |
|
rmcilroy
2016/05/10 11:14:10
I think we should only do these checks as DCHECKS
oth
2016/05/11 13:17:31
The semantics of CanReplace will be too cryptic aw
rmcilroy
2016/05/12 12:15:13
Works for me.
|
| + bytecode_ = bytecode; |
| + return; |
| + } |
| + |
| + UNREACHABLE(); |
| +} |
| + |
| +size_t BytecodeNode::Size() const { |
| + size_t size = Bytecodes::Size(bytecode_, operand_scale_); |
| + if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale_)) { |
| + size += 1; |
| + } |
| + return size; |
| +} |
| + |
| +void BytecodeNode::Release() { |
| + bytecode_ = Bytecode::kIllegal; |
| + source_info_.set_invalid(); |
| + allocator_->Release(this); |
| +} |
| + |
| +void BytecodeNode::Print(std::ostream& os) { |
| +#ifdef DEBUG |
| + std::ios saved_state(nullptr); |
| + saved_state.copyfmt(os); |
| + |
| + os << Bytecodes::ToString(bytecode_); |
| + if (Bytecodes::OperandScaleRequiresPrefixBytecode(operand_scale_)) { |
| + Bytecode scale_prefix = |
| + Bytecodes::OperandScaleToPrefixBytecode(operand_scale_); |
| + os << '.' << Bytecodes::ToString(scale_prefix); |
| + } |
| + |
| + for (int i = 0; i < operand_count(); ++i) { |
| + os << ' ' << std::setw(8) << std::setfill('0') << std::hex << operands_[i]; |
| + } |
| + os.copyfmt(saved_state); |
| + |
| + if (source_info_.is_valid()) { |
| + char type = source_info_.is_statement() ? 'S' : 'E'; |
| + os << ' ' << type << '@' << source_info_.source_position(); |
| + } |
| + os << '\n'; |
| +#endif // DEBUG |
| +} |
| + |
| +BytecodeNode* BytecodeNodeAllocator::Allocate() { |
| + if (free_list_ != nullptr) { |
| + BytecodeNode* node = free_list_; |
| + free_list_ = free_list_->next_; |
| + return node; |
| + } else { |
| + DCHECK_LT(allocation_count_, kMaxDebugAllocations); |
| + allocation_count_++; |
| + return new (zone()) BytecodeNode(this); |
| + } |
| +} |
| + |
| +void BytecodeNodeAllocator::Release(BytecodeNode* node) { |
| + node->next_ = free_list_; |
| + free_list_ = node; |
| +} |
| + |
| +} // namespace interpreter |
| +} // namespace internal |
| +} // namespace v8 |