[interpreter] Avoid code duplication in Interpreter::Initialize().

BUG=

Review-Url: https://codereview.chromium.org/2560893002
Cr-Commit-Position: refs/heads/master@{#41561}
This commit is contained in:
ishell 2016-12-07 10:53:12 -08:00 committed by Commit bot
parent 089e4fd32c
commit 0d29250547
2 changed files with 32 additions and 24 deletions

View File

@ -73,30 +73,9 @@ void Interpreter::Initialize() {
};
for (OperandScale operand_scale : kOperandScales) {
#define GENERATE_CODE(Name, ...) \
{ \
if (Bytecodes::BytecodeHasHandler(Bytecode::k##Name, operand_scale)) { \
InterpreterDispatchDescriptor descriptor(isolate_); \
compiler::CodeAssemblerState state( \
isolate_, &zone, descriptor, \
Code::ComputeFlags(Code::BYTECODE_HANDLER), \
Bytecodes::ToString(Bytecode::k##Name), \
Bytecodes::ReturnCount(Bytecode::k##Name)); \
InterpreterAssembler assembler(&state, Bytecode::k##Name, \
operand_scale); \
Do##Name(&assembler); \
Handle<Code> code = compiler::CodeAssembler::GenerateCode(&state); \
size_t index = GetDispatchTableIndex(Bytecode::k##Name, operand_scale); \
dispatch_table_[index] = code->entry(); \
TraceCodegen(code); \
PROFILE( \
isolate_, \
CodeCreateEvent( \
CodeEventListener::BYTECODE_HANDLER_TAG, \
AbstractCode::cast(*code), \
Bytecodes::ToString(Bytecode::k##Name, operand_scale).c_str())); \
} \
}
#define GENERATE_CODE(Name, ...) \
InstallBytecodeHandler(&zone, Bytecode::k##Name, operand_scale, \
&Interpreter::Do##Name);
BYTECODE_LIST(GENERATE_CODE)
#undef GENERATE_CODE
}
@ -114,6 +93,27 @@ void Interpreter::Initialize() {
DCHECK(IsDispatchTableInitialized());
}
void Interpreter::InstallBytecodeHandler(Zone* zone, Bytecode bytecode,
OperandScale operand_scale,
BytecodeGeneratorFunc generator) {
if (!Bytecodes::BytecodeHasHandler(bytecode, operand_scale)) return;
InterpreterDispatchDescriptor descriptor(isolate_);
compiler::CodeAssemblerState state(
isolate_, zone, descriptor, Code::ComputeFlags(Code::BYTECODE_HANDLER),
Bytecodes::ToString(bytecode), Bytecodes::ReturnCount(bytecode));
InterpreterAssembler assembler(&state, bytecode, operand_scale);
(this->*generator)(&assembler);
Handle<Code> code = compiler::CodeAssembler::GenerateCode(&state);
size_t index = GetDispatchTableIndex(bytecode, operand_scale);
dispatch_table_[index] = code->entry();
TraceCodegen(code);
PROFILE(isolate_, CodeCreateEvent(
CodeEventListener::BYTECODE_HANDLER_TAG,
AbstractCode::cast(*code),
Bytecodes::ToString(bytecode, operand_scale).c_str()));
}
Code* Interpreter::GetBytecodeHandler(Bytecode bytecode,
OperandScale operand_scale) {
DCHECK(IsDispatchTableInitialized());

View File

@ -76,6 +76,14 @@ class Interpreter {
BYTECODE_LIST(DECLARE_BYTECODE_HANDLER_GENERATOR)
#undef DECLARE_BYTECODE_HANDLER_GENERATOR
typedef void (Interpreter::*BytecodeGeneratorFunc)(InterpreterAssembler*);
// Generates handler for given |bytecode| and |operand_scale| using
// |generator| and installs it into the dispatch table.
void InstallBytecodeHandler(Zone* zone, Bytecode bytecode,
OperandScale operand_scale,
BytecodeGeneratorFunc generator);
// Generates code to perform the binary operation via |Generator|.
template <class Generator>
void DoBinaryOpWithFeedback(InterpreterAssembler* assembler);