LLVM  15.0.0git
DwarfStringPoolEntry.h
Go to the documentation of this file.
1 //===- llvm/CodeGen/DwarfStringPoolEntry.h - String pool entry --*- 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_DWARFSTRINGPOOLENTRY_H
10 #define LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
11 
12 #include "llvm/ADT/PointerUnion.h"
13 #include "llvm/ADT/StringMap.h"
14 
15 namespace llvm {
16 
17 class MCSymbol;
18 
19 /// Data for a string pool entry.
21  static constexpr unsigned NotIndexed = -1;
22 
23  MCSymbol *Symbol = nullptr;
25  unsigned Index = 0;
26 
27  bool isIndexed() const { return Index != NotIndexed; }
28 };
29 
30 /// DwarfStringPoolEntryRef: Dwarf string pool entry reference.
31 ///
32 /// Dwarf string pool entry keeps string value and its data.
33 /// There are two variants how data are represented:
34 ///
35 /// 1. By value - StringMapEntry<DwarfStringPoolEntry>.
36 /// 2. By pointer - StringMapEntry<DwarfStringPoolEntry *>.
37 ///
38 /// The "By pointer" variant allows for reducing memory usage for the case
39 /// when string pool entry does not have data: it keeps the null pointer
40 /// and so no need to waste space for the full DwarfStringPoolEntry.
41 /// It is recommended to use "By pointer" variant if not all entries
42 /// of dwarf string pool have corresponding DwarfStringPoolEntry.
43 
45  /// Pointer type for "By value" string entry.
47 
48  /// Pointer type for "By pointer" string entry.
50 
51  /// Pointer to the dwarf string pool Entry.
53 
54 public:
55  DwarfStringPoolEntryRef() = default;
56 
57  /// ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to \p Entry,
58  /// thus specified entry mustn`t be reallocated.
60  : MapEntry(&Entry) {}
61 
62  /// ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to \p Entry,
63  /// thus specified entry mustn`t be reallocated.
65  : MapEntry(&Entry) {
66  assert(MapEntry.get<ByPtrStringEntryPtr>()->second != nullptr);
67  }
68 
69  explicit operator bool() const { return !MapEntry.isNull(); }
70 
71  /// \returns symbol for the dwarf string.
72  MCSymbol *getSymbol() const {
73  assert(getEntry().Symbol && "No symbol available!");
74  return getEntry().Symbol;
75  }
76 
77  /// \returns offset for the dwarf string.
78  uint64_t getOffset() const { return getEntry().Offset; }
79 
80  /// \returns index for the dwarf string.
81  unsigned getIndex() const {
82  assert(getEntry().isIndexed() && "Index is not set!");
83  return getEntry().Index;
84  }
85 
86  /// \returns string.
87  StringRef getString() const {
88  if (MapEntry.is<ByValStringEntryPtr>())
89  return MapEntry.get<ByValStringEntryPtr>()->first();
90 
91  return MapEntry.get<ByPtrStringEntryPtr>()->first();
92  }
93 
94  /// \returns the entire string pool entry for convenience.
95  const DwarfStringPoolEntry &getEntry() const {
96  if (MapEntry.is<ByValStringEntryPtr>())
97  return MapEntry.get<ByValStringEntryPtr>()->second;
98 
99  return *MapEntry.get<ByPtrStringEntryPtr>()->second;
100  }
101 
102  bool operator==(const DwarfStringPoolEntryRef &X) const {
103  return MapEntry.getOpaqueValue() == X.MapEntry.getOpaqueValue();
104  }
105 
106  bool operator!=(const DwarfStringPoolEntryRef &X) const {
107  return MapEntry.getOpaqueValue() != X.MapEntry.getOpaqueValue();
108  }
109 };
110 
111 } // end namespace llvm
112 
113 #endif
llvm::PointerUnion::isNull
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
Definition: PointerUnion.h:142
llvm::DwarfStringPoolEntryRef::DwarfStringPoolEntryRef
DwarfStringPoolEntryRef(const StringMapEntry< DwarfStringPoolEntry > &Entry)
ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to Entry, thus specified entry mustn`t be reallocat...
Definition: DwarfStringPoolEntry.h:59
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::StringMapEntry
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
Definition: StringMapEntry.h:101
llvm::DwarfStringPoolEntry::isIndexed
bool isIndexed() const
Definition: DwarfStringPoolEntry.h:27
llvm::PointerUnion::getOpaqueValue
void * getOpaqueValue() const
Definition: PointerUnion.h:193
llvm::PointerUnion::get
T get() const
Returns the value of the specified pointer type.
Definition: PointerUnion.h:155
llvm::DwarfStringPoolEntryRef
DwarfStringPoolEntryRef: Dwarf string pool entry reference.
Definition: DwarfStringPoolEntry.h:44
llvm::PointerUnion::is
bool is() const
Test if the Union currently holds the type matching T.
Definition: PointerUnion.h:150
llvm::DwarfStringPoolEntry::Offset
uint64_t Offset
Definition: DwarfStringPoolEntry.h:24
llvm::DwarfStringPoolEntry::NotIndexed
static constexpr unsigned NotIndexed
Definition: DwarfStringPoolEntry.h:21
llvm::dwarf::Index
Index
Definition: Dwarf.h:472
llvm::DwarfStringPoolEntryRef::DwarfStringPoolEntryRef
DwarfStringPoolEntryRef()=default
StringMap.h
llvm::DwarfStringPoolEntryRef::getString
StringRef getString() const
Definition: DwarfStringPoolEntry.h:87
X
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
llvm::StringMapEntryStorage::second
ValueTy second
Definition: StringMapEntry.h:72
llvm::DwarfStringPoolEntryRef::DwarfStringPoolEntryRef
DwarfStringPoolEntryRef(const StringMapEntry< DwarfStringPoolEntry * > &Entry)
ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to Entry, thus specified entry mustn`t be reallocat...
Definition: DwarfStringPoolEntry.h:64
llvm::DwarfStringPoolEntry
Data for a string pool entry.
Definition: DwarfStringPoolEntry.h:20
uint64_t
llvm::DwarfStringPoolEntryRef::getOffset
uint64_t getOffset() const
Definition: DwarfStringPoolEntry.h:78
assert
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
PointerUnion.h
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:58
llvm::DwarfStringPoolEntryRef::getEntry
const DwarfStringPoolEntry & getEntry() const
Definition: DwarfStringPoolEntry.h:95
llvm::PointerUnion
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:112
llvm::DwarfStringPoolEntryRef::getSymbol
MCSymbol * getSymbol() const
Definition: DwarfStringPoolEntry.h:72
llvm::DwarfStringPoolEntry::Symbol
MCSymbol * Symbol
Definition: DwarfStringPoolEntry.h:23
llvm::DwarfStringPoolEntryRef::getIndex
unsigned getIndex() const
Definition: DwarfStringPoolEntry.h:81
llvm::DwarfStringPoolEntryRef::operator!=
bool operator!=(const DwarfStringPoolEntryRef &X) const
Definition: DwarfStringPoolEntry.h:106
llvm::ARMBuildAttrs::Symbol
@ Symbol
Definition: ARMBuildAttributes.h:83
llvm::DwarfStringPoolEntryRef::operator==
bool operator==(const DwarfStringPoolEntryRef &X) const
Definition: DwarfStringPoolEntry.h:102
llvm::DwarfStringPoolEntry::Index
unsigned Index
Definition: DwarfStringPoolEntry.h:25
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172