Commit fe424b3b authored by Zhao Jiazhong's avatar Zhao Jiazhong Committed by Commit Bot

[mips][wasm] Turn ValueType from an enum to a class.

Port f3b4167f
https://crrev.com/c/2091471

Original Commit Message:

  In preparation for adding reference types, which need an additional
  parameter to indicate the referenced type.

Change-Id: I1b66bffea3ac2637886673476c8f7d62150b33a3
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2100695
Auto-Submit: Zhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66699}
parent 1c565fdc
......@@ -59,20 +59,20 @@ inline MemOperand GetInstanceOperand() { return GetStackSlot(kInstanceOffset); }
inline void Load(LiftoffAssembler* assm, LiftoffRegister dst, Register base,
int32_t offset, ValueType type) {
MemOperand src(base, offset);
switch (type) {
case kWasmI32:
switch (type.kind()) {
case ValueType::kI32:
assm->lw(dst.gp(), src);
break;
case kWasmI64:
case ValueType::kI64:
assm->lw(dst.low_gp(),
MemOperand(base, offset + liftoff::kLowWordOffset));
assm->lw(dst.high_gp(),
MemOperand(base, offset + liftoff::kHighWordOffset));
break;
case kWasmF32:
case ValueType::kF32:
assm->lwc1(dst.fp(), src);
break;
case kWasmF64:
case ValueType::kF64:
assm->Ldc1(dst.fp(), src);
break;
default:
......@@ -83,20 +83,20 @@ inline void Load(LiftoffAssembler* assm, LiftoffRegister dst, Register base,
inline void Store(LiftoffAssembler* assm, Register base, int32_t offset,
LiftoffRegister src, ValueType type) {
MemOperand dst(base, offset);
switch (type) {
case kWasmI32:
switch (type.kind()) {
case ValueType::kI32:
assm->Usw(src.gp(), dst);
break;
case kWasmI64:
case ValueType::kI64:
assm->Usw(src.low_gp(),
MemOperand(base, offset + liftoff::kLowWordOffset));
assm->Usw(src.high_gp(),
MemOperand(base, offset + liftoff::kHighWordOffset));
break;
case kWasmF32:
case ValueType::kF32:
assm->Uswc1(src.fp(), dst, t8);
break;
case kWasmF64:
case ValueType::kF64:
assm->Usdc1(src.fp(), dst, t8);
break;
default:
......@@ -105,18 +105,18 @@ inline void Store(LiftoffAssembler* assm, Register base, int32_t offset,
}
inline void push(LiftoffAssembler* assm, LiftoffRegister reg, ValueType type) {
switch (type) {
case kWasmI32:
switch (type.kind()) {
case ValueType::kI32:
assm->push(reg.gp());
break;
case kWasmI64:
case ValueType::kI64:
assm->Push(reg.high_gp(), reg.low_gp());
break;
case kWasmF32:
case ValueType::kF32:
assm->addiu(sp, sp, -sizeof(float));
assm->swc1(reg.fp(), MemOperand(sp, 0));
break;
case kWasmF64:
case ValueType::kF64:
assm->addiu(sp, sp, -sizeof(double));
assm->Sdc1(reg.fp(), MemOperand(sp, 0));
break;
......@@ -298,17 +298,17 @@ constexpr int LiftoffAssembler::StaticStackFrameSize() {
}
int LiftoffAssembler::SlotSizeForType(ValueType type) {
switch (type) {
case kWasmS128:
return ValueTypes::ElementSizeInBytes(type);
switch (type.kind()) {
case ValueType::kS128:
return type.element_size_bytes();
default:
return kStackSlotSize;
}
}
bool LiftoffAssembler::NeedsAlignment(ValueType type) {
switch (type) {
case kWasmS128:
switch (type.kind()) {
case ValueType::kS128:
return true;
default:
// No alignment because all other types are kStackSlotSize.
......@@ -318,11 +318,11 @@ bool LiftoffAssembler::NeedsAlignment(ValueType type) {
void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
RelocInfo::Mode rmode) {
switch (value.type()) {
case kWasmI32:
switch (value.type().kind()) {
case ValueType::kI32:
TurboAssembler::li(reg.gp(), Operand(value.to_i32(), rmode));
break;
case kWasmI64: {
case ValueType::kI64: {
DCHECK(RelocInfo::IsNone(rmode));
int32_t low_word = value.to_i64();
int32_t high_word = value.to_i64() >> 32;
......@@ -330,10 +330,10 @@ void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
TurboAssembler::li(reg.high_gp(), Operand(high_word));
break;
}
case kWasmF32:
case ValueType::kF32:
TurboAssembler::Move(reg.fp(), value.to_f32_boxed().get_bits());
break;
case kWasmF64:
case ValueType::kF64:
TurboAssembler::Move(reg.fp(), value.to_f64_boxed().get_bits());
break;
default:
......@@ -612,18 +612,18 @@ void LiftoffAssembler::Move(DoubleRegister dst, DoubleRegister src,
void LiftoffAssembler::Spill(int offset, LiftoffRegister reg, ValueType type) {
RecordUsedSpillOffset(offset);
MemOperand dst = liftoff::GetStackSlot(offset);
switch (type) {
case kWasmI32:
switch (type.kind()) {
case ValueType::kI32:
sw(reg.gp(), dst);
break;
case kWasmI64:
case ValueType::kI64:
sw(reg.low_gp(), liftoff::GetHalfStackSlot(offset, kLowWord));
sw(reg.high_gp(), liftoff::GetHalfStackSlot(offset, kHighWord));
break;
case kWasmF32:
case ValueType::kF32:
swc1(reg.fp(), dst);
break;
case kWasmF64:
case ValueType::kF64:
TurboAssembler::Sdc1(reg.fp(), dst);
break;
default:
......@@ -634,14 +634,14 @@ void LiftoffAssembler::Spill(int offset, LiftoffRegister reg, ValueType type) {
void LiftoffAssembler::Spill(int offset, WasmValue value) {
RecordUsedSpillOffset(offset);
MemOperand dst = liftoff::GetStackSlot(offset);
switch (value.type()) {
case kWasmI32: {
switch (value.type().kind()) {
case ValueType::kI32: {
LiftoffRegister tmp = GetUnusedRegister(kGpReg);
TurboAssembler::li(tmp.gp(), Operand(value.to_i32()));
sw(tmp.gp(), dst);
break;
}
case kWasmI64: {
case ValueType::kI64: {
LiftoffRegister tmp = GetUnusedRegister(kGpRegPair);
int32_t low_word = value.to_i64();
......@@ -662,18 +662,18 @@ void LiftoffAssembler::Spill(int offset, WasmValue value) {
void LiftoffAssembler::Fill(LiftoffRegister reg, int offset, ValueType type) {
MemOperand src = liftoff::GetStackSlot(offset);
switch (type) {
case kWasmI32:
switch (type.kind()) {
case ValueType::kI32:
lw(reg.gp(), src);
break;
case kWasmI64:
case ValueType::kI64:
lw(reg.low_gp(), liftoff::GetHalfStackSlot(offset, kLowWord));
lw(reg.high_gp(), liftoff::GetHalfStackSlot(offset, kHighWord));
break;
case kWasmF32:
case ValueType::kF32:
lwc1(reg.fp(), src);
break;
case kWasmF64:
case ValueType::kF64:
TurboAssembler::Ldc1(reg.fp(), src);
break;
default:
......@@ -1780,7 +1780,7 @@ void LiftoffAssembler::CallC(const wasm::FunctionSig* sig,
int arg_bytes = 0;
for (ValueType param_type : sig->parameters()) {
liftoff::Store(this, sp, arg_bytes, *args++, param_type);
arg_bytes += ValueTypes::MemSize(param_type);
arg_bytes += param_type.element_size_bytes();
}
DCHECK_LE(arg_bytes, stack_bytes);
......@@ -1848,7 +1848,7 @@ void LiftoffStackSlots::Construct() {
const LiftoffAssembler::VarState& src = slot.src_;
switch (src.loc()) {
case LiftoffAssembler::VarState::kStack: {
if (src.type() == kWasmF64) {
if (src.type().kind() == ValueType::kF64) {
DCHECK_EQ(kLowWord, slot.half_);
asm_->lw(kScratchReg,
liftoff::GetHalfStackSlot(slot.src_offset_, kHighWord));
......@@ -1860,7 +1860,7 @@ void LiftoffStackSlots::Construct() {
break;
}
case LiftoffAssembler::VarState::kRegister:
if (src.type() == kWasmI64) {
if (src.type().kind() == ValueType::kI64) {
liftoff::push(
asm_, slot.half_ == kLowWord ? src.reg().low() : src.reg().high(),
kWasmI32);
......
......@@ -48,17 +48,17 @@ inline MemOperand GetInstanceOperand() { return GetStackSlot(kInstanceOffset); }
inline void Load(LiftoffAssembler* assm, LiftoffRegister dst, MemOperand src,
ValueType type) {
switch (type) {
case kWasmI32:
switch (type.kind()) {
case ValueType::kI32:
assm->lw(dst.gp(), src);
break;
case kWasmI64:
case ValueType::kI64:
assm->ld(dst.gp(), src);
break;
case kWasmF32:
case ValueType::kF32:
assm->lwc1(dst.fp(), src);
break;
case kWasmF64:
case ValueType::kF64:
assm->Ldc1(dst.fp(), src);
break;
default:
......@@ -69,17 +69,17 @@ inline void Load(LiftoffAssembler* assm, LiftoffRegister dst, MemOperand src,
inline void Store(LiftoffAssembler* assm, Register base, int32_t offset,
LiftoffRegister src, ValueType type) {
MemOperand dst(base, offset);
switch (type) {
case kWasmI32:
switch (type.kind()) {
case ValueType::kI32:
assm->Usw(src.gp(), dst);
break;
case kWasmI64:
case ValueType::kI64:
assm->Usd(src.gp(), dst);
break;
case kWasmF32:
case ValueType::kF32:
assm->Uswc1(src.fp(), dst, t8);
break;
case kWasmF64:
case ValueType::kF64:
assm->Usdc1(src.fp(), dst, t8);
break;
default:
......@@ -88,19 +88,19 @@ inline void Store(LiftoffAssembler* assm, Register base, int32_t offset,
}
inline void push(LiftoffAssembler* assm, LiftoffRegister reg, ValueType type) {
switch (type) {
case kWasmI32:
switch (type.kind()) {
case ValueType::kI32:
assm->daddiu(sp, sp, -kSystemPointerSize);
assm->sw(reg.gp(), MemOperand(sp, 0));
break;
case kWasmI64:
case ValueType::kI64:
assm->push(reg.gp());
break;
case kWasmF32:
case ValueType::kF32:
assm->daddiu(sp, sp, -kSystemPointerSize);
assm->swc1(reg.fp(), MemOperand(sp, 0));
break;
case kWasmF64:
case ValueType::kF64:
assm->daddiu(sp, sp, -kSystemPointerSize);
assm->Sdc1(reg.fp(), MemOperand(sp, 0));
break;
......@@ -256,17 +256,17 @@ constexpr int LiftoffAssembler::StaticStackFrameSize() {
}
int LiftoffAssembler::SlotSizeForType(ValueType type) {
switch (type) {
case kWasmS128:
return ValueTypes::ElementSizeInBytes(type);
switch (type.kind()) {
case ValueType::kS128:
return type.element_size_bytes();
default:
return kStackSlotSize;
}
}
bool LiftoffAssembler::NeedsAlignment(ValueType type) {
switch (type) {
case kWasmS128:
switch (type.kind()) {
case ValueType::kS128:
return true;
default:
// No alignment because all other types are kStackSlotSize.
......@@ -276,17 +276,17 @@ bool LiftoffAssembler::NeedsAlignment(ValueType type) {
void LiftoffAssembler::LoadConstant(LiftoffRegister reg, WasmValue value,
RelocInfo::Mode rmode) {
switch (value.type()) {
case kWasmI32:
switch (value.type().kind()) {
case ValueType::kI32:
TurboAssembler::li(reg.gp(), Operand(value.to_i32(), rmode));
break;
case kWasmI64:
case ValueType::kI64:
TurboAssembler::li(reg.gp(), Operand(value.to_i64(), rmode));
break;
case kWasmF32:
case ValueType::kF32:
TurboAssembler::Move(reg.fp(), value.to_f32_boxed().get_bits());
break;
case kWasmF64:
case ValueType::kF64:
TurboAssembler::Move(reg.fp(), value.to_f64_boxed().get_bits());
break;
default:
......@@ -529,17 +529,17 @@ void LiftoffAssembler::Move(DoubleRegister dst, DoubleRegister src,
void LiftoffAssembler::Spill(int offset, LiftoffRegister reg, ValueType type) {
RecordUsedSpillOffset(offset);
MemOperand dst = liftoff::GetStackSlot(offset);
switch (type) {
case kWasmI32:
switch (type.kind()) {
case ValueType::kI32:
Sw(reg.gp(), dst);
break;
case kWasmI64:
case ValueType::kI64:
Sd(reg.gp(), dst);
break;
case kWasmF32:
case ValueType::kF32:
Swc1(reg.fp(), dst);
break;
case kWasmF64:
case ValueType::kF64:
TurboAssembler::Sdc1(reg.fp(), dst);
break;
default:
......@@ -550,14 +550,14 @@ void LiftoffAssembler::Spill(int offset, LiftoffRegister reg, ValueType type) {
void LiftoffAssembler::Spill(int offset, WasmValue value) {
RecordUsedSpillOffset(offset);
MemOperand dst = liftoff::GetStackSlot(offset);
switch (value.type()) {
case kWasmI32: {
switch (value.type().kind()) {
case ValueType::kI32: {
LiftoffRegister tmp = GetUnusedRegister(kGpReg);
TurboAssembler::li(tmp.gp(), Operand(value.to_i32()));
sw(tmp.gp(), dst);
break;
}
case kWasmI64: {
case ValueType::kI64: {
LiftoffRegister tmp = GetUnusedRegister(kGpReg);
TurboAssembler::li(tmp.gp(), value.to_i64());
sd(tmp.gp(), dst);
......@@ -572,17 +572,17 @@ void LiftoffAssembler::Spill(int offset, WasmValue value) {
void LiftoffAssembler::Fill(LiftoffRegister reg, int offset, ValueType type) {
MemOperand src = liftoff::GetStackSlot(offset);
switch (type) {
case kWasmI32:
switch (type.kind()) {
case ValueType::kI32:
Lw(reg.gp(), src);
break;
case kWasmI64:
case ValueType::kI64:
Ld(reg.gp(), src);
break;
case kWasmF32:
case ValueType::kF32:
Lwc1(reg.fp(), src);
break;
case kWasmF64:
case ValueType::kF64:
TurboAssembler::Ldc1(reg.fp(), src);
break;
default:
......@@ -1572,7 +1572,7 @@ void LiftoffAssembler::CallC(const wasm::FunctionSig* sig,
int arg_bytes = 0;
for (ValueType param_type : sig->parameters()) {
liftoff::Store(this, sp, arg_bytes, *args++, param_type);
arg_bytes += ValueTypes::MemSize(param_type);
arg_bytes += param_type.element_size_bytes();
}
DCHECK_LE(arg_bytes, stack_bytes);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment