Commit 5ccf1bf9 authored by Manos Koukoutos's avatar Manos Koukoutos Committed by Commit Bot

[wasm][refactor] Make SigEnv a ZoneObject

Also, change its 'locals' field to a ZoneVector.
This is needed for 'let' as per [wasm-gc].

Bug: v8:7748
Change-Id: I9e6ca7f7e483b4bc13b64643107297be31af0e35
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2202995
Commit-Queue: Manos Koukoutos <manoskouk@chromium.org>
Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67847}
parent 5699fab9
......@@ -28,18 +28,19 @@ namespace {
// as well as the current effect and control dependency in the TF graph.
// It maintains a control state that tracks whether the environment
// is reachable, has reached a control end, or has been merged.
struct SsaEnv {
struct SsaEnv : public ZoneObject {
enum State { kControlEnd, kUnreachable, kReached, kMerged };
State state;
TFNode* control;
TFNode* effect;
compiler::WasmInstanceCacheNodes instance_cache;
TFNode** locals;
ZoneVector<TFNode*> locals;
explicit SsaEnv(Zone* zone) : locals(zone) {}
void Kill(State new_state = kControlEnd) {
state = new_state;
locals = nullptr;
locals.clear();
control = nullptr;
effect = nullptr;
instance_cache = {};
......@@ -98,15 +99,10 @@ class WasmGraphBuildingInterface {
: builder_(builder) {}
void StartFunction(FullDecoder* decoder) {
SsaEnv* ssa_env =
reinterpret_cast<SsaEnv*>(decoder->zone()->New(sizeof(SsaEnv)));
SsaEnv* ssa_env = new (decoder->zone()) SsaEnv(decoder->zone());
uint32_t num_locals = decoder->num_locals();
uint32_t env_count = num_locals;
size_t size = sizeof(TFNode*) * env_count;
ssa_env->state = SsaEnv::kReached;
ssa_env->locals =
size > 0 ? reinterpret_cast<TFNode**>(decoder->zone()->New(size))
: nullptr;
ssa_env->locals.resize(num_locals);
// The first '+ 1' is needed by TF Start node, the second '+ 1' is for the
// instance parameter.
......@@ -275,20 +271,17 @@ class WasmGraphBuildingInterface {
void LocalGet(FullDecoder* decoder, Value* result,
const LocalIndexImmediate<validate>& imm) {
if (!ssa_env_->locals) return; // unreachable
result->node = ssa_env_->locals[imm.index];
}
void LocalSet(FullDecoder* decoder, const Value& value,
const LocalIndexImmediate<validate>& imm) {
if (!ssa_env_->locals) return; // unreachable
ssa_env_->locals[imm.index] = value.node;
}
void LocalTee(FullDecoder* decoder, const Value& value, Value* result,
const LocalIndexImmediate<validate>& imm) {
result->node = value.node;
if (!ssa_env_->locals) return; // unreachable
ssa_env_->locals[imm.index] = value.node;
}
......@@ -946,19 +939,12 @@ class WasmGraphBuildingInterface {
ssa_env_->control = control();
ssa_env_->effect = effect();
}
SsaEnv* result =
reinterpret_cast<SsaEnv*>(decoder->zone()->New(sizeof(SsaEnv)));
size_t size = sizeof(TFNode*) * decoder->num_locals();
SsaEnv* result = new (decoder->zone()) SsaEnv(decoder->zone());
result->control = from->control;
result->effect = from->effect;
result->state = SsaEnv::kReached;
if (size > 0) {
result->locals = reinterpret_cast<TFNode**>(decoder->zone()->New(size));
memcpy(result->locals, from->locals, size);
} else {
result->locals = nullptr;
}
result->locals = from->locals;
result->instance_cache = from->instance_cache;
return result;
......@@ -972,9 +958,9 @@ class WasmGraphBuildingInterface {
ssa_env_->control = control();
ssa_env_->effect = effect();
}
SsaEnv* result = reinterpret_cast<SsaEnv*>(zone->New(sizeof(SsaEnv)));
SsaEnv* result = new (zone) SsaEnv(zone);
result->state = SsaEnv::kReached;
result->locals = from->locals;
result->locals = std::move(from->locals);
result->control = from->control;
result->effect = from->effect;
result->instance_cache = from->instance_cache;
......@@ -984,11 +970,10 @@ class WasmGraphBuildingInterface {
// Create an unreachable environment.
SsaEnv* UnreachableEnv(Zone* zone) {
SsaEnv* result = reinterpret_cast<SsaEnv*>(zone->New(sizeof(SsaEnv)));
SsaEnv* result = new (zone) SsaEnv(zone);
result->state = SsaEnv::kUnreachable;
result->control = nullptr;
result->effect = nullptr;
result->locals = nullptr;
result->instance_cache = {};
return result;
}
......
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