[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; return;
} }
Node* limit_address = graph()->NewNode( Node* limit_address =
mcgraph()->machine()->Load(MachineType::Pointer()), instance_node_.get(), LOAD_INSTANCE_FIELD(StackLimitAddress, MachineType::Pointer());
mcgraph()->Int32Constant(WASM_INSTANCE_OBJECT_OFFSET(StackLimitAddress)),
effect(), control());
Node* limit = SetEffect(graph()->NewNode( Node* limit = SetEffect(graph()->NewNode(
mcgraph()->machine()->Load(MachineType::Pointer()), limit_address, mcgraph()->machine()->Load(MachineType::Pointer()), limit_address,
mcgraph()->IntPtrConstant(0), limit_address, control())); mcgraph()->IntPtrConstant(0), limit_address, control()));
@ -3496,12 +3494,8 @@ void WasmGraphBuilder::SetEffectControl(Node* effect, Node* control) {
Node* WasmGraphBuilder::GetImportedMutableGlobals() { Node* WasmGraphBuilder::GetImportedMutableGlobals() {
if (imported_mutable_globals_ == nullptr) { if (imported_mutable_globals_ == nullptr) {
// Load imported_mutable_globals_ from the instance object at runtime. // Load imported_mutable_globals_ from the instance object at runtime.
imported_mutable_globals_ = graph()->NewNode( imported_mutable_globals_ =
mcgraph()->machine()->Load(MachineType::UintPtr()), LOAD_INSTANCE_FIELD(ImportedMutableGlobals, MachineType::UintPtr());
instance_node_.get(),
mcgraph()->Int32Constant(
WASM_INSTANCE_OBJECT_OFFSET(ImportedMutableGlobals)),
graph()->start(), graph()->start());
} }
return imported_mutable_globals_.get(); return imported_mutable_globals_.get();
} }
@ -6052,16 +6046,12 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Node* BuildLoadUndefinedValueFromInstance() { Node* BuildLoadUndefinedValueFromInstance() {
if (undefined_value_node_ == nullptr) { if (undefined_value_node_ == nullptr) {
Node* isolate_root = graph()->NewNode( Node* isolate_root =
mcgraph()->machine()->Load(MachineType::Pointer()), LOAD_INSTANCE_FIELD(IsolateRoot, MachineType::Pointer());
instance_node_.get(), undefined_value_node_ = gasm_->Load(
mcgraph()->Int32Constant(WASM_INSTANCE_OBJECT_OFFSET(IsolateRoot)), MachineType::Pointer(), isolate_root,
graph()->start(), graph()->start());
undefined_value_node_ = graph()->NewNode(
mcgraph()->machine()->Load(MachineType::Pointer()), isolate_root,
mcgraph()->Int32Constant( mcgraph()->Int32Constant(
IsolateData::root_slot_offset(RootIndex::kUndefinedValue)), IsolateData::root_slot_offset(RootIndex::kUndefinedValue)));
isolate_root, graph()->start());
} }
return undefined_value_node_.get(); return undefined_value_node_.get();
} }
@ -6552,7 +6542,14 @@ class WasmWrapperGraphBuilder : public WasmGraphBuilder {
Node* jsval; Node* jsval;
if (sig_->return_count() == 0) { 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) { } else if (sig_->return_count() == 1) {
jsval = ToJS(rets[0], sig_->GetReturn()); jsval = ToJS(rets[0], sig_->GetReturn());
} else { } else {

View File

@ -121,10 +121,8 @@ class WasmGraphBuildingInterface {
uint32_t num_locals = decoder->num_locals(); uint32_t num_locals = decoder->num_locals();
SsaEnv* ssa_env = decoder->zone()->New<SsaEnv>( SsaEnv* ssa_env = decoder->zone()->New<SsaEnv>(
decoder->zone(), SsaEnv::kReached, start, start, num_locals); 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). // Initialize the instance parameter (index 0).
builder_->set_instance_node(builder_->Param(kWasmInstanceParameterIndex)); builder_->set_instance_node(builder_->Param(kWasmInstanceParameterIndex));
// Initialize local variables. Parameters are shifted by 1 because of the // Initialize local variables. Parameters are shifted by 1 because of the
@ -141,7 +139,6 @@ class WasmGraphBuildingInterface {
ssa_env->locals[index++] = node; ssa_env->locals[index++] = node;
} }
} }
SetEnv(ssa_env);
LoadContextIntoSsa(ssa_env); LoadContextIntoSsa(ssa_env);
if (FLAG_trace_wasm) BUILD(TraceFunctionEntry, decoder->position()); if (FLAG_trace_wasm) BUILD(TraceFunctionEntry, decoder->position());