This is an archive of the discontinued LLVM Phabricator instance.

Pass split-machine-functions to code generator when flto is used
ClosedPublic

Authored by junfd on Mar 17 2022, 3:33 PM.

Details

Summary

-fsplit-machine-functions is an optimization in codegen phase. when -flto is use, clang generate IR bitcode in .o files, and linker will call into these codegen optimization passes. Current clang driver doesn't pass this option to linker when both -fsplit-machine-functions and -flto are used, so the optimization is silently ignored. My fix generates linker option -plugin-opt=-split-machine-functions for this case. It allows the linker to pass "split-machine-functions" to code generator to turn on that optimization. It works for both gold and lld.

Diff Detail

Event Timeline

junfd created this revision.Mar 17 2022, 3:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 3:33 PM
Herald added a subscriber: inglorion. · View Herald Transcript
junfd requested review of this revision.Mar 17 2022, 3:33 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 3:33 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
junfd edited the summary of this revision. (Show Details)Mar 17 2022, 4:05 PM
junfd added reviewers: hoy, wenlei.
junfd updated this revision to Diff 416363.Mar 17 2022, 5:25 PM

Follow clang format.

junfd updated this revision to Diff 416555.Mar 18 2022, 10:17 AM

Disable test on Windows, because -fsplit-machine-functions only works for ELF.

wenlei added inline comments.Mar 19 2022, 10:25 AM
clang/test/Driver/split-machine-functions.c
3

My understanding is that if you specify target, e.g. -target x86_64-unknown-linux, the test should still be runnable on windows host platform.

junfd updated this revision to Diff 417146.Mar 21 2022, 6:02 PM

Refine the test case.

hoy added inline comments.Mar 21 2022, 9:01 PM
clang/lib/Driver/ToolChains/CommonArgs.cpp
577

Should also check OPT_fno_split_machine_functions, i.e,

if (Args.getLastArg(options::OPT_fsplit_machine_functions,
                           options::OPT_fno_split_machine_functions))
clang/test/Driver/fsplit-machine-functions2.c
5 ↗(On Diff #417146)

Please add a test case for mixed -fsplit-machine-functions and -fno-split-machine-functions

junfd updated this revision to Diff 417387.Mar 22 2022, 1:34 PM

Check the mixing -fsplit-machine-functions and -fno-split-machine-functions.

junfd marked 2 inline comments as done.Mar 22 2022, 1:38 PM
junfd marked an inline comment as done.
hoy accepted this revision.Mar 22 2022, 3:04 PM

lgtm, thanks.

This revision is now accepted and ready to land.Mar 22 2022, 3:04 PM

The linter warning seems legit, otherwise looks good.

wenlei accepted this revision.Mar 22 2022, 4:22 PM
junfd updated this revision to Diff 417458.Mar 22 2022, 6:17 PM

Apply clang format.

This revision was automatically updated to reflect the committed changes.