Skip to content

Minor cleanup in ARCSequenceOpts #33578

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 5 commits into from
Aug 25, 2020
Merged

Conversation

meg-gupta
Copy link
Contributor

This change removes some more dead code in ARCSequenceOpts. And adds more info to the LoopRegion printer

  • Removes more reference to Insertion points and NewInsts that are no longer needed in ARCSequenceOpts
  • Update bottom up loop traversal to remove some code duplication
  • Add more info in LoopRegion printer, this is useful while calling dump() utilities within the debugger

@meg-gupta meg-gupta requested review from atrick and gottesmm August 21, 2020 00:16
@meg-gupta
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - bae11c36b4dd103b977a906b7f83fac04e94125c

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - bae11c36b4dd103b977a906b7f83fac04e94125c

@meg-gupta
Copy link
Contributor Author

@swift-ci test OS X platform

@meg-gupta
Copy link
Contributor Author

@swift-ci test Linux platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - bae11c36b4dd103b977a906b7f83fac04e94125c

@meg-gupta
Copy link
Contributor Author

@swift-ci test OS X platform

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - bae11c36b4dd103b977a906b7f83fac04e94125c

@meg-gupta
Copy link
Contributor Author

@swift-ci test OS X platform

Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

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

LGTM, but I don't understand the "make bottom up traversal simpler" commit.

mergeSuccessors(Subregion, SubregionData);

// Then perform the region optimization.
NestingDetected |= SubregionData.processBottomUp(
Copy link
Contributor

@atrick atrick Aug 21, 2020

Choose a reason for hiding this comment

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

Why does the call to SubregionData.processBottomUp go away in this commit?

Nevermind, I see the other instance of processBottomUp now that I expanded the diff.

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - bae11c36b4dd103b977a906b7f83fac04e94125c

Copy link
Contributor

@gottesmm gottesmm left a comment

Choose a reason for hiding this comment

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

Some thoughts, comments, etc.

@@ -88,6 +89,19 @@ void LoopRegion::print(llvm::raw_ostream &os, bool isShort) const {

os << " ucfh:" << (IsUnknownControlFlowEdgeHead? "true " : "false")
<< " ucft:" << (IsUnknownControlFlowEdgeTail? "true " : "false");

if (isVerbose) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use early returns rather than else if? That is:

if (!verbose)
   return;

os << "\n";

if (isBlock())
  return getBlock()->dump();

if (isLoop())
  return getLoop()->dump();

if (isFunction())
  return getFunction()->dump();

llvm_unreachable("Unknown region type");

In general, else if chains like this should be eliminated through the usage of early returns like that.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes! Sorry I needed to be reminded :)

@@ -285,9 +285,6 @@ handleRefCountInstMatch(SILInstruction *RefCountInst) {
return false;
case LatticeState::Decremented:
case LatticeState::MightBeUsed:
// Unset InsertPt so we remove retain release pairs instead of
// performing code motion.
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand this change. Was there originally code here that was removed, but the comment wasn't removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, there were a lot of stale comments left out about 'InsertPt'. This code was refactored out and a lot of functionality moved to ARCCodeMotion.

if (!isARCSignificantTerminator(&cast<TermInst>(*II))) {
II++;
}
if (!isARCSignificantTerminator(&cast<TermInst>(*II))) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe put a small comment here that we know that we have a TermInst since rbegin is the last instruction in the block and we are in well-formed canonical SIL?

AA, RCFI, EAFI, LRFI, FreezeOwnedArgEpilogueReleases, IncToDecStateMap,
RegionStateInfo, SetFactory);
--End;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

@meg-gupta do you know from the history why the last iteration was originally peeled?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can't tell much from history. Maybe just an oversight that it wasn't updated with getReverseSubregions.

Copy link
Contributor

Choose a reason for hiding this comment

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

I remember why I think. I think there was a miscompile from clang with getReverseSubregions() when I wrote this. So I worked around it. Thanks for fixing!

LLVM_DEBUG(llvm::dbgs() << "Adding new interesting insts!\n");
do {
auto *I = NewInsts.pop_back_val();
LLVM_DEBUG(llvm::dbgs() << " " << *I);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just as a note to myself. The reason why this code was here was b/c we originally always performed code motion and were always rewriting all rr when making changes. The end result is that we needed to add the new instructions that we inserted to be adding to the interesting instructions inst. Since we are only removing RR now. This is not needed.

// Returns true if any of the non-local successors of the region are leaking
// blocks. We currently do not handle early exits, but do handle trapping
// blocks. Returns false if otherwise
static bool hasEarlyExits(
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice rename! Much better name! And thanks for the great comment improvement!

@@ -48,7 +48,7 @@ llvm::cl::opt<bool> EnableLoopARC("enable-loop-arc", llvm::cl::init(false));
// This routine takes in the ARCMatchingSet \p MatchSet and adds the increments
// and decrements to the delete list.
void ARCPairingContext::optimizeMatchingSet(
Copy link
Contributor

Choose a reason for hiding this comment

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

You may want to even rename this one to something more descriptive since we only delete instructions now. You could even make this a method on MatchSet. IDK, what are your thoughts.

@meg-gupta
Copy link
Contributor Author

@swift-ci smoke test

@meg-gupta meg-gupta merged commit b1c0bd3 into swiftlang:master Aug 25, 2020
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