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 @@ ...@@ -6,6 +6,7 @@
#include "src/base/optional.h" #include "src/base/optional.h"
#include "src/base/v8-fallthrough.h" #include "src/base/v8-fallthrough.h"
#include "src/builtins/builtins-constructor.h"
#include "src/codegen/interface-descriptors-inl.h" #include "src/codegen/interface-descriptors-inl.h"
#include "src/common/globals.h" #include "src/common/globals.h"
#include "src/compiler/compilation-dependencies.h" #include "src/compiler/compilation-dependencies.h"
...@@ -2216,11 +2217,22 @@ void MaglevGraphBuilder::VisitCreateCatchContext() { ...@@ -2216,11 +2217,22 @@ void MaglevGraphBuilder::VisitCreateCatchContext() {
void MaglevGraphBuilder::VisitCreateFunctionContext() { void MaglevGraphBuilder::VisitCreateFunctionContext() {
compiler::ScopeInfoRef info = GetRefOperand<ScopeInfo>(0); compiler::ScopeInfoRef info = GetRefOperand<ScopeInfo>(0);
uint32_t slot_count = iterator_.GetUnsignedImmediateOperand(1); uint32_t slot_count = iterator_.GetUnsignedImmediateOperand(1);
SetAccumulator( SetAccumulator(AddNewNode<CreateFunctionContext>(
AddNewNode<CreateFunctionContext>({GetContext()}, info, slot_count)); {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() { void MaglevGraphBuilder::VisitCreateWithContext() {
// TODO(v8:7700): Inline allocation when context is small. // TODO(v8:7700): Inline allocation when context is small.
......
...@@ -1060,24 +1060,42 @@ void CreateShallowObjectLiteral::GenerateCode( ...@@ -1060,24 +1060,42 @@ void CreateShallowObjectLiteral::GenerateCode(
void CreateFunctionContext::AllocateVreg( void CreateFunctionContext::AllocateVreg(
MaglevVregAllocationState* vreg_state) { MaglevVregAllocationState* vreg_state) {
using D = CallInterfaceDescriptorFor< DCHECK_LE(slot_count(),
Builtin::kFastNewFunctionContextFunction>::type; static_cast<uint32_t>(
static_assert(D::HasContextParameter()); ConstructorBuiltins::MaximumFunctionContextSlots()));
UseFixed(context(), D::ContextRegister()); 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); DefineAsFixed(vreg_state, this, kReturnRegister0);
} }
void CreateFunctionContext::GenerateCode(MaglevCodeGenState* code_gen_state, void CreateFunctionContext::GenerateCode(MaglevCodeGenState* code_gen_state,
const ProcessingState& state) { const ProcessingState& state) {
using D = CallInterfaceDescriptorFor< if (scope_type() == FUNCTION_SCOPE) {
Builtin::kFastNewFunctionContextFunction>::type; using D = CallInterfaceDescriptorFor<
DCHECK_LE(slot_count(), ConstructorBuiltins::MaximumFunctionContextSlots()); Builtin::kFastNewFunctionContextFunction>::type;
DCHECK_EQ(scope_info().object()->scope_type(), ScopeType::FUNCTION_SCOPE); DCHECK_EQ(ToRegister(context()), D::ContextRegister());
__ Move(D::GetRegisterParameter(D::kScopeInfo), scope_info().object());
DCHECK_EQ(ToRegister(context()), D::ContextRegister()); __ Move(D::GetRegisterParameter(D::kSlots), Immediate(slot_count()));
__ Move(D::GetRegisterParameter(D::kScopeInfo), scope_info().object()); // TODO(leszeks): Consider inlining this allocation.
__ Move(D::GetRegisterParameter(D::kSlots), Immediate(slot_count())); __ CallBuiltin(Builtin::kFastNewFunctionContextFunction);
// TODO(leszeks): Consider inlining this allocation. } else {
__ CallBuiltin(Builtin::kFastNewFunctionContextFunction); 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( void CreateFunctionContext::PrintParams(
std::ostream& os, MaglevGraphLabeller* graph_labeller) const { std::ostream& os, MaglevGraphLabeller* graph_labeller) const {
......
...@@ -2166,11 +2166,15 @@ class CreateFunctionContext ...@@ -2166,11 +2166,15 @@ class CreateFunctionContext
public: public:
explicit CreateFunctionContext(uint64_t bitfield, explicit CreateFunctionContext(uint64_t bitfield,
compiler::ScopeInfoRef scope_info, compiler::ScopeInfoRef scope_info,
uint32_t slot_count) uint32_t slot_count, ScopeType scope_type)
: Base(bitfield), scope_info_(scope_info), slot_count_(slot_count) {} : Base(bitfield),
scope_info_(scope_info),
slot_count_(slot_count),
scope_type_(scope_type) {}
compiler::ScopeInfoRef scope_info() const { return scope_info_; } compiler::ScopeInfoRef scope_info() const { return scope_info_; }
uint32_t slot_count() const { return slot_count_; } uint32_t slot_count() const { return slot_count_; }
ScopeType scope_type() const { return scope_type_; }
Input& context() { return input(0); } Input& context() { return input(0); }
...@@ -2184,6 +2188,7 @@ class CreateFunctionContext ...@@ -2184,6 +2188,7 @@ class CreateFunctionContext
private: private:
const compiler::ScopeInfoRef scope_info_; const compiler::ScopeInfoRef scope_info_;
const uint32_t slot_count_; const uint32_t slot_count_;
ScopeType scope_type_;
}; };
class FastCreateClosure : public FixedInputValueNodeT<1, FastCreateClosure> { 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