Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:28

0001 //===- llvm/CodeGen/DwarfStringPoolEntry.h - String pool entry --*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
0010 #define LLVM_CODEGEN_DWARFSTRINGPOOLENTRY_H
0011 
0012 #include "llvm/ADT/PointerUnion.h"
0013 #include "llvm/ADT/StringMap.h"
0014 
0015 namespace llvm {
0016 
0017 class MCSymbol;
0018 
0019 /// Data for a string pool entry.
0020 struct DwarfStringPoolEntry {
0021   static constexpr unsigned NotIndexed = -1;
0022 
0023   MCSymbol *Symbol = nullptr;
0024   uint64_t Offset = 0;
0025   unsigned Index = 0;
0026 
0027   bool isIndexed() const { return Index != NotIndexed; }
0028 };
0029 
0030 /// DwarfStringPoolEntry with string keeping externally.
0031 struct DwarfStringPoolEntryWithExtString : public DwarfStringPoolEntry {
0032   StringRef String;
0033 };
0034 
0035 /// DwarfStringPoolEntryRef: Dwarf string pool entry reference.
0036 ///
0037 /// Dwarf string pool entry keeps string value and its data.
0038 /// There are two variants how data are represented:
0039 ///
0040 ///   1. String data in pool  - StringMapEntry<DwarfStringPoolEntry>.
0041 ///   2. External string data - DwarfStringPoolEntryWithExtString.
0042 ///
0043 /// The external data variant allows reducing memory usage for the case
0044 /// when string pool entry does not have data: string entry does not
0045 /// keep any data and so no need to waste space for the full
0046 /// DwarfStringPoolEntry. It is recommended to use external variant if not all
0047 /// entries of dwarf string pool have corresponding DwarfStringPoolEntry.
0048 
0049 class DwarfStringPoolEntryRef {
0050   /// Pointer type for "By value" string entry.
0051   using ByValStringEntryPtr = const StringMapEntry<DwarfStringPoolEntry> *;
0052 
0053   /// Pointer type for external string entry.
0054   using ExtStringEntryPtr = const DwarfStringPoolEntryWithExtString *;
0055 
0056   /// Pointer to the dwarf string pool Entry.
0057   PointerUnion<ByValStringEntryPtr, ExtStringEntryPtr> MapEntry = nullptr;
0058 
0059 public:
0060   DwarfStringPoolEntryRef() = default;
0061 
0062   /// ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to \p Entry,
0063   /// thus specified entry mustn`t be reallocated.
0064   DwarfStringPoolEntryRef(const StringMapEntry<DwarfStringPoolEntry> &Entry)
0065       : MapEntry(&Entry) {}
0066 
0067   /// ASSUMPTION: DwarfStringPoolEntryRef keeps pointer to \p Entry,
0068   /// thus specified entry mustn`t be reallocated.
0069   DwarfStringPoolEntryRef(const DwarfStringPoolEntryWithExtString &Entry)
0070       : MapEntry(&Entry) {}
0071 
0072   explicit operator bool() const { return !MapEntry.isNull(); }
0073 
0074   /// \returns symbol for the dwarf string.
0075   MCSymbol *getSymbol() const {
0076     assert(getEntry().Symbol && "No symbol available!");
0077     return getEntry().Symbol;
0078   }
0079 
0080   /// \returns offset for the dwarf string.
0081   uint64_t getOffset() const { return getEntry().Offset; }
0082 
0083   /// \returns index for the dwarf string.
0084   unsigned getIndex() const {
0085     assert(getEntry().isIndexed() && "Index is not set!");
0086     return getEntry().Index;
0087   }
0088 
0089   /// \returns string.
0090   StringRef getString() const {
0091     if (isa<ByValStringEntryPtr>(MapEntry))
0092       return cast<ByValStringEntryPtr>(MapEntry)->first();
0093 
0094     return cast<ExtStringEntryPtr>(MapEntry)->String;
0095   }
0096 
0097   /// \returns the entire string pool entry for convenience.
0098   const DwarfStringPoolEntry &getEntry() const {
0099     if (isa<ByValStringEntryPtr>(MapEntry))
0100       return cast<ByValStringEntryPtr>(MapEntry)->second;
0101 
0102     return *cast<ExtStringEntryPtr>(MapEntry);
0103   }
0104 
0105   bool operator==(const DwarfStringPoolEntryRef &X) const {
0106     return MapEntry.getOpaqueValue() == X.MapEntry.getOpaqueValue();
0107   }
0108 
0109   bool operator!=(const DwarfStringPoolEntryRef &X) const {
0110     return MapEntry.getOpaqueValue() != X.MapEntry.getOpaqueValue();
0111   }
0112 };
0113 
0114 } // end namespace llvm
0115 
0116 #endif