1 //===- "DependencyTracker.h" ------------------------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIB_DWARFLINKERPARALLEL_DEPENDENCYTRACKER_H
10 #define LLVM_LIB_DWARFLINKERPARALLEL_DEPENDENCYTRACKER_H
12 #include "DWARFLinkerCompileUnit.h"
13 #include "DWARFLinkerImpl.h"
14 #include "llvm/ADT/SmallVector.h"
17 class DWARFDebugInfoEntry
;
20 namespace dwarflinker_parallel
{
22 /// This class discovers DIEs dependencies and marks "live" DIEs.
23 class DependencyTracker
{
25 DependencyTracker(DWARFLinkerImpl::LinkContext
&Context
) : Context(Context
) {}
27 /// Recursively walk the \p DIE tree and look for DIEs to keep. Store that
28 /// information in \p CU's DIEInfo.
30 /// This function is the entry point of the DIE selection algorithm. It is
31 /// expected to walk the DIE tree and(through the mediation of
32 /// Context.File.Addresses) ask for relocation adjustment value on each
33 /// DIE that might be a 'root DIE'.
35 /// Returns true if all dependencies are correctly discovered. Inter-CU
36 /// dependencies cannot be discovered if referenced CU is not analyzed yet.
37 /// If that is the case this method returns false.
38 bool resolveDependenciesAndMarkLiveness(CompileUnit
&CU
);
40 /// Recursively walk the \p DIE tree and check "keepness" information.
41 /// It is an error if parent node does not have "keep" flag, while
42 /// child have one. This function dump error at stderr in that case.
44 static void verifyKeepChain(CompileUnit
&CU
);
49 RootEntryTy(CompileUnit
&CU
, const DWARFDebugInfoEntry
*RootEntry
)
50 : CU(CU
), RootEntry(RootEntry
) {}
52 // Compile unit keeping root entry.
56 const DWARFDebugInfoEntry
*RootEntry
;
59 using RootEntriesListTy
= SmallVector
<RootEntryTy
>;
61 /// This function navigates DIEs tree starting from specified \p Entry.
62 /// It puts 'root DIE' into the worklist.
63 void collectRootsToKeep(CompileUnit
&CU
, const DWARFDebugInfoEntry
*Entry
);
65 /// Returns true if specified variable references live code section.
66 bool isLiveVariableEntry(CompileUnit
&CU
, const DWARFDebugInfoEntry
*Entry
);
68 /// Returns true if specified subprogram references live code section.
69 bool isLiveSubprogramEntry(CompileUnit
&CU
, const DWARFDebugInfoEntry
*Entry
);
71 /// Examine worklist and mark all 'root DIE's as kept.
72 bool markLiveRootsAsKept();
74 /// Mark whole DIE tree as kept recursively.
75 bool markDIEEntryAsKeptRec(const RootEntryTy
&RootItem
, CompileUnit
&CU
,
76 const DWARFDebugInfoEntry
*Entry
);
78 /// Check referenced DIEs and add them into the worklist if neccessary.
79 bool maybeAddReferencedRoots(const RootEntryTy
&RootItem
, CompileUnit
&CU
,
80 const DWARFDebugInfoEntry
*Entry
);
82 /// Add 'root DIE' into the worklist.
83 void addItemToWorklist(CompileUnit
&CU
, const DWARFDebugInfoEntry
*Entry
);
85 /// Set kind of placement(whether it goes into type table, plain dwarf or
86 /// both) for the specified die \p DieIdx.
87 void setDIEPlacementAndTypename(CompileUnit::DIEInfo
&Info
);
89 /// Flag indicating whether liveness information should be examined.
90 bool TrackLiveness
= false;
92 /// List of CU, Entry pairs which are 'root DIE's.
93 RootEntriesListTy RootEntriesWorkList
;
95 /// Link context for the analyzed CU.
96 DWARFLinkerImpl::LinkContext
&Context
;
99 } // end namespace dwarflinker_parallel
100 } // end namespace llvm
102 #endif // LLVM_LIB_DWARFLINKERPARALLEL_DEPENDENCYTRACKER_H