This is an archive of the discontinued LLVM Phabricator instance.

Do not verify MachimeDominatorTree if it is not calculated
ClosedPublic

Authored by sepavloff on Jan 30 2017, 6:45 AM.

Details

Summary

If dominator tree is not calculated or is invalidated, set corresponding
pointer in the pass state to nullptr. Such pointer value will indicate
that operations with dominator tree are not allowed. In particular, it
allows to skip verification for such pass state. The dominator thee is
not calculated if the machine dominator pass was skipped, it occures in
the case of entities with linkage available_externally.

The change fixes some test fails observed when expensive checks
are enabled.

Diff Detail

Repository
rL LLVM

Event Timeline

sepavloff created this revision.Jan 30 2017, 6:45 AM
fhahn added a subscriber: fhahn.Jan 30 2017, 7:29 AM
fhahn added a comment.Jan 30 2017, 3:13 PM

Do you know why the machine dominator pass was skipped for test/CodeGen/Generic/externally_available.ll? Or has it been invalidated?

Do you know why the machine dominator pass was skipped for test/CodeGen/Generic/externally_available.ll? Or has it been invalidated?

Not only dominator pass was skipped, all machine code passes were skipped too. According to the documentation (http://llvm.org/docs/LangRef.html#linkage-types):

Globals with “available_externally” linkage are never emitted into the object file

So there is no sense to run machine code generation for them.

fhahn added a comment.Feb 1 2017, 2:26 AM

Not only dominator pass was skipped, all machine code passes were skipped too. According to the documentation (http://llvm.org/docs/LangRef.html#linkage-types):

Globals with “available_externally” linkage are never emitted into the object file

So there is no sense to run machine code generation for them.

Ah thanks that makes sense. The only thing I am still wondering about: if no machine passes are run, MachineDominatorTree::verifyAnalysis or MachineDominatorTree::verifyDomTree shouldn't be called in the first place, no?

lib/CodeGen/MachineDominators.cpp
142 ↗(On Diff #86281)

Would this change here in combination with moving the allocation of the dominator tree to runOnMachineFunction be enough to skip the verification in cases runOnMachineFunction is not executed?

The change to use unique_ptr might be a worthwhile refactoring, but it looks like most of the changes in this patch are related to the change to unique_ptr instead of skipping the dominator tree verification. I think it would make it easier for reviewers if the patch would only contain the changes required to skip the dominator tree verification.

Globals with “available_externally” linkage are never emitted into the object file

So there is no sense to run machine code generation for them.

Ah thanks that makes sense. The only thing I am still wondering about: if no machine passes are run, MachineDominatorTree::verifyAnalysis or MachineDominatorTree::verifyDomTree shouldn't be called in the first place, no?

The relevant code looks as follows:

bool MachineFunctionPass::runOnFunction(Function &F) {
  // Do not codegen any 'available_externally' functions at all, they have
  // definitions outside the translation unit.
  if (F.hasAvailableExternallyLinkage())
    return false;

So the pass was run but it decided to skip processing of some functions. Pass Manager does not know if the pass actually did not make its job and calls verifyAnalysis for it. The latter obviously crashes. Solution in D27190 tried to extend Pass state so that it keeps a flag, whether or not the pass produced result, but it was decided to use a simpler solution.

Would this change here in combination with moving the allocation of the dominator tree to runOnMachineFunction be enough to skip the verification in cases runOnMachineFunction is not executed?

Dominator tree appears when runOnMachineFunction is run and is invalidated when Pass Manager releases the pass by call to releaseMemory, it looks like correct domtree lifetime.

The change to use unique_ptr might be a worthwhile refactoring, but it looks like most of the changes in this patch are related to the change to unique_ptr instead of skipping the dominator tree verification. I think it would make it easier for reviewers if the patch would only contain the changes required to skip the dominator tree verification.

The simple patch was presented in D28767. In subsequent discussion http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20170123/423110.html it was pointed out that dominator tree should not exist if it does not represent any function. This patch is an attempt to add lifetime management of the dominator tree.

RKSimon added a subscriber: RKSimon.Feb 8 2017, 6:59 AM

Is there anything I can do to make this patch acceptable?

dberlin accepted this revision.Feb 28 2017, 10:11 AM

I am fine with this at this point.

This revision is now accepted and ready to land.Feb 28 2017, 10:11 AM
This revision was automatically updated to reflect the committed changes.