LLVM 22.0.0git
SPIRVConvergenceRegionAnalysis.h
Go to the documentation of this file.
1//===- SPIRVConvergenceRegionAnalysis.h ------------------------*- 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// The analysis determines the convergence region for each basic block of
10// the module, and provides a tree-like structure describing the region
11// hierarchy.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_LIB_TARGET_SPIRV_SPIRVCONVERGENCEREGIONANALYSIS_H
16#define LLVM_LIB_TARGET_SPIRV_SPIRVCONVERGENCEREGIONANALYSIS_H
17
19#include "llvm/Analysis/CFG.h"
21#include "llvm/IR/Dominators.h"
22#include <optional>
23
24namespace llvm {
25class IntrinsicInst;
26class SPIRVSubtarget;
27class MachineFunction;
29
30namespace SPIRV {
31
32// Returns the first convergence intrinsic found in |BB|, |nullopt| otherwise.
33std::optional<IntrinsicInst *> getConvergenceToken(BasicBlock *BB);
34std::optional<const IntrinsicInst *> getConvergenceToken(const BasicBlock *BB);
35
36// Describes a hierarchy of convergence regions.
37// A convergence region defines a CFG for which the execution flow can diverge
38// starting from the entry block, but should reconverge back before the end of
39// the exit blocks.
41 DominatorTree &DT;
42 LoopInfo &LI;
43
44public:
45 // The parent region of this region, if any.
47 // The sub-regions contained in this region, if any.
49 // The convergence instruction linked to this region, if any.
50 std::optional<IntrinsicInst *> ConvergenceToken = std::nullopt;
51 // The only block with a predecessor outside of this region.
52 BasicBlock *Entry = nullptr;
53 // All the blocks with an edge leaving this convergence region.
55 // All the blocks that belongs to this region, including its subregions'.
57
58 // Creates a single convergence region encapsulating the whole function |F|.
60
61 // Creates a single convergence region defined by entry and exits nodes, a
62 // list of blocks, and possibly a convergence token.
64 std::optional<IntrinsicInst *> ConvergenceToken,
67
69 : DT(CR.DT), LI(CR.LI), Parent(std::move(CR.Parent)),
72 Entry(std::move(CR.Entry)), Exits(std::move(CR.Exits)),
73 Blocks(std::move(CR.Blocks)) {}
74
76
78 ConvergenceRegion(const ConvergenceRegion &other) = delete;
80
81 // Returns true if the given basic block belongs to this region, or to one of
82 // its subregion.
83 bool contains(const BasicBlock *BB) const { return Blocks.count(BB) != 0; }
84
85 void releaseMemory();
86
87 // Write to the debug output this region's hierarchy.
88 // |IndentSize| defines the number of tabs to print before any new line.
89 void dump(const unsigned IndentSize = 0) const;
90};
91
92// Holds a ConvergenceRegion hierarchy.
94 // The convergence region this structure holds.
95 ConvergenceRegion *TopLevelRegion;
96
97public:
98 ConvergenceRegionInfo() : TopLevelRegion(nullptr) {}
99
100 // Creates a new ConvergenceRegionInfo. Ownership of the TopLevelRegion is
101 // passed to this object.
103 : TopLevelRegion(TopLevelRegion) {}
104
106
109
111 : TopLevelRegion(LHS.TopLevelRegion) {
112 if (TopLevelRegion != LHS.TopLevelRegion) {
113 releaseMemory();
114 TopLevelRegion = LHS.TopLevelRegion;
115 }
116 LHS.TopLevelRegion = nullptr;
117 }
118
120 if (TopLevelRegion != LHS.TopLevelRegion) {
122 TopLevelRegion = LHS.TopLevelRegion;
123 }
124 LHS.TopLevelRegion = nullptr;
125 return *this;
126 }
127
129 if (TopLevelRegion == nullptr)
130 return;
131
132 TopLevelRegion->releaseMemory();
133 delete TopLevelRegion;
134 TopLevelRegion = nullptr;
135 }
136
137 const ConvergenceRegion *getTopLevelRegion() const { return TopLevelRegion; }
139 return TopLevelRegion;
140 }
141};
142
143} // namespace SPIRV
144
145// Wrapper around the function above to use it with the legacy pass manager.
148
149public:
150 static char ID;
151
153
159
160 bool runOnFunction(Function &F) override;
161
163 const SPIRV::ConvergenceRegionInfo &getRegionInfo() const { return CRI; }
164};
165
166// Wrapper around the function above to use it with the new pass manager.
168 : public AnalysisInfoMixin<SPIRVConvergenceRegionAnalysis> {
170 static AnalysisKey Key;
171
172public:
174
176};
177
178namespace SPIRV {
179ConvergenceRegionInfo getConvergenceRegions(Function &F, DominatorTree &DT,
180 LoopInfo &LI);
181} // namespace SPIRV
182
183} // namespace llvm
184#endif // LLVM_LIB_TARGET_SPIRV_SPIRVCONVERGENCEREGIONANALYSIS_H
#define F(x, y, z)
Definition MD5.cpp:54
This file defines the SmallPtrSet class.
Value * LHS
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
void setPreservesAll()
Set by analyses that do not transform their input at all.
LLVM Basic Block Representation.
Definition BasicBlock.h:62
Legacy analysis pass which computes a DominatorTree.
Definition Dominators.h:321
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition Dominators.h:164
FunctionPass(char &pid)
Definition Pass.h:316
A wrapper class for inspecting calls to intrinsic functions.
The legacy pass manager's analysis pass to compute loop information.
Definition LoopInfo.h:596
This class contains meta information specific to a module.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
const SPIRV::ConvergenceRegionInfo & getRegionInfo() const
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
Result run(Function &F, FunctionAnalysisManager &AM)
const ConvergenceRegion * getTopLevelRegion() const
ConvergenceRegionInfo & operator=(ConvergenceRegionInfo &&LHS)
ConvergenceRegionInfo & operator=(const ConvergenceRegionInfo &LHS)=delete
ConvergenceRegionInfo(const ConvergenceRegionInfo &LHS)=delete
ConvergenceRegionInfo(ConvergenceRegion *TopLevelRegion)
SmallVector< ConvergenceRegion * > Children
ConvergenceRegion & operator=(const ConvergenceRegion &other)=delete
ConvergenceRegion(DominatorTree &DT, LoopInfo &LI, Function &F)
void dump(const unsigned IndentSize=0) const
bool contains(const BasicBlock *BB) const
ConvergenceRegion(const ConvergenceRegion &other)=delete
std::optional< IntrinsicInst * > ConvergenceToken
ConvergenceRegion & operator=(ConvergenceRegion &&CR)=delete
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
ConvergenceRegionInfo getConvergenceRegions(Function &F, DominatorTree &DT, LoopInfo &LI)
std::optional< IntrinsicInst * > getConvergenceToken(BasicBlock *BB)
This is an optimization pass for GlobalISel generic memory operations.
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1867
AnalysisManager< Function > FunctionAnalysisManager
Convenience typedef for the Function analysis manager.
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:867
A CRTP mix-in that provides informational APIs needed for analysis passes.
Definition PassManager.h:92
A special type used by analysis passes to provide an address that identifies that particular analysis...
Definition Analysis.h:29