2014-04-25 14:22:32 +08:00
|
|
|
//===-- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---*- C++ -*--===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2014-04-24 05:04:59 +08:00
|
|
|
|
|
|
|
#include "AddressPool.h"
|
|
|
|
#include "llvm/CodeGen/AsmPrinter.h"
|
|
|
|
#include "llvm/MC/MCStreamer.h"
|
|
|
|
#include "llvm/Target/TargetLoweringObjectFile.h"
|
|
|
|
|
|
|
|
using namespace llvm;
|
|
|
|
|
|
|
|
unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
|
2014-04-27 01:27:38 +08:00
|
|
|
HasBeenUsed = true;
|
2014-04-24 05:04:59 +08:00
|
|
|
auto IterBool =
|
|
|
|
Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
|
|
|
|
return IterBool.first->second.Number;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Emit addresses into the section given.
|
2015-05-22 03:20:38 +08:00
|
|
|
void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
|
2014-04-24 05:04:59 +08:00
|
|
|
if (Pool.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Start the dwarf addr section.
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm.OutStreamer->SwitchSection(AddrSection);
|
2014-04-24 05:04:59 +08:00
|
|
|
|
|
|
|
// Order the address pool entries by ID
|
|
|
|
SmallVector<const MCExpr *, 64> Entries(Pool.size());
|
|
|
|
|
|
|
|
for (const auto &I : Pool)
|
|
|
|
Entries[I.second.Number] =
|
|
|
|
I.second.TLS
|
|
|
|
? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
|
2015-05-30 09:25:56 +08:00
|
|
|
: MCSymbolRefExpr::create(I.first, Asm.OutContext);
|
2014-04-24 05:04:59 +08:00
|
|
|
|
|
|
|
for (const MCExpr *Entry : Entries)
|
2015-04-25 03:11:51 +08:00
|
|
|
Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());
|
2014-04-24 05:04:59 +08:00
|
|
|
}
|