LLVM 17.0.0git
MipsPostLegalizerCombiner.cpp
Go to the documentation of this file.
1//=== lib/CodeGen/GlobalISel/MipsPostLegalizerCombiner.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// after the legalizer.
11//
12//===----------------------------------------------------------------------===//
13
15#include "Mips.h"
16#include "MipsLegalizerInfo.h"
17#include "MipsSubtarget.h"
26
27#define DEBUG_TYPE "mips-postlegalizer-combiner"
28
29using namespace llvm;
30using namespace MIPatternMatch;
31
32#define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS
33#include "MipsGenPostLegalizeGICombiner.inc"
34#undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS
35
36namespace {
37#define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H
38#include "MipsGenPostLegalizeGICombiner.inc"
39#undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H
40
41class MipsPostLegalizerCombinerInfo final : public CombinerInfo {
43
44public:
45 MipsGenPostLegalizerCombinerHelperRuleConfig GeneratedRuleCfg;
46
47 MipsPostLegalizerCombinerInfo(bool EnableOpt, bool OptSize, bool MinSize,
48 GISelKnownBits *KB, const MipsLegalizerInfo *LI)
49 : CombinerInfo(/*AllowIllegalOps*/ false, /*ShouldLegalizeIllegal*/ true,
50 /*LegalizerInfo*/ LI, EnableOpt, OptSize, MinSize),
51 KB(KB) {
52 if (!GeneratedRuleCfg.parseCommandLineOption())
53 report_fatal_error("Invalid rule identifier");
54 }
55
57 MachineIRBuilder &B) const override;
58};
59
60bool MipsPostLegalizerCombinerInfo::combine(GISelChangeObserver &Observer,
62 MachineIRBuilder &B) const {
63
64 CombinerHelper Helper(Observer, B, /* IsPreLegalize*/ false, KB,
65 /*DominatorTree*/ nullptr, LInfo);
66 MipsGenPostLegalizerCombinerHelper Generated(GeneratedRuleCfg, Helper);
67 return Generated.tryCombineAll(Observer, MI, B, Helper);
68}
69
70#define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP
71#include "MipsGenPostLegalizeGICombiner.inc"
72#undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP
73
74// Pass boilerplate
75// ================
76
77class MipsPostLegalizerCombiner : public MachineFunctionPass {
78public:
79 static char ID;
80
81 MipsPostLegalizerCombiner(bool IsOptNone = false);
82
83 StringRef getPassName() const override {
84 return "MipsPostLegalizerCombiner";
85 }
86
87 bool runOnMachineFunction(MachineFunction &MF) override;
88
89 void getAnalysisUsage(AnalysisUsage &AU) const override;
90
91private:
92 bool IsOptNone;
93};
94} // end anonymous namespace
95
96void MipsPostLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
98 AU.setPreservesCFG();
102 if (!IsOptNone) {
105 }
107}
108
109MipsPostLegalizerCombiner::MipsPostLegalizerCombiner(bool IsOptNone)
110 : MachineFunctionPass(ID), IsOptNone(IsOptNone) {
112}
113
114bool MipsPostLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
115 if (MF.getProperties().hasProperty(
116 MachineFunctionProperties::Property::FailedISel))
117 return false;
118 auto *TPC = &getAnalysis<TargetPassConfig>();
119 const Function &F = MF.getFunction();
120 bool EnableOpt =
121 MF.getTarget().getOptLevel() != CodeGenOpt::None && !skipFunction(F);
122
124 const MipsLegalizerInfo *LI =
125 static_cast<const MipsLegalizerInfo *>(ST.getLegalizerInfo());
126
127 GISelKnownBits *KB = &getAnalysis<GISelKnownBitsAnalysis>().get(MF);
128 MipsPostLegalizerCombinerInfo PCInfo(EnableOpt, F.hasOptSize(),
129 F.hasMinSize(), KB, LI);
130 Combiner C(PCInfo, TPC);
131 return C.combineMachineInstrs(MF, /*CSEInfo*/ nullptr);
132}
133
134char MipsPostLegalizerCombiner::ID = 0;
135INITIALIZE_PASS_BEGIN(MipsPostLegalizerCombiner, DEBUG_TYPE,
136 "Combine Mips machine instrs after legalization", false,
137 false)
140INITIALIZE_PASS_END(MipsPostLegalizerCombiner, DEBUG_TYPE,
141 "Combine Mips machine instrs after legalization", false,
142 false)
143
144namespace llvm {
146 return new MipsPostLegalizerCombiner(IsOptNone);
147}
148} // end namespace llvm
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...
Interface for Targets to specify which operations are combined how and when.
This contains common code to drive combines.
Provides analysis for querying information about KnownBits during GISel passes.
Hexagon Vector Combine
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
Contains matchers for matching SSA Machine Instructions.
This file declares the targeting of the Machinelegalizer class for Mips.
Combine Mips machine instrs after legalization
#define DEBUG_TYPE
#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
Target-Independent Code Generator Pass Configuration Options pass.
vector combine
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:265
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
Abstract class that contains various methods for clients to notify about changes.
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.
Helper class to build MachineInstr.
Representation of each machine instruction.
Definition: MachineInstr.h:68
This class provides legalization strategies.
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
CodeGenOpt::Level 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
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145
void initializeMipsPostLegalizerCombinerPass(PassRegistry &)
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition: Utils.cpp:895
auto instrs(const MachineBasicBlock &BB)
FunctionPass * createMipsPostLegalizeCombiner(bool IsOptNone)