Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:25

0001 //===- SymbolRemappingReader.h - Read symbol remapping file -----*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file contains definitions needed for reading and applying symbol
0010 // remapping files.
0011 //
0012 // Support is provided only for the Itanium C++ name mangling scheme for now.
0013 //
0014 // NOTE: If you are making changes to this file format, please remember
0015 //       to document them in the Clang documentation at
0016 //       tools/clang/docs/UsersManual.rst.
0017 //
0018 // File format
0019 // -----------
0020 //
0021 // The symbol remappings are written as an ASCII text file. Blank lines and
0022 // lines starting with a # are ignored. All other lines specify a kind of
0023 // mangled name fragment, along with two fragments of that kind that should
0024 // be treated as equivalent, separated by spaces.
0025 //
0026 // See http://itanium-cxx-abi.github.io/cxx-abi/abi.html#mangling for a
0027 // description of the Itanium name mangling scheme.
0028 //
0029 // The accepted fragment kinds are:
0030 //
0031 //  * name  A <name>, such as 6foobar or St3__1
0032 //  * type  A <type>, such as Ss or N4llvm9StringRefE
0033 //  * encoding  An <encoding> (a complete mangling without the leading _Z)
0034 //
0035 // For example:
0036 //
0037 // # Ignore int / long differences to treat symbols from 32-bit and 64-bit
0038 // # builds with differing size_t / ptrdiff_t / intptr_t as equivalent.
0039 // type i l
0040 // type j m
0041 //
0042 // # Ignore differences between libc++ and libstdc++, and between libstdc++'s
0043 // # C++98 and C++11 ABIs.
0044 // name 3std St3__1
0045 // name 3std St7__cxx11
0046 //
0047 // # Remap a function overload to a specialization of a template (including
0048 // # any local symbols declared within it).
0049 // encoding N2NS1fEi N2NS1fIiEEvT_
0050 //
0051 // # Substitutions must be remapped separately from namespace 'std' for now.
0052 // name Sa NSt3__19allocatorE
0053 // name Sb NSt3__112basic_stringE
0054 // type Ss NSt3__112basic_stringIcSt11char_traitsIcESaE
0055 // # ...
0056 //
0057 //===----------------------------------------------------------------------===//
0058 
0059 #ifndef LLVM_PROFILEDATA_SYMBOLREMAPPINGREADER_H
0060 #define LLVM_PROFILEDATA_SYMBOLREMAPPINGREADER_H
0061 
0062 #include "llvm/ADT/StringRef.h"
0063 #include "llvm/ProfileData/ItaniumManglingCanonicalizer.h"
0064 #include "llvm/Support/Error.h"
0065 
0066 namespace llvm {
0067 
0068 class MemoryBuffer;
0069 
0070 class SymbolRemappingParseError : public ErrorInfo<SymbolRemappingParseError> {
0071 public:
0072   SymbolRemappingParseError(StringRef File, int64_t Line, const Twine &Message)
0073       : File(File), Line(Line), Message(Message.str()) {}
0074 
0075   void log(llvm::raw_ostream &OS) const override {
0076     OS << File << ':' << Line << ": " << Message;
0077   }
0078   std::error_code convertToErrorCode() const override {
0079     return llvm::inconvertibleErrorCode();
0080   }
0081 
0082   StringRef getFileName() const { return File; }
0083   int64_t getLineNum() const { return Line; }
0084   StringRef getMessage() const { return Message; }
0085 
0086   static char ID;
0087 
0088 private:
0089   std::string File;
0090   int64_t Line;
0091   std::string Message;
0092 };
0093 
0094 /// Reader for symbol remapping files.
0095 ///
0096 /// Remaps the symbol names in profile data to match those in the program
0097 /// according to a set of rules specified in a given file.
0098 class SymbolRemappingReader {
0099 public:
0100   /// Read remappings from the given buffer, which must live as long as
0101   /// the remapper.
0102   Error read(MemoryBuffer &B);
0103 
0104   /// A Key represents an equivalence class of symbol names.
0105   using Key = uintptr_t;
0106 
0107   /// Construct a key for the given symbol, or return an existing one if an
0108   /// equivalent name has already been inserted. The symbol name must live
0109   /// as long as the remapper.
0110   ///
0111   /// The result will be Key() if the name cannot be remapped (typically
0112   /// because it is not a valid mangled name).
0113   Key insert(StringRef FunctionName) {
0114     return Canonicalizer.canonicalize(FunctionName);
0115   }
0116 
0117   /// Map the given symbol name into the key for the corresponding equivalence
0118   /// class.
0119   ///
0120   /// The result will typically be Key() if no equivalent symbol has been
0121   /// inserted, but this is not guaranteed: a Key different from all keys ever
0122   /// returned by \c insert may be returned instead.
0123   Key lookup(StringRef FunctionName) {
0124     return Canonicalizer.lookup(FunctionName);
0125   }
0126 
0127 private:
0128   ItaniumManglingCanonicalizer Canonicalizer;
0129 };
0130 
0131 } // end namespace llvm
0132 
0133 #endif // LLVM_PROFILEDATA_SYMBOLREMAPPINGREADER_H