1 //===- PostOrderCFGView.cpp - Post order view of CFG blocks ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file implements post order view of the blocks in a CFG.
12 //===----------------------------------------------------------------------===//
14 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
15 #include "clang/Analysis/AnalysisDeclContext.h"
16 #include "clang/Analysis/CFG.h"
18 using namespace clang;
20 void PostOrderCFGView::anchor() {}
22 PostOrderCFGView::PostOrderCFGView(const CFG *cfg) {
23 Blocks.reserve(cfg->getNumBlockIDs());
24 CFGBlockSet BSet(cfg);
26 for (po_iterator I = po_iterator::begin(cfg, BSet),
27 E = po_iterator::end(cfg, BSet); I != E; ++I) {
28 BlockOrder[*I] = Blocks.size() + 1;
33 PostOrderCFGView *PostOrderCFGView::create(AnalysisDeclContext &ctx) {
34 const CFG *cfg = ctx.getCFG();
37 return new PostOrderCFGView(cfg);
40 const void *PostOrderCFGView::getTag() { static int x; return &x; }
42 bool PostOrderCFGView::BlockOrderCompare::operator()(const CFGBlock *b1,
43 const CFGBlock *b2) const {
44 PostOrderCFGView::BlockOrderTy::const_iterator b1It = POV.BlockOrder.find(b1);
45 PostOrderCFGView::BlockOrderTy::const_iterator b2It = POV.BlockOrder.find(b2);
47 unsigned b1V = (b1It == POV.BlockOrder.end()) ? 0 : b1It->second;
48 unsigned b2V = (b2It == POV.BlockOrder.end()) ? 0 : b2It->second;