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
26namespace {
27
28class SystemZCodeGenPassBuilder : public CodeGenPassBuilder {
29 using Base = CodeGenPassBuilder;
30
31 SystemZTargetMachine &getTM() const {
32 return static_cast<SystemZTargetMachine &>(TM);
33 }
34
35public:
36 explicit SystemZCodeGenPassBuilder(SystemZTargetMachine &TM,
37 const CGPassBuilderOption &Opts,
38 PassInstrumentationCallbacks *PIC)
39 : CodeGenPassBuilder(TM, Opts, PIC) {}
40
41protected:
42 void addIRPasses(PassManagerWrapper &PMW) override;
43 Error addInstSelector(PassManagerWrapper &PMW) override;
44 void addILPOpts(PassManagerWrapper &PMW) override;
45 void addPreRegAlloc(PassManagerWrapper &PMW) override;
46 void addPostRewrite(PassManagerWrapper &PMW) override;
47 void addPostRegAlloc(PassManagerWrapper &PMW) override;
48 void addPreSched2(PassManagerWrapper &PMW) override;
49 void addPreEmitPass(PassManagerWrapper &PMW) override;
50 void addAsmPrinterBegin(PassManagerWrapper &PMW) override;
51 void addAsmPrinter(PassManagerWrapper &PMW) override;
52 void addAsmPrinterEnd(PassManagerWrapper &PMW) override;
53};
54
55} // namespace
56
57void SystemZCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
58 if (getOptLevel() != CodeGenOptLevel::None) {
59 flushFPMsToMPM(PMW);
60 addModulePass(SystemZAlignGlobalsPass(), PMW);
61 addFunctionPass(SystemZTDCPass(getTM()), PMW);
62 addFunctionPass(LoopDataPrefetchPass(), PMW);
63 }
64
65 addFunctionPass(AtomicExpandPass(getTM()), PMW);
66
67 Base::addIRPasses(PMW);
68}
69
70Error SystemZCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) {
71 addMachineFunctionPass(SystemZISelDAGToDAGPass(getTM(), getOptLevel()), PMW);
72
73 if (getOptLevel() != CodeGenOptLevel::None)
74 addMachineFunctionPass(SystemZLDCleanupPass(), PMW);
75
76 return Error::success();
77}
78
79void SystemZCodeGenPassBuilder::addILPOpts(PassManagerWrapper &PMW) {
80 addMachineFunctionPass(EarlyIfConverterPass(), PMW);
81
82 if (getTM().getCLOpts().machine_combiner)
83 addMachineFunctionPass(MachineCombinerPass(), PMW);
84}
85
86void SystemZCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) {
87 addMachineFunctionPass(SystemZCopyPhysRegsPass(), PMW);
88}
89
90void SystemZCodeGenPassBuilder::addPostRewrite(PassManagerWrapper &PMW) {
91 addMachineFunctionPass(SystemZPostRewritePass(), PMW);
92}
93
94void SystemZCodeGenPassBuilder::addPostRegAlloc(PassManagerWrapper &PMW) {
95 // PostRewrite needs to be run at -O0 also (in which case addPostRewrite()
96 // is not called).
97 if (getOptLevel() == CodeGenOptLevel::None)
98 addMachineFunctionPass(SystemZPostRewritePass(), PMW);
99}
100
101void SystemZCodeGenPassBuilder::addPreSched2(PassManagerWrapper &PMW) {
102 if (getOptLevel() != CodeGenOptLevel::None)
103 addMachineFunctionPass(IfConverterPass(), PMW);
104}
105
106void SystemZCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) {
107 // Do instruction shortening before compare elimination because some
108 // vector instructions will be shortened into opcodes that compare
109 // elimination recognizes.
110 if (getOptLevel() != CodeGenOptLevel::None)
111 addMachineFunctionPass(SystemZShortenInstPass(), PMW);
112
113 // We eliminate comparisons here rather than earlier because some
114 // transformations can change the set of available CC values and we
115 // generally want those transformations to have priority. This is
116 // especially true in the commonest case where the result of the comparison
117 // is used by a single in-range branch instruction, since we will then
118 // be able to fuse the compare and the branch instead.
119 //
120 // For example, two-address NILF can sometimes be converted into
121 // three-address RISBLG. NILF produces a CC value that indicates whether
122 // the low word is zero, but RISBLG does not modify CC at all. On the
123 // other hand, 64-bit ANDs like NILL can sometimes be converted to RISBG.
124 // The CC value produced by NILL isn't useful for our purposes, but the
125 // value produced by RISBG can be used for any comparison with zero
126 // (not just equality). So there are some transformations that lose
127 // CC values (while still being worthwhile) and others that happen to make
128 // the CC result more useful than it was originally.
129 //
130 // Another reason is that we only want to use BRANCH ON COUNT in cases
131 // where we know that the count register is not going to be spilled.
132 //
133 // Doing it so late makes it more likely that a register will be reused
134 // between the comparison and the branch, but it isn't clear whether
135 // preventing that would be a win or not.
136 if (getOptLevel() != CodeGenOptLevel::None)
137 addMachineFunctionPass(SystemZElimComparePass(), PMW);
138 addMachineFunctionPass(SystemZLongBranchPass(), PMW);
139
140 // Do final scheduling after all other optimizations, to get an
141 // optimal input for the decoder (branch relaxation must happen
142 // after block placement).
143 if (getOptLevel() != CodeGenOptLevel::None)
144 addMachineFunctionPass(PostMachineSchedulerPass(&getTM()), PMW);
145}
146
147void SystemZCodeGenPassBuilder::addAsmPrinterBegin(PassManagerWrapper &PMW) {
148 addModulePass(SystemZAsmPrinterBeginPass(), PMW, /*Force=*/true);
149}
150
151void SystemZCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) {
152 addMachineFunctionPass(SystemZAsmPrinterPass(), PMW);
153}
154
155void SystemZCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) {
156 addModulePass(SystemZAsmPrinterEndPass(), PMW, /*Force=*/true);
157}
158
160#define GET_PASS_REGISTRY "SystemZPassRegistry.def"
162}
163
166 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
167 const CGPassBuilderOption &Opt, MCContext &Ctx,
169 auto CGPB = SystemZCodeGenPassBuilder(*this, Opt, PIC);
170 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
171}
Interfaces for producing common pass manager configurations.
This file provides the interface for LLVM's Loop Data Prefetching Pass.
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:84
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,...
const AArch64MCOptions & getCLOpts(const MCTargetOptions &Options)
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