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 "MipsTargetMachine.h"
14
15using namespace llvm;
16
17namespace {
18
19class MipsCodeGenPassBuilder : public CodeGenPassBuilder {
20 using Base = CodeGenPassBuilder;
21
22 MipsTargetMachine &getTM() const {
23 return static_cast<MipsTargetMachine &>(TM);
24 }
25
26public:
27 explicit MipsCodeGenPassBuilder(MipsTargetMachine &TM,
28 const CGPassBuilderOption &Opts,
29 PassInstrumentationCallbacks *PIC)
30 : CodeGenPassBuilder(TM, Opts, PIC) {}
31
32 void addIRPasses(PassManagerWrapper &PMW) override;
33 Error addInstSelector(PassManagerWrapper &PMW) override;
34 void addPreRegAlloc(PassManagerWrapper &PMW) override;
35 void addPreEmitPass(PassManagerWrapper &PMW) override;
36 void addAsmPrinterBegin(PassManagerWrapper &PMW) override;
37 void addAsmPrinter(PassManagerWrapper &PMW) override;
38 void addAsmPrinterEnd(PassManagerWrapper &PMW) override;
39};
40
41} // namespace
42
43void MipsCodeGenPassBuilder::addIRPasses(PassManagerWrapper &PMW) {
44 Base::addIRPasses(PMW);
45 addFunctionPass(AtomicExpandPass(getTM()), PMW);
46 flushFPMsToMPM(PMW);
47 if (getTM().getCLOpts().os16) {
48 addModulePass(MipsOs16Pass(), PMW);
49 }
50 addModulePass(Mips16HardFloatPass(getTM()), PMW);
51}
52
53Error MipsCodeGenPassBuilder::addInstSelector(PassManagerWrapper &PMW) {
54 addMachineFunctionPass(Mips16ISelDAGPass(getTM(), getOptLevel()), PMW);
55 addMachineFunctionPass(MipsSEISelDAGPass(getTM(), getOptLevel()), PMW);
56 return Error::success();
57}
58
59void MipsCodeGenPassBuilder::addPreRegAlloc(PassManagerWrapper &PMW) {
60 addMachineFunctionPass(MipsOptimizePICCallPass(), PMW);
61}
62
63void MipsCodeGenPassBuilder::addPreEmitPass(PassManagerWrapper &PMW) {
64 // Expand pseudo instructions that are sensitive to register allocation.
65 addMachineFunctionPass(MipsExpandPseudoPass(), PMW);
66
67 // The microMIPS size reduction pass performs instruction reselection for
68 // instructions which can be remapped to a 16 bit instruction.
69 addMachineFunctionPass(MicroMipsSizeReducePass(), PMW);
70
71 // This pass inserts a nop instruction between two back-to-back multiplication
72 // instructions when the "mfix4300" flag is passed.
73 if (getTM().getCLOpts().mfix4300)
74 addMachineFunctionPass(MipsMulMulBugFixPass(), PMW);
75
76 // The delay slot filler pass can potientially create forbidden slot hazards
77 // for MIPSR6 and therefore it should go before MipsBranchExpansion pass.
78 // TODO(boomanaiden154): Add MipsDelaySlotFillerPass
79
80 // This pass expands branches and takes care about the forbidden slot hazards.
81 // Expanding branches may potentially create forbidden slot hazards for
82 // MIPSR6, and fixing such hazard may potentially break a branch by extending
83 // its offset out of range. That's why this pass combine these two tasks, and
84 // runs them alternately until one of them finishes without any changes. Only
85 // then we can be sure that all branches are expanded properly and no hazards
86 // exists.
87 // Any new pass should go before this pass.
88 // TODO(boomanaiden154): AddMipsBranchExpansionPass
89
90 // TODO(boomanaiden154): Add MipsConstantIslandPass
91}
92
93void MipsCodeGenPassBuilder::addAsmPrinterBegin(PassManagerWrapper &PMW) {
94 // TODO(boomanaiden154): Add MipsAsmPrinterBeginPass
95}
96
97void MipsCodeGenPassBuilder::addAsmPrinter(PassManagerWrapper &PMW) {
98 // TODO(boomanaiden154): Add MipsAsmPrinterPass
99}
100
101void MipsCodeGenPassBuilder::addAsmPrinterEnd(PassManagerWrapper &PMW) {
102 // TODO(boomanaiden154): Add MipsAsmPrinterEndPass
103}
104
106#define GET_PASS_REGISTRY "MipsPassRegistry.def"
108}
109
112 raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
113 const CGPassBuilderOption &Opt, MCContext &Ctx,
115 auto CGPB = MipsCodeGenPassBuilder(*this, Opt, PIC);
116 return CGPB.buildPipeline(MPM, MAM, Out, DwoOut, FileType, Ctx);
117}
Interfaces for producing common pass manager configurations.
ModuleAnalysisManager MAM
PassBuilder PB(Mod->getContext(), Machine, PassOpts->PTO, std::nullopt, &PIC)
PassInstrumentationCallbacks PIC
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
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