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