LCOV - code coverage report
Current view: top level - lib/CodeGen - ResetMachineFunctionPass.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 15 17 88.2 %
Date: 2017-09-14 15:23:50 Functions: 4 7 57.1 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===-- ResetMachineFunctionPass.cpp - Reset Machine Function ----*- C++ -*-==//
       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             : /// \file
      10             : /// This file implements a pass that will conditionally reset a machine
      11             : /// function as if it was just created. This is used to provide a fallback
      12             : /// mechanism when GlobalISel fails, thus the condition for the reset to
      13             : /// happen is that the MachineFunction has the FailedISel property.
      14             : //===----------------------------------------------------------------------===//
      15             : 
      16             : #include "llvm/ADT/Statistic.h"
      17             : #include "llvm/CodeGen/MachineFunction.h"
      18             : #include "llvm/CodeGen/MachineFunctionPass.h"
      19             : #include "llvm/CodeGen/Passes.h"
      20             : #include "llvm/IR/DiagnosticInfo.h"
      21             : #include "llvm/Support/Debug.h"
      22             : using namespace llvm;
      23             : 
      24             : #define DEBUG_TYPE "reset-machine-function"
      25             : 
      26             : STATISTIC(NumFunctionsReset, "Number of functions reset");
      27             : 
      28             : namespace {
      29         113 :   class ResetMachineFunction : public MachineFunctionPass {
      30             :     /// Tells whether or not this pass should emit a fallback
      31             :     /// diagnostic when it resets a function.
      32             :     bool EmitFallbackDiag;
      33             :     /// Whether we should abort immediately instead of resetting the function.
      34             :     bool AbortOnFailedISel;
      35             : 
      36             :   public:
      37             :     static char ID; // Pass identification, replacement for typeid
      38             :     ResetMachineFunction(bool EmitFallbackDiag = false,
      39             :                          bool AbortOnFailedISel = false)
      40         114 :         : MachineFunctionPass(ID), EmitFallbackDiag(EmitFallbackDiag),
      41         114 :           AbortOnFailedISel(AbortOnFailedISel) {}
      42             : 
      43           5 :     StringRef getPassName() const override { return "ResetMachineFunction"; }
      44             : 
      45         603 :     bool runOnMachineFunction(MachineFunction &MF) override {
      46        1206 :       if (MF.getProperties().hasProperty(
      47             :               MachineFunctionProperties::Property::FailedISel)) {
      48          93 :         if (AbortOnFailedISel)
      49           0 :           report_fatal_error("Instruction selection failed");
      50             :         DEBUG(dbgs() << "Reseting: " << MF.getName() << '\n');
      51          93 :         ++NumFunctionsReset;
      52          93 :         MF.reset();
      53          93 :         if (EmitFallbackDiag) {
      54          81 :           const Function &F = *MF.getFunction();
      55         162 :           DiagnosticInfoISelFallback DiagFallback(F);
      56          81 :           F.getContext().diagnose(DiagFallback);
      57             :         }
      58             :         return true;
      59             :       }
      60             :       return false;
      61             :     }
      62             : 
      63             :   };
      64             : } // end anonymous namespace
      65             : 
      66             : char ResetMachineFunction::ID = 0;
      67           0 : INITIALIZE_PASS(ResetMachineFunction, DEBUG_TYPE,
      68             :                 "reset machine function if ISel failed", false, false)
      69             : 
      70             : MachineFunctionPass *
      71         114 : llvm::createResetMachineFunctionPass(bool EmitFallbackDiag = false,
      72             :                                      bool AbortOnFailedISel = false) {
      73         228 :   return new ResetMachineFunction(EmitFallbackDiag, AbortOnFailedISel);
      74             : }

Generated by: LCOV version 1.13