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_LCR_LOWERING_H 17 #define ECMASCRIPT_COMPILER_LCR_LOWERING_H 18 19 #include "ecmascript/compiler/circuit.h" 20 #include "ecmascript/compiler/circuit_builder-inl.h" 21 #include "ecmascript/compiler/gate_accessor.h" 22 23 namespace panda::ecmascript::kungfu { 24 class LCRLowering { 25 public: LCRLowering(Circuit * circuit,CompilationConfig * cmpCfg,bool enableLog,const std::string & name)26 LCRLowering(Circuit *circuit, CompilationConfig *cmpCfg, 27 bool enableLog, const std::string& name) 28 : circuit_(circuit), acc_(circuit), builder_(circuit, cmpCfg), 29 enableLog_(enableLog), methodName_(name), glue_(acc_.GetGlueFromArgList()) 30 { 31 } 32 ~LCRLowering() = default; 33 IsLogEnabled()34 bool IsLogEnabled() const 35 { 36 return enableLog_; 37 } 38 void Run(); 39 StateDepend LowerConvert(StateDepend stateDepend, GateRef gate); 40 private: GetMethodName()41 const std::string& GetMethodName() const 42 { 43 return methodName_; 44 } 45 46 void DeleteStateSplit(GateRef gate); 47 void LowerArrayGuardianCheck(GateRef gate); 48 void LowerHeapObjectCheck(GateRef gate); 49 void LowerHClassStableArrayCheck(GateRef gate); 50 void LowerGetConstPool(GateRef gate); 51 void LowerLoadConstOffset(GateRef gate); 52 void LowerStoreConstOffset(GateRef gate); 53 void LowerConvertHoleAsUndefined(GateRef gate); 54 void LowerCheckAndConvert(GateRef gate); 55 void LowerCheckUInt32AndConvert(GateRef gate, GateRef frameState); 56 void LowerCheckTaggedIntAndConvert(GateRef gate, GateRef frameState); 57 void LowerCheckTaggedDoubleAndConvert(GateRef gate, GateRef frameState, Label *exit); 58 void LowerCheckTaggedNumberAndConvert(GateRef gate, GateRef frameState, Label *exit); 59 void LowerCheckTaggedBoolAndConvert(GateRef gate, GateRef frameState); 60 void LowerCheckSupportAndConvert(GateRef gate, GateRef frameState); 61 void LowerGetGlobalEnv(GateRef gate); 62 void LowerGetGlobalEnvObjHClass(GateRef gate); 63 void LowerGetGlobalConstantValue(GateRef gate); 64 void LowerHeapAllocate(GateRef gate); 65 void LowerInt32CheckRightIsZero(GateRef gate); 66 void LowerFloat64CheckRightIsZero(GateRef gate); 67 void LowerValueCheckNegOverflow(GateRef gate); 68 void LowerOverflowCheck(GateRef gate); 69 void LowerInt32UnsignedUpperBoundCheck(GateRef gate); 70 void LowerInt32DivWithCheck(GateRef gate); 71 void LowerLexVarIsHoleCheck(GateRef gate); 72 void LowerStoreMemory(GateRef gate); 73 74 GateRef ConvertBoolToTaggedBoolean(GateRef gate); 75 GateRef ConvertInt32ToFloat64(GateRef gate); 76 GateRef ConvertUInt32ToFloat64(GateRef gate); 77 GateRef ConvertInt32ToTaggedInt(GateRef gate); 78 GateRef ConvertUInt32ToTaggedNumber(GateRef gate, Label *exit); 79 GateRef ConvertFloat64ToBool(GateRef gate); 80 GateRef ConvertFloat64ToInt32(GateRef gate, Label *exit); 81 GateRef ConvertFloat64ToTaggedDouble(GateRef gate); 82 GateRef ConvertTaggedIntToInt32(GateRef gate); 83 GateRef ConvertTaggedIntToFloat64(GateRef gate); 84 GateRef ConvertTaggedDoubleToInt32(GateRef gate, Label *exit); 85 GateRef ConvertTaggedDoubleToFloat64(GateRef gate); 86 GateRef ConvertTaggedNumberToBool(GateRef gate, Label *exit); 87 GateRef ConvertTaggedNumberToInt32(GateRef gate, Label *exit); 88 GateRef ConvertTaggedNumberToFloat64(GateRef gate, Label *exit); 89 GateRef ConvertTaggedBooleanToBool(GateRef gate); 90 void HeapAllocateInYoung(GateRef gate); 91 void InitializeWithSpeicalValue(Label *exit, GateRef object, GateRef glue, GateRef value, 92 GateRef start, GateRef end); 93 94 Circuit *circuit_; 95 GateAccessor acc_; 96 CircuitBuilder builder_; 97 bool enableLog_ {false}; 98 std::string methodName_; 99 GateRef glue_ {Circuit::NullGate()}; 100 }; 101 } // panda::ecmascript::kungfu 102 #endif // ECMASCRIPT_COMPILER_LCR_LOWERING_H 103