LLVM  7.0.0svn
DivergenceAnalysis.h
Go to the documentation of this file.
1 //===- llvm/Analysis/DivergenceAnalysis.h - Divergence 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 divergence analysis is an LLVM pass which can be used to find out
11 // if a branch instruction in a GPU program 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_DIVERGENCE_ANALYSIS_H
17 #define LLVM_ANALYSIS_DIVERGENCE_ANALYSIS_H
18 
19 #include "llvm/ADT/DenseSet.h"
20 #include "llvm/IR/Function.h"
21 #include "llvm/Pass.h"
22 
23 namespace llvm {
24 class Value;
26 public:
27  static char ID;
28 
31  }
32 
33  void getAnalysisUsage(AnalysisUsage &AU) const override;
34 
35  bool runOnFunction(Function &F) override;
36 
37  // Print all divergent branches in the function.
38  void print(raw_ostream &OS, const Module *) const override;
39 
40  // Returns true if V is divergent at its definition.
41  //
42  // Even if this function returns false, V may still be divergent when used
43  // in a different basic block.
44  bool isDivergent(const Value *V) const { return DivergentValues.count(V); }
45 
46  // Returns true if V is uniform/non-divergent.
47  //
48  // Even if this function returns true, V may still be divergent when used
49  // in a different basic block.
50  bool isUniform(const Value *V) const { return !isDivergent(V); }
51 
52  // Keep the analysis results uptodate by removing an erased value.
53  void removeValue(const Value *V) { DivergentValues.erase(V); }
54 
55 private:
56  // Stores all divergent values.
57  DenseSet<const Value *> DivergentValues;
58 };
59 } // End llvm namespace
60 
61 #endif //LLVM_ANALYSIS_DIVERGENCE_ANALYSIS_H
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
Compute iterated dominance frontiers using a linear time algorithm.
Definition: AllocatorList.h:24
A Module instance is used to store all the information related to an LLVM module. ...
Definition: Module.h:63
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
bool erase(const ValueT &V)
Definition: DenseSet.h:95
F(f)
void initializeDivergenceAnalysisPass(PassRegistry &)
bool isUniform(const Value *V) const
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state 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
static char ID
end namespace anonymous
bool isDivergent(const Value *V) const
void removeValue(const Value *V)
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
Definition: DenseSet.h:91
LLVM Value Representation.
Definition: Value.h:73
This class implements an extremely fast bulk output stream that can only output to a stream...
Definition: raw_ostream.h:46