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