LLVM  10.0.0svn
ItaniumManglingCanonicalizer.h
Go to the documentation of this file.
1 //===--- ItaniumManglingCanonicalizer.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 defines a class for computing equivalence classes of mangled names
10 // given a set of equivalences between name fragments.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H
15 #define LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H
16 
17 #include "llvm/ADT/StringRef.h"
18 
19 #include <cstddef>
20 
21 namespace llvm {
22 /// Canonicalizer for mangled names.
23 ///
24 /// This class allows specifying a list of "equivalent" manglings. For example,
25 /// you can specify that Ss is equivalent to
26 /// NSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEE
27 /// and then manglings that refer to libstdc++'s 'std::string' will be
28 /// considered equivalent to manglings that are the same except that they refer
29 /// to libc++'s 'std::string'.
30 ///
31 /// This can be used when data (eg, profiling data) is available for a version
32 /// of a program built in a different configuration, with correspondingly
33 /// different manglings.
35 public:
38  void operator=(const ItaniumManglingCanonicalizer &) = delete;
40 
41  enum class EquivalenceError {
42  Success,
43 
44  /// Both the equivalent manglings have already been used as components of
45  /// some other mangling we've looked at. It's too late to add this
46  /// equivalence.
48 
49  /// The first equivalent mangling is invalid.
51 
52  /// The second equivalent mangling is invalid.
54  };
55 
56  enum class FragmentKind {
57  /// The mangling fragment is a <name> (or a predefined <substitution>).
58  Name,
59  /// The mangling fragment is a <type>.
60  Type,
61  /// The mangling fragment is an <encoding>.
62  Encoding,
63  };
64 
65  /// Add an equivalence between \p First and \p Second. Both manglings must
66  /// live at least as long as the canonicalizer.
68  StringRef Second);
69 
70  using Key = uintptr_t;
71 
72  /// Form a canonical key for the specified mangling. They key will be the
73  /// same for all equivalent manglings, and different for any two
74  /// non-equivalent manglings, but is otherwise unspecified.
75  ///
76  /// Returns Key() if (and only if) the mangling is not a valid Itanium C++
77  /// ABI mangling.
78  ///
79  /// The string denoted by Mangling must live as long as the canonicalizer.
80  Key canonicalize(StringRef Mangling);
81 
82  /// Find a canonical key for the specified mangling, if one has already been
83  /// formed. Otherwise returns Key().
84  Key lookup(StringRef Mangling);
85 
86 private:
87  struct Impl;
88  Impl *P;
89 };
90 } // namespace llvm
91 
92 #endif // LLVM_SUPPORT_ITANIUMMANGLINGCANONICALIZER_H
This class represents lattice values for constants.
Definition: AllocatorList.h:23
#define P(N)
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
Canonicalizer for mangled names.
Key lookup(StringRef Mangling)
Find a canonical key for the specified mangling, if one has already been formed.
Both the equivalent manglings have already been used as components of some other mangling we&#39;ve looke...
void operator=(const ItaniumManglingCanonicalizer &)=delete
EquivalenceError addEquivalence(FragmentKind Kind, StringRef First, StringRef Second)
Add an equivalence between First and Second.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:48
Key canonicalize(StringRef Mangling)
Form a canonical key for the specified mangling.