-
Notifications
You must be signed in to change notification settings - Fork 14.6k
[DTLTO][LLD][COFF] Add support for Integrated Distributed ThinLTO #148594
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
81e1c4f
[DTLTO][LLD][COFF] Add support for Integrated Distributed ThinLTO
bd1976bris f88476a
Merge branch 'main' into dtlto_lld_coff
tru b25fa9a
Use more efficient indenting for new the options in Options.td
bd1976bris f131ad7
Use -<option name> spelling for -thinlto- options in new tests.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
REQUIRES: lld-link | ||
|
||
## Test that a DTLTO link succeeds and outputs the expected set of files | ||
## correctly when thin archives are present. | ||
|
||
RUN: rm -rf %t && split-file %s %t && cd %t | ||
|
||
## Compile bitcode. -O2 is required for cross-module importing. | ||
RUN: %clang -O2 --target=x86_64-pc-windows-msvc -flto=thin -c \ | ||
RUN: foo.c bar.c dog.c cat.c start.c | ||
|
||
## Generate thin archives. | ||
RUN: lld-link /lib /llvmlibthin /out:foo.lib foo.o | ||
## Create this bitcode thin archive in a subdirectory to test the expansion of | ||
## the path to a bitcode file that is referenced using "..", e.g., in this case | ||
## "../bar.o". | ||
RUN: mkdir lib | ||
RUN: lld-link /lib /llvmlibthin /out:lib/bar.lib bar.o | ||
## Create this bitcode thin archive with an absolute path entry containing "..". | ||
RUN: lld-link /lib /llvmlibthin /out:dog.lib %t/lib/../dog.o | ||
RUN: lld-link /lib /llvmlibthin /out:cat.lib cat.o | ||
RUN: lld-link /lib /llvmlibthin /out:start.lib start.o | ||
|
||
## Link from a different directory to ensure that thin archive member paths are | ||
## resolved correctly relative to the archive locations. | ||
RUN: mkdir %t/out && cd %t/out | ||
RUN: lld-link /subsystem:console /machine:x64 /entry:start /out:my.exe \ | ||
RUN: %t/foo.lib %t/lib/bar.lib ../start.lib %t/cat.lib \ | ||
RUN: /includeoptional:dog ../dog.lib \ | ||
RUN: -thinlto-distributor:%python \ | ||
RUN: -thinlto-distributor-arg:%llvm_src_root/utils/dtlto/local.py \ | ||
RUN: -thinlto-remote-compiler:%clang \ | ||
RUN: /lldsavetemps | ||
|
||
## Check that the required output files have been created. | ||
RUN: ls | FileCheck %s --check-prefix=OUTPUTS --implicit-check-not=cat | ||
|
||
## JSON jobs description. | ||
OUTPUTS-DAG: my.[[PID:[a-zA-Z0-9_]+]].dist-file.json | ||
|
||
## Individual summary index files. | ||
OUTPUTS-DAG: start.1.[[PID]].native.o.thinlto.bc{{$}} | ||
OUTPUTS-DAG: dog.2.[[PID]].native.o.thinlto.bc{{$}} | ||
OUTPUTS-DAG: foo.3.[[PID]].native.o.thinlto.bc{{$}} | ||
OUTPUTS-DAG: bar.4.[[PID]].native.o.thinlto.bc{{$}} | ||
|
||
## Native output object files. | ||
OUTPUTS-DAG: start.1.[[PID]].native.o{{$}} | ||
OUTPUTS-DAG: dog.2.[[PID]].native.o{{$}} | ||
OUTPUTS-DAG: foo.3.[[PID]].native.o{{$}} | ||
OUTPUTS-DAG: bar.4.[[PID]].native.o{{$}} | ||
|
||
|
||
## It is important that cross-module inlining occurs for this test to show that Clang can | ||
## successfully load the bitcode file dependencies recorded in the summary indices. | ||
## Explicitly check that the expected importing has occurred. | ||
|
||
RUN: llvm-dis start.1.*.native.o.thinlto.bc -o - | \ | ||
RUN: FileCheck %s --check-prefixes=FOO,BAR,START | ||
|
||
RUN: llvm-dis dog.2.*.native.o.thinlto.bc -o - | \ | ||
RUN: FileCheck %s --check-prefixes=FOO,BAR,DOG,START | ||
|
||
RUN: llvm-dis foo.3.*.native.o.thinlto.bc -o - | \ | ||
RUN: FileCheck %s --check-prefixes=FOO,BAR,START | ||
|
||
RUN: llvm-dis bar.4.*.native.o.thinlto.bc -o - | \ | ||
RUN: FileCheck %s --check-prefixes=FOO,BAR,START | ||
|
||
FOO-DAG: foo.o | ||
BAR-DAG: bar.o | ||
DOG-DAG: dog.o | ||
START-DAG: start.o | ||
|
||
|
||
#--- foo.c | ||
extern int bar(int), start(int); | ||
__attribute__((retain)) int foo(int x) { return x + bar(x) + start(x); } | ||
|
||
#--- bar.c | ||
extern int foo(int), start(int); | ||
__attribute__((retain)) int bar(int x) { return x + foo(x) + start(x); } | ||
|
||
#--- dog.c | ||
extern int foo(int), bar(int), start(int); | ||
__attribute__((retain)) int dog(int x) { return x + foo(x) + bar(x) + start(x); } | ||
|
||
#--- cat.c | ||
__attribute__((retain)) void cat(int x) {} | ||
|
||
#--- start.c | ||
extern int foo(int), bar(int); | ||
__attribute__((retain)) int start(int x) { return x + foo(x) + bar(x); } |
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,41 @@ | ||
// REQUIRES: lld-link | ||
|
||
/// Simple test that DTLTO works with a single input bitcode file and that | ||
/// --save-temps can be applied to the remote compilation. | ||
|
||
// RUN: rm -rf %t && mkdir %t && cd %t | ||
|
||
// RUN: %clang --target=x86_64-pc-windows-msvc -c -flto=thin %s -o dtlto.obj | ||
|
||
// RUN: lld-link /subsystem:console /entry:_start dtlto.obj \ | ||
// RUN: -thinlto-distributor:%python \ | ||
// RUN: -thinlto-distributor-arg:%llvm_src_root/utils/dtlto/local.py \ | ||
// RUN: -thinlto-remote-compiler:%clang \ | ||
// RUN: -thinlto-remote-compiler-arg:--save-temps | ||
|
||
/// Check that the required output files have been created. | ||
// RUN: ls | sort | FileCheck %s | ||
|
||
/// No files are expected before. | ||
// CHECK-NOT: {{.}} | ||
|
||
/// Linked ELF. | ||
// CHECK: {{^}}dtlto.exe{{$}} | ||
|
||
/// Produced by the bitcode compilation. | ||
// CHECK-NEXT: {{^}}dtlto.obj{{$}} | ||
|
||
/// --save-temps output for the backend compilation. | ||
// CHECK-NEXT: {{^}}dtlto.s{{$}} | ||
// CHECK-NEXT: {{^}}dtlto.s.0.preopt.bc{{$}} | ||
// CHECK-NEXT: {{^}}dtlto.s.1.promote.bc{{$}} | ||
// CHECK-NEXT: {{^}}dtlto.s.2.internalize.bc{{$}} | ||
// CHECK-NEXT: {{^}}dtlto.s.3.import.bc{{$}} | ||
// CHECK-NEXT: {{^}}dtlto.s.4.opt.bc{{$}} | ||
// CHECK-NEXT: {{^}}dtlto.s.5.precodegen.bc{{$}} | ||
// CHECK-NEXT: {{^}}dtlto.s.resolution.txt{{$}} | ||
|
||
/// No files are expected after. | ||
// CHECK-NOT: {{.}} | ||
|
||
int _start() { return 0; } |
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
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,71 @@ | ||
REQUIRES: x86 | ||
|
||
## Test that the LLD options /lldsavetemps and -thinlto-emit-imports-files | ||
## function correctly with DTLTO we also check that index files | ||
## (-thinlto-emit-index-files) are not emitted with DTLTO. | ||
|
||
RUN: rm -rf %t && split-file %s %t && cd %t | ||
|
||
RUN: sed 's/@t1/@t2/g' t1.ll > t2.ll | ||
|
||
## Generate ThinLTO bitcode files. Note that t3.bc will not be used by the | ||
## linker. | ||
RUN: opt -thinlto-bc t1.ll -o t1.bc | ||
RUN: opt -thinlto-bc t2.ll -o t2.bc | ||
RUN: cp t1.bc t3.bc | ||
|
||
## Generate object files for mock.py to return. | ||
RUN: llc t1.ll --filetype=obj -o t1.obj | ||
RUN: llc t2.ll --filetype=obj -o t2.obj | ||
|
||
## Create response file containing shared ThinLTO linker arguments. | ||
## -start-lib/-end-lib is used to test the special case where unused lazy | ||
## bitcode inputs result in empty index/imports files. | ||
## Note that mock.py does not do any compilation; instead, it simply writes | ||
## the contents of the object files supplied on the command line into the | ||
## output object files in job order. | ||
RUN: echo "/entry:t1 /subsystem:console \ | ||
RUN: t1.bc t2.bc -start-lib t3.bc -end-lib /out:my.exe \ | ||
RUN: -thinlto-distributor:\"%python\" \ | ||
RUN: -thinlto-distributor-arg:\"%llvm_src_root/utils/dtlto/mock.py\" \ | ||
RUN: -thinlto-distributor-arg:t1.obj \ | ||
RUN: -thinlto-distributor-arg:t2.obj \ | ||
RUN: -thinlto-remote-compiler:fake.exe" > l.rsp | ||
|
||
## Check that without extra flags, no index/imports files are produced and | ||
## backend temp files are removed. | ||
RUN: lld-link @l.rsp | ||
RUN: ls | FileCheck %s \ | ||
RUN: --check-prefixes=NOBACKEND,NOOTHERS | ||
|
||
## Check that with /lldsavetemps and -thinlto-emit-imports-files backend | ||
## tempoary files are retained and no index/imports files are produced. | ||
RUN: rm -f *.imports *.thinlto.bc | ||
RUN: lld-link @l.rsp /lldsavetemps -thinlto-emit-imports-files | ||
RUN: ls | sort | FileCheck %s \ | ||
RUN: --check-prefixes=BACKEND,NOOTHERS | ||
|
||
## JSON jobs description, retained with --save-temps. | ||
## Note that DTLTO temporary files include a PID component. | ||
NOBACKEND-NOT: {{^}}my.[[#]].dist-file.json{{$}} | ||
BACKEND: {{^}}my.[[#]].dist-file.json{{$}} | ||
|
||
## Index/imports files for t1.bc. | ||
NOOTHERS-NOT: {{^}}t1.bc.imports{{$}} | ||
NOOTHERS-NOT: {{^}}t1.bc.thinlto.bc{{$}} | ||
|
||
## Index/imports files for t2.bc. | ||
NOOTHERS-NOT: {{^}}t2.bc.imports{{$}} | ||
NOOTHERS-NOT: {{^}}t2.bc.thinlto.bc{{$}} | ||
|
||
## Empty index/imports files for unused t3.bc. | ||
NOOTHERS-NOT: {{^}}t3.bc.imports{{$}} | ||
NOOTHERS-NOT: {{^}}t3.bc.thinlto.bc{{$}} | ||
|
||
#--- t1.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 @t1() { | ||
ret void | ||
} |
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.
It seems that most ThinLTO tests use the
-thinlto*
spelling.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.
Thanks for this comment. I have changed the tests to use the
-thinlto*
spelling for consistency. However, I strongly feel that for user facing content like the documentation and the new error message we should use the/thinlto*
spelling for consistency with the help text. The currently help text renders like: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.
OK:)