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