Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 1 | //===- llvm/CodeGen/AddressPool.h - Dwarf Debug Framework -------*- C++ -*-===// |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 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 |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | |
Benjamin Kramer | a7c40ef | 2014-08-13 16:26:38 +0000 | [diff] [blame] | 9 | #ifndef LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H |
| 10 | #define LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 11 | |
| 12 | #include "llvm/ADT/DenseMap.h" |
| 13 | |
| 14 | namespace llvm { |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 15 | |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 16 | class AsmPrinter; |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 17 | class MCSection; |
| 18 | class MCSymbol; |
| 19 | |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 20 | // Collection of addresses for this unit and assorted labels. |
| 21 | // A Symbol->unsigned mapping of addresses used by indirect |
| 22 | // references. |
| 23 | class AddressPool { |
| 24 | struct AddressPoolEntry { |
| 25 | unsigned Number; |
| 26 | bool TLS; |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 27 | |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 28 | AddressPoolEntry(unsigned Number, bool TLS) : Number(Number), TLS(TLS) {} |
| 29 | }; |
| 30 | DenseMap<const MCSymbol *, AddressPoolEntry> Pool; |
David Blaikie | b2133cb | 2014-04-28 22:52:50 +0000 | [diff] [blame] | 31 | |
| 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 Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 36 | bool HasBeenUsed = false; |
David Blaikie | 8fb87ee | 2014-04-23 21:20:07 +0000 | [diff] [blame] | 37 | |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 38 | public: |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 39 | AddressPool() = default; |
David Blaikie | e12b49a | 2014-04-26 17:27:38 +0000 | [diff] [blame] | 40 | |
Adrian Prantl | 5f8f34e4 | 2018-05-01 15:54:18 +0000 | [diff] [blame] | 41 | /// Returns the index into the address pool with the given |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 42 | /// label/symbol. |
| 43 | unsigned getIndex(const MCSymbol *Sym, bool TLS = false); |
| 44 | |
Rafael Espindola | 0709a7b | 2015-05-21 19:20:38 +0000 | [diff] [blame] | 45 | void emit(AsmPrinter &Asm, MCSection *AddrSection); |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 46 | |
| 47 | bool isEmpty() { return Pool.empty(); } |
David Blaikie | e12b49a | 2014-04-26 17:27:38 +0000 | [diff] [blame] | 48 | |
| 49 | bool hasBeenUsed() const { return HasBeenUsed; } |
| 50 | |
| 51 | void resetUsedFlag() { HasBeenUsed = false; } |
Victor Leschuk | 64e0c56 | 2018-08-01 05:48:06 +0000 | [diff] [blame] | 52 | |
George Rimar | 425f751 | 2018-09-20 09:17:36 +0000 | [diff] [blame] | 53 | MCSymbol *getLabel() { return AddressTableBaseSym; } |
| 54 | void setLabel(MCSymbol *Sym) { AddressTableBaseSym = Sym; } |
| 55 | |
Victor Leschuk | 64e0c56 | 2018-08-01 05:48:06 +0000 | [diff] [blame] | 56 | private: |
David Blaikie | 7b58567 | 2019-01-24 03:27:57 +0000 | [diff] [blame] | 57 | MCSymbol *emitHeader(AsmPrinter &Asm, MCSection *Section); |
George Rimar | 425f751 | 2018-09-20 09:17:36 +0000 | [diff] [blame] | 58 | |
| 59 | /// Symbol designates the start of the contribution to the address table. |
| 60 | MCSymbol *AddressTableBaseSym = nullptr; |
David Blaikie | e226b08 | 2014-04-23 21:04:59 +0000 | [diff] [blame] | 61 | }; |
Eugene Zelenko | 6e07bfd | 2017-08-17 21:26:39 +0000 | [diff] [blame] | 62 | |
| 63 | } // end namespace llvm |
| 64 | |
| 65 | #endif // LLVM_LIB_CODEGEN_ASMPRINTER_ADDRESSPOOL_H |