Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(151)

Side by Side Diff: src/interpreter/register-translator.h

Issue 1613163002: [interpreter] Wide register support. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Compilation fixes for gcc/msvc. Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_REGISTER_TRANSLATOR_H_
6 #define V8_INTERPRETER_REGISTER_TRANSLATOR_H_
7
8 #include "src/interpreter/bytecodes.h"
9
10 namespace v8 {
11 namespace internal {
12 namespace interpreter {
13
14 class RegisterMover;
15
16 // A class that enables bytecodes having only byte sized register operands
17 // to access all registers in the two byte space. Most bytecode uses few
18 // registers so space can be saved if most bytecodes with register operands
19 // just take byte operands.
20 //
21 // To reach the wider register space, a translation window is reserved in
22 // the byte addressable space specifically for copying registers into and
23 // out of before a bytecode is emitted. The translation window occupies
24 // the last register slots at the top of the byte addressable range.
25 //
26 // Because of the translation window any registers which naturally lie
27 // at above the translation window have to have their register index
28 // incremented by the window width before they are emitted.
29 //
30 // This class does not support moving ranges of registers to and from
31 // the translation window. It would be straightforward to add support
32 // for constrained ranges, e.g. kRegPair8, kRegTriple8 operands, but
33 // these would have two negative effects. The translation window would
34 // need to be wider, further limiting the space for byte operands. And
35 // every register in a range would need to be moved consuming more
36 // space in the bytecode array.
37 class RegisterTranslator final {
38 public:
39 explicit RegisterTranslator(RegisterMover* mover);
40
41 // Translate and re-write register operands in bytecode to be
42 // emitted.
43 void TranslateRegisters(Bytecode bytecode, uint32_t* raw_operands,
44 int raw_operand_count);
45
46 // Undo translations after bytecode has been emitted.
47 void UntranslateRegisters();
48
49 // Returns true if |reg| is in the translation window.
50 static bool InTranslationWindow(Register reg);
51
52 // Returns the distance in registers between the translation window
53 // start and |reg|. The result is negative when |reg| is above the
54 // start of the translation window.
55 static int DistanceToTranslationWindow(Register reg);
56
57 // Returns true if |reg| can be represented as an 8-bit operand
58 // after translation.
59 static bool FitsInReg8Operand(Register reg);
60
61 // Returns true if |reg| can be represented as an 16-bit operand
62 // after translation.
63 static bool FitsInReg16Operand(Register reg);
64
65 // Returns the increment to the register count necessary if the
66 // value indicates the translation window is required.
67 static int RegisterCountAdjustment(int register_count, int parameter_count);
68
69 private:
70 static const int kTranslationWindowLength = 4;
71 static const int kTranslationWindowLimit = -kMinInt8;
72 static const int kTranslationWindowStart =
73 kTranslationWindowLimit - kTranslationWindowLength + 1;
74
75 Register TranslateAndMove(Bytecode bytecode, int operand_index, Register reg);
76 Register MakeAddressable(Register reg, OperandType reg_type);
77 static Register Translate(Register reg);
78
79 static bool NonRegisterOperandIsValid(Bytecode bytecode, int operand_index);
80 static bool OperandIsMoveable(Bytecode bytecode, int operand_index);
81
82 RegisterMover* mover() const { return mover_; }
83
84 // Entity to perform register moves necessary to translate registers
85 // and ensure reachability.
86 RegisterMover* mover_;
87
88 // Flag to avoid re-entrancy when emitting move bytecodes for
89 // translation.
90 bool emitting_moves_;
91
92 // State for restoring registers after bytecode.
93 Register window_registers_[kTranslationWindowLength];
94 int window_registers_count_;
95 };
96
97
98 // Interface for RegisterTranslator helper class that will emit
99 // register move bytecodes at the translator's behest.
100 class RegisterMover {
101 public:
102 virtual ~RegisterMover() {}
103
104 // Move register |from| to register |to| with no translation.
105 // returns false if either register operand is invalid. Implementations
106 // of this method must be aware that register moves with bad
107 // register values are a security hole.
108 virtual void MoveRegisterUntranslated(Register from, Register to) = 0;
109 };
110
111 } // namespace interpreter
112 } // namespace internal
113 } // namespace v8
114
115 #endif // V8_INTERPRETER_REGISTER_TRANSLATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698