LLVM 24.0.0git
X86PostLegalizerCombiner.cpp
Go to the documentation of this file.
1//===--------------- X86PostLegalizerCombiner.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/// Lowering combines (e.g. pseudo matching) should be handled by
15/// X86PostLegalizerLowering.
16///
17/// Combines which don't rely on instruction legality should go in the
18/// X86PreLegalizerCombiner.
19///
20//===----------------------------------------------------------------------===//
21#include "X86.h"
22#include "X86TargetMachine.h"
36
37#define GET_GICOMBINER_DEPS
38#include "X86GenPostLegalizeGICombiner.inc"
39#undef GET_GICOMBINER_DEPS
40
41#define DEBUG_TYPE "X86-postlegalizer-combiner"
42
43using namespace llvm;
44using namespace MIPatternMatch;
45
46namespace {
47
48CombinerInfo createCombinerInfo(bool OptEnabled, const Function &F) {
49 CombinerInfo CInfo(/*AllowIllegalOps=*/true,
50 /*ShouldLegalizeIllegal=*/false,
51 /*LInfo=*/nullptr, /*OptEnabled=*/OptEnabled,
52 /*OptSize=*/F.hasOptSize(), /*MinSize=*/F.hasMinSize());
53 // Disable fixed-point iteration to reduce compile-time
54 CInfo.MaxIterations = 1;
56 // Legalizer performs DCE, so a full DCE pass is unnecessary.
57 CInfo.EnableFullDCE = false;
58 return CInfo;
59}
60
61#define GET_GICOMBINER_TYPES
62#include "X86GenPostLegalizeGICombiner.inc"
63#undef GET_GICOMBINER_TYPES
64
65class X86PostLegalizerCombinerImpl : public Combiner {
66protected:
67 const CombinerHelper Helper;
68 const X86PostLegalizerCombinerImplRuleConfig &RuleConfig;
69 const X86Subtarget &STI;
70
71public:
72 X86PostLegalizerCombinerImpl(
74 GISelCSEInfo *CSEInfo,
75 const X86PostLegalizerCombinerImplRuleConfig &RuleConfig,
77
78 static const char *getName() { return "X86PostLegalizerCombiner"; }
79
80 bool tryCombineAll(MachineInstr &I) const override;
81 bool tryCombineAllImpl(MachineInstr &I) const;
82
83private:
84#define GET_GICOMBINER_CLASS_MEMBERS
85#include "X86GenPostLegalizeGICombiner.inc"
86#undef GET_GICOMBINER_CLASS_MEMBERS
87};
88
89#define GET_GICOMBINER_IMPL
90#include "X86GenPostLegalizeGICombiner.inc"
91#undef GET_GICOMBINER_IMPL
92
93X86PostLegalizerCombinerImpl::X86PostLegalizerCombinerImpl(
95 GISelCSEInfo *CSEInfo,
96 const X86PostLegalizerCombinerImplRuleConfig &RuleConfig,
98 : Combiner(MF, CInfo, &VT, CSEInfo),
99 Helper(Observer, B, /*IsPreLegalize=*/false, &VT, MDT,
100 MF.getSubtarget<X86Subtarget>().getLegalizerInfo()),
101 RuleConfig(RuleConfig), STI(MF.getSubtarget<X86Subtarget>()),
103#include "X86GenPostLegalizeGICombiner.inc"
105{
106}
107
108bool X86PostLegalizerCombinerImpl::tryCombineAll(MachineInstr &MI) const {
109 return tryCombineAllImpl(MI);
110}
111
112class X86PostLegalizerCombinerLegacy : public MachineFunctionPass {
113public:
114 static char ID;
115
116 X86PostLegalizerCombinerLegacy();
117
118 StringRef getPassName() const override {
119 return "X86PostLegalizerCombinerLegacy";
120 }
121
122 bool runOnMachineFunction(MachineFunction &MF) override;
123 void getAnalysisUsage(AnalysisUsage &AU) const override;
124
125private:
126 X86PostLegalizerCombinerImplRuleConfig RuleConfig;
127};
128} // end anonymous namespace
129
130void X86PostLegalizerCombinerLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
131 AU.addRequired<TargetPassConfig>();
132 AU.setPreservesCFG();
134 AU.addRequired<GISelValueTrackingAnalysisLegacy>();
135 AU.addPreserved<GISelValueTrackingAnalysisLegacy>();
136 // This is only added when processing level is not OptNone.
137 AU.addRequired<MachineDominatorTreeWrapperPass>();
138 AU.addRequired<GISelCSEAnalysisWrapperPass>();
139 AU.addPreserved<GISelCSEAnalysisWrapperPass>();
140
142}
143
144X86PostLegalizerCombinerLegacy::X86PostLegalizerCombinerLegacy()
145 : MachineFunctionPass(ID) {
146 if (!RuleConfig.parseCommandLineOption())
147 reportFatalInternalError("Invalid rule identifier");
148}
149
150bool X86PostLegalizerCombinerLegacy::runOnMachineFunction(MachineFunction &MF) {
151 if (MF.getProperties().hasFailedISel())
152 return false;
153 assert(MF.getProperties().hasLegalized() && "Expected a legalized function?");
154 auto *TPC = &getAnalysis<TargetPassConfig>();
155 const Function &F = MF.getFunction();
156
158 &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
160 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
162 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
163 auto *CSEInfo = &Wrapper.get(TPC->getCSEConfig());
164
165 CombinerInfo CInfo = createCombinerInfo(!skipFunction(F), F);
166
167 X86PostLegalizerCombinerImpl Impl(MF, CInfo, *VT, CSEInfo, RuleConfig, MDT);
168 return Impl.combineMachineInstrs();
169}
170
171char X86PostLegalizerCombinerLegacy::ID = 0;
172INITIALIZE_PASS_BEGIN(X86PostLegalizerCombinerLegacy, DEBUG_TYPE,
173 "Combine X86 MachineInstrs after legalization", false,
174 false)
177INITIALIZE_PASS_END(X86PostLegalizerCombinerLegacy, DEBUG_TYPE,
178 "Combine X86 MachineInstrs after legalization", false,
179 false)
180
181namespace llvm {
182
186 if (MF.getProperties().hasFailedISel())
187 return PreservedAnalyses::all();
188 assert(MF.getProperties().hasLegalized() && "Expected a legalized function.");
189 const Function &F = MF.getFunction();
190
193 auto &CSEInfo = MFAM.getResult<GISelCSEAnalysis>(MF);
194
195 CombinerInfo CInfo = createCombinerInfo(true, F);
196
197 X86PostLegalizerCombinerImplRuleConfig RuleConfig;
198 if (!RuleConfig.parseCommandLineOption())
199 reportFatalInternalError("Invalid rule identifier");
200
201 X86PostLegalizerCombinerImpl Impl(MF, CInfo, VT, CSEInfo.get(), RuleConfig,
202 &MDT);
203 if (!Impl.combineMachineInstrs())
204 return PreservedAnalyses::all();
205
210 return PA;
211}
212
214 return new X86PostLegalizerCombinerLegacy();
215}
216} // end namespace llvm
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.
This contains common code to allow clients to notify changes to machine instr.
Provides analysis for querying information about KnownBits during GISel passes.
#define DEBUG_TYPE
IRTranslator LLVM IR MI
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
Contains matchers for matching SSA Machine Instructions.
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)
Target-Independent Code Generator Pass Configuration Options pass.
PassT::Result & getResult(IRUnitT &IR, ExtraArgTs... ExtraArgs)
Get the result of an analysis pass for a given IR unit.
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:275
Represents analyses that only rely on functions' control flow.
Definition Analysis.h:73
Combiner implementation.
Definition Combiner.h:33
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
Simple wrapper that does the following.
Definition CSEInfo.h:214
The CSE Analysis object.
Definition CSEInfo.h:72
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelValueTrackingInfoAnal...
Analysis pass which computes a MachineDominatorTree.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Function & getFunction()
Return the LLVM function that this machine code represents.
const MachineFunctionProperties & getProperties() const
Get the function properties.
Representation of each machine instruction.
A set of analyses that are preserved following a run of a transformation pass.
Definition Analysis.h:112
static PreservedAnalyses all()
Construct a special preserved set that preserves all passes.
Definition Analysis.h:118
PreservedAnalyses & preserveSet()
Mark an analysis set as preserved.
Definition Analysis.h:151
PreservedAnalyses & preserve()
Mark an analysis as preserved.
Definition Analysis.h:132
Target-Independent Code Generator Pass Configuration Options.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
This is an optimization pass for GlobalISel generic memory operations.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
Definition Error.cpp:173
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
FunctionPass * createX86PostLegalizerCombinerLegacy()
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition Utils.cpp:1137
unsigned MaxIterations
The maximum number of times the Combiner will iterate over the MachineFunction.
ObserverLevel ObserverLvl
Select how the Combiner acts on MIR changes.
bool EnableFullDCE
Whether dead code elimination is performed before each Combiner iteration.
@ SinglePass
Enables Observer-based DCE and additional heuristics that retry combining defined and used instructio...