Commit 8d940b91 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[ignition] Use dead code elimination for implicit returns

Rather than manually tracking basic blocks in the bytecode array builder,
use the existing dead code elimination to generate an implicit return iff
the block ending the bytecode is not dead by the time all statements have
been visited.

Change-Id: I9520486a523ec4e01bc203e9a847eb1f57b130b6
Reviewed-on: https://chromium-review.googlesource.com/c/1494756Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59951}
parent 919e6b4f
......@@ -47,7 +47,6 @@ BytecodeArrayBuilder::BytecodeArrayBuilder(
bytecode_generated_(false),
constant_array_builder_(zone),
handler_table_builder_(zone),
return_seen_in_block_(false),
parameter_count_(parameter_count),
local_register_count_(locals_count),
register_allocator_(fixed_register_count()),
......@@ -82,7 +81,7 @@ Register BytecodeArrayBuilder::Local(int index) const {
}
Handle<BytecodeArray> BytecodeArrayBuilder::ToBytecodeArray(Isolate* isolate) {
DCHECK(return_seen_in_block_);
DCHECK(RemainderOfBlockIsDead());
DCHECK(!bytecode_generated_);
bytecode_generated_ = true;
......@@ -339,7 +338,6 @@ class BytecodeNodeBuilder {
DCHECK(Bytecodes::IsForwardJump(Bytecode::k##name)); \
BytecodeNode node(Create##name##Node(operands...)); \
WriteJump(&node, label); \
LeaveBasicBlock(); \
}
BYTECODE_LIST(DEFINE_BYTECODE_OUTPUT)
#undef DEFINE_BYTECODE_OUTPUT
......@@ -356,7 +354,6 @@ void BytecodeArrayBuilder::OutputSwitchOnSmiNoFeedback(
jump_table->constant_pool_index(), jump_table->size(),
jump_table->case_value_base()));
WriteSwitch(&node, jump_table);
LeaveBasicBlock();
}
BytecodeArrayBuilder& BytecodeArrayBuilder::BinaryOperation(Token::Value op,
......@@ -1073,7 +1070,6 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::Bind(BytecodeLabel* label) {
// expected registers are valid when jumping to this label.
if (register_optimizer_) register_optimizer_->Flush();
bytecode_array_writer_.BindLabel(label);
LeaveBasicBlock();
return *this;
}
......@@ -1083,7 +1079,6 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::Bind(
// registers are valid when jumping to the loop header.
if (register_optimizer_) register_optimizer_->Flush();
bytecode_array_writer_.BindLoopHeader(loop_header);
LeaveBasicBlock();
return *this;
}
......@@ -1093,7 +1088,6 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::Bind(BytecodeJumpTable* jump_table,
// all expected registers are valid when jumping to this location.
if (register_optimizer_) register_optimizer_->Flush();
bytecode_array_writer_.BindJumpTableEntry(jump_table, case_value);
LeaveBasicBlock();
return *this;
}
......@@ -1278,7 +1272,6 @@ BytecodeArrayBuilder& BytecodeArrayBuilder::Abort(AbortReason reason) {
BytecodeArrayBuilder& BytecodeArrayBuilder::Return() {
OutputReturn();
return_seen_in_block_ = true;
return *this;
}
......
......@@ -521,7 +521,6 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final {
}
}
bool RequiresImplicitReturn() const { return !return_seen_in_block_; }
bool RemainderOfBlockIsDead() const {
return bytecode_array_writer_.RemainderOfBlockIsDead();
}
......@@ -598,8 +597,6 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final {
template <Bytecode bytecode, AccumulatorUse accumulator_use>
void PrepareToOutputBytecode();
void LeaveBasicBlock() { return_seen_in_block_ = false; }
BytecodeArrayWriter* bytecode_array_writer() {
return &bytecode_array_writer_;
}
......@@ -618,7 +615,6 @@ class V8_EXPORT_PRIVATE BytecodeArrayBuilder final {
bool bytecode_generated_;
ConstantArrayBuilder constant_array_builder_;
HandlerTableBuilder handler_table_builder_;
bool return_seen_in_block_;
int parameter_count_;
int local_register_count_;
BytecodeRegisterAllocator register_allocator_;
......
......@@ -1093,7 +1093,7 @@ void BytecodeGenerator::GenerateBytecode(uintptr_t stack_limit) {
}
// Check that we are not falling off the end.
DCHECK(!builder()->RequiresImplicitReturn());
DCHECK(builder()->RemainderOfBlockIsDead());
}
void BytecodeGenerator::GenerateBytecodeBody() {
......@@ -1153,7 +1153,7 @@ void BytecodeGenerator::GenerateBytecodeBody() {
// Emit an implicit return instruction in case control flow can fall off the
// end of the function without an explicit return being present on all paths.
if (builder()->RequiresImplicitReturn()) {
if (!builder()->RemainderOfBlockIsDead()) {
builder()->LoadUndefined();
BuildReturn();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment