• 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 "cg_dominance.h"
17 #include <set>
18 #include "cg_option.h"
19 #include "cgfunc.h"
20 
21 /*
22  * This phase build dominance
23  */
24 namespace maplebe {
25 constexpr uint32 kBBVectorInitialSize = 2;
PostOrderWalk(const BB & bb,int32 & pid,MapleVector<bool> & visitedMap)26 void DomAnalysis::PostOrderWalk(const BB &bb, int32 &pid, MapleVector<bool> &visitedMap)
27 {
28     std::stack<const BB*> s;
29     s.push(&bb);
30     visitedMap[bb.GetId()] = true;
31     while (!s.empty()) {
32         auto node = s.top();
33         auto nodeId = node->GetId();
34         DEBUG_ASSERT(nodeId < visitedMap.size() && nodeId < postOrderIDVec.size(), "index out of range");
35         bool tail = true;
36         for (auto succ : node->GetSuccs()) {
37             if (!visitedMap[succ->GetId()]) {
38                 tail = false;
39                 visitedMap[succ->GetId()] = true;
40                 s.push(succ);
41                 break;
42             }
43         }
44         if (tail) {
45             s.pop();
46             postOrderIDVec[nodeId] = pid++;
47         }
48     }
49 }
50 
GenPostOrderID()51 void DomAnalysis::GenPostOrderID()
52 {
53     DEBUG_ASSERT(!bbVec.empty(), "size to be allocated is 0");
54     MapleVector<bool> visitedMap(bbVec.size() + 1, false, cgFunc.GetFuncScopeAllocator()->Adapter());
55     int32 postOrderID = 0;
56     PostOrderWalk(commonEntryBB, postOrderID, visitedMap);
57     // initialize reversePostOrder
58     int32 maxPostOrderID = postOrderID - 1;
59     reversePostOrder.resize(static_cast<uint32>(maxPostOrderID + 1));
60     for (size_t i = 0; i < postOrderIDVec.size(); ++i) {
61         int32 postOrderNo = postOrderIDVec[i];
62         if (postOrderNo == -1) {
63             continue;
64         }
65         reversePostOrder[static_cast<uint32>(maxPostOrderID - postOrderNo)] = bbVec[i];
66     }
67 }
68 
Intersect(BB & bb1,const BB & bb2)69 BB *DomAnalysis::Intersect(BB &bb1, const BB &bb2)
70 {
71     auto *ptrBB1 = &bb1;
72     auto *ptrBB2 = &bb2;
73     while (ptrBB1 != ptrBB2) {
74         while (postOrderIDVec[ptrBB1->GetId()] < postOrderIDVec[ptrBB2->GetId()]) {
75             ptrBB1 = GetDom(ptrBB1->GetId());
76         }
77         while (postOrderIDVec[ptrBB2->GetId()] < postOrderIDVec[ptrBB1->GetId()]) {
78             ptrBB2 = GetDom(ptrBB2->GetId());
79         }
80     }
81     return ptrBB1;
82 }
83 
CommonEntryBBIsPred(const BB & bb) const84 bool DominanceBase::CommonEntryBBIsPred(const BB &bb) const
85 {
86     for (const BB *suc : commonEntryBB.GetSuccs()) {
87         if (suc == &bb) {
88             return true;
89         }
90     }
91     return false;
92 }
93 
94 // Figure 3 in "A Simple, Fast Dominance Algorithm" by Keith Cooper et al.
ComputeDominance()95 void DomAnalysis::ComputeDominance()
96 {
97     SetDom(commonEntryBB.GetId(), &commonEntryBB);
98     bool changed;
99     do {
100         changed = false;
101         for (size_t i = 1; i < reversePostOrder.size(); ++i) {
102             BB *bb = reversePostOrder[i];
103             if (bb == nullptr) {
104                 continue;
105             }
106             BB *pre = nullptr;
107             auto it = bb->GetPredsBegin();
108             if (CommonEntryBBIsPred(*bb) || bb->GetPreds().empty()) {
109                 pre = &commonEntryBB;
110             } else {
111                 pre = *it;
112             }
113             ++it;
114             while ((GetDom(pre->GetId()) == nullptr || pre == bb) && it != bb->GetPredsEnd()) {
115                 pre = *it;
116                 ++it;
117             }
118             BB *newIDom = pre;
119             for (; it != bb->GetPredsEnd(); ++it) {
120                 pre = *it;
121                 if (GetDom(pre->GetId()) != nullptr && pre != bb) {
122                     newIDom = Intersect(*pre, *newIDom);
123                 }
124             }
125             if (GetDom(bb->GetId()) != newIDom) {
126                 SetDom(bb->GetId(), newIDom);
127                 changed = true;
128             }
129         }
130     } while (changed);
131 }
132 
133 // Figure 5 in "A Simple, Fast Dominance Algorithm" by Keith Cooper et al.
ComputeDomFrontiers()134 void DomAnalysis::ComputeDomFrontiers()
135 {
136     for (const BB *bb : bbVec) {
137         if (bb == nullptr || bb == &commonExitBB) {
138             continue;
139         }
140         if (bb->GetPreds().size() < kBBVectorInitialSize) {
141             continue;
142         }
143         for (BB *pre : bb->GetPreds()) {
144             BB *runner = pre;
145             while (runner != nullptr && runner != GetDom(bb->GetId()) && runner != &commonEntryBB) {
146                 if (!HasDomFrontier(runner->GetId(), bb->GetId())) {
147                     domFrontier[runner->GetId()].push_back(bb->GetId());
148                 }
149                 runner = GetDom(runner->GetId());
150             }
151         }
152     }
153     // check entry bb's predBB, such as :
154     // bb1 is commonEntryBB, bb2 is entryBB, bb2 is domFrontier of bb3 and bb7.
155     //       1
156     //       |
157     //       2 <-
158     //      /   |
159     //     3    |
160     //    / \   |
161     //   4   7---
162     //  / \  ^
163     // |   | |
164     // 5-->6--
165     for (BB *succ : commonEntryBB.GetSuccs()) {
166         if (succ->GetPreds().size() != 1) {  // Only deal with one pred bb.
167             continue;
168         }
169         for (BB *pre : succ->GetPreds()) {
170             BB *runner = pre;
171             while (runner != GetDom(succ->GetId()) && runner != &commonEntryBB && runner != succ) {
172                 if (!HasDomFrontier(runner->GetId(), succ->GetId())) {
173                     domFrontier[runner->GetId()].push_back(succ->GetId());
174                 }
175                 runner = GetDom(runner->GetId());
176             }
177         }
178     }
179 }
180 
ComputeDomChildren()181 void DomAnalysis::ComputeDomChildren()
182 {
183     for (auto *bb : reversePostOrder) {
184         if (bb == nullptr || GetDom(bb->GetId()) == nullptr) {
185             continue;
186         }
187         BB *parent = GetDom(bb->GetId());
188         if (parent == bb) {
189             continue;
190         }
191         domChildren[parent->GetId()].push_back(bb->GetId());
192     }
193 }
194 
195 // bbidMarker indicates that the iterDomFrontier results for bbid < bbidMarker
196 // have been computed
GetIterDomFrontier(const BB * bb,MapleUnorderedSet<uint32> * dfset,uint32 bbidMarker,std::vector<bool> & visitedMap)197 void DomAnalysis::GetIterDomFrontier(const BB *bb, MapleUnorderedSet<uint32> *dfset, uint32 bbidMarker,
198                                      std::vector<bool> &visitedMap)
199 {
200     if (visitedMap[bb->GetId()]) {
201         return;
202     }
203     visitedMap[bb->GetId()] = true;
204     for (uint32 frontierbbid : domFrontier[bb->GetId()]) {
205         (void)dfset->insert(frontierbbid);
206         if (frontierbbid < bbidMarker) {  // union with its computed result
207             dfset->insert(iterDomFrontier[frontierbbid].begin(), iterDomFrontier[frontierbbid].end());
208         } else {  // recursive call
209             BB *frontierbb = bbVec[frontierbbid];
210             GetIterDomFrontier(frontierbb, dfset, bbidMarker, visitedMap);
211         }
212     }
213 }
214 
ComputeIterDomFrontiers()215 void DomAnalysis::ComputeIterDomFrontiers()
216 {
217     for (BB *bb : bbVec) {
218         if (bb == nullptr || bb == &commonExitBB) {
219             continue;
220         }
221         std::vector<bool> visitedMap(bbVec.size(), false);
222         GetIterDomFrontier(bb, &iterDomFrontier[bb->GetId()], bb->GetId(), visitedMap);
223     }
224 }
225 
ComputeDtPreorder(const BB & bb,uint32 & num)226 uint32 DomAnalysis::ComputeDtPreorder(const BB &bb, uint32 &num)
227 {
228     // {BB, parent/self BB id}
229     using Node = std::pair<const BB *, uint32>;
230     std::stack<Node> allNodes;
231     allNodes.emplace(Node{&bb, bb.GetId()});
232 
233     while (!allNodes.empty()) {
234         DEBUG_ASSERT(num < dtPreOrder.size(), "index out of range in Dominance::ComputeDtPreorder");
235         Node curNode = allNodes.top();
236         allNodes.pop();
237         auto curBBId = curNode.first->GetId();
238         dtPreOrder[num] = curBBId;
239         dtDfn[curBBId] = num;
240         ++num;
241         dtDfnOut[curNode.second] = num;
242         if (domChildren[curBBId].empty()) {
243             dtDfnOut[curBBId] = num;
244             continue;
245         }
246         for (size_t idx = domChildren[curBBId].size(); idx > 0; --idx) {
247             allNodes.emplace(Node{bbVec[domChildren[curBBId][idx - 1]], curBBId});
248         }
249     }
250     return num;
251 }
252 
253 // true if b1 dominates b2
Dominate(const BB & bb1,const BB & bb2)254 bool DomAnalysis::Dominate(const BB &bb1, const BB &bb2)
255 {
256     return dtDfn[bb1.GetId()] <= dtDfn[bb2.GetId()] && dtDfnOut[bb1.GetId()] >= dtDfnOut[bb2.GetId()];
257 }
258 
Compute()259 void DomAnalysis::Compute()
260 {
261     GenPostOrderID();
262     ComputeDominance();
263     ComputeDomFrontiers();
264     ComputeDomChildren();
265     ComputeIterDomFrontiers();
266     uint32 num = 0;
267     (void)ComputeDtPreorder(*cgFunc.GetFirstBB(), num);
268     GetDtPreOrder().resize(num);
269 }
270 
Dump()271 void DomAnalysis::Dump()
272 {
273     for (BB *bb : reversePostOrder) {
274         LogInfo::MapleLogger() << "postorder no " << postOrderIDVec[bb->GetId()];
275         LogInfo::MapleLogger() << " is bb:" << bb->GetId();
276         LogInfo::MapleLogger() << " im_dom is bb:" << GetDom(bb->GetId())->GetId();
277         LogInfo::MapleLogger() << " domfrontier: [";
278         for (uint32 id : domFrontier[bb->GetId()]) {
279             LogInfo::MapleLogger() << id << " ";
280         }
281         LogInfo::MapleLogger() << "] domchildren: [";
282         for (uint32 id : domChildren[bb->GetId()]) {
283             LogInfo::MapleLogger() << id << " ";
284         }
285         LogInfo::MapleLogger() << "]\n";
286     }
287     LogInfo::MapleLogger() << "\npreorder traversal of dominator tree:";
288     for (uint32 id : dtPreOrder) {
289         LogInfo::MapleLogger() << id << " ";
290     }
291     LogInfo::MapleLogger() << "\n\n";
292 }
293 
294 /* ================= for PostDominance ================= */
PdomPostOrderWalk(const BB & bb,int32 & pid,MapleVector<bool> & visitedMap)295 void PostDomAnalysis::PdomPostOrderWalk(const BB &bb, int32 &pid, MapleVector<bool> &visitedMap)
296 {
297     std::stack<const BB*> s;
298     s.push(&bb);
299     visitedMap[bb.GetId()] = true;
300     while (!s.empty()) {
301         auto node = s.top();
302         auto nodeId = node->GetId();
303         if (bbVec[nodeId] == nullptr) {
304             s.pop();
305             continue;
306         }
307         DEBUG_ASSERT(nodeId < visitedMap.size() && nodeId < pdomPostOrderIDVec.size(), "index out of range");
308         bool tail = true;
309         for (auto pred : node->GetPreds()) {
310             if (!visitedMap[pred->GetId()]) {
311                 tail = false;
312                 visitedMap[pred->GetId()] = true;
313                 s.push(pred);
314                 break;
315             }
316         }
317         if (tail) {
318             s.pop();
319             pdomPostOrderIDVec[nodeId] = pid++;
320         }
321     }
322 }
323 
PdomGenPostOrderID()324 void PostDomAnalysis::PdomGenPostOrderID()
325 {
326     DEBUG_ASSERT(!bbVec.empty(), "call calloc failed in Dominance::PdomGenPostOrderID");
327     MapleVector<bool> visitedMap(bbVec.size(), false, cgFunc.GetFuncScopeAllocator()->Adapter());
328     int32 postOrderID = 0;
329     PdomPostOrderWalk(commonExitBB, postOrderID, visitedMap);
330     // initialize pdomReversePostOrder
331     int32 maxPostOrderID = postOrderID - 1;
332     pdomReversePostOrder.resize(static_cast<uint32>(maxPostOrderID + 1));
333     for (size_t i = 0; i < pdomPostOrderIDVec.size(); ++i) {
334         int32 postOrderNo = pdomPostOrderIDVec[i];
335         if (postOrderNo == -1) {
336             continue;
337         }
338         pdomReversePostOrder[static_cast<uint32>(maxPostOrderID - postOrderNo)] = bbVec[i];
339     }
340 }
341 
PdomIntersect(BB & bb1,const BB & bb2)342 BB *PostDomAnalysis::PdomIntersect(BB &bb1, const BB &bb2)
343 {
344     auto *ptrBB1 = &bb1;
345     auto *ptrBB2 = &bb2;
346     while (ptrBB1 != ptrBB2) {
347         while (pdomPostOrderIDVec[ptrBB1->GetId()] < pdomPostOrderIDVec[ptrBB2->GetId()]) {
348             ptrBB1 = GetPdom(ptrBB1->GetId());
349         }
350         while (pdomPostOrderIDVec[ptrBB2->GetId()] < pdomPostOrderIDVec[ptrBB1->GetId()]) {
351             ptrBB2 = GetPdom(ptrBB2->GetId());
352         }
353     }
354     return ptrBB1;
355 }
356 
357 // Figure 3 in "A Simple, Fast Dominance Algorithm" by Keith Cooper et al.
ComputePostDominance()358 void PostDomAnalysis::ComputePostDominance()
359 {
360     SetPdom(commonExitBB.GetId(), &commonExitBB);
361     bool changed = false;
362     do {
363         changed = false;
364         for (size_t i = 1; i < pdomReversePostOrder.size(); ++i) {
365             BB *bb = pdomReversePostOrder[i];
366             BB *suc = nullptr;
367             auto it = bb->GetSuccsBegin();
368             if (cgFunc.IsExitBB(*bb) || bb->GetSuccs().empty() || (bb->IsWontExit() && bb->GetKind() == BB::kBBGoto)) {
369                 suc = &commonExitBB;
370             } else {
371                 suc = *it;
372             }
373             ++it;
374             while ((GetPdom(suc->GetId()) == nullptr || suc == bb) && it != bb->GetSuccsEnd()) {
375                 suc = *it;
376                 ++it;
377             }
378             if (GetPdom(suc->GetId()) == nullptr) {
379                 suc = &commonExitBB;
380             }
381             BB *newIDom = suc;
382             for (; it != bb->GetSuccsEnd(); ++it) {
383                 suc = *it;
384                 if (GetPdom(suc->GetId()) != nullptr && suc != bb) {
385                     newIDom = PdomIntersect(*suc, *newIDom);
386                 }
387             }
388             if (GetPdom(bb->GetId()) != newIDom) {
389                 SetPdom(bb->GetId(), newIDom);
390                 DEBUG_ASSERT(GetPdom(newIDom->GetId()) != nullptr, "null ptr check");
391                 changed = true;
392             }
393         }
394     } while (changed);
395 }
396 
397 // Figure 5 in "A Simple, Fast Dominance Algorithm" by Keith Cooper et al.
ComputePdomFrontiers()398 void PostDomAnalysis::ComputePdomFrontiers()
399 {
400     for (const BB *bb : bbVec) {
401         if (bb == nullptr || bb == &commonEntryBB) {
402             continue;
403         }
404         if (bb->GetSuccs().size() < kBBVectorInitialSize) {
405             continue;
406         }
407         for (BB *suc : bb->GetSuccs()) {
408             BB *runner = suc;
409             while (runner != GetPdom(bb->GetId()) && runner != &commonEntryBB) {
410                 if (!HasPdomFrontier(runner->GetId(), bb->GetId())) {
411                     pdomFrontier[runner->GetId()].push_back(bb->GetId());
412                 }
413                 DEBUG_ASSERT(GetPdom(runner->GetId()) != nullptr, "ComputePdomFrontiers: pdoms[] is nullptr");
414                 runner = GetPdom(runner->GetId());
415             }
416         }
417     }
418 }
419 
ComputePdomChildren()420 void PostDomAnalysis::ComputePdomChildren()
421 {
422     for (const BB *bb : bbVec) {
423         if (bb == nullptr || GetPdom(bb->GetId()) == nullptr) {
424             continue;
425         }
426         const BB *parent = GetPdom(bb->GetId());
427         if (parent == bb) {
428             continue;
429         }
430         pdomChildren[parent->GetId()].push_back(bb->GetId());
431     }
432 }
433 
434 // bbidMarker indicates that the iterPdomFrontier results for bbid < bbidMarker
435 // have been computed
GetIterPdomFrontier(const BB * bb,MapleUnorderedSet<uint32> * dfset,uint32 bbidMarker,std::vector<bool> & visitedMap)436 void PostDomAnalysis::GetIterPdomFrontier(const BB *bb, MapleUnorderedSet<uint32> *dfset, uint32 bbidMarker,
437                                           std::vector<bool> &visitedMap)
438 {
439     if (visitedMap[bb->GetId()]) {
440         return;
441     }
442     visitedMap[bb->GetId()] = true;
443     for (uint32 frontierbbid : pdomFrontier[bb->GetId()]) {
444         (void)dfset->insert(frontierbbid);
445         if (frontierbbid < bbidMarker) {  // union with its computed result
446             dfset->insert(iterPdomFrontier[frontierbbid].begin(), iterPdomFrontier[frontierbbid].end());
447         } else {  // recursive call
448             BB *frontierbb = bbVec[frontierbbid];
449             GetIterPdomFrontier(frontierbb, dfset, bbidMarker, visitedMap);
450         }
451     }
452 }
453 
ComputeIterPdomFrontiers()454 void PostDomAnalysis::ComputeIterPdomFrontiers()
455 {
456     for (BB *bb : bbVec) {
457         if (bb == nullptr || bb == &commonEntryBB) {
458             continue;
459         }
460         std::vector<bool> visitedMap(bbVec.size(), false);
461         GetIterPdomFrontier(bb, &iterPdomFrontier[bb->GetId()], bb->GetId(), visitedMap);
462     }
463 }
464 
ComputePdtPreorder(const BB & bb,uint32 & num)465 uint32 PostDomAnalysis::ComputePdtPreorder(const BB &bb, uint32 &num)
466 {
467     DEBUG_ASSERT(num < pdtPreOrder.size(), "index out of range in Dominance::ComputePdtPreOrder");
468     pdtPreOrder[num] = bb.GetId();
469     pdtDfn[bb.GetId()] = num;
470     uint32 maxDtDfnOut = num;
471     ++num;
472 
473     for (uint32 k : pdomChildren[bb.GetId()]) {
474         maxDtDfnOut = ComputePdtPreorder(*bbVec[k], num);
475     }
476 
477     pdtDfnOut[bb.GetId()] = maxDtDfnOut;
478     return maxDtDfnOut;
479 }
480 
481 // true if b1 postdominates b2
PostDominate(const BB & bb1,const BB & bb2)482 bool PostDomAnalysis::PostDominate(const BB &bb1, const BB &bb2)
483 {
484     return pdtDfn[bb1.GetId()] <= pdtDfn[bb2.GetId()] && pdtDfnOut[bb1.GetId()] >= pdtDfnOut[bb2.GetId()];
485 }
486 
Dump()487 void PostDomAnalysis::Dump()
488 {
489     for (BB *bb : pdomReversePostOrder) {
490         LogInfo::MapleLogger() << "pdom_postorder no " << pdomPostOrderIDVec[bb->GetId()];
491         LogInfo::MapleLogger() << " is bb:" << bb->GetId();
492         LogInfo::MapleLogger() << " im_pdom is bb:" << GetPdom(bb->GetId())->GetId();
493         LogInfo::MapleLogger() << " pdomfrontier: [";
494         for (uint32 id : pdomFrontier[bb->GetId()]) {
495             LogInfo::MapleLogger() << id << " ";
496         }
497         LogInfo::MapleLogger() << "] pdomchildren: [";
498         for (uint32 id : pdomChildren[bb->GetId()]) {
499             LogInfo::MapleLogger() << id << " ";
500         }
501         LogInfo::MapleLogger() << "]\n";
502     }
503     LogInfo::MapleLogger() << "\n";
504     LogInfo::MapleLogger() << "preorder traversal of post-dominator tree:";
505     for (uint32 id : pdtPreOrder) {
506         LogInfo::MapleLogger() << id << " ";
507     }
508     LogInfo::MapleLogger() << "\n\n";
509 }
510 
GeneratePdomTreeDot()511 void PostDomAnalysis::GeneratePdomTreeDot()
512 {
513     std::streambuf *coutBuf = std::cout.rdbuf();
514     std::ofstream pdomFile;
515     std::streambuf *fileBuf = pdomFile.rdbuf();
516     (void)std::cout.rdbuf(fileBuf);
517 
518     std::string fileName;
519     (void)fileName.append("pdom_tree_");
520     (void)fileName.append(cgFunc.GetName());
521     (void)fileName.append(".dot");
522 
523     pdomFile.open(fileName.c_str(), std::ios::trunc);
524     if (!pdomFile.is_open()) {
525         LogInfo::MapleLogger(kLlWarn) << "fileName:" << fileName << " open failed.\n";
526         return;
527     }
528     pdomFile << "digraph Pdom_" << cgFunc.GetName() << " {\n\n";
529     pdomFile << "  node [shape=box];\n\n";
530 
531     FOR_ALL_BB_CONST(bb, &cgFunc)
532     {
533         if (bb->IsUnreachable()) {
534             continue;
535         }
536         pdomFile << "  BB_" << bb->GetId();
537         pdomFile << "[label= \"";
538         if (bb == cgFunc.GetCommonEntryBB()) {
539             pdomFile << "ENTRY\n";
540         }
541         pdomFile << "BB_" << bb->GetId() << "\"];\n";
542     }
543     BB *exitBB = cgFunc.GetCommonExitBB();
544     pdomFile << "  BB_" << exitBB->GetId();
545     pdomFile << "[label= \"EXIT\n";
546     pdomFile << "BB_" << exitBB->GetId() << "\"];\n";
547     pdomFile << "\n";
548 
549     for (uint32 bbId = 0; bbId < pdomChildren.size(); ++bbId) {
550         if (pdomChildren[bbId].empty()) {
551             continue;
552         }
553         BB *parent = cgFunc.GetBBFromID(bbId);
554         CHECK_FATAL(parent != nullptr, "get pdom parent-node failed");
555         for (auto childId : pdomChildren[bbId]) {
556             BB *child = cgFunc.GetBBFromID(childId);
557             CHECK_FATAL(child != nullptr, "get pdom child-node failed");
558             pdomFile << "  BB_" << parent->GetId() << " -> "
559                      << "BB_" << child->GetId();
560             pdomFile << " [dir=none]"
561                      << ";\n";
562         }
563     }
564     pdomFile << "\n";
565 
566     pdomFile << "}\n";
567     (void)pdomFile.flush();
568     pdomFile.close();
569     (void)std::cout.rdbuf(coutBuf);
570 }
571 
Compute()572 void PostDomAnalysis::Compute()
573 {
574     PdomGenPostOrderID();
575     ComputePostDominance();
576     ComputePdomFrontiers();
577     ComputePdomChildren();
578     ComputeIterPdomFrontiers();
579     uint32 num = 0;
580     (void)ComputePdtPreorder(GetCommonExitBB(), num);
581     ResizePdtPreOrder(num);
582 }
583 
PhaseRun(maplebe::CGFunc & f)584 bool CgDomAnalysis::PhaseRun(maplebe::CGFunc &f)
585 {
586     MemPool *domMemPool = GetPhaseMemPool();
587     domAnalysis =
588         domMemPool->New<DomAnalysis>(f, *domMemPool, *domMemPool, f.GetAllBBs(), *f.GetFirstBB(), *f.GetCommonExitBB());
589     domAnalysis->Compute();
590     if (CG_DEBUG_FUNC(f)) {
591         domAnalysis->Dump();
592     }
593     return false;
594 }
MAPLE_ANALYSIS_PHASE_REGISTER(CgDomAnalysis,domanalysis)595 MAPLE_ANALYSIS_PHASE_REGISTER(CgDomAnalysis, domanalysis)
596 
597 bool CgPostDomAnalysis::PhaseRun(maplebe::CGFunc &f)
598 {
599     MemPool *pdomMemPool = GetPhaseMemPool();
600     pdomAnalysis = pdomMemPool->New<PostDomAnalysis>(f, *pdomMemPool, *pdomMemPool, f.GetAllBBs(), *f.GetFirstBB(),
601                                                      *f.GetCommonExitBB());
602     pdomAnalysis->Compute();
603     if (CG_DEBUG_FUNC(f)) {
604         pdomAnalysis->Dump();
605     }
606     return false;
607 }
608 MAPLE_ANALYSIS_PHASE_REGISTER(CgPostDomAnalysis, pdomanalysis)
609 } /* namespace maplebe */
610