14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci#include "ecmascript/compiler/native_inline_lowering.h"
164514f5e3Sopenharmony_ci#include "ecmascript/builtins/builtins_number.h"
174514f5e3Sopenharmony_ci#include "ecmascript/builtins/builtins_string.h"
184514f5e3Sopenharmony_ci#include "ecmascript/base/number_helper.h"
194514f5e3Sopenharmony_ci#include "ecmascript/compiler/circuit.h"
204514f5e3Sopenharmony_ci#include "ecmascript/compiler/circuit_builder-inl.h"
214514f5e3Sopenharmony_ci#include "ecmascript/compiler/circuit_builder_helper.h"
224514f5e3Sopenharmony_ci#include "ecmascript/compiler/share_gate_meta_data.h"
234514f5e3Sopenharmony_ci#include "ecmascript/js_dataview.h"
244514f5e3Sopenharmony_ci#include "ecmascript/compiler/circuit.h"
254514f5e3Sopenharmony_ci#include "ecmascript/compiler/new_object_stub_builder.h"
264514f5e3Sopenharmony_ci#include "ecmascript/global_env.h"
274514f5e3Sopenharmony_ci#include "ecmascript/js_iterator.h"
284514f5e3Sopenharmony_ci#include "ecmascript/js_thread.h"
294514f5e3Sopenharmony_ci#include "ecmascript/message_string.h"
304514f5e3Sopenharmony_ci
314514f5e3Sopenharmony_cinamespace panda::ecmascript::kungfu {
324514f5e3Sopenharmony_ci
334514f5e3Sopenharmony_cistd::optional<std::pair<size_t, bool>> NativeInlineLowering::GetCallInfo(GateRef gate)
344514f5e3Sopenharmony_ci{
354514f5e3Sopenharmony_ci    EcmaOpcode ecmaOpcode = acc_.GetByteCodeOpcode(gate);
364514f5e3Sopenharmony_ci    switch (ecmaOpcode) {
374514f5e3Sopenharmony_ci        case EcmaOpcode::CALLARG0_IMM8:
384514f5e3Sopenharmony_ci            return {{0U, false}};
394514f5e3Sopenharmony_ci        case EcmaOpcode::CALLTHIS0_IMM8_V8:
404514f5e3Sopenharmony_ci            return {{0U, true}};
414514f5e3Sopenharmony_ci        case EcmaOpcode::CALLARG1_IMM8_V8:
424514f5e3Sopenharmony_ci            return {{1U, false}};
434514f5e3Sopenharmony_ci        case EcmaOpcode::CALLTHIS1_IMM8_V8_V8:
444514f5e3Sopenharmony_ci            return {{1U, true}};
454514f5e3Sopenharmony_ci        case EcmaOpcode::CALLARGS2_IMM8_V8_V8:
464514f5e3Sopenharmony_ci            return {{2U, false}};
474514f5e3Sopenharmony_ci        case EcmaOpcode::CALLTHIS2_IMM8_V8_V8_V8:
484514f5e3Sopenharmony_ci            return {{2U, true}};
494514f5e3Sopenharmony_ci        case EcmaOpcode::CALLARGS3_IMM8_V8_V8_V8:
504514f5e3Sopenharmony_ci            return {{3U, false}};
514514f5e3Sopenharmony_ci        case EcmaOpcode::CALLTHIS3_IMM8_V8_V8_V8_V8:
524514f5e3Sopenharmony_ci            return {{3U, true}};
534514f5e3Sopenharmony_ci        case EcmaOpcode::CALLRANGE_IMM8_IMM8_V8: {
544514f5e3Sopenharmony_ci            CallRangeTypeInfoAccessor tia(compilationEnv_, circuit_, gate);
554514f5e3Sopenharmony_ci            return {{tia.GetArgc(), false}};
564514f5e3Sopenharmony_ci        }
574514f5e3Sopenharmony_ci        case EcmaOpcode::CALLTHISRANGE_IMM8_IMM8_V8: {
584514f5e3Sopenharmony_ci            CallThisRangeTypeInfoAccessor tia(compilationEnv_, circuit_, gate);
594514f5e3Sopenharmony_ci            return {{tia.GetArgc(), true}};
604514f5e3Sopenharmony_ci        }
614514f5e3Sopenharmony_ci        default:
624514f5e3Sopenharmony_ci            return std::nullopt;
634514f5e3Sopenharmony_ci    }
644514f5e3Sopenharmony_ci}
654514f5e3Sopenharmony_ci
664514f5e3Sopenharmony_civoid NativeInlineLowering::RunNativeInlineLowering()
674514f5e3Sopenharmony_ci{
684514f5e3Sopenharmony_ci    std::vector<GateRef> gateList;
694514f5e3Sopenharmony_ci    circuit_->GetAllGates(gateList);
704514f5e3Sopenharmony_ci    for (const auto &gate : gateList) {
714514f5e3Sopenharmony_ci        auto op = acc_.GetOpCode(gate);
724514f5e3Sopenharmony_ci        if (op != OpCode::JS_BYTECODE) {
734514f5e3Sopenharmony_ci            continue;
744514f5e3Sopenharmony_ci        }
754514f5e3Sopenharmony_ci        auto optCallInfo = GetCallInfo(gate);
764514f5e3Sopenharmony_ci        if (!optCallInfo) {
774514f5e3Sopenharmony_ci            continue;
784514f5e3Sopenharmony_ci        }
794514f5e3Sopenharmony_ci        auto [argc, skipThis] = optCallInfo.value();
804514f5e3Sopenharmony_ci        CallTypeInfoAccessor ctia(compilationEnv_, circuit_, gate);
814514f5e3Sopenharmony_ci        BuiltinsStubCSigns::ID id = ctia.TryGetPGOBuiltinMethodId();
824514f5e3Sopenharmony_ci        if (IS_INVALID_ID(id) && id != BuiltinsStubCSigns::ID::BigIntConstructor) {
834514f5e3Sopenharmony_ci            continue;
844514f5e3Sopenharmony_ci        }
854514f5e3Sopenharmony_ci        switch (id) {
864514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::StringFromCharCode:
874514f5e3Sopenharmony_ci                TryInlineStringFromCharCode(gate, argc, skipThis);
884514f5e3Sopenharmony_ci                break;
894514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::StringCharCodeAt:
904514f5e3Sopenharmony_ci                TryInlineStringCharCodeAt(gate, argc, skipThis);
914514f5e3Sopenharmony_ci                break;
924514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::StringSubstring:
934514f5e3Sopenharmony_ci                TryInlineStringSubstring(gate, argc, skipThis);
944514f5e3Sopenharmony_ci                break;
954514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::StringSubStr:
964514f5e3Sopenharmony_ci                TryInlineStringSubStr(gate, argc, skipThis);
974514f5e3Sopenharmony_ci                break;
984514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::StringSlice:
994514f5e3Sopenharmony_ci                TryInlineStringSlice(gate, argc, skipThis);
1004514f5e3Sopenharmony_ci                break;
1014514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::NumberIsFinite:
1024514f5e3Sopenharmony_ci                TryInlineNumberIsFinite(gate, argc, skipThis);
1034514f5e3Sopenharmony_ci                break;
1044514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::NumberIsInteger:
1054514f5e3Sopenharmony_ci                TryInlineNumberIsInteger(gate, argc, skipThis);
1064514f5e3Sopenharmony_ci                break;
1074514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::NumberIsNaN:
1084514f5e3Sopenharmony_ci                TryInlineNumberIsNaN(gate, argc, skipThis);
1094514f5e3Sopenharmony_ci                break;
1104514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::NumberParseFloat:
1114514f5e3Sopenharmony_ci                TryInlineNumberParseFloat(gate, argc, skipThis);
1124514f5e3Sopenharmony_ci                break;
1134514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::NumberParseInt:
1144514f5e3Sopenharmony_ci                TryInlineNumberParseInt(gate, argc, skipThis);
1154514f5e3Sopenharmony_ci                break;
1164514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::NumberIsSafeInteger:
1174514f5e3Sopenharmony_ci                TryInlineNumberIsSafeInteger(gate, argc, skipThis);
1184514f5e3Sopenharmony_ci                break;
1194514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::TypedArrayEntries:
1204514f5e3Sopenharmony_ci                TryInlineTypedArrayIteratorBuiltin(gate, id, circuit_->TypedArrayEntries(), skipThis);
1214514f5e3Sopenharmony_ci                break;
1224514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::TypedArrayKeys:
1234514f5e3Sopenharmony_ci                TryInlineTypedArrayIteratorBuiltin(gate, id, circuit_->TypedArrayKeys(), skipThis);
1244514f5e3Sopenharmony_ci                break;
1254514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::TypedArrayValues:
1264514f5e3Sopenharmony_ci                TryInlineTypedArrayIteratorBuiltin(gate, id, circuit_->TypedArrayValues(), skipThis);
1274514f5e3Sopenharmony_ci                break;
1284514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayValues:
1294514f5e3Sopenharmony_ci                TryInlineArrayIterator(gate, id, skipThis);
1304514f5e3Sopenharmony_ci                break;
1314514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayKeys:
1324514f5e3Sopenharmony_ci                TryInlineArrayIterator(gate, id, skipThis);
1334514f5e3Sopenharmony_ci                break;
1344514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayEntries:
1354514f5e3Sopenharmony_ci                TryInlineArrayIterator(gate, id, skipThis);
1364514f5e3Sopenharmony_ci                break;
1374514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathAcos:
1384514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathAcos(), skipThis);
1394514f5e3Sopenharmony_ci                break;
1404514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathAcosh:
1414514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathAcosh(), skipThis);
1424514f5e3Sopenharmony_ci                break;
1434514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathAsin:
1444514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathAsin(), skipThis);
1454514f5e3Sopenharmony_ci                break;
1464514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathAsinh:
1474514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathAsinh(), skipThis);
1484514f5e3Sopenharmony_ci                break;
1494514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathAtan:
1504514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathAtan(), skipThis);
1514514f5e3Sopenharmony_ci                break;
1524514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathAtan2:
1534514f5e3Sopenharmony_ci                TryInlineMathBinaryBuiltin(gate, argc, id, circuit_->MathAtan2(), skipThis);
1544514f5e3Sopenharmony_ci                break;
1554514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathAtanh:
1564514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathAtanh(), skipThis);
1574514f5e3Sopenharmony_ci                break;
1584514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathCos:
1594514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathCos(), skipThis);
1604514f5e3Sopenharmony_ci                break;
1614514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathCosh:
1624514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathCosh(), skipThis);
1634514f5e3Sopenharmony_ci                break;
1644514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathSign:
1654514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathSign(), skipThis);
1664514f5e3Sopenharmony_ci                break;
1674514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathSin:
1684514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathSin(), skipThis);
1694514f5e3Sopenharmony_ci                break;
1704514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathSinh:
1714514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathSinh(), skipThis);
1724514f5e3Sopenharmony_ci                break;
1734514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathSqrt:
1744514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathSqrt(), skipThis);
1754514f5e3Sopenharmony_ci                break;
1764514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathTan:
1774514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathTan(), skipThis);
1784514f5e3Sopenharmony_ci                break;
1794514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathTanh:
1804514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathTanh(), skipThis);
1814514f5e3Sopenharmony_ci                break;
1824514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathTrunc:
1834514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathTrunc(), skipThis);
1844514f5e3Sopenharmony_ci                break;
1854514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathAbs:
1864514f5e3Sopenharmony_ci                TryInlineMathAbsBuiltin(gate, argc, skipThis);
1874514f5e3Sopenharmony_ci                break;
1884514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathLog:
1894514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathLog(), skipThis);
1904514f5e3Sopenharmony_ci                break;
1914514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathLog2:
1924514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathLog2(), skipThis);
1934514f5e3Sopenharmony_ci                break;
1944514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathLog10:
1954514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathLog10(), skipThis);
1964514f5e3Sopenharmony_ci                break;
1974514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathLog1p:
1984514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathLog1p(), skipThis);
1994514f5e3Sopenharmony_ci                break;
2004514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathExp:
2014514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathExp(), skipThis);
2024514f5e3Sopenharmony_ci                break;
2034514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathExpm1:
2044514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathExpm1(), skipThis);
2054514f5e3Sopenharmony_ci                break;
2064514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathClz32:
2074514f5e3Sopenharmony_ci                TryInlineMathClz32Builtin(gate, argc, skipThis);
2084514f5e3Sopenharmony_ci                break;
2094514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathPow:
2104514f5e3Sopenharmony_ci                TryInlineMathBinaryBuiltin(gate, argc, id, circuit_->MathPow(), skipThis);
2114514f5e3Sopenharmony_ci                break;
2124514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathCbrt:
2134514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathCbrt(), skipThis);
2144514f5e3Sopenharmony_ci                break;
2154514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathImul:
2164514f5e3Sopenharmony_ci                TryInlineMathImulBuiltin(gate, argc, id, circuit_->MathImul(), skipThis);
2174514f5e3Sopenharmony_ci                break;
2184514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::GlobalIsFinite:
2194514f5e3Sopenharmony_ci                TryInlineGlobalFiniteBuiltin(gate, argc, id, circuit_->GlobalIsFinite(), skipThis);
2204514f5e3Sopenharmony_ci                break;
2214514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::GlobalIsNan:
2224514f5e3Sopenharmony_ci                TryInlineGlobalNanBuiltin(gate, argc, id, circuit_->GlobalIsNan(), skipThis);
2234514f5e3Sopenharmony_ci                break;
2244514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DateGetTime:
2254514f5e3Sopenharmony_ci                TryInlineDateGetTime(gate, argc, skipThis);
2264514f5e3Sopenharmony_ci                break;
2274514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathMin:
2284514f5e3Sopenharmony_ci                TryInlineMathMinMaxBuiltin(gate, argc, id, circuit_->MathMin(), base::POSITIVE_INFINITY, skipThis);
2294514f5e3Sopenharmony_ci                break;
2304514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathMax:
2314514f5e3Sopenharmony_ci                TryInlineMathMinMaxBuiltin(gate, argc, id, circuit_->MathMax(), -base::POSITIVE_INFINITY, skipThis);
2324514f5e3Sopenharmony_ci                break;
2334514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathRound:
2344514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathRound(), skipThis);
2354514f5e3Sopenharmony_ci                break;
2364514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathFRound:
2374514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathFRound(), skipThis);
2384514f5e3Sopenharmony_ci                break;
2394514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathCeil:
2404514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathCeil(), skipThis);
2414514f5e3Sopenharmony_ci                break;
2424514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MathFloor:
2434514f5e3Sopenharmony_ci                TryInlineMathUnaryBuiltin(gate, argc, id, circuit_->MathFloor(), skipThis);
2444514f5e3Sopenharmony_ci                break;
2454514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayBufferIsView:
2464514f5e3Sopenharmony_ci                TryInlineArrayBufferIsView(gate, argc, id, skipThis);
2474514f5e3Sopenharmony_ci                break;
2484514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewGetFloat32:
2494514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewGetFloat64:
2504514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewGetInt8:
2514514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewGetInt16:
2524514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewGetInt32:
2534514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewGetUint16:
2544514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewGetUint32:
2554514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewGetUint8:
2564514f5e3Sopenharmony_ci                TryInlineDataViewGet(gate, argc, id, skipThis);
2574514f5e3Sopenharmony_ci                break;
2584514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewSetFloat32:
2594514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewSetFloat64:
2604514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewSetInt8:
2614514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewSetInt16:
2624514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewSetInt32:
2634514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewSetUint8:
2644514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewSetUint16:
2654514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DataViewSetUint32:
2664514f5e3Sopenharmony_ci                TryInlineDataViewSet(gate, argc, id, skipThis);
2674514f5e3Sopenharmony_ci                break;
2684514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::BigIntAsIntN:
2694514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::BigIntAsUintN:
2704514f5e3Sopenharmony_ci                TryInlineBigIntAsIntN(gate, argc, id, skipThis);
2714514f5e3Sopenharmony_ci                break;
2724514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MapGet:
2734514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 1U, argc, id, circuit_->MapGet(), skipThis);
2744514f5e3Sopenharmony_ci                break;
2754514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MapHas:
2764514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 1U, argc, id, circuit_->MapHas(), skipThis);
2774514f5e3Sopenharmony_ci                break;
2784514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MapKeys:
2794514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 0U, argc, id, circuit_->MapKeys(), skipThis);
2804514f5e3Sopenharmony_ci                break;
2814514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MapValues:
2824514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 0U, argc, id, circuit_->MapValues(), skipThis);
2834514f5e3Sopenharmony_ci                break;
2844514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MapEntries:
2854514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 0U, argc, id, circuit_->MapEntries(), skipThis);
2864514f5e3Sopenharmony_ci                break;
2874514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::SetHas:
2884514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 1U, argc, id, circuit_->SetHas(), skipThis);
2894514f5e3Sopenharmony_ci                break;
2904514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::SetAdd:
2914514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 1U, argc, id, circuit_->SetAdd(), skipThis);
2924514f5e3Sopenharmony_ci                break;
2934514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::DateNow:
2944514f5e3Sopenharmony_ci                TryInlineWhitoutParamBuiltin(gate, argc, id, circuit_->DateNow(), skipThis);
2954514f5e3Sopenharmony_ci                break;
2964514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MapDelete:
2974514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 1U, argc, id, circuit_->MapDelete(), skipThis);
2984514f5e3Sopenharmony_ci                break;
2994514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::SetDelete:
3004514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 1U, argc, id, circuit_->SetDelete(), skipThis);
3014514f5e3Sopenharmony_ci                break;
3024514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::SetValues:
3034514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 0U, argc, id, circuit_->SetValues(), skipThis);
3044514f5e3Sopenharmony_ci                break;
3054514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::SetEntries:
3064514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 0U, argc, id, circuit_->SetEntries(), skipThis);
3074514f5e3Sopenharmony_ci                break;
3084514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::BigIntConstructor:
3094514f5e3Sopenharmony_ci                TryInlineBigIntConstructor(gate, argc, skipThis);
3104514f5e3Sopenharmony_ci                break;
3114514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::MapClear:
3124514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 0U, argc, id, circuit_->MapClear(), skipThis);
3134514f5e3Sopenharmony_ci                break;
3144514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::SetClear:
3154514f5e3Sopenharmony_ci                InlineStubBuiltin(gate, 0U, argc, id, circuit_->SetClear(), skipThis);
3164514f5e3Sopenharmony_ci                break;
3174514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArraySort:
3184514f5e3Sopenharmony_ci                TryInlineArraySort(gate, argc, id, skipThis);
3194514f5e3Sopenharmony_ci                break;
3204514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ObjectIs:
3214514f5e3Sopenharmony_ci                TryInlineObjectIs(gate, argc, id, skipThis);
3224514f5e3Sopenharmony_ci                break;
3234514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ObjectGetPrototypeOf:
3244514f5e3Sopenharmony_ci                TryInlineObjectGetPrototypeOf(gate, argc, id, skipThis);
3254514f5e3Sopenharmony_ci                break;
3264514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ObjectGetProto:
3274514f5e3Sopenharmony_ci                TryInlineObjectGetProto(gate, argc, id, skipThis);
3284514f5e3Sopenharmony_ci                break;
3294514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ObjectCreate:
3304514f5e3Sopenharmony_ci                TryInlineObjectCreate(gate, argc, id, skipThis);
3314514f5e3Sopenharmony_ci                break;
3324514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ObjectIsPrototypeOf:
3334514f5e3Sopenharmony_ci                TryInlineObjectIsPrototypeOf(gate, argc, id, skipThis);
3344514f5e3Sopenharmony_ci                break;
3354514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ObjectHasOwnProperty:
3364514f5e3Sopenharmony_ci                TryInlineObjectHasOwnProperty(gate, argc, id, skipThis);
3374514f5e3Sopenharmony_ci                break;
3384514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ReflectGetPrototypeOf:
3394514f5e3Sopenharmony_ci                TryInlineReflectGetPrototypeOf(gate, argc, id, skipThis);
3404514f5e3Sopenharmony_ci                break;
3414514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ReflectGet:
3424514f5e3Sopenharmony_ci                TryInlineReflectGet(gate, argc, id, skipThis);
3434514f5e3Sopenharmony_ci                break;
3444514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ReflectHas:
3454514f5e3Sopenharmony_ci                TryInlineReflectHas(gate, argc, id, skipThis);
3464514f5e3Sopenharmony_ci                break;
3474514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ReflectConstruct:
3484514f5e3Sopenharmony_ci                TryInlineReflectConstruct(gate, argc, id, skipThis);
3494514f5e3Sopenharmony_ci                break;
3504514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ReflectApply:
3514514f5e3Sopenharmony_ci                TryInlineReflectApply(gate, argc, id, skipThis);
3524514f5e3Sopenharmony_ci                break;
3534514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::FunctionPrototypeHasInstance:
3544514f5e3Sopenharmony_ci                TryInlineFunctionPrototypeHasInstance(gate, argc, id, skipThis);
3554514f5e3Sopenharmony_ci                break;
3564514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayIndexOf:
3574514f5e3Sopenharmony_ci                TryInlineIndexOfIncludes(gate, argc, id, skipThis);
3584514f5e3Sopenharmony_ci                break;
3594514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayIncludes:
3604514f5e3Sopenharmony_ci                TryInlineIndexOfIncludes(gate, argc, id, skipThis);
3614514f5e3Sopenharmony_ci                break;
3624514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayForEach:
3634514f5e3Sopenharmony_ci                TryInlineArrayForEach(gate, argc, id, skipThis);
3644514f5e3Sopenharmony_ci                break;
3654514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayFind:
3664514f5e3Sopenharmony_ci                TryInlineArrayFindOrFindIndex(gate, argc, id, skipThis);
3674514f5e3Sopenharmony_ci                break;
3684514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayFindIndex:
3694514f5e3Sopenharmony_ci                TryInlineArrayFindOrFindIndex(gate, argc, id, skipThis);
3704514f5e3Sopenharmony_ci                break;
3714514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayFilter:
3724514f5e3Sopenharmony_ci                TryInlineArrayFilter(gate, argc, id, skipThis);
3734514f5e3Sopenharmony_ci                break;
3744514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayMap:
3754514f5e3Sopenharmony_ci                TryInlineArrayMap(gate, argc, id, skipThis);
3764514f5e3Sopenharmony_ci                break;
3774514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArraySome:
3784514f5e3Sopenharmony_ci                TryInlineArraySome(gate, argc, id, skipThis);
3794514f5e3Sopenharmony_ci                break;
3804514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayEvery:
3814514f5e3Sopenharmony_ci                TryInlineArrayEvery(gate, argc, id, skipThis);
3824514f5e3Sopenharmony_ci                break;
3834514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArrayPop:
3844514f5e3Sopenharmony_ci                TryInlineArrayPop(gate, argc, id, skipThis);
3854514f5e3Sopenharmony_ci                break;
3864514f5e3Sopenharmony_ci            case BuiltinsStubCSigns::ID::ArraySlice:
3874514f5e3Sopenharmony_ci                TryInlineArraySlice(gate, argc, id, skipThis);
3884514f5e3Sopenharmony_ci                break;
3894514f5e3Sopenharmony_ci            default:
3904514f5e3Sopenharmony_ci                break;
3914514f5e3Sopenharmony_ci        }
3924514f5e3Sopenharmony_ci    }
3934514f5e3Sopenharmony_ci
3944514f5e3Sopenharmony_ci    if (EnableLog()) {
3954514f5e3Sopenharmony_ci        LOG_COMPILER(INFO) << " ";
3964514f5e3Sopenharmony_ci        LOG_COMPILER(INFO) << "\033[34m" << "================="
3974514f5e3Sopenharmony_ci                           << " After Native Inline Lowering "
3984514f5e3Sopenharmony_ci                           << "[" << GetMethodName() << "] "
3994514f5e3Sopenharmony_ci                           << "=================" << "\033[0m";
4004514f5e3Sopenharmony_ci        circuit_->PrintAllGatesWithBytecode();
4014514f5e3Sopenharmony_ci        LOG_COMPILER(INFO) << "\033[34m" << "=========================== End ===========================" << "\033[0m";
4024514f5e3Sopenharmony_ci    }
4034514f5e3Sopenharmony_ci}
4044514f5e3Sopenharmony_ci
4054514f5e3Sopenharmony_civoid NativeInlineLowering::AddTraceLogs(GateRef gate, BuiltinsStubCSigns::ID id)
4064514f5e3Sopenharmony_ci{
4074514f5e3Sopenharmony_ci    size_t index = RTSTUB_ID(AotInlineBuiltinTrace);
4084514f5e3Sopenharmony_ci
4094514f5e3Sopenharmony_ci    GateRef frameState = acc_.GetFrameState(gate);
4104514f5e3Sopenharmony_ci    GateRef frameArgs = acc_.GetValueIn(frameState);
4114514f5e3Sopenharmony_ci    GateRef callerFunc = acc_.GetValueIn(frameArgs, 0);
4124514f5e3Sopenharmony_ci    std::vector<GateRef> args{callerFunc, builder_.Int32(id)};
4134514f5e3Sopenharmony_ci
4144514f5e3Sopenharmony_ci    builder_.CallRuntime(glue_, index, Gate::InvalidGateRef, args, gate);
4154514f5e3Sopenharmony_ci}
4164514f5e3Sopenharmony_ci
4174514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineStringFromCharCode(GateRef gate, size_t argc, bool skipThis)
4184514f5e3Sopenharmony_ci{
4194514f5e3Sopenharmony_ci    if (!skipThis) {
4204514f5e3Sopenharmony_ci        return;
4214514f5e3Sopenharmony_ci    }
4224514f5e3Sopenharmony_ci    if (argc != 1) {
4234514f5e3Sopenharmony_ci        return;
4244514f5e3Sopenharmony_ci    }
4254514f5e3Sopenharmony_ci    CallThis1TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
4264514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
4274514f5e3Sopenharmony_ci    if (!Uncheck()) {
4284514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, tacc.GetFunc(),
4294514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::StringFromCharCode)),
4304514f5e3Sopenharmony_ci                                 {tacc.GetArg0()});
4314514f5e3Sopenharmony_ci    }
4324514f5e3Sopenharmony_ci
4334514f5e3Sopenharmony_ci    if (EnableTrace()) {
4344514f5e3Sopenharmony_ci        AddTraceLogs(gate, BuiltinsStubCSigns::ID::StringFromCharCode);
4354514f5e3Sopenharmony_ci    }
4364514f5e3Sopenharmony_ci
4374514f5e3Sopenharmony_ci    GateRef ret = builder_.StringFromSingleCharCode(tacc.GetArg0());
4384514f5e3Sopenharmony_ci    acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), ret);
4394514f5e3Sopenharmony_ci}
4404514f5e3Sopenharmony_ci
4414514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineStringCharCodeAt(GateRef gate, size_t argc, bool skipThis)
4424514f5e3Sopenharmony_ci{
4434514f5e3Sopenharmony_ci    // only inline number input, string input will be deoptimized
4444514f5e3Sopenharmony_ci    if (!skipThis) {
4454514f5e3Sopenharmony_ci        return;
4464514f5e3Sopenharmony_ci    }
4474514f5e3Sopenharmony_ci
4484514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
4494514f5e3Sopenharmony_ci    GateRef posTag = (argc == 0) ? (builder_.Int32(0)) : (acc_.GetValueIn(gate, 1));
4504514f5e3Sopenharmony_ci    GateRef func = acc_.GetValueIn(gate, argc + 1);
4514514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
4524514f5e3Sopenharmony_ci    if (!Uncheck()) {
4534514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, func,
4544514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::StringCharCodeAt)),
4554514f5e3Sopenharmony_ci                                 {thisValue});
4564514f5e3Sopenharmony_ci        builder_.EcmaStringCheck(thisValue);
4574514f5e3Sopenharmony_ci    }
4584514f5e3Sopenharmony_ci
4594514f5e3Sopenharmony_ci    if (EnableTrace()) {
4604514f5e3Sopenharmony_ci        AddTraceLogs(gate, BuiltinsStubCSigns::ID::StringCharCodeAt);
4614514f5e3Sopenharmony_ci    }
4624514f5e3Sopenharmony_ci
4634514f5e3Sopenharmony_ci    GateRef ret = builder_.StringCharCodeAt(thisValue, posTag);
4644514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
4654514f5e3Sopenharmony_ci}
4664514f5e3Sopenharmony_ci
4674514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineStringSubstring(GateRef gate, size_t argc, bool skipThis)
4684514f5e3Sopenharmony_ci{
4694514f5e3Sopenharmony_ci    if (!skipThis) {
4704514f5e3Sopenharmony_ci        return;
4714514f5e3Sopenharmony_ci    }
4724514f5e3Sopenharmony_ci    if (argc != 1 && argc != 2) { // only optimize one or two parameters scene
4734514f5e3Sopenharmony_ci        return;
4744514f5e3Sopenharmony_ci    }
4754514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
4764514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
4774514f5e3Sopenharmony_ci    if (argc == 1) {
4784514f5e3Sopenharmony_ci        CallThis1TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
4794514f5e3Sopenharmony_ci        GateRef thisValue = acc_.GetValueIn(gate, 0);
4804514f5e3Sopenharmony_ci        GateRef startTag = tacc.GetArg0();
4814514f5e3Sopenharmony_ci        GateRef endTag = builder_.GetLengthFromString(thisValue);
4824514f5e3Sopenharmony_ci        if (!Uncheck()) {
4834514f5e3Sopenharmony_ci            builder_.CallTargetCheck(gate, tacc.GetFunc(),
4844514f5e3Sopenharmony_ci                                     builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::StringSubstring)),
4854514f5e3Sopenharmony_ci                                     {tacc.GetArg0()});
4864514f5e3Sopenharmony_ci            builder_.EcmaStringCheck(thisValue);
4874514f5e3Sopenharmony_ci            auto param_check = builder_.TaggedIsNumber(startTag);
4884514f5e3Sopenharmony_ci            builder_.DeoptCheck(param_check, acc_.GetFrameState(gate), DeoptType::BUILTIN_INLINING_TYPE_GUARD);
4894514f5e3Sopenharmony_ci        }
4904514f5e3Sopenharmony_ci        ret = builder_.StringSubstring(thisValue, startTag, endTag);
4914514f5e3Sopenharmony_ci    } else {
4924514f5e3Sopenharmony_ci        GateRef thisValue = acc_.GetValueIn(gate, 0);
4934514f5e3Sopenharmony_ci        GateRef startTag = acc_.GetValueIn(gate, 1);
4944514f5e3Sopenharmony_ci        GateRef endTag = acc_.GetValueIn(gate, 2);
4954514f5e3Sopenharmony_ci        GateRef func = acc_.GetValueIn(gate, 3);
4964514f5e3Sopenharmony_ci        if (!Uncheck()) {
4974514f5e3Sopenharmony_ci            builder_.CallTargetCheck(gate, func,
4984514f5e3Sopenharmony_ci                                     builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::StringSubstring)));
4994514f5e3Sopenharmony_ci            builder_.EcmaStringCheck(thisValue);
5004514f5e3Sopenharmony_ci            auto param_check = LogicAndBuilder(&env).And(builder_.TaggedIsNumber(startTag))
5014514f5e3Sopenharmony_ci                .And(builder_.TaggedIsNumber(endTag)).Done();
5024514f5e3Sopenharmony_ci            builder_.DeoptCheck(param_check, acc_.GetFrameState(gate), DeoptType::BUILTIN_INLINING_TYPE_GUARD);
5034514f5e3Sopenharmony_ci        }
5044514f5e3Sopenharmony_ci        ret = builder_.StringSubstring(thisValue, startTag, endTag);
5054514f5e3Sopenharmony_ci    }
5064514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
5074514f5e3Sopenharmony_ci}
5084514f5e3Sopenharmony_ci
5094514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineStringSubStr(GateRef gate, size_t argc, bool skipThis)
5104514f5e3Sopenharmony_ci{
5114514f5e3Sopenharmony_ci    if (!skipThis) {
5124514f5e3Sopenharmony_ci        return;
5134514f5e3Sopenharmony_ci    }
5144514f5e3Sopenharmony_ci    if (argc != 1 && argc != 2) { // only optimize one or two parameters scene
5154514f5e3Sopenharmony_ci        return;
5164514f5e3Sopenharmony_ci    }
5174514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
5184514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
5194514f5e3Sopenharmony_ci    if (argc == 1) {
5204514f5e3Sopenharmony_ci        CallThis1TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
5214514f5e3Sopenharmony_ci        GateRef thisValue = acc_.GetValueIn(gate, 0);
5224514f5e3Sopenharmony_ci        GateRef intStart = tacc.GetArg0();
5234514f5e3Sopenharmony_ci        GateRef lengthTag = builder_.Int32(INT_MAX);
5244514f5e3Sopenharmony_ci        if (!Uncheck()) {
5254514f5e3Sopenharmony_ci            builder_.CallTargetCheck(gate, tacc.GetFunc(),
5264514f5e3Sopenharmony_ci                                     builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::StringSubStr)),
5274514f5e3Sopenharmony_ci                                     {tacc.GetArg0()});
5284514f5e3Sopenharmony_ci            builder_.EcmaStringCheck(thisValue);
5294514f5e3Sopenharmony_ci            auto param_check = builder_.TaggedIsNumber(intStart);
5304514f5e3Sopenharmony_ci            builder_.DeoptCheck(param_check, acc_.GetFrameState(gate), DeoptType::BUILTIN_INLINING_TYPE_GUARD);
5314514f5e3Sopenharmony_ci        }
5324514f5e3Sopenharmony_ci        ret = builder_.StringSubStr(thisValue, intStart, lengthTag);
5334514f5e3Sopenharmony_ci    } else {
5344514f5e3Sopenharmony_ci        GateRef thisValue = acc_.GetValueIn(gate, 0);
5354514f5e3Sopenharmony_ci        GateRef intStart = acc_.GetValueIn(gate, 1);
5364514f5e3Sopenharmony_ci        GateRef lengthTag = acc_.GetValueIn(gate, 2);
5374514f5e3Sopenharmony_ci        GateRef func = acc_.GetValueIn(gate, 3);  //acc
5384514f5e3Sopenharmony_ci        if (!Uncheck()) {
5394514f5e3Sopenharmony_ci            builder_.CallTargetCheck(gate, func,
5404514f5e3Sopenharmony_ci                                     builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::StringSubStr)));
5414514f5e3Sopenharmony_ci            builder_.EcmaStringCheck(thisValue);
5424514f5e3Sopenharmony_ci            auto param_check = LogicAndBuilder(&env).And(builder_.TaggedIsNumber(intStart))
5434514f5e3Sopenharmony_ci                .And(builder_.TaggedIsNumber(lengthTag)).Done();
5444514f5e3Sopenharmony_ci            builder_.DeoptCheck(param_check, acc_.GetFrameState(gate), DeoptType::BUILTIN_INLINING_TYPE_GUARD);
5454514f5e3Sopenharmony_ci        }
5464514f5e3Sopenharmony_ci        ret = builder_.StringSubStr(thisValue, intStart, lengthTag);
5474514f5e3Sopenharmony_ci    }
5484514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
5494514f5e3Sopenharmony_ci}
5504514f5e3Sopenharmony_ci
5514514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineStringSlice(GateRef gate, size_t argc, bool skipThis)
5524514f5e3Sopenharmony_ci{
5534514f5e3Sopenharmony_ci    if (!skipThis) {
5544514f5e3Sopenharmony_ci        return;
5554514f5e3Sopenharmony_ci    }
5564514f5e3Sopenharmony_ci    if (argc != 1 && argc != 2) { // only optimize one or two parameters scene
5574514f5e3Sopenharmony_ci        return;
5584514f5e3Sopenharmony_ci    }
5594514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
5604514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
5614514f5e3Sopenharmony_ci    if (argc == 1) {
5624514f5e3Sopenharmony_ci        CallThis1TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
5634514f5e3Sopenharmony_ci        GateRef thisValue = acc_.GetValueIn(gate, 0);
5644514f5e3Sopenharmony_ci        GateRef startTag = tacc.GetArg0();
5654514f5e3Sopenharmony_ci        GateRef endTag = builder_.GetLengthFromString(thisValue);
5664514f5e3Sopenharmony_ci        if (!Uncheck()) {
5674514f5e3Sopenharmony_ci            builder_.CallTargetCheck(gate, tacc.GetFunc(),
5684514f5e3Sopenharmony_ci                                     builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::StringSlice)),
5694514f5e3Sopenharmony_ci                                     {tacc.GetArg0()});
5704514f5e3Sopenharmony_ci            builder_.EcmaStringCheck(thisValue);
5714514f5e3Sopenharmony_ci            auto param_check = builder_.TaggedIsNumber(startTag);
5724514f5e3Sopenharmony_ci            builder_.DeoptCheck(param_check, acc_.GetFrameState(gate), DeoptType::BUILTIN_INLINING_TYPE_GUARD);
5734514f5e3Sopenharmony_ci        }
5744514f5e3Sopenharmony_ci        ret = builder_.StringSlice(thisValue, startTag, endTag);
5754514f5e3Sopenharmony_ci    } else {
5764514f5e3Sopenharmony_ci        GateRef thisValue = acc_.GetValueIn(gate, 0);
5774514f5e3Sopenharmony_ci        GateRef startTag = acc_.GetValueIn(gate, 1);
5784514f5e3Sopenharmony_ci        GateRef endTag = acc_.GetValueIn(gate, 2);
5794514f5e3Sopenharmony_ci        GateRef func = acc_.GetValueIn(gate, 3);
5804514f5e3Sopenharmony_ci        if (!Uncheck()) {
5814514f5e3Sopenharmony_ci            builder_.CallTargetCheck(gate, func,
5824514f5e3Sopenharmony_ci                                     builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::StringSlice)));
5834514f5e3Sopenharmony_ci            builder_.EcmaStringCheck(thisValue);
5844514f5e3Sopenharmony_ci            auto param_check = LogicAndBuilder(&env).And(builder_.TaggedIsNumber(startTag))
5854514f5e3Sopenharmony_ci                .And(builder_.TaggedIsNumber(endTag)).Done();
5864514f5e3Sopenharmony_ci            builder_.DeoptCheck(param_check, acc_.GetFrameState(gate), DeoptType::BUILTIN_INLINING_TYPE_GUARD);
5874514f5e3Sopenharmony_ci        }
5884514f5e3Sopenharmony_ci        ret = builder_.StringSlice(thisValue, startTag, endTag);
5894514f5e3Sopenharmony_ci    }
5904514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
5914514f5e3Sopenharmony_ci}
5924514f5e3Sopenharmony_ci
5934514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineNumberIsFinite(GateRef gate, size_t argc, bool skipThis)
5944514f5e3Sopenharmony_ci{
5954514f5e3Sopenharmony_ci    if (!skipThis) {
5964514f5e3Sopenharmony_ci        return;
5974514f5e3Sopenharmony_ci    }
5984514f5e3Sopenharmony_ci    if (argc != 1) {
5994514f5e3Sopenharmony_ci        return;
6004514f5e3Sopenharmony_ci    }
6014514f5e3Sopenharmony_ci    CallThis1TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
6024514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
6034514f5e3Sopenharmony_ci    if (!Uncheck()) {
6044514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, tacc.GetFunc(),
6054514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::NumberIsFinite)));
6064514f5e3Sopenharmony_ci    }
6074514f5e3Sopenharmony_ci    GateRef ret = builder_.NumberIsFinite(tacc.GetArg0());
6084514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
6094514f5e3Sopenharmony_ci}
6104514f5e3Sopenharmony_ci
6114514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineNumberIsInteger(GateRef gate, size_t argc, bool skipThis)
6124514f5e3Sopenharmony_ci{
6134514f5e3Sopenharmony_ci    if (!skipThis) {
6144514f5e3Sopenharmony_ci        return;
6154514f5e3Sopenharmony_ci    }
6164514f5e3Sopenharmony_ci    if (argc != 1) {
6174514f5e3Sopenharmony_ci        return;
6184514f5e3Sopenharmony_ci    }
6194514f5e3Sopenharmony_ci    CallThis1TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
6204514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
6214514f5e3Sopenharmony_ci    auto id = BuiltinsStubCSigns::ID::NumberIsInteger;
6224514f5e3Sopenharmony_ci    if (!Uncheck()) {
6234514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, tacc.GetFunc(),
6244514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
6254514f5e3Sopenharmony_ci    }
6264514f5e3Sopenharmony_ci    if (EnableTrace()) {
6274514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
6284514f5e3Sopenharmony_ci    }
6294514f5e3Sopenharmony_ci    GateRef ret = builder_.NumberIsInteger(tacc.GetArg0());
6304514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
6314514f5e3Sopenharmony_ci}
6324514f5e3Sopenharmony_ci
6334514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineNumberIsNaN(GateRef gate, size_t argc, bool skipThis)
6344514f5e3Sopenharmony_ci{
6354514f5e3Sopenharmony_ci    if (!skipThis) {
6364514f5e3Sopenharmony_ci        return;
6374514f5e3Sopenharmony_ci    }
6384514f5e3Sopenharmony_ci    if (argc != 1) {
6394514f5e3Sopenharmony_ci        return;
6404514f5e3Sopenharmony_ci    }
6414514f5e3Sopenharmony_ci    CallThis1TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
6424514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
6434514f5e3Sopenharmony_ci    if (!Uncheck()) {
6444514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, tacc.GetFunc(),
6454514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::NumberIsNaN)));
6464514f5e3Sopenharmony_ci    }
6474514f5e3Sopenharmony_ci    GateRef ret = builder_.NumberIsNaN(tacc.GetArg0());
6484514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
6494514f5e3Sopenharmony_ci}
6504514f5e3Sopenharmony_ci
6514514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineNumberParseFloat(GateRef gate, size_t argc, bool skipThis)
6524514f5e3Sopenharmony_ci{
6534514f5e3Sopenharmony_ci    auto firstParam = skipThis ? 1 : 0;
6544514f5e3Sopenharmony_ci    auto func = acc_.GetValueIn(gate, argc + firstParam);
6554514f5e3Sopenharmony_ci    auto arg = acc_.GetValueIn(gate, firstParam);
6564514f5e3Sopenharmony_ci
6574514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
6584514f5e3Sopenharmony_ci    auto id = BuiltinsStubCSigns::ID::NumberParseFloat;
6594514f5e3Sopenharmony_ci    if (!Uncheck()) {
6604514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, func, builder_.IntPtr(static_cast<int64_t>(id)));
6614514f5e3Sopenharmony_ci    }
6624514f5e3Sopenharmony_ci    if (EnableTrace()) {
6634514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
6644514f5e3Sopenharmony_ci    }
6654514f5e3Sopenharmony_ci    GateRef ret = builder_.NumberParseFloat(arg, acc_.GetFrameState(gate));
6664514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
6674514f5e3Sopenharmony_ci}
6684514f5e3Sopenharmony_ci
6694514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineNumberParseInt(GateRef gate, size_t argc, bool skipThis)
6704514f5e3Sopenharmony_ci{
6714514f5e3Sopenharmony_ci    auto firstParam = skipThis ? 1 : 0;
6724514f5e3Sopenharmony_ci    auto func = acc_.GetValueIn(gate, argc + firstParam);
6734514f5e3Sopenharmony_ci    auto arg = acc_.GetValueIn(gate, firstParam);
6744514f5e3Sopenharmony_ci    auto radix = builder_.Undefined();
6754514f5e3Sopenharmony_ci    if (argc > 1) {
6764514f5e3Sopenharmony_ci        radix = acc_.GetValueIn(gate, firstParam + 1);
6774514f5e3Sopenharmony_ci    }
6784514f5e3Sopenharmony_ci
6794514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
6804514f5e3Sopenharmony_ci    auto id = BuiltinsStubCSigns::ID::NumberParseInt;
6814514f5e3Sopenharmony_ci    if (!Uncheck()) {
6824514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, func, builder_.IntPtr(static_cast<int64_t>(id)));
6834514f5e3Sopenharmony_ci    }
6844514f5e3Sopenharmony_ci    if (EnableTrace()) {
6854514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
6864514f5e3Sopenharmony_ci    }
6874514f5e3Sopenharmony_ci    GateRef ret = builder_.NumberParseInt(arg, radix);
6884514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
6894514f5e3Sopenharmony_ci}
6904514f5e3Sopenharmony_ci
6914514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineNumberIsSafeInteger(GateRef gate, size_t argc, bool skipThis)
6924514f5e3Sopenharmony_ci{
6934514f5e3Sopenharmony_ci    if (!skipThis) {
6944514f5e3Sopenharmony_ci        return;
6954514f5e3Sopenharmony_ci    }
6964514f5e3Sopenharmony_ci    if (argc != 1) {
6974514f5e3Sopenharmony_ci        return;
6984514f5e3Sopenharmony_ci    }
6994514f5e3Sopenharmony_ci    CallThis1TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
7004514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
7014514f5e3Sopenharmony_ci    auto id = BuiltinsStubCSigns::ID::NumberIsSafeInteger;
7024514f5e3Sopenharmony_ci    if (!Uncheck()) {
7034514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, tacc.GetFunc(),
7044514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
7054514f5e3Sopenharmony_ci    }
7064514f5e3Sopenharmony_ci    if (EnableTrace()) {
7074514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
7084514f5e3Sopenharmony_ci    }
7094514f5e3Sopenharmony_ci    GateRef ret = builder_.NumberIsSafeInteger(tacc.GetArg0());
7104514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
7114514f5e3Sopenharmony_ci}
7124514f5e3Sopenharmony_ci
7134514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineBigIntAsIntN(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
7144514f5e3Sopenharmony_ci                                                 bool skipThis)
7154514f5e3Sopenharmony_ci{
7164514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
7174514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
7184514f5e3Sopenharmony_ci    if (argc < 2U) {
7194514f5e3Sopenharmony_ci        return;
7204514f5e3Sopenharmony_ci    }
7214514f5e3Sopenharmony_ci    if (!Uncheck()) {
7224514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
7234514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
7244514f5e3Sopenharmony_ci    }
7254514f5e3Sopenharmony_ci    if (EnableTrace()) {
7264514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
7274514f5e3Sopenharmony_ci    }
7284514f5e3Sopenharmony_ci    GateRef bits = acc_.GetValueIn(gate, firstParam);
7294514f5e3Sopenharmony_ci    GateRef bigint = acc_.GetValueIn(gate, firstParam + 1);
7304514f5e3Sopenharmony_ci    GateRef frameState = acc_.GetFrameState(gate);
7314514f5e3Sopenharmony_ci    bool isUnsigned = (id == BuiltinsStubCSigns::ID::BigIntAsUintN);
7324514f5e3Sopenharmony_ci    const auto* op = isUnsigned ? circuit_->BigIntAsUintN() : circuit_->BigIntAsIntN();
7334514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildBigIntAsIntN(op, {bits, bigint, frameState});
7344514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
7354514f5e3Sopenharmony_ci}
7364514f5e3Sopenharmony_ci
7374514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineTypedArrayIteratorBuiltin(GateRef gate,
7384514f5e3Sopenharmony_ci                                                              BuiltinsStubCSigns::ID id,
7394514f5e3Sopenharmony_ci                                                              const GateMetaData* op, bool skipThis)
7404514f5e3Sopenharmony_ci{
7414514f5e3Sopenharmony_ci    if (!skipThis) {
7424514f5e3Sopenharmony_ci        return;
7434514f5e3Sopenharmony_ci    }
7444514f5e3Sopenharmony_ci
7454514f5e3Sopenharmony_ci    CallThis0TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
7464514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
7474514f5e3Sopenharmony_ci
7484514f5e3Sopenharmony_ci    if (!Uncheck()) {
7494514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, tacc.GetFunc(), builder_.IntPtr(static_cast<int64_t>(id)), {tacc.GetThisObj()});
7504514f5e3Sopenharmony_ci    }
7514514f5e3Sopenharmony_ci
7524514f5e3Sopenharmony_ci    if (EnableTrace()) {
7534514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
7544514f5e3Sopenharmony_ci    }
7554514f5e3Sopenharmony_ci
7564514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildTypedArrayIterator(acc_.GetValueIn(gate, 0), op);
7574514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
7584514f5e3Sopenharmony_ci}
7594514f5e3Sopenharmony_ci
7604514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineMathUnaryBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
7614514f5e3Sopenharmony_ci                                                     const GateMetaData* op, bool skipThis)
7624514f5e3Sopenharmony_ci{
7634514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
7644514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
7654514f5e3Sopenharmony_ci    if (!Uncheck()) {
7664514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
7674514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
7684514f5e3Sopenharmony_ci    }
7694514f5e3Sopenharmony_ci
7704514f5e3Sopenharmony_ci    if (EnableTrace()) {
7714514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
7724514f5e3Sopenharmony_ci    }
7734514f5e3Sopenharmony_ci
7744514f5e3Sopenharmony_ci    if (argc == 0) {
7754514f5e3Sopenharmony_ci        acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), builder_.NanValue());
7764514f5e3Sopenharmony_ci        return;
7774514f5e3Sopenharmony_ci    }
7784514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(op, {acc_.GetValueIn(gate, firstParam)});
7794514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
7804514f5e3Sopenharmony_ci}
7814514f5e3Sopenharmony_ci
7824514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineWhitoutParamBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
7834514f5e3Sopenharmony_ci                                                        const GateMetaData* op, bool skipThis)
7844514f5e3Sopenharmony_ci{
7854514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
7864514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
7874514f5e3Sopenharmony_ci    if (!Uncheck()) {
7884514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
7894514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
7904514f5e3Sopenharmony_ci    }
7914514f5e3Sopenharmony_ci
7924514f5e3Sopenharmony_ci    if (EnableTrace()) {
7934514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
7944514f5e3Sopenharmony_ci    }
7954514f5e3Sopenharmony_ci
7964514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(op, {});
7974514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
7984514f5e3Sopenharmony_ci}
7994514f5e3Sopenharmony_ci
8004514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineMathAbsBuiltin(GateRef gate, size_t argc, bool skipThis)
8014514f5e3Sopenharmony_ci{
8024514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
8034514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
8044514f5e3Sopenharmony_ci    if (!Uncheck()) {
8054514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
8064514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::MathAbs)));
8074514f5e3Sopenharmony_ci    }
8084514f5e3Sopenharmony_ci
8094514f5e3Sopenharmony_ci    if (EnableTrace()) {
8104514f5e3Sopenharmony_ci        AddTraceLogs(gate, BuiltinsStubCSigns::ID::MathAbs);
8114514f5e3Sopenharmony_ci    }
8124514f5e3Sopenharmony_ci
8134514f5e3Sopenharmony_ci    if (argc == 0) {
8144514f5e3Sopenharmony_ci        acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), builder_.NanValue());
8154514f5e3Sopenharmony_ci        return;
8164514f5e3Sopenharmony_ci    }
8174514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->MathAbs(), {acc_.GetValueIn(gate, firstParam)},
8184514f5e3Sopenharmony_ci                                                {acc_.GetFrameState(gate)});
8194514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
8204514f5e3Sopenharmony_ci}
8214514f5e3Sopenharmony_ci
8224514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineMathClz32Builtin(GateRef gate, size_t argc, bool skipThis)
8234514f5e3Sopenharmony_ci{
8244514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
8254514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
8264514f5e3Sopenharmony_ci    if (!Uncheck()) {
8274514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
8284514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::MathClz32)));
8294514f5e3Sopenharmony_ci    }
8304514f5e3Sopenharmony_ci    if (EnableTrace()) {
8314514f5e3Sopenharmony_ci        AddTraceLogs(gate, BuiltinsStubCSigns::ID::MathClz32);
8324514f5e3Sopenharmony_ci    }
8334514f5e3Sopenharmony_ci    if (argc == 0) {
8344514f5e3Sopenharmony_ci        const int32_t defaultValue = 32;
8354514f5e3Sopenharmony_ci        acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), builder_.Int32(defaultValue));
8364514f5e3Sopenharmony_ci        return;
8374514f5e3Sopenharmony_ci    }
8384514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->MathClz32(), {acc_.GetValueIn(gate, firstParam)});
8394514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
8404514f5e3Sopenharmony_ci}
8414514f5e3Sopenharmony_ci
8424514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineGlobalFiniteBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
8434514f5e3Sopenharmony_ci                                                        const GateMetaData* op, bool skipThis)
8444514f5e3Sopenharmony_ci{
8454514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
8464514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
8474514f5e3Sopenharmony_ci    if (!Uncheck()) {
8484514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
8494514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
8504514f5e3Sopenharmony_ci    }
8514514f5e3Sopenharmony_ci    if (EnableTrace()) {
8524514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
8534514f5e3Sopenharmony_ci    }
8544514f5e3Sopenharmony_ci    if (argc == 0) {
8554514f5e3Sopenharmony_ci        acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), builder_.Boolean(false));
8564514f5e3Sopenharmony_ci        return;
8574514f5e3Sopenharmony_ci    }
8584514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(op, {acc_.GetValueIn(gate, firstParam)});
8594514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
8604514f5e3Sopenharmony_ci}
8614514f5e3Sopenharmony_ci
8624514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineGlobalNanBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
8634514f5e3Sopenharmony_ci                                                     const GateMetaData* op, bool skipThis)
8644514f5e3Sopenharmony_ci{
8654514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
8664514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
8674514f5e3Sopenharmony_ci    if (!Uncheck()) {
8684514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
8694514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
8704514f5e3Sopenharmony_ci    }
8714514f5e3Sopenharmony_ci    if (EnableTrace()) {
8724514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
8734514f5e3Sopenharmony_ci    }
8744514f5e3Sopenharmony_ci    if (argc == 0) {
8754514f5e3Sopenharmony_ci        acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), builder_.Boolean(true));
8764514f5e3Sopenharmony_ci        return;
8774514f5e3Sopenharmony_ci    }
8784514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(op, {acc_.GetValueIn(gate, firstParam)});
8794514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
8804514f5e3Sopenharmony_ci}
8814514f5e3Sopenharmony_ci
8824514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineMathImulBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
8834514f5e3Sopenharmony_ci                                                    const GateMetaData* op, bool skipThis)
8844514f5e3Sopenharmony_ci{
8854514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
8864514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
8874514f5e3Sopenharmony_ci    if (!Uncheck()) {
8884514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
8894514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
8904514f5e3Sopenharmony_ci    }
8914514f5e3Sopenharmony_ci    if (EnableTrace()) {
8924514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
8934514f5e3Sopenharmony_ci    }
8944514f5e3Sopenharmony_ci    if (argc < 2U) {
8954514f5e3Sopenharmony_ci        acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), builder_.Int32(0));
8964514f5e3Sopenharmony_ci        return;
8974514f5e3Sopenharmony_ci    }
8984514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(op, {acc_.GetValueIn(gate, firstParam),
8994514f5e3Sopenharmony_ci                                              acc_.GetValueIn(gate, firstParam + 1)});
9004514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
9014514f5e3Sopenharmony_ci    return;
9024514f5e3Sopenharmony_ci}
9034514f5e3Sopenharmony_ci
9044514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineMathBinaryBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
9054514f5e3Sopenharmony_ci                                                      const GateMetaData* op, bool skipThis)
9064514f5e3Sopenharmony_ci{
9074514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
9084514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
9094514f5e3Sopenharmony_ci    if (!Uncheck()) {
9104514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
9114514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
9124514f5e3Sopenharmony_ci    }
9134514f5e3Sopenharmony_ci    if (EnableTrace()) {
9144514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
9154514f5e3Sopenharmony_ci    }
9164514f5e3Sopenharmony_ci    if (argc < 2U) {
9174514f5e3Sopenharmony_ci        acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), builder_.NanValue());
9184514f5e3Sopenharmony_ci        return;
9194514f5e3Sopenharmony_ci    }
9204514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(op, {acc_.GetValueIn(gate, firstParam),
9214514f5e3Sopenharmony_ci                                              acc_.GetValueIn(gate, firstParam + 1)});
9224514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
9234514f5e3Sopenharmony_ci    return;
9244514f5e3Sopenharmony_ci}
9254514f5e3Sopenharmony_ci
9264514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineMathMinMaxBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
9274514f5e3Sopenharmony_ci                                                      const GateMetaData* op, double defaultValue, bool skipThis)
9284514f5e3Sopenharmony_ci{
9294514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
9304514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
9314514f5e3Sopenharmony_ci    if (!Uncheck()) {
9324514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
9334514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
9344514f5e3Sopenharmony_ci    }
9354514f5e3Sopenharmony_ci    if (EnableTrace()) {
9364514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
9374514f5e3Sopenharmony_ci    }
9384514f5e3Sopenharmony_ci    if (argc == 0) {
9394514f5e3Sopenharmony_ci        acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), builder_.Double(defaultValue));
9404514f5e3Sopenharmony_ci        return;
9414514f5e3Sopenharmony_ci    }
9424514f5e3Sopenharmony_ci    GateRef ret = acc_.GetValueIn(gate, firstParam);
9434514f5e3Sopenharmony_ci    if (argc == 1) {
9444514f5e3Sopenharmony_ci        builder_.TypeOfCheck(ret, ParamType::NumberType());
9454514f5e3Sopenharmony_ci        acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
9464514f5e3Sopenharmony_ci        return;
9474514f5e3Sopenharmony_ci    }
9484514f5e3Sopenharmony_ci    for (size_t i = 1; i < argc; i++) {
9494514f5e3Sopenharmony_ci        auto param = acc_.GetValueIn(gate, i + firstParam);
9504514f5e3Sopenharmony_ci        ret = builder_.BuildControlDependOp(op, {ret, param});
9514514f5e3Sopenharmony_ci    }
9524514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
9534514f5e3Sopenharmony_ci}
9544514f5e3Sopenharmony_ci
9554514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArrayBufferIsView(GateRef gate,
9564514f5e3Sopenharmony_ci                                                      size_t argc,
9574514f5e3Sopenharmony_ci                                                      BuiltinsStubCSigns::ID id,
9584514f5e3Sopenharmony_ci                                                      bool skipThis)
9594514f5e3Sopenharmony_ci{
9604514f5e3Sopenharmony_ci    if (!skipThis) {
9614514f5e3Sopenharmony_ci        return;
9624514f5e3Sopenharmony_ci    }
9634514f5e3Sopenharmony_ci    if (argc != 1) {
9644514f5e3Sopenharmony_ci        return;
9654514f5e3Sopenharmony_ci    }
9664514f5e3Sopenharmony_ci    CallThis1TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
9674514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
9684514f5e3Sopenharmony_ci    if (!Uncheck()) {
9694514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, tacc.GetFunc(), builder_.IntPtr(static_cast<int64_t>(id)), {tacc.GetArg0()});
9704514f5e3Sopenharmony_ci    }
9714514f5e3Sopenharmony_ci    GateRef arg0 = tacc.GetArg0();
9724514f5e3Sopenharmony_ci    GateRef ret = builder_.ArrayBufferIsView(arg0);
9734514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
9744514f5e3Sopenharmony_ci}
9754514f5e3Sopenharmony_ci
9764514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineDataViewGet(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
9774514f5e3Sopenharmony_ci{
9784514f5e3Sopenharmony_ci    if (!skipThis) {
9794514f5e3Sopenharmony_ci        return;
9804514f5e3Sopenharmony_ci    }
9814514f5e3Sopenharmony_ci    if (argc != 1 && argc != 2) { // number of args must be 1/2
9824514f5e3Sopenharmony_ci        return;
9834514f5e3Sopenharmony_ci    }
9844514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
9854514f5e3Sopenharmony_ci    if (!Uncheck()) {
9864514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
9874514f5e3Sopenharmony_ci    }
9884514f5e3Sopenharmony_ci    GateRef thisObj = acc_.GetValueIn(gate, 0); // 0: this
9894514f5e3Sopenharmony_ci    builder_.EcmaObjectCheck(thisObj);
9904514f5e3Sopenharmony_ci    builder_.IsDataViewCheck(thisObj);
9914514f5e3Sopenharmony_ci    GateRef dataViewCallID = builder_.Int32(id);
9924514f5e3Sopenharmony_ci    GateRef index = acc_.GetValueIn(gate, 1); // 1: index of dataView
9934514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
9944514f5e3Sopenharmony_ci    GateRef frameState = acc_.GetFrameState(gate);
9954514f5e3Sopenharmony_ci    builder_.DeoptCheck(builder_.TaggedIsInt(index), frameState, DeoptType::INDEXNOTINT);
9964514f5e3Sopenharmony_ci    GateRef indexInt = builder_.TaggedGetInt(index);
9974514f5e3Sopenharmony_ci    if (argc == 1) { // if not provide isLittleEndian, default use big endian
9984514f5e3Sopenharmony_ci        ret = builder_.DataViewGet(thisObj, indexInt, dataViewCallID, builder_.False(), frameState);
9994514f5e3Sopenharmony_ci    } else if (argc == 2) { // 2: provide isLittleEndian
10004514f5e3Sopenharmony_ci        GateRef isLittleEndian = acc_.GetValueIn(gate, 2); // 2: is little endian mode
10014514f5e3Sopenharmony_ci        ret = builder_.DataViewGet(thisObj, indexInt, dataViewCallID, isLittleEndian, frameState);
10024514f5e3Sopenharmony_ci    }
10034514f5e3Sopenharmony_ci    if (EnableTrace()) {
10044514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
10054514f5e3Sopenharmony_ci    }
10064514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
10074514f5e3Sopenharmony_ci}
10084514f5e3Sopenharmony_ci
10094514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineDataViewSet(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
10104514f5e3Sopenharmony_ci{
10114514f5e3Sopenharmony_ci    if (!skipThis) {
10124514f5e3Sopenharmony_ci        return;
10134514f5e3Sopenharmony_ci    }
10144514f5e3Sopenharmony_ci    if (argc != 1 && argc != 2 && argc != 3) { // number of args must be 1/2/3
10154514f5e3Sopenharmony_ci        return;
10164514f5e3Sopenharmony_ci    }
10174514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
10184514f5e3Sopenharmony_ci    if (!Uncheck()) {
10194514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
10204514f5e3Sopenharmony_ci    }
10214514f5e3Sopenharmony_ci    GateRef thisObj = acc_.GetValueIn(gate, 0); // 0: this
10224514f5e3Sopenharmony_ci    builder_.EcmaObjectCheck(thisObj);
10234514f5e3Sopenharmony_ci    builder_.IsDataViewCheck(thisObj);
10244514f5e3Sopenharmony_ci    GateRef dataViewCallID = builder_.Int32(id);
10254514f5e3Sopenharmony_ci    GateRef index = acc_.GetValueIn(gate, 1); // 1: index
10264514f5e3Sopenharmony_ci    GateRef frameState = acc_.GetFrameState(gate);
10274514f5e3Sopenharmony_ci    builder_.DeoptCheck(builder_.TaggedIsInt(index), frameState, DeoptType::INDEXNOTINT);
10284514f5e3Sopenharmony_ci    GateRef indexInt = builder_.TaggedGetInt(index);
10294514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
10304514f5e3Sopenharmony_ci    if (argc == 1) { // arg counts is 1
10314514f5e3Sopenharmony_ci        ret = builder_.DataViewSet(
10324514f5e3Sopenharmony_ci            thisObj, indexInt, builder_.Double(base::NAN_VALUE), dataViewCallID, builder_.False(), frameState);
10334514f5e3Sopenharmony_ci    } else if (argc == 2) { // arg counts is 2
10344514f5e3Sopenharmony_ci        GateRef value = acc_.GetValueIn(gate, 2); // 2: value
10354514f5e3Sopenharmony_ci        ret = builder_.DataViewSet(thisObj, indexInt, value, dataViewCallID, builder_.False(), frameState);
10364514f5e3Sopenharmony_ci    } else if (argc == 3) { // arg counts is 3
10374514f5e3Sopenharmony_ci        GateRef value = acc_.GetValueIn(gate, 2); // 2: value
10384514f5e3Sopenharmony_ci        GateRef isLittleEndian = acc_.GetValueIn(gate, 3); // 3: is little endian mode
10394514f5e3Sopenharmony_ci        ret = builder_.DataViewSet(thisObj, indexInt, value, dataViewCallID, isLittleEndian, frameState);
10404514f5e3Sopenharmony_ci    }
10414514f5e3Sopenharmony_ci    if (EnableTrace()) {
10424514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
10434514f5e3Sopenharmony_ci    }
10444514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
10454514f5e3Sopenharmony_ci}
10464514f5e3Sopenharmony_ci
10474514f5e3Sopenharmony_civoid NativeInlineLowering::InlineStubBuiltin(GateRef gate, size_t builtinArgc, size_t realArgc,
10484514f5e3Sopenharmony_ci    BuiltinsStubCSigns::ID id, const GateMetaData* op, bool skipThis)
10494514f5e3Sopenharmony_ci{
10504514f5e3Sopenharmony_ci    if (!skipThis) {
10514514f5e3Sopenharmony_ci        return;
10524514f5e3Sopenharmony_ci    }
10534514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
10544514f5e3Sopenharmony_ci    if (!Uncheck()) {
10554514f5e3Sopenharmony_ci        GateRef obj = acc_.GetValueIn(gate, 0);
10564514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, realArgc + 1U),
10574514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)), {obj});
10584514f5e3Sopenharmony_ci    }
10594514f5e3Sopenharmony_ci    if (EnableTrace()) {
10604514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
10614514f5e3Sopenharmony_ci    }
10624514f5e3Sopenharmony_ci
10634514f5e3Sopenharmony_ci    std::vector<GateRef> args {};
10644514f5e3Sopenharmony_ci    for (size_t i = 0; i <= builtinArgc; i++) {
10654514f5e3Sopenharmony_ci        args.push_back(i <= realArgc ? acc_.GetValueIn(gate, i) : builder_.Undefined());
10664514f5e3Sopenharmony_ci    }
10674514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(op, args);
10684514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
10694514f5e3Sopenharmony_ci}
10704514f5e3Sopenharmony_ci
10714514f5e3Sopenharmony_civoid NativeInlineLowering::ReplaceGateWithPendingException(GateRef hirGate, GateRef value)
10724514f5e3Sopenharmony_ci{
10734514f5e3Sopenharmony_ci    GateRef state = builder_.GetState();
10744514f5e3Sopenharmony_ci    // copy depend-wire of hirGate to value
10754514f5e3Sopenharmony_ci    GateRef depend = builder_.GetDepend();
10764514f5e3Sopenharmony_ci    // exception condition
10774514f5e3Sopenharmony_ci    GateRef condition = builder_.HasPendingException(glue_);
10784514f5e3Sopenharmony_ci    auto ifBranch = builder_.Branch(state, condition, 1, BranchWeight::DEOPT_WEIGHT, "checkException");
10794514f5e3Sopenharmony_ci
10804514f5e3Sopenharmony_ci    GateRef ifTrue = builder_.IfTrue(ifBranch);
10814514f5e3Sopenharmony_ci    GateRef ifFalse = builder_.IfFalse(ifBranch);
10824514f5e3Sopenharmony_ci    GateRef eDepend = builder_.DependRelay(ifTrue, depend);
10834514f5e3Sopenharmony_ci    GateRef sDepend = builder_.DependRelay(ifFalse, depend);
10844514f5e3Sopenharmony_ci    StateDepend success(ifFalse, sDepend);
10854514f5e3Sopenharmony_ci    StateDepend exception(ifTrue, eDepend);
10864514f5e3Sopenharmony_ci    acc_.ReplaceHirWithIfBranch(hirGate, success, exception, value);
10874514f5e3Sopenharmony_ci}
10884514f5e3Sopenharmony_ci
10894514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineBigIntConstructor(GateRef gate, size_t argc, bool skipThis)
10904514f5e3Sopenharmony_ci{
10914514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
10924514f5e3Sopenharmony_ci    bool firstParam = skipThis ? 1 : 0;
10934514f5e3Sopenharmony_ci    auto id = BuiltinsStubCSigns::ID::BigIntConstructor;
10944514f5e3Sopenharmony_ci    if (!Uncheck()) {
10954514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
10964514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
10974514f5e3Sopenharmony_ci    }
10984514f5e3Sopenharmony_ci    if (EnableTrace()) {
10994514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
11004514f5e3Sopenharmony_ci    }
11014514f5e3Sopenharmony_ci
11024514f5e3Sopenharmony_ci    auto param = builder_.Undefined();
11034514f5e3Sopenharmony_ci    if (argc > 0) {
11044514f5e3Sopenharmony_ci        param = acc_.GetValueIn(gate, firstParam);
11054514f5e3Sopenharmony_ci    }
11064514f5e3Sopenharmony_ci
11074514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->BigIntConstructor(), {param});
11084514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
11094514f5e3Sopenharmony_ci    return;
11104514f5e3Sopenharmony_ci}
11114514f5e3Sopenharmony_ci
11124514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineDateGetTime(GateRef gate, size_t argc, bool skipThis)
11134514f5e3Sopenharmony_ci{
11144514f5e3Sopenharmony_ci    // Always shout be "this", we can't inline this function without instance of object
11154514f5e3Sopenharmony_ci    if (!skipThis) {
11164514f5e3Sopenharmony_ci        return;
11174514f5e3Sopenharmony_ci    }
11184514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
11194514f5e3Sopenharmony_ci    // We are sure, that "this" is passed to this function, so always need to do +1
11204514f5e3Sopenharmony_ci    bool firstParam = 1;
11214514f5e3Sopenharmony_ci    if (!Uncheck()) {
11224514f5e3Sopenharmony_ci        GateRef obj = acc_.GetValueIn(gate, 0);
11234514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
11244514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(BuiltinsStubCSigns::ID::DateGetTime)), {obj});
11254514f5e3Sopenharmony_ci    }
11264514f5e3Sopenharmony_ci    if (EnableTrace()) {
11274514f5e3Sopenharmony_ci        AddTraceLogs(gate, BuiltinsStubCSigns::ID::DateGetTime);
11284514f5e3Sopenharmony_ci    }
11294514f5e3Sopenharmony_ci    // Take object using "this"
11304514f5e3Sopenharmony_ci    GateRef obj = acc_.GetValueIn(gate, 0);
11314514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->DateGetTime(), {obj});
11324514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
11334514f5e3Sopenharmony_ci}
11344514f5e3Sopenharmony_ci
11354514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineObjectIs(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
11364514f5e3Sopenharmony_ci{
11374514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
11384514f5e3Sopenharmony_ci    if (argc != 2) {  // 2: left and right
11394514f5e3Sopenharmony_ci        return;
11404514f5e3Sopenharmony_ci    }
11414514f5e3Sopenharmony_ci
11424514f5e3Sopenharmony_ci    size_t firstParam = skipThis ? 1 : 0;
11434514f5e3Sopenharmony_ci    if (!Uncheck()) {
11444514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
11454514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
11464514f5e3Sopenharmony_ci    }
11474514f5e3Sopenharmony_ci
11484514f5e3Sopenharmony_ci    if (EnableTrace()) {
11494514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
11504514f5e3Sopenharmony_ci    }
11514514f5e3Sopenharmony_ci
11524514f5e3Sopenharmony_ci    GateRef left = acc_.GetValueIn(gate, firstParam);
11534514f5e3Sopenharmony_ci    GateRef right = acc_.GetValueIn(gate, firstParam + 1);
11544514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ObjectIs(), { left, right });
11554514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
11564514f5e3Sopenharmony_ci}
11574514f5e3Sopenharmony_ci
11584514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineObjectGetPrototypeOf(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
11594514f5e3Sopenharmony_ci                                                         bool skipThis)
11604514f5e3Sopenharmony_ci{
11614514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
11624514f5e3Sopenharmony_ci    if (argc != 1) {
11634514f5e3Sopenharmony_ci        return;
11644514f5e3Sopenharmony_ci    }
11654514f5e3Sopenharmony_ci
11664514f5e3Sopenharmony_ci    size_t firstParam = skipThis ? 1 : 0;
11674514f5e3Sopenharmony_ci    if (!Uncheck()) {
11684514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
11694514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
11704514f5e3Sopenharmony_ci    }
11714514f5e3Sopenharmony_ci
11724514f5e3Sopenharmony_ci    if (EnableTrace()) {
11734514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
11744514f5e3Sopenharmony_ci    }
11754514f5e3Sopenharmony_ci
11764514f5e3Sopenharmony_ci    GateRef value = acc_.GetValueIn(gate, firstParam);
11774514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ObjectGetPrototypeOf(), { value });
11784514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
11794514f5e3Sopenharmony_ci}
11804514f5e3Sopenharmony_ci
11814514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineObjectGetProto(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
11824514f5e3Sopenharmony_ci{
11834514f5e3Sopenharmony_ci    if (!skipThis || argc != 0) {
11844514f5e3Sopenharmony_ci        return;
11854514f5e3Sopenharmony_ci    }
11864514f5e3Sopenharmony_ci
11874514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
11884514f5e3Sopenharmony_ci    if (!Uncheck()) {
11894514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, 1), builder_.IntPtr(static_cast<int64_t>(id)));  // 1: func
11904514f5e3Sopenharmony_ci    }
11914514f5e3Sopenharmony_ci
11924514f5e3Sopenharmony_ci    if (EnableTrace()) {
11934514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
11944514f5e3Sopenharmony_ci    }
11954514f5e3Sopenharmony_ci
11964514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
11974514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ObjectGetPrototypeOf(), { thisValue });
11984514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
11994514f5e3Sopenharmony_ci}
12004514f5e3Sopenharmony_ci
12014514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineObjectCreate(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
12024514f5e3Sopenharmony_ci{
12034514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
12044514f5e3Sopenharmony_ci    if (argc != 1) {
12054514f5e3Sopenharmony_ci        return;
12064514f5e3Sopenharmony_ci    }
12074514f5e3Sopenharmony_ci
12084514f5e3Sopenharmony_ci    size_t firstParam = skipThis ? 1 : 0;
12094514f5e3Sopenharmony_ci    if (!Uncheck()) {
12104514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
12114514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
12124514f5e3Sopenharmony_ci    }
12134514f5e3Sopenharmony_ci
12144514f5e3Sopenharmony_ci    if (EnableTrace()) {
12154514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
12164514f5e3Sopenharmony_ci    }
12174514f5e3Sopenharmony_ci
12184514f5e3Sopenharmony_ci    GateRef proto = acc_.GetValueIn(gate, firstParam);
12194514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ObjectCreate(), { proto });
12204514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
12214514f5e3Sopenharmony_ci}
12224514f5e3Sopenharmony_ci
12234514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineObjectIsPrototypeOf(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
12244514f5e3Sopenharmony_ci                                                        bool skipThis)
12254514f5e3Sopenharmony_ci{
12264514f5e3Sopenharmony_ci    if (!skipThis || argc != 1) {
12274514f5e3Sopenharmony_ci        return;
12284514f5e3Sopenharmony_ci    }
12294514f5e3Sopenharmony_ci
12304514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
12314514f5e3Sopenharmony_ci    if (!Uncheck()) {
12324514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, 2), builder_.IntPtr(static_cast<int64_t>(id)));  // 2: func
12334514f5e3Sopenharmony_ci    }
12344514f5e3Sopenharmony_ci
12354514f5e3Sopenharmony_ci    if (EnableTrace()) {
12364514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
12374514f5e3Sopenharmony_ci    }
12384514f5e3Sopenharmony_ci
12394514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
12404514f5e3Sopenharmony_ci    GateRef value = acc_.GetValueIn(gate, 1);
12414514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ObjectIsPrototypeOf(), {thisValue, value});
12424514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
12434514f5e3Sopenharmony_ci}
12444514f5e3Sopenharmony_ci
12454514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineObjectHasOwnProperty(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
12464514f5e3Sopenharmony_ci                                                         bool skipThis)
12474514f5e3Sopenharmony_ci{
12484514f5e3Sopenharmony_ci    if (!skipThis || argc != 1) {
12494514f5e3Sopenharmony_ci        return;
12504514f5e3Sopenharmony_ci    }
12514514f5e3Sopenharmony_ci
12524514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
12534514f5e3Sopenharmony_ci    if (!Uncheck()) {
12544514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, 2), builder_.IntPtr(static_cast<int64_t>(id)));  // 2: func
12554514f5e3Sopenharmony_ci    }
12564514f5e3Sopenharmony_ci
12574514f5e3Sopenharmony_ci    if (EnableTrace()) {
12584514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
12594514f5e3Sopenharmony_ci    }
12604514f5e3Sopenharmony_ci
12614514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
12624514f5e3Sopenharmony_ci    GateRef key = acc_.GetValueIn(gate, 1);
12634514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ObjectHasOwnProperty(), { thisValue, key });
12644514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
12654514f5e3Sopenharmony_ci}
12664514f5e3Sopenharmony_ci
12674514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineReflectGetPrototypeOf(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
12684514f5e3Sopenharmony_ci                                                          bool skipThis)
12694514f5e3Sopenharmony_ci{
12704514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
12714514f5e3Sopenharmony_ci    if (argc != 1) {
12724514f5e3Sopenharmony_ci        return;
12734514f5e3Sopenharmony_ci    }
12744514f5e3Sopenharmony_ci
12754514f5e3Sopenharmony_ci    size_t firstParam = skipThis ? 1 : 0;
12764514f5e3Sopenharmony_ci    if (!Uncheck()) {
12774514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
12784514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
12794514f5e3Sopenharmony_ci    }
12804514f5e3Sopenharmony_ci
12814514f5e3Sopenharmony_ci    if (EnableTrace()) {
12824514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
12834514f5e3Sopenharmony_ci    }
12844514f5e3Sopenharmony_ci
12854514f5e3Sopenharmony_ci    GateRef value = acc_.GetValueIn(gate, firstParam);
12864514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ReflectGetPrototypeOf(), { value });
12874514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
12884514f5e3Sopenharmony_ci}
12894514f5e3Sopenharmony_ci
12904514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineReflectGet(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
12914514f5e3Sopenharmony_ci{
12924514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
12934514f5e3Sopenharmony_ci    if (argc != 2) {  // 2: target and key, do not handle receiver argument scene
12944514f5e3Sopenharmony_ci        return;
12954514f5e3Sopenharmony_ci    }
12964514f5e3Sopenharmony_ci
12974514f5e3Sopenharmony_ci    size_t firstParam = skipThis ? 1 : 0;
12984514f5e3Sopenharmony_ci    GateRef key = acc_.GetValueIn(gate, firstParam + 1);
12994514f5e3Sopenharmony_ci    if (!TypeInfoAccessor::IsTrustedStringType(compilationEnv_, circuit_, chunk_, acc_, key)) {
13004514f5e3Sopenharmony_ci        return;
13014514f5e3Sopenharmony_ci    }
13024514f5e3Sopenharmony_ci
13034514f5e3Sopenharmony_ci    if (!Uncheck()) {
13044514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
13054514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
13064514f5e3Sopenharmony_ci    }
13074514f5e3Sopenharmony_ci
13084514f5e3Sopenharmony_ci    if (EnableTrace()) {
13094514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
13104514f5e3Sopenharmony_ci    }
13114514f5e3Sopenharmony_ci
13124514f5e3Sopenharmony_ci    GateRef target = acc_.GetValueIn(gate, firstParam);
13134514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ReflectGet(), { target, key });
13144514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
13154514f5e3Sopenharmony_ci}
13164514f5e3Sopenharmony_ci
13174514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineReflectHas(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
13184514f5e3Sopenharmony_ci{
13194514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
13204514f5e3Sopenharmony_ci    if (argc != 2) {  // 2: target and key
13214514f5e3Sopenharmony_ci        return;
13224514f5e3Sopenharmony_ci    }
13234514f5e3Sopenharmony_ci
13244514f5e3Sopenharmony_ci    size_t firstParam = skipThis ? 1 : 0;
13254514f5e3Sopenharmony_ci    if (!Uncheck()) {
13264514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
13274514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
13284514f5e3Sopenharmony_ci    }
13294514f5e3Sopenharmony_ci
13304514f5e3Sopenharmony_ci    if (EnableTrace()) {
13314514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
13324514f5e3Sopenharmony_ci    }
13334514f5e3Sopenharmony_ci
13344514f5e3Sopenharmony_ci    GateRef target = acc_.GetValueIn(gate, firstParam);
13354514f5e3Sopenharmony_ci    GateRef key = acc_.GetValueIn(gate, firstParam + 1);
13364514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ReflectHas(), { target, key });
13374514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
13384514f5e3Sopenharmony_ci}
13394514f5e3Sopenharmony_ci
13404514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineReflectConstruct(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
13414514f5e3Sopenharmony_ci                                                     bool skipThis)
13424514f5e3Sopenharmony_ci{
13434514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
13444514f5e3Sopenharmony_ci    if (argc != 2) {  // 2: optimize newtarget equal target
13454514f5e3Sopenharmony_ci        return;
13464514f5e3Sopenharmony_ci    }
13474514f5e3Sopenharmony_ci
13484514f5e3Sopenharmony_ci    size_t firstParam = skipThis ? 1 : 0;
13494514f5e3Sopenharmony_ci    GateRef target = acc_.GetValueIn(gate, firstParam);
13504514f5e3Sopenharmony_ci    GateRef argumentsList = acc_.GetValueIn(gate, firstParam + 1);
13514514f5e3Sopenharmony_ci
13524514f5e3Sopenharmony_ci    OpCode op = acc_.GetOpCode(argumentsList);
13534514f5e3Sopenharmony_ci    if (op != OpCode::JS_BYTECODE) {
13544514f5e3Sopenharmony_ci        return;
13554514f5e3Sopenharmony_ci    }
13564514f5e3Sopenharmony_ci
13574514f5e3Sopenharmony_ci    EcmaOpcode ecmaOpcode = acc_.GetByteCodeOpcode(argumentsList);
13584514f5e3Sopenharmony_ci    // optimize empty array literal argumentsList
13594514f5e3Sopenharmony_ci    if ((ecmaOpcode != EcmaOpcode::CREATEEMPTYARRAY_IMM8) && (ecmaOpcode != EcmaOpcode::CREATEEMPTYARRAY_IMM16)) {
13604514f5e3Sopenharmony_ci        return;
13614514f5e3Sopenharmony_ci    }
13624514f5e3Sopenharmony_ci
13634514f5e3Sopenharmony_ci    if (!Uncheck()) {
13644514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
13654514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
13664514f5e3Sopenharmony_ci    }
13674514f5e3Sopenharmony_ci
13684514f5e3Sopenharmony_ci    if (EnableTrace()) {
13694514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
13704514f5e3Sopenharmony_ci    }
13714514f5e3Sopenharmony_ci
13724514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ReflectConstruct(), { target });
13734514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
13744514f5e3Sopenharmony_ci}
13754514f5e3Sopenharmony_ci
13764514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineReflectApply(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
13774514f5e3Sopenharmony_ci                                                 bool skipThis)
13784514f5e3Sopenharmony_ci{
13794514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
13804514f5e3Sopenharmony_ci    if (argc != 3) {  // 3: target key and  argumentsList
13814514f5e3Sopenharmony_ci        return;
13824514f5e3Sopenharmony_ci    }
13834514f5e3Sopenharmony_ci
13844514f5e3Sopenharmony_ci    size_t firstParam = skipThis ? 1 : 0;
13854514f5e3Sopenharmony_ci    GateRef target = acc_.GetValueIn(gate, firstParam);
13864514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, firstParam + 1);
13874514f5e3Sopenharmony_ci    GateRef argumentsList = acc_.GetValueIn(gate, firstParam + 2);
13884514f5e3Sopenharmony_ci
13894514f5e3Sopenharmony_ci    if (!Uncheck()) {
13904514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + firstParam),
13914514f5e3Sopenharmony_ci                                 builder_.IntPtr(static_cast<int64_t>(id)));
13924514f5e3Sopenharmony_ci    }
13934514f5e3Sopenharmony_ci
13944514f5e3Sopenharmony_ci    if (EnableTrace()) {
13954514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
13964514f5e3Sopenharmony_ci    }
13974514f5e3Sopenharmony_ci
13984514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->ReflectApply(), { target, thisValue, argumentsList });
13994514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
14004514f5e3Sopenharmony_ci}
14014514f5e3Sopenharmony_ci
14024514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineFunctionPrototypeApply(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
14034514f5e3Sopenharmony_ci                                                           bool skipThis)
14044514f5e3Sopenharmony_ci{
14054514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
14064514f5e3Sopenharmony_ci    if (!skipThis || argc == 0) {
14074514f5e3Sopenharmony_ci        return;
14084514f5e3Sopenharmony_ci    }
14094514f5e3Sopenharmony_ci
14104514f5e3Sopenharmony_ci    if (!Uncheck()) {
14114514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
14124514f5e3Sopenharmony_ci    }
14134514f5e3Sopenharmony_ci
14144514f5e3Sopenharmony_ci    if (EnableTrace()) {
14154514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
14164514f5e3Sopenharmony_ci    }
14174514f5e3Sopenharmony_ci
14184514f5e3Sopenharmony_ci    GateRef thisFunc = acc_.GetValueIn(gate, 0);
14194514f5e3Sopenharmony_ci    GateRef thisArg = acc_.GetValueIn(gate, 1);
14204514f5e3Sopenharmony_ci    GateRef argArray = (argc == 2) ? (acc_.GetValueIn(gate, 2)) : (builder_.UndefineConstant());
14214514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->FunctionPrototypeApply(), { thisFunc, thisArg, argArray });
14224514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
14234514f5e3Sopenharmony_ci}
14244514f5e3Sopenharmony_ci
14254514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineFunctionPrototypeBind(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
14264514f5e3Sopenharmony_ci                                                          bool skipThis)
14274514f5e3Sopenharmony_ci{
14284514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
14294514f5e3Sopenharmony_ci    if (!skipThis || argc != 1) {
14304514f5e3Sopenharmony_ci        return;
14314514f5e3Sopenharmony_ci    }
14324514f5e3Sopenharmony_ci
14334514f5e3Sopenharmony_ci    if (!Uncheck()) {
14344514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, 2), builder_.IntPtr(static_cast<int64_t>(id)));  // 2: func
14354514f5e3Sopenharmony_ci    }
14364514f5e3Sopenharmony_ci
14374514f5e3Sopenharmony_ci    if (EnableTrace()) {
14384514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
14394514f5e3Sopenharmony_ci    }
14404514f5e3Sopenharmony_ci
14414514f5e3Sopenharmony_ci    GateRef target = acc_.GetValueIn(gate, 0);
14424514f5e3Sopenharmony_ci    GateRef thisArg = acc_.GetValueIn(gate, 1);
14434514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->FunctionPrototypeBind(), { target, thisArg });
14444514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
14454514f5e3Sopenharmony_ci}
14464514f5e3Sopenharmony_ci
14474514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineFunctionPrototypeCall(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
14484514f5e3Sopenharmony_ci                                                          bool skipThis)
14494514f5e3Sopenharmony_ci{
14504514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
14514514f5e3Sopenharmony_ci    if (!skipThis || argc == 0) {
14524514f5e3Sopenharmony_ci        return;
14534514f5e3Sopenharmony_ci    }
14544514f5e3Sopenharmony_ci
14554514f5e3Sopenharmony_ci    if (!Uncheck()) {
14564514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
14574514f5e3Sopenharmony_ci    }
14584514f5e3Sopenharmony_ci
14594514f5e3Sopenharmony_ci    if (EnableTrace()) {
14604514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
14614514f5e3Sopenharmony_ci    }
14624514f5e3Sopenharmony_ci
14634514f5e3Sopenharmony_ci    std::vector<GateRef> args(argc + 1);  // 1: thisFunc
14644514f5e3Sopenharmony_ci    for (size_t i = 0; i <= argc; ++i) {
14654514f5e3Sopenharmony_ci        args[i] = acc_.GetValueIn(gate, i);
14664514f5e3Sopenharmony_ci    }
14674514f5e3Sopenharmony_ci    GateRef ret = builder_.BuildControlDependOp(circuit_->FunctionPrototypeCall(argc + 1), args);
14684514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
14694514f5e3Sopenharmony_ci}
14704514f5e3Sopenharmony_ci
14714514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineFunctionPrototypeHasInstance(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id,
14724514f5e3Sopenharmony_ci                                                                 bool skipThis)
14734514f5e3Sopenharmony_ci{
14744514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
14754514f5e3Sopenharmony_ci    if (!skipThis || argc != 1) {
14764514f5e3Sopenharmony_ci        return;
14774514f5e3Sopenharmony_ci    }
14784514f5e3Sopenharmony_ci
14794514f5e3Sopenharmony_ci    if (!Uncheck()) {
14804514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, 2), builder_.IntPtr(static_cast<int64_t>(id)));  // 2: func
14814514f5e3Sopenharmony_ci    }
14824514f5e3Sopenharmony_ci
14834514f5e3Sopenharmony_ci    if (EnableTrace()) {
14844514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
14854514f5e3Sopenharmony_ci    }
14864514f5e3Sopenharmony_ci
14874514f5e3Sopenharmony_ci    GateRef function = acc_.GetValueIn(gate, 0);
14884514f5e3Sopenharmony_ci    GateRef value = acc_.GetValueIn(gate, 1);
14894514f5e3Sopenharmony_ci    GateRef ret = builder_.OrdinaryHasInstance(value, function);
14904514f5e3Sopenharmony_ci    ReplaceGateWithPendingException(gate, ret);
14914514f5e3Sopenharmony_ci}
14924514f5e3Sopenharmony_ci
14934514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineIndexOfIncludes(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
14944514f5e3Sopenharmony_ci{
14954514f5e3Sopenharmony_ci    if (!skipThis) {
14964514f5e3Sopenharmony_ci        return;
14974514f5e3Sopenharmony_ci    }
14984514f5e3Sopenharmony_ci    if (argc == 0) {
14994514f5e3Sopenharmony_ci        return;
15004514f5e3Sopenharmony_ci    }
15014514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
15024514f5e3Sopenharmony_ci    GateRef thisArray = acc_.GetValueIn(gate, 0);
15034514f5e3Sopenharmony_ci    GateRef targetElement = acc_.GetValueIn(gate, 1);
15044514f5e3Sopenharmony_ci    ElementsKind kind = acc_.TryGetArrayElementsKind(thisArray);
15054514f5e3Sopenharmony_ci    if (!Uncheck()) {
15064514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
15074514f5e3Sopenharmony_ci    }
15084514f5e3Sopenharmony_ci    builder_.BuiltinPrototypeHClassCheck(thisArray, BuiltinTypeId::ARRAY, kind, false);
15094514f5e3Sopenharmony_ci    builder_.StableArrayCheck(thisArray, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
15104514f5e3Sopenharmony_ci    builder_.ElementsKindCheck(thisArray, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
15114514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
15124514f5e3Sopenharmony_ci    GateRef callID = builder_.Int32(static_cast<int32_t>(id));
15134514f5e3Sopenharmony_ci    GateRef arrayKind = builder_.Int32(static_cast<int32_t>(kind));
15144514f5e3Sopenharmony_ci    if (argc == 1) {
15154514f5e3Sopenharmony_ci        ret = builder_.ArrayIncludesIndexOf(thisArray, builder_.Int32(0), targetElement, callID, arrayKind);
15164514f5e3Sopenharmony_ci    } else {
15174514f5e3Sopenharmony_ci        GateRef fromIndexHandler = acc_.GetValueIn(gate, 2);
15184514f5e3Sopenharmony_ci        builder_.DeoptCheck(builder_.TaggedIsInt(fromIndexHandler), acc_.GetFrameState(gate), DeoptType::INDEXNOTINT);
15194514f5e3Sopenharmony_ci        GateRef fromIndex = builder_.TaggedGetInt(fromIndexHandler);
15204514f5e3Sopenharmony_ci        ret = builder_.ArrayIncludesIndexOf(thisArray, fromIndex, targetElement, callID, arrayKind);
15214514f5e3Sopenharmony_ci    }
15224514f5e3Sopenharmony_ci    if (EnableTrace()) {
15234514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
15244514f5e3Sopenharmony_ci    }
15254514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
15264514f5e3Sopenharmony_ci}
15274514f5e3Sopenharmony_ci
15284514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArrayIterator(GateRef gate, BuiltinsStubCSigns::ID id, bool skipThis)
15294514f5e3Sopenharmony_ci{
15304514f5e3Sopenharmony_ci    if (!skipThis) {
15314514f5e3Sopenharmony_ci        return;
15324514f5e3Sopenharmony_ci    }
15334514f5e3Sopenharmony_ci    CallThis0TypeInfoAccessor tacc(compilationEnv_, circuit_, gate);
15344514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
15354514f5e3Sopenharmony_ci
15364514f5e3Sopenharmony_ci    if (!Uncheck()) {
15374514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, tacc.GetFunc(), builder_.IntPtr(static_cast<int64_t>(id)), {tacc.GetThisObj()});
15384514f5e3Sopenharmony_ci    }
15394514f5e3Sopenharmony_ci    if (EnableTrace()) {
15404514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
15414514f5e3Sopenharmony_ci    }
15424514f5e3Sopenharmony_ci    GateRef thisObj = acc_.GetValueIn(gate, 0);
15434514f5e3Sopenharmony_ci    builder_.EcmaObjectCheck(thisObj);
15444514f5e3Sopenharmony_ci    GateRef CallIDRef = builder_.Int32(static_cast<int32_t>(id));
15454514f5e3Sopenharmony_ci    GateRef ret = builder_.ArrayIteratorBuiltin(thisObj, CallIDRef);
15464514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
15474514f5e3Sopenharmony_ci}
15484514f5e3Sopenharmony_ci
15494514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArrayForEach(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
15504514f5e3Sopenharmony_ci{
15514514f5e3Sopenharmony_ci    if (argc == 0) { // 0: Must have a callBackFn
15524514f5e3Sopenharmony_ci        return;
15534514f5e3Sopenharmony_ci    }
15544514f5e3Sopenharmony_ci    if (!skipThis) {
15554514f5e3Sopenharmony_ci        return;
15564514f5e3Sopenharmony_ci    }
15574514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
15584514f5e3Sopenharmony_ci    auto pcOffset = acc_.TryGetPcOffset(gate);
15594514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
15604514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
15614514f5e3Sopenharmony_ci    ElementsKind kind = acc_.TryGetArrayElementsKind(thisValue);
15624514f5e3Sopenharmony_ci    if (Elements::IsHole(kind)) {
15634514f5e3Sopenharmony_ci        return;
15644514f5e3Sopenharmony_ci    }
15654514f5e3Sopenharmony_ci    if (!Uncheck()) {
15664514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
15674514f5e3Sopenharmony_ci    }
15684514f5e3Sopenharmony_ci    builder_.BuiltinPrototypeHClassCheck(thisValue, BuiltinTypeId::ARRAY, kind, false);
15694514f5e3Sopenharmony_ci    builder_.StableArrayCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
15704514f5e3Sopenharmony_ci    builder_.ElementsKindCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
15714514f5e3Sopenharmony_ci    GateRef callBackFn = acc_.GetValueIn(gate, 1);
15724514f5e3Sopenharmony_ci    builder_.IsCallableCheck(callBackFn);
15734514f5e3Sopenharmony_ci    if (EnableTrace()) {
15744514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
15754514f5e3Sopenharmony_ci    }
15764514f5e3Sopenharmony_ci    if (argc == 1) {
15774514f5e3Sopenharmony_ci        ret = builder_.ArrayForEach(thisValue, callBackFn, builder_.UndefineConstant(), pcOffset);
15784514f5e3Sopenharmony_ci    } else {
15794514f5e3Sopenharmony_ci        ret = builder_.ArrayForEach(thisValue, callBackFn, acc_.GetValueIn(gate, 2), pcOffset); // 2:provide using This
15804514f5e3Sopenharmony_ci    }
15814514f5e3Sopenharmony_ci    acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), ret);
15824514f5e3Sopenharmony_ci}
15834514f5e3Sopenharmony_ci
15844514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArrayFindOrFindIndex(GateRef gate,
15854514f5e3Sopenharmony_ci                                                         size_t argc,
15864514f5e3Sopenharmony_ci                                                         BuiltinsStubCSigns::ID id,
15874514f5e3Sopenharmony_ci                                                         bool skipThis)
15884514f5e3Sopenharmony_ci{
15894514f5e3Sopenharmony_ci    if (argc == 0) { // 0: Must have a callBackFn
15904514f5e3Sopenharmony_ci        return;
15914514f5e3Sopenharmony_ci    }
15924514f5e3Sopenharmony_ci    if (!skipThis) {
15934514f5e3Sopenharmony_ci        return;
15944514f5e3Sopenharmony_ci    }
15954514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
15964514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
15974514f5e3Sopenharmony_ci    ElementsKind kind = acc_.TryGetArrayElementsKind(thisValue);
15984514f5e3Sopenharmony_ci    if (Elements::IsHole(kind)) {
15994514f5e3Sopenharmony_ci        return;
16004514f5e3Sopenharmony_ci    }
16014514f5e3Sopenharmony_ci    if (!Uncheck()) {
16024514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
16034514f5e3Sopenharmony_ci    }
16044514f5e3Sopenharmony_ci    uint32_t pcOffset = acc_.TryGetPcOffset(gate);
16054514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
16064514f5e3Sopenharmony_ci
16074514f5e3Sopenharmony_ci    builder_.BuiltinPrototypeHClassCheck(thisValue, BuiltinTypeId::ARRAY, kind, false);
16084514f5e3Sopenharmony_ci    builder_.StableArrayCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
16094514f5e3Sopenharmony_ci    builder_.ElementsKindCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
16104514f5e3Sopenharmony_ci    GateRef callBackFn = acc_.GetValueIn(gate, 1);
16114514f5e3Sopenharmony_ci    builder_.IsCallableCheck(callBackFn);
16124514f5e3Sopenharmony_ci    if (EnableTrace()) {
16134514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
16144514f5e3Sopenharmony_ci    }
16154514f5e3Sopenharmony_ci    GateRef callIDRef = builder_.Int32(static_cast<int32_t>(id));
16164514f5e3Sopenharmony_ci
16174514f5e3Sopenharmony_ci    if (argc == 1) {
16184514f5e3Sopenharmony_ci        ret = builder_.ArrayFindOrFindIndex(thisValue, callBackFn, builder_.UndefineConstant(), callIDRef, pcOffset);
16194514f5e3Sopenharmony_ci    } else {
16204514f5e3Sopenharmony_ci        ret = builder_.ArrayFindOrFindIndex(
16214514f5e3Sopenharmony_ci            thisValue, callBackFn, acc_.GetValueIn(gate, 2), callIDRef, pcOffset); // 2:provide using This
16224514f5e3Sopenharmony_ci    }
16234514f5e3Sopenharmony_ci    acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), ret);
16244514f5e3Sopenharmony_ci}
16254514f5e3Sopenharmony_ci
16264514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArrayFilter(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
16274514f5e3Sopenharmony_ci{
16284514f5e3Sopenharmony_ci    if (argc == 0) {
16294514f5e3Sopenharmony_ci        return;
16304514f5e3Sopenharmony_ci    }
16314514f5e3Sopenharmony_ci    if (!skipThis) {
16324514f5e3Sopenharmony_ci        return;
16334514f5e3Sopenharmony_ci    }
16344514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
16354514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
16364514f5e3Sopenharmony_ci    ElementsKind kind = acc_.TryGetArrayElementsKind(thisValue);
16374514f5e3Sopenharmony_ci    if (Elements::IsHole(kind)) {
16384514f5e3Sopenharmony_ci        return;
16394514f5e3Sopenharmony_ci    }
16404514f5e3Sopenharmony_ci    if (!Uncheck()) {
16414514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
16424514f5e3Sopenharmony_ci    }
16434514f5e3Sopenharmony_ci    builder_.BuiltinPrototypeHClassCheck(thisValue, BuiltinTypeId::ARRAY, kind, false);
16444514f5e3Sopenharmony_ci    builder_.StableArrayCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
16454514f5e3Sopenharmony_ci    builder_.ElementsKindCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
16464514f5e3Sopenharmony_ci    GateRef callBackFn = acc_.GetValueIn(gate, 1);
16474514f5e3Sopenharmony_ci    builder_.IsCallableCheck(callBackFn);
16484514f5e3Sopenharmony_ci    if (EnableTrace()) {
16494514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
16504514f5e3Sopenharmony_ci    }
16514514f5e3Sopenharmony_ci    uint32_t pcOffset = acc_.TryGetPcOffset(gate);
16524514f5e3Sopenharmony_ci    GateRef frameState = acc_.GetFrameState(gate);
16534514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
16544514f5e3Sopenharmony_ci    if (argc == 1) {
16554514f5e3Sopenharmony_ci        ret = builder_.ArrayFilter(thisValue, callBackFn, builder_.UndefineConstant(), frameState, pcOffset);
16564514f5e3Sopenharmony_ci    } else {
16574514f5e3Sopenharmony_ci        ret = builder_.ArrayFilter(
16584514f5e3Sopenharmony_ci            thisValue, callBackFn, acc_.GetValueIn(gate, 2), frameState, pcOffset); //2: provide usingThis
16594514f5e3Sopenharmony_ci    }
16604514f5e3Sopenharmony_ci    acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), ret);
16614514f5e3Sopenharmony_ci}
16624514f5e3Sopenharmony_ci
16634514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArrayMap(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
16644514f5e3Sopenharmony_ci{
16654514f5e3Sopenharmony_ci    if (argc == 0) {
16664514f5e3Sopenharmony_ci        return;
16674514f5e3Sopenharmony_ci    }
16684514f5e3Sopenharmony_ci    if (!skipThis) {
16694514f5e3Sopenharmony_ci        return;
16704514f5e3Sopenharmony_ci    }
16714514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
16724514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
16734514f5e3Sopenharmony_ci    ElementsKind kind = acc_.TryGetArrayElementsKind(thisValue);
16744514f5e3Sopenharmony_ci    if (Elements::IsHole(kind)) {
16754514f5e3Sopenharmony_ci        return;
16764514f5e3Sopenharmony_ci    }
16774514f5e3Sopenharmony_ci    if (!Uncheck()) {
16784514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
16794514f5e3Sopenharmony_ci    }
16804514f5e3Sopenharmony_ci    builder_.BuiltinPrototypeHClassCheck(thisValue, BuiltinTypeId::ARRAY, kind, false);
16814514f5e3Sopenharmony_ci    builder_.StableArrayCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
16824514f5e3Sopenharmony_ci    builder_.ElementsKindCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
16834514f5e3Sopenharmony_ci    GateRef callBackFn = acc_.GetValueIn(gate, 1);
16844514f5e3Sopenharmony_ci    builder_.IsCallableCheck(callBackFn);
16854514f5e3Sopenharmony_ci    if (EnableTrace()) {
16864514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
16874514f5e3Sopenharmony_ci    }
16884514f5e3Sopenharmony_ci    uint32_t pcOffset = acc_.TryGetPcOffset(gate);
16894514f5e3Sopenharmony_ci    GateRef frameState = acc_.GetFrameState(gate);
16904514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
16914514f5e3Sopenharmony_ci    if (argc == 1) {
16924514f5e3Sopenharmony_ci        ret = builder_.ArrayMap(thisValue, callBackFn, builder_.UndefineConstant(), frameState, pcOffset);
16934514f5e3Sopenharmony_ci    } else {
16944514f5e3Sopenharmony_ci        ret = builder_.ArrayMap(
16954514f5e3Sopenharmony_ci            thisValue, callBackFn, acc_.GetValueIn(gate, 2), frameState, pcOffset); //2: provide usingThis
16964514f5e3Sopenharmony_ci    }
16974514f5e3Sopenharmony_ci    acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), ret);
16984514f5e3Sopenharmony_ci}
16994514f5e3Sopenharmony_ci
17004514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArraySome(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
17014514f5e3Sopenharmony_ci{
17024514f5e3Sopenharmony_ci    if (argc == 0) {
17034514f5e3Sopenharmony_ci        return;
17044514f5e3Sopenharmony_ci    }
17054514f5e3Sopenharmony_ci    if (!skipThis) {
17064514f5e3Sopenharmony_ci        return;
17074514f5e3Sopenharmony_ci    }
17084514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
17094514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
17104514f5e3Sopenharmony_ci    ElementsKind kind = acc_.TryGetArrayElementsKind(thisValue);
17114514f5e3Sopenharmony_ci    if (Elements::IsHole(kind)) {
17124514f5e3Sopenharmony_ci        return;
17134514f5e3Sopenharmony_ci    }
17144514f5e3Sopenharmony_ci    if (!Uncheck()) {
17154514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
17164514f5e3Sopenharmony_ci    }
17174514f5e3Sopenharmony_ci    builder_.BuiltinPrototypeHClassCheck(thisValue, BuiltinTypeId::ARRAY, kind, false);
17184514f5e3Sopenharmony_ci    builder_.StableArrayCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
17194514f5e3Sopenharmony_ci    builder_.ElementsKindCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
17204514f5e3Sopenharmony_ci    GateRef callBackFn = acc_.GetValueIn(gate, 1);
17214514f5e3Sopenharmony_ci    builder_.IsCallableCheck(callBackFn);
17224514f5e3Sopenharmony_ci    if (EnableTrace()) {
17234514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
17244514f5e3Sopenharmony_ci    }
17254514f5e3Sopenharmony_ci    uint32_t pcOffset = acc_.TryGetPcOffset(gate);
17264514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
17274514f5e3Sopenharmony_ci    if (argc == 1) {
17284514f5e3Sopenharmony_ci        ret = builder_.ArraySome(thisValue, callBackFn, builder_.UndefineConstant(), pcOffset);
17294514f5e3Sopenharmony_ci    } else {
17304514f5e3Sopenharmony_ci        ret = builder_.ArraySome(thisValue, callBackFn, acc_.GetValueIn(gate, 2), pcOffset); //2: provide usingThis
17314514f5e3Sopenharmony_ci    }
17324514f5e3Sopenharmony_ci    acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), ret);
17334514f5e3Sopenharmony_ci}
17344514f5e3Sopenharmony_ci
17354514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArrayEvery(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
17364514f5e3Sopenharmony_ci{
17374514f5e3Sopenharmony_ci    if (argc == 0) {
17384514f5e3Sopenharmony_ci        return;
17394514f5e3Sopenharmony_ci    }
17404514f5e3Sopenharmony_ci    if (!skipThis) {
17414514f5e3Sopenharmony_ci        return;
17424514f5e3Sopenharmony_ci    }
17434514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
17444514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
17454514f5e3Sopenharmony_ci    ElementsKind kind = acc_.TryGetArrayElementsKind(thisValue);
17464514f5e3Sopenharmony_ci    if (Elements::IsHole(kind)) {
17474514f5e3Sopenharmony_ci        return;
17484514f5e3Sopenharmony_ci    }
17494514f5e3Sopenharmony_ci    if (!Uncheck()) {
17504514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
17514514f5e3Sopenharmony_ci    }
17524514f5e3Sopenharmony_ci    builder_.BuiltinPrototypeHClassCheck(thisValue, BuiltinTypeId::ARRAY, kind, false);
17534514f5e3Sopenharmony_ci    builder_.StableArrayCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
17544514f5e3Sopenharmony_ci    builder_.ElementsKindCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
17554514f5e3Sopenharmony_ci    GateRef callBackFn = acc_.GetValueIn(gate, 1);
17564514f5e3Sopenharmony_ci    builder_.IsCallableCheck(callBackFn);
17574514f5e3Sopenharmony_ci    if (EnableTrace()) {
17584514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
17594514f5e3Sopenharmony_ci    }
17604514f5e3Sopenharmony_ci    uint32_t pcOffset = acc_.TryGetPcOffset(gate);
17614514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
17624514f5e3Sopenharmony_ci    if (argc == 1) {
17634514f5e3Sopenharmony_ci        ret = builder_.ArrayEvery(thisValue, callBackFn, builder_.UndefineConstant(), pcOffset);
17644514f5e3Sopenharmony_ci    } else {
17654514f5e3Sopenharmony_ci        ret = builder_.ArrayEvery(thisValue, callBackFn, acc_.GetValueIn(gate, 2), pcOffset); //2: provide usingThis
17664514f5e3Sopenharmony_ci    }
17674514f5e3Sopenharmony_ci    acc_.ReplaceGate(gate, builder_.GetState(), builder_.GetDepend(), ret);
17684514f5e3Sopenharmony_ci}
17694514f5e3Sopenharmony_ci
17704514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArrayPop(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
17714514f5e3Sopenharmony_ci{
17724514f5e3Sopenharmony_ci    if (!skipThis) {
17734514f5e3Sopenharmony_ci        return;
17744514f5e3Sopenharmony_ci    }
17754514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
17764514f5e3Sopenharmony_ci    if (!Uncheck()) {
17774514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
17784514f5e3Sopenharmony_ci    }
17794514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
17804514f5e3Sopenharmony_ci    ElementsKind kind = acc_.TryGetArrayElementsKind(thisValue);
17814514f5e3Sopenharmony_ci    builder_.BuiltinPrototypeHClassCheck(thisValue, BuiltinTypeId::ARRAY, kind, false);
17824514f5e3Sopenharmony_ci    builder_.StableArrayCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
17834514f5e3Sopenharmony_ci    builder_.ElementsKindCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
17844514f5e3Sopenharmony_ci    if (EnableTrace()) {
17854514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
17864514f5e3Sopenharmony_ci    }
17874514f5e3Sopenharmony_ci    GateRef ret = builder_.ArrayPop(thisValue, acc_.GetFrameState(gate));
17884514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
17894514f5e3Sopenharmony_ci}
17904514f5e3Sopenharmony_ci
17914514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArraySlice(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
17924514f5e3Sopenharmony_ci{
17934514f5e3Sopenharmony_ci    if (!skipThis) {
17944514f5e3Sopenharmony_ci        return;
17954514f5e3Sopenharmony_ci    }
17964514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
17974514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
17984514f5e3Sopenharmony_ci    ElementsKind kind = acc_.TryGetArrayElementsKind(thisValue);
17994514f5e3Sopenharmony_ci    builder_.BuiltinPrototypeHClassCheck(thisValue, BuiltinTypeId::ARRAY, kind, false);
18004514f5e3Sopenharmony_ci    builder_.StableArrayCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
18014514f5e3Sopenharmony_ci    builder_.ElementsKindCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
18024514f5e3Sopenharmony_ci    GateRef frameState = acc_.GetFrameState(gate);
18034514f5e3Sopenharmony_ci    if (!Uncheck()) {
18044514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
18054514f5e3Sopenharmony_ci    }
18064514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
18074514f5e3Sopenharmony_ci    if (argc == 0) {
18084514f5e3Sopenharmony_ci        ret = builder_.ArraySlice(thisValue, builder_.UndefineConstant(), builder_.UndefineConstant(), frameState);
18094514f5e3Sopenharmony_ci    } else if (argc == 1) {
18104514f5e3Sopenharmony_ci        GateRef startIndex = acc_.GetValueIn(gate, 1);
18114514f5e3Sopenharmony_ci        builder_.DeoptCheck(builder_.TaggedIsInt(startIndex), acc_.GetFrameState(gate), DeoptType::INDEXNOTINT);
18124514f5e3Sopenharmony_ci        ret = builder_.ArraySlice(thisValue, startIndex, builder_.UndefineConstant(), frameState);
18134514f5e3Sopenharmony_ci    } else {
18144514f5e3Sopenharmony_ci        GateRef startIndex = acc_.GetValueIn(gate, 1);
18154514f5e3Sopenharmony_ci        GateRef endIndex = acc_.GetValueIn(gate, 2);
18164514f5e3Sopenharmony_ci        builder_.DeoptCheck(builder_.TaggedIsInt(startIndex), acc_.GetFrameState(gate), DeoptType::INDEXNOTINT);
18174514f5e3Sopenharmony_ci        builder_.DeoptCheck(builder_.TaggedIsInt(endIndex), acc_.GetFrameState(gate), DeoptType::INDEXNOTINT);
18184514f5e3Sopenharmony_ci        ret = builder_.ArraySlice(thisValue, startIndex, endIndex, frameState);
18194514f5e3Sopenharmony_ci    }
18204514f5e3Sopenharmony_ci    if (EnableTrace()) {
18214514f5e3Sopenharmony_ci        AddTraceLogs(gate, id);
18224514f5e3Sopenharmony_ci    }
18234514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
18244514f5e3Sopenharmony_ci}
18254514f5e3Sopenharmony_ci
18264514f5e3Sopenharmony_civoid NativeInlineLowering::TryInlineArraySort(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis)
18274514f5e3Sopenharmony_ci{
18284514f5e3Sopenharmony_ci    if (!skipThis) {
18294514f5e3Sopenharmony_ci        return;
18304514f5e3Sopenharmony_ci    }
18314514f5e3Sopenharmony_ci    if (argc > 1) {
18324514f5e3Sopenharmony_ci        return;
18334514f5e3Sopenharmony_ci    }
18344514f5e3Sopenharmony_ci    Environment env(gate, circuit_, &builder_);
18354514f5e3Sopenharmony_ci    if (argc == 1) {
18364514f5e3Sopenharmony_ci        GateRef callBackFn = acc_.GetValueIn(gate, 1);
18374514f5e3Sopenharmony_ci        auto fnType = acc_.GetGateType(callBackFn);
18384514f5e3Sopenharmony_ci        if (!fnType.IsUndefinedType()) {
18394514f5e3Sopenharmony_ci            return;
18404514f5e3Sopenharmony_ci        }
18414514f5e3Sopenharmony_ci    }
18424514f5e3Sopenharmony_ci    GateRef thisValue = acc_.GetValueIn(gate, 0);
18434514f5e3Sopenharmony_ci    ElementsKind kind = acc_.TryGetArrayElementsKind(thisValue);
18444514f5e3Sopenharmony_ci    if (Elements::IsHole(kind)) {
18454514f5e3Sopenharmony_ci        return;
18464514f5e3Sopenharmony_ci    }
18474514f5e3Sopenharmony_ci    if (!Uncheck()) {
18484514f5e3Sopenharmony_ci        builder_.CallTargetCheck(gate, acc_.GetValueIn(gate, argc + 1), builder_.IntPtr(static_cast<int64_t>(id)));
18494514f5e3Sopenharmony_ci    }
18504514f5e3Sopenharmony_ci    GateRef ret = Circuit::NullGate();
18514514f5e3Sopenharmony_ci
18524514f5e3Sopenharmony_ci    builder_.BuiltinPrototypeHClassCheck(thisValue, BuiltinTypeId::ARRAY, kind, false);
18534514f5e3Sopenharmony_ci    builder_.StableArrayCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
18544514f5e3Sopenharmony_ci    builder_.ElementsKindCheck(thisValue, kind, ArrayMetaDataAccessor::Mode::CALL_BUILTIN_METHOD);
18554514f5e3Sopenharmony_ci    ret = builder_.ArraySort(thisValue, builder_.UndefineConstant());
18564514f5e3Sopenharmony_ci    acc_.ReplaceHirAndDeleteIfException(gate, builder_.GetStateDepend(), ret);
18574514f5e3Sopenharmony_ci}
18584514f5e3Sopenharmony_ci
18594514f5e3Sopenharmony_ci}  // namespace panda::ecmascript
1860