LLVM 17.0.0git
LegacyDivergenceAnalysis.h
Go to the documentation of this file.
1//===- llvm/Analysis/LegacyDivergenceAnalysis.h - KernelDivergence Analysis -*- 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 kernel divergence analysis is an LLVM pass which can be used to find out
10// if a branch instruction in a GPU program (kernel) is divergent or not. It can help
11// branch optimizations such as jump threading and loop unswitching to make
12// better decisions.
13//
14//===----------------------------------------------------------------------===//
15#ifndef LLVM_ANALYSIS_LEGACYDIVERGENCEANALYSIS_H
16#define LLVM_ANALYSIS_LEGACYDIVERGENCEANALYSIS_H
17
18#include "llvm/ADT/DenseSet.h"
21#include "llvm/IR/PassManager.h"
22#include "llvm/Pass.h"
23#include <memory>
24
25namespace llvm {
26class DivergenceInfo;
27class Function;
28class Module;
29class raw_ostream;
30class TargetTransformInfo;
31class Use;
32class Value;
33
35public:
36 // Returns true if V is divergent at its definition.
37 bool isDivergent(const Value *V) const;
38
39 // Returns true if U is divergent. Uses of a uniform value can be divergent.
40 bool isDivergentUse(const Use *U) const;
41
42 // Returns true if V is uniform/non-divergent.
43 bool isUniform(const Value *V) const { return !isDivergent(V); }
44
45 // Returns true if U is uniform/non-divergent. Uses of a uniform value can be
46 // divergent.
47 bool isUniformUse(const Use *U) const { return !isDivergentUse(U); }
48
49 // Keep the analysis results uptodate by removing an erased value.
50 void removeValue(const Value *V) { DivergentValues.erase(V); }
51
52 // Print all divergent branches in the function.
53 void print(raw_ostream &OS, const Module *) const;
54
55 // Whether analysis should be performed by GPUDivergenceAnalysis.
58 const LoopInfo &LI);
59
61 PostDominatorTree &PDT, const LoopInfo &LI);
62
63protected:
64 // (optional) handle to new DivergenceAnalysis
65 std::unique_ptr<DivergenceInfo> gpuDA;
66
67 // Stores all divergent values.
69
70 // Stores divergent uses of possibly uniform values.
72};
73
76public:
77 static char ID;
78
80 void getAnalysisUsage(AnalysisUsage &AU) const override;
81 bool runOnFunction(Function &F) override;
82};
83
85 : public PassInfoMixin<LegacyDivergenceAnalysisPass>,
87public:
89
90private:
91 // (optional) handle to new DivergenceAnalysis
92 std::unique_ptr<DivergenceInfo> gpuDA;
93
94 // Stores all divergent values.
95 DenseSet<const Value *> DivergentValues;
96
97 // Stores divergent uses of possibly uniform values.
98 DenseSet<const Use *> DivergentUses;
99};
100
101} // end namespace llvm
102
103#endif // LLVM_ANALYSIS_LEGACYDIVERGENCEANALYSIS_H
This file defines the DenseSet and SmallDenseSet classes.
#define F(x, y, z)
Definition: MD5.cpp:55
Machine Check Debug Module
This header defines various interfaces for pass management in LLVM.
raw_pwrite_stream & OS
A container for analyses that lazily runs them and caches their results.
Definition: PassManager.h:620
Represent the analysis usage information of a pass.
Implements a dense probed hash-table based set.
Definition: DenseSet.h:271
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree.
Definition: Dominators.h:166
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
std::unique_ptr< DivergenceInfo > gpuDA
void run(Function &F, TargetTransformInfo &TTI, DominatorTree &DT, PostDominatorTree &PDT, const LoopInfo &LI)
bool shouldUseGPUDivergenceAnalysis(const Function &F, const TargetTransformInfo &TTI, const LoopInfo &LI)
void print(raw_ostream &OS, const Module *) const
PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM)
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
A set of analyses that are preserved following a run of a transformation pass.
Definition: PassManager.h:152
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
A Use represents the edge between a Value definition and its users.
Definition: Use.h:43
LLVM Value Representation.
Definition: Value.h:74
bool erase(const ValueT &V)
Definition: DenseSet.h:101
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
A CRTP mix-in to automatically provide informational APIs needed for passes.
Definition: PassManager.h:371