9#ifndef LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
10#define LLVM_LIB_DWARFLINKERPARALLEL_DWARFLINKERCOMPILEUNIT_H
18namespace dwarflinker_parallel {
70 OrigUnit(&OrigUnit), getUnitFromOffset(UnitFromOffset),
167 auto InputData =
Flags.load();
168 while (!
Flags.compare_exchange_weak(InputData,
175 auto InputData =
Flags.load();
176 while (!
Flags.compare_exchange_weak(InputData, (InputData & ~0x7))) {
182 auto InputData =
Flags.load();
183 if ((InputData & 0x7) ==
NotSet)
184 if (
Flags.compare_exchange_weak(InputData, (InputData |
Placement)))
190#define SINGLE_FLAG_METHODS_SET(Name, Value) \
191 bool get##Name() const { return Flags & Value; } \
193 auto InputData = Flags.load(); \
194 while (!Flags.compare_exchange_weak(InputData, InputData | Value)) { \
197 void unset##Name() { \
198 auto InputData = Flags.load(); \
199 while (!Flags.compare_exchange_weak(InputData, InputData & ~Value)) { \
219 auto InputData =
Flags.load();
220 while (!
Flags.compare_exchange_weak(
221 InputData, InputData & ~(0x7 | 0x8 | 0x10 | 0x20))) {
228#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
272 return reinterpret_cast<std::atomic<uint64_t> *
>(&OutDieOffsetArray[
Idx])
279 reinterpret_cast<std::atomic<uint64_t> *
>(&OutDieOffsetArray[
Idx])
286 std::optional<uint64_t>
getLowPc()
const {
return LowPc; }
302 std::optional<std::pair<CompileUnit *, uint32_t>>
328 std::optional<int64_t> FuncAddressAdjustment,
329 std::optional<int64_t> VarAddressAdjustment,
339 std::optional<int64_t> VarAddressAdjustment,
349 return DebugStringIndexMap.getValueIndex(
String);
358 assert(OrigUnit !=
nullptr);
364 assert(OrigUnit !=
nullptr);
370 assert(OrigUnit !=
nullptr);
375 assert(OrigUnit !=
nullptr);
380 assert(OrigUnit !=
nullptr);
385 assert(OrigUnit !=
nullptr);
390 assert(OrigUnit !=
nullptr);
391 return OrigUnit->
getUnitDIE(ExtractUnitDIEOnly);
395 assert(OrigUnit !=
nullptr);
400 assert(OrigUnit !=
nullptr);
405 assert(OrigUnit !=
nullptr);
411 assert(OrigUnit !=
nullptr);
421 for (
auto Attr : Attrs) {
422 if (
auto Value = AbbrevDecl->getAttributeValue(Die->
getOffset(), Attr,
451 if (DieEntry !=
nullptr) {
475 bool IsInModule,
bool IsInFunction);
477 struct LinkedLocationExpressionsWithOffsetPatches {
481 using LinkedLocationExpressionsVector =
488 uint64_t emitLocListHeader(SectionDescriptor &OutLocationSection);
492 const LinkedLocationExpressionsVector &LinkedLocationExpression,
493 SectionDescriptor &OutLocationSection);
496 Error emitDebugAddrSection();
499 Error emitDebugStringOffsetSection();
509 uint64_t emitRangeListHeader(SectionDescriptor &OutRangeSection);
512 void emitRangeListFragment(
const AddressRanges &LinkedRanges,
513 SectionDescriptor &OutRangeSection);
517 void insertLineSequence(std::vector<DWARFDebugLine::Row> &Seq,
518 std::vector<DWARFDebugLine::Row> &Rows);
522 uint64_t OffsetToMacroTable,
bool hasDWARFv5Header);
526 uint64_t OutOffset, AttributesInfo &AttrInfo);
530 uint64_t OutOffset, AttributesInfo &AttrInfo);
544 ResolvedPathsMap ResolvedFullPaths;
548 IndexedValuesMap<uint64_t> DebugAddrIndexMap;
551 IndexedValuesMap<const StringEntry *> DebugStringIndexMap;
558 std::optional<uint64_t> LowPc;
565 std::mutex RangesMutex;
569 std::mutex LabelsMutex;
572 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.
std::optional< DWARFFormValue > find(dwarf::Attribute Attr) const
Extract the specified attribute from this DIE.
const char * getName(DINameKind Kind) const
Return the DIE name resolving DW_AT_specification or DW_AT_abstract_origin references if necessary.
This class represents DWARF information for source file and its address map.
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.
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.
std::string str() const
str - Get the contents as an std::string.
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.
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:...
uint64_t getDebugStrIndex(const StringEntry *String)
Returns index(inside .debug_str_offsets) of specified string.
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.
@ 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,...
uint64_t getHighPc() const
Returns value of DW_AT_high_pc attribute.
void cleanupDataAfterClonning()
Cleanup unneeded resources after compile unit is cloned.
DieOutputPlacement
Kinds of placement for the output die.
@ Parent
Corresponding DIE needs to examine parent to determine the point of placement.
@ 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.
Error cloneAndEmit(std::optional< Triple > TargetTriple)
Clone and emit this compilation unit.
CompileUnit(LinkingGlobalData &GlobalData, DWARFUnit &OrigUnit, unsigned ID, StringRef ClangModuleName, DWARFFile &File, OffsetToUnitTy UnitFromOffset, dwarf::FormParams Format, support::endianness Endianess)
void addFunctionRange(uint64_t LowPC, uint64_t HighPC, int64_t PCOffset)
Add a function range [LowPC, HighPC) that is relocated by applying offset PCOffset.
std::optional< std::pair< CompileUnit *, uint32_t > > resolveDIEReference(const DWARFFormValue &RefValue, ResolveInterCUReferencesMode CanResolveInterCUReferences)
Resolve the DIE attribute reference that has been extracted in RefValue.
Error cloneAndEmitRanges()
Clone and emit ranges.
Stage getStage() const
Returns stage of overall processing.
const RangesTy & getFunctionRanges() const
Returns function ranges of this unit.
DIE * cloneDIE(const DWARFDebugInfoEntry *InputDieEntry, uint64_t OutOffset, std::optional< int64_t > FuncAddressAdjustment, std::optional< int64_t > VarAddressAdjustment, BumpPtrAllocator &Allocator)
void updateDieRefPatchesWithClonedOffsets()
After cloning stage the output DIEs offsets are deallocated.
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.
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.
CompileUnit(LinkingGlobalData &GlobalData, unsigned ID, StringRef ClangModuleName, DWARFFile &File, OffsetToUnitTy UnitFromOffset, dwarf::FormParams Format, support::endianness Endianess)
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 represents DWARF information for source file and it's address map.
Base class for all Dwarf units(Compile unit/Type table unit).
std::string UnitName
The name of this unit.
std::string ClangModuleName
If this is a Clang module, this holds the module's name.
StringRef getUnitName() const
Returns this unit name.
uint16_t Language
The DW_AT_language of this unit.
std::string SysRoot
The DW_AT_LLVM_sysroot of this unit.
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
void setOutputFormat(dwarf::FormParams Format, support::endianness Endianness)
Sets output format for all keeping sections.
dwarf::FormParams Format
Format for sections.
uint64_t getDieOutOffset(uint32_t Idx)
Idx index of the DIE.
DIEInfo & getDIEInfo(const DWARFDebugInfoEntry *Entry)
Idx index of the DIE.
DIEInfo & getDIEInfo(unsigned Idx)
Idx index of the DIE.
const DIEInfo & getDIEInfo(const DWARFDie &Die) const
Die
DIEInfo & getDIEInfo(const DWARFDie &Die)
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)
StringRef toStringRef(const std::optional< DWARFFormValue > &V, StringRef Default={})
Take an optional DWARFFormValue and try to extract a string value from it.
std::optional< uint64_t > toUnsigned(const std::optional< DWARFFormValue > &V)
Take an optional DWARFFormValue and try to extract an unsigned constant.
DebugSectionKind
List of tracked debug tables.
ResolveInterCUReferencesMode
function_ref< CompileUnit *(uint64_t Offset)> OffsetToUnitTy
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.
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.
This structure is used to keep data of the concrete section.