LLVM  10.0.0
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 
37 bool MipsPreLegalizerCombinerInfo::combine(GISelChangeObserver &Observer,
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  return Helper.tryCombineExtendingLoads(MI);
49  }
50  return false;
51 }
52 
53 // Pass boilerplate
54 // ================
55 
56 class MipsPreLegalizerCombiner : public MachineFunctionPass {
57 public:
58  static char ID;
59 
60  MipsPreLegalizerCombiner();
61 
62  StringRef getPassName() const override { return "MipsPreLegalizerCombiner"; }
63 
64  bool runOnMachineFunction(MachineFunction &MF) override;
65 
66  void getAnalysisUsage(AnalysisUsage &AU) const override;
67 };
68 } // end anonymous namespace
69 
70 void MipsPreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
72  AU.setPreservesCFG();
75 }
76 
77 MipsPreLegalizerCombiner::MipsPreLegalizerCombiner() : MachineFunctionPass(ID) {
79 }
80 
81 bool MipsPreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
82  if (MF.getProperties().hasProperty(
84  return false;
85  auto *TPC = &getAnalysis<TargetPassConfig>();
86  MipsPreLegalizerCombinerInfo PCInfo;
87  Combiner C(PCInfo, TPC);
88  return C.combineMachineInstrs(MF, nullptr);
89 }
90 
92 INITIALIZE_PASS_BEGIN(MipsPreLegalizerCombiner, DEBUG_TYPE,
93  "Combine Mips machine instrs before legalization", false,
94  false)
96 INITIALIZE_PASS_END(MipsPreLegalizerCombiner, DEBUG_TYPE,
97  "Combine Mips machine instrs before legalization", false,
98  false)
99 
100 namespace llvm {
102  return new MipsPreLegalizerCombiner();
103 }
104 } // 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:1612
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:431
const MachineFunctionProperties & getProperties() const
Get the function properties.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:50
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:426
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")
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.
#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:282
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
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:256
Representation of each machine instruction.
Definition: MachineInstr.h:63
bool hasProperty(Property P) const
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:54
void initializeMipsPreLegalizerCombinerPass(PassRegistry &)