clang API Documentation

PostOrderCFGView.cpp
Go to the documentation of this file.
00001 //===- PostOrderCFGView.cpp - Post order view of CFG blocks -------*- C++ --*-//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file implements post order view of the blocks in a CFG.
00011 //
00012 //===----------------------------------------------------------------------===//
00013 
00014 #include "clang/Analysis/Analyses/PostOrderCFGView.h"
00015 
00016 using namespace clang;
00017 
00018 void PostOrderCFGView::anchor() { }
00019 
00020 PostOrderCFGView::PostOrderCFGView(const CFG *cfg) {
00021   Blocks.reserve(cfg->getNumBlockIDs());
00022   CFGBlockSet BSet(cfg);
00023     
00024   for (po_iterator I = po_iterator::begin(cfg, BSet),
00025                    E = po_iterator::end(cfg, BSet); I != E; ++I) {
00026     BlockOrder[*I] = Blocks.size() + 1;
00027     Blocks.push_back(*I);      
00028   }
00029 }
00030 
00031 PostOrderCFGView *PostOrderCFGView::create(AnalysisDeclContext &ctx) {
00032   const CFG *cfg = ctx.getCFG();
00033   if (!cfg)
00034     return nullptr;
00035   return new PostOrderCFGView(cfg);
00036 }
00037 
00038 const void *PostOrderCFGView::getTag() { static int x; return &x; }
00039 
00040 bool PostOrderCFGView::BlockOrderCompare::operator()(const CFGBlock *b1,
00041                                                      const CFGBlock *b2) const {
00042   PostOrderCFGView::BlockOrderTy::const_iterator b1It = POV.BlockOrder.find(b1);
00043   PostOrderCFGView::BlockOrderTy::const_iterator b2It = POV.BlockOrder.find(b2);
00044     
00045   unsigned b1V = (b1It == POV.BlockOrder.end()) ? 0 : b1It->second;
00046   unsigned b2V = (b2It == POV.BlockOrder.end()) ? 0 : b2It->second;
00047   return b1V > b2V;
00048 }
00049