Skip to content

Re-architect MCCAS debug info section materialization to no longer be recursive or attach children DIEDataRefs to their parents #7811

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

Merged
merged 4 commits into from
Dec 19, 2023

Conversation

rastogishubham
Copy link

@rastogishubham rastogishubham commented Nov 17, 2023

With this change, the layout of the debug info section in MCCAS has been changed. Now, if there is a DIE that can be split off into it's own CAS block, we do not attach it to its parent CAS block as a reference, it gets added as a neighbor instead. This reduces the dependencies between CAS blocks and increases chances of deduplication if a DIEDataRef doesn't dedupe, by making sure it's parent will still dedupe.

This change also re-writes the materialization of the debug info section to be iterative, rather than recursive.

It also introduces the new cas block DIEDedupeTopLevelRef

The results of this work give us a cleaner instruments trace which enabled us to identify the function visitDIEAttrs as a place we could optimize MCCAS replay

@rastogishubham rastogishubham marked this pull request as ready for review December 2, 2023 00:23
@rastogishubham rastogishubham changed the title Add an experimental change to MCCAS, use iteration instead of recursion Re-architect MCCAS debug info section materialization to no longer be recursive or attach children DIEDataRefs to their parents Dec 2, 2023
@rastogishubham rastogishubham force-pushed the ExperimentMCCAS branch 3 times, most recently from 2158b92 to cbea924 Compare December 9, 2023 23:10
@felipepiovezan felipepiovezan self-requested a review December 11, 2023 21:41
Copy link

@felipepiovezan felipepiovezan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So I still think we would benefit a lot from a simpler while loop, and I spent some time trying to figure out if this is feasiable. As you know better than I do, the devil is in the details, so I tried to be pretty thoughtful here. If you don't think this is possibe, that's fine, but what do you think of this algorithm?

(btw, you are right about the need to push the "data" into the stack as well as the reader, the visitDIEAttrs need to "peek" into the data, and the stream class doesn't give us access to it)

// DIEData == ArrayRef<StringRef>

BinaryStreamReader Reader(DIEData[0], /*offset*/ 0);
stack.push({Reader, DIEData[0]});
DIEData = DIEData.drop_front();

while(!stack.empty() {

  auto AbbrevIdx = DistinctReader.read_abbrev();

  if (AbbrevIdx == getDIEInAnotherBlockMarker()) {
    NewBlockCallback (...)
    BinaryStreamReader Reader(DIEData[0], /*offset*/ 0);
    stack.push(Reader, DIEData[0]);
    DIEData = DIEData.drop_front();
    continue;
  }

  auto CurrentReader, CurrentData = stack.pop_back_val();

  if (AbbrevIdx == getEndOfDIESiblingsMarker())
    EndTagCallback(true /*had children*/);
  else {
    AbbrevReader = get abbrev reader for AbbrevIdx;
    Tag = AbbrevReader.readTag();
    StartTagCallback(*MaybeTag, AbbrevIdx);
    visitDIEAttrs(AbbrevReader, CurrentReader, CurrentData))
    if (!AbbrevReader.HasChildren)
      EndTagCallback(false /*had children*/);
  }

  // Reached the end of a DIE, if this reader still has data in it, push it.
  if (!CurrentReader.empty())
    stack.push({CurrentReader, CurrentData});
}

DIEDedupeTopLevelRef is a CAS block that holds no data and has
references to DIEDataRef CAS blocks. This makes it easy to check that a
DIETopLevelRef in a CAS is valid, as it should only have 3 references to
it, a DIEDedupeTopLevelRef, a DIEAbbrevSetRef, and a DIEDistinctDataRef
With this change, the layout of the debug info section in MCCAS has been
changed. Now, if there is a DIE that can be split off into it's own
CAS block, we do not attach it to its parent CAS block as a reference,
it gets added as a neighbor instead. This reduces the dependencies
between CAS blocks and increases chances of deduplication if a
DIEDataRef doesn't dedupe, by making sure it's parent will still dedupe.

This change also re-writes the materialization of the debug info section
to be iterative, rather than recursive.
@rastogishubham
Copy link
Author

@swift-ci please test

@rastogishubham
Copy link
Author

@swift-ci please test llvm

1 similar comment
@rastogishubham
Copy link
Author

@swift-ci please test llvm

@rastogishubham rastogishubham merged commit 2798633 into swiftlang:next Dec 19, 2023
@yoki31
Copy link

yoki31 commented Dec 19, 2023

Ok thank you I go to home GitHub

rastogishubham added a commit that referenced this pull request Dec 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants