LLVM  14.0.0git
NonRelocatableStringpool.h
Go to the documentation of this file.
1 //===- NonRelocatableStringpool.h -------------------------------*- C++ -*-===//
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 #ifndef LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H
10 #define LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H
11 
13 #include "llvm/Support/Allocator.h"
14 #include <cstdint>
15 #include <vector>
16 
17 namespace llvm {
18 
19 /// A string table that doesn't need relocations.
20 ///
21 /// Use this class when a string table doesn't need relocations.
22 /// This class provides this ability by just associating offsets with strings.
24 public:
25  /// Entries are stored into the StringMap and simply linked together through
26  /// the second element of this pair in order to keep track of insertion
27  /// order.
29 
31  std::function<StringRef(StringRef Input)> Translator = nullptr,
32  bool PutEmptyString = false)
33  : Translator(Translator) {
34  if (PutEmptyString)
35  EmptyString = getEntry("");
36  }
37 
39 
40  /// Get the offset of string \p S in the string table. This can insert a new
41  /// element or return the offset of a pre-existing one.
43 
44  /// Get permanent storage for \p S (but do not necessarily emit \p S in the
45  /// output section). A latter call to getStringOffset() with the same string
46  /// will chain it though.
47  ///
48  /// \returns The StringRef that points to permanent storage to use
49  /// in place of \p S.
51 
52  uint64_t getSize() { return CurrentEndOffset; }
53 
54  /// Return the list of strings to be emitted. This does not contain the
55  /// strings which were added via internString only.
56  std::vector<DwarfStringPoolEntryRef> getEntriesForEmission() const;
57 
58 private:
59  MapTy Strings;
60  uint64_t CurrentEndOffset = 0;
61  unsigned NumEntries = 0;
62  DwarfStringPoolEntryRef EmptyString;
63  std::function<StringRef(StringRef Input)> Translator;
64 };
65 
66 /// Helper for making strong types.
67 template <typename T, typename S> class StrongType : public T {
68 public:
69  template <typename... Args>
70  explicit StrongType(Args... A) : T(std::forward<Args>(A)...) {}
71 };
72 
73 /// It's very easy to introduce bugs by passing the wrong string pool.
74 /// By using strong types the interface enforces that the right
75 /// kind of pool is used.
76 struct UniqueTag {};
77 struct OffsetsTag {};
80 
81 } // end namespace llvm
82 
83 #endif // LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
Allocator.h
T
#define T
Definition: Mips16ISelLowering.cpp:341
llvm::DwarfStringPoolEntryRef
String pool entry reference.
Definition: DwarfStringPoolEntry.h:31
llvm::UniqueTag
It's very easy to introduce bugs by passing the wrong string pool.
Definition: NonRelocatableStringpool.h:76
llvm::NonRelocatableStringpool::MapTy
StringMap< DwarfStringPoolEntry, BumpPtrAllocator > MapTy
Entries are stored into the StringMap and simply linked together through the second element of this p...
Definition: NonRelocatableStringpool.h:28
llvm::NonRelocatableStringpool::getEntriesForEmission
std::vector< DwarfStringPoolEntryRef > getEntriesForEmission() const
Return the list of strings to be emitted.
Definition: NonRelocatableStringpool.cpp:41
llvm::NonRelocatableStringpool::getStringOffset
uint64_t getStringOffset(StringRef S)
Get the offset of string S in the string table.
Definition: NonRelocatableStringpool.h: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:30
DwarfStringPoolEntry.h
llvm::NonRelocatableStringpool::getEntry
DwarfStringPoolEntryRef getEntry(StringRef S)
Definition: NonRelocatableStringpool.cpp:13
llvm::StringMap< DwarfStringPoolEntry, BumpPtrAllocator >
llvm::NonRelocatableStringpool::NonRelocatableStringpool
NonRelocatableStringpool(std::function< StringRef(StringRef Input)> Translator=nullptr, bool PutEmptyString=false)
Definition: NonRelocatableStringpool.h:30
llvm::StrongType::StrongType
StrongType(Args... A)
Definition: NonRelocatableStringpool.h:70
uint64_t
llvm::DwarfStringPoolEntryRef::getOffset
uint64_t getOffset() const
Definition: DwarfStringPoolEntry.h:50
llvm::OffsetsTag
Definition: NonRelocatableStringpool.h:77
function
print Print MemDeps of function
Definition: MemDepPrinter.cpp:83
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
std
Definition: BitVector.h:838
llvm::NonRelocatableStringpool
A string table that doesn't need relocations.
Definition: NonRelocatableStringpool.h:23
llvm::StrongType
Helper for making strong types.
Definition: NonRelocatableStringpool.h:67
llvm::NonRelocatableStringpool::getSize
uint64_t getSize()
Definition: NonRelocatableStringpool.h:52
llvm::AMDGPU::HSAMD::Kernel::Key::Args
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
Definition: AMDGPUMetadata.h:389