clang  14.0.0git
PostOrderCFGView.cpp
Go to the documentation of this file.
1 //===- PostOrderCFGView.cpp - Post order view of CFG blocks ---------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements post order view of the blocks in a CFG.
10 //
11 //===----------------------------------------------------------------------===//
12 
15 #include "clang/Analysis/CFG.h"
16 
17 using namespace clang;
18 
19 void PostOrderCFGView::anchor() {}
20 
22  Blocks.reserve(cfg->getNumBlockIDs());
23  CFGBlockSet BSet(cfg);
24 
25  for (po_iterator I = po_iterator::begin(cfg, BSet),
26  E = po_iterator::end(cfg, BSet); I != E; ++I) {
27  BlockOrder[*I] = Blocks.size() + 1;
28  Blocks.push_back(*I);
29  }
30 }
31 
32 std::unique_ptr<PostOrderCFGView>
34  const CFG *cfg = ctx.getCFG();
35  if (!cfg)
36  return nullptr;
37  return std::make_unique<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 }
clang::CFG::getNumBlockIDs
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
Definition: CFG.h:1411
AnalysisDeclContext.h
clang::AnalysisDeclContext
AnalysisDeclContext contains the context data for the function, method or block under analysis.
Definition: AnalysisDeclContext.h:72
PostOrderCFGView.h
clang::CFG
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition: CFG.h:1225
clang::CFGBlock
Represents a single basic block in a source-level CFG.
Definition: CFG.h:576
x
IRgen optimization opportunities The common pattern of short x
Definition: README.txt:7
clang::PostOrderCFGView::create
static std::unique_ptr< PostOrderCFGView > create(AnalysisDeclContext &analysisContext)
Definition: PostOrderCFGView.cpp:33
clang::PostOrderCFGView::BlockOrderCompare::POV
const PostOrderCFGView & POV
Definition: PostOrderCFGView.h:96
clang
Definition: CalledOnceCheck.h:17
CFG.h
clang::PostOrderCFGView::CFGBlockSet
Implements a set of CFGBlocks using a BitVector.
Definition: PostOrderCFGView.h:38
clang::PostOrderCFGView::getTag
static const void * getTag()
Definition: PostOrderCFGView.cpp:40
clang::AnalysisDeclContext::getCFG
CFG * getCFG()
Definition: AnalysisDeclContext.cpp:213
clang::PostOrderCFGView::BlockOrderCompare::operator()
bool operator()(const CFGBlock *b1, const CFGBlock *b2) const
Definition: PostOrderCFGView.cpp:42
clang::PostOrderCFGView::PostOrderCFGView
PostOrderCFGView(const CFG *cfg)
Definition: PostOrderCFGView.cpp:21