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 164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_COMPILER_BUILTIN_INLINE_H 174514f5e3Sopenharmony_ci#define ECMASCRIPT_COMPILER_BUILTIN_INLINE_H 184514f5e3Sopenharmony_ci 194514f5e3Sopenharmony_ci#include "ecmascript/compiler/builtins/builtins_call_signature.h" 204514f5e3Sopenharmony_ci#include "ecmascript/compiler/circuit_builder.h" 214514f5e3Sopenharmony_ci#include "ecmascript/compiler/gate_accessor.h" 224514f5e3Sopenharmony_ci#include "ecmascript/compiler/graph_linearizer.h" 234514f5e3Sopenharmony_ci#include "ecmascript/compiler/pass_manager.h" 244514f5e3Sopenharmony_ci#include "ecmascript/compiler/share_gate_meta_data.h" 254514f5e3Sopenharmony_ci#include "ecmascript/compiler/type_info_accessors.h" 264514f5e3Sopenharmony_ci#include "ecmascript/js_dataview.h" 274514f5e3Sopenharmony_ci 284514f5e3Sopenharmony_cinamespace panda::ecmascript::kungfu { 294514f5e3Sopenharmony_ciclass NativeInlineLowering { 304514f5e3Sopenharmony_cipublic: 314514f5e3Sopenharmony_ci explicit NativeInlineLowering(Circuit *circuit, CompilationConfig* cmpCfg, PassContext *ctx, bool enableLog, 324514f5e3Sopenharmony_ci const std::string& name, Chunk *chunk) 334514f5e3Sopenharmony_ci : circuit_(circuit), 344514f5e3Sopenharmony_ci builder_(circuit, cmpCfg), 354514f5e3Sopenharmony_ci acc_(circuit), 364514f5e3Sopenharmony_ci glue_(acc_.GetGlueFromArgList()), 374514f5e3Sopenharmony_ci enableLog_(enableLog), 384514f5e3Sopenharmony_ci methodName_(name), 394514f5e3Sopenharmony_ci nocheck_(ctx->GetCompilationEnv()->GetJSOptions().IsCompilerNoCheck()), 404514f5e3Sopenharmony_ci traceInline_(ctx->GetCompilationEnv()->GetJSOptions().GetTraceInline()), 414514f5e3Sopenharmony_ci compilationEnv_(ctx->GetCompilationEnv()), 424514f5e3Sopenharmony_ci chunk_(chunk) {} 434514f5e3Sopenharmony_ci ~NativeInlineLowering() = default; 444514f5e3Sopenharmony_ci void RunNativeInlineLowering(); 454514f5e3Sopenharmony_ci 464514f5e3Sopenharmony_ciprivate: 474514f5e3Sopenharmony_ci enum IncludesOrIndexOf : uint8_t { INCLUDES = 0, INDEXOF }; 484514f5e3Sopenharmony_ci std::optional<std::pair<size_t, bool>> GetCallInfo(GateRef gate); 494514f5e3Sopenharmony_ci void TryInlineStringFromCharCode(GateRef gate, size_t argc, bool skipThis); 504514f5e3Sopenharmony_ci void TryInlineStringCharCodeAt(GateRef gate, size_t argc, bool skipThis); 514514f5e3Sopenharmony_ci void TryInlineStringSubstring(GateRef gate, size_t argc, bool skipThis); 524514f5e3Sopenharmony_ci void TryInlineStringSubStr(GateRef gate, size_t argc, bool skipThis); 534514f5e3Sopenharmony_ci void TryInlineStringSlice(GateRef gate, size_t argc, bool skipThis); 544514f5e3Sopenharmony_ci void TryInlineNumberIsFinite(GateRef gate, size_t argc, bool skipThis); 554514f5e3Sopenharmony_ci void TryInlineNumberIsInteger(GateRef gate, size_t argc, bool skipThis); 564514f5e3Sopenharmony_ci void TryInlineNumberIsNaN(GateRef gate, size_t argc, bool skipThis); 574514f5e3Sopenharmony_ci void TryInlineNumberParseFloat(GateRef gate, size_t argc, bool skipThis); 584514f5e3Sopenharmony_ci void TryInlineNumberParseInt(GateRef gate, size_t argc, bool skipThis); 594514f5e3Sopenharmony_ci void TryInlineNumberIsSafeInteger(GateRef gate, size_t argc, bool skipThis); 604514f5e3Sopenharmony_ci void TryInlineTypedArrayIteratorBuiltin(GateRef gate, BuiltinsStubCSigns::ID id, 614514f5e3Sopenharmony_ci const GateMetaData* op, bool skipThis); 624514f5e3Sopenharmony_ci void TryInlineMathUnaryBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, const GateMetaData* op, 634514f5e3Sopenharmony_ci bool skipThis); 644514f5e3Sopenharmony_ci void TryInlineMathBinaryBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, const GateMetaData* op, 654514f5e3Sopenharmony_ci bool skipThis); 664514f5e3Sopenharmony_ci void TryInlineMathImulBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, const GateMetaData* op, 674514f5e3Sopenharmony_ci bool skipThis); 684514f5e3Sopenharmony_ci void TryInlineGlobalFiniteBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, const GateMetaData* op, 694514f5e3Sopenharmony_ci bool skipThis); 704514f5e3Sopenharmony_ci void TryInlineGlobalNanBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, const GateMetaData* op, 714514f5e3Sopenharmony_ci bool skipThis); 724514f5e3Sopenharmony_ci void TryInlineMathMinMaxBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, const GateMetaData* op, 734514f5e3Sopenharmony_ci double defaultValue, bool skipThis); 744514f5e3Sopenharmony_ci void TryInlineMathAbsBuiltin(GateRef gate, size_t argc, bool skipThis); 754514f5e3Sopenharmony_ci void TryInlineMathClz32Builtin(GateRef gate, size_t argc, bool skipThis); 764514f5e3Sopenharmony_ci void TryInlineArrayBufferIsView(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 774514f5e3Sopenharmony_ci void TryInlineBigIntAsIntN(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 784514f5e3Sopenharmony_ci void TryInlineDataViewGet(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 794514f5e3Sopenharmony_ci void TryInlineDataViewSet(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 804514f5e3Sopenharmony_ci void InlineStubBuiltin(GateRef gate, size_t builtinArgc, size_t realArgc, BuiltinsStubCSigns::ID id, 814514f5e3Sopenharmony_ci const GateMetaData* op, bool skipThis); 824514f5e3Sopenharmony_ci void TryInlineDateGetTime(GateRef gate, size_t argc, bool skipThis); 834514f5e3Sopenharmony_ci void TryInlineWhitoutParamBuiltin(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, 844514f5e3Sopenharmony_ci const GateMetaData* op, bool skipThis); 854514f5e3Sopenharmony_ci void TryInlineObjectIs(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 864514f5e3Sopenharmony_ci void TryInlineObjectGetPrototypeOf(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 874514f5e3Sopenharmony_ci void TryInlineObjectGetProto(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 884514f5e3Sopenharmony_ci void TryInlineObjectCreate(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 894514f5e3Sopenharmony_ci void TryInlineObjectIsPrototypeOf(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 904514f5e3Sopenharmony_ci void TryInlineObjectHasOwnProperty(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 914514f5e3Sopenharmony_ci void TryInlineReflectGetPrototypeOf(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 924514f5e3Sopenharmony_ci void TryInlineReflectGet(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 934514f5e3Sopenharmony_ci void TryInlineReflectHas(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 944514f5e3Sopenharmony_ci void TryInlineReflectConstruct(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 954514f5e3Sopenharmony_ci void TryInlineReflectApply(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 964514f5e3Sopenharmony_ci void TryInlineFunctionPrototypeApply(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 974514f5e3Sopenharmony_ci void TryInlineFunctionPrototypeBind(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 984514f5e3Sopenharmony_ci void TryInlineFunctionPrototypeCall(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 994514f5e3Sopenharmony_ci void TryInlineFunctionPrototypeHasInstance(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1004514f5e3Sopenharmony_ci 1014514f5e3Sopenharmony_ci void TryInlineBigIntConstructor(GateRef gate, size_t argc, bool skipThis); 1024514f5e3Sopenharmony_ci void ReplaceGateWithPendingException(GateRef hirGate, GateRef value); 1034514f5e3Sopenharmony_ci void AddTraceLogs(GateRef gate, BuiltinsStubCSigns::ID id); 1044514f5e3Sopenharmony_ci void TryInlineIndexOfIncludes(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1054514f5e3Sopenharmony_ci void TryInlineArrayIterator(GateRef gate, BuiltinsStubCSigns::ID id, bool skipThis); 1064514f5e3Sopenharmony_ci void TryInlineArrayForEach(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1074514f5e3Sopenharmony_ci void TryInlineArrayFindOrFindIndex(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1084514f5e3Sopenharmony_ci void TryInlineArrayFilter(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1094514f5e3Sopenharmony_ci void TryInlineArrayMap(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1104514f5e3Sopenharmony_ci void TryInlineArraySome(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1114514f5e3Sopenharmony_ci void TryInlineArrayEvery(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1124514f5e3Sopenharmony_ci void TryInlineArrayPop(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1134514f5e3Sopenharmony_ci void TryInlineArraySlice(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1144514f5e3Sopenharmony_ci void TryInlineArraySort(GateRef gate, size_t argc, BuiltinsStubCSigns::ID id, bool skipThis); 1154514f5e3Sopenharmony_ci 1164514f5e3Sopenharmony_ci bool EnableLog() const 1174514f5e3Sopenharmony_ci { 1184514f5e3Sopenharmony_ci return enableLog_; 1194514f5e3Sopenharmony_ci } 1204514f5e3Sopenharmony_ci 1214514f5e3Sopenharmony_ci const std::string& GetMethodName() const 1224514f5e3Sopenharmony_ci { 1234514f5e3Sopenharmony_ci return methodName_; 1244514f5e3Sopenharmony_ci } 1254514f5e3Sopenharmony_ci 1264514f5e3Sopenharmony_ci bool Uncheck() const 1274514f5e3Sopenharmony_ci { 1284514f5e3Sopenharmony_ci return nocheck_; 1294514f5e3Sopenharmony_ci } 1304514f5e3Sopenharmony_ci 1314514f5e3Sopenharmony_ci bool EnableTrace() const 1324514f5e3Sopenharmony_ci { 1334514f5e3Sopenharmony_ci return traceInline_; 1344514f5e3Sopenharmony_ci } 1354514f5e3Sopenharmony_ci 1364514f5e3Sopenharmony_ciprivate: 1374514f5e3Sopenharmony_ci Circuit *circuit_ {nullptr}; 1384514f5e3Sopenharmony_ci CircuitBuilder builder_; 1394514f5e3Sopenharmony_ci GateAccessor acc_; 1404514f5e3Sopenharmony_ci GateRef glue_; 1414514f5e3Sopenharmony_ci bool enableLog_; 1424514f5e3Sopenharmony_ci std::string methodName_; 1434514f5e3Sopenharmony_ci bool nocheck_; 1444514f5e3Sopenharmony_ci bool traceInline_; 1454514f5e3Sopenharmony_ci const CompilationEnv *compilationEnv_ {nullptr}; 1464514f5e3Sopenharmony_ci Chunk* chunk_ {nullptr}; 1474514f5e3Sopenharmony_ci}; 1484514f5e3Sopenharmony_ci} 1494514f5e3Sopenharmony_ci#endif // ECMASCRIPT_COMPILER_BUILTIN_INLINE_H 150