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"
16 #include "llvm/Support/Debug.h"
17 using namespace llvm;
18 
19 #define DEBUG_TYPE "reset-machine-function"
20 
21 namespace {
22   class ResetMachineFunction : public MachineFunctionPass {
23   public:
24     static char ID; // Pass identification, replacement for typeid
25     ResetMachineFunction() :
26       MachineFunctionPass(ID) {
27     }
28 
29     const char *getPassName() const override {
30       return "ResetMachineFunction";
31     }
32 
33     bool runOnMachineFunction(MachineFunction &MF) override {
34       if (MF.getProperties().hasProperty(
35               MachineFunctionProperties::Property::FailedISel)) {
36         DEBUG(dbgs() << "Reseting: " << MF.getName() << '\n');
37         MF.reset();
38         return true;
39       }
40       return false;
41     }
42 
43   };
44 } // end anonymous namespace
45 
46 char ResetMachineFunction::ID = 0;
47 INITIALIZE_PASS(ResetMachineFunction, DEBUG_TYPE,
48                 "reset machine function if ISel failed", false, false)
49 
50 MachineFunctionPass *
51 llvm::createResetMachineFunctionPass() {
52   return new ResetMachineFunction();
53 }
54