Thanks to visit codestin.com
Credit goes to llvm.org

LLVM 22.0.0git
SymbolSet.h
Go to the documentation of this file.
1//===- llvm/TextAPI/SymbolSet.h - TAPI Symbol Set --------------*- 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#ifndef LLVM_TEXTAPI_SYMBOLSET_H
10#define LLVM_TEXTAPI_SYMBOLSET_H
11
12#include "llvm/ADT/DenseMap.h"
13#include "llvm/ADT/Hashing.h"
14#include "llvm/ADT/StringRef.h"
15#include "llvm/ADT/iterator.h"
21#include "llvm/TextAPI/Symbol.h"
22#include <stddef.h>
23
24namespace llvm {
25
33template <> struct DenseMapInfo<SymbolsMapKey> {
37
42
43 static unsigned getHashValue(const SymbolsMapKey &Key) {
44 return hash_combine(hash_value(Key.Kind), hash_value(Key.Name));
45 }
46
47 static bool isEqual(const SymbolsMapKey &LHS, const SymbolsMapKey &RHS) {
48 return std::tie(LHS.Kind, LHS.Name) == std::tie(RHS.Kind, RHS.Name);
49 }
50};
51
52template <typename DerivedT, typename KeyInfoT, typename BucketT>
54 KeyInfoT, BucketT> &LHS,
55 const DenseMapBase<DerivedT, SymbolsMapKey, MachO::Symbol *,
56 KeyInfoT, BucketT> &RHS) {
57 if (LHS.size() != RHS.size())
58 return false;
59 for (const auto &KV : LHS) {
60 auto I = RHS.find(KV.first);
61 if (I == RHS.end() || *I->second != *KV.second)
62 return false;
63 }
64 return true;
65}
66
67template <typename DerivedT, typename KeyInfoT, typename BucketT>
69 KeyInfoT, BucketT> &LHS,
70 const DenseMapBase<DerivedT, SymbolsMapKey, MachO::Symbol *,
71 KeyInfoT, BucketT> &RHS) {
72 return !(LHS == RHS);
73}
74
75namespace MachO {
76
77class SymbolSet {
78private:
79 llvm::BumpPtrAllocator Allocator;
80 StringRef copyString(StringRef String) {
81 if (String.empty())
82 return {};
83 void *Ptr = Allocator.Allocate(String.size(), 1);
84 memcpy(Ptr, String.data(), String.size());
85 return StringRef(reinterpret_cast<const char *>(Ptr), String.size());
86 }
87
88 using SymbolsMapType = llvm::DenseMap<SymbolsMapKey, Symbol *>;
89 SymbolsMapType Symbols;
90
91 LLVM_ABI Symbol *addGlobalImpl(EncodeKind, StringRef Name, SymbolFlags Flags);
92
93public:
94 SymbolSet() = default;
95 SymbolSet(const SymbolSet &other) = delete;
96 SymbolSet &operator=(const SymbolSet &other) = delete;
99 const Target &Targ);
100 size_t size() const { return Symbols.size(); }
101
102 template <typename RangeT, typename ElT = std::remove_reference_t<
103 decltype(*std::begin(std::declval<RangeT>()))>>
105 RangeT &&Targets) {
106 auto *Global = addGlobalImpl(Kind, Name, Flags);
107 for (const auto &Targ : Targets)
108 Global->addTarget(Targ);
110 addGlobal(EncodeKind::ObjectiveCClass, Name, Flags, Targets);
111 return Global;
112 }
113
114 LLVM_ABI const Symbol *
117
119 : public iterator_adaptor_base<
121 std::forward_iterator_tag, const Symbol *, ptrdiff_t,
122 const Symbol *, const Symbol *> {
124
125 template <typename U>
127 : iterator_adaptor_base(std::forward<U &&>(u)) {}
128
129 reference operator*() const { return I->second; }
130 pointer operator->() const { return I->second; }
131 };
132
134
137 std::function<bool(const Symbol *)>>;
140
141 // Range that contains all symbols.
143 return {Symbols.begin(), Symbols.end()};
144 }
145
146 // Range that contains all defined and exported symbols.
148 std::function<bool(const Symbol *)> fn = [](const Symbol *Symbol) {
149 return !Symbol->isUndefined() && !Symbol->isReexported();
150 };
151 return make_filter_range(
152 make_range<const_symbol_iterator>({Symbols.begin()}, {Symbols.end()}),
153 fn);
154 }
155
156 // Range that contains all reexported symbols.
158 std::function<bool(const Symbol *)> fn = [](const Symbol *Symbol) {
159 return Symbol->isReexported();
160 };
161 return make_filter_range(
162 make_range<const_symbol_iterator>({Symbols.begin()}, {Symbols.end()}),
163 fn);
164 }
165
166 // Range that contains all undefined and exported symbols.
168 std::function<bool(const Symbol *)> fn = [](const Symbol *Symbol) {
169 return Symbol->isUndefined();
170 };
171 return make_filter_range(
172 make_range<const_symbol_iterator>({Symbols.begin()}, {Symbols.end()}),
173 fn);
174 }
175
176 LLVM_ABI bool operator==(const SymbolSet &O) const;
177
178 bool operator!=(const SymbolSet &O) const { return !(Symbols == O.Symbols); }
179
180 void *allocate(size_t Size, unsigned Align = 8) {
181 return Allocator.Allocate(Size, Align);
182 }
183};
184
185} // namespace MachO
186} // namespace llvm
187#endif // LLVM_TEXTAPI_SYMBOLSET_H
This file defines the BumpPtrAllocator interface.
#define LLVM_ABI
Definition Compiler.h:213
This file defines the DenseMap class.
#define I(x, y, z)
Definition MD5.cpp:58
Value * RHS
Value * LHS
DenseMapIterator< KeyT, ValueT, KeyInfoT, BucketT, true > const_iterator
Definition DenseMap.h:75
SymbolSet & operator=(const SymbolSet &other)=delete
iterator_range< const_filtered_symbol_iterator > const_filtered_symbol_range
Definition SymbolSet.h:138
filter_iterator< const_symbol_iterator, std::function< bool(const Symbol *)> > const_filtered_symbol_iterator
Definition SymbolSet.h:135
Symbol * addGlobal(EncodeKind Kind, StringRef Name, SymbolFlags Flags, RangeT &&Targets)
Definition SymbolSet.h:104
bool operator!=(const SymbolSet &O) const
Definition SymbolSet.h:178
void * allocate(size_t Size, unsigned Align=8)
Definition SymbolSet.h:180
LLVM_ABI bool operator==(const SymbolSet &O) const
iterator_range< const_symbol_iterator > const_symbol_range
Definition SymbolSet.h:133
SymbolSet(const SymbolSet &other)=delete
LLVM_ABI Symbol * addGlobal(EncodeKind Kind, StringRef Name, SymbolFlags Flags, const Target &Targ)
Definition SymbolSet.cpp:29
LLVM_ABI const Symbol * findSymbol(EncodeKind Kind, StringRef Name, ObjCIFSymbolKind ObjCIF=ObjCIFSymbolKind::None) const
Definition SymbolSet.cpp:36
size_t size() const
Definition SymbolSet.h:100
const_filtered_symbol_range undefineds() const
Definition SymbolSet.h:167
const_symbol_range symbols() const
Definition SymbolSet.h:142
const_filtered_symbol_range reexports() const
Definition SymbolSet.h:157
const_filtered_symbol_range exports() const
Definition SymbolSet.h:147
bool isUndefined() const
Definition Symbol.h:123
bool isReexported() const
Definition Symbol.h:127
StringRef - Represent a constant reference to a string, i.e.
Definition StringRef.h:55
A range adaptor for a pair of iterators.
This provides a very simple, boring adaptor for a begin and end iterator into a range type.
ObjCIFSymbolKind
ObjC Interface symbol mappings.
Definition Symbol.h:70
EncodeKind
Mapping of entry types in TextStubs.
Definition Symbol.h:56
SymbolFlags
Symbol flags.
Definition Symbol.h:25
This is an optimization pass for GlobalISel generic memory operations.
hash_code hash_value(const FixedPointSemantics &Val)
bool operator!=(uint64_t V1, const APInt &V2)
Definition APInt.h:2113
iterator_range< T > make_range(T x, T y)
Convenience function for iterating over sub-ranges.
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
Definition STLExtras.h:552
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
LLVM_ATTRIBUTE_VISIBILITY_DEFAULT AnalysisKey InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key
@ Global
Append to llvm.global_dtors.
hash_code hash_combine(const Ts &...args)
Combine values into a single hash_code.
Definition Hashing.h:592
filter_iterator_impl< WrappedIteratorT, PredicateT, detail::fwd_or_bidi_tag< WrappedIteratorT > > filter_iterator
Defines filter_iterator to a suitable specialization of filter_iterator_impl, based on the underlying...
Definition STLExtras.h:539
Implement std::hash so that hash_code can be used in STL containers.
Definition BitVector.h:870
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition Alignment.h:39
static SymbolsMapKey getEmptyKey()
Definition SymbolSet.h:34
static SymbolsMapKey getTombstoneKey()
Definition SymbolSet.h:38
static bool isEqual(const SymbolsMapKey &LHS, const SymbolsMapKey &RHS)
Definition SymbolSet.h:47
static unsigned getHashValue(const SymbolsMapKey &Key)
Definition SymbolSet.h:43
An information struct used to provide DenseMap with the various necessary components for a given valu...
SymbolsMapKey(MachO::EncodeKind Kind, StringRef Name)
Definition SymbolSet.h:30
MachO::EncodeKind Kind
Definition SymbolSet.h:27