This is an archive of the discontinued LLVM Phabricator instance.

Refactor normalization for invokes in placestatepoints pass.
ClosedPublic

Authored by igor-laevsky on May 5 2015, 7:41 AM.

Details

Reviewers
reames
Summary

This change moves basic block normalization for invokes right before replacement of a call with safepoint in "ReplaceWithStatepoint". Previously it was partly done before replacement of calls with safepoint and partly after call replacement but before RAUW's for gc_relocates, which was confusing.

Since "normalizeForInvokeSafepoint" now looks very much alike it's analog in RewriteSafepointsForGC I think it's reasonable to consider creating utility function in BasicBlockUtils.cpp

Diff Detail

Repository
rL LLVM

Event Timeline

igor-laevsky retitled this revision from to Refactor normalization for invokes in placestatepoints pass. .
igor-laevsky updated this object.
igor-laevsky edited the test plan for this revision. (Show Details)
igor-laevsky added a reviewer: reames.
igor-laevsky set the repository for this revision to rL LLVM.
igor-laevsky added a subscriber: Unknown Object (MLST).
reames requested changes to this revision.May 5 2015, 3:38 PM
reames edited edge metadata.
reames added inline comments.
lib/Transforms/Scalar/PlaceSafepoints.cpp
698

Leaving the assertion here would be good.

952

Please just do this as a preprocessing step. If the statepoint we're about to insert is for an invoke, normalize it before starting the insertion process. Having this functionality inside a function called ReplaceWithStatepoint seems misleading.

In RewriteStatepointsForGC, we have:

// When inserting gc.relocates for invokes, we need to be able to insert at
// the top of the successor blocks.  See the comment on
// normalForInvokeSafepoint on exactly what is needed.  Note that this step
// may restructure the CFG.
for (CallSite CS : toUpdate) {
  if (!CS.isInvoke())
    continue;
  InvokeInst *invoke = cast<InvokeInst>(CS.getInstruction());
  normalizeForInvokeSafepoint(invoke->getNormalDest(), invoke->getParent(),
                              P);
  normalizeForInvokeSafepoint(invoke->getUnwindDest(), invoke->getParent(),
                              P);
}

Doing that same thing before calling ReplaceWithStatepoint would seem reasonable.

This revision now requires changes to proceed.May 5 2015, 3:38 PM
igor-laevsky edited edge metadata.

Add assertion and move call to normalizeForInvokeSafepoint out from ReplaceWithStatepoint.

I specifically did not wan't to run normalizeForInvokeSafepoint in a separate loop, to make more clear that ReplaceWithStatepoint is dependent on normalizeForInvokeSafepoint being previously run.

reames accepted this revision.May 6 2015, 10:36 AM
reames edited edge metadata.

With comment corrections, LGTM.

lib/Transforms/Scalar/PlaceSafepoints.cpp
699

Comment is incorrect. gc_result, not gc_relocate.

Also, spelling: malformed.

This revision is now accepted and ready to land.May 6 2015, 10:36 AM
igor-laevsky closed this revision.May 8 2015, 5:03 AM

Committed revision 236829.