1 //===- StringEntryToDwarfStringPoolEntryMap.h -------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
10 #define LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
12 #include "DWARFLinkerGlobalData.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/DWARFLinker/StringPool.h"
17 namespace dwarf_linker
{
20 /// This class creates a DwarfStringPoolEntry for the corresponding StringEntry.
21 class StringEntryToDwarfStringPoolEntryMap
{
23 StringEntryToDwarfStringPoolEntryMap(LinkingGlobalData
&GlobalData
)
24 : GlobalData(GlobalData
) {}
25 ~StringEntryToDwarfStringPoolEntryMap() {}
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
);
32 if (it
== DwarfStringPoolEntries
.end()) {
33 DwarfStringPoolEntryWithExtString
*DataPtr
=
34 GlobalData
.getAllocator()
35 .Allocate
<DwarfStringPoolEntryWithExtString
>();
36 DataPtr
->String
= String
->getKey();
37 DataPtr
->Index
= DwarfStringPoolEntry::NotIndexed
;
39 DataPtr
->Symbol
= nullptr;
40 it
= DwarfStringPoolEntries
.insert(std::make_pair(String
, DataPtr
)).first
;
43 assert(it
->second
!= nullptr);
47 /// Returns already existed DwarfStringPoolEntry for the specified
49 DwarfStringPoolEntryWithExtString
*
50 getExistingEntry(const StringEntry
*String
) const {
51 DwarfStringPoolEntriesTy::const_iterator it
=
52 DwarfStringPoolEntries
.find(String
);
54 assert(it
!= DwarfStringPoolEntries
.end());
55 assert(it
->second
!= nullptr);
59 /// Erase contents of StringsForEmission.
60 void clear() { DwarfStringPoolEntries
.clear(); }
63 using DwarfStringPoolEntriesTy
=
64 DenseMap
<const StringEntry
*, DwarfStringPoolEntryWithExtString
*>;
65 DwarfStringPoolEntriesTy DwarfStringPoolEntries
;
67 LinkingGlobalData
&GlobalData
;
70 } // end of namespace parallel
71 } // end of namespace dwarf_linker
72 } // end of namespace llvm
74 #endif // LLVM_LIB_DWARFLINKER_PARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H