LLVM  15.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 #include "llvm/ADT/STLExtras.h"
11 
12 namespace llvm {
13 
15  if (S.empty() && !Strings.empty())
16  return EmptyString;
17 
18  if (Translator)
19  S = Translator(S);
20  auto I = Strings.insert({S, DwarfStringPoolEntry()});
21  auto &Entry = I.first->second;
22  if (I.second || !Entry.isIndexed()) {
23  Entry.Index = NumEntries++;
24  Entry.Offset = CurrentEndOffset;
25  Entry.Symbol = nullptr;
26  CurrentEndOffset += S.size() + 1;
27  }
28  return DwarfStringPoolEntryRef(*I.first, true);
29 }
30 
33 
34  if (Translator)
35  S = Translator(S);
36 
37  auto InsertResult = Strings.insert({S, Entry});
38  return InsertResult.first->getKey();
39 }
40 
41 std::vector<DwarfStringPoolEntryRef>
43  std::vector<DwarfStringPoolEntryRef> Result;
44  Result.reserve(Strings.size());
45  for (const auto &E : Strings)
46  if (E.getValue().isIndexed())
47  Result.emplace_back(E, true);
48  llvm::sort(Result, [](const DwarfStringPoolEntryRef A,
49  const DwarfStringPoolEntryRef B) {
50  return A.getIndex() < B.getIndex();
51  });
52  return Result;
53 }
54 
55 } // namespace llvm
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
STLExtras.h
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:276
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:42
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:31
llvm::NonRelocatableStringpool::getEntry
DwarfStringPoolEntryRef getEntry(StringRef S)
Definition: NonRelocatableStringpool.cpp:14
llvm::DwarfStringPoolEntry
Data for a string pool entry.
Definition: DwarfStringPoolEntry.h:20
I
#define I(x, y, z)
Definition: MD5.cpp:58
llvm::StringMapImpl::size
unsigned size() const
Definition: StringMap.h:95
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
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:1552
llvm::StringMapImpl::empty
bool empty() const
Definition: StringMap.h:94