LLVM  11.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_LOAD:
46  case TargetOpcode::G_SEXTLOAD:
47  case TargetOpcode::G_ZEXTLOAD: {
48  // Don't attempt to combine non power of 2 loads or unaligned loads when
49  // subtarget doesn't support them.
50  auto MMO = *MI.memoperands_begin();
51  const MipsSubtarget &STI =
52  static_cast<const MipsSubtarget &>(MI.getMF()->getSubtarget());
53  if (!isPowerOf2_64(MMO->getSize()))
54  return false;
55  bool isUnaligned = MMO->getAlign() < MMO->getSize();
56  if (!STI.systemSupportsUnalignedAccess() && isUnaligned)
57  return false;
58 
59  return Helper.tryCombineExtendingLoads(MI);
60  }
61  }
62 
63  return false;
64 }
65 
66 // Pass boilerplate
67 // ================
68 
69 class MipsPreLegalizerCombiner : public MachineFunctionPass {
70 public:
71  static char ID;
72 
73  MipsPreLegalizerCombiner();
74 
75  StringRef getPassName() const override { return "MipsPreLegalizerCombiner"; }
76 
77  bool runOnMachineFunction(MachineFunction &MF) override;
78 
79  void getAnalysisUsage(AnalysisUsage &AU) const override;
80 };
81 } // end anonymous namespace
82 
83 void MipsPreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
85  AU.setPreservesCFG();
88 }
89 
90 MipsPreLegalizerCombiner::MipsPreLegalizerCombiner() : MachineFunctionPass(ID) {
92 }
93 
94 bool MipsPreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
95  if (MF.getProperties().hasProperty(
97  return false;
98  auto *TPC = &getAnalysis<TargetPassConfig>();
99  MipsPreLegalizerCombinerInfo PCInfo;
100  Combiner C(PCInfo, TPC);
101  return C.combineMachineInstrs(MF, nullptr);
102 }
103 
105 INITIALIZE_PASS_BEGIN(MipsPreLegalizerCombiner, DEBUG_TYPE,
106  "Combine Mips machine instrs before legalization", false,
107  false)
109 INITIALIZE_PASS_END(MipsPreLegalizerCombiner, DEBUG_TYPE,
110  "Combine Mips machine instrs before legalization", false,
111  false)
112 
113 namespace llvm {
115  return new MipsPreLegalizerCombiner();
116 }
117 } // end namespace llvm
uint64_t CallInst * C
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
coro Split coroutine into a set of functions driving its state machine
Definition: CoroSplit.cpp:1904
const MachineFunction * getMF() const
Return the function that contains the basic block that this instruction belongs to.
This class represents lattice values for constants.
Definition: AllocatorList.h:23
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition: Utils.cpp:509
const MachineFunctionProperties & getProperties() const
Get the function properties.
AnalysisUsage & addRequired()
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
Definition: MachineInstr.h:456
Combine Mips machine instrs before legalization
Target-Independent Code Generator Pass Configuration Options.
Abstract class that contains various methods for clients to notify about changes. ...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
Helper class to build MachineInstr.
FunctionPass * createMipsPreLegalizeCombiner()
INITIALIZE_PASS_BEGIN(MipsPreLegalizerCombiner, DEBUG_TYPE, "Combine Mips machine instrs before legalization", false, false) INITIALIZE_PASS_END(MipsPreLegalizerCombiner
Represent the analysis usage information of a pass.
constexpr bool isPowerOf2_64(uint64_t Value)
Return true if the argument is a power of two > 0 (64 bit edition.)
Definition: MathExtras.h:497
#define DEBUG_TYPE
bool tryCombineExtendingLoads(MachineInstr &MI)
If MI is extend that consumes the result of a load, try to combine it.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:284
bool combineMachineInstrs(MachineFunction &MF, GISelCSEInfo *CSEInfo)
If CSEInfo is not null, then the Combiner will setup observer for CSEInfo and instantiate a CSEMIRBui...
Definition: Combiner.cpp:98
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
mmo_iterator memoperands_begin() const
Access to memory operands of the instruction.
Definition: MachineInstr.h:645
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:253
vector combine
Representation of each machine instruction.
Definition: MachineInstr.h:62
bool hasProperty(Property P) const
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
bool systemSupportsUnalignedAccess() const
Does the system support unaligned memory access.
void initializeMipsPreLegalizerCombinerPass(PassRegistry &)
INITIALIZE_PASS_DEPENDENCY(DominatorTreeWrapperPass)