AddressPool.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. //===- llvm/CodeGen/AddressPool.h - Dwarf Debug Framework -------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H
  9. #define LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H
  10. #include "llvm/ADT/DenseMap.h"
  11. namespace llvm {
  12. class AsmPrinter;
  13. class MCSection;
  14. class MCSymbol;
  15. // Collection of addresses for this unit and assorted labels.
  16. // A Symbol->unsigned mapping of addresses used by indirect
  17. // references.
  18. class AddressPool {
  19. struct AddressPoolEntry {
  20. unsigned Number;
  21. bool TLS;
  22. AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
  23. };
  24. DenseMap<const MCSymbol *, AddressPoolEntry> Pool;
  25. /// Record whether the AddressPool has been queried for an address index since
  26. /// the last "resetUsedFlag" call. Used to implement type unit fallback - a
  27. /// type that references addresses cannot be placed in a type unit when using
  28. /// fission.
  29. bool HasBeenUsed = false;
  30. public:
  31. AddressPool() = default;
  32. /// Returns the index into the address pool with the given
  33. /// label/symbol.
  34. unsigned getIndex(const MCSymbol *Sym, bool TLS = false);
  35. void emit(AsmPrinter &Asm, MCSection *AddrSection);
  36. bool isEmpty() { return Pool.empty(); }
  37. bool hasBeenUsed() const { return HasBeenUsed; }
  38. void resetUsedFlag(bool HasBeenUsed = false) { this->HasBeenUsed = HasBeenUsed; }
  39. MCSymbol *getLabel() { return AddressTableBaseSym; }
  40. void setLabel(MCSymbol *Sym) { AddressTableBaseSym = Sym; }
  41. private:
  42. MCSymbol *emitHeader(AsmPrinter &Asm, MCSection *Section);
  43. /// Symbol designates the start of the contribution to the address table.
  44. MCSymbol *AddressTableBaseSym = nullptr;
  45. };
  46. } // end namespace llvm
  47. #endif // LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H