LLVM 17.0.0git
RemarkLinker.h
Go to the documentation of this file.
1//===-- llvm/Remarks/RemarkLinker.h -----------------------------*- 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 provides an interface to link together multiple remark files.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_REMARKS_REMARKLINKER_H
14#define LLVM_REMARKS_REMARKLINKER_H
15
16#include "llvm/Remarks/Remark.h"
19#include "llvm/Support/Error.h"
20#include <memory>
21#include <optional>
22#include <set>
23
24namespace llvm {
25
26namespace object {
27class ObjectFile;
28}
29
30namespace remarks {
31
33private:
34 /// Compare through the pointers.
35 struct RemarkPtrCompare {
36 bool operator()(const std::unique_ptr<Remark> &LHS,
37 const std::unique_ptr<Remark> &RHS) const {
38 assert(LHS && RHS && "Invalid pointers to compare.");
39 return *LHS < *RHS;
40 };
41 };
42
43 /// The main string table for the remarks.
44 /// Note: all remarks should use the strings from this string table to avoid
45 /// dangling references.
46 StringTable StrTab;
47
48 /// A set holding unique remarks.
49 /// FIXME: std::set is probably not the most appropriate data structure here.
50 /// Due to the limitation of having a move-only key, there isn't another
51 /// obvious choice for now.
52 std::set<std::unique_ptr<Remark>, RemarkPtrCompare> Remarks;
53
54 /// A path to append before the external file path found in remark metadata.
55 std::optional<std::string> PrependPath;
56
57 /// Keep this remark. If it's already in the set, discard it.
58 Remark &keep(std::unique_ptr<Remark> Remark);
59
60public:
61 /// Set a path to prepend to the external file path.
62 void setExternalFilePrependPath(StringRef PrependPath);
63
64 /// Link the remarks found in \p Buffer.
65 /// If \p RemarkFormat is not provided, try to deduce it from the metadata in
66 /// \p Buffer.
67 /// \p Buffer can be either a standalone remark container or just
68 /// metadata. This takes care of uniquing and merging the remarks.
69 Error link(StringRef Buffer,
70 std::optional<Format> RemarkFormat = std::nullopt);
71
72 /// Link the remarks found in \p Obj by looking for the right section and
73 /// calling the method above.
74 Error link(const object::ObjectFile &Obj,
75 std::optional<Format> RemarkFormat = std::nullopt);
76
77 /// Serialize the linked remarks to the stream \p OS, using the format \p
78 /// RemarkFormat.
79 /// This clears internal state such as the string table.
80 /// Note: this implies that the serialization mode is standalone.
82
83 /// Check whether there are any remarks linked.
84 bool empty() const { return Remarks.empty(); }
85
86 /// Return a collection of the linked unique remarks to iterate on.
87 /// Ex:
88 /// for (const Remark &R : RL.remarks() { [...] }
89 using iterator = pointee_iterator<decltype(Remarks)::const_iterator>;
90
92 return {Remarks.begin(), Remarks.end()};
93 }
94};
95
96/// Returns a buffer with the contents of the remarks section depending on the
97/// format of the file. If the section doesn't exist, this returns an empty
98/// optional.
101
102} // end namespace remarks
103} // end namespace llvm
104
105#endif // LLVM_REMARKS_REMARKLINKER_H
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Value * LHS
Lightweight error class with error context and mandatory checking.
Definition: Error.h:156
Tagged union holding either a T or a Error.
Definition: Error.h:470
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
A range adaptor for a pair of iterators.
This class is the base class for all object file types.
Definition: ObjectFile.h:228
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
Format
The format used for serializing/deserializing remarks.
Definition: RemarkFormat.h:25
Expected< std::optional< StringRef > > getRemarksSectionContents(const object::ObjectFile &Obj)
Returns a buffer with the contents of the remarks section depending on the format of the file.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
cl::opt< std::string > RemarksFormat("lto-pass-remarks-format", cl::desc("The format used for serializing remarks (default: YAML)"), cl::value_desc("format"), cl::init("yaml"))
An iterator type that allows iterating over the pointees via some other iterator.
Definition: iterator.h:324
void setExternalFilePrependPath(StringRef PrependPath)
Set a path to prepend to the external file path.
Error serialize(raw_ostream &OS, Format RemarksFormat) const
Serialize the linked remarks to the stream OS, using the format RemarkFormat.
bool empty() const
Check whether there are any remarks linked.
Definition: RemarkLinker.h:84
Error link(StringRef Buffer, std::optional< Format > RemarkFormat=std::nullopt)
Link the remarks found in Buffer.
iterator_range< iterator > remarks() const
Definition: RemarkLinker.h:91
A remark type used for both emission and parsing.
Definition: Remark.h:67
The string table used for serializing remarks.