1 //===-- NonRelocatableStringpool.cpp --------------------------------------===//
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
7 //===----------------------------------------------------------------------===//
9 #include "llvm/CodeGen/NonRelocatableStringpool.h"
10 #include "llvm/ADT/STLExtras.h"
14 DwarfStringPoolEntryRef
NonRelocatableStringpool::getEntry(StringRef S
) {
15 auto I
= Strings
.insert({S
, DwarfStringPoolEntry()});
16 auto &Entry
= I
.first
->second
;
17 if (I
.second
|| !Entry
.isIndexed()) {
18 Entry
.Index
= NumEntries
++;
19 Entry
.Offset
= CurrentEndOffset
;
20 Entry
.Symbol
= nullptr;
21 CurrentEndOffset
+= S
.size() + 1;
23 return DwarfStringPoolEntryRef(*I
.first
);
26 StringRef
NonRelocatableStringpool::internString(StringRef S
) {
27 DwarfStringPoolEntry Entry
{nullptr, 0, DwarfStringPoolEntry::NotIndexed
};
29 auto InsertResult
= Strings
.insert({S
, Entry
});
30 return InsertResult
.first
->getKey();
33 std::vector
<DwarfStringPoolEntryRef
>
34 NonRelocatableStringpool::getEntriesForEmission() const {
35 std::vector
<DwarfStringPoolEntryRef
> Result
;
36 Result
.reserve(Strings
.size());
37 for (const auto &E
: Strings
)
38 if (E
.getValue().isIndexed())
39 Result
.emplace_back(E
);
40 llvm::sort(Result
, [](const DwarfStringPoolEntryRef A
,
41 const DwarfStringPoolEntryRef B
) {
42 return A
.getIndex() < B
.getIndex();