blob: ec552e0640e9be83f7ef8a26e348edc1d71ebf18 [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
David Blaikiee226b082014-04-23 21:04:59 +000017unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
David Blaikiee12b49a2014-04-26 17:27:38 +000018 HasBeenUsed = true;
David Blaikiee226b082014-04-23 21:04:59 +000019 auto IterBool =
20 Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
21 return IterBool.first->second.Number;
22}
23
24// Emit addresses into the section given.
Rafael Espindola0709a7b2015-05-21 19:20:38 +000025void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
David Blaikiee226b082014-04-23 21:04:59 +000026 if (Pool.empty())
27 return;
28
29 // Start the dwarf addr section.
Lang Hames9ff69c82015-04-24 19:11:51 +000030 Asm.OutStreamer->SwitchSection(AddrSection);
David Blaikiee226b082014-04-23 21:04:59 +000031
32 // Order the address pool entries by ID
33 SmallVector<const MCExpr *, 64> Entries(Pool.size());
34
35 for (const auto &I : Pool)
36 Entries[I.second.Number] =
37 I.second.TLS
38 ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
Jim Grosbach13760bd2015-05-30 01:25:56 +000039 : MCSymbolRefExpr::create(I.first, Asm.OutContext);
David Blaikiee226b082014-04-23 21:04:59 +000040
41 for (const MCExpr *Entry : Entries)
Lang Hames9ff69c82015-04-24 19:11:51 +000042 Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());
David Blaikiee226b082014-04-23 21:04:59 +000043}