LLVM 24.0.0git
RISCVO0PreLegalizerCombiner.cpp
Go to the documentation of this file.
1//=== RISCVO0PreLegalizerCombiner.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 "RISCV.h"
15#include "RISCVSubtarget.h"
27#include "llvm/IR/Analysis.h"
29
30#define GET_GICOMBINER_DEPS
31#include "RISCVGenO0PreLegalizeGICombiner.inc"
32#undef GET_GICOMBINER_DEPS
33
34#define DEBUG_TYPE "riscv-O0-prelegalizer-combiner"
35
36using namespace llvm;
37
38namespace {
39#define GET_GICOMBINER_TYPES
40#include "RISCVGenO0PreLegalizeGICombiner.inc"
41#undef GET_GICOMBINER_TYPES
42
43class RISCVO0PreLegalizerCombinerImpl : public Combiner {
44protected:
45 const CombinerHelper Helper;
46 const RISCVO0PreLegalizerCombinerImplRuleConfig &RuleConfig;
47 const RISCVSubtarget &STI;
48
49public:
50 RISCVO0PreLegalizerCombinerImpl(
52 GISelCSEInfo *CSEInfo,
53 const RISCVO0PreLegalizerCombinerImplRuleConfig &RuleConfig,
54 const RISCVSubtarget &STI);
55
56 static const char *getName() { return "RISCVO0PreLegalizerCombiner"; }
57
58 bool tryCombineAll(MachineInstr &I) const override;
59
60private:
61#define GET_GICOMBINER_CLASS_MEMBERS
62#include "RISCVGenO0PreLegalizeGICombiner.inc"
63#undef GET_GICOMBINER_CLASS_MEMBERS
64};
65
66#define GET_GICOMBINER_IMPL
67#include "RISCVGenO0PreLegalizeGICombiner.inc"
68#undef GET_GICOMBINER_IMPL
69
70RISCVO0PreLegalizerCombinerImpl::RISCVO0PreLegalizerCombinerImpl(
72 GISelCSEInfo *CSEInfo,
73 const RISCVO0PreLegalizerCombinerImplRuleConfig &RuleConfig,
74 const RISCVSubtarget &STI)
75 : Combiner(MF, CInfo, &VT, CSEInfo),
76 Helper(Observer, B, /*IsPreLegalize*/ true, &VT), RuleConfig(RuleConfig),
77 STI(STI),
79#include "RISCVGenO0PreLegalizeGICombiner.inc"
81{
82}
83
84// Pass boilerplate
85// ================
86
87class RISCVO0PreLegalizerCombinerLegacy : public MachineFunctionPass {
88public:
89 static char ID;
90
91 RISCVO0PreLegalizerCombinerLegacy();
92
93 StringRef getPassName() const override {
94 return "RISCVO0PreLegalizerCombiner";
95 }
96
97 bool runOnMachineFunction(MachineFunction &MF) override;
98
99 void getAnalysisUsage(AnalysisUsage &AU) const override;
100};
101} // end anonymous namespace
102
103void RISCVO0PreLegalizerCombinerLegacy::getAnalysisUsage(
104 AnalysisUsage &AU) const {
105 AU.setPreservesCFG();
110}
111
112RISCVO0PreLegalizerCombinerLegacy::RISCVO0PreLegalizerCombinerLegacy()
113 : MachineFunctionPass(ID) {}
114
115static bool
117 function_ref<GISelValueTracking *()> GetVT) {
118 if (MF.getProperties().hasFailedISel())
119 return false;
120
121 RISCVO0PreLegalizerCombinerImplRuleConfig RuleConfig;
122 if (!RuleConfig.parseCommandLineOption())
123 reportFatalUsageError("Invalid rule identifier");
124
125 const Function &F = MF.getFunction();
126 GISelValueTracking *VT = GetVT();
127
129
130 CombinerInfo CInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
131 /*LegalizerInfo*/ nullptr, /*EnableOpt*/ false,
132 F.hasOptSize(), F.hasMinSize());
133 // Disable fixed-point iteration in the Combiner. This improves compile-time
134 // at the cost of possibly missing optimizations. See PR#94291 for details.
135 CInfo.MaxIterations = 1;
136
137 RISCVO0PreLegalizerCombinerImpl Impl(MF, CInfo, *VT,
138 /*CSEInfo*/ nullptr, RuleConfig, ST);
139 return Impl.combineMachineInstrs();
140}
141
142char RISCVO0PreLegalizerCombinerLegacy::ID = 0;
143INITIALIZE_PASS_BEGIN(RISCVO0PreLegalizerCombinerLegacy, DEBUG_TYPE,
144 "Combine RISC-V machine instrs before legalization",
145 false, false)
148INITIALIZE_PASS_END(RISCVO0PreLegalizerCombinerLegacy, DEBUG_TYPE,
149 "Combine RISC-V machine instrs before legalization", false,
150 false)
151
153 return new RISCVO0PreLegalizerCombinerLegacy();
154}
155
156bool RISCVO0PreLegalizerCombinerLegacy::runOnMachineFunction(
157 MachineFunction &MF) {
158 return runO0PreLegalizerCombiner(MF, [&]() {
159 return &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
160 });
161}
162
167 MF, [&]() { return &MFAM.getResult<GISelValueTrackingAnalysis>(MF); });
168 if (!Changed)
169 return PreservedAnalyses::all();
172 .preserve<GISelValueTrackingAnalysis>();
173}
#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
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)
static bool runO0PreLegalizerCombiner(MachineFunction &MF, function_ref< GISelValueTracking *()> GetVT)
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
The actual analysis pass wrapper.
Definition CSEInfo.h:244
The CSE Analysis object.
Definition CSEInfo.h:72
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelValueTrackingInfoAnal...
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.
Representation of each machine instruction.
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
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition Utils.cpp:1156
FunctionPass * createRISCVO0PreLegalizerCombinerLegacyPass()
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
Definition Error.cpp:177