xref: /freebsd-src/contrib/llvm-project/llvm/lib/CodeGen/AsmPrinter/DwarfStringPool.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===- llvm/CodeGen/DwarfStringPool.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_DWARFSTRINGPOOL_H
100b57cec5SDimitry Andric #define LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H
110b57cec5SDimitry Andric 
120b57cec5SDimitry Andric #include "llvm/ADT/StringMap.h"
130b57cec5SDimitry Andric #include "llvm/ADT/StringRef.h"
140b57cec5SDimitry Andric #include "llvm/CodeGen/DwarfStringPoolEntry.h"
150b57cec5SDimitry Andric #include "llvm/Support/Allocator.h"
160b57cec5SDimitry Andric 
170b57cec5SDimitry Andric namespace llvm {
180b57cec5SDimitry Andric 
190b57cec5SDimitry Andric class AsmPrinter;
200b57cec5SDimitry Andric class MCSection;
210b57cec5SDimitry Andric class MCSymbol;
220b57cec5SDimitry Andric 
230b57cec5SDimitry Andric // Collection of strings for this unit and assorted symbols.
240b57cec5SDimitry Andric // A String->Symbol mapping of strings used by indirect
250b57cec5SDimitry Andric // references.
260b57cec5SDimitry Andric class DwarfStringPool {
270b57cec5SDimitry Andric   using EntryTy = DwarfStringPoolEntry;
280b57cec5SDimitry Andric 
290b57cec5SDimitry Andric   StringMap<EntryTy, BumpPtrAllocator &> Pool;
300b57cec5SDimitry Andric   StringRef Prefix;
31*e8d8bef9SDimitry Andric   uint64_t NumBytes = 0;
320b57cec5SDimitry Andric   unsigned NumIndexedStrings = 0;
330b57cec5SDimitry Andric   bool ShouldCreateSymbols;
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric   StringMapEntry<EntryTy> &getEntryImpl(AsmPrinter &Asm, StringRef Str);
360b57cec5SDimitry Andric 
370b57cec5SDimitry Andric public:
380b57cec5SDimitry Andric   using EntryRef = DwarfStringPoolEntryRef;
390b57cec5SDimitry Andric 
400b57cec5SDimitry Andric   DwarfStringPool(BumpPtrAllocator &A, AsmPrinter &Asm, StringRef Prefix);
410b57cec5SDimitry Andric 
420b57cec5SDimitry Andric   void emitStringOffsetsTableHeader(AsmPrinter &Asm, MCSection *OffsetSection,
430b57cec5SDimitry Andric                                     MCSymbol *StartSym);
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric   void emit(AsmPrinter &Asm, MCSection *StrSection,
460b57cec5SDimitry Andric             MCSection *OffsetSection = nullptr,
470b57cec5SDimitry Andric             bool UseRelativeOffsets = false);
480b57cec5SDimitry Andric 
empty()490b57cec5SDimitry Andric   bool empty() const { return Pool.empty(); }
500b57cec5SDimitry Andric 
size()510b57cec5SDimitry Andric   unsigned size() const { return Pool.size(); }
520b57cec5SDimitry Andric 
getNumIndexedStrings()530b57cec5SDimitry Andric   unsigned getNumIndexedStrings() const { return NumIndexedStrings; }
540b57cec5SDimitry Andric 
550b57cec5SDimitry Andric   /// Get a reference to an entry in the string pool.
560b57cec5SDimitry Andric   EntryRef getEntry(AsmPrinter &Asm, StringRef Str);
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric   /// Same as getEntry, except that you can use EntryRef::getIndex to obtain a
590b57cec5SDimitry Andric   /// unique ID of this entry (e.g., for use in indexed forms like
600b57cec5SDimitry Andric   /// DW_FORM_strx).
610b57cec5SDimitry Andric   EntryRef getIndexedEntry(AsmPrinter &Asm, StringRef Str);
620b57cec5SDimitry Andric };
630b57cec5SDimitry Andric 
640b57cec5SDimitry Andric } // end namespace llvm
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric #endif // LLVM_LIB_CODEGEN_ASMPRINTER_DWARFSTRINGPOOL_H
67