AddressPool.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //===-- 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. //===----------------------------------------------------------------------===//
  9. #include "AddressPool.h"
  10. #include "llvm/CodeGen/AsmPrinter.h"
  11. #include "llvm/MC/MCStreamer.h"
  12. #include "llvm/Target/TargetLoweringObjectFile.h"
  13. using namespace llvm;
  14. class MCExpr;
  15. unsigned AddressPool::getIndex(const MCSymbol *Sym, bool TLS) {
  16. HasBeenUsed = true;
  17. auto IterBool =
  18. Pool.insert(std::make_pair(Sym, AddressPoolEntry(Pool.size(), TLS)));
  19. return IterBool.first->second.Number;
  20. }
  21. // Emit addresses into the section given.
  22. void AddressPool::emit(AsmPrinter &Asm, MCSection *AddrSection) {
  23. if (Pool.empty())
  24. return;
  25. // Start the dwarf addr section.
  26. Asm.OutStreamer->SwitchSection(AddrSection);
  27. // Order the address pool entries by ID
  28. SmallVector<const MCExpr *, 64> Entries(Pool.size());
  29. for (const auto &I : Pool)
  30. Entries[I.second.Number] =
  31. I.second.TLS
  32. ? Asm.getObjFileLowering().getDebugThreadLocalSymbol(I.first)
  33. : MCSymbolRefExpr::create(I.first, Asm.OutContext);
  34. for (const MCExpr *Entry : Entries)
  35. Asm.OutStreamer->EmitValue(Entry, Asm.getDataLayout().getPointerSize());
  36. }