LLVM  10.0.0
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_INTRINSIC_W_SIDE_EFFECTS:
66  switch (MI.getIntrinsicID()) {
67  case Intrinsic::memcpy:
68  case Intrinsic::memmove:
69  case Intrinsic::memset: {
70  // If we're at -O0 set a maxlen of 32 to inline, otherwise let the other
71  // heuristics decide.
72  unsigned MaxLen = EnableOpt ? 0 : 32;
73  // Try to inline memcpy type calls if optimizations are enabled.
74  return (!EnableMinSize) ? Helper.tryCombineMemCpyFamily(MI, MaxLen)
75  : false;
76  }
77  default:
78  break;
79  }
80  }
81 
82  if (Generated.tryCombineAll(Observer, MI, B, Helper))
83  return true;
84 
85  switch (MI.getOpcode()) {
86  case TargetOpcode::G_CONCAT_VECTORS:
87  return Helper.tryCombineConcatVectors(MI);
88  case TargetOpcode::G_SHUFFLE_VECTOR:
89  return Helper.tryCombineShuffleVector(MI);
90  }
91 
92  return false;
93 }
94 
95 #define AARCH64PRELEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP
96 #include "AArch64GenGICombiner.inc"
97 #undef AARCH64PRELEGALIZERCOMBINERHELPER_GENCOMBINERHELPER_CPP
98 
99 // Pass boilerplate
100 // ================
101 
102 class AArch64PreLegalizerCombiner : public MachineFunctionPass {
103 public:
104  static char ID;
105 
106  AArch64PreLegalizerCombiner(bool IsOptNone = false);
107 
108  StringRef getPassName() const override { return "AArch64PreLegalizerCombiner"; }
109 
110  bool runOnMachineFunction(MachineFunction &MF) override;
111 
112  void getAnalysisUsage(AnalysisUsage &AU) const override;
113 private:
114  bool IsOptNone;
115 };
116 } // end anonymous namespace
117 
118 void AArch64PreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
120  AU.setPreservesCFG();
124  if (!IsOptNone) {
127  }
129 }
130 
131 AArch64PreLegalizerCombiner::AArch64PreLegalizerCombiner(bool IsOptNone)
132  : MachineFunctionPass(ID), IsOptNone(IsOptNone) {
134 }
135 
136 bool AArch64PreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
137  if (MF.getProperties().hasProperty(
139  return false;
140  auto *TPC = &getAnalysis<TargetPassConfig>();
141  const Function &F = MF.getFunction();
142  bool EnableOpt =
143  MF.getTarget().getOptLevel() != CodeGenOpt::None && !skipFunction(F);
144  GISelKnownBits *KB = &getAnalysis<GISelKnownBitsAnalysis>().get(MF);
145  MachineDominatorTree *MDT =
146  IsOptNone ? nullptr : &getAnalysis<MachineDominatorTree>();
147  AArch64PreLegalizerCombinerInfo PCInfo(EnableOpt, F.hasOptSize(),
148  F.hasMinSize(), KB, MDT);
149  Combiner C(PCInfo, TPC);
150  return C.combineMachineInstrs(MF, /*CSEInfo*/ nullptr);
151 }
152 
154 INITIALIZE_PASS_BEGIN(AArch64PreLegalizerCombiner, DEBUG_TYPE,
155  "Combine AArch64 machine instrs before legalization",
156  false, false)
159 INITIALIZE_PASS_END(AArch64PreLegalizerCombiner, DEBUG_TYPE,
160  "Combine AArch64 machine instrs before legalization", false,
161  false)
162 
163 
164 namespace llvm {
166  return new AArch64PreLegalizerCombiner(IsOptNone);
167 }
168 } // 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:1612
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:140
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:426
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.
FunctionPass class - This class is used to implement most global optimizations.
Definition: Pass.h:282
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:256
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:54
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...