Revert r354244 "[DAGCombiner] Eliminate dead stores to stack."
[llvm-complete.git] / lib / Target / AArch64 / AArch64PreLegalizerCombiner.cpp
blobcffe7dbfe6632c3d7f7243ea3b06655b45aa05e4
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.
12 //===----------------------------------------------------------------------===//
14 #include "AArch64TargetMachine.h"
15 #include "llvm/CodeGen/GlobalISel/Combiner.h"
16 #include "llvm/CodeGen/GlobalISel/CombinerHelper.h"
17 #include "llvm/CodeGen/GlobalISel/CombinerInfo.h"
18 #include "llvm/CodeGen/GlobalISel/MIPatternMatch.h"
19 #include "llvm/CodeGen/MachineFunctionPass.h"
20 #include "llvm/CodeGen/TargetPassConfig.h"
21 #include "llvm/Support/Debug.h"
23 #define DEBUG_TYPE "aarch64-prelegalizer-combiner"
25 using namespace llvm;
26 using namespace MIPatternMatch;
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;
38 bool AArch64PreLegalizerCombinerInfo::combine(GISelChangeObserver &Observer,
39 MachineInstr &MI,
40 MachineIRBuilder &B) const {
41 CombinerHelper Helper(Observer, B);
43 switch (MI.getOpcode()) {
44 default:
45 return false;
46 case TargetOpcode::G_LOAD:
47 case TargetOpcode::G_SEXTLOAD:
48 case TargetOpcode::G_ZEXTLOAD:
49 return Helper.tryCombineExtendingLoads(MI);
52 return false;
55 // Pass boilerplate
56 // ================
58 class AArch64PreLegalizerCombiner : public MachineFunctionPass {
59 public:
60 static char ID;
62 AArch64PreLegalizerCombiner();
64 StringRef getPassName() const override { return "AArch64PreLegalizerCombiner"; }
66 bool runOnMachineFunction(MachineFunction &MF) override;
68 void getAnalysisUsage(AnalysisUsage &AU) const override;
72 void AArch64PreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const {
73 AU.addRequired<TargetPassConfig>();
74 AU.setPreservesCFG();
75 getSelectionDAGFallbackAnalysisUsage(AU);
76 MachineFunctionPass::getAnalysisUsage(AU);
79 AArch64PreLegalizerCombiner::AArch64PreLegalizerCombiner() : MachineFunctionPass(ID) {
80 initializeAArch64PreLegalizerCombinerPass(*PassRegistry::getPassRegistry());
83 bool AArch64PreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) {
84 if (MF.getProperties().hasProperty(
85 MachineFunctionProperties::Property::FailedISel))
86 return false;
87 auto *TPC = &getAnalysis<TargetPassConfig>();
88 AArch64PreLegalizerCombinerInfo PCInfo;
89 Combiner C(PCInfo, TPC);
90 return C.combineMachineInstrs(MF, /*CSEInfo*/ nullptr);
93 char AArch64PreLegalizerCombiner::ID = 0;
94 INITIALIZE_PASS_BEGIN(AArch64PreLegalizerCombiner, DEBUG_TYPE,
95 "Combine AArch64 machine instrs before legalization",
96 false, false)
97 INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
98 INITIALIZE_PASS_END(AArch64PreLegalizerCombiner, DEBUG_TYPE,
99 "Combine AArch64 machine instrs before legalization", false,
100 false)
103 namespace llvm {
104 FunctionPass *createAArch64PreLegalizeCombiner() {
105 return new AArch64PreLegalizerCombiner();
107 } // end namespace llvm