This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Skip the validation of CFG after it is finalized
ClosedPublic

Authored by Kepontry on Sep 3 2023, 5:37 AM.

Details

Summary

When current state is CFG_Finalized, function validateCFG() should return true directly.

Diff Detail

Event Timeline

Kepontry created this revision.Sep 3 2023, 5:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 3 2023, 5:37 AM
Kepontry requested review of this revision.Sep 3 2023, 5:37 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 3 2023, 5:37 AM

In the validateSuccessorInvariants function, we validate the correspondence between the number of successors and the type of branching instruction. An error is triggered when an instruction is an unconditional branch and has no successors.

When there is a "b _ZdlPvm@PLT" TailCall instruction at the end of a basic block. This instruction jumps to the PLT table, and does not have any successors. Although this instruction is an unconditional jump, the function “isUnconditionalBranch” returns false because the inst is a TailCall and doesn’t need CFG validation.

However, when the “inst-lowering” Pass is applied, the lowerTailCall function is invoked, removing the “kTailCall” label from this instruction. Consequently, the isTailCall(Inst) function returns true, which then leads to an error during the CFG validation of this instruction.

Kepontry edited the summary of this revision. (Show Details)Sep 3 2023, 5:39 AM
yota9 accepted this revision.Sep 3 2023, 5:39 AM

Agree, it was bothering me a long time ago :) LGTM, let's wait for meta team opinion

This revision is now accepted and ready to land.Sep 3 2023, 5:39 AM

Any suggestions from the Meta team?
:-)

I agree that we shouldn't validate CFG after the instruction lowering pass. Thanks for the fix and for providing the explanation.

Implementation-wise, I think we should make the validation requirement even stronger. Once a CFG is finalized, i.e. a function is in CFG_Finalized state, we should skip the check. You can simply return true from validateCFG().

@Kepontry, if you already have a test case, could you please add it?

Kepontry updated this revision to Diff 556859.Sep 15 2023, 8:16 AM
Kepontry retitled this revision from [BOLT] skip CFG verification after the 'inst-lowering' Pass to [BOLT] Skip the validation of CFG after it is finalized.
Kepontry edited the summary of this revision. (Show Details)
maksfb accepted this revision.Sep 15 2023, 1:00 PM

Thanks!

bolt/lib/Core/BinaryFunction.cpp
3160–3162

nit: drop curly braces.

Kepontry accepted this revision.Sep 15 2023, 7:42 PM
Kepontry updated this revision to Diff 556888.