blob: c5f5637fdae3fa4a5facd86582c62bf2ceedb00c [file] [log] [blame]
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +00001//===- llvm/CodeGen/DwarfStringPool.h - Dwarf Debug Framework ---*- C++ -*-===//
David Blaikiedaefdbf2014-04-25 21:34:35 +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 Blaikiedaefdbf2014-04-25 21:34:35 +00006//
7//===----------------------------------------------------------------------===//
8
Benjamin Kramera7c40ef2014-08-13 16:26:38 +00009#ifndef LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H
10#define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H
David Blaikiedaefdbf2014-04-25 21:34:35 +000011
12#include "llvm/ADT/StringMap.h"
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000013#include "llvm/ADT/StringRef.h"
Duncan P. N. Exon Smith03b7a1c2015-05-24 16:33:33 +000014#include "llvm/CodeGen/DwarfStringPoolEntry.h"
David Blaikiedaefdbf2014-04-25 21:34:35 +000015#include "llvm/Support/Allocator.h"
David Blaikiedaefdbf2014-04-25 21:34:35 +000016
17namespace llvm {
18
Duncan P. N. Exon Smith9d50e822015-05-24 16:54:59 +000019class AsmPrinter;
David Blaikiedaefdbf2014-04-25 21:34:35 +000020class MCSection;
Pavel Labath7bfa5d62018-07-26 14:36:07 +000021class MCSymbol;
David Blaikiedaefdbf2014-04-25 21:34:35 +000022
23// Collection of strings for this unit and assorted symbols.
24// A String->Symbol mapping of strings used by indirect
25// references.
26class DwarfStringPool {
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000027 using EntryTy = DwarfStringPoolEntry;
28
Duncan P. N. Exon Smith1a65e4a2015-05-24 16:14:59 +000029 StringMap<EntryTy, BumpPtrAllocator &> Pool;
David Blaikiedaefdbf2014-04-25 21:34:35 +000030 StringRef Prefix;
Duncan P. N. Exon Smith1a65e4a2015-05-24 16:14:59 +000031 unsigned NumBytes = 0;
Pavel Labath2f088112018-08-07 09:54:52 +000032 unsigned NumIndexedStrings = 0;
Duncan P. N. Exon Smith882a2b52015-05-24 16:58:59 +000033 bool ShouldCreateSymbols;
David Blaikiedaefdbf2014-04-25 21:34:35 +000034
Pavel Labath2f088112018-08-07 09:54:52 +000035 StringMapEntry<EntryTy> &getEntryImpl(AsmPrinter &Asm, StringRef Str);
36
David Blaikiedaefdbf2014-04-25 21:34:35 +000037public:
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000038 using EntryRef = DwarfStringPoolEntryRef;
Duncan P. N. Exon Smith03b7a1c2015-05-24 16:33:33 +000039
Duncan P. N. Exon Smith882a2b52015-05-24 16:58:59 +000040 DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix);
David Blaikiedaefdbf2014-04-25 21:34:35 +000041
Pavel Labath7bfa5d62018-07-26 14:36:07 +000042 void emitStringOffsetsTableHeader(AsmPrinter &Asm, MCSection *OffsetSection,
43 MCSymbol *StartSym);
44
Rafael Espindola0709a7b2015-05-21 19:20:38 +000045 void emit(AsmPrinter &Asm, MCSection *StrSection,
Wolfgang Pieb456b5552018-01-26 18:52:58 +000046 MCSection *OffsetSection = nullptr,
47 bool UseRelativeOffsets = false);
David Blaikiedaefdbf2014-04-25 21:34:35 +000048
David Blaikiedaefdbf2014-04-25 21:34:35 +000049 bool empty() const { return Pool.empty(); }
Duncan P. N. Exon Smith8c6499f2015-05-24 16:06:08 +000050
Wolfgang Pieb456b5552018-01-26 18:52:58 +000051 unsigned size() const { return Pool.size(); }
52
Pavel Labath2f088112018-08-07 09:54:52 +000053 unsigned getNumIndexedStrings() const { return NumIndexedStrings; }
54
Duncan P. N. Exon Smith03b7a1c2015-05-24 16:33:33 +000055 /// Get a reference to an entry in the string pool.
56 EntryRef getEntry(AsmPrinter &Asm, StringRef Str);
Pavel Labath2f088112018-08-07 09:54:52 +000057
58 /// Same as getEntry, except that you can use EntryRef::getIndex to obtain a
59 /// unique ID of this entry (e.g., for use in indexed forms like
60 /// DW_FORM_strx).
61 EntryRef getIndexedEntry(AsmPrinter &Asm, StringRef Str);
David Blaikiedaefdbf2014-04-25 21:34:35 +000062};
Eugene Zelenko6e07bfd2017-08-17 21:26:39 +000063
64} // end namespace llvm
65
66#endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H