-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Integrated Distributed ThinLTO (DTLTO): Design Overview #126654
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bd1976bris
wants to merge
15
commits into
llvm:main
Choose a base branch
from
bd1976bris:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,150
−78
Open
Changes from 5 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
3711d21
Implement integrated distribution for ThinLTO (DTLTO). ELF and COFF o…
bd1976bris e4bd134
Update clang/docs/ThinLTO.rst
bd1976bris ea25797
Test improvements and a bug fix.
bd1976bris 3da7c73
Address non-test review comments.
bd1976bris ea95125
Replace -Xdist with -Xthinlto-distributor=
bd1976bris fec5490
Sync with #127749
bd1976bris 36fe827
Support more than one LTO partition.
bd1976bris 46934b6
[LLD] Improve thin archive handling
bd1976bris 68e088b
Go back to previous more contained thin archive bitcode members scheme
bd1976bris f5cb455
Replace `remote-opt-tool` with `remote-compiler`
bd1976bris 7525a13
Make `thinlto-remote-compiler` a cl::opt
bd1976bris 6d60e48
Forward Clang -mllvm options to remote compiler invocations
bd1976bris 273b2e5
Update documentation to match recent changes
bd1976bris 8eb070a
Update python module docstrings to match the script names
bd1976bris 4297340
Disable problematic Clang format for the mllvm.c test
bd1976bris File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/// Check DTLTO options are forwarded to the linker. | ||
|
||
// REQUIRES: lld | ||
|
||
// RUN: echo "--target=x86_64-linux-gnu \ | ||
// RUN: -Xthinlto-distributor=distarg1 \ | ||
// RUN: -Xthinlto-distributor=distarg2,distarg3 \ | ||
// RUN: -fuse-ld=lld" > %t.rsp | ||
|
||
|
||
/// Check that options are forwarded as expected with --thinlto-distributor=. | ||
// RUN: %clang -### @%t.rsp -fthinlto-distributor=dist.exe %s 2>&1 | \ | ||
// RUN: FileCheck %s --implicit-check-not=warning | ||
|
||
// CHECK: ld.lld | ||
// CHECK-SAME: "--thinlto-distributor=dist.exe" | ||
// CHECK-SAME: "--thinlto-remote-opt-tool={{.*}}clang | ||
// CHECK-SAME: "-mllvm=-thinlto-distributor-arg=distarg1" | ||
// CHECK-SAME: "-mllvm=-thinlto-distributor-arg=distarg2" | ||
// CHECK-SAME: "-mllvm=-thinlto-distributor-arg=distarg3" | ||
|
||
|
||
/// Check that options are not added without --thinlto-distributor= and | ||
/// that there is an unused option warning issued for -Xthinlto-distributor= options. We | ||
/// specify -flto here as these options should be unaffected by it. | ||
// RUN: %clang -### @%t.rsp -flto=thin %s 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefixes=NONE,NOMORE --implicit-check-not=warning | ||
|
||
// NONE: warning: argument unused during compilation: '-Xthinlto-distributor=distarg1' | ||
// NONE: warning: argument unused during compilation: '-Xthinlto-distributor=distarg2,distarg3' | ||
// NONE: ld.lld | ||
// NOMORE-NOT: --thinlto-distributor= | ||
// NOMORE-NOT: --thinlto-remote-opt-tool= | ||
// NOMORE-NOT: -mllvm | ||
// NOMORE-NOT: -thinlto-distributor-arg= | ||
|
||
|
||
/// Check the expected arguments are forwarded by default with only | ||
/// --thinlto-distributor=. | ||
// RUN: %clang --target=x86_64-linux-gnu -fthinlto-distributor=dist.exe \ | ||
// RUN: -fuse-ld=lld -Werror -### %s 2>&1 | \ | ||
// RUN: FileCheck %s --check-prefixes=DEFAULT,NOMORE | ||
|
||
// DEFAULT: ld.lld | ||
// DEFAULT-SAME: "--thinlto-distributor=dist.exe" | ||
// DEFAULT-SAME: "--thinlto-remote-opt-tool={{.*}}clang |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Tests for DTLTO (integrated distributed ThinLTO) functionality. | ||
|
||
These are integration tests as DTLTO invokes `clang` for code-generation. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
## Simple test that a DTLTO link succeeds and outputs the expected set of files | ||
## correctly when thin archives are present. | ||
|
||
# RUN: rm -rf %t.dir && split-file %s %t.dir && cd %t.dir | ||
# RUN: %clang --target=x86_64-linux-gnu -c foo.c -o foo.o | ||
# RUN: %clang --target=x86_64-linux-gnu -c -flto=thin bar.c -o bar.o | ||
# RUN: %clang --target=x86_64-linux-gnu -c -flto=thin dog.c -o dog.o | ||
# RUN: %clang --target=x86_64-linux-gnu -c -flto=thin cat.c -o cat.o | ||
# RUN: %clang --target=x86_64-linux-gnu -c -flto=thin _start.c -o _start.o | ||
|
||
# RUN: llvm-ar rcs foo.a foo.o --thin | ||
## Create this bitcode thin archive in a sub-directory to test the expansion of | ||
## the path to a bitcode file which is referenced using "..", e.g. in this case | ||
## "../bar.o". The ".." should be collapsed in any expansion to avoid | ||
## referencing an unknown directory on the remote side. | ||
# RUN: mkdir lib | ||
# RUN: llvm-ar rcs lib/bar.a bar.o --thin | ||
## Create this bitcode thin archive with an absolute path entry containing "..". | ||
# RUN: llvm-ar rcs dog.a %t.dir/lib/../dog.o --thin | ||
# RUN: llvm-ar rcs cat.a cat.o --thin | ||
# RUN: llvm-ar rcs _start.a _start.o --thin | ||
|
||
# RUN: mkdir %t.dir/out && cd %t.dir/out | ||
|
||
# RUN: %clang --target=x86_64-linux-gnu \ | ||
# RUN: %t.dir/foo.a %t.dir/lib/bar.a ../_start.a %t.dir/cat.a -Wl,--whole-archive,../dog.a \ | ||
# RUN: -flto=thin \ | ||
# RUN: -fthinlto-distributor=%python \ | ||
# RUN: -Xthinlto-distributor=%llvm_src_root/utils/dtlto/local.py \ | ||
# RUN: --save-temps \ | ||
# RUN: -fuse-ld=lld \ | ||
# RUN: -nostdlib \ | ||
# RUN: -nostartfiles \ | ||
# RUN: -Wl,--save-temps \ | ||
# RUN: -Wl,-mllvm,--thinlto-remote-opt-tool-arg=-save-temps=cwd \ | ||
# RUN: -Werror | ||
|
||
## Check that the required output files have been created. | ||
# RUN: ls | FileCheck %s --check-prefix=OUTPUTS \ | ||
# RUN: --implicit-check-not=cat --implicit-check-not=foo | ||
|
||
## The DTLTO backend emits the JSON jobs description and summary shards. | ||
# OUTPUTS-DAG: a.{{[0-9]+}}.dist-file.json | ||
# OUTPUTS-DAG: bar.{{[0-9]+}}.{{[0-9]+}}.native.o.thinlto.bc{{$}} | ||
# OUTPUTS-DAG: dog.{{[0-9]+}}.{{[0-9]+}}.native.o.thinlto.bc{{$}} | ||
# OUTPUTS-DAG: _start.{{[0-9]+}}.{{[0-9]+}}.native.o.thinlto.bc{{$}} | ||
## Native output object files. | ||
# OUTPUTS-DAG: bar.{{[0-9]+}}.{{[0-9]+}}.native.o{{$}} | ||
# OUTPUTS-DAG: dog.{{[0-9]+}}.{{[0-9]+}}.native.o{{$}} | ||
# OUTPUTS-DAG: _start.{{[0-9]+}}.{{[0-9]+}}.native.o{{$}} | ||
|
||
## Check that bar.o and dog.o are not referenced using "..". | ||
# RUN: not grep '\.\.\(/\|\\\\\)\(bar\|dog\)\.o' a.*.dist-file.json | ||
|
||
#--- foo.c | ||
__attribute__((retain)) void foo() {} | ||
|
||
#--- bar.c | ||
extern void foo(); | ||
__attribute__((retain)) void bar() { foo(); } | ||
|
||
#--- dog.c | ||
__attribute__((retain)) void dog() {} | ||
|
||
#--- cat.c | ||
__attribute__((retain)) void cat() {} | ||
|
||
#--- _start.c | ||
extern void bar(); | ||
__attribute__((retain)) void _start() { | ||
bar(); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
;; Check that the expected Clang arguments are generated by DTLTO for the | ||
;; backend compilations and are accepted by Clang. | ||
|
||
; RUN: rm -rf %t && split-file %s %t && cd %t | ||
|
||
;; Generate bitcode files with a summary index. | ||
; RUN: opt -thinlto-bc x86_64-unknown-linux-gnu.ll -o x86_64-unknown-linux-gnu.bc | ||
; RUN: opt -thinlto-bc x86_64-pc-windows-msvc.ll -o x86_64-pc-windows-msvc.bc | ||
|
||
|
||
;; Check that any invalid arguments would cause a Clang error. This property is | ||
;; relied on by the actual testcases later in this test. | ||
; RUN: not %clang -x ir x86_64-unknown-linux-gnu.ll \ | ||
; RUN: -invalid-incorrect-not-an-option 2>&1 | FileCheck %s --check-prefix=SANITY1 | ||
; SANITY1: unknown argument: '-invalid-incorrect-not-an-option' | ||
|
||
|
||
;; Define a substitution used to simplify the testcases. | ||
; DEFINE: %{distributor} = dummy | ||
; DEFINE: %{extra_flags} = dummy | ||
; DEFINE: %{triple} = dummy | ||
; DEFINE: %{command} = llvm-lto2 run \ | ||
; DEFINE: -thinlto-distributor-arg=%llvm_src_root/utils/dtlto/%{distributor} \ | ||
; DEFINE: -thinlto-remote-opt-tool-arg=-Wunused-command-line-argument \ | ||
; DEFINE: @%{triple}.rsp %{extra_flags} | ||
|
||
|
||
;; Write common arguments to a response files. | ||
|
||
; RUN: echo "x86_64-unknown-linux-gnu.bc -o x86_64-unknown-linux-gnu.o \ | ||
; RUN: -dtlto \ | ||
; RUN: -dtlto-remote-opt-tool=%clang \ | ||
; RUN: -thinlto-remote-opt-tool-arg=-Werror \ | ||
; RUN: -dtlto-distributor=%python \ | ||
; RUN: -r=x86_64-unknown-linux-gnu.bc,globalfunc1,plx" > x86_64-unknown-linux-gnu.rsp | ||
|
||
; RUN: echo "x86_64-pc-windows-msvc.bc -o x86_64-pc-windows-msvc.o \ | ||
; RUN: -dtlto \ | ||
; RUN: -dtlto-remote-opt-tool=%clang \ | ||
; RUN: -thinlto-remote-opt-tool-arg=-Werror \ | ||
; RUN: -thinlto-remote-opt-tool-arg=-Wno-override-module \ | ||
; RUN: -dtlto-distributor=%python \ | ||
; RUN: -r=x86_64-pc-windows-msvc.bc,globalfunc2,plx" > x86_64-pc-windows-msvc.rsp | ||
|
||
|
||
;; Check that boolean configuration states are translated as expected and Clang | ||
;; accepts them. | ||
|
||
; RUN: echo " \ | ||
; RUN: --addrsig=1 \ | ||
; RUN: -function-sections=1 \ | ||
; RUN: -data-sections=1" > on.rsp | ||
|
||
; RUN: echo " \ | ||
; RUN: --addrsig=0 \ | ||
; RUN: -function-sections=0 \ | ||
; RUN: -data-sections=0" > off.rsp | ||
|
||
;; Perform DTLTO with configuration state set. | ||
; REDEFINE: %{extra_flags} = @on.rsp | ||
; REDEFINE: %{distributor} = local.py | ||
; REDEFINE: %{triple} = x86_64-unknown-linux-gnu | ||
; RUN: %{command} | ||
; REDEFINE: %{distributor} = validate.py | ||
; RUN: not %{command} 2>&1 | FileCheck %s --check-prefix=ON \ | ||
; RUN: --implicit-check-not=-no-pgo-warn-mismatch | ||
; ON-DAG: "-faddrsig" | ||
; ON-DAG: "-ffunction-sections" | ||
; ON-DAG: "-fdata-sections" | ||
|
||
;; Perform DTLTO with configuration state unset. | ||
; REDEFINE: %{extra_flags} = @off.rsp | ||
; REDEFINE: %{distributor} = local.py | ||
; RUN: %{command} | ||
; REDEFINE: %{distributor} = validate.py | ||
; RUN: not %{command} 2>&1 | FileCheck %s --check-prefix=OFF | ||
; OFF-NOT: --implicit-check-not=--faddrsig | ||
; OFF-NOT: --implicit-check-not=--ffunction-sections | ||
; OFF-NOT: --implicit-check-not=--fdata-sections | ||
; OFF-NOT: --implicit-check-not=-no-pgo-warn-mismatch | ||
|
||
|
||
;; Check optimisation level. | ||
|
||
; RUN: llvm-lto2 run \ | ||
; RUN: -thinlto-distributor-arg=%llvm_src_root/utils/dtlto/local.py \ | ||
; RUN: @x86_64-unknown-linux-gnu.rsp \ | ||
; RUN: -O3 | ||
|
||
; RUN: not llvm-lto2 run \ | ||
; RUN: -thinlto-distributor-arg=%llvm_src_root/utils/dtlto/validate.py \ | ||
; RUN: @x86_64-unknown-linux-gnu.rsp \ | ||
; RUN: -O3 2>&1 | FileCheck %s --check-prefix=OPTLEVEL | ||
; OPTLEVEL-DAG: "-O3" | ||
|
||
|
||
;; Check relocation model. | ||
|
||
; REDEFINE: %{extra_flags} = -relocation-model=pic | ||
; REDEFINE: %{distributor} = local.py | ||
; RUN: %{command} | ||
; REDEFINE: %{distributor} = validate.py | ||
; RUN: not %{command} 2>&1 | FileCheck %s --check-prefix=PIC | ||
; PIC: -fpic | ||
|
||
|
||
; REDEFINE: %{extra_flags} = -relocation-model=pic | ||
; REDEFINE: %{distributor} = local.py | ||
; REDEFINE: %{triple} = x86_64-pc-windows-msvc | ||
; RUN: %{command} | ||
; REDEFINE: %{distributor} = validate.py | ||
; RUN: not %{command} 2>&1 | FileCheck %s --check-prefix=NOPIC | ||
; REDEFINE: %{triple} = x86_64-unknown-linux-gnu | ||
; NOPIC-NOT: -fpic | ||
|
||
;; Check specifying a sample profile. | ||
; REDEFINE: %{extra_flags} = --lto-sample-profile-file="missing.profdata" | ||
; REDEFINE: %{distributor} = local.py | ||
; RUN: not %{command} 2>&1 | FileCheck %s --check-prefix=SAMPLE_PROFILE_ERR | ||
; SAMPLE_PROFILE_ERR: no such file or directory: 'missing.profdata' | ||
; REDEFINE: %{distributor} = validate.py | ||
; RUN: not %{command} 2>&1 | FileCheck %s --check-prefix=SAMPLE_PROFILE | ||
; SAMPLE_PROFILE-DAG: "-fprofile-sample-use=missing.profdata" | ||
|
||
|
||
;--- x86_64-unknown-linux-gnu.ll | ||
|
||
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
define void @globalfunc1() { | ||
entry: | ||
ret void | ||
} | ||
|
||
;--- x86_64-pc-windows-msvc.ll | ||
|
||
target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-pc-windows-msvc" | ||
|
||
define void @globalfunc2() { | ||
entry: | ||
ret void | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am curious why we don't use a regular linker option. In lld, you could use
getStrings
to read a list option, e.g.However, introducing a new linker option requires changes to all lld ports and llvm-lto. Therefore, perhaps make
--thinlto-remote-opt-tool
a cl::opt tool as well?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you already worked out I used
cl::opt
options to minimize the changes to LLD ports and llvm-lto. The syntax is verbose, but LLD is usually invoked via the compiler driver so the verbose syntax is not exposed. I'm happy to use acl::opt
for this. However, I would like to retain a retain the LLD option for the COFF port where LLD is often invoked directly. Does that sound ok?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having looked at this again I think your suggestion of making
--thinlto-remote-opt-tool
acl::opt
tool makes sense. I have updated the code to match. Please take a look.