clang  8.0.0svn
PostOrderCFGView.cpp
Go to the documentation of this file.
1 //===- PostOrderCFGView.cpp - Post order view of CFG blocks ---------------===//
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 
16 #include "clang/Analysis/CFG.h"
17 
18 using namespace clang;
19 
20 void PostOrderCFGView::anchor() {}
21 
23  Blocks.reserve(cfg->getNumBlockIDs());
24  CFGBlockSet BSet(cfg);
25 
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;
29  Blocks.push_back(*I);
30  }
31 }
32 
34  const CFG *cfg = ctx.getCFG();
35  if (!cfg)
36  return nullptr;
37  return new PostOrderCFGView(cfg);
38 }
39 
40 const void *PostOrderCFGView::getTag() { static int x; return &x; }
41 
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);
46 
47  unsigned b1V = (b1It == POV.BlockOrder.end()) ? 0 : b1It->second;
48  unsigned b2V = (b2It == POV.BlockOrder.end()) ? 0 : b2It->second;
49  return b1V > b2V;
50 }
AnalysisDeclContext contains the context data for the function or method under analysis.
static PostOrderCFGView * create(AnalysisDeclContext &analysisContext)
Implements a set of CFGBlocks using a BitVector.
Represents a single basic block in a source-level CFG.
Definition: CFG.h:552
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt...
Definition: CFG.h:1003
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
Definition: CFG.h:1169
Dataflow Directional Tag Classes.
bool operator()(const CFGBlock *b1, const CFGBlock *b2) const
static const void * getTag()
PostOrderCFGView(const CFG *cfg)