15#include "llvm/ADT/DenseMap.h"
20struct VisitClockTimes {
31 const Stmt *Term =
Block->getTerminatorStmt();
40llvm::DenseMap<const CFGBlock *, const CFGBlock *>
43 llvm::DenseMap<const CFGBlock *, const CFGBlock *> BackEdges;
45 std::vector<VisitClockTimes> VisitState;
47 std::stack<std::pair<const CFGBlock *, CFGBlock::const_succ_iterator>>
54 while (!DFSStack.empty()) {
55 auto &[
Block, SuccIt] = DFSStack.top();
56 if (SuccIt ==
Block->succ_end()) {
57 VisitState[
Block->getBlockID()].Post = Clock++;
68 VisitClockTimes &SuccVisitState = VisitState[Succ->
getBlockID()];
69 if (SuccVisitState.Pre != -1) {
70 if (SuccVisitState.Post == -1)
71 BackEdges.insert({
Block, Succ});
73 SuccVisitState.Pre = Clock++;
82llvm::SmallDenseSet<const CFGBlock *>
84 llvm::SmallDenseSet<const CFGBlock *> NonStructLoopBackedgeNodes;
87 return NonStructLoopBackedgeNodes;
89 llvm::DenseMap<const CFGBlock *, const CFGBlock *> Backedges =
91 for (
const auto &[From, To] : Backedges) {
92 if (From->getLoopTarget() ==
nullptr)
93 NonStructLoopBackedgeNodes.insert(From);
95 return NonStructLoopBackedgeNodes;
100 const llvm::SmallDenseSet<const CFGBlock *> &NonStructLoopBackedgeNodes) {
102 NonStructLoopBackedgeNodes.contains(&B);
This class represents a potential adjacent block in the CFG.
CFGBlock * getReachableBlock() const
Get the reachable block, if one exists.
Represents a single basic block in a source-level CFG.
succ_iterator succ_begin()
const Stmt * getLoopTarget() const
unsigned getBlockID() const
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
Stmt - This represents one statement.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
llvm::DenseMap< const CFGBlock *, const CFGBlock * > findCFGBackEdges(const CFG &CFG)
Finds and returns back edges in Clang CFGs.
static bool hasGotoInCFG(const CFG &CFG)
bool isBackedgeCFGNode(const CFGBlock &B, const llvm::SmallDenseSet< const CFGBlock * > &NonStructLoopBackedgeNodes)
Given a backedge from B1 to B2, B1 is a "backedge node" in a CFG.
llvm::SmallDenseSet< const CFGBlock * > findNonStructuredLoopBackedgeNodes(const CFG &CFG)
Returns a set of CFG blocks that is the source of a backedge and is not tracked as part of a structur...