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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « src/interpreter/bytecode-dead-code-optimizer.h ('k') | src/v8.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/interpreter/bytecode-dead-code-optimizer.h"
6
7 namespace v8 {
8 namespace internal {
9 namespace interpreter {
10
11 BytecodeDeadCodeOptimizer::BytecodeDeadCodeOptimizer(
12 BytecodePipelineStage* next_stage)
13 : next_stage_(next_stage), exit_seen_in_block_(false) {}
14
15 // override
16 Handle<BytecodeArray> BytecodeDeadCodeOptimizer::ToBytecodeArray(
17 int fixed_register_count, int parameter_count,
18 Handle<FixedArray> handler_table) {
19 return next_stage_->ToBytecodeArray(fixed_register_count, parameter_count,
20 handler_table);
21 }
22
23 // override
24 void BytecodeDeadCodeOptimizer::Write(BytecodeNode* node) {
25 // Don't emit dead code.
26 if (exit_seen_in_block_) return;
27
28 switch (node->bytecode()) {
29 case Bytecode::kReturn:
30 case Bytecode::kThrow:
31 case Bytecode::kReThrow:
32 exit_seen_in_block_ = true;
33 break;
34 default:
35 break;
36 }
37
38 next_stage_->Write(node);
39 }
40
41 // override
42 void BytecodeDeadCodeOptimizer::WriteJump(BytecodeNode* node,
43 BytecodeLabel* label) {
44 // Don't emit dead code.
45 // TODO(rmcilroy): For forward jumps we could mark the label as dead, thereby
46 // avoiding emitting dead code when we bind the label.
47 if (exit_seen_in_block_) return;
48
49 switch (node->bytecode()) {
50 case Bytecode::kJump:
51 case Bytecode::kJumpConstant:
52 exit_seen_in_block_ = true;
53 break;
54 default:
55 break;
56 }
57
58 next_stage_->WriteJump(node, label);
59 }
60
61 // override
62 void BytecodeDeadCodeOptimizer::BindLabel(BytecodeLabel* label) {
63 next_stage_->BindLabel(label);
64 exit_seen_in_block_ = false;
65 }
66
67 // override
68 void BytecodeDeadCodeOptimizer::BindLabel(const BytecodeLabel& target,
69 BytecodeLabel* label) {
70 next_stage_->BindLabel(target, label);
71 // exit_seen_in_block_ was reset when target was bound, so shouldn't be
72 // changed here.
73 }
74
75 } // namespace interpreter
76 } // namespace internal
77 } // namespace v8
OLDNEW
« 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