LLVM 19.0.0git
RISCVPostLegalizerCombiner.cpp
Go to the documentation of this file.
1//=== RISCVPostLegalizerCombiner.cpp --------------------------*- C++ -*-===//
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/// \file
10/// Post-legalization combines on generic MachineInstrs.
11///
12/// The combines here must preserve instruction legality.
13///
14/// Combines which don't rely on instruction legality should go in the
15/// RISCVPreLegalizerCombiner.
16///
17//===----------------------------------------------------------------------===//
18
19#include "RISCVTargetMachine.h"
32
33#define GET_GICOMBINER_DEPS
34#include "RISCVGenPostLegalizeGICombiner.inc"
35#undef GET_GICOMBINER_DEPS
36
37#define DEBUG_TYPE "riscv-postlegalizer-combiner"
38
39using namespace llvm;
40
41namespace {
42
43#define GET_GICOMBINER_TYPES
44#include "RISCVGenPostLegalizeGICombiner.inc"
45#undef GET_GICOMBINER_TYPES
46
47class RISCVPostLegalizerCombinerImpl : public Combiner {
48protected:
49 // TODO: Make CombinerHelper methods const.
50 mutable CombinerHelper Helper;
51 const RISCVPostLegalizerCombinerImplRuleConfig &RuleConfig;
52 const RISCVSubtarget &STI;
53
54public:
55 RISCVPostLegalizerCombinerImpl(
56 MachineFunction &MF, CombinerInfo &CInfo, const TargetPassConfig *TPC,
57 GISelKnownBits &KB, GISelCSEInfo *CSEInfo,
58 const RISCVPostLegalizerCombinerImplRuleConfig &RuleConfig,
59 const RISCVSubtarget &STI, MachineDominatorTree *MDT,
60 const LegalizerInfo *LI);
61
62 static const char *getName() { return "RISCVPostLegalizerCombiner"; }
63
64 bool tryCombineAll(MachineInstr &I) const override;
65
66private:
67#define GET_GICOMBINER_CLASS_MEMBERS
68#include "RISCVGenPostLegalizeGICombiner.inc"
69#undef GET_GICOMBINER_CLASS_MEMBERS
70};
71
72#define GET_GICOMBINER_IMPL
73#include "RISCVGenPostLegalizeGICombiner.inc"
74#undef GET_GICOMBINER_IMPL
75
76RISCVPostLegalizerCombinerImpl::RISCVPostLegalizerCombinerImpl(
77 MachineFunction &MF, CombinerInfo &CInfo, const TargetPassConfig *TPC,
78 GISelKnownBits &KB, GISelCSEInfo *CSEInfo,
79 const RISCVPostLegalizerCombinerImplRuleConfig &RuleConfig,
80 const RISCVSubtarget &STI, MachineDominatorTree *MDT,
81 const LegalizerInfo *LI)
82 : Combiner(MF, CInfo, TPC, &KB, CSEInfo),
83 Helper(Observer, B, /*IsPreLegalize*/ false, &KB, MDT, LI),
84 RuleConfig(RuleConfig), STI(STI),
86#include "RISCVGenPostLegalizeGICombiner.inc"
88{
89}
90
91class RISCVPostLegalizerCombiner : public MachineFunctionPass {
92public:
93 static char ID;
94
95 RISCVPostLegalizerCombiner();
96
97 StringRef getPassName() const override {
98 return "RISCVPostLegalizerCombiner";
99 }
100
101 bool runOnMachineFunction(MachineFunction &MF) override;
102 void getAnalysisUsage(AnalysisUsage &AU) const override;
103
104private:
105 RISCVPostLegalizerCombinerImplRuleConfig RuleConfig;
106};
107} // end anonymous namespace
108
109void RISCVPostLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
111 AU.setPreservesCFG();
120}
121
122RISCVPostLegalizerCombiner::RISCVPostLegalizerCombiner()
125
126 if (!RuleConfig.parseCommandLineOption())
127 report_fatal_error("Invalid rule identifier");
128}
129
130bool RISCVPostLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
131 if (MF.getProperties().hasProperty(
132 MachineFunctionProperties::Property::FailedISel))
133 return false;
135 MachineFunctionProperties::Property::Legalized) &&
136 "Expected a legalized function?");
137 auto *TPC = &getAnalysis<TargetPassConfig>();
138 const Function &F = MF.getFunction();
139 bool EnableOpt =
140 MF.getTarget().getOptLevel() != CodeGenOptLevel::None && !skipFunction(F);
141
143 const auto *LI = ST.getLegalizerInfo();
144
145 GISelKnownBits *KB = &getAnalysis<GISelKnownBitsAnalysis>().get(MF);
146 MachineDominatorTree *MDT = &getAnalysis<MachineDominatorTree>();
148 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
149 auto *CSEInfo = &Wrapper.get(TPC->getCSEConfig());
150
151 CombinerInfo CInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
152 /*LegalizerInfo*/ nullptr, EnableOpt, F.hasOptSize(),
153 F.hasMinSize());
154 RISCVPostLegalizerCombinerImpl Impl(MF, CInfo, TPC, *KB, CSEInfo,
155 RuleConfig, ST, MDT, LI);
156 return Impl.combineMachineInstrs();
157}
158
159char RISCVPostLegalizerCombiner::ID = 0;
160INITIALIZE_PASS_BEGIN(RISCVPostLegalizerCombiner, DEBUG_TYPE,
161 "Combine RISC-V MachineInstrs after legalization", false,
162 false)
165INITIALIZE_PASS_END(RISCVPostLegalizerCombiner, DEBUG_TYPE,
166 "Combine RISC-V MachineInstrs after legalization", false,
167 false)
168
169namespace llvm {
171 return new RISCVPostLegalizerCombiner();
172}
173} // end namespace llvm
amdgpu aa AMDGPU Address space based Alias Analysis Wrapper
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Provides analysis for continuously CSEing during GISel passes.
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.
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
Hexagon Vector Combine
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
This file declares the MachineIRBuilder class.
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:55
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:59
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:52
static StringRef getName(Value *V)
#define GET_GICOMBINER_CONSTRUCTOR_INITS
Combine RISC V MachineInstrs after legalization
#define DEBUG_TYPE
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Target-Independent Code Generator Pass Configuration Options pass.
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.
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:269
Combiner implementation.
Definition: Combiner.h:34
virtual bool tryCombineAll(MachineInstr &I) const =0
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:311
The actual analysis pass wrapper.
Definition: CSEInfo.h:222
Simple wrapper that does the following.
Definition: CSEInfo.h:204
The CSE Analysis object.
Definition: CSEInfo.h:69
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelKnownBitsInfoAnalysis...
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...
bool hasProperty(Property P) const
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 LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
const MachineFunctionProperties & getProperties() const
Get the function properties.
Representation of each machine instruction.
Definition: MachineInstr.h:69
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition: Pass.cpp:81
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Target-Independent Code Generator Pass Configuration Options.
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
FunctionPass * createRISCVPostLegalizerCombiner()
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:156
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition: Utils.cpp:1142
void initializeRISCVPostLegalizerCombinerPass(PassRegistry &)