LLVM 24.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"
30
31#define GET_GICOMBINER_DEPS
32#include "X86GenPreLegalizeGICombiner.inc"
33#undef GET_GICOMBINER_DEPS
34
35#define DEBUG_TYPE "x86-prelegalizer-combiner"
36
37using namespace llvm;
38using namespace MIPatternMatch;
39
40namespace {
41
42CombinerInfo createCombinerInfo(bool EnableOpt, const Function &F) {
43 CombinerInfo CInfo(/*AllowIllegalOps=*/true, /*ShouldLegalizeIllegal=*/false,
44 nullptr, EnableOpt, F.hasOptSize(), F.hasMinSize());
45
46 // This is the first Combiner, so the input IR might contain dead
47 // instructions.
48 CInfo.EnableFullDCE = true;
49 return CInfo;
50}
51
52#define GET_GICOMBINER_TYPES
53#include "X86GenPreLegalizeGICombiner.inc"
54#undef GET_GICOMBINER_TYPES
55
56class X86PreLegalizerCombinerImpl : public Combiner {
57protected:
58 const CombinerHelper Helper;
59 const X86PreLegalizerCombinerImplRuleConfig &RuleConfig;
60 const X86Subtarget &STI;
61
62public:
63 X86PreLegalizerCombinerImpl(
65 GISelCSEInfo *CSEInfo,
66 const X86PreLegalizerCombinerImplRuleConfig &RuleConfig,
68
69 static const char *getName() { return "X86PreLegalizerCombiner"; }
70
71 bool tryCombineAll(MachineInstr &I) const override;
72
73 bool tryCombineAllImpl(MachineInstr &I) const;
74
75private:
76#define GET_GICOMBINER_CLASS_MEMBERS
77#include "X86GenPreLegalizeGICombiner.inc"
78#undef GET_GICOMBINER_CLASS_MEMBERS
79};
80
81#define GET_GICOMBINER_IMPL
82#include "X86GenPreLegalizeGICombiner.inc"
83#undef GET_GICOMBINER_IMPL
84
85X86PreLegalizerCombinerImpl::X86PreLegalizerCombinerImpl(
87 GISelCSEInfo *CSEInfo,
88 const X86PreLegalizerCombinerImplRuleConfig &RuleConfig,
90 : Combiner(MF, CInfo, &VT, CSEInfo),
91 Helper(Observer, B, /*IsPreLegalize=*/true, &VT, MDT,
92 MF.getSubtarget<X86Subtarget>().getLegalizerInfo()),
93 RuleConfig(RuleConfig), STI(MF.getSubtarget<X86Subtarget>()),
95#include "X86GenPreLegalizeGICombiner.inc"
97{
98}
99
100bool X86PreLegalizerCombinerImpl::tryCombineAll(MachineInstr &MI) const {
101 return tryCombineAllImpl(MI);
102}
103
104class X86PreLegalizerCombinerLegacy : public MachineFunctionPass {
105public:
106 static char ID;
107
108 X86PreLegalizerCombinerLegacy();
109
110 StringRef getPassName() const override {
111 return "X86PreLegalizerCombinerLegacy";
112 }
113
114 bool runOnMachineFunction(MachineFunction &MF) override;
115
116 void getAnalysisUsage(AnalysisUsage &AU) const override;
117
118private:
119 X86PreLegalizerCombinerImplRuleConfig RuleConfig;
120};
121} // end anonymous namespace
122
123void X86PreLegalizerCombinerLegacy::getAnalysisUsage(AnalysisUsage &AU) const {
124 AU.addRequired<TargetPassConfig>();
125 AU.setPreservesCFG();
127 AU.addRequired<GISelValueTrackingAnalysisLegacy>();
128 AU.addPreserved<GISelValueTrackingAnalysisLegacy>();
129 AU.addRequired<MachineDominatorTreeWrapperPass>();
130 AU.addRequired<GISelCSEAnalysisWrapperPass>();
131 AU.addPreserved<GISelCSEAnalysisWrapperPass>();
133}
134
135X86PreLegalizerCombinerLegacy::X86PreLegalizerCombinerLegacy()
136 : MachineFunctionPass(ID) {
137 if (!RuleConfig.parseCommandLineOption())
138 report_fatal_error("Invalid rule identifier");
139}
140
141bool X86PreLegalizerCombinerLegacy::runOnMachineFunction(MachineFunction &MF) {
142 if (MF.getProperties().hasFailedISel())
143 return false;
144 auto &TPC = getAnalysis<TargetPassConfig>();
145
146 // Enable CSE.
148 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
149 auto *CSEInfo = &Wrapper.get(TPC.getCSEConfig());
150 const Function &F = MF.getFunction();
151 bool EnableOpt =
152 MF.getTarget().getOptLevel() != CodeGenOptLevel::None && !skipFunction(F);
154 &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
156 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
157 CombinerInfo CInfo = createCombinerInfo(EnableOpt, F);
158 X86PreLegalizerCombinerImpl Impl(MF, CInfo, *VT, CSEInfo, RuleConfig, MDT);
159 return Impl.combineMachineInstrs();
160}
161
162char X86PreLegalizerCombinerLegacy::ID = 0;
163INITIALIZE_PASS_BEGIN(X86PreLegalizerCombinerLegacy, DEBUG_TYPE,
164 "Combine X86 machine instrs before legalization", false,
165 false)
169INITIALIZE_PASS_END(X86PreLegalizerCombinerLegacy, DEBUG_TYPE,
170 "Combine X86 machine instrs before legalization", false,
171 false)
172
173namespace llvm {
174
178 if (MF.getProperties().hasFailedISel())
179 return PreservedAnalyses::all();
180
181 X86PreLegalizerCombinerImplRuleConfig RuleConfig;
182 if (!RuleConfig.parseCommandLineOption())
183 report_fatal_error("Invalid rule identifier");
184
185 auto &CSEInfo = MFAM.getResult<GISelCSEAnalysis>(MF);
186 const Function &F = MF.getFunction();
187 bool EnableOpt = MF.getTarget().getOptLevel() != CodeGenOptLevel::None;
190 CombinerInfo CInfo = createCombinerInfo(EnableOpt, F);
191 X86PreLegalizerCombinerImpl Impl(MF, CInfo, VT, CSEInfo.get(), RuleConfig,
192 &MDT);
193 Impl.combineMachineInstrs();
194
199 return PA;
200}
201
203 return new X86PreLegalizerCombinerLegacy();
204}
205} // 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: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
The actual analysis pass wrapper.
Definition CSEInfo.h:244
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.
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)
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:1137
FunctionPass * createX86PreLegalizerCombinerLegacy()
bool EnableFullDCE
Whether dead code elimination is performed before each Combiner iteration.