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