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