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

Side by Side Diff: src/interpreter/bytecode-peephole-optimizer.cc

Issue 2793923002: [Interpreter] Optimize code of the form 'if (x === undefined)'. (Closed)
Patch Set: Rebase Created 3 years, 8 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-generator.cc ('k') | src/interpreter/bytecode-peephole-table.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/interpreter/bytecode-peephole-optimizer.h" 5 #include "src/interpreter/bytecode-peephole-optimizer.h"
6 6
7 #include "src/objects-inl.h" 7 #include "src/objects-inl.h"
8 #include "src/objects.h" 8 #include "src/objects.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 BytecodeNode* const current) { 134 BytecodeNode* const current) {
135 DCHECK_EQ(last->bytecode(), Bytecode::kLdaZero); 135 DCHECK_EQ(last->bytecode(), Bytecode::kLdaZero);
136 BytecodeNode node(new_bytecode, 0, current->operand(0), current->operand(1), 136 BytecodeNode node(new_bytecode, 0, current->operand(0), current->operand(1),
137 current->source_info()); 137 current->source_info());
138 if (last->source_info().is_valid()) { 138 if (last->source_info().is_valid()) {
139 node.set_source_info(last->source_info()); 139 node.set_source_info(last->source_info());
140 } 140 }
141 return node; 141 return node;
142 } 142 }
143 143
144 BytecodeNode TransformEqualityWithNullOrUndefined(Bytecode new_bytecode,
145 BytecodeNode* const last,
146 BytecodeNode* const current) {
147 DCHECK((last->bytecode() == Bytecode::kLdaNull) ||
148 (last->bytecode() == Bytecode::kLdaUndefined));
149 DCHECK((current->bytecode() == Bytecode::kTestEqual) ||
150 (current->bytecode() == Bytecode::kTestEqualStrict));
151 BytecodeNode node(new_bytecode, current->operand(0), current->source_info());
152 if (last->source_info().is_valid()) {
153 node.set_source_info(last->source_info());
154 }
155 return node;
156 }
157
158 } // namespace 144 } // namespace
159 145
160 void BytecodePeepholeOptimizer::DefaultAction( 146 void BytecodePeepholeOptimizer::DefaultAction(
161 BytecodeNode* const node, const PeepholeActionAndData* action_data) { 147 BytecodeNode* const node, const PeepholeActionAndData* action_data) {
162 DCHECK(LastIsValid()); 148 DCHECK(LastIsValid());
163 DCHECK(!Bytecodes::IsJump(node->bytecode())); 149 DCHECK(!Bytecodes::IsJump(node->bytecode()));
164 150
165 next_stage()->Write(last()); 151 next_stage()->Write(last());
166 SetLast(node); 152 SetLast(node);
167 } 153 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 if (!node->source_info().is_valid() || !last()->source_info().is_valid()) { 247 if (!node->source_info().is_valid() || !last()->source_info().is_valid()) {
262 // Fused last and current into current. 248 // Fused last and current into current.
263 BytecodeNode new_node(TransformLdaZeroBinaryOpToBinaryOpWithZero( 249 BytecodeNode new_node(TransformLdaZeroBinaryOpToBinaryOpWithZero(
264 action_data->bytecode, last(), node)); 250 action_data->bytecode, last(), node));
265 SetLast(&new_node); 251 SetLast(&new_node);
266 } else { 252 } else {
267 DefaultAction(node); 253 DefaultAction(node);
268 } 254 }
269 } 255 }
270 256
271 void BytecodePeepholeOptimizer::TransformEqualityWithNullOrUndefinedAction(
272 BytecodeNode* const node, const PeepholeActionAndData* action_data) {
273 DCHECK(LastIsValid());
274 DCHECK(!Bytecodes::IsJump(node->bytecode()));
275 // Fused last and current into current.
276 BytecodeNode new_node(TransformEqualityWithNullOrUndefined(
277 action_data->bytecode, last(), node));
278 SetLast(&new_node);
279 }
280
281 void BytecodePeepholeOptimizer::DefaultJumpAction( 257 void BytecodePeepholeOptimizer::DefaultJumpAction(
282 BytecodeNode* const node, const PeepholeActionAndData* action_data) { 258 BytecodeNode* const node, const PeepholeActionAndData* action_data) {
283 DCHECK(LastIsValid()); 259 DCHECK(LastIsValid());
284 DCHECK(Bytecodes::IsJump(node->bytecode())); 260 DCHECK(Bytecodes::IsJump(node->bytecode()));
285 261
286 next_stage()->Write(last()); 262 next_stage()->Write(last());
287 InvalidateLast(); 263 InvalidateLast();
288 } 264 }
289 265
290 void BytecodePeepholeOptimizer::UpdateLastJumpAction( 266 void BytecodePeepholeOptimizer::UpdateLastJumpAction(
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
333 #undef CASE 309 #undef CASE
334 default: 310 default:
335 UNREACHABLE(); 311 UNREACHABLE();
336 break; 312 break;
337 } 313 }
338 } 314 }
339 315
340 } // namespace interpreter 316 } // namespace interpreter
341 } // namespace internal 317 } // namespace internal
342 } // namespace v8 318 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-generator.cc ('k') | src/interpreter/bytecode-peephole-table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698