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 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // | 176 // |
177 // An example transformation here would be: | 177 // An example transformation here would be: |
178 // | 178 // |
179 // LdaGlobal i0, i1 ____\ LdrGlobal i0, i1, R | 179 // LdaGlobal i0, i1 ____\ LdrGlobal i0, i1, R |
180 // Star R ====/ Ldar R | 180 // Star R ====/ Ldar R |
181 // | 181 // |
182 // which loads a global value into both a register and the | 182 // which loads a global value into both a register and the |
183 // accumulator. However, in the second form the Ldar can often be | 183 // accumulator. However, in the second form the Ldar can often be |
184 // peephole optimized away unlike the Star in the first form. | 184 // peephole optimized away unlike the Star in the first form. |
185 // | 185 // |
186 last->Transform(new_bytecode, current->operand(0), current->operand_scale()); | 186 last->Transform(new_bytecode, current->operand(0)); |
187 current->set_bytecode(Bytecode::kLdar, current->operand(0), | 187 current->set_bytecode(Bytecode::kLdar, current->operand(0)); |
188 current->operand_scale()); | |
189 | 188 |
190 // If there was a source position on |current| transfer it to the | 189 // If there was a source position on |current| transfer it to the |
191 // updated |last| to maintain the debugger's causal view. ie. if an | 190 // updated |last| to maintain the debugger's causal view. ie. if an |
192 // expression position LdrGlobal is the bytecode that could throw | 191 // expression position LdrGlobal is the bytecode that could throw |
193 // and if a statement position it needs to be placed before the | 192 // and if a statement position it needs to be placed before the |
194 // store to R occurs. | 193 // store to R occurs. |
195 last->source_info().Update(current->source_info()); | 194 last->source_info().Update(current->source_info()); |
196 current->source_info().set_invalid(); | 195 current->source_info().set_invalid(); |
197 } | 196 } |
198 | 197 |
(...skipping 28 matching lines...) Expand all Loading... |
227 BytecodeNode* const current) { | 226 BytecodeNode* const current) { |
228 bool can_remove = Bytecodes::IsJumpIfToBoolean(current->bytecode()) && | 227 bool can_remove = Bytecodes::IsJumpIfToBoolean(current->bytecode()) && |
229 Bytecodes::WritesBooleanToAccumulator(last_.bytecode()); | 228 Bytecodes::WritesBooleanToAccumulator(last_.bytecode()); |
230 if (can_remove) { | 229 if (can_remove) { |
231 // Conditional jumps with boolean conditions are emiitted in | 230 // Conditional jumps with boolean conditions are emiitted in |
232 // ToBoolean form by the bytecode array builder, | 231 // ToBoolean form by the bytecode array builder, |
233 // i.e. JumpIfToBooleanTrue rather JumpIfTrue. The ToBoolean | 232 // i.e. JumpIfToBooleanTrue rather JumpIfTrue. The ToBoolean |
234 // element can be removed if the previous bytecode put a boolean | 233 // element can be removed if the previous bytecode put a boolean |
235 // value in the accumulator. | 234 // value in the accumulator. |
236 Bytecode jump = Bytecodes::GetJumpWithoutToBoolean(current->bytecode()); | 235 Bytecode jump = Bytecodes::GetJumpWithoutToBoolean(current->bytecode()); |
237 current->set_bytecode(jump, current->operand(0), current->operand_scale()); | 236 current->set_bytecode(jump, current->operand(0)); |
238 } | 237 } |
239 return can_remove; | 238 return can_remove; |
240 } | 239 } |
241 | 240 |
242 bool BytecodePeepholeOptimizer::RemoveToBooleanFromLogicalNot( | 241 bool BytecodePeepholeOptimizer::RemoveToBooleanFromLogicalNot( |
243 BytecodeNode* const current) { | 242 BytecodeNode* const current) { |
244 bool can_remove = current->bytecode() == Bytecode::kToBooleanLogicalNot && | 243 bool can_remove = current->bytecode() == Bytecode::kToBooleanLogicalNot && |
245 Bytecodes::WritesBooleanToAccumulator(last_.bytecode()); | 244 Bytecodes::WritesBooleanToAccumulator(last_.bytecode()); |
246 if (can_remove) { | 245 if (can_remove) { |
247 // Logical-nots are emitted in ToBoolean form by the bytecode array | 246 // Logical-nots are emitted in ToBoolean form by the bytecode array |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 next_stage_->Write(&last_); | 316 next_stage_->Write(&last_); |
318 InvalidateLast(); | 317 InvalidateLast(); |
319 } | 318 } |
320 } | 319 } |
321 return current; | 320 return current; |
322 } | 321 } |
323 | 322 |
324 } // namespace interpreter | 323 } // namespace interpreter |
325 } // namespace internal | 324 } // namespace internal |
326 } // namespace v8 | 325 } // namespace v8 |
OLD | NEW |