• 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 #include "maple_phase.h"
17 namespace maple {
GetMaplePhaseRegister()18 MaplePhaseRegister *MaplePhaseRegister::GetMaplePhaseRegister()
19 {
20     static MaplePhaseRegister *globalRegister = new MaplePhaseRegister();
21     return globalRegister;
22 }
23 
RegisterPhase(const MaplePhaseInfo & PI)24 void MaplePhaseRegister::RegisterPhase(const MaplePhaseInfo &PI)
25 {
26     bool checkSucc = passInfoMap.emplace(std::pair<MaplePhaseID, const MaplePhaseInfo *>(PI.GetPhaseID(), &PI)).second;
27     CHECK_FATAL(checkSucc, "Register Phase failed");
28 }
29 
GetPhaseByID(MaplePhaseID id)30 const MaplePhaseInfo *MaplePhaseRegister::GetPhaseByID(MaplePhaseID id)
31 {
32     if (passInfoMap.count(id)) {
33         return passInfoMap.find(id)->second;
34     } else {
35         CHECK_FATAL(false, "This phase has not been registered");
36         return passInfoMap.end()->second;
37     }
38 }
39 
Dump() const40 void MaplePhase::Dump() const
41 {
42     LogInfo::MapleLogger() << "this is Phase : " << PhaseName() << " Kind : " << phaseKind << " ID : " << phaseID
43                            << "\n";
44 }
45 
ApplyTempMemPool()46 MemPool *MaplePhase::ApplyTempMemPool()
47 {
48     MemPool *res = memPoolCtrler.NewMemPool("temp Mempool", true);
49     tempMemPools.emplace_back(res);
50     return res;
51 }
52 
ClearTempMemPool()53 void MaplePhase::ClearTempMemPool()
54 {
55 #ifdef DEBUG
56     uint32 maxMemPoolNum = 5;
57     DEBUG_ASSERT(tempMemPools.size() <= maxMemPoolNum, " maple phase uses too many temp mempool");
58 #endif
59     if (!tempMemPools.empty()) {
60         for (auto mpIt : tempMemPools) {
61             delete mpIt;
62             mpIt = nullptr;
63         }
64         tempMemPools.clear();
65     }
66 }
67 
68 /* default : do not require any phases */
AnalysisDepInit(AnalysisDep & aDep) const69 void MaplePhase::AnalysisDepInit(AnalysisDep &aDep) const
70 {
71     GetAnalysisDependence(aDep);
72 }
73 
GetAnalysisDependence(AnalysisDep & aDep) const74 void MaplePhase::GetAnalysisDependence(AnalysisDep &aDep) const
75 {
76     (void)aDep;
77     // do nothing if derived class not defined analysis dependence
78 }
79 
SetAnalysisInfoHook(AnalysisInfoHook * hook)80 void MaplePhase::SetAnalysisInfoHook(AnalysisInfoHook *hook)
81 {
82     analysisInfo = hook;
83 }
84 
GetAnalysisInfoHook()85 AnalysisInfoHook *MaplePhase::GetAnalysisInfoHook()
86 {
87     return analysisInfo;
88 }
89 }  // namespace maple
90