LLVM  14.0.0git
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 
10 
11 namespace llvm {
12 
14  if (S.empty() && !Strings.empty())
15  return EmptyString;
16 
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;
26  }
27  return DwarfStringPoolEntryRef(*I.first, true);
28 }
29 
32 
33  if (Translator)
34  S = Translator(S);
35 
36  auto InsertResult = Strings.insert({S, Entry});
37  return InsertResult.first->getKey();
38 }
39 
40 std::vector<DwarfStringPoolEntryRef>
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;
52 }
53 
54 } // namespace llvm
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
llvm::DwarfStringPoolEntryRef
String pool entry reference.
Definition: DwarfStringPoolEntry.h:31
llvm::DwarfStringPoolEntry::NotIndexed
static constexpr unsigned NotIndexed
Definition: DwarfStringPoolEntry.h:21
E
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
NonRelocatableStringpool.h
llvm::StringMap::insert
bool insert(MapEntryTy *KeyValue)
insert - Insert the specified key/value pair into the map.
Definition: StringMap.h:274
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::NonRelocatableStringpool::getEntriesForEmission
std::vector< DwarfStringPoolEntryRef > getEntriesForEmission() const
Return the list of strings to be emitted.
Definition: NonRelocatableStringpool.cpp:41
llvm::NonRelocatableStringpool::internString
StringRef internString(StringRef S)
Get permanent storage for S (but do not necessarily emit S in the output section).
Definition: NonRelocatableStringpool.cpp:30
llvm::NonRelocatableStringpool::getEntry
DwarfStringPoolEntryRef getEntry(StringRef S)
Definition: NonRelocatableStringpool.cpp:13
llvm::DwarfStringPoolEntry
Data for a string pool entry.
Definition: DwarfStringPoolEntry.h:20
I
#define I(x, y, z)
Definition: MD5.cpp:59
llvm::StringMapImpl::size
unsigned size() const
Definition: StringMap.h:93
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
S
add sub stmia L5 ldr r0 bl L_printf $stub Instead of a and a wouldn t it be better to do three moves *Return an aggregate type is even return S
Definition: README.txt:210
llvm::sort
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1541
llvm::StringMapImpl::empty
bool empty() const
Definition: StringMap.h:92