LLVM 24.0.0git
SystemZCodeGenPassBuilder.cpp
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "SystemZ.h"
10#include "SystemZAsmPrinter.h"
23
24using namespace llvm;
25
27
28namespace {
29
30class SystemZCodeGenPassBuilder : public CodeGenPassBuilder {
31 using Base = CodeGenPassBuilder;
32
33 SystemZTargetMachine &getTM() const {
34 return static_cast<SystemZTargetMachine &>(TM);
35 }
36
37public:
38 explicit SystemZCodeGenPassBuilder(SystemZTargetMachine &TM,
39 const CGPassBuilderOption &Opts,
40 PassInstrumentationCallbacks *PIC)
41 : CodeGenPassBuilder(TM, Opts, PIC) {}
42
43 void addIRPasses(PassManagerWrapper &PMW) override;
44 Error addInstSelector(PassManagerWrapper &PMW) override;
45 void addILPOpts(PassManagerWrapper &PMW) override;
46 void addPreRegAlloc(PassManagerWrapper &PMW) override;
47 void addPostRewrite(PassManagerWrapper &PMW) override;
48 void addPostRegAlloc(PassManagerWrapper &PMW) override;
49 void addPreSched2(PassManagerWrapper &PMW) override;
50 void addPreEmitPass(PassManagerWrapper &PMW) override;
51 void addAsmPrinterBegin(PassManagerWrapper &PMW) override;
52 void addAsmPrinter(PassManagerWrapper &PMW) override;
53 void addAsmPrinterEnd(PassManagerWrapper &PMW) override;
54};
55
56void SystemZCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
57 if (getOptLevel() != CodeGenOptLevel::None) {
58 flushFPMsToMPM(PMW);
59 addModulePass(SystemZAlignGlobalsPass(), PMW);
60 addFunctionPass(SystemZTDCPass(getTM()), PMW);
61 addFunctionPass(LoopDataPrefetchPass(), PMW);
62 }
63
64 addFunctionPass(AtomicExpandPass(getTM()), PMW);
65
66 Base::addIRPasses(PMW);
67}
68
69Error SystemZCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) {
70 addMachineFunctionPass(SystemZISelDAGToDAGPass(getTM(), getOptLevel()), PMW);
71
72 if (getOptLevel() != CodeGenOptLevel::None)
73 addMachineFunctionPass(SystemZLDCleanupPass(), PMW);
74
75 return Error::success();
76}
77
78void SystemZCodeGenPassBuilder::addILPOpts(PassManagerWrapper &PMW) {
79 addMachineFunctionPass(EarlyIfConverterPass(), PMW);
80
82 addMachineFunctionPass(MachineCombinerPass(), PMW);
83}
84
85void SystemZCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) {
86 addMachineFunctionPass(SystemZCopyPhysRegsPass(), PMW);
87}
88
89void SystemZCodeGenPassBuilder::addPostRewrite(PassManagerWrapper &PMW) {
90 addMachineFunctionPass(SystemZPostRewritePass(), PMW);
91}
92
93void SystemZCodeGenPassBuilder::addPostRegAlloc(PassManagerWrapper &PMW) {
94 // PostRewrite needs to be run at -O0 also (in which case addPostRewrite()
95 // is not called).
96 if (getOptLevel() == CodeGenOptLevel::None)
97 addMachineFunctionPass(SystemZPostRewritePass(), PMW);
98}
99
100void SystemZCodeGenPassBuilder::addPreSched2(PassManagerWrapper &PMW) {
101 if (getOptLevel() != CodeGenOptLevel::None)
102 addMachineFunctionPass(IfConverterPass(), PMW);
103}
104
105void SystemZCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) {
106 // Do instruction shortening before compare elimination because some
107 // vector instructions will be shortened into opcodes that compare
108 // elimination recognizes.
109 if (getOptLevel() != CodeGenOptLevel::None)
110 addMachineFunctionPass(SystemZShortenInstPass(), PMW);
111
112 // We eliminate comparisons here rather than earlier because some
113 // transformations can change the set of available CC values and we
114 // generally want those transformations to have priority. This is
115 // especially true in the commonest case where the result of the comparison
116 // is used by a single in-range branch instruction, since we will then
117 // be able to fuse the compare and the branch instead.
118 //
119 // For example, two-address NILF can sometimes be converted into
120 // three-address RISBLG. NILF produces a CC value that indicates whether
121 // the low word is zero, but RISBLG does not modify CC at all. On the
122 // other hand, 64-bit ANDs like NILL can sometimes be converted to RISBG.
123 // The CC value produced by NILL isn't useful for our purposes, but the
124 // value produced by RISBG can be used for any comparison with zero
125 // (not just equality). So there are some transformations that lose
126 // CC values (while still being worthwhile) and others that happen to make
127 // the CC result more useful than it was originally.
128 //
129 // Another reason is that we only want to use BRANCH ON COUNT in cases
130 // where we know that the count register is not going to be spilled.
131 //
132 // Doing it so late makes it more likely that a register will be reused
133 // between the comparison and the branch, but it isn't clear whether
134 // preventing that would be a win or not.
135 if (getOptLevel() != CodeGenOptLevel::None)
136 addMachineFunctionPass(SystemZElimComparePass(), PMW);
137 addMachineFunctionPass(SystemZLongBranchPass(), PMW);
138
139 // Do final scheduling after all other optimizations, to get an
140 // optimal input for the decoder (branch relaxation must happen
141 // after block placement).
142 if (getOptLevel() != CodeGenOptLevel::None)
143 addMachineFunctionPass(PostMachineSchedulerPass(&getTM()), PMW);
144}
145
146void SystemZCodeGenPassBuilder::addAsmPrinterBegin(PassManagerWrapper &PMW) {
147 addModulePass(SystemZAsmPrinterBeginPass(), PMW, /*Force=*/true);
148}
149
150void SystemZCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) {
151 addMachineFunctionPass(SystemZAsmPrinterPass(), PMW);
152}
153
154void SystemZCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) {
155 addModulePass(SystemZAsmPrinterEndPass(), PMW, /*Force=*/true);
156}
157
158} // namespace
159
161#define GET_PASS_REGISTRY "SystemZPassRegistry.def"
163}
164
167 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
168 const CGPassBuilderOption &Opt, MCContext &Ctx,
170 auto CGPB = SystemZCodeGenPassBuilder(*this, Opt, PIC);
171 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
172}
Interfaces for producing common pass manager configurations.
This file provides the interface for LLVM's Loop Data Prefetching Pass.
static cl::opt< bool > EnableMachineCombinerPass("ppc-machine-combiner", cl::desc("Enable the machine combiner pass"), cl::init(true), cl::Hidden)
ModuleAnalysisManager MAM
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
PassInstrumentationCallbacks PIC
This file defines the Pass Instrumentation classes that provide instrumentation points into the pass ...
const GCNTargetMachine & getTM(const GCNSubtarget *STI)
This class provides access to building LLVM's passes.
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
Context object for machine code objects.
Definition MCContext.h:83
This class provides access to building LLVM's passes.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, const CGPassBuilderOption &Opt, MCContext &Ctx, PassInstrumentationCallbacks *PIC) override
void registerPassBuilderCallbacks(PassBuilder &PB) override
Allow the target to modify the pass pipeline.
An abstract base class for streams implementations that also support a pwrite operation.
Interfaces for registering analysis passes, producing common pass manager configurations,...
This is an optimization pass for GlobalISel generic memory operations.
CodeGenFileType
These enums are meant to be passed into addPassesToEmitFile to indicate what type of file to emit,...
Definition CodeGen.h:309
PassManager< Module > ModulePassManager
Convenience typedef for a pass manager over modules.
AnalysisManager< Module > ModuleAnalysisManager
Convenience typedef for the Module analysis manager.
Definition MIRParser.h:39