-
Notifications
You must be signed in to change notification settings - Fork 12.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a smoketest for combining PGO with xLTO.
- Loading branch information
1 parent
30a3fad
commit 1de93a7
Showing
5 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
src/test/run-make-fulldeps/cross-lang-lto-pgo-smoketest/Makefile
This file contains 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,87 @@ | ||
# needs-matching-clang | ||
|
||
# This test makes sure that cross-language inlining can be used in conjunction | ||
# with profile-guided optimization. The test only tests that the whole workflow | ||
# can be executed without anything crashing. It does not test whether PGO or | ||
# xLTO have any specific effect on the generated code. | ||
|
||
-include ../tools.mk | ||
|
||
COMMON_FLAGS=-Copt-level=3 -Ccodegen-units=1 | ||
|
||
# LLVM doesn't support instrumenting binaries that use SEH: | ||
# https://bugs.llvm.org/show_bug.cgi?id=41279 | ||
# | ||
# Things work fine with -Cpanic=abort though. | ||
ifdef IS_MSVC | ||
COMMON_FLAGS+= -Cpanic=abort | ||
endif | ||
|
||
all: cpp-executable rust-executable | ||
|
||
cpp-executable: | ||
$(RUSTC) -Clinker-plugin-lto=on \ | ||
-Zpgo-gen="$(TMPDIR)"/cpp-profdata \ | ||
-o "$(TMPDIR)"/librustlib-xlto.a \ | ||
$(COMMON_FLAGS) \ | ||
./rustlib.rs | ||
$(CLANG) -flto=thin \ | ||
-fprofile-generate="$(TMPDIR)"/cpp-profdata \ | ||
-fuse-ld=lld \ | ||
-L "$(TMPDIR)" \ | ||
-lrustlib-xlto \ | ||
-o "$(TMPDIR)"/cmain \ | ||
-O3 \ | ||
./cmain.c | ||
$(TMPDIR)/cmain | ||
# Postprocess the profiling data so it can be used by the compiler | ||
"$(LLVM_BIN_DIR)"/llvm-profdata merge \ | ||
-o "$(TMPDIR)"/cpp-profdata/merged.profdata \ | ||
"$(TMPDIR)"/cpp-profdata/default_*.profraw | ||
$(RUSTC) -Clinker-plugin-lto=on \ | ||
-Zpgo-use="$(TMPDIR)"/cpp-profdata/merged.profdata \ | ||
-o "$(TMPDIR)"/librustlib-xlto.a \ | ||
$(COMMON_FLAGS) \ | ||
./rustlib.rs | ||
$(CLANG) -flto=thin \ | ||
-fprofile-use="$(TMPDIR)"/cpp-profdata/merged.profdata \ | ||
-fuse-ld=lld \ | ||
-L "$(TMPDIR)" \ | ||
-lrustlib-xlto \ | ||
-o "$(TMPDIR)"/cmain \ | ||
-O3 \ | ||
./cmain.c | ||
|
||
rust-executable: | ||
exit | ||
$(CLANG) ./clib.c -fprofile-generate="$(TMPDIR)"/rs-profdata -flto=thin -c -o $(TMPDIR)/clib.o -O3 | ||
(cd $(TMPDIR); $(AR) crus ./libxyz.a ./clib.o) | ||
$(RUSTC) -Clinker-plugin-lto=on \ | ||
-Zpgo-gen="$(TMPDIR)"/rs-profdata \ | ||
-L$(TMPDIR) \ | ||
$(COMMON_FLAGS) \ | ||
-Clinker=$(CLANG) \ | ||
-Clink-arg=-fuse-ld=lld \ | ||
-o $(TMPDIR)/rsmain \ | ||
./main.rs | ||
$(TMPDIR)/rsmain | ||
# Postprocess the profiling data so it can be used by the compiler | ||
"$(LLVM_BIN_DIR)"/llvm-profdata merge \ | ||
-o "$(TMPDIR)"/rs-profdata/merged.profdata \ | ||
"$(TMPDIR)"/rs-profdata/default_*.profraw | ||
$(CLANG) ./clib.c \ | ||
-fprofile-use="$(TMPDIR)"/rs-profdata/merged.profdata \ | ||
-flto=thin \ | ||
-c \ | ||
-o $(TMPDIR)/clib.o \ | ||
-O3 | ||
rm "$(TMPDIR)"/libxyz.a | ||
(cd $(TMPDIR); $(AR) crus ./libxyz.a ./clib.o) | ||
$(RUSTC) -Clinker-plugin-lto=on \ | ||
-Zpgo-use="$(TMPDIR)"/rs-profdata/merged.profdata \ | ||
-L$(TMPDIR) \ | ||
$(COMMON_FLAGS) \ | ||
-Clinker=$(CLANG) \ | ||
-Clink-arg=-fuse-ld=lld \ | ||
-o $(TMPDIR)/rsmain \ | ||
./main.rs |
9 changes: 9 additions & 0 deletions
9
src/test/run-make-fulldeps/cross-lang-lto-pgo-smoketest/clib.c
This file contains 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,9 @@ | ||
#include <stdint.h> | ||
|
||
uint32_t c_always_inlined() { | ||
return 1234; | ||
} | ||
|
||
__attribute__((noinline)) uint32_t c_never_inlined() { | ||
return 12345; | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/run-make-fulldeps/cross-lang-lto-pgo-smoketest/cmain.c
This file contains 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,12 @@ | ||
#include <stdint.h> | ||
|
||
// A trivial function defined in Rust, returning a constant value. This should | ||
// always be inlined. | ||
uint32_t rust_always_inlined(); | ||
|
||
|
||
uint32_t rust_never_inlined(); | ||
|
||
int main(int argc, char** argv) { | ||
return (rust_never_inlined() + rust_always_inlined()) * 0; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/test/run-make-fulldeps/cross-lang-lto-pgo-smoketest/main.rs
This file contains 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,11 @@ | ||
#[link(name = "xyz")] | ||
extern "C" { | ||
fn c_always_inlined() -> u32; | ||
fn c_never_inlined() -> u32; | ||
} | ||
|
||
fn main() { | ||
unsafe { | ||
println!("blub: {}", c_always_inlined() + c_never_inlined()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/run-make-fulldeps/cross-lang-lto-pgo-smoketest/rustlib.rs
This file contains 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,12 @@ | ||
#![crate_type="staticlib"] | ||
|
||
#[no_mangle] | ||
pub extern "C" fn rust_always_inlined() -> u32 { | ||
42 | ||
} | ||
|
||
#[no_mangle] | ||
#[inline(never)] | ||
pub extern "C" fn rust_never_inlined() -> u32 { | ||
421 | ||
} |