blob: 81ef619ba77a6b0651d27bcae0de9141551f2101 [file] [log] [blame]
David Blaikiee226b082014-04-23 21:04:59 +00001
2#include "AddressPool.h"
3#include "llvm/CodeGen/AsmPrinter.h"
4#include "llvm/MC/MCStreamer.h"
5#include "llvm/Target/TargetLoweringObjectFile.h"
6
7using namespace llvm;
8
9class MCExpr;
10
11unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
12 auto IterBool =
13 Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
14 return IterBool.first->second.Number;
15}
16
17// Emit addresses into the section given.
18void AddressPool::emit(AsmPrinter &Asm, const MCSection *AddrSection) {
19 if (Pool.empty())
20 return;
21
22 // Start the dwarf addr section.
23 Asm.OutStreamer.SwitchSection(AddrSection);
24
25 // Order the address pool entries by ID
26 SmallVector<const MCExpr *, 64> Entries(Pool.size());
27
28 for (const auto &I : Pool)
29 Entries[I.second.Number] =
30 I.second.TLS
31 ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
32 : MCSymbolRefExpr::Create(I.first, Asm.OutContext);
33
34 for (const MCExpr *Entry : Entries)
35 Asm.OutStreamer.EmitValue(Entry, Asm.getDataLayout().getPointerSize());
36}