2018-03-14 05:32:01 +08:00
|
|
|
//===- PostOrderCFGView.cpp - Post order view of CFG blocks ---------------===//
|
2011-10-22 10:14:23 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2014-09-23 16:34:41 +08:00
|
|
|
// This file implements post order view of the blocks in a CFG.
|
2011-10-22 10:14:23 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "clang/Analysis/Analyses/PostOrderCFGView.h"
|
2018-03-14 05:32:01 +08:00
|
|
|
#include "clang/Analysis/AnalysisDeclContext.h"
|
|
|
|
#include "clang/Analysis/CFG.h"
|
2011-10-22 10:14:23 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
2018-03-14 05:32:01 +08:00
|
|
|
void PostOrderCFGView::anchor() {}
|
2011-12-20 10:48:34 +08:00
|
|
|
|
2014-09-23 16:34:41 +08:00
|
|
|
PostOrderCFGView::PostOrderCFGView(const CFG *cfg) {
|
2011-10-22 10:14:23 +08:00
|
|
|
Blocks.reserve(cfg->getNumBlockIDs());
|
|
|
|
CFGBlockSet BSet(cfg);
|
2014-09-23 16:34:41 +08:00
|
|
|
|
2011-10-22 10:14:23 +08:00
|
|
|
for (po_iterator I = po_iterator::begin(cfg, BSet),
|
|
|
|
E = po_iterator::end(cfg, BSet); I != E; ++I) {
|
2014-09-23 16:34:41 +08:00
|
|
|
BlockOrder[*I] = Blocks.size() + 1;
|
2011-10-22 10:14:23 +08:00
|
|
|
Blocks.push_back(*I);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-24 09:32:45 +08:00
|
|
|
PostOrderCFGView *PostOrderCFGView::create(AnalysisDeclContext &ctx) {
|
2011-10-22 10:14:23 +08:00
|
|
|
const CFG *cfg = ctx.getCFG();
|
|
|
|
if (!cfg)
|
2014-05-20 12:30:07 +08:00
|
|
|
return nullptr;
|
2011-10-22 10:14:23 +08:00
|
|
|
return new PostOrderCFGView(cfg);
|
|
|
|
}
|
|
|
|
|
|
|
|
const void *PostOrderCFGView::getTag() { static int x; return &x; }
|
|
|
|
|
|
|
|
bool PostOrderCFGView::BlockOrderCompare::operator()(const CFGBlock *b1,
|
|
|
|
const CFGBlock *b2) const {
|
|
|
|
PostOrderCFGView::BlockOrderTy::const_iterator b1It = POV.BlockOrder.find(b1);
|
|
|
|
PostOrderCFGView::BlockOrderTy::const_iterator b2It = POV.BlockOrder.find(b2);
|
|
|
|
|
|
|
|
unsigned b1V = (b1It == POV.BlockOrder.end()) ? 0 : b1It->second;
|
|
|
|
unsigned b2V = (b2It == POV.BlockOrder.end()) ? 0 : b2It->second;
|
|
|
|
return b1V > b2V;
|
|
|
|
}
|