• 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 #include "me_dominance.h"
16 #include <iostream>
17 #include "me_option.h"
18 #include "me_cfg.h"
19 #include "base_graph_node.h"
20 // This phase analyses the CFG of the given MeFunction, generates the dominator tree,
21 // and the dominance frontiers of each basic block using Keith Cooper's algorithm.
22 // For some backward data-flow problems, such as LiveOut,
23 // the reverse CFG(The CFG with its edges reversed) is always useful,
24 // so we also generates the above two structures on the reverse CFG.
25 namespace maple {
GetAnalysisDependence(maple::AnalysisDep & aDep) const26 void MEDominance::GetAnalysisDependence(maple::AnalysisDep &aDep) const
27 {
28     aDep.AddRequired<MEMeCfg>();
29     aDep.SetPreservedAll();
30 }
31 
PhaseRun(maple::MeFunction & f)32 bool MEDominance::PhaseRun(maple::MeFunction &f)
33 {
34     MeCFG *cfg = f.GetCfg();
35     ASSERT_NOT_NULL(cfg);
36     MemPool *memPool = GetPhaseMemPool();
37     auto alloc = MapleAllocator(memPool);
38     auto nodeVec = memPool->New<MapleVector<BaseGraphNode *>>(alloc.Adapter());
39     CHECK_NULL_FATAL(nodeVec);
40     ConvertToVectorOfBasePtr<BB>(cfg->GetAllBBs(), *nodeVec);
41     dom = memPool->New<Dominance>(*memPool, *nodeVec, *cfg->GetCommonEntryBB(), *cfg->GetCommonExitBB(), false);
42     CHECK_NULL_FATAL(dom);
43     pdom = memPool->New<Dominance>(*memPool, *nodeVec, *cfg->GetCommonExitBB(), *cfg->GetCommonEntryBB(), true);
44     CHECK_NULL_FATAL(pdom);
45     dom->Init();
46     pdom->Init();
47     if (DEBUGFUNC_NEWPM(f)) {
48         LogInfo::MapleLogger() << "-----------------Dump dominance info and postdominance info---------\n";
49         dom->DumpDoms();
50         pdom->DumpDoms();
51     }
52     return false;
53 }
54 }  // namespace maple
55