This is an archive of the discontinued LLVM Phabricator instance.

[ThinLTO] Pass -save-temps to LTO backend for distributed ThinLTO builds
ClosedPublic

Authored by tejohnson on Apr 3 2018, 11:23 AM.

Details

Summary

The clang driver option -save-temps was not passed to the LTO config,
so when invoking the ThinLTO backends via clang during distributed
builds there was no way to get LTO to save temp files.

Getting this to work with ThinLTO distributed builds also required
changing the driver to avoid a separate compile step to emit unoptimized
bitcode when the input was already bitcode under -save-temps. Not only is
this unnecessary in general, it is problematic for ThinLTO backends since
the temporary bitcode file to the backend would not match the module path
in the combined index, leading to incorrect ThinLTO backend index-based
optimizations.

Diff Detail

Repository
rL LLVM

Event Timeline

tejohnson created this revision.Apr 3 2018, 11:23 AM
pcc added inline comments.Apr 12 2018, 2:39 PM
include/clang/Driver/Options.td
2255 ↗(On Diff #140832)

This is still just a DriverOption, right?

lib/Frontend/CompilerInvocation.cpp
747 ↗(On Diff #140832)

Why do you need the "./" part?

test/CodeGen/thinlto_backend.ll
30 ↗(On Diff #140832)

Should there be another test for -save-temps=cwd?

tejohnson marked 2 inline comments as done.Apr 16 2018, 11:26 AM
tejohnson added inline comments.
include/clang/Driver/Options.td
2255 ↗(On Diff #140832)

No, we need to pass to cc1 to get it into the CodeGenOptions. See the changes to Clang.cpp (passes to cc1 invocation) and CompilerInvocation.cpp (consumes during cc1 invocation).

lib/Frontend/CompilerInvocation.cpp
747 ↗(On Diff #140832)

Not needed, removed.

test/CodeGen/thinlto_backend.ll
30 ↗(On Diff #140832)

Added -save-temps=cwd and -save-temps

tejohnson marked 2 inline comments as done.

Addressed comments

pcc added inline comments.Apr 16 2018, 11:31 AM
include/clang/Driver/Options.td
2255 ↗(On Diff #140832)

You are producing a -save-temps= flag, not -save-temps.

i.e. I think you should be able to remove the CC1Option from this line and keep it on line 2253.

test/CodeGen/thinlto_backend.ll
30 ↗(On Diff #140832)

This isn't actually testing that the behaviour is different between -save-temps=obj and -save-temps=cwd, right?

Maybe create a new directory, cd there and verify that the files are created there?

tejohnson marked 2 inline comments as done.Apr 16 2018, 11:44 AM
tejohnson added inline comments.
include/clang/Driver/Options.td
2255 ↗(On Diff #140832)

Oh, I see what you are saying. Removed CC1Option from the plain -save-temps.

test/CodeGen/thinlto_backend.ll
30 ↗(On Diff #140832)

Using different directories for all 3 cases now.

tejohnson marked 2 inline comments as done.

Address comments

pcc accepted this revision.Apr 16 2018, 1:54 PM

LGTM

This revision is now accepted and ready to land.Apr 16 2018, 1:54 PM
This revision was automatically updated to reflect the committed changes.
bjope added a subscriber: bjope.Apr 17 2018, 12:59 PM
bjope added inline comments.
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
3270

A is not used, so this does not compile when using -Werror:

../tools/clang/lib/Driver/ToolChains/Clang.cpp:3270:18: error: unused variable 'A' [-Werror,-Wunused-variable]
  if (const Arg *A = Args.getLastArg(options::OPT_save_temps_EQ))
tejohnson added inline comments.Apr 17 2018, 1:05 PM
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
3270

Sorry, will fix shortly.

tejohnson added inline comments.Apr 17 2018, 1:25 PM
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
3270

Fixed in r330210