This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Make BinaryFunction::eraseInvalidBBs() thread-safe
AcceptedPublic

Authored by maksfb on Feb 13 2022, 11:15 AM.

Details

Summary

Calculation of the size of a basic block is not thread-safe, hence add a
lock.

Additionally, free CFG-related members after the deletion.

Diff Detail

Event Timeline

maksfb requested review of this revision.Feb 13 2022, 11:15 AM
maksfb created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 13 2022, 11:15 AM

Is there a reason now to keep the DeletedBasicBlocks list at all?

Is there a reason now to keep the DeletedBasicBlocks list at all?

These blocks are still referenced from BasicBlockOffsets that is used for debug info updates, so we cannot delete them until the function is destroyed.

yota9 accepted this revision.Feb 14 2022, 9:12 AM

@maksfb I see, thanks for explanation!

This revision is now accepted and ready to land.Feb 14 2022, 9:12 AM
yota9 added inline comments.Feb 14 2022, 9:22 AM
bolt/lib/Core/BinaryFunction.cpp
352

Maybe move lock under estimateSize()?

Amir added inline comments.Feb 14 2022, 10:45 AM
bolt/lib/Core/BinaryFunction.cpp
352

BB->estimateSize is called from two more places:

  • ExtTSPReorderAlgorithm
  • ReorderAlgorithm

which operate with an IndependentCodeEmitter and don't need locks.

yota9 added inline comments.Feb 14 2022, 10:54 AM
bolt/lib/Core/BinaryFunction.cpp
352

Than it might be lock under condition. I just feel that it is not the best place. The estimateSize might be used in other places, e.g. the passes like golang support and longjmp. And we will need to think about locking each time in each place. Anyway I don't insist on this :)