[wasm] Pass breakpoints to Liftoff compiler

This extends the API to pass breakpoint information to Liftoff. The
Liftoff compiler identifies the places where breakpoints should be set,
but does not emit breakpoints yet.
This allows us to see the performance overhead of just checking where to
emit breakpoints (which should be negligible).

R=thibaudm@chromium.org

Bug: v8:10147
Change-Id: I3fd40ab9009e9c317a26f70b4f06db512f96a763
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2019169
Reviewed-by: Thibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65988}
This commit is contained in:
Clemens Backes 2020-01-27 09:45:10 +01:00 committed by Commit Bot
parent 615ecdf8c9
commit 261a22e258
3 changed files with 33 additions and 14 deletions

View File

@ -286,14 +286,17 @@ class LiftoffCompiler {
LiftoffCompiler(compiler::CallDescriptor* call_descriptor, LiftoffCompiler(compiler::CallDescriptor* call_descriptor,
CompilationEnv* env, Zone* compilation_zone, CompilationEnv* env, Zone* compilation_zone,
std::unique_ptr<AssemblerBuffer> buffer, std::unique_ptr<AssemblerBuffer> buffer,
DebugSideTableBuilder* debug_sidetable_builder) DebugSideTableBuilder* debug_sidetable_builder,
Vector<int> breakpoints = {})
: asm_(std::move(buffer)), : asm_(std::move(buffer)),
descriptor_( descriptor_(
GetLoweredCallDescriptor(compilation_zone, call_descriptor)), GetLoweredCallDescriptor(compilation_zone, call_descriptor)),
env_(env), env_(env),
debug_sidetable_builder_(debug_sidetable_builder), debug_sidetable_builder_(debug_sidetable_builder),
compilation_zone_(compilation_zone), compilation_zone_(compilation_zone),
safepoint_table_builder_(compilation_zone_) {} safepoint_table_builder_(compilation_zone_),
next_breakpoint_ptr_(breakpoints.begin()),
next_breakpoint_end_(breakpoints.end()) {}
bool did_bailout() const { return bailout_reason_ != kSuccess; } bool did_bailout() const { return bailout_reason_ != kSuccess; }
LiftoffBailoutReason bailout_reason() const { return bailout_reason_; } LiftoffBailoutReason bailout_reason() const { return bailout_reason_; }
@ -615,6 +618,8 @@ class LiftoffCompiler {
} }
void FinishFunction(FullDecoder* decoder) { void FinishFunction(FullDecoder* decoder) {
// All breakpoints (if any) must be emitted by now.
DCHECK_NULL(next_breakpoint_ptr_);
if (DidAssemblerBailout(decoder)) return; if (DidAssemblerBailout(decoder)) return;
for (OutOfLineCode& ool : out_of_line_code_) { for (OutOfLineCode& ool : out_of_line_code_) {
GenerateOutOfLineCode(&ool); GenerateOutOfLineCode(&ool);
@ -635,11 +640,24 @@ class LiftoffCompiler {
} }
void NextInstruction(FullDecoder* decoder, WasmOpcode opcode) { void NextInstruction(FullDecoder* decoder, WasmOpcode opcode) {
if (V8_UNLIKELY(next_breakpoint_ptr_) &&
*next_breakpoint_ptr_ == decoder->position()) {
++next_breakpoint_ptr_;
if (next_breakpoint_ptr_ == next_breakpoint_end_) {
next_breakpoint_ptr_ = next_breakpoint_end_ = nullptr;
}
EmitBreakpoint();
}
TraceCacheState(decoder); TraceCacheState(decoder);
SLOW_DCHECK(__ ValidateCacheState()); SLOW_DCHECK(__ ValidateCacheState());
DEBUG_CODE_COMMENT(WasmOpcodes::OpcodeName(opcode)); DEBUG_CODE_COMMENT(WasmOpcodes::OpcodeName(opcode));
} }
void EmitBreakpoint() {
DEBUG_CODE_COMMENT("breakpoint");
// TODO(clemensb): Actually emit a breakpoint.
}
void Block(FullDecoder* decoder, Control* block) {} void Block(FullDecoder* decoder, Control* block) {}
void Loop(FullDecoder* decoder, Control* loop) { void Loop(FullDecoder* decoder, Control* loop) {
@ -2429,6 +2447,10 @@ class LiftoffCompiler {
// The pc offset of the instructions to reserve the stack frame. Needed to // The pc offset of the instructions to reserve the stack frame. Needed to
// patch the actually needed stack size in the end. // patch the actually needed stack size in the end.
uint32_t pc_offset_stack_frame_construction_ = 0; uint32_t pc_offset_stack_frame_construction_ = 0;
// For emitting breakpoint, we store a pointer to the position of the next
// breakpoint, and a pointer after the list of breakpoints as end marker.
int* next_breakpoint_ptr_ = nullptr;
int* next_breakpoint_end_ = nullptr;
bool has_outstanding_op() const { bool has_outstanding_op() const {
return outstanding_op_ != kNoOutstandingOp; return outstanding_op_ != kNoOutstandingOp;
@ -2454,12 +2476,10 @@ class LiftoffCompiler {
} // namespace } // namespace
WasmCompilationResult ExecuteLiftoffCompilation(AccountingAllocator* allocator, WasmCompilationResult ExecuteLiftoffCompilation(
CompilationEnv* env, AccountingAllocator* allocator, CompilationEnv* env,
const FunctionBody& func_body, const FunctionBody& func_body, int func_index, Counters* counters,
int func_index, WasmFeatures* detected, Vector<int> breakpoints) {
Counters* counters,
WasmFeatures* detected) {
int func_body_size = static_cast<int>(func_body.end - func_body.start); int func_body_size = static_cast<int>(func_body.end - func_body.start);
TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("v8.wasm"), TRACE_EVENT2(TRACE_DISABLED_BY_DEFAULT("v8.wasm"),
"ExecuteLiftoffCompilation", "func_index", func_index, "ExecuteLiftoffCompilation", "func_index", func_index,
@ -2481,7 +2501,7 @@ WasmCompilationResult ExecuteLiftoffCompilation(AccountingAllocator* allocator,
WasmFullDecoder<Decoder::kValidate, LiftoffCompiler> decoder( WasmFullDecoder<Decoder::kValidate, LiftoffCompiler> decoder(
&zone, env->module, env->enabled_features, detected, func_body, &zone, env->module, env->enabled_features, detected, func_body,
call_descriptor, env, &zone, instruction_buffer->CreateView(), call_descriptor, env, &zone, instruction_buffer->CreateView(),
kNoDebugSideTable); kNoDebugSideTable, breakpoints);
decoder.Decode(); decoder.Decode();
liftoff_compile_time_scope.reset(); liftoff_compile_time_scope.reset();
LiftoffCompiler* compiler = &decoder.interface(); LiftoffCompiler* compiler = &decoder.interface();

View File

@ -54,7 +54,7 @@ enum LiftoffBailoutReason : int8_t {
V8_EXPORT_PRIVATE WasmCompilationResult ExecuteLiftoffCompilation( V8_EXPORT_PRIVATE WasmCompilationResult ExecuteLiftoffCompilation(
AccountingAllocator*, CompilationEnv*, const FunctionBody&, int func_index, AccountingAllocator*, CompilationEnv*, const FunctionBody&, int func_index,
Counters*, WasmFeatures* detected_features); Counters*, WasmFeatures* detected_features, Vector<int> breakpoints = {});
V8_EXPORT_PRIVATE DebugSideTable GenerateLiftoffDebugSideTable( V8_EXPORT_PRIVATE DebugSideTable GenerateLiftoffDebugSideTable(
AccountingAllocator*, CompilationEnv*, const FunctionBody&); AccountingAllocator*, CompilationEnv*, const FunctionBody&);

View File

@ -597,10 +597,9 @@ class DebugInfoImpl {
FunctionBody body{function->sig, function->code.offset(), FunctionBody body{function->sig, function->code.offset(),
wire_bytes.begin() + function->code.offset(), wire_bytes.begin() + function->code.offset(),
wire_bytes.begin() + function->code.end_offset()}; wire_bytes.begin() + function->code.end_offset()};
// TODO(clemensb): Pass breakpoints to Liftoff. WasmCompilationResult result = ExecuteLiftoffCompilation(
WasmCompilationResult result = native_module_->engine()->allocator(), &env, body, func_index, nullptr,
ExecuteLiftoffCompilation(native_module_->engine()->allocator(), &env, nullptr, VectorOf(breakpoints));
body, func_index, nullptr, nullptr);
DCHECK(result.succeeded()); DCHECK(result.succeeded());
WasmCodeRefScope wasm_code_ref_scope; WasmCodeRefScope wasm_code_ref_scope;