[InstCombine] Signed saturation patterns
[llvm-complete.git] / lib / Target / Mips / MipsPreLegalizerCombiner.cpp
blobace0735652bdecf80275b24389d4aa5e14af4003
1 //=== lib/CodeGen/GlobalISel/MipsPreLegalizerCombiner.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 "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"
23 using namespace llvm;
25 namespace {
26 class MipsPreLegalizerCombinerInfo : public CombinerInfo {
27 public:
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,
37 MachineInstr &MI,
38 MachineIRBuilder &B) const {
39 CombinerHelper Helper(Observer, B);
41 switch (MI.getOpcode()) {
42 default:
43 return false;
44 case TargetOpcode::G_LOAD:
45 case TargetOpcode::G_SEXTLOAD:
46 case TargetOpcode::G_ZEXTLOAD:
47 return Helper.tryCombineExtendingLoads(MI);
49 return false;
52 // Pass boilerplate
53 // ================
55 class MipsPreLegalizerCombiner : public MachineFunctionPass {
56 public:
57 static char ID;
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>();
71 AU.setPreservesCFG();
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))
83 return false;
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,
93 false)
94 INITIALIZE_PASS_DEPENDENCY(TargetPassConfig)
95 INITIALIZE_PASS_END(MipsPreLegalizerCombiner, DEBUG_TYPE,
96 "Combine Mips machine instrs before legalization", false,
97 false)
99 namespace llvm {
100 FunctionPass *createMipsPreLegalizeCombiner() {
101 return new MipsPreLegalizerCombiner();
103 } // end namespace llvm