38#define GET_GICOMBINER_DEPS
39#include "RISCVGenPostLegalizeGICombiner.inc"
40#undef GET_GICOMBINER_DEPS
42#define DEBUG_TYPE "riscv-postlegalizer-combiner"
49#define GET_GICOMBINER_TYPES
50#include "RISCVGenPostLegalizeGICombiner.inc"
51#undef GET_GICOMBINER_TYPES
57 if (
MI.getOpcode() != TargetOpcode::G_STORE)
67 unsigned ValBits =
MRI.getType(SrcReg).getSizeInBits();
68 if ((ValBits == 16 && !STI.hasStdExtZfh()) ||
69 (ValBits == 32 && !STI.hasStdExtF()) ||
70 (ValBits == 64 && (!STI.hasStdExtD() || !STI.
is64Bit())))
81 const unsigned XLen = STI.
getXLen();
84 MI.getOperand(0).setReg(
Zero.getReg(0));
87 if (Def &&
MRI.use_nodbg_empty(MatchInfo))
88 Def->eraseFromParent();
91 unsigned ValBits =
MRI.getType(MatchInfo).getSizeInBits();
93 "(XLEN={1}, ValBits={2}):\n {3}\n",
103 if (!STI.hasStdExtZbb())
106 LLT Ty =
MRI.getType(
MI.getOperand(0).getReg());
115 LeftShift < 1 || LeftShift > 8 ||
MRI.getType(Src) != Ty)
119 if (RightShift == 0) {
129 if (!
MRI.hasOneNonDBGUse(
LHS) &&
130 (RightShift == 0 || !
MRI.hasOneNonDBGUse(
RHS)))
144 B.buildInstr(RISCV::G_ORC_B, {
MI.getOperand(0)}, {Src});
145 MI.eraseFromParent();
148class RISCVPostLegalizerCombinerImpl :
public Combiner {
150 const CombinerHelper Helper;
151 const RISCVPostLegalizerCombinerImplRuleConfig &RuleConfig;
152 const RISCVSubtarget &STI;
155 RISCVPostLegalizerCombinerImpl(
157 GISelCSEInfo *CSEInfo,
158 const RISCVPostLegalizerCombinerImplRuleConfig &RuleConfig,
159 const RISCVSubtarget &STI, MachineDominatorTree *MDT,
160 const LegalizerInfo *LI);
162 static const char *
getName() {
return "RISCVPostLegalizerCombiner"; }
164 bool tryCombineAll(MachineInstr &
I)
const override;
167#define GET_GICOMBINER_CLASS_MEMBERS
168#include "RISCVGenPostLegalizeGICombiner.inc"
169#undef GET_GICOMBINER_CLASS_MEMBERS
172#define GET_GICOMBINER_IMPL
173#include "RISCVGenPostLegalizeGICombiner.inc"
174#undef GET_GICOMBINER_IMPL
176RISCVPostLegalizerCombinerImpl::RISCVPostLegalizerCombinerImpl(
179 const RISCVPostLegalizerCombinerImplRuleConfig &RuleConfig,
182 :
Combiner(MF, CInfo, &VT, CSEInfo),
183 Helper(Observer,
B,
false, &VT, MDT, LI),
184 RuleConfig(RuleConfig), STI(STI),
186#include
"RISCVGenPostLegalizeGICombiner.inc"
195 RISCVPostLegalizerCombinerLegacy();
198 return "RISCVPostLegalizerCombiner";
206void RISCVPostLegalizerCombinerLegacy::getAnalysisUsage(
219RISCVPostLegalizerCombinerLegacy::RISCVPostLegalizerCombinerLegacy()
235 RISCVPostLegalizerCombinerImplRuleConfig RuleConfig;
236 if (!RuleConfig.parseCommandLineOption())
240 const auto *LI = ST.getLegalizerInfo();
247 nullptr, EnableOpt,
F.hasOptSize(),
249 RISCVPostLegalizerCombinerImpl Impl(MF, CInfo, *VT, CSEInfo, RuleConfig, ST,
251 return Impl.combineMachineInstrs();
254char RISCVPostLegalizerCombinerLegacy::ID = 0;
256 "Combine RISC-V MachineInstrs after legalization",
false,
261 "Combine RISC-V MachineInstrs after legalization",
false,
265 return new RISCVPostLegalizerCombinerLegacy();
268bool RISCVPostLegalizerCombinerLegacy::runOnMachineFunction(
271 MF, [&]() {
return skipFunction(MF.
getFunction()); },
273 return &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
276 return &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
281 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
300 .preserve<GISelValueTrackingAnalysis>()
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
#define GET_GICOMBINER_CONSTRUCTOR_INITS
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.
Contains matchers for matching SSA Machine Instructions.
This file declares the MachineIRBuilder class.
static bool runCombinerOnMachineFunction(MachineFunction &MF, bool IsOptNone, function_ref< bool()> ShouldSkip, function_ref< GISelValueTracking *()> GetVT, function_ref< MachineDominatorTree *()> GetMDT)
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
static StringRef getName(Value *V)
MachineRegisterInfo & MRI
static bool runCombinerOnMachineFunction(MachineFunction &MF, function_ref< bool()> ShouldSkip, function_ref< GISelValueTracking *()> GetVT, function_ref< MachineDominatorTree *()> GetMDT, function_ref< GISelCSEInfo *()> GetCSEInfo)
Target-Independent Code Generator Pass Configuration Options pass.
Class for arbitrary precision integers.
static LLVM_ABI APInt getSplat(unsigned NewLen, const APInt &V)
Return a value containing V broadcasted over NewLen bits.
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:
Represents analyses that only rely on functions' control flow.
FunctionPass class - This class is used to implement most global optimizations.
bool hasOptNone() const
Do not optimize this function (-O0).
The actual analysis pass wrapper.
Simple wrapper that does the following.
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelValueTrackingInfoAnal...
bool maskedValueIsZero(Register Val, const APInt &Mask)
static constexpr LLT scalar(unsigned SizeInBits)
Get a low-level scalar or aggregate "bag of bits".
static LLT integer(unsigned SizeInBits)
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
Helper class to build MachineInstr.
Representation of each machine instruction.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
A set of analyses that are preserved following a run of a transformation pass.
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Target-Independent Code Generator Pass Configuration Options.
virtual std::unique_ptr< CSEConfigBase > getCSEConfig() const
Returns the CSEConfig object to use for the current optimization level.
An efficient, type-erasing, non-owning reference to a callable.
Pass manager infrastructure for declaring and invalidating analyses.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
operand_type_match m_Reg()
SpecificConstantMatch m_SpecificICst(const APInt &RequestedValue)
Matches a constant equal to RequestedValue.
ConstantMatch< APInt > m_ICst(APInt &Cst)
auto m_PosZeroFP()
Matches a floating-point positive zero.
bool mi_match(Reg R, const MachineRegisterInfo &MRI, Pattern &&P)
SpecificRegisterMatch m_SpecificReg(Register RequestedReg)
Matches a register only if it is equal to RequestedReg.
BinaryOp_match< LHS, RHS, TargetOpcode::G_SHL, false > m_GShl(const LHS &L, const RHS &R)
BinaryOp_match< LHS, RHS, TargetOpcode::G_LSHR, false > m_GLShr(const LHS &L, const RHS &R)
NodeAddr< DefNode * > Def
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.
auto formatv(bool Validate, const char *Fmt, Ts &&...Vals)
decltype(auto) get(const PointerIntPair< PointerTy, IntBits, IntType, PtrTraits, Info > &Pair)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
FunctionPass * createRISCVPostLegalizerCombinerLegacyPass()
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
LLVM_ABI void reportFatalUsageError(Error Err)
Report a fatal error that does not indicate a bug in LLVM.
bool shouldSkipOptimizationForOptBisect(IRUnitRef IR)