LLVM API Documentation

AddressPool.cpp
Go to the documentation of this file.
00001 //===-- llvm/CodeGen/AddressPool.cpp - Dwarf Debug Framework ---*- C++ -*--===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "AddressPool.h"
00011 #include "llvm/CodeGen/AsmPrinter.h"
00012 #include "llvm/MC/MCStreamer.h"
00013 #include "llvm/Target/TargetLoweringObjectFile.h"
00014 
00015 using namespace llvm;
00016 
00017 class MCExpr;
00018 
00019 unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
00020   HasBeenUsed = true;
00021   auto IterBool =
00022       Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
00023   return IterBool.first->second.Number;
00024 }
00025 
00026 // Emit addresses into the section given.
00027 void AddressPool::emit(AsmPrinter &Asm, const MCSection *AddrSection) {
00028   if (Pool.empty())
00029     return;
00030 
00031   // Start the dwarf addr section.
00032   Asm.OutStreamer.SwitchSection(AddrSection);
00033 
00034   // Order the address pool entries by ID
00035   SmallVector<const MCExpr *, 64> Entries(Pool.size());
00036 
00037   for (const auto &I : Pool)
00038     Entries[I.second.Number] =
00039         I.second.TLS
00040             ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
00041             : MCSymbolRefExpr::Create(I.first, Asm.OutContext);
00042 
00043   for (const MCExpr *Entry : Entries)
00044     Asm.OutStreamer.EmitValue(Entry, Asm.getDataLayout().getPointerSize());
00045 }