9
9
#include " AMDGPUCodeGenPassBuilder.h"
10
10
#include " AMDGPU.h"
11
11
#include " AMDGPUISelDAGToDAG.h"
12
+ #include " AMDGPUPerfHintAnalysis.h"
12
13
#include " AMDGPUTargetMachine.h"
14
+ #include " AMDGPUUnifyDivergentExitNodes.h"
13
15
#include " SIFixSGPRCopies.h"
14
16
#include " llvm/Analysis/UniformityAnalysis.h"
17
+ #include " llvm/Transforms/Scalar/FlattenCFG.h"
18
+ #include " llvm/Transforms/Scalar/Sink.h"
19
+ #include " llvm/Transforms/Scalar/StructurizeCFG.h"
20
+ #include " llvm/Transforms/Utils/FixIrreducible.h"
21
+ #include " llvm/Transforms/Utils/LCSSA.h"
22
+ #include " llvm/Transforms/Utils/UnifyLoopExits.h"
15
23
16
24
using namespace llvm ;
17
25
@@ -28,8 +36,51 @@ AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder(
28
36
}
29
37
30
38
void AMDGPUCodeGenPassBuilder::addPreISel (AddIRPass &addPass) const {
31
- // TODO: Add passes pre instruction selection.
32
- // Test only, convert to real IR passes in future.
39
+ const bool LateCFGStructurize = AMDGPUTargetMachine::EnableLateStructurizeCFG;
40
+ const bool DisableStructurizer = AMDGPUTargetMachine::DisableStructurizer;
41
+ const bool EnableStructurizerWorkarounds =
42
+ AMDGPUTargetMachine::EnableStructurizerWorkarounds;
43
+
44
+ if (TM.getOptLevel () > CodeGenOptLevel::None)
45
+ addPass (FlattenCFGPass ());
46
+
47
+ if (TM.getOptLevel () > CodeGenOptLevel::None)
48
+ addPass (SinkingPass ());
49
+
50
+ addPass (AMDGPULateCodeGenPreparePass (TM));
51
+
52
+ // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit
53
+ // regions formed by them.
54
+
55
+ addPass (AMDGPUUnifyDivergentExitNodesPass ());
56
+
57
+ if (!LateCFGStructurize && !DisableStructurizer) {
58
+ if (EnableStructurizerWorkarounds) {
59
+ addPass (FixIrreduciblePass ());
60
+ addPass (UnifyLoopExitsPass ());
61
+ }
62
+
63
+ addPass (StructurizeCFGPass (/* SkipUniformRegions=*/ false ));
64
+ }
65
+
66
+ addPass (AMDGPUAnnotateUniformValuesPass ());
67
+
68
+ if (!LateCFGStructurize && !DisableStructurizer) {
69
+ addPass (SIAnnotateControlFlowPass (TM));
70
+
71
+ // TODO: Move this right after structurizeCFG to avoid extra divergence
72
+ // analysis. This depends on stopping SIAnnotateControlFlow from making
73
+ // control flow modifications.
74
+ addPass (AMDGPURewriteUndefForPHIPass ());
75
+ }
76
+
77
+ addPass (LCSSAPass ());
78
+
79
+ if (TM.getOptLevel () > CodeGenOptLevel::Less)
80
+ addPass (AMDGPUPerfHintAnalysisPass (TM));
81
+
82
+ // FIXME: Why isn't this queried as required from AMDGPUISelDAGToDAG, and why
83
+ // isn't this in addInstSelector?
33
84
addPass (RequireAnalysisPass<UniformityInfoAnalysis, Function>());
34
85
}
35
86
0 commit comments