LLVM
22.0.0git
lib
CodeGen
NonRelocatableStringpool.cpp
Go to the documentation of this file.
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
12
using namespace
llvm
;
13
14
DwarfStringPoolEntryRef
NonRelocatableStringpool::getEntry
(
StringRef
S) {
15
auto
I
= Strings.try_emplace(S);
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;
22
}
23
return
DwarfStringPoolEntryRef
(*
I
.first);
24
}
25
26
StringRef
NonRelocatableStringpool::internString
(
StringRef
S) {
27
DwarfStringPoolEntry
Entry{
nullptr
, 0,
DwarfStringPoolEntry::NotIndexed
};
28
29
auto
InsertResult = Strings.insert({S, Entry});
30
return
InsertResult.first->getKey();
31
}
32
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();
43
});
44
return
Result;
45
}
A
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
I
#define I(x, y, z)
Definition
MD5.cpp:58
NonRelocatableStringpool.h
STLExtras.h
This file contains some templates that are useful if you are working with the STL at all.
llvm::DwarfStringPoolEntryRef
DwarfStringPoolEntryRef: Dwarf string pool entry reference.
Definition
DwarfStringPoolEntry.h:49
llvm::NonRelocatableStringpool::internString
LLVM_ABI StringRef internString(StringRef S)
Get permanent storage for S (but do not necessarily emit S in the output section).
Definition
NonRelocatableStringpool.cpp:26
llvm::NonRelocatableStringpool::getEntry
LLVM_ABI DwarfStringPoolEntryRef getEntry(StringRef S)
Definition
NonRelocatableStringpool.cpp:14
llvm::NonRelocatableStringpool::getEntriesForEmission
LLVM_ABI std::vector< DwarfStringPoolEntryRef > getEntriesForEmission() const
Return the list of strings to be emitted.
Definition
NonRelocatableStringpool.cpp:34
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition
StringRef.h:55
llvm::StringRef::size
constexpr size_t size() const
size - Get the string size.
Definition
StringRef.h:146
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition
AddressRanges.h:18
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition
STLExtras.h:1622
llvm::DwarfStringPoolEntry
Data for a string pool entry.
Definition
DwarfStringPoolEntry.h:20
llvm::DwarfStringPoolEntry::NotIndexed
static constexpr unsigned NotIndexed
Definition
DwarfStringPoolEntry.h:21
Generated on
for LLVM by
1.14.0