• 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_MCR_LOWERING_H
17 #define ECMASCRIPT_COMPILER_MCR_LOWERING_H
18 
19 #include "ecmascript/compiler/circuit.h"
20 #include "ecmascript/compiler/circuit_builder-inl.h"
21 #include "ecmascript/compiler/combined_pass_visitor.h"
22 #include "ecmascript/compiler/compilation_env.h"
23 #include "ecmascript/compiler/gate_accessor.h"
24 
25 namespace panda::ecmascript::kungfu {
26 class MCRLowering : public PassVisitor {
27 public:
MCRLowering(CompilationEnv * env,Circuit * circuit,RPOVisitor * visitor,CompilationConfig * cmpCfg,Chunk * chunk)28     MCRLowering(CompilationEnv* env, Circuit *circuit, RPOVisitor *visitor, CompilationConfig *cmpCfg, Chunk *chunk)
29         : PassVisitor(circuit, chunk, visitor), env_(env), circuit_(circuit), acc_(circuit),
30           builder_(circuit, cmpCfg), glue_(acc_.GetGlueFromArgList())
31     {
32     }
33     ~MCRLowering() = default;
34 
35     GateRef VisitGate(GateRef gate) override;
36     StateDepend LowerConvert(StateDepend stateDepend, GateRef gate);
37 private:
38 
39     void DeleteStateSplit(GateRef gate);
40     void LowerArrayGuardianCheck(GateRef gate);
41     void LowerHeapObjectCheck(GateRef gate);
42     void LowerTaggedIsHeapObject(GateRef gate);
43     void LowerIsMarkerCellValid(GateRef gate);
44     void LowerIsSpecificObjectType(GateRef gate);
45     void LowerHClassStableArrayCheck(GateRef gate);
46     void LowerMathHClassConsistencyCheck(GateRef gate);
47     void LowerGetConstPool(GateRef gate);
48     void LowerGetUnsharedConstpool(GateRef gate);
49     void LowerLoadConstOffset(GateRef gate);
50     void LowerLoadHClassConstOffset(GateRef gate);
51     void LowerLoadHClassFromConstpool(GateRef gate);
52     void LowerStoreConstOffset(GateRef gate);
53     void LowerStoreHClassConstOffset(GateRef gate);
54     void LowerConvertHoleAsUndefined(GateRef gate);
55     void LowerCheckAndConvert(GateRef gate);
56     void LowerCheckUInt32AndConvert(GateRef gate, GateRef frameState);
57     void LowerCheckTaggedIntAndConvert(GateRef gate, GateRef frameState);
58     void LowerCheckTaggedDoubleAndConvert(GateRef gate, GateRef frameState);
59     void LowerCheckTaggedNumberAndConvert(GateRef gate, GateRef frameState, Label *exit);
60     void LowerCheckTaggedBoolAndConvert(GateRef gate, GateRef frameState);
61     void LowerCheckSpecialHoleAndConvert(GateRef gate, GateRef frameState);
62     void LowerCheckSupportAndConvertBool(GateRef gate, GateRef frameState);
63     void LowerGetGlobalEnv(GateRef gate);
64     void LowerGetGlobalEnvObj(GateRef gate);
65     void LowerGetGlobalEnvObjHClass(GateRef gate);
66     void LowerGetGlobalConstantValue(GateRef gate);
67     void LowerProductIsNegativeZero(GateRef gate);
68     void LowerInt32CheckRightIsZero(GateRef gate);
69     void LowerRemainderIsNegativeZero(GateRef gate);
70     void LowerFloat64CheckRightIsZero(GateRef gate);
71     void LowerValueCheckNegOverflow(GateRef gate);
72     void LowerOverflowCheck(GateRef gate);
73     void LowerInt32UnsignedUpperBoundCheck(GateRef gate);
74     void LowerInt32DivWithCheck(GateRef gate);
75     void LowerLexVarIsHoleCheck(GateRef gate);
76     void LowerIsUndefinedOrHoleCheck(GateRef gate);
77     void LowerIsNotUndefinedOrHoleCheck(GateRef gate);
78     void LowerIsEcmaObjectCheck(GateRef gate);
79     void LowerIsDataViewCheck(GateRef gate);
80     void LowerStoreMemory(GateRef gate);
81     void LowerCheckNullAndConvert(GateRef gate, GateRef frameState);
82     void LowerUndefinedAndConvert(GateRef gate, GateRef frameState);
83     void LowerMigrateFromRawValueToHeapValues(GateRef gate);
84     void LowerMigrateFromHeapValueToRawValue(GateRef gate);
85     void LowerMigrateFromHoleIntToHoleNumber(GateRef gate);
86     void LowerMigrateFromHoleNumberToHoleInt(GateRef gate);
87     void LowerHeapObjectIsEcmaObject(GateRef gate);
88     void LowerIsCallableCheck(GateRef gate);
89     void LowerCheckFloat64AndConvert(GateRef gate, GateRef frameState);
90     void LowerStringAdd(GateRef gate);
91 
92     GateRef ConvertSpecialHoleIntToTagged(GateRef gate, Label* exit);
93     GateRef ConvertSpecialHoleDoubleToTagged(GateRef gate, Label* exit);
94     GateRef ConvertBoolToTaggedBoolean(GateRef gate);
95     GateRef ConvertInt32ToFloat64(GateRef gate);
96     GateRef ConvertUInt32ToFloat64(GateRef gate);
97     GateRef ConvertInt32ToTaggedInt(GateRef gate);
98     GateRef ConvertUInt32ToTaggedNumber(GateRef gate, Label *exit);
99     GateRef ConvertFloat64ToBool(GateRef gate);
100     GateRef ConvertFloat64ToInt32(GateRef glue, GateRef gate);
101     GateRef ConvertFloat64ToTaggedDouble(GateRef gate);
102     GateRef ConvertTaggedIntToInt32(GateRef gate);
103     GateRef ConvertTaggedIntToFloat64(GateRef gate);
104     GateRef ConvertTaggedDoubleToInt32(GateRef glue, GateRef gate);
105     GateRef ConvertTaggedDoubleToFloat64(GateRef gate);
106     GateRef ConvertTaggedNumberToBool(GateRef gate, Label *exit);
107     GateRef ConvertTaggedNumberToInt32(GateRef gate, Label *exit);
108     GateRef ConvertTaggedNumberToFloat64(GateRef gate, Label *exit);
109     GateRef ConvertTaggedBooleanToBool(GateRef gate);
110     void HeapAllocateInSOld(GateRef gate);
111     void InitializeWithSpeicalValue(Label *exit, GateRef object, GateRef glue, GateRef value,
112                                     GateRef start, GateRef end);
113     CompilationEnv *env_;
114     Circuit *circuit_;
115     GateAccessor acc_;
116     CircuitBuilder builder_;
117     GateRef glue_ {Circuit::NullGate()};
118 };
119 }  // panda::ecmascript::kungfu
120 #endif  // ECMASCRIPT_COMPILER_MCR_LOWERING_H
121