blob: f92cf72093ca03c828ea1647736194105e6e593c [file] [log] [blame]
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +00001//===- llvm/CodeGen/AddressPool.h - Dwarf Debug Framework -------*- C++ -*-===//
David Blaikiee226b082014-04-23 21:04:59 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// 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
David Blaikiee226b082014-04-23 21:04:59 +00006//
7//===----------------------------------------------------------------------===//
8
Benjamin Kramera7c40ef2014-08-13 16:26:38 +00009#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H
10#define LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H
David Blaikiee226b082014-04-23 21:04:59 +000011
12#include "llvm/ADT/DenseMap.h"
13
14namespace llvm {
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000015
David Blaikiee226b082014-04-23 21:04:59 +000016class AsmPrinter;
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000017class MCSection;
18class MCSymbol;
19
David Blaikiee226b082014-04-23 21:04:59 +000020// Collection of addresses for this unit and assorted labels.
21// A Symbol->unsigned mapping of addresses used by indirect
22// references.
23class AddressPool {
24 struct AddressPoolEntry {
25 unsigned Number;
26 bool TLS;
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000027
David Blaikiee226b082014-04-23 21:04:59 +000028 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
29 };
30 DenseMap<const MCSymbol *, AddressPoolEntry> Pool;
David Blaikieb2133cb2014-04-28 22:52:50 +000031
32 /// Record whether the AddressPool has been queried for an address index since
33 /// the last "resetUsedFlag" call. Used to implement type unit fallback - a
34 /// type that references addresses cannot be placed in a type unit when using
35 /// fission.
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000036 bool HasBeenUsed = false;
David Blaikie8fb87ee2014-04-23 21:20:07 +000037
David Blaikiee226b082014-04-23 21:04:59 +000038public:
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000039 AddressPool() = default;
David Blaikiee12b49a2014-04-26 17:27:38 +000040
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000041 /// Returns the index into the address pool with the given
David Blaikiee226b082014-04-23 21:04:59 +000042 /// label/symbol.
43 unsigned getIndex(const MCSymbol *Sym, bool TLS = false);
44
Rafael Espindola0709a7b2015-05-21 19:20:38 +000045 void emit(AsmPrinter &Asm, MCSection *AddrSection);
David Blaikiee226b082014-04-23 21:04:59 +000046
47 bool isEmpty() { return Pool.empty(); }
David Blaikiee12b49a2014-04-26 17:27:38 +000048
49 bool hasBeenUsed() const { return HasBeenUsed; }
50
51 void resetUsedFlag() { HasBeenUsed = false; }
Victor Leschuk64e0c562018-08-01 05:48:06 +000052
George Rimar425f7512018-09-20 09:17:36 +000053 MCSymbol *getLabel() { return AddressTableBaseSym; }
54 void setLabel(MCSymbol *Sym) { AddressTableBaseSym = Sym; }
55
Victor Leschuk64e0c562018-08-01 05:48:06 +000056private:
David Blaikie7b585672019-01-24 03:27:57 +000057 MCSymbol *emitHeader(AsmPrinter &Asm, MCSection *Section);
George Rimar425f7512018-09-20 09:17:36 +000058
59 /// Symbol designates the start of the contribution to the address table.
60 MCSymbol *AddressTableBaseSym = nullptr;
David Blaikiee226b082014-04-23 21:04:59 +000061};
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000062
63} // end namespace llvm
64
65#endif // LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H