LLVM  8.0.1
LegacyDivergenceAnalysis.h
Go to the documentation of this file.
1 //===- llvm/Analysis/LegacyDivergenceAnalysis.h - KernelDivergence Analysis -*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // The kernel divergence analysis is an LLVM pass which can be used to find out
11 // if a branch instruction in a GPU program (kernel) is divergent or not. It can help
12 // branch optimizations such as jump threading and loop unswitching to make
13 // better decisions.
14 //
15 //===----------------------------------------------------------------------===//
16 #ifndef LLVM_ANALYSIS_LEGACY_DIVERGENCE_ANALYSIS_H
17 #define LLVM_ANALYSIS_LEGACY_DIVERGENCE_ANALYSIS_H
18 
19 #include "llvm/ADT/DenseSet.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/Pass.h"
23 
24 namespace llvm {
25 class Value;
26 class GPUDivergenceAnalysis;
28 public:
29  static char ID;
30 
33  }
34 
35  void getAnalysisUsage(AnalysisUsage &AU) const override;
36 
37  bool runOnFunction(Function &F) override;
38 
39  // Print all divergent branches in the function.
40  void print(raw_ostream &OS, const Module *) const override;
41 
42  // Returns true if V is divergent at its definition.
43  //
44  // Even if this function returns false, V may still be divergent when used
45  // in a different basic block.
46  bool isDivergent(const Value *V) const;
47 
48  // Returns true if V is uniform/non-divergent.
49  //
50  // Even if this function returns true, V may still be divergent when used
51  // in a different basic block.
52  bool isUniform(const Value *V) const { return !isDivergent(V); }
53 
54  // Keep the analysis results uptodate by removing an erased value.
55  void removeValue(const Value *V) { DivergentValues.erase(V); }
56 
57 private:
58  // Whether analysis should be performed by GPUDivergenceAnalysis.
59  bool shouldUseGPUDivergenceAnalysis(const Function &F) const;
60 
61  // (optional) handle to new DivergenceAnalysis
62  std::unique_ptr<GPUDivergenceAnalysis> gpuDA;
63 
64  // Stores all divergent values.
65  DenseSet<const Value *> DivergentValues;
66 };
67 } // End llvm namespace
68 
69 #endif //LLVM_ANALYSIS_LEGACY_DIVERGENCE_ANALYSIS_H
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
bool isDivergent(const Value *V) const
This class represents lattice values for constants.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:65
bool erase(const ValueT &V)
Definition: DenseSet.h:96
F(f)
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
Represent the analysis usage information of a pass.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:285
LLVM Value Representation.
Definition: Value.h:73
bool isUniform(const Value *V) const
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46
void initializeLegacyDivergenceAnalysisPass(PassRegistry &)