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