• 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 LowerLoadHClassFromConstpool(GateRef gate);
51     void LowerStoreConstOffset(GateRef gate);
52     void LowerConvertHoleAsUndefined(GateRef gate);
53     void LowerCheckAndConvert(GateRef gate);
54     void LowerCheckUInt32AndConvert(GateRef gate, GateRef frameState);
55     void LowerCheckTaggedIntAndConvert(GateRef gate, GateRef frameState);
56     void LowerCheckTaggedDoubleAndConvert(GateRef gate, GateRef frameState);
57     void LowerCheckTaggedNumberAndConvert(GateRef gate, GateRef frameState, Label *exit);
58     void LowerCheckTaggedBoolAndConvert(GateRef gate, GateRef frameState);
59     void LowerCheckSpecialHoleAndConvert(GateRef gate, GateRef frameState);
60     void LowerCheckSupportAndConvertBool(GateRef gate, GateRef frameState);
61     void LowerGetGlobalEnv(GateRef gate);
62     void LowerGetGlobalEnvObj(GateRef gate);
63     void LowerGetGlobalEnvObjHClass(GateRef gate);
64     void LowerGetGlobalConstantValue(GateRef gate);
65     void LowerInt32CheckRightIsZero(GateRef gate);
66     void LowerRemainderIsNegativeZero(GateRef gate);
67     void LowerFloat64CheckRightIsZero(GateRef gate);
68     void LowerValueCheckNegOverflow(GateRef gate);
69     void LowerOverflowCheck(GateRef gate);
70     void LowerInt32UnsignedUpperBoundCheck(GateRef gate);
71     void LowerInt32DivWithCheck(GateRef gate);
72     void LowerLexVarIsHoleCheck(GateRef gate);
73     void LowerIsUndefinedOrHoleCheck(GateRef gate);
74     void LowerIsNotUndefinedOrHoleCheck(GateRef gate);
75     void LowerIsEcmaObjectCheck(GateRef gate);
76     void LowerIsDataViewCheck(GateRef gate);
77     void LowerStoreMemory(GateRef gate);
78     void LowerCheckNullAndConvert(GateRef gate, GateRef frameState);
79     void LowerUndefinedAndConvert(GateRef gate, GateRef frameState);
80     void LowerMigrateFromRawValueToHeapValues(GateRef gate);
81     void LowerMigrateFromHeapValueToRawValue(GateRef gate);
82     void LowerMigrateFromHoleIntToHoleNumber(GateRef gate);
83     void LowerMigrateFromHoleNumberToHoleInt(GateRef gate);
84     void LowerHeapObjectIsEcmaObject(GateRef gate);
85     void LowerIsCallableCheck(GateRef gate);
86     void LowerCheckFloat64AndConvert(GateRef gate, GateRef frameState);
87     void LowerStringAdd(GateRef gate);
88 
89     GateRef ConvertSpecialHoleIntToTagged(GateRef gate, Label* exit);
90     GateRef ConvertSpecialHoleDoubleToTagged(GateRef gate, Label* exit);
91     GateRef ConvertBoolToTaggedBoolean(GateRef gate);
92     GateRef ConvertInt32ToFloat64(GateRef gate);
93     GateRef ConvertUInt32ToFloat64(GateRef gate);
94     GateRef ConvertInt32ToTaggedInt(GateRef gate);
95     GateRef ConvertUInt32ToTaggedNumber(GateRef gate, Label *exit);
96     GateRef ConvertFloat64ToBool(GateRef gate);
97     GateRef ConvertFloat64ToInt32(GateRef glue, GateRef gate);
98     GateRef ConvertFloat64ToTaggedDouble(GateRef gate);
99     GateRef ConvertTaggedIntToInt32(GateRef gate);
100     GateRef ConvertTaggedIntToFloat64(GateRef gate);
101     GateRef ConvertTaggedDoubleToInt32(GateRef glue, GateRef gate);
102     GateRef ConvertTaggedDoubleToFloat64(GateRef gate);
103     GateRef ConvertTaggedNumberToBool(GateRef gate, Label *exit);
104     GateRef ConvertTaggedNumberToInt32(GateRef gate, Label *exit);
105     GateRef ConvertTaggedNumberToFloat64(GateRef gate, Label *exit);
106     GateRef ConvertTaggedBooleanToBool(GateRef gate);
107     void HeapAllocateInSOld(GateRef gate);
108     void InitializeWithSpeicalValue(Label *exit, GateRef object, GateRef glue, GateRef value,
109                                     GateRef start, GateRef end);
110     CompilationEnv *env_;
111     Circuit *circuit_;
112     GateAccessor acc_;
113     CircuitBuilder builder_;
114     GateRef glue_ {Circuit::NullGate()};
115 };
116 }  // panda::ecmascript::kungfu
117 #endif  // ECMASCRIPT_COMPILER_MCR_LOWERING_H
118