From 612cd1fdd64cc7593b38115abd0e1bfb6f552b9d Mon Sep 17 00:00:00 2001 From: Quentin Colombet Date: Wed, 31 Aug 2016 18:43:01 +0000 Subject: [PATCH] [ResetMachineFunction] Emit the diagnostic isel fallback when asked. This pass is now able to report when the function is being reset. llvm-svn: 280272 --- llvm/include/llvm/CodeGen/Passes.h | 6 +++++- llvm/lib/CodeGen/ResetMachineFunctionPass.cpp | 19 ++++++++++++++----- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/llvm/include/llvm/CodeGen/Passes.h b/llvm/include/llvm/CodeGen/Passes.h index 26fb834d95a8..09e660987482 100644 --- a/llvm/include/llvm/CodeGen/Passes.h +++ b/llvm/include/llvm/CodeGen/Passes.h @@ -53,7 +53,11 @@ namespace llvm { /// using the MIR serialization format. MachineFunctionPass *createPrintMIRPass(raw_ostream &OS); - MachineFunctionPass *createResetMachineFunctionPass(); + /// This pass resets a MachineFunction when it has the FailedISel property + /// as if it was just created. + /// If EmitFallbackDiag is true, the pass will emit a + /// DiagnosticInfoISelFallback for every MachineFunction it resets. + MachineFunctionPass *createResetMachineFunctionPass(bool EmitFallbackDiag); /// createCodeGenPreparePass - Transform the code to expose more pattern /// matching during instruction selection. diff --git a/llvm/lib/CodeGen/ResetMachineFunctionPass.cpp b/llvm/lib/CodeGen/ResetMachineFunctionPass.cpp index 3b7729a05406..07a8259a70cf 100644 --- a/llvm/lib/CodeGen/ResetMachineFunctionPass.cpp +++ b/llvm/lib/CodeGen/ResetMachineFunctionPass.cpp @@ -13,6 +13,7 @@ #include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/MachineFunction.h" #include "llvm/CodeGen/MachineFunctionPass.h" +#include "llvm/IR/DiagnosticInfo.h" #include "llvm/Support/Debug.h" using namespace llvm; @@ -20,11 +21,14 @@ using namespace llvm; namespace { class ResetMachineFunction : public MachineFunctionPass { + /// Tells whether or not this pass should emit a fallback + /// diagnostic when it resets a function. + bool EmitFallbackDiag; + public: static char ID; // Pass identification, replacement for typeid - ResetMachineFunction() : - MachineFunctionPass(ID) { - } + ResetMachineFunction(bool EmitFallbackDiag = false) + : MachineFunctionPass(ID), EmitFallbackDiag(EmitFallbackDiag) {} const char *getPassName() const override { return "ResetMachineFunction"; @@ -35,6 +39,11 @@ namespace { MachineFunctionProperties::Property::FailedISel)) { DEBUG(dbgs() << "Reseting: " << MF.getName() << '\n'); MF.reset(); + if (EmitFallbackDiag) { + const Function &F = *MF.getFunction(); + DiagnosticInfoISelFallback DiagFallback(F); + F.getContext().diagnose(DiagFallback); + } return true; } return false; @@ -48,6 +57,6 @@ INITIALIZE_PASS(ResetMachineFunction, DEBUG_TYPE, "reset machine function if ISel failed", false, false) MachineFunctionPass * -llvm::createResetMachineFunctionPass() { - return new ResetMachineFunction(); +llvm::createResetMachineFunctionPass(bool EmitFallbackDiag = false) { + return new ResetMachineFunction(EmitFallbackDiag); }