1//===- llvm/CodeGen/DwarfStringPool.cpp - Dwarf Debug Framework -----------===// 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 7//===----------------------------------------------------------------------===// 22 : Pool(
A), Prefix(Prefix),
23 ShouldCreateSymbols(Asm.doesDwarfUseRelocationsAcrossSections()) {}
27autoI = Pool.insert(std::make_pair(Str, EntryTy()));
28auto &Entry =
I.first->second;
31 Entry.Offset = NumBytes;
32 Entry.Symbol = ShouldCreateSymbols ? Asm.createTempSymbol(Prefix) :
nullptr;
34 NumBytes += Str.size() + 1;
41auto &MapEntry = getEntryImpl(Asm, Str);
47auto &MapEntry = getEntryImpl(Asm, Str);
48if (!MapEntry.getValue().isIndexed())
49 MapEntry.getValue().Index = NumIndexedStrings++;
58 Asm.OutStreamer->switchSection(Section);
59unsigned EntrySize = Asm.getDwarfOffsetByteSize();
60// We are emitting the header for a contribution to the string offsets 61// table. The header consists of an entry with the contribution's 62// size (not including the size of the length field), the DWARF version and 65"Length of String Offsets Set");
66 Asm.emitInt16(Asm.getDwarfVersion());
68// Define the symbol that marks the start of the contribution. It is 69// referenced by most unit headers via DW_AT_str_offsets_base. 70// Split units do not use the attribute. 72 Asm.OutStreamer->emitLabel(StartSym);
76MCSection *OffsetSection,
bool UseRelativeOffsets) {
80// Start the dwarf str section. 81 Asm.OutStreamer->switchSection(StrSection);
83// Get all of the string pool entries and sort them by their offset. 85 Entries.reserve(Pool.size());
87for (
constauto &E : Pool)
88 Entries.push_back(&E);
92returnA->getValue().Offset < B->getValue().
Offset;
95for (
constauto &Entry : Entries) {
96assert(ShouldCreateSymbols ==
static_cast<bool>(Entry->getValue().Symbol) &&
97"Mismatch between setting and entry");
99// Emit a label for reference from debug information entries. 100if (ShouldCreateSymbols)
101 Asm.OutStreamer->emitLabel(Entry->getValue().Symbol);
103// Emit the string itself with a terminating null byte. 104 Asm.OutStreamer->AddComment(
"string offset=" +
105Twine(Entry->getValue().Offset));
106 Asm.OutStreamer->emitBytes(
107StringRef(Entry->getKeyData(), Entry->getKeyLength() + 1));
110// If we've got an offset section go ahead and emit that now as well. 112// Now only take the indexed entries and put them in an array by their ID so 113// we can emit them in order. 114 Entries.resize(NumIndexedStrings);
115for (
constauto &Entry : Pool) {
116if (Entry.getValue().isIndexed())
117 Entries[Entry.getValue().Index] = &Entry;
120 Asm.OutStreamer->switchSection(OffsetSection);
121unsignedsize = Asm.getDwarfOffsetByteSize();
122for (
constauto &Entry : Entries)
123if (UseRelativeOffsets)
124 Asm.emitDwarfStringOffset(Entry->getValue());
126 Asm.OutStreamer->emitIntValue(Entry->getValue().Offset,
size);
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This file defines the SmallVector class.
This class is intended to be used as a driving class for all asm writers.
Allocate memory in an ever growing pool, as if by bump-pointer.
DwarfStringPoolEntryRef: Dwarf string pool entry reference.
EntryRef getEntry(AsmPrinter &Asm, StringRef Str)
Get a reference to an entry in the string pool.
EntryRef getIndexedEntry(AsmPrinter &Asm, StringRef Str)
Same as getEntry, except that you can use EntryRef::getIndex to obtain a unique ID of this entry (e....
DwarfStringPoolEntryRef EntryRef
unsigned getNumIndexedStrings() const
void emitStringOffsetsTableHeader(AsmPrinter &Asm, MCSection *OffsetSection, MCSymbol *StartSym)
DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix)
void emit(AsmPrinter &Asm, MCSection *StrSection, MCSection *OffsetSection=nullptr, bool UseRelativeOffsets=false)
Instances of this class represent a uniqued identifier for a section in the current translation unit.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMapEntry - This is used to represent one value that is inserted into a StringMap.
StringRef - Represent a constant reference to a string, i.e.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
This is an optimization pass for GlobalISel generic memory operations.
void sort(IteratorTy Start, IteratorTy End)
static constexpr unsigned NotIndexed