1 //===- SyncDependenceAnalysis.h - Divergent Branch Dependence -*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
10 // This file defines the SyncDependenceAnalysis class, which computes for
11 // every divergent branch the set of phi nodes that the branch will make
14 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_ANALYSIS_SYNC_DEPENDENCE_ANALYSIS_H
17 #define LLVM_ANALYSIS_SYNC_DEPENDENCE_ANALYSIS_H
19 #include "llvm/ADT/DenseMap.h"
20 #include "llvm/ADT/PostOrderIterator.h"
21 #include "llvm/ADT/SmallPtrSet.h"
22 #include "llvm/Analysis/LoopInfo.h"
30 class PostDominatorTree;
32 using ConstBlockSet = SmallPtrSet<const BasicBlock *, 4>;
34 /// \brief Relates points of divergent control to join points in
37 /// This analysis relates points of divergent control to points of converging
38 /// divergent control. The analysis requires all loops to be reducible.
39 class SyncDependenceAnalysis {
41 ~SyncDependenceAnalysis();
42 SyncDependenceAnalysis(const DominatorTree &DT, const PostDominatorTree &PDT,
45 /// \brief Computes divergent join points and loop exits caused by branch
46 /// divergence in \p Term.
48 /// The set of blocks which are reachable by disjoint paths from \p Term.
49 /// The set also contains loop exits if there two disjoint paths:
50 /// one from \p Term to the loop exit and another from \p Term to the loop
51 /// header. Those exit blocks are added to the returned set.
52 /// If L is the parent loop of \p Term and an exit of L is in the returned
53 /// set then L is a divergent loop.
54 const ConstBlockSet &join_blocks(const Instruction &Term);
56 /// \brief Computes divergent join points and loop exits (in the surrounding
57 /// loop) caused by the divergent loop exits of\p Loop.
59 /// The set of blocks which are reachable by disjoint paths from the
60 /// loop exits of \p Loop.
61 /// This treats the loop as a single node in \p Loop's parent loop.
62 /// The returned set has the same properties as for join_blocks(TermInst&).
63 const ConstBlockSet &join_blocks(const Loop &Loop);
66 static ConstBlockSet EmptyBlockSet;
68 ReversePostOrderTraversal<const Function *> FuncRPOT;
69 const DominatorTree &DT;
70 const PostDominatorTree &PDT;
73 std::map<const Loop *, std::unique_ptr<ConstBlockSet>> CachedLoopExitJoins;
74 std::map<const Instruction *, std::unique_ptr<ConstBlockSet>>
80 #endif // LLVM_ANALYSIS_SYNC_DEPENDENCE_ANALYSIS_H