1 //===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "AddressPool.h"
11 #include "llvm/ADT/SmallVector.h"
12 #include "llvm/CodeGen/AsmPrinter.h"
13 #include "llvm/CodeGen/TargetLoweringObjectFile.h"
14 #include "llvm/IR/DataLayout.h"
15 #include "llvm/MC/MCStreamer.h"
20 unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
23 Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
24 return IterBool.first->second.Number;
27 // Emit addresses into the section given.
28 void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
32 // Start the dwarf addr section.
33 Asm.OutStreamer->SwitchSection(AddrSection);
35 // Order the address pool entries by ID
36 SmallVector<const MCExpr *, 64> Entries(Pool.size());
38 for (const auto &I : Pool)
39 Entries[I.second.Number] =
41 ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
42 : MCSymbolRefExpr::create(I.first, Asm.OutContext);
44 for (const MCExpr *Entry : Entries)
45 Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());