This is an archive of the discontinued LLVM Phabricator instance.

[GlobalOpt] Get DT only if it is available.
AbandonedPublic

Authored by fhahn on Jan 4 2020, 1:20 PM.

Details

Summary

D68298 updated GlobalOpt to use the DomTreeUpdater, but that can cause compile-time regressions for cases where we do not need to compute the DT for most functions. This patch adds some plumbing to only fetch the DT to update, if it was already requested elsewhere in GlobalOpt.

This is mostly a workaround a limitation of the legacy pass manager, which cannot return function analysis only if available for module passes. In the NewPassManager, getCachedResult works as expected.

Diff Detail

Event Timeline

fhahn created this revision.Jan 4 2020, 1:20 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 4 2020, 1:20 PM
Herald added a subscriber: hiraditya. · View Herald Transcript

Unit tests: pass. 61243 tests passed, 0 failed and 736 were skipped.

clang-tidy: fail. Please fix clang-tidy findings.

clang-format: pass.

Build artifacts: diff.json, clang-tidy.txt, clang-format.patch, CMakeCache.txt, console-log.txt, test-results.xml

alex added a subscriber: alex.Jan 5 2020, 2:17 PM
nikic added a subscriber: nikic.Jan 7 2020, 1:20 PM
nikic added a comment.Jan 8 2020, 8:30 AM

Do you plan to pursue this patch? It would be great to resolve this one way or the other before LLVM 10 branches.

ekatz added a subscriber: ekatz.Jan 9 2020, 1:28 PM

This is a welcoming improvement!
Is it sufficient that I'll approve it for you? Or are you waiting for the code-owner?

Other than that, I know that that it is a bit out of scope of this patch, but can we tag DT analysis as preserved?

llvm/lib/Transforms/IPO/GlobalOpt.cpp
114

Why the underscore? I think this is what clang-tidy warns about.

fhahn edited the summary of this revision. (Show Details)Jan 9 2020, 1:50 PM
fhahn added reviewers: davide, kuhar, brzycki.

Do you plan to pursue this patch? It would be great to resolve this one way or the other before LLVM 10 branches.

Yes I think it would be good to fix this. I'd like to hear what other people think about this workaround. Maybe there's something I am missing to do that in the legacy pass manager?

ekatz added a comment.EditedJan 10 2020, 9:18 AM

The old PassManager has the function getAnalysisIfAvailable that should be used in case you only need to update an analysis (equivalent to getCachedResult of the new PassManager). You should probably switch to use this function, instead of the SmallPtrSet<> DTRequested technique.

fhahn added a comment.Jan 10 2020, 9:20 AM

The old PassManager has the function getAnalysisIfAvailable that should be used in case you only need to update an analysis (equivalent to getCachedResult of the new PassManager). You should probably switch to use this function, instead of the SmallPtrSet<> DTRequested technique.

I could not get getAnalysisIfAvailable to get a function level analysis from a module pass. IIUC it only works for function passes.

I could not get getAnalysisIfAvailable to get a function level analysis from a module pass. IIUC it only works for function passes.

And I guess adding this functionality to the Legacy PassManager is too much, for something that is going to be removed anyway.
Then the solution (in the patch) seems legit.

fhahn abandoned this revision.Jan 14 2020, 6:55 AM

After thinking about it a bit more, I think this patch makes things too brittle with the legacy pass manager (e.g. we might end up with invalid DTs, if they are not used by GlobalOpt, but removeUnreachableBlocks makes changes. I'll revert D68298 for now.