LLVM 24.0.0git
AArch64O0PreLegalizerCombiner.cpp
Go to the documentation of this file.
1//=== lib/CodeGen/GlobalISel/AArch64O0PreLegalizerCombiner.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// before the legalizer.
11//
12//===----------------------------------------------------------------------===//
13
14#include "AArch64.h"
31#include <memory>
32
33#define GET_GICOMBINER_DEPS
34#include "AArch64GenO0PreLegalizeGICombiner.inc"
35#undef GET_GICOMBINER_DEPS
36
37#define DEBUG_TYPE "aarch64-O0-prelegalizer-combiner"
38
39using namespace llvm;
40using namespace MIPatternMatch;
41
42#define GET_GICOMBINER_TYPES
43#include "AArch64GenO0PreLegalizeGICombiner.inc"
44#undef GET_GICOMBINER_TYPES
45
46namespace {
47
48class AArch64O0PreLegalizerCombinerImpl : public Combiner {
49protected:
50 const CombinerHelper Helper;
51 const AArch64O0PreLegalizerCombinerImplRuleConfig &RuleConfig;
52 const AArch64Subtarget &STI;
53 const LibcallLoweringInfo &Libcalls;
54
55public:
56 AArch64O0PreLegalizerCombinerImpl(
57 MachineFunction &MF, CombinerInfo &CInfo, GISelCSEInfo *CSEInfo,
58 const AArch64O0PreLegalizerCombinerImplRuleConfig &RuleConfig,
59 const AArch64Subtarget &STI, const LibcallLoweringInfo &Libcalls);
60
61 static const char *getName() { return "AArch64O0PreLegalizerCombiner"; }
62
63 bool tryCombineAll(MachineInstr &I) const override;
64
65 bool tryCombineAllImpl(MachineInstr &I) const;
66
67private:
68#define GET_GICOMBINER_CLASS_MEMBERS
69#include "AArch64GenO0PreLegalizeGICombiner.inc"
70#undef GET_GICOMBINER_CLASS_MEMBERS
71};
72
73#define GET_GICOMBINER_IMPL
74#include "AArch64GenO0PreLegalizeGICombiner.inc"
75#undef GET_GICOMBINER_IMPL
76
77AArch64O0PreLegalizerCombinerImpl::AArch64O0PreLegalizerCombinerImpl(
78 MachineFunction &MF, CombinerInfo &CInfo, GISelCSEInfo *CSEInfo,
79 const AArch64O0PreLegalizerCombinerImplRuleConfig &RuleConfig,
80 const AArch64Subtarget &STI, const LibcallLoweringInfo &Libcalls)
81 : Combiner(MF, CInfo, /*VT=*/nullptr, CSEInfo),
82 Helper(Observer, B, /*IsPreLegalize*/ true, /*VT=*/nullptr),
83 RuleConfig(RuleConfig), STI(STI), Libcalls(Libcalls),
85#include "AArch64GenO0PreLegalizeGICombiner.inc"
87{
88}
89
90bool AArch64O0PreLegalizerCombinerImpl::tryCombineAll(MachineInstr &MI) const {
91 if (tryCombineAllImpl(MI))
92 return true;
93
94 return false;
95}
96
97bool runCombiner(
98 MachineFunction &MF, const LibcallLoweringInfo &Libcalls,
99 const AArch64O0PreLegalizerCombinerImplRuleConfig &RuleConfig) {
100 const Function &F = MF.getFunction();
101 const AArch64Subtarget &ST = MF.getSubtarget<AArch64Subtarget>();
102
103 CombinerInfo CInfo(/*AllowIllegalOps=*/true, /*ShouldLegalizeIllegal=*/false,
104 /*LegalizerInfo=*/nullptr, /*EnableOpt=*/false,
105 F.hasOptSize(), F.hasMinSize());
106 // Disable fixed-point iteration in the Combiner. This improves compile-time
107 // at the cost of possibly missing optimizations. See PR#94291 for details.
108 CInfo.MaxIterations = 1;
109
110 AArch64O0PreLegalizerCombinerImpl Impl(MF, CInfo,
111 /*CSEInfo*/ nullptr, RuleConfig, ST,
112 Libcalls);
113 return Impl.combineMachineInstrs();
114}
115
116// Pass boilerplate
117// ================
118
119class AArch64O0PreLegalizerCombinerLegacy : public MachineFunctionPass {
120public:
121 static char ID;
122
123 AArch64O0PreLegalizerCombinerLegacy();
124
125 StringRef getPassName() const override {
126 return "AArch64O0PreLegalizerCombiner";
127 }
128
129 bool runOnMachineFunction(MachineFunction &MF) override;
130
131 void getAnalysisUsage(AnalysisUsage &AU) const override;
132
133private:
134 AArch64O0PreLegalizerCombinerImplRuleConfig RuleConfig;
135};
136} // end anonymous namespace
137
138void AArch64O0PreLegalizerCombinerLegacy::getAnalysisUsage(
139 AnalysisUsage &AU) const {
140 AU.setPreservesCFG();
142 AU.addRequired<LibcallLoweringInfoWrapper>();
144}
145
146AArch64O0PreLegalizerCombinerLegacy::AArch64O0PreLegalizerCombinerLegacy()
147 : MachineFunctionPass(ID) {
148 if (!RuleConfig.parseCommandLineOption())
149 report_fatal_error("Invalid rule identifier");
150}
151
152bool AArch64O0PreLegalizerCombinerLegacy::runOnMachineFunction(
153 MachineFunction &MF) {
154 if (MF.getProperties().hasFailedISel())
155 return false;
156
157 const Function &F = MF.getFunction();
158
159 const AArch64Subtarget &ST = MF.getSubtarget<AArch64Subtarget>();
160 const LibcallLoweringInfo &Libcalls =
161 getAnalysis<LibcallLoweringInfoWrapper>().getLibcallLowering(
162 *F.getParent(), ST);
163
164 return runCombiner(MF, Libcalls, RuleConfig);
165}
166
167char AArch64O0PreLegalizerCombinerLegacy::ID = 0;
168INITIALIZE_PASS_BEGIN(AArch64O0PreLegalizerCombinerLegacy, DEBUG_TYPE,
169 "Combine AArch64 machine instrs before legalization",
170 false, false)
173INITIALIZE_PASS_END(AArch64O0PreLegalizerCombinerLegacy, DEBUG_TYPE,
174 "Combine AArch64 machine instrs before legalization", false,
175 false)
176
178 : RuleConfig(
179 std::make_unique<AArch64O0PreLegalizerCombinerImplRuleConfig>()) {
180 if (!RuleConfig->parseCommandLineOption())
181 report_fatal_error("Invalid rule identifier");
182}
183
186
188 default;
189
193 if (MF.getProperties().hasFailedISel())
194 return PreservedAnalyses::all();
195
197 auto &MAMProxy =
199 const ModuleLibcallLoweringInfo *LibcallResult =
200 MAMProxy.getCachedResult<LibcallLoweringModuleAnalysis>(
201 *MF.getFunction().getParent());
202 if (!LibcallResult)
203 reportFatalUsageError("LibcallLoweringModuleAnalysis result not available");
204
205 const LibcallLoweringInfo &Libcalls = getLibcallLowering(*LibcallResult, ST);
206
207 if (!runCombiner(MF, Libcalls, *RuleConfig))
208 return PreservedAnalyses::all();
209
212 return PA;
213}
214
215namespace llvm {
217 return new AArch64O0PreLegalizerCombinerLegacy();
218}
219} // end namespace llvm
#define GET_GICOMBINER_CONSTRUCTOR_INITS
static const Function * getParent(const Value *V)
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
IRTranslator LLVM IR MI
#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 MachineIRBuilder class.
#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)
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
AnalysisUsage & addRequired()
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:278
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:314
The actual analysis pass wrapper.
Definition CSEInfo.h:244
The CSE Analysis object.
Definition CSEInfo.h:72
Tracks which library functions to use for a particular subtarget or function.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
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.
Representation of each machine instruction.
Records a mapping from an opaque lowering context to its LibcallLoweringInfo.
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
This is an optimization pass for GlobalISel generic memory operations.
OuterAnalysisManagerProxy< ModuleAnalysisManager, MachineFunction > ModuleAnalysisManagerMachineFunctionProxy
Provide the ModuleAnalysisManager to Function proxy.
FunctionPass * createAArch64O0PreLegalizerCombiner()
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI const LibcallLoweringInfo & getLibcallLowering(const ModuleLibcallLoweringInfo &ModuleInfo, const TargetSubtargetInfo &Subtarget)
Resolve the LibcallLoweringInfo for Subtarget from the module-level ModuleInfo, applying the subtarge...
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:1137
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:878