v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
liftoff-varstate.h
Go to the documentation of this file.
1// Copyright 2024 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_WASM_BASELINE_LIFTOFF_VARSTATE_H_
6#define V8_WASM_BASELINE_LIFTOFF_VARSTATE_H_
7
10
11namespace v8::internal::wasm {
12
14 public:
15 enum Location : uint8_t { kStack, kRegister, kIntConst };
16
34
35 bool is_stack() const { return loc_ == kStack; }
36 bool is_gp_reg() const { return loc_ == kRegister && reg_.is_gp(); }
37 bool is_fp_reg() const { return loc_ == kRegister && reg_.is_fp(); }
38 bool is_gp_reg_pair() const { return loc_ == kRegister && reg_.is_gp_pair(); }
39 bool is_fp_reg_pair() const { return loc_ == kRegister && reg_.is_fp_pair(); }
40 bool is_reg() const { return loc_ == kRegister; }
41 bool is_const() const { return loc_ == kIntConst; }
42
43 ValueKind kind() const { return kind_; }
44
45 Location loc() const { return loc_; }
46
47 // The constant as 32-bit value, to be sign-extended if {kind() == kI64}.
48 int32_t i32_const() const {
50 return i32_const_;
51 }
53 DCHECK(kind_ == kI32 || kind_ == kI64);
55 return kind_ == kI32 ? WasmValue(i32_const_)
56 : WasmValue(int64_t{i32_const_});
57 }
58
59 int offset() const {
61 return spill_offset_;
62 }
67
68 Register gp_reg() const { return reg().gp(); }
69 DoubleRegister fp_reg() const { return reg().fp(); }
72 return reg_;
73 }
74 RegClass reg_class() const { return reg().reg_class(); }
75
76 void MakeStack() { loc_ = kStack; }
77
80 reg_ = r;
81 }
82
83 void MakeConstant(int32_t i32_const) {
84 DCHECK(kind_ == kI32 || kind_ == kI64);
87 }
88
89 // Copy src to this, except for offset, since src and this could have been
90 // from different stack states.
92 loc_ = src.loc();
93 kind_ = src.kind();
94 if (loc_ == kRegister) {
95 reg_ = src.reg();
96 } else if (loc_ == kIntConst) {
97 i32_const_ = src.i32_const();
98 }
99 }
100
101 private:
103 // TODO(wasm): This is redundant, the decoder already knows the type of each
104 // stack value. Try to collapse.
106
107 union {
108 LiftoffRegister reg_; // used if loc_ == kRegister
109 int32_t i32_const_; // used if loc_ == kIntConst
110 };
112};
113
114std::ostream& operator<<(std::ostream& os, LiftoffVarState);
115
117} // namespace v8::internal::wasm
118
119#endif // V8_WASM_BASELINE_LIFTOFF_VARSTATE_H_
constexpr DoubleRegister fp() const
constexpr RegClass reg_class() const
void MakeConstant(int32_t i32_const)
LiftoffVarState(ValueKind kind, int offset)
LiftoffVarState(ValueKind kind, LiftoffRegister r, int offset)
LiftoffVarState(ValueKind kind, int32_t i32_const, int offset)
void MakeRegister(LiftoffRegister r)
int r
Definition mul-fft.cc:298
static constexpr RegClass reg_class_for(ValueKind kind)
std::ostream & operator<<(std::ostream &os, LiftoffVarState slot)
#define DCHECK_LE(v1, v2)
Definition logging.h:490
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define ASSERT_TRIVIALLY_COPYABLE(T)
Definition macros.h:267
#define V8_ASSUME
Definition v8config.h:533