LLVM 23.0.0git
X86PreLegalizerCombiner.cpp
Go to the documentation of this file.
1//===---------------- X86PreLegalizerCombiner.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/// \file
9/// This pass does combining of machine instructions at the generic MI level,
10/// before the legalizer.
11///
12//===----------------------------------------------------------------------===//
13#include "X86.h"
14#include "X86TargetMachine.h"
31
32#define GET_GICOMBINER_DEPS
33#include "X86GenPreLegalizeGICombiner.inc"
34#undef GET_GICOMBINER_DEPS
35
36#define DEBUG_TYPE "x86-prelegalizer-combiner"
37
38using namespace llvm;
39using namespace MIPatternMatch;
40
41namespace {
42
43CombinerInfo createCombinerInfo(bool EnableOpt, const Function &F) {
44 CombinerInfo CInfo(/*AllowIllegalOps=*/true, /*ShouldLegalizeIllegal=*/false,
45 nullptr, EnableOpt, F.hasOptSize(), F.hasMinSize());
46
47 // This is the first Combiner, so the input IR might contain dead
48 // instructions.
49 CInfo.EnableFullDCE = true;
50 return CInfo;
51}
52
53#define GET_GICOMBINER_TYPES
54#include "X86GenPreLegalizeGICombiner.inc"
55#undef GET_GICOMBINER_TYPES
56
57class X86PreLegalizerCombinerImpl : public Combiner {
58protected:
59 const CombinerHelper Helper;
60 const X86PreLegalizerCombinerImplRuleConfig &RuleConfig;
61 const X86Subtarget &STI;
62
63public:
64 X86PreLegalizerCombinerImpl(
66 GISelCSEInfo *CSEInfo,
67 const X86PreLegalizerCombinerImplRuleConfig &RuleConfig,
69
70 static const char *getName() { return "X86PreLegalizerCombiner"; }
71
72 bool tryCombineAll(MachineInstr &I) const override;
73
74 bool tryCombineAllImpl(MachineInstr &I) const;
75
76private:
77#define GET_GICOMBINER_CLASS_MEMBERS
78#include "X86GenPreLegalizeGICombiner.inc"
79#undef GET_GICOMBINER_CLASS_MEMBERS
80};
81
82#define GET_GICOMBINER_IMPL
83#include "X86GenPreLegalizeGICombiner.inc"
84#undef GET_GICOMBINER_IMPL
85
86X86PreLegalizerCombinerImpl::X86PreLegalizerCombinerImpl(
88 GISelCSEInfo *CSEInfo,
89 const X86PreLegalizerCombinerImplRuleConfig &RuleConfig,
91 : Combiner(MF, CInfo, &VT, CSEInfo),
92 Helper(Observer, B, /*IsPreLegalize=*/true, &VT, MDT,
93 MF.getSubtarget<X86Subtarget>().getLegalizerInfo()),
94 RuleConfig(RuleConfig), STI(MF.getSubtarget<X86Subtarget>()),
96#include "X86GenPreLegalizeGICombiner.inc"
98{
99}
100
101bool X86PreLegalizerCombinerImpl::tryCombineAll(MachineInstr &MI) const {
102 return tryCombineAllImpl(MI);
103}
104
105class X86PreLegalizerCombinerLegacy : public MachineFunctionPass {
106public:
107 static char ID;
108
109 X86PreLegalizerCombinerLegacy();
110
111 StringRef getPassName() const override {
112 return "X86PreLegalizerCombinerLegacy";
113 }
114
115 bool runOnMachineFunction(MachineFunction &MF) override;
116
117 void getAnalysisUsage(AnalysisUsage &AU) const override;
118
119private:
120 X86PreLegalizerCombinerImplRuleConfig RuleConfig;
121};
122} // end anonymous namespace
123
124void X86PreLegalizerCombinerLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
125 AU.addRequired<TargetPassConfig>();
126 AU.setPreservesCFG();
128 AU.addRequired<GISelValueTrackingAnalysisLegacy>();
129 AU.addPreserved<GISelValueTrackingAnalysisLegacy>();
130 AU.addRequired<MachineDominatorTreeWrapperPass>();
131 AU.addPreserved<MachineDominatorTreeWrapperPass>();
132 AU.addRequired<GISelCSEAnalysisWrapperPass>();
133 AU.addPreserved<GISelCSEAnalysisWrapperPass>();
135}
136
137X86PreLegalizerCombinerLegacy::X86PreLegalizerCombinerLegacy()
138 : MachineFunctionPass(ID) {
139 if (!RuleConfig.parseCommandLineOption())
140 report_fatal_error("Invalid rule identifier");
141}
142
143bool X86PreLegalizerCombinerLegacy::runOnMachineFunction(MachineFunction &MF) {
144 if (MF.getProperties().hasFailedISel())
145 return false;
146 auto &TPC = getAnalysis<TargetPassConfig>();
147
148 // Enable CSE.
150 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
151 auto *CSEInfo = &Wrapper.get(TPC.getCSEConfig());
152 const Function &F = MF.getFunction();
153 bool EnableOpt =
154 MF.getTarget().getOptLevel() != CodeGenOptLevel::None && !skipFunction(F);
156 &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
158 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
159 CombinerInfo CInfo = createCombinerInfo(EnableOpt, F);
160 X86PreLegalizerCombinerImpl Impl(MF, CInfo, *VT, CSEInfo, RuleConfig, MDT);
161 return Impl.combineMachineInstrs();
162}
163
164char X86PreLegalizerCombinerLegacy::ID = 0;
165INITIALIZE_PASS_BEGIN(X86PreLegalizerCombinerLegacy, DEBUG_TYPE,
166 "Combine X86 machine instrs before legalization", false,
167 false)
171INITIALIZE_PASS_END(X86PreLegalizerCombinerLegacy, DEBUG_TYPE,
172 "Combine X86 machine instrs before legalization", false,
173 false)
174
175namespace llvm {
176
180 if (MF.getProperties().hasFailedISel())
181 return PreservedAnalyses::all();
182
183 X86PreLegalizerCombinerImplRuleConfig RuleConfig;
184 if (!RuleConfig.parseCommandLineOption())
185 report_fatal_error("Invalid rule identifier");
186
187 auto &CSEInfo = MFAM.getResult<GISelCSEAnalysis>(MF);
188 const Function &F = MF.getFunction();
189 bool EnableOpt = MF.getTarget().getOptLevel() != CodeGenOptLevel::None;
192 CombinerInfo CInfo = createCombinerInfo(EnableOpt, F);
193 X86PreLegalizerCombinerImpl Impl(MF, CInfo, VT, CSEInfo.get(), RuleConfig,
194 &MDT);
195 Impl.combineMachineInstrs();
196
201 return PA;
202}
203
205 return new X86PreLegalizerCombinerLegacy();
206}
207} // end namespace llvm
#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.
#define DEBUG_TYPE
IRTranslator LLVM IR MI
Interface for Targets to specify which operations they can successfully select and how the others sho...
#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:270
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
The actual analysis pass wrapper.
Definition CSEInfo.h:242
Simple wrapper that does the following.
Definition CSEInfo.h:212
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.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
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
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Target-Independent Code Generator Pass Configuration Options.
PreservedAnalyses run(MachineFunction &MF, MachineFunctionAnalysisManager &MFAM)
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.
AnalysisManager< MachineFunction > MachineFunctionAnalysisManager
LLVM_ABI PreservedAnalyses getMachineFunctionPassPreservedAnalyses()
Returns the minimum set of Analyses that all machine function passes must preserve.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
Definition Error.cpp:163
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition Utils.cpp:1143
FunctionPass * createX86PreLegalizerCombinerLegacy()
bool EnableFullDCE
Whether dead code elimination is performed before each Combiner iteration.