LLVM  14.0.0git
MipsPreLegalizerCombiner.cpp
Go to the documentation of this file.
1 //=== lib/CodeGen/GlobalISel/MipsPreLegalizerCombiner.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 // before the legalizer.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #include "MipsTargetMachine.h"
20 #include "llvm/InitializePasses.h"
21 
22 #define DEBUG_TYPE "mips-prelegalizer-combiner"
23 
24 using namespace llvm;
25 
26 namespace {
27 class MipsPreLegalizerCombinerInfo : public CombinerInfo {
28 public:
29  MipsPreLegalizerCombinerInfo()
30  : CombinerInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
31  /*LegalizerInfo*/ nullptr, /*EnableOpt*/ false,
32  /*EnableOptSize*/ false, /*EnableMinSize*/ false) {}
33  virtual bool combine(GISelChangeObserver &Observer, MachineInstr &MI,
34  MachineIRBuilder &B) const override;
35 };
36 
39  MachineIRBuilder &B) const {
40  CombinerHelper Helper(Observer, B);
41 
42  switch (MI.getOpcode()) {
43  default:
44  return false;
45  case TargetOpcode::G_MEMCPY_INLINE:
46  return Helper.tryEmitMemcpyInline(MI);
47  case TargetOpcode::G_LOAD:
48  case TargetOpcode::G_SEXTLOAD:
49  case TargetOpcode::G_ZEXTLOAD: {
50  // Don't attempt to combine non power of 2 loads or unaligned loads when
51  // subtarget doesn't support them.
52  auto MMO = *MI.memoperands_begin();
53  const MipsSubtarget &STI =
54  static_cast<const MipsSubtarget &>(MI.getMF()->getSubtarget());
55  if (!isPowerOf2_64(MMO->getSize()))
56  return false;
57  bool isUnaligned = MMO->getAlign() < MMO->getSize();
58  if (!STI.systemSupportsUnalignedAccess() && isUnaligned)
59  return false;
60 
61  return Helper.tryCombineExtendingLoads(MI);
62  }
63  }
64 
65  return false;
66 }
67 
68 // Pass boilerplate
69 // ================
70 
71 class MipsPreLegalizerCombiner : public MachineFunctionPass {
72 public:
73  static char ID;
74 
75  MipsPreLegalizerCombiner();
76 
77  StringRef getPassName() const override { return "MipsPreLegalizerCombiner"; }
78 
79  bool runOnMachineFunction(MachineFunction &MF) override;
80 
81  void getAnalysisUsage(AnalysisUsage &AU) const override;
82 };
83 } // end anonymous namespace
84 
85 void MipsPreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
87  AU.setPreservesCFG();
90 }
91 
92 MipsPreLegalizerCombiner::MipsPreLegalizerCombiner() : MachineFunctionPass(ID) {
93  initializeMipsPreLegalizerCombinerPass(*PassRegistry::getPassRegistry());
94 }
95 
96 bool MipsPreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
97  if (MF.getProperties().hasProperty(
98  MachineFunctionProperties::Property::FailedISel))
99  return false;
100  auto *TPC = &getAnalysis<TargetPassConfig>();
101  MipsPreLegalizerCombinerInfo PCInfo;
102  Combiner C(PCInfo, TPC);
103  return C.combineMachineInstrs(MF, nullptr);
104 }
105 
107 INITIALIZE_PASS_BEGIN(MipsPreLegalizerCombiner, DEBUG_TYPE,
108  "Combine Mips machine instrs before legalization", false,
109  false)
111 INITIALIZE_PASS_END(MipsPreLegalizerCombiner, DEBUG_TYPE,
112  "Combine Mips machine instrs before legalization", false,
113  false)
114 
115 namespace llvm {
117  return new MipsPreLegalizerCombiner();
118 }
119 } // end namespace llvm
MIPatternMatch.h
CombinerInfo.h
llvm::MachineFunctionProperties::hasProperty
bool hasProperty(Property P) const
Definition: MachineFunction.h:165
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:105
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
llvm::MipsSubtarget::systemSupportsUnalignedAccess
bool systemSupportsUnalignedAccess() const
Does the system support unaligned memory access.
Definition: MipsSubtarget.h:373
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:863
llvm::CombinerHelper::tryCombineExtendingLoads
bool tryCombineExtendingLoads(MachineInstr &MI)
If MI is extend that consumes the result of a load, try to combine it.
Definition: CombinerHelper.cpp:453
MipsTargetMachine.h
llvm::CombinerInfo
Definition: CombinerInfo.h:27
llvm::MachineFunctionPass::getAnalysisUsage
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Definition: MachineFunctionPass.cpp:102
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
llvm::MachineFunction::getProperties
const MachineFunctionProperties & getProperties() const
Get the function properties.
Definition: MachineFunction.h:717
llvm::createMipsPreLegalizeCombiner
FunctionPass * createMipsPreLegalizeCombiner()
Definition: MipsPreLegalizerCombiner.cpp:116
false
Definition: StackSlotColoring.cpp:142
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::CombinerHelper
Definition: CombinerHelper.h:104
INITIALIZE_PASS_BEGIN
INITIALIZE_PASS_BEGIN(MipsPreLegalizerCombiner, DEBUG_TYPE, "Combine Mips machine instrs before legalization", false, false) INITIALIZE_PASS_END(MipsPreLegalizerCombiner
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
Combine
Hexagon Vector Combine
Definition: HexagonVectorCombine.cpp:1525
llvm::MachineIRBuilder
Helper class to build MachineInstr.
Definition: MachineIRBuilder.h:212
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
llvm::Combiner
Definition: Combiner.h:27
INITIALIZE_PASS_DEPENDENCY
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)
TargetPassConfig.h
llvm::MachineFunction
Definition: MachineFunction.h:230
legalization
Combine Mips machine instrs before legalization
Definition: MipsPreLegalizerCombiner.cpp:112
CombinerHelper.h
llvm::AnalysisUsage::setPreservesCFG
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:253
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
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::CombinerHelper::tryEmitMemcpyInline
bool tryEmitMemcpyInline(MachineInstr &MI)
Emit loads and stores that perform the given memcpy.
Definition: CombinerHelper.cpp:1204
llvm::initializeMipsPreLegalizerCombinerPass
void initializeMipsPreLegalizerCombinerPass(PassRegistry &)
DEBUG_TYPE
#define DEBUG_TYPE
Definition: MipsPreLegalizerCombiner.cpp:22
llvm::FunctionPass
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:298
llvm::AnalysisUsage::addRequired
AnalysisUsage & addRequired()
Definition: PassAnalysisSupport.h:75
combine
vector combine
Definition: VectorCombine.cpp:1161
llvm::isPowerOf2_64
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition: MathExtras.h:496
InitializePasses.h
machine
coro Split coroutine into a set of functions driving its state machine
Definition: CoroSplit.cpp:2277
llvm::Intrinsic::ID
unsigned ID
Definition: TargetTransformInfo.h:37