Petar Avramovic | 7d370a3 | 2019-01-14 10:27:05 +0000 | [diff] [blame^] | 1 | //=== lib/CodeGen/GlobalISel/MipsPreLegalizerCombiner.cpp --------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This pass does combining of machine instructions at the generic MI level, |
| 11 | // before the legalizer. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #include "MipsTargetMachine.h" |
| 16 | #include "llvm/CodeGen/GlobalISel/Combiner.h" |
| 17 | #include "llvm/CodeGen/GlobalISel/CombinerInfo.h" |
| 18 | #include "llvm/CodeGen/GlobalISel/MIPatternMatch.h" |
| 19 | #include "llvm/CodeGen/TargetPassConfig.h" |
| 20 | |
| 21 | #define DEBUG_TYPE "mips-prelegalizer-combiner" |
| 22 | |
| 23 | using namespace llvm; |
| 24 | |
| 25 | namespace { |
| 26 | class MipsPreLegalizerCombinerInfo : public CombinerInfo { |
| 27 | public: |
| 28 | MipsPreLegalizerCombinerInfo() |
| 29 | : CombinerInfo(/*AllowIllegalOps*/ true, /*ShouldLegalizeIllegal*/ false, |
| 30 | /*LegalizerInfo*/ nullptr) {} |
| 31 | virtual bool combine(GISelChangeObserver &Observer, MachineInstr &MI, |
| 32 | MachineIRBuilder &B) const override; |
| 33 | }; |
| 34 | |
| 35 | bool MipsPreLegalizerCombinerInfo::combine(GISelChangeObserver &Observer, |
| 36 | MachineInstr &MI, |
| 37 | MachineIRBuilder &B) const { |
| 38 | return false; |
| 39 | } |
| 40 | |
| 41 | // Pass boilerplate |
| 42 | // ================ |
| 43 | |
| 44 | class MipsPreLegalizerCombiner : public MachineFunctionPass { |
| 45 | public: |
| 46 | static char ID; |
| 47 | |
| 48 | MipsPreLegalizerCombiner(); |
| 49 | |
| 50 | StringRef getPassName() const override { return "MipsPreLegalizerCombiner"; } |
| 51 | |
| 52 | bool runOnMachineFunction(MachineFunction &MF) override; |
| 53 | |
| 54 | void getAnalysisUsage(AnalysisUsage &AU) const override; |
| 55 | }; |
| 56 | } // end anonymous namespace |
| 57 | |
| 58 | void MipsPreLegalizerCombiner::getAnalysisUsage(AnalysisUsage &AU) const { |
| 59 | AU.addRequired<TargetPassConfig>(); |
| 60 | AU.setPreservesCFG(); |
| 61 | getSelectionDAGFallbackAnalysisUsage(AU); |
| 62 | MachineFunctionPass::getAnalysisUsage(AU); |
| 63 | } |
| 64 | |
| 65 | MipsPreLegalizerCombiner::MipsPreLegalizerCombiner() : MachineFunctionPass(ID) { |
| 66 | initializeMipsPreLegalizerCombinerPass(*PassRegistry::getPassRegistry()); |
| 67 | } |
| 68 | |
| 69 | bool MipsPreLegalizerCombiner::runOnMachineFunction(MachineFunction &MF) { |
| 70 | if (MF.getProperties().hasProperty( |
| 71 | MachineFunctionProperties::Property::FailedISel)) |
| 72 | return false; |
| 73 | auto *TPC = &getAnalysis<TargetPassConfig>(); |
| 74 | MipsPreLegalizerCombinerInfo PCInfo; |
| 75 | Combiner C(PCInfo, TPC); |
| 76 | return C.combineMachineInstrs(MF); |
| 77 | } |
| 78 | |
| 79 | char MipsPreLegalizerCombiner::ID = 0; |
| 80 | INITIALIZE_PASS_BEGIN(MipsPreLegalizerCombiner, DEBUG_TYPE, |
| 81 | "Combine Mips machine instrs before legalization", false, |
| 82 | false) |
| 83 | INITIALIZE_PASS_DEPENDENCY(TargetPassConfig) |
| 84 | INITIALIZE_PASS_END(MipsPreLegalizerCombiner, DEBUG_TYPE, |
| 85 | "Combine Mips machine instrs before legalization", false, |
| 86 | false) |
| 87 | |
| 88 | namespace llvm { |
| 89 | FunctionPass *createMipsPreLegalizeCombiner() { |
| 90 | return new MipsPreLegalizerCombiner(); |
| 91 | } |
| 92 | } // end namespace llvm |