clang 23.0.0git
CFGBackEdges.h
Go to the documentation of this file.
1//===- CFGBackEdges.h - Finds back edges in Clang CFGs -*- C++ ----------*-===//
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#ifndef LLVM_CLANG_ANALYSIS_CFG_BACKEDGES_H
10#define LLVM_CLANG_ANALYSIS_CFG_BACKEDGES_H
11
12#include "clang/Analysis/CFG.h"
13#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/DenseSet.h"
15
16namespace clang {
17
18/// Finds and returns back edges in Clang CFGs. The CFG already has some
19/// backedge information for structured loops (\c CFGBlock::getLoopTarget).
20/// However, unstructured back edges from \c goto statements are not included.
21/// This helps find back edges, whether the CFG is reducible or not.
22/// This includes CFGBlock::getLoopTarget nodes, but one can filter those out
23/// e.g., with \c findNonStructuredLoopBackedgeNodes.
24llvm::DenseMap<const CFGBlock *, const CFGBlock *>
26
27/// Returns a set of CFG blocks that is the source of a backedge and is not
28/// tracked as part of a structured loop (with `CFGBlock::getLoopTarget`).
29llvm::SmallDenseSet<const CFGBlock *>
31
32/// Given a backedge from B1 to B2, B1 is a "backedge node" in a CFG.
33/// It can be:
34/// - A block introduced in the CFG exclusively to indicate a structured loop's
35/// backedge. They are exactly identified by the presence of a non-null
36/// pointer to the entry block of the loop condition. Note that this is not
37/// necessarily the block with the loop statement as terminator, because
38/// short-circuit operators will result in multiple blocks encoding the loop
39/// condition, only one of which will contain the loop statement as
40/// terminator.
41/// - A block that is part of a backedge in a CFG with unstructured loops
42/// (e.g., a CFG with a `goto` statement). Note that this is not necessarily
43/// the block with the goto statement as terminator. The choice depends on how
44/// blocks and edges are ordered.
45///
46/// \param NonStructLoopBackedgeNodes is the set of nodes from
47/// \c findNonStructuredLoopBackedgeNodes.
49 const CFGBlock &B,
50 const llvm::SmallDenseSet<const CFGBlock *> &NonStructLoopBackedgeNodes);
51
52} // namespace clang
53
54#endif // LLVM_CLANG_ANALYSIS_CFG_BACKEDGES_H
Represents a single basic block in a source-level CFG.
Definition CFG.h:632
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition CFG.h:1250
The JSON file list parser is used to communicate input to InstallAPI.
llvm::DenseMap< const CFGBlock *, const CFGBlock * > findCFGBackEdges(const CFG &CFG)
Finds and returns back edges in Clang CFGs.
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...