1 //===- PostOrderCFGView.cpp - Post order view of CFG blocks ---------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements post order view of the blocks in a CFG.
11 //===----------------------------------------------------------------------===//
13 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
14 #include "clang/Analysis/AnalysisDeclContext.h"
15 #include "clang/Analysis/CFG.h"
17 using namespace clang;
19 void PostOrderCFGView::anchor() {}
21 PostOrderCFGView::PostOrderCFGView(const CFG *cfg) {
22 Blocks.reserve(cfg->getNumBlockIDs());
23 CFGBlockSet BSet(cfg);
25 for (po_iterator I = po_iterator::begin(cfg, BSet),
26 E = po_iterator::end(cfg, BSet); I != E; ++I) {
27 BlockOrder[*I] = Blocks.size() + 1;
32 PostOrderCFGView *PostOrderCFGView::create(AnalysisDeclContext &ctx) {
33 const CFG *cfg = ctx.getCFG();
36 return new PostOrderCFGView(cfg);
39 const void *PostOrderCFGView::getTag() { static int x; return &x; }
41 bool PostOrderCFGView::BlockOrderCompare::operator()(const CFGBlock *b1,
42 const CFGBlock *b2) const {
43 PostOrderCFGView::BlockOrderTy::const_iterator b1It = POV.BlockOrder.find(b1);
44 PostOrderCFGView::BlockOrderTy::const_iterator b2It = POV.BlockOrder.find(b2);
46 unsigned b1V = (b1It == POV.BlockOrder.end()) ? 0 : b1It->second;
47 unsigned b2V = (b2It == POV.BlockOrder.end()) ? 0 : b2It->second;