PostOrderCFGView.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. #include "clang/Analysis/Analyses/PostOrderCFGView.h"
  14. using namespace clang;
  15. void PostOrderCFGView::anchor() { }
  16. PostOrderCFGView::PostOrderCFGView(const CFG *cfg) {
  17. Blocks.reserve(cfg->getNumBlockIDs());
  18. CFGBlockSet BSet(cfg);
  19. for (po_iterator I = po_iterator::begin(cfg, BSet),
  20. E = po_iterator::end(cfg, BSet); I != E; ++I) {
  21. BlockOrder[*I] = Blocks.size() + 1;
  22. Blocks.push_back(*I);
  23. }
  24. }
  25. PostOrderCFGView *PostOrderCFGView::create(AnalysisDeclContext &ctx) {
  26. const CFG *cfg = ctx.getCFG();
  27. if (!cfg)
  28. return nullptr;
  29. return new PostOrderCFGView(cfg);
  30. }
  31. const void *PostOrderCFGView::getTag() { static int x; return &x; }
  32. bool PostOrderCFGView::BlockOrderCompare::operator()(const CFGBlock *b1,
  33. const CFGBlock *b2) const {
  34. PostOrderCFGView::BlockOrderTy::const_iterator b1It = POV.BlockOrder.find(b1);
  35. PostOrderCFGView::BlockOrderTy::const_iterator b2It = POV.BlockOrder.find(b2);
  36. unsigned b1V = (b1It == POV.BlockOrder.end()) ? 0 : b1It->second;
  37. unsigned b2V = (b2It == POV.BlockOrder.end()) ? 0 : b2It->second;
  38. return b1V > b2V;
  39. }