Commit 314da8ee authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Remove reachability checks from TF backend

The function body decoder already tracks reachability and only calls
the backend for reachable code. Thus the checks in the TF backend can
be skipped.
Note that there was already a DCHECK in place that checks whether
{SsaEnv::reached()} always returns true. This was to give fuzzers a
chance to prove the reachability analysis in the function body decoder
wrong. Since this did not happen, we can not remove the {reached()}
method from SsaEnv, since it always returned true anyway.

R=titzer@chromium.org

Bug: v8:8423, v8:8611
Change-Id: I2336aa7a092e381e3d94d87051b6e14db0dbab99
Reviewed-on: https://chromium-review.googlesource.com/c/1415493Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#58871}
parent 2f543fad
...@@ -36,14 +36,6 @@ struct SsaEnv { ...@@ -36,14 +36,6 @@ struct SsaEnv {
compiler::WasmInstanceCacheNodes instance_cache; compiler::WasmInstanceCacheNodes instance_cache;
TFNode** locals; TFNode** locals;
bool reached() const {
// The function body decoder already keeps track of reached vs unreached
// code. Each SsaEnv we work with should be reached.
// TODO(clemensh): Remove this method (https://crbug.com/v8/8611).
DCHECK_LE(kReached, state);
return state >= kReached;
}
void Kill(State new_state = kControlEnd) { void Kill(State new_state = kControlEnd) {
state = new_state; state = new_state;
locals = nullptr; locals = nullptr;
...@@ -58,7 +50,6 @@ struct SsaEnv { ...@@ -58,7 +50,6 @@ struct SsaEnv {
#define BUILD(func, ...) \ #define BUILD(func, ...) \
([&] { \ ([&] { \
DCHECK(ssa_env_->reached()); \
DCHECK(decoder->ok()); \ DCHECK(decoder->ok()); \
return CheckForException(decoder, builder_->func(__VA_ARGS__)); \ return CheckForException(decoder, builder_->func(__VA_ARGS__)); \
})() })()
...@@ -148,8 +139,7 @@ class WasmGraphBuildingInterface { ...@@ -148,8 +139,7 @@ class WasmGraphBuildingInterface {
// Reload the instance cache entries into the Ssa Environment. // Reload the instance cache entries into the Ssa Environment.
void LoadContextIntoSsa(SsaEnv* ssa_env) { void LoadContextIntoSsa(SsaEnv* ssa_env) {
if (!ssa_env || !ssa_env->reached()) return; if (ssa_env) builder_->InitInstanceCache(&ssa_env->instance_cache);
builder_->InitInstanceCache(&ssa_env->instance_cache);
} }
void StartFunctionBody(FullDecoder* decoder, Control* block) {} void StartFunctionBody(FullDecoder* decoder, Control* block) {}
...@@ -198,9 +188,7 @@ class WasmGraphBuildingInterface { ...@@ -198,9 +188,7 @@ class WasmGraphBuildingInterface {
void If(FullDecoder* decoder, const Value& cond, Control* if_block) { void If(FullDecoder* decoder, const Value& cond, Control* if_block) {
TFNode* if_true = nullptr; TFNode* if_true = nullptr;
TFNode* if_false = nullptr; TFNode* if_false = nullptr;
if (ssa_env_->reached()) {
BUILD(BranchNoHint, cond.node, &if_true, &if_false); BUILD(BranchNoHint, cond.node, &if_true, &if_false);
}
SsaEnv* end_env = ssa_env_; SsaEnv* end_env = ssa_env_;
SsaEnv* false_env = Split(decoder, ssa_env_); SsaEnv* false_env = Split(decoder, ssa_env_);
false_env->control = if_false; false_env->control = if_false;
...@@ -665,7 +653,6 @@ class WasmGraphBuildingInterface { ...@@ -665,7 +653,6 @@ class WasmGraphBuildingInterface {
void MergeValuesInto(FullDecoder* decoder, Control* c, Merge<Value>* merge) { void MergeValuesInto(FullDecoder* decoder, Control* c, Merge<Value>* merge) {
DCHECK(merge == &c->start_merge || merge == &c->end_merge); DCHECK(merge == &c->start_merge || merge == &c->end_merge);
if (!ssa_env_->reached()) return;
SsaEnv* target = c->end_env; SsaEnv* target = c->end_env;
const bool first = target->state == SsaEnv::kUnreachable; const bool first = target->state == SsaEnv::kUnreachable;
...@@ -692,7 +679,6 @@ class WasmGraphBuildingInterface { ...@@ -692,7 +679,6 @@ class WasmGraphBuildingInterface {
void Goto(FullDecoder* decoder, SsaEnv* from, SsaEnv* to) { void Goto(FullDecoder* decoder, SsaEnv* from, SsaEnv* to) {
DCHECK_NOT_NULL(to); DCHECK_NOT_NULL(to);
if (!from->reached()) return;
switch (to->state) { switch (to->state) {
case SsaEnv::kUnreachable: { // Overwrite destination. case SsaEnv::kUnreachable: { // Overwrite destination.
to->state = SsaEnv::kReached; to->state = SsaEnv::kReached;
...@@ -753,7 +739,6 @@ class WasmGraphBuildingInterface { ...@@ -753,7 +739,6 @@ class WasmGraphBuildingInterface {
} }
SsaEnv* PrepareForLoop(FullDecoder* decoder, SsaEnv* env) { SsaEnv* PrepareForLoop(FullDecoder* decoder, SsaEnv* env) {
if (!env->reached()) return Split(decoder, env);
env->state = SsaEnv::kMerged; env->state = SsaEnv::kMerged;
env->control = builder_->Loop(env->control); env->control = builder_->Loop(env->control);
...@@ -807,18 +792,12 @@ class WasmGraphBuildingInterface { ...@@ -807,18 +792,12 @@ class WasmGraphBuildingInterface {
result->control = from->control; result->control = from->control;
result->effect = from->effect; result->effect = from->effect;
if (from->reached()) {
result->state = SsaEnv::kReached; result->state = SsaEnv::kReached;
result->locals = result->locals =
size > 0 ? reinterpret_cast<TFNode**>(decoder->zone()->New(size)) size > 0 ? reinterpret_cast<TFNode**>(decoder->zone()->New(size))
: nullptr; : nullptr;
memcpy(result->locals, from->locals, size); memcpy(result->locals, from->locals, size);
result->instance_cache = from->instance_cache; result->instance_cache = from->instance_cache;
} else {
result->state = SsaEnv::kUnreachable;
result->locals = nullptr;
result->instance_cache = {};
}
return result; return result;
} }
...@@ -827,7 +806,6 @@ class WasmGraphBuildingInterface { ...@@ -827,7 +806,6 @@ class WasmGraphBuildingInterface {
// unreachable. // unreachable.
SsaEnv* Steal(Zone* zone, SsaEnv* from) { SsaEnv* Steal(Zone* zone, SsaEnv* from) {
DCHECK_NOT_NULL(from); DCHECK_NOT_NULL(from);
if (!from->reached()) return UnreachableEnv(zone);
SsaEnv* result = reinterpret_cast<SsaEnv*>(zone->New(sizeof(SsaEnv))); SsaEnv* result = reinterpret_cast<SsaEnv*>(zone->New(sizeof(SsaEnv)));
result->state = SsaEnv::kReached; result->state = SsaEnv::kReached;
result->locals = from->locals; result->locals = from->locals;
......
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