|
7 | 7 | //===----------------------------------------------------------------------===//
|
8 | 8 | //
|
9 | 9 | /// \file
|
10 |
| -/// The AMDGPU target machine contains all of the hardware specific |
11 |
| -/// information needed to emit code for SI+ GPUs. |
| 10 | +/// This file contains both AMDGPU target machine and the CodeGen pass builder. |
| 11 | +/// The AMDGPU target machine contains all of the hardware specific information |
| 12 | +/// needed to emit code for SI+ GPUs in the legacy pass manager pipeline. The |
| 13 | +/// CodeGen pass builder handles the pass pipeline for new pass manager. |
12 | 14 | //
|
13 | 15 | //===----------------------------------------------------------------------===//
|
14 | 16 |
|
15 | 17 | #include "AMDGPUTargetMachine.h"
|
16 | 18 | #include "AMDGPU.h"
|
17 | 19 | #include "AMDGPUAliasAnalysis.h"
|
18 |
| -#include "AMDGPUCodeGenPassBuilder.h" |
19 | 20 | #include "AMDGPUCtorDtorLowering.h"
|
20 | 21 | #include "AMDGPUExportClustering.h"
|
21 | 22 | #include "AMDGPUIGroupLP.h"
|
|
40 | 41 | #include "Utils/AMDGPUBaseInfo.h"
|
41 | 42 | #include "llvm/Analysis/CGSCCPassManager.h"
|
42 | 43 | #include "llvm/Analysis/CallGraphSCCPass.h"
|
| 44 | +#include "llvm/Analysis/UniformityAnalysis.h" |
43 | 45 | #include "llvm/CodeGen/GlobalISel/CSEInfo.h"
|
44 | 46 | #include "llvm/CodeGen/GlobalISel/IRTranslator.h"
|
45 | 47 | #include "llvm/CodeGen/GlobalISel/InstructionSelect.h"
|
|
64 | 66 | #include "llvm/Transforms/IPO/GlobalDCE.h"
|
65 | 67 | #include "llvm/Transforms/IPO/Internalize.h"
|
66 | 68 | #include "llvm/Transforms/Scalar.h"
|
| 69 | +#include "llvm/Transforms/Scalar/FlattenCFG.h" |
67 | 70 | #include "llvm/Transforms/Scalar/GVN.h"
|
68 | 71 | #include "llvm/Transforms/Scalar/InferAddressSpaces.h"
|
| 72 | +#include "llvm/Transforms/Scalar/Sink.h" |
| 73 | +#include "llvm/Transforms/Scalar/StructurizeCFG.h" |
69 | 74 | #include "llvm/Transforms/Utils.h"
|
| 75 | +#include "llvm/Transforms/Utils/FixIrreducible.h" |
| 76 | +#include "llvm/Transforms/Utils/LCSSA.h" |
70 | 77 | #include "llvm/Transforms/Utils/SimplifyLibCalls.h"
|
| 78 | +#include "llvm/Transforms/Utils/UnifyLoopExits.h" |
71 | 79 | #include "llvm/Transforms/Vectorize/LoadStoreVectorizer.h"
|
72 | 80 | #include <optional>
|
73 | 81 |
|
@@ -930,7 +938,7 @@ Error GCNTargetMachine::buildCodeGenPipeline(
|
930 | 938 | }
|
931 | 939 |
|
932 | 940 | //===----------------------------------------------------------------------===//
|
933 |
| -// AMDGPU Pass Setup |
| 941 | +// AMDGPU Legacy Pass Setup |
934 | 942 | //===----------------------------------------------------------------------===//
|
935 | 943 |
|
936 | 944 | std::unique_ptr<CSEConfigBase> llvm::AMDGPUPassConfig::getCSEConfig() const {
|
@@ -1214,7 +1222,7 @@ MachineFunctionInfo *R600TargetMachine::createMachineFunctionInfo(
|
1214 | 1222 | }
|
1215 | 1223 |
|
1216 | 1224 | //===----------------------------------------------------------------------===//
|
1217 |
| -// GCN Pass Setup |
| 1225 | +// GCN Legacy Pass Setup |
1218 | 1226 | //===----------------------------------------------------------------------===//
|
1219 | 1227 |
|
1220 | 1228 | ScheduleDAGInstrs *GCNPassConfig::createMachineScheduler(
|
@@ -1751,3 +1759,80 @@ bool GCNTargetMachine::parseMachineFunctionInfo(
|
1751 | 1759 |
|
1752 | 1760 | return false;
|
1753 | 1761 | }
|
| 1762 | + |
| 1763 | +//===----------------------------------------------------------------------===// |
| 1764 | +// AMDGPU CodeGen Pass Builder interface. |
| 1765 | +//===----------------------------------------------------------------------===// |
| 1766 | + |
| 1767 | +AMDGPUCodeGenPassBuilder::AMDGPUCodeGenPassBuilder( |
| 1768 | + GCNTargetMachine &TM, const CGPassBuilderOption &Opts, |
| 1769 | + PassInstrumentationCallbacks *PIC) |
| 1770 | + : CodeGenPassBuilder(TM, Opts, PIC) { |
| 1771 | + Opt.RequiresCodeGenSCCOrder = true; |
| 1772 | + // Exceptions and StackMaps are not supported, so these passes will never do |
| 1773 | + // anything. |
| 1774 | + // Garbage collection is not supported. |
| 1775 | + disablePass<StackMapLivenessPass, FuncletLayoutPass, |
| 1776 | + ShadowStackGCLoweringPass>(); |
| 1777 | +} |
| 1778 | + |
| 1779 | +void AMDGPUCodeGenPassBuilder::addPreISel(AddIRPass &addPass) const { |
| 1780 | + const bool LateCFGStructurize = AMDGPUTargetMachine::EnableLateStructurizeCFG; |
| 1781 | + const bool DisableStructurizer = AMDGPUTargetMachine::DisableStructurizer; |
| 1782 | + const bool EnableStructurizerWorkarounds = |
| 1783 | + AMDGPUTargetMachine::EnableStructurizerWorkarounds; |
| 1784 | + |
| 1785 | + if (TM.getOptLevel() > CodeGenOptLevel::None) |
| 1786 | + addPass(FlattenCFGPass()); |
| 1787 | + |
| 1788 | + if (TM.getOptLevel() > CodeGenOptLevel::None) |
| 1789 | + addPass(SinkingPass()); |
| 1790 | + |
| 1791 | + addPass(AMDGPULateCodeGenPreparePass(TM)); |
| 1792 | + |
| 1793 | + // Merge divergent exit nodes. StructurizeCFG won't recognize the multi-exit |
| 1794 | + // regions formed by them. |
| 1795 | + |
| 1796 | + addPass(AMDGPUUnifyDivergentExitNodesPass()); |
| 1797 | + |
| 1798 | + if (!LateCFGStructurize && !DisableStructurizer) { |
| 1799 | + if (EnableStructurizerWorkarounds) { |
| 1800 | + addPass(FixIrreduciblePass()); |
| 1801 | + addPass(UnifyLoopExitsPass()); |
| 1802 | + } |
| 1803 | + |
| 1804 | + addPass(StructurizeCFGPass(/*SkipUniformRegions=*/false)); |
| 1805 | + } |
| 1806 | + |
| 1807 | + addPass(AMDGPUAnnotateUniformValuesPass()); |
| 1808 | + |
| 1809 | + if (!LateCFGStructurize && !DisableStructurizer) { |
| 1810 | + addPass(SIAnnotateControlFlowPass(TM)); |
| 1811 | + |
| 1812 | + // TODO: Move this right after structurizeCFG to avoid extra divergence |
| 1813 | + // analysis. This depends on stopping SIAnnotateControlFlow from making |
| 1814 | + // control flow modifications. |
| 1815 | + addPass(AMDGPURewriteUndefForPHIPass()); |
| 1816 | + } |
| 1817 | + |
| 1818 | + addPass(LCSSAPass()); |
| 1819 | + |
| 1820 | + if (TM.getOptLevel() > CodeGenOptLevel::Less) |
| 1821 | + addPass(AMDGPUPerfHintAnalysisPass(TM)); |
| 1822 | + |
| 1823 | + // FIXME: Why isn't this queried as required from AMDGPUISelDAGToDAG, and why |
| 1824 | + // isn't this in addInstSelector? |
| 1825 | + addPass(RequireAnalysisPass<UniformityInfoAnalysis, Function>()); |
| 1826 | +} |
| 1827 | + |
| 1828 | +void AMDGPUCodeGenPassBuilder::addAsmPrinter(AddMachinePass &addPass, |
| 1829 | + CreateMCStreamer) const { |
| 1830 | + // TODO: Add AsmPrinter. |
| 1831 | +} |
| 1832 | + |
| 1833 | +Error AMDGPUCodeGenPassBuilder::addInstSelector(AddMachinePass &addPass) const { |
| 1834 | + addPass(AMDGPUISelDAGToDAGPass(TM)); |
| 1835 | + addPass(SIFixSGPRCopiesPass()); |
| 1836 | + addPass(SILowerI1CopiesPass()); |
| 1837 | + return Error::success(); |
| 1838 | +} |
0 commit comments