Commit 5a9eac3a authored by leszeks's avatar leszeks Committed by Commit bot

[Interpreter] Add an unsigned immediate operand type

Review-Url: https://codereview.chromium.org/2336203002
Cr-Commit-Position: refs/heads/master@{#39388}
parent 526f4dc6
...@@ -838,9 +838,9 @@ Node* BytecodeGraphBuilder::BuildLoadContextSlot() { ...@@ -838,9 +838,9 @@ Node* BytecodeGraphBuilder::BuildLoadContextSlot() {
// TODO(mythria): immutable flag is also set to false. This information is not // TODO(mythria): immutable flag is also set to false. This information is not
// available in bytecode array. update this code when the implementation // available in bytecode array. update this code when the implementation
// changes. // changes.
const Operator* op = const Operator* op = javascript()->LoadContext(
javascript()->LoadContext(bytecode_iterator().GetIndexOperand(2), bytecode_iterator().GetUnsignedImmediateOperand(2),
bytecode_iterator().GetIndexOperand(1), false); bytecode_iterator().GetIndexOperand(1), false);
Node* context = Node* context =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0)); environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
return NewNode(op, context); return NewNode(op, context);
...@@ -857,9 +857,9 @@ void BytecodeGraphBuilder::VisitLdrContextSlot() { ...@@ -857,9 +857,9 @@ void BytecodeGraphBuilder::VisitLdrContextSlot() {
} }
void BytecodeGraphBuilder::VisitStaContextSlot() { void BytecodeGraphBuilder::VisitStaContextSlot() {
const Operator* op = const Operator* op = javascript()->StoreContext(
javascript()->StoreContext(bytecode_iterator().GetIndexOperand(2), bytecode_iterator().GetUnsignedImmediateOperand(2),
bytecode_iterator().GetIndexOperand(1)); bytecode_iterator().GetIndexOperand(1));
Node* context = Node* context =
environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0)); environment()->LookupRegister(bytecode_iterator().GetRegisterOperand(0));
Node* value = environment()->LookupAccumulator(); Node* value = environment()->LookupAccumulator();
...@@ -1037,7 +1037,7 @@ void BytecodeGraphBuilder::VisitCreateBlockContext() { ...@@ -1037,7 +1037,7 @@ void BytecodeGraphBuilder::VisitCreateBlockContext() {
} }
void BytecodeGraphBuilder::VisitCreateFunctionContext() { void BytecodeGraphBuilder::VisitCreateFunctionContext() {
uint32_t slots = bytecode_iterator().GetIndexOperand(0); uint32_t slots = bytecode_iterator().GetUnsignedImmediateOperand(0);
const Operator* op = javascript()->CreateFunctionContext(slots); const Operator* op = javascript()->CreateFunctionContext(slots);
Node* context = NewNode(op, GetFunctionClosure()); Node* context = NewNode(op, GetFunctionClosure());
environment()->BindAccumulator(context); environment()->BindAccumulator(context);
......
...@@ -788,10 +788,10 @@ bool BytecodeArrayBuilder::OperandsAreValid( ...@@ -788,10 +788,10 @@ bool BytecodeArrayBuilder::OperandsAreValid(
} }
break; break;
case OperandType::kIdx: case OperandType::kIdx:
// TODO(oth): Consider splitting OperandType::kIdx into two // TODO(leszeks): Possibly split this up into constant pool indices and
// operand types. One which is a constant pool index that can // other indices, for checking
// be checked, and the other is an unsigned value.
break; break;
case OperandType::kUImm:
case OperandType::kImm: case OperandType::kImm:
break; break;
case OperandType::kMaybeReg: case OperandType::kMaybeReg:
......
...@@ -97,6 +97,13 @@ uint32_t BytecodeArrayIterator::GetFlagOperand(int operand_index) const { ...@@ -97,6 +97,13 @@ uint32_t BytecodeArrayIterator::GetFlagOperand(int operand_index) const {
return GetUnsignedOperand(operand_index, OperandType::kFlag8); return GetUnsignedOperand(operand_index, OperandType::kFlag8);
} }
uint32_t BytecodeArrayIterator::GetUnsignedImmediateOperand(
int operand_index) const {
DCHECK_EQ(Bytecodes::GetOperandType(current_bytecode(), operand_index),
OperandType::kUImm);
return GetUnsignedOperand(operand_index, OperandType::kUImm);
}
int32_t BytecodeArrayIterator::GetImmediateOperand(int operand_index) const { int32_t BytecodeArrayIterator::GetImmediateOperand(int operand_index) const {
DCHECK_EQ(Bytecodes::GetOperandType(current_bytecode(), operand_index), DCHECK_EQ(Bytecodes::GetOperandType(current_bytecode(), operand_index),
OperandType::kImm); OperandType::kImm);
......
...@@ -31,6 +31,7 @@ class BytecodeArrayIterator { ...@@ -31,6 +31,7 @@ class BytecodeArrayIterator {
} }
uint32_t GetFlagOperand(int operand_index) const; uint32_t GetFlagOperand(int operand_index) const;
uint32_t GetUnsignedImmediateOperand(int operand_index) const;
int32_t GetImmediateOperand(int operand_index) const; int32_t GetImmediateOperand(int operand_index) const;
uint32_t GetIndexOperand(int operand_index) const; uint32_t GetIndexOperand(int operand_index) const;
uint32_t GetRegisterCountOperand(int operand_index) const; uint32_t GetRegisterCountOperand(int operand_index) const;
......
...@@ -107,6 +107,7 @@ std::ostream& BytecodeDecoder::Decode(std::ostream& os, ...@@ -107,6 +107,7 @@ std::ostream& BytecodeDecoder::Decode(std::ostream& os,
<< DecodeUnsignedOperand(operand_start, op_type, operand_scale); << DecodeUnsignedOperand(operand_start, op_type, operand_scale);
break; break;
case interpreter::OperandType::kIdx: case interpreter::OperandType::kIdx:
case interpreter::OperandType::kUImm:
case interpreter::OperandType::kRuntimeId: case interpreter::OperandType::kRuntimeId:
case interpreter::OperandType::kIntrinsicId: case interpreter::OperandType::kIntrinsicId:
os << "[" os << "["
......
...@@ -33,6 +33,7 @@ namespace interpreter { ...@@ -33,6 +33,7 @@ namespace interpreter {
V(Flag8, OperandTypeInfo::kFixedUnsignedByte) \ V(Flag8, OperandTypeInfo::kFixedUnsignedByte) \
V(IntrinsicId, OperandTypeInfo::kFixedUnsignedByte) \ V(IntrinsicId, OperandTypeInfo::kFixedUnsignedByte) \
V(Idx, OperandTypeInfo::kScalableUnsignedByte) \ V(Idx, OperandTypeInfo::kScalableUnsignedByte) \
V(UImm, OperandTypeInfo::kScalableUnsignedByte) \
V(Imm, OperandTypeInfo::kScalableSignedByte) \ V(Imm, OperandTypeInfo::kScalableSignedByte) \
V(RegCount, OperandTypeInfo::kScalableUnsignedByte) \ V(RegCount, OperandTypeInfo::kScalableUnsignedByte) \
V(RuntimeId, OperandTypeInfo::kFixedUnsignedShort) V(RuntimeId, OperandTypeInfo::kFixedUnsignedShort)
...@@ -106,11 +107,11 @@ namespace interpreter { ...@@ -106,11 +107,11 @@ namespace interpreter {
V(PushContext, AccumulatorUse::kRead, OperandType::kRegOut) \ V(PushContext, AccumulatorUse::kRead, OperandType::kRegOut) \
V(PopContext, AccumulatorUse::kNone, OperandType::kReg) \ V(PopContext, AccumulatorUse::kNone, OperandType::kReg) \
V(LdaContextSlot, AccumulatorUse::kWrite, OperandType::kReg, \ V(LdaContextSlot, AccumulatorUse::kWrite, OperandType::kReg, \
OperandType::kIdx, OperandType::kIdx) \ OperandType::kIdx, OperandType::kUImm) \
V(LdrContextSlot, AccumulatorUse::kNone, OperandType::kReg, \ V(LdrContextSlot, AccumulatorUse::kNone, OperandType::kReg, \
OperandType::kIdx, OperandType::kIdx, OperandType::kRegOut) \ OperandType::kIdx, OperandType::kUImm, OperandType::kRegOut) \
V(StaContextSlot, AccumulatorUse::kRead, OperandType::kReg, \ V(StaContextSlot, AccumulatorUse::kRead, OperandType::kReg, \
OperandType::kIdx, OperandType::kIdx) \ OperandType::kIdx, OperandType::kUImm) \
\ \
/* Load-Store lookup slots */ \ /* Load-Store lookup slots */ \
V(LdaLookupSlot, AccumulatorUse::kWrite, OperandType::kIdx) \ V(LdaLookupSlot, AccumulatorUse::kWrite, OperandType::kIdx) \
...@@ -246,8 +247,7 @@ namespace interpreter { ...@@ -246,8 +247,7 @@ namespace interpreter {
V(CreateBlockContext, AccumulatorUse::kReadWrite, OperandType::kIdx) \ V(CreateBlockContext, AccumulatorUse::kReadWrite, OperandType::kIdx) \
V(CreateCatchContext, AccumulatorUse::kReadWrite, OperandType::kReg, \ V(CreateCatchContext, AccumulatorUse::kReadWrite, OperandType::kReg, \
OperandType::kIdx, OperandType::kIdx) \ OperandType::kIdx, OperandType::kIdx) \
/* TODO(klaasb) rename Idx or add unsigned Imm OperandType? */ \ V(CreateFunctionContext, AccumulatorUse::kWrite, OperandType::kUImm) \
V(CreateFunctionContext, AccumulatorUse::kWrite, OperandType::kIdx) \
V(CreateWithContext, AccumulatorUse::kReadWrite, OperandType::kReg, \ V(CreateWithContext, AccumulatorUse::kReadWrite, OperandType::kReg, \
OperandType::kIdx) \ OperandType::kIdx) \
\ \
......
...@@ -371,6 +371,14 @@ Node* InterpreterAssembler::BytecodeOperandFlag(int operand_index) { ...@@ -371,6 +371,14 @@ Node* InterpreterAssembler::BytecodeOperandFlag(int operand_index) {
return BytecodeUnsignedOperand(operand_index, operand_size); return BytecodeUnsignedOperand(operand_index, operand_size);
} }
Node* InterpreterAssembler::BytecodeOperandUImm(int operand_index) {
DCHECK_EQ(OperandType::kUImm,
Bytecodes::GetOperandType(bytecode_, operand_index));
OperandSize operand_size =
Bytecodes::GetOperandSize(bytecode_, operand_index, operand_scale());
return BytecodeUnsignedOperand(operand_index, operand_size);
}
Node* InterpreterAssembler::BytecodeOperandImm(int operand_index) { Node* InterpreterAssembler::BytecodeOperandImm(int operand_index) {
DCHECK_EQ(OperandType::kImm, DCHECK_EQ(OperandType::kImm,
Bytecodes::GetOperandType(bytecode_, operand_index)); Bytecodes::GetOperandType(bytecode_, operand_index));
......
...@@ -32,6 +32,9 @@ class InterpreterAssembler : public CodeStubAssembler { ...@@ -32,6 +32,9 @@ class InterpreterAssembler : public CodeStubAssembler {
// Returns the index immediate for bytecode operand |operand_index| in the // Returns the index immediate for bytecode operand |operand_index| in the
// current bytecode. // current bytecode.
compiler::Node* BytecodeOperandIdx(int operand_index); compiler::Node* BytecodeOperandIdx(int operand_index);
// Returns the UImm8 immediate for bytecode operand |operand_index| in the
// current bytecode.
compiler::Node* BytecodeOperandUImm(int operand_index);
// Returns the Imm8 immediate for bytecode operand |operand_index| in the // Returns the Imm8 immediate for bytecode operand |operand_index| in the
// current bytecode. // current bytecode.
compiler::Node* BytecodeOperandImm(int operand_index); compiler::Node* BytecodeOperandImm(int operand_index);
......
...@@ -520,7 +520,7 @@ compiler::Node* Interpreter::BuildLoadContextSlot( ...@@ -520,7 +520,7 @@ compiler::Node* Interpreter::BuildLoadContextSlot(
Node* reg_index = __ BytecodeOperandReg(0); Node* reg_index = __ BytecodeOperandReg(0);
Node* context = __ LoadRegister(reg_index); Node* context = __ LoadRegister(reg_index);
Node* slot_index = __ BytecodeOperandIdx(1); Node* slot_index = __ BytecodeOperandIdx(1);
Node* depth = __ BytecodeOperandIdx(2); Node* depth = __ BytecodeOperandUImm(2);
Node* slot_context = __ GetContextAtDepth(context, depth); Node* slot_context = __ GetContextAtDepth(context, depth);
return __ LoadContextSlot(slot_context, slot_index); return __ LoadContextSlot(slot_context, slot_index);
} }
...@@ -555,7 +555,7 @@ void Interpreter::DoStaContextSlot(InterpreterAssembler* assembler) { ...@@ -555,7 +555,7 @@ void Interpreter::DoStaContextSlot(InterpreterAssembler* assembler) {
Node* reg_index = __ BytecodeOperandReg(0); Node* reg_index = __ BytecodeOperandReg(0);
Node* context = __ LoadRegister(reg_index); Node* context = __ LoadRegister(reg_index);
Node* slot_index = __ BytecodeOperandIdx(1); Node* slot_index = __ BytecodeOperandIdx(1);
Node* depth = __ BytecodeOperandIdx(2); Node* depth = __ BytecodeOperandUImm(2);
Node* slot_context = __ GetContextAtDepth(context, depth); Node* slot_context = __ GetContextAtDepth(context, depth);
__ StoreContextSlot(slot_context, slot_index, value); __ StoreContextSlot(slot_context, slot_index, value);
__ Dispatch(); __ Dispatch();
...@@ -2039,7 +2039,7 @@ void Interpreter::DoCreateCatchContext(InterpreterAssembler* assembler) { ...@@ -2039,7 +2039,7 @@ void Interpreter::DoCreateCatchContext(InterpreterAssembler* assembler) {
// Creates a new context with number of |slots| for the function closure. // Creates a new context with number of |slots| for the function closure.
void Interpreter::DoCreateFunctionContext(InterpreterAssembler* assembler) { void Interpreter::DoCreateFunctionContext(InterpreterAssembler* assembler) {
Node* closure = __ LoadRegister(Register::function_closure()); Node* closure = __ LoadRegister(Register::function_closure());
Node* slots = __ BytecodeOperandIdx(0); Node* slots = __ BytecodeOperandUImm(0);
Node* context = __ GetContext(); Node* context = __ GetContext();
__ SetAccumulator( __ SetAccumulator(
FastNewFunctionContextStub::Generate(assembler, closure, slots, context)); FastNewFunctionContextStub::Generate(assembler, closure, slots, context));
......
...@@ -150,6 +150,9 @@ void BytecodeExpectationsPrinter::PrintBytecodeOperand( ...@@ -150,6 +150,9 @@ void BytecodeExpectationsPrinter::PrintBytecodeOperand(
case OperandType::kIdx: case OperandType::kIdx:
stream << bytecode_iterator.GetIndexOperand(op_index); stream << bytecode_iterator.GetIndexOperand(op_index);
break; break;
case OperandType::kUImm:
stream << bytecode_iterator.GetUnsignedImmediateOperand(op_index);
break;
case OperandType::kImm: case OperandType::kImm:
stream << bytecode_iterator.GetImmediateOperand(op_index); stream << bytecode_iterator.GetImmediateOperand(op_index);
break; break;
......
...@@ -421,6 +421,10 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) { ...@@ -421,6 +421,10 @@ TARGET_TEST_F(InterpreterAssemblerTest, BytecodeOperand) {
EXPECT_THAT(m.BytecodeOperandIdx(i), EXPECT_THAT(m.BytecodeOperandIdx(i),
m.IsUnsignedOperand(offset, operand_size)); m.IsUnsignedOperand(offset, operand_size));
break; break;
case interpreter::OperandType::kUImm:
EXPECT_THAT(m.BytecodeOperandUImm(i),
m.IsUnsignedOperand(offset, operand_size));
break;
case interpreter::OperandType::kImm: { case interpreter::OperandType::kImm: {
EXPECT_THAT(m.BytecodeOperandImm(i), EXPECT_THAT(m.BytecodeOperandImm(i),
m.IsSignedOperand(offset, operand_size)); m.IsSignedOperand(offset, operand_size));
......
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