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"
13 DwarfStringPoolEntryRef
NonRelocatableStringpool::getEntry(StringRef S
) {
14 if (S
.empty() && !Strings
.empty())
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
};
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();