11cb0ef41Sopenharmony_ci// Copyright 2021 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ci// TODO(v8:11421): Remove #if once baseline compiler is ported to other 61cb0ef41Sopenharmony_ci// architectures. 71cb0ef41Sopenharmony_ci#include "src/flags/flags.h" 81cb0ef41Sopenharmony_ci#if ENABLE_SPARKPLUG 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ci#include <algorithm> 111cb0ef41Sopenharmony_ci#include <type_traits> 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci#include "src/base/bits.h" 141cb0ef41Sopenharmony_ci#include "src/baseline/baseline-assembler-inl.h" 151cb0ef41Sopenharmony_ci#include "src/baseline/baseline-assembler.h" 161cb0ef41Sopenharmony_ci#include "src/baseline/baseline-compiler.h" 171cb0ef41Sopenharmony_ci#include "src/builtins/builtins-constructor.h" 181cb0ef41Sopenharmony_ci#include "src/builtins/builtins-descriptors.h" 191cb0ef41Sopenharmony_ci#include "src/builtins/builtins.h" 201cb0ef41Sopenharmony_ci#include "src/codegen/assembler.h" 211cb0ef41Sopenharmony_ci#include "src/codegen/compiler.h" 221cb0ef41Sopenharmony_ci#include "src/codegen/interface-descriptors-inl.h" 231cb0ef41Sopenharmony_ci#include "src/codegen/machine-type.h" 241cb0ef41Sopenharmony_ci#include "src/codegen/macro-assembler-inl.h" 251cb0ef41Sopenharmony_ci#include "src/common/globals.h" 261cb0ef41Sopenharmony_ci#include "src/execution/frame-constants.h" 271cb0ef41Sopenharmony_ci#include "src/heap/local-factory-inl.h" 281cb0ef41Sopenharmony_ci#include "src/interpreter/bytecode-array-iterator.h" 291cb0ef41Sopenharmony_ci#include "src/interpreter/bytecode-flags.h" 301cb0ef41Sopenharmony_ci#include "src/logging/runtime-call-stats-scope.h" 311cb0ef41Sopenharmony_ci#include "src/objects/code.h" 321cb0ef41Sopenharmony_ci#include "src/objects/heap-object.h" 331cb0ef41Sopenharmony_ci#include "src/objects/instance-type.h" 341cb0ef41Sopenharmony_ci#include "src/objects/literal-objects-inl.h" 351cb0ef41Sopenharmony_ci#include "src/objects/shared-function-info-inl.h" 361cb0ef41Sopenharmony_ci#include "src/roots/roots.h" 371cb0ef41Sopenharmony_ci 381cb0ef41Sopenharmony_ci#if V8_TARGET_ARCH_X64 391cb0ef41Sopenharmony_ci#include "src/baseline/x64/baseline-compiler-x64-inl.h" 401cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_ARM64 411cb0ef41Sopenharmony_ci#include "src/baseline/arm64/baseline-compiler-arm64-inl.h" 421cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_IA32 431cb0ef41Sopenharmony_ci#include "src/baseline/ia32/baseline-compiler-ia32-inl.h" 441cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_ARM 451cb0ef41Sopenharmony_ci#include "src/baseline/arm/baseline-compiler-arm-inl.h" 461cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_PPC64 471cb0ef41Sopenharmony_ci#include "src/baseline/ppc/baseline-compiler-ppc-inl.h" 481cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_S390X 491cb0ef41Sopenharmony_ci#include "src/baseline/s390/baseline-compiler-s390-inl.h" 501cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_RISCV64 511cb0ef41Sopenharmony_ci#include "src/baseline/riscv64/baseline-compiler-riscv64-inl.h" 521cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_MIPS64 531cb0ef41Sopenharmony_ci#include "src/baseline/mips64/baseline-compiler-mips64-inl.h" 541cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_MIPS 551cb0ef41Sopenharmony_ci#include "src/baseline/mips/baseline-compiler-mips-inl.h" 561cb0ef41Sopenharmony_ci#elif V8_TARGET_ARCH_LOONG64 571cb0ef41Sopenharmony_ci#include "src/baseline/loong64/baseline-compiler-loong64-inl.h" 581cb0ef41Sopenharmony_ci#else 591cb0ef41Sopenharmony_ci#error Unsupported target architecture. 601cb0ef41Sopenharmony_ci#endif 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_cinamespace v8 { 631cb0ef41Sopenharmony_cinamespace internal { 641cb0ef41Sopenharmony_cinamespace baseline { 651cb0ef41Sopenharmony_ci 661cb0ef41Sopenharmony_citemplate <typename IsolateT> 671cb0ef41Sopenharmony_ciHandle<ByteArray> BytecodeOffsetTableBuilder::ToBytecodeOffsetTable( 681cb0ef41Sopenharmony_ci IsolateT* isolate) { 691cb0ef41Sopenharmony_ci if (bytes_.empty()) return isolate->factory()->empty_byte_array(); 701cb0ef41Sopenharmony_ci Handle<ByteArray> table = isolate->factory()->NewByteArray( 711cb0ef41Sopenharmony_ci static_cast<int>(bytes_.size()), AllocationType::kOld); 721cb0ef41Sopenharmony_ci MemCopy(table->GetDataStartAddress(), bytes_.data(), bytes_.size()); 731cb0ef41Sopenharmony_ci return table; 741cb0ef41Sopenharmony_ci} 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_cinamespace detail { 771cb0ef41Sopenharmony_ci 781cb0ef41Sopenharmony_ci#ifdef DEBUG 791cb0ef41Sopenharmony_cibool Clobbers(Register target, Register reg) { return target == reg; } 801cb0ef41Sopenharmony_cibool Clobbers(Register target, Handle<Object> handle) { return false; } 811cb0ef41Sopenharmony_cibool Clobbers(Register target, Smi smi) { return false; } 821cb0ef41Sopenharmony_cibool Clobbers(Register target, TaggedIndex index) { return false; } 831cb0ef41Sopenharmony_cibool Clobbers(Register target, int32_t imm) { return false; } 841cb0ef41Sopenharmony_cibool Clobbers(Register target, RootIndex index) { return false; } 851cb0ef41Sopenharmony_cibool Clobbers(Register target, interpreter::Register reg) { return false; } 861cb0ef41Sopenharmony_cibool Clobbers(Register target, interpreter::RegisterList list) { return false; } 871cb0ef41Sopenharmony_ci 881cb0ef41Sopenharmony_ci// We don't know what's inside machine registers or operands, so assume they 891cb0ef41Sopenharmony_ci// match. 901cb0ef41Sopenharmony_cibool MachineTypeMatches(MachineType type, Register reg) { return true; } 911cb0ef41Sopenharmony_cibool MachineTypeMatches(MachineType type, MemOperand reg) { return true; } 921cb0ef41Sopenharmony_cibool MachineTypeMatches(MachineType type, Handle<HeapObject> handle) { 931cb0ef41Sopenharmony_ci return type.IsTagged() && !type.IsTaggedSigned(); 941cb0ef41Sopenharmony_ci} 951cb0ef41Sopenharmony_cibool MachineTypeMatches(MachineType type, Smi handle) { 961cb0ef41Sopenharmony_ci return type.IsTagged() && !type.IsTaggedPointer(); 971cb0ef41Sopenharmony_ci} 981cb0ef41Sopenharmony_cibool MachineTypeMatches(MachineType type, TaggedIndex handle) { 991cb0ef41Sopenharmony_ci // TaggedIndex doesn't have a separate type, so check for the same type as for 1001cb0ef41Sopenharmony_ci // Smis. 1011cb0ef41Sopenharmony_ci return type.IsTagged() && !type.IsTaggedPointer(); 1021cb0ef41Sopenharmony_ci} 1031cb0ef41Sopenharmony_cibool MachineTypeMatches(MachineType type, int32_t imm) { 1041cb0ef41Sopenharmony_ci // 32-bit immediates can be used for 64-bit params -- they'll be 1051cb0ef41Sopenharmony_ci // zero-extended. 1061cb0ef41Sopenharmony_ci return type.representation() == MachineRepresentation::kWord32 || 1071cb0ef41Sopenharmony_ci type.representation() == MachineRepresentation::kWord64; 1081cb0ef41Sopenharmony_ci} 1091cb0ef41Sopenharmony_cibool MachineTypeMatches(MachineType type, RootIndex index) { 1101cb0ef41Sopenharmony_ci return type.IsTagged() && !type.IsTaggedSigned(); 1111cb0ef41Sopenharmony_ci} 1121cb0ef41Sopenharmony_cibool MachineTypeMatches(MachineType type, interpreter::Register reg) { 1131cb0ef41Sopenharmony_ci return type.IsTagged(); 1141cb0ef41Sopenharmony_ci} 1151cb0ef41Sopenharmony_ci 1161cb0ef41Sopenharmony_citemplate <typename Descriptor, typename... Args> 1171cb0ef41Sopenharmony_cistruct CheckArgsHelper; 1181cb0ef41Sopenharmony_ci 1191cb0ef41Sopenharmony_citemplate <typename Descriptor> 1201cb0ef41Sopenharmony_cistruct CheckArgsHelper<Descriptor> { 1211cb0ef41Sopenharmony_ci static void Check(BaselineAssembler* masm, int i) { 1221cb0ef41Sopenharmony_ci if (Descriptor::AllowVarArgs()) { 1231cb0ef41Sopenharmony_ci CHECK_GE(i, Descriptor::GetParameterCount()); 1241cb0ef41Sopenharmony_ci } else { 1251cb0ef41Sopenharmony_ci CHECK_EQ(i, Descriptor::GetParameterCount()); 1261cb0ef41Sopenharmony_ci } 1271cb0ef41Sopenharmony_ci } 1281cb0ef41Sopenharmony_ci}; 1291cb0ef41Sopenharmony_ci 1301cb0ef41Sopenharmony_citemplate <typename Descriptor, typename Arg, typename... Args> 1311cb0ef41Sopenharmony_cistruct CheckArgsHelper<Descriptor, Arg, Args...> { 1321cb0ef41Sopenharmony_ci static void Check(BaselineAssembler* masm, int i, Arg arg, Args... args) { 1331cb0ef41Sopenharmony_ci if (i >= Descriptor::GetParameterCount()) { 1341cb0ef41Sopenharmony_ci CHECK(Descriptor::AllowVarArgs()); 1351cb0ef41Sopenharmony_ci return; 1361cb0ef41Sopenharmony_ci } 1371cb0ef41Sopenharmony_ci CHECK(MachineTypeMatches(Descriptor().GetParameterType(i), arg)); 1381cb0ef41Sopenharmony_ci CheckArgsHelper<Descriptor, Args...>::Check(masm, i + 1, args...); 1391cb0ef41Sopenharmony_ci } 1401cb0ef41Sopenharmony_ci}; 1411cb0ef41Sopenharmony_ci 1421cb0ef41Sopenharmony_citemplate <typename Descriptor, typename... Args> 1431cb0ef41Sopenharmony_cistruct CheckArgsHelper<Descriptor, interpreter::RegisterList, Args...> { 1441cb0ef41Sopenharmony_ci static void Check(BaselineAssembler* masm, int i, 1451cb0ef41Sopenharmony_ci interpreter::RegisterList list, Args... args) { 1461cb0ef41Sopenharmony_ci for (int reg_index = 0; reg_index < list.register_count(); 1471cb0ef41Sopenharmony_ci ++reg_index, ++i) { 1481cb0ef41Sopenharmony_ci if (i >= Descriptor::GetParameterCount()) { 1491cb0ef41Sopenharmony_ci CHECK(Descriptor::AllowVarArgs()); 1501cb0ef41Sopenharmony_ci return; 1511cb0ef41Sopenharmony_ci } 1521cb0ef41Sopenharmony_ci CHECK(MachineTypeMatches(Descriptor().GetParameterType(i), 1531cb0ef41Sopenharmony_ci list[reg_index])); 1541cb0ef41Sopenharmony_ci } 1551cb0ef41Sopenharmony_ci CheckArgsHelper<Descriptor, Args...>::Check(masm, i, args...); 1561cb0ef41Sopenharmony_ci } 1571cb0ef41Sopenharmony_ci}; 1581cb0ef41Sopenharmony_ci 1591cb0ef41Sopenharmony_citemplate <typename Descriptor, typename... Args> 1601cb0ef41Sopenharmony_civoid CheckArgs(BaselineAssembler* masm, Args... args) { 1611cb0ef41Sopenharmony_ci CheckArgsHelper<Descriptor, Args...>::Check(masm, 0, args...); 1621cb0ef41Sopenharmony_ci} 1631cb0ef41Sopenharmony_ci 1641cb0ef41Sopenharmony_civoid CheckSettingDoesntClobber(Register target) {} 1651cb0ef41Sopenharmony_citemplate <typename Arg, typename... Args> 1661cb0ef41Sopenharmony_civoid CheckSettingDoesntClobber(Register target, Arg arg, Args... args) { 1671cb0ef41Sopenharmony_ci DCHECK(!Clobbers(target, arg)); 1681cb0ef41Sopenharmony_ci CheckSettingDoesntClobber(target, args...); 1691cb0ef41Sopenharmony_ci} 1701cb0ef41Sopenharmony_ci 1711cb0ef41Sopenharmony_ci#else // DEBUG 1721cb0ef41Sopenharmony_ci 1731cb0ef41Sopenharmony_citemplate <typename Descriptor, typename... Args> 1741cb0ef41Sopenharmony_civoid CheckArgs(Args... args) {} 1751cb0ef41Sopenharmony_ci 1761cb0ef41Sopenharmony_citemplate <typename... Args> 1771cb0ef41Sopenharmony_civoid CheckSettingDoesntClobber(Register target, Args... args) {} 1781cb0ef41Sopenharmony_ci 1791cb0ef41Sopenharmony_ci#endif // DEBUG 1801cb0ef41Sopenharmony_ci 1811cb0ef41Sopenharmony_citemplate <typename Descriptor, int ArgIndex, bool kIsRegister, typename... Args> 1821cb0ef41Sopenharmony_cistruct ArgumentSettingHelper; 1831cb0ef41Sopenharmony_ci 1841cb0ef41Sopenharmony_citemplate <typename Descriptor, int ArgIndex, bool kIsRegister> 1851cb0ef41Sopenharmony_cistruct ArgumentSettingHelper<Descriptor, ArgIndex, kIsRegister> { 1861cb0ef41Sopenharmony_ci static void Set(BaselineAssembler* masm) { 1871cb0ef41Sopenharmony_ci // Should only ever be called for the end of register arguments. 1881cb0ef41Sopenharmony_ci STATIC_ASSERT(ArgIndex == Descriptor::GetRegisterParameterCount()); 1891cb0ef41Sopenharmony_ci } 1901cb0ef41Sopenharmony_ci}; 1911cb0ef41Sopenharmony_ci 1921cb0ef41Sopenharmony_citemplate <typename Descriptor, int ArgIndex, typename Arg, typename... Args> 1931cb0ef41Sopenharmony_cistruct ArgumentSettingHelper<Descriptor, ArgIndex, true, Arg, Args...> { 1941cb0ef41Sopenharmony_ci static void Set(BaselineAssembler* masm, Arg arg, Args... args) { 1951cb0ef41Sopenharmony_ci STATIC_ASSERT(ArgIndex < Descriptor::GetRegisterParameterCount()); 1961cb0ef41Sopenharmony_ci Register target = Descriptor::GetRegisterParameter(ArgIndex); 1971cb0ef41Sopenharmony_ci CheckSettingDoesntClobber(target, args...); 1981cb0ef41Sopenharmony_ci masm->Move(target, arg); 1991cb0ef41Sopenharmony_ci ArgumentSettingHelper<Descriptor, ArgIndex + 1, 2001cb0ef41Sopenharmony_ci (ArgIndex + 1 < 2011cb0ef41Sopenharmony_ci Descriptor::GetRegisterParameterCount()), 2021cb0ef41Sopenharmony_ci Args...>::Set(masm, args...); 2031cb0ef41Sopenharmony_ci } 2041cb0ef41Sopenharmony_ci}; 2051cb0ef41Sopenharmony_ci 2061cb0ef41Sopenharmony_citemplate <typename Descriptor, int ArgIndex> 2071cb0ef41Sopenharmony_cistruct ArgumentSettingHelper<Descriptor, ArgIndex, true, 2081cb0ef41Sopenharmony_ci interpreter::RegisterList> { 2091cb0ef41Sopenharmony_ci static void Set(BaselineAssembler* masm, interpreter::RegisterList list) { 2101cb0ef41Sopenharmony_ci STATIC_ASSERT(ArgIndex < Descriptor::GetRegisterParameterCount()); 2111cb0ef41Sopenharmony_ci DCHECK_EQ(ArgIndex + list.register_count(), 2121cb0ef41Sopenharmony_ci Descriptor::GetRegisterParameterCount()); 2131cb0ef41Sopenharmony_ci for (int i = 0; ArgIndex + i < Descriptor::GetRegisterParameterCount(); 2141cb0ef41Sopenharmony_ci ++i) { 2151cb0ef41Sopenharmony_ci Register target = Descriptor::GetRegisterParameter(ArgIndex + i); 2161cb0ef41Sopenharmony_ci masm->Move(target, masm->RegisterFrameOperand(list[i])); 2171cb0ef41Sopenharmony_ci } 2181cb0ef41Sopenharmony_ci } 2191cb0ef41Sopenharmony_ci}; 2201cb0ef41Sopenharmony_ci 2211cb0ef41Sopenharmony_citemplate <typename Descriptor, int ArgIndex, typename Arg, typename... Args> 2221cb0ef41Sopenharmony_cistruct ArgumentSettingHelper<Descriptor, ArgIndex, false, Arg, Args...> { 2231cb0ef41Sopenharmony_ci static void Set(BaselineAssembler* masm, Arg arg, Args... args) { 2241cb0ef41Sopenharmony_ci if (Descriptor::kStackArgumentOrder == StackArgumentOrder::kDefault) { 2251cb0ef41Sopenharmony_ci masm->Push(arg, args...); 2261cb0ef41Sopenharmony_ci } else { 2271cb0ef41Sopenharmony_ci masm->PushReverse(arg, args...); 2281cb0ef41Sopenharmony_ci } 2291cb0ef41Sopenharmony_ci } 2301cb0ef41Sopenharmony_ci}; 2311cb0ef41Sopenharmony_ci 2321cb0ef41Sopenharmony_citemplate <Builtin kBuiltin, typename... Args> 2331cb0ef41Sopenharmony_civoid MoveArgumentsForBuiltin(BaselineAssembler* masm, Args... args) { 2341cb0ef41Sopenharmony_ci using Descriptor = typename CallInterfaceDescriptorFor<kBuiltin>::type; 2351cb0ef41Sopenharmony_ci CheckArgs<Descriptor>(masm, args...); 2361cb0ef41Sopenharmony_ci ArgumentSettingHelper<Descriptor, 0, 2371cb0ef41Sopenharmony_ci (0 < Descriptor::GetRegisterParameterCount()), 2381cb0ef41Sopenharmony_ci Args...>::Set(masm, args...); 2391cb0ef41Sopenharmony_ci if (Descriptor::HasContextParameter()) { 2401cb0ef41Sopenharmony_ci masm->LoadContext(Descriptor::ContextRegister()); 2411cb0ef41Sopenharmony_ci } 2421cb0ef41Sopenharmony_ci} 2431cb0ef41Sopenharmony_ci 2441cb0ef41Sopenharmony_ci} // namespace detail 2451cb0ef41Sopenharmony_ci 2461cb0ef41Sopenharmony_cinamespace { 2471cb0ef41Sopenharmony_ci// Rough upper-bound estimate. Copying the data is most likely more expensive 2481cb0ef41Sopenharmony_ci// than pre-allocating a large enough buffer. 2491cb0ef41Sopenharmony_ci#ifdef V8_TARGET_ARCH_IA32 2501cb0ef41Sopenharmony_ciconst int kAverageBytecodeToInstructionRatio = 5; 2511cb0ef41Sopenharmony_ci#else 2521cb0ef41Sopenharmony_ciconst int kAverageBytecodeToInstructionRatio = 7; 2531cb0ef41Sopenharmony_ci#endif 2541cb0ef41Sopenharmony_cistd::unique_ptr<AssemblerBuffer> AllocateBuffer( 2551cb0ef41Sopenharmony_ci Handle<BytecodeArray> bytecodes) { 2561cb0ef41Sopenharmony_ci int estimated_size; 2571cb0ef41Sopenharmony_ci { 2581cb0ef41Sopenharmony_ci DisallowHeapAllocation no_gc; 2591cb0ef41Sopenharmony_ci estimated_size = BaselineCompiler::EstimateInstructionSize(*bytecodes); 2601cb0ef41Sopenharmony_ci } 2611cb0ef41Sopenharmony_ci return NewAssemblerBuffer(RoundUp(estimated_size, 4 * KB)); 2621cb0ef41Sopenharmony_ci} 2631cb0ef41Sopenharmony_ci} // namespace 2641cb0ef41Sopenharmony_ci 2651cb0ef41Sopenharmony_ciBaselineCompiler::BaselineCompiler( 2661cb0ef41Sopenharmony_ci LocalIsolate* local_isolate, 2671cb0ef41Sopenharmony_ci Handle<SharedFunctionInfo> shared_function_info, 2681cb0ef41Sopenharmony_ci Handle<BytecodeArray> bytecode) 2691cb0ef41Sopenharmony_ci : local_isolate_(local_isolate), 2701cb0ef41Sopenharmony_ci stats_(local_isolate->runtime_call_stats()), 2711cb0ef41Sopenharmony_ci shared_function_info_(shared_function_info), 2721cb0ef41Sopenharmony_ci bytecode_(bytecode), 2731cb0ef41Sopenharmony_ci masm_(local_isolate->GetMainThreadIsolateUnsafe(), 2741cb0ef41Sopenharmony_ci CodeObjectRequired::kNo, AllocateBuffer(bytecode)), 2751cb0ef41Sopenharmony_ci basm_(&masm_), 2761cb0ef41Sopenharmony_ci iterator_(bytecode_), 2771cb0ef41Sopenharmony_ci zone_(local_isolate->allocator(), ZONE_NAME), 2781cb0ef41Sopenharmony_ci labels_(zone_.NewArray<BaselineLabels*>(bytecode_->length())) { 2791cb0ef41Sopenharmony_ci MemsetPointer(labels_, nullptr, bytecode_->length()); 2801cb0ef41Sopenharmony_ci 2811cb0ef41Sopenharmony_ci // Empirically determined expected size of the offset table at the 95th %ile, 2821cb0ef41Sopenharmony_ci // based on the size of the bytecode, to be: 2831cb0ef41Sopenharmony_ci // 2841cb0ef41Sopenharmony_ci // 16 + (bytecode size) / 4 2851cb0ef41Sopenharmony_ci bytecode_offset_table_builder_.Reserve( 2861cb0ef41Sopenharmony_ci base::bits::RoundUpToPowerOfTwo(16 + bytecode_->Size() / 4)); 2871cb0ef41Sopenharmony_ci} 2881cb0ef41Sopenharmony_ci 2891cb0ef41Sopenharmony_ci#define __ basm_. 2901cb0ef41Sopenharmony_ci 2911cb0ef41Sopenharmony_ci#define RCS_BASELINE_SCOPE(rcs) \ 2921cb0ef41Sopenharmony_ci RCS_SCOPE(stats_, \ 2931cb0ef41Sopenharmony_ci local_isolate_->is_main_thread() \ 2941cb0ef41Sopenharmony_ci ? RuntimeCallCounterId::kCompileBaseline##rcs \ 2951cb0ef41Sopenharmony_ci : RuntimeCallCounterId::kCompileBackgroundBaseline##rcs) 2961cb0ef41Sopenharmony_ci 2971cb0ef41Sopenharmony_civoid BaselineCompiler::GenerateCode() { 2981cb0ef41Sopenharmony_ci { 2991cb0ef41Sopenharmony_ci RCS_BASELINE_SCOPE(PreVisit); 3001cb0ef41Sopenharmony_ci for (; !iterator_.done(); iterator_.Advance()) { 3011cb0ef41Sopenharmony_ci PreVisitSingleBytecode(); 3021cb0ef41Sopenharmony_ci } 3031cb0ef41Sopenharmony_ci iterator_.Reset(); 3041cb0ef41Sopenharmony_ci } 3051cb0ef41Sopenharmony_ci 3061cb0ef41Sopenharmony_ci // No code generated yet. 3071cb0ef41Sopenharmony_ci DCHECK_EQ(__ pc_offset(), 0); 3081cb0ef41Sopenharmony_ci __ CodeEntry(); 3091cb0ef41Sopenharmony_ci 3101cb0ef41Sopenharmony_ci { 3111cb0ef41Sopenharmony_ci RCS_BASELINE_SCOPE(Visit); 3121cb0ef41Sopenharmony_ci Prologue(); 3131cb0ef41Sopenharmony_ci AddPosition(); 3141cb0ef41Sopenharmony_ci for (; !iterator_.done(); iterator_.Advance()) { 3151cb0ef41Sopenharmony_ci VisitSingleBytecode(); 3161cb0ef41Sopenharmony_ci AddPosition(); 3171cb0ef41Sopenharmony_ci } 3181cb0ef41Sopenharmony_ci } 3191cb0ef41Sopenharmony_ci} 3201cb0ef41Sopenharmony_ci 3211cb0ef41Sopenharmony_ciMaybeHandle<Code> BaselineCompiler::Build(LocalIsolate* local_isolate) { 3221cb0ef41Sopenharmony_ci CodeDesc desc; 3231cb0ef41Sopenharmony_ci __ GetCode(local_isolate->GetMainThreadIsolateUnsafe(), &desc); 3241cb0ef41Sopenharmony_ci 3251cb0ef41Sopenharmony_ci // Allocate the bytecode offset table. 3261cb0ef41Sopenharmony_ci Handle<ByteArray> bytecode_offset_table = 3271cb0ef41Sopenharmony_ci bytecode_offset_table_builder_.ToBytecodeOffsetTable(local_isolate); 3281cb0ef41Sopenharmony_ci 3291cb0ef41Sopenharmony_ci Factory::CodeBuilder code_builder(local_isolate, desc, CodeKind::BASELINE); 3301cb0ef41Sopenharmony_ci code_builder.set_bytecode_offset_table(bytecode_offset_table); 3311cb0ef41Sopenharmony_ci if (shared_function_info_->HasInterpreterData()) { 3321cb0ef41Sopenharmony_ci code_builder.set_interpreter_data( 3331cb0ef41Sopenharmony_ci handle(shared_function_info_->interpreter_data(), local_isolate)); 3341cb0ef41Sopenharmony_ci } else { 3351cb0ef41Sopenharmony_ci code_builder.set_interpreter_data(bytecode_); 3361cb0ef41Sopenharmony_ci } 3371cb0ef41Sopenharmony_ci return code_builder.TryBuild(); 3381cb0ef41Sopenharmony_ci} 3391cb0ef41Sopenharmony_ci 3401cb0ef41Sopenharmony_ciint BaselineCompiler::EstimateInstructionSize(BytecodeArray bytecode) { 3411cb0ef41Sopenharmony_ci return bytecode.length() * kAverageBytecodeToInstructionRatio; 3421cb0ef41Sopenharmony_ci} 3431cb0ef41Sopenharmony_ci 3441cb0ef41Sopenharmony_ciinterpreter::Register BaselineCompiler::RegisterOperand(int operand_index) { 3451cb0ef41Sopenharmony_ci return iterator().GetRegisterOperand(operand_index); 3461cb0ef41Sopenharmony_ci} 3471cb0ef41Sopenharmony_ci 3481cb0ef41Sopenharmony_civoid BaselineCompiler::LoadRegister(Register output, int operand_index) { 3491cb0ef41Sopenharmony_ci __ LoadRegister(output, RegisterOperand(operand_index)); 3501cb0ef41Sopenharmony_ci} 3511cb0ef41Sopenharmony_ci 3521cb0ef41Sopenharmony_civoid BaselineCompiler::StoreRegister(int operand_index, Register value) { 3531cb0ef41Sopenharmony_ci __ Move(RegisterOperand(operand_index), value); 3541cb0ef41Sopenharmony_ci} 3551cb0ef41Sopenharmony_ci 3561cb0ef41Sopenharmony_civoid BaselineCompiler::StoreRegisterPair(int operand_index, Register val0, 3571cb0ef41Sopenharmony_ci Register val1) { 3581cb0ef41Sopenharmony_ci interpreter::Register reg0, reg1; 3591cb0ef41Sopenharmony_ci std::tie(reg0, reg1) = iterator().GetRegisterPairOperand(operand_index); 3601cb0ef41Sopenharmony_ci __ StoreRegister(reg0, val0); 3611cb0ef41Sopenharmony_ci __ StoreRegister(reg1, val1); 3621cb0ef41Sopenharmony_ci} 3631cb0ef41Sopenharmony_citemplate <typename Type> 3641cb0ef41Sopenharmony_ciHandle<Type> BaselineCompiler::Constant(int operand_index) { 3651cb0ef41Sopenharmony_ci return Handle<Type>::cast( 3661cb0ef41Sopenharmony_ci iterator().GetConstantForIndexOperand(operand_index, local_isolate_)); 3671cb0ef41Sopenharmony_ci} 3681cb0ef41Sopenharmony_ciSmi BaselineCompiler::ConstantSmi(int operand_index) { 3691cb0ef41Sopenharmony_ci return iterator().GetConstantAtIndexAsSmi(operand_index); 3701cb0ef41Sopenharmony_ci} 3711cb0ef41Sopenharmony_citemplate <typename Type> 3721cb0ef41Sopenharmony_civoid BaselineCompiler::LoadConstant(Register output, int operand_index) { 3731cb0ef41Sopenharmony_ci __ Move(output, Constant<Type>(operand_index)); 3741cb0ef41Sopenharmony_ci} 3751cb0ef41Sopenharmony_ciuint32_t BaselineCompiler::Uint(int operand_index) { 3761cb0ef41Sopenharmony_ci return iterator().GetUnsignedImmediateOperand(operand_index); 3771cb0ef41Sopenharmony_ci} 3781cb0ef41Sopenharmony_ciint32_t BaselineCompiler::Int(int operand_index) { 3791cb0ef41Sopenharmony_ci return iterator().GetImmediateOperand(operand_index); 3801cb0ef41Sopenharmony_ci} 3811cb0ef41Sopenharmony_ciuint32_t BaselineCompiler::Index(int operand_index) { 3821cb0ef41Sopenharmony_ci return iterator().GetIndexOperand(operand_index); 3831cb0ef41Sopenharmony_ci} 3841cb0ef41Sopenharmony_ciuint32_t BaselineCompiler::Flag(int operand_index) { 3851cb0ef41Sopenharmony_ci return iterator().GetFlagOperand(operand_index); 3861cb0ef41Sopenharmony_ci} 3871cb0ef41Sopenharmony_ciuint32_t BaselineCompiler::RegisterCount(int operand_index) { 3881cb0ef41Sopenharmony_ci return iterator().GetRegisterCountOperand(operand_index); 3891cb0ef41Sopenharmony_ci} 3901cb0ef41Sopenharmony_ciTaggedIndex BaselineCompiler::IndexAsTagged(int operand_index) { 3911cb0ef41Sopenharmony_ci return TaggedIndex::FromIntptr(Index(operand_index)); 3921cb0ef41Sopenharmony_ci} 3931cb0ef41Sopenharmony_ciTaggedIndex BaselineCompiler::UintAsTagged(int operand_index) { 3941cb0ef41Sopenharmony_ci return TaggedIndex::FromIntptr(Uint(operand_index)); 3951cb0ef41Sopenharmony_ci} 3961cb0ef41Sopenharmony_ciSmi BaselineCompiler::IndexAsSmi(int operand_index) { 3971cb0ef41Sopenharmony_ci return Smi::FromInt(Index(operand_index)); 3981cb0ef41Sopenharmony_ci} 3991cb0ef41Sopenharmony_ciSmi BaselineCompiler::IntAsSmi(int operand_index) { 4001cb0ef41Sopenharmony_ci return Smi::FromInt(Int(operand_index)); 4011cb0ef41Sopenharmony_ci} 4021cb0ef41Sopenharmony_ciSmi BaselineCompiler::FlagAsSmi(int operand_index) { 4031cb0ef41Sopenharmony_ci return Smi::FromInt(Flag(operand_index)); 4041cb0ef41Sopenharmony_ci} 4051cb0ef41Sopenharmony_ci 4061cb0ef41Sopenharmony_ciMemOperand BaselineCompiler::FeedbackVector() { 4071cb0ef41Sopenharmony_ci return __ FeedbackVectorOperand(); 4081cb0ef41Sopenharmony_ci} 4091cb0ef41Sopenharmony_ci 4101cb0ef41Sopenharmony_civoid BaselineCompiler::LoadFeedbackVector(Register output) { 4111cb0ef41Sopenharmony_ci ASM_CODE_COMMENT(&masm_); 4121cb0ef41Sopenharmony_ci __ Move(output, __ FeedbackVectorOperand()); 4131cb0ef41Sopenharmony_ci} 4141cb0ef41Sopenharmony_ci 4151cb0ef41Sopenharmony_civoid BaselineCompiler::LoadClosureFeedbackArray(Register output) { 4161cb0ef41Sopenharmony_ci LoadFeedbackVector(output); 4171cb0ef41Sopenharmony_ci __ LoadTaggedPointerField(output, output, 4181cb0ef41Sopenharmony_ci FeedbackVector::kClosureFeedbackCellArrayOffset); 4191cb0ef41Sopenharmony_ci} 4201cb0ef41Sopenharmony_ci 4211cb0ef41Sopenharmony_civoid BaselineCompiler::SelectBooleanConstant( 4221cb0ef41Sopenharmony_ci Register output, std::function<void(Label*, Label::Distance)> jump_func) { 4231cb0ef41Sopenharmony_ci Label done, set_true; 4241cb0ef41Sopenharmony_ci jump_func(&set_true, Label::kNear); 4251cb0ef41Sopenharmony_ci __ LoadRoot(output, RootIndex::kFalseValue); 4261cb0ef41Sopenharmony_ci __ Jump(&done, Label::kNear); 4271cb0ef41Sopenharmony_ci __ Bind(&set_true); 4281cb0ef41Sopenharmony_ci __ LoadRoot(output, RootIndex::kTrueValue); 4291cb0ef41Sopenharmony_ci __ Bind(&done); 4301cb0ef41Sopenharmony_ci} 4311cb0ef41Sopenharmony_ci 4321cb0ef41Sopenharmony_civoid BaselineCompiler::AddPosition() { 4331cb0ef41Sopenharmony_ci bytecode_offset_table_builder_.AddPosition(__ pc_offset()); 4341cb0ef41Sopenharmony_ci} 4351cb0ef41Sopenharmony_ci 4361cb0ef41Sopenharmony_civoid BaselineCompiler::PreVisitSingleBytecode() { 4371cb0ef41Sopenharmony_ci switch (iterator().current_bytecode()) { 4381cb0ef41Sopenharmony_ci case interpreter::Bytecode::kJumpLoop: 4391cb0ef41Sopenharmony_ci EnsureLabels(iterator().GetJumpTargetOffset()); 4401cb0ef41Sopenharmony_ci break; 4411cb0ef41Sopenharmony_ci 4421cb0ef41Sopenharmony_ci // TODO(leszeks): Update the max_call_args as part of the main bytecode 4431cb0ef41Sopenharmony_ci // visit loop, by patching the value passed to the prologue. 4441cb0ef41Sopenharmony_ci case interpreter::Bytecode::kCallProperty: 4451cb0ef41Sopenharmony_ci case interpreter::Bytecode::kCallAnyReceiver: 4461cb0ef41Sopenharmony_ci case interpreter::Bytecode::kCallWithSpread: 4471cb0ef41Sopenharmony_ci case interpreter::Bytecode::kConstruct: 4481cb0ef41Sopenharmony_ci case interpreter::Bytecode::kConstructWithSpread: 4491cb0ef41Sopenharmony_ci return UpdateMaxCallArgs( 4501cb0ef41Sopenharmony_ci iterator().GetRegisterListOperand(1).register_count()); 4511cb0ef41Sopenharmony_ci case interpreter::Bytecode::kCallUndefinedReceiver: 4521cb0ef41Sopenharmony_ci return UpdateMaxCallArgs( 4531cb0ef41Sopenharmony_ci iterator().GetRegisterListOperand(1).register_count() + 1); 4541cb0ef41Sopenharmony_ci case interpreter::Bytecode::kCallProperty0: 4551cb0ef41Sopenharmony_ci case interpreter::Bytecode::kCallUndefinedReceiver0: 4561cb0ef41Sopenharmony_ci return UpdateMaxCallArgs(1); 4571cb0ef41Sopenharmony_ci case interpreter::Bytecode::kCallProperty1: 4581cb0ef41Sopenharmony_ci case interpreter::Bytecode::kCallUndefinedReceiver1: 4591cb0ef41Sopenharmony_ci return UpdateMaxCallArgs(2); 4601cb0ef41Sopenharmony_ci case interpreter::Bytecode::kCallProperty2: 4611cb0ef41Sopenharmony_ci case interpreter::Bytecode::kCallUndefinedReceiver2: 4621cb0ef41Sopenharmony_ci return UpdateMaxCallArgs(3); 4631cb0ef41Sopenharmony_ci 4641cb0ef41Sopenharmony_ci default: 4651cb0ef41Sopenharmony_ci break; 4661cb0ef41Sopenharmony_ci } 4671cb0ef41Sopenharmony_ci} 4681cb0ef41Sopenharmony_ci 4691cb0ef41Sopenharmony_civoid BaselineCompiler::VisitSingleBytecode() { 4701cb0ef41Sopenharmony_ci int offset = iterator().current_offset(); 4711cb0ef41Sopenharmony_ci if (labels_[offset]) { 4721cb0ef41Sopenharmony_ci // Bind labels for this offset that have already been linked to a 4731cb0ef41Sopenharmony_ci // jump (i.e. forward jumps, excluding jump tables). 4741cb0ef41Sopenharmony_ci for (auto&& label : labels_[offset]->linked) { 4751cb0ef41Sopenharmony_ci __ BindWithoutJumpTarget(&label->label); 4761cb0ef41Sopenharmony_ci } 4771cb0ef41Sopenharmony_ci#ifdef DEBUG 4781cb0ef41Sopenharmony_ci labels_[offset]->linked.Clear(); 4791cb0ef41Sopenharmony_ci#endif 4801cb0ef41Sopenharmony_ci __ BindWithoutJumpTarget(&labels_[offset]->unlinked); 4811cb0ef41Sopenharmony_ci } 4821cb0ef41Sopenharmony_ci 4831cb0ef41Sopenharmony_ci // Mark position as valid jump target. This is required for the deoptimizer 4841cb0ef41Sopenharmony_ci // and exception handling, when CFI is enabled. 4851cb0ef41Sopenharmony_ci __ JumpTarget(); 4861cb0ef41Sopenharmony_ci 4871cb0ef41Sopenharmony_ci#ifdef V8_CODE_COMMENTS 4881cb0ef41Sopenharmony_ci std::ostringstream str; 4891cb0ef41Sopenharmony_ci if (FLAG_code_comments) { 4901cb0ef41Sopenharmony_ci iterator().PrintTo(str); 4911cb0ef41Sopenharmony_ci } 4921cb0ef41Sopenharmony_ci ASM_CODE_COMMENT_STRING(&masm_, str.str()); 4931cb0ef41Sopenharmony_ci#endif 4941cb0ef41Sopenharmony_ci 4951cb0ef41Sopenharmony_ci VerifyFrame(); 4961cb0ef41Sopenharmony_ci 4971cb0ef41Sopenharmony_ci#ifdef V8_TRACE_UNOPTIMIZED 4981cb0ef41Sopenharmony_ci TraceBytecode(Runtime::kTraceUnoptimizedBytecodeEntry); 4991cb0ef41Sopenharmony_ci#endif 5001cb0ef41Sopenharmony_ci 5011cb0ef41Sopenharmony_ci { 5021cb0ef41Sopenharmony_ci interpreter::Bytecode bytecode = iterator().current_bytecode(); 5031cb0ef41Sopenharmony_ci 5041cb0ef41Sopenharmony_ci#ifdef DEBUG 5051cb0ef41Sopenharmony_ci base::Optional<EnsureAccumulatorPreservedScope> accumulator_preserved_scope; 5061cb0ef41Sopenharmony_ci // We should make sure to preserve the accumulator whenever the bytecode 5071cb0ef41Sopenharmony_ci // isn't registered as writing to it. We can't do this for jumps or switches 5081cb0ef41Sopenharmony_ci // though, since the control flow would not match the control flow of this 5091cb0ef41Sopenharmony_ci // scope. 5101cb0ef41Sopenharmony_ci if (FLAG_debug_code && 5111cb0ef41Sopenharmony_ci !interpreter::Bytecodes::WritesAccumulator(bytecode) && 5121cb0ef41Sopenharmony_ci !interpreter::Bytecodes::IsJump(bytecode) && 5131cb0ef41Sopenharmony_ci !interpreter::Bytecodes::IsSwitch(bytecode)) { 5141cb0ef41Sopenharmony_ci accumulator_preserved_scope.emplace(&basm_); 5151cb0ef41Sopenharmony_ci } 5161cb0ef41Sopenharmony_ci#endif // DEBUG 5171cb0ef41Sopenharmony_ci 5181cb0ef41Sopenharmony_ci switch (bytecode) { 5191cb0ef41Sopenharmony_ci#define BYTECODE_CASE(name, ...) \ 5201cb0ef41Sopenharmony_ci case interpreter::Bytecode::k##name: \ 5211cb0ef41Sopenharmony_ci Visit##name(); \ 5221cb0ef41Sopenharmony_ci break; 5231cb0ef41Sopenharmony_ci BYTECODE_LIST(BYTECODE_CASE) 5241cb0ef41Sopenharmony_ci#undef BYTECODE_CASE 5251cb0ef41Sopenharmony_ci } 5261cb0ef41Sopenharmony_ci } 5271cb0ef41Sopenharmony_ci 5281cb0ef41Sopenharmony_ci#ifdef V8_TRACE_UNOPTIMIZED 5291cb0ef41Sopenharmony_ci TraceBytecode(Runtime::kTraceUnoptimizedBytecodeExit); 5301cb0ef41Sopenharmony_ci#endif 5311cb0ef41Sopenharmony_ci} 5321cb0ef41Sopenharmony_ci 5331cb0ef41Sopenharmony_civoid BaselineCompiler::VerifyFrame() { 5341cb0ef41Sopenharmony_ci if (FLAG_debug_code) { 5351cb0ef41Sopenharmony_ci ASM_CODE_COMMENT(&masm_); 5361cb0ef41Sopenharmony_ci __ RecordComment(" -- Verify frame size"); 5371cb0ef41Sopenharmony_ci VerifyFrameSize(); 5381cb0ef41Sopenharmony_ci 5391cb0ef41Sopenharmony_ci __ RecordComment(" -- Verify feedback vector"); 5401cb0ef41Sopenharmony_ci { 5411cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope temps(&basm_); 5421cb0ef41Sopenharmony_ci Register scratch = temps.AcquireScratch(); 5431cb0ef41Sopenharmony_ci __ Move(scratch, __ FeedbackVectorOperand()); 5441cb0ef41Sopenharmony_ci Label is_smi, is_ok; 5451cb0ef41Sopenharmony_ci __ JumpIfSmi(scratch, &is_smi); 5461cb0ef41Sopenharmony_ci __ JumpIfObjectType(Condition::kEqual, scratch, FEEDBACK_VECTOR_TYPE, 5471cb0ef41Sopenharmony_ci scratch, &is_ok); 5481cb0ef41Sopenharmony_ci __ Bind(&is_smi); 5491cb0ef41Sopenharmony_ci __ masm()->Abort(AbortReason::kExpectedFeedbackVector); 5501cb0ef41Sopenharmony_ci __ Bind(&is_ok); 5511cb0ef41Sopenharmony_ci } 5521cb0ef41Sopenharmony_ci 5531cb0ef41Sopenharmony_ci // TODO(leszeks): More verification. 5541cb0ef41Sopenharmony_ci } 5551cb0ef41Sopenharmony_ci} 5561cb0ef41Sopenharmony_ci 5571cb0ef41Sopenharmony_ci#ifdef V8_TRACE_UNOPTIMIZED 5581cb0ef41Sopenharmony_civoid BaselineCompiler::TraceBytecode(Runtime::FunctionId function_id) { 5591cb0ef41Sopenharmony_ci if (!FLAG_trace_baseline_exec) return; 5601cb0ef41Sopenharmony_ci ASM_CODE_COMMENT_STRING(&masm_, 5611cb0ef41Sopenharmony_ci function_id == Runtime::kTraceUnoptimizedBytecodeEntry 5621cb0ef41Sopenharmony_ci ? "Trace bytecode entry" 5631cb0ef41Sopenharmony_ci : "Trace bytecode exit"); 5641cb0ef41Sopenharmony_ci SaveAccumulatorScope accumulator_scope(&basm_); 5651cb0ef41Sopenharmony_ci CallRuntime(function_id, bytecode_, 5661cb0ef41Sopenharmony_ci Smi::FromInt(BytecodeArray::kHeaderSize - kHeapObjectTag + 5671cb0ef41Sopenharmony_ci iterator().current_offset()), 5681cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister); 5691cb0ef41Sopenharmony_ci} 5701cb0ef41Sopenharmony_ci#endif 5711cb0ef41Sopenharmony_ci 5721cb0ef41Sopenharmony_ci#define DECLARE_VISITOR(name, ...) void Visit##name(); 5731cb0ef41Sopenharmony_ciBYTECODE_LIST(DECLARE_VISITOR) 5741cb0ef41Sopenharmony_ci#undef DECLARE_VISITOR 5751cb0ef41Sopenharmony_ci 5761cb0ef41Sopenharmony_ci#define DECLARE_VISITOR(name, ...) \ 5771cb0ef41Sopenharmony_ci void VisitIntrinsic##name(interpreter::RegisterList args); 5781cb0ef41Sopenharmony_ciINTRINSICS_LIST(DECLARE_VISITOR) 5791cb0ef41Sopenharmony_ci#undef DECLARE_VISITOR 5801cb0ef41Sopenharmony_ci 5811cb0ef41Sopenharmony_civoid BaselineCompiler::UpdateInterruptBudgetAndJumpToLabel( 5821cb0ef41Sopenharmony_ci int weight, Label* label, Label* skip_interrupt_label) { 5831cb0ef41Sopenharmony_ci if (weight != 0) { 5841cb0ef41Sopenharmony_ci ASM_CODE_COMMENT(&masm_); 5851cb0ef41Sopenharmony_ci __ AddToInterruptBudgetAndJumpIfNotExceeded(weight, skip_interrupt_label); 5861cb0ef41Sopenharmony_ci 5871cb0ef41Sopenharmony_ci if (weight < 0) { 5881cb0ef41Sopenharmony_ci SaveAccumulatorScope accumulator_scope(&basm_); 5891cb0ef41Sopenharmony_ci CallRuntime(Runtime::kBytecodeBudgetInterruptWithStackCheck, 5901cb0ef41Sopenharmony_ci __ FunctionOperand()); 5911cb0ef41Sopenharmony_ci } 5921cb0ef41Sopenharmony_ci } 5931cb0ef41Sopenharmony_ci if (label) __ Jump(label); 5941cb0ef41Sopenharmony_ci} 5951cb0ef41Sopenharmony_ci 5961cb0ef41Sopenharmony_civoid BaselineCompiler::UpdateInterruptBudgetAndDoInterpreterJump() { 5971cb0ef41Sopenharmony_ci int weight = iterator().GetRelativeJumpTargetOffset() - 5981cb0ef41Sopenharmony_ci iterator().current_bytecode_size_without_prefix(); 5991cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndJumpToLabel(weight, BuildForwardJumpLabel(), nullptr); 6001cb0ef41Sopenharmony_ci} 6011cb0ef41Sopenharmony_ci 6021cb0ef41Sopenharmony_civoid BaselineCompiler::UpdateInterruptBudgetAndDoInterpreterJumpIfRoot( 6031cb0ef41Sopenharmony_ci RootIndex root) { 6041cb0ef41Sopenharmony_ci Label dont_jump; 6051cb0ef41Sopenharmony_ci __ JumpIfNotRoot(kInterpreterAccumulatorRegister, root, &dont_jump, 6061cb0ef41Sopenharmony_ci Label::kNear); 6071cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJump(); 6081cb0ef41Sopenharmony_ci __ Bind(&dont_jump); 6091cb0ef41Sopenharmony_ci} 6101cb0ef41Sopenharmony_ci 6111cb0ef41Sopenharmony_civoid BaselineCompiler::UpdateInterruptBudgetAndDoInterpreterJumpIfNotRoot( 6121cb0ef41Sopenharmony_ci RootIndex root) { 6131cb0ef41Sopenharmony_ci Label dont_jump; 6141cb0ef41Sopenharmony_ci __ JumpIfRoot(kInterpreterAccumulatorRegister, root, &dont_jump, 6151cb0ef41Sopenharmony_ci Label::kNear); 6161cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJump(); 6171cb0ef41Sopenharmony_ci __ Bind(&dont_jump); 6181cb0ef41Sopenharmony_ci} 6191cb0ef41Sopenharmony_ci 6201cb0ef41Sopenharmony_ciLabel* BaselineCompiler::BuildForwardJumpLabel() { 6211cb0ef41Sopenharmony_ci int target_offset = iterator().GetJumpTargetOffset(); 6221cb0ef41Sopenharmony_ci ThreadedLabel* threaded_label = zone_.New<ThreadedLabel>(); 6231cb0ef41Sopenharmony_ci EnsureLabels(target_offset)->linked.Add(threaded_label); 6241cb0ef41Sopenharmony_ci return &threaded_label->label; 6251cb0ef41Sopenharmony_ci} 6261cb0ef41Sopenharmony_ci 6271cb0ef41Sopenharmony_citemplate <Builtin kBuiltin, typename... Args> 6281cb0ef41Sopenharmony_civoid BaselineCompiler::CallBuiltin(Args... args) { 6291cb0ef41Sopenharmony_ci ASM_CODE_COMMENT(&masm_); 6301cb0ef41Sopenharmony_ci detail::MoveArgumentsForBuiltin<kBuiltin>(&basm_, args...); 6311cb0ef41Sopenharmony_ci __ CallBuiltin(kBuiltin); 6321cb0ef41Sopenharmony_ci} 6331cb0ef41Sopenharmony_ci 6341cb0ef41Sopenharmony_citemplate <Builtin kBuiltin, typename... Args> 6351cb0ef41Sopenharmony_civoid BaselineCompiler::TailCallBuiltin(Args... args) { 6361cb0ef41Sopenharmony_ci detail::MoveArgumentsForBuiltin<kBuiltin>(&basm_, args...); 6371cb0ef41Sopenharmony_ci __ TailCallBuiltin(kBuiltin); 6381cb0ef41Sopenharmony_ci} 6391cb0ef41Sopenharmony_ci 6401cb0ef41Sopenharmony_citemplate <typename... Args> 6411cb0ef41Sopenharmony_civoid BaselineCompiler::CallRuntime(Runtime::FunctionId function, Args... args) { 6421cb0ef41Sopenharmony_ci __ LoadContext(kContextRegister); 6431cb0ef41Sopenharmony_ci int nargs = __ Push(args...); 6441cb0ef41Sopenharmony_ci __ CallRuntime(function, nargs); 6451cb0ef41Sopenharmony_ci} 6461cb0ef41Sopenharmony_ci 6471cb0ef41Sopenharmony_ci// Returns into kInterpreterAccumulatorRegister 6481cb0ef41Sopenharmony_civoid BaselineCompiler::JumpIfToBoolean(bool do_jump_if_true, Label* label, 6491cb0ef41Sopenharmony_ci Label::Distance distance) { 6501cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kToBooleanForBaselineJump>( 6511cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister); 6521cb0ef41Sopenharmony_ci // ToBooleanForBaselineJump returns the ToBoolean value into return reg 1, and 6531cb0ef41Sopenharmony_ci // the original value into kInterpreterAccumulatorRegister, so we don't have 6541cb0ef41Sopenharmony_ci // to worry about it getting clobbered. 6551cb0ef41Sopenharmony_ci STATIC_ASSERT(kReturnRegister0 == kInterpreterAccumulatorRegister); 6561cb0ef41Sopenharmony_ci __ JumpIfSmi(do_jump_if_true ? Condition::kNotEqual : Condition::kEqual, 6571cb0ef41Sopenharmony_ci kReturnRegister1, Smi::FromInt(0), label, distance); 6581cb0ef41Sopenharmony_ci} 6591cb0ef41Sopenharmony_ci 6601cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaZero() { 6611cb0ef41Sopenharmony_ci __ Move(kInterpreterAccumulatorRegister, Smi::FromInt(0)); 6621cb0ef41Sopenharmony_ci} 6631cb0ef41Sopenharmony_ci 6641cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaSmi() { 6651cb0ef41Sopenharmony_ci Smi constant = Smi::FromInt(iterator().GetImmediateOperand(0)); 6661cb0ef41Sopenharmony_ci __ Move(kInterpreterAccumulatorRegister, constant); 6671cb0ef41Sopenharmony_ci} 6681cb0ef41Sopenharmony_ci 6691cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaUndefined() { 6701cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kUndefinedValue); 6711cb0ef41Sopenharmony_ci} 6721cb0ef41Sopenharmony_ci 6731cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaNull() { 6741cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kNullValue); 6751cb0ef41Sopenharmony_ci} 6761cb0ef41Sopenharmony_ci 6771cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaTheHole() { 6781cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTheHoleValue); 6791cb0ef41Sopenharmony_ci} 6801cb0ef41Sopenharmony_ci 6811cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaTrue() { 6821cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue); 6831cb0ef41Sopenharmony_ci} 6841cb0ef41Sopenharmony_ci 6851cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaFalse() { 6861cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue); 6871cb0ef41Sopenharmony_ci} 6881cb0ef41Sopenharmony_ci 6891cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaConstant() { 6901cb0ef41Sopenharmony_ci LoadConstant<HeapObject>(kInterpreterAccumulatorRegister, 0); 6911cb0ef41Sopenharmony_ci} 6921cb0ef41Sopenharmony_ci 6931cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaGlobal() { 6941cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kLoadGlobalICBaseline>(Constant<Name>(0), // name 6951cb0ef41Sopenharmony_ci IndexAsTagged(1)); // slot 6961cb0ef41Sopenharmony_ci} 6971cb0ef41Sopenharmony_ci 6981cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaGlobalInsideTypeof() { 6991cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kLoadGlobalICInsideTypeofBaseline>( 7001cb0ef41Sopenharmony_ci Constant<Name>(0), // name 7011cb0ef41Sopenharmony_ci IndexAsTagged(1)); // slot 7021cb0ef41Sopenharmony_ci} 7031cb0ef41Sopenharmony_ci 7041cb0ef41Sopenharmony_civoid BaselineCompiler::VisitStaGlobal() { 7051cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kStoreGlobalICBaseline>( 7061cb0ef41Sopenharmony_ci Constant<Name>(0), // name 7071cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // value 7081cb0ef41Sopenharmony_ci IndexAsTagged(1)); // slot 7091cb0ef41Sopenharmony_ci} 7101cb0ef41Sopenharmony_ci 7111cb0ef41Sopenharmony_civoid BaselineCompiler::VisitPushContext() { 7121cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 7131cb0ef41Sopenharmony_ci Register context = scratch_scope.AcquireScratch(); 7141cb0ef41Sopenharmony_ci __ LoadContext(context); 7151cb0ef41Sopenharmony_ci __ StoreContext(kInterpreterAccumulatorRegister); 7161cb0ef41Sopenharmony_ci StoreRegister(0, context); 7171cb0ef41Sopenharmony_ci} 7181cb0ef41Sopenharmony_ci 7191cb0ef41Sopenharmony_civoid BaselineCompiler::VisitPopContext() { 7201cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 7211cb0ef41Sopenharmony_ci Register context = scratch_scope.AcquireScratch(); 7221cb0ef41Sopenharmony_ci LoadRegister(context, 0); 7231cb0ef41Sopenharmony_ci __ StoreContext(context); 7241cb0ef41Sopenharmony_ci} 7251cb0ef41Sopenharmony_ci 7261cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaContextSlot() { 7271cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 7281cb0ef41Sopenharmony_ci Register context = scratch_scope.AcquireScratch(); 7291cb0ef41Sopenharmony_ci LoadRegister(context, 0); 7301cb0ef41Sopenharmony_ci int depth = Uint(2); 7311cb0ef41Sopenharmony_ci for (; depth > 0; --depth) { 7321cb0ef41Sopenharmony_ci __ LoadTaggedPointerField(context, context, Context::kPreviousOffset); 7331cb0ef41Sopenharmony_ci } 7341cb0ef41Sopenharmony_ci __ LoadTaggedAnyField(kInterpreterAccumulatorRegister, context, 7351cb0ef41Sopenharmony_ci Context::OffsetOfElementAt(Index(1))); 7361cb0ef41Sopenharmony_ci} 7371cb0ef41Sopenharmony_ci 7381cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaImmutableContextSlot() { VisitLdaContextSlot(); } 7391cb0ef41Sopenharmony_ci 7401cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaCurrentContextSlot() { 7411cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 7421cb0ef41Sopenharmony_ci Register context = scratch_scope.AcquireScratch(); 7431cb0ef41Sopenharmony_ci __ LoadContext(context); 7441cb0ef41Sopenharmony_ci __ LoadTaggedAnyField(kInterpreterAccumulatorRegister, context, 7451cb0ef41Sopenharmony_ci Context::OffsetOfElementAt(Index(0))); 7461cb0ef41Sopenharmony_ci} 7471cb0ef41Sopenharmony_ci 7481cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaImmutableCurrentContextSlot() { 7491cb0ef41Sopenharmony_ci VisitLdaCurrentContextSlot(); 7501cb0ef41Sopenharmony_ci} 7511cb0ef41Sopenharmony_ci 7521cb0ef41Sopenharmony_civoid BaselineCompiler::VisitStaContextSlot() { 7531cb0ef41Sopenharmony_ci Register value = WriteBarrierDescriptor::ValueRegister(); 7541cb0ef41Sopenharmony_ci Register context = WriteBarrierDescriptor::ObjectRegister(); 7551cb0ef41Sopenharmony_ci DCHECK(!AreAliased(value, context, kInterpreterAccumulatorRegister)); 7561cb0ef41Sopenharmony_ci __ Move(value, kInterpreterAccumulatorRegister); 7571cb0ef41Sopenharmony_ci LoadRegister(context, 0); 7581cb0ef41Sopenharmony_ci int depth = Uint(2); 7591cb0ef41Sopenharmony_ci for (; depth > 0; --depth) { 7601cb0ef41Sopenharmony_ci __ LoadTaggedPointerField(context, context, Context::kPreviousOffset); 7611cb0ef41Sopenharmony_ci } 7621cb0ef41Sopenharmony_ci __ StoreTaggedFieldWithWriteBarrier( 7631cb0ef41Sopenharmony_ci context, Context::OffsetOfElementAt(iterator().GetIndexOperand(1)), 7641cb0ef41Sopenharmony_ci value); 7651cb0ef41Sopenharmony_ci} 7661cb0ef41Sopenharmony_ci 7671cb0ef41Sopenharmony_civoid BaselineCompiler::VisitStaCurrentContextSlot() { 7681cb0ef41Sopenharmony_ci Register value = WriteBarrierDescriptor::ValueRegister(); 7691cb0ef41Sopenharmony_ci Register context = WriteBarrierDescriptor::ObjectRegister(); 7701cb0ef41Sopenharmony_ci DCHECK(!AreAliased(value, context, kInterpreterAccumulatorRegister)); 7711cb0ef41Sopenharmony_ci __ Move(value, kInterpreterAccumulatorRegister); 7721cb0ef41Sopenharmony_ci __ LoadContext(context); 7731cb0ef41Sopenharmony_ci __ StoreTaggedFieldWithWriteBarrier( 7741cb0ef41Sopenharmony_ci context, Context::OffsetOfElementAt(Index(0)), value); 7751cb0ef41Sopenharmony_ci} 7761cb0ef41Sopenharmony_ci 7771cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaLookupSlot() { 7781cb0ef41Sopenharmony_ci CallRuntime(Runtime::kLoadLookupSlot, Constant<Name>(0)); 7791cb0ef41Sopenharmony_ci} 7801cb0ef41Sopenharmony_ci 7811cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaLookupContextSlot() { 7821cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kLookupContextBaseline>( 7831cb0ef41Sopenharmony_ci Constant<Name>(0), UintAsTagged(2), IndexAsTagged(1)); 7841cb0ef41Sopenharmony_ci} 7851cb0ef41Sopenharmony_ci 7861cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaLookupGlobalSlot() { 7871cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kLookupGlobalICBaseline>( 7881cb0ef41Sopenharmony_ci Constant<Name>(0), UintAsTagged(2), IndexAsTagged(1)); 7891cb0ef41Sopenharmony_ci} 7901cb0ef41Sopenharmony_ci 7911cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaLookupSlotInsideTypeof() { 7921cb0ef41Sopenharmony_ci CallRuntime(Runtime::kLoadLookupSlotInsideTypeof, Constant<Name>(0)); 7931cb0ef41Sopenharmony_ci} 7941cb0ef41Sopenharmony_ci 7951cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaLookupContextSlotInsideTypeof() { 7961cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kLookupContextInsideTypeofBaseline>( 7971cb0ef41Sopenharmony_ci Constant<Name>(0), UintAsTagged(2), IndexAsTagged(1)); 7981cb0ef41Sopenharmony_ci} 7991cb0ef41Sopenharmony_ci 8001cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaLookupGlobalSlotInsideTypeof() { 8011cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kLookupGlobalICInsideTypeofBaseline>( 8021cb0ef41Sopenharmony_ci Constant<Name>(0), UintAsTagged(2), IndexAsTagged(1)); 8031cb0ef41Sopenharmony_ci} 8041cb0ef41Sopenharmony_ci 8051cb0ef41Sopenharmony_civoid BaselineCompiler::VisitStaLookupSlot() { 8061cb0ef41Sopenharmony_ci uint32_t flags = Flag(1); 8071cb0ef41Sopenharmony_ci Runtime::FunctionId function_id; 8081cb0ef41Sopenharmony_ci if (flags & interpreter::StoreLookupSlotFlags::LanguageModeBit::kMask) { 8091cb0ef41Sopenharmony_ci function_id = Runtime::kStoreLookupSlot_Strict; 8101cb0ef41Sopenharmony_ci } else if (flags & 8111cb0ef41Sopenharmony_ci interpreter::StoreLookupSlotFlags::LookupHoistingModeBit::kMask) { 8121cb0ef41Sopenharmony_ci function_id = Runtime::kStoreLookupSlot_SloppyHoisting; 8131cb0ef41Sopenharmony_ci } else { 8141cb0ef41Sopenharmony_ci function_id = Runtime::kStoreLookupSlot_Sloppy; 8151cb0ef41Sopenharmony_ci } 8161cb0ef41Sopenharmony_ci CallRuntime(function_id, Constant<Name>(0), // name 8171cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister); // value 8181cb0ef41Sopenharmony_ci} 8191cb0ef41Sopenharmony_ci 8201cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdar() { 8211cb0ef41Sopenharmony_ci LoadRegister(kInterpreterAccumulatorRegister, 0); 8221cb0ef41Sopenharmony_ci} 8231cb0ef41Sopenharmony_ci 8241cb0ef41Sopenharmony_civoid BaselineCompiler::VisitStar() { 8251cb0ef41Sopenharmony_ci StoreRegister(0, kInterpreterAccumulatorRegister); 8261cb0ef41Sopenharmony_ci} 8271cb0ef41Sopenharmony_ci 8281cb0ef41Sopenharmony_ci#define SHORT_STAR_VISITOR(Name, ...) \ 8291cb0ef41Sopenharmony_ci void BaselineCompiler::Visit##Name() { \ 8301cb0ef41Sopenharmony_ci __ StoreRegister( \ 8311cb0ef41Sopenharmony_ci interpreter::Register::FromShortStar(interpreter::Bytecode::k##Name), \ 8321cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister); \ 8331cb0ef41Sopenharmony_ci } 8341cb0ef41Sopenharmony_ciSHORT_STAR_BYTECODE_LIST(SHORT_STAR_VISITOR) 8351cb0ef41Sopenharmony_ci#undef SHORT_STAR_VISITOR 8361cb0ef41Sopenharmony_ci 8371cb0ef41Sopenharmony_civoid BaselineCompiler::VisitMov() { 8381cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 8391cb0ef41Sopenharmony_ci Register scratch = scratch_scope.AcquireScratch(); 8401cb0ef41Sopenharmony_ci LoadRegister(scratch, 0); 8411cb0ef41Sopenharmony_ci StoreRegister(1, scratch); 8421cb0ef41Sopenharmony_ci} 8431cb0ef41Sopenharmony_ci 8441cb0ef41Sopenharmony_civoid BaselineCompiler::VisitGetNamedProperty() { 8451cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kLoadICBaseline>(RegisterOperand(0), // object 8461cb0ef41Sopenharmony_ci Constant<Name>(1), // name 8471cb0ef41Sopenharmony_ci IndexAsTagged(2)); // slot 8481cb0ef41Sopenharmony_ci} 8491cb0ef41Sopenharmony_ci 8501cb0ef41Sopenharmony_civoid BaselineCompiler::VisitGetNamedPropertyFromSuper() { 8511cb0ef41Sopenharmony_ci __ LoadPrototype( 8521cb0ef41Sopenharmony_ci LoadWithReceiverAndVectorDescriptor::LookupStartObjectRegister(), 8531cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister); 8541cb0ef41Sopenharmony_ci 8551cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kLoadSuperICBaseline>( 8561cb0ef41Sopenharmony_ci RegisterOperand(0), // object 8571cb0ef41Sopenharmony_ci LoadWithReceiverAndVectorDescriptor:: 8581cb0ef41Sopenharmony_ci LookupStartObjectRegister(), // lookup start 8591cb0ef41Sopenharmony_ci Constant<Name>(1), // name 8601cb0ef41Sopenharmony_ci IndexAsTagged(2)); // slot 8611cb0ef41Sopenharmony_ci} 8621cb0ef41Sopenharmony_ci 8631cb0ef41Sopenharmony_civoid BaselineCompiler::VisitGetKeyedProperty() { 8641cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kKeyedLoadICBaseline>( 8651cb0ef41Sopenharmony_ci RegisterOperand(0), // object 8661cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // key 8671cb0ef41Sopenharmony_ci IndexAsTagged(1)); // slot 8681cb0ef41Sopenharmony_ci} 8691cb0ef41Sopenharmony_ci 8701cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLdaModuleVariable() { 8711cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 8721cb0ef41Sopenharmony_ci Register scratch = scratch_scope.AcquireScratch(); 8731cb0ef41Sopenharmony_ci __ LoadContext(scratch); 8741cb0ef41Sopenharmony_ci int depth = Uint(1); 8751cb0ef41Sopenharmony_ci for (; depth > 0; --depth) { 8761cb0ef41Sopenharmony_ci __ LoadTaggedPointerField(scratch, scratch, Context::kPreviousOffset); 8771cb0ef41Sopenharmony_ci } 8781cb0ef41Sopenharmony_ci __ LoadTaggedPointerField(scratch, scratch, Context::kExtensionOffset); 8791cb0ef41Sopenharmony_ci int cell_index = Int(0); 8801cb0ef41Sopenharmony_ci if (cell_index > 0) { 8811cb0ef41Sopenharmony_ci __ LoadTaggedPointerField(scratch, scratch, 8821cb0ef41Sopenharmony_ci SourceTextModule::kRegularExportsOffset); 8831cb0ef41Sopenharmony_ci // The actual array index is (cell_index - 1). 8841cb0ef41Sopenharmony_ci cell_index -= 1; 8851cb0ef41Sopenharmony_ci } else { 8861cb0ef41Sopenharmony_ci __ LoadTaggedPointerField(scratch, scratch, 8871cb0ef41Sopenharmony_ci SourceTextModule::kRegularImportsOffset); 8881cb0ef41Sopenharmony_ci // The actual array index is (-cell_index - 1). 8891cb0ef41Sopenharmony_ci cell_index = -cell_index - 1; 8901cb0ef41Sopenharmony_ci } 8911cb0ef41Sopenharmony_ci __ LoadFixedArrayElement(scratch, scratch, cell_index); 8921cb0ef41Sopenharmony_ci __ LoadTaggedAnyField(kInterpreterAccumulatorRegister, scratch, 8931cb0ef41Sopenharmony_ci Cell::kValueOffset); 8941cb0ef41Sopenharmony_ci} 8951cb0ef41Sopenharmony_ci 8961cb0ef41Sopenharmony_civoid BaselineCompiler::VisitStaModuleVariable() { 8971cb0ef41Sopenharmony_ci int cell_index = Int(0); 8981cb0ef41Sopenharmony_ci if (V8_UNLIKELY(cell_index < 0)) { 8991cb0ef41Sopenharmony_ci // Not supported (probably never). 9001cb0ef41Sopenharmony_ci CallRuntime(Runtime::kAbort, 9011cb0ef41Sopenharmony_ci Smi::FromInt(static_cast<int>( 9021cb0ef41Sopenharmony_ci AbortReason::kUnsupportedModuleOperation))); 9031cb0ef41Sopenharmony_ci __ Trap(); 9041cb0ef41Sopenharmony_ci } 9051cb0ef41Sopenharmony_ci Register value = WriteBarrierDescriptor::ValueRegister(); 9061cb0ef41Sopenharmony_ci Register scratch = WriteBarrierDescriptor::ObjectRegister(); 9071cb0ef41Sopenharmony_ci DCHECK(!AreAliased(value, scratch, kInterpreterAccumulatorRegister)); 9081cb0ef41Sopenharmony_ci __ Move(value, kInterpreterAccumulatorRegister); 9091cb0ef41Sopenharmony_ci __ LoadContext(scratch); 9101cb0ef41Sopenharmony_ci int depth = Uint(1); 9111cb0ef41Sopenharmony_ci for (; depth > 0; --depth) { 9121cb0ef41Sopenharmony_ci __ LoadTaggedPointerField(scratch, scratch, Context::kPreviousOffset); 9131cb0ef41Sopenharmony_ci } 9141cb0ef41Sopenharmony_ci __ LoadTaggedPointerField(scratch, scratch, Context::kExtensionOffset); 9151cb0ef41Sopenharmony_ci __ LoadTaggedPointerField(scratch, scratch, 9161cb0ef41Sopenharmony_ci SourceTextModule::kRegularExportsOffset); 9171cb0ef41Sopenharmony_ci 9181cb0ef41Sopenharmony_ci // The actual array index is (cell_index - 1). 9191cb0ef41Sopenharmony_ci cell_index -= 1; 9201cb0ef41Sopenharmony_ci __ LoadFixedArrayElement(scratch, scratch, cell_index); 9211cb0ef41Sopenharmony_ci __ StoreTaggedFieldWithWriteBarrier(scratch, Cell::kValueOffset, value); 9221cb0ef41Sopenharmony_ci} 9231cb0ef41Sopenharmony_ci 9241cb0ef41Sopenharmony_civoid BaselineCompiler::VisitSetNamedProperty() { 9251cb0ef41Sopenharmony_ci // StoreIC is currently a base class for multiple property store operations 9261cb0ef41Sopenharmony_ci // and contains mixed logic for named and keyed, set and define operations, 9271cb0ef41Sopenharmony_ci // the paths are controlled by feedback. 9281cb0ef41Sopenharmony_ci // TODO(v8:12548): refactor SetNamedIC as a subclass of StoreIC, which can be 9291cb0ef41Sopenharmony_ci // called here. 9301cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kStoreICBaseline>( 9311cb0ef41Sopenharmony_ci RegisterOperand(0), // object 9321cb0ef41Sopenharmony_ci Constant<Name>(1), // name 9331cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // value 9341cb0ef41Sopenharmony_ci IndexAsTagged(2)); // slot 9351cb0ef41Sopenharmony_ci} 9361cb0ef41Sopenharmony_ci 9371cb0ef41Sopenharmony_civoid BaselineCompiler::VisitDefineNamedOwnProperty() { 9381cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kDefineNamedOwnICBaseline>( 9391cb0ef41Sopenharmony_ci RegisterOperand(0), // object 9401cb0ef41Sopenharmony_ci Constant<Name>(1), // name 9411cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // value 9421cb0ef41Sopenharmony_ci IndexAsTagged(2)); // slot 9431cb0ef41Sopenharmony_ci} 9441cb0ef41Sopenharmony_ci 9451cb0ef41Sopenharmony_civoid BaselineCompiler::VisitSetKeyedProperty() { 9461cb0ef41Sopenharmony_ci // KeyedStoreIC is currently a base class for multiple keyed property store 9471cb0ef41Sopenharmony_ci // operations and contains mixed logic for set and define operations, 9481cb0ef41Sopenharmony_ci // the paths are controlled by feedback. 9491cb0ef41Sopenharmony_ci // TODO(v8:12548): refactor SetKeyedIC as a subclass of KeyedStoreIC, which 9501cb0ef41Sopenharmony_ci // can be called here. 9511cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kKeyedStoreICBaseline>( 9521cb0ef41Sopenharmony_ci RegisterOperand(0), // object 9531cb0ef41Sopenharmony_ci RegisterOperand(1), // key 9541cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // value 9551cb0ef41Sopenharmony_ci IndexAsTagged(2)); // slot 9561cb0ef41Sopenharmony_ci} 9571cb0ef41Sopenharmony_ci 9581cb0ef41Sopenharmony_civoid BaselineCompiler::VisitDefineKeyedOwnProperty() { 9591cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kDefineKeyedOwnICBaseline>( 9601cb0ef41Sopenharmony_ci RegisterOperand(0), // object 9611cb0ef41Sopenharmony_ci RegisterOperand(1), // key 9621cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // value 9631cb0ef41Sopenharmony_ci IndexAsTagged(2)); // slot 9641cb0ef41Sopenharmony_ci} 9651cb0ef41Sopenharmony_ci 9661cb0ef41Sopenharmony_civoid BaselineCompiler::VisitStaInArrayLiteral() { 9671cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kStoreInArrayLiteralICBaseline>( 9681cb0ef41Sopenharmony_ci RegisterOperand(0), // object 9691cb0ef41Sopenharmony_ci RegisterOperand(1), // name 9701cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // value 9711cb0ef41Sopenharmony_ci IndexAsTagged(2)); // slot 9721cb0ef41Sopenharmony_ci} 9731cb0ef41Sopenharmony_ci 9741cb0ef41Sopenharmony_civoid BaselineCompiler::VisitDefineKeyedOwnPropertyInLiteral() { 9751cb0ef41Sopenharmony_ci // Here we should save the accumulator, since 9761cb0ef41Sopenharmony_ci // DefineKeyedOwnPropertyInLiteral doesn't write the accumulator, but 9771cb0ef41Sopenharmony_ci // Runtime::kDefineKeyedOwnPropertyInLiteral returns the value that we got 9781cb0ef41Sopenharmony_ci // from the accumulator so this still works. 9791cb0ef41Sopenharmony_ci CallRuntime(Runtime::kDefineKeyedOwnPropertyInLiteral, 9801cb0ef41Sopenharmony_ci RegisterOperand(0), // object 9811cb0ef41Sopenharmony_ci RegisterOperand(1), // name 9821cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // value 9831cb0ef41Sopenharmony_ci FlagAsSmi(2), // flags 9841cb0ef41Sopenharmony_ci FeedbackVector(), // feedback vector 9851cb0ef41Sopenharmony_ci IndexAsTagged(3)); // slot 9861cb0ef41Sopenharmony_ci} 9871cb0ef41Sopenharmony_ci 9881cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCollectTypeProfile() { 9891cb0ef41Sopenharmony_ci SaveAccumulatorScope accumulator_scope(&basm_); 9901cb0ef41Sopenharmony_ci CallRuntime(Runtime::kCollectTypeProfile, 9911cb0ef41Sopenharmony_ci IntAsSmi(0), // position 9921cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // value 9931cb0ef41Sopenharmony_ci FeedbackVector()); // feedback vector 9941cb0ef41Sopenharmony_ci} 9951cb0ef41Sopenharmony_ci 9961cb0ef41Sopenharmony_civoid BaselineCompiler::VisitAdd() { 9971cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAdd_Baseline>( 9981cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 9991cb0ef41Sopenharmony_ci} 10001cb0ef41Sopenharmony_ci 10011cb0ef41Sopenharmony_civoid BaselineCompiler::VisitSub() { 10021cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kSubtract_Baseline>( 10031cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10041cb0ef41Sopenharmony_ci} 10051cb0ef41Sopenharmony_ci 10061cb0ef41Sopenharmony_civoid BaselineCompiler::VisitMul() { 10071cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kMultiply_Baseline>( 10081cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10091cb0ef41Sopenharmony_ci} 10101cb0ef41Sopenharmony_ci 10111cb0ef41Sopenharmony_civoid BaselineCompiler::VisitDiv() { 10121cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kDivide_Baseline>( 10131cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10141cb0ef41Sopenharmony_ci} 10151cb0ef41Sopenharmony_ci 10161cb0ef41Sopenharmony_civoid BaselineCompiler::VisitMod() { 10171cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kModulus_Baseline>( 10181cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10191cb0ef41Sopenharmony_ci} 10201cb0ef41Sopenharmony_ci 10211cb0ef41Sopenharmony_civoid BaselineCompiler::VisitExp() { 10221cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kExponentiate_Baseline>( 10231cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10241cb0ef41Sopenharmony_ci} 10251cb0ef41Sopenharmony_ci 10261cb0ef41Sopenharmony_civoid BaselineCompiler::VisitBitwiseOr() { 10271cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kBitwiseOr_Baseline>( 10281cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10291cb0ef41Sopenharmony_ci} 10301cb0ef41Sopenharmony_ci 10311cb0ef41Sopenharmony_civoid BaselineCompiler::VisitBitwiseXor() { 10321cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kBitwiseXor_Baseline>( 10331cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10341cb0ef41Sopenharmony_ci} 10351cb0ef41Sopenharmony_ci 10361cb0ef41Sopenharmony_civoid BaselineCompiler::VisitBitwiseAnd() { 10371cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kBitwiseAnd_Baseline>( 10381cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10391cb0ef41Sopenharmony_ci} 10401cb0ef41Sopenharmony_ci 10411cb0ef41Sopenharmony_civoid BaselineCompiler::VisitShiftLeft() { 10421cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kShiftLeft_Baseline>( 10431cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10441cb0ef41Sopenharmony_ci} 10451cb0ef41Sopenharmony_ci 10461cb0ef41Sopenharmony_civoid BaselineCompiler::VisitShiftRight() { 10471cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kShiftRight_Baseline>( 10481cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10491cb0ef41Sopenharmony_ci} 10501cb0ef41Sopenharmony_ci 10511cb0ef41Sopenharmony_civoid BaselineCompiler::VisitShiftRightLogical() { 10521cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kShiftRightLogical_Baseline>( 10531cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 10541cb0ef41Sopenharmony_ci} 10551cb0ef41Sopenharmony_ci 10561cb0ef41Sopenharmony_civoid BaselineCompiler::VisitAddSmi() { 10571cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAddSmi_Baseline>(kInterpreterAccumulatorRegister, 10581cb0ef41Sopenharmony_ci IntAsSmi(0), Index(1)); 10591cb0ef41Sopenharmony_ci} 10601cb0ef41Sopenharmony_ci 10611cb0ef41Sopenharmony_civoid BaselineCompiler::VisitSubSmi() { 10621cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kSubtractSmi_Baseline>(kInterpreterAccumulatorRegister, 10631cb0ef41Sopenharmony_ci IntAsSmi(0), Index(1)); 10641cb0ef41Sopenharmony_ci} 10651cb0ef41Sopenharmony_ci 10661cb0ef41Sopenharmony_civoid BaselineCompiler::VisitMulSmi() { 10671cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kMultiplySmi_Baseline>(kInterpreterAccumulatorRegister, 10681cb0ef41Sopenharmony_ci IntAsSmi(0), Index(1)); 10691cb0ef41Sopenharmony_ci} 10701cb0ef41Sopenharmony_ci 10711cb0ef41Sopenharmony_civoid BaselineCompiler::VisitDivSmi() { 10721cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kDivideSmi_Baseline>(kInterpreterAccumulatorRegister, 10731cb0ef41Sopenharmony_ci IntAsSmi(0), Index(1)); 10741cb0ef41Sopenharmony_ci} 10751cb0ef41Sopenharmony_ci 10761cb0ef41Sopenharmony_civoid BaselineCompiler::VisitModSmi() { 10771cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kModulusSmi_Baseline>(kInterpreterAccumulatorRegister, 10781cb0ef41Sopenharmony_ci IntAsSmi(0), Index(1)); 10791cb0ef41Sopenharmony_ci} 10801cb0ef41Sopenharmony_ci 10811cb0ef41Sopenharmony_civoid BaselineCompiler::VisitExpSmi() { 10821cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kExponentiateSmi_Baseline>( 10831cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, IntAsSmi(0), Index(1)); 10841cb0ef41Sopenharmony_ci} 10851cb0ef41Sopenharmony_ci 10861cb0ef41Sopenharmony_civoid BaselineCompiler::VisitBitwiseOrSmi() { 10871cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kBitwiseOrSmi_Baseline>(kInterpreterAccumulatorRegister, 10881cb0ef41Sopenharmony_ci IntAsSmi(0), Index(1)); 10891cb0ef41Sopenharmony_ci} 10901cb0ef41Sopenharmony_ci 10911cb0ef41Sopenharmony_civoid BaselineCompiler::VisitBitwiseXorSmi() { 10921cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kBitwiseXorSmi_Baseline>(kInterpreterAccumulatorRegister, 10931cb0ef41Sopenharmony_ci IntAsSmi(0), Index(1)); 10941cb0ef41Sopenharmony_ci} 10951cb0ef41Sopenharmony_ci 10961cb0ef41Sopenharmony_civoid BaselineCompiler::VisitBitwiseAndSmi() { 10971cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kBitwiseAndSmi_Baseline>(kInterpreterAccumulatorRegister, 10981cb0ef41Sopenharmony_ci IntAsSmi(0), Index(1)); 10991cb0ef41Sopenharmony_ci} 11001cb0ef41Sopenharmony_ci 11011cb0ef41Sopenharmony_civoid BaselineCompiler::VisitShiftLeftSmi() { 11021cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kShiftLeftSmi_Baseline>(kInterpreterAccumulatorRegister, 11031cb0ef41Sopenharmony_ci IntAsSmi(0), Index(1)); 11041cb0ef41Sopenharmony_ci} 11051cb0ef41Sopenharmony_ci 11061cb0ef41Sopenharmony_civoid BaselineCompiler::VisitShiftRightSmi() { 11071cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kShiftRightSmi_Baseline>(kInterpreterAccumulatorRegister, 11081cb0ef41Sopenharmony_ci IntAsSmi(0), Index(1)); 11091cb0ef41Sopenharmony_ci} 11101cb0ef41Sopenharmony_ci 11111cb0ef41Sopenharmony_civoid BaselineCompiler::VisitShiftRightLogicalSmi() { 11121cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kShiftRightLogicalSmi_Baseline>( 11131cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, IntAsSmi(0), Index(1)); 11141cb0ef41Sopenharmony_ci} 11151cb0ef41Sopenharmony_ci 11161cb0ef41Sopenharmony_civoid BaselineCompiler::VisitInc() { 11171cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kIncrement_Baseline>(kInterpreterAccumulatorRegister, 11181cb0ef41Sopenharmony_ci Index(0)); 11191cb0ef41Sopenharmony_ci} 11201cb0ef41Sopenharmony_ci 11211cb0ef41Sopenharmony_civoid BaselineCompiler::VisitDec() { 11221cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kDecrement_Baseline>(kInterpreterAccumulatorRegister, 11231cb0ef41Sopenharmony_ci Index(0)); 11241cb0ef41Sopenharmony_ci} 11251cb0ef41Sopenharmony_ci 11261cb0ef41Sopenharmony_civoid BaselineCompiler::VisitNegate() { 11271cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kNegate_Baseline>(kInterpreterAccumulatorRegister, 11281cb0ef41Sopenharmony_ci Index(0)); 11291cb0ef41Sopenharmony_ci} 11301cb0ef41Sopenharmony_ci 11311cb0ef41Sopenharmony_civoid BaselineCompiler::VisitBitwiseNot() { 11321cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kBitwiseNot_Baseline>(kInterpreterAccumulatorRegister, 11331cb0ef41Sopenharmony_ci Index(0)); 11341cb0ef41Sopenharmony_ci} 11351cb0ef41Sopenharmony_ci 11361cb0ef41Sopenharmony_civoid BaselineCompiler::VisitToBooleanLogicalNot() { 11371cb0ef41Sopenharmony_ci SelectBooleanConstant(kInterpreterAccumulatorRegister, 11381cb0ef41Sopenharmony_ci [&](Label* if_true, Label::Distance distance) { 11391cb0ef41Sopenharmony_ci JumpIfToBoolean(false, if_true, distance); 11401cb0ef41Sopenharmony_ci }); 11411cb0ef41Sopenharmony_ci} 11421cb0ef41Sopenharmony_ci 11431cb0ef41Sopenharmony_civoid BaselineCompiler::VisitLogicalNot() { 11441cb0ef41Sopenharmony_ci SelectBooleanConstant(kInterpreterAccumulatorRegister, 11451cb0ef41Sopenharmony_ci [&](Label* if_true, Label::Distance distance) { 11461cb0ef41Sopenharmony_ci __ JumpIfRoot(kInterpreterAccumulatorRegister, 11471cb0ef41Sopenharmony_ci RootIndex::kFalseValue, if_true, 11481cb0ef41Sopenharmony_ci distance); 11491cb0ef41Sopenharmony_ci }); 11501cb0ef41Sopenharmony_ci} 11511cb0ef41Sopenharmony_ci 11521cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTypeOf() { 11531cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kTypeof>(kInterpreterAccumulatorRegister); 11541cb0ef41Sopenharmony_ci} 11551cb0ef41Sopenharmony_ci 11561cb0ef41Sopenharmony_civoid BaselineCompiler::VisitDeletePropertyStrict() { 11571cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 11581cb0ef41Sopenharmony_ci Register scratch = scratch_scope.AcquireScratch(); 11591cb0ef41Sopenharmony_ci __ Move(scratch, kInterpreterAccumulatorRegister); 11601cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kDeleteProperty>(RegisterOperand(0), scratch, 11611cb0ef41Sopenharmony_ci Smi::FromEnum(LanguageMode::kStrict)); 11621cb0ef41Sopenharmony_ci} 11631cb0ef41Sopenharmony_ci 11641cb0ef41Sopenharmony_civoid BaselineCompiler::VisitDeletePropertySloppy() { 11651cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 11661cb0ef41Sopenharmony_ci Register scratch = scratch_scope.AcquireScratch(); 11671cb0ef41Sopenharmony_ci __ Move(scratch, kInterpreterAccumulatorRegister); 11681cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kDeleteProperty>(RegisterOperand(0), scratch, 11691cb0ef41Sopenharmony_ci Smi::FromEnum(LanguageMode::kSloppy)); 11701cb0ef41Sopenharmony_ci} 11711cb0ef41Sopenharmony_ci 11721cb0ef41Sopenharmony_civoid BaselineCompiler::VisitGetSuperConstructor() { 11731cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 11741cb0ef41Sopenharmony_ci Register prototype = scratch_scope.AcquireScratch(); 11751cb0ef41Sopenharmony_ci __ LoadPrototype(prototype, kInterpreterAccumulatorRegister); 11761cb0ef41Sopenharmony_ci StoreRegister(0, prototype); 11771cb0ef41Sopenharmony_ci} 11781cb0ef41Sopenharmony_ci 11791cb0ef41Sopenharmony_cinamespace { 11801cb0ef41Sopenharmony_ciconstexpr Builtin ConvertReceiverModeToCompactBuiltin( 11811cb0ef41Sopenharmony_ci ConvertReceiverMode mode) { 11821cb0ef41Sopenharmony_ci switch (mode) { 11831cb0ef41Sopenharmony_ci case ConvertReceiverMode::kAny: 11841cb0ef41Sopenharmony_ci return Builtin::kCall_ReceiverIsAny_Baseline_Compact; 11851cb0ef41Sopenharmony_ci case ConvertReceiverMode::kNullOrUndefined: 11861cb0ef41Sopenharmony_ci return Builtin::kCall_ReceiverIsNullOrUndefined_Baseline_Compact; 11871cb0ef41Sopenharmony_ci case ConvertReceiverMode::kNotNullOrUndefined: 11881cb0ef41Sopenharmony_ci return Builtin::kCall_ReceiverIsNotNullOrUndefined_Baseline_Compact; 11891cb0ef41Sopenharmony_ci } 11901cb0ef41Sopenharmony_ci} 11911cb0ef41Sopenharmony_ciconstexpr Builtin ConvertReceiverModeToBuiltin(ConvertReceiverMode mode) { 11921cb0ef41Sopenharmony_ci switch (mode) { 11931cb0ef41Sopenharmony_ci case ConvertReceiverMode::kAny: 11941cb0ef41Sopenharmony_ci return Builtin::kCall_ReceiverIsAny_Baseline; 11951cb0ef41Sopenharmony_ci case ConvertReceiverMode::kNullOrUndefined: 11961cb0ef41Sopenharmony_ci return Builtin::kCall_ReceiverIsNullOrUndefined_Baseline; 11971cb0ef41Sopenharmony_ci case ConvertReceiverMode::kNotNullOrUndefined: 11981cb0ef41Sopenharmony_ci return Builtin::kCall_ReceiverIsNotNullOrUndefined_Baseline; 11991cb0ef41Sopenharmony_ci } 12001cb0ef41Sopenharmony_ci} 12011cb0ef41Sopenharmony_ci} // namespace 12021cb0ef41Sopenharmony_ci 12031cb0ef41Sopenharmony_citemplate <ConvertReceiverMode kMode, typename... Args> 12041cb0ef41Sopenharmony_civoid BaselineCompiler::BuildCall(uint32_t slot, uint32_t arg_count, 12051cb0ef41Sopenharmony_ci Args... args) { 12061cb0ef41Sopenharmony_ci uint32_t bitfield; 12071cb0ef41Sopenharmony_ci if (CallTrampoline_Baseline_CompactDescriptor::EncodeBitField(arg_count, slot, 12081cb0ef41Sopenharmony_ci &bitfield)) { 12091cb0ef41Sopenharmony_ci CallBuiltin<ConvertReceiverModeToCompactBuiltin(kMode)>( 12101cb0ef41Sopenharmony_ci RegisterOperand(0), // kFunction 12111cb0ef41Sopenharmony_ci bitfield, // kActualArgumentsCount | kSlot 12121cb0ef41Sopenharmony_ci args...); // Arguments 12131cb0ef41Sopenharmony_ci } else { 12141cb0ef41Sopenharmony_ci CallBuiltin<ConvertReceiverModeToBuiltin(kMode)>( 12151cb0ef41Sopenharmony_ci RegisterOperand(0), // kFunction 12161cb0ef41Sopenharmony_ci arg_count, // kActualArgumentsCount 12171cb0ef41Sopenharmony_ci slot, // kSlot 12181cb0ef41Sopenharmony_ci args...); // Arguments 12191cb0ef41Sopenharmony_ci } 12201cb0ef41Sopenharmony_ci} 12211cb0ef41Sopenharmony_ci 12221cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallAnyReceiver() { 12231cb0ef41Sopenharmony_ci interpreter::RegisterList args = iterator().GetRegisterListOperand(1); 12241cb0ef41Sopenharmony_ci uint32_t arg_count = args.register_count(); 12251cb0ef41Sopenharmony_ci BuildCall<ConvertReceiverMode::kAny>(Index(3), arg_count, args); 12261cb0ef41Sopenharmony_ci} 12271cb0ef41Sopenharmony_ci 12281cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallProperty() { 12291cb0ef41Sopenharmony_ci interpreter::RegisterList args = iterator().GetRegisterListOperand(1); 12301cb0ef41Sopenharmony_ci uint32_t arg_count = args.register_count(); 12311cb0ef41Sopenharmony_ci BuildCall<ConvertReceiverMode::kNotNullOrUndefined>(Index(3), arg_count, 12321cb0ef41Sopenharmony_ci args); 12331cb0ef41Sopenharmony_ci} 12341cb0ef41Sopenharmony_ci 12351cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallProperty0() { 12361cb0ef41Sopenharmony_ci BuildCall<ConvertReceiverMode::kNotNullOrUndefined>( 12371cb0ef41Sopenharmony_ci Index(2), JSParameterCount(0), RegisterOperand(1)); 12381cb0ef41Sopenharmony_ci} 12391cb0ef41Sopenharmony_ci 12401cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallProperty1() { 12411cb0ef41Sopenharmony_ci BuildCall<ConvertReceiverMode::kNotNullOrUndefined>( 12421cb0ef41Sopenharmony_ci Index(3), JSParameterCount(1), RegisterOperand(1), RegisterOperand(2)); 12431cb0ef41Sopenharmony_ci} 12441cb0ef41Sopenharmony_ci 12451cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallProperty2() { 12461cb0ef41Sopenharmony_ci BuildCall<ConvertReceiverMode::kNotNullOrUndefined>( 12471cb0ef41Sopenharmony_ci Index(4), JSParameterCount(2), RegisterOperand(1), RegisterOperand(2), 12481cb0ef41Sopenharmony_ci RegisterOperand(3)); 12491cb0ef41Sopenharmony_ci} 12501cb0ef41Sopenharmony_ci 12511cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallUndefinedReceiver() { 12521cb0ef41Sopenharmony_ci interpreter::RegisterList args = iterator().GetRegisterListOperand(1); 12531cb0ef41Sopenharmony_ci uint32_t arg_count = JSParameterCount(args.register_count()); 12541cb0ef41Sopenharmony_ci BuildCall<ConvertReceiverMode::kNullOrUndefined>( 12551cb0ef41Sopenharmony_ci Index(3), arg_count, RootIndex::kUndefinedValue, args); 12561cb0ef41Sopenharmony_ci} 12571cb0ef41Sopenharmony_ci 12581cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallUndefinedReceiver0() { 12591cb0ef41Sopenharmony_ci BuildCall<ConvertReceiverMode::kNullOrUndefined>( 12601cb0ef41Sopenharmony_ci Index(1), JSParameterCount(0), RootIndex::kUndefinedValue); 12611cb0ef41Sopenharmony_ci} 12621cb0ef41Sopenharmony_ci 12631cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallUndefinedReceiver1() { 12641cb0ef41Sopenharmony_ci BuildCall<ConvertReceiverMode::kNullOrUndefined>( 12651cb0ef41Sopenharmony_ci Index(2), JSParameterCount(1), RootIndex::kUndefinedValue, 12661cb0ef41Sopenharmony_ci RegisterOperand(1)); 12671cb0ef41Sopenharmony_ci} 12681cb0ef41Sopenharmony_ci 12691cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallUndefinedReceiver2() { 12701cb0ef41Sopenharmony_ci BuildCall<ConvertReceiverMode::kNullOrUndefined>( 12711cb0ef41Sopenharmony_ci Index(3), JSParameterCount(2), RootIndex::kUndefinedValue, 12721cb0ef41Sopenharmony_ci RegisterOperand(1), RegisterOperand(2)); 12731cb0ef41Sopenharmony_ci} 12741cb0ef41Sopenharmony_ci 12751cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallWithSpread() { 12761cb0ef41Sopenharmony_ci interpreter::RegisterList args = iterator().GetRegisterListOperand(1); 12771cb0ef41Sopenharmony_ci 12781cb0ef41Sopenharmony_ci // Do not push the spread argument 12791cb0ef41Sopenharmony_ci interpreter::Register spread_register = args.last_register(); 12801cb0ef41Sopenharmony_ci args = args.Truncate(args.register_count() - 1); 12811cb0ef41Sopenharmony_ci 12821cb0ef41Sopenharmony_ci uint32_t arg_count = args.register_count(); 12831cb0ef41Sopenharmony_ci 12841cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCallWithSpread_Baseline>( 12851cb0ef41Sopenharmony_ci RegisterOperand(0), // kFunction 12861cb0ef41Sopenharmony_ci arg_count, // kActualArgumentsCount 12871cb0ef41Sopenharmony_ci spread_register, // kSpread 12881cb0ef41Sopenharmony_ci Index(3), // kSlot 12891cb0ef41Sopenharmony_ci args); 12901cb0ef41Sopenharmony_ci} 12911cb0ef41Sopenharmony_ci 12921cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallRuntime() { 12931cb0ef41Sopenharmony_ci CallRuntime(iterator().GetRuntimeIdOperand(0), 12941cb0ef41Sopenharmony_ci iterator().GetRegisterListOperand(1)); 12951cb0ef41Sopenharmony_ci} 12961cb0ef41Sopenharmony_ci 12971cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallRuntimeForPair() { 12981cb0ef41Sopenharmony_ci SaveAccumulatorScope accumulator_scope(&basm_); 12991cb0ef41Sopenharmony_ci CallRuntime(iterator().GetRuntimeIdOperand(0), 13001cb0ef41Sopenharmony_ci iterator().GetRegisterListOperand(1)); 13011cb0ef41Sopenharmony_ci StoreRegisterPair(3, kReturnRegister0, kReturnRegister1); 13021cb0ef41Sopenharmony_ci} 13031cb0ef41Sopenharmony_ci 13041cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCallJSRuntime() { 13051cb0ef41Sopenharmony_ci interpreter::RegisterList args = iterator().GetRegisterListOperand(1); 13061cb0ef41Sopenharmony_ci uint32_t arg_count = JSParameterCount(args.register_count()); 13071cb0ef41Sopenharmony_ci 13081cb0ef41Sopenharmony_ci // Load context for LoadNativeContextSlot. 13091cb0ef41Sopenharmony_ci __ LoadContext(kContextRegister); 13101cb0ef41Sopenharmony_ci __ LoadNativeContextSlot(kJavaScriptCallTargetRegister, 13111cb0ef41Sopenharmony_ci iterator().GetNativeContextIndexOperand(0)); 13121cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCall_ReceiverIsNullOrUndefined>( 13131cb0ef41Sopenharmony_ci kJavaScriptCallTargetRegister, // kFunction 13141cb0ef41Sopenharmony_ci arg_count, // kActualArgumentsCount 13151cb0ef41Sopenharmony_ci RootIndex::kUndefinedValue, // kReceiver 13161cb0ef41Sopenharmony_ci args); 13171cb0ef41Sopenharmony_ci} 13181cb0ef41Sopenharmony_ci 13191cb0ef41Sopenharmony_civoid BaselineCompiler::VisitInvokeIntrinsic() { 13201cb0ef41Sopenharmony_ci Runtime::FunctionId intrinsic_id = iterator().GetIntrinsicIdOperand(0); 13211cb0ef41Sopenharmony_ci interpreter::RegisterList args = iterator().GetRegisterListOperand(1); 13221cb0ef41Sopenharmony_ci switch (intrinsic_id) { 13231cb0ef41Sopenharmony_ci#define CASE(Name, ...) \ 13241cb0ef41Sopenharmony_ci case Runtime::kInline##Name: \ 13251cb0ef41Sopenharmony_ci VisitIntrinsic##Name(args); \ 13261cb0ef41Sopenharmony_ci break; 13271cb0ef41Sopenharmony_ci INTRINSICS_LIST(CASE) 13281cb0ef41Sopenharmony_ci#undef CASE 13291cb0ef41Sopenharmony_ci 13301cb0ef41Sopenharmony_ci default: 13311cb0ef41Sopenharmony_ci UNREACHABLE(); 13321cb0ef41Sopenharmony_ci } 13331cb0ef41Sopenharmony_ci} 13341cb0ef41Sopenharmony_ci 13351cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicCopyDataProperties( 13361cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 13371cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCopyDataProperties>(args); 13381cb0ef41Sopenharmony_ci} 13391cb0ef41Sopenharmony_ci 13401cb0ef41Sopenharmony_civoid BaselineCompiler:: 13411cb0ef41Sopenharmony_ci VisitIntrinsicCopyDataPropertiesWithExcludedPropertiesOnStack( 13421cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 13431cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 13441cb0ef41Sopenharmony_ci Register rscratch = scratch_scope.AcquireScratch(); 13451cb0ef41Sopenharmony_ci // Use an offset from args[0] instead of args[1] to pass a valid "end of" 13461cb0ef41Sopenharmony_ci // pointer in the case where args.register_count() == 1. 13471cb0ef41Sopenharmony_ci basm_.RegisterFrameAddress(interpreter::Register(args[0].index() + 1), 13481cb0ef41Sopenharmony_ci rscratch); 13491cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCopyDataPropertiesWithExcludedPropertiesOnStack>( 13501cb0ef41Sopenharmony_ci args[0], args.register_count() - 1, rscratch); 13511cb0ef41Sopenharmony_ci} 13521cb0ef41Sopenharmony_ci 13531cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicCreateIterResultObject( 13541cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 13551cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCreateIterResultObject>(args); 13561cb0ef41Sopenharmony_ci} 13571cb0ef41Sopenharmony_ci 13581cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicCreateAsyncFromSyncIterator( 13591cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 13601cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCreateAsyncFromSyncIteratorBaseline>(args[0]); 13611cb0ef41Sopenharmony_ci} 13621cb0ef41Sopenharmony_ci 13631cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicCreateJSGeneratorObject( 13641cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 13651cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCreateGeneratorObject>(args); 13661cb0ef41Sopenharmony_ci} 13671cb0ef41Sopenharmony_ci 13681cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicGeneratorGetResumeMode( 13691cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 13701cb0ef41Sopenharmony_ci __ LoadRegister(kInterpreterAccumulatorRegister, args[0]); 13711cb0ef41Sopenharmony_ci __ LoadTaggedAnyField(kInterpreterAccumulatorRegister, 13721cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, 13731cb0ef41Sopenharmony_ci JSGeneratorObject::kResumeModeOffset); 13741cb0ef41Sopenharmony_ci} 13751cb0ef41Sopenharmony_ci 13761cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicGeneratorClose( 13771cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 13781cb0ef41Sopenharmony_ci __ LoadRegister(kInterpreterAccumulatorRegister, args[0]); 13791cb0ef41Sopenharmony_ci __ StoreTaggedSignedField(kInterpreterAccumulatorRegister, 13801cb0ef41Sopenharmony_ci JSGeneratorObject::kContinuationOffset, 13811cb0ef41Sopenharmony_ci Smi::FromInt(JSGeneratorObject::kGeneratorClosed)); 13821cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kUndefinedValue); 13831cb0ef41Sopenharmony_ci} 13841cb0ef41Sopenharmony_ci 13851cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicGetImportMetaObject( 13861cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 13871cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kGetImportMetaObjectBaseline>(); 13881cb0ef41Sopenharmony_ci} 13891cb0ef41Sopenharmony_ci 13901cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicAsyncFunctionAwaitCaught( 13911cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 13921cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAsyncFunctionAwaitCaught>(args); 13931cb0ef41Sopenharmony_ci} 13941cb0ef41Sopenharmony_ci 13951cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicAsyncFunctionAwaitUncaught( 13961cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 13971cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAsyncFunctionAwaitUncaught>(args); 13981cb0ef41Sopenharmony_ci} 13991cb0ef41Sopenharmony_ci 14001cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicAsyncFunctionEnter( 14011cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 14021cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAsyncFunctionEnter>(args); 14031cb0ef41Sopenharmony_ci} 14041cb0ef41Sopenharmony_ci 14051cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicAsyncFunctionReject( 14061cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 14071cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAsyncFunctionReject>(args); 14081cb0ef41Sopenharmony_ci} 14091cb0ef41Sopenharmony_ci 14101cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicAsyncFunctionResolve( 14111cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 14121cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAsyncFunctionResolve>(args); 14131cb0ef41Sopenharmony_ci} 14141cb0ef41Sopenharmony_ci 14151cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicAsyncGeneratorAwaitCaught( 14161cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 14171cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAsyncGeneratorAwaitCaught>(args); 14181cb0ef41Sopenharmony_ci} 14191cb0ef41Sopenharmony_ci 14201cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicAsyncGeneratorAwaitUncaught( 14211cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 14221cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAsyncGeneratorAwaitUncaught>(args); 14231cb0ef41Sopenharmony_ci} 14241cb0ef41Sopenharmony_ci 14251cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicAsyncGeneratorReject( 14261cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 14271cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAsyncGeneratorReject>(args); 14281cb0ef41Sopenharmony_ci} 14291cb0ef41Sopenharmony_ci 14301cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicAsyncGeneratorResolve( 14311cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 14321cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAsyncGeneratorResolve>(args); 14331cb0ef41Sopenharmony_ci} 14341cb0ef41Sopenharmony_ci 14351cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIntrinsicAsyncGeneratorYield( 14361cb0ef41Sopenharmony_ci interpreter::RegisterList args) { 14371cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kAsyncGeneratorYield>(args); 14381cb0ef41Sopenharmony_ci} 14391cb0ef41Sopenharmony_ci 14401cb0ef41Sopenharmony_civoid BaselineCompiler::VisitConstruct() { 14411cb0ef41Sopenharmony_ci interpreter::RegisterList args = iterator().GetRegisterListOperand(1); 14421cb0ef41Sopenharmony_ci uint32_t arg_count = JSParameterCount(args.register_count()); 14431cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kConstruct_Baseline>( 14441cb0ef41Sopenharmony_ci RegisterOperand(0), // kFunction 14451cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // kNewTarget 14461cb0ef41Sopenharmony_ci arg_count, // kActualArgumentsCount 14471cb0ef41Sopenharmony_ci Index(3), // kSlot 14481cb0ef41Sopenharmony_ci RootIndex::kUndefinedValue, // kReceiver 14491cb0ef41Sopenharmony_ci args); 14501cb0ef41Sopenharmony_ci} 14511cb0ef41Sopenharmony_ci 14521cb0ef41Sopenharmony_civoid BaselineCompiler::VisitConstructWithSpread() { 14531cb0ef41Sopenharmony_ci interpreter::RegisterList args = iterator().GetRegisterListOperand(1); 14541cb0ef41Sopenharmony_ci 14551cb0ef41Sopenharmony_ci // Do not push the spread argument 14561cb0ef41Sopenharmony_ci interpreter::Register spread_register = args.last_register(); 14571cb0ef41Sopenharmony_ci args = args.Truncate(args.register_count() - 1); 14581cb0ef41Sopenharmony_ci 14591cb0ef41Sopenharmony_ci uint32_t arg_count = JSParameterCount(args.register_count()); 14601cb0ef41Sopenharmony_ci 14611cb0ef41Sopenharmony_ci using Descriptor = 14621cb0ef41Sopenharmony_ci CallInterfaceDescriptorFor<Builtin::kConstructWithSpread_Baseline>::type; 14631cb0ef41Sopenharmony_ci Register new_target = 14641cb0ef41Sopenharmony_ci Descriptor::GetRegisterParameter(Descriptor::kNewTarget); 14651cb0ef41Sopenharmony_ci __ Move(new_target, kInterpreterAccumulatorRegister); 14661cb0ef41Sopenharmony_ci 14671cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kConstructWithSpread_Baseline>( 14681cb0ef41Sopenharmony_ci RegisterOperand(0), // kFunction 14691cb0ef41Sopenharmony_ci new_target, // kNewTarget 14701cb0ef41Sopenharmony_ci arg_count, // kActualArgumentsCount 14711cb0ef41Sopenharmony_ci Index(3), // kSlot 14721cb0ef41Sopenharmony_ci spread_register, // kSpread 14731cb0ef41Sopenharmony_ci RootIndex::kUndefinedValue, // kReceiver 14741cb0ef41Sopenharmony_ci args); 14751cb0ef41Sopenharmony_ci} 14761cb0ef41Sopenharmony_ci 14771cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestEqual() { 14781cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kEqual_Baseline>( 14791cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 14801cb0ef41Sopenharmony_ci} 14811cb0ef41Sopenharmony_ci 14821cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestEqualStrict() { 14831cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kStrictEqual_Baseline>( 14841cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 14851cb0ef41Sopenharmony_ci} 14861cb0ef41Sopenharmony_ci 14871cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestLessThan() { 14881cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kLessThan_Baseline>( 14891cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 14901cb0ef41Sopenharmony_ci} 14911cb0ef41Sopenharmony_ci 14921cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestGreaterThan() { 14931cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kGreaterThan_Baseline>( 14941cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 14951cb0ef41Sopenharmony_ci} 14961cb0ef41Sopenharmony_ci 14971cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestLessThanOrEqual() { 14981cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kLessThanOrEqual_Baseline>( 14991cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 15001cb0ef41Sopenharmony_ci} 15011cb0ef41Sopenharmony_ci 15021cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestGreaterThanOrEqual() { 15031cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kGreaterThanOrEqual_Baseline>( 15041cb0ef41Sopenharmony_ci RegisterOperand(0), kInterpreterAccumulatorRegister, Index(1)); 15051cb0ef41Sopenharmony_ci} 15061cb0ef41Sopenharmony_ci 15071cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestReferenceEqual() { 15081cb0ef41Sopenharmony_ci SelectBooleanConstant( 15091cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, 15101cb0ef41Sopenharmony_ci [&](Label* is_true, Label::Distance distance) { 15111cb0ef41Sopenharmony_ci __ JumpIfTagged(Condition::kEqual, 15121cb0ef41Sopenharmony_ci __ RegisterFrameOperand(RegisterOperand(0)), 15131cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, is_true, distance); 15141cb0ef41Sopenharmony_ci }); 15151cb0ef41Sopenharmony_ci} 15161cb0ef41Sopenharmony_ci 15171cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestInstanceOf() { 15181cb0ef41Sopenharmony_ci using Descriptor = 15191cb0ef41Sopenharmony_ci CallInterfaceDescriptorFor<Builtin::kInstanceOf_Baseline>::type; 15201cb0ef41Sopenharmony_ci Register callable = Descriptor::GetRegisterParameter(Descriptor::kRight); 15211cb0ef41Sopenharmony_ci __ Move(callable, kInterpreterAccumulatorRegister); 15221cb0ef41Sopenharmony_ci 15231cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kInstanceOf_Baseline>(RegisterOperand(0), // object 15241cb0ef41Sopenharmony_ci callable, // callable 15251cb0ef41Sopenharmony_ci Index(1)); // slot 15261cb0ef41Sopenharmony_ci} 15271cb0ef41Sopenharmony_ci 15281cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestIn() { 15291cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kKeyedHasICBaseline>( 15301cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, // object 15311cb0ef41Sopenharmony_ci RegisterOperand(0), // name 15321cb0ef41Sopenharmony_ci IndexAsTagged(1)); // slot 15331cb0ef41Sopenharmony_ci} 15341cb0ef41Sopenharmony_ci 15351cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestUndetectable() { 15361cb0ef41Sopenharmony_ci Label done, is_smi, not_undetectable; 15371cb0ef41Sopenharmony_ci __ JumpIfSmi(kInterpreterAccumulatorRegister, &is_smi, Label::kNear); 15381cb0ef41Sopenharmony_ci 15391cb0ef41Sopenharmony_ci Register map_bit_field = kInterpreterAccumulatorRegister; 15401cb0ef41Sopenharmony_ci __ LoadMap(map_bit_field, kInterpreterAccumulatorRegister); 15411cb0ef41Sopenharmony_ci __ LoadWord8Field(map_bit_field, map_bit_field, Map::kBitFieldOffset); 15421cb0ef41Sopenharmony_ci __ TestAndBranch(map_bit_field, Map::Bits1::IsUndetectableBit::kMask, 15431cb0ef41Sopenharmony_ci Condition::kZero, ¬_undetectable, Label::kNear); 15441cb0ef41Sopenharmony_ci 15451cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue); 15461cb0ef41Sopenharmony_ci __ Jump(&done, Label::kNear); 15471cb0ef41Sopenharmony_ci 15481cb0ef41Sopenharmony_ci __ Bind(&is_smi); 15491cb0ef41Sopenharmony_ci __ Bind(¬_undetectable); 15501cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue); 15511cb0ef41Sopenharmony_ci __ Bind(&done); 15521cb0ef41Sopenharmony_ci} 15531cb0ef41Sopenharmony_ci 15541cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestNull() { 15551cb0ef41Sopenharmony_ci SelectBooleanConstant(kInterpreterAccumulatorRegister, 15561cb0ef41Sopenharmony_ci [&](Label* is_true, Label::Distance distance) { 15571cb0ef41Sopenharmony_ci __ JumpIfRoot(kInterpreterAccumulatorRegister, 15581cb0ef41Sopenharmony_ci RootIndex::kNullValue, is_true, 15591cb0ef41Sopenharmony_ci distance); 15601cb0ef41Sopenharmony_ci }); 15611cb0ef41Sopenharmony_ci} 15621cb0ef41Sopenharmony_ci 15631cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestUndefined() { 15641cb0ef41Sopenharmony_ci SelectBooleanConstant(kInterpreterAccumulatorRegister, 15651cb0ef41Sopenharmony_ci [&](Label* is_true, Label::Distance distance) { 15661cb0ef41Sopenharmony_ci __ JumpIfRoot(kInterpreterAccumulatorRegister, 15671cb0ef41Sopenharmony_ci RootIndex::kUndefinedValue, is_true, 15681cb0ef41Sopenharmony_ci distance); 15691cb0ef41Sopenharmony_ci }); 15701cb0ef41Sopenharmony_ci} 15711cb0ef41Sopenharmony_ci 15721cb0ef41Sopenharmony_civoid BaselineCompiler::VisitTestTypeOf() { 15731cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 15741cb0ef41Sopenharmony_ci 15751cb0ef41Sopenharmony_ci auto literal_flag = 15761cb0ef41Sopenharmony_ci static_cast<interpreter::TestTypeOfFlags::LiteralFlag>(Flag(0)); 15771cb0ef41Sopenharmony_ci 15781cb0ef41Sopenharmony_ci Label done; 15791cb0ef41Sopenharmony_ci switch (literal_flag) { 15801cb0ef41Sopenharmony_ci case interpreter::TestTypeOfFlags::LiteralFlag::kNumber: { 15811cb0ef41Sopenharmony_ci Label is_smi, is_heap_number; 15821cb0ef41Sopenharmony_ci __ JumpIfSmi(kInterpreterAccumulatorRegister, &is_smi, Label::kNear); 15831cb0ef41Sopenharmony_ci __ JumpIfObjectType(Condition::kEqual, kInterpreterAccumulatorRegister, 15841cb0ef41Sopenharmony_ci HEAP_NUMBER_TYPE, scratch_scope.AcquireScratch(), 15851cb0ef41Sopenharmony_ci &is_heap_number, Label::kNear); 15861cb0ef41Sopenharmony_ci 15871cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue); 15881cb0ef41Sopenharmony_ci __ Jump(&done, Label::kNear); 15891cb0ef41Sopenharmony_ci 15901cb0ef41Sopenharmony_ci __ Bind(&is_smi); 15911cb0ef41Sopenharmony_ci __ Bind(&is_heap_number); 15921cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue); 15931cb0ef41Sopenharmony_ci break; 15941cb0ef41Sopenharmony_ci } 15951cb0ef41Sopenharmony_ci case interpreter::TestTypeOfFlags::LiteralFlag::kString: { 15961cb0ef41Sopenharmony_ci Label is_smi, bad_instance_type; 15971cb0ef41Sopenharmony_ci __ JumpIfSmi(kInterpreterAccumulatorRegister, &is_smi, Label::kNear); 15981cb0ef41Sopenharmony_ci STATIC_ASSERT(INTERNALIZED_STRING_TYPE == FIRST_TYPE); 15991cb0ef41Sopenharmony_ci __ JumpIfObjectType(Condition::kGreaterThanEqual, 16001cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, FIRST_NONSTRING_TYPE, 16011cb0ef41Sopenharmony_ci scratch_scope.AcquireScratch(), &bad_instance_type, 16021cb0ef41Sopenharmony_ci Label::kNear); 16031cb0ef41Sopenharmony_ci 16041cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue); 16051cb0ef41Sopenharmony_ci __ Jump(&done, Label::kNear); 16061cb0ef41Sopenharmony_ci 16071cb0ef41Sopenharmony_ci __ Bind(&is_smi); 16081cb0ef41Sopenharmony_ci __ Bind(&bad_instance_type); 16091cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue); 16101cb0ef41Sopenharmony_ci break; 16111cb0ef41Sopenharmony_ci } 16121cb0ef41Sopenharmony_ci case interpreter::TestTypeOfFlags::LiteralFlag::kSymbol: { 16131cb0ef41Sopenharmony_ci Label is_smi, bad_instance_type; 16141cb0ef41Sopenharmony_ci __ JumpIfSmi(kInterpreterAccumulatorRegister, &is_smi, Label::kNear); 16151cb0ef41Sopenharmony_ci __ JumpIfObjectType(Condition::kNotEqual, kInterpreterAccumulatorRegister, 16161cb0ef41Sopenharmony_ci SYMBOL_TYPE, scratch_scope.AcquireScratch(), 16171cb0ef41Sopenharmony_ci &bad_instance_type, Label::kNear); 16181cb0ef41Sopenharmony_ci 16191cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue); 16201cb0ef41Sopenharmony_ci __ Jump(&done, Label::kNear); 16211cb0ef41Sopenharmony_ci 16221cb0ef41Sopenharmony_ci __ Bind(&is_smi); 16231cb0ef41Sopenharmony_ci __ Bind(&bad_instance_type); 16241cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue); 16251cb0ef41Sopenharmony_ci break; 16261cb0ef41Sopenharmony_ci } 16271cb0ef41Sopenharmony_ci case interpreter::TestTypeOfFlags::LiteralFlag::kBoolean: { 16281cb0ef41Sopenharmony_ci Label is_true, is_false; 16291cb0ef41Sopenharmony_ci __ JumpIfRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue, 16301cb0ef41Sopenharmony_ci &is_true, Label::kNear); 16311cb0ef41Sopenharmony_ci __ JumpIfRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue, 16321cb0ef41Sopenharmony_ci &is_false, Label::kNear); 16331cb0ef41Sopenharmony_ci 16341cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue); 16351cb0ef41Sopenharmony_ci __ Jump(&done, Label::kNear); 16361cb0ef41Sopenharmony_ci 16371cb0ef41Sopenharmony_ci __ Bind(&is_true); 16381cb0ef41Sopenharmony_ci __ Bind(&is_false); 16391cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue); 16401cb0ef41Sopenharmony_ci break; 16411cb0ef41Sopenharmony_ci } 16421cb0ef41Sopenharmony_ci case interpreter::TestTypeOfFlags::LiteralFlag::kBigInt: { 16431cb0ef41Sopenharmony_ci Label is_smi, bad_instance_type; 16441cb0ef41Sopenharmony_ci __ JumpIfSmi(kInterpreterAccumulatorRegister, &is_smi, Label::kNear); 16451cb0ef41Sopenharmony_ci __ JumpIfObjectType(Condition::kNotEqual, kInterpreterAccumulatorRegister, 16461cb0ef41Sopenharmony_ci BIGINT_TYPE, scratch_scope.AcquireScratch(), 16471cb0ef41Sopenharmony_ci &bad_instance_type, Label::kNear); 16481cb0ef41Sopenharmony_ci 16491cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue); 16501cb0ef41Sopenharmony_ci __ Jump(&done, Label::kNear); 16511cb0ef41Sopenharmony_ci 16521cb0ef41Sopenharmony_ci __ Bind(&is_smi); 16531cb0ef41Sopenharmony_ci __ Bind(&bad_instance_type); 16541cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue); 16551cb0ef41Sopenharmony_ci break; 16561cb0ef41Sopenharmony_ci } 16571cb0ef41Sopenharmony_ci case interpreter::TestTypeOfFlags::LiteralFlag::kUndefined: { 16581cb0ef41Sopenharmony_ci Label is_smi, is_null, not_undetectable; 16591cb0ef41Sopenharmony_ci __ JumpIfSmi(kInterpreterAccumulatorRegister, &is_smi, Label::kNear); 16601cb0ef41Sopenharmony_ci 16611cb0ef41Sopenharmony_ci // null is undetectable, so test it explicitly, and return false. 16621cb0ef41Sopenharmony_ci __ JumpIfRoot(kInterpreterAccumulatorRegister, RootIndex::kNullValue, 16631cb0ef41Sopenharmony_ci &is_null, Label::kNear); 16641cb0ef41Sopenharmony_ci 16651cb0ef41Sopenharmony_ci // All other undetectable maps are typeof undefined. 16661cb0ef41Sopenharmony_ci Register map_bit_field = kInterpreterAccumulatorRegister; 16671cb0ef41Sopenharmony_ci __ LoadMap(map_bit_field, kInterpreterAccumulatorRegister); 16681cb0ef41Sopenharmony_ci __ LoadWord8Field(map_bit_field, map_bit_field, Map::kBitFieldOffset); 16691cb0ef41Sopenharmony_ci __ TestAndBranch(map_bit_field, Map::Bits1::IsUndetectableBit::kMask, 16701cb0ef41Sopenharmony_ci Condition::kZero, ¬_undetectable, Label::kNear); 16711cb0ef41Sopenharmony_ci 16721cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue); 16731cb0ef41Sopenharmony_ci __ Jump(&done, Label::kNear); 16741cb0ef41Sopenharmony_ci 16751cb0ef41Sopenharmony_ci __ Bind(&is_smi); 16761cb0ef41Sopenharmony_ci __ Bind(&is_null); 16771cb0ef41Sopenharmony_ci __ Bind(¬_undetectable); 16781cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue); 16791cb0ef41Sopenharmony_ci break; 16801cb0ef41Sopenharmony_ci } 16811cb0ef41Sopenharmony_ci case interpreter::TestTypeOfFlags::LiteralFlag::kFunction: { 16821cb0ef41Sopenharmony_ci Label is_smi, not_callable, undetectable; 16831cb0ef41Sopenharmony_ci __ JumpIfSmi(kInterpreterAccumulatorRegister, &is_smi, Label::kNear); 16841cb0ef41Sopenharmony_ci 16851cb0ef41Sopenharmony_ci // Check if the map is callable but not undetectable. 16861cb0ef41Sopenharmony_ci Register map_bit_field = kInterpreterAccumulatorRegister; 16871cb0ef41Sopenharmony_ci __ LoadMap(map_bit_field, kInterpreterAccumulatorRegister); 16881cb0ef41Sopenharmony_ci __ LoadWord8Field(map_bit_field, map_bit_field, Map::kBitFieldOffset); 16891cb0ef41Sopenharmony_ci __ TestAndBranch(map_bit_field, Map::Bits1::IsCallableBit::kMask, 16901cb0ef41Sopenharmony_ci Condition::kZero, ¬_callable, Label::kNear); 16911cb0ef41Sopenharmony_ci __ TestAndBranch(map_bit_field, Map::Bits1::IsUndetectableBit::kMask, 16921cb0ef41Sopenharmony_ci Condition::kNotZero, &undetectable, Label::kNear); 16931cb0ef41Sopenharmony_ci 16941cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue); 16951cb0ef41Sopenharmony_ci __ Jump(&done, Label::kNear); 16961cb0ef41Sopenharmony_ci 16971cb0ef41Sopenharmony_ci __ Bind(&is_smi); 16981cb0ef41Sopenharmony_ci __ Bind(¬_callable); 16991cb0ef41Sopenharmony_ci __ Bind(&undetectable); 17001cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue); 17011cb0ef41Sopenharmony_ci break; 17021cb0ef41Sopenharmony_ci } 17031cb0ef41Sopenharmony_ci case interpreter::TestTypeOfFlags::LiteralFlag::kObject: { 17041cb0ef41Sopenharmony_ci Label is_smi, is_null, bad_instance_type, undetectable_or_callable; 17051cb0ef41Sopenharmony_ci __ JumpIfSmi(kInterpreterAccumulatorRegister, &is_smi, Label::kNear); 17061cb0ef41Sopenharmony_ci 17071cb0ef41Sopenharmony_ci // If the object is null, return true. 17081cb0ef41Sopenharmony_ci __ JumpIfRoot(kInterpreterAccumulatorRegister, RootIndex::kNullValue, 17091cb0ef41Sopenharmony_ci &is_null, Label::kNear); 17101cb0ef41Sopenharmony_ci 17111cb0ef41Sopenharmony_ci // If the object's instance type isn't within the range, return false. 17121cb0ef41Sopenharmony_ci STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); 17131cb0ef41Sopenharmony_ci Register map = scratch_scope.AcquireScratch(); 17141cb0ef41Sopenharmony_ci __ JumpIfObjectType(Condition::kLessThan, kInterpreterAccumulatorRegister, 17151cb0ef41Sopenharmony_ci FIRST_JS_RECEIVER_TYPE, map, &bad_instance_type, 17161cb0ef41Sopenharmony_ci Label::kNear); 17171cb0ef41Sopenharmony_ci 17181cb0ef41Sopenharmony_ci // If the map is undetectable or callable, return false. 17191cb0ef41Sopenharmony_ci Register map_bit_field = kInterpreterAccumulatorRegister; 17201cb0ef41Sopenharmony_ci __ LoadWord8Field(map_bit_field, map, Map::kBitFieldOffset); 17211cb0ef41Sopenharmony_ci __ TestAndBranch(map_bit_field, 17221cb0ef41Sopenharmony_ci Map::Bits1::IsUndetectableBit::kMask | 17231cb0ef41Sopenharmony_ci Map::Bits1::IsCallableBit::kMask, 17241cb0ef41Sopenharmony_ci Condition::kNotZero, &undetectable_or_callable, 17251cb0ef41Sopenharmony_ci Label::kNear); 17261cb0ef41Sopenharmony_ci 17271cb0ef41Sopenharmony_ci __ Bind(&is_null); 17281cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kTrueValue); 17291cb0ef41Sopenharmony_ci __ Jump(&done, Label::kNear); 17301cb0ef41Sopenharmony_ci 17311cb0ef41Sopenharmony_ci __ Bind(&is_smi); 17321cb0ef41Sopenharmony_ci __ Bind(&bad_instance_type); 17331cb0ef41Sopenharmony_ci __ Bind(&undetectable_or_callable); 17341cb0ef41Sopenharmony_ci __ LoadRoot(kInterpreterAccumulatorRegister, RootIndex::kFalseValue); 17351cb0ef41Sopenharmony_ci break; 17361cb0ef41Sopenharmony_ci } 17371cb0ef41Sopenharmony_ci case interpreter::TestTypeOfFlags::LiteralFlag::kOther: 17381cb0ef41Sopenharmony_ci default: 17391cb0ef41Sopenharmony_ci UNREACHABLE(); 17401cb0ef41Sopenharmony_ci } 17411cb0ef41Sopenharmony_ci __ Bind(&done); 17421cb0ef41Sopenharmony_ci} 17431cb0ef41Sopenharmony_ci 17441cb0ef41Sopenharmony_civoid BaselineCompiler::VisitToName() { 17451cb0ef41Sopenharmony_ci SaveAccumulatorScope save_accumulator(&basm_); 17461cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kToName>(kInterpreterAccumulatorRegister); 17471cb0ef41Sopenharmony_ci StoreRegister(0, kInterpreterAccumulatorRegister); 17481cb0ef41Sopenharmony_ci} 17491cb0ef41Sopenharmony_ci 17501cb0ef41Sopenharmony_civoid BaselineCompiler::VisitToNumber() { 17511cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kToNumber_Baseline>(kInterpreterAccumulatorRegister, 17521cb0ef41Sopenharmony_ci Index(0)); 17531cb0ef41Sopenharmony_ci} 17541cb0ef41Sopenharmony_ci 17551cb0ef41Sopenharmony_civoid BaselineCompiler::VisitToNumeric() { 17561cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kToNumeric_Baseline>(kInterpreterAccumulatorRegister, 17571cb0ef41Sopenharmony_ci Index(0)); 17581cb0ef41Sopenharmony_ci} 17591cb0ef41Sopenharmony_ci 17601cb0ef41Sopenharmony_civoid BaselineCompiler::VisitToObject() { 17611cb0ef41Sopenharmony_ci SaveAccumulatorScope save_accumulator(&basm_); 17621cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kToObject>(kInterpreterAccumulatorRegister); 17631cb0ef41Sopenharmony_ci StoreRegister(0, kInterpreterAccumulatorRegister); 17641cb0ef41Sopenharmony_ci} 17651cb0ef41Sopenharmony_ci 17661cb0ef41Sopenharmony_civoid BaselineCompiler::VisitToString() { 17671cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kToString>(kInterpreterAccumulatorRegister); 17681cb0ef41Sopenharmony_ci} 17691cb0ef41Sopenharmony_ci 17701cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateRegExpLiteral() { 17711cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCreateRegExpLiteral>( 17721cb0ef41Sopenharmony_ci FeedbackVector(), // feedback vector 17731cb0ef41Sopenharmony_ci IndexAsTagged(1), // slot 17741cb0ef41Sopenharmony_ci Constant<HeapObject>(0), // pattern 17751cb0ef41Sopenharmony_ci FlagAsSmi(2)); // flags 17761cb0ef41Sopenharmony_ci} 17771cb0ef41Sopenharmony_ci 17781cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateArrayLiteral() { 17791cb0ef41Sopenharmony_ci uint32_t flags = Flag(2); 17801cb0ef41Sopenharmony_ci int32_t flags_raw = static_cast<int32_t>( 17811cb0ef41Sopenharmony_ci interpreter::CreateArrayLiteralFlags::FlagsBits::decode(flags)); 17821cb0ef41Sopenharmony_ci if (flags & 17831cb0ef41Sopenharmony_ci interpreter::CreateArrayLiteralFlags::FastCloneSupportedBit::kMask) { 17841cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCreateShallowArrayLiteral>( 17851cb0ef41Sopenharmony_ci FeedbackVector(), // feedback vector 17861cb0ef41Sopenharmony_ci IndexAsTagged(1), // slot 17871cb0ef41Sopenharmony_ci Constant<HeapObject>(0), // constant elements 17881cb0ef41Sopenharmony_ci Smi::FromInt(flags_raw)); // flags 17891cb0ef41Sopenharmony_ci } else { 17901cb0ef41Sopenharmony_ci CallRuntime(Runtime::kCreateArrayLiteral, 17911cb0ef41Sopenharmony_ci FeedbackVector(), // feedback vector 17921cb0ef41Sopenharmony_ci IndexAsTagged(1), // slot 17931cb0ef41Sopenharmony_ci Constant<HeapObject>(0), // constant elements 17941cb0ef41Sopenharmony_ci Smi::FromInt(flags_raw)); // flags 17951cb0ef41Sopenharmony_ci } 17961cb0ef41Sopenharmony_ci} 17971cb0ef41Sopenharmony_ci 17981cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateArrayFromIterable() { 17991cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kIterableToListWithSymbolLookup>( 18001cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister); // iterable 18011cb0ef41Sopenharmony_ci} 18021cb0ef41Sopenharmony_ci 18031cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateEmptyArrayLiteral() { 18041cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCreateEmptyArrayLiteral>(FeedbackVector(), 18051cb0ef41Sopenharmony_ci IndexAsTagged(0)); 18061cb0ef41Sopenharmony_ci} 18071cb0ef41Sopenharmony_ci 18081cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateObjectLiteral() { 18091cb0ef41Sopenharmony_ci uint32_t flags = Flag(2); 18101cb0ef41Sopenharmony_ci int32_t flags_raw = static_cast<int32_t>( 18111cb0ef41Sopenharmony_ci interpreter::CreateObjectLiteralFlags::FlagsBits::decode(flags)); 18121cb0ef41Sopenharmony_ci if (flags & 18131cb0ef41Sopenharmony_ci interpreter::CreateObjectLiteralFlags::FastCloneSupportedBit::kMask) { 18141cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCreateShallowObjectLiteral>( 18151cb0ef41Sopenharmony_ci FeedbackVector(), // feedback vector 18161cb0ef41Sopenharmony_ci IndexAsTagged(1), // slot 18171cb0ef41Sopenharmony_ci Constant<ObjectBoilerplateDescription>(0), // boilerplate 18181cb0ef41Sopenharmony_ci Smi::FromInt(flags_raw)); // flags 18191cb0ef41Sopenharmony_ci } else { 18201cb0ef41Sopenharmony_ci CallRuntime(Runtime::kCreateObjectLiteral, 18211cb0ef41Sopenharmony_ci FeedbackVector(), // feedback vector 18221cb0ef41Sopenharmony_ci IndexAsTagged(1), // slot 18231cb0ef41Sopenharmony_ci Constant<ObjectBoilerplateDescription>(0), // boilerplate 18241cb0ef41Sopenharmony_ci Smi::FromInt(flags_raw)); // flags 18251cb0ef41Sopenharmony_ci } 18261cb0ef41Sopenharmony_ci} 18271cb0ef41Sopenharmony_ci 18281cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateEmptyObjectLiteral() { 18291cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCreateEmptyLiteralObject>(); 18301cb0ef41Sopenharmony_ci} 18311cb0ef41Sopenharmony_ci 18321cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCloneObject() { 18331cb0ef41Sopenharmony_ci uint32_t flags = Flag(1); 18341cb0ef41Sopenharmony_ci int32_t raw_flags = 18351cb0ef41Sopenharmony_ci interpreter::CreateObjectLiteralFlags::FlagsBits::decode(flags); 18361cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kCloneObjectICBaseline>( 18371cb0ef41Sopenharmony_ci RegisterOperand(0), // source 18381cb0ef41Sopenharmony_ci Smi::FromInt(raw_flags), // flags 18391cb0ef41Sopenharmony_ci IndexAsTagged(2)); // slot 18401cb0ef41Sopenharmony_ci} 18411cb0ef41Sopenharmony_ci 18421cb0ef41Sopenharmony_civoid BaselineCompiler::VisitGetTemplateObject() { 18431cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 18441cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kGetTemplateObject>( 18451cb0ef41Sopenharmony_ci shared_function_info_, // shared function info 18461cb0ef41Sopenharmony_ci Constant<HeapObject>(0), // description 18471cb0ef41Sopenharmony_ci Index(1), // slot 18481cb0ef41Sopenharmony_ci FeedbackVector()); // feedback_vector 18491cb0ef41Sopenharmony_ci} 18501cb0ef41Sopenharmony_ci 18511cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateClosure() { 18521cb0ef41Sopenharmony_ci Register feedback_cell = 18531cb0ef41Sopenharmony_ci FastNewClosureBaselineDescriptor::GetRegisterParameter( 18541cb0ef41Sopenharmony_ci FastNewClosureBaselineDescriptor::kFeedbackCell); 18551cb0ef41Sopenharmony_ci LoadClosureFeedbackArray(feedback_cell); 18561cb0ef41Sopenharmony_ci __ LoadFixedArrayElement(feedback_cell, feedback_cell, Index(1)); 18571cb0ef41Sopenharmony_ci 18581cb0ef41Sopenharmony_ci uint32_t flags = Flag(2); 18591cb0ef41Sopenharmony_ci if (interpreter::CreateClosureFlags::FastNewClosureBit::decode(flags)) { 18601cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kFastNewClosureBaseline>( 18611cb0ef41Sopenharmony_ci Constant<SharedFunctionInfo>(0), feedback_cell); 18621cb0ef41Sopenharmony_ci } else { 18631cb0ef41Sopenharmony_ci Runtime::FunctionId function_id = 18641cb0ef41Sopenharmony_ci interpreter::CreateClosureFlags::PretenuredBit::decode(flags) 18651cb0ef41Sopenharmony_ci ? Runtime::kNewClosure_Tenured 18661cb0ef41Sopenharmony_ci : Runtime::kNewClosure; 18671cb0ef41Sopenharmony_ci CallRuntime(function_id, Constant<SharedFunctionInfo>(0), feedback_cell); 18681cb0ef41Sopenharmony_ci } 18691cb0ef41Sopenharmony_ci} 18701cb0ef41Sopenharmony_ci 18711cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateBlockContext() { 18721cb0ef41Sopenharmony_ci CallRuntime(Runtime::kPushBlockContext, Constant<ScopeInfo>(0)); 18731cb0ef41Sopenharmony_ci} 18741cb0ef41Sopenharmony_ci 18751cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateCatchContext() { 18761cb0ef41Sopenharmony_ci CallRuntime(Runtime::kPushCatchContext, 18771cb0ef41Sopenharmony_ci RegisterOperand(0), // exception 18781cb0ef41Sopenharmony_ci Constant<ScopeInfo>(1)); 18791cb0ef41Sopenharmony_ci} 18801cb0ef41Sopenharmony_ci 18811cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateFunctionContext() { 18821cb0ef41Sopenharmony_ci Handle<ScopeInfo> info = Constant<ScopeInfo>(0); 18831cb0ef41Sopenharmony_ci uint32_t slot_count = Uint(1); 18841cb0ef41Sopenharmony_ci if (slot_count < static_cast<uint32_t>( 18851cb0ef41Sopenharmony_ci ConstructorBuiltins::MaximumFunctionContextSlots())) { 18861cb0ef41Sopenharmony_ci DCHECK_EQ(info->scope_type(), ScopeType::FUNCTION_SCOPE); 18871cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kFastNewFunctionContextFunction>(info, slot_count); 18881cb0ef41Sopenharmony_ci } else { 18891cb0ef41Sopenharmony_ci CallRuntime(Runtime::kNewFunctionContext, Constant<ScopeInfo>(0)); 18901cb0ef41Sopenharmony_ci } 18911cb0ef41Sopenharmony_ci} 18921cb0ef41Sopenharmony_ci 18931cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateEvalContext() { 18941cb0ef41Sopenharmony_ci Handle<ScopeInfo> info = Constant<ScopeInfo>(0); 18951cb0ef41Sopenharmony_ci uint32_t slot_count = Uint(1); 18961cb0ef41Sopenharmony_ci if (slot_count < static_cast<uint32_t>( 18971cb0ef41Sopenharmony_ci ConstructorBuiltins::MaximumFunctionContextSlots())) { 18981cb0ef41Sopenharmony_ci DCHECK_EQ(info->scope_type(), ScopeType::EVAL_SCOPE); 18991cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kFastNewFunctionContextEval>(info, slot_count); 19001cb0ef41Sopenharmony_ci } else { 19011cb0ef41Sopenharmony_ci CallRuntime(Runtime::kNewFunctionContext, Constant<ScopeInfo>(0)); 19021cb0ef41Sopenharmony_ci } 19031cb0ef41Sopenharmony_ci} 19041cb0ef41Sopenharmony_ci 19051cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateWithContext() { 19061cb0ef41Sopenharmony_ci CallRuntime(Runtime::kPushWithContext, 19071cb0ef41Sopenharmony_ci RegisterOperand(0), // object 19081cb0ef41Sopenharmony_ci Constant<ScopeInfo>(1)); 19091cb0ef41Sopenharmony_ci} 19101cb0ef41Sopenharmony_ci 19111cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateMappedArguments() { 19121cb0ef41Sopenharmony_ci if (shared_function_info_->has_duplicate_parameters()) { 19131cb0ef41Sopenharmony_ci CallRuntime(Runtime::kNewSloppyArguments, __ FunctionOperand()); 19141cb0ef41Sopenharmony_ci } else { 19151cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kFastNewSloppyArguments>(__ FunctionOperand()); 19161cb0ef41Sopenharmony_ci } 19171cb0ef41Sopenharmony_ci} 19181cb0ef41Sopenharmony_ci 19191cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateUnmappedArguments() { 19201cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kFastNewStrictArguments>(__ FunctionOperand()); 19211cb0ef41Sopenharmony_ci} 19221cb0ef41Sopenharmony_ci 19231cb0ef41Sopenharmony_civoid BaselineCompiler::VisitCreateRestParameter() { 19241cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kFastNewRestArguments>(__ FunctionOperand()); 19251cb0ef41Sopenharmony_ci} 19261cb0ef41Sopenharmony_ci 19271cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpLoop() { 19281cb0ef41Sopenharmony_ci Label osr_not_armed, osr; 19291cb0ef41Sopenharmony_ci { 19301cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scope(&basm_); 19311cb0ef41Sopenharmony_ci Register osr_urgency_and_install_target = scope.AcquireScratch(); 19321cb0ef41Sopenharmony_ci 19331cb0ef41Sopenharmony_ci ASM_CODE_COMMENT_STRING(&masm_, "OSR Check Armed"); 19341cb0ef41Sopenharmony_ci __ LoadRegister(osr_urgency_and_install_target, 19351cb0ef41Sopenharmony_ci interpreter::Register::bytecode_array()); 19361cb0ef41Sopenharmony_ci __ LoadWord16FieldZeroExtend( 19371cb0ef41Sopenharmony_ci osr_urgency_and_install_target, osr_urgency_and_install_target, 19381cb0ef41Sopenharmony_ci BytecodeArray::kOsrUrgencyAndInstallTargetOffset); 19391cb0ef41Sopenharmony_ci int loop_depth = iterator().GetImmediateOperand(1); 19401cb0ef41Sopenharmony_ci __ JumpIfImmediate(Condition::kUnsignedLessThanEqual, 19411cb0ef41Sopenharmony_ci osr_urgency_and_install_target, loop_depth, 19421cb0ef41Sopenharmony_ci &osr_not_armed, Label::kNear); 19431cb0ef41Sopenharmony_ci 19441cb0ef41Sopenharmony_ci // TODO(jgruber): Move the extended checks into the 19451cb0ef41Sopenharmony_ci // BaselineOnStackReplacement builtin. 19461cb0ef41Sopenharmony_ci 19471cb0ef41Sopenharmony_ci // OSR based on urgency, i.e. is the OSR urgency greater than the current 19481cb0ef41Sopenharmony_ci // loop depth? 19491cb0ef41Sopenharmony_ci STATIC_ASSERT(BytecodeArray::OsrUrgencyBits::kShift == 0); 19501cb0ef41Sopenharmony_ci Register scratch2 = scope.AcquireScratch(); 19511cb0ef41Sopenharmony_ci __ Word32And(scratch2, osr_urgency_and_install_target, 19521cb0ef41Sopenharmony_ci BytecodeArray::OsrUrgencyBits::kMask); 19531cb0ef41Sopenharmony_ci __ JumpIfImmediate(Condition::kUnsignedGreaterThan, scratch2, loop_depth, 19541cb0ef41Sopenharmony_ci &osr, Label::kNear); 19551cb0ef41Sopenharmony_ci 19561cb0ef41Sopenharmony_ci // OSR based on the install target offset, i.e. does the current bytecode 19571cb0ef41Sopenharmony_ci // offset match the install target offset? 19581cb0ef41Sopenharmony_ci static constexpr int kShift = BytecodeArray::OsrInstallTargetBits::kShift; 19591cb0ef41Sopenharmony_ci static constexpr int kMask = BytecodeArray::OsrInstallTargetBits::kMask; 19601cb0ef41Sopenharmony_ci const int encoded_current_offset = 19611cb0ef41Sopenharmony_ci BytecodeArray::OsrInstallTargetFor( 19621cb0ef41Sopenharmony_ci BytecodeOffset{iterator().current_offset()}) 19631cb0ef41Sopenharmony_ci << kShift; 19641cb0ef41Sopenharmony_ci __ Word32And(scratch2, osr_urgency_and_install_target, kMask); 19651cb0ef41Sopenharmony_ci __ JumpIfImmediate(Condition::kNotEqual, scratch2, encoded_current_offset, 19661cb0ef41Sopenharmony_ci &osr_not_armed, Label::kNear); 19671cb0ef41Sopenharmony_ci } 19681cb0ef41Sopenharmony_ci 19691cb0ef41Sopenharmony_ci __ Bind(&osr); 19701cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kBaselineOnStackReplacement>(); 19711cb0ef41Sopenharmony_ci 19721cb0ef41Sopenharmony_ci __ Bind(&osr_not_armed); 19731cb0ef41Sopenharmony_ci Label* label = &labels_[iterator().GetJumpTargetOffset()]->unlinked; 19741cb0ef41Sopenharmony_ci int weight = iterator().GetRelativeJumpTargetOffset() - 19751cb0ef41Sopenharmony_ci iterator().current_bytecode_size_without_prefix(); 19761cb0ef41Sopenharmony_ci // We can pass in the same label twice since it's a back edge and thus already 19771cb0ef41Sopenharmony_ci // bound. 19781cb0ef41Sopenharmony_ci DCHECK(label->is_bound()); 19791cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndJumpToLabel(weight, label, label); 19801cb0ef41Sopenharmony_ci} 19811cb0ef41Sopenharmony_ci 19821cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJump() { 19831cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJump(); 19841cb0ef41Sopenharmony_ci} 19851cb0ef41Sopenharmony_ci 19861cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpConstant() { VisitJump(); } 19871cb0ef41Sopenharmony_ci 19881cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfNullConstant() { VisitJumpIfNull(); } 19891cb0ef41Sopenharmony_ci 19901cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfNotNullConstant() { VisitJumpIfNotNull(); } 19911cb0ef41Sopenharmony_ci 19921cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfUndefinedConstant() { 19931cb0ef41Sopenharmony_ci VisitJumpIfUndefined(); 19941cb0ef41Sopenharmony_ci} 19951cb0ef41Sopenharmony_ci 19961cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfNotUndefinedConstant() { 19971cb0ef41Sopenharmony_ci VisitJumpIfNotUndefined(); 19981cb0ef41Sopenharmony_ci} 19991cb0ef41Sopenharmony_ci 20001cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfUndefinedOrNullConstant() { 20011cb0ef41Sopenharmony_ci VisitJumpIfUndefinedOrNull(); 20021cb0ef41Sopenharmony_ci} 20031cb0ef41Sopenharmony_ci 20041cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfTrueConstant() { VisitJumpIfTrue(); } 20051cb0ef41Sopenharmony_ci 20061cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfFalseConstant() { VisitJumpIfFalse(); } 20071cb0ef41Sopenharmony_ci 20081cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfJSReceiverConstant() { 20091cb0ef41Sopenharmony_ci VisitJumpIfJSReceiver(); 20101cb0ef41Sopenharmony_ci} 20111cb0ef41Sopenharmony_ci 20121cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfToBooleanTrueConstant() { 20131cb0ef41Sopenharmony_ci VisitJumpIfToBooleanTrue(); 20141cb0ef41Sopenharmony_ci} 20151cb0ef41Sopenharmony_ci 20161cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfToBooleanFalseConstant() { 20171cb0ef41Sopenharmony_ci VisitJumpIfToBooleanFalse(); 20181cb0ef41Sopenharmony_ci} 20191cb0ef41Sopenharmony_ci 20201cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfToBooleanTrue() { 20211cb0ef41Sopenharmony_ci Label dont_jump; 20221cb0ef41Sopenharmony_ci JumpIfToBoolean(false, &dont_jump, Label::kNear); 20231cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJump(); 20241cb0ef41Sopenharmony_ci __ Bind(&dont_jump); 20251cb0ef41Sopenharmony_ci} 20261cb0ef41Sopenharmony_ci 20271cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfToBooleanFalse() { 20281cb0ef41Sopenharmony_ci Label dont_jump; 20291cb0ef41Sopenharmony_ci JumpIfToBoolean(true, &dont_jump, Label::kNear); 20301cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJump(); 20311cb0ef41Sopenharmony_ci __ Bind(&dont_jump); 20321cb0ef41Sopenharmony_ci} 20331cb0ef41Sopenharmony_ci 20341cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfTrue() { 20351cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJumpIfRoot(RootIndex::kTrueValue); 20361cb0ef41Sopenharmony_ci} 20371cb0ef41Sopenharmony_ci 20381cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfFalse() { 20391cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJumpIfRoot(RootIndex::kFalseValue); 20401cb0ef41Sopenharmony_ci} 20411cb0ef41Sopenharmony_ci 20421cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfNull() { 20431cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJumpIfRoot(RootIndex::kNullValue); 20441cb0ef41Sopenharmony_ci} 20451cb0ef41Sopenharmony_ci 20461cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfNotNull() { 20471cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJumpIfNotRoot(RootIndex::kNullValue); 20481cb0ef41Sopenharmony_ci} 20491cb0ef41Sopenharmony_ci 20501cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfUndefined() { 20511cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJumpIfRoot(RootIndex::kUndefinedValue); 20521cb0ef41Sopenharmony_ci} 20531cb0ef41Sopenharmony_ci 20541cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfNotUndefined() { 20551cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJumpIfNotRoot( 20561cb0ef41Sopenharmony_ci RootIndex::kUndefinedValue); 20571cb0ef41Sopenharmony_ci} 20581cb0ef41Sopenharmony_ci 20591cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfUndefinedOrNull() { 20601cb0ef41Sopenharmony_ci Label do_jump, dont_jump; 20611cb0ef41Sopenharmony_ci __ JumpIfRoot(kInterpreterAccumulatorRegister, RootIndex::kUndefinedValue, 20621cb0ef41Sopenharmony_ci &do_jump); 20631cb0ef41Sopenharmony_ci __ JumpIfNotRoot(kInterpreterAccumulatorRegister, RootIndex::kNullValue, 20641cb0ef41Sopenharmony_ci &dont_jump, Label::kNear); 20651cb0ef41Sopenharmony_ci __ Bind(&do_jump); 20661cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJump(); 20671cb0ef41Sopenharmony_ci __ Bind(&dont_jump); 20681cb0ef41Sopenharmony_ci} 20691cb0ef41Sopenharmony_ci 20701cb0ef41Sopenharmony_civoid BaselineCompiler::VisitJumpIfJSReceiver() { 20711cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 20721cb0ef41Sopenharmony_ci 20731cb0ef41Sopenharmony_ci Label is_smi, dont_jump; 20741cb0ef41Sopenharmony_ci __ JumpIfSmi(kInterpreterAccumulatorRegister, &is_smi, Label::kNear); 20751cb0ef41Sopenharmony_ci 20761cb0ef41Sopenharmony_ci __ JumpIfObjectType(Condition::kLessThan, kInterpreterAccumulatorRegister, 20771cb0ef41Sopenharmony_ci FIRST_JS_RECEIVER_TYPE, scratch_scope.AcquireScratch(), 20781cb0ef41Sopenharmony_ci &dont_jump); 20791cb0ef41Sopenharmony_ci UpdateInterruptBudgetAndDoInterpreterJump(); 20801cb0ef41Sopenharmony_ci 20811cb0ef41Sopenharmony_ci __ Bind(&is_smi); 20821cb0ef41Sopenharmony_ci __ Bind(&dont_jump); 20831cb0ef41Sopenharmony_ci} 20841cb0ef41Sopenharmony_ci 20851cb0ef41Sopenharmony_civoid BaselineCompiler::VisitSwitchOnSmiNoFeedback() { 20861cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 20871cb0ef41Sopenharmony_ci interpreter::JumpTableTargetOffsets offsets = 20881cb0ef41Sopenharmony_ci iterator().GetJumpTableTargetOffsets(); 20891cb0ef41Sopenharmony_ci 20901cb0ef41Sopenharmony_ci if (offsets.size() == 0) return; 20911cb0ef41Sopenharmony_ci 20921cb0ef41Sopenharmony_ci int case_value_base = (*offsets.begin()).case_value; 20931cb0ef41Sopenharmony_ci 20941cb0ef41Sopenharmony_ci std::unique_ptr<Label*[]> labels = std::make_unique<Label*[]>(offsets.size()); 20951cb0ef41Sopenharmony_ci for (interpreter::JumpTableTargetOffset offset : offsets) { 20961cb0ef41Sopenharmony_ci labels[offset.case_value - case_value_base] = 20971cb0ef41Sopenharmony_ci &EnsureLabels(offset.target_offset)->unlinked; 20981cb0ef41Sopenharmony_ci } 20991cb0ef41Sopenharmony_ci Register case_value = scratch_scope.AcquireScratch(); 21001cb0ef41Sopenharmony_ci __ SmiUntag(case_value, kInterpreterAccumulatorRegister); 21011cb0ef41Sopenharmony_ci __ Switch(case_value, case_value_base, labels.get(), offsets.size()); 21021cb0ef41Sopenharmony_ci} 21031cb0ef41Sopenharmony_ci 21041cb0ef41Sopenharmony_civoid BaselineCompiler::VisitForInEnumerate() { 21051cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kForInEnumerate>(RegisterOperand(0)); 21061cb0ef41Sopenharmony_ci} 21071cb0ef41Sopenharmony_ci 21081cb0ef41Sopenharmony_civoid BaselineCompiler::VisitForInPrepare() { 21091cb0ef41Sopenharmony_ci StoreRegister(0, kInterpreterAccumulatorRegister); 21101cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kForInPrepare>(kInterpreterAccumulatorRegister, 21111cb0ef41Sopenharmony_ci IndexAsTagged(1), FeedbackVector()); 21121cb0ef41Sopenharmony_ci interpreter::Register first = iterator().GetRegisterOperand(0); 21131cb0ef41Sopenharmony_ci interpreter::Register second(first.index() + 1); 21141cb0ef41Sopenharmony_ci interpreter::Register third(first.index() + 2); 21151cb0ef41Sopenharmony_ci __ StoreRegister(second, kReturnRegister0); 21161cb0ef41Sopenharmony_ci __ StoreRegister(third, kReturnRegister1); 21171cb0ef41Sopenharmony_ci} 21181cb0ef41Sopenharmony_ci 21191cb0ef41Sopenharmony_civoid BaselineCompiler::VisitForInContinue() { 21201cb0ef41Sopenharmony_ci SelectBooleanConstant(kInterpreterAccumulatorRegister, 21211cb0ef41Sopenharmony_ci [&](Label* is_true, Label::Distance distance) { 21221cb0ef41Sopenharmony_ci LoadRegister(kInterpreterAccumulatorRegister, 0); 21231cb0ef41Sopenharmony_ci __ JumpIfTagged( 21241cb0ef41Sopenharmony_ci Condition::kNotEqual, 21251cb0ef41Sopenharmony_ci kInterpreterAccumulatorRegister, 21261cb0ef41Sopenharmony_ci __ RegisterFrameOperand(RegisterOperand(1)), 21271cb0ef41Sopenharmony_ci is_true, distance); 21281cb0ef41Sopenharmony_ci }); 21291cb0ef41Sopenharmony_ci} 21301cb0ef41Sopenharmony_ci 21311cb0ef41Sopenharmony_civoid BaselineCompiler::VisitForInNext() { 21321cb0ef41Sopenharmony_ci interpreter::Register cache_type, cache_array; 21331cb0ef41Sopenharmony_ci std::tie(cache_type, cache_array) = iterator().GetRegisterPairOperand(2); 21341cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kForInNext>(Index(3), // vector slot 21351cb0ef41Sopenharmony_ci RegisterOperand(0), // object 21361cb0ef41Sopenharmony_ci cache_array, // cache array 21371cb0ef41Sopenharmony_ci cache_type, // cache type 21381cb0ef41Sopenharmony_ci RegisterOperand(1), // index 21391cb0ef41Sopenharmony_ci FeedbackVector()); // feedback vector 21401cb0ef41Sopenharmony_ci} 21411cb0ef41Sopenharmony_ci 21421cb0ef41Sopenharmony_civoid BaselineCompiler::VisitForInStep() { 21431cb0ef41Sopenharmony_ci LoadRegister(kInterpreterAccumulatorRegister, 0); 21441cb0ef41Sopenharmony_ci __ AddSmi(kInterpreterAccumulatorRegister, Smi::FromInt(1)); 21451cb0ef41Sopenharmony_ci} 21461cb0ef41Sopenharmony_ci 21471cb0ef41Sopenharmony_civoid BaselineCompiler::VisitSetPendingMessage() { 21481cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 21491cb0ef41Sopenharmony_ci Register pending_message = scratch_scope.AcquireScratch(); 21501cb0ef41Sopenharmony_ci __ Move(pending_message, 21511cb0ef41Sopenharmony_ci ExternalReference::address_of_pending_message(local_isolate_)); 21521cb0ef41Sopenharmony_ci Register tmp = scratch_scope.AcquireScratch(); 21531cb0ef41Sopenharmony_ci __ Move(tmp, kInterpreterAccumulatorRegister); 21541cb0ef41Sopenharmony_ci __ Move(kInterpreterAccumulatorRegister, MemOperand(pending_message, 0)); 21551cb0ef41Sopenharmony_ci __ Move(MemOperand(pending_message, 0), tmp); 21561cb0ef41Sopenharmony_ci} 21571cb0ef41Sopenharmony_ci 21581cb0ef41Sopenharmony_civoid BaselineCompiler::VisitThrow() { 21591cb0ef41Sopenharmony_ci CallRuntime(Runtime::kThrow, kInterpreterAccumulatorRegister); 21601cb0ef41Sopenharmony_ci __ Trap(); 21611cb0ef41Sopenharmony_ci} 21621cb0ef41Sopenharmony_ci 21631cb0ef41Sopenharmony_civoid BaselineCompiler::VisitReThrow() { 21641cb0ef41Sopenharmony_ci CallRuntime(Runtime::kReThrow, kInterpreterAccumulatorRegister); 21651cb0ef41Sopenharmony_ci __ Trap(); 21661cb0ef41Sopenharmony_ci} 21671cb0ef41Sopenharmony_ci 21681cb0ef41Sopenharmony_civoid BaselineCompiler::VisitReturn() { 21691cb0ef41Sopenharmony_ci ASM_CODE_COMMENT_STRING(&masm_, "Return"); 21701cb0ef41Sopenharmony_ci int profiling_weight = iterator().current_offset() + 21711cb0ef41Sopenharmony_ci iterator().current_bytecode_size_without_prefix(); 21721cb0ef41Sopenharmony_ci int parameter_count = bytecode_->parameter_count(); 21731cb0ef41Sopenharmony_ci 21741cb0ef41Sopenharmony_ci TailCallBuiltin<Builtin::kBaselineLeaveFrame>(parameter_count, 21751cb0ef41Sopenharmony_ci -profiling_weight); 21761cb0ef41Sopenharmony_ci} 21771cb0ef41Sopenharmony_ci 21781cb0ef41Sopenharmony_civoid BaselineCompiler::VisitThrowReferenceErrorIfHole() { 21791cb0ef41Sopenharmony_ci Label done; 21801cb0ef41Sopenharmony_ci __ JumpIfNotRoot(kInterpreterAccumulatorRegister, RootIndex::kTheHoleValue, 21811cb0ef41Sopenharmony_ci &done); 21821cb0ef41Sopenharmony_ci CallRuntime(Runtime::kThrowAccessedUninitializedVariable, Constant<Name>(0)); 21831cb0ef41Sopenharmony_ci // Unreachable. 21841cb0ef41Sopenharmony_ci __ Trap(); 21851cb0ef41Sopenharmony_ci __ Bind(&done); 21861cb0ef41Sopenharmony_ci} 21871cb0ef41Sopenharmony_ci 21881cb0ef41Sopenharmony_civoid BaselineCompiler::VisitThrowSuperNotCalledIfHole() { 21891cb0ef41Sopenharmony_ci Label done; 21901cb0ef41Sopenharmony_ci __ JumpIfNotRoot(kInterpreterAccumulatorRegister, RootIndex::kTheHoleValue, 21911cb0ef41Sopenharmony_ci &done); 21921cb0ef41Sopenharmony_ci CallRuntime(Runtime::kThrowSuperNotCalled); 21931cb0ef41Sopenharmony_ci // Unreachable. 21941cb0ef41Sopenharmony_ci __ Trap(); 21951cb0ef41Sopenharmony_ci __ Bind(&done); 21961cb0ef41Sopenharmony_ci} 21971cb0ef41Sopenharmony_ci 21981cb0ef41Sopenharmony_civoid BaselineCompiler::VisitThrowSuperAlreadyCalledIfNotHole() { 21991cb0ef41Sopenharmony_ci Label done; 22001cb0ef41Sopenharmony_ci __ JumpIfRoot(kInterpreterAccumulatorRegister, RootIndex::kTheHoleValue, 22011cb0ef41Sopenharmony_ci &done); 22021cb0ef41Sopenharmony_ci CallRuntime(Runtime::kThrowSuperAlreadyCalledError); 22031cb0ef41Sopenharmony_ci // Unreachable. 22041cb0ef41Sopenharmony_ci __ Trap(); 22051cb0ef41Sopenharmony_ci __ Bind(&done); 22061cb0ef41Sopenharmony_ci} 22071cb0ef41Sopenharmony_ci 22081cb0ef41Sopenharmony_civoid BaselineCompiler::VisitThrowIfNotSuperConstructor() { 22091cb0ef41Sopenharmony_ci Label done; 22101cb0ef41Sopenharmony_ci 22111cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 22121cb0ef41Sopenharmony_ci Register reg = scratch_scope.AcquireScratch(); 22131cb0ef41Sopenharmony_ci LoadRegister(reg, 0); 22141cb0ef41Sopenharmony_ci Register map_bit_field = scratch_scope.AcquireScratch(); 22151cb0ef41Sopenharmony_ci __ LoadMap(map_bit_field, reg); 22161cb0ef41Sopenharmony_ci __ LoadWord8Field(map_bit_field, map_bit_field, Map::kBitFieldOffset); 22171cb0ef41Sopenharmony_ci __ TestAndBranch(map_bit_field, Map::Bits1::IsConstructorBit::kMask, 22181cb0ef41Sopenharmony_ci Condition::kNotZero, &done, Label::kNear); 22191cb0ef41Sopenharmony_ci 22201cb0ef41Sopenharmony_ci CallRuntime(Runtime::kThrowNotSuperConstructor, reg, __ FunctionOperand()); 22211cb0ef41Sopenharmony_ci 22221cb0ef41Sopenharmony_ci __ Bind(&done); 22231cb0ef41Sopenharmony_ci} 22241cb0ef41Sopenharmony_ci 22251cb0ef41Sopenharmony_civoid BaselineCompiler::VisitSwitchOnGeneratorState() { 22261cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 22271cb0ef41Sopenharmony_ci 22281cb0ef41Sopenharmony_ci Label fallthrough; 22291cb0ef41Sopenharmony_ci 22301cb0ef41Sopenharmony_ci Register generator_object = scratch_scope.AcquireScratch(); 22311cb0ef41Sopenharmony_ci LoadRegister(generator_object, 0); 22321cb0ef41Sopenharmony_ci __ JumpIfRoot(generator_object, RootIndex::kUndefinedValue, &fallthrough); 22331cb0ef41Sopenharmony_ci 22341cb0ef41Sopenharmony_ci Register continuation = scratch_scope.AcquireScratch(); 22351cb0ef41Sopenharmony_ci __ LoadTaggedAnyField(continuation, generator_object, 22361cb0ef41Sopenharmony_ci JSGeneratorObject::kContinuationOffset); 22371cb0ef41Sopenharmony_ci __ StoreTaggedSignedField( 22381cb0ef41Sopenharmony_ci generator_object, JSGeneratorObject::kContinuationOffset, 22391cb0ef41Sopenharmony_ci Smi::FromInt(JSGeneratorObject::kGeneratorExecuting)); 22401cb0ef41Sopenharmony_ci 22411cb0ef41Sopenharmony_ci Register context = scratch_scope.AcquireScratch(); 22421cb0ef41Sopenharmony_ci __ LoadTaggedAnyField(context, generator_object, 22431cb0ef41Sopenharmony_ci JSGeneratorObject::kContextOffset); 22441cb0ef41Sopenharmony_ci __ StoreContext(context); 22451cb0ef41Sopenharmony_ci 22461cb0ef41Sopenharmony_ci interpreter::JumpTableTargetOffsets offsets = 22471cb0ef41Sopenharmony_ci iterator().GetJumpTableTargetOffsets(); 22481cb0ef41Sopenharmony_ci 22491cb0ef41Sopenharmony_ci if (0 < offsets.size()) { 22501cb0ef41Sopenharmony_ci DCHECK_EQ(0, (*offsets.begin()).case_value); 22511cb0ef41Sopenharmony_ci 22521cb0ef41Sopenharmony_ci std::unique_ptr<Label*[]> labels = 22531cb0ef41Sopenharmony_ci std::make_unique<Label*[]>(offsets.size()); 22541cb0ef41Sopenharmony_ci for (interpreter::JumpTableTargetOffset offset : offsets) { 22551cb0ef41Sopenharmony_ci labels[offset.case_value] = &EnsureLabels(offset.target_offset)->unlinked; 22561cb0ef41Sopenharmony_ci } 22571cb0ef41Sopenharmony_ci __ SmiUntag(continuation); 22581cb0ef41Sopenharmony_ci __ Switch(continuation, 0, labels.get(), offsets.size()); 22591cb0ef41Sopenharmony_ci // We should never fall through this switch. 22601cb0ef41Sopenharmony_ci // TODO(v8:11429,leszeks): Maybe remove the fallthrough check in the Switch? 22611cb0ef41Sopenharmony_ci __ Trap(); 22621cb0ef41Sopenharmony_ci } 22631cb0ef41Sopenharmony_ci 22641cb0ef41Sopenharmony_ci __ Bind(&fallthrough); 22651cb0ef41Sopenharmony_ci} 22661cb0ef41Sopenharmony_ci 22671cb0ef41Sopenharmony_civoid BaselineCompiler::VisitSuspendGenerator() { 22681cb0ef41Sopenharmony_ci DCHECK_EQ(iterator().GetRegisterOperand(1), interpreter::Register(0)); 22691cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 22701cb0ef41Sopenharmony_ci Register generator_object = scratch_scope.AcquireScratch(); 22711cb0ef41Sopenharmony_ci LoadRegister(generator_object, 0); 22721cb0ef41Sopenharmony_ci { 22731cb0ef41Sopenharmony_ci SaveAccumulatorScope accumulator_scope(&basm_); 22741cb0ef41Sopenharmony_ci 22751cb0ef41Sopenharmony_ci int bytecode_offset = 22761cb0ef41Sopenharmony_ci BytecodeArray::kHeaderSize + iterator().current_offset(); 22771cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kSuspendGeneratorBaseline>( 22781cb0ef41Sopenharmony_ci generator_object, 22791cb0ef41Sopenharmony_ci static_cast<int>(Uint(3)), // suspend_id 22801cb0ef41Sopenharmony_ci bytecode_offset, 22811cb0ef41Sopenharmony_ci static_cast<int>(RegisterCount(2))); // register_count 22821cb0ef41Sopenharmony_ci } 22831cb0ef41Sopenharmony_ci VisitReturn(); 22841cb0ef41Sopenharmony_ci} 22851cb0ef41Sopenharmony_ci 22861cb0ef41Sopenharmony_civoid BaselineCompiler::VisitResumeGenerator() { 22871cb0ef41Sopenharmony_ci DCHECK_EQ(iterator().GetRegisterOperand(1), interpreter::Register(0)); 22881cb0ef41Sopenharmony_ci BaselineAssembler::ScratchRegisterScope scratch_scope(&basm_); 22891cb0ef41Sopenharmony_ci Register generator_object = scratch_scope.AcquireScratch(); 22901cb0ef41Sopenharmony_ci LoadRegister(generator_object, 0); 22911cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kResumeGeneratorBaseline>( 22921cb0ef41Sopenharmony_ci generator_object, 22931cb0ef41Sopenharmony_ci static_cast<int>(RegisterCount(2))); // register_count 22941cb0ef41Sopenharmony_ci} 22951cb0ef41Sopenharmony_ci 22961cb0ef41Sopenharmony_civoid BaselineCompiler::VisitGetIterator() { 22971cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kGetIteratorBaseline>(RegisterOperand(0), // receiver 22981cb0ef41Sopenharmony_ci IndexAsTagged(1), // load_slot 22991cb0ef41Sopenharmony_ci IndexAsTagged(2)); // call_slot 23001cb0ef41Sopenharmony_ci} 23011cb0ef41Sopenharmony_ci 23021cb0ef41Sopenharmony_civoid BaselineCompiler::VisitDebugger() { 23031cb0ef41Sopenharmony_ci SaveAccumulatorScope accumulator_scope(&basm_); 23041cb0ef41Sopenharmony_ci CallRuntime(Runtime::kHandleDebuggerStatement); 23051cb0ef41Sopenharmony_ci} 23061cb0ef41Sopenharmony_ci 23071cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIncBlockCounter() { 23081cb0ef41Sopenharmony_ci SaveAccumulatorScope accumulator_scope(&basm_); 23091cb0ef41Sopenharmony_ci CallBuiltin<Builtin::kIncBlockCounter>(__ FunctionOperand(), 23101cb0ef41Sopenharmony_ci IndexAsSmi(0)); // coverage array slot 23111cb0ef41Sopenharmony_ci} 23121cb0ef41Sopenharmony_ci 23131cb0ef41Sopenharmony_civoid BaselineCompiler::VisitAbort() { 23141cb0ef41Sopenharmony_ci CallRuntime(Runtime::kAbort, Smi::FromInt(Index(0))); 23151cb0ef41Sopenharmony_ci __ Trap(); 23161cb0ef41Sopenharmony_ci} 23171cb0ef41Sopenharmony_ci 23181cb0ef41Sopenharmony_civoid BaselineCompiler::VisitWide() { 23191cb0ef41Sopenharmony_ci // Consumed by the BytecodeArrayIterator. 23201cb0ef41Sopenharmony_ci UNREACHABLE(); 23211cb0ef41Sopenharmony_ci} 23221cb0ef41Sopenharmony_ci 23231cb0ef41Sopenharmony_civoid BaselineCompiler::VisitExtraWide() { 23241cb0ef41Sopenharmony_ci // Consumed by the BytecodeArrayIterator. 23251cb0ef41Sopenharmony_ci UNREACHABLE(); 23261cb0ef41Sopenharmony_ci} 23271cb0ef41Sopenharmony_ci 23281cb0ef41Sopenharmony_civoid BaselineCompiler::VisitIllegal() { 23291cb0ef41Sopenharmony_ci // Not emitted in valid bytecode. 23301cb0ef41Sopenharmony_ci UNREACHABLE(); 23311cb0ef41Sopenharmony_ci} 23321cb0ef41Sopenharmony_ci#define DEBUG_BREAK(Name, ...) \ 23331cb0ef41Sopenharmony_ci void BaselineCompiler::Visit##Name() { UNREACHABLE(); } 23341cb0ef41Sopenharmony_ciDEBUG_BREAK_BYTECODE_LIST(DEBUG_BREAK) 23351cb0ef41Sopenharmony_ci#undef DEBUG_BREAK 23361cb0ef41Sopenharmony_ci 23371cb0ef41Sopenharmony_ci} // namespace baseline 23381cb0ef41Sopenharmony_ci} // namespace internal 23391cb0ef41Sopenharmony_ci} // namespace v8 23401cb0ef41Sopenharmony_ci 23411cb0ef41Sopenharmony_ci#endif // ENABLE_SPARKPLUG 2342