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_DWARFLINKERPARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
10 #define LLVM_LIB_DWARFLINKERPARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H
12 #include "DWARFLinkerGlobalData.h"
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/DWARFLinkerParallel/StringPool.h"
17 namespace dwarflinker_parallel
{
19 /// This class creates a DwarfStringPoolEntry for the corresponding StringEntry.
20 class StringEntryToDwarfStringPoolEntryMap
{
22 StringEntryToDwarfStringPoolEntryMap(LinkingGlobalData
&GlobalData
)
23 : GlobalData(GlobalData
) {}
24 ~StringEntryToDwarfStringPoolEntryMap() {}
26 /// Create DwarfStringPoolEntry for specified StringEntry if necessary.
27 /// Initialize DwarfStringPoolEntry with initial values.
28 DwarfStringPoolEntryWithExtString
*add(const StringEntry
*String
) {
29 DwarfStringPoolEntriesTy::iterator it
= DwarfStringPoolEntries
.find(String
);
31 if (it
== DwarfStringPoolEntries
.end()) {
32 DwarfStringPoolEntryWithExtString
*DataPtr
=
33 GlobalData
.getAllocator()
34 .Allocate
<DwarfStringPoolEntryWithExtString
>();
35 DataPtr
->String
= GlobalData
.translateString(String
->getKey());
36 DataPtr
->Index
= DwarfStringPoolEntry::NotIndexed
;
38 DataPtr
->Symbol
= nullptr;
39 it
= DwarfStringPoolEntries
.insert(std::make_pair(String
, DataPtr
)).first
;
42 assert(it
->second
!= nullptr);
46 /// Returns already existed DwarfStringPoolEntry for the specified
48 DwarfStringPoolEntryWithExtString
*
49 getExistingEntry(const StringEntry
*String
) const {
50 DwarfStringPoolEntriesTy::const_iterator it
=
51 DwarfStringPoolEntries
.find(String
);
53 assert(it
!= DwarfStringPoolEntries
.end());
54 assert(it
->second
!= nullptr);
58 /// Erase contents of StringsForEmission.
59 void clear() { DwarfStringPoolEntries
.clear(); }
62 using DwarfStringPoolEntriesTy
=
63 DenseMap
<const StringEntry
*, DwarfStringPoolEntryWithExtString
*>;
64 DwarfStringPoolEntriesTy DwarfStringPoolEntries
;
66 LinkingGlobalData
&GlobalData
;
69 } // end of namespace dwarflinker_parallel
70 } // end namespace llvm
72 #endif // LLVM_LIB_DWARFLINKERPARALLEL_STRINGENTRYTODWARFSTRINGPOOLENTRYMAP_H