LLVM 23.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"
23#include "llvm/ADT/STLExtras.h"
41#include "llvm/Support/Debug.h"
42
43#define GET_GICOMBINER_DEPS
44#include "X86GenPostLegalizeGICombiner.inc"
45#undef GET_GICOMBINER_DEPS
46
47#define DEBUG_TYPE "X86-postlegalizer-combiner"
48
49using namespace llvm;
50using namespace MIPatternMatch;
51
52namespace {
53
54#define GET_GICOMBINER_TYPES
55#include "X86GenPostLegalizeGICombiner.inc"
56#undef GET_GICOMBINER_TYPES
57
58class X86PostLegalizerCombinerImpl : public Combiner {
59protected:
60 const CombinerHelper Helper;
61 const X86PostLegalizerCombinerImplRuleConfig &RuleConfig;
62 const X86Subtarget &STI;
63
64public:
65 X86PostLegalizerCombinerImpl(
66 MachineFunction &MF, CombinerInfo &CInfo, const TargetPassConfig *TPC,
67 GISelValueTracking &VT, GISelCSEInfo *CSEInfo,
68 const X86PostLegalizerCombinerImplRuleConfig &RuleConfig,
69 const X86Subtarget &STI, MachineDominatorTree *MDT,
70 const LegalizerInfo *LI);
71
72 static const char *getName() { return "X86PostLegalizerCombiner"; }
73
74 bool tryCombineAll(MachineInstr &I) const override;
75 bool tryCombineAllImpl(MachineInstr &I) const;
76
77private:
78#define GET_GICOMBINER_CLASS_MEMBERS
79#include "X86GenPostLegalizeGICombiner.inc"
80#undef GET_GICOMBINER_CLASS_MEMBERS
81};
82
83#define GET_GICOMBINER_IMPL
84#include "X86GenPostLegalizeGICombiner.inc"
85#undef GET_GICOMBINER_IMPL
86
87X86PostLegalizerCombinerImpl::X86PostLegalizerCombinerImpl(
88 MachineFunction &MF, CombinerInfo &CInfo, const TargetPassConfig *TPC,
89 GISelValueTracking &VT, GISelCSEInfo *CSEInfo,
90 const X86PostLegalizerCombinerImplRuleConfig &RuleConfig,
91 const X86Subtarget &STI, MachineDominatorTree *MDT, const LegalizerInfo *LI)
92 : Combiner(MF, CInfo, TPC, &VT, CSEInfo),
93 Helper(Observer, B, /*IsPreLegalize=*/false, &VT, MDT, LI),
94 RuleConfig(RuleConfig), STI(STI),
96#include "X86GenPostLegalizeGICombiner.inc"
98{
99}
100
101bool X86PostLegalizerCombinerImpl::tryCombineAll(MachineInstr &MI) const {
102 return tryCombineAllImpl(MI);
103}
104
105class X86PostLegalizerCombiner : public MachineFunctionPass {
106public:
107 static char ID;
108
109 X86PostLegalizerCombiner();
110
111 StringRef getPassName() const override { return "X86PostLegalizerCombiner"; }
112
113 bool runOnMachineFunction(MachineFunction &MF) override;
114 void getAnalysisUsage(AnalysisUsage &AU) const override;
115
116private:
117 X86PostLegalizerCombinerImplRuleConfig RuleConfig;
118};
119} // end anonymous namespace
120
121void X86PostLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
122 AU.addRequired<TargetPassConfig>();
123 AU.setPreservesCFG();
125 AU.addRequired<GISelValueTrackingAnalysisLegacy>();
126 AU.addPreserved<GISelValueTrackingAnalysisLegacy>();
127 // This is only added when processing level is not OptNone.
128 AU.addRequired<MachineDominatorTreeWrapperPass>();
129 AU.addPreserved<MachineDominatorTreeWrapperPass>();
130 AU.addRequired<GISelCSEAnalysisWrapperPass>();
131 AU.addPreserved<GISelCSEAnalysisWrapperPass>();
132
134}
135
136X86PostLegalizerCombiner::X86PostLegalizerCombiner() : MachineFunctionPass(ID) {
137 if (!RuleConfig.parseCommandLineOption())
138 reportFatalInternalError("Invalid rule identifier");
139}
140
141bool X86PostLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
142 if (MF.getProperties().hasFailedISel())
143 return false;
144 assert(MF.getProperties().hasLegalized() && "Expected a legalized function?");
145 auto *TPC = &getAnalysis<TargetPassConfig>();
146 const Function &F = MF.getFunction();
147
149 const auto *LI = ST.getLegalizerInfo();
150
152 &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
154 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
156 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
157 auto *CSEInfo = &Wrapper.get(TPC->getCSEConfig());
158
159 CombinerInfo CInfo(/*AllowIllegalOps=*/true,
160 /*ShouldLegalizeIllegal=*/false,
161 /*LegalizerInfo=*/nullptr, !skipFunction(F),
162 F.hasOptSize(), F.hasMinSize());
163 // Disable fixed-point iteration to reduce compile-time
164 CInfo.MaxIterations = 1;
165 CInfo.ObserverLvl = CombinerInfo::ObserverLevel::SinglePass;
166 // Legalizer performs DCE, so a full DCE pass is unnecessary.
167 CInfo.EnableFullDCE = false;
168 X86PostLegalizerCombinerImpl Impl(MF, CInfo, TPC, *VT, CSEInfo, RuleConfig,
169 ST, MDT, LI);
170 return Impl.combineMachineInstrs();
171}
172
173char X86PostLegalizerCombiner::ID = 0;
174INITIALIZE_PASS_BEGIN(X86PostLegalizerCombiner, DEBUG_TYPE,
175 "Combine X86 MachineInstrs after legalization", false,
176 false)
179INITIALIZE_PASS_END(X86PostLegalizerCombiner, DEBUG_TYPE,
180 "Combine X86 MachineInstrs after legalization", false,
181 false)
182
183namespace llvm {
185 return new X86PostLegalizerCombiner();
186}
187} // 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 file implements a version of MachineIRBuilder which CSEs insts within a MachineBasicBlock.
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
Declares convenience wrapper classes for interpreting MachineInstr instances as specific generic oper...
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)
This file contains some templates that are useful if you are working with the STL at all.
Target-Independent Code Generator Pass Configuration Options pass.
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
Combiner implementation.
Definition Combiner.h:34
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
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...
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.
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.
Target-Independent Code Generator Pass Configuration Options.
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 Types.h:26
LLVM_ABI void reportFatalInternalError(Error Err)
Report a fatal error that indicates a bug in LLVM.
Definition Error.cpp:173
LLVM_ABI void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition Utils.cpp:1190
FunctionPass * createX86PostLegalizerCombiner()
@ SinglePass
Enables Observer-based DCE and additional heuristics that retry combining defined and used instructio...