9#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
10#define LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
17namespace dwarflinker_parallel {
40 std::optional<UnitEntryPairTy>
getParent();
140 bool InterCUProcessingStarted,
141 std::atomic<bool> &HasNewInterconnectedCUs);
186 auto InputData =
Flags.load();
187 while (!
Flags.compare_exchange_weak(InputData,
194 auto InputData =
Flags.load();
195 while (!
Flags.compare_exchange_weak(InputData, (InputData & ~0x7))) {
201 auto InputData =
Flags.load();
202 if ((InputData & 0x7) ==
NotSet)
203 if (
Flags.compare_exchange_weak(InputData, (InputData |
Placement)))
209#define SINGLE_FLAG_METHODS_SET(Name, Value) \
210 bool get##Name() const { return Flags & Value; } \
212 auto InputData = Flags.load(); \
213 while (!Flags.compare_exchange_weak(InputData, InputData | Value)) { \
216 void unset##Name() { \
217 auto InputData = Flags.load(); \
218 while (!Flags.compare_exchange_weak(InputData, InputData & ~Value)) { \
250 auto InputData =
Flags.load();
251 while (!
Flags.compare_exchange_weak(
252 InputData, InputData & ~(0x7 | 0x8 | 0x10 | 0x20))) {
259#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
266 getKeepTypeChildren();
272 getKeepPlainChildren();
315 return reinterpret_cast<std::atomic<uint64_t> *
>(&OutDieOffsetArray[
Idx])
322 return reinterpret_cast<std::atomic<TypeEntry *> *
>(&TypeEntries[
Idx])
329 return reinterpret_cast<std::atomic<uint64_t> *
>(
337 return reinterpret_cast<std::atomic<TypeEntry *> *
>(
345 reinterpret_cast<std::atomic<uint64_t> *
>(&OutDieOffsetArray[
Idx])
352 reinterpret_cast<std::atomic<TypeEntry *> *
>(&TypeEntries[
Idx])
360 reinterpret_cast<std::atomic<TypeEntry *> *
>(
368 std::optional<uint64_t>
getLowPc()
const {
return LowPc; }
384 std::optional<UnitEntryPairTy>
388 std::optional<UnitEntryPairTy>
416 std::pair<DIE *, TypeEntry *>
419 std::optional<int64_t> FuncAddressAdjustment,
420 std::optional<int64_t> VarAddressAdjustment,
430 std::optional<int64_t> VarAddressAdjustment,
439 std::optional<std::pair<StringRef, StringRef>>
443 std::optional<std::pair<StringRef, StringRef>>
452 assert(OrigUnit !=
nullptr);
458 assert(OrigUnit !=
nullptr);
464 assert(OrigUnit !=
nullptr);
469 assert(OrigUnit !=
nullptr);
474 assert(OrigUnit !=
nullptr);
479 assert(OrigUnit !=
nullptr);
484 assert(OrigUnit !=
nullptr);
485 return OrigUnit->
getUnitDIE(ExtractUnitDIEOnly);
489 assert(OrigUnit !=
nullptr);
494 assert(OrigUnit !=
nullptr);
499 assert(OrigUnit !=
nullptr);
505 assert(OrigUnit !=
nullptr);
515 for (
auto Attr : Attrs) {
516 if (
auto Value = AbbrevDecl->getAttributeValue(Die->
getOffset(), Attr,
545 if (DieEntry !=
nullptr) {
574 AcceleratorRecords.
forEach(Handler);
603 bool IsODRUnavailableFunctionScope);
605 struct LinkedLocationExpressionsWithOffsetPatches {
609 using LinkedLocationExpressionsVector =
620 const LinkedLocationExpressionsVector &LinkedLocationExpression,
624 Error emitDebugAddrSection();
637 void emitRangeListFragment(
const AddressRanges &LinkedRanges,
642 void insertLineSequence(std::vector<DWARFDebugLine::Row> &Seq,
643 std::vector<DWARFDebugLine::Row> &Rows);
647 uint64_t OffsetToMacroTable,
bool hasDWARFv5Header);
650 DIE *createPlainDIEandCloneAttributes(
652 uint64_t &OutOffset, std::optional<int64_t> &FuncAddressAdjustment,
653 std::optional<int64_t> &VarAddressAdjustment);
656 TypeEntry *createTypeDIEandCloneAttributes(
663 bool IsDeclaration,
bool IsParentDeclaration);
676 std::optional<uint16_t> Language;
684 ResolvedPathsMap ResolvedFullPaths;
690 std::unique_ptr<DependencyTracker> Dependencies;
697 std::optional<uint64_t> LowPc;
707 std::mutex RangesMutex;
712 std::mutex LabelsMutex;
715 std::atomic<Stage>
Stage;
Analysis containing CSE Info
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
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
Branch Probability Basic Block Placement
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),...
Allocate memory in an ever growing pool, as if by bump-pointer.
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.
const DWARFDebugInfoEntry * getDebugInfoEntry(unsigned Index) const
Return DWARFDebugInfoEntry for the specified index Index.
const DWARFDebugInfoEntry * getSiblingEntry(const DWARFDebugInfoEntry *Die) const
DWARFDie getUnitDIE(bool ExtractUnitDIEOnly=true)
DWARFDie getParent(const DWARFDebugInfoEntry *Die)
std::optional< uint32_t > getDIEIndexForOffset(uint64_t Offset)
Return the DIE index for a given offset Offset inside the unit's DIE vector.
uint32_t getDIEIndex(const DWARFDebugInfoEntry *Die) const
Return the index of a Die entry inside the unit's DIE vector.
const DWARFDebugInfoEntry * getFirstChildEntry(const DWARFDebugInfoEntry *Die) const
DWARFDie getDIEAtIndex(unsigned Index)
Return the DIE object at the given index Index.
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
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 bit of the poin...
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
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",...
StringRef - 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 is a simple list of T structures.
T & add(const T &Item)
Add specified Item to the list.
void forEach(ItemHandlerTy Handler)
Enumerate all items and apply specified Handler to each.
TypeUnit * getAsTypeUnit()
Returns TypeUnit if applicable.
DwarfUnit * operator->()
Accessor for common functionality.
PointerUnion< CompileUnit *, TypeUnit * > Ptr
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.
@ Cloned
Output DWARF is generated.
@ 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.
@ Loaded
Input DWARF is loaded.
@ 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.
void loadLineTable()
Loads unit line table.
Error cloneAndEmitLineTable(Triple &TargetTriple)
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 represents DWARF information for source file and it's address map.
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.
uint64_t getValueIndex(T Value)
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.
LinkingGlobalData & GlobalData
dwarf::FormParams Format
Format for sections.
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.
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
DWARFDie getDIEAtIndex(unsigned Index)
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)
DebugSectionKind
List of tracked debug tables.
ResolveInterCUReferencesMode
ArrayRef< dwarf::Attribute > getODRAttributes()
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...
@ 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.
bool needToKeepInPlainDwarf() const
LLVM_DUMP_METHOD void dump()
void unsetPlacement()
Unsets Placement kind for the corresponding die.
DieOutputPlacement getPlacement() const
bool setPlacementIfUnset(DieOutputPlacement Placement)
Sets Placement kind for the corresponding die.
DIEInfo & operator=(const DIEInfo &Other)
void eraseData()
Erase all flags.
void unsetFlagsWhichSetDuringLiveAnalysis()
DIE is a part of the linked output.
DIEInfo(const DIEInfo &Other)
void setPlacement(DieOutputPlacement Placement)
Sets Placement kind for the corresponding die.
std::atomic< uint16_t > Flags
Data member keeping various flags.
bool needToPlaceInTypeTable() const
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.
const DWARFDebugInfoEntry * DieEntry
UnitEntryPairTy()=default
UnitEntryPairTy(CompileUnit *CU, const DWARFDebugInfoEntry *DieEntry)
std::optional< UnitEntryPairTy > getParent()
UnitEntryPairTy getNamespaceOrigin()