LLVM 24.0.0git
WebAssemblyPostLegalizerCombiner.cpp
Go to the documentation of this file.
1//=== WebAssemblyPostLegalizerCombiner.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/// Combines which don't rely on instruction legality should go in the
15/// WebAssemblyPreLegalizerCombiner.
16///
17//===----------------------------------------------------------------------===//
18
19#include "WebAssembly.h"
31
32#define GET_GICOMBINER_DEPS
33#include "WebAssemblyGenPostLegalizeGICombiner.inc"
34#undef GET_GICOMBINER_DEPS
35
36#define DEBUG_TYPE "wasm-postlegalizer-combiner"
37
38using namespace llvm;
39
40namespace {
41
42#define GET_GICOMBINER_TYPES
43#include "WebAssemblyGenPostLegalizeGICombiner.inc"
44#undef GET_GICOMBINER_TYPES
45
46class WebAssemblyPostLegalizerCombinerImpl : public Combiner {
47protected:
48 const CombinerHelper Helper;
49 const WebAssemblyPostLegalizerCombinerImplRuleConfig &RuleConfig;
50 const WebAssemblySubtarget &STI;
51
52public:
53 WebAssemblyPostLegalizerCombinerImpl(
55 GISelCSEInfo *CSEInfo,
56 const WebAssemblyPostLegalizerCombinerImplRuleConfig &RuleConfig,
58 const LegalizerInfo *LI);
59
60 static const char *getName() { return "WebAssemblyPostLegalizerCombiner"; }
61
62 bool tryCombineAll(MachineInstr &I) const override;
63
64private:
65#define GET_GICOMBINER_CLASS_MEMBERS
66#include "WebAssemblyGenPostLegalizeGICombiner.inc"
67#undef GET_GICOMBINER_CLASS_MEMBERS
68};
69
70#define GET_GICOMBINER_IMPL
71#include "WebAssemblyGenPostLegalizeGICombiner.inc"
72#undef GET_GICOMBINER_IMPL
73
74WebAssemblyPostLegalizerCombinerImpl::WebAssemblyPostLegalizerCombinerImpl(
76 GISelCSEInfo *CSEInfo,
77 const WebAssemblyPostLegalizerCombinerImplRuleConfig &RuleConfig,
79 const LegalizerInfo *LI)
80 : Combiner(MF, CInfo, &VT, CSEInfo),
81 Helper(Observer, B, /*IsPreLegalize*/ false, &VT, MDT, LI),
82 RuleConfig(RuleConfig), STI(STI),
84#include "WebAssemblyGenPostLegalizeGICombiner.inc"
86{
87}
88
89class WebAssemblyPostLegalizerCombiner : public MachineFunctionPass {
90public:
91 static char ID;
92
93 WebAssemblyPostLegalizerCombiner();
94
95 StringRef getPassName() const override {
96 return "WebAssemblyPostLegalizerCombiner";
97 }
98
99 bool runOnMachineFunction(MachineFunction &MF) override;
100 void getAnalysisUsage(AnalysisUsage &AU) const override;
101
102private:
103 WebAssemblyPostLegalizerCombinerImplRuleConfig RuleConfig;
104};
105} // end anonymous namespace
106
107void WebAssemblyPostLegalizerCombiner::getAnalysisUsage(
108 AnalysisUsage &AU) const {
110 AU.setPreservesCFG();
118}
119
120WebAssemblyPostLegalizerCombiner::WebAssemblyPostLegalizerCombiner()
121 : MachineFunctionPass(ID) {
122 if (!RuleConfig.parseCommandLineOption())
123 report_fatal_error("Invalid rule identifier");
124}
125
126bool WebAssemblyPostLegalizerCombiner::runOnMachineFunction(
127 MachineFunction &MF) {
128 if (MF.getProperties().hasFailedISel())
129 return false;
130 assert(MF.getProperties().hasLegalized() && "Expected a legalized function?");
131 auto *TPC = &getAnalysis<TargetPassConfig>();
132 const Function &F = MF.getFunction();
133 bool EnableOpt =
134 MF.getTarget().getOptLevel() != CodeGenOptLevel::None && !skipFunction(F);
135
137 const auto *LI = ST.getLegalizerInfo();
138
140 &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
141 MachineDominatorTree *MDT = nullptr;
142 GISelCSEInfo *CSEInfo = nullptr;
143
144 MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
145
147 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
148 CSEInfo = &Wrapper.get(TPC->getCSEConfig());
149
150 CombinerInfo CInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
151 /*LegalizerInfo*/ nullptr, EnableOpt, F.hasOptSize(),
152 F.hasMinSize());
153 // Disable fixed-point iteration to reduce compile-time
154 CInfo.MaxIterations = 1;
155 CInfo.ObserverLvl = CombinerInfo::ObserverLevel::SinglePass;
156 // Legalizer performs DCE, so a full DCE pass is unnecessary.
157 CInfo.EnableFullDCE = false;
158 WebAssemblyPostLegalizerCombinerImpl Impl(MF, CInfo, *VT, CSEInfo, RuleConfig,
159 ST, MDT, LI);
160 return Impl.combineMachineInstrs();
161}
162
163char WebAssemblyPostLegalizerCombiner::ID = 0;
164INITIALIZE_PASS_BEGIN(WebAssemblyPostLegalizerCombiner, DEBUG_TYPE,
165 "Combine WebAssembly MachineInstrs after legalization",
166 false, false)
169INITIALIZE_PASS_END(WebAssemblyPostLegalizerCombiner, DEBUG_TYPE,
170 "Combine WebAssembly MachineInstrs after legalization",
172
174 return new WebAssemblyPostLegalizerCombiner();
175}
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.
Provides analysis for querying information about KnownBits during GISel passes.
#define DEBUG_TYPE
#define F(x, y, z)
Definition MD5.cpp:54
#define I(x, y, z)
Definition MD5.cpp:57
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.
This file declares the WebAssembly-specific subclass of TargetMachine.
This file contains the entry points for global functions defined in the LLVM WebAssembly back-end.
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.
LLVM_ABI void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition Pass.cpp:275
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:243
Simple wrapper that does the following.
Definition CSEInfo.h:213
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...
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...
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.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
virtual StringRef getPassName() const
getPassName - Return a nice clean name for a pass.
Definition Pass.cpp:85
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Target-Independent Code Generator Pass Configuration Options.
This is an optimization pass for GlobalISel generic memory operations.
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 * createWebAssemblyPostLegalizerCombiner()
@ SinglePass
Enables Observer-based DCE and additional heuristics that retry combining defined and used instructio...