[wasm] Simplify type checking for merges
Improve readability by avoiding a helper method. Just read from the stack directly. R=titzer@chromium.org Change-Id: I38c944fac45c721f328a2b7bec3a3f4602f05c05 Reviewed-on: https://chromium-review.googlesource.com/c/1360572 Commit-Queue: Clemens Hammacher <clemensh@chromium.org> Reviewed-by: Ben Titzer <titzer@chromium.org> Cr-Commit-Position: refs/heads/master@{#58023}
This commit is contained in:
parent
4ab8c906e1
commit
1fba4b7cff
@ -1508,12 +1508,10 @@ class WasmFullDecoder : public WasmDecoder<validate> {
|
||||
return static_cast<uint32_t>(stack_.size());
|
||||
}
|
||||
|
||||
inline Value& GetMergeValueFromStack(
|
||||
Control* c, Merge<Value>* merge, uint32_t i) {
|
||||
DCHECK(merge == &c->start_merge || merge == &c->end_merge);
|
||||
DCHECK_GT(merge->arity, i);
|
||||
DCHECK_GE(stack_.size(), c->stack_depth + merge->arity);
|
||||
return stack_[stack_.size() - merge->arity + i];
|
||||
inline Value* stack_value(uint32_t depth) {
|
||||
DCHECK_LT(0, depth);
|
||||
DCHECK_GE(stack_.size(), depth);
|
||||
return &*(stack_.end() - depth);
|
||||
}
|
||||
|
||||
private:
|
||||
@ -2645,10 +2643,13 @@ class WasmFullDecoder : public WasmDecoder<validate> {
|
||||
bool TypeCheckMergeValues(Control* c, Merge<Value>* merge) {
|
||||
DCHECK(merge == &c->start_merge || merge == &c->end_merge);
|
||||
DCHECK_GE(stack_.size(), c->stack_depth + merge->arity);
|
||||
// The computation of {stack_values} is only valid if {merge->arity} is >0.
|
||||
DCHECK_LT(0, merge->arity);
|
||||
Value* stack_values = &*(stack_.end() - merge->arity);
|
||||
// Typecheck the topmost {merge->arity} values on the stack.
|
||||
for (uint32_t i = 0; i < merge->arity; ++i) {
|
||||
auto& val = GetMergeValueFromStack(c, merge, i);
|
||||
auto& old = (*merge)[i];
|
||||
Value& val = stack_values[i];
|
||||
Value& old = (*merge)[i];
|
||||
if (val.type != old.type) {
|
||||
// If {val.type} is polymorphic, which results from unreachable, make
|
||||
// it more specific by using the merge value's expected type.
|
||||
@ -2680,6 +2681,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
|
||||
expected, startrel(c->pc), actual);
|
||||
return false;
|
||||
}
|
||||
if (expected == 0) return true; // Fast path.
|
||||
|
||||
return TypeCheckMergeValues(c, &c->end_merge);
|
||||
}
|
||||
@ -2687,6 +2689,7 @@ class WasmFullDecoder : public WasmDecoder<validate> {
|
||||
bool TypeCheckBreak(Control* c) {
|
||||
// Breaks must have at least the number of values expected; can have more.
|
||||
uint32_t expected = c->br_merge()->arity;
|
||||
if (expected == 0) return true; // Fast path.
|
||||
DCHECK_GE(stack_.size(), control_.back().stack_depth);
|
||||
uint32_t actual =
|
||||
static_cast<uint32_t>(stack_.size()) - control_.back().stack_depth;
|
||||
|
@ -649,12 +649,16 @@ class WasmGraphBuildingInterface {
|
||||
const bool first = target->state == SsaEnv::kUnreachable;
|
||||
Goto(decoder, ssa_env_, target);
|
||||
|
||||
if (merge->arity == 0) return;
|
||||
|
||||
uint32_t avail =
|
||||
decoder->stack_size() - decoder->control_at(0)->stack_depth;
|
||||
DCHECK_GE(avail, merge->arity);
|
||||
uint32_t start = avail >= merge->arity ? 0 : merge->arity - avail;
|
||||
Value* stack_values = decoder->stack_value(merge->arity);
|
||||
for (uint32_t i = start; i < merge->arity; ++i) {
|
||||
auto& val = decoder->GetMergeValueFromStack(c, merge, i);
|
||||
auto& old = (*merge)[i];
|
||||
Value& val = stack_values[i];
|
||||
Value& old = (*merge)[i];
|
||||
DCHECK_NOT_NULL(val.node);
|
||||
DCHECK(val.type == old.type || val.type == kWasmVar);
|
||||
old.node = first ? val.node
|
||||
|
Loading…
Reference in New Issue
Block a user