• 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_NTYPE_HCR_LOWERING_H
17 #define ECMASCRIPT_COMPILER_NTYPE_HCR_LOWERING_H
18 
19 #include "ecmascript/compiler/combined_pass_visitor.h"
20 #include "ecmascript/compiler/pass_manager.h"
21 #include "ecmascript/jspandafile/program_object.h"
22 
23 namespace panda::ecmascript::kungfu {
24 class NTypeHCRLowering : public PassVisitor {
25 public:
NTypeHCRLowering(Circuit * circuit,RPOVisitor * visitor,PassContext * ctx,const CString & recordName,const MethodLiteral * methodLiteral,Chunk * chunk)26     NTypeHCRLowering(Circuit *circuit, RPOVisitor *visitor, PassContext *ctx, const CString &recordName,
27                      const MethodLiteral *methodLiteral, Chunk* chunk)
28         : PassVisitor(circuit, chunk, visitor),
29           circuit_(circuit),
30           acc_(circuit),
31           compilationEnv_(ctx->GetCompilationEnv()),
32           builder_(circuit, ctx->GetCompilerConfig()),
33           dependEntry_(circuit->GetDependRoot()),
34           jsPandaFile_(ctx->GetJSPandaFile()),
35           recordName_(recordName),
36           methodLiteral_(methodLiteral),
37           profiling_(ctx->GetCompilerConfig()->IsProfiling()),
38           traceBc_(ctx->GetCompilerConfig()->IsTraceBC()),
39           glue_(acc_.GetGlueFromArgList()) {}
40 
41     ~NTypeHCRLowering() = default;
42     GateRef VisitGate(GateRef gate) override;
43 private:
44     static constexpr int MAX_TAGGED_ARRAY_LENGTH = 50;
45     void Lower(GateRef gate);
46     void LowerCreateArray(GateRef gate, GateRef glue);
47     void LowerCreateArrayWithBuffer(GateRef gate, GateRef glue);
48     void LowerCreateArguments(GateRef gate, GateRef glue);
49     void LowerCreateEmptyArray(GateRef gate, GateRef glue);
50     void LowerCreateArrayWithOwn(GateRef gate, GateRef glue);
51     void LowerStoreModuleVar(GateRef gate, GateRef glue);
52     void LowerLdLocalModuleVar(GateRef gate);
53 
54     GateRef LoadFromConstPool(GateRef unsharedConstPool, size_t index, size_t valVecType);
55     GateRef NewActualArgv(GateRef gate, GateRef glue);
56     GateRef NewJSArrayLiteral(GateRef glue, GateRef gate, GateRef elements, GateRef length, uint32_t hintLength = 0);
57     GateRef NewTaggedArray(size_t length, GateRef glue);
58     GateRef CreateElementsWithLength(GateRef gate, GateRef glue, size_t arrayLength);
59     GateRef LowerCallRuntime(GateRef glue, GateRef hirGate, int index, const std::vector<GateRef> &args,
60                              bool useLabel = false);
61     void ReplaceGateWithPendingException(GateRef gate, GateRef state, GateRef depend, GateRef value);
62 
GetFrameState(GateRef gate)63     GateRef GetFrameState(GateRef gate) const
64     {
65         return acc_.GetFrameState(gate);
66     }
67 
GetConstantpoolValue(uint32_t cpId)68     JSTaggedValue GetConstantpoolValue(uint32_t cpId)
69     {
70         return compilationEnv_->FindConstpool(jsPandaFile_, cpId);
71     }
72 
GetArrayLiteralValue(uint32_t cpId,uint32_t cpIdx)73     JSTaggedValue GetArrayLiteralValue(uint32_t cpId, uint32_t cpIdx)
74     {
75         JSTaggedValue cp = GetConstantpoolValue(cpId);
76         JSTaggedValue unsharedCp = compilationEnv_->FindOrCreateUnsharedConstpool(cp);
77         return compilationEnv_->GetArrayLiteralFromCache(unsharedCp, cpIdx, recordName_);
78     }
79 
80     Circuit *circuit_ {nullptr};
81     GateAccessor acc_;
82     CompilationEnv *compilationEnv_ {nullptr};
83     CircuitBuilder builder_;
84     GateRef dependEntry_;
85     const JSPandaFile *jsPandaFile_ {nullptr};
86     const CString &recordName_;
87     const MethodLiteral *methodLiteral_ {nullptr};
88     panda_file::File::EntityId methodId_ {0};
89     bool profiling_ {false};
90     bool traceBc_ {false};
91     GateRef glue_ {Circuit::NullGate()};
92 };
93 }  // panda::ecmascript::kungfu
94 #endif  // ECMASCRIPT_COMPILER_NTYPE_HCR_LOWERING_H
95