• 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/gate_accessor.h"
23 
24 
25 namespace panda::ecmascript::kungfu {
26 class MCRLowering : public PassVisitor {
27 public:
MCRLowering(Circuit * circuit,RPOVisitor * visitor,CompilationConfig * cmpCfg,Chunk * chunk)28     MCRLowering(Circuit *circuit, RPOVisitor *visitor, CompilationConfig *cmpCfg, Chunk *chunk)
29         : PassVisitor(circuit, chunk, visitor), 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 LowerGetConstPool(GateRef gate);
47     void LowerLoadConstOffset(GateRef gate);
48     void LowerLoadHClassFromConstpool(GateRef gate);
49     void LowerStoreConstOffset(GateRef gate);
50     void LowerConvertHoleAsUndefined(GateRef gate);
51     void LowerCheckAndConvert(GateRef gate);
52     void LowerCheckUInt32AndConvert(GateRef gate, GateRef frameState);
53     void LowerCheckTaggedIntAndConvert(GateRef gate, GateRef frameState);
54     void LowerCheckTaggedDoubleAndConvert(GateRef gate, GateRef frameState, Label *exit);
55     void LowerCheckTaggedNumberAndConvert(GateRef gate, GateRef frameState, Label *exit);
56     void LowerCheckTaggedBoolAndConvert(GateRef gate, GateRef frameState);
57     void LowerCheckSupportAndConvert(GateRef gate, GateRef frameState);
58     void LowerGetGlobalEnv(GateRef gate);
59     void LowerGetGlobalEnvObj(GateRef gate);
60     void LowerGetGlobalEnvObjHClass(GateRef gate);
61     void LowerGetGlobalConstantValue(GateRef gate);
62     void LowerHeapAllocate(GateRef gate);
63     void LowerInt32CheckRightIsZero(GateRef gate);
64     void LowerRemainderIsNegativeZero(GateRef gate);
65     void LowerFloat64CheckRightIsZero(GateRef gate);
66     void LowerValueCheckNegOverflow(GateRef gate);
67     void LowerOverflowCheck(GateRef gate);
68     void LowerInt32UnsignedUpperBoundCheck(GateRef gate);
69     void LowerInt32DivWithCheck(GateRef gate);
70     void LowerLexVarIsHoleCheck(GateRef gate);
71     void LowerStoreMemory(GateRef gate);
72     void LowerCheckNullAndConvert(GateRef gate, GateRef frameState);
73     void LowerUndefinedAndConvert(GateRef gate, GateRef frameState);
74 
75     GateRef ConvertBoolToTaggedBoolean(GateRef gate);
76     GateRef ConvertInt32ToFloat64(GateRef gate);
77     GateRef ConvertUInt32ToFloat64(GateRef gate);
78     GateRef ConvertInt32ToTaggedInt(GateRef gate);
79     GateRef ConvertUInt32ToTaggedNumber(GateRef gate, Label *exit);
80     GateRef ConvertFloat64ToBool(GateRef gate);
81     GateRef ConvertFloat64ToInt32(GateRef gate, Label *exit);
82     GateRef ConvertFloat64ToTaggedDouble(GateRef gate);
83     GateRef ConvertTaggedIntToInt32(GateRef gate);
84     GateRef ConvertTaggedIntToFloat64(GateRef gate);
85     GateRef ConvertTaggedDoubleToInt32(GateRef gate, Label *exit);
86     GateRef ConvertTaggedDoubleToFloat64(GateRef gate);
87     GateRef ConvertTaggedNumberToBool(GateRef gate, Label *exit);
88     GateRef ConvertTaggedNumberToInt32(GateRef gate, Label *exit);
89     GateRef ConvertTaggedNumberToFloat64(GateRef gate, Label *exit);
90     GateRef ConvertTaggedBooleanToBool(GateRef gate);
91     void HeapAllocateInYoung(GateRef gate);
92     void InitializeWithSpeicalValue(Label *exit, GateRef object, GateRef glue, GateRef value,
93                                     GateRef start, GateRef end);
94 
95     Circuit *circuit_;
96     GateAccessor acc_;
97     CircuitBuilder builder_;
98     GateRef glue_ {Circuit::NullGate()};
99 };
100 }  // panda::ecmascript::kungfu
101 #endif  // ECMASCRIPT_COMPILER_MCR_LOWERING_H
102