Commit 1a5df8eb authored by Ben L. Titzer's avatar Ben L. Titzer Committed by Commit Bot

[wasm] Remove WasmCompilationData

The WasmCompilationData was a struct that served as an input/output
mechanism for communicating with the code generator. In particular,
it contained a flag for enabling runtime exception for WASM in the code
generator and it also gathered the protected instruction info from
the code generator to be communicated to the WasmCodeManager.

This CL inlines the exception support flag into OptimizedCompilationInfo
and the protected instruction information into the code generator,
along the lines of other flags and data structures created by the
code generator.

R=mstarzinger@chromium.org

Change-Id: If436636067f1a829a095310a73045fe3301cb694
Reviewed-on: https://chromium-review.googlesource.com/1186409
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55358}
parent faa6cfbb
......@@ -42,9 +42,8 @@ CodeGenerator::CodeGenerator(
Zone* codegen_zone, Frame* frame, Linkage* linkage,
InstructionSequence* code, OptimizedCompilationInfo* info, Isolate* isolate,
base::Optional<OsrHelper> osr_helper, int start_source_position,
JumpOptimizationInfo* jump_opt, WasmCompilationData* wasm_compilation_data,
PoisoningMitigationLevel poisoning_level, const AssemblerOptions& options,
int32_t builtin_index)
JumpOptimizationInfo* jump_opt, PoisoningMitigationLevel poisoning_level,
const AssemblerOptions& options, int32_t builtin_index)
: zone_(codegen_zone),
isolate_(isolate),
frame_access_state_(nullptr),
......@@ -75,7 +74,7 @@ CodeGenerator::CodeGenerator(
optimized_out_literal_id_(-1),
source_position_table_builder_(
SourcePositionTableBuilder::RECORD_SOURCE_POSITIONS),
wasm_compilation_data_(wasm_compilation_data),
protected_instructions_(zone()),
result_(kSuccess),
poisoning_level_(poisoning_level),
block_starts_(zone()),
......@@ -86,7 +85,7 @@ CodeGenerator::CodeGenerator(
CreateFrameAccessState(frame);
CHECK_EQ(info->is_osr(), osr_helper_.has_value());
tasm_.set_jump_optimization_info(jump_opt);
Code::Kind code_kind = info_->code_kind();
Code::Kind code_kind = info->code_kind();
if (code_kind == Code::WASM_FUNCTION ||
code_kind == Code::WASM_TO_JS_FUNCTION ||
code_kind == Code::WASM_INTERPRETER_ENTRY ||
......@@ -98,14 +97,13 @@ CodeGenerator::CodeGenerator(
}
bool CodeGenerator::wasm_runtime_exception_support() const {
DCHECK(wasm_compilation_data_);
return wasm_compilation_data_->runtime_exception_support();
DCHECK_NOT_NULL(info_);
return info_->wasm_runtime_exception_support();
}
void CodeGenerator::AddProtectedInstructionLanding(uint32_t instr_offset,
uint32_t landing_offset) {
DCHECK_NOT_NULL(wasm_compilation_data_);
wasm_compilation_data_->AddProtectedInstruction(instr_offset, landing_offset);
protected_instructions_.push_back({instr_offset, landing_offset});
}
void CodeGenerator::CreateFrameAccessState(Frame* frame) {
......@@ -374,6 +372,12 @@ OwnedVector<byte> CodeGenerator::GetSourcePositionTable() {
return source_position_table_builder_.ToSourcePositionTableVector();
}
OwnedVector<trap_handler::ProtectedInstructionData>
CodeGenerator::GetProtectedInstructions() {
return OwnedVector<trap_handler::ProtectedInstructionData>::Of(
protected_instructions_);
}
MaybeHandle<Code> CodeGenerator::FinalizeCode() {
if (result_ != kSuccess) {
tasm()->AbortedCodeGeneration();
......
......@@ -14,6 +14,7 @@
#include "src/macro-assembler.h"
#include "src/safepoint-table.h"
#include "src/source-position-table.h"
#include "src/trap-handler/trap-handler.h"
namespace v8 {
namespace internal {
......@@ -27,7 +28,6 @@ class DeoptimizationExit;
class FrameAccessState;
class Linkage;
class OutOfLineCode;
class WasmCompilationData;
struct BranchInfo {
FlagsCondition condition;
......@@ -83,7 +83,6 @@ class CodeGenerator final : public GapResolver::Assembler {
base::Optional<OsrHelper> osr_helper,
int start_source_position,
JumpOptimizationInfo* jump_opt,
WasmCompilationData* wasm_compilation_data,
PoisoningMitigationLevel poisoning_level,
const AssemblerOptions& options,
int32_t builtin_index);
......@@ -95,6 +94,8 @@ class CodeGenerator final : public GapResolver::Assembler {
MaybeHandle<Code> FinalizeCode();
OwnedVector<byte> GetSourcePositionTable();
OwnedVector<trap_handler::ProtectedInstructionData>
GetProtectedInstructions();
InstructionSequence* code() const { return code_; }
FrameAccessState* frame_access_state() const { return frame_access_state_; }
......@@ -427,7 +428,7 @@ class CodeGenerator final : public GapResolver::Assembler {
int osr_pc_offset_;
int optimized_out_literal_id_;
SourcePositionTableBuilder source_position_table_builder_;
WasmCompilationData* wasm_compilation_data_;
ZoneVector<trap_handler::ProtectedInstructionData> protected_instructions_;
CodeGenResult result_;
PoisoningMitigationLevel poisoning_level_;
ZoneVector<int> block_starts_;
......
......@@ -148,7 +148,6 @@ class PipelineData {
PipelineStatistics* pipeline_statistics,
SourcePositionTable* source_positions,
NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data,
int wasm_function_index,
const AssemblerOptions& assembler_options)
: isolate_(nullptr),
......@@ -173,7 +172,6 @@ class PipelineData {
codegen_zone_(codegen_zone_scope_.zone()),
register_allocation_zone_scope_(zone_stats_, ZONE_NAME),
register_allocation_zone_(register_allocation_zone_scope_.zone()),
wasm_compilation_data_(wasm_compilation_data),
assembler_options_(assembler_options) {}
// For machine graph testing entry point.
......@@ -399,8 +397,8 @@ class PipelineData {
code_generator_ = new CodeGenerator(
codegen_zone(), frame(), linkage, sequence(), info(), isolate(),
osr_helper_, start_source_position_, jump_optimization_info_,
wasm_compilation_data_, info()->GetPoisoningMitigationLevel(),
assembler_options_, info_->builtin_index());
info()->GetPoisoningMitigationLevel(), assembler_options_,
info_->builtin_index());
}
void BeginPhaseKind(const char* phase_kind_name) {
......@@ -417,10 +415,6 @@ class PipelineData {
const char* debug_name() const { return debug_name_.get(); }
WasmCompilationData* wasm_compilation_data() const {
return wasm_compilation_data_;
}
int wasm_function_index() const { return wasm_function_index_; }
private:
......@@ -484,8 +478,6 @@ class PipelineData {
// Source position output for --trace-turbo.
std::string source_position_output_;
WasmCompilationData* wasm_compilation_data_ = nullptr;
JumpOptimizationInfo* jump_optimization_info_ = nullptr;
AssemblerOptions assembler_options_;
......@@ -1005,7 +997,6 @@ class PipelineWasmCompilationJob final : public OptimizedCompilationJob {
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
MachineGraph* mcgraph, CallDescriptor* call_descriptor,
SourcePositionTable* source_positions, NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data,
wasm::FunctionBody function_body, wasm::WasmModule* wasm_module,
wasm::NativeModule* native_module, int function_index, bool asmjs_origin)
: OptimizedCompilationJob(kNoStackLimit, info, "TurboFan",
......@@ -1015,7 +1006,7 @@ class PipelineWasmCompilationJob final : public OptimizedCompilationJob {
wasm_engine, function_body, wasm_module, info, &zone_stats_)),
data_(&zone_stats_, wasm_engine, info, mcgraph,
pipeline_statistics_.get(), source_positions, node_origins,
wasm_compilation_data, function_index, WasmAssemblerOptions()),
function_index, WasmAssemblerOptions()),
pipeline_(&data_),
linkage_(call_descriptor),
native_module_(native_module),
......@@ -1091,7 +1082,7 @@ PipelineWasmCompilationJob::ExecuteJobImpl() {
code_generator->frame()->GetTotalFrameSlotCount(),
code_generator->GetSafepointTableOffset(),
code_generator->GetHandlerTableOffset(),
data_.wasm_compilation_data()->GetProtectedInstructions(),
code_generator->GetProtectedInstructions(),
code_generator->GetSourcePositionTable(), wasm::WasmCode::kTurbofan);
if (data_.info()->trace_turbo_json_enabled()) {
......@@ -2282,14 +2273,13 @@ OptimizedCompilationJob* Pipeline::NewWasmCompilationJob(
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
MachineGraph* mcgraph, CallDescriptor* call_descriptor,
SourcePositionTable* source_positions, NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data,
wasm::FunctionBody function_body, wasm::WasmModule* wasm_module,
wasm::NativeModule* native_module, int function_index,
wasm::ModuleOrigin asmjs_origin) {
return new PipelineWasmCompilationJob(
info, wasm_engine, mcgraph, call_descriptor, source_positions,
node_origins, wasm_compilation_data, function_body, wasm_module,
native_module, function_index, asmjs_origin);
node_origins, function_body, wasm_module, native_module, function_index,
asmjs_origin);
}
bool Pipeline::AllocateRegistersForTesting(const RegisterConfiguration* config,
......
......@@ -37,7 +37,6 @@ class MachineGraph;
class NodeOriginTable;
class Schedule;
class SourcePositionTable;
class WasmCompilationData;
class Pipeline : public AllStatic {
public:
......@@ -51,7 +50,6 @@ class Pipeline : public AllStatic {
OptimizedCompilationInfo* info, wasm::WasmEngine* wasm_engine,
MachineGraph* mcgraph, CallDescriptor* call_descriptor,
SourcePositionTable* source_positions, NodeOriginTable* node_origins,
WasmCompilationData* wasm_compilation_data,
wasm::FunctionBody function_body, wasm::WasmModule* wasm_module,
wasm::NativeModule* native_module, int function_index,
wasm::ModuleOrigin wasm_origin);
......
......@@ -5025,8 +5025,7 @@ MaybeHandle<Code> CompileCWasmEntry(Isolate* isolate, wasm::FunctionSig* sig) {
TurbofanWasmCompilationUnit::TurbofanWasmCompilationUnit(
wasm::WasmCompilationUnit* wasm_unit)
: wasm_unit_(wasm_unit),
wasm_compilation_data_(wasm_unit->env_->runtime_exception_support) {}
: wasm_unit_(wasm_unit) {}
// Clears unique_ptrs, but (part of) the type is forward declared in the header.
TurbofanWasmCompilationUnit::~TurbofanWasmCompilationUnit() = default;
......@@ -5126,6 +5125,9 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
GetDebugName(&compilation_zone, wasm_unit_->func_name_,
wasm_unit_->func_index_),
&compilation_zone, Code::WASM_FUNCTION);
if (wasm_unit_->env_->runtime_exception_support) {
info.SetWasmRuntimeExceptionSupport();
}
NodeOriginTable* node_origins = info.trace_turbo_json_enabled()
? new (&graph_zone)
......@@ -5160,8 +5162,7 @@ void TurbofanWasmCompilationUnit::ExecuteCompilation() {
std::unique_ptr<OptimizedCompilationJob> job(
Pipeline::NewWasmCompilationJob(
&info, wasm_unit_->wasm_engine_, mcgraph, call_descriptor,
source_positions, node_origins, &wasm_compilation_data_,
wasm_unit_->func_body_,
source_positions, node_origins, wasm_unit_->func_body_,
const_cast<wasm::WasmModule*>(wasm_unit_->env_->module),
wasm_unit_->native_module_, wasm_unit_->func_index_,
wasm_unit_->env_->module->origin));
......
......@@ -10,7 +10,6 @@
// Clients of this interface shouldn't depend on lots of compiler internals.
// Do not include anything from src/compiler here!
#include "src/runtime/runtime.h"
#include "src/trap-handler/trap-handler.h"
#include "src/wasm/function-body-decoder.h"
#include "src/wasm/function-compiler.h"
#include "src/wasm/wasm-module.h"
......@@ -45,37 +44,6 @@ class WasmCode;
namespace compiler {
// Information about Wasm compilation that needs to be plumbed through the
// different layers of the compiler.
class WasmCompilationData {
public:
explicit WasmCompilationData(
wasm::RuntimeExceptionSupport runtime_exception_support)
: runtime_exception_support_(runtime_exception_support) {}
void AddProtectedInstruction(uint32_t instr_offset, uint32_t landing_offset) {
protected_instructions_.push_back({instr_offset, landing_offset});
}
OwnedVector<trap_handler::ProtectedInstructionData>
GetProtectedInstructions() {
return OwnedVector<trap_handler::ProtectedInstructionData>::Of(
protected_instructions_);
}
wasm::RuntimeExceptionSupport runtime_exception_support() const {
return runtime_exception_support_;
}
private:
std::vector<trap_handler::ProtectedInstructionData> protected_instructions_;
// See ModuleEnv::runtime_exception_support_.
wasm::RuntimeExceptionSupport runtime_exception_support_;
DISALLOW_COPY_AND_ASSIGN(WasmCompilationData);
};
class TurbofanWasmCompilationUnit {
public:
explicit TurbofanWasmCompilationUnit(wasm::WasmCompilationUnit* wasm_unit);
......@@ -91,7 +59,6 @@ class TurbofanWasmCompilationUnit {
private:
wasm::WasmCompilationUnit* const wasm_unit_;
WasmCompilationData wasm_compilation_data_;
bool ok_ = true;
wasm::WasmCode* wasm_code_ = nullptr;
wasm::Result<wasm::DecodeStruct*> graph_construction_result_;
......
......@@ -56,6 +56,7 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
kTraceTurboJson = 1 << 14,
kTraceTurboGraph = 1 << 15,
kTraceTurboScheduled = 1 << 16,
kWasmRuntimeExceptionSupport = 1 << 17
};
// Construct a compilation info for optimized compilation.
......@@ -166,6 +167,14 @@ class V8_EXPORT_PRIVATE OptimizedCompilationInfo final {
return GetFlag(kAnalyzeEnvironmentLiveness);
}
void SetWasmRuntimeExceptionSupport() {
SetFlag(kWasmRuntimeExceptionSupport);
}
bool wasm_runtime_exception_support() {
return GetFlag(kWasmRuntimeExceptionSupport);
}
bool trace_turbo_json_enabled() const { return GetFlag(kTraceTurboJson); }
bool trace_turbo_graph_enabled() const { return GetFlag(kTraceTurboGraph); }
......
......@@ -996,8 +996,7 @@ class CodeGeneratorTester {
generator_ = new CodeGenerator(
environment->main_zone(), &frame_, &linkage_, environment->code(),
&info_, environment->main_isolate(), base::Optional<OsrHelper>(),
kNoSourcePosition, nullptr, nullptr,
PoisoningMitigationLevel::kDontPoison,
kNoSourcePosition, nullptr, PoisoningMitigationLevel::kDontPoison,
AssemblerOptions::Default(environment->main_isolate()),
Builtins::kNoBuiltinId);
......
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