Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/include/llvm/IR/RemarkStreamer.h
Line
Count
Source (jump to first uncovered line)
1
//===- llvm/IR/RemarkStreamer.h - Remark Streamer ---------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file declares the main interface for outputting remarks.
10
//
11
//===----------------------------------------------------------------------===//
12
13
#ifndef LLVM_IR_REMARKSTREAMER_H
14
#define LLVM_IR_REMARKSTREAMER_H
15
16
#include "llvm/IR/DiagnosticInfo.h"
17
#include "llvm/Remarks/RemarkSerializer.h"
18
#include "llvm/Support/Error.h"
19
#include "llvm/Support/Regex.h"
20
#include "llvm/Support/ToolOutputFile.h"
21
#include "llvm/Support/raw_ostream.h"
22
#include <string>
23
#include <vector>
24
25
namespace llvm {
26
/// Streamer for remarks.
27
class RemarkStreamer {
28
  /// The filename that the remark diagnostics are emitted to.
29
  const std::string Filename;
30
  /// The regex used to filter remarks based on the passes that emit them.
31
  Optional<Regex> PassFilter;
32
  /// The object used to serialize the remarks to a specific format.
33
  std::unique_ptr<remarks::Serializer> Serializer;
34
35
  /// Convert diagnostics into remark objects.
36
  /// The lifetime of the members of the result is bound to the lifetime of
37
  /// the LLVM diagnostics.
38
  remarks::Remark toRemark(const DiagnosticInfoOptimizationBase &Diag);
39
40
public:
41
  RemarkStreamer(StringRef Filename,
42
                 std::unique_ptr<remarks::Serializer> Serializer);
43
  /// Return the filename that the remark diagnostics are emitted to.
44
3
  StringRef getFilename() const { return Filename; }
45
  /// Return stream that the remark diagnostics are emitted to.
46
0
  raw_ostream &getStream() { return Serializer->OS; }
47
  /// Return the serializer used for this stream.
48
3
  remarks::Serializer &getSerializer() { return *Serializer; }
49
  /// Set a pass filter based on a regex \p Filter.
50
  /// Returns an error if the regex is invalid.
51
  Error setFilter(StringRef Filter);
52
  /// Emit a diagnostic through the streamer.
53
  void emit(const DiagnosticInfoOptimizationBase &Diag);
54
};
55
56
template <typename ThisError>
57
struct RemarkSetupErrorInfo : public ErrorInfo<ThisError> {
58
  std::string Msg;
59
  std::error_code EC;
60
61
2
  RemarkSetupErrorInfo(Error E) {
62
2
    handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) {
63
2
      Msg = EIB.message();
64
2
      EC = EIB.convertToErrorCode();
65
2
    });
Unexecuted instantiation: llvm::RemarkSetupErrorInfo<llvm::RemarkSetupFileError>::RemarkSetupErrorInfo(llvm::Error)::'lambda'(llvm::ErrorInfoBase const&)::operator()(llvm::ErrorInfoBase const&) const
llvm::RemarkSetupErrorInfo<llvm::RemarkSetupFormatError>::RemarkSetupErrorInfo(llvm::Error)::'lambda'(llvm::ErrorInfoBase const&)::operator()(llvm::ErrorInfoBase const&) const
Line
Count
Source
62
1
    handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) {
63
1
      Msg = EIB.message();
64
1
      EC = EIB.convertToErrorCode();
65
1
    });
llvm::RemarkSetupErrorInfo<llvm::RemarkSetupPatternError>::RemarkSetupErrorInfo(llvm::Error)::'lambda'(llvm::ErrorInfoBase const&)::operator()(llvm::ErrorInfoBase const&) const
Line
Count
Source
62
1
    handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) {
63
1
      Msg = EIB.message();
64
1
      EC = EIB.convertToErrorCode();
65
1
    });
66
2
  }
Unexecuted instantiation: llvm::RemarkSetupErrorInfo<llvm::RemarkSetupFileError>::RemarkSetupErrorInfo(llvm::Error)
llvm::RemarkSetupErrorInfo<llvm::RemarkSetupFormatError>::RemarkSetupErrorInfo(llvm::Error)
Line
Count
Source
61
1
  RemarkSetupErrorInfo(Error E) {
62
1
    handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) {
63
1
      Msg = EIB.message();
64
1
      EC = EIB.convertToErrorCode();
65
1
    });
66
1
  }
llvm::RemarkSetupErrorInfo<llvm::RemarkSetupPatternError>::RemarkSetupErrorInfo(llvm::Error)
Line
Count
Source
61
1
  RemarkSetupErrorInfo(Error E) {
62
1
    handleAllErrors(std::move(E), [&](const ErrorInfoBase &EIB) {
63
1
      Msg = EIB.message();
64
1
      EC = EIB.convertToErrorCode();
65
1
    });
66
1
  }
67
68
1
  void log(raw_ostream &OS) const override { OS << Msg; }
Unexecuted instantiation: llvm::RemarkSetupErrorInfo<llvm::RemarkSetupFileError>::log(llvm::raw_ostream&) const
Unexecuted instantiation: llvm::RemarkSetupErrorInfo<llvm::RemarkSetupFormatError>::log(llvm::raw_ostream&) const
llvm::RemarkSetupErrorInfo<llvm::RemarkSetupPatternError>::log(llvm::raw_ostream&) const
Line
Count
Source
68
1
  void log(raw_ostream &OS) const override { OS << Msg; }
69
0
  std::error_code convertToErrorCode() const override { return EC; }
Unexecuted instantiation: llvm::RemarkSetupErrorInfo<llvm::RemarkSetupFileError>::convertToErrorCode() const
Unexecuted instantiation: llvm::RemarkSetupErrorInfo<llvm::RemarkSetupFormatError>::convertToErrorCode() const
Unexecuted instantiation: llvm::RemarkSetupErrorInfo<llvm::RemarkSetupPatternError>::convertToErrorCode() const
70
};
71
72
struct RemarkSetupFileError : RemarkSetupErrorInfo<RemarkSetupFileError> {
73
  static char ID;
74
  using RemarkSetupErrorInfo<RemarkSetupFileError>::RemarkSetupErrorInfo;
75
};
76
77
struct RemarkSetupPatternError : RemarkSetupErrorInfo<RemarkSetupPatternError> {
78
  static char ID;
79
  using RemarkSetupErrorInfo<RemarkSetupPatternError>::RemarkSetupErrorInfo;
80
};
81
82
struct RemarkSetupFormatError : RemarkSetupErrorInfo<RemarkSetupFormatError> {
83
  static char ID;
84
  using RemarkSetupErrorInfo<RemarkSetupFormatError>::RemarkSetupErrorInfo;
85
};
86
87
/// Setup optimization remarks.
88
Expected<std::unique_ptr<ToolOutputFile>>
89
setupOptimizationRemarks(LLVMContext &Context, StringRef RemarksFilename,
90
                         StringRef RemarksPasses, StringRef RemarksFormat,
91
                         bool RemarksWithHotness,
92
                         unsigned RemarksHotnessThreshold = 0);
93
94
} // end namespace llvm
95
96
#endif // LLVM_IR_REMARKSTREAMER_H