xref: /freebsd/contrib/llvm-project/llvm/lib/DWARFLinker/Parallel/StringEntryToDwarfStringPoolEntryMap.h (revision 0fca6ea1d4eea4c934cfff25ac9ee8ad6fe95583)
11db9f3b2SDimitry Andric //===- StringEntryToDwarfStringPoolEntryMap.h -------------------*- C++ -*-===//
21db9f3b2SDimitry Andric //
31db9f3b2SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
41db9f3b2SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
51db9f3b2SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
61db9f3b2SDimitry Andric //
71db9f3b2SDimitry Andric //===----------------------------------------------------------------------===//
81db9f3b2SDimitry Andric 
91db9f3b2SDimitry Andric #ifndef LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
101db9f3b2SDimitry Andric #define LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
111db9f3b2SDimitry Andric 
121db9f3b2SDimitry Andric #include "DWARFLinkerGlobalData.h"
131db9f3b2SDimitry Andric #include "llvm/ADT/SmallVector.h"
141db9f3b2SDimitry Andric #include "llvm/DWARFLinker/StringPool.h"
151db9f3b2SDimitry Andric 
161db9f3b2SDimitry Andric namespace llvm {
171db9f3b2SDimitry Andric namespace dwarf_linker {
181db9f3b2SDimitry Andric namespace parallel {
191db9f3b2SDimitry Andric 
201db9f3b2SDimitry Andric /// This class creates a DwarfStringPoolEntry for the corresponding StringEntry.
211db9f3b2SDimitry Andric class StringEntryToDwarfStringPoolEntryMap {
221db9f3b2SDimitry Andric public:
StringEntryToDwarfStringPoolEntryMap(LinkingGlobalData & GlobalData)231db9f3b2SDimitry Andric   StringEntryToDwarfStringPoolEntryMap(LinkingGlobalData &GlobalData)
241db9f3b2SDimitry Andric       : GlobalData(GlobalData) {}
~StringEntryToDwarfStringPoolEntryMap()251db9f3b2SDimitry Andric   ~StringEntryToDwarfStringPoolEntryMap() {}
261db9f3b2SDimitry Andric 
271db9f3b2SDimitry Andric   /// Create DwarfStringPoolEntry for specified StringEntry if necessary.
281db9f3b2SDimitry Andric   /// Initialize DwarfStringPoolEntry with initial values.
add(const StringEntry * String)291db9f3b2SDimitry Andric   DwarfStringPoolEntryWithExtString *add(const StringEntry *String) {
301db9f3b2SDimitry Andric     DwarfStringPoolEntriesTy::iterator it = DwarfStringPoolEntries.find(String);
311db9f3b2SDimitry Andric 
321db9f3b2SDimitry Andric     if (it == DwarfStringPoolEntries.end()) {
331db9f3b2SDimitry Andric       DwarfStringPoolEntryWithExtString *DataPtr =
341db9f3b2SDimitry Andric           GlobalData.getAllocator()
351db9f3b2SDimitry Andric               .Allocate<DwarfStringPoolEntryWithExtString>();
36*0fca6ea1SDimitry Andric       DataPtr->String = String->getKey();
371db9f3b2SDimitry Andric       DataPtr->Index = DwarfStringPoolEntry::NotIndexed;
381db9f3b2SDimitry Andric       DataPtr->Offset = 0;
391db9f3b2SDimitry Andric       DataPtr->Symbol = nullptr;
401db9f3b2SDimitry Andric       it = DwarfStringPoolEntries.insert(std::make_pair(String, DataPtr)).first;
411db9f3b2SDimitry Andric     }
421db9f3b2SDimitry Andric 
431db9f3b2SDimitry Andric     assert(it->second != nullptr);
441db9f3b2SDimitry Andric     return it->second;
451db9f3b2SDimitry Andric   }
461db9f3b2SDimitry Andric 
471db9f3b2SDimitry Andric   /// Returns already existed DwarfStringPoolEntry for the specified
481db9f3b2SDimitry Andric   /// StringEntry.
491db9f3b2SDimitry Andric   DwarfStringPoolEntryWithExtString *
getExistingEntry(const StringEntry * String)501db9f3b2SDimitry Andric   getExistingEntry(const StringEntry *String) const {
511db9f3b2SDimitry Andric     DwarfStringPoolEntriesTy::const_iterator it =
521db9f3b2SDimitry Andric         DwarfStringPoolEntries.find(String);
531db9f3b2SDimitry Andric 
541db9f3b2SDimitry Andric     assert(it != DwarfStringPoolEntries.end());
551db9f3b2SDimitry Andric     assert(it->second != nullptr);
561db9f3b2SDimitry Andric     return it->second;
571db9f3b2SDimitry Andric   }
581db9f3b2SDimitry Andric 
591db9f3b2SDimitry Andric   /// Erase contents of StringsForEmission.
clear()601db9f3b2SDimitry Andric   void clear() { DwarfStringPoolEntries.clear(); }
611db9f3b2SDimitry Andric 
621db9f3b2SDimitry Andric protected:
631db9f3b2SDimitry Andric   using DwarfStringPoolEntriesTy =
641db9f3b2SDimitry Andric       DenseMap<const StringEntry *, DwarfStringPoolEntryWithExtString *>;
651db9f3b2SDimitry Andric   DwarfStringPoolEntriesTy DwarfStringPoolEntries;
661db9f3b2SDimitry Andric 
671db9f3b2SDimitry Andric   LinkingGlobalData &GlobalData;
681db9f3b2SDimitry Andric };
691db9f3b2SDimitry Andric 
701db9f3b2SDimitry Andric } // end of namespace parallel
711db9f3b2SDimitry Andric } // end of namespace dwarf_linker
721db9f3b2SDimitry Andric } // end of namespace llvm
731db9f3b2SDimitry Andric 
741db9f3b2SDimitry Andric #endif // LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
75