blob: dd3c68e2dd673259d99f33ed7d445b491e3da366 [file] [log] [blame]
Andrew Scull5e1ddfa2018-08-14 10:06:54 +01001//===- 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
23namespace llvm {
24class Value;
25class DivergenceAnalysis : public FunctionPass {
26public:
27 static char ID;
28
29 DivergenceAnalysis() : FunctionPass(ID) {
30 initializeDivergenceAnalysisPass(*PassRegistry::getPassRegistry());
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.
41 bool isDivergent(const Value *V) const { return DivergentValues.count(V); }
42
43 // Returns true if V is uniform/non-divergent.
44 bool isUniform(const Value *V) const { return !isDivergent(V); }
45
46private:
47 // Stores all divergent values.
48 DenseSet<const Value *> DivergentValues;
49};
50} // End llvm namespace
51
52#endif //LLVM_ANALYSIS_DIVERGENCE_ANALYSIS_H