LLVM 20.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
13#include "llvm/ADT/StringMap.h"
14
15namespace llvm {
16
17class 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/// DwarfStringPoolEntry with string keeping externally.
33};
34
35/// DwarfStringPoolEntryRef: Dwarf string pool entry reference.
36///
37/// Dwarf string pool entry keeps string value and its data.
38/// There are two variants how data are represented:
39///
40/// 1. String data in pool - StringMapEntry<DwarfStringPoolEntry>.
41/// 2. External string data - DwarfStringPoolEntryWithExtString.
42///
43/// The external data variant allows reducing memory usage for the case
44/// when string pool entry does not have data: string entry does not
45/// keep any data and so no need to waste space for the full
46/// DwarfStringPoolEntry. It is recommended to use external variant if not all
47/// entries of dwarf string pool have corresponding DwarfStringPoolEntry.
48
50 /// Pointer type for "By value" string entry.
52
53 /// Pointer type for external string entry.
55
56 /// Pointer to the dwarf string pool Entry.
58
59public:
61
62 /// ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to \p Entry,
63 /// thus specified entry mustn`t be reallocated.
65 : MapEntry(&Entry) {}
66
67 /// ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to \p Entry,
68 /// thus specified entry mustn`t be reallocated.
70 : MapEntry(&Entry) {}
71
72 explicit operator bool() const { return !MapEntry.isNull(); }
73
74 /// \returns symbol for the dwarf string.
76 assert(getEntry().Symbol && "No symbol available!");
77 return getEntry().Symbol;
78 }
79
80 /// \returns offset for the dwarf string.
81 uint64_t getOffset() const { return getEntry().Offset; }
82
83 /// \returns index for the dwarf string.
84 unsigned getIndex() const {
85 assert(getEntry().isIndexed() && "Index is not set!");
86 return getEntry().Index;
87 }
88
89 /// \returns string.
91 if (isa<ByValStringEntryPtr>(MapEntry))
92 return cast<ByValStringEntryPtr>(MapEntry)->first();
93
94 return cast<ExtStringEntryPtr>(MapEntry)->String;
95 }
96
97 /// \returns the entire string pool entry for convenience.
99 if (isa<ByValStringEntryPtr>(MapEntry))
100 return cast<ByValStringEntryPtr>(MapEntry)->second;
101
102 return *cast<ExtStringEntryPtr>(MapEntry);
103 }
104
106 return MapEntry.getOpaqueValue() == X.MapEntry.getOpaqueValue();
107 }
108
110 return MapEntry.getOpaqueValue() != X.MapEntry.getOpaqueValue();
111 }
112};
113
114} // end namespace llvm
115
116#endif
This file defines the StringMap class.
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
This file defines the PointerUnion class, which is a discriminated union of pointer types.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
DwarfStringPoolEntryRef: Dwarf string pool entry reference.
bool operator!=(const DwarfStringPoolEntryRef &X) const
const DwarfStringPoolEntry & getEntry() const
DwarfStringPoolEntryRef(const StringMapEntry< DwarfStringPoolEntry > &Entry)
ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to Entry, thus specified entry mustn`t be reallocat...
bool operator==(const DwarfStringPoolEntryRef &X) const
DwarfStringPoolEntryRef(const DwarfStringPoolEntryWithExtString &Entry)
ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to Entry, thus specified entry mustn`t be reallocat...
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
Definition: PointerUnion.h:118
bool isNull() const
Test if the pointer held in the union is null, regardless of which type it is.
Definition: PointerUnion.h:142
void * getOpaqueValue() const
Definition: PointerUnion.h:193
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
DwarfStringPoolEntry with string keeping externally.
Data for a string pool entry.
static constexpr unsigned NotIndexed