LLVM 19.0.0git
AArch64O0PreLegalizerCombiner.cpp
Go to the documentation of this file.
1//=== lib/CodeGen/GlobalISel/AArch64O0PreLegalizerCombiner.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
29#include "llvm/Support/Debug.h"
30
31#define GET_GICOMBINER_DEPS
32#include "AArch64GenO0PreLegalizeGICombiner.inc"
33#undef GET_GICOMBINER_DEPS
34
35#define DEBUG_TYPE "aarch64-O0-prelegalizer-combiner"
36
37using namespace llvm;
38using namespace MIPatternMatch;
39namespace {
40#define GET_GICOMBINER_TYPES
41#include "AArch64GenO0PreLegalizeGICombiner.inc"
42#undef GET_GICOMBINER_TYPES
43
44class AArch64O0PreLegalizerCombinerImpl : public Combiner {
45protected:
46 // TODO: Make CombinerHelper methods const.
47 mutable CombinerHelper Helper;
48 const AArch64O0PreLegalizerCombinerImplRuleConfig &RuleConfig;
49 const AArch64Subtarget &STI;
50
51public:
52 AArch64O0PreLegalizerCombinerImpl(
53 MachineFunction &MF, CombinerInfo &CInfo, const TargetPassConfig *TPC,
54 GISelKnownBits &KB, GISelCSEInfo *CSEInfo,
55 const AArch64O0PreLegalizerCombinerImplRuleConfig &RuleConfig,
56 const AArch64Subtarget &STI);
57
58 static const char *getName() { return "AArch64O0PreLegalizerCombiner"; }
59
60 bool tryCombineAll(MachineInstr &I) const override;
61
62 bool tryCombineAllImpl(MachineInstr &I) const;
63
64private:
65#define GET_GICOMBINER_CLASS_MEMBERS
66#include "AArch64GenO0PreLegalizeGICombiner.inc"
67#undef GET_GICOMBINER_CLASS_MEMBERS
68};
69
70#define GET_GICOMBINER_IMPL
71#include "AArch64GenO0PreLegalizeGICombiner.inc"
72#undef GET_GICOMBINER_IMPL
73
74AArch64O0PreLegalizerCombinerImpl::AArch64O0PreLegalizerCombinerImpl(
75 MachineFunction &MF, CombinerInfo &CInfo, const TargetPassConfig *TPC,
76 GISelKnownBits &KB, GISelCSEInfo *CSEInfo,
77 const AArch64O0PreLegalizerCombinerImplRuleConfig &RuleConfig,
78 const AArch64Subtarget &STI)
79 : Combiner(MF, CInfo, TPC, &KB, CSEInfo),
80 Helper(Observer, B, /*IsPreLegalize*/ true, &KB), RuleConfig(RuleConfig),
81 STI(STI),
83#include "AArch64GenO0PreLegalizeGICombiner.inc"
85{
86}
87
88bool AArch64O0PreLegalizerCombinerImpl::tryCombineAll(MachineInstr &MI) const {
89 if (tryCombineAllImpl(MI))
90 return true;
91
92 unsigned Opc = MI.getOpcode();
93 switch (Opc) {
94 case TargetOpcode::G_SHUFFLE_VECTOR:
95 return Helper.tryCombineShuffleVector(MI);
96 case TargetOpcode::G_MEMCPY_INLINE:
97 return Helper.tryEmitMemcpyInline(MI);
98 case TargetOpcode::G_MEMCPY:
99 case TargetOpcode::G_MEMMOVE:
100 case TargetOpcode::G_MEMSET: {
101 // At -O0 set a maxlen of 32 to inline;
102 unsigned MaxLen = 32;
103 // Try to inline memcpy type calls if optimizations are enabled.
104 if (Helper.tryCombineMemCpyFamily(MI, MaxLen))
105 return true;
106 if (Opc == TargetOpcode::G_MEMSET)
107 return llvm::AArch64GISelUtils::tryEmitBZero(MI, B, CInfo.EnableMinSize);
108 return false;
109 }
110 }
111
112 return false;
113}
114
115// Pass boilerplate
116// ================
117
118class AArch64O0PreLegalizerCombiner : public MachineFunctionPass {
119public:
120 static char ID;
121
122 AArch64O0PreLegalizerCombiner();
123
124 StringRef getPassName() const override {
125 return "AArch64O0PreLegalizerCombiner";
126 }
127
128 bool runOnMachineFunction(MachineFunction &MF) override;
129
130 void getAnalysisUsage(AnalysisUsage &AU) const override;
131
132private:
133 AArch64O0PreLegalizerCombinerImplRuleConfig RuleConfig;
134};
135} // end anonymous namespace
136
137void AArch64O0PreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
139 AU.setPreservesCFG();
144}
145
146AArch64O0PreLegalizerCombiner::AArch64O0PreLegalizerCombiner()
149
150 if (!RuleConfig.parseCommandLineOption())
151 report_fatal_error("Invalid rule identifier");
152}
153
154bool AArch64O0PreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
155 if (MF.getProperties().hasProperty(
156 MachineFunctionProperties::Property::FailedISel))
157 return false;
158 auto &TPC = getAnalysis<TargetPassConfig>();
159
160 const Function &F = MF.getFunction();
161 GISelKnownBits *KB = &getAnalysis<GISelKnownBitsAnalysis>().get(MF);
162
164
165 CombinerInfo CInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
166 /*LegalizerInfo*/ nullptr, /*EnableOpt*/ false,
167 F.hasOptSize(), F.hasMinSize());
168 AArch64O0PreLegalizerCombinerImpl Impl(MF, CInfo, &TPC, *KB,
169 /*CSEInfo*/ nullptr, RuleConfig, ST);
170 return Impl.combineMachineInstrs();
171}
172
173char AArch64O0PreLegalizerCombiner::ID = 0;
174INITIALIZE_PASS_BEGIN(AArch64O0PreLegalizerCombiner, DEBUG_TYPE,
175 "Combine AArch64 machine instrs before legalization",
176 false, false)
180INITIALIZE_PASS_END(AArch64O0PreLegalizerCombiner, DEBUG_TYPE,
181 "Combine AArch64 machine instrs before legalization", false,
182 false)
183
184namespace llvm {
186 return new AArch64O0PreLegalizerCombiner();
187}
188} // end namespace llvm
#define GET_GICOMBINER_CONSTRUCTOR_INITS
Combine AArch64 machine instrs before legalization
basic Basic Alias true
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.
Hexagon Vector Combine
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition: MD5.cpp:55
#define I(x, y, z)
Definition: MD5.cpp:58
Contains matchers for matching SSA Machine Instructions.
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)
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
The CSE Analysis object.
Definition: CSEInfo.h:69
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelKnownBitsInfoAnalysis...
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 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
Target-Independent Code Generator Pass Configuration Options.
bool tryEmitBZero(MachineInstr &MI, MachineIRBuilder &MIRBuilder, bool MinSize)
Replace a G_MEMSET with a value of 0 with a G_BZERO instruction if it is supported and beneficial to ...
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 * createAArch64O0PreLegalizerCombiner()
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:1140
auto instrs(const MachineBasicBlock &BB)
void initializeAArch64O0PreLegalizerCombinerPass(PassRegistry &)