| 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 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 namespace interpreter { | 13 namespace interpreter { |
| 14 | 14 |
| 15 BytecodePeepholeOptimizer::BytecodePeepholeOptimizer( | 15 BytecodePeepholeOptimizer::BytecodePeepholeOptimizer( |
| 16 ConstantArrayBuilder* constant_array_builder, | 16 ConstantArrayBuilder* constant_array_builder, |
| 17 BytecodePipelineStage* next_stage) | 17 BytecodePipelineStage* next_stage) |
| 18 : constant_array_builder_(constant_array_builder), | 18 : constant_array_builder_(constant_array_builder), |
| 19 next_stage_(next_stage), | 19 next_stage_(next_stage), |
| 20 last_(Bytecode::kNop), | |
| 21 last_is_valid_(false), | |
| 22 last_is_discardable_(false) { | 20 last_is_discardable_(false) { |
| 23 // TODO(oth): Remove last_is_valid_ and use kIllegal for last_ when | 21 InvalidateLast(); |
| 24 // not invalid. Currently blocked on bytecode generator emitting | |
| 25 // kIllegal for entry not found in jump table. | |
| 26 } | 22 } |
| 27 | 23 |
| 28 void BytecodePeepholeOptimizer::InvalidateLast() { last_is_valid_ = false; } | 24 void BytecodePeepholeOptimizer::InvalidateLast() { |
| 25 last_.set_bytecode(Bytecode::kIllegal); |
| 26 } |
| 29 | 27 |
| 30 bool BytecodePeepholeOptimizer::LastIsValid() const { return last_is_valid_; } | 28 bool BytecodePeepholeOptimizer::LastIsValid() const { |
| 29 return last_.bytecode() != Bytecode::kIllegal; |
| 30 } |
| 31 | 31 |
| 32 void BytecodePeepholeOptimizer::SetLast(const BytecodeNode* const node) { | 32 void BytecodePeepholeOptimizer::SetLast(const BytecodeNode* const node) { |
| 33 last_.Clone(node); | 33 last_.Clone(node); |
| 34 last_is_valid_ = true; | |
| 35 last_is_discardable_ = true; | 34 last_is_discardable_ = true; |
| 36 } | 35 } |
| 37 | 36 |
| 38 // override | 37 // override |
| 39 size_t BytecodePeepholeOptimizer::FlushForOffset() { | 38 size_t BytecodePeepholeOptimizer::FlushForOffset() { |
| 40 size_t buffered_size = next_stage_->FlushForOffset(); | 39 size_t buffered_size = next_stage_->FlushForOffset(); |
| 41 if (LastIsValid()) { | 40 if (LastIsValid()) { |
| 42 if (last_.bytecode() == Bytecode::kNop && | 41 if (last_.bytecode() == Bytecode::kNop && |
| 43 !last_.source_info().is_statement()) { | 42 !last_.source_info().is_statement()) { |
| 44 // The Nop can be dropped as it doesn't have a statement | 43 // The Nop can be dropped as it doesn't have a statement |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 current->source_info().Update(last_.source_info()); | 163 current->source_info().Update(last_.source_info()); |
| 165 } | 164 } |
| 166 InvalidateLast(); | 165 InvalidateLast(); |
| 167 } | 166 } |
| 168 return current; | 167 return current; |
| 169 } | 168 } |
| 170 | 169 |
| 171 } // namespace interpreter | 170 } // namespace interpreter |
| 172 } // namespace internal | 171 } // namespace internal |
| 173 } // namespace v8 | 172 } // namespace v8 |
| OLD | NEW |