Commit 3ddec7cc authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[sparkplug] Add builtins for intrinsic runtime calls

Add baseline builtins for CreateAsyncFromSyncIterator and
GetImportMetaObject, and call those instead of the runtime functions.

Drive-by remove some TODOs in baseline-compiler.cc which are either no
longer planned or don't need to be done any time soon.

Bug: v8:11420, v8:11429
Change-Id: I15b4fe1f04316492045250b2c65ab6016f29b313
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2699261
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#72808}
parent a974dd7e
......@@ -193,8 +193,6 @@ struct ArgumentSettingHelper<interpreter::RegisterList> {
int i, interpreter::RegisterList list) {
// Either all the values are in machine registers, or they're all on the
// stack.
// TODO(v8:11429,leszeks): Support splitting the register list over
// registers and stack.
if (i < descriptor.GetRegisterParameterCount()) {
for (int reg_index = 0; reg_index < list.register_count();
++reg_index, ++i) {
......@@ -545,7 +543,7 @@ void BaselineCompiler::VerifyFrame() {
__ Bind(&is_ok);
}
// TODO(v8:11429,leszeks): More verification.
// TODO(leszeks): More verification.
__ RecordComment("]");
}
......@@ -582,8 +580,7 @@ void BaselineCompiler::UpdateInterruptBudgetAndJumpToLabel(
__ AddToInterruptBudget(weight);
if (weight < 0) {
// Use compare flags set by add
// TODO(v8:11429,leszeks): This might be trickier cross-arch.
// Use compare flags set by AddToInterruptBudget
__ JumpIf(Condition::kGreaterThanEqual, skip_interrupt_label);
SaveAccumulatorScope accumulator_scope(&basm_);
CallRuntime(Runtime::kBytecodeBudgetInterruptFromBytecode,
......@@ -1407,8 +1404,7 @@ void BaselineCompiler::VisitIntrinsicCall(interpreter::RegisterList args) {
void BaselineCompiler::VisitIntrinsicCreateAsyncFromSyncIterator(
interpreter::RegisterList args) {
// TODO(v8:11429,leszeks): Add fast-path.
CallRuntime(Runtime::kCreateAsyncFromSyncIterator, args);
CallBuiltin(Builtins::kCreateAsyncFromSyncIteratorBaseline, args[0]);
}
void BaselineCompiler::VisitIntrinsicCreateJSGeneratorObject(
......@@ -1435,8 +1431,7 @@ void BaselineCompiler::VisitIntrinsicGeneratorClose(
void BaselineCompiler::VisitIntrinsicGetImportMetaObject(
interpreter::RegisterList args) {
// TODO(v8:11429,leszeks): Add fast-path.
CallRuntime(Runtime::kGetImportMetaObject, args);
CallBuiltin(Builtins::kGetImportMetaObjectBaseline);
}
void BaselineCompiler::VisitIntrinsicAsyncFunctionAwaitCaught(
......@@ -2217,8 +2212,6 @@ void BaselineCompiler::VisitResumeGenerator() {
__ StoreRegister(interpreter::Register(i), value);
}
// TODO(v8:11429,leszeks): Just load the known InputOrDebugPosOffset value
// directly.
__ LoadTaggedAnyField(kInterpreterAccumulatorRegister, generator_object,
JSGeneratorObject::kInputOrDebugPosOffset);
}
......
......@@ -85,4 +85,12 @@ transitioning builtin ForInNext(
UpdateFeedbackMode::kGuaranteedFeedback);
}
extern macro GetImportMetaObject(Context): Object;
extern macro LoadContextFromBaseline(): Context;
builtin GetImportMetaObjectBaseline(): Object {
const context: Context = LoadContextFromBaseline();
return GetImportMetaObject(context);
}
} // namespace internal
......@@ -74,6 +74,7 @@ transitioning builtin GetIteratorWithFeedback(
context, receiver, iteratorMethod, callSlotSmi, maybeFeedbackVector);
}
extern macro LoadContextFromBaseline(): Context;
extern macro LoadFeedbackVectorFromBaseline(): FeedbackVector;
transitioning builtin GetIteratorBaseline(
......@@ -88,6 +89,14 @@ transitioning builtin GetIteratorBaseline(
context, receiver, iteratorMethod, callSlotSmi, feedback);
}
extern macro CreateAsyncFromSyncIterator(Context, JSAny): JSAny;
transitioning builtin CreateAsyncFromSyncIteratorBaseline(syncIterator: JSAny):
JSAny {
const context: Context = LoadContextFromBaseline();
return CreateAsyncFromSyncIterator(context, syncIterator);
}
transitioning builtin CallIteratorWithFeedback(
context: Context, receiver: JSAny, iteratorMethod: JSAny, callSlot: Smi,
feedback: Undefined|FeedbackVector): JSAny {
......
......@@ -2637,6 +2637,25 @@ TNode<Context> CodeStubAssembler::LoadModuleContext(TNode<Context> context) {
return UncheckedCast<Context>(cur_context.value());
}
TNode<Object> CodeStubAssembler::GetImportMetaObject(TNode<Context> context) {
const TNode<Context> module_context = LoadModuleContext(context);
const TNode<HeapObject> module =
CAST(LoadContextElement(module_context, Context::EXTENSION_INDEX));
const TNode<Object> import_meta =
LoadObjectField(module, SourceTextModule::kImportMetaOffset);
TVARIABLE(Object, return_value, import_meta);
Label end(this);
GotoIfNot(IsTheHole(import_meta), &end);
return_value = CallRuntime(Runtime::kGetImportMetaObject, context);
Goto(&end);
BIND(&end);
return return_value.value();
}
TNode<Map> CodeStubAssembler::LoadObjectFunctionInitialMap(
TNode<NativeContext> native_context) {
TNode<JSFunction> object_function =
......@@ -8820,6 +8839,43 @@ TNode<Object> CodeStubAssembler::GetIteratorMethod(
if_iteratorundefined);
}
TNode<Object> CodeStubAssembler::CreateAsyncFromSyncIterator(
TNode<Context> context, TNode<Object> sync_iterator) {
Label not_receiver(this, Label::kDeferred);
Label done(this);
TVARIABLE(Object, return_value);
GotoIf(TaggedIsSmi(sync_iterator), &not_receiver);
GotoIfNot(IsJSReceiver(CAST(sync_iterator)), &not_receiver);
const TNode<Object> next =
GetProperty(context, sync_iterator, factory()->next_string());
const TNode<NativeContext> native_context = LoadNativeContext(context);
const TNode<Map> map = CAST(LoadContextElement(
native_context, Context::ASYNC_FROM_SYNC_ITERATOR_MAP_INDEX));
const TNode<JSObject> iterator = AllocateJSObjectFromMap(map);
StoreObjectFieldNoWriteBarrier(
iterator, JSAsyncFromSyncIterator::kSyncIteratorOffset, sync_iterator);
StoreObjectFieldNoWriteBarrier(iterator, JSAsyncFromSyncIterator::kNextOffset,
next);
return_value = iterator;
Goto(&done);
BIND(&not_receiver);
{
return_value = CallRuntime(Runtime::kThrowSymbolIteratorInvalid, context);
// Unreachable due to the Throw in runtime call.
Goto(&done);
}
BIND(&done);
return return_value.value();
}
void CodeStubAssembler::LoadPropertyFromFastObject(
TNode<HeapObject> object, TNode<Map> map,
TNode<DescriptorArray> descriptors, TNode<IntPtrT> name_index,
......
......@@ -1477,6 +1477,8 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
// Calling this is only valid if there's a module context in the chain.
TNode<Context> LoadModuleContext(TNode<Context> context);
TNode<Object> GetImportMetaObject(TNode<Context> context);
void GotoIfContextElementEqual(SloppyTNode<Object> value,
TNode<NativeContext> native_context,
int slot_index, Label* if_equal) {
......@@ -3025,6 +3027,9 @@ class V8_EXPORT_PRIVATE CodeStubAssembler
TNode<HeapObject> heap_obj,
Label* if_iteratorundefined);
TNode<Object> CreateAsyncFromSyncIterator(TNode<Context> context,
TNode<Object> sync_iterator);
template <class... TArgs>
TNode<Object> CallBuiltin(Builtins::Name id, SloppyTNode<Object> context,
TArgs... args) {
......
......@@ -261,43 +261,8 @@ TNode<Object> IntrinsicsGenerator::Call(
TNode<Object> IntrinsicsGenerator::CreateAsyncFromSyncIterator(
const InterpreterAssembler::RegListNodePair& args, TNode<Context> context,
int arg_count) {
InterpreterAssembler::Label not_receiver(
assembler_, InterpreterAssembler::Label::kDeferred);
InterpreterAssembler::Label done(assembler_);
InterpreterAssembler::TVariable<Object> return_value(assembler_);
TNode<Object> sync_iterator = __ LoadRegisterFromRegisterList(args, 0);
__ GotoIf(__ TaggedIsSmi(sync_iterator), &not_receiver);
__ GotoIfNot(__ IsJSReceiver(__ CAST(sync_iterator)), &not_receiver);
const TNode<Object> next =
__ GetProperty(context, sync_iterator, factory()->next_string());
const TNode<NativeContext> native_context = __ LoadNativeContext(context);
const TNode<Map> map = __ CAST(__ LoadContextElement(
native_context, Context::ASYNC_FROM_SYNC_ITERATOR_MAP_INDEX));
const TNode<JSObject> iterator = __ AllocateJSObjectFromMap(map);
__ StoreObjectFieldNoWriteBarrier(
iterator, JSAsyncFromSyncIterator::kSyncIteratorOffset, sync_iterator);
__ StoreObjectFieldNoWriteBarrier(iterator,
JSAsyncFromSyncIterator::kNextOffset, next);
return_value = iterator;
__ Goto(&done);
__ BIND(&not_receiver);
{
return_value =
__ CallRuntime(Runtime::kThrowSymbolIteratorInvalid, context);
// Unreachable due to the Throw in runtime call.
__ Goto(&done);
}
__ BIND(&done);
return return_value.value();
return __ CreateAsyncFromSyncIterator(context, sync_iterator);
}
TNode<Object> IntrinsicsGenerator::CreateJSGeneratorObject(
......@@ -332,23 +297,7 @@ TNode<Object> IntrinsicsGenerator::GeneratorClose(
TNode<Object> IntrinsicsGenerator::GetImportMetaObject(
const InterpreterAssembler::RegListNodePair& args, TNode<Context> context,
int arg_count) {
const TNode<Context> module_context = __ LoadModuleContext(context);
const TNode<HeapObject> module =
__ CAST(__ LoadContextElement(module_context, Context::EXTENSION_INDEX));
const TNode<Object> import_meta =
__ LoadObjectField(module, SourceTextModule::kImportMetaOffset);
InterpreterAssembler::TVariable<Object> return_value(assembler_);
return_value = import_meta;
InterpreterAssembler::Label end(assembler_);
__ GotoIfNot(__ IsTheHole(import_meta), &end);
return_value = __ CallRuntime(Runtime::kGetImportMetaObject, context);
__ Goto(&end);
__ BIND(&end);
return return_value.value();
return __ GetImportMetaObject(context);
}
TNode<Object> IntrinsicsGenerator::AsyncFunctionAwaitCaught(
......
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