 Chromium Code Reviews
 Chromium Code Reviews Issue 2142273003:
  [interpreter] Inline Star on dispatch for some bytecodes  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master
    
  
    Issue 2142273003:
  [interpreter] Inline Star on dispatch for some bytecodes  (Closed) 
  Base URL: https://chromium.googlesource.com/v8/v8.git@master| Index: src/interpreter/interpreter-assembler.cc | 
| diff --git a/src/interpreter/interpreter-assembler.cc b/src/interpreter/interpreter-assembler.cc | 
| index ee5f8be27981f19b63ddf8eb3029729cb147a7fa..7583a82aa0207933b116e3f7663d423ff7c006e2 100644 | 
| --- a/src/interpreter/interpreter-assembler.cc | 
| +++ b/src/interpreter/interpreter-assembler.cc | 
| @@ -30,6 +30,7 @@ InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone, | 
| Bytecodes::ToString(bytecode), | 
| Bytecodes::ReturnCount(bytecode)), | 
| bytecode_(bytecode), | 
| + bytecode_offset_(this, MachineType::PointerRepresentation()), | 
| operand_scale_(operand_scale), | 
| interpreted_frame_pointer_(this, MachineType::PointerRepresentation()), | 
| accumulator_(this, MachineRepresentation::kTagged), | 
| @@ -39,6 +40,8 @@ InterpreterAssembler::InterpreterAssembler(Isolate* isolate, Zone* zone, | 
| stack_pointer_before_call_(nullptr) { | 
| accumulator_.Bind( | 
| Parameter(InterpreterDispatchDescriptor::kAccumulatorParameter)); | 
| + bytecode_offset_.Bind( | 
| + Parameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter)); | 
| if (FLAG_trace_ignition) { | 
| TraceBytecode(Runtime::kInterpreterTraceBytecodeEntry); | 
| } | 
| @@ -83,7 +86,7 @@ void InterpreterAssembler::SetContext(Node* value) { | 
| } | 
| Node* InterpreterAssembler::BytecodeOffset() { | 
| - return Parameter(InterpreterDispatchDescriptor::kBytecodeOffsetParameter); | 
| + return bytecode_offset_.value(); | 
| } | 
| Node* InterpreterAssembler::BytecodeArrayTaggedPointer() { | 
| @@ -506,17 +509,29 @@ void InterpreterAssembler::UpdateInterruptBudget(Node* weight) { | 
| new_budget.value()); | 
| } | 
| +Node* InterpreterAssembler::Advance() { | 
| + return Advance(Bytecodes::Size(bytecode_, operand_scale_)); | 
| +} | 
| + | 
| Node* InterpreterAssembler::Advance(int delta) { | 
| - return IntPtrAdd(BytecodeOffset(), IntPtrConstant(delta)); | 
| + return Advance(IntPtrConstant(delta)); | 
| } | 
| Node* InterpreterAssembler::Advance(Node* delta) { | 
| - return IntPtrAdd(BytecodeOffset(), delta); | 
| + if (FLAG_trace_ignition) { | 
| + TraceBytecode(Runtime::kInterpreterTraceBytecodeExit); | 
| + } | 
| + Node* next_offset = IntPtrAdd(BytecodeOffset(), delta); | 
| + bytecode_offset_.Bind(next_offset); | 
| + return next_offset; | 
| } | 
| Node* InterpreterAssembler::Jump(Node* delta) { | 
| UpdateInterruptBudget(delta); | 
| - return DispatchTo(Advance(delta)); | 
| + Node* previous_offset = BytecodeOffset(); | 
| + Node* dispatch = DispatchTo(Advance(delta)); | 
| + bytecode_offset_.Bind(previous_offset); | 
| 
rmcilroy
2016/07/19 20:18:27
I don't think we need this line do we? We are be e
 
klaasb
2016/07/20 09:26:24
Done.
 | 
| + return dispatch; | 
| } | 
| void InterpreterAssembler::JumpConditional(Node* condition, Node* delta) { | 
| @@ -538,17 +553,71 @@ void InterpreterAssembler::JumpIfWordNotEqual(Node* lhs, Node* rhs, | 
| JumpConditional(WordNotEqual(lhs, rhs), delta); | 
| } | 
| +Node* InterpreterAssembler::LoadBytecode(compiler::Node* bytecode_offset) { | 
| + Node* bytecode = | 
| + Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(), bytecode_offset); | 
| + if (kPointerSize == 8) { | 
| + bytecode = ChangeUint32ToUint64(bytecode); | 
| + } | 
| + return bytecode; | 
| +} | 
| + | 
| +void InterpreterAssembler::StarDispatchLookahead(Variable& target_bytecode) { | 
| 
rmcilroy
2016/07/19 20:18:27
no non-const references - https://google.github.io
 
klaasb
2016/07/20 09:26:24
Done.
 | 
| + Label do_inline_star(this), done(this); | 
| + | 
| + Node* star_bytecode = IntPtrConstant(static_cast<int>(Bytecode::kStar)); | 
| + Node* is_star = WordEqual(target_bytecode.value(), star_bytecode); | 
| + BranchIf(is_star, &do_inline_star, &done); | 
| + Bind(&do_inline_star); | 
| 
rmcilroy
2016/07/19 20:18:27
nit - newline above.
 
klaasb
2016/07/20 09:26:24
Done.
 | 
| + { | 
| + InlineStar(); | 
| + target_bytecode.Bind(LoadBytecode(BytecodeOffset())); | 
| + Goto(&done); | 
| + } | 
| + Bind(&done); | 
| +} | 
| + | 
| +void InterpreterAssembler::InlineStar() { | 
| + Bytecode previous_bytecode = bytecode_; | 
| + AccumulatorUse previous_acc_use = accumulator_use_; | 
| + | 
| + bytecode_ = Bytecode::kStar; | 
| + accumulator_use_ = AccumulatorUse::kNone; | 
| + | 
| + if (FLAG_trace_ignition) { | 
| + TraceBytecode(Runtime::kInterpreterTraceBytecodeEntry); | 
| + } | 
| + StoreRegister(GetAccumulator(), BytecodeOperandReg(0)); | 
| + | 
| + DCHECK_EQ(accumulator_use_, Bytecodes::GetAccumulatorUse(bytecode_)); | 
| + | 
| + Advance(); | 
| + bytecode_ = previous_bytecode; | 
| + accumulator_use_ = previous_acc_use; | 
| +} | 
| + | 
| Node* InterpreterAssembler::Dispatch() { | 
| - return DispatchTo(Advance(Bytecodes::Size(bytecode_, operand_scale_))); | 
| + Node* previous_offset = BytecodeOffset(); | 
| + Node* target_offset = Advance(); | 
| + Node* target_bytecode = LoadBytecode(target_offset); | 
| + Variable var_bytecode(this, MachineRepresentation::kWord8); | 
| + var_bytecode.Bind(target_bytecode); | 
| + | 
| + if (Bytecodes::IsStarLookahead(bytecode_, operand_scale_)) { | 
| + StarDispatchLookahead(var_bytecode); | 
| + } | 
| + Node* dispatch = DispatchToBytecode(var_bytecode.value(), BytecodeOffset()); | 
| + bytecode_offset_.Bind(previous_offset); | 
| 
rmcilroy
2016/07/19 20:18:27
same comment as above.
 
klaasb
2016/07/20 09:26:24
Done.
 | 
| + return dispatch; | 
| } | 
| Node* InterpreterAssembler::DispatchTo(Node* new_bytecode_offset) { | 
| - Node* target_bytecode = Load( | 
| - MachineType::Uint8(), BytecodeArrayTaggedPointer(), new_bytecode_offset); | 
| - if (kPointerSize == 8) { | 
| - target_bytecode = ChangeUint32ToUint64(target_bytecode); | 
| - } | 
| + Node* target_bytecode = LoadBytecode(new_bytecode_offset); | 
| 
rmcilroy
2016/07/19 20:18:27
nit - DCHECK here that !Bytecodes::IsStarLookahead
 
klaasb
2016/07/20 09:26:24
Done.
 | 
| + return DispatchToBytecode(target_bytecode, new_bytecode_offset); | 
| +} | 
| +Node* InterpreterAssembler::DispatchToBytecode(Node* target_bytecode, | 
| + Node* new_bytecode_offset) { | 
| if (FLAG_trace_ignition_dispatches) { | 
| TraceBytecodeDispatch(target_bytecode); | 
| } | 
| @@ -569,10 +638,6 @@ Node* InterpreterAssembler::DispatchToBytecodeHandler(Node* handler, | 
| Node* InterpreterAssembler::DispatchToBytecodeHandlerEntry( | 
| Node* handler_entry, Node* bytecode_offset) { | 
| - if (FLAG_trace_ignition) { | 
| - TraceBytecode(Runtime::kInterpreterTraceBytecodeExit); | 
| - } | 
| - | 
| InterpreterDispatchDescriptor descriptor(isolate()); | 
| Node* args[] = {GetAccumulatorUnchecked(), bytecode_offset, | 
| BytecodeArrayTaggedPointer(), DispatchTableRawPointer()}; | 
| @@ -588,8 +653,7 @@ void InterpreterAssembler::DispatchWide(OperandScale operand_scale) { | 
| // Indices 256-511 correspond to bytecodes with operand_scale == 1 | 
| // Indices 512-767 correspond to bytecodes with operand_scale == 2 | 
| Node* next_bytecode_offset = Advance(1); | 
| - Node* next_bytecode = Load(MachineType::Uint8(), BytecodeArrayTaggedPointer(), | 
| - next_bytecode_offset); | 
| + Node* next_bytecode = LoadBytecode(next_bytecode_offset); | 
| if (kPointerSize == 8) { | 
| next_bytecode = ChangeUint32ToUint64(next_bytecode); | 
| } | 
| 
rmcilroy
2016/07/19 20:18:27
Remove extra ChangeUint32ToUint64 given it is alre
 
klaasb
2016/07/20 09:26:24
Done.
 |