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 #include "me_function.h" 17 #include <iostream> 18 #include <functional> 19 #include "ssa_mir_nodes.h" 20 #include "me_cfg.h" 21 #include "mir_lower.h" 22 #include "mir_builder.h" 23 #include "constantfold.h" 24 #include "me_irmap.h" 25 #include "me_ssa_update.h" 26 27 namespace maple { 28 #if DEBUG 29 MIRModule *globalMIRModule = nullptr; 30 MeFunction *globalFunc = nullptr; 31 MeIRMap *globalIRMap = nullptr; 32 SSATab *globalSSATab = nullptr; 33 #endif PartialInit()34void MeFunction::PartialInit() 35 { 36 theCFG = nullptr; 37 irmap = nullptr; 38 regNum = 0; 39 hasEH = false; 40 ConstantFold cf(mirModule); 41 (void)cf.Simplify(mirFunc->GetBody()); 42 if (mirModule.IsJavaModule() && (!mirFunc->GetInfoVector().empty())) { 43 std::string string("INFO_registers"); 44 GStrIdx strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(string); 45 regNum = mirFunc->GetInfo(strIdx); 46 std::string tryNum("INFO_tries_size"); 47 strIdx = GlobalTables::GetStrTable().GetOrCreateStrIdxFromName(tryNum); 48 uint32 num = mirFunc->GetInfo(strIdx); 49 hasEH = (num != 0); 50 } 51 } 52 Release()53void MeFunction::Release() 54 { 55 ReleaseVersMemory(); 56 if (preMeMp) { 57 memPoolCtrler.DeleteMemPool(preMeMp); 58 } 59 preMeMp = nullptr; 60 } 61 Verify() const62void MeFunction::Verify() const 63 { 64 CHECK_FATAL(theCFG != nullptr, "theCFG is null"); 65 theCFG->Verify(); 66 theCFG->VerifyLabels(); 67 } 68 69 /* create label for bb */ GetOrCreateBBLabel(BB & bb)70LabelIdx MeFunction::GetOrCreateBBLabel(BB &bb) 71 { 72 LabelIdx label = bb.GetBBLabel(); 73 if (label != 0) { 74 return label; 75 } 76 label = mirModule.CurFunction()->GetLabelTab()->CreateLabelWithPrefix('m'); 77 mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(label); 78 bb.SetBBLabel(label); 79 theCFG->SetLabelBBAt(label, &bb); 80 return label; 81 } 82 } // namespace maple 83