1b1c73532SDimitry Andric //===- StringEntryToDwarfStringPoolEntryMap.h -------------------*- C++ -*-===// 2b1c73532SDimitry Andric // 3b1c73532SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4b1c73532SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5b1c73532SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6b1c73532SDimitry Andric // 7b1c73532SDimitry Andric //===----------------------------------------------------------------------===// 8b1c73532SDimitry Andric 9aca2e42cSDimitry Andric #ifndef LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H 10aca2e42cSDimitry Andric #define LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H 11b1c73532SDimitry Andric 12b1c73532SDimitry Andric #include "DWARFLinkerGlobalData.h" 13b1c73532SDimitry Andric #include "llvm/ADT/SmallVector.h" 14aca2e42cSDimitry Andric #include "llvm/DWARFLinker/StringPool.h" 15b1c73532SDimitry Andric 16b1c73532SDimitry Andric namespace llvm { 17aca2e42cSDimitry Andric namespace dwarf_linker { 18aca2e42cSDimitry Andric namespace parallel { 19b1c73532SDimitry Andric 20b1c73532SDimitry Andric /// This class creates a DwarfStringPoolEntry for the corresponding StringEntry. 21b1c73532SDimitry Andric class StringEntryToDwarfStringPoolEntryMap { 22b1c73532SDimitry Andric public: StringEntryToDwarfStringPoolEntryMap(LinkingGlobalData & GlobalData)23b1c73532SDimitry Andric StringEntryToDwarfStringPoolEntryMap(LinkingGlobalData &GlobalData) 24b1c73532SDimitry Andric : GlobalData(GlobalData) {} ~StringEntryToDwarfStringPoolEntryMap()25b1c73532SDimitry Andric ~StringEntryToDwarfStringPoolEntryMap() {} 26b1c73532SDimitry Andric 27b1c73532SDimitry Andric /// Create DwarfStringPoolEntry for specified StringEntry if necessary. 28b1c73532SDimitry Andric /// Initialize DwarfStringPoolEntry with initial values. add(const StringEntry * String)29b1c73532SDimitry Andric DwarfStringPoolEntryWithExtString *add(const StringEntry *String) { 30b1c73532SDimitry Andric DwarfStringPoolEntriesTy::iterator it = DwarfStringPoolEntries.find(String); 31b1c73532SDimitry Andric 32b1c73532SDimitry Andric if (it == DwarfStringPoolEntries.end()) { 33b1c73532SDimitry Andric DwarfStringPoolEntryWithExtString *DataPtr = 34b1c73532SDimitry Andric GlobalData.getAllocator() 35b1c73532SDimitry Andric .Allocate<DwarfStringPoolEntryWithExtString>(); 36ac9a064cSDimitry Andric DataPtr->String = String->getKey(); 37b1c73532SDimitry Andric DataPtr->Index = DwarfStringPoolEntry::NotIndexed; 38b1c73532SDimitry Andric DataPtr->Offset = 0; 39b1c73532SDimitry Andric DataPtr->Symbol = nullptr; 40b1c73532SDimitry Andric it = DwarfStringPoolEntries.insert(std::make_pair(String, DataPtr)).first; 41b1c73532SDimitry Andric } 42b1c73532SDimitry Andric 43b1c73532SDimitry Andric assert(it->second != nullptr); 44b1c73532SDimitry Andric return it->second; 45b1c73532SDimitry Andric } 46b1c73532SDimitry Andric 47b1c73532SDimitry Andric /// Returns already existed DwarfStringPoolEntry for the specified 48b1c73532SDimitry Andric /// StringEntry. 49b1c73532SDimitry Andric DwarfStringPoolEntryWithExtString * getExistingEntry(const StringEntry * String)50b1c73532SDimitry Andric getExistingEntry(const StringEntry *String) const { 51b1c73532SDimitry Andric DwarfStringPoolEntriesTy::const_iterator it = 52b1c73532SDimitry Andric DwarfStringPoolEntries.find(String); 53b1c73532SDimitry Andric 54b1c73532SDimitry Andric assert(it != DwarfStringPoolEntries.end()); 55b1c73532SDimitry Andric assert(it->second != nullptr); 56b1c73532SDimitry Andric return it->second; 57b1c73532SDimitry Andric } 58b1c73532SDimitry Andric 59b1c73532SDimitry Andric /// Erase contents of StringsForEmission. clear()60b1c73532SDimitry Andric void clear() { DwarfStringPoolEntries.clear(); } 61b1c73532SDimitry Andric 62b1c73532SDimitry Andric protected: 63b1c73532SDimitry Andric using DwarfStringPoolEntriesTy = 64b1c73532SDimitry Andric DenseMap<const StringEntry *, DwarfStringPoolEntryWithExtString *>; 65b1c73532SDimitry Andric DwarfStringPoolEntriesTy DwarfStringPoolEntries; 66b1c73532SDimitry Andric 67b1c73532SDimitry Andric LinkingGlobalData &GlobalData; 68b1c73532SDimitry Andric }; 69b1c73532SDimitry Andric 70aca2e42cSDimitry Andric } // end of namespace parallel 71aca2e42cSDimitry Andric } // end of namespace dwarf_linker 72aca2e42cSDimitry Andric } // end of namespace llvm 73b1c73532SDimitry Andric 74aca2e42cSDimitry Andric #endif // LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H 75