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