1*374796d6SQuentin Colombet //===-- ResetMachineFunctionPass.cpp - Machine Loop Invariant Code Motion Pass ---------===//
2*374796d6SQuentin Colombet //
3*374796d6SQuentin Colombet //                     The LLVM Compiler Infrastructure
4*374796d6SQuentin Colombet //
5*374796d6SQuentin Colombet // This file is distributed under the University of Illinois Open Source
6*374796d6SQuentin Colombet // License. See LICENSE.TXT for details.
7*374796d6SQuentin Colombet //
8*374796d6SQuentin Colombet //===----------------------------------------------------------------------===//
9*374796d6SQuentin Colombet //
10*374796d6SQuentin Colombet //
11*374796d6SQuentin Colombet //===----------------------------------------------------------------------===//
12*374796d6SQuentin Colombet 
13*374796d6SQuentin Colombet #include "llvm/CodeGen/Passes.h"
14*374796d6SQuentin Colombet #include "llvm/CodeGen/MachineFunction.h"
15*374796d6SQuentin Colombet #include "llvm/CodeGen/MachineFunctionPass.h"
16*374796d6SQuentin Colombet #include "llvm/Support/Debug.h"
17*374796d6SQuentin Colombet using namespace llvm;
18*374796d6SQuentin Colombet 
19*374796d6SQuentin Colombet #define DEBUG_TYPE "reset-machine-function"
20*374796d6SQuentin Colombet 
21*374796d6SQuentin Colombet namespace {
22*374796d6SQuentin Colombet   class ResetMachineFunction : public MachineFunctionPass {
23*374796d6SQuentin Colombet   public:
24*374796d6SQuentin Colombet     static char ID; // Pass identification, replacement for typeid
25*374796d6SQuentin Colombet     ResetMachineFunction() :
26*374796d6SQuentin Colombet       MachineFunctionPass(ID) {
27*374796d6SQuentin Colombet     }
28*374796d6SQuentin Colombet 
29*374796d6SQuentin Colombet     const char *getPassName() const override {
30*374796d6SQuentin Colombet       return "ResetMachineFunction";
31*374796d6SQuentin Colombet     }
32*374796d6SQuentin Colombet 
33*374796d6SQuentin Colombet     bool runOnMachineFunction(MachineFunction &MF) override {
34*374796d6SQuentin Colombet       if (MF.getProperties().hasProperty(
35*374796d6SQuentin Colombet               MachineFunctionProperties::Property::FailedISel)) {
36*374796d6SQuentin Colombet         DEBUG(dbgs() << "Reseting: " << MF.getName() << '\n');
37*374796d6SQuentin Colombet         MF.reset();
38*374796d6SQuentin Colombet         return true;
39*374796d6SQuentin Colombet       }
40*374796d6SQuentin Colombet       return false;
41*374796d6SQuentin Colombet     }
42*374796d6SQuentin Colombet 
43*374796d6SQuentin Colombet   };
44*374796d6SQuentin Colombet } // end anonymous namespace
45*374796d6SQuentin Colombet 
46*374796d6SQuentin Colombet char ResetMachineFunction::ID = 0;
47*374796d6SQuentin Colombet INITIALIZE_PASS(ResetMachineFunction, DEBUG_TYPE,
48*374796d6SQuentin Colombet                 "reset machine function if ISel failed", false, false)
49*374796d6SQuentin Colombet 
50*374796d6SQuentin Colombet MachineFunctionPass *
51*374796d6SQuentin Colombet llvm::createResetMachineFunctionPass() {
52*374796d6SQuentin Colombet   return new ResetMachineFunction();
53*374796d6SQuentin Colombet }
54