LLVM 24.0.0git
MipsCodeGenPassBuilder.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 "Mips.h"
10#include "MipsAsmPrinter.h"
11#include "MipsTargetMachine.h"
19
20using namespace llvm;
21
22namespace {
23
24class MipsCodeGenPassBuilder : public CodeGenPassBuilder {
25 using Base = CodeGenPassBuilder;
26
27 MipsTargetMachine &getTM() const {
28 return static_cast<MipsTargetMachine &>(TM);
29 }
30
31public:
32 explicit MipsCodeGenPassBuilder(MipsTargetMachine &TM,
33 const CGPassBuilderOption &Opts,
34 PassInstrumentationCallbacks *PIC)
35 : CodeGenPassBuilder(TM, Opts, PIC) {}
36
37protected:
38 void addIRPasses(PassManagerWrapper &PMW) override;
39
40 Error addInstSelector(PassManagerWrapper &PMW) override;
41
42 Error addIRTranslator(PassManagerWrapper &PMW) override;
43 void addPreLegalizeMachineIR(PassManagerWrapper &PMW) override;
44 Error addLegalizeMachineIR(PassManagerWrapper &PMW) override;
45 void addPreRegBankSelect(PassManagerWrapper &PMW) override;
46 Error addRegBankSelect(PassManagerWrapper &PMW) override;
47 Error addGlobalInstructionSelect(PassManagerWrapper &PMW) override;
48
49 void addPreRegAlloc(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
56} // namespace
57
58void MipsCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
59 Base::addIRPasses(PMW);
60 addFunctionPass(AtomicExpandPass(getTM()), PMW);
61 flushFPMsToMPM(PMW);
62 if (getTM().getCLOpts().os16) {
63 addModulePass(MipsOs16Pass(), PMW);
64 }
65 addModulePass(Mips16HardFloatPass(getTM()), PMW);
66}
67
68Error MipsCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) {
69 addMachineFunctionPass(Mips16ISelDAGPass(getTM(), getOptLevel()), PMW);
70 addMachineFunctionPass(MipsSEISelDAGPass(getTM(), getOptLevel()), PMW);
71 return Error::success();
72}
73
74Error MipsCodeGenPassBuilder::addIRTranslator(PassManagerWrapper &PMW) {
75 addMachineFunctionPass(IRTranslatorPass(getOptLevel()), PMW);
76 return Error::success();
77}
78
79void MipsCodeGenPassBuilder::addPreLegalizeMachineIR(PassManagerWrapper &PMW) {
80 addMachineFunctionPass(MipsPreLegalizerCombinerPass(), PMW);
81}
82
83Error MipsCodeGenPassBuilder::addLegalizeMachineIR(PassManagerWrapper &PMW) {
84 addMachineFunctionPass(LegalizerPass(), PMW);
85 return Error::success();
86}
87
88void MipsCodeGenPassBuilder::addPreRegBankSelect(PassManagerWrapper &PMW) {
89 bool IsOptNone = getOptLevel() == CodeGenOptLevel::None;
90 addMachineFunctionPass(MipsPostLegalizerCombinerPass(IsOptNone), PMW);
91}
92
93Error MipsCodeGenPassBuilder::addRegBankSelect(PassManagerWrapper &PMW) {
94 addMachineFunctionPass(RegBankSelectPass(), PMW);
95 return Error::success();
96}
97
98Error MipsCodeGenPassBuilder::addGlobalInstructionSelect(
99 PassManagerWrapper &PMW) {
100 addMachineFunctionPass(InstructionSelectPass(getOptLevel()), PMW);
101 return Error::success();
102}
103
104void MipsCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) {
105 addMachineFunctionPass(MipsOptimizePICCallPass(), PMW);
106}
107
108void MipsCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) {
109 // Expand pseudo instructions that are sensitive to register allocation.
110 addMachineFunctionPass(MipsExpandPseudoPass(), PMW);
111
112 // The microMIPS size reduction pass performs instruction reselection for
113 // instructions which can be remapped to a 16 bit instruction.
114 addMachineFunctionPass(MicroMipsSizeReducePass(), PMW);
115
116 // This pass inserts a nop instruction between two back-to-back multiplication
117 // instructions when the "mfix4300" flag is passed.
118 if (getTM().getCLOpts().mfix4300)
119 addMachineFunctionPass(MipsMulMulBugFixPass(), PMW);
120
121 // The delay slot filler pass can potientially create forbidden slot hazards
122 // for MIPSR6 and therefore it should go before MipsBranchExpansion pass.
123 addMachineFunctionPass(MipsDelaySlotFillerPass(), PMW);
124
125 // This pass expands branches and takes care about the forbidden slot hazards.
126 // Expanding branches may potentially create forbidden slot hazards for
127 // MIPSR6, and fixing such hazard may potentially break a branch by extending
128 // its offset out of range. That's why this pass combine these two tasks, and
129 // runs them alternately until one of them finishes without any changes. Only
130 // then we can be sure that all branches are expanded properly and no hazards
131 // exists.
132 // Any new pass should go before this pass.
133 addMachineFunctionPass(MipsBranchExpansionPass(), PMW);
134
135 addMachineFunctionPass(MipsConstantIslandPass(), PMW);
136}
137
138void MipsCodeGenPassBuilder::addAsmPrinterBegin(PassManagerWrapper &PMW) {
139 addModulePass(MipsAsmPrinterBeginPass(), PMW, /*Force=*/true);
140}
141
142void MipsCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) {
143 addMachineFunctionPass(MipsAsmPrinterPass(), PMW);
144}
145
146void MipsCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) {
147 addModulePass(MipsAsmPrinterEndPass(), PMW, /*Force=*/true);
148}
149
151#define GET_PASS_REGISTRY "MipsPassRegistry.def"
153}
154
157 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
158 const CGPassBuilderOption &Opt, MCContext &Ctx,
160 auto CGPB = MipsCodeGenPassBuilder(*this, Opt, PIC);
161 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
162}
Interfaces for producing common pass manager configurations.
This file declares the IRTranslator pass.
ModuleAnalysisManager MAM
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
PassInstrumentationCallbacks PIC
This file describes the interface of the MachineFunctionPass responsible for assigning the generic vi...
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
void registerPassBuilderCallbacks(PassBuilder &PB) override
Allow the target to modify the pass pipeline.
Error buildCodeGenPipeline(ModulePassManager &MPM, ModuleAnalysisManager &MAM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut, CodeGenFileType FileType, const CGPassBuilderOption &Opt, MCContext &Ctx, PassInstrumentationCallbacks *PIC) override
This class provides access to building LLVM's passes.
This class manages callbacks registration, as well as provides a way for PassInstrumentation to pass ...
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