[wasm] Use graph assembler to fix effect chain

There is a verification phase in the graph verifier that is currently
disabled for WebAssembly. This CL is a first step to enable this
verification phase for WebAssembly.

CC=manoskouk@chromium.org
R=clemensb@chromium.org

Bug: v8:11236
Change-Id: I925153511f8f93e6d32d05008ddce800e61d5488
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2575062
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#71656}
This commit is contained in:
Andreas Haas 2020-12-07 20:39:20 +01:00 committed by Commit Bot
parent 88f7740636
commit 45fd31f808
2 changed files with 18 additions and 24 deletions

View File

@ -514,10 +514,8 @@ void WasmGraphBuilder::StackCheck(wasm::WasmCodePosition position) {
return;
}
Node* limit_address = graph()->NewNode(
mcgraph()->machine()->Load(MachineType::Pointer()), instance_node_.get(),
mcgraph()->Int32Constant(WASM_INSTANCE_OBJECT_OFFSET(StackLimitAddress)),
effect(), control());
Node* limit_address =
LOAD_INSTANCE_FIELD(StackLimitAddress, MachineType::Pointer());
Node* limit = SetEffect(graph()->NewNode(
mcgraph()->machine()->Load(MachineType::Pointer()), limit_address,
mcgraph()->IntPtrConstant(0), limit_address, control()));
@ -3496,12 +3494,8 @@ void WasmGraphBuilder::SetEffectControl(Node* effect, Node* control) {
Node* WasmGraphBuilder::GetImportedMutableGlobals() {
if (imported_mutable_globals_ == nullptr) {
// Load imported_mutable_globals_ from the instance object at runtime.
imported_mutable_globals_ = graph()->NewNode(
mcgraph()->machine()->Load(MachineType::UintPtr()),
instance_node_.get(),
mcgraph()->Int32Constant(
WASM_INSTANCE_OBJECT_OFFSET(ImportedMutableGlobals)),
graph()->start(), graph()->start());
imported_mutable_globals_ =
LOAD_INSTANCE_FIELD(ImportedMutableGlobals, MachineType::UintPtr());
}
return imported_mutable_globals_.get();
}
@ -6052,16 +6046,12 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Node* BuildLoadUndefinedValueFromInstance() {
if (undefined_value_node_ == nullptr) {
Node* isolate_root = graph()->NewNode(
mcgraph()->machine()->Load(MachineType::Pointer()),
instance_node_.get(),
mcgraph()->Int32Constant(WASM_INSTANCE_OBJECT_OFFSET(IsolateRoot)),
graph()->start(), graph()->start());
undefined_value_node_ = graph()->NewNode(
mcgraph()->machine()->Load(MachineType::Pointer()), isolate_root,
Node* isolate_root =
LOAD_INSTANCE_FIELD(IsolateRoot, MachineType::Pointer());
undefined_value_node_ = gasm_->Load(
MachineType::Pointer(), isolate_root,
mcgraph()->Int32Constant(
IsolateData::root_slot_offset(RootIndex::kUndefinedValue)),
isolate_root, graph()->start());
IsolateData::root_slot_offset(RootIndex::kUndefinedValue)));
}
return undefined_value_node_.get();
}
@ -6552,7 +6542,14 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Node* jsval;
if (sig_->return_count() == 0) {
jsval = BuildLoadUndefinedValueFromInstance();
// We do not use {BuildLoadUndefinedValueFromInstance} here because it
// would create an invalid graph.
Node* isolate_root =
LOAD_INSTANCE_FIELD(IsolateRoot, MachineType::Pointer());
jsval = gasm_->Load(
MachineType::Pointer(), isolate_root,
mcgraph()->Int32Constant(
IsolateData::root_slot_offset(RootIndex::kUndefinedValue)));
} else if (sig_->return_count() == 1) {
jsval = ToJS(rets[0], sig_->GetReturn());
} else {

View File

@ -121,10 +121,8 @@ class WasmGraphBuildingInterface {
uint32_t num_locals = decoder->num_locals();
SsaEnv* ssa_env = decoder->zone()->New<SsaEnv>(
decoder->zone(), SsaEnv::kReached, start, start, num_locals);
SetEnv(ssa_env);
// Initialize effect and control before initializing the locals default
// values (which might require instance loads) or loading the context.
builder_->SetEffectControl(start);
// Initialize the instance parameter (index 0).
builder_->set_instance_node(builder_->Param(kWasmInstanceParameterIndex));
// Initialize local variables. Parameters are shifted by 1 because of the
@ -141,7 +139,6 @@ class WasmGraphBuildingInterface {
ssa_env->locals[index++] = node;
}
}
SetEnv(ssa_env);
LoadContextIntoSsa(ssa_env);
if (FLAG_trace_wasm) BUILD(TraceFunctionEntry, decoder->position());