LLVM 20.0.0git
DWARFEmitterImpl.h
Go to the documentation of this file.
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//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_DWARFEMITTERIMPL_H
10#define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFEMITTERIMPL_H
11
17#include "llvm/MC/MCAsmInfo.h"
18#include "llvm/MC/MCContext.h"
19#include "llvm/MC/MCInstrInfo.h"
22#include "llvm/MC/MCStreamer.h"
25
26namespace llvm {
27
28/// User of DwarfEmitterImpl should call initialization code
29/// for AsmPrinter:
30///
31/// InitializeAllTargetInfos();
32/// InitializeAllTargetMCs();
33/// InitializeAllTargets();
34/// InitializeAllAsmPrinters();
35
36template <typename DataT> class AccelTable;
37class MCCodeEmitter;
38
39namespace dwarf_linker {
40namespace parallel {
41
42using DebugNamesUnitsOffsets = std::vector<std::variant<MCSymbol *, uint64_t>>;
44
45/// This class emits DWARF data to the output stream. It emits already
46/// generated section data and specific data, which could not be generated
47/// by CompileUnit.
49public:
51 raw_pwrite_stream &OutFile)
52 : OutFile(OutFile), OutFileType(OutFileType) {}
53
54 /// Initialize AsmPrinter data.
55 Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName);
56
57 /// Returns triple of output stream.
58 const Triple &getTargetTriple() { return MC->getTargetTriple(); }
59
60 /// Dump the file to the disk.
61 void finish() { MS->finish(); }
62
63 /// Emit abbreviations.
64 void emitAbbrevs(const SmallVector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
65 unsigned DwarfVersion);
66
67 /// Emit compile unit header.
69
70 /// Emit DIE recursively.
71 void emitDIE(DIE &Die);
72
73 /// Returns size of generated .debug_info section.
74 uint64_t getDebugInfoSectionSize() const { return DebugInfoSectionSize; }
75
76 /// Emits .debug_names section according to the specified \p Table.
78 DebugNamesUnitsOffsets &CUOffsets,
79 CompUnitIDToIdx &UnitIDToIdxMap);
80
81 /// Emits .apple_names section according to the specified \p Table.
83
84 /// Emits .apple_namespaces section according to the specified \p Table.
86
87 /// Emits .apple_objc section according to the specified \p Table.
89
90 /// Emits .apple_types section according to the specified \p Table.
92
93private:
94 // Enumerate all string patches and write them into the destination section.
95 // Order of patches is the same as in original input file. To avoid emitting
96 // the same string twice we accumulate NextOffset value. Thus if string
97 // offset smaller than NextOffset value then the patch is skipped (as that
98 // string was emitted earlier).
99 template <typename PatchTy>
100 void emitStringsImpl(ArrayList<PatchTy> &StringPatches,
102 uint64_t &NextOffset, MCSection *OutSection);
103
104 /// \defgroup MCObjects MC layer objects constructed by the streamer
105 /// @{
106 std::unique_ptr<MCRegisterInfo> MRI;
107 std::unique_ptr<MCAsmInfo> MAI;
108 std::unique_ptr<MCObjectFileInfo> MOFI;
109 std::unique_ptr<MCContext> MC;
110 MCAsmBackend *MAB; // Owned by MCStreamer
111 std::unique_ptr<MCInstrInfo> MII;
112 std::unique_ptr<MCSubtargetInfo> MSTI;
113 MCInstPrinter *MIP; // Owned by AsmPrinter
114 MCCodeEmitter *MCE; // Owned by MCStreamer
115 MCStreamer *MS; // Owned by AsmPrinter
116 std::unique_ptr<TargetMachine> TM;
117 std::unique_ptr<AsmPrinter> Asm;
118 /// @}
119
120 /// The output file we stream the linked Dwarf to.
121 raw_pwrite_stream &OutFile;
124
125 uint64_t DebugInfoSectionSize = 0;
126};
127
128} // end of namespace parallel
129} // end of namespace dwarf_linker
130} // end of namespace llvm
131
132#endif // LLVM_LIB_DWARFLINKER_PARALLEL_DWARFEMITTERIMPL_H
This file contains support for writing accelerator tables.
This class holds an abstract representation of an Accelerator Table, consisting of a sequence of buck...
Definition: AccelTable.h:202
A structured debug information entry.
Definition: DIE.h:819
Lightweight error class with error context and mandatory checking.
Definition: Error.h:160
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:42
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:21
This is an instance of a target assembly language printer that converts an MCInst to valid target ass...
Definition: MCInstPrinter.h:46
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:36
Streaming machine code generation interface.
Definition: MCStreamer.h:213
void finish(SMLoc EndLoc=SMLoc())
Finish emission of machine code.
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1196
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:51
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:44
This class is a simple list of T structures.
Definition: ArrayList.h:23
This class emits DWARF data to the output stream.
const Triple & getTargetTriple()
Returns triple of output stream.
void emitCompileUnitHeader(DwarfUnit &Unit)
Emit compile unit header.
Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName)
Initialize AsmPrinter data.
void emitAppleNames(AccelTable< AppleAccelTableStaticOffsetData > &Table)
Emits .apple_names section according to the specified Table.
uint64_t getDebugInfoSectionSize() const
Returns size of generated .debug_info section.
void emitAbbrevs(const SmallVector< std::unique_ptr< DIEAbbrev > > &Abbrevs, unsigned DwarfVersion)
Emit abbreviations.
DwarfEmitterImpl(DWARFLinker::OutputFileType OutFileType, raw_pwrite_stream &OutFile)
void emitAppleTypes(AccelTable< AppleAccelTableStaticTypeData > &Table)
Emits .apple_types section according to the specified Table.
void emitDIE(DIE &Die)
Emit DIE recursively.
void emitAppleNamespaces(AccelTable< AppleAccelTableStaticOffsetData > &Table)
Emits .apple_namespaces section according to the specified Table.
void emitDebugNames(DWARF5AccelTable &Table, DebugNamesUnitsOffsets &CUOffsets, CompUnitIDToIdx &UnitIDToIdxMap)
Emits .debug_names section according to the specified Table.
void emitAppleObjc(AccelTable< AppleAccelTableStaticOffsetData > &Table)
Emits .apple_objc section according to the specified Table.
void finish()
Dump the file to the disk.
Base class for all Dwarf units(Compile unit/Type table unit).
This class creates a DwarfStringPoolEntry for the corresponding StringEntry.
An abstract base class for streams implementations that also support a pwrite operation.
Definition: raw_ostream.h:434
std::vector< std::variant< MCSymbol *, uint64_t > > DebugNamesUnitsOffsets
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18