RemarkStreamer.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/Remarks/RemarkStreamer.h ----------------------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file declares the main interface for streaming remarks.
  15. //
  16. // This is used to stream any llvm::remarks::Remark to an open file taking
  17. // advantage of all the serialization capabilities developed for remarks (e.g.
  18. // metadata in a section, bitstream format, etc.).
  19. //
  20. // Typically, a specialized remark emitter should hold a reference to the main
  21. // remark streamer set up in the LLVMContext, and should convert specialized
  22. // diagnostics to llvm::remarks::Remark objects as they get emitted.
  23. //
  24. // Specialized remark emitters can be components like:
  25. // * Remarks from LLVM (M)IR passes
  26. // * Remarks from the frontend
  27. // * Remarks from an intermediate IR
  28. //
  29. // This allows for composition between specialized remark emitters throughout
  30. // the compilation pipeline, that end up in the same file, using the same format
  31. // and serialization techniques.
  32. //
  33. //===----------------------------------------------------------------------===//
  34. #ifndef LLVM_REMARKS_REMARKSTREAMER_H
  35. #define LLVM_REMARKS_REMARKSTREAMER_H
  36. #include "llvm/ADT/Optional.h"
  37. #include "llvm/Remarks/RemarkSerializer.h"
  38. #include "llvm/Support/Error.h"
  39. #include "llvm/Support/Regex.h"
  40. #include "llvm/Support/raw_ostream.h"
  41. #include <memory>
  42. namespace llvm {
  43. namespace remarks {
  44. class RemarkStreamer final {
  45. /// The regex used to filter remarks based on the passes that emit them.
  46. Optional<Regex> PassFilter;
  47. /// The object used to serialize the remarks to a specific format.
  48. std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer;
  49. /// The filename that the remark diagnostics are emitted to.
  50. const Optional<std::string> Filename;
  51. public:
  52. RemarkStreamer(std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
  53. Optional<StringRef> Filename = None);
  54. /// Return the filename that the remark diagnostics are emitted to.
  55. Optional<StringRef> getFilename() const {
  56. return Filename ? Optional<StringRef>(*Filename) : None;
  57. }
  58. /// Return stream that the remark diagnostics are emitted to.
  59. raw_ostream &getStream() { return RemarkSerializer->OS; }
  60. /// Return the serializer used for this stream.
  61. remarks::RemarkSerializer &getSerializer() { return *RemarkSerializer; }
  62. /// Set a pass filter based on a regex \p Filter.
  63. /// Returns an error if the regex is invalid.
  64. Error setFilter(StringRef Filter);
  65. /// Check wether the string matches the filter.
  66. bool matchesFilter(StringRef Str);
  67. /// Check if the remarks also need to have associated metadata in a section.
  68. bool needsSection() const;
  69. };
  70. } // end namespace remarks
  71. } // end namespace llvm
  72. #endif // LLVM_REMARKS_REMARKSTREAMER_H
  73. #ifdef __GNUC__
  74. #pragma GCC diagnostic pop
  75. #endif