aboutsummaryrefslogtreecommitdiff
path: root/src/interpreter/bytecode-peephole-table.h
blob: 1790f5a1090d94cc22f6653207bd37c21203c70c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// 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.

#ifndef V8_INTERPRETER_BYTECODE_PEEPHOLE_TABLE_H_
#define V8_INTERPRETER_BYTECODE_PEEPHOLE_TABLE_H_

#include "src/interpreter/bytecodes.h"

namespace v8 {
namespace internal {
namespace interpreter {

#define PEEPHOLE_NON_JUMP_ACTION_LIST(V)            \
  V(DefaultAction)                                  \
  V(UpdateLastAction)                               \
  V(UpdateLastIfSourceInfoPresentAction)            \
  V(ElideCurrentAction)                             \
  V(ElideCurrentIfOperand0MatchesAction)            \
  V(ElideLastAction)                                \
  V(ChangeBytecodeAction)                           \
  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;
};

// Lookup table for matching pairs of bytecodes to peephole optimization
// actions. The contents of the table are generated by mkpeephole.cc.
struct PeepholeActionTable final {
 public:
  static const PeepholeActionAndData* Lookup(Bytecode last, Bytecode current);

 private:
  static const size_t kNumberOfBytecodes =
      static_cast<size_t>(Bytecode::kLast) + 1;

  static const PeepholeActionAndData row_data_[][kNumberOfBytecodes];
  static const PeepholeActionAndData* const row_[kNumberOfBytecodes];
};

}  // namespace interpreter
}  // namespace internal
}  // namespace v8

#endif  // V8_INTERPRETER_BYTECODE_PEEPHOLE_TABLE_H_