Quentin Colombet | 374796d | 2016-08-27 00:18:31 +0000 | [diff] [blame] | 1 | //===-- ResetMachineFunctionPass.cpp - Machine Loop Invariant Code Motion Pass ---------===// |
| 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 | // |
| 11 | //===----------------------------------------------------------------------===// |
| 12 | |
| 13 | #include "llvm/CodeGen/Passes.h" |
| 14 | #include "llvm/CodeGen/MachineFunction.h" |
| 15 | #include "llvm/CodeGen/MachineFunctionPass.h" |
Quentin Colombet | 612cd1f | 2016-08-31 18:43:01 +0000 | [diff] [blame] | 16 | #include "llvm/IR/DiagnosticInfo.h" |
Quentin Colombet | 374796d | 2016-08-27 00:18:31 +0000 | [diff] [blame] | 17 | #include "llvm/Support/Debug.h" |
| 18 | using namespace llvm; |
| 19 | |
| 20 | #define DEBUG_TYPE "reset-machine-function" |
| 21 | |
| 22 | namespace { |
| 23 | class ResetMachineFunction : public MachineFunctionPass { |
Quentin Colombet | 612cd1f | 2016-08-31 18:43:01 +0000 | [diff] [blame] | 24 | /// Tells whether or not this pass should emit a fallback |
| 25 | /// diagnostic when it resets a function. |
| 26 | bool EmitFallbackDiag; |
| 27 | |
Quentin Colombet | 374796d | 2016-08-27 00:18:31 +0000 | [diff] [blame] | 28 | public: |
| 29 | static char ID; // Pass identification, replacement for typeid |
Quentin Colombet | 612cd1f | 2016-08-31 18:43:01 +0000 | [diff] [blame] | 30 | ResetMachineFunction(bool EmitFallbackDiag = false) |
| 31 | : MachineFunctionPass(ID), EmitFallbackDiag(EmitFallbackDiag) {} |
Quentin Colombet | 374796d | 2016-08-27 00:18:31 +0000 | [diff] [blame] | 32 | |
| 33 | const char *getPassName() const override { |
| 34 | return "ResetMachineFunction"; |
| 35 | } |
| 36 | |
| 37 | bool runOnMachineFunction(MachineFunction &MF) override { |
| 38 | if (MF.getProperties().hasProperty( |
| 39 | MachineFunctionProperties::Property::FailedISel)) { |
| 40 | DEBUG(dbgs() << "Reseting: " << MF.getName() << '\n'); |
| 41 | MF.reset(); |
Quentin Colombet | 612cd1f | 2016-08-31 18:43:01 +0000 | [diff] [blame] | 42 | if (EmitFallbackDiag) { |
| 43 | const Function &F = *MF.getFunction(); |
| 44 | DiagnosticInfoISelFallback DiagFallback(F); |
| 45 | F.getContext().diagnose(DiagFallback); |
| 46 | } |
Quentin Colombet | 374796d | 2016-08-27 00:18:31 +0000 | [diff] [blame] | 47 | return true; |
| 48 | } |
| 49 | return false; |
| 50 | } |
| 51 | |
| 52 | }; |
| 53 | } // end anonymous namespace |
| 54 | |
| 55 | char ResetMachineFunction::ID = 0; |
| 56 | INITIALIZE_PASS(ResetMachineFunction, DEBUG_TYPE, |
| 57 | "reset machine function if ISel failed", false, false) |
| 58 | |
| 59 | MachineFunctionPass * |
Quentin Colombet | 612cd1f | 2016-08-31 18:43:01 +0000 | [diff] [blame] | 60 | llvm::createResetMachineFunctionPass(bool EmitFallbackDiag = false) { |
| 61 | return new ResetMachineFunction(EmitFallbackDiag); |
Quentin Colombet | 374796d | 2016-08-27 00:18:31 +0000 | [diff] [blame] | 62 | } |