LLVM  8.0.1
AArch64PreLegalizerCombiner.cpp
Go to the documentation of this file.
1 //=== lib/CodeGen/GlobalISel/AArch64PreLegalizerCombiner.cpp --------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This pass does combining of machine instructions at the generic MI level,
11 // before the legalizer.
12 //
13 //===----------------------------------------------------------------------===//
14 
15 #include "AArch64TargetMachine.h"
22 #include "llvm/Support/Debug.h"
23 
24 #define DEBUG_TYPE "aarch64-prelegalizer-combiner"
25 
26 using namespace llvm;
27 using namespace MIPatternMatch;
28 
29 namespace {
30 class AArch64PreLegalizerCombinerInfo : public CombinerInfo {
31 public:
32  AArch64PreLegalizerCombinerInfo()
33  : CombinerInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
34  /*LegalizerInfo*/ nullptr) {}
35  virtual bool combine(GISelChangeObserver &Observer, MachineInstr &MI,
36  MachineIRBuilder &B) const override;
37 };
38 
39 bool AArch64PreLegalizerCombinerInfo::combine(GISelChangeObserver &Observer,
41  MachineIRBuilder &B) const {
42  CombinerHelper Helper(Observer, B);
43 
44  switch (MI.getOpcode()) {
45  default:
46  return false;
47  case TargetOpcode::G_LOAD:
48  case TargetOpcode::G_SEXTLOAD:
49  case TargetOpcode::G_ZEXTLOAD:
50  return Helper.tryCombineExtendingLoads(MI);
51  }
52 
53  return false;
54 }
55 
56 // Pass boilerplate
57 // ================
58 
59 class AArch64PreLegalizerCombiner : public MachineFunctionPass {
60 public:
61  static char ID;
62 
63  AArch64PreLegalizerCombiner();
64 
65  StringRef getPassName() const override { return "AArch64PreLegalizerCombiner"; }
66 
67  bool runOnMachineFunction(MachineFunction &MF) override;
68 
69  void getAnalysisUsage(AnalysisUsage &AU) const override;
70 };
71 }
72 
73 void AArch64PreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
75  AU.setPreservesCFG();
78 }
79 
80 AArch64PreLegalizerCombiner::AArch64PreLegalizerCombiner() : MachineFunctionPass(ID) {
82 }
83 
84 bool AArch64PreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
85  if (MF.getProperties().hasProperty(
87  return false;
88  auto *TPC = &getAnalysis<TargetPassConfig>();
89  AArch64PreLegalizerCombinerInfo PCInfo;
90  Combiner C(PCInfo, TPC);
91  return C.combineMachineInstrs(MF, /*CSEInfo*/ nullptr);
92 }
93 
95 INITIALIZE_PASS_BEGIN(AArch64PreLegalizerCombiner, DEBUG_TYPE,
96  "Combine AArch64 machine instrs before legalization",
97  false, false)
99 INITIALIZE_PASS_END(AArch64PreLegalizerCombiner, DEBUG_TYPE,
100  "Combine AArch64 machine instrs before legalization", false,
101  false)
102 
103 
104 namespace llvm {
106  return new AArch64PreLegalizerCombiner();
107 }
108 } // 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:24
void getSelectionDAGFallbackAnalysisUsage(AnalysisUsage &AU)
Modify analysis usage so it preserves passes required for the SelectionDAG fallback.
Definition: Utils.cpp:289
const MachineFunctionProperties & getProperties() const
Get the function properties.
AnalysisUsage & addRequired()
#define INITIALIZE_PASS_DEPENDENCY(depName)
Definition: PassSupport.h:51
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:409
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:285
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:87
INITIALIZE_PASS_END(RegBankSelect, DEBUG_TYPE, "Assign register bank of generic virtual registers", false, false) RegBankSelect
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:286
void initializeAArch64PreLegalizerCombinerPass(PassRegistry &)
Representation of each machine instruction.
Definition: MachineInstr.h:64
FunctionPass * createAArch64PreLegalizeCombiner()
bool hasProperty(Property P) const
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49