LLVM 22.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"
20#include "llvm/MC/MCInstrInfo.h"
23#include "llvm/MC/MCStreamer.h"
26
27namespace llvm {
28
29/// User of DwarfEmitterImpl should call initialization code
30/// for AsmPrinter:
31///
32/// InitializeAllTargetInfos();
33/// InitializeAllTargetMCs();
34/// InitializeAllTargets();
35/// InitializeAllAsmPrinters();
36
37template <typename DataT> class AccelTable;
38class MCCodeEmitter;
39
40namespace dwarf_linker {
41namespace parallel {
42
43using DebugNamesUnitsOffsets = std::vector<std::variant<MCSymbol *, uint64_t>>;
45
46/// This class emits DWARF data to the output stream. It emits already
47/// generated section data and specific data, which could not be generated
48/// by CompileUnit.
50public:
52 raw_pwrite_stream &OutFile)
53 : OutFile(OutFile), OutFileType(OutFileType) {}
54
55 /// Initialize AsmPrinter data.
56 Error init(Triple TheTriple, StringRef Swift5ReflectionSegmentName);
57
58 /// Returns triple of output stream.
59 const Triple &getTargetTriple() { return MC->getTargetTriple(); }
60
61 /// Dump the file to the disk.
62 void finish() { MS->finish(); }
63
64 /// Emit abbreviations.
65 void emitAbbrevs(const SmallVector<std::unique_ptr<DIEAbbrev>> &Abbrevs,
66 unsigned DwarfVersion);
67
68 /// Emit compile unit header.
70
71 /// Emit DIE recursively.
72 void emitDIE(DIE &Die);
73
74 /// Returns size of generated .debug_info section.
75 uint64_t getDebugInfoSectionSize() const { return DebugInfoSectionSize; }
76
77 /// Emits .debug_names section according to the specified \p Table.
79 DebugNamesUnitsOffsets &CUOffsets,
80 CompUnitIDToIdx &UnitIDToIdxMap);
81
82 /// Emits .apple_names section according to the specified \p Table.
84
85 /// Emits .apple_namespaces section according to the specified \p Table.
87
88 /// Emits .apple_objc section according to the specified \p Table.
90
91 /// Emits .apple_types section according to the specified \p Table.
93
94private:
95 // Enumerate all string patches and write them into the destination section.
96 // Order of patches is the same as in original input file. To avoid emitting
97 // the same string twice we accumulate NextOffset value. Thus if string
98 // offset smaller than NextOffset value then the patch is skipped (as that
99 // string was emitted earlier).
100 template <typename PatchTy>
101 void emitStringsImpl(ArrayList<PatchTy> &StringPatches,
103 uint64_t &NextOffset, MCSection *OutSection);
104
105 /// \defgroup MCObjects MC layer objects constructed by the streamer
106 /// @{
107 std::unique_ptr<MCRegisterInfo> MRI;
108 std::unique_ptr<MCAsmInfo> MAI;
109 std::unique_ptr<MCObjectFileInfo> MOFI;
110 std::unique_ptr<MCContext> MC;
111 MCAsmBackend *MAB; // Owned by MCStreamer
112 std::unique_ptr<MCInstrInfo> MII;
113 std::unique_ptr<MCSubtargetInfo> MSTI;
114 std::unique_ptr<MCInstPrinter> MIP; // Owned by AsmPrinter
115 MCCodeEmitter *MCE; // Owned by MCStreamer
116 MCStreamer *MS; // Owned by AsmPrinter
117 std::unique_ptr<TargetMachine> TM;
118 std::unique_ptr<AsmPrinter> Asm;
119 /// @}
120
121 /// The output file we stream the linked Dwarf to.
122 raw_pwrite_stream &OutFile;
125
126 uint64_t DebugInfoSectionSize = 0;
127};
128
129} // end of namespace parallel
130} // end of namespace dwarf_linker
131} // end of namespace llvm
132
133#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:203
A structured debug information entry.
Definition: DIE.h:828
Lightweight error class with error context and mandatory checking.
Definition: Error.h:159
Generic interface to target specific assembler backends.
Definition: MCAsmBackend.h:55
MCCodeEmitter - Generic instruction encoding interface.
Definition: MCCodeEmitter.h:23
Instances of this class represent a uniqued identifier for a section in the current translation unit.
Definition: MCSection.h:496
Streaming machine code generation interface.
Definition: MCStreamer.h:220
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:1197
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Triple - Helper class for working with autoconf configuration names.
Definition: Triple.h:47
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:435
std::vector< std::variant< MCSymbol *, uint64_t > > DebugNamesUnitsOffsets
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18