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 } 43 Release()44void MeFunction::Release() 45 { 46 ReleaseVersMemory(); 47 if (preMeMp) { 48 memPoolCtrler.DeleteMemPool(preMeMp); 49 } 50 preMeMp = nullptr; 51 } 52 Verify() const53void MeFunction::Verify() const 54 { 55 CHECK_FATAL(theCFG != nullptr, "theCFG is null"); 56 theCFG->Verify(); 57 theCFG->VerifyLabels(); 58 } 59 60 /* create label for bb */ GetOrCreateBBLabel(BB & bb)61LabelIdx MeFunction::GetOrCreateBBLabel(BB &bb) 62 { 63 LabelIdx label = bb.GetBBLabel(); 64 if (label != 0) { 65 return label; 66 } 67 label = mirModule.CurFunction()->GetLabelTab()->CreateLabelWithPrefix('m'); 68 mirModule.CurFunction()->GetLabelTab()->AddToStringLabelMap(label); 69 bb.SetBBLabel(label); 70 theCFG->SetLabelBBAt(label, &bb); 71 return label; 72 } 73 } // namespace maple 74