Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(14)

Unified Diff: src/interpreter/bytecode-dead-code-optimizer.cc

Issue 2038083002: [Interpreter] Add a simple dead-code elimination bytecode optimizer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@int_jump_writer
Patch Set: Fix tests Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/interpreter/bytecode-dead-code-optimizer.h ('k') | src/v8.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/interpreter/bytecode-dead-code-optimizer.cc
diff --git a/src/interpreter/bytecode-dead-code-optimizer.cc b/src/interpreter/bytecode-dead-code-optimizer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..964d2a83aae2a797cfefe2c6f2dca2eed555eb48
--- /dev/null
+++ b/src/interpreter/bytecode-dead-code-optimizer.cc
@@ -0,0 +1,77 @@
+// 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.
+
+#include "src/interpreter/bytecode-dead-code-optimizer.h"
+
+namespace v8 {
+namespace internal {
+namespace interpreter {
+
+BytecodeDeadCodeOptimizer::BytecodeDeadCodeOptimizer(
+ BytecodePipelineStage* next_stage)
+ : next_stage_(next_stage), exit_seen_in_block_(false) {}
+
+// override
+Handle<BytecodeArray> BytecodeDeadCodeOptimizer::ToBytecodeArray(
+ int fixed_register_count, int parameter_count,
+ Handle<FixedArray> handler_table) {
+ return next_stage_->ToBytecodeArray(fixed_register_count, parameter_count,
+ handler_table);
+}
+
+// override
+void BytecodeDeadCodeOptimizer::Write(BytecodeNode* node) {
+ // Don't emit dead code.
+ if (exit_seen_in_block_) return;
+
+ switch (node->bytecode()) {
+ case Bytecode::kReturn:
+ case Bytecode::kThrow:
+ case Bytecode::kReThrow:
+ exit_seen_in_block_ = true;
+ break;
+ default:
+ break;
+ }
+
+ next_stage_->Write(node);
+}
+
+// override
+void BytecodeDeadCodeOptimizer::WriteJump(BytecodeNode* node,
+ BytecodeLabel* label) {
+ // Don't emit dead code.
+ // TODO(rmcilroy): For forward jumps we could mark the label as dead, thereby
+ // avoiding emitting dead code when we bind the label.
+ if (exit_seen_in_block_) return;
+
+ switch (node->bytecode()) {
+ case Bytecode::kJump:
+ case Bytecode::kJumpConstant:
+ exit_seen_in_block_ = true;
+ break;
+ default:
+ break;
+ }
+
+ next_stage_->WriteJump(node, label);
+}
+
+// override
+void BytecodeDeadCodeOptimizer::BindLabel(BytecodeLabel* label) {
+ next_stage_->BindLabel(label);
+ exit_seen_in_block_ = false;
+}
+
+// override
+void BytecodeDeadCodeOptimizer::BindLabel(const BytecodeLabel& target,
+ BytecodeLabel* label) {
+ next_stage_->BindLabel(target, label);
+ // exit_seen_in_block_ was reset when target was bound, so shouldn't be
+ // changed here.
+}
+
+} // namespace interpreter
+} // namespace internal
+} // namespace v8
« no previous file with comments | « src/interpreter/bytecode-dead-code-optimizer.h ('k') | src/v8.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698