Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef V8_INTERPRETER_BYTECODE_PEEPHOLE_OPTIMIZER_H_ |
| 6 | #define V8_INTERPRETER_BYTECODE_PEEPHOLE_OPTIMIZER_H_ |
| 7 | |
| 8 | #include "src/interpreter/bytecode-pipeline.h" |
| 9 | |
| 10 | namespace v8 { |
| 11 | namespace internal { |
| 12 | namespace interpreter { |
| 13 | |
| 14 | class ConstantArrayBuilder; |
| 15 | |
| 16 | // An optimization stage for performing peephole optimizations on |
| 17 | // generated bytecode. The optimizer may buffer one bytecode |
| 18 | // internally. |
| 19 | class BytecodePeepholeOptimizer final : public BytecodePipelineStage, |
| 20 | public ZoneObject { |
| 21 | public: |
| 22 | BytecodePeepholeOptimizer(ConstantArrayBuilder* constant_array_builder, |
| 23 | BytecodePipelineStage* next_stage); |
| 24 | |
| 25 | void Write(BytecodeNode* node) override; |
| 26 | size_t FlushForOffset() override; |
| 27 | void FlushBasicBlock() override; |
| 28 | |
| 29 | private: |
| 30 | BytecodeNode* Optimize(BytecodeNode* current); |
| 31 | |
| 32 | void UpdateCurrentBytecode(BytecodeNode* const current); |
| 33 | bool CanElideCurrent(const BytecodeNode* const current) const; |
| 34 | bool CanElideLast(const BytecodeNode* const current) const; |
| 35 | |
| 36 | void InvalidateLast(); |
| 37 | bool LastIsValid() const; |
| 38 | void SetLast(const BytecodeNode* const node); |
| 39 | |
| 40 | bool LastBytecodePutsNameInAccumulator() const; |
| 41 | |
| 42 | Handle<Object> GetConstantForIndexOperand(const BytecodeNode* const node, |
| 43 | int index) const; |
| 44 | |
| 45 | ConstantArrayBuilder* constant_array_builder_; |
| 46 | BytecodePipelineStage* next_stage_; |
| 47 | BytecodeNode last_; |
| 48 | bool last_is_discardable_; |
| 49 | |
| 50 | DISALLOW_COPY_AND_ASSIGN(BytecodePeepholeOptimizer); |
| 51 | }; |
| 52 | |
| 53 | } // namespace interpreter |
| 54 | } // namespace internal |
| 55 | } // namespace v8 |
| 56 | |
| 57 | #endif // V8_INTERPRETER_BYTECODE_PEEPHOLE_OPTIMIZER_H_ |