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