Commit ec3774ec authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[maglev] Support CreateEvalContext

Bug: v8:7700
Change-Id: Iaff0bf8d3ed1510bd9d8605932905bee9341e33f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3815483
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#82252}
parent 752872d0
......@@ -6,6 +6,7 @@
#include "src/base/optional.h"
#include "src/base/v8-fallthrough.h"
#include "src/builtins/builtins-constructor.h"
#include "src/codegen/interface-descriptors-inl.h"
#include "src/common/globals.h"
#include "src/compiler/compilation-dependencies.h"
......@@ -2216,11 +2217,22 @@ void MaglevGraphBuilder::VisitCreateCatchContext() {
void MaglevGraphBuilder::VisitCreateFunctionContext() {
compiler::ScopeInfoRef info = GetRefOperand<ScopeInfo>(0);
uint32_t slot_count = iterator_.GetUnsignedImmediateOperand(1);
SetAccumulator(
AddNewNode<CreateFunctionContext>({GetContext()}, info, slot_count));
SetAccumulator(AddNewNode<CreateFunctionContext>(
{GetContext()}, info, slot_count, ScopeType::FUNCTION_SCOPE));
}
MAGLEV_UNIMPLEMENTED_BYTECODE(CreateEvalContext)
void MaglevGraphBuilder::VisitCreateEvalContext() {
compiler::ScopeInfoRef info = GetRefOperand<ScopeInfo>(0);
uint32_t slot_count = iterator_.GetUnsignedImmediateOperand(1);
if (slot_count <= static_cast<uint32_t>(
ConstructorBuiltins::MaximumFunctionContextSlots())) {
SetAccumulator(AddNewNode<CreateFunctionContext>(
{GetContext()}, info, slot_count, ScopeType::EVAL_SCOPE));
} else {
SetAccumulator(
BuildCallRuntime(Runtime::kNewFunctionContext, {GetConstant(info)}));
}
}
void MaglevGraphBuilder::VisitCreateWithContext() {
// TODO(v8:7700): Inline allocation when context is small.
......
......@@ -1060,24 +1060,42 @@ void CreateShallowObjectLiteral::GenerateCode(
void CreateFunctionContext::AllocateVreg(
MaglevVregAllocationState* vreg_state) {
using D = CallInterfaceDescriptorFor<
Builtin::kFastNewFunctionContextFunction>::type;
static_assert(D::HasContextParameter());
UseFixed(context(), D::ContextRegister());
DCHECK_LE(slot_count(),
static_cast<uint32_t>(
ConstructorBuiltins::MaximumFunctionContextSlots()));
if (scope_type() == FUNCTION_SCOPE) {
using D = CallInterfaceDescriptorFor<
Builtin::kFastNewFunctionContextFunction>::type;
static_assert(D::HasContextParameter());
UseFixed(context(), D::ContextRegister());
} else {
DCHECK_EQ(scope_type(), ScopeType::EVAL_SCOPE);
using D =
CallInterfaceDescriptorFor<Builtin::kFastNewFunctionContextEval>::type;
static_assert(D::HasContextParameter());
UseFixed(context(), D::ContextRegister());
}
DefineAsFixed(vreg_state, this, kReturnRegister0);
}
void CreateFunctionContext::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) {
using D = CallInterfaceDescriptorFor<
Builtin::kFastNewFunctionContextFunction>::type;
DCHECK_LE(slot_count(), ConstructorBuiltins::MaximumFunctionContextSlots());
DCHECK_EQ(scope_info().object()->scope_type(), ScopeType::FUNCTION_SCOPE);
DCHECK_EQ(ToRegister(context()), D::ContextRegister());
__ Move(D::GetRegisterParameter(D::kScopeInfo), scope_info().object());
__ Move(D::GetRegisterParameter(D::kSlots), Immediate(slot_count()));
// TODO(leszeks): Consider inlining this allocation.
__ CallBuiltin(Builtin::kFastNewFunctionContextFunction);
if (scope_type() == FUNCTION_SCOPE) {
using D = CallInterfaceDescriptorFor<
Builtin::kFastNewFunctionContextFunction>::type;
DCHECK_EQ(ToRegister(context()), D::ContextRegister());
__ Move(D::GetRegisterParameter(D::kScopeInfo), scope_info().object());
__ Move(D::GetRegisterParameter(D::kSlots), Immediate(slot_count()));
// TODO(leszeks): Consider inlining this allocation.
__ CallBuiltin(Builtin::kFastNewFunctionContextFunction);
} else {
DCHECK_EQ(scope_type(), ScopeType::EVAL_SCOPE);
using D =
CallInterfaceDescriptorFor<Builtin::kFastNewFunctionContextEval>::type;
DCHECK_EQ(ToRegister(context()), D::ContextRegister());
__ Move(D::GetRegisterParameter(D::kScopeInfo), scope_info().object());
__ Move(D::GetRegisterParameter(D::kSlots), Immediate(slot_count()));
__ CallBuiltin(Builtin::kFastNewFunctionContextEval);
}
}
void CreateFunctionContext::PrintParams(
std::ostream& os, MaglevGraphLabeller* graph_labeller) const {
......
......@@ -2166,11 +2166,15 @@ class CreateFunctionContext
public:
explicit CreateFunctionContext(uint64_t bitfield,
compiler::ScopeInfoRef scope_info,
uint32_t slot_count)
: Base(bitfield), scope_info_(scope_info), slot_count_(slot_count) {}
uint32_t slot_count, ScopeType scope_type)
: Base(bitfield),
scope_info_(scope_info),
slot_count_(slot_count),
scope_type_(scope_type) {}
compiler::ScopeInfoRef scope_info() const { return scope_info_; }
uint32_t slot_count() const { return slot_count_; }
ScopeType scope_type() const { return scope_type_; }
Input& context() { return input(0); }
......@@ -2184,6 +2188,7 @@ class CreateFunctionContext
private:
const compiler::ScopeInfoRef scope_info_;
const uint32_t slot_count_;
ScopeType scope_type_;
};
class FastCreateClosure : public FixedInputValueNodeT<1, FastCreateClosure> {
......
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