Commit f3897c7e authored by Eric Holk's avatar Eric Holk Committed by Commit Bot

[wasm] cleanup after https://crrev.com/c/802322

Bug: v8:7143
Change-Id: Ie8eee40ba1761a5790dc67a8ce03d2b2cb949722
Reviewed-on: https://chromium-review.googlesource.com/815677
Commit-Queue: Eric Holk <eholk@chromium.org>
Reviewed-by: 's avatarMircea Trofin <mtrofin@chromium.org>
Reviewed-by: 's avatarClemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49975}
parent 70598c50
......@@ -72,8 +72,8 @@ void MergeControlToEnd(JSGraph* jsgraph, Node* node) {
} // namespace
WasmGraphBuilder::WasmGraphBuilder(
const ModuleEnv* env, bool use_trap_handler, Zone* zone, JSGraph* jsgraph,
Handle<Code> centry_stub, wasm::FunctionSig* sig,
ModuleEnv* env, Zone* zone, JSGraph* jsgraph, Handle<Code> centry_stub,
wasm::FunctionSig* sig,
compiler::SourcePositionTable* source_position_table,
RuntimeExceptionSupport exception_support)
: zone_(zone),
......@@ -85,11 +85,10 @@ WasmGraphBuilder::WasmGraphBuilder(
function_table_sizes_(zone),
cur_buffer_(def_buffer_),
cur_bufsize_(kDefaultBufferSize),
use_trap_handler_(use_trap_handler),
runtime_exception_support_(exception_support),
sig_(sig),
source_position_table_(source_position_table) {
DCHECK_IMPLIES(use_trap_handler_, trap_handler::IsTrapHandlerEnabled());
DCHECK_IMPLIES(use_trap_handler(), trap_handler::IsTrapHandlerEnabled());
for (size_t i = sig->parameter_count(); i > 0 && !has_simd_; --i) {
if (sig->GetParam(i - 1) == wasm::kWasmS128) has_simd_ = true;
}
......@@ -3344,7 +3343,7 @@ void WasmGraphBuilder::EnsureFunctionTableNodes() {
Node* WasmGraphBuilder::BuildModifyThreadInWasmFlag(bool new_value) {
// TODO(eholk): generate code to modify the thread-local storage directly,
// rather than calling the runtime.
if (!UseTrapHandler()) {
if (!use_trap_handler()) {
return *control_;
}
......@@ -3557,13 +3556,13 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype,
graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), index);
}
// Wasm semantics throw on OOB. Introduce explicit bounds check.
if (!UseTrapHandler()) {
if (!use_trap_handler()) {
BoundsCheckMem(memtype, index, offset, position);
}
if (memtype.representation() == MachineRepresentation::kWord8 ||
jsgraph()->machine()->UnalignedLoadSupported(memtype.representation())) {
if (UseTrapHandler()) {
if (use_trap_handler()) {
load = graph()->NewNode(jsgraph()->machine()->ProtectedLoad(memtype),
MemBuffer(offset), index, *effect_, *control_);
SetSourcePosition(load, position);
......@@ -3573,7 +3572,7 @@ Node* WasmGraphBuilder::LoadMem(wasm::ValueType type, MachineType memtype,
}
} else {
// TODO(eholk): Support unaligned loads with trap handlers.
DCHECK(!UseTrapHandler());
DCHECK(!use_trap_handler());
load = graph()->NewNode(jsgraph()->machine()->UnalignedLoad(memtype),
MemBuffer(offset), index, *effect_, *control_);
}
......@@ -3616,7 +3615,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
graph()->NewNode(jsgraph()->machine()->ChangeUint32ToUint64(), index);
}
// Wasm semantics throw on OOB. Introduce explicit bounds check.
if (!UseTrapHandler()) {
if (!use_trap_handler()) {
BoundsCheckMem(memtype, index, offset, position);
}
......@@ -3626,7 +3625,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
if (memtype.representation() == MachineRepresentation::kWord8 ||
jsgraph()->machine()->UnalignedStoreSupported(memtype.representation())) {
if (UseTrapHandler()) {
if (use_trap_handler()) {
store = graph()->NewNode(
jsgraph()->machine()->ProtectedStore(memtype.representation()),
MemBuffer(offset), index, val, *effect_, *control_);
......@@ -3639,7 +3638,7 @@ Node* WasmGraphBuilder::StoreMem(MachineType memtype, Node* index,
}
} else {
// TODO(eholk): Support unaligned stores with trap handlers.
DCHECK(!UseTrapHandler());
DCHECK(!use_trap_handler());
UnalignedStoreRepresentation rep(memtype.representation());
store =
graph()->NewNode(jsgraph()->machine()->UnalignedStore(rep),
......@@ -4389,7 +4388,8 @@ Handle<Code> CompileWasmToJSWrapper(
origin == wasm::kAsmJsOrigin ? new (&zone) SourcePositionTable(&graph)
: nullptr;
WasmGraphBuilder builder(use_trap_handler, &zone, &jsgraph,
ModuleEnv env = {nullptr, {}, {}, {}, Handle<Code>(), use_trap_handler};
WasmGraphBuilder builder(&env, &zone, &jsgraph,
CEntryStub(isolate, 1).GetCode(), sig,
source_position_table);
builder.set_control_ptr(&control);
......@@ -4459,8 +4459,7 @@ Handle<Code> CompileWasmToJSWrapper(
Handle<Code> CompileWasmToWasmWrapper(Isolate* isolate, WasmCodeWrapper target,
wasm::FunctionSig* sig,
Address new_wasm_context_address,
bool use_trap_handler) {
Address new_wasm_context_address) {
//----------------------------------------------------------------------------
// Create the Graph
//----------------------------------------------------------------------------
......@@ -4476,8 +4475,14 @@ Handle<Code> CompileWasmToWasmWrapper(Isolate* isolate, WasmCodeWrapper target,
Node* control = nullptr;
Node* effect = nullptr;
WasmGraphBuilder builder(use_trap_handler, &zone, &jsgraph, Handle<Code>(),
sig);
ModuleEnv env = {
nullptr,
{},
{},
{},
Handle<Code>(),
!target.IsCodeObject() && target.GetWasmCode()->HasTrapHandlerIndex()};
WasmGraphBuilder builder(&env, &zone, &jsgraph, Handle<Code>(), sig);
builder.set_control_ptr(&control);
builder.set_effect_ptr(&effect);
builder.BuildWasmToWasmWrapper(target, new_wasm_context_address);
......@@ -4547,7 +4552,7 @@ Handle<Code> CompileWasmInterpreterEntry(Isolate* isolate, uint32_t func_index,
Node* control = nullptr;
Node* effect = nullptr;
WasmGraphBuilder builder(instance->UseTrapHandler(), &zone, &jsgraph,
WasmGraphBuilder builder(nullptr, &zone, &jsgraph,
CEntryStub(isolate, 1).GetCode(), sig);
builder.set_control_ptr(&control);
builder.set_effect_ptr(&effect);
......@@ -4614,8 +4619,8 @@ Handle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig,
Node* control = nullptr;
Node* effect = nullptr;
WasmGraphBuilder builder(trap_handler::IsTrapHandlerEnabled(), &zone,
&jsgraph, CEntryStub(isolate, 1).GetCode(), sig);
WasmGraphBuilder builder(nullptr, &zone, &jsgraph,
CEntryStub(isolate, 1).GetCode(), sig);
builder.set_control_ptr(&control);
builder.set_effect_ptr(&effect);
builder.BuildCWasmEntry(wasm_context_address);
......@@ -4754,11 +4759,9 @@ WasmCompilationUnit::WasmCompilationUnit(
runtime_exception_support_(exception_support),
native_module_(native_module),
lower_simd_(lower_simd),
use_trap_handler_(env && env->use_trap_handler),
protected_instructions_(
new std::vector<trap_handler::ProtectedInstructionData>()),
mode_(mode) {
DCHECK_IMPLIES(use_trap_handler_, trap_handler::IsTrapHandlerEnabled());
switch (mode_) {
case WasmCompilationUnit::CompilationMode::kLiftoff:
new (&liftoff_) LiftoffData(isolate);
......@@ -5011,14 +5014,7 @@ WasmCodeWrapper WasmCompilationUnit::FinishLiftoffCompilation(
WasmCodeWrapper ret;
if (!FLAG_wasm_jit_to_native) {
Handle<Code> code;
code = isolate_->factory()->NewCode(
desc, Code::WASM_FUNCTION, code, Builtins::kNoBuiltinId,
MaybeHandle<HandlerTable>(), MaybeHandle<ByteArray>(),
MaybeHandle<DeoptimizationData>(), kMovable,
0, // stub_key
false, // is_turbofanned
liftoff_.asm_.GetTotalFrameSlotCount(), // stack_slots
liftoff_.safepoint_table_offset_);
code = isolate_->factory()->NewCode(desc, Code::WASM_FUNCTION, code);
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_code || FLAG_print_wasm_code) {
// TODO(wasm): Use proper log files, here and elsewhere.
......
......@@ -112,8 +112,6 @@ class WasmCompilationUnit final {
size_t memory_cost() const { return memory_cost_; }
bool UseTrapHandler() const { return use_trap_handler_; }
private:
void PackProtectedInstructions(Handle<Code> code) const;
......@@ -157,7 +155,6 @@ class WasmCompilationUnit final {
size_t memory_cost_ = 0;
wasm::NativeModule* native_module_;
bool lower_simd_;
const bool use_trap_handler_;
std::shared_ptr<std::vector<trap_handler::ProtectedInstructionData>>
protected_instructions_;
CompilationMode mode_;
......@@ -191,8 +188,7 @@ V8_EXPORT_PRIVATE Handle<Code> CompileJSToWasmWrapper(
// wasm instances (the WasmContext address must be changed).
Handle<Code> CompileWasmToWasmWrapper(Isolate* isolate, WasmCodeWrapper target,
wasm::FunctionSig* sig,
Address new_wasm_context_address,
bool use_trap_handler);
Address new_wasm_context_address);
// Compiles a stub that redirects a call to a wasm function to the wasm
// interpreter. It's ABI compatible with the compiled wasm function.
......@@ -218,22 +214,10 @@ Handle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig,
typedef ZoneVector<Node*> NodeVector;
class WasmGraphBuilder {
public:
WasmGraphBuilder(const ModuleEnv* env, Zone* zone, JSGraph* graph,
WasmGraphBuilder(ModuleEnv* env, Zone* zone, JSGraph* graph,
Handle<Code> centry_stub, wasm::FunctionSig* sig,
compiler::SourcePositionTable* spt = nullptr,
RuntimeExceptionSupport res = kRuntimeExceptionSupport)
: WasmGraphBuilder(env, (env && env->use_trap_handler), zone, graph,
centry_stub, sig, spt, res) {
DCHECK_NOT_NULL(env);
}
// Same as above, but when no module environment is available.
WasmGraphBuilder(bool use_trap_handler, Zone* zone, JSGraph* graph,
Handle<Code> centry_stub, wasm::FunctionSig* sig,
compiler::SourcePositionTable* spt = nullptr,
RuntimeExceptionSupport res = kRuntimeExceptionSupport)
: WasmGraphBuilder(nullptr, use_trap_handler, zone, graph, centry_stub,
sig, spt, res) {}
RuntimeExceptionSupport res = kRuntimeExceptionSupport);
Node** Buffer(size_t count) {
if (count > cur_bufsize_) {
......@@ -412,7 +396,7 @@ class WasmGraphBuilder {
const wasm::WasmModule* module() { return env_ ? env_->module : nullptr; }
bool UseTrapHandler() const { return use_trap_handler_; }
bool use_trap_handler() const { return env_ && env_->use_trap_handler; }
private:
static const int kDefaultBufferSize = 16;
......@@ -420,7 +404,9 @@ class WasmGraphBuilder {
Zone* zone_;
JSGraph* jsgraph_;
Node* centry_stub_node_;
const ModuleEnv* env_ = nullptr;
// env_ == nullptr means we're not compiling Wasm functions, such as for
// wrappers or interpreter stubs.
ModuleEnv* env_ = nullptr;
Node* wasm_context_ = nullptr;
NodeVector signature_tables_;
NodeVector function_tables_;
......@@ -435,7 +421,6 @@ class WasmGraphBuilder {
Node* def_buffer_[kDefaultBufferSize];
bool has_simd_ = false;
bool needs_stack_check_ = false;
const bool use_trap_handler_;
// If the runtime doesn't support exception propagation,
// we won't generate stack checks, and trap handling will also
// be generated differently.
......@@ -446,10 +431,6 @@ class WasmGraphBuilder {
compiler::SourcePositionTable* source_position_table_ = nullptr;
WasmGraphBuilder(const ModuleEnv*, bool use_trap_handler, Zone*, JSGraph*,
Handle<Code> centry_stub_, wasm::FunctionSig*,
compiler::SourcePositionTable*, RuntimeExceptionSupport);
// Internal helper methods.
JSGraph* jsgraph() { return jsgraph_; }
Graph* graph();
......
......@@ -342,7 +342,7 @@ class InstanceBuilder {
}
Counters* counters() const { return async_counters().get(); }
bool UseTrapHandler() const { return compiled_module_->use_trap_handler(); }
bool use_trap_handler() const { return compiled_module_->use_trap_handler(); }
// Helper routines to print out errors with imports.
#define ERROR_THROWER_WITH_MESSAGE(TYPE) \
......@@ -1935,7 +1935,7 @@ WasmCodeWrapper MakeWasmToWasmWrapper(
if (!FLAG_wasm_jit_to_native) {
Handle<Code> wrapper_code = compiler::CompileWasmToWasmWrapper(
isolate, imported_function->GetWasmCode(), *sig,
new_wasm_context_address, instance->UseTrapHandler());
new_wasm_context_address);
// Set the deoptimization data for the WasmToWasm wrapper. This is
// needed by the interpreter to find the imported instance for
// a cross-instance call.
......@@ -1945,7 +1945,7 @@ WasmCodeWrapper MakeWasmToWasmWrapper(
} else {
Handle<Code> code = compiler::CompileWasmToWasmWrapper(
isolate, imported_function->GetWasmCode(), *sig,
new_wasm_context_address, instance->UseTrapHandler());
new_wasm_context_address);
return WasmCodeWrapper(
instance->compiled_module()->GetNativeModule()->AddCodeCopy(
code, wasm::WasmCode::kWasmToWasmWrapper, index));
......@@ -1967,15 +1967,15 @@ WasmCodeWrapper UnwrapExportOrCompileImportWrapper(
// signature.
if (FLAG_wasm_jit_to_native) {
Handle<Code> temp_code = compiler::CompileWasmToJSWrapper(
isolate, target, sig, import_index, origin, instance->UseTrapHandler(),
js_imports_table);
isolate, target, sig, import_index, origin,
instance->compiled_module()->use_trap_handler(), js_imports_table);
return WasmCodeWrapper(
instance->compiled_module()->GetNativeModule()->AddCodeCopy(
temp_code, wasm::WasmCode::kWasmToJsWrapper, import_index));
} else {
return WasmCodeWrapper(compiler::CompileWasmToJSWrapper(
isolate, target, sig, import_index, origin, instance->UseTrapHandler(),
js_imports_table));
isolate, target, sig, import_index, origin,
instance->compiled_module()->use_trap_handler(), js_imports_table));
}
}
......@@ -2436,7 +2436,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
// Set externally passed ArrayBuffer non neuterable.
memory->set_is_neuterable(false);
DCHECK_IMPLIES(UseTrapHandler(),
DCHECK_IMPLIES(use_trap_handler(),
module_->is_asm_js() || memory->has_guard_region());
} else if (initial_pages > 0) {
memory_ = AllocateMemory(initial_pages);
......@@ -2564,7 +2564,7 @@ MaybeHandle<WasmInstanceObject> InstanceBuilder::Build() {
//--------------------------------------------------------------------------
// Unpack and notify signal handler of protected instructions.
//--------------------------------------------------------------------------
if (UseTrapHandler()) {
if (use_trap_handler()) {
if (FLAG_wasm_jit_to_native) {
UnpackAndRegisterProtectedInstructions(isolate_, native_module);
} else {
......@@ -2986,8 +2986,7 @@ int InstanceBuilder::ProcessImports(Handle<FixedArray> code_table,
imported_instance->wasm_context()->get();
Handle<Code> wrapper = compiler::CompileWasmToWasmWrapper(
isolate_, target->GetWasmCode(), sig,
reinterpret_cast<Address>(other_context),
instance->UseTrapHandler());
reinterpret_cast<Address>(other_context));
set_of_native_module_scopes.Add(exporting_module);
wrapper_code = exporting_module->AddExportedWrapper(
wrapper, exported_code->index());
......@@ -3153,7 +3152,7 @@ Handle<JSArrayBuffer> InstanceBuilder::AllocateMemory(uint32_t num_pages) {
thrower_->RangeError("Out of memory: wasm memory too large");
return Handle<JSArrayBuffer>::null();
}
const bool enable_guard_regions = UseTrapHandler();
const bool enable_guard_regions = use_trap_handler();
Handle<JSArrayBuffer> mem_buffer = NewArrayBuffer(
isolate_, num_pages * WasmModule::kPageSize, enable_guard_regions);
......@@ -3546,7 +3545,7 @@ void InstanceBuilder::LoadTableSegments(Handle<FixedArray> code_table,
Handle<Code> wrapper_code =
js_to_wasm_cache_.CloneOrCompileJSToWasmWrapper(
isolate_, module_, wasm_code, func_index,
instance->UseTrapHandler());
instance->compiled_module()->use_trap_handler());
MaybeHandle<String> func_name;
if (module_->is_asm_js()) {
// For modules arising from asm.js, honor the names section.
......
......@@ -345,8 +345,7 @@ void WasmTableObject::Set(Isolate* isolate, Handle<WasmTableObject> table,
native_module->GetExportedWrapper(wasm_code.GetWasmCode()->index());
if (exported_wrapper == nullptr) {
Handle<Code> new_wrapper = compiler::CompileWasmToWasmWrapper(
isolate, wasm_code, wasm_function->sig, new_context_address,
exported_function->instance()->UseTrapHandler());
isolate, wasm_code, wasm_function->sig, new_context_address);
exported_wrapper = native_module->AddExportedWrapper(
new_wrapper, wasm_code.GetWasmCode()->index());
}
......@@ -357,8 +356,7 @@ void WasmTableObject::Set(Isolate* isolate, Handle<WasmTableObject> table,
isolate);
int func_index = exported_function->function_index();
code = compiler::CompileWasmToWasmWrapper(
isolate, wasm_code, wasm_function->sig, new_context_address,
instance->UseTrapHandler());
isolate, wasm_code, wasm_function->sig, new_context_address);
// TODO(6792): No longer needed once WebAssembly code is off heap.
CodeSpaceMemoryModificationScope modification_scope(isolate->heap());
AttachWasmFunctionInfo(isolate, Handle<Code>::cast(code), instance,
......@@ -560,10 +558,6 @@ int32_t WasmMemoryObject::Grow(Isolate* isolate,
return old_size / WasmModule::kPageSize;
}
bool WasmInstanceObject::UseTrapHandler() const {
return compiled_module()->use_trap_handler();
}
WasmModuleObject* WasmInstanceObject::module_object() {
return *compiled_module()->wasm_module();
}
......
......@@ -214,8 +214,6 @@ class WasmInstanceObject : public JSObject {
WasmModuleObject* module_object();
V8_EXPORT_PRIVATE wasm::WasmModule* module();
bool UseTrapHandler() const;
// Get the debug info associated with the given wasm object.
// If no debug info exists yet, it is created automatically.
static Handle<WasmDebugInfo> GetOrCreateDebugInfo(Handle<WasmInstanceObject>);
......
......@@ -300,9 +300,8 @@ void TestBuildingGraph(
TestBuildingGraphWithBuilder(&builder, zone, sig, start, end);
} else {
compiler::WasmGraphBuilder builder(
trap_handler::IsTrapHandlerEnabled(), zone, jsgraph,
CEntryStub(jsgraph->isolate(), 1).GetCode(), sig, source_position_table,
runtime_exception_support);
nullptr, zone, jsgraph, CEntryStub(jsgraph->isolate(), 1).GetCode(),
sig, source_position_table, runtime_exception_support);
TestBuildingGraphWithBuilder(&builder, zone, sig, start, end);
}
}
......
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