Commit 5760d76e authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[Liftoff] Attach source positions and safepoint info

So far we generated source positions and safepoint information, but we
never actually attached it to the generated code objects. This CL adds
that.

R=titzer@chromium.org

Bug: v8:6600, chromium:793694
Change-Id: I8f4c6d8752f4c31a1df51c4893c262ea5925f3b5
Reviewed-on: https://chromium-review.googlesource.com/824266Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50077}
parent c8102945
......@@ -5051,12 +5051,11 @@ WasmCodeWrapper WasmCompilationUnit::FinishTurbofanCompilation(
MaybeHandle<HandlerTable> handler_table =
tf_.job_->compilation_info()->wasm_code_desc()->handler_table;
int function_index_as_int = static_cast<int>(func_index_);
native_module_->compiled_module()->source_positions()->set(
function_index_as_int, *source_positions);
func_index_, *source_positions);
if (!handler_table.is_null()) {
native_module_->compiled_module()->handler_table()->set(
function_index_as_int, *handler_table.ToHandleChecked());
func_index_, *handler_table.ToHandleChecked());
}
// TODO(mtrofin): this should probably move up in the common caller,
// once liftoff has source positions. Until then, we'd need to handle
......@@ -5091,10 +5090,21 @@ WasmCodeWrapper WasmCompilationUnit::FinishLiftoffCompilation(
wasm::ErrorThrower* thrower) {
CodeDesc desc;
liftoff_.asm_.GetCode(isolate_, &desc);
Handle<ByteArray> source_positions =
liftoff_.source_position_table_builder_.ToSourcePositionTable(isolate_);
WasmCodeWrapper ret;
if (!FLAG_wasm_jit_to_native) {
Handle<Code> code;
code = isolate_->factory()->NewCode(desc, Code::WASM_FUNCTION, code);
code = isolate_->factory()->NewCode(
desc, Code::WASM_FUNCTION, code, Builtins::kNoBuiltinId,
MaybeHandle<HandlerTable>(), source_positions,
MaybeHandle<DeoptimizationData>(), kMovable,
0, // stub_key
false, // is_turbofanned
liftoff_.asm_.GetTotalFrameSlotCount(), // stack_slots
liftoff_.safepoint_table_offset_);
#ifdef ENABLE_DISASSEMBLER
if (FLAG_print_code || FLAG_print_wasm_code) {
// TODO(wasm): Use proper log files, here and elsewhere.
......@@ -5117,6 +5127,8 @@ WasmCodeWrapper WasmCompilationUnit::FinishLiftoffCompilation(
} else {
// TODO(mtrofin): figure a way to raise events; also, disassembly.
// Consider lifting them both to FinishCompilation.
native_module_->compiled_module()->source_positions()->set(
func_index_, *source_positions);
return WasmCodeWrapper(native_module_->AddCode(
desc, liftoff_.asm_.GetTotalFrameSlotCount(), func_index_,
liftoff_.safepoint_table_offset_, protected_instructions_, true));
......
......@@ -118,6 +118,7 @@ class WasmCompilationUnit final {
struct LiftoffData {
wasm::LiftoffAssembler asm_;
int safepoint_table_offset_;
SourcePositionTableBuilder source_position_table_builder_;
explicit LiftoffData(Isolate* isolate) : asm_(isolate) {}
};
struct TurbofanData {
......
......@@ -73,11 +73,13 @@ class LiftoffCompiler {
LiftoffCompiler(LiftoffAssembler* liftoff_asm,
compiler::CallDescriptor* call_desc, compiler::ModuleEnv* env,
compiler::RuntimeExceptionSupport runtime_exception_support)
compiler::RuntimeExceptionSupport runtime_exception_support,
SourcePositionTableBuilder* source_position_table_builder)
: asm_(liftoff_asm),
call_desc_(call_desc),
env_(env),
runtime_exception_support_(runtime_exception_support),
source_position_table_builder_(source_position_table_builder),
compilation_zone_(liftoff_asm->isolate()->allocator(),
"liftoff compilation"),
safepoint_table_builder_(&compilation_zone_) {}
......@@ -252,8 +254,10 @@ class LiftoffCompiler {
}
DCHECK(runtime_exception_support_);
source_position_table_builder_.AddPosition(__ pc_offset(),
SourcePosition(position), true);
source_position_table_builder_->AddPosition(
__ pc_offset(), SourcePosition(position), false);
safepoint_table_builder_.DefineSafepoint(asm_, Safepoint::kSimple, 0,
Safepoint::kNoLazyDeopt);
Builtins::Name trap_id = GetBuiltinIdForTrap(reason);
__ Call(__ isolate()->builtins()->builtin_handle(trap_id),
RelocInfo::CODE_TARGET);
......@@ -669,7 +673,7 @@ class LiftoffCompiler {
compiler::RuntimeExceptionSupport runtime_exception_support_;
bool ok_ = true;
std::vector<TrapOolCode> trap_ool_code_;
SourcePositionTableBuilder source_position_table_builder_;
SourcePositionTableBuilder* source_position_table_builder_;
// Zone used to store information during compilation. The result will be
// stored independently, such that this zone can die together with the
// LiftoffCompiler after compilation.
......@@ -731,7 +735,8 @@ bool compiler::WasmCompilationUnit::ExecuteLiftoffCompilation() {
auto* call_desc = compiler::GetWasmCallDescriptor(&zone, func_body_.sig);
wasm::WasmFullDecoder<wasm::Decoder::kValidate, wasm::LiftoffCompiler>
decoder(&zone, module, func_body_, &liftoff_.asm_, call_desc, env_,
runtime_exception_support_);
runtime_exception_support_,
&liftoff_.source_position_table_builder_);
decoder.Decode();
if (!decoder.interface().ok()) {
// Liftoff compilation failed.
......
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