LLVM 24.0.0git
MipsPostLegalizerCombiner.cpp
Go to the documentation of this file.
1//=== lib/CodeGen/GlobalISel/MipsPostLegalizerCombiner.cpp ----------------===//
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// This pass does combining of machine instructions at the generic MI level,
10// after the legalizer.
11//
12//===----------------------------------------------------------------------===//
13
15#include "Mips.h"
16#include "MipsLegalizerInfo.h"
17#include "MipsSubtarget.h"
28#include "llvm/IR/Analysis.h"
30
31#define GET_GICOMBINER_DEPS
32#include "MipsGenPostLegalizeGICombiner.inc"
33#undef GET_GICOMBINER_DEPS
34
35#define DEBUG_TYPE "mips-postlegalizer-combiner"
36
37using namespace llvm;
38using namespace MIPatternMatch;
39
40namespace {
41#define GET_GICOMBINER_TYPES
42#include "MipsGenPostLegalizeGICombiner.inc"
43#undef GET_GICOMBINER_TYPES
44
45class MipsPostLegalizerCombinerImpl : public Combiner {
46protected:
47 const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig;
48 const MipsSubtarget &STI;
49 const CombinerHelper Helper;
50
51public:
52 MipsPostLegalizerCombinerImpl(
54 GISelCSEInfo *CSEInfo,
55 const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig,
56 const MipsSubtarget &STI, MachineDominatorTree *MDT,
57 const LegalizerInfo *LI);
58
59 static const char *getName() { return "MipsPostLegalizerCombiner"; }
60
61 bool tryCombineAll(MachineInstr &I) const override;
62
63private:
64#define GET_GICOMBINER_CLASS_MEMBERS
65#include "MipsGenPostLegalizeGICombiner.inc"
66#undef GET_GICOMBINER_CLASS_MEMBERS
67};
68
69#define GET_GICOMBINER_IMPL
70#include "MipsGenPostLegalizeGICombiner.inc"
71#undef GET_GICOMBINER_IMPL
72
73MipsPostLegalizerCombinerImpl::MipsPostLegalizerCombinerImpl(
75 GISelCSEInfo *CSEInfo,
76 const MipsPostLegalizerCombinerImplRuleConfig &RuleConfig,
77 const MipsSubtarget &STI, MachineDominatorTree *MDT,
78 const LegalizerInfo *LI)
79 : Combiner(MF, CInfo, &VT, CSEInfo), RuleConfig(RuleConfig), STI(STI),
80 Helper(Observer, B, /*IsPreLegalize*/ false, &VT, MDT, LI),
82#include "MipsGenPostLegalizeGICombiner.inc"
84{
85}
86
87// Pass boilerplate
88// ================
89
90class MipsPostLegalizerCombinerLegacy : public MachineFunctionPass {
91public:
92 static char ID;
93
94 MipsPostLegalizerCombinerLegacy(bool IsOptNone = false);
95
96 StringRef getPassName() const override { return "MipsPostLegalizerCombiner"; }
97
98 bool runOnMachineFunction(MachineFunction &MF) override;
99
100 void getAnalysisUsage(AnalysisUsage &AU) const override;
101
102private:
103 bool IsOptNone;
104};
105} // end anonymous namespace
106
107void MipsPostLegalizerCombinerLegacy::getAnalysisUsage(
108 AnalysisUsage &AU) const {
109 AU.setPreservesCFG();
113 if (!IsOptNone) {
115 }
117}
118
119MipsPostLegalizerCombinerLegacy::MipsPostLegalizerCombinerLegacy(bool IsOptNone)
120 : MachineFunctionPass(ID), IsOptNone(IsOptNone) {}
121
122static bool
124 function_ref<bool()> ShouldSkip,
127 if (MF.getProperties().hasFailedISel())
128 return false;
129 const Function &F = MF.getFunction();
130 bool EnableOpt =
131 MF.getTarget().getOptLevel() != CodeGenOptLevel::None && !ShouldSkip();
132
133 MipsPostLegalizerCombinerImplRuleConfig RuleConfig;
134 if (!RuleConfig.parseCommandLineOption())
135 report_fatal_error("Invalid rule identifier");
136
137 const MipsSubtarget &ST = MF.getSubtarget<MipsSubtarget>();
138 const MipsLegalizerInfo *LI =
139 static_cast<const MipsLegalizerInfo *>(ST.getLegalizerInfo());
140
141 GISelValueTracking *VT = GetVT();
142 MachineDominatorTree *MDT = IsOptNone ? nullptr : GetMDT();
143 CombinerInfo CInfo(/*AllowIllegalOps*/ false, /*ShouldLegalizeIllegal*/ true,
144 LI, EnableOpt, F.hasOptSize(), F.hasMinSize());
145 MipsPostLegalizerCombinerImpl Impl(MF, CInfo, *VT, /*CSEInfo*/ nullptr,
146 RuleConfig, ST, MDT, LI);
147 return Impl.combineMachineInstrs();
148}
149
150char MipsPostLegalizerCombinerLegacy::ID = 0;
151INITIALIZE_PASS_BEGIN(MipsPostLegalizerCombinerLegacy, DEBUG_TYPE,
152 "Combine Mips machine instrs after legalization", false,
153 false)
155INITIALIZE_PASS_END(MipsPostLegalizerCombinerLegacy, DEBUG_TYPE,
156 "Combine Mips machine instrs after legalization", false,
157 false)
158
160 return new MipsPostLegalizerCombinerLegacy(IsOptNone);
161}
162
163bool MipsPostLegalizerCombinerLegacy::runOnMachineFunction(
164 MachineFunction &MF) {
166 MF, IsOptNone, [&]() { return skipFunction(MF.getFunction()); },
167 [&]() {
168 return &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
169 },
170 [&]() {
171 return &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
172 });
173}
174
179 MF, IsOptNone,
180 [&]() {
181 return MF.getFunction().hasOptNone() ||
183 },
184 [&]() { return &MFAM.getResult<GISelValueTrackingAnalysis>(MF); },
185 [&]() { return &MFAM.getResult<MachineDominatorTreeAnalysis>(MF); });
186 if (!Changed)
187 return PreservedAnalyses::all();
190 .preserve<GISelValueTrackingAnalysis>();
191}
#define GET_GICOMBINER_CONSTRUCTOR_INITS
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
This contains common combine transformations that may be used in a combine pass,or by the target else...
Option class for Targets to specify which operations are combined how and when.
This contains the base class for all Combiners generated by TableGen.
Provides analysis for querying information about KnownBits during GISel passes.
#define DEBUG_TYPE
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Contains matchers for matching SSA Machine Instructions.
This file declares the targeting of the Machinelegalizer class for Mips.
static bool runCombinerOnMachineFunction(MachineFunction &MF, bool IsOptNone, function_ref< bool()> ShouldSkip, function_ref< GISelValueTracking *()> GetVT, function_ref< MachineDominatorTree *()> GetMDT)
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition PassSupport.h:42
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition PassSupport.h:44
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition PassSupport.h:39
static StringRef getName(Value *V)
Target-Independent Code Generator Pass Configuration Options pass.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
Represent the analysis usage information of a pass.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:280
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
Combiner implementation.
Definition Combiner.h:33
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:312
bool hasOptNone() const
Do not optimize this function (-O0).
Definition Function.h:686
The CSE Analysis object.
Definition CSEInfo.h:72
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelValueTrackingInfoAnal...
Analysis pass which computes a MachineDominatorTree.
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
virtual bool runOnMachineFunction(MachineFunction &MF)=0
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineFunctionProperties & getProperties() const
Get the function properties.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
This class provides legalization strategies.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition Pass.cpp:87
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
An efficient, type-erasing, non-owning reference to a callable.
Pass manager infrastructure for declaring and invalidating analyses.
This is an optimization pass for GlobalISel generic memory operations.
FunctionPass * createMipsPostLegalizeCombinerLegacyPass(bool IsOptNone)
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition Utils.cpp:1296