LLVM 24.0.0git
llvm::dwarf_linker::parallel::DependencyTracker Class Reference

This class discovers DIEs dependencies: marks "live" DIEs, marks DIE locations (whether DIE should be cloned as regular DIE or it should be put into the artificial type unit). More...

#include "DWARFLinker/Parallel/DependencyTracker.h"

Classes

class  LiveRootWorklistItemTy
 Class keeping live worklist item data. More...
struct  SubtreeDependencyRefTy
 A root referencing an already-marked subtree, standing in for all of that subtree's dependencies. More...
struct  SubtreeDependencyTy
 A completeness dependency of a subtree that belongs to whichever root references the subtree, which is not known while the subtree is walked. More...

Public Member Functions

 DependencyTracker (CompileUnit &CU)
bool resolveDependenciesAndMarkLiveness (bool InterCUProcessingStarted, std::atomic< bool > &HasNewInterconnectedCUs)
 Recursively walk the DIE tree and look for DIEs to keep.
bool updateDependenciesCompleteness ()
 Check if dependencies have incompatible placement.
void verifyKeepChain ()
 Recursively walk the DIE tree and check "keepness" and "placement" information.

Protected Types

enum class  LiveRootWorklistActionTy : uint8_t {
  MarkSingleLiveEntry = 0 , MarkSingleTypeEntry , MarkLiveEntryRec , MarkTypeEntryRec ,
  MarkLiveChildrenRec , MarkTypeChildrenRec
}
enum class  TreeWalkKindTy : uint8_t { MarkTree , RecordSubtreeDeps , RecordNestedSubprogramDeps }
 What a tree walk does, and for a walk that only records dependencies, which root the dependencies it finds are recorded under. More...
using RootEntriesListTy = SmallVector<LiveRootWorklistItemTy>
using SubtreeDependenciesTy = SmallVector<SubtreeDependencyTy>
using SubtreeDependenciesKeyTy
 A subtree paired with the action it is walked with, which selects both the visited children and the action recorded for a reference.

Protected Member Functions

bool isLiveAction (LiveRootWorklistActionTy Action)
bool isTypeAction (LiveRootWorklistActionTy Action)
bool isChildrenAction (LiveRootWorklistActionTy Action)
void collectRootsToKeep (const UnitEntryPairTy &Entry, std::optional< UnitEntryPairTy > ReferencedBy, bool IsLiveParent)
 This function navigates DIEs tree starting from specified Entry.
bool markCollectedLiveRootsAsKept (bool InterCUProcessingStarted, std::atomic< bool > &HasNewInterconnectedCUs)
 Examine worklist and mark all 'root DIE's as kept and set "Placement" property.
bool markDIEEntryAsKeptRec (LiveRootWorklistActionTy Action, const UnitEntryPairTy &RootEntry, const UnitEntryPairTy &Entry, bool InterCUProcessingStarted, std::atomic< bool > &HasNewInterconnectedCUs, TreeWalkKindTy Kind=TreeWalkKindTy::MarkTree)
 Mark whole DIE tree as kept recursively.
void recordSubtreeDependencies (LiveRootWorklistActionTy Action, const UnitEntryPairTy &RootEntry, const UnitEntryPairTy &Entry)
 Record that RootEntry references the already-marked subtree Entry, and therefore carries the completeness dependencies of that subtree.
void materializeSubtreeSummaries ()
 Walk every subtree that a recorded reference stands for, once per subtree and action, and summarize the dependencies it contributes.
bool applySubtreeSummaries ()
 Apply each summarized subtree's dependencies to every root recorded as referencing it.
bool demoteIfIncomplete (const UnitEntryPairTy &Root, const DWARFDebugInfoEntry *ReferencedTypeDieEntry, const UnitEntryPairTy &ReferencedBy)
 Demote ReferencedBy to plain DWARF if it may not stay in the type table while the DIE it references through Root is not placed there.
void markParentsAsKeepingChildren (const UnitEntryPairTy &Entry)
 Mark parents as keeping children.
void setPlainDwarfPlacementRec (const UnitEntryPairTy &Entry)
 Mark whole DIE tree as placed in "PlainDwarf".
bool maybeAddReferencedRoots (LiveRootWorklistActionTy Action, const UnitEntryPairTy &RootEntry, const UnitEntryPairTy &Entry, bool InterCUProcessingStarted, std::atomic< bool > &HasNewInterconnectedCUs, TreeWalkKindTy Kind=TreeWalkKindTy::MarkTree)
 Check referenced DIEs and add them into the worklist.
bool isTypeTableCandidate (const DWARFDebugInfoEntry *DIEEntry)
UnitEntryPairTy getRootForSpecifiedEntry (UnitEntryPairTy Entry)
void addActionToRootEntriesWorkList (LiveRootWorklistActionTy Action, const UnitEntryPairTy &Entry, std::optional< UnitEntryPairTy > ReferencedBy, const DWARFDebugInfoEntry *ReferencedTypeDieEntry=nullptr)
 Add action item to the work list.

Static Protected Member Functions

static bool recordsDepsOnly (TreeWalkKindTy Kind)
static bool isLiveVariableEntry (const UnitEntryPairTy &Entry, bool IsLiveParent)
 Returns true if specified variable references live code section.
static bool isLiveSubprogramEntry (const UnitEntryPairTy &Entry)
 Returns true if specified subprogram references live code section.

Protected Attributes

CompileUnitCU
RootEntriesListTy RootEntriesWorkList
 List of entries which are 'root DIE's.
RootEntriesListTy Dependencies
 List of entries dependencies.
DenseMap< SubtreeDependenciesKeyTy, SubtreeDependenciesTySubtreeSummaries
 Dependency summaries of already-marked subtrees, keyed by subtree and action.
SmallVector< SubtreeDependencyRefTySubtreeDependencyRefs
 Roots referencing an already-marked subtree.
size_t MaterializedRefs = 0
 Number of leading SubtreeDependencyRefs whose subtree is summarized.
SubtreeDependenciesTyCollectedSubtreeDeps = nullptr
 Where the walk in progress collects the dependencies that belong to the root referencing the walked subtree, or null when no such walk is in progress.
bool InterCUProcessingWasStarted = false
 Whether inter-unit references could be resolved during marking.

Detailed Description

This class discovers DIEs dependencies: marks "live" DIEs, marks DIE locations (whether DIE should be cloned as regular DIE or it should be put into the artificial type unit).

Definition at line 27 of file DependencyTracker.h.

Member Typedef Documentation

◆ RootEntriesListTy

◆ SubtreeDependenciesKeyTy

Initial value:
std::tuple<CompileUnit *, const DWARFDebugInfoEntry *,
DWARFDebugInfoEntry - A DIE with only the minimum required data.
Stores all information related to a compile unit, be it in its original instance of the object file o...

A subtree paired with the action it is walked with, which selects both the visited children and the action recorded for a reference.

Definition at line 265 of file DependencyTracker.h.

◆ SubtreeDependenciesTy

Member Enumeration Documentation

◆ LiveRootWorklistActionTy

Enumerator
MarkSingleLiveEntry 

Mark current item as live entry.

MarkSingleTypeEntry 

Mark current item as type entry.

MarkLiveEntryRec 

Mark current item and all its children as live entry.

MarkTypeEntryRec 

Mark current item and all its children as type entry.

MarkLiveChildrenRec 

Mark all children of current item as live entry.

MarkTypeChildrenRec 

Mark all children of current item as type entry.

Definition at line 61 of file DependencyTracker.h.

◆ TreeWalkKindTy

What a tree walk does, and for a walk that only records dependencies, which root the dependencies it finds are recorded under.

Only a DW_TAG_subprogram re-anchors that root, so the distinction cannot be recovered by comparing root entries: a walk of a subprogram subtree starts out anchored to the subprogram itself.

Enumerator
MarkTree 

Mark the tree as kept and schedule the roots it references.

RecordSubtreeDeps 

Do not mark.

Record the dependencies as belonging to whichever root references the walked subtree.

RecordNestedSubprogramDeps 

Do not mark.

Record the dependencies as belonging to a subprogram inside the walked subtree, which makes them the same for every referencing root.

Definition at line 138 of file DependencyTracker.h.

Constructor & Destructor Documentation

◆ DependencyTracker()

llvm::dwarf_linker::parallel::DependencyTracker::DependencyTracker ( CompileUnit & CU)
inline

Definition at line 29 of file DependencyTracker.h.

Member Function Documentation

◆ addActionToRootEntriesWorkList()

void DependencyTracker::addActionToRootEntriesWorkList ( LiveRootWorklistActionTy Action,
const UnitEntryPairTy & Entry,
std::optional< UnitEntryPairTy > ReferencedBy,
const DWARFDebugInfoEntry * ReferencedTypeDieEntry = nullptr )
protected

Add action item to the work list.

Definition at line 145 of file DependencyTracker.cpp.

References RootEntriesWorkList.

Referenced by collectRootsToKeep(), markParentsAsKeepingChildren(), and maybeAddReferencedRoots().

◆ applySubtreeSummaries()

◆ collectRootsToKeep()

void DependencyTracker::collectRootsToKeep ( const UnitEntryPairTy & Entry,
std::optional< UnitEntryPairTy > ReferencedBy,
bool IsLiveParent )
protected

This function navigates DIEs tree starting from specified Entry.

It puts found 'root DIE' into the worklist. The CollectLiveEntries instructs to collect either live roots(like subprograms having live DW_AT_low_pc) or otherwise roots which is not live(they need to be collected if they are imported f.e. by DW_TAG_imported_module).

Definition at line 158 of file DependencyTracker.cpp.

References addActionToRootEntriesWorkList(), collectRootsToKeep(), llvm::DWARFDebugInfoEntry::getAbbreviationDeclarationPtr(), isLiveSubprogramEntry(), isLiveVariableEntry(), isNamespaceLikeEntry(), llvm::dwarf::isType(), llvm_unreachable, MarkLiveEntryRec, MarkSingleLiveEntry, MarkSingleTypeEntry, MarkTypeEntryRec, and llvm::dwarf::toUnsigned().

Referenced by collectRootsToKeep(), and resolveDependenciesAndMarkLiveness().

◆ demoteIfIncomplete()

bool DependencyTracker::demoteIfIncomplete ( const UnitEntryPairTy & Root,
const DWARFDebugInfoEntry * ReferencedTypeDieEntry,
const UnitEntryPairTy & ReferencedBy )
protected

Demote ReferencedBy to plain DWARF if it may not stay in the type table while the DIE it references through Root is not placed there.

Returns
true if the placement was updated.

Definition at line 340 of file DependencyTracker.cpp.

References llvm::dwarf_linker::parallel::UnitEntryPairTy::CU, llvm::dwarf_linker::parallel::UnitEntryPairTy::DieEntry, llvm::dwarf_linker::parallel::CompileUnit::getDIEInfo(), llvm::dwarf_linker::parallel::CompileUnit::DIEInfo::needToPlaceInTypeTable(), and setPlainDwarfPlacementRec().

Referenced by applySubtreeSummaries(), and updateDependenciesCompleteness().

◆ getRootForSpecifiedEntry()

UnitEntryPairTy DependencyTracker::getRootForSpecifiedEntry ( UnitEntryPairTy Entry)
protected
Returns
root for the specified Entry.

Definition at line 932 of file DependencyTracker.cpp.

References isNamespaceLikeEntry().

Referenced by maybeAddReferencedRoots().

◆ isChildrenAction()

bool llvm::dwarf_linker::parallel::DependencyTracker::isChildrenAction ( LiveRootWorklistActionTy Action)
inlineprotected
Returns
true if the specified action affects only Root entry itself and does not affect it`s children. bool isSingleAction(LiveRootWorklistActionTy Action) { switch (Action) { default: return false;

case LiveRootWorklistActionTy::MarkSingleLiveEntry: case LiveRootWorklistActionTy::MarkSingleTypeEntry: return true; } }

/

Returns
true if the specified action affects only Root entry / itself and does not affect it`s children.

Definition at line 122 of file DependencyTracker.h.

References MarkLiveChildrenRec, and MarkTypeChildrenRec.

Referenced by markDIEEntryAsKeptRec().

◆ isLiveAction()

bool llvm::dwarf_linker::parallel::DependencyTracker::isLiveAction ( LiveRootWorklistActionTy Action)
inlineprotected
Returns
true if the specified action is for the "PlainDwarf".

Definition at line 82 of file DependencyTracker.h.

References MarkLiveChildrenRec, MarkLiveEntryRec, and MarkSingleLiveEntry.

Referenced by markDIEEntryAsKeptRec(), and maybeAddReferencedRoots().

◆ isLiveSubprogramEntry()

bool DependencyTracker::isLiveSubprogramEntry ( const UnitEntryPairTy & Entry)
staticprotected

Returns true if specified subprogram references live code section.

Definition at line 1012 of file DependencyTracker.cpp.

References dumpKeptDIE(), llvm::DIE::getTag(), Range, llvm::dwarf::toAddress(), llvm::dwarf::toUnsigned(), UINT64_MAX, and llvm::Verbose.

Referenced by collectRootsToKeep(), and verifyKeepChain().

◆ isLiveVariableEntry()

bool DependencyTracker::isLiveVariableEntry ( const UnitEntryPairTy & Entry,
bool IsLiveParent )
staticprotected

Returns true if specified variable references live code section.

Definition at line 973 of file DependencyTracker.cpp.

References dumpKeptDIE().

Referenced by collectRootsToKeep().

◆ isTypeAction()

bool llvm::dwarf_linker::parallel::DependencyTracker::isTypeAction ( LiveRootWorklistActionTy Action)
inlineprotected
Returns
true if the specified action is for the "TypeTable".

Definition at line 95 of file DependencyTracker.h.

References MarkSingleTypeEntry, MarkTypeChildrenRec, and MarkTypeEntryRec.

Referenced by markDIEEntryAsKeptRec(), and maybeAddReferencedRoots().

◆ isTypeTableCandidate()

bool DependencyTracker::isTypeTableCandidate ( const DWARFDebugInfoEntry * DIEEntry)
protected
Returns
true if DIEEntry can possibly be put into the artificial type unit.

Definition at line 762 of file DependencyTracker.cpp.

Referenced by markDIEEntryAsKeptRec().

◆ markCollectedLiveRootsAsKept()

bool DependencyTracker::markCollectedLiveRootsAsKept ( bool InterCUProcessingStarted,
std::atomic< bool > & HasNewInterconnectedCUs )
protected

◆ markDIEEntryAsKeptRec()

bool DependencyTracker::markDIEEntryAsKeptRec ( LiveRootWorklistActionTy Action,
const UnitEntryPairTy & RootEntry,
const UnitEntryPairTy & Entry,
bool InterCUProcessingStarted,
std::atomic< bool > & HasNewInterconnectedCUs,
TreeWalkKindTy Kind = TreeWalkKindTy::MarkTree )
protected

◆ markParentsAsKeepingChildren()

◆ materializeSubtreeSummaries()

void DependencyTracker::materializeSubtreeSummaries ( )
protected

Walk every subtree that a recorded reference stands for, once per subtree and action, and summarize the dependencies it contributes.

Called when completeness is checked, so that liveness marking and inter-unit reference resolution have settled and the summary no longer depends on the order the units were processed in.

Definition at line 303 of file DependencyTracker.cpp.

References assert(), CollectedSubtreeDeps, llvm::InnerAnalysisManagerProxy< AnalysisManagerT, IRUnitT, ExtraArgTs... >::Key, InterCUProcessingWasStarted, markDIEEntryAsKeptRec(), MaterializedRefs, RecordSubtreeDeps, llvm::Ref, SubtreeDependencyRefs, and SubtreeSummaries.

Referenced by updateDependenciesCompleteness().

◆ maybeAddReferencedRoots()

bool DependencyTracker::maybeAddReferencedRoots ( LiveRootWorklistActionTy Action,
const UnitEntryPairTy & RootEntry,
const UnitEntryPairTy & Entry,
bool InterCUProcessingStarted,
std::atomic< bool > & HasNewInterconnectedCUs,
TreeWalkKindTy Kind = TreeWalkKindTy::MarkTree )
protected

Check referenced DIEs and add them into the worklist.

A walk that only records dependencies (see Kind) schedules nothing, so it triggers no reference-following recursion. Each dependency it finds is instead collected for the root that carries it, which is either whichever root references the walked subtree or a subprogram nested inside it. This is used when Entry was already marked by a racing CU/root: the marking and subtree are handled elsewhere, but the referencing root's dependencies must still be recorded so the completeness fixpoint sees a complete, order-independent dependency set.

Definition at line 810 of file DependencyTracker.cpp.

References addActionToRootEntriesWorkList(), assert(), llvm::dwarf_linker::parallel::AvoidResolving, CollectedSubtreeDeps, llvm::Data, Dependencies, llvm::DWARFFormValue::extractValue(), llvm::DWARFFormValue::FC_Reference, llvm::dwarf_linker::parallel::getODRAttributes(), getRootForSpecifiedEntry(), llvm::getULEB128Size(), llvm::is_contained(), llvm::DWARFFormValue::isFormClass(), isLiveAction(), isNamespaceLikeEntry(), isTypeAction(), llvm_unreachable, MarkLiveEntryRec, MarkSingleLiveEntry, MarkSingleTypeEntry, MarkTree, MarkTypeEntryRec, llvm::Offset, RecordNestedSubprogramDeps, recordsDepsOnly(), RecordSubtreeDeps, llvm::dwarf_linker::parallel::Resolve, and llvm::DWARFFormValue::skipValue().

Referenced by markDIEEntryAsKeptRec().

◆ recordsDepsOnly()

bool llvm::dwarf_linker::parallel::DependencyTracker::recordsDepsOnly ( TreeWalkKindTy Kind)
inlinestaticprotected
Returns
true if the specified walk records dependencies instead of marking the tree.

Definition at line 154 of file DependencyTracker.h.

References MarkTree.

Referenced by markDIEEntryAsKeptRec(), and maybeAddReferencedRoots().

◆ recordSubtreeDependencies()

void DependencyTracker::recordSubtreeDependencies ( LiveRootWorklistActionTy Action,
const UnitEntryPairTy & RootEntry,
const UnitEntryPairTy & Entry )
protected

Record that RootEntry references the already-marked subtree Entry, and therefore carries the completeness dependencies of that subtree.

The subtree itself is walked later, by materializeSubtreeSummaries().

Definition at line 297 of file DependencyTracker.cpp.

References SubtreeDependencyRefs.

Referenced by markDIEEntryAsKeptRec().

◆ resolveDependenciesAndMarkLiveness()

bool DependencyTracker::resolveDependenciesAndMarkLiveness ( bool InterCUProcessingStarted,
std::atomic< bool > & HasNewInterconnectedCUs )

Recursively walk the DIE tree and look for DIEs to keep.

Store that information in CU's DIEInfo.

This function is the entry point of the DIE selection algorithm. It is expected to walk the DIE tree and(through the mediation of Context.File.Addresses) ask for relocation adjustment value on each DIE that might be a 'root DIE'(f.e. subprograms, variables).

Returns true if all dependencies are correctly discovered. Inter-CU dependencies cannot be discovered if referenced CU is not analyzed yet. If that is the case this method returns false.

Definition at line 121 of file DependencyTracker.cpp.

References assert(), collectRootsToKeep(), InterCUProcessingWasStarted, markCollectedLiveRootsAsKept(), llvm::dwarf_linker::parallel::CompileUnit::PlainDwarf, RootEntriesWorkList, llvm::dwarf_linker::parallel::CompileUnit::DIEInfo::setPlacement(), and SubtreeDependencyRefs.

◆ setPlainDwarfPlacementRec()

◆ updateDependenciesCompleteness()

bool DependencyTracker::updateDependenciesCompleteness ( )

Check if dependencies have incompatible placement.

If that is the case modify placement to be compatible.

Returns
true if any placement was updated, otherwise returns false. This method should be called as a followup processing after resolveDependenciesAndMarkLiveness().

Definition at line 394 of file DependencyTracker.cpp.

References applySubtreeSummaries(), assert(), demoteIfIncomplete(), Dependencies, and materializeSubtreeSummaries().

◆ verifyKeepChain()

void DependencyTracker::verifyKeepChain ( )

Recursively walk the DIE tree and check "keepness" and "placement" information.

Verify the keep chain by looking for DIEs that are kept but who's parent isn't.

It is an error if parent node does not have "keep" flag, while child has one. It is an error if parent node has "TypeTable" placement while child has "PlainDwarf" placement. This function dump error at stderr in that case.

Definition at line 29 of file DependencyTracker.cpp.

References assert(), llvm::SmallVectorTemplateCommon< T, typename >::back(), llvm::DWARFDie::children(), llvm::SmallVectorImpl< T >::emplace_back(), llvm::SmallVectorTemplateCommon< T, typename >::empty(), llvm::WithColor::error(), llvm::errs(), llvm::formatv(), llvm::DWARFDie::getDebugInfoEntry(), isLiveSubprogramEntry(), llvm::DWARFDie::isValid(), llvm::dwarf_linker::parallel::CompileUnit::DIEInfo::needToKeepInPlainDwarf(), llvm::dwarf_linker::parallel::CompileUnit::DIEInfo::needToPlaceInTypeTable(), llvm::SmallVectorTemplateBase< T, bool >::pop_back(), llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::report_fatal_error(), and llvm::reverse().

Member Data Documentation

◆ CollectedSubtreeDeps

SubtreeDependenciesTy* llvm::dwarf_linker::parallel::DependencyTracker::CollectedSubtreeDeps = nullptr
protected

Where the walk in progress collects the dependencies that belong to the root referencing the walked subtree, or null when no such walk is in progress.

Scoped by materializeSubtreeSummaries().

Definition at line 402 of file DependencyTracker.h.

Referenced by materializeSubtreeSummaries(), and maybeAddReferencedRoots().

◆ CU

CompileUnit& llvm::dwarf_linker::parallel::DependencyTracker::CU
protected

Definition at line 381 of file DependencyTracker.h.

◆ Dependencies

RootEntriesListTy llvm::dwarf_linker::parallel::DependencyTracker::Dependencies
protected

List of entries dependencies.

Definition at line 387 of file DependencyTracker.h.

Referenced by markCollectedLiveRootsAsKept(), maybeAddReferencedRoots(), and updateDependenciesCompleteness().

◆ InterCUProcessingWasStarted

bool llvm::dwarf_linker::parallel::DependencyTracker::InterCUProcessingWasStarted = false
protected

Whether inter-unit references could be resolved during marking.

Reused when the recorded subtrees are walked, which happens outside of marking.

Definition at line 406 of file DependencyTracker.h.

Referenced by materializeSubtreeSummaries(), and resolveDependenciesAndMarkLiveness().

◆ MaterializedRefs

size_t llvm::dwarf_linker::parallel::DependencyTracker::MaterializedRefs = 0
protected

Number of leading SubtreeDependencyRefs whose subtree is summarized.

Definition at line 397 of file DependencyTracker.h.

Referenced by materializeSubtreeSummaries().

◆ RootEntriesWorkList

RootEntriesListTy llvm::dwarf_linker::parallel::DependencyTracker::RootEntriesWorkList
protected

List of entries which are 'root DIE's.

Definition at line 384 of file DependencyTracker.h.

Referenced by addActionToRootEntriesWorkList(), markCollectedLiveRootsAsKept(), and resolveDependenciesAndMarkLiveness().

◆ SubtreeDependencyRefs

SmallVector<SubtreeDependencyRefTy> llvm::dwarf_linker::parallel::DependencyTracker::SubtreeDependencyRefs
protected

Roots referencing an already-marked subtree.

Definition at line 394 of file DependencyTracker.h.

Referenced by applySubtreeSummaries(), materializeSubtreeSummaries(), recordSubtreeDependencies(), and resolveDependenciesAndMarkLiveness().

◆ SubtreeSummaries

DenseMap<SubtreeDependenciesKeyTy, SubtreeDependenciesTy> llvm::dwarf_linker::parallel::DependencyTracker::SubtreeSummaries
protected

Dependency summaries of already-marked subtrees, keyed by subtree and action.

Filled once, when completeness is first checked.

Definition at line 391 of file DependencyTracker.h.

Referenced by applySubtreeSummaries(), and materializeSubtreeSummaries().


The documentation for this class was generated from the following files: