blob: 07a8259a70cf6a5b9131af7a4e425f51e9c3cb0c [file] [log] [blame]
Quentin Colombet374796d2016-08-27 00:18:31 +00001//===-- 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 Colombet612cd1f2016-08-31 18:43:01 +000016#include "llvm/IR/DiagnosticInfo.h"
Quentin Colombet374796d2016-08-27 00:18:31 +000017#include "llvm/Support/Debug.h"
18using namespace llvm;
19
20#define DEBUG_TYPE "reset-machine-function"
21
22namespace {
23 class ResetMachineFunction : public MachineFunctionPass {
Quentin Colombet612cd1f2016-08-31 18:43:01 +000024 /// Tells whether or not this pass should emit a fallback
25 /// diagnostic when it resets a function.
26 bool EmitFallbackDiag;
27
Quentin Colombet374796d2016-08-27 00:18:31 +000028 public:
29 static char ID; // Pass identification, replacement for typeid
Quentin Colombet612cd1f2016-08-31 18:43:01 +000030 ResetMachineFunction(bool EmitFallbackDiag = false)
31 : MachineFunctionPass(ID), EmitFallbackDiag(EmitFallbackDiag) {}
Quentin Colombet374796d2016-08-27 00:18:31 +000032
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 Colombet612cd1f2016-08-31 18:43:01 +000042 if (EmitFallbackDiag) {
43 const Function &F = *MF.getFunction();
44 DiagnosticInfoISelFallback DiagFallback(F);
45 F.getContext().diagnose(DiagFallback);
46 }
Quentin Colombet374796d2016-08-27 00:18:31 +000047 return true;
48 }
49 return false;
50 }
51
52 };
53} // end anonymous namespace
54
55char ResetMachineFunction::ID = 0;
56INITIALIZE_PASS(ResetMachineFunction, DEBUG_TYPE,
57 "reset machine function if ISel failed", false, false)
58
59MachineFunctionPass *
Quentin Colombet612cd1f2016-08-31 18:43:01 +000060llvm::createResetMachineFunctionPass(bool EmitFallbackDiag = false) {
61 return new ResetMachineFunction(EmitFallbackDiag);
Quentin Colombet374796d2016-08-27 00:18:31 +000062}