LLVM  8.0.1
AddressPool.cpp
Go to the documentation of this file.
1 //===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "AddressPool.h"
11 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/IR/DataLayout.h"
14 #include "llvm/MC/MCStreamer.h"
16 #include <utility>
17 
18 using namespace llvm;
19 
20 unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
21  HasBeenUsed = true;
22  auto IterBool =
23  Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
24  return IterBool.first->second.Number;
25 }
26 
27 
28 void AddressPool::emitHeader(AsmPrinter &Asm, MCSection *Section) {
29  static const uint8_t AddrSize = Asm.getDataLayout().getPointerSize();
30  uint64_t Length = sizeof(uint16_t) // version
31  + sizeof(uint8_t) // address_size
32  + sizeof(uint8_t) // segment_selector_size
33  + AddrSize * Pool.size(); // entries
34  Asm.OutStreamer->AddComment("Length of contribution");
35  Asm.emitInt32(Length); // TODO: Support DWARF64 format.
36  Asm.OutStreamer->AddComment("DWARF version number");
37  Asm.emitInt16(Asm.getDwarfVersion());
38  Asm.OutStreamer->AddComment("Address size");
39  Asm.emitInt8(AddrSize);
40  Asm.OutStreamer->AddComment("Segment selector size");
41  Asm.emitInt8(0); // TODO: Support non-zero segment_selector_size.
42 }
43 
44 // Emit addresses into the section given.
45 void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
46  if (isEmpty())
47  return;
48 
49  // Start the dwarf addr section.
50  Asm.OutStreamer->SwitchSection(AddrSection);
51 
52  if (Asm.getDwarfVersion() >= 5)
53  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
66  : MCSymbolRefExpr::create(I.first, Asm.OutContext);
67 
68  for (const MCExpr *Entry : Entries)
69  Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());
70 }
const TargetLoweringObjectFile & getObjFileLowering() const
Return information about object file lowering.
Definition: AsmPrinter.cpp:212
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:39
std::unique_ptr< MCStreamer > OutStreamer
This is the MCStreamer object for the file we are generating.
Definition: AsmPrinter.h:94
static const MCSymbolRefExpr * create(const MCSymbol *Symbol, MCContext &Ctx)
Definition: MCExpr.h:323
This class represents lattice values for constants.
Definition: AllocatorList.h:24
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
MCContext & OutContext
This is the context for the output file that we are streaming.
Definition: AsmPrinter.h:89
uint16_t getDwarfVersion() const
Base class for the full range of assembler expressions which are needed for parsing.
Definition: MCExpr.h:36
void emit(AsmPrinter &Asm, MCSection *AddrSection)
Definition: AddressPool.cpp:45
unsigned getPointerSize(unsigned AS=0) const
Layout pointer size FIXME: The defaults need to be removed once all of the backends/clients are updat...
Definition: DataLayout.cpp:629
This class is intended to be used as a driving class for all asm writers.
Definition: AsmPrinter.h:79
This is a &#39;vector&#39; (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:847
void emitInt32(int Value) const
Emit a long directive and value.
#define I(x, y, z)
Definition: MD5.cpp:58
void emitInt8(int Value) const
Emit a byte directive and value.
const DataLayout & getDataLayout() const
Return information about data layout.
Definition: AsmPrinter.cpp:216
virtual const MCExpr * getDebugThreadLocalSymbol(const MCSymbol *Sym) const
Create a symbol reference to describe the given TLS variable when emitting the address in debug info...
void emitInt16(int Value) const
Emit a short directive and value.
unsigned getIndex(const MCSymbol *Sym, bool TLS=false)
Returns the index into the address pool with the given label/symbol.
Definition: AddressPool.cpp:20