LLVM 23.0.0git
SPIRVPreLegalizerCombiner.cpp
Go to the documentation of this file.
1//===-- SPIRVPreLegalizerCombiner.cpp - combine legalization ----*- 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// This pass does combining of machine instructions at the generic MI level,
10// before the legalizer.
11//
12//===----------------------------------------------------------------------===//
13
14#include "SPIRV.h"
15#include "SPIRVCombinerHelper.h"
26
27#define GET_GICOMBINER_DEPS
28#include "SPIRVGenPreLegalizeGICombiner.inc"
29#undef GET_GICOMBINER_DEPS
30
31#define DEBUG_TYPE "spirv-prelegalizer-combiner"
32
33using namespace llvm;
34using namespace MIPatternMatch;
35
36namespace {
37
38#define GET_GICOMBINER_TYPES
39#include "SPIRVGenPreLegalizeGICombiner.inc"
40#undef GET_GICOMBINER_TYPES
41
42class SPIRVPreLegalizerCombinerImpl : public Combiner {
43protected:
44 const SPIRVCombinerHelper Helper;
45 const SPIRVPreLegalizerCombinerImplRuleConfig &RuleConfig;
46 const SPIRVSubtarget &STI;
47
48public:
49 SPIRVPreLegalizerCombinerImpl(
51 GISelCSEInfo *CSEInfo,
52 const SPIRVPreLegalizerCombinerImplRuleConfig &RuleConfig,
53 const SPIRVSubtarget &STI, MachineDominatorTree *MDT,
54 const LegalizerInfo *LI);
55
56 static const char *getName() { return "SPIRVPreLegalizerCombiner"; }
57
58 bool tryCombineAll(MachineInstr &I) const override;
59
60 bool tryCombineAllImpl(MachineInstr &I) const;
61
62private:
63#define GET_GICOMBINER_CLASS_MEMBERS
64#include "SPIRVGenPreLegalizeGICombiner.inc"
65#undef GET_GICOMBINER_CLASS_MEMBERS
66};
67
68#define GET_GICOMBINER_IMPL
69#include "SPIRVGenPreLegalizeGICombiner.inc"
70#undef GET_GICOMBINER_IMPL
71
72SPIRVPreLegalizerCombinerImpl::SPIRVPreLegalizerCombinerImpl(
74 GISelCSEInfo *CSEInfo,
75 const SPIRVPreLegalizerCombinerImplRuleConfig &RuleConfig,
76 const SPIRVSubtarget &STI, MachineDominatorTree *MDT,
77 const LegalizerInfo *LI)
78 : Combiner(MF, CInfo, &VT, CSEInfo),
79 Helper(Observer, B, /*IsPreLegalize*/ true, &VT, MDT, LI, STI),
80 RuleConfig(RuleConfig), STI(STI),
82#include "SPIRVGenPreLegalizeGICombiner.inc"
84{
85}
86
87bool SPIRVPreLegalizerCombinerImpl::tryCombineAll(MachineInstr &MI) const {
88 return tryCombineAllImpl(MI);
89}
90
91// Pass boilerplate
92// ================
93
94class SPIRVPreLegalizerCombiner : public MachineFunctionPass {
95public:
96 static char ID;
97
98 SPIRVPreLegalizerCombiner();
99
100 StringRef getPassName() const override { return "SPIRVPreLegalizerCombiner"; }
101
102 bool runOnMachineFunction(MachineFunction &MF) override;
103
104 void getAnalysisUsage(AnalysisUsage &AU) const override;
105
106private:
107 SPIRVPreLegalizerCombinerImplRuleConfig RuleConfig;
108};
109
110} // end anonymous namespace
111
112void SPIRVPreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
113 AU.setPreservesCFG();
115 AU.addRequired<GISelValueTrackingAnalysisLegacy>();
116 AU.addPreserved<GISelValueTrackingAnalysisLegacy>();
117 AU.addRequired<MachineDominatorTreeWrapperPass>();
118 AU.addPreserved<MachineDominatorTreeWrapperPass>();
120}
121
122SPIRVPreLegalizerCombiner::SPIRVPreLegalizerCombiner()
123 : MachineFunctionPass(ID) {
124 if (!RuleConfig.parseCommandLineOption())
125 report_fatal_error("Invalid rule identifier");
126}
127
128bool SPIRVPreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
129 if (MF.getProperties().hasFailedISel())
130 return false;
131
133 const auto *LI = ST.getLegalizerInfo();
134
135 const Function &F = MF.getFunction();
136 bool EnableOpt =
137 MF.getTarget().getOptLevel() != CodeGenOptLevel::None && !skipFunction(F);
139 &getAnalysis<GISelValueTrackingAnalysisLegacy>().get(MF);
141 &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
142 CombinerInfo CInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
143 /*LegalizerInfo*/ nullptr, EnableOpt, F.hasOptSize(),
144 F.hasMinSize());
145 // Disable fixed-point iteration to reduce compile-time
146 CInfo.MaxIterations = 1;
147 CInfo.ObserverLvl = CombinerInfo::ObserverLevel::SinglePass;
148 // This is the first Combiner, so the input IR might contain dead
149 // instructions.
150 CInfo.EnableFullDCE = false;
151 SPIRVPreLegalizerCombinerImpl Impl(MF, CInfo, *VT, /*CSEInfo*/ nullptr,
152 RuleConfig, ST, MDT, LI);
153 return Impl.combineMachineInstrs();
154}
155
156char SPIRVPreLegalizerCombiner::ID = 0;
157INITIALIZE_PASS_BEGIN(SPIRVPreLegalizerCombiner, DEBUG_TYPE,
158 "Combine SPIRV machine instrs before legalization", false,
159 false)
161INITIALIZE_PASS_END(SPIRVPreLegalizerCombiner, DEBUG_TYPE,
162 "Combine SPIRV machine instrs before legalization", false,
163 false)
164
165namespace llvm {
167 return new SPIRVPreLegalizerCombiner();
168}
169} // end namespace llvm
#define GET_GICOMBINER_CONSTRUCTOR_INITS
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
Provides analysis for continuously CSEing during GISel passes.
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
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.
#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.
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:33
FunctionPass class - This class is used to implement most global optimizations.
Definition Pass.h:314
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.
const TargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Representation of each machine instruction.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
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.
FunctionPass * createSPIRVPreLegalizerCombiner()
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:1185
@ SinglePass
Enables Observer-based DCE and additional heuristics that retry combining defined and used instructio...