15#include "llvm/ADT/BitVector.h"
16#include "llvm/ADT/STLExtras.h"
28 std::vector<const Node *>
Nodes;
38template <
typename Node>
41 assert(Header !=
nullptr);
43 Interval.
Nodes.push_back(Header);
44 Partitioned.set(
getID(*Header));
50 std::queue<const Node *> Worklist;
51 llvm::BitVector Workset(Partitioned.size(),
false);
52 for (
const Node *S : Header->succs())
54 if (
auto SID =
getID(*S); !Partitioned.test(SID)) {
68 std::vector<const Node *> MaybeSuccessors;
70 while (!Worklist.empty()) {
71 const auto *B = Worklist.front();
78 bool AllInInterval = llvm::all_of(B->preds(), [&](
const Node *
P) {
79 return llvm::is_contained(Interval.Nodes, P);
82 Interval.
Nodes.push_back(B);
84 for (
const Node *S : B->succs())
86 if (
auto SID =
getID(*S);
87 !Partitioned.test(SID) && !Workset.test(SID)) {
92 MaybeSuccessors.push_back(B);
97 for (
const Node *B : MaybeSuccessors)
98 if (!llvm::is_contained(Interval.
Nodes, B))
104template <
typename Node>
106 std::vector<CFGIntervalNode *> &Index,
107 std::queue<const Node *> &Successors,
108 llvm::BitVector &Partitioned,
const Node *Header) {
110 for (
const auto *S :
Result.Successors)
119 for (
const auto *N :
Result.Nodes) {
120 assert(N !=
nullptr);
121 assert(
getID(*N) < Index.size());
122 Index[
getID(*N)] = &Interval;
125 if constexpr (std::is_same_v<std::decay_t<Node>,
CFGBlock>)
128 std::vector<const CFGBlock *>
Nodes;
131 for (
auto &N :
Result.Nodes)
132 Count += N->Nodes.size();
133 Nodes.reserve(Count);
134 for (
auto &N :
Result.Nodes)
135 Nodes.insert(
Nodes.end(), N->Nodes.begin(), N->Nodes.end());
140template <
typename Node>
142 const Node *EntryBlock) {
143 assert(EntryBlock !=
nullptr);
148 std::vector<CFGIntervalNode *> Index(NumBlockIDs,
nullptr);
154 std::vector<std::pair<const Node *, CFGIntervalNode *>> Intervals;
155 llvm::BitVector Partitioned(NumBlockIDs,
false);
156 std::queue<const Node *> Successors;
159 Intervals.emplace_back(EntryBlock, &Graph.back());
161 while (!Successors.empty()) {
162 const auto *B = Successors.front();
164 assert(B !=
nullptr);
165 if (Partitioned.test(
getID(*B)))
171 Intervals.emplace_back(B, &Graph.back());
175 for (
auto [H, N] : Intervals) {
178 for (
const Node *
P : H->preds()) {
182 assert(
getID(*
P) < NumBlockIDs);
215 unsigned PrevSize = Cfg.
size();
219 unsigned Size = Graph.size();
220 while (Size > 1 && Size < PrevSize) {
221 PrevSize = Graph.size();
230 return std::move(Graph[0].
Nodes);
236 auto N = WTO[0]->getParent()->getNumBlockIDs();
238 for (
unsigned I = 0, S = WTO.size(); I < S; ++I)
BoundNodesTreeBuilder Nodes
Represents a single basic block in a source-level CFG.
unsigned getBlockID() const
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
unsigned size() const
Return the total number of CFGBlocks within the CFG This is simply a renaming of the getNumBlockIDs()...
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
void fillIntervalNode(CFGIntervalGraph &Graph, std::vector< CFGIntervalNode * > &Index, std::queue< const Node * > &Successors, llvm::BitVector &Partitioned, const Node *Header)
static unsigned getID(const CFGBlock &B)
std::vector< const CFGBlock * > buildInterval(const CFGBlock *Header)
std::deque< CFGIntervalNode > CFGIntervalGraph
CFGIntervalGraph partitionIntoIntervalsImpl(unsigned NumBlockIDs, const Node *EntryBlock)
CFGIntervalGraph partitionIntoIntervals(const CFG &Cfg)
The JSON file list parser is used to communicate input to InstallAPI.
@ Result
The result type of a method or function.
std::vector< const CFGBlock * > WeakTopologicalOrdering
A weak topological ordering (WTO) of CFG nodes provides a total order over the CFG (defined in WTOCom...
std::optional< WeakTopologicalOrdering > getIntervalWTO(const CFG &Cfg)
llvm::SmallDenseSet< const Node * > Successors
std::vector< const Node * > Nodes
std::vector< unsigned > BlockOrder
WTOCompare(const WeakTopologicalOrdering &WTO)
std::vector< const CFGBlock * > Nodes
llvm::SmallDenseSet< const CFGIntervalNode * > Predecessors
llvm::SmallDenseSet< const CFGIntervalNode * > Successors