]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - contrib/llvm/tools/clang/lib/Analysis/PostOrderCFGView.cpp
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / contrib / llvm / tools / clang / lib / Analysis / PostOrderCFGView.cpp
1 //===- PostOrderCFGView.cpp - Post order view of CFG blocks -------*- C++ --*-//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file implements post order view of the blocks in a CFG.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
15
16 using namespace clang;
17
18 void PostOrderCFGView::anchor() { }
19
20 PostOrderCFGView::PostOrderCFGView(const CFG *cfg) {
21   Blocks.reserve(cfg->getNumBlockIDs());
22   CFGBlockSet BSet(cfg);
23     
24   for (po_iterator I = po_iterator::begin(cfg, BSet),
25                    E = po_iterator::end(cfg, BSet); I != E; ++I) {
26     BlockOrder[*I] = Blocks.size() + 1;
27     Blocks.push_back(*I);      
28   }
29 }
30
31 PostOrderCFGView *PostOrderCFGView::create(AnalysisDeclContext &ctx) {
32   const CFG *cfg = ctx.getCFG();
33   if (!cfg)
34     return 0;
35   return new PostOrderCFGView(cfg);
36 }
37
38 const void *PostOrderCFGView::getTag() { static int x; return &x; }
39
40 bool PostOrderCFGView::BlockOrderCompare::operator()(const CFGBlock *b1,
41                                                      const CFGBlock *b2) const {
42   PostOrderCFGView::BlockOrderTy::const_iterator b1It = POV.BlockOrder.find(b1);
43   PostOrderCFGView::BlockOrderTy::const_iterator b2It = POV.BlockOrder.find(b2);
44     
45   unsigned b1V = (b1It == POV.BlockOrder.end()) ? 0 : b1It->second;
46   unsigned b2V = (b2It == POV.BlockOrder.end()) ? 0 : b2It->second;
47   return b1V > b2V;
48 }
49