Commit cd647530 authored by Victor Gomes's avatar Victor Gomes Committed by Commit Bot

[interpreter] Adapt interpreter to handle V8_REVERSE_JSARGS

Bug: v8:10201
Change-Id: Ia7e964df89ac134c01a3fd94ce4b15f1afd0cbff
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2083295Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66560}
parent cb67be1a
......@@ -233,8 +233,13 @@ BytecodeRegisterOptimizer::BytecodeRegisterOptimizer(
// a vector of register metadata.
// There is at least one parameter, which is the JS receiver.
DCHECK_NE(parameter_count, 0);
#ifdef V8_REVERSE_JSARGS
int first_slot_index = parameter_count - 1;
#else
int first_slot_index = 0;
#endif
register_info_table_offset_ =
-Register::FromParameterIndex(0, parameter_count).index();
-Register::FromParameterIndex(first_slot_index, parameter_count).index();
// Initialize register map for parameters, locals, and the
// accumulator.
......
......@@ -8,10 +8,17 @@ namespace v8 {
namespace internal {
namespace interpreter {
#ifdef V8_REVERSE_JSARGS
static const int kFirstParamRegisterIndex =
(InterpreterFrameConstants::kRegisterFileFromFp -
InterpreterFrameConstants::kFirstParamFromFp) /
kSystemPointerSize;
#else
static const int kLastParamRegisterIndex =
(InterpreterFrameConstants::kRegisterFileFromFp -
InterpreterFrameConstants::kLastParamFromFp) /
kSystemPointerSize;
#endif
static const int kFunctionClosureRegisterIndex =
(InterpreterFrameConstants::kRegisterFileFromFp -
StandardFrameConstants::kFunctionOffset) /
......@@ -36,14 +43,22 @@ static const int kCallerPCOffsetRegisterIndex =
Register Register::FromParameterIndex(int index, int parameter_count) {
DCHECK_GE(index, 0);
DCHECK_LT(index, parameter_count);
#ifdef V8_REVERSE_JSARGS
int register_index = kFirstParamRegisterIndex - index;
#else
int register_index = kLastParamRegisterIndex - parameter_count + index + 1;
#endif
DCHECK_LT(register_index, 0);
return Register(register_index);
}
int Register::ToParameterIndex(int parameter_count) const {
DCHECK(is_parameter());
#ifdef V8_REVERSE_JSARGS
return kFirstParamRegisterIndex - index();
#else
return index() - kLastParamRegisterIndex + parameter_count - 1;
#endif
}
Register Register::function_closure() {
......
......@@ -765,9 +765,15 @@ void InterpreterAssembler::CallJSAndDispatch(TNode<Object> function,
if (receiver_mode == ConvertReceiverMode::kNullOrUndefined) {
// The first argument parameter (the receiver) is implied to be undefined.
#ifdef V8_REVERSE_JSARGS
TailCallStubThenBytecodeDispatch(callable.descriptor(), code_target,
context, function, arg_count, args...,
UndefinedConstant());
#else
TailCallStubThenBytecodeDispatch(callable.descriptor(), code_target,
context, function, arg_count,
UndefinedConstant(), args...);
#endif
} else {
TailCallStubThenBytecodeDispatch(callable.descriptor(), code_target,
context, function, arg_count, args...);
......@@ -1523,9 +1529,14 @@ TNode<FixedArray> InterpreterAssembler::ExportParametersAndRegisterFile(
// Iterate over parameters and write them into the array.
Label loop(this, &var_index), done_loop(this);
#ifdef V8_REVERSE_JSARGS
TNode<IntPtrT> reg_base =
IntPtrConstant(Register::FromParameterIndex(0, 1).ToOperand() + 1);
#else
TNode<IntPtrT> reg_base = IntPtrAdd(
IntPtrConstant(Register::FromParameterIndex(0, 1).ToOperand() - 1),
formal_parameter_count_intptr);
#endif
Goto(&loop);
BIND(&loop);
......@@ -1534,7 +1545,11 @@ TNode<FixedArray> InterpreterAssembler::ExportParametersAndRegisterFile(
GotoIfNot(UintPtrLessThan(index, formal_parameter_count_intptr),
&done_loop);
#ifdef V8_REVERSE_JSARGS
TNode<IntPtrT> reg_index = IntPtrAdd(reg_base, index);
#else
TNode<IntPtrT> reg_index = IntPtrSub(reg_base, index);
#endif
TNode<Object> value = LoadRegister(reg_index);
StoreFixedArrayElement(array, index, value);
......
......@@ -1586,17 +1586,32 @@ class InterpreterJSCallAssembler : public InterpreterAssembler {
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex));
break;
case 2:
#ifdef V8_REVERSE_JSARGS
CallJSAndDispatch(
function, context, Int32Constant(arg_count), receiver_mode,
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex + 1),
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex));
#else
CallJSAndDispatch(
function, context, Int32Constant(arg_count), receiver_mode,
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex),
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex + 1));
#endif
break;
case 3:
#ifdef V8_REVERSE_JSARGS
CallJSAndDispatch(
function, context, Int32Constant(arg_count), receiver_mode,
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex + 2),
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex + 1),
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex));
#else
CallJSAndDispatch(
function, context, Int32Constant(arg_count), receiver_mode,
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex),
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex + 1),
LoadRegisterAtOperandIndex(kFirstArgumentOperandIndex + 2));
#endif
break;
default:
UNREACHABLE();
......
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