LLVM  15.0.0git
MipsPostLegalizerCombiner.cpp
Go to the documentation of this file.
1 //=== lib/CodeGen/GlobalISel/MipsPostLegalizerCombiner.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 //
9 // This pass does combining of machine instructions at the generic MI level,
10 // after the legalizer.
11 //
12 //===----------------------------------------------------------------------===//
13 
15 #include "Mips.h"
16 #include "MipsLegalizerInfo.h"
17 #include "MipsSubtarget.h"
26 
27 #define DEBUG_TYPE "mips-postlegalizer-combiner"
28 
29 using namespace llvm;
30 using namespace MIPatternMatch;
31 
32 #define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS
33 #include "MipsGenPostLegalizeGICombiner.inc"
34 #undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS
35 
36 namespace {
37 #define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H
38 #include "MipsGenPostLegalizeGICombiner.inc"
39 #undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H
40 
41 class MipsPostLegalizerCombinerInfo final : public CombinerInfo {
42  GISelKnownBits *KB;
43 
44 public:
45  MipsGenPostLegalizerCombinerHelperRuleConfig GeneratedRuleCfg;
46 
47  MipsPostLegalizerCombinerInfo(bool EnableOpt, bool OptSize, bool MinSize,
48  GISelKnownBits *KB, const MipsLegalizerInfo *LI)
49  : CombinerInfo(/*AllowIllegalOps*/ false, /*ShouldLegalizeIllegal*/ true,
50  /*LegalizerInfo*/ LI, EnableOpt, OptSize, MinSize),
51  KB(KB) {
52  if (!GeneratedRuleCfg.parseCommandLineOption())
53  report_fatal_error("Invalid rule identifier");
54  }
55 
56  bool combine(GISelChangeObserver &Observer, MachineInstr &MI,
57  MachineIRBuilder &B) const override;
58 };
59 
62  MachineIRBuilder &B) const {
63 
64  CombinerHelper Helper(Observer, B, KB,
65  /*DominatorTree*/ nullptr, LInfo);
66  MipsGenPostLegalizerCombinerHelper Generated(GeneratedRuleCfg, Helper);
67  return Generated.tryCombineAll(Observer, MI, B, Helper);
68 }
69 
70 #define MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP
71 #include "MipsGenPostLegalizeGICombiner.inc"
72 #undef MIPSPOSTLEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP
73 
74 // Pass boilerplate
75 // ================
76 
77 class MipsPostLegalizerCombiner : public MachineFunctionPass {
78 public:
79  static char ID;
80 
81  MipsPostLegalizerCombiner(bool IsOptNone = false);
82 
83  StringRef getPassName() const override {
84  return "MipsPostLegalizerCombiner";
85  }
86 
87  bool runOnMachineFunction(MachineFunction &MF) override;
88 
89  void getAnalysisUsage(AnalysisUsage &AU) const override;
90 
91 private:
92  bool IsOptNone;
93 };
94 } // end anonymous namespace
95 
96 void MipsPostLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
98  AU.setPreservesCFG();
102  if (!IsOptNone) {
105  }
107 }
108 
109 MipsPostLegalizerCombiner::MipsPostLegalizerCombiner(bool IsOptNone)
110  : MachineFunctionPass(ID), IsOptNone(IsOptNone) {
111  initializeMipsPostLegalizerCombinerPass(*PassRegistry::getPassRegistry());
112 }
113 
114 bool MipsPostLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
115  if (MF.getProperties().hasProperty(
116  MachineFunctionProperties::Property::FailedISel))
117  return false;
118  auto *TPC = &getAnalysis<TargetPassConfig>();
119  const Function &F = MF.getFunction();
120  bool EnableOpt =
121  MF.getTarget().getOptLevel() != CodeGenOpt::None && !skipFunction(F);
122 
124  const MipsLegalizerInfo *LI =
125  static_cast<const MipsLegalizerInfo *>(ST.getLegalizerInfo());
126 
127  GISelKnownBits *KB = &getAnalysis<GISelKnownBitsAnalysis>().get(MF);
128  MipsPostLegalizerCombinerInfo PCInfo(EnableOpt, F.hasOptSize(),
129  F.hasMinSize(), KB, LI);
130  Combiner C(PCInfo, TPC);
131  return C.combineMachineInstrs(MF, /*CSEInfo*/ nullptr);
132 }
133 
135 INITIALIZE_PASS_BEGIN(MipsPostLegalizerCombiner, DEBUG_TYPE,
136  "Combine Mips machine instrs after legalization", false,
137  false)
140 INITIALIZE_PASS_END(MipsPostLegalizerCombiner, DEBUG_TYPE,
141  "Combine Mips machine instrs after legalization", false,
142  false)
143 
144 namespace llvm {
146  return new MipsPostLegalizerCombiner(IsOptNone);
147 }
148 } // end namespace llvm
MIPatternMatch.h
llvm::TargetMachine::getOptLevel
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
Definition: TargetMachine.cpp:182
CombinerInfo.h
llvm::MachineFunctionProperties::hasProperty
bool hasProperty(Property P) const
Definition: MachineFunction.h:192
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:104
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::GISelKnownBits
Definition: GISelKnownBits.h:29
llvm::Function
Definition: Function.h:60
MipsLegalizerInfo.h
GISelKnownBits.h
llvm::MachineFunctionPass
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
Definition: MachineFunctionPass.h:30
llvm::getSelectionDAGFallbackAnalysisUsage
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition: Utils.cpp:878
llvm::CombinerInfo
Definition: CombinerInfo.h:26
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:103
F
#define F(x, y, z)
Definition: MD5.cpp:55
llvm::createMipsPostLegalizeCombiner
FunctionPass * createMipsPostLegalizeCombiner(bool IsOptNone)
Definition: MipsPostLegalizerCombiner.cpp:145
llvm::GISelKnownBitsAnalysis
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelKnownBitsInfoAnalysis...
Definition: GISelKnownBits.h:113
TargetMachine.h
C
(vector float) vec_cmpeq(*A, *B) C
Definition: README_ALTIVEC.txt:86
llvm::AnalysisUsage
Represent the analysis usage information of a pass.
Definition: PassAnalysisSupport.h:47
Mips.h
llvm::MachineFunction::getProperties
const MachineFunctionProperties & getProperties() const
Get the function properties.
Definition: MachineFunction.h:747
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(MipsPostLegalizerCombiner, DEBUG_TYPE, "Combine Mips machine instrs after legalization", false, false) INITIALIZE_PASS_END(MipsPostLegalizerCombiner
false
Definition: StackSlotColoring.cpp:141
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::report_fatal_error
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:143
llvm::CombinerHelper
Definition: CombinerHelper.h:108
llvm::None
const NoneType None
Definition: None.h:24
llvm::CallingConv::ID
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition: CallingConv.h:24
INITIALIZE_PASS_END
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
Definition: PassSupport.h:58
llvm::TargetPassConfig
Target-Independent Code Generator Pass Configuration Options.
Definition: TargetPassConfig.h:84
llvm::MachineFunction::getSubtarget
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
Definition: MachineFunction.h:656
Combine
Hexagon Vector Combine
Definition: HexagonVectorCombine.cpp:1527
DEBUG_TYPE
#define DEBUG_TYPE
Definition: MipsPostLegalizerCombiner.cpp:27
llvm::MachineIRBuilder
Helper class to build MachineInstr.
Definition: MachineIRBuilder.h:219
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:66
llvm::Combiner
Definition: Combiner.h:26
llvm::ARM_MB::ST
@ ST
Definition: ARMBaseInfo.h:73
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
TargetPassConfig.h
MipsMCTargetDesc.h
llvm::MachineFunction
Definition: MachineFunction.h:257
CombinerHelper.h
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:263
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::AnalysisUsage::addPreserved
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Definition: PassAnalysisSupport.h:98
Combiner.h
llvm::MipsSubtarget
Definition: MipsSubtarget.h:39
llvm::GISelChangeObserver
Abstract class that contains various methods for clients to notify about changes.
Definition: GISelChangeObserver.h:29
llvm::MachineFunction::getFunction
Function & getFunction()
Return the LLVM function that this machine code represents.
Definition: MachineFunction.h:622
llvm::MachineFunction::getTarget
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
Definition: MachineFunction.h:652
llvm::MipsLegalizerInfo
This class provides legalization strategies.
Definition: MipsLegalizerInfo.h:24
MipsSubtarget.h
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:308
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
legalization
Combine Mips machine instrs after legalization
Definition: MipsPostLegalizerCombiner.cpp:141
llvm::MachineDominatorTree
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
Definition: MachineDominators.h:51
combine
vector combine
Definition: VectorCombine.cpp:1549
MachineDominators.h
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:38
llvm::initializeMipsPostLegalizerCombinerPass
void initializeMipsPostLegalizerCombinerPass(PassRegistry &)