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//===----------------------------------------------------------------------===//
8
9#include "llvm/CodeGen/NonRelocatableStringpool.h"
10#include "llvm/ADT/STLExtras.h"
11
12namespace llvm {
13
14DwarfStringPoolEntryRef NonRelocatableStringpool::getEntry(StringRef S) {
15 if (Translator)
16 S = Translator(S);
17 auto I = Strings.insert(KV: {S, DwarfStringPoolEntry()});
18 auto &Entry = I.first->second;
19 if (I.second || !Entry.isIndexed()) {
20 Entry.Index = NumEntries++;
21 Entry.Offset = CurrentEndOffset;
22 Entry.Symbol = nullptr;
23 CurrentEndOffset += S.size() + 1;
24 }
25 return DwarfStringPoolEntryRef(*I.first);
26}
27
28StringRef NonRelocatableStringpool::internString(StringRef S) {
29 DwarfStringPoolEntry Entry{.Symbol: nullptr, .Offset: 0, .Index: DwarfStringPoolEntry::NotIndexed};
30
31 if (Translator)
32 S = Translator(S);
33
34 auto InsertResult = Strings.insert(KV: {S, Entry});
35 return InsertResult.first->getKey();
36}
37
38std::vector<DwarfStringPoolEntryRef>
39NonRelocatableStringpool::getEntriesForEmission() const {
40 std::vector<DwarfStringPoolEntryRef> Result;
41 Result.reserve(n: Strings.size());
42 for (const auto &E : Strings)
43 if (E.getValue().isIndexed())
44 Result.emplace_back(args: E);
45 llvm::sort(C&: Result, Comp: [](const DwarfStringPoolEntryRef A,
46 const DwarfStringPoolEntryRef B) {
47 return A.getIndex() < B.getIndex();
48 });
49 return Result;
50}
51
52} // namespace llvm
53

source code of llvm/lib/CodeGen/NonRelocatableStringpool.cpp