80 #define DEBUG_TYPE "divergence" 84 class DivergencePropagator {
88 :
F(F), TTI(TTI), DT(DT), PDT(PDT), DV(DV) {}
89 void populateWithSourcesOfDivergence();
94 void exploreDataDependency(
Value *V);
103 void findUsersOutsideInfluenceRegion(
110 std::vector<Value *> Worklist;
114 void DivergencePropagator::populateWithSourcesOfDivergence() {
118 if (TTI.isSourceOfDivergence(&
I)) {
119 Worklist.push_back(&
I);
123 for (
auto &
Arg :
F.args()) {
124 if (TTI.isSourceOfDivergence(&
Arg)) {
125 Worklist.push_back(&
Arg);
131 void DivergencePropagator::exploreSyncDependency(
TerminatorInst *TI) {
144 if (!DT.isReachableFromEntry(ThisBB))
154 if (IPostDom ==
nullptr)
157 for (
auto I = IPostDom->
begin(); isa<PHINode>(
I); ++
I) {
160 if (!cast<PHINode>(
I)->hasConstantOrUndefValue() && DV.insert(&*
I).second)
161 Worklist.push_back(&*
I);
184 computeInfluenceRegion(ThisBB, IPostDom, InfluenceRegion);
190 while (InfluenceRegion.
count(InfluencedBB)) {
191 for (
auto &
I : *InfluencedBB)
192 findUsersOutsideInfluenceRegion(
I, InfluenceRegion);
194 if (IDomNode ==
nullptr)
196 InfluencedBB = IDomNode->
getBlock();
200 void DivergencePropagator::findUsersOutsideInfluenceRegion(
205 if (DV.insert(UserInst).second)
206 Worklist.push_back(UserInst);
216 std::vector<BasicBlock *> &InfluenceStack) {
218 if (Succ != End && InfluenceRegion.
insert(Succ).second)
219 InfluenceStack.push_back(Succ);
223 void DivergencePropagator::computeInfluenceRegion(
226 assert(PDT.properlyDominates(End, Start) &&
227 "End does not properly dominate Start");
232 std::vector<BasicBlock *> InfluenceStack;
233 addSuccessorsToInfluenceRegion(Start, End, InfluenceRegion, InfluenceStack);
234 while (!InfluenceStack.empty()) {
236 InfluenceStack.pop_back();
237 addSuccessorsToInfluenceRegion(BB, End, InfluenceRegion, InfluenceStack);
241 void DivergencePropagator::exploreDataDependency(
Value *V) {
245 if (!TTI.isAlwaysUniform(U) && DV.insert(UserInst).second)
246 Worklist.push_back(UserInst);
252 while (!Worklist.empty()) {
253 Value *V = Worklist.back();
259 exploreSyncDependency(TI);
261 exploreDataDependency(V);
287 auto *TTIWP = getAnalysisIfAvailable<TargetTransformInfoWrapperPass>();
288 if (TTIWP ==
nullptr)
297 DivergentValues.clear();
298 auto &PDT = getAnalysis<PostDominatorTreeWrapperPass>().getPostDomTree();
299 DivergencePropagator DP(F, TTI,
300 getAnalysis<DominatorTreeWrapperPass>().getDomTree(),
301 PDT, DivergentValues);
302 DP.populateWithSourcesOfDivergence();
305 dbgs() <<
"\nAfter divergence analysis on " << F.
getName() <<
":\n";
312 if (DivergentValues.empty())
314 const Value *FirstDivergentValue = *DivergentValues.begin();
316 if (
const Argument *
Arg = dyn_cast<Argument>(FirstDivergentValue)) {
317 F =
Arg->getParent();
319 dyn_cast<Instruction>(FirstDivergentValue)) {
320 F =
I->getParent()->getParent();
327 OS << (DivergentValues.count(&
Arg) ?
"DIVERGENT: " :
" ");
331 for (
auto BI = F->
begin(), BE = F->
end(); BI != BE; ++BI) {
333 OS <<
"\n " << BB.getName() <<
":\n";
334 for (
auto &
I : BB.instructionsWithoutDebug()) {
335 OS << (DivergentValues.count(&
I) ?
"DIVERGENT: " :
" ");
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - This function should be overriden by passes that need analysis information to do t...
This class represents an incoming formal argument to a Function.
Compute iterated dominance frontiers using a linear time algorithm.
A Module instance is used to store all the information related to an LLVM module. ...
bool runOnFunction(Function &F) override
runOnFunction - Virtual method overriden by subclasses to do the per-function processing of the pass...
block Block Frequency true
iterator begin()
Instruction iterator methods.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
FunctionPass * createDivergenceAnalysisPass()
Concrete subclass of DominatorTreeBase that is used to compute a normal dominator tree...
Subclasses of this class are all able to terminate a basic block.
LLVM Basic Block Representation.
void print(raw_ostream &OS, const Module *) const override
print - Print out the internal state of the pass.
DomTreeNodeBase * getIDom() const
std::pair< iterator, bool > insert(const ValueT &V)
Represent the analysis usage information of a pass.
const Instruction & back() const
FunctionPass class - This class is used to implement most global optimizations.
static void print(raw_ostream &Out, object::Archive::Kind Kind, T Val)
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static char ID
end namespace anonymous
void setPreservesAll()
Set by analyses that do not transform their input at all.
iterator_range< user_iterator > users()
PostDominatorTree Class - Concrete subclass of DominatorTree that is used to compute the post-dominat...
static void propagate(InstantiatedValue From, InstantiatedValue To, MatchState State, ReachabilitySet &ReachSet, std::vector< WorkListItem > &WorkList)
amdgpu Simplify well known AMD library false Value Value * Arg
StringRef getName() const
Return a constant reference to the value's name.
size_type count(const_arg_type_t< ValueT > V) const
Return 1 if the specified key is in the set, 0 otherwise.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
succ_range successors(BasicBlock *BB)
This class implements an extremely fast bulk output stream that can only output to a stream...
inst_range instructions(Function *F)
Legacy analysis pass which computes a DominatorTree.
INITIALIZE_PASS_BEGIN(DivergenceAnalysis, "divergence", "Divergence Analysis", false, true) INITIALIZE_PASS_END(DivergenceAnalysis
iterator_range< arg_iterator > args()
const BasicBlock * getParent() const