Commit 097b5c3b authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Move compilation-related structs to own header

This is to prepare larger refactorings that reduce the amount of
information stored in the WasmCompilationUnits and avoid ever storing
the ModuleEnv. Instead, we will generate it when needed. This will
allow us to correctly switch from a trap-handler configuration to
non-trap-handler.

R=mstarzinger@chromium.org

Bug: v8:8343, v8:5277
Change-Id: I383a8105448ccdcae1148ddfebd74db70c648ecf
Reviewed-on: https://chromium-review.googlesource.com/c/1293951Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56893}
parent 497723cf
......@@ -2583,6 +2583,7 @@ v8_source_set("v8_base") {
"src/wasm/baseline/liftoff-compiler.cc",
"src/wasm/baseline/liftoff-compiler.h",
"src/wasm/baseline/liftoff-register.h",
"src/wasm/compilation-environment.h",
"src/wasm/decoder.h",
"src/wasm/function-body-decoder-impl.h",
"src/wasm/function-body-decoder.cc",
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_WASM_COMPILATION_ENVIRONMENT_H_
#define V8_WASM_COMPILATION_ENVIRONMENT_H_
#include "src/wasm/function-body-decoder.h"
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
#include "src/wasm/wasm-tier.h"
namespace v8 {
namespace internal {
namespace wasm {
class CompilationState;
class LiftoffCompilationUnit;
struct ModuleWireBytes;
class NativeModule;
class WasmCode;
class WasmEngine;
struct WasmFunction;
enum RuntimeExceptionSupport : bool {
kRuntimeExceptionSupport = true,
kNoRuntimeExceptionSupport = false
};
enum UseTrapHandler : bool { kUseTrapHandler = true, kNoTrapHandler = false };
enum LowerSimd : bool { kLowerSimd = true, kNoLowerSimd = false };
// The {ModuleEnv} encapsulates the module data that is used during compilation.
// ModuleEnvs are shareable across multiple compilations.
// TODO(clemensh): Rename this struct to CompilationEnv.
struct ModuleEnv {
// A pointer to the decoded module's static representation.
const WasmModule* const module;
// True if trap handling should be used in compiled code, rather than
// compiling in bounds checks for each memory access.
const UseTrapHandler 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.
const RuntimeExceptionSupport runtime_exception_support;
// The smallest size of any memory that could be used with this module, in
// bytes.
const uint64_t min_memory_size;
// The largest size of any memory that could be used with this module, in
// bytes.
const uint64_t max_memory_size;
const LowerSimd lower_simd;
constexpr ModuleEnv(const WasmModule* module, UseTrapHandler use_trap_handler,
RuntimeExceptionSupport runtime_exception_support,
LowerSimd lower_simd = kNoLowerSimd)
: module(module),
use_trap_handler(use_trap_handler),
runtime_exception_support(runtime_exception_support),
min_memory_size(module ? module->initial_pages * uint64_t{kWasmPageSize}
: 0),
max_memory_size(module && module->has_maximum_pages
? (module->maximum_pages * uint64_t{kWasmPageSize})
: kSpecMaxWasmMemoryBytes),
lower_simd(lower_simd) {}
};
// The implementation of {CompilationState} and {CompilationStateDeleter} lives
// in module-compiler.cc.
struct CompilationStateDeleter {
void operator()(CompilationState* compilation_state) const;
};
// Wrapper to create a CompilationState exists in order to avoid having
// the CompilationState in the header file.
std::unique_ptr<CompilationState, CompilationStateDeleter> NewCompilationState(
Isolate*, const ModuleEnv&);
ModuleEnv* GetModuleEnv(CompilationState* compilation_state);
} // namespace wasm
} // namespace internal
} // namespace v8
#endif // V8_WASM_COMPILATION_ENVIRONMENT_H_
......@@ -5,6 +5,7 @@
#ifndef V8_WASM_FUNCTION_COMPILER_H_
#define V8_WASM_FUNCTION_COMPILER_H_
#include "src/wasm/compilation-environment.h"
#include "src/wasm/function-body-decoder.h"
#include "src/wasm/wasm-limits.h"
#include "src/wasm/wasm-module.h"
......@@ -22,60 +23,11 @@ class TurbofanWasmCompilationUnit;
namespace wasm {
class LiftoffCompilationUnit;
struct ModuleWireBytes;
class NativeModule;
class WasmCode;
class WasmEngine;
struct WasmFunction;
enum RuntimeExceptionSupport : bool {
kRuntimeExceptionSupport = true,
kNoRuntimeExceptionSupport = false
};
enum UseTrapHandler : bool { kUseTrapHandler = true, kNoTrapHandler = false };
enum LowerSimd : bool { kLowerSimd = true, kNoLowerSimd = false };
// The {ModuleEnv} encapsulates the module data that is used during compilation.
// ModuleEnvs are shareable across multiple compilations.
struct ModuleEnv {
// A pointer to the decoded module's static representation.
const WasmModule* const module;
// True if trap handling should be used in compiled code, rather than
// compiling in bounds checks for each memory access.
const UseTrapHandler 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.
const RuntimeExceptionSupport runtime_exception_support;
// The smallest size of any memory that could be used with this module, in
// bytes.
const uint64_t min_memory_size;
// The largest size of any memory that could be used with this module, in
// bytes.
const uint64_t max_memory_size;
const LowerSimd lower_simd;
constexpr ModuleEnv(const WasmModule* module, UseTrapHandler use_trap_handler,
RuntimeExceptionSupport runtime_exception_support,
LowerSimd lower_simd = kNoLowerSimd)
: module(module),
use_trap_handler(use_trap_handler),
runtime_exception_support(runtime_exception_support),
min_memory_size(module ? module->initial_pages * uint64_t{kWasmPageSize}
: 0),
max_memory_size(module && module->has_maximum_pages
? (module->maximum_pages * uint64_t{kWasmPageSize})
: kSpecMaxWasmMemoryBytes),
lower_simd(lower_simd) {}
};
class WasmCompilationUnit final {
public:
static ExecutionTier GetDefaultExecutionTier();
......
......@@ -11,6 +11,7 @@
#include "src/cancelable-task.h"
#include "src/globals.h"
#include "src/wasm/compilation-environment.h"
#include "src/wasm/wasm-features.h"
#include "src/wasm/wasm-module.h"
......@@ -29,7 +30,6 @@ class Vector;
namespace wasm {
class CompilationResultResolver;
class CompilationState;
class ErrorThrower;
class ModuleCompiler;
class NativeModule;
......@@ -37,17 +37,6 @@ class WasmCode;
struct ModuleEnv;
struct WasmModule;
struct CompilationStateDeleter {
void operator()(CompilationState* compilation_state) const;
};
// Wrapper to create a CompilationState exists in order to avoid having
// the CompilationState in the header file.
std::unique_ptr<CompilationState, CompilationStateDeleter> NewCompilationState(
Isolate* isolate, const ModuleEnv& env);
ModuleEnv* GetModuleEnv(CompilationState* compilation_state);
MaybeHandle<WasmModuleObject> CompileToModuleObject(
Isolate* isolate, const WasmFeatures& enabled, ErrorThrower* thrower,
std::shared_ptr<const WasmModule> module, const ModuleWireBytes& wire_bytes,
......
......@@ -16,6 +16,7 @@
#include "src/macro-assembler-inl.h"
#include "src/macro-assembler.h"
#include "src/objects-inl.h"
#include "src/wasm/compilation-environment.h"
#include "src/wasm/function-compiler.h"
#include "src/wasm/jump-table-assembler.h"
#include "src/wasm/wasm-import-wrapper-cache-inl.h"
......
......@@ -16,7 +16,7 @@
#include "src/handles.h"
#include "src/trap-handler/trap-handler.h"
#include "src/vector.h"
#include "src/wasm/module-compiler.h"
#include "src/wasm/compilation-environment.h"
#include "src/wasm/wasm-features.h"
#include "src/wasm/wasm-limits.h"
......
......@@ -18,14 +18,15 @@ namespace internal {
class CodeTracer;
class CompilationStatistics;
class WasmModuleObject;
class WasmInstanceObject;
class WasmModuleObject;
namespace wasm {
class AsyncCompileJob;
class ErrorThrower;
struct WasmFeatures;
struct ModuleWireBytes;
struct WasmFeatures;
class V8_EXPORT_PRIVATE CompilationResultResolver {
public:
......
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