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 "RISCVSubtarget.h"
24
25#define GET_GICOMBINER_DEPS
26#include "RISCVGenO0PreLegalizeGICombiner.inc"
27#undef GET_GICOMBINER_DEPS
28
29#define DEBUG_TYPE "riscv-O0-prelegalizer-combiner"
30
31using namespace llvm;
32
33namespace {
34#define GET_GICOMBINER_TYPES
35#include "RISCVGenO0PreLegalizeGICombiner.inc"
36#undef GET_GICOMBINER_TYPES
37
38class RISCVO0PreLegalizerCombinerImpl : public Combiner {
39protected:
40 const CombinerHelper Helper;
41 const RISCVO0PreLegalizerCombinerImplRuleConfig &RuleConfig;
42 const RISCVSubtarget &STI;
43
44public:
45 RISCVO0PreLegalizerCombinerImpl(
47 GISelCSEInfo *CSEInfo,
48 const RISCVO0PreLegalizerCombinerImplRuleConfig &RuleConfig,
49 const RISCVSubtarget &STI);
50
51 static const char *getName() { return "RISCVO0PreLegalizerCombiner"; }
52
53 bool tryCombineAll(MachineInstr &I) const override;
54
55private:
56#define GET_GICOMBINER_CLASS_MEMBERS
57#include "RISCVGenO0PreLegalizeGICombiner.inc"
58#undef GET_GICOMBINER_CLASS_MEMBERS
59};
60
61#define GET_GICOMBINER_IMPL
62#include "RISCVGenO0PreLegalizeGICombiner.inc"
63#undef GET_GICOMBINER_IMPL
64
65RISCVO0PreLegalizerCombinerImpl::RISCVO0PreLegalizerCombinerImpl(
67 GISelCSEInfo *CSEInfo,
68 const RISCVO0PreLegalizerCombinerImplRuleConfig &RuleConfig,
69 const RISCVSubtarget &STI)
70 : Combiner(MF, CInfo, &VT, CSEInfo),
71 Helper(Observer, B, /*IsPreLegalize*/ true, &VT), RuleConfig(RuleConfig),
72 STI(STI),
74#include "RISCVGenO0PreLegalizeGICombiner.inc"
76{
77}
78
79// Pass boilerplate
80// ================
81
82class RISCVO0PreLegalizerCombiner : public MachineFunctionPass {
83public:
84 static char ID;
85
86 RISCVO0PreLegalizerCombiner();
87
88 StringRef getPassName() const override {
89 return "RISCVO0PreLegalizerCombiner";
90 }
91
92 bool runOnMachineFunction(MachineFunction &MF) override;
93
94 void getAnalysisUsage(AnalysisUsage &AU) const override;
95
96private:
97 RISCVO0PreLegalizerCombinerImplRuleConfig RuleConfig;
98};
99} // end anonymous namespace
100
101void RISCVO0PreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
102 AU.setPreservesCFG();
107}
108
109RISCVO0PreLegalizerCombiner::RISCVO0PreLegalizerCombiner()
110 : MachineFunctionPass(ID) {
111 if (!RuleConfig.parseCommandLineOption())
112 report_fatal_error("Invalid rule identifier");
113}
114
115bool RISCVO0PreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
116 if (MF.getProperties().hasFailedISel())
117 return false;
118
119 const Function &F = MF.getFunction();
121 &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
122
124
125 CombinerInfo CInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
126 /*LegalizerInfo*/ nullptr, /*EnableOpt*/ false,
127 F.hasOptSize(), F.hasMinSize());
128 // Disable fixed-point iteration in the Combiner. This improves compile-time
129 // at the cost of possibly missing optimizations. See PR#94291 for details.
130 CInfo.MaxIterations = 1;
131
132 RISCVO0PreLegalizerCombinerImpl Impl(MF, CInfo, *VT,
133 /*CSEInfo*/ nullptr, RuleConfig, ST);
134 return Impl.combineMachineInstrs();
135}
136
137char RISCVO0PreLegalizerCombiner::ID = 0;
138INITIALIZE_PASS_BEGIN(RISCVO0PreLegalizerCombiner, DEBUG_TYPE,
139 "Combine RISC-V machine instrs before legalization",
140 false, false)
143INITIALIZE_PASS_END(RISCVO0PreLegalizerCombiner, DEBUG_TYPE,
144 "Combine RISC-V machine instrs before legalization", false,
145 false)
146
148 return new RISCVO0PreLegalizerCombiner();
149}
#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)
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:278
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
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:86
This is an optimization pass for GlobalISel generic memory operations.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
FunctionPass * createRISCVO0PreLegalizerCombiner()
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition Utils.cpp:1137