[interpreter] source positions should not be emitted for dead code.
R=mstarzinger@chromium.org Review URL: https://codereview.chromium.org/1668863002 Cr-Commit-Position: refs/heads/master@{#33775}
This commit is contained in:
parent
709be02b9f
commit
85eff14c37
@ -138,7 +138,10 @@ Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray() {
|
|||||||
template <size_t N>
|
template <size_t N>
|
||||||
void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) {
|
void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t(&operands)[N]) {
|
||||||
// Don't output dead code.
|
// Don't output dead code.
|
||||||
if (exit_seen_in_block_) return;
|
if (exit_seen_in_block_) {
|
||||||
|
source_position_table_builder_.RevertPosition(bytecodes()->size());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
int operand_count = static_cast<int>(N);
|
int operand_count = static_cast<int>(N);
|
||||||
DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count);
|
DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), operand_count);
|
||||||
@ -206,7 +209,10 @@ void BytecodeArrayBuilder::Output(Bytecode bytecode, uint32_t operand0) {
|
|||||||
|
|
||||||
void BytecodeArrayBuilder::Output(Bytecode bytecode) {
|
void BytecodeArrayBuilder::Output(Bytecode bytecode) {
|
||||||
// Don't output dead code.
|
// Don't output dead code.
|
||||||
if (exit_seen_in_block_) return;
|
if (exit_seen_in_block_) {
|
||||||
|
source_position_table_builder_.RevertPosition(bytecodes()->size());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
|
DCHECK_EQ(Bytecodes::NumberOfOperands(bytecode), 0);
|
||||||
last_bytecode_start_ = bytecodes()->size();
|
last_bytecode_start_ = bytecodes()->size();
|
||||||
@ -886,7 +892,10 @@ void BytecodeArrayBuilder::PatchJump(
|
|||||||
BytecodeArrayBuilder& BytecodeArrayBuilder::OutputJump(Bytecode jump_bytecode,
|
BytecodeArrayBuilder& BytecodeArrayBuilder::OutputJump(Bytecode jump_bytecode,
|
||||||
BytecodeLabel* label) {
|
BytecodeLabel* label) {
|
||||||
// Don't emit dead code.
|
// Don't emit dead code.
|
||||||
if (exit_seen_in_block_) return *this;
|
if (exit_seen_in_block_) {
|
||||||
|
source_position_table_builder_.RevertPosition(bytecodes()->size());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
// Check if the value in accumulator is boolean, if not choose an
|
// Check if the value in accumulator is boolean, if not choose an
|
||||||
// appropriate JumpIfToBoolean bytecode.
|
// appropriate JumpIfToBoolean bytecode.
|
||||||
@ -1210,14 +1219,14 @@ size_t BytecodeArrayBuilder::GetConstantPoolEntry(Handle<Object> object) {
|
|||||||
|
|
||||||
void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) {
|
void BytecodeArrayBuilder::SetStatementPosition(Statement* stmt) {
|
||||||
if (stmt->position() == RelocInfo::kNoPosition) return;
|
if (stmt->position() == RelocInfo::kNoPosition) return;
|
||||||
source_position_table_builder_.AddStatementPosition(
|
source_position_table_builder_.AddStatementPosition(bytecodes_.size(),
|
||||||
static_cast<int>(bytecodes_.size()), stmt->position());
|
stmt->position());
|
||||||
}
|
}
|
||||||
|
|
||||||
void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) {
|
void BytecodeArrayBuilder::SetExpressionPosition(Expression* expr) {
|
||||||
if (expr->position() == RelocInfo::kNoPosition) return;
|
if (expr->position() == RelocInfo::kNoPosition) return;
|
||||||
source_position_table_builder_.AddExpressionPosition(
|
source_position_table_builder_.AddExpressionPosition(bytecodes_.size(),
|
||||||
static_cast<int>(bytecodes_.size()), expr->position());
|
expr->position());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BytecodeArrayBuilder::TemporaryRegisterIsLive(Register reg) const {
|
bool BytecodeArrayBuilder::TemporaryRegisterIsLive(Register reg) const {
|
||||||
|
@ -15,20 +15,32 @@ namespace interpreter {
|
|||||||
class IsStatementField : public BitField<bool, 0, 1> {};
|
class IsStatementField : public BitField<bool, 0, 1> {};
|
||||||
class SourcePositionField : public BitField<int, 1, 30> {};
|
class SourcePositionField : public BitField<int, 1, 30> {};
|
||||||
|
|
||||||
void SourcePositionTableBuilder::AddStatementPosition(int bytecode_offset,
|
void SourcePositionTableBuilder::AddStatementPosition(size_t bytecode_offset,
|
||||||
int source_position) {
|
int source_position) {
|
||||||
AssertMonotonic(bytecode_offset);
|
int offset = static_cast<int>(bytecode_offset);
|
||||||
|
AssertMonotonic(offset);
|
||||||
uint32_t encoded = IsStatementField::encode(true) |
|
uint32_t encoded = IsStatementField::encode(true) |
|
||||||
SourcePositionField::encode(source_position);
|
SourcePositionField::encode(source_position);
|
||||||
entries_.push_back({bytecode_offset, encoded});
|
entries_.push_back({offset, encoded});
|
||||||
}
|
}
|
||||||
|
|
||||||
void SourcePositionTableBuilder::AddExpressionPosition(int bytecode_offset,
|
void SourcePositionTableBuilder::AddExpressionPosition(size_t bytecode_offset,
|
||||||
int source_position) {
|
int source_position) {
|
||||||
AssertMonotonic(bytecode_offset);
|
int offset = static_cast<int>(bytecode_offset);
|
||||||
|
AssertMonotonic(offset);
|
||||||
uint32_t encoded = IsStatementField::encode(false) |
|
uint32_t encoded = IsStatementField::encode(false) |
|
||||||
SourcePositionField::encode(source_position);
|
SourcePositionField::encode(source_position);
|
||||||
entries_.push_back({bytecode_offset, encoded});
|
entries_.push_back({offset, encoded});
|
||||||
|
}
|
||||||
|
|
||||||
|
void SourcePositionTableBuilder::RevertPosition(size_t bytecode_offset) {
|
||||||
|
int offset = static_cast<int>(bytecode_offset);
|
||||||
|
// If we already added a source position table entry, but the bytecode array
|
||||||
|
// builder ended up not outputting a bytecode for the corresponding bytecode
|
||||||
|
// offset, we have to remove that entry.
|
||||||
|
if (entries_.size() > 0 && entries_.back().bytecode_offset == offset) {
|
||||||
|
entries_.pop_back();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle<FixedArray> SourcePositionTableBuilder::ToFixedArray() {
|
Handle<FixedArray> SourcePositionTableBuilder::ToFixedArray() {
|
||||||
|
@ -24,8 +24,9 @@ class SourcePositionTableBuilder {
|
|||||||
explicit SourcePositionTableBuilder(Isolate* isolate, Zone* zone)
|
explicit SourcePositionTableBuilder(Isolate* isolate, Zone* zone)
|
||||||
: isolate_(isolate), entries_(zone) {}
|
: isolate_(isolate), entries_(zone) {}
|
||||||
|
|
||||||
void AddStatementPosition(int bytecode_offset, int source_position);
|
void AddStatementPosition(size_t bytecode_offset, int source_position);
|
||||||
void AddExpressionPosition(int bytecode_offset, int source_position);
|
void AddExpressionPosition(size_t bytecode_offset, int source_position);
|
||||||
|
void RevertPosition(size_t bytecode_offset);
|
||||||
Handle<FixedArray> ToFixedArray();
|
Handle<FixedArray> ToFixedArray();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
9
test/mjsunit/ignition/dead-code-source-position.js
Normal file
9
test/mjsunit/ignition/dead-code-source-position.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Copyright 2016 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.
|
||||||
|
|
||||||
|
function f() {
|
||||||
|
for (f(x) in []) { f(new f()) }
|
||||||
|
}
|
||||||
|
|
||||||
|
f();
|
Loading…
Reference in New Issue
Block a user