[AMDGPU][AsmParser][NFC] Translate parsed MIMG instructions to MCInsts automatically.
[llvm-project.git] / llvm / lib / DWARFLinkerParallel / DWARFEmitterImpl.h
blobd07397a304196edf5977ac058f37757ebc8781d2
1 //===- DwarfEmitterImpl.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_DWARFEMITTERIMPL_H
10 #define LLVM_LIB_DWARFLINKERPARALLEL_DWARFEMITTERIMPL_H
12 #include "DWARFLinkerCompileUnit.h"
13 #include "llvm/BinaryFormat/Swift.h"
14 #include "llvm/CodeGen/AccelTable.h"
15 #include "llvm/CodeGen/AsmPrinter.h"
16 #include "llvm/DWARFLinkerParallel/DWARFLinker.h"
17 #include "llvm/DWARFLinkerParallel/StringTable.h"
18 #include "llvm/MC/MCAsmInfo.h"
19 #include "llvm/MC/MCContext.h"
20 #include "llvm/MC/MCInstrInfo.h"
21 #include "llvm/MC/MCObjectFileInfo.h"
22 #include "llvm/MC/MCRegisterInfo.h"
23 #include "llvm/MC/MCStreamer.h"
24 #include "llvm/MC/MCSubtargetInfo.h"
25 #include "llvm/Target/TargetMachine.h"
27 namespace llvm {
29 /// User of DwarfEmitterImpl should call initialization code
30 /// for AsmPrinter:
31 ///
32 /// InitializeAllTargetInfos();
33 /// InitializeAllTargetMCs();
34 /// InitializeAllTargets();
35 /// InitializeAllAsmPrinters();
37 template <typename DataT> class AccelTable;
38 class MCCodeEmitter;
39 class DWARFDebugMacro;
41 namespace dwarflinker_parallel {
43 struct UnitStartSymbol {
44 unsigned UnitID = 0;
45 MCSymbol *Symbol = 0;
47 using UnitStartSymbolsTy = SmallVector<UnitStartSymbol>;
48 using Offset2UnitMapTy = DenseMap<uint64_t, CompileUnit *>;
50 struct RangeAttrPatch;
51 struct LocAttrPatch;
53 /// The Dwarf emission logic.
54 ///
55 /// All interactions with the MC layer that is used to build the debug
56 /// information binary representation are handled in this class.
57 class DwarfEmitterImpl : public ExtraDwarfEmitter {
58 public:
59 DwarfEmitterImpl(DWARFLinker::OutputFileType OutFileType,
60 raw_pwrite_stream &OutFile,
61 std::function<StringRef(StringRef Input)> Translator,
62 DWARFLinker::MessageHandlerTy Warning)
63 : OutFile(OutFile), OutFileType(OutFileType), Translator(Translator),
64 WarningHandler(Warning) {}
66 Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName);
68 /// Dump the file to the disk.
69 void finish() override { MS->finish(); }
71 AsmPrinter &getAsmPrinter() const override { return *Asm; }
73 /// Set the current output section to debug_info and change
74 /// the MC Dwarf version to \p DwarfVersion.
75 void switchToDebugInfoSection(unsigned DwarfVersion) {}
77 /// Emit the swift_ast section stored in \p Buffer.
78 void emitSwiftAST(StringRef Buffer) override {}
80 /// Emit the swift reflection section stored in \p Buffer.
81 void emitSwiftReflectionSection(
82 llvm::binaryformat::Swift5ReflectionSectionKind ReflSectionKind,
83 StringRef Buffer, uint32_t Alignment, uint32_t Size) override {}
85 void emitPaperTrailWarningsDie(DIE &Die) {}
87 void emitSectionContents(StringRef SecData, StringRef SecName) override {}
89 MCSymbol *emitTempSym(StringRef SecName, StringRef SymName) override {
90 return nullptr;
93 void emitAbbrevs(const SmallVector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
94 unsigned DwarfVersion) {}
96 void emitStrings(const StringTable &Strings) {}
98 void emitLineStrings(const StringTable &Strings) {}
100 void emitDebugNames(AccelTable<DWARF5AccelTableStaticData> &,
101 UnitStartSymbolsTy &UnitOffsets) {}
103 void emitAppleNamespaces(AccelTable<AppleAccelTableStaticOffsetData> &) {}
105 void emitAppleNames(AccelTable<AppleAccelTableStaticOffsetData> &) {}
107 void emitAppleObjc(AccelTable<AppleAccelTableStaticOffsetData> &) {}
109 void emitAppleTypes(AccelTable<AppleAccelTableStaticTypeData> &) {}
111 MCSymbol *emitDwarfDebugRangeListHeader(const CompileUnit &Unit) {
112 return nullptr;
115 void emitDwarfDebugRangeListFragment(const CompileUnit &Unit,
116 const AddressRanges &LinkedRanges,
117 RangeAttrPatch &Patch) {}
119 void emitDwarfDebugRangeListFooter(const CompileUnit &Unit,
120 MCSymbol *EndLabel) {}
122 MCSymbol *emitDwarfDebugLocListHeader(const CompileUnit &Unit) {
123 return nullptr;
126 void emitDwarfDebugLocListFragment(
127 const CompileUnit &Unit,
128 const DWARFLocationExpressionsVector &LinkedLocationExpression,
129 LocAttrPatch &Patch) {}
131 void emitDwarfDebugLocListFooter(const CompileUnit &Unit,
132 MCSymbol *EndLabel) {}
134 void emitDwarfDebugArangesTable(const CompileUnit &Unit,
135 const AddressRanges &LinkedRanges) {}
137 void translateLineTable(DataExtractor LineData, uint64_t Offset) {}
139 void emitLineTableForUnit(MCDwarfLineTableParams Params,
140 StringRef PrologueBytes, unsigned MinInstLength,
141 std::vector<DWARFDebugLine::Row> &Rows,
142 unsigned AdddressSize) {}
144 void emitLineTableForUnit(const DWARFDebugLine::LineTable &LineTable,
145 const CompileUnit &Unit, const StringTable &Strings,
146 const StringTable &LineTableStrings) {}
148 void emitPubNamesForUnit(const CompileUnit &Unit) {}
150 void emitPubTypesForUnit(const CompileUnit &Unit) {}
152 void emitCIE(StringRef CIEBytes) {}
154 void emitFDE(uint32_t CIEOffset, uint32_t AddreSize, uint64_t Address,
155 StringRef Bytes) {}
157 void emitCompileUnitHeader(CompileUnit &Unit, unsigned DwarfVersion) {}
159 void emitDIE(DIE &Die) {}
161 void emitMacroTables(DWARFContext *Context,
162 const Offset2UnitMapTy &UnitMacroMap,
163 StringTable &Strings) {}
165 /// Returns size of generated .debug_line section.
166 uint64_t getDebugLineSectionSize() const { return LineSectionSize; }
168 /// Returns size of generated .debug_frame section.
169 uint64_t getDebugFrameSectionSize() const { return FrameSectionSize; }
171 /// Returns size of generated .debug_ranges section.
172 uint64_t getDebugRangesSectionSize() const { return RangesSectionSize; }
174 /// Returns size of generated .debug_rnglists section.
175 uint64_t getDebugRngListsSectionSize() const { return RngListsSectionSize; }
177 /// Returns size of generated .debug_info section.
178 uint64_t getDebugInfoSectionSize() const { return DebugInfoSectionSize; }
180 /// Returns size of generated .debug_macinfo section.
181 uint64_t getDebugMacInfoSectionSize() const { return MacInfoSectionSize; }
183 /// Returns size of generated .debug_macro section.
184 uint64_t getDebugMacroSectionSize() const { return MacroSectionSize; }
186 /// Returns size of generated .debug_loc section.
187 uint64_t getDebugLocSectionSize() const { return LocSectionSize; }
189 /// Returns size of generated .debug_loclists section.
190 uint64_t getDebugLocListsSectionSize() const { return LocListsSectionSize; }
192 private:
193 inline void warn(const Twine &Warning, StringRef Context = "") {
194 if (WarningHandler)
195 WarningHandler(Warning, Context, nullptr);
198 void emitMacroTableImpl(const DWARFDebugMacro *MacroTable,
199 const Offset2UnitMapTy &UnitMacroMap,
200 StringPool &StringPool, uint64_t &OutOffset) {}
202 /// Emit piece of .debug_ranges for \p LinkedRanges.
203 void emitDwarfDebugRangesTableFragment(const CompileUnit &Unit,
204 const AddressRanges &LinkedRanges,
205 RangeAttrPatch &Patch) {}
207 /// Emit piece of .debug_rnglists for \p LinkedRanges.
208 void emitDwarfDebugRngListsTableFragment(const CompileUnit &Unit,
209 const AddressRanges &LinkedRanges,
210 RangeAttrPatch &Patch) {}
212 /// Emit piece of .debug_loc for \p LinkedRanges.
213 void emitDwarfDebugLocTableFragment(
214 const CompileUnit &Unit,
215 const DWARFLocationExpressionsVector &LinkedLocationExpression,
216 LocAttrPatch &Patch) {}
218 /// Emit piece of .debug_loclists for \p LinkedRanges.
219 void emitDwarfDebugLocListsTableFragment(
220 const CompileUnit &Unit,
221 const DWARFLocationExpressionsVector &LinkedLocationExpression,
222 LocAttrPatch &Patch) {}
224 /// \defgroup MCObjects MC layer objects constructed by the streamer
225 /// @{
226 std::unique_ptr<MCRegisterInfo> MRI;
227 std::unique_ptr<MCAsmInfo> MAI;
228 std::unique_ptr<MCObjectFileInfo> MOFI;
229 std::unique_ptr<MCContext> MC;
230 MCAsmBackend *MAB; // Owned by MCStreamer
231 std::unique_ptr<MCInstrInfo> MII;
232 std::unique_ptr<MCSubtargetInfo> MSTI;
233 MCInstPrinter *MIP; // Owned by AsmPrinter
234 MCCodeEmitter *MCE; // Owned by MCStreamer
235 MCStreamer *MS; // Owned by AsmPrinter
236 std::unique_ptr<TargetMachine> TM;
237 std::unique_ptr<AsmPrinter> Asm;
238 /// @}
240 /// The output file we stream the linked Dwarf to.
241 raw_pwrite_stream &OutFile;
242 DWARFLinker::OutputFileType OutFileType = DWARFLinker::OutputFileType::Object;
243 std::function<StringRef(StringRef Input)> Translator;
245 uint64_t RangesSectionSize = 0;
246 uint64_t RngListsSectionSize = 0;
247 uint64_t LocSectionSize = 0;
248 uint64_t LocListsSectionSize = 0;
249 uint64_t LineSectionSize = 0;
250 uint64_t FrameSectionSize = 0;
251 uint64_t DebugInfoSectionSize = 0;
252 uint64_t MacInfoSectionSize = 0;
253 uint64_t MacroSectionSize = 0;
255 /// Keep track of emitted CUs and their Unique ID.
256 struct EmittedUnit {
257 unsigned ID;
258 MCSymbol *LabelBegin;
260 std::vector<EmittedUnit> EmittedUnitsTy;
262 /// Emit the pubnames or pubtypes section contribution for \p
263 /// Unit into \p Sec. The data is provided in \p Names.
264 void emitPubSectionForUnit(MCSection *Sec, StringRef Name,
265 const CompileUnit &Unit,
266 const std::vector<CompileUnit::AccelInfo> &Names);
268 DWARFLinker::MessageHandlerTy WarningHandler = nullptr;
271 } // end namespace dwarflinker_parallel
272 } // end namespace llvm
274 #endif // LLVM_LIB_DWARFLINKERPARALLEL_DWARFEMITTERIMPL_H