]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/lib/CodeGen/AsmPrinter/AddressPool.cpp
Merge ^/head r327341 through r327623.
[FreeBSD/FreeBSD.git] / contrib / llvm / lib / CodeGen / AsmPrinter / AddressPool.cpp
1 //===- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---------------===//
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 //===----------------------------------------------------------------------===//
9
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"
16 #include <utility>
17
18 using namespace llvm;
19
20 unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
21   HasBeenUsed = true;
22   auto IterBool =
23       Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
24   return IterBool.first->second.Number;
25 }
26
27 // Emit addresses into the section given.
28 void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
29   if (Pool.empty())
30     return;
31
32   // Start the dwarf addr section.
33   Asm.OutStreamer->SwitchSection(AddrSection);
34
35   // Order the address pool entries by ID
36   SmallVector<const MCExpr *, 64> Entries(Pool.size());
37
38   for (const auto &I : Pool)
39     Entries[I.second.Number] =
40         I.second.TLS
41             ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
42             : MCSymbolRefExpr::create(I.first, Asm.OutContext);
43
44   for (const MCExpr *Entry : Entries)
45     Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());
46 }