Commit 826a6e7f authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Add interface callback before each instruction

In Liftoff, we want to trace the cache state basically before or after
processing each instruction. Instead of duplicating this code
everywhere, introduce a new interface method {NextInstruction}, which
is called before each instruction.

R=titzer@chromium.org

Bug: v8:6600
Change-Id: Iea61738d200076690a8440a75a2fd90018efa43b
Reviewed-on: https://chromium-review.googlesource.com/852457
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarBen Titzer <titzer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50447}
parent 6b5578ec
...@@ -347,13 +347,15 @@ class LiftoffCompiler { ...@@ -347,13 +347,15 @@ class LiftoffCompiler {
BindUnboundLabels(decoder); BindUnboundLabels(decoder);
} }
void Block(Decoder* decoder, Control* block) { void NextInstruction(Decoder* decoder, WasmOpcode) {
TraceCacheState(decoder); TraceCacheState(decoder);
}
void Block(Decoder* decoder, Control* block) {
block->label_state.stack_base = __ cache_state()->stack_height(); block->label_state.stack_base = __ cache_state()->stack_height();
} }
void Loop(Decoder* decoder, Control* loop) { void Loop(Decoder* decoder, Control* loop) {
TraceCacheState(decoder);
loop->label_state.stack_base = __ cache_state()->stack_height(); loop->label_state.stack_base = __ cache_state()->stack_height();
// Before entering a loop, spill all locals to the stack, in order to free // Before entering a loop, spill all locals to the stack, in order to free
...@@ -396,7 +398,6 @@ class LiftoffCompiler { ...@@ -396,7 +398,6 @@ class LiftoffCompiler {
} }
void FallThruTo(Decoder* decoder, Control* c) { void FallThruTo(Decoder* decoder, Control* c) {
TraceCacheState(decoder);
if (c->end_merge.reached) { if (c->end_merge.reached) {
__ MergeFullStackWith(c->label_state); __ MergeFullStackWith(c->label_state);
} else if (c->is_onearmed_if()) { } else if (c->is_onearmed_if()) {
...@@ -406,6 +407,7 @@ class LiftoffCompiler { ...@@ -406,6 +407,7 @@ class LiftoffCompiler {
} else { } else {
c->label_state.Split(*__ cache_state()); c->label_state.Split(*__ cache_state());
} }
TraceCacheState(decoder);
} }
void PopControl(Decoder* decoder, Control* c) { void PopControl(Decoder* decoder, Control* c) {
...@@ -431,7 +433,6 @@ class LiftoffCompiler { ...@@ -431,7 +433,6 @@ class LiftoffCompiler {
void UnOp(Decoder* decoder, WasmOpcode opcode, FunctionSig*, void UnOp(Decoder* decoder, WasmOpcode opcode, FunctionSig*,
const Value& value, Value* result) { const Value& value, Value* result) {
TraceCacheState(decoder);
#define CASE_UNOP(opcode, type, fn) \ #define CASE_UNOP(opcode, type, fn) \
case WasmOpcode::kExpr##opcode: \ case WasmOpcode::kExpr##opcode: \
type##UnOp(&LiftoffAssembler::emit_##fn); \ type##UnOp(&LiftoffAssembler::emit_##fn); \
...@@ -473,7 +474,6 @@ class LiftoffCompiler { ...@@ -473,7 +474,6 @@ class LiftoffCompiler {
void BinOp(Decoder* decoder, WasmOpcode opcode, FunctionSig*, void BinOp(Decoder* decoder, WasmOpcode opcode, FunctionSig*,
const Value& lhs, const Value& rhs, Value* result) { const Value& lhs, const Value& rhs, Value* result) {
TraceCacheState(decoder);
#define CASE_BINOP(opcode, type, fn) \ #define CASE_BINOP(opcode, type, fn) \
case WasmOpcode::kExpr##opcode: \ case WasmOpcode::kExpr##opcode: \
return type##BinOp(&LiftoffAssembler::emit_##fn); return type##BinOp(&LiftoffAssembler::emit_##fn);
...@@ -494,7 +494,6 @@ class LiftoffCompiler { ...@@ -494,7 +494,6 @@ class LiftoffCompiler {
} }
void I32Const(Decoder* decoder, Value* result, int32_t value) { void I32Const(Decoder* decoder, Value* result, int32_t value) {
TraceCacheState(decoder);
__ cache_state()->stack_state.emplace_back(kWasmI32, value); __ cache_state()->stack_state.emplace_back(kWasmI32, value);
CheckStackSizeLimit(decoder); CheckStackSizeLimit(decoder);
} }
...@@ -515,7 +514,6 @@ class LiftoffCompiler { ...@@ -515,7 +514,6 @@ class LiftoffCompiler {
} }
void Drop(Decoder* decoder, const Value& value) { void Drop(Decoder* decoder, const Value& value) {
TraceCacheState(decoder);
__ DropStackSlot(&__ cache_state()->stack_state.back()); __ DropStackSlot(&__ cache_state()->stack_state.back());
__ cache_state()->stack_state.pop_back(); __ cache_state()->stack_state.pop_back();
} }
...@@ -540,7 +538,6 @@ class LiftoffCompiler { ...@@ -540,7 +538,6 @@ class LiftoffCompiler {
void GetLocal(Decoder* decoder, Value* result, void GetLocal(Decoder* decoder, Value* result,
const LocalIndexOperand<validate>& operand) { const LocalIndexOperand<validate>& operand) {
TraceCacheState(decoder);
auto& slot = __ cache_state()->stack_state[operand.index]; auto& slot = __ cache_state()->stack_state[operand.index];
DCHECK_EQ(slot.type(), operand.type); DCHECK_EQ(slot.type(), operand.type);
switch (slot.loc()) { switch (slot.loc()) {
...@@ -665,12 +662,10 @@ class LiftoffCompiler { ...@@ -665,12 +662,10 @@ class LiftoffCompiler {
} }
void Br(Decoder* decoder, Control* target) { void Br(Decoder* decoder, Control* target) {
TraceCacheState(decoder);
Br(target); Br(target);
} }
void BrIf(Decoder* decoder, const Value& cond, Control* target) { void BrIf(Decoder* decoder, const Value& cond, Control* target) {
TraceCacheState(decoder);
Label cont_false; Label cont_false;
Register value = __ PopToRegister(kGpReg).gp(); Register value = __ PopToRegister(kGpReg).gp();
__ emit_i32_test(value); __ emit_i32_test(value);
...@@ -800,8 +795,6 @@ class LiftoffCompiler { ...@@ -800,8 +795,6 @@ class LiftoffCompiler {
if (operand.sig->return_count() > 1) if (operand.sig->return_count() > 1)
return unsupported(decoder, "multi-return"); return unsupported(decoder, "multi-return");
TraceCacheState(decoder);
compiler::CallDescriptor* call_desc = compiler::CallDescriptor* call_desc =
compiler::GetWasmCallDescriptor(&compilation_zone_, operand.sig); compiler::GetWasmCallDescriptor(&compilation_zone_, operand.sig);
......
...@@ -551,6 +551,7 @@ struct ControlWithNamedConstructors : public ControlBase<Value> { ...@@ -551,6 +551,7 @@ struct ControlWithNamedConstructors : public ControlBase<Value> {
F(StartFunctionBody, Control* block) \ F(StartFunctionBody, Control* block) \
F(FinishFunction) \ F(FinishFunction) \
F(OnFirstError) \ F(OnFirstError) \
F(NextInstruction, WasmOpcode) \
/* Control: */ \ /* Control: */ \
F(Block, Control* block) \ F(Block, Control* block) \
F(Loop, Control* block) \ F(Loop, Control* block) \
...@@ -1331,6 +1332,9 @@ class WasmFullDecoder : public WasmDecoder<validate> { ...@@ -1331,6 +1332,9 @@ class WasmFullDecoder : public WasmDecoder<validate> {
while (this->pc_ < this->end_) { // decoding loop. while (this->pc_ < this->end_) { // decoding loop.
unsigned len = 1; unsigned len = 1;
WasmOpcode opcode = static_cast<WasmOpcode>(*this->pc_); WasmOpcode opcode = static_cast<WasmOpcode>(*this->pc_);
CALL_INTERFACE_IF_REACHABLE(NextInstruction, opcode);
#if DEBUG #if DEBUG
TraceLine trace_msg; TraceLine trace_msg;
#define TRACE_PART(...) trace_msg.Append(__VA_ARGS__) #define TRACE_PART(...) trace_msg.Append(__VA_ARGS__)
......
...@@ -142,11 +142,11 @@ class WasmGraphBuildingInterface { ...@@ -142,11 +142,11 @@ class WasmGraphBuildingInterface {
block->end_env = break_env; block->end_env = break_env;
} }
void FinishFunction(Decoder* decoder) { void FinishFunction(Decoder*) { builder_->PatchInStackCheckIfNeeded(); }
builder_->PatchInStackCheckIfNeeded();
} void OnFirstError(Decoder*) {}
void OnFirstError(Decoder* decoder) {} void NextInstruction(Decoder*, WasmOpcode) {}
void Block(Decoder* decoder, Control* block) { void Block(Decoder* decoder, Control* block) {
// The break environment is the outer environment. // The break environment is the outer environment.
......
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