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