LLVM 22.0.0git
SymbolRemappingReader.h
Go to the documentation of this file.
1//===- SymbolRemappingReader.h - Read symbol remapping file -----*- 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 definitions needed for reading and applying symbol
10// remapping files.
11//
12// Support is provided only for the Itanium C++ name mangling scheme for now.
13//
14// NOTE: If you are making changes to this file format, please remember
15// to document them in the Clang documentation at
16// tools/clang/docs/UsersManual.rst.
17//
18// File format
19// -----------
20//
21// The symbol remappings are written as an ASCII text file. Blank lines and
22// lines starting with a # are ignored. All other lines specify a kind of
23// mangled name fragment, along with two fragments of that kind that should
24// be treated as equivalent, separated by spaces.
25//
26// See http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling for a
27// description of the Itanium name mangling scheme.
28//
29// The accepted fragment kinds are:
30//
31// * name A <name>, such as 6foobar or St3__1
32// * type A <type>, such as Ss or N4llvm9StringRefE
33// * encoding An <encoding> (a complete mangling without the leading _Z)
34//
35// For example:
36//
37// # Ignore int / long differences to treat symbols from 32-bit and 64-bit
38// # builds with differing size_t / ptrdiff_t / intptr_t as equivalent.
39// type i l
40// type j m
41//
42// # Ignore differences between libc++ and libstdc++, and between libstdc++'s
43// # C++98 and C++11 ABIs.
44// name 3std St3__1
45// name 3std St7__cxx11
46//
47// # Remap a function overload to a specialization of a template (including
48// # any local symbols declared within it).
49// encoding N2NS1fEi N2NS1fIiEEvT_
50//
51// # Substitutions must be remapped separately from namespace 'std' for now.
52// name Sa NSt3__19allocatorE
53// name Sb NSt3__112basic_stringE
54// type Ss NSt3__112basic_stringIcSt11char_traitsIcESaE
55// # ...
56//
57//===----------------------------------------------------------------------===//
58
59#ifndef LLVM_PROFILEDATA_SYMBOLREMAPPINGREADER_H
60#define LLVM_PROFILEDATA_SYMBOLREMAPPINGREADER_H
61
62#include "llvm/ADT/StringRef.h"
65#include "llvm/Support/Error.h"
66
67namespace llvm {
68
69class MemoryBuffer;
70
71class SymbolRemappingParseError : public ErrorInfo<SymbolRemappingParseError> {
72public:
73 SymbolRemappingParseError(StringRef File, int64_t Line, const Twine &Message)
74 : File(File), Line(Line), Message(Message.str()) {}
75
76 void log(llvm::raw_ostream &OS) const override {
77 OS << File << ':' << Line << ": " << Message;
78 }
79 std::error_code convertToErrorCode() const override {
81 }
82
83 StringRef getFileName() const { return File; }
84 int64_t getLineNum() const { return Line; }
85 StringRef getMessage() const { return Message; }
86
87 LLVM_ABI static char ID;
88
89private:
90 std::string File;
91 int64_t Line;
92 std::string Message;
93};
94
95/// Reader for symbol remapping files.
96///
97/// Remaps the symbol names in profile data to match those in the program
98/// according to a set of rules specified in a given file.
100public:
101 /// Read remappings from the given buffer, which must live as long as
102 /// the remapper.
104
105 /// A Key represents an equivalence class of symbol names.
106 using Key = uintptr_t;
107
108 /// Construct a key for the given symbol, or return an existing one if an
109 /// equivalent name has already been inserted. The symbol name must live
110 /// as long as the remapper.
111 ///
112 /// The result will be Key() if the name cannot be remapped (typically
113 /// because it is not a valid mangled name).
114 Key insert(StringRef FunctionName) {
115 return Canonicalizer.canonicalize(FunctionName);
116 }
117
118 /// Map the given symbol name into the key for the corresponding equivalence
119 /// class.
120 ///
121 /// The result will typically be Key() if no equivalent symbol has been
122 /// inserted, but this is not guaranteed: a Key different from all keys ever
123 /// returned by \c insert may be returned instead.
124 Key lookup(StringRef FunctionName) {
125 return Canonicalizer.lookup(FunctionName);
126 }
127
128private:
129 ItaniumManglingCanonicalizer Canonicalizer;
130};
131
132} // end namespace llvm
133
134#endif // LLVM_PROFILEDATA_SYMBOLREMAPPINGREADER_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition: Compiler.h:213
raw_pwrite_stream & OS
Base class for user error types.
Definition: Error.h:354
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
LLVM_ABI Key lookup(StringRef Mangling)
Find a canonical key for the specified mangling, if one has already been formed.
LLVM_ABI Key canonicalize(StringRef Mangling)
Form a canonical key for the specified mangling.
This interface provides simple read-only access to a block of memory, and provides simple methods for...
Definition: MemoryBuffer.h:52
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
std::error_code convertToErrorCode() const override
Convert this error to a std::error_code.
SymbolRemappingParseError(StringRef File, int64_t Line, const Twine &Message)
void log(llvm::raw_ostream &OS) const override
Print an error message to an output stream.
Reader for symbol remapping files.
Key insert(StringRef FunctionName)
Construct a key for the given symbol, or return an existing one if an equivalent name has already bee...
Key lookup(StringRef FunctionName)
Map the given symbol name into the key for the corresponding equivalence class.
LLVM_ABI Error read(MemoryBuffer &B)
Read remappings from the given buffer, which must live as long as the remapper.
uintptr_t Key
A Key represents an equivalence class of symbol names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
LLVM_ABI std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
Definition: Error.cpp:98