9#ifndef LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERCOMPILEUNIT_H
10#define LLVM_LIB_DWARFLINKER_PARALLEL_DWARFLINKERCOMPILEUNIT_H
42 std::optional<UnitEntryPairTy>
getParent();
176 bool InterCUProcessingStarted,
177 std::atomic<bool> &HasNewInterconnectedCUs);
222 auto InputData =
Flags.load();
223 while (!
Flags.compare_exchange_weak(InputData,
230 auto InputData =
Flags.load();
231 while (!
Flags.compare_exchange_weak(InputData, (InputData & ~0x7))) {
237 auto InputData =
Flags.load();
238 if ((InputData & 0x7) ==
NotSet)
239 if (
Flags.compare_exchange_strong(InputData, (InputData |
Placement)))
251 auto InputData =
Flags.load();
252 while (!
Flags.compare_exchange_weak(InputData, (InputData |
Placement))) {
263 auto InputData =
Flags.load();
271 Desired = (InputData & ~0x7) | Joined;
272 }
while (!
Flags.compare_exchange_weak(InputData, Desired));
275#define SINGLE_FLAG_METHODS_SET(Name, Value) \
276 bool get##Name() const { return Flags & Value; } \
278 auto InputData = Flags.load(); \
279 while (!Flags.compare_exchange_weak(InputData, InputData | Value)) { \
282 void unset##Name() { \
283 auto InputData = Flags.load(); \
284 while (!Flags.compare_exchange_weak(InputData, InputData & ~Value)) { \
320 auto InputData =
Flags.load();
321 while (!
Flags.compare_exchange_weak(
322 InputData, InputData & ~(0x7 | 0x8 | 0x10 | 0x20))) {
329#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
336 getKeepTypeChildren();
342 getKeepPlainChildren();
385 return reinterpret_cast<std::atomic<uint64_t> *
>(&OutDieOffsetArray[Idx])
392 return reinterpret_cast<std::atomic<TypeEntry *> *
>(&TypeEntries[Idx])
399 return reinterpret_cast<std::atomic<uint64_t> *
>(
407 return reinterpret_cast<std::atomic<TypeEntry *> *
>(
415 reinterpret_cast<std::atomic<uint64_t> *
>(&OutDieOffsetArray[Idx])
422 reinterpret_cast<std::atomic<TypeEntry *> *
>(&TypeEntries[Idx])
430 reinterpret_cast<std::atomic<TypeEntry *> *
>(
438 std::optional<uint64_t>
getLowPc()
const {
return LowPc; }
454 std::optional<UnitEntryPairTy>
458 std::optional<UnitEntryPairTy>
481 StmtSeqListAttributes.push_back({
V, InputStmtSeqOffset});
486 cloneAndEmit(std::optional<std::reference_wrapper<const Triple>> TargetTriple,
500 std::pair<DIE *, TypeEntry *>
503 std::optional<int64_t> FuncAddressAdjustment,
504 std::optional<int64_t> VarAddressAdjustment,
506 uint32_t SiblingOrdinal = std::numeric_limits<uint32_t>::max());
515 std::optional<int64_t> VarAddressAdjustment,
520 return DebugAddrIndexMap.getValueIndex(Addr);
524 std::optional<std::pair<StringRef, StringRef>>
528 std::optional<std::pair<StringRef, StringRef>>
537 assert(OrigUnit !=
nullptr);
543 assert(OrigUnit !=
nullptr);
544 return OrigUnit->getFirstChildEntry(Die);
549 assert(OrigUnit !=
nullptr);
550 return OrigUnit->getSiblingEntry(Die);
554 assert(OrigUnit !=
nullptr);
555 return OrigUnit->getParent(Die);
559 assert(OrigUnit !=
nullptr);
560 return OrigUnit->getDIEAtIndex(Index);
564 assert(OrigUnit !=
nullptr);
565 return OrigUnit->getDebugInfoEntry(Index);
569 assert(OrigUnit !=
nullptr);
570 return OrigUnit->getUnitDIE(ExtractUnitDIEOnly);
574 assert(OrigUnit !=
nullptr);
579 assert(OrigUnit !=
nullptr);
580 return OrigUnit->getDIEIndex(Die);
584 assert(OrigUnit !=
nullptr);
585 return OrigUnit->getDIEIndex(Die);
590 assert(OrigUnit !=
nullptr);
591 return find(OrigUnit->getDebugInfoEntry(DieIdx), Attrs);
600 for (
auto Attr : Attrs) {
601 if (
auto Value = AbbrevDecl->getAttributeValue(Die->
getOffset(), Attr,
610 return OrigUnit->getDIEIndexForOffset(
Offset);
630 if (DieEntry !=
nullptr) {
653 AcceleratorRecords.add(Info);
659 AcceleratorRecords.forEach(Handler);
688 bool IsODRUnavailableFunctionScope);
690 struct LinkedLocationExpressionsWithOffsetPatches {
694 using LinkedLocationExpressionsVector =
705 const LinkedLocationExpressionsVector &LinkedLocationExpression,
709 Error emitDebugAddrSection();
722 void emitRangeListFragment(
const AddressRanges &LinkedRanges,
732 std::vector<DWARFDebugLine::Row> &Rows,
742 std::vector<DWARFDebugLine::Row> &NewRows,
754 void patchStmtSeqAttributes(
770 uint64_t OffsetToMacroTable,
bool hasDWARFv5Header);
773 DIE *createPlainDIEandCloneAttributes(
775 uint64_t &OutOffset, std::optional<int64_t> &FuncAddressAdjustment,
776 std::optional<int64_t> &VarAddressAdjustment);
780 TypeEntry *createTypeDIEandCloneAttributes(
788 bool IsDeclaration,
bool IsParentDeclaration);
801 std::optional<uint16_t> Language;
805 struct PendingSwiftInterface {
809 std::string ResolvedPath;
819 ResolvedPathsMap ResolvedFullPaths;
825 std::unique_ptr<DependencyTracker> Dependencies;
832 std::optional<uint64_t> LowPc;
839 uint64_t Priority = std::numeric_limits<uint64_t>::max();
845 std::mutex RangesMutex;
857 struct StmtSeqPatch {
861 SmallVector<StmtSeqPatch, 4> StmtSeqListAttributes;
862 std::mutex LabelsMutex;
865 std::atomic<Stage>
Stage;
869 SmallVector<uint64_t> OutDieOffsetArray;
873 ArrayList<AccelInfo> AcceleratorRecords;
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Mark last scratch load
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Branch Probability Basic Block Placement
The AddressRanges class helps normalize address range collections.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
A structured debug information entry.
DWARFDebugInfoEntry - A DIE with only the minimum required data.
uint64_t getOffset() const
const DWARFAbbreviationDeclaration * getAbbreviationDeclarationPtr() const
Utility class that carries the DWARF compile/type unit and the debug info entry in an object.
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const
Return the index of a Die entry inside the unit's DIE vector.
Base class for error info classes.
Lightweight error class with error context and mandatory checking.
Class representing an expression and its matching format.
A discriminated union of two or more pointer types, with the discriminator in the low bits of the poi...
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",...
Represent a constant reference to a string, i.e.
Triple - Helper class for working with autoconf configuration names.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
LLVM Value Representation.
This class represents DWARF information for source file and it's address map.
std::map< std::string, std::string > SwiftInterfacesMapTy
This class stores values sequentually and assigns index to the each value.
TypeUnit * getAsTypeUnit()
Returns TypeUnit if applicable.
DwarfUnit * operator->()
Accessor for common functionality.
PointerUnion< CompileUnit *, TypeUnit * > Ptr
CompileUnit * getAsCompileUnit()
Returns CompileUnit if applicable.
OutputUnitVariantPtr(CompileUnit *U)
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.
void collectLiveRoots()
Search for subprograms and variables referencing live code.
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, uint32_t SiblingOrdinal=std::numeric_limits< uint32_t >::max())
void cleanupDataAfterClonning()
Cleanup unneeded resources after compile unit is cloned.
Error assignTypeNames(TypePool &TypePoolRef)
Search for type entries and assign names.
llvm::Error setPriority(uint64_t ObjFileIdx, uint64_t LocalIdx)
Set deterministic priority for type DIE allocation ordering.
uint64_t getHighPc() const
Returns value of DW_AT_high_pc attribute.
void noteModuleAnchors()
Must run while the output offsets are still available, and once they are final.
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)
const DWARFFile & getContainingFile() const
Returns DWARFFile containing this compile unit.
void analyzeDWARFStructure()
Navigate DWARF tree and set die properties.
Error cloneAndEmitRanges()
Clone and emit ranges.
void mergeSwiftInterfaces(DWARFLinkerBase::SwiftInterfacesMapTy &Map)
Merge the Swift interface entries collected by analyzeImportedModule into Map, emitting a warning for...
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.
bool resolveDependenciesAndMarkLiveness(bool InterCUProcessingStarted, std::atomic< bool > &HasNewInterconnectedCUs)
Discover the DIEs the live roots depend on.
std::optional< uint16_t > getLanguage() const
Returns raw DW_AT_language of the input compile unit.
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.
void noteStmtSeqListAttribute(DIEValue *V, uint64_t InputStmtSeqOffset)
Record that a DW_AT_LLVM_stmt_sequence attribute on this unit references the input line-table sequenc...
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.
@ Cloned
Output DWARF is generated.
@ TypeNamesAssigned
Type names assigned to DIEs.
@ LiveRootsCollected
DIEs with a live address are found.
@ CreatedNotLoaded
Created, linked with input DWARF file.
@ PatchesUpdated
Offsets inside patch records are updated.
@ Cleaned
Resources(Input DWARF, Output DWARF tree) are released.
@ Loaded
Input DWARF is loaded.
@ LivenessAnalysisDone
Input DWARF is analysed(DIEs pointing to the real code section and theDIEs they depend on are marked)...
@ UpdateDependenciesCompleteness
Check if dependencies have incompatible placement.
@ Skipped
Compile Unit should be skipped.
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.
void loadLineTable()
Loads unit line table.
bool getModulePath(const DWARFDebugInfoEntry *DieEntry, SmallVectorImpl< char > &Path)
Appends the names of the DW_TAG_module enclosing DieEntry, outermost first.
uint64_t getPriority() const
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.
LinkingGlobalData & GlobalData
The helper class to build type name based on DIE properties.
Keeps cloned data for the type DIE.
TypePool keeps type descriptors which contain partially cloned DIE correspinding to each type.
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 getDIEAtIndex(unsigned Index)
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)
function_ref< CompileUnit *(uint64_t Offset)> OffsetToUnitTy
SmallVector< uint64_t * > OffsetsPtrVector
Type for list of pointers to patches offsets.
StringMapEntry< std::atomic< TypeEntryBody * > > TypeEntry
ArrayRef< dwarf::Attribute > getODRAttributes()
ResolveInterCUReferencesMode
DebugSectionKind
List of tracked debug tables.
LLVM_ABI void buildStmtSeqOffsetToFirstRowIndex(const DWARFDebugLine::LineTable <, ArrayRef< uint64_t > SortedStmtSeqOffsets, DenseMap< uint64_t, uint64_t > &SeqOffToFirstRow)
Build a map from an input DW_AT_LLVM_stmt_sequence byte offset to the first-row index (in LT....
StringMapEntry< EmptyStringSetTag > StringEntry
StringEntry keeps data of the string: the length, external offset and a string body which is placed r...
AddressRangesMap RangesTy
Mapped value in the address map is the offset to apply to the linked address.
This is an optimization pass for GlobalISel generic memory operations.
void handleAllErrors(Error E, HandlerTs &&... Handlers)
Behaves the same as handleErrors, except that by contract all errors must be handled by the given han...
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.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
ArrayRef(const T &OneElt) -> ArrayRef< T >
BumpPtrAllocatorImpl<> BumpPtrAllocator
The standard BumpPtrAllocator which just uses the default template parameters.
@ Keep
No function return thunk.
Represents a single DWARF expression, whose value is location-dependent.
Information gathered and exchanged between the various clone*Attr helpers about the attributes of a p...
Information gathered about source DIEs.
LLVM_DUMP_METHOD void dump()
void setPlacement(DieOutputPlacement Placement)
Sets Placement kind for the corresponding die.
bool needToKeepInPlainDwarf() const
std::atomic< uint16_t > Flags
Data member keeping various flags.
bool needToPlaceInTypeTable() const
void joinVariablePlacement(DieOutputPlacement Placement)
Atomically joins Placement for a DW_TAG_variable, for which PlainDwarf is absorbing because a variabl...
DieOutputPlacement getPlacement() const
void unsetPlacement()
Unsets Placement kind for the corresponding die.
bool setPlacementIfUnset(DieOutputPlacement Placement)
Sets Placement kind for the corresponding die.
DIEInfo & operator=(const DIEInfo &Other)
void joinPlacement(DieOutputPlacement Placement)
Atomically joins Placement into the current placement: the least-upper-bound of the lattice NotSet < ...
void unsetFlagsWhichSetDuringLiveAnalysis()
DIE is a part of the linked output.
DIEInfo(const DIEInfo &Other)
void eraseData()
Erase all flags.
This structure keeps fields which would be used for creating accelerator table.
This structure is used to keep data of the concrete section.
UnitEntryPairTy()=default
UnitEntryPairTy(CompileUnit *CU, const DWARFDebugInfoEntry *DieEntry)
std::optional< UnitEntryPairTy > getParent()
UnitEntryPairTy getNamespaceOrigin()
const DWARFDebugInfoEntry * DieEntry