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-07-13 00:08:38 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      598602 : struct PassRemarksOpt {
      26             :   std::shared_ptr<Regex> Pattern;
      27             : 
      28         348 :   void operator=(const std::string &Val) {
      29             :     // Create a regexp object to match pass names for emitOptimizationRemark.
      30         348 :     if (!Val.empty()) {
      31         348 :       Pattern = std::make_shared<Regex>(Val);
      32             :       std::string RegexError;
      33         348 :       if (!Pattern->isValid(RegexError))
      34           2 :         report_fatal_error("Invalid regular expression '" + Val +
      35           1 :                                "' in -pass-remarks: " + RegexError,
      36             :                            false);
      37             :     }
      38         347 :   }
      39             : };
      40             : 
      41       99767 : static PassRemarksOpt PassRemarksPassedOptLoc;
      42       99767 : static PassRemarksOpt PassRemarksMissedOptLoc;
      43       99767 : static PassRemarksOpt PassRemarksAnalysisOptLoc;
      44             : 
      45             : // -pass-remarks
      46             : //    Command line flag to enable emitOptimizationRemark()
      47       99767 : static cl::opt<PassRemarksOpt, true, cl::parser<std::string>> PassRemarks(
      48       99767 :     "pass-remarks", cl::value_desc("pattern"),
      49       99767 :     cl::desc("Enable optimization remarks from passes whose name match "
      50             :              "the given regular expression"),
      51      199534 :     cl::Hidden, cl::location(PassRemarksPassedOptLoc), cl::ValueRequired,
      52      498835 :     cl::ZeroOrMore);
      53             : 
      54             : // -pass-remarks-missed
      55             : //    Command line flag to enable emitOptimizationRemarkMissed()
      56       99767 : static cl::opt<PassRemarksOpt, true, cl::parser<std::string>> PassRemarksMissed(
      57       99767 :     "pass-remarks-missed", cl::value_desc("pattern"),
      58       99767 :     cl::desc("Enable missed optimization remarks from passes whose name match "
      59             :              "the given regular expression"),
      60      199534 :     cl::Hidden, cl::location(PassRemarksMissedOptLoc), cl::ValueRequired,
      61      498835 :     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       99767 :     PassRemarksAnalysis(
      67       99767 :         "pass-remarks-analysis", cl::value_desc("pattern"),
      68       99767 :         cl::desc(
      69             :             "Enable optimization analysis remarks from passes whose name match "
      70             :             "the given regular expression"),
      71      199534 :         cl::Hidden, cl::location(PassRemarksAnalysisOptLoc), cl::ValueRequired,
      72      498835 :         cl::ZeroOrMore);
      73             : }
      74             : 
      75    56969161 : bool DiagnosticHandler::isAnalysisRemarkEnabled(StringRef PassName) const {
      76    56975149 :   return (PassRemarksAnalysisOptLoc.Pattern &&
      77   113944310 :           PassRemarksAnalysisOptLoc.Pattern->match(PassName));
      78             : }
      79       31091 : bool DiagnosticHandler::isMissedOptRemarkEnabled(StringRef PassName) const {
      80       31731 :   return (PassRemarksMissedOptLoc.Pattern &&
      81       62822 :           PassRemarksMissedOptLoc.Pattern->match(PassName));
      82             : }
      83        7196 : bool DiagnosticHandler::isPassedOptRemarkEnabled(StringRef PassName) const {
      84        7451 :   return (PassRemarksPassedOptLoc.Pattern &&
      85       14647 :           PassRemarksPassedOptLoc.Pattern->match(PassName));
      86             : }
      87             : 
      88      202330 : bool DiagnosticHandler::isAnyRemarkEnabled() const {
      89      404187 :   return (PassRemarksPassedOptLoc.Pattern || PassRemarksMissedOptLoc.Pattern ||
      90      404187 :           PassRemarksAnalysisOptLoc.Pattern);
      91      299301 : }

Generated by: LCOV version 1.13