1 //===-- AMDGPULaneDominator.cpp - Determine Lane Dominators ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // MBB A lane-dominates MBB B if
11 // 1. A dominates B in the usual sense, i.e. every path from the entry to B
12 // goes through A, and
13 // 2. whenever B executes, every active lane during that execution of B was
14 // also active during the most recent execution of A.
16 // The simplest example where A dominates B but does not lane-dominate it is
26 // Unfortunately, the second condition is not fully captured by the control
27 // flow graph when it is unstructured (as may happen when branch conditions are
30 // The following replacement of the second condition is a conservative
31 // approximation. It is an equivalent condition when the CFG is fully
34 // 2'. every cycle in the CFG that contains A also contains B.
36 //===----------------------------------------------------------------------===//
38 #include "AMDGPULaneDominator.h"
40 #include "llvm/ADT/DenseSet.h"
41 #include "llvm/ADT/SmallVector.h"
42 #include "llvm/CodeGen/MachineBasicBlock.h"
48 // Given machine basic blocks A and B where A dominates B, check whether
49 // A lane-dominates B.
51 // The check is conservative, i.e. there can be false-negatives.
52 bool laneDominates(MachineBasicBlock *A, MachineBasicBlock *B) {
53 // Check whether A is reachable from itself without going through B.
54 DenseSet<MachineBasicBlock *> Reachable;
55 SmallVector<MachineBasicBlock *, 8> Stack;
59 MachineBasicBlock *MBB = Stack.back();
62 for (MachineBasicBlock *Succ : MBB->successors()) {
65 if (Succ != B && Reachable.insert(Succ).second)
66 Stack.push_back(Succ);
68 } while (!Stack.empty());