Commit d0838334 authored by ishell's avatar ishell Committed by Commit bot

[turbofan] Remove virtual methods from CodeAssembler.

... and add explicit CallPrologue/CallEpilogue callbacks to CodeAssemblerState instead.
This will allow IntepreterAssembler to use any other helper assembler.

TBR=rmcilroy@chromium.org
BUG=

Review-Url: https://codereview.chromium.org/2600183004
Cr-Commit-Position: refs/heads/master@{#41973}
parent 505cfdd8
......@@ -96,9 +96,32 @@ void CodeAssembler::BreakOnNode(int node_id) {
graph->AddDecorator(decorator);
}
void CodeAssembler::CallPrologue() {}
void CodeAssembler::RegisterCallGenerationCallbacks(
const CodeAssemblerCallback& call_prologue,
const CodeAssemblerCallback& call_epilogue) {
// The callback can be registered only once.
DCHECK(!state_->call_prologue_);
DCHECK(!state_->call_epilogue_);
state_->call_prologue_ = call_prologue;
state_->call_epilogue_ = call_epilogue;
}
void CodeAssembler::UnregisterCallGenerationCallbacks() {
state_->call_prologue_ = nullptr;
state_->call_epilogue_ = nullptr;
}
void CodeAssembler::CallPrologue() {
if (state_->call_prologue_) {
state_->call_prologue_();
}
}
void CodeAssembler::CallEpilogue() {}
void CodeAssembler::CallEpilogue() {
if (state_->call_epilogue_) {
state_->call_epilogue_();
}
}
// static
Handle<Code> CodeAssembler::GenerateCode(CodeAssemblerState* state) {
......@@ -450,11 +473,7 @@ Node* CodeAssembler::TailCallRuntime(Runtime::FunctionId function,
Node* nodes[] = {centry, args..., ref, arity, context};
CallPrologue();
Node* return_value =
raw_assembler()->TailCallN(desc, arraysize(nodes), nodes);
CallEpilogue();
return return_value;
return raw_assembler()->TailCallN(desc, arraysize(nodes), nodes);
}
// Instantiate TailCallRuntime() with up to 6 arguments.
......
......@@ -40,6 +40,8 @@ class RawMachineLabel;
typedef ZoneList<CodeAssemblerVariable*> CodeAssemblerVariableList;
typedef std::function<void()> CodeAssemblerCallback;
#define CODE_ASSEMBLER_COMPARE_BINARY_OP_LIST(V) \
V(Float32Equal) \
V(Float32LessThan) \
......@@ -189,8 +191,7 @@ typedef ZoneList<CodeAssemblerVariable*> CodeAssemblerVariableList;
class V8_EXPORT_PRIVATE CodeAssembler {
public:
explicit CodeAssembler(CodeAssemblerState* state) : state_(state) {}
virtual ~CodeAssembler();
~CodeAssembler();
static Handle<Code> GenerateCode(CodeAssemblerState* state);
......@@ -374,13 +375,18 @@ class V8_EXPORT_PRIVATE CodeAssembler {
void BreakOnNode(int node_id);
protected:
// Enables subclasses to perform operations before and after a call.
virtual void CallPrologue();
virtual void CallEpilogue();
void RegisterCallGenerationCallbacks(
const CodeAssemblerCallback& call_prologue,
const CodeAssemblerCallback& call_epilogue);
void UnregisterCallGenerationCallbacks();
private:
RawMachineAssembler* raw_assembler() const;
// Calls respective callback registered in the state.
void CallPrologue();
void CallEpilogue();
CodeAssemblerState* state_;
DISALLOW_COPY_AND_ASSIGN(CodeAssembler);
......@@ -477,6 +483,8 @@ class V8_EXPORT_PRIVATE CodeAssemblerState {
const char* name_;
bool code_generated_;
ZoneSet<CodeAssemblerVariable::Impl*> variables_;
CodeAssemblerCallback call_prologue_;
CodeAssemblerCallback call_epilogue_;
DISALLOW_COPY_AND_ASSIGN(CodeAssemblerState);
};
......
......@@ -42,6 +42,8 @@ InterpreterAssembler::InterpreterAssembler(CodeAssemblerState* state,
if (FLAG_trace_ignition) {
TraceBytecode(Runtime::kInterpreterTraceBytecodeEntry);
}
RegisterCallGenerationCallbacks([this] { CallPrologue(); },
[this] { CallEpilogue(); });
}
InterpreterAssembler::~InterpreterAssembler() {
......@@ -49,6 +51,7 @@ InterpreterAssembler::~InterpreterAssembler() {
// accumulator in the way described in the bytecode definitions in
// bytecodes.h.
DCHECK_EQ(accumulator_use_, Bytecodes::GetAccumulatorUse(bytecode_));
UnregisterCallGenerationCallbacks();
}
Node* InterpreterAssembler::GetInterpretedFramePointer() {
......
......@@ -22,7 +22,7 @@ class V8_EXPORT_PRIVATE InterpreterAssembler : public CodeStubAssembler {
public:
InterpreterAssembler(compiler::CodeAssemblerState* state, Bytecode bytecode,
OperandScale operand_scale);
virtual ~InterpreterAssembler();
~InterpreterAssembler();
// Returns the 32-bit unsigned count immediate for bytecode operand
// |operand_index| in the current bytecode.
......@@ -218,8 +218,8 @@ class V8_EXPORT_PRIVATE InterpreterAssembler : public CodeStubAssembler {
// Saves and restores interpreter bytecode offset to the interpreter stack
// frame when performing a call.
void CallPrologue() override;
void CallEpilogue() override;
void CallPrologue();
void CallEpilogue();
// Increment the dispatch counter for the (current, next) bytecode pair.
void TraceBytecodeDispatch(compiler::Node* target_index);
......
......@@ -36,7 +36,7 @@ class InterpreterAssemblerTest : public TestWithIsolateAndZone {
InterpreterAssemblerTestState* state, Bytecode bytecode,
OperandScale operand_scale = OperandScale::kSingle)
: InterpreterAssembler(state, bytecode, operand_scale) {}
~InterpreterAssemblerForTest() override;
~InterpreterAssemblerForTest();
Matcher<compiler::Node*> IsLoad(
const Matcher<compiler::LoadRepresentation>& rep_matcher,
......
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