This is an archive of the discontinued LLVM Phabricator instance.

[ThinkLTO] Invoke build(Thin)?LTOPreLinkDefaultPipeline.
ClosedPublic

Authored by timshen on Jun 27 2017, 5:08 PM.

Details

Summary

Previously it doesn't actually invoke the designated new PM builder
functions.

This patch moves NameAnonGlobalPass out from PassBuilder, as Chandler points out that PassBuilder is used for non-O0 builds, and for optimizations only.

Diff Detail

Repository
rL LLVM

Event Timeline

timshen created this revision.Jun 27 2017, 5:08 PM
timshen edited the summary of this revision. (Show Details)Jun 27 2017, 5:09 PM

A question I have is that I don't know how to test this. Ideally we want -debug-pass-manager from opt, but that flag is not part of the LLVM libraries.

chandlerc added inline comments.Jun 27 2017, 5:15 PM
clang/lib/CodeGen/BackendUtil.cpp
804–807 ↗(On Diff #104321)

Why is this change needed?

885–886 ↗(On Diff #104321)

Keep this comment?

893–894 ↗(On Diff #104321)

Why not a single addition of this pass at the end and a comment explaining taht regardless of optimization level this is required for ThinLTO?

tejohnson added inline comments.Jun 27 2017, 6:36 PM
llvm/test/Other/new-pm-thinlto-defaults.ll
157 ↗(On Diff #104321)

Can this be changed to check for the pass being added in its new location, since it should still be invoked somewhere for ThinLTO? If this change means it is no longer added under options to set up the thinlto pipeline via opt, I'd prefer that we go back to adding this to the pipeline in buildThinLTOPreLinkDefaultPipeline in the non-O0 case.

chandlerc added inline comments.Jun 27 2017, 6:42 PM
llvm/test/Other/new-pm-thinlto-defaults.ll
157 ↗(On Diff #104321)

It seems somewhat unfortunate to have a *semantic* requirement on a particular placement of this pass inside of the pipeline... Especially when the semantics pretty much only stem from C++. For example, an a language without anonymous globals, you might not want this pass when doing ThinLTO.

Note that you can exactly model the thing Clang is doing with opt even after this:

opt -passes='thinlto-pre-link<O3>,name-anon-globals'
tejohnson edited edge metadata.Jun 28 2017, 7:52 AM

A question I have is that I don't know how to test this. Ideally we want -debug-pass-manager from opt, but that flag is not part of the LLVM libraries.

How about add a clang test that builds with "-mllvm -debug-pass=Structure" and -flto=thin, and check for the passes that are now expected to be added with this patch.

clang/lib/CodeGen/BackendUtil.cpp
804–807 ↗(On Diff #104321)

I assume it is just cleanup since this isn't currently called under O0 (so it would hit the assert under the default switch case if we ever did). Not sure that is necessary though, up to you two.

llvm/test/Other/new-pm-thinlto-defaults.ll
157 ↗(On Diff #104321)

For example, an a language without anonymous globals, you might not want this pass when doing ThinLTO.

Wouldn't it just be a no-op?

opt -passes='thinlto-pre-link<O3>,name-anon-globals'

True, it just seems less user-friendly. But since this is just for testing, I guess it doesn't matter much. So I am ok with your suggestion of pulling that out and doing a single call to this pass when in ThinLTO mode after setting up the pipelines.

timshen updated this revision to Diff 104533.Jun 28 2017, 3:50 PM
timshen marked 5 inline comments as done.

Added -fexperimental-new-pass-manager=off/on/debug for printing debug information.

Added a Clang test.

Do tell if you want me to split this patch. I didn't, becuase then I don't have to write a test for each of them. :)

clang/lib/CodeGen/BackendUtil.cpp
804–807 ↗(On Diff #104321)

Removed. I used to use it in prototyping, and forgot to remove it. It's always good to take a look at the patch after posting it, and I failed to do so. :P

893–894 ↗(On Diff #104321)

I feel more readable this way. The structure has less "joint points", aka the if statements form a tree, rather than a DAG. I'm fine with the current duplication.

llvm/test/Other/new-pm-thinlto-defaults.ll
157 ↗(On Diff #104321)

I added a clang test for checking everything in the pipeline.

In this LLVM test I used 'thinlto-pre-link<O3>,name-anon-globals', but the order of that pass changed.

Added -fexperimental-new-pass-manager=off/on/debug for printing debug information.

Added a Clang test.

Do tell if you want me to split this patch. I didn't, becuase then I don't have to write a test for each of them. :)

I think they should be split into two patches, one for the option change and one for the thinLTO pipeline fixes. You could just put the new lto-newpm-pipeline.c test in with the option changes patch and commit it right after the thinlto pipeline fixes (or do it first and modify that test to add the thinlto passes when the pipeline fix goes in).

LGTM, but please wait to see if Chandler has any more comments.

clang/include/clang/Frontend/CodeGenOptions.h
92 ↗(On Diff #104533)

Document

timshen updated this revision to Diff 104551.Jun 28 2017, 4:58 PM

Splitted into two patches. I'll commit this one (ThinLTO change) without the test first, then commit the flag change with the Clang ThinLTO pipeline test.

timshen marked an inline comment as done.Jun 28 2017, 5:01 PM
chandlerc accepted this revision.Jun 28 2017, 5:54 PM

LGTM as well.

This revision is now accepted and ready to land.Jun 28 2017, 5:54 PM
This revision was automatically updated to reflect the committed changes.

Already said LGTM, please go ahead and submit. If tehre are further requsets, we can always amke follow-up changes.