clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name DivergenceAnalysis.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/gnu/usr.bin/clang/libLLVM/obj -resource-dir /usr/local/lib/clang/13.0.0 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/AMDGPU -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Analysis -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ASMParser -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/BinaryFormat -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitcode -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitcode -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Bitstream -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /include/llvm/CodeGen -I /include/llvm/CodeGen/PBQP -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/IR -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/IR -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Coroutines -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ProfileData/Coverage -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/CodeView -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/DWARF -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/MSF -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/PDB -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Demangle -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine/JITLink -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ExecutionEngine/Orc -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend/OpenACC -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Frontend/OpenMP -I /include/llvm/CodeGen/GlobalISel -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/IRReader -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/InstCombine -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/Transforms/InstCombine -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/LTO -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Linker -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/MC -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/MC/MCParser -I /include/llvm/CodeGen/MIRParser -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Object -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Option -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Passes -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ProfileData -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Scalar -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/ADT -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Support -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/DebugInfo/Symbolize -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Target -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Utils -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/Vectorize -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include/llvm/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Target/X86 -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include/llvm/Transforms/IPO -I /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/include -I /usr/src/gnu/usr.bin/clang/libLLVM/../include -I /usr/src/gnu/usr.bin/clang/libLLVM/obj -I /usr/src/gnu/usr.bin/clang/libLLVM/obj/../include -D NDEBUG -D __STDC_LIMIT_MACROS -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D LLVM_PREFIX="/usr" -D PIC -internal-isystem /usr/include/c++/v1 -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-comment -std=c++14 -fdeprecated-macro -fdebug-compilation-dir=/usr/src/gnu/usr.bin/clang/libLLVM/obj -ferror-limit 19 -fvisibility-inlines-hidden -fwrapv -D_RET_PROTECTOR -ret-protector -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c++ /usr/src/gnu/usr.bin/clang/libLLVM/../../../llvm/llvm/lib/Analysis/DivergenceAnalysis.cpp
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | |
56 | |
57 | |
58 | |
59 | |
60 | |
61 | |
62 | |
63 | |
64 | |
65 | |
66 | |
67 | |
68 | |
69 | |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | #include "llvm/Analysis/DivergenceAnalysis.h" |
76 | #include "llvm/Analysis/CFG.h" |
77 | #include "llvm/Analysis/LoopInfo.h" |
78 | #include "llvm/Analysis/Passes.h" |
79 | #include "llvm/Analysis/PostDominators.h" |
80 | #include "llvm/Analysis/TargetTransformInfo.h" |
81 | #include "llvm/IR/Dominators.h" |
82 | #include "llvm/IR/InstIterator.h" |
83 | #include "llvm/IR/Instructions.h" |
84 | #include "llvm/IR/IntrinsicInst.h" |
85 | #include "llvm/IR/Value.h" |
86 | #include "llvm/Support/Debug.h" |
87 | #include "llvm/Support/raw_ostream.h" |
88 | |
89 | using namespace llvm; |
90 | |
91 | #define DEBUG_TYPE "divergence" |
92 | |
93 | DivergenceAnalysisImpl::DivergenceAnalysisImpl( |
94 | const Function &F, const Loop *RegionLoop, const DominatorTree &DT, |
95 | const LoopInfo &LI, SyncDependenceAnalysis &SDA, bool IsLCSSAForm) |
96 | : F(F), RegionLoop(RegionLoop), DT(DT), LI(LI), SDA(SDA), |
97 | IsLCSSAForm(IsLCSSAForm) {} |
98 | |
99 | bool DivergenceAnalysisImpl::markDivergent(const Value &DivVal) { |
100 | if (isAlwaysUniform(DivVal)) |
101 | return false; |
102 | assert(isa<Instruction>(DivVal) || isa<Argument>(DivVal)); |
103 | assert(!isAlwaysUniform(DivVal) && "cannot be a divergent"); |
104 | return DivergentValues.insert(&DivVal).second; |
105 | } |
106 | |
107 | void DivergenceAnalysisImpl::addUniformOverride(const Value &UniVal) { |
108 | UniformOverrides.insert(&UniVal); |
109 | } |
110 | |
111 | bool DivergenceAnalysisImpl::isTemporalDivergent( |
112 | const BasicBlock &ObservingBlock, const Value &Val) const { |
113 | const auto *Inst = dyn_cast<const Instruction>(&Val); |
114 | if (!Inst) |
115 | return false; |
116 | |
117 | |
118 | for (const auto *Loop = LI.getLoopFor(Inst->getParent()); |
119 | Loop != RegionLoop && !Loop->contains(&ObservingBlock); |
120 | Loop = Loop->getParentLoop()) { |
121 | if (DivergentLoops.contains(Loop)) |
122 | return true; |
123 | } |
124 | |
125 | return false; |
126 | } |
127 | |
128 | bool DivergenceAnalysisImpl::inRegion(const Instruction &I) const { |
129 | return I.getParent() && inRegion(*I.getParent()); |
130 | } |
131 | |
132 | bool DivergenceAnalysisImpl::inRegion(const BasicBlock &BB) const { |
133 | return (!RegionLoop && BB.getParent() == &F) || RegionLoop->contains(&BB); |
| 4 | | Assuming field 'RegionLoop' is null | |
|
| 5 | | Assuming the condition is false | |
|
| 6 | | Called C++ object pointer is null |
|
134 | } |
135 | |
136 | void DivergenceAnalysisImpl::pushUsers(const Value &V) { |
137 | const auto *I = dyn_cast<const Instruction>(&V); |
138 | |
139 | if (I && I->isTerminator()) { |
140 | analyzeControlDivergence(*I); |
141 | return; |
142 | } |
143 | |
144 | for (const auto *User : V.users()) { |
145 | const auto *UserInst = dyn_cast<const Instruction>(User); |
146 | if (!UserInst) |
147 | continue; |
148 | |
149 | |
150 | if (!inRegion(*UserInst)) |
151 | continue; |
152 | |
153 | |
154 | if (markDivergent(*UserInst)) |
155 | Worklist.push_back(UserInst); |
156 | } |
157 | } |
158 | |
159 | static const Instruction *getIfCarriedInstruction(const Use &U, |
160 | const Loop &DivLoop) { |
161 | const auto *I = dyn_cast<const Instruction>(&U); |
162 | if (!I) |
163 | return nullptr; |
164 | if (!DivLoop.contains(I)) |
165 | return nullptr; |
166 | return I; |
167 | } |
168 | |
169 | void DivergenceAnalysisImpl::analyzeTemporalDivergence( |
170 | const Instruction &I, const Loop &OuterDivLoop) { |
171 | if (isAlwaysUniform(I)) |
172 | return; |
173 | if (isDivergent(I)) |
174 | return; |
175 | |
176 | LLVM_DEBUG(dbgs() << "Analyze temporal divergence: " << I.getName() << "\n"); |
177 | assert((isa<PHINode>(I) || !IsLCSSAForm) && |
178 | "In LCSSA form all users of loop-exiting defs are Phi nodes."); |
179 | for (const Use &Op : I.operands()) { |
180 | const auto *OpInst = getIfCarriedInstruction(Op, OuterDivLoop); |
181 | if (!OpInst) |
182 | continue; |
183 | if (markDivergent(I)) |
184 | pushUsers(I); |
185 | return; |
186 | } |
187 | } |
188 | |
189 | |
190 | |
191 | void DivergenceAnalysisImpl::analyzeLoopExitDivergence( |
192 | const BasicBlock &DivExit, const Loop &OuterDivLoop) { |
193 | |
194 | if (IsLCSSAForm) { |
| 1 | Assuming field 'IsLCSSAForm' is false | |
|
| |
195 | for (const auto &Phi : DivExit.phis()) { |
196 | analyzeTemporalDivergence(Phi, OuterDivLoop); |
197 | } |
198 | return; |
199 | } |
200 | |
201 | |
202 | const BasicBlock &LoopHeader = *OuterDivLoop.getHeader(); |
203 | SmallVector<const BasicBlock *, 8> TaintStack; |
204 | TaintStack.push_back(&DivExit); |
205 | |
206 | |
207 | |
208 | DenseSet<const BasicBlock *> Visited; |
209 | Visited.insert(&DivExit); |
210 | |
211 | do { |
212 | auto *UserBlock = TaintStack.pop_back_val(); |
213 | |
214 | |
215 | if (!inRegion(*UserBlock)) |
| 3 | | Calling 'DivergenceAnalysisImpl::inRegion' | |
|
216 | continue; |
217 | |
218 | assert(!OuterDivLoop.contains(UserBlock) && |
219 | "irreducible control flow detected"); |
220 | |
221 | |
222 | if (!DT.dominates(&LoopHeader, UserBlock)) { |
223 | |
224 | for (auto &Phi : UserBlock->phis()) { |
225 | analyzeTemporalDivergence(Phi, OuterDivLoop); |
226 | } |
227 | continue; |
228 | } |
229 | |
230 | |
231 | for (auto &I : *UserBlock) { |
232 | analyzeTemporalDivergence(I, OuterDivLoop); |
233 | } |
234 | |
235 | |
236 | for (auto *SuccBlock : successors(UserBlock)) { |
237 | if (!Visited.insert(SuccBlock).second) { |
238 | continue; |
239 | } |
240 | TaintStack.push_back(SuccBlock); |
241 | } |
242 | } while (!TaintStack.empty()); |
243 | } |
244 | |
245 | void DivergenceAnalysisImpl::propagateLoopExitDivergence( |
246 | const BasicBlock &DivExit, const Loop &InnerDivLoop) { |
247 | LLVM_DEBUG(dbgs() << "\tpropLoopExitDiv " << DivExit.getName() << "\n"); |
248 | |
249 | |
250 | const Loop *DivLoop = &InnerDivLoop; |
251 | const Loop *OuterDivLoop = DivLoop; |
252 | const Loop *ExitLevelLoop = LI.getLoopFor(&DivExit); |
253 | const unsigned LoopExitDepth = |
254 | ExitLevelLoop ? ExitLevelLoop->getLoopDepth() : 0; |
255 | while (DivLoop && DivLoop->getLoopDepth() > LoopExitDepth) { |
256 | DivergentLoops.insert(DivLoop); |
257 | OuterDivLoop = DivLoop; |
258 | DivLoop = DivLoop->getParentLoop(); |
259 | } |
260 | LLVM_DEBUG(dbgs() << "\tOuter-most left loop: " << OuterDivLoop->getName() |
261 | << "\n"); |
262 | |
263 | analyzeLoopExitDivergence(DivExit, *OuterDivLoop); |
264 | } |
265 | |
266 | |
267 | |
268 | void DivergenceAnalysisImpl::taintAndPushPhiNodes(const BasicBlock &JoinBlock) { |
269 | LLVM_DEBUG(dbgs() << "taintAndPushPhiNodes in " << JoinBlock.getName() |
270 | << "\n"); |
271 | |
272 | |
273 | if (!inRegion(JoinBlock)) { |
274 | return; |
275 | } |
276 | |
277 | |
278 | for (const auto &Phi : JoinBlock.phis()) { |
279 | if (isDivergent(Phi)) |
280 | continue; |
281 | |
282 | |
283 | if (Phi.hasConstantOrUndefValue()) |
284 | continue; |
285 | if (markDivergent(Phi)) |
286 | Worklist.push_back(&Phi); |
287 | } |
288 | } |
289 | |
290 | void DivergenceAnalysisImpl::analyzeControlDivergence(const Instruction &Term) { |
291 | LLVM_DEBUG(dbgs() << "analyzeControlDiv " << Term.getParent()->getName() |
292 | << "\n"); |
293 | |
294 | |
295 | if (!DT.isReachableFromEntry(Term.getParent())) |
296 | return; |
297 | |
298 | const auto *BranchLoop = LI.getLoopFor(Term.getParent()); |
299 | |
300 | const auto &DivDesc = SDA.getJoinBlocks(Term); |
301 | |
302 | |
303 | for (const auto *JoinBlock : DivDesc.JoinDivBlocks) { |
304 | taintAndPushPhiNodes(*JoinBlock); |
305 | } |
306 | |
307 | assert(DivDesc.LoopDivBlocks.empty() || BranchLoop); |
308 | for (const auto *DivExitBlock : DivDesc.LoopDivBlocks) { |
309 | propagateLoopExitDivergence(*DivExitBlock, *BranchLoop); |
310 | } |
311 | } |
312 | |
313 | void DivergenceAnalysisImpl::compute() { |
314 | |
315 | auto DivValuesCopy = DivergentValues; |
316 | for (const auto *DivVal : DivValuesCopy) { |
317 | assert(isDivergent(*DivVal) && "Worklist invariant violated!"); |
318 | pushUsers(*DivVal); |
319 | } |
320 | |
321 | |
322 | |
323 | while (!Worklist.empty()) { |
324 | const Instruction &I = *Worklist.back(); |
325 | Worklist.pop_back(); |
326 | |
327 | |
328 | assert(isDivergent(I) && "Worklist invariant violated!"); |
329 | pushUsers(I); |
330 | } |
331 | } |
332 | |
333 | bool DivergenceAnalysisImpl::isAlwaysUniform(const Value &V) const { |
334 | return UniformOverrides.contains(&V); |
335 | } |
336 | |
337 | bool DivergenceAnalysisImpl::isDivergent(const Value &V) const { |
338 | return DivergentValues.contains(&V); |
339 | } |
340 | |
341 | bool DivergenceAnalysisImpl::isDivergentUse(const Use &U) const { |
342 | Value &V = *U.get(); |
343 | Instruction &I = *cast<Instruction>(U.getUser()); |
344 | return isDivergent(V) || isTemporalDivergent(*I.getParent(), V); |
345 | } |
346 | |
347 | DivergenceInfo::DivergenceInfo(Function &F, const DominatorTree &DT, |
348 | const PostDominatorTree &PDT, const LoopInfo &LI, |
349 | const TargetTransformInfo &TTI, |
350 | bool KnownReducible) |
351 | : F(F), ContainsIrreducible(false) { |
352 | if (!KnownReducible) { |
353 | using RPOTraversal = ReversePostOrderTraversal<const Function *>; |
354 | RPOTraversal FuncRPOT(&F); |
355 | if (containsIrreducibleCFG<const BasicBlock *, const RPOTraversal, |
356 | const LoopInfo>(FuncRPOT, LI)) { |
357 | ContainsIrreducible = true; |
358 | return; |
359 | } |
360 | } |
361 | SDA = std::make_unique<SyncDependenceAnalysis>(DT, PDT, LI); |
362 | DA = std::make_unique<DivergenceAnalysisImpl>(F, nullptr, DT, LI, *SDA, |
363 | false); |
364 | for (auto &I : instructions(F)) { |
365 | if (TTI.isSourceOfDivergence(&I)) { |
366 | DA->markDivergent(I); |
367 | } else if (TTI.isAlwaysUniform(&I)) { |
368 | DA->addUniformOverride(I); |
369 | } |
370 | } |
371 | for (auto &Arg : F.args()) { |
372 | if (TTI.isSourceOfDivergence(&Arg)) { |
373 | DA->markDivergent(Arg); |
374 | } |
375 | } |
376 | |
377 | DA->compute(); |
378 | } |
379 | |
380 | AnalysisKey DivergenceAnalysis::Key; |
381 | |
382 | DivergenceAnalysis::Result |
383 | DivergenceAnalysis::run(Function &F, FunctionAnalysisManager &AM) { |
384 | auto &DT = AM.getResult<DominatorTreeAnalysis>(F); |
385 | auto &PDT = AM.getResult<PostDominatorTreeAnalysis>(F); |
386 | auto &LI = AM.getResult<LoopAnalysis>(F); |
387 | auto &TTI = AM.getResult<TargetIRAnalysis>(F); |
388 | |
389 | return DivergenceInfo(F, DT, PDT, LI, TTI, false); |
390 | } |
391 | |
392 | PreservedAnalyses |
393 | DivergenceAnalysisPrinterPass::run(Function &F, FunctionAnalysisManager &FAM) { |
394 | auto &DI = FAM.getResult<DivergenceAnalysis>(F); |
395 | OS << "'Divergence Analysis' for function '" << F.getName() << "':\n"; |
396 | if (DI.hasDivergence()) { |
397 | for (auto &Arg : F.args()) { |
398 | OS << (DI.isDivergent(Arg) ? "DIVERGENT: " : " "); |
399 | OS << Arg << "\n"; |
400 | } |
401 | for (const BasicBlock &BB : F) { |
402 | OS << "\n " << BB.getName() << ":\n"; |
403 | for (auto &I : BB.instructionsWithoutDebug()) { |
404 | OS << (DI.isDivergent(I) ? "DIVERGENT: " : " "); |
405 | OS << I << "\n"; |
406 | } |
407 | } |
408 | } |
409 | return PreservedAnalyses::all(); |
410 | } |