1//===- AcceleratorRecordsSaver.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_ACCELERATORRECORDSSAVER_H
10#define LLVM_LIB_DWARFLINKER_PARALLEL_ACCELERATORRECORDSSAVER_H
11
12#include "DIEAttributeCloner.h"
13#include "DWARFLinkerCompileUnit.h"
14#include "DWARFLinkerGlobalData.h"
15#include "DWARFLinkerTypeUnit.h"
16
17namespace llvm {
18namespace dwarf_linker {
19namespace parallel {
20
21/// This class helps to store information for accelerator entries.
22/// It prepares accelerator info for the certain DIE and store it inside
23/// OutUnit.
24class AcceleratorRecordsSaver {
25public:
26 AcceleratorRecordsSaver(LinkingGlobalData &GlobalData, CompileUnit &InUnit,
27 CompileUnit *OutUnit)
28 : AcceleratorRecordsSaver(GlobalData, InUnit,
29 CompileUnit::OutputUnitVariantPtr(OutUnit)) {}
30
31 AcceleratorRecordsSaver(LinkingGlobalData &GlobalData, CompileUnit &InUnit,
32 TypeUnit *OutUnit)
33 : AcceleratorRecordsSaver(GlobalData, InUnit,
34 CompileUnit::OutputUnitVariantPtr(OutUnit)) {}
35
36 /// Save accelerator info for the specified \p OutDIE inside OutUnit.
37 /// Side effects: set attributes in \p AttrInfo.
38 void save(const DWARFDebugInfoEntry *InputDieEntry, DIE *OutDIE,
39 AttributesInfo &AttrInfo, TypeEntry *TypeEntry);
40
41protected:
42 AcceleratorRecordsSaver(LinkingGlobalData &GlobalData, CompileUnit &InUnit,
43 CompileUnit::OutputUnitVariantPtr OutUnit)
44 : GlobalData(GlobalData), InUnit(InUnit), OutUnit(OutUnit) {}
45
46 void saveObjC(const DWARFDebugInfoEntry *InputDieEntry, DIE *OutDIE,
47 AttributesInfo &AttrInfo, TypeEntry *TypeEntry);
48
49 void saveNameRecord(const DWARFDebugInfoEntry *InputDieEntry,
50 StringEntry *Name, DIE *OutDIE, dwarf::Tag Tag,
51 bool AvoidForPubSections, TypeEntry *TypeEntry);
52 void saveNamespaceRecord(const DWARFDebugInfoEntry *InputDieEntry,
53 StringEntry *Name, DIE *OutDIE, dwarf::Tag Tag,
54 TypeEntry *TypeEntry);
55 void saveObjCNameRecord(const DWARFDebugInfoEntry *InputDieEntry,
56 StringEntry *Name, DIE *OutDIE, dwarf::Tag Tag,
57 TypeEntry *TypeEntry);
58 void saveTypeRecord(const DWARFDebugInfoEntry *InputDieEntry,
59 StringEntry *Name, DIE *OutDIE, dwarf::Tag Tag,
60 uint32_t QualifiedNameHash, bool ObjcClassImplementation,
61 TypeEntry *TypeEntry);
62
63 /// Return the output offset of \p InputDieEntry's immediate
64 /// non-declaration parent, for use as the DW_IDX_parent field of a name
65 /// index entry. Matches classic's one-level lookup: does not walk past a
66 /// pruned or declaration parent to find a surviving ancestor. Returns
67 /// std::nullopt if there is no usable parent.
68 std::optional<uint64_t>
69 getDefiningParentOutOffset(const DWARFDebugInfoEntry *InputDieEntry);
70
71 /// Global linking data.
72 LinkingGlobalData &GlobalData;
73
74 /// Comiple unit corresponding to input DWARF.
75 CompileUnit &InUnit;
76
77 /// Compile unit or Artificial type unit corresponding to the output DWARF.
78 CompileUnit::OutputUnitVariantPtr OutUnit;
79};
80
81} // end of namespace parallel
82} // end of namespace dwarf_linker
83} // end of namespace llvm
84
85#endif // LLVM_LIB_DWARFLINKER_PARALLEL_ACCELERATORRECORDSSAVER_H
86