LCOV - code coverage report
Current view: top level - lib/IR - DiagnosticHandler.cpp (source / functions) Hit Total Coverage
Test: llvm-toolchain.info Lines: 39 39 100.0 %
Date: 2018-06-17 00:07:59 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //===- DiagnosticHandler.h - DiagnosticHandler class for LLVM -------------===//
       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             : #include "llvm/IR/DiagnosticHandler.h"
      13             : #include "llvm/Support/CommandLine.h"
      14             : #include "llvm/Support/Regex.h"
      15             : 
      16             : using namespace llvm;
      17             : 
      18             : namespace {
      19             : 
      20             : /// Regular expression corresponding to the value given in one of the
      21             : /// -pass-remarks* command line flags. Passes whose name matches this regexp
      22             : /// will emit a diagnostic when calling the associated diagnostic function
      23             : /// (emitOptimizationRemark, emitOptimizationRemarkMissed or
      24             : /// emitOptimizationRemarkAnalysis).
      25      607158 : struct PassRemarksOpt {
      26             :   std::shared_ptr<Regex> Pattern;
      27             : 
      28         346 :   void operator=(const std::string &Val) {
      29             :     // Create a regexp object to match pass names for emitOptimizationRemark.
      30         346 :     if (!Val.empty()) {
      31         346 :       Pattern = std::make_shared<Regex>(Val);
      32             :       std::string RegexError;
      33         346 :       if (!Pattern->isValid(RegexError))
      34           2 :         report_fatal_error("Invalid regular expression '" + Val +
      35           1 :                                "' in -pass-remarks: " + RegexError,
      36             :                            false);
      37             :     }
      38         345 :   }
      39             : };
      40             : 
      41      101193 : static PassRemarksOpt PassRemarksPassedOptLoc;
      42      101193 : static PassRemarksOpt PassRemarksMissedOptLoc;
      43      101193 : static PassRemarksOpt PassRemarksAnalysisOptLoc;
      44             : 
      45             : // -pass-remarks
      46             : //    Command line flag to enable emitOptimizationRemark()
      47      101193 : static cl::opt<PassRemarksOpt, true, cl::parser<std::string>> PassRemarks(
      48      101193 :     "pass-remarks", cl::value_desc("pattern"),
      49      101193 :     cl::desc("Enable optimization remarks from passes whose name match "
      50             :              "the given regular expression"),
      51      202386 :     cl::Hidden, cl::location(PassRemarksPassedOptLoc), cl::ValueRequired,
      52      505965 :     cl::ZeroOrMore);
      53             : 
      54             : // -pass-remarks-missed
      55             : //    Command line flag to enable emitOptimizationRemarkMissed()
      56      101193 : static cl::opt<PassRemarksOpt, true, cl::parser<std::string>> PassRemarksMissed(
      57      101193 :     "pass-remarks-missed", cl::value_desc("pattern"),
      58      101193 :     cl::desc("Enable missed optimization remarks from passes whose name match "
      59             :              "the given regular expression"),
      60      202386 :     cl::Hidden, cl::location(PassRemarksMissedOptLoc), cl::ValueRequired,
      61      505965 :     cl::ZeroOrMore);
      62             : 
      63             : // -pass-remarks-analysis
      64             : //    Command line flag to enable emitOptimizationRemarkAnalysis()
      65             : static cl::opt<PassRemarksOpt, true, cl::parser<std::string>>
      66      101193 :     PassRemarksAnalysis(
      67      101193 :         "pass-remarks-analysis", cl::value_desc("pattern"),
      68      101193 :         cl::desc(
      69             :             "Enable optimization analysis remarks from passes whose name match "
      70             :             "the given regular expression"),
      71      202386 :         cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired,
      72      505965 :         cl::ZeroOrMore);
      73             : }
      74             : 
      75    55708372 : bool DiagnosticHandler::isAnalysisRemarkEnabled(StringRef PassName) const {
      76    55714360 :   return (PassRemarksAnalysisOptLoc.Pattern &&
      77   111422732 :           PassRemarksAnalysisOptLoc.Pattern->match(PassName));
      78             : }
      79       30209 : bool DiagnosticHandler::isMissedOptRemarkEnabled(StringRef PassName) const {
      80       30849 :   return (PassRemarksMissedOptLoc.Pattern &&
      81       61058 :           PassRemarksMissedOptLoc.Pattern->match(PassName));
      82             : }
      83        6970 : bool DiagnosticHandler::isPassedOptRemarkEnabled(StringRef PassName) const {
      84        7225 :   return (PassRemarksPassedOptLoc.Pattern &&
      85       14195 :           PassRemarksPassedOptLoc.Pattern->match(PassName));
      86             : }
      87             : 
      88      199152 : bool DiagnosticHandler::isAnyRemarkEnabled() const {
      89      397831 :   return (PassRemarksPassedOptLoc.Pattern || PassRemarksMissedOptLoc.Pattern ||
      90      397831 :           PassRemarksAnalysisOptLoc.Pattern);
      91      303579 : }

Generated by: LCOV version 1.13