Index: src/interpreter/bytecode-peephole-optimizer.h |
diff --git a/src/interpreter/bytecode-peephole-optimizer.h b/src/interpreter/bytecode-peephole-optimizer.h |
index e6ada2aa1ef244c4f3c07c176f80ac26df4994ca..70d439343ae056a07a05aec7983841cf9215e7ea 100644 |
--- a/src/interpreter/bytecode-peephole-optimizer.h |
+++ b/src/interpreter/bytecode-peephole-optimizer.h |
@@ -1,4 +1,4 @@ |
-// Copyright 2015 the V8 project authors. All rights reserved. |
+// Copyright 2016 the V8 project authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
@@ -13,6 +13,46 @@ namespace interpreter { |
class ConstantArrayBuilder; |
+#define PEEPHOLE_NON_JUMP_ACTION_LIST(V) \ |
+ V(DefaultAction) \ |
+ V(UpdateLastAction) \ |
+ V(ElideCurrentAction) \ |
+ V(ElideCurrentIfOperand0MatchesAction) \ |
+ V(ElideCurrentIfLoadingNameConstantAction) \ |
+ V(ElideLastAction) \ |
+ V(ChangeBytecodeAction) \ |
+ V(TransformLdaStarToLdrLdarAction) \ |
+ V(TransformLdaSmiBinaryOpToBinaryOpWithSmiAction) \ |
+ V(TransformLdaZeroBinaryOpToBinaryOpWithZeroAction) |
+ |
+#define PEEPHOLE_JUMP_ACTION_LIST(V) \ |
+ V(DefaultJumpAction) \ |
+ V(UpdateLastJumpAction) \ |
+ V(ChangeJumpBytecodeAction) \ |
+ V(ElideLastBeforeJumpAction) |
+ |
+#define PEEPHOLE_ACTION_LIST(V) \ |
+ PEEPHOLE_NON_JUMP_ACTION_LIST(V) \ |
+ PEEPHOLE_JUMP_ACTION_LIST(V) |
+ |
+// Actions to take when a pair of bytes is encountered. A handler |
+// exists for each action. |
+enum class PeepholeAction : uint8_t { |
+#define DECLARE_PEEPHOLE_ACTION(Action) k##Action, |
+ PEEPHOLE_ACTION_LIST(DECLARE_PEEPHOLE_ACTION) |
+#undef DECLARE_PEEPHOLE_ACTION |
+}; |
+ |
+// Tuple of action to take when pair of bytecodes is encountered and |
+// optional data to invoke handler with. |
+struct PeepholeActionAndData final { |
+ // Action to take when tuple of bytecodes encountered. |
+ PeepholeAction action; |
+ |
+ // Replacement bytecode (if valid). |
+ Bytecode bytecode; |
+}; |
+ |
// An optimization stage for performing peephole optimizations on |
// generated bytecode. The optimizer may buffer one bytecode |
// internally. |
@@ -32,31 +72,26 @@ class BytecodePeepholeOptimizer final : public BytecodePipelineStage, |
Handle<FixedArray> handler_table) override; |
private: |
- BytecodeNode* OptimizeAndEmitLast(BytecodeNode* current); |
- BytecodeNode* Optimize(BytecodeNode* current); |
- void Flush(); |
+#define DECLARE_ACTION(Action) \ |
+ void Action(BytecodeNode* const node, \ |
+ const PeepholeActionAndData* const action_data = nullptr); |
+ PEEPHOLE_ACTION_LIST(DECLARE_ACTION) |
+#undef DECLARE_ACTION |
- void TryToRemoveLastExpressionPosition(const BytecodeNode* const current); |
- bool TransformCurrentBytecode(BytecodeNode* const current); |
- bool TransformLastAndCurrentBytecodes(BytecodeNode* const current); |
- bool CanElideCurrent(const BytecodeNode* const current) const; |
- bool CanElideLast(const BytecodeNode* const current) const; |
+ void Optimize(BytecodeNode* const node); |
+ void Flush(); |
bool CanElideLastBasedOnSourcePosition( |
const BytecodeNode* const current) const; |
- |
- // Simple substitution methods. |
- bool RemoveToBooleanFromJump(BytecodeNode* const current); |
- bool RemoveToBooleanFromLogicalNot(BytecodeNode* const current); |
- |
void InvalidateLast(); |
bool LastIsValid() const; |
void SetLast(const BytecodeNode* const node); |
- bool LastBytecodePutsNameInAccumulator() const; |
- |
Handle<Object> GetConstantForIndexOperand(const BytecodeNode* const node, |
int index) const; |
+ BytecodePipelineStage* next_stage() const { return next_stage_; } |
+ BytecodeNode* last() { return &last_; } |
+ |
ConstantArrayBuilder* constant_array_builder_; |
BytecodePipelineStage* next_stage_; |
BytecodeNode last_; |