LLVM 22.0.0git
DWARFLinkerCompileUnit.h
Go to the documentation of this file.
1//===- DWARFLinkerCompileUnit.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_DWARFLINKERCOMPILEUNIT_H
10#define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERCOMPILEUNIT_H
11
12#include "DWARFLinkerUnit.h"
14#include <optional>
15
16namespace llvm {
17namespace dwarf_linker {
18namespace parallel {
19
21
22struct AttributesInfo;
24class DIEGenerator;
25class TypeUnit;
27
28class CompileUnit;
29
30/// This is a helper structure which keeps a debug info entry
31/// with it's containing compilation unit.
33 UnitEntryPairTy() = default;
36
37 CompileUnit *CU = nullptr;
38 const DWARFDebugInfoEntry *DieEntry = nullptr;
39
41 std::optional<UnitEntryPairTy> getParent();
42};
43
45 Resolve = true,
47};
48
49/// Stores all information related to a compile unit, be it in its original
50/// instance of the object file or its brand new cloned and generated DIE tree.
51/// NOTE: we need alignment of at least 8 bytes as we use
52/// PointerIntPair<CompileUnit *, 3> in the DependencyTracker.h
53class alignas(8) CompileUnit : public DwarfUnit {
54public:
55 /// The stages of new compile unit processing.
56 enum class Stage : uint8_t {
57 /// Created, linked with input DWARF file.
59
60 /// Input DWARF is loaded.
62
63 /// Input DWARF is analysed(DIEs pointing to the real code section are
64 /// discovered, type names are assigned if ODR is requested).
66
67 /// Check if dependencies have incompatible placement.
68 /// If that is the case modify placement to be compatible.
70
71 /// Type names assigned to DIEs.
73
74 /// Output DWARF is generated.
76
77 /// Offsets inside patch records are updated.
79
80 /// Resources(Input DWARF, Output DWARF tree) are released.
82
83 /// Compile Unit should be skipped
85 };
86
90 llvm::endianness Endianess);
91
95 llvm::endianness Endianess);
96
97 /// Returns stage of overall processing.
98 Stage getStage() const { return Stage; }
99
100 /// Set stage of overall processing.
101 void setStage(Stage Stage) { this->Stage = Stage; }
102
103 /// Loads unit line table.
104 void loadLineTable();
105
106 /// Returns name of the file for the \p FileIdx
107 /// from the unit`s line table.
108 StringEntry *getFileName(unsigned FileIdx, StringPool &GlobalStrings);
109
110 /// Returns DWARFFile containing this compile unit.
111 const DWARFFile &getContaingFile() const { return File; }
112
113 /// Load DIEs of input compilation unit. \returns true if input DIEs
114 /// successfully loaded.
115 bool loadInputDIEs();
116
117 /// Reset compile units data(results of liveness analysis, clonning)
118 /// if current stage greater than Stage::Loaded. We need to reset data
119 /// as we are going to repeat stages.
121
122 /// Collect references to parseable Swift interfaces in imported
123 /// DW_TAG_module blocks.
124 void analyzeImportedModule(const DWARFDebugInfoEntry *DieEntry);
125
126 /// Navigate DWARF tree and set die properties.
128 analyzeDWARFStructureRec(getUnitDIE().getDebugInfoEntry(), false);
129 }
130
131 /// Cleanup unneeded resources after compile unit is cloned.
133
134 /// After cloning stage the output DIEs offsets are deallocated.
135 /// This method copies output offsets for referenced DIEs into DIEs patches.
137
138 /// Search for subprograms and variables referencing live code and discover
139 /// dependend DIEs. Mark live DIEs, set placement for DIEs.
141 bool InterCUProcessingStarted,
142 std::atomic<bool> &HasNewInterconnectedCUs);
143
144 /// Check dependend DIEs for incompatible placement.
145 /// Make placement to be consistent.
147
148 /// Check DIEs to have a consistent marking(keep marking, placement marking).
149 void verifyDependencies();
150
151 /// Search for type entries and assign names.
152 Error assignTypeNames(TypePool &TypePoolRef);
153
154 /// Kinds of placement for the output die.
157
158 /// Corresponding DIE goes to the type table only.
160
161 /// Corresponding DIE goes to the plain dwarf only.
163
164 /// Corresponding DIE goes to type table and to plain dwarf.
165 Both = 3,
166 };
167
168 /// Information gathered about source DIEs.
169 struct DIEInfo {
170 DIEInfo() = default;
171 DIEInfo(const DIEInfo &Other) { Flags = Other.Flags.load(); }
173 Flags = Other.Flags.load();
174 return *this;
175 }
176
177 /// Data member keeping various flags.
178 std::atomic<uint16_t> Flags = {0};
179
180 /// \returns Placement kind for the corresponding die.
182 return DieOutputPlacement(Flags & 0x7);
183 }
184
185 /// Sets Placement kind for the corresponding die.
187 auto InputData = Flags.load();
188 while (!Flags.compare_exchange_weak(InputData,
189 ((InputData & ~0x7) | Placement))) {
190 }
191 }
192
193 /// Unsets Placement kind for the corresponding die.
195 auto InputData = Flags.load();
196 while (!Flags.compare_exchange_weak(InputData, (InputData & ~0x7))) {
197 }
198 }
199
200 /// Sets Placement kind for the corresponding die.
202 auto InputData = Flags.load();
203 if ((InputData & 0x7) == NotSet)
204 if (Flags.compare_exchange_strong(InputData, (InputData | Placement)))
205 return true;
206
207 return false;
208 }
209
210#define SINGLE_FLAG_METHODS_SET(Name, Value) \
211 bool get##Name() const { return Flags & Value; } \
212 void set##Name() { \
213 auto InputData = Flags.load(); \
214 while (!Flags.compare_exchange_weak(InputData, InputData | Value)) { \
215 } \
216 } \
217 void unset##Name() { \
218 auto InputData = Flags.load(); \
219 while (!Flags.compare_exchange_weak(InputData, InputData & ~Value)) { \
220 } \
221 }
222
223 /// DIE is a part of the linked output.
225
226 /// DIE has children which are part of the linked output.
227 SINGLE_FLAG_METHODS_SET(KeepPlainChildren, 0x10)
228
229 /// DIE has children which are part of the type table.
230 SINGLE_FLAG_METHODS_SET(KeepTypeChildren, 0x20)
231
232 /// DIE is in module scope.
233 SINGLE_FLAG_METHODS_SET(IsInMouduleScope, 0x40)
234
235 /// DIE is in function scope.
236 SINGLE_FLAG_METHODS_SET(IsInFunctionScope, 0x80)
237
238 /// DIE is in anonymous namespace scope.
239 SINGLE_FLAG_METHODS_SET(IsInAnonNamespaceScope, 0x100)
240
241 /// DIE is available for ODR type deduplication.
242 SINGLE_FLAG_METHODS_SET(ODRAvailable, 0x200)
243
244 /// Track liveness for the DIE.
245 SINGLE_FLAG_METHODS_SET(TrackLiveness, 0x400)
246
247 /// Track liveness for the DIE.
248 SINGLE_FLAG_METHODS_SET(HasAnAddress, 0x800)
249
251 auto InputData = Flags.load();
252 while (!Flags.compare_exchange_weak(
253 InputData, InputData & ~(0x7 | 0x8 | 0x10 | 0x20))) {
254 }
255 }
256
257 /// Erase all flags.
258 void eraseData() { Flags = 0; }
259
260#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
261 LLVM_DUMP_METHOD void dump();
262#endif
263
265 return (getKeep() && (getPlacement() == CompileUnit::TypeTable ||
267 getKeepTypeChildren();
268 }
269
271 return (getKeep() && (getPlacement() == CompileUnit::PlainDwarf ||
273 getKeepPlainChildren();
274 }
275 };
276
277 /// \defgroup Group of functions returning DIE info.
278 ///
279 /// @{
280
281 /// \p Idx index of the DIE.
282 /// \returns DieInfo descriptor.
283 DIEInfo &getDIEInfo(unsigned Idx) { return DieInfoArray[Idx]; }
284
285 /// \p Idx index of the DIE.
286 /// \returns DieInfo descriptor.
287 const DIEInfo &getDIEInfo(unsigned Idx) const { return DieInfoArray[Idx]; }
288
289 /// \p Idx index of the DIE.
290 /// \returns DieInfo descriptor.
292 return DieInfoArray[getOrigUnit().getDIEIndex(Entry)];
293 }
294
295 /// \p Idx index of the DIE.
296 /// \returns DieInfo descriptor.
297 const DIEInfo &getDIEInfo(const DWARFDebugInfoEntry *Entry) const {
298 return DieInfoArray[getOrigUnit().getDIEIndex(Entry)];
299 }
300
301 /// \p Die
302 /// \returns PlainDieInfo descriptor.
304 return DieInfoArray[getOrigUnit().getDIEIndex(Die)];
305 }
306
307 /// \p Die
308 /// \returns PlainDieInfo descriptor.
309 const DIEInfo &getDIEInfo(const DWARFDie &Die) const {
310 return DieInfoArray[getOrigUnit().getDIEIndex(Die)];
311 }
312
313 /// \p Idx index of the DIE.
314 /// \returns DieInfo descriptor.
316 return reinterpret_cast<std::atomic<uint64_t> *>(&OutDieOffsetArray[Idx])
317 ->load();
318 }
319
320 /// \p Idx index of the DIE.
321 /// \returns type entry.
323 return reinterpret_cast<std::atomic<TypeEntry *> *>(&TypeEntries[Idx])
324 ->load();
325 }
326
327 /// \p InputDieEntry debug info entry.
328 /// \returns DieInfo descriptor.
330 return reinterpret_cast<std::atomic<uint64_t> *>(
331 &OutDieOffsetArray[getOrigUnit().getDIEIndex(InputDieEntry)])
332 ->load();
333 }
334
335 /// \p InputDieEntry debug info entry.
336 /// \returns type entry.
338 return reinterpret_cast<std::atomic<TypeEntry *> *>(
339 &TypeEntries[getOrigUnit().getDIEIndex(InputDieEntry)])
340 ->load();
341 }
342
343 /// \p Idx index of the DIE.
344 /// \returns DieInfo descriptor.
346 reinterpret_cast<std::atomic<uint64_t> *>(&OutDieOffsetArray[Idx])
347 ->store(Offset);
348 }
349
350 /// \p Idx index of the DIE.
351 /// \p Type entry.
353 reinterpret_cast<std::atomic<TypeEntry *> *>(&TypeEntries[Idx])
354 ->store(Entry);
355 }
356
357 /// \p InputDieEntry debug info entry.
358 /// \p Type entry.
359 void setDieTypeEntry(const DWARFDebugInfoEntry *InputDieEntry,
360 TypeEntry *Entry) {
361 reinterpret_cast<std::atomic<TypeEntry *> *>(
362 &TypeEntries[getOrigUnit().getDIEIndex(InputDieEntry)])
363 ->store(Entry);
364 }
365
366 /// @}
367
368 /// Returns value of DW_AT_low_pc attribute.
369 std::optional<uint64_t> getLowPc() const { return LowPc; }
370
371 /// Returns value of DW_AT_high_pc attribute.
372 uint64_t getHighPc() const { return HighPc; }
373
374 /// Returns true if there is a label corresponding to the specified \p Addr.
375 bool hasLabelAt(uint64_t Addr) const { return Labels.count(Addr); }
376
377 /// Add the low_pc of a label that is relocated by applying
378 /// offset \p PCOffset.
379 void addLabelLowPc(uint64_t LabelLowPc, int64_t PcOffset);
380
381 /// Resolve the DIE attribute reference that has been extracted in \p
382 /// RefValue. The resulting DIE might be in another CompileUnit.
383 /// \returns referenced die and corresponding compilation unit.
384 /// compilation unit is null if reference could not be resolved.
385 std::optional<UnitEntryPairTy>
386 resolveDIEReference(const DWARFFormValue &RefValue,
387 ResolveInterCUReferencesMode CanResolveInterCUReferences);
388
389 std::optional<UnitEntryPairTy>
391 dwarf::Attribute Attr,
392 ResolveInterCUReferencesMode CanResolveInterCUReferences);
393
394 /// @}
395
396 /// Add a function range [\p LowPC, \p HighPC) that is relocated by applying
397 /// offset \p PCOffset.
398 void addFunctionRange(uint64_t LowPC, uint64_t HighPC, int64_t PCOffset);
399
400 /// Returns function ranges of this unit.
401 const RangesTy &getFunctionRanges() const { return Ranges; }
402
403 /// Clone and emit this compilation unit.
404 Error
405 cloneAndEmit(std::optional<std::reference_wrapper<const Triple>> TargetTriple,
406 TypeUnit *ArtificialTypeUnit);
407
408 /// Clone and emit debug locations(.debug_loc/.debug_loclists).
410
411 /// Clone and emit ranges.
413
414 /// Clone and emit debug macros(.debug_macinfo/.debug_macro).
416
417 // Clone input DIE entry.
418 std::pair<DIE *, TypeEntry *>
419 cloneDIE(const DWARFDebugInfoEntry *InputDieEntry,
420 TypeEntry *ClonedParentTypeDIE, uint64_t OutOffset,
421 std::optional<int64_t> FuncAddressAdjustment,
422 std::optional<int64_t> VarAddressAdjustment,
423 BumpPtrAllocator &Allocator, TypeUnit *ArtificialTypeUnit);
424
425 // Clone and emit line table.
426 Error cloneAndEmitLineTable(const Triple &TargetTriple);
427
428 /// Clone attribute location axpression.
429 void cloneDieAttrExpression(const DWARFExpression &InputExpression,
430 SmallVectorImpl<uint8_t> &OutputExpression,
431 SectionDescriptor &Section,
432 std::optional<int64_t> VarAddressAdjustment,
433 OffsetsPtrVector &PatchesOffsets);
434
435 /// Returns index(inside .debug_addr) of an address.
437 return DebugAddrIndexMap.getValueIndex(Addr);
438 }
439
440 /// Returns directory and file from the line table by index.
441 std::optional<std::pair<StringRef, StringRef>>
443
444 /// Returns directory and file from the line table by index.
445 std::optional<std::pair<StringRef, StringRef>>
447
448 /// \defgroup Helper methods to access OrigUnit.
449 ///
450 /// @{
451
452 /// Returns paired compile unit from input DWARF.
454 assert(OrigUnit != nullptr);
455 return *OrigUnit;
456 }
457
458 const DWARFDebugInfoEntry *
460 assert(OrigUnit != nullptr);
461 return OrigUnit->getFirstChildEntry(Die);
462 }
463
464 const DWARFDebugInfoEntry *
466 assert(OrigUnit != nullptr);
467 return OrigUnit->getSiblingEntry(Die);
468 }
469
471 assert(OrigUnit != nullptr);
472 return OrigUnit->getParent(Die);
473 }
474
475 DWARFDie getDIEAtIndex(unsigned Index) {
476 assert(OrigUnit != nullptr);
477 return OrigUnit->getDIEAtIndex(Index);
478 }
479
480 const DWARFDebugInfoEntry *getDebugInfoEntry(unsigned Index) const {
481 assert(OrigUnit != nullptr);
482 return OrigUnit->getDebugInfoEntry(Index);
483 }
484
485 DWARFDie getUnitDIE(bool ExtractUnitDIEOnly = true) {
486 assert(OrigUnit != nullptr);
487 return OrigUnit->getUnitDIE(ExtractUnitDIEOnly);
488 }
489
491 assert(OrigUnit != nullptr);
492 return DWARFDie(OrigUnit, Die);
493 }
494
496 assert(OrigUnit != nullptr);
497 return OrigUnit->getDIEIndex(Die);
498 }
499
500 uint32_t getDIEIndex(const DWARFDie &Die) const {
501 assert(OrigUnit != nullptr);
502 return OrigUnit->getDIEIndex(Die);
503 }
504
505 std::optional<DWARFFormValue> find(uint32_t DieIdx,
506 ArrayRef<dwarf::Attribute> Attrs) const {
507 assert(OrigUnit != nullptr);
508 return find(OrigUnit->getDebugInfoEntry(DieIdx), Attrs);
509 }
510
511 std::optional<DWARFFormValue> find(const DWARFDebugInfoEntry *Die,
512 ArrayRef<dwarf::Attribute> Attrs) const {
513 if (!Die)
514 return std::nullopt;
515 auto AbbrevDecl = Die->getAbbreviationDeclarationPtr();
516 if (AbbrevDecl) {
517 for (auto Attr : Attrs) {
518 if (auto Value = AbbrevDecl->getAttributeValue(Die->getOffset(), Attr,
519 *OrigUnit))
520 return Value;
521 }
522 }
523 return std::nullopt;
524 }
525
526 std::optional<uint32_t> getDIEIndexForOffset(uint64_t Offset) {
527 return OrigUnit->getDIEIndexForOffset(Offset);
528 }
529
530 /// @}
531
532 /// \defgroup Methods used for reporting warnings and errors:
533 ///
534 /// @{
535
536 void warn(const Twine &Warning, const DWARFDie *DIE = nullptr) {
538 }
539
540 void warn(Error Warning, const DWARFDie *DIE = nullptr) {
541 handleAllErrors(std::move(Warning), [&](ErrorInfoBase &Info) {
542 GlobalData.warn(Info.message(), getUnitName(), DIE);
543 });
544 }
545
546 void warn(const Twine &Warning, const DWARFDebugInfoEntry *DieEntry) {
547 if (DieEntry != nullptr) {
548 DWARFDie DIE(&getOrigUnit(), DieEntry);
550 return;
551 }
552
554 }
555
556 void error(const Twine &Err, const DWARFDie *DIE = nullptr) {
557 GlobalData.warn(Err, getUnitName(), DIE);
558 }
559
560 void error(Error Err, const DWARFDie *DIE = nullptr) {
561 handleAllErrors(std::move(Err), [&](ErrorInfoBase &Info) {
562 GlobalData.error(Info.message(), getUnitName(), DIE);
563 });
564 }
565
566 /// @}
567
568 /// Save specified accelerator info \p Info.
570 AcceleratorRecords.add(Info);
571 }
572
573 /// Enumerates all units accelerator records.
574 void
576 AcceleratorRecords.forEach(Handler);
577 }
578
579 /// Output unit selector.
581 public:
584
585 /// Accessor for common functionality.
587
588 bool isCompileUnit();
589
590 bool isTypeUnit();
591
592 /// Returns CompileUnit if applicable.
594
595 /// Returns TypeUnit if applicable.
597
598 protected:
600 };
601
602private:
603 /// Navigate DWARF tree recursively and set die properties.
604 void analyzeDWARFStructureRec(const DWARFDebugInfoEntry *DieEntry,
605 bool IsODRUnavailableFunctionScope);
606
607 struct LinkedLocationExpressionsWithOffsetPatches {
609 OffsetsPtrVector Patches;
610 };
611 using LinkedLocationExpressionsVector =
613
614 /// Emit debug locations.
615 void emitLocations(DebugSectionKind LocationSectionKind);
616
617 /// Emit location list header.
618 uint64_t emitLocListHeader(SectionDescriptor &OutLocationSection);
619
620 /// Emit location list fragment.
621 uint64_t emitLocListFragment(
622 const LinkedLocationExpressionsVector &LinkedLocationExpression,
623 SectionDescriptor &OutLocationSection);
624
625 /// Emit the .debug_addr section fragment for current unit.
626 Error emitDebugAddrSection();
627
628 /// Emit .debug_aranges.
629 void emitAranges(AddressRanges &LinkedFunctionRanges);
630
631 /// Clone and emit .debug_ranges/.debug_rnglists.
632 void cloneAndEmitRangeList(DebugSectionKind RngSectionKind,
633 AddressRanges &LinkedFunctionRanges);
634
635 /// Emit range list header.
636 uint64_t emitRangeListHeader(SectionDescriptor &OutRangeSection);
637
638 /// Emit range list fragment.
639 void emitRangeListFragment(const AddressRanges &LinkedRanges,
640 SectionDescriptor &OutRangeSection);
641
642 /// Insert the new line info sequence \p Seq into the current
643 /// set of already linked line info \p Rows.
644 void insertLineSequence(std::vector<DWARFDebugLine::Row> &Seq,
645 std::vector<DWARFDebugLine::Row> &Rows);
646
647 /// Emits body for both macro sections.
648 void emitMacroTableImpl(const DWARFDebugMacro *MacroTable,
649 uint64_t OffsetToMacroTable, bool hasDWARFv5Header);
650
651 /// Creates DIE which would be placed into the "Plain" compile unit.
652 DIE *createPlainDIEandCloneAttributes(
653 const DWARFDebugInfoEntry *InputDieEntry, DIEGenerator &PlainDIEGenerator,
654 uint64_t &OutOffset, std::optional<int64_t> &FuncAddressAdjustment,
655 std::optional<int64_t> &VarAddressAdjustment);
656
657 /// Creates DIE which would be placed into the "Type" compile unit.
658 TypeEntry *createTypeDIEandCloneAttributes(
659 const DWARFDebugInfoEntry *InputDieEntry, DIEGenerator &TypeDIEGenerator,
660 TypeEntry *ClonedParentTypeDIE, TypeUnit *ArtificialTypeUnit);
661
662 /// Create output DIE inside specified \p TypeDescriptor.
663 DIE *allocateTypeDie(TypeEntryBody *TypeDescriptor,
664 DIEGenerator &TypeDIEGenerator, dwarf::Tag DieTag,
665 bool IsDeclaration, bool IsParentDeclaration);
666
667 /// Enumerate \p DieEntry children and assign names for them.
668 Error assignTypeNamesRec(const DWARFDebugInfoEntry *DieEntry,
669 SyntheticTypeNameBuilder &NameBuilder);
670
671 /// DWARFFile containing this compile unit.
672 DWARFFile &File;
673
674 /// Pointer to the paired compile unit from the input DWARF.
675 DWARFUnit *OrigUnit = nullptr;
676
677 /// The DW_AT_language of this unit.
678 std::optional<uint16_t> Language;
679
680 /// Line table for this unit.
681 const DWARFDebugLine::LineTable *LineTablePtr = nullptr;
682
683 /// Cached resolved paths from the line table.
684 /// The key is <UniqueUnitID, FileIdx>.
685 using ResolvedPathsMap = DenseMap<unsigned, StringEntry *>;
686 ResolvedPathsMap ResolvedFullPaths;
687 StringMap<StringEntry *> ResolvedParentPaths;
688
689 /// Maps an address into the index inside .debug_addr section.
690 IndexedValuesMap<uint64_t> DebugAddrIndexMap;
691
692 std::unique_ptr<DependencyTracker> Dependencies;
693
694 /// \defgroup Data Members accessed asinchronously.
695 ///
696 /// @{
697 OffsetToUnitTy getUnitFromOffset;
698
699 std::optional<uint64_t> LowPc;
700 uint64_t HighPc = 0;
701
702 /// Flag indicating whether type de-duplication is forbidden.
703 bool NoODR = true;
704
705 /// The ranges in that map are the PC ranges for functions in this unit,
706 /// associated with the PC offset to apply to the addresses to get
707 /// the linked address.
708 RangesTy Ranges;
709 std::mutex RangesMutex;
710
711 /// The DW_AT_low_pc of each DW_TAG_label.
712 using LabelMapTy = SmallDenseMap<uint64_t, uint64_t, 1>;
713 LabelMapTy Labels;
714 std::mutex LabelsMutex;
715
716 /// This field keeps current stage of overall compile unit processing.
717 std::atomic<Stage> Stage;
718
719 /// DIE info indexed by DIE index.
720 SmallVector<DIEInfo> DieInfoArray;
721 SmallVector<uint64_t> OutDieOffsetArray;
722 SmallVector<TypeEntry *> TypeEntries;
723
724 /// The list of accelerator records for this unit.
725 ArrayList<AccelInfo> AcceleratorRecords;
726 /// @}
727};
728
729/// \returns list of attributes referencing type DIEs which might be
730/// deduplicated.
731/// Note: it does not include DW_AT_containing_type attribute to avoid
732/// infinite recursion.
734
735} // end of namespace parallel
736} // end of namespace dwarf_linker
737} // end of namespace llvm
738
739#endif // LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERCOMPILEUNIT_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Mark last scratch load
Analysis containing CSE Info
Definition CSEInfo.cpp:27
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition Compiler.h:638
Branch Probability Basic Block Placement
Basic Register Allocator
The AddressRanges class helps normalize address range collections.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:41
A structured debug information entry.
Definition DIE.h:828
DWARFDebugInfoEntry - A DIE with only the minimum required data.
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
Definition DWARFDie.h:43
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const
Return the index of a Die entry inside the unit's DIE vector.
Definition DWARFUnit.h:273
Base class for error info classes.
Definition Error.h:44
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Class representing an expression and its matching format.
A discriminated union of two or more pointer types, with the discriminator in the low bit of the poin...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
StringMap - This is an unconventional map that is specialized for handling keys that are "strings",...
Definition StringMap.h:133
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
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition Twine.h:82
LLVM Value Representation.
Definition Value.h:75
This class represents DWARF information for source file and it's address map.
Definition DWARFFile.h:25
This class stores values sequentually and assigns index to the each value.
This class is a simple list of T structures.
Definition ArrayList.h:23
CompileUnit * getAsCompileUnit()
Returns CompileUnit if applicable.
Stores all information related to a compile unit, be it in its original instance of the object file o...
void addLabelLowPc(uint64_t LabelLowPc, int64_t PcOffset)
Add the low_pc of a label that is relocated by applying offset PCOffset.
Error cloneAndEmitDebugLocations()
Clone and emit debug locations(.debug_loc/.debug_loclists).
void cloneDieAttrExpression(const DWARFExpression &InputExpression, SmallVectorImpl< uint8_t > &OutputExpression, SectionDescriptor &Section, std::optional< int64_t > VarAddressAdjustment, OffsetsPtrVector &PatchesOffsets)
Clone attribute location axpression.
void maybeResetToLoadedStage()
Reset compile units data(results of liveness analysis, clonning) if current stage greater than Stage:...
void addFunctionRange(uint64_t LowPC, uint64_t HighPC, int64_t PCOffset)
Add a function range [LowPC, HighPC) that is relocated by applying offset PCOffset.
void analyzeImportedModule(const DWARFDebugInfoEntry *DieEntry)
Collect references to parseable Swift interfaces in imported DW_TAG_module blocks.
std::pair< DIE *, TypeEntry * > cloneDIE(const DWARFDebugInfoEntry *InputDieEntry, TypeEntry *ClonedParentTypeDIE, uint64_t OutOffset, std::optional< int64_t > FuncAddressAdjustment, std::optional< int64_t > VarAddressAdjustment, BumpPtrAllocator &Allocator, TypeUnit *ArtificialTypeUnit)
void cleanupDataAfterClonning()
Cleanup unneeded resources after compile unit is cloned.
Error assignTypeNames(TypePool &TypePoolRef)
Search for type entries and assign names.
uint64_t getHighPc() const
Returns value of DW_AT_high_pc attribute.
DieOutputPlacement
Kinds of placement for the output die.
@ Both
Corresponding DIE goes to type table and to plain dwarf.
@ TypeTable
Corresponding DIE goes to the type table only.
@ PlainDwarf
Corresponding DIE goes to the plain dwarf only.
Error cloneAndEmitLineTable(const Triple &TargetTriple)
void analyzeDWARFStructure()
Navigate DWARF tree and set die properties.
void updateDieRefPatchesWithClonedOffsets()
After cloning stage the output DIEs offsets are deallocated.
uint64_t getDebugAddrIndex(uint64_t Addr)
Returns index(inside .debug_addr) of an address.
const DWARFFile & getContaingFile() const
Returns DWARFFile containing this compile unit.
bool resolveDependenciesAndMarkLiveness(bool InterCUProcessingStarted, std::atomic< bool > &HasNewInterconnectedCUs)
Search for subprograms and variables referencing live code and discover dependend DIEs.
bool hasLabelAt(uint64_t Addr) const
Returns true if there is a label corresponding to the specified Addr.
bool updateDependenciesCompleteness()
Check dependend DIEs for incompatible placement.
bool loadInputDIEs()
Load DIEs of input compilation unit.
const RangesTy & getFunctionRanges() const
Returns function ranges of this unit.
void saveAcceleratorInfo(const DwarfUnit::AccelInfo &Info)
Save specified accelerator info Info.
Error cloneAndEmitDebugMacro()
Clone and emit debug macros(.debug_macinfo/.debug_macro).
Error cloneAndEmit(std::optional< std::reference_wrapper< const Triple > > TargetTriple, TypeUnit *ArtificialTypeUnit)
Clone and emit this compilation unit.
void setStage(Stage Stage)
Set stage of overall processing.
Stage getStage() const
Returns stage of overall processing.
CompileUnit(LinkingGlobalData &GlobalData, unsigned ID, StringRef ClangModuleName, DWARFFile &File, OffsetToUnitTy UnitFromOffset, dwarf::FormParams Format, llvm::endianness Endianess)
void verifyDependencies()
Check DIEs to have a consistent marking(keep marking, placement marking).
Stage
The stages of new compile unit processing.
@ CreatedNotLoaded
Created, linked with input DWARF file.
@ PatchesUpdated
Offsets inside patch records are updated.
@ Cleaned
Resources(Input DWARF, Output DWARF tree) are released.
@ LivenessAnalysisDone
Input DWARF is analysed(DIEs pointing to the real code section arediscovered, type names are assigned...
@ UpdateDependenciesCompleteness
Check if dependencies have incompatible placement.
void forEachAcceleratorRecord(function_ref< void(AccelInfo &)> Handler) override
Enumerates all units accelerator records.
std::optional< uint64_t > getLowPc() const
Returns value of DW_AT_low_pc attribute.
std::optional< std::pair< StringRef, StringRef > > getDirAndFilenameFromLineTable(const DWARFFormValue &FileIdxValue)
Returns directory and file from the line table by index.
std::optional< UnitEntryPairTy > resolveDIEReference(const DWARFFormValue &RefValue, ResolveInterCUReferencesMode CanResolveInterCUReferences)
Resolve the DIE attribute reference that has been extracted in RefValue.
StringEntry * getFileName(unsigned FileIdx, StringPool &GlobalStrings)
Returns name of the file for the FileIdx from the unit`s line table.
This class is a helper to create output DIE tree.
This class discovers DIEs dependencies: marks "live" DIEs, marks DIE locations (whether DIE should be...
StringRef getUnitName() const
Returns this unit name.
DwarfUnit(LinkingGlobalData &GlobalData, unsigned ID, StringRef ClangModuleName)
std::string ClangModuleName
If this is a Clang module, this holds the module's name.
This class keeps data and services common for the whole linking process.
The helper class to build type name based on DIE properties.
Keeps cloned data for the type DIE.
Definition TypePool.h:30
TypePool keeps type descriptors which contain partially cloned DIE correspinding to each type.
Definition TypePool.h:111
Type Unit is used to represent an artificial compilation unit which keeps all type information.
An efficient, type-erasing, non-owning reference to a callable.
uint64_t getDieOutOffset(const DWARFDebugInfoEntry *InputDieEntry)
InputDieEntry debug info entry.
void rememberDieOutOffset(uint32_t Idx, uint64_t Offset)
Idx index of the DIE.
TypeEntry * getDieTypeEntry(uint32_t Idx)
Idx index of the DIE.
DIEInfo & getDIEInfo(unsigned Idx)
Idx index of the DIE.
const DIEInfo & getDIEInfo(const DWARFDebugInfoEntry *Entry) const
Idx index of the DIE.
uint64_t getDieOutOffset(uint32_t Idx)
Idx index of the DIE.
const DIEInfo & getDIEInfo(const DWARFDie &Die) const
Die
const DIEInfo & getDIEInfo(unsigned Idx) const
Idx index of the DIE.
DIEInfo & getDIEInfo(const DWARFDebugInfoEntry *Entry)
Idx index of the DIE.
TypeEntry * getDieTypeEntry(const DWARFDebugInfoEntry *InputDieEntry)
InputDieEntry debug info entry.
void setDieTypeEntry(const DWARFDebugInfoEntry *InputDieEntry, TypeEntry *Entry)
InputDieEntry debug info entry.
void setDieTypeEntry(uint32_t Idx, TypeEntry *Entry)
Idx index of the DIE.
DIEInfo & getDIEInfo(const DWARFDie &Die)
Die
const DWARFDebugInfoEntry * getSiblingEntry(const DWARFDebugInfoEntry *Die) const
const DWARFDebugInfoEntry * getFirstChildEntry(const DWARFDebugInfoEntry *Die) const
std::optional< uint32_t > getDIEIndexForOffset(uint64_t Offset)
DWARFDie getDIE(const DWARFDebugInfoEntry *Die)
std::optional< DWARFFormValue > find(const DWARFDebugInfoEntry *Die, ArrayRef< dwarf::Attribute > Attrs) const
const DWARFDebugInfoEntry * getDebugInfoEntry(unsigned Index) const
DWARFUnit & getOrigUnit() const
Returns paired compile unit from input DWARF.
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const
uint32_t getDIEIndex(const DWARFDie &Die) const
std::optional< DWARFFormValue > find(uint32_t DieIdx, ArrayRef< dwarf::Attribute > Attrs) const
void error(Error Err, const DWARFDie *DIE=nullptr)
void warn(Error Warning, const DWARFDie *DIE=nullptr)
void warn(const Twine &Warning, const DWARFDie *DIE=nullptr)
void error(const Twine &Err, const DWARFDie *DIE=nullptr)
void warn(const Twine &Warning, const DWARFDebugInfoEntry *DieEntry)
#define SINGLE_FLAG_METHODS_SET(Name, Value)
unsigned ID
LLVM IR allows to use arbitrary numbers as calling convention identifiers.
Definition CallingConv.h:24
function_ref< CompileUnit *(uint64_t Offset)> OffsetToUnitTy
SmallVector< uint64_t * > OffsetsPtrVector
Type for list of pointers to patches offsets.
StringMapEntry< std::atomic< TypeEntryBody * > > TypeEntry
Definition TypePool.h:27
ArrayRef< dwarf::Attribute > getODRAttributes()
StringMapEntry< std::nullopt_t > StringEntry
StringEntry keeps data of the string: the length, external offset and a string body which is placed r...
Definition StringPool.h:23
DebugSectionKind
List of tracked debug tables.
AddressRangesMap RangesTy
Mapped value in the address map is the offset to apply to the linked address.
Attribute
Attributes.
Definition Dwarf.h:124
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
Definition Error.h:990
static void insertLineSequence(std::vector< TrackedRow > &Seq, std::vector< TrackedRow > &Rows)
Insert the new line info sequence Seq into the current set of already linked line info Rows.
BumpPtrAllocatorImpl BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
Definition Allocator.h:383
@ Other
Any other memory.
Definition ModRef.h:68
endianness
Definition bit.h:71
@ Keep
No function return thunk.
Definition CodeGen.h:156
Represents a single DWARF expression, whose value is location-dependent.
A helper struct providing information about the byte size of DW_FORM values that vary in size dependi...
Definition Dwarf.h:1093
Information gathered and exchanged between the various clone*Attr helpers about the attributes of a p...
void setPlacement(DieOutputPlacement Placement)
Sets Placement kind for the corresponding die.
std::atomic< uint16_t > Flags
Data member keeping various flags.
void unsetPlacement()
Unsets Placement kind for the corresponding die.
bool setPlacementIfUnset(DieOutputPlacement Placement)
Sets Placement kind for the corresponding die.
void unsetFlagsWhichSetDuringLiveAnalysis()
DIE is a part of the linked output.
This structure keeps fields which would be used for creating accelerator table.
This structure is used to keep data of the concrete section.
UnitEntryPairTy(CompileUnit *CU, const DWARFDebugInfoEntry *DieEntry)