• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef ECMASCRIPT_COMPILER_BUILTIN_INLINE_H
17 #define ECMASCRIPT_COMPILER_BUILTIN_INLINE_H
18 
19 #include "ecmascript/compiler/circuit_builder.h"
20 #include "ecmascript/compiler/gate_accessor.h"
21 #include "ecmascript/compiler/pass_manager.h"
22 #include "ecmascript/compiler/type_info_accessors.h"
23 #include "ecmascript/ts_types/ts_manager.h"
24 
25 namespace panda::ecmascript::kungfu {
26 class NativeInlineLowering {
27 public:
NativeInlineLowering(Circuit * circuit,PassContext * ctx,bool enableLog,const std::string & name)28     explicit NativeInlineLowering(Circuit *circuit, PassContext *ctx, bool enableLog, const std::string& name)
29         : circuit_(circuit),
30           builder_(circuit),
31           acc_(circuit),
32           glue_(acc_.GetGlueFromArgList()),
33           tsManager_(ctx->GetTSManager()),
34           enableLog_(enableLog),
35           methodName_(name),
36           nocheck_(ctx->GetEcmaVM()->GetJSOptions().IsCompilerNoCheck()),
37           thread_(ctx->GetEcmaVM()->GetJSThread()) {}
38     ~NativeInlineLowering() = default;
39     void RunNativeInlineLowering();
40 
41 private:
42     void RunArrayForeachInline(GateRef gate);
43     void ArrayForeachCall(GateRef gate, GateRef thisObj, GateRef callBack, GateRef thisArg, Label *exit);
44     void TryInlineNativeCallThis1(GateRef gate);
45     void TryInlineBuiltinsArrayFunc(GateRef gate);
46     bool IsCreateArray(GateRef gate);
47     GateRef LoadArrayElement(ElementsKind kind, GateRef gate, GateRef index);
48     void ReplaceHirDirectly(GateRef gate, GateRef value);
49     GateRef LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args, bool useLabel);
50     GateRef NativeCallTS(GateRef gate, GateRef depend, const std::vector<GateRef> &args);
51     void TryInlineStringFromCharCode(GateRef gate, CallThis1TypeInfoAccessor &tacc);
EnableLog()52     bool EnableLog() const
53     {
54         return enableLog_;
55     }
56 
GetMethodName()57     const std::string& GetMethodName() const
58     {
59         return methodName_;
60     }
61 
Uncheck()62     bool Uncheck() const
63     {
64         return nocheck_;
65     }
66 
67     Circuit *circuit_ {nullptr};
68     CircuitBuilder builder_;
69     GateAccessor acc_;
70     GateRef glue_;
71     TSManager *tsManager_;
72     bool enableLog_;
73     std::string methodName_;
74     bool nocheck_;
75     const JSThread *thread_ {nullptr};
76 };
77 }
78 #endif // ECMASCRIPT_COMPILER_BUILTIN_INLINE_H