Back to home page

EIC code displayed by LXR

 
 

    


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

0001 //===- NonRelocatableStringpool.h -------------------------------*- 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_NONRELOCATABLESTRINGPOOL_H
0010 #define LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H
0011 
0012 #include "llvm/CodeGen/DwarfStringPoolEntry.h"
0013 #include "llvm/Support/Allocator.h"
0014 #include <cstdint>
0015 #include <vector>
0016 
0017 namespace llvm {
0018 
0019 /// A string table that doesn't need relocations.
0020 ///
0021 /// Use this class when a string table doesn't need relocations.
0022 /// This class provides this ability by just associating offsets with strings.
0023 class NonRelocatableStringpool {
0024 public:
0025   /// Entries are stored into the StringMap and simply linked together through
0026   /// the second element of this pair in order to keep track of insertion
0027   /// order.
0028   using MapTy = StringMap<DwarfStringPoolEntry, BumpPtrAllocator>;
0029 
0030   NonRelocatableStringpool(bool PutEmptyString = false) {
0031     if (PutEmptyString)
0032       getEntry("");
0033   }
0034 
0035   DwarfStringPoolEntryRef getEntry(StringRef S);
0036 
0037   /// Get the offset of string \p S in the string table. This can insert a new
0038   /// element or return the offset of a pre-existing one.
0039   uint64_t getStringOffset(StringRef S) { return getEntry(S).getOffset(); }
0040 
0041   /// Get permanent storage for \p S (but do not necessarily emit \p S in the
0042   /// output section). A latter call to getStringOffset() with the same string
0043   /// will chain it though.
0044   ///
0045   /// \returns The StringRef that points to permanent storage to use
0046   /// in place of \p S.
0047   StringRef internString(StringRef S);
0048 
0049   uint64_t getSize() { return CurrentEndOffset; }
0050 
0051   /// Return the list of strings to be emitted. This does not contain the
0052   /// strings which were added via internString only.
0053   std::vector<DwarfStringPoolEntryRef> getEntriesForEmission() const;
0054 
0055 private:
0056   MapTy Strings;
0057   uint64_t CurrentEndOffset = 0;
0058   unsigned NumEntries = 0;
0059 };
0060 
0061 /// Helper for making strong types.
0062 template <typename T, typename S> class StrongType : public T {
0063 public:
0064   template <typename... Args>
0065   explicit StrongType(Args... A) : T(std::forward<Args>(A)...) {}
0066 };
0067 
0068 /// It's very easy to introduce bugs by passing the wrong string pool.
0069 /// By using strong types the interface enforces that the right
0070 /// kind of pool is used.
0071 struct UniqueTag {};
0072 struct OffsetsTag {};
0073 using UniquingStringPool = StrongType<NonRelocatableStringpool, UniqueTag>;
0074 using OffsetsStringPool = StrongType<NonRelocatableStringpool, OffsetsTag>;
0075 
0076 } // end namespace llvm
0077 
0078 #endif // LLVM_CODEGEN_NONRELOCATABLESTRINGPOOL_H