Petar Avramovic | 7d370a3 | 2019-01-14 10:27:05 +0000 | [diff] [blame] | 1 | //=== lib/CodeGen/GlobalISel/MipsPreLegalizerCombiner.cpp --------------===// |
| 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame^] | 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 |
Petar Avramovic | 7d370a3 | 2019-01-14 10:27:05 +0000 | [diff] [blame] | 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 "MipsTargetMachine.h" |
| 15 | #include "llvm/CodeGen/GlobalISel/Combiner.h" |
| 16 | #include "llvm/CodeGen/GlobalISel/CombinerInfo.h" |
| 17 | #include "llvm/CodeGen/GlobalISel/MIPatternMatch.h" |
| 18 | #include "llvm/CodeGen/TargetPassConfig.h" |
| 19 | |
| 20 | #define DEBUG_TYPE "mips-prelegalizer-combiner" |
| 21 | |
| 22 | using namespace llvm; |
| 23 | |
| 24 | namespace { |
| 25 | class MipsPreLegalizerCombinerInfo : public CombinerInfo { |
| 26 | public: |
| 27 | MipsPreLegalizerCombinerInfo() |
| 28 | : CombinerInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false, |
| 29 | /*LegalizerInfo*/ nullptr) {} |
| 30 | virtual bool combine(GISelChangeObserver &Observer, MachineInstr &MI, |
| 31 | MachineIRBuilder &B) const override; |
| 32 | }; |
| 33 | |
| 34 | bool MipsPreLegalizerCombinerInfo::combine(GISelChangeObserver &Observer, |
| 35 | MachineInstr &MI, |
| 36 | MachineIRBuilder &B) const { |
| 37 | return false; |
| 38 | } |
| 39 | |
| 40 | // Pass boilerplate |
| 41 | // ================ |
| 42 | |
| 43 | class MipsPreLegalizerCombiner : public MachineFunctionPass { |
| 44 | public: |
| 45 | static char ID; |
| 46 | |
| 47 | MipsPreLegalizerCombiner(); |
| 48 | |
| 49 | StringRef getPassName() const override { return "MipsPreLegalizerCombiner"; } |
| 50 | |
| 51 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 52 | |
| 53 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 54 | }; |
| 55 | } // end anonymous namespace |
| 56 | |
| 57 | void MipsPreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const { |
| 58 | AU.addRequired<TargetPassConfig>(); |
| 59 | AU.setPreservesCFG(); |
| 60 | getSelectionDAGFallbackAnalysisUsage(AU); |
| 61 | MachineFunctionPass::getAnalysisUsage(AU); |
| 62 | } |
| 63 | |
| 64 | MipsPreLegalizerCombiner::MipsPreLegalizerCombiner() : MachineFunctionPass(ID) { |
| 65 | initializeMipsPreLegalizerCombinerPass(*PassRegistry::getPassRegistry()); |
| 66 | } |
| 67 | |
| 68 | bool MipsPreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) { |
| 69 | if (MF.getProperties().hasProperty( |
| 70 | MachineFunctionProperties::Property::FailedISel)) |
| 71 | return false; |
| 72 | auto *TPC = &getAnalysis<TargetPassConfig>(); |
| 73 | MipsPreLegalizerCombinerInfo PCInfo; |
| 74 | Combiner C(PCInfo, TPC); |
Aditya Nandakumar | 500e3ea | 2019-01-16 00:40:37 +0000 | [diff] [blame] | 75 | return C.combineMachineInstrs(MF, nullptr); |
Petar Avramovic | 7d370a3 | 2019-01-14 10:27:05 +0000 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | char MipsPreLegalizerCombiner::ID = 0; |
| 79 | INITIALIZE_PASS_BEGIN(MipsPreLegalizerCombiner, DEBUG_TYPE, |
| 80 | "Combine Mips machine instrs before legalization", false, |
| 81 | false) |
| 82 | INITIALIZE_PASS_DEPENDENCY(TargetPassConfig) |
| 83 | INITIALIZE_PASS_END(MipsPreLegalizerCombiner, DEBUG_TYPE, |
| 84 | "Combine Mips machine instrs before legalization", false, |
| 85 | false) |
| 86 | |
| 87 | namespace llvm { |
| 88 | FunctionPass *createMipsPreLegalizeCombiner() { |
| 89 | return new MipsPreLegalizerCombiner(); |
| 90 | } |
| 91 | } // end namespace llvm |