This is an archive of the discontinued LLVM Phabricator instance.

Replace all weight-based interfaces in MBB with probability-based interfaces, and update all uses of old interfaces.
ClosedPublic

Authored by congh on Nov 24 2015, 4:25 PM.

Details

Summary

The patch in http://reviews.llvm.org/D13745 is broken into four parts:

  1. New interfaces without functional changes (http://reviews.llvm.org/D13908).
  2. Use new interfaces in SelectionDAG, while in other passes treat probabilities as weights (http://reviews.llvm.org/D14361).
  3. Use new interfaces in all other passes.
  4. Remove old interfaces.

This patch is 3+4 above. In this patch, MBB won't provide weight-based interfaces any more, which are totally replaced by probability-based ones. The interface addSuccessor() is redesigned so that the default probability is unknown. We allow unknown probabilities but don't allow using it together with known probabilities in successor list. That is to say, we either have a list of successors with all known probabilities, or all unknown probabilities. In the latter case, we assume each successor has 1/N probability where N is the number of successors. An assertion checks if the user is attempting to add a successor with the disallowed mix use as stated above. This can help us catch many misuses.

All uses of weight-based interfaces are now updated to use probability-based ones.

Diff Detail

Repository
rL LLVM

Event Timeline

congh updated this revision to Diff 41097.Nov 24 2015, 4:25 PM
congh retitled this revision from to Replace all weight-based interfaces in MBB with probability-based interfaces, and update all uses of old interfaces..
congh updated this object.
congh added reviewers: davidxl, manmanren, dexonsmith.
congh added a subscriber: llvm-commits.
davidxl added inline comments.Nov 25 2015, 11:55 AM
include/llvm/CodeGen/MachineBasicBlock.h
439 ↗(On Diff #41097)

We don't ... --> Mixing ... is not allowed.

440 ↗(On Diff #41097)

We return ... ---> 1/N is returned ...

include/llvm/CodeGen/MachineBranchProbabilityInfo.h
62 ↗(On Diff #41097)

Same as above,

lib/CodeGen/BranchFolding.cpp
1107 ↗(On Diff #41097)

I remembered we talked about adding a new constructor interface in BranchProbablity to take 64 bit integer arguments -- or replace the 32bit version. The handling of overflow in intermediate step should be handled in BP -- otherwise each client will need to deal with the overflow and scaling which is not desirable.

lib/CodeGen/IfConversion.cpp
1247 ↗(On Diff #41097)

Is it cleaner to move this after NewFalseBB is computed?

After NewNext and NewFalse are computed, do

BBI.BB->addSuccessor (... , NewFalse);
BBI.BB->setSuccProbability(NewTrueBB, NewNext)

lib/CodeGen/MachineBranchProbabilityInfo.cpp
31 ↗(On Diff #41097)

It is not safe to keep this interface -- it gives user an impression that weight can be compared across edges with different Src BBs. Why not just change clients to use BP directly?

congh marked 3 inline comments as done.Nov 25 2015, 1:24 PM

Thanks for the review!

lib/CodeGen/BranchFolding.cpp
1107 ↗(On Diff #41097)

OK. I agree. I have added a static method in BP to build a BP from 64-bit integers.

lib/CodeGen/IfConversion.cpp
1247 ↗(On Diff #41097)

Yes, this is much cleaner. Updated.

lib/CodeGen/MachineBranchProbabilityInfo.cpp
31 ↗(On Diff #41097)

This interface is still used by BFI to calculate frequencies. Once we replace all weights by probabilities in BFI (on IR level) we can safely remove those two interfaces.

congh updated this revision to Diff 41179.Nov 25 2015, 1:31 PM
congh edited edge metadata.

Update the patch according to David's comment.

congh updated this revision to Diff 41181.Nov 25 2015, 1:43 PM

Fixed a bug.

davidxl added inline comments.Nov 30 2015, 2:42 PM
include/llvm/Support/BranchProbability.h
57 ↗(On Diff #41181)

It is better to remove 64 suffix in the name here.

lib/CodeGen/IfConversion.cpp
1246 ↗(On Diff #41181)

it is better to move this closer to addSuccessor call .

1249 ↗(On Diff #41181)

// NewNext = New_Prob(....) =

1252 ↗(On Diff #41181)

// NewFalse = New_Prob(...) =

congh updated this revision to Diff 41440.Nov 30 2015, 2:56 PM
congh marked 4 inline comments as done.

Update the patch according to David's comments.

davidxl accepted this revision.Nov 30 2015, 3:13 PM
davidxl edited edge metadata.
This revision is now accepted and ready to land.Nov 30 2015, 3:13 PM
congh added a comment.Nov 30 2015, 3:23 PM

Thanks for the review!

This revision was automatically updated to reflect the committed changes.