1 //=== lib/CodeGen/GlobalISel/AArch64PreLegalizerCombiner.cpp --------------===//
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
7 //===----------------------------------------------------------------------===//
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"
26 using namespace MIPatternMatch
;
29 class AArch64PreLegalizerCombinerInfo
: public CombinerInfo
{
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
,
40 MachineIRBuilder
&B
) const {
41 CombinerHelper
Helper(Observer
, B
);
43 switch (MI
.getOpcode()) {
46 case TargetOpcode::G_LOAD
:
47 case TargetOpcode::G_SEXTLOAD
:
48 case TargetOpcode::G_ZEXTLOAD
:
49 return Helper
.tryCombineExtendingLoads(MI
);
58 class AArch64PreLegalizerCombiner
: public MachineFunctionPass
{
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
>();
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
))
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",
97 INITIALIZE_PASS_DEPENDENCY(TargetPassConfig
)
98 INITIALIZE_PASS_END(AArch64PreLegalizerCombiner
, DEBUG_TYPE
,
99 "Combine AArch64 machine instrs before legalization", false,
104 FunctionPass
*createAArch64PreLegalizeCombiner() {
105 return new AArch64PreLegalizerCombiner();
107 } // end namespace llvm