This is an archive of the discontinued LLVM Phabricator instance.

[PM] Use getAnalysisIfAvailable / addUsedIfAvailable with StackProtector
AbandonedPublic

Authored by thegameg on Jul 11 2018, 1:15 PM.

Details

Summary

When trying to use llc -run-pass stack-coloring or any other pass that
requires the StackProtector pass, the PM will fail with:

Unable to schedule 'Slot index numbering' required by 'Merge disjoint stack slots'
Unable to schedule pass
UNREACHABLE executed at ../lib/IR/LegacyPassManager.cpp:1314!

The problem with StackProtector is that it is an IR pass which is added
as a dependency to an MI pass.

This patch makes it so passes only use the StackProtector pass if it is
available. In general, the pass is added in TargetPassConfig::addISelPrepare.

This allows these passes to be used with -run-pass or
-start-after/before.

It also fixes one machine verifier issue by using -run-pass instead of
re-running ISel on the whole IR.

Diff Detail

Event Timeline

thegameg created this revision.Jul 11 2018, 1:15 PM
thanm added a comment.Jul 11 2018, 1:33 PM

Thanks for looking into this-- I've definitely run into the "Unable to schedule pass" issue but hadn't been able to sort out the cause.

mattd added a comment.Jul 11 2018, 2:18 PM

@thegameg - Good catch, and thanks for hunting this down.

I'm not a pass manager expert, but since the TargetPassConfig will always add StackProtector for code that is generating IR, this seems ok to me. Is there not a way to get MF passes to express a required dependency on an IR analysis pass, I'm guessing not since llc only really deals with lower level machine passes. Perhaps a more helpful diagnostic could have made locating this issue easier "Machine Function pass is dependent on a IR pass that cannot be generated."

See also: https://reviews.llvm.org/D37582
(Looks like I never got around comitting it and nobody pinged, oops)

thegameg abandoned this revision.Jul 12 2018, 7:03 AM

Thanks all for taking a look. I'll close this and push for D37582.