LLVM 17.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/// 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
54public:
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(cast<ByPtrStringEntryPtr>(MapEntry)->second != nullptr);
67 }
68
69 explicit operator bool() const { return !MapEntry.isNull(); }
70
71 /// \returns symbol for the dwarf string.
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.
88 if (isa<ByValStringEntryPtr>(MapEntry))
89 return cast<ByValStringEntryPtr>(MapEntry)->first();
90
91 return cast<ByPtrStringEntryPtr>(MapEntry)->first();
92 }
93
94 /// \returns the entire string pool entry for convenience.
96 if (isa<ByValStringEntryPtr>(MapEntry))
97 return cast<ByValStringEntryPtr>(MapEntry)->second;
98
99 return *cast<ByPtrStringEntryPtr>(MapEntry)->second;
100 }
101
103 return MapEntry.getOpaqueValue() == X.MapEntry.getOpaqueValue();
104 }
105
107 return MapEntry.getOpaqueValue() != X.MapEntry.getOpaqueValue();
108 }
109};
110
111} // end namespace llvm
112
113#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...
DwarfStringPoolEntryRef(const StringMapEntry< DwarfStringPoolEntry > &Entry)
ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to Entry, thus specified entry mustn`t be reallocat...
bool operator==(const DwarfStringPoolEntryRef &X) const
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
Data for a string pool entry.
static constexpr unsigned NotIndexed