Separate out the DWARF address pool into its own type/files.
[oota-llvm.git] / lib / CodeGen / AsmPrinter / AddressPool.cpp
1
2 #include "AddressPool.h"
3 #include "llvm/CodeGen/AsmPrinter.h"
4 #include "llvm/MC/MCStreamer.h"
5 #include "llvm/Target/TargetLoweringObjectFile.h"
6
7 using namespace llvm;
8
9 class MCExpr;
10
11 unsigned 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.
18 void 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 }