OLD | NEW |
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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
177 // | 177 // |
178 // An example transformation here would be: | 178 // An example transformation here would be: |
179 // | 179 // |
180 // LdaGlobal i0, i1 ____\ LdrGlobal i0, i1, R | 180 // LdaGlobal i0, i1 ____\ LdrGlobal i0, i1, R |
181 // Star R ====/ Ldar R | 181 // Star R ====/ Ldar R |
182 // | 182 // |
183 // which loads a global value into both a register and the | 183 // which loads a global value into both a register and the |
184 // accumulator. However, in the second form the Ldar can often be | 184 // accumulator. However, in the second form the Ldar can often be |
185 // peephole optimized away unlike the Star in the first form. | 185 // peephole optimized away unlike the Star in the first form. |
186 // | 186 // |
187 last->Transform(new_bytecode, current->operand(0), current->operand_scale()); | 187 last->Transform(new_bytecode, current->operand(0)); |
188 current->set_bytecode(Bytecode::kLdar, current->operand(0), | 188 current->set_bytecode(Bytecode::kLdar, current->operand(0)); |
189 current->operand_scale()); | |
190 } | 189 } |
191 | 190 |
192 } // namespace | 191 } // namespace |
193 | 192 |
194 bool BytecodePeepholeOptimizer::TransformLastAndCurrentBytecodes( | 193 bool BytecodePeepholeOptimizer::TransformLastAndCurrentBytecodes( |
195 BytecodeNode* const current) { | 194 BytecodeNode* const current) { |
196 if (current->bytecode() == Bytecode::kStar && | 195 if (current->bytecode() == Bytecode::kStar && |
197 !current->source_info().is_statement()) { | 196 !current->source_info().is_statement()) { |
198 // Note: If the Star is tagged with a statement position, we can't | 197 // Note: If the Star is tagged with a statement position, we can't |
199 // perform this transform as the store to the register will | 198 // perform this transform as the store to the register will |
(...skipping 25 matching lines...) Expand all Loading... |
225 BytecodeNode* const current) { | 224 BytecodeNode* const current) { |
226 bool can_remove = Bytecodes::IsJumpIfToBoolean(current->bytecode()) && | 225 bool can_remove = Bytecodes::IsJumpIfToBoolean(current->bytecode()) && |
227 Bytecodes::WritesBooleanToAccumulator(last_.bytecode()); | 226 Bytecodes::WritesBooleanToAccumulator(last_.bytecode()); |
228 if (can_remove) { | 227 if (can_remove) { |
229 // Conditional jumps with boolean conditions are emiitted in | 228 // Conditional jumps with boolean conditions are emiitted in |
230 // ToBoolean form by the bytecode array builder, | 229 // ToBoolean form by the bytecode array builder, |
231 // i.e. JumpIfToBooleanTrue rather JumpIfTrue. The ToBoolean | 230 // i.e. JumpIfToBooleanTrue rather JumpIfTrue. The ToBoolean |
232 // element can be removed if the previous bytecode put a boolean | 231 // element can be removed if the previous bytecode put a boolean |
233 // value in the accumulator. | 232 // value in the accumulator. |
234 Bytecode jump = Bytecodes::GetJumpWithoutToBoolean(current->bytecode()); | 233 Bytecode jump = Bytecodes::GetJumpWithoutToBoolean(current->bytecode()); |
235 current->set_bytecode(jump, current->operand(0), current->operand_scale()); | 234 current->set_bytecode(jump, current->operand(0)); |
236 } | 235 } |
237 return can_remove; | 236 return can_remove; |
238 } | 237 } |
239 | 238 |
240 bool BytecodePeepholeOptimizer::RemoveToBooleanFromLogicalNot( | 239 bool BytecodePeepholeOptimizer::RemoveToBooleanFromLogicalNot( |
241 BytecodeNode* const current) { | 240 BytecodeNode* const current) { |
242 bool can_remove = current->bytecode() == Bytecode::kToBooleanLogicalNot && | 241 bool can_remove = current->bytecode() == Bytecode::kToBooleanLogicalNot && |
243 Bytecodes::WritesBooleanToAccumulator(last_.bytecode()); | 242 Bytecodes::WritesBooleanToAccumulator(last_.bytecode()); |
244 if (can_remove) { | 243 if (can_remove) { |
245 // Logical-nots are emitted in ToBoolean form by the bytecode array | 244 // Logical-nots are emitted in ToBoolean form by the bytecode array |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 next_stage_->Write(&last_); | 315 next_stage_->Write(&last_); |
317 InvalidateLast(); | 316 InvalidateLast(); |
318 } | 317 } |
319 } | 318 } |
320 return current; | 319 return current; |
321 } | 320 } |
322 | 321 |
323 } // namespace interpreter | 322 } // namespace interpreter |
324 } // namespace internal | 323 } // namespace internal |
325 } // namespace v8 | 324 } // namespace v8 |
OLD | NEW |