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
16using namespace llvm;
17
18unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
19 resetUsedFlag(true);
20 auto IterBool = Pool.try_emplace(Sym, Pool.size(), TLS);
21 return IterBool.first->second.Number;
22}
23
24MCSymbol *AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) {
25 static const uint8_t AddrSize = Asm.MAI->getCodePointerSize();
26
27 MCSymbol *EndLabel =
28 Asm.emitDwarfUnitLength("debug_addr", "Length of contribution");
29 Asm.OutStreamer->AddComment("DWARF version number");
30 Asm.emitInt16(Asm.getDwarfVersion());
31 Asm.OutStreamer->AddComment("Address size");
32 Asm.emitInt8(AddrSize);
33 Asm.OutStreamer->AddComment("Segment selector size");
34 Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size.
35
36 return EndLabel;
37}
38
39// Emit addresses into the section given.
40void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
41 if (isEmpty())
42 return;
43
44 // Start the dwarf addr section.
45 Asm.OutStreamer->switchSection(AddrSection);
46
47 MCSymbol *EndLabel = nullptr;
48
49 if (Asm.getDwarfVersion() >= 5)
50 EndLabel = emitHeader(Asm, AddrSection);
51
52 // Define the symbol that marks the start of the contribution.
53 // It is referenced via DW_AT_addr_base.
54 Asm.OutStreamer->emitLabel(AddressTableBaseSym);
55
56 // Order the address pool entries by ID
57 SmallVector<const MCExpr *, 64> Entries(Pool.size());
58
59 for (const auto &I : Pool)
60 Entries[I.second.Number] =
61 I.second.TLS
62 ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
63 : MCSymbolRefExpr::create(I.first, Asm.OutContext);
64
65 for (const MCExpr *Entry : Entries)
66 Asm.OutStreamer->emitValue(Entry, Asm.MAI->getCodePointerSize());
67
68 if (EndLabel)
69 Asm.OutStreamer->emitLabel(EndLabel);
70}
#define I(x, y, z)
Definition MD5.cpp:57
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.