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 MAPLEBE_INCLUDE_CG_CG_PHASEMANAGER_H 17 #define MAPLEBE_INCLUDE_CG_CG_PHASEMANAGER_H 18 #include <vector> 19 #include <string> 20 #include <sys/stat.h> 21 #include "mempool.h" 22 #include "mempool_allocator.h" 23 #include "mir_module.h" 24 #include "mir_lower.h" 25 #include "lower.h" 26 #include "constantfold.h" 27 #include "cgfunc.h" 28 #include "cg_phase.h" 29 #include "cg_option.h" 30 namespace maplebe { 31 using cgFuncOptTy = MapleFunctionPhase<CGFunc>; 32 33 /* =================== new phase manager =================== */ 34 class CgFuncPM : public FunctionPM { 35 public: CgFuncPM(MemPool * mp)36 explicit CgFuncPM(MemPool *mp) : FunctionPM(mp, &id) {} 37 PHASECONSTRUCTOR(CgFuncPM); 38 std::string PhaseName() const override; ~CgFuncPM()39 ~CgFuncPM() override 40 { 41 cgOptions = nullptr; 42 cg = nullptr; 43 beCommon = nullptr; 44 if (CGOptions::IsEnableTimePhases()) { 45 DumpPhaseTime(); 46 } 47 } 48 bool PhaseRun(MIRModule &m) override; 49 SetCGOptions(CGOptions * curCGOptions)50 void SetCGOptions(CGOptions *curCGOptions) 51 { 52 cgOptions = curCGOptions; 53 } 54 GetCG()55 CG *GetCG() 56 { 57 return cg; 58 } GetBECommon()59 BECommon *GetBECommon() 60 { 61 return beCommon; 62 } 63 64 private: 65 bool FuncLevelRun(CGFunc &cgFunc, AnalysisDataManager &serialADM); 66 void GenerateOutPutFile(MIRModule &m); 67 void CreateCGAndBeCommon(MIRModule &m); 68 void PrepareLower(MIRModule &m); 69 void PostOutPut(MIRModule &m); 70 void DoFuncCGLower(const MIRModule &m, MIRFunction &mirFunc); 71 /* Tool functions */ 72 void DumpFuncCGIR(const CGFunc &f, const std::string &phaseName) const; 73 /* For Emit */ 74 void InitProfile(MIRModule &m) const; 75 void EmitGlobalInfo(MIRModule &m) const; 76 void EmitDuplicatedAsmFunc(MIRModule &m) const; 77 void EmitDebugInfo(const MIRModule &m) const; 78 void EmitFastFuncs(const MIRModule &m) const; 79 bool IsFramework(MIRModule &m) const; 80 void SweepUnusedStaticSymbol(MIRModule &m); 81 82 CG *cg = nullptr; 83 BECommon *beCommon = nullptr; 84 MIRLower *mirLower = nullptr; 85 CGLowerer *cgLower = nullptr; 86 /* module options */ 87 CGOptions *cgOptions = nullptr; 88 }; 89 } /* namespace maplebe */ 90 #endif /* MAPLEBE_INCLUDE_CG_CG_PHASEMANAGER_H */ 91