Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / lib / DWARFLinkerParallel / StringEntryToDwarfStringPoolEntryMap.h
blobb4c74d0adba9709b5969c2e6a5b2d80f29c67bcc
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 //===----------------------------------------------------------------------===//
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"
16 namespace llvm {
17 namespace dwarflinker_parallel {
19 /// This class creates a DwarfStringPoolEntry for the corresponding StringEntry.
20 class StringEntryToDwarfStringPoolEntryMap {
21 public:
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;
37 DataPtr->Offset = 0;
38 DataPtr->Symbol = nullptr;
39 it = DwarfStringPoolEntries.insert(std::make_pair(String, DataPtr)).first;
42 assert(it->second != nullptr);
43 return it->second;
46 /// Returns already existed DwarfStringPoolEntry for the specified
47 /// StringEntry.
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);
55 return it->second;
58 /// Erase contents of StringsForEmission.
59 void clear() { DwarfStringPoolEntries.clear(); }
61 protected:
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