14514f5e3Sopenharmony_ci/*
24514f5e3Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
34514f5e3Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
44514f5e3Sopenharmony_ci * you may not use this file except in compliance with the License.
54514f5e3Sopenharmony_ci * You may obtain a copy of the License at
64514f5e3Sopenharmony_ci *
74514f5e3Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
84514f5e3Sopenharmony_ci *
94514f5e3Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
104514f5e3Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
114514f5e3Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
124514f5e3Sopenharmony_ci * See the License for the specific language governing permissions and
134514f5e3Sopenharmony_ci * limitations under the License.
144514f5e3Sopenharmony_ci */
154514f5e3Sopenharmony_ci
164514f5e3Sopenharmony_ci#ifndef ECMASCRIPT_COMPILER_MCR_LOWERING_H
174514f5e3Sopenharmony_ci#define ECMASCRIPT_COMPILER_MCR_LOWERING_H
184514f5e3Sopenharmony_ci
194514f5e3Sopenharmony_ci#include "ecmascript/compiler/circuit.h"
204514f5e3Sopenharmony_ci#include "ecmascript/compiler/circuit_builder-inl.h"
214514f5e3Sopenharmony_ci#include "ecmascript/compiler/combined_pass_visitor.h"
224514f5e3Sopenharmony_ci#include "ecmascript/compiler/compilation_env.h"
234514f5e3Sopenharmony_ci#include "ecmascript/compiler/gate_accessor.h"
244514f5e3Sopenharmony_ci
254514f5e3Sopenharmony_cinamespace panda::ecmascript::kungfu {
264514f5e3Sopenharmony_ciclass MCRLowering : public PassVisitor {
274514f5e3Sopenharmony_cipublic:
284514f5e3Sopenharmony_ci    MCRLowering(CompilationEnv* env, Circuit *circuit, RPOVisitor *visitor, CompilationConfig *cmpCfg, Chunk *chunk)
294514f5e3Sopenharmony_ci        : PassVisitor(circuit, chunk, visitor), env_(env), circuit_(circuit), acc_(circuit),
304514f5e3Sopenharmony_ci          builder_(circuit, cmpCfg), glue_(acc_.GetGlueFromArgList())
314514f5e3Sopenharmony_ci    {
324514f5e3Sopenharmony_ci    }
334514f5e3Sopenharmony_ci    ~MCRLowering() = default;
344514f5e3Sopenharmony_ci
354514f5e3Sopenharmony_ci    GateRef VisitGate(GateRef gate) override;
364514f5e3Sopenharmony_ci    StateDepend LowerConvert(StateDepend stateDepend, GateRef gate);
374514f5e3Sopenharmony_ciprivate:
384514f5e3Sopenharmony_ci
394514f5e3Sopenharmony_ci    void DeleteStateSplit(GateRef gate);
404514f5e3Sopenharmony_ci    void LowerArrayGuardianCheck(GateRef gate);
414514f5e3Sopenharmony_ci    void LowerHeapObjectCheck(GateRef gate);
424514f5e3Sopenharmony_ci    void LowerTaggedIsHeapObject(GateRef gate);
434514f5e3Sopenharmony_ci    void LowerIsMarkerCellValid(GateRef gate);
444514f5e3Sopenharmony_ci    void LowerIsSpecificObjectType(GateRef gate);
454514f5e3Sopenharmony_ci    void LowerHClassStableArrayCheck(GateRef gate);
464514f5e3Sopenharmony_ci    void LowerGetConstPool(GateRef gate);
474514f5e3Sopenharmony_ci    void LowerGetUnsharedConstpool(GateRef gate);
484514f5e3Sopenharmony_ci    void LowerLoadConstOffset(GateRef gate);
494514f5e3Sopenharmony_ci    void LowerLoadHClassFromConstpool(GateRef gate);
504514f5e3Sopenharmony_ci    void LowerStoreConstOffset(GateRef gate);
514514f5e3Sopenharmony_ci    void LowerConvertHoleAsUndefined(GateRef gate);
524514f5e3Sopenharmony_ci    void LowerCheckAndConvert(GateRef gate);
534514f5e3Sopenharmony_ci    void LowerCheckUInt32AndConvert(GateRef gate, GateRef frameState);
544514f5e3Sopenharmony_ci    void LowerCheckTaggedIntAndConvert(GateRef gate, GateRef frameState);
554514f5e3Sopenharmony_ci    void LowerCheckTaggedDoubleAndConvert(GateRef gate, GateRef frameState, Label *exit);
564514f5e3Sopenharmony_ci    void LowerCheckTaggedNumberAndConvert(GateRef gate, GateRef frameState, Label *exit);
574514f5e3Sopenharmony_ci    void LowerCheckTaggedBoolAndConvert(GateRef gate, GateRef frameState);
584514f5e3Sopenharmony_ci    void LowerCheckSpecialHoleAndConvert(GateRef gate, GateRef frameState);
594514f5e3Sopenharmony_ci    void LowerCheckSupportAndConvert(GateRef gate, GateRef frameState);
604514f5e3Sopenharmony_ci    void LowerGetGlobalEnv(GateRef gate);
614514f5e3Sopenharmony_ci    void LowerGetGlobalEnvObj(GateRef gate);
624514f5e3Sopenharmony_ci    void LowerGetGlobalEnvObjHClass(GateRef gate);
634514f5e3Sopenharmony_ci    void LowerGetGlobalConstantValue(GateRef gate);
644514f5e3Sopenharmony_ci    void LowerInt32CheckRightIsZero(GateRef gate);
654514f5e3Sopenharmony_ci    void LowerRemainderIsNegativeZero(GateRef gate);
664514f5e3Sopenharmony_ci    void LowerFloat64CheckRightIsZero(GateRef gate);
674514f5e3Sopenharmony_ci    void LowerValueCheckNegOverflow(GateRef gate);
684514f5e3Sopenharmony_ci    void LowerOverflowCheck(GateRef gate);
694514f5e3Sopenharmony_ci    void LowerInt32UnsignedUpperBoundCheck(GateRef gate);
704514f5e3Sopenharmony_ci    void LowerInt32DivWithCheck(GateRef gate);
714514f5e3Sopenharmony_ci    void LowerLexVarIsHoleCheck(GateRef gate);
724514f5e3Sopenharmony_ci    void LowerIsUndefinedOrHoleCheck(GateRef gate);
734514f5e3Sopenharmony_ci    void LowerIsNotUndefinedOrHoleCheck(GateRef gate);
744514f5e3Sopenharmony_ci    void LowerIsEcmaObjectCheck(GateRef gate);
754514f5e3Sopenharmony_ci    void LowerIsDataViewCheck(GateRef gate);
764514f5e3Sopenharmony_ci    void LowerStoreMemory(GateRef gate);
774514f5e3Sopenharmony_ci    void LowerCheckNullAndConvert(GateRef gate, GateRef frameState);
784514f5e3Sopenharmony_ci    void LowerUndefinedAndConvert(GateRef gate, GateRef frameState);
794514f5e3Sopenharmony_ci    void LowerMigrateFromRawValueToHeapValues(GateRef gate);
804514f5e3Sopenharmony_ci    void LowerMigrateFromHeapValueToRawValue(GateRef gate);
814514f5e3Sopenharmony_ci    void LowerMigrateFromHoleIntToHoleNumber(GateRef gate);
824514f5e3Sopenharmony_ci    void LowerMigrateFromHoleNumberToHoleInt(GateRef gate);
834514f5e3Sopenharmony_ci    void LowerHeapObjectIsEcmaObject(GateRef gate);
844514f5e3Sopenharmony_ci    void LowerIsCallableCheck(GateRef gate);
854514f5e3Sopenharmony_ci    void LowerCheckFloat64AndConvert(GateRef gate, GateRef frameState, Label *exit);
864514f5e3Sopenharmony_ci
874514f5e3Sopenharmony_ci    GateRef ConvertSpecialHoleIntToTagged(GateRef gate, Label* exit);
884514f5e3Sopenharmony_ci    GateRef ConvertSpecialHoleDoubleToTagged(GateRef gate, Label* exit);
894514f5e3Sopenharmony_ci    GateRef ConvertBoolToTaggedBoolean(GateRef gate);
904514f5e3Sopenharmony_ci    GateRef ConvertInt32ToFloat64(GateRef gate);
914514f5e3Sopenharmony_ci    GateRef ConvertUInt32ToFloat64(GateRef gate);
924514f5e3Sopenharmony_ci    GateRef ConvertInt32ToTaggedInt(GateRef gate);
934514f5e3Sopenharmony_ci    GateRef ConvertUInt32ToTaggedNumber(GateRef gate, Label *exit);
944514f5e3Sopenharmony_ci    GateRef ConvertFloat64ToBool(GateRef gate);
954514f5e3Sopenharmony_ci    GateRef ConvertFloat64ToInt32(GateRef gate, Label *exit);
964514f5e3Sopenharmony_ci    GateRef ConvertFloat64ToTaggedDouble(GateRef gate);
974514f5e3Sopenharmony_ci    GateRef ConvertTaggedIntToInt32(GateRef gate);
984514f5e3Sopenharmony_ci    GateRef ConvertTaggedIntToFloat64(GateRef gate);
994514f5e3Sopenharmony_ci    GateRef ConvertTaggedDoubleToInt32(GateRef gate, Label *exit);
1004514f5e3Sopenharmony_ci    GateRef ConvertTaggedDoubleToFloat64(GateRef gate);
1014514f5e3Sopenharmony_ci    GateRef ConvertTaggedNumberToBool(GateRef gate, Label *exit);
1024514f5e3Sopenharmony_ci    GateRef ConvertTaggedNumberToInt32(GateRef gate, Label *exit);
1034514f5e3Sopenharmony_ci    GateRef ConvertTaggedNumberToFloat64(GateRef gate, Label *exit);
1044514f5e3Sopenharmony_ci    GateRef ConvertTaggedBooleanToBool(GateRef gate);
1054514f5e3Sopenharmony_ci    void HeapAllocateInSOld(GateRef gate);
1064514f5e3Sopenharmony_ci    void InitializeWithSpeicalValue(Label *exit, GateRef object, GateRef glue, GateRef value,
1074514f5e3Sopenharmony_ci                                    GateRef start, GateRef end);
1084514f5e3Sopenharmony_ci    CompilationEnv *env_;
1094514f5e3Sopenharmony_ci    Circuit *circuit_;
1104514f5e3Sopenharmony_ci    GateAccessor acc_;
1114514f5e3Sopenharmony_ci    CircuitBuilder builder_;
1124514f5e3Sopenharmony_ci    GateRef glue_ {Circuit::NullGate()};
1134514f5e3Sopenharmony_ci};
1144514f5e3Sopenharmony_ci}  // panda::ecmascript::kungfu
1154514f5e3Sopenharmony_ci#endif  // ECMASCRIPT_COMPILER_MCR_LOWERING_H
116