LLVM 22.0.0git
RemarkStreamer.cpp
Go to the documentation of this file.
1//===- llvm/Remarks/RemarkStreamer.cpp - 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 contains the implementation of the main remark streamer.
10//
11//===----------------------------------------------------------------------===//
12
15#include <cassert>
16#include <optional>
17
18using namespace llvm;
19using namespace llvm::remarks;
20
22 "remarks-section",
24 "Emit a section containing remark diagnostics metadata. By default, "
25 "this is enabled for the following formats: bitstream."),
27
29 std::unique_ptr<remarks::RemarkSerializer> RemarkSerializer,
30 std::optional<StringRef> FilenameIn)
31 : RemarkSerializer(std::move(RemarkSerializer)),
32 Filename(FilenameIn ? std::optional<std::string>(FilenameIn->str())
33 : std::nullopt) {}
34
36 // Ensure that llvm::finalizeOptimizationRemarks was called before the
37 // RemarkStreamer is destroyed.
38 assert(!RemarkSerializer &&
39 "RemarkSerializer must be released before RemarkStreamer is "
40 "destroyed. Ensure llvm::finalizeOptimizationRemarks is called.");
41}
42
44 Regex R = Regex(Filter);
45 std::string RegexError;
46 if (!R.isValid(RegexError))
47 return createStringError(std::make_error_code(std::errc::invalid_argument),
48 RegexError.data());
49 PassFilter = std::move(R);
50 return Error::success();
51}
52
54 if (PassFilter)
55 return PassFilter->match(Str);
56 // No filter means all strings pass.
57 return true;
58}
59
62 return true;
63
65 return false;
66
68
69 // Enable remark sections by default for bitstream remarks (so dsymutil can
70 // find all remarks for a linked binary)
71 return RemarkSerializer->SerializerFormat == Format::Bitstream;
72}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static cl::opt< cl::boolOrDefault > EnableRemarksSection("remarks-section", cl::desc("Emit a section containing remark diagnostics metadata. By default, " "this is enabled for the following formats: bitstream."), cl::init(cl::BOU_UNSET), cl::Hidden)
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
static ErrorSuccess success()
Create a success value.
Definition Error.h:336
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
Error setFilter(StringRef Filter)
Set a pass filter based on a regex Filter.
bool needsSection() const
Check if the remarks also need to have associated metadata in a section.
RemarkStreamer(std::unique_ptr< remarks::RemarkSerializer > RemarkSerializer, std::optional< StringRef > Filename=std::nullopt)
bool matchesFilter(StringRef Str)
Check wether the string matches the filter.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
Definition Error.h:1305
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition STLExtras.h:1847
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870