1 //=== lib/CodeGen/GlobalISel/MipsPreLegalizerCombiner.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 "MipsTargetMachine.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/TargetPassConfig.h"
21 #define DEBUG_TYPE "mips-prelegalizer-combiner"
26 class MipsPreLegalizerCombinerInfo
: public CombinerInfo
{
28 MipsPreLegalizerCombinerInfo()
29 : CombinerInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false,
30 /*LegalizerInfo*/ nullptr, /*EnableOpt*/ false,
31 /*EnableOptSize*/ false, /*EnableMinSize*/ false) {}
32 virtual bool combine(GISelChangeObserver
&Observer
, MachineInstr
&MI
,
33 MachineIRBuilder
&B
) const override
;
36 bool MipsPreLegalizerCombinerInfo::combine(GISelChangeObserver
&Observer
,
38 MachineIRBuilder
&B
) const {
39 CombinerHelper
Helper(Observer
, B
);
41 switch (MI
.getOpcode()) {
44 case TargetOpcode::G_LOAD
:
45 case TargetOpcode::G_SEXTLOAD
:
46 case TargetOpcode::G_ZEXTLOAD
:
47 return Helper
.tryCombineExtendingLoads(MI
);
55 class MipsPreLegalizerCombiner
: public MachineFunctionPass
{
59 MipsPreLegalizerCombiner();
61 StringRef
getPassName() const override
{ return "MipsPreLegalizerCombiner"; }
63 bool runOnMachineFunction(MachineFunction
&MF
) override
;
65 void getAnalysisUsage(AnalysisUsage
&AU
) const override
;
67 } // end anonymous namespace
69 void MipsPreLegalizerCombiner::getAnalysisUsage(AnalysisUsage
&AU
) const {
70 AU
.addRequired
<TargetPassConfig
>();
72 getSelectionDAGFallbackAnalysisUsage(AU
);
73 MachineFunctionPass::getAnalysisUsage(AU
);
76 MipsPreLegalizerCombiner::MipsPreLegalizerCombiner() : MachineFunctionPass(ID
) {
77 initializeMipsPreLegalizerCombinerPass(*PassRegistry::getPassRegistry());
80 bool MipsPreLegalizerCombiner::runOnMachineFunction(MachineFunction
&MF
) {
81 if (MF
.getProperties().hasProperty(
82 MachineFunctionProperties::Property::FailedISel
))
84 auto *TPC
= &getAnalysis
<TargetPassConfig
>();
85 MipsPreLegalizerCombinerInfo PCInfo
;
86 Combiner
C(PCInfo
, TPC
);
87 return C
.combineMachineInstrs(MF
, nullptr);
90 char MipsPreLegalizerCombiner::ID
= 0;
91 INITIALIZE_PASS_BEGIN(MipsPreLegalizerCombiner
, DEBUG_TYPE
,
92 "Combine Mips machine instrs before legalization", false,
94 INITIALIZE_PASS_DEPENDENCY(TargetPassConfig
)
95 INITIALIZE_PASS_END(MipsPreLegalizerCombiner
, DEBUG_TYPE
,
96 "Combine Mips machine instrs before legalization", false,
100 FunctionPass
*createMipsPreLegalizeCombiner() {
101 return new MipsPreLegalizerCombiner();
103 } // end namespace llvm