LLVM  9.0.0svn
AArch64PreLegalizerCombiner.cpp
Go to the documentation of this file.
1 //=== lib/CodeGen/GlobalISel/AArch64PreLegalizerCombiner.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 "AArch64TargetMachine.h"
21 #include "llvm/Support/Debug.h"
22 
23 #define DEBUG_TYPE "aarch64-prelegalizer-combiner"
24 
25 using namespace llvm;
26 using namespace MIPatternMatch;
27 
28 namespace {
29 class AArch64PreLegalizerCombinerInfo : public CombinerInfo {
30 public:
31  AArch64PreLegalizerCombinerInfo()
32  : CombinerInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
33  /*LegalizerInfo*/ nullptr) {}
34  virtual bool combine(GISelChangeObserver &Observer, MachineInstr &MI,
35  MachineIRBuilder &B) const override;
36 };
37 
38 bool AArch64PreLegalizerCombinerInfo::combine(GISelChangeObserver &Observer,
40  MachineIRBuilder &B) const {
41  CombinerHelper Helper(Observer, B);
42 
43  switch (MI.getOpcode()) {
44  default:
45  return false;
46  case TargetOpcode::COPY:
47  return Helper.tryCombineCopy(MI);
48  case TargetOpcode::G_LOAD:
49  case TargetOpcode::G_SEXTLOAD:
50  case TargetOpcode::G_ZEXTLOAD:
51  return Helper.tryCombineExtendingLoads(MI);
52  }
53 
54  return false;
55 }
56 
57 // Pass boilerplate
58 // ================
59 
60 class AArch64PreLegalizerCombiner : public MachineFunctionPass {
61 public:
62  static char ID;
63 
64  AArch64PreLegalizerCombiner();
65 
66  StringRef getPassName() const override { return "AArch64PreLegalizerCombiner"; }
67 
68  bool runOnMachineFunction(MachineFunction &MF) override;
69 
70  void getAnalysisUsage(AnalysisUsage &AU) const override;
71 };
72 }
73 
74 void AArch64PreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
76  AU.setPreservesCFG();
79 }
80 
81 AArch64PreLegalizerCombiner::AArch64PreLegalizerCombiner() : MachineFunctionPass(ID) {
83 }
84 
85 bool AArch64PreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
86  if (MF.getProperties().hasProperty(
88  return false;
89  auto *TPC = &getAnalysis<TargetPassConfig>();
90  AArch64PreLegalizerCombinerInfo PCInfo;
91  Combiner C(PCInfo, TPC);
92  return C.combineMachineInstrs(MF, /*CSEInfo*/ nullptr);
93 }
94 
96 INITIALIZE_PASS_BEGIN(AArch64PreLegalizerCombiner, DEBUG_TYPE,
97  "Combine AArch64 machine instrs before legalization",
98  false, false)
100 INITIALIZE_PASS_END(AArch64PreLegalizerCombiner, DEBUG_TYPE,
101  "Combine AArch64 machine instrs before legalization", false,
102  false)
103 
104 
105 namespace llvm {
107  return new AArch64PreLegalizerCombiner();
108 }
109 } // end namespace llvm
uint64_t CallInst * C
Combine AArch64 machine instrs before legalization
static PassRegistry * getPassRegistry()
getPassRegistry - Access the global registry object, which is automatically initialized at applicatio...
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:364
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:408
Target-Independent Code Generator Pass Configuration Options.
#define DEBUG_TYPE
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.
Represent the analysis usage information of a pass.
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:86
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
bool tryCombineCopy(MachineInstr &MI)
If MI is COPY, try to combine it.
INITIALIZE_PASS_BEGIN(AArch64PreLegalizerCombiner, DEBUG_TYPE, "Combine AArch64 machine instrs before legalization", false, false) INITIALIZE_PASS_END(AArch64PreLegalizerCombiner
void setPreservesCFG()
This function should be called by the pass, iff they do not:
Definition: Pass.cpp:301
void initializeAArch64PreLegalizerCombinerPass(PassRegistry &)
Representation of each machine instruction.
Definition: MachineInstr.h:63
FunctionPass * createAArch64PreLegalizeCombiner()
bool hasProperty(Property P) const
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48