LLVM 23.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(
54 MachineFunction &MF, CombinerInfo &CInfo, const TargetPassConfig *TPC,
55 GISelValueTracking &VT, 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(
75 MachineFunction &MF, CombinerInfo &CInfo, const TargetPassConfig *TPC,
76 GISelValueTracking &VT, GISelCSEInfo *CSEInfo,
77 const WebAssemblyPostLegalizerCombinerImplRuleConfig &RuleConfig,
79 const LegalizerInfo *LI)
80 : Combiner(MF, CInfo, TPC, &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();
119}
120
121WebAssemblyPostLegalizerCombiner::WebAssemblyPostLegalizerCombiner()
123 if (!RuleConfig.parseCommandLineOption())
124 report_fatal_error("Invalid rule identifier");
125}
126
127bool WebAssemblyPostLegalizerCombiner::runOnMachineFunction(
128 MachineFunction &MF) {
129 if (MF.getProperties().hasFailedISel())
130 return false;
131 assert(MF.getProperties().hasLegalized() && "Expected a legalized function?");
132 auto *TPC = &getAnalysis<TargetPassConfig>();
133 const Function &F = MF.getFunction();
134 bool EnableOpt =
135 MF.getTarget().getOptLevel() != CodeGenOptLevel::None && !skipFunction(F);
136
138 const auto *LI = ST.getLegalizerInfo();
139
141 &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
142 MachineDominatorTree *MDT = nullptr;
143 GISelCSEInfo *CSEInfo = nullptr;
144
145 MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
146
148 getAnalysis<GISelCSEAnalysisWrapperPass>().getCSEWrapper();
149 CSEInfo = &Wrapper.get(TPC->getCSEConfig());
150
151 CombinerInfo CInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
152 /*LegalizerInfo*/ nullptr, EnableOpt, F.hasOptSize(),
153 F.hasMinSize());
154 // Disable fixed-point iteration to reduce compile-time
155 CInfo.MaxIterations = 1;
156 CInfo.ObserverLvl = CombinerInfo::ObserverLevel::SinglePass;
157 // Legalizer performs DCE, so a full DCE pass is unnecessary.
158 CInfo.EnableFullDCE = false;
159 WebAssemblyPostLegalizerCombinerImpl Impl(MF, CInfo, TPC, *VT, CSEInfo,
160 RuleConfig, ST, MDT, LI);
161 return Impl.combineMachineInstrs();
162}
163
164char WebAssemblyPostLegalizerCombiner::ID = 0;
165INITIALIZE_PASS_BEGIN(WebAssemblyPostLegalizerCombiner, DEBUG_TYPE,
166 "Combine WebAssembly MachineInstrs after legalization",
167 false, false)
170INITIALIZE_PASS_END(WebAssemblyPostLegalizerCombiner, DEBUG_TYPE,
171 "Combine WebAssembly MachineInstrs after legalization",
173
175 return new WebAssemblyPostLegalizerCombiner();
176}
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:270
Combiner implementation.
Definition Combiner.h:34
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...
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.
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 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:1190
FunctionPass * createWebAssemblyPostLegalizerCombiner()
@ SinglePass
Enables Observer-based DCE and additional heuristics that retry combining defined and used instructio...