Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug string move #5407

Draft
wants to merge 13 commits into
base: experimental/cas/main
Choose a base branch
from
2 changes: 1 addition & 1 deletion llvm/include/llvm/MC/CAS/MCCASObjectV1.def
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ CASV1_SIMPLE_DATA_REF(DataInCodeRef, mc:data_in_code)
CASV1_SIMPLE_DATA_REF(CStringRef, mc:cstring)
CASV1_SIMPLE_DATA_REF(MergedFragmentRef, mc:merged_fragment)
CASV1_SIMPLE_DATA_REF(DebugStrRef, mc:debug_string)
CASV1_SIMPLE_DATA_REF(DebugInfoCURef, mc:debug_info_cu)
CASV1_SIMPLE_DATA_REF(DebugLineRef, mc:debug_line)
CASV1_SIMPLE_DATA_REF(DebugAbbrevRef, mc:debug_abbrev)
CASV1_SIMPLE_DATA_REF(DebugAbbrevOffsetsRef, mc:debug_abbrev_offsets)
Expand All @@ -33,6 +32,7 @@ CASV1_SIMPLE_GROUP_REF(GroupRef, mc:group)
CASV1_SIMPLE_GROUP_REF(SectionRef, mc:section)
CASV1_SIMPLE_GROUP_REF(DebugAbbrevSectionRef, mc:debug_abbrev_section)
CASV1_SIMPLE_GROUP_REF(DebugLineSectionRef, mc:debug_line_section)
CASV1_SIMPLE_GROUP_REF(DebugStringSectionRef, mc:debug_string_section)
CASV1_SIMPLE_GROUP_REF(AtomRef, mc:atom)
CASV1_SIMPLE_GROUP_REF(SymbolTableRef, mc:symbol_table)

Expand Down
67 changes: 60 additions & 7 deletions llvm/include/llvm/MC/CAS/MCCASObjectV1.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ class MCObjectProxy : public cas::ObjectProxy {

MCObjectProxy() = delete;

static Error encodeReferences(ArrayRef<cas::ObjectRef> Refs,
SmallVectorImpl<char> &Data,
SmallVectorImpl<cas::ObjectRef> &IDs);

static Expected<SmallVector<cas::ObjectRef>>
decodeReferences(const MCObjectProxy &Node, StringRef &Remaining);

protected:
MCObjectProxy(const MCSchema &Schema, const cas::ObjectProxy &Node)
: cas::ObjectProxy(Node), Schema(&Schema) {}
Expand Down Expand Up @@ -402,6 +409,34 @@ class MCAssemblerRef : public SpecificRef<MCAssemblerRef> {
MCAssemblerRef(SpecificRefT Ref) : SpecificRefT(Ref) {}
};

class DebugInfoCURef : public SpecificRef<DebugInfoCURef> {
using SpecificRefT = SpecificRef<DebugInfoCURef>;
friend class SpecificRef<DebugInfoCURef>;

public:
static constexpr StringLiteral KindString = "mc:debug_info_cu";
static Expected<DebugInfoCURef> create(MCCASBuilder &MB, StringRef Data,
ArrayRef<cas::ObjectRef> Refs);
static Expected<DebugInfoCURef> get(Expected<MCObjectProxy> Ref);
static Expected<DebugInfoCURef> get(const MCSchema &Schema,
cas::ObjectRef ID) {
return get(Schema.get(ID));
}
static Optional<DebugInfoCURef> Cast(MCObjectProxy Ref) {
auto Specific = SpecificRefT::Cast(Ref);
if (!Specific)
return None;
return DebugInfoCURef(*Specific);
}
Expected<uint64_t> materialize(raw_ostream &OS) const {
OS << getData();
return getData().size();
}

private:
explicit DebugInfoCURef(SpecificRefT Ref) : SpecificRefT(Ref) {}
};

struct DwarfSectionsCache {
MCSection *DebugInfo;
MCSection *Line;
Expand Down Expand Up @@ -497,6 +532,15 @@ class MCCASBuilder {
return AtomAddends;
}

Optional<cas::ObjectRef>
getObjectRefFromStringMap(unsigned StringOffset) const {
auto StringRefIt =
DebugStringSectionContents::MapOfStringRefs.find(StringOffset);
if (StringRefIt != DebugStringSectionContents::MapOfStringRefs.end())
return StringRefIt->getSecond();
return None;
}

// Scratch space
SmallString<8> FragmentData;
raw_svector_ostream FragmentOS;
Expand All @@ -510,7 +554,7 @@ class MCCASBuilder {

// Helper functions.
Error createStringSection(StringRef S,
std::function<Error(StringRef)> CreateFn);
std::function<Error(StringRef, unsigned)> CreateFn);

// If a DWARF Line Section exists, create a DebugLineRef CAS object per
// function contribution to the line table.
Expand All @@ -522,7 +566,8 @@ class MCCASBuilder {
/// A pair of vectors with the CAS objects is returned.
/// The CAS objects appear in the same order as in the object file.
/// If the section doesn't exist, an empty container is returned.
Expected<AbbrevAndDebugSplit> splitDebugInfoAndAbbrevSections();
Expected<AbbrevAndDebugSplit>
splitDebugInfoAndAbbrevSections(ArrayRef<DebugStrRef> DebugStringRefs);

/// If CURefs is non-empty, create a SectionRef CAS object with edges to all
/// CURefs. Otherwise, no objects are created and `success` is returned.
Expand All @@ -543,6 +588,13 @@ class MCCASBuilder {
splitAbbrevSection(ArrayRef<size_t> AbbrevOffsets,
ArrayRef<char> FullAbbrevData);

struct DebugStringSectionContents {
SmallVector<DebugStrRef, 0> DebugStringRefs;
static DenseMap<unsigned, cas::ObjectRef> MapOfStringRefs;
};

Expected<DebugStringSectionContents> createDebugStringRefs();

struct CUSplit {
SmallVector<MutableArrayRef<char>> SplitCUData;
SmallVector<size_t> AbbrevOffsets;
Expand All @@ -555,7 +607,7 @@ class MCCASBuilder {

// If a DWARF String section exists, create a DebugStrRef CAS object per
// string in the section.
Error createDebugStrSection();
Error createDebugStrSection(ArrayRef<DebugStrRef> DebugStringRefs);

/// If there is any padding between one section and the next, create a
/// PaddingRef CAS object to represent the bytes of Padding between the two
Expand Down Expand Up @@ -632,10 +684,11 @@ class DebugInfoSectionRef : public SpecificRef<DebugInfoSectionRef> {
return None;
return DebugInfoSectionRef(*Specific);
}
Expected<uint64_t> materialize(MCCASReader &Reader,
ArrayRef<char> AbbrevSectionContents,
ArrayRef<uint32_t> SecOffsetVals,
raw_ostream *Stream = nullptr) const;

Expected<uint64_t>
materialize(MCCASReader &Reader, ArrayRef<char> AbbrevSectionContents, ArrayRef<uint32_t> SecOffsetVals,
DenseMap<cas::ObjectRef, unsigned> &MapOfStringOffsets,
raw_ostream *Stream = nullptr) const;

private:
explicit DebugInfoSectionRef(SpecificRefT Ref) : SpecificRefT(Ref) {}
Expand Down
Loading