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

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

Issue 1985033002: [Interpreter] Change LogicalNot to ToBooleanLogicalNot and add non-ToBoolean version. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase Created 4 years, 7 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-array-builder.cc ('k') | src/interpreter/bytecodes.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/interpreter/constant-array-builder.h" 7 #include "src/interpreter/constant-array-builder.h"
8 #include "src/objects-inl.h" 8 #include "src/objects-inl.h"
9 #include "src/objects.h" 9 #include "src/objects.h"
10 10
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 88
89 bool BytecodePeepholeOptimizer::LastBytecodePutsNameInAccumulator() const { 89 bool BytecodePeepholeOptimizer::LastBytecodePutsNameInAccumulator() const {
90 DCHECK(LastIsValid()); 90 DCHECK(LastIsValid());
91 return (last_.bytecode() == Bytecode::kTypeOf || 91 return (last_.bytecode() == Bytecode::kTypeOf ||
92 last_.bytecode() == Bytecode::kToName || 92 last_.bytecode() == Bytecode::kToName ||
93 (last_.bytecode() == Bytecode::kLdaConstant && 93 (last_.bytecode() == Bytecode::kLdaConstant &&
94 GetConstantForIndexOperand(&last_, 0)->IsName())); 94 GetConstantForIndexOperand(&last_, 0)->IsName()));
95 } 95 }
96 96
97 void BytecodePeepholeOptimizer::UpdateCurrentBytecode(BytecodeNode* current) { 97 void BytecodePeepholeOptimizer::UpdateCurrentBytecode(BytecodeNode* current) {
98 // Conditional jumps with boolean conditions are emiitted in
99 // ToBoolean form by the bytecode array builder,
100 // i.e. JumpIfToBooleanTrue rather JumpIfTrue. The ToBoolean element
101 // can be removed if the previous bytecode put a boolean value in
102 // the accumulator.
103 if (Bytecodes::IsJumpIfToBoolean(current->bytecode()) && 98 if (Bytecodes::IsJumpIfToBoolean(current->bytecode()) &&
104 Bytecodes::WritesBooleanToAccumulator(last_.bytecode())) { 99 Bytecodes::WritesBooleanToAccumulator(last_.bytecode())) {
100 // Conditional jumps with boolean conditions are emitted in
101 // ToBoolean form by the bytecode array builder,
102 // i.e. JumpIfToBooleanTrue rather JumpIfTrue. The ToBoolean element
103 // can be removed if the previous bytecode put a boolean value in
104 // the accumulator.
105 Bytecode jump = Bytecodes::GetJumpWithoutToBoolean(current->bytecode()); 105 Bytecode jump = Bytecodes::GetJumpWithoutToBoolean(current->bytecode());
106 current->set_bytecode(jump, current->operand(0), current->operand_scale()); 106 current->set_bytecode(jump, current->operand(0), current->operand_scale());
107 } else if (current->bytecode() == Bytecode::kToBooleanLogicalNot &&
108 Bytecodes::WritesBooleanToAccumulator(last_.bytecode())) {
109 // Logical-nots are emitted in ToBoolean form by the bytecode array
110 // builder, The ToBoolean element can be removed if the previous bytecode
111 // put a boolean value in the accumulator.
112 current->set_bytecode(Bytecode::kLogicalNot);
107 } 113 }
108 } 114 }
109 115
110 bool BytecodePeepholeOptimizer::CanElideCurrent( 116 bool BytecodePeepholeOptimizer::CanElideCurrent(
111 const BytecodeNode* const current) const { 117 const BytecodeNode* const current) const {
112 if (Bytecodes::IsLdarOrStar(last_.bytecode()) && 118 if (Bytecodes::IsLdarOrStar(last_.bytecode()) &&
113 Bytecodes::IsLdarOrStar(current->bytecode()) && 119 Bytecodes::IsLdarOrStar(current->bytecode()) &&
114 current->operand(0) == last_.operand(0)) { 120 current->operand(0) == last_.operand(0)) {
115 // Ldar and Star make the accumulator and register hold equivalent 121 // Ldar and Star make the accumulator and register hold equivalent
116 // values. Only the first bytecode is needed if there's a sequence 122 // values. Only the first bytecode is needed if there's a sequence
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 current->source_info().Update(last_.source_info()); 169 current->source_info().Update(last_.source_info());
164 } 170 }
165 InvalidateLast(); 171 InvalidateLast();
166 } 172 }
167 return current; 173 return current;
168 } 174 }
169 175
170 } // namespace interpreter 176 } // namespace interpreter
171 } // namespace internal 177 } // namespace internal
172 } // namespace v8 178 } // namespace v8
OLDNEW
« no previous file with comments | « src/interpreter/bytecode-array-builder.cc ('k') | src/interpreter/bytecodes.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698