v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
maglev-register-frame-array.h
Go to the documentation of this file.
1// Copyright 2022 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_MAGLEV_MAGLEV_REGISTER_FRAME_ARRAY_H_
6#define V8_MAGLEV_MAGLEV_REGISTER_FRAME_ARRAY_H_
7
10#include "src/zone/zone.h"
11
12namespace v8 {
13namespace internal {
14namespace maglev {
15
16// Vector of values associated with a bytecode's register frame. Indexable by
17// interpreter register.
18template <typename T>
20 public:
22 // The first local is at index zero, parameters are behind it with
23 // negative indices, and the unoptimized frame header is between the two,
24 // so the entire frame state including parameters is the number of locals
25 // and parameters, plus the number of slots between them.
26 constexpr interpreter::Register first_param =
28 static_assert(first_param.index() < 0);
29 static_assert(interpreter::Register(0).index() == 0);
30 constexpr int frame_size_between_params_and_locals = -first_param.index();
31
32 T* frame = info.zone()->AllocateArray<T>(
33 info.parameter_count() + frame_size_between_params_and_locals +
34 info.register_count());
35
36 // Set frame_start_ to a "butterfly" pointer into the middle of the above
37 // Zone-allocated array, so that locals start at zero.
39 frame + info.parameter_count() + frame_size_between_params_and_locals;
40 }
41
42 // Disallow copy (use CopyFrom instead).
45 V8_NOEXCEPT = delete;
46
47 // Allow move.
50 V8_NOEXCEPT = default;
51
53 const RegisterFrameArray& other,
54 const compiler::BytecodeLivenessState* liveness) {
55 interpreter::Register last_param =
56 interpreter::Register::FromParameterIndex(info.parameter_count() - 1);
57 int end = 1;
58 if (!liveness) {
59 interpreter::Register last_local =
60 interpreter::Register(info.register_count() - 1);
61 end = last_local.index();
62 }
63 // All parameters are live.
64 for (int index = last_param.index(); index <= end; ++index) {
66 (*this)[reg] = other[reg];
67 }
68 if (liveness) {
69 for (int index : *liveness) {
71 (*this)[reg] = other[reg];
72 }
73 }
74 }
75
77
79 return frame_start_[reg.index()];
80 }
81
82 private:
83 static int DataSize(int register_count, int parameter_count) {
84 // The first local is at index zero, parameters are behind it with
85 // negative indices, and the unoptimized frame header is between the two,
86 // so the entire frame state including parameters is the distance from the
87 // last parameter to the last local frame register, plus one to include both
88 // ends.
89 interpreter::Register last_local =
90 interpreter::Register(register_count - 1);
91 interpreter::Register last_param =
93 return last_local.index() - last_param.index() + 1;
94 }
95
101
102 // Butterfly pointer for registers, pointing into the middle of a
103 // Zone-allocated Node array.
104 // |
105 // v
106 // [Parameters] [Unoptimized Frame Header] [Locals]
107 T* frame_start_ = nullptr;
108};
109
110} // namespace maglev
111} // namespace internal
112} // namespace v8
113
114#endif // V8_MAGLEV_MAGLEV_REGISTER_FRAME_ARRAY_H_
int16_t parameter_count
Definition builtins.cc:67
static constexpr Register FromParameterIndex(int index)
RegisterFrameArray & operator=(RegisterFrameArray &&other) V8_NOEXCEPT=default
static int DataSize(int register_count, int parameter_count)
RegisterFrameArray(const RegisterFrameArray &other) V8_NOEXCEPT=delete
void CopyFrom(const MaglevCompilationUnit &info, const RegisterFrameArray &other, const compiler::BytecodeLivenessState *liveness)
RegisterFrameArray & operator=(const RegisterFrameArray &other) V8_NOEXCEPT=delete
RegisterFrameArray(const MaglevCompilationUnit &info)
const T & operator[](interpreter::Register reg) const
RegisterFrameArray(RegisterFrameArray &&other) V8_NOEXCEPT=default
int end
LiftoffRegister reg
#define V8_NOEXCEPT