blob: d5008fab5563a348f4507e88c75a8d3c7bde5d42 [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//
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
Benjamin Kramera7c40ef2014-08-13 16:26:38 +000010#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H
11#define LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H
David Blaikiee226b082014-04-23 21:04:59 +000012
13#include "llvm/ADT/DenseMap.h"
14
15namespace llvm {
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000016
David Blaikiee226b082014-04-23 21:04:59 +000017class AsmPrinter;
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000018class MCSection;
19class MCSymbol;
20
David Blaikiee226b082014-04-23 21:04:59 +000021// Collection of addresses for this unit and assorted labels.
22// A Symbol->unsigned mapping of addresses used by indirect
23// references.
24class AddressPool {
25 struct AddressPoolEntry {
26 unsigned Number;
27 bool TLS;
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000028
David Blaikiee226b082014-04-23 21:04:59 +000029 AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {}
30 };
31 DenseMap<const MCSymbol *, AddressPoolEntry> Pool;
David Blaikieb2133cb2014-04-28 22:52:50 +000032
33 /// Record whether the AddressPool has been queried for an address index since
34 /// the last "resetUsedFlag" call. Used to implement type unit fallback - a
35 /// type that references addresses cannot be placed in a type unit when using
36 /// fission.
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000037 bool HasBeenUsed = false;
David Blaikie8fb87ee2014-04-23 21:20:07 +000038
David Blaikiee226b082014-04-23 21:04:59 +000039public:
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000040 AddressPool() = default;
David Blaikiee12b49a2014-04-26 17:27:38 +000041
Adrian Prantl5f8f34e42018-05-01 15:54:18 +000042 /// Returns the index into the address pool with the given
David Blaikiee226b082014-04-23 21:04:59 +000043 /// label/symbol.
44 unsigned getIndex(const MCSymbol *Sym, bool TLS = false);
45
Rafael Espindola0709a7b2015-05-21 19:20:38 +000046 void emit(AsmPrinter &Asm, MCSection *AddrSection);
David Blaikiee226b082014-04-23 21:04:59 +000047
48 bool isEmpty() { return Pool.empty(); }
David Blaikiee12b49a2014-04-26 17:27:38 +000049
50 bool hasBeenUsed() const { return HasBeenUsed; }
51
52 void resetUsedFlag() { HasBeenUsed = false; }
Victor Leschuk64e0c562018-08-01 05:48:06 +000053
54private:
55 void emitHeader(AsmPrinter &Asm, MCSection *Section);
David Blaikiee226b082014-04-23 21:04:59 +000056};
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000057
58} // end namespace llvm
59
60#endif // LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H