[ORC] Add std::tuple support to SimplePackedSerialization.
[llvm-project.git] / llvm / lib / CodeGen / NonRelocatableStringpool.cpp
blob9ed3471c0fc9661731738796d0758895f8c6596e
1 //===-- NonRelocatableStringpool.cpp --------------------------------------===//
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 //===----------------------------------------------------------------------===//
9 #include "llvm/CodeGen/NonRelocatableStringpool.h"
11 namespace llvm {
13 DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
14 if (S.empty() && !Strings.empty())
15 return EmptyString;
17 if (Translator)
18 S = Translator(S);
19 auto I = Strings.insert({S, DwarfStringPoolEntry()});
20 auto &Entry = I.first->second;
21 if (I.second || !Entry.isIndexed()) {
22 Entry.Index = NumEntries++;
23 Entry.Offset = CurrentEndOffset;
24 Entry.Symbol = nullptr;
25 CurrentEndOffset += S.size() + 1;
27 return DwarfStringPoolEntryRef(*I.first, true);
30 StringRef NonRelocatableStringpool::internString(StringRef S) {
31 DwarfStringPoolEntry Entry{nullptr, 0, DwarfStringPoolEntry::NotIndexed};
33 if (Translator)
34 S = Translator(S);
36 auto InsertResult = Strings.insert({S, Entry});
37 return InsertResult.first->getKey();
40 std::vector<DwarfStringPoolEntryRef>
41 NonRelocatableStringpool::getEntriesForEmission() const {
42 std::vector<DwarfStringPoolEntryRef> Result;
43 Result.reserve(Strings.size());
44 for (const auto &E : Strings)
45 if (E.getValue().isIndexed())
46 Result.emplace_back(E, true);
47 llvm::sort(Result, [](const DwarfStringPoolEntryRef A,
48 const DwarfStringPoolEntryRef B) {
49 return A.getIndex() < B.getIndex();
50 });
51 return Result;
54 } // namespace llvm