LLVM  10.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"
23 #include "llvm/Support/Debug.h"
24 
25 #define DEBUG_TYPE "aarch64-prelegalizer-combiner"
26 
27 using namespace llvm;
28 using namespace MIPatternMatch;
29 
30 #define AARCH64PRELEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS
31 #include "AArch64GenGICombiner.inc"
32 #undef AARCH64PRELEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_DEPS
33 
34 namespace {
35 #define AARCH64PRELEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H
36 #include "AArch64GenGICombiner.inc"
37 #undef AARCH64PRELEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_H
38 
39 class AArch64PreLegalizerCombinerInfo : public CombinerInfo {
40  GISelKnownBits *KB;
42 
43 public:
44  AArch64GenPreLegalizerCombinerHelper Generated;
45 
46  AArch64PreLegalizerCombinerInfo(bool EnableOpt, bool OptSize, bool MinSize,
48  : CombinerInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
49  /*LegalizerInfo*/ nullptr, EnableOpt, OptSize, MinSize),
50  KB(KB), MDT(MDT) {
51  if (!Generated.parseCommandLineOption())
52  report_fatal_error("Invalid rule identifier");
53  }
54 
55  virtual bool combine(GISelChangeObserver &Observer, MachineInstr &MI,
56  MachineIRBuilder &B) const override;
57 };
58 
59 bool AArch64PreLegalizerCombinerInfo::combine(GISelChangeObserver &Observer,
61  MachineIRBuilder &B) const {
62  CombinerHelper Helper(Observer, B, KB, MDT);
63 
64  switch (MI.getOpcode()) {
65  case TargetOpcode::G_CONCAT_VECTORS:
66  return Helper.tryCombineConcatVectors(MI);
67  case TargetOpcode::G_SHUFFLE_VECTOR:
68  return Helper.tryCombineShuffleVector(MI);
69  case TargetOpcode::G_LOAD:
70  case TargetOpcode::G_SEXTLOAD:
71  case TargetOpcode::G_ZEXTLOAD: {
72  bool Changed = false;
73  Changed |= Helper.tryCombineExtendingLoads(MI);
74  Changed |= Helper.tryCombineIndexedLoadStore(MI);
75  return Changed;
76  }
77  case TargetOpcode::G_STORE:
78  return Helper.tryCombineIndexedLoadStore(MI);
79  case TargetOpcode::G_INTRINSIC_W_SIDE_EFFECTS:
80  switch (MI.getIntrinsicID()) {
81  case Intrinsic::memcpy:
82  case Intrinsic::memmove:
83  case Intrinsic::memset: {
84  // If we're at -O0 set a maxlen of 32 to inline, otherwise let the other
85  // heuristics decide.
86  unsigned MaxLen = EnableOpt ? 0 : 32;
87  // Try to inline memcpy type calls if optimizations are enabled.
88  return (!EnableMinSize) ? Helper.tryCombineMemCpyFamily(MI, MaxLen)
89  : false;
90  }
91  default:
92  break;
93  }
94  }
95 
96  if (Generated.tryCombineAll(Observer, MI, B))
97  return true;
98 
99  return false;
100 }
101 
102 #define AARCH64PRELEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP
103 #include "AArch64GenGICombiner.inc"
104 #undef AARCH64PRELEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP
105 
106 // Pass boilerplate
107 // ================
108 
109 class AArch64PreLegalizerCombiner : public MachineFunctionPass {
110 public:
111  static char ID;
112 
113  AArch64PreLegalizerCombiner(bool IsOptNone = false);
114 
115  StringRef getPassName() const override { return "AArch64PreLegalizerCombiner"; }
116 
117  bool runOnMachineFunction(MachineFunction &MF) override;
118 
119  void getAnalysisUsage(AnalysisUsage &AU) const override;
120 private:
121  bool IsOptNone;
122 };
123 } // end anonymous namespace
124 
125 void AArch64PreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
127  AU.setPreservesCFG();
131  if (!IsOptNone) {
134  }
136 }
137 
138 AArch64PreLegalizerCombiner::AArch64PreLegalizerCombiner(bool IsOptNone)
139  : MachineFunctionPass(ID), IsOptNone(IsOptNone) {
141 }
142 
143 bool AArch64PreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
144  if (MF.getProperties().hasProperty(
146  return false;
147  auto *TPC = &getAnalysis<TargetPassConfig>();
148  const Function &F = MF.getFunction();
149  bool EnableOpt =
150  MF.getTarget().getOptLevel() != CodeGenOpt::None && !skipFunction(F);
151  GISelKnownBits *KB = &getAnalysis<GISelKnownBitsAnalysis>().get(MF);
152  MachineDominatorTree *MDT =
153  IsOptNone ? nullptr : &getAnalysis<MachineDominatorTree>();
154  AArch64PreLegalizerCombinerInfo PCInfo(EnableOpt, F.hasOptSize(),
155  F.hasMinSize(), KB, MDT);
156  Combiner C(PCInfo, TPC);
157  return C.combineMachineInstrs(MF, /*CSEInfo*/ nullptr);
158 }
159 
161 INITIALIZE_PASS_BEGIN(AArch64PreLegalizerCombiner, DEBUG_TYPE,
162  "Combine AArch64 machine instrs before legalization",
163  false, false)
166 INITIALIZE_PASS_END(AArch64PreLegalizerCombiner, DEBUG_TYPE,
167  "Combine AArch64 machine instrs before legalization", false,
168  false)
169 
170 
171 namespace llvm {
173  return new AArch64PreLegalizerCombiner(IsOptNone);
174 }
175 } // end namespace llvm
uint64_t CallInst * C
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
Combine AArch64 machine instrs before legalization
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:1597
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:139
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.
F(f)
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:410
Target-Independent Code Generator Pass Configuration Options.
#define DEBUG_TYPE
FunctionPass * createAArch64PreLegalizeCombiner(bool IsOptNone)
To use KnownBitsInfo analysis in a pass, KnownBitsInfo &Info = getAnalysis<GISelKnownBitsInfoAnalysis...
Abstract class that contains various methods for clients to notify about changes. ...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
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
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:301
const Function & getFunction() const
Return the LLVM function that this machine code represents.
void initializeAArch64PreLegalizerCombinerPass(PassRegistry &)
bool tryCombineShuffleVector(MachineInstr &MI)
Try to combine G_SHUFFLE_VECTOR into G_CONCAT_VECTORS.
Representation of each machine instruction.
Definition: MachineInstr.h:63
bool tryCombineMemCpyFamily(MachineInstr &MI, unsigned MaxLen=0)
Optimize memcpy intrinsics et al, e.g.
const LLVMTargetMachine & getTarget() const
getTarget - Return the target machine this machine code is compiled with
bool hasProperty(Property P) const
unsigned getIntrinsicID() const
Returns the Intrinsic::ID for this instruction.
IRTranslator LLVM IR MI
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
bool tryCombineConcatVectors(MachineInstr &MI)
If MI is G_CONCAT_VECTORS, try to combine it.
DominatorTree Class - Concrete subclass of DominatorTreeBase that is used to compute a normal dominat...
bool tryCombineIndexedLoadStore(MachineInstr &MI)
Combine MI into a pre-indexed or post-indexed load/store operation if legal and the surrounding code ...