Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===--- ItaniumManglingCanonicalizer.h -------------------------*- 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 defines a class for computing equivalence classes of mangled names
0010 // given a set of equivalences between name fragments.
0011 //
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_PROFILEDATA_ITANIUMMANGLINGCANONICALIZER_H
0015 #define LLVM_PROFILEDATA_ITANIUMMANGLINGCANONICALIZER_H
0016 
0017 #include <cstdint>
0018 
0019 namespace llvm {
0020 
0021 class StringRef;
0022 
0023 /// Canonicalizer for mangled names.
0024 ///
0025 /// This class allows specifying a list of "equivalent" manglings. For example,
0026 /// you can specify that Ss is equivalent to
0027 ///   NSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE
0028 /// and then manglings that refer to libstdc++'s 'std::string' will be
0029 /// considered equivalent to manglings that are the same except that they refer
0030 /// to libc++'s 'std::string'.
0031 ///
0032 /// This can be used when data (eg, profiling data) is available for a version
0033 /// of a program built in a different configuration, with correspondingly
0034 /// different manglings.
0035 class ItaniumManglingCanonicalizer {
0036 public:
0037   ItaniumManglingCanonicalizer();
0038   ItaniumManglingCanonicalizer(const ItaniumManglingCanonicalizer &) = delete;
0039   void operator=(const ItaniumManglingCanonicalizer &) = delete;
0040   ~ItaniumManglingCanonicalizer();
0041 
0042   enum class EquivalenceError {
0043     Success,
0044 
0045     /// Both the equivalent manglings have already been used as components of
0046     /// some other mangling we've looked at. It's too late to add this
0047     /// equivalence.
0048     ManglingAlreadyUsed,
0049 
0050     /// The first equivalent mangling is invalid.
0051     InvalidFirstMangling,
0052 
0053     /// The second equivalent mangling is invalid.
0054     InvalidSecondMangling,
0055   };
0056 
0057   enum class FragmentKind {
0058     /// The mangling fragment is a <name> (or a predefined <substitution>).
0059     Name,
0060     /// The mangling fragment is a <type>.
0061     Type,
0062     /// The mangling fragment is an <encoding>.
0063     Encoding,
0064   };
0065 
0066   /// Add an equivalence between \p First and \p Second. Both manglings must
0067   /// live at least as long as the canonicalizer.
0068   EquivalenceError addEquivalence(FragmentKind Kind, StringRef First,
0069                                   StringRef Second);
0070 
0071   using Key = uintptr_t;
0072 
0073   /// Form a canonical key for the specified mangling. They key will be the
0074   /// same for all equivalent manglings, and different for any two
0075   /// non-equivalent manglings, but is otherwise unspecified.
0076   ///
0077   /// Returns Key() if (and only if) the mangling is not a valid Itanium C++
0078   /// ABI mangling.
0079   ///
0080   /// The string denoted by Mangling must live as long as the canonicalizer.
0081   Key canonicalize(StringRef Mangling);
0082 
0083   /// Find a canonical key for the specified mangling, if one has already been
0084   /// formed. Otherwise returns Key().
0085   Key lookup(StringRef Mangling);
0086 
0087 private:
0088   struct Impl;
0089   Impl *P;
0090 };
0091 } // namespace llvm
0092 
0093 #endif // LLVM_PROFILEDATA_ITANIUMMANGLINGCANONICALIZER_H