xref: /freebsd-src/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/AddressPool.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===- llvm/CodeGen/AddressPool.h - Dwarf Debug Framework -------*- C++ -*-===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric 
90b57cec5SDimitry Andric #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H
100b57cec5SDimitry Andric #define LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "llvm/ADT/DenseMap.h"
130b57cec5SDimitry Andric 
140b57cec5SDimitry Andric namespace llvm {
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric class AsmPrinter;
170b57cec5SDimitry Andric class MCSection;
180b57cec5SDimitry Andric class MCSymbol;
190b57cec5SDimitry Andric 
200b57cec5SDimitry Andric // Collection of addresses for this unit and assorted labels.
210b57cec5SDimitry Andric // A Symbol->unsigned mapping of addresses used by indirect
220b57cec5SDimitry Andric // references.
230b57cec5SDimitry Andric class AddressPool {
240b57cec5SDimitry Andric   struct AddressPoolEntry {
250b57cec5SDimitry Andric     unsigned Number;
260b57cec5SDimitry Andric     bool TLS;
270b57cec5SDimitry Andric 
AddressPoolEntryAddressPoolEntry280b57cec5SDimitry Andric     AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
290b57cec5SDimitry Andric   };
300b57cec5SDimitry Andric   DenseMap<const MCSymbol *, AddressPoolEntry> Pool;
310b57cec5SDimitry Andric 
320b57cec5SDimitry Andric   /// Record whether the AddressPool has been queried for an address index since
330b57cec5SDimitry Andric   /// the last "resetUsedFlag" call. Used to implement type unit fallback - a
340b57cec5SDimitry Andric   /// type that references addresses cannot be placed in a type unit when using
350b57cec5SDimitry Andric   /// fission.
360b57cec5SDimitry Andric   bool HasBeenUsed = false;
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric public:
390b57cec5SDimitry Andric   AddressPool() = default;
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric   /// Returns the index into the address pool with the given
420b57cec5SDimitry Andric   /// label/symbol.
430b57cec5SDimitry Andric   unsigned getIndex(const MCSymbol *Sym, bool TLS = false);
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric   void emit(AsmPrinter &Asm, MCSection *AddrSection);
460b57cec5SDimitry Andric 
isEmpty()470b57cec5SDimitry Andric   bool isEmpty() { return Pool.empty(); }
480b57cec5SDimitry Andric 
hasBeenUsed()490b57cec5SDimitry Andric   bool hasBeenUsed() const { return HasBeenUsed; }
500b57cec5SDimitry Andric 
51*e8d8bef9SDimitry Andric   void resetUsedFlag(bool HasBeenUsed = false) { this->HasBeenUsed = HasBeenUsed; }
520b57cec5SDimitry Andric 
getLabel()530b57cec5SDimitry Andric   MCSymbol *getLabel() { return AddressTableBaseSym; }
setLabel(MCSymbol * Sym)540b57cec5SDimitry Andric   void setLabel(MCSymbol *Sym) { AddressTableBaseSym = Sym; }
550b57cec5SDimitry Andric 
560b57cec5SDimitry Andric private:
570b57cec5SDimitry Andric   MCSymbol *emitHeader(AsmPrinter &Asm, MCSection *Section);
580b57cec5SDimitry Andric 
590b57cec5SDimitry Andric   /// Symbol designates the start of the contribution to the address table.
600b57cec5SDimitry Andric   MCSymbol *AddressTableBaseSym = nullptr;
610b57cec5SDimitry Andric };
620b57cec5SDimitry Andric 
630b57cec5SDimitry Andric } // end namespace llvm
640b57cec5SDimitry Andric 
650b57cec5SDimitry Andric #endif // LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H
66