[codegen] Ensure that all register types fit in an int
Registers were supposed to fit in an int, but some register subclasses added extra fields which made them too big. This fiddles around with field sizes so that all the Register subclasses still fit inside of an int (by making the Register code field 8-bit etc). Change-Id: I31ffbc8f98b6a5e1f638fc59147009e5f81dff41 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3513612 Auto-Submit: Leszek Swirski <leszeks@chromium.org> Reviewed-by: Victor Gomes <victorgomes@chromium.org> Commit-Queue: Victor Gomes <victorgomes@chromium.org> Cr-Commit-Position: refs/heads/main@{#79421}
This commit is contained in:
parent
7ef1fc1565
commit
79dfd0eb4f
@ -109,7 +109,7 @@ class Register : public RegisterBase<Register, kRegAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(Register);
|
||||
static_assert(sizeof(Register) == sizeof(int),
|
||||
static_assert(sizeof(Register) <= sizeof(int),
|
||||
"Register can efficiently be passed by value");
|
||||
|
||||
// r7: context register
|
||||
@ -169,7 +169,7 @@ class SwVfpRegister : public RegisterBase<SwVfpRegister, kSwVfpAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(SwVfpRegister);
|
||||
static_assert(sizeof(SwVfpRegister) == sizeof(int),
|
||||
static_assert(sizeof(SwVfpRegister) <= sizeof(int),
|
||||
"SwVfpRegister can efficiently be passed by value");
|
||||
|
||||
using FloatRegister = SwVfpRegister;
|
||||
@ -210,7 +210,7 @@ class DwVfpRegister : public RegisterBase<DwVfpRegister, kDoubleAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(DwVfpRegister);
|
||||
static_assert(sizeof(DwVfpRegister) == sizeof(int),
|
||||
static_assert(sizeof(DwVfpRegister) <= sizeof(int),
|
||||
"DwVfpRegister can efficiently be passed by value");
|
||||
|
||||
using DoubleRegister = DwVfpRegister;
|
||||
|
@ -95,7 +95,7 @@ enum RegisterCode {
|
||||
|
||||
class CPURegister : public RegisterBase<CPURegister, kRegAfterLast> {
|
||||
public:
|
||||
enum RegisterType { kRegister, kVRegister, kNoRegister };
|
||||
enum RegisterType : int8_t { kRegister, kVRegister, kNoRegister };
|
||||
|
||||
static constexpr CPURegister no_reg() {
|
||||
return CPURegister{kCode_no_reg, 0, kNoRegister};
|
||||
@ -188,7 +188,7 @@ class CPURegister : public RegisterBase<CPURegister, kRegAfterLast> {
|
||||
bool IsSameSizeAndType(const CPURegister& other) const;
|
||||
|
||||
protected:
|
||||
int reg_size_;
|
||||
uint8_t reg_size_;
|
||||
RegisterType reg_type_;
|
||||
|
||||
#if defined(V8_OS_WIN) && !defined(__clang__)
|
||||
@ -224,6 +224,8 @@ class CPURegister : public RegisterBase<CPURegister, kRegAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(CPURegister);
|
||||
static_assert(sizeof(CPURegister) <= sizeof(int),
|
||||
"CPURegister can efficiently be passed by value");
|
||||
|
||||
class Register : public CPURegister {
|
||||
public:
|
||||
@ -250,6 +252,8 @@ class Register : public CPURegister {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(Register);
|
||||
static_assert(sizeof(Register) <= sizeof(int),
|
||||
"Register can efficiently be passed by value");
|
||||
|
||||
// Stack frame alignment and padding.
|
||||
constexpr int ArgumentPaddingSlots(int argument_count) {
|
||||
@ -419,7 +423,7 @@ class VRegister : public CPURegister {
|
||||
}
|
||||
|
||||
private:
|
||||
int lane_count_;
|
||||
int8_t lane_count_;
|
||||
|
||||
constexpr explicit VRegister(const CPURegister& r, int lane_count)
|
||||
: CPURegister(r), lane_count_(lane_count) {}
|
||||
@ -430,6 +434,8 @@ class VRegister : public CPURegister {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(VRegister);
|
||||
static_assert(sizeof(VRegister) <= sizeof(int),
|
||||
"VRegister can efficiently be passed by value");
|
||||
|
||||
// No*Reg is used to indicate an unused argument, or an error case. Note that
|
||||
// these all compare equal. The Register and VRegister variants are provided for
|
||||
|
@ -67,7 +67,7 @@ class Register : public RegisterBase<Register, kRegAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(Register);
|
||||
static_assert(sizeof(Register) == sizeof(int),
|
||||
static_assert(sizeof(Register) <= sizeof(int),
|
||||
"Register can efficiently be passed by value");
|
||||
|
||||
#define DEFINE_REGISTER(R) \
|
||||
|
@ -199,7 +199,7 @@ class Register : public RegisterBase<Register, kRegAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(Register);
|
||||
static_assert(sizeof(Register) == sizeof(int),
|
||||
static_assert(sizeof(Register) <= sizeof(int),
|
||||
"Register can efficiently be passed by value");
|
||||
|
||||
#define DEFINE_REGISTER(R) \
|
||||
@ -249,7 +249,7 @@ class DoubleRegister : public RegisterBase<DoubleRegister, kDoubleAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(DoubleRegister);
|
||||
static_assert(sizeof(DoubleRegister) == sizeof(int),
|
||||
static_assert(sizeof(DoubleRegister) <= sizeof(int),
|
||||
"DoubleRegister can efficiently be passed by value");
|
||||
|
||||
using FloatRegister = DoubleRegister;
|
||||
@ -292,7 +292,7 @@ class Simd128Register
|
||||
explicit constexpr Simd128Register(int code) : RegisterBase(code) {}
|
||||
};
|
||||
ASSERT_TRIVIALLY_COPYABLE(Simd128Register);
|
||||
static_assert(sizeof(Simd128Register) == sizeof(int),
|
||||
static_assert(sizeof(Simd128Register) <= sizeof(int),
|
||||
"Simd128Register can efficiently be passed by value");
|
||||
|
||||
#define DECLARE_SIMD128_REGISTER(R) \
|
||||
|
@ -8,6 +8,7 @@
|
||||
#include "src/base/bits.h"
|
||||
#include "src/base/bounds.h"
|
||||
#include "src/codegen/reglist.h"
|
||||
#include "src/common/globals.h"
|
||||
|
||||
namespace v8 {
|
||||
|
||||
@ -28,13 +29,13 @@ namespace internal {
|
||||
template <typename SubType, int kAfterLastRegister>
|
||||
class RegisterBase {
|
||||
public:
|
||||
static constexpr int kCode_no_reg = -1;
|
||||
static constexpr int kNumRegisters = kAfterLastRegister;
|
||||
static constexpr int8_t kCode_no_reg = -1;
|
||||
static constexpr int8_t kNumRegisters = kAfterLastRegister;
|
||||
|
||||
static constexpr SubType no_reg() { return SubType{kCode_no_reg}; }
|
||||
|
||||
static constexpr SubType from_code(int code) {
|
||||
DCHECK(base::IsInRange(code, 0, kNumRegisters - 1));
|
||||
static constexpr SubType from_code(int8_t code) {
|
||||
DCHECK(base::IsInRange(static_cast<int>(code), 0, kNumRegisters - 1));
|
||||
return SubType{code};
|
||||
}
|
||||
|
||||
@ -45,7 +46,7 @@ class RegisterBase {
|
||||
|
||||
constexpr bool is_valid() const { return reg_code_ != kCode_no_reg; }
|
||||
|
||||
constexpr int code() const {
|
||||
constexpr int8_t code() const {
|
||||
DCHECK(is_valid());
|
||||
return reg_code_;
|
||||
}
|
||||
@ -90,7 +91,8 @@ class RegisterBase {
|
||||
explicit constexpr RegisterBase(int code) : reg_code_(code) {}
|
||||
|
||||
private:
|
||||
int reg_code_;
|
||||
int8_t reg_code_;
|
||||
STATIC_ASSERT(kAfterLastRegister <= kMaxInt8);
|
||||
};
|
||||
|
||||
template <typename RegType,
|
||||
|
@ -154,7 +154,7 @@ class Register : public RegisterBase<Register, kRegAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(Register);
|
||||
static_assert(sizeof(Register) == sizeof(int),
|
||||
static_assert(sizeof(Register) <= sizeof(int),
|
||||
"Register can efficiently be passed by value");
|
||||
|
||||
#define DEFINE_REGISTER(R) \
|
||||
@ -204,7 +204,7 @@ class DoubleRegister : public RegisterBase<DoubleRegister, kDoubleAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(DoubleRegister);
|
||||
static_assert(sizeof(DoubleRegister) == sizeof(int),
|
||||
static_assert(sizeof(DoubleRegister) <= sizeof(int),
|
||||
"DoubleRegister can efficiently be passed by value");
|
||||
|
||||
using FloatRegister = DoubleRegister;
|
||||
|
@ -75,7 +75,7 @@ class Register : public RegisterBase<Register, kRegAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(Register);
|
||||
static_assert(sizeof(Register) == sizeof(int),
|
||||
static_assert(sizeof(Register) <= sizeof(int),
|
||||
"Register can efficiently be passed by value");
|
||||
|
||||
#define DECLARE_REGISTER(R) \
|
||||
@ -212,7 +212,7 @@ class XMMRegister : public RegisterBase<XMMRegister, kDoubleAfterLast> {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(XMMRegister);
|
||||
static_assert(sizeof(XMMRegister) == sizeof(int),
|
||||
static_assert(sizeof(XMMRegister) <= sizeof(int),
|
||||
"XMMRegister can efficiently be passed by value");
|
||||
|
||||
class YMMRegister : public XMMRegister {
|
||||
@ -228,7 +228,7 @@ class YMMRegister : public XMMRegister {
|
||||
};
|
||||
|
||||
ASSERT_TRIVIALLY_COPYABLE(YMMRegister);
|
||||
static_assert(sizeof(YMMRegister) == sizeof(int),
|
||||
static_assert(sizeof(YMMRegister) <= sizeof(int),
|
||||
"YMMRegister can efficiently be passed by value");
|
||||
|
||||
using FloatRegister = XMMRegister;
|
||||
|
Loading…
Reference in New Issue
Block a user