LLVM 22.0.0git
AddressPool.cpp
Go to the documentation of this file.
1//===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//
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#include "AddressPool.h"
12#include "llvm/MC/MCAsmInfo.h"
13#include "llvm/MC/MCStreamer.h"
15#include <utility>
16
17using namespace llvm;
18
19unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
20 resetUsedFlag(true);
21 auto IterBool = Pool.try_emplace(Sym, Pool.size(), TLS);
22 return IterBool.first->second.Number;
23}
24
25MCSymbol *AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) {
26 static const uint8_t AddrSize = Asm.MAI->getCodePointerSize();
27
28 MCSymbol *EndLabel =
29 Asm.emitDwarfUnitLength("debug_addr", "Length of contribution");
30 Asm.OutStreamer->AddComment("DWARF version number");
31 Asm.emitInt16(Asm.getDwarfVersion());
32 Asm.OutStreamer->AddComment("Address size");
33 Asm.emitInt8(AddrSize);
34 Asm.OutStreamer->AddComment("Segment selector size");
35 Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size.
36
37 return EndLabel;
38}
39
40// Emit addresses into the section given.
41void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
42 if (isEmpty())
43 return;
44
45 // Start the dwarf addr section.
46 Asm.OutStreamer->switchSection(AddrSection);
47
48 MCSymbol *EndLabel = nullptr;
49
50 if (Asm.getDwarfVersion() >= 5)
51 EndLabel = emitHeader(Asm, AddrSection);
52
53 // Define the symbol that marks the start of the contribution.
54 // It is referenced via DW_AT_addr_base.
55 Asm.OutStreamer->emitLabel(AddressTableBaseSym);
56
57 // Order the address pool entries by ID
58 SmallVector<const MCExpr *, 64> Entries(Pool.size());
59
60 for (const auto &I : Pool)
61 Entries[I.second.Number] =
62 I.second.TLS
63 ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
64 : MCSymbolRefExpr::create(I.first, Asm.OutContext);
65
66 for (const MCExpr *Entry : Entries)
67 Asm.OutStreamer->emitValue(Entry, Asm.MAI->getCodePointerSize());
68
69 if (EndLabel)
70 Asm.OutStreamer->emitLabel(EndLabel);
71}
#define I(x, y, z)
Definition MD5.cpp:58
This file defines the SmallVector class.
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
void emit(AsmPrinter &Asm, MCSection *AddrSection)
void resetUsedFlag(bool HasBeenUsed=false)
Definition AddressPool.h:51
This class is intended to be used as a driving class for all asm writers.
Definition AsmPrinter.h:96
Base class for the full range of assembler expressions which are needed for parsing.
Definition MCExpr.h:34
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition MCSection.h:521
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx, SMLoc Loc=SMLoc())
Definition MCExpr.h:214
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition MCSymbol.h:42
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This is an optimization pass for GlobalISel generic memory operations.