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 #ifndef V8_INTERPRETER_BYTECODE_PEEPHOLE_OPTIMIZER_H_ | 5 #ifndef V8_INTERPRETER_BYTECODE_PEEPHOLE_OPTIMIZER_H_ |
6 #define V8_INTERPRETER_BYTECODE_PEEPHOLE_OPTIMIZER_H_ | 6 #define V8_INTERPRETER_BYTECODE_PEEPHOLE_OPTIMIZER_H_ |
7 | 7 |
8 #include "src/interpreter/bytecode-pipeline.h" | 8 #include "src/interpreter/bytecode-pipeline.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 14 matching lines...) Expand all Loading... |
25 // BytecodePipelineStage interface. | 25 // BytecodePipelineStage interface. |
26 void Write(BytecodeNode* node) override; | 26 void Write(BytecodeNode* node) override; |
27 void WriteJump(BytecodeNode* node, BytecodeLabel* label) override; | 27 void WriteJump(BytecodeNode* node, BytecodeLabel* label) override; |
28 void BindLabel(BytecodeLabel* label) override; | 28 void BindLabel(BytecodeLabel* label) override; |
29 void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override; | 29 void BindLabel(const BytecodeLabel& target, BytecodeLabel* label) override; |
30 Handle<BytecodeArray> ToBytecodeArray( | 30 Handle<BytecodeArray> ToBytecodeArray( |
31 int fixed_register_count, int parameter_count, | 31 int fixed_register_count, int parameter_count, |
32 Handle<FixedArray> handler_table) override; | 32 Handle<FixedArray> handler_table) override; |
33 | 33 |
34 private: | 34 private: |
35 BytecodeNode* OptimizeAndEmitLast(BytecodeNode* current); | 35 // Actions for non-jump bytecodes. |
36 BytecodeNode* Optimize(BytecodeNode* current); | 36 void DefaultAction(BytecodeNode* const node); |
| 37 void UpdateLastAction(BytecodeNode* const node); |
| 38 void ElideCurrentAction(BytecodeNode* const node); |
| 39 void ElideCurrentIfOperand0MatchesAction(BytecodeNode* const node); |
| 40 void ElideCurrentIfLoadingNameConstantAction(BytecodeNode* const node); |
| 41 void ElideLastAction(BytecodeNode* const node); |
| 42 void ChangeBytecodeAction(BytecodeNode* const node, Bytecode replacement); |
| 43 void TransformLdaStarToLdrLdarAction(BytecodeNode* const node, |
| 44 Bytecode replacement); |
| 45 |
| 46 // Actions for jump bytecodes. |
| 47 void DefaultJumpAction(BytecodeNode* const node); |
| 48 void UpdateLastJumpAction(BytecodeNode* const node); |
| 49 void ChangeJumpBytecodeAction(BytecodeNode* const node, Bytecode replacement); |
| 50 void ElideLastBeforeJumpAction(BytecodeNode* const node); |
| 51 |
| 52 void Optimize(BytecodeNode* const node); |
37 void Flush(); | 53 void Flush(); |
38 | |
39 void TryToRemoveLastExpressionPosition(const BytecodeNode* const current); | |
40 bool TransformCurrentBytecode(BytecodeNode* const current); | |
41 bool TransformLastAndCurrentBytecodes(BytecodeNode* const current); | |
42 bool CanElideCurrent(const BytecodeNode* const current) const; | |
43 bool CanElideLast(const BytecodeNode* const current) const; | |
44 bool CanElideLastBasedOnSourcePosition( | 54 bool CanElideLastBasedOnSourcePosition( |
45 const BytecodeNode* const current) const; | 55 const BytecodeNode* const current) const; |
46 | |
47 // Simple substitution methods. | |
48 bool RemoveToBooleanFromJump(BytecodeNode* const current); | |
49 bool RemoveToBooleanFromLogicalNot(BytecodeNode* const current); | |
50 | |
51 void InvalidateLast(); | 56 void InvalidateLast(); |
52 bool LastIsValid() const; | 57 bool LastIsValid() const; |
53 void SetLast(const BytecodeNode* const node); | 58 void SetLast(const BytecodeNode* const node); |
54 | 59 |
55 bool LastBytecodePutsNameInAccumulator() const; | |
56 | |
57 Handle<Object> GetConstantForIndexOperand(const BytecodeNode* const node, | 60 Handle<Object> GetConstantForIndexOperand(const BytecodeNode* const node, |
58 int index) const; | 61 int index) const; |
59 | 62 |
| 63 BytecodePipelineStage* next_stage() const { return next_stage_; } |
| 64 BytecodeNode* last() { return &last_; } |
| 65 |
60 ConstantArrayBuilder* constant_array_builder_; | 66 ConstantArrayBuilder* constant_array_builder_; |
61 BytecodePipelineStage* next_stage_; | 67 BytecodePipelineStage* next_stage_; |
62 BytecodeNode last_; | 68 BytecodeNode last_; |
63 | 69 |
64 DISALLOW_COPY_AND_ASSIGN(BytecodePeepholeOptimizer); | 70 DISALLOW_COPY_AND_ASSIGN(BytecodePeepholeOptimizer); |
65 }; | 71 }; |
66 | 72 |
67 } // namespace interpreter | 73 } // namespace interpreter |
68 } // namespace internal | 74 } // namespace internal |
69 } // namespace v8 | 75 } // namespace v8 |
70 | 76 |
71 #endif // V8_INTERPRETER_BYTECODE_PEEPHOLE_OPTIMIZER_H_ | 77 #endif // V8_INTERPRETER_BYTECODE_PEEPHOLE_OPTIMIZER_H_ |
OLD | NEW |