LLVM  14.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"
19 #include "llvm/Pass.h"
20 #include <memory>
21 
22 namespace llvm {
23 class DivergenceInfo;
24 class Function;
25 class Module;
26 class raw_ostream;
27 class TargetTransformInfo;
28 class Use;
29 class Value;
30 
32 public:
33  static char ID;
34 
36 
37  void getAnalysisUsage(AnalysisUsage &AU) const override;
38 
39  bool runOnFunction(Function &F) override;
40 
41  // Print all divergent branches in the function.
42  void print(raw_ostream &OS, const Module *) const override;
43 
44  // Returns true if V is divergent at its definition.
45  bool isDivergent(const Value *V) const;
46 
47  // Returns true if U is divergent. Uses of a uniform value can be divergent.
48  bool isDivergentUse(const Use *U) const;
49 
50  // Returns true if V is uniform/non-divergent.
51  bool isUniform(const Value *V) const { return !isDivergent(V); }
52 
53  // Returns true if U is uniform/non-divergent. Uses of a uniform value can be
54  // divergent.
55  bool isUniformUse(const Use *U) const { return !isDivergentUse(U); }
56 
57  // Keep the analysis results uptodate by removing an erased value.
58  void removeValue(const Value *V) { DivergentValues.erase(V); }
59 
60 private:
61  // Whether analysis should be performed by GPUDivergenceAnalysis.
62  bool shouldUseGPUDivergenceAnalysis(const Function &F,
63  const TargetTransformInfo &TTI) const;
64 
65  // (optional) handle to new DivergenceAnalysis
66  std::unique_ptr<DivergenceInfo> gpuDA;
67 
68  // Stores all divergent values.
69  DenseSet<const Value *> DivergentValues;
70 
71  // Stores divergent uses of possibly uniform values.
72  DenseSet<const Use *> DivergentUses;
73 };
74 } // End llvm namespace
75 
76 #endif // LLVM_ANALYSIS_LEGACYDIVERGENCEANALYSIS_H
llvm::LegacyDivergenceAnalysis::isDivergentUse
bool isDivergentUse(const Use *U) const
Definition: LegacyDivergenceAnalysis.cpp:366
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::Function
Definition: Function.h:62
Pass.h
llvm::TargetTransformInfo
This pass provides access to the codegen interfaces that are needed for IR-level transformations.
Definition: TargetTransformInfo.h:169
llvm::LegacyDivergenceAnalysis::LegacyDivergenceAnalysis
LegacyDivergenceAnalysis()
Definition: LegacyDivergenceAnalysis.cpp:286
F
#define F(x, y, z)
Definition: MD5.cpp:56
llvm::LegacyDivergenceAnalysis::ID
static char ID
Definition: LegacyDivergenceAnalysis.h:33
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
DenseSet.h
llvm::raw_ostream
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
llvm::LegacyDivergenceAnalysis
Definition: LegacyDivergenceAnalysis.h:31
llvm::LegacyDivergenceAnalysis::print
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
Definition: LegacyDivergenceAnalysis.cpp:373
llvm::LegacyDivergenceAnalysis::runOnFunction
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass.
Definition: LegacyDivergenceAnalysis.cpp:321
llvm::DenseSet< const Value * >
llvm::LegacyDivergenceAnalysis::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Definition: LegacyDivergenceAnalysis.cpp:301
llvm::LegacyDivergenceAnalysis::removeValue
void removeValue(const Value *V)
Definition: LegacyDivergenceAnalysis.h:58
llvm::Module
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:67
Module
Machine Check Debug Module
Definition: MachineCheckDebugify.cpp:122
llvm::LegacyDivergenceAnalysis::isDivergent
bool isDivergent(const Value *V) const
Definition: LegacyDivergenceAnalysis.cpp:359
llvm::TargetStackID::Value
Value
Definition: TargetFrameLowering.h:27
llvm::LegacyDivergenceAnalysis::isUniform
bool isUniform(const Value *V) const
Definition: LegacyDivergenceAnalysis.h:51
llvm::detail::DenseSetImpl::erase
bool erase(const ValueT &V)
Definition: DenseSet.h:101
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
llvm::Value
LLVM Value Representation.
Definition: Value.h:74
llvm::codeview::PublicSymFlags::Function
@ Function
llvm::Use
A Use represents the edge between a Value definition and its users.
Definition: Use.h:44
llvm::LegacyDivergenceAnalysis::isUniformUse
bool isUniformUse(const Use *U) const
Definition: LegacyDivergenceAnalysis.h:55