• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "target_select.h"
31 #include "target_registry.h"
32 namespace maplebe {
33 using cgFuncOptTy = MapleFunctionPhase<CGFunc>;
34 
35 /* =================== new phase manager ===================  */
36 class CgFuncPM : public FunctionPM {
37 public:
CgFuncPM(MemPool * mp)38     explicit CgFuncPM(MemPool *mp) : FunctionPM(mp, &id) {}
39     PHASECONSTRUCTOR(CgFuncPM);
40     std::string PhaseName() const override;
~CgFuncPM()41     ~CgFuncPM() override
42     {
43         cgOptions = nullptr;
44         cg = nullptr;
45         beCommon = nullptr;
46         if (CGOptions::IsEnableTimePhases()) {
47             DumpPhaseTime();
48         }
49     }
50     bool PhaseRun(MIRModule &m) override;
51 
SetCGOptions(CGOptions * curCGOptions)52     void SetCGOptions(CGOptions *curCGOptions)
53     {
54         cgOptions = curCGOptions;
55     }
56 
GetCG()57     CG *GetCG()
58     {
59         return cg;
60     }
GetBECommon()61     BECommon *GetBECommon()
62     {
63         return beCommon;
64     }
65 
66 private:
67     bool FuncLevelRun(CGFunc &cgFunc, AnalysisDataManager &serialADM);
68     void GenerateOutPutFile(MIRModule &m);
69     void CreateCGAndBeCommon(MIRModule &m, const Target *T);
70     void PrepareLower(MIRModule &m);
71     void PostOutPut(MIRModule &m);
72     void DoFuncCGLower(const MIRModule &m, MIRFunction &mirFunc);
73     /* Tool functions */
74     void DumpFuncCGIR(const CGFunc &f, const std::string &phaseName) const;
75     /* For Emit */
76     void EmitGlobalInfo(MIRModule &m) const;
77     void EmitDuplicatedAsmFunc(MIRModule &m) const;
78     bool IsFramework(MIRModule &m) const;
79 
80     CG *cg = nullptr;
81     BECommon *beCommon = nullptr;
82     MIRLower *mirLower = nullptr;
83     CGLowerer *cgLower = nullptr;
84     /* module options */
85     CGOptions *cgOptions = nullptr;
86 };
87 } /* namespace maplebe */
88 #endif /* MAPLEBE_INCLUDE_CG_CG_PHASEMANAGER_H */
89