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

Implement optimize(size) and optimize(speed) attributes #55641

Open
wants to merge 4 commits into
base: master
from

Conversation

Projects
None yet
8 participants
@nagisa
Contributor

nagisa commented Nov 3, 2018

This PR implements both optimize(size) and optimize(speed) attributes.

While the functionality itself works fine now, this PR is not yet complete: the code might be messy in places and, most importantly, the compiletest must be improved with functionality to run tests with custom optimization levels. Otherwise the new attribute cannot be tested properly. Oh, and not all of the RFC is implemented – attribute propagation is not implemented for example.

TODO

  • Improve compiletest so that tests can be written;
  • Assign a proper error number (E9999 currently, no idea how to allocate a number properly);
  • Perhaps reduce the duplication in LLVM attribute assignment code…
@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Nov 3, 2018

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@nagisa

This comment has been minimized.

Contributor

nagisa commented Nov 3, 2018

cc #54882

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Nov 3, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:009315a3:start=1541237044741724763,finish=1541237046948850037,duration=2207125274
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
travis_time:start:tidy
tidy check
[00:03:49] * 568 error codes
[00:03:49] * highest error code: E9999
[00:03:50] tidy error: Found 1 features without a gate test.
[00:03:50] Expected a gate test for the feature 'optimize_attribute'.
[00:03:50] Hint: create a failing test file named 'feature-gate-optimize_attribute.rs'
[00:03:50]       in the 'ui' test suite, with its failures due to
[00:03:50]       missing usage of #![feature(optimize_attribute)].
[00:03:50] Hint: If you already have such a test and don't want to rename it,
[00:03:50]       you can also add a // gate-test-optimize_attribute line to the test file.
[00:03:50] some tidy checks failed
[00:03:50] 
[00:03:50] 
[00:03:50] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:03:50] 
[00:03:50] 
[00:03:50] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:03:50] Build completed unsuccessfully in 0:00:47
[00:03:50] Build completed unsuccessfully in 0:00:47
[00:03:50] Makefile:79: recipe for target 'tidy' failed
[00:03:50] make: *** [tidy] Error 1

The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:04133410
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
---
travis_time:end:29a33223:start=1541237288665578516,finish=1541237288669755760,duration=4177244
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0d79e220
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0014bf32
travis_time:start:0014bf32
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:0ca39a44
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

// If any of the items require optimize(speed), we must use speed optimisation globally
// and set either `optnone` or corresponding size-oriented optimisation level for the
// rest of the items in the crate. Those attributes are set specifically
for_speed

This comment has been minimized.

@nikic

nikic Nov 3, 2018

Contributor

I suspect that this will have some unintended fallout. While function passes are going to skip optnone functions, we'll also end up populating a full module pass manager, where likely not all module passes will ignore optnone functions (not to mention non-functions -- I don't believe there is an optnone for global variables.) Marking a single function for optimize(speed) may end up influencing codegen for the whole crate in non-trivial ways.

This comment has been minimized.

@nagisa

nagisa Nov 3, 2018

Contributor

This is a known caveat. Alas, to get optimize(speed) (or optimize(speed), now that I think about it) to work as intended, it is necessary to initialize some sort of pass manager.

Are you saying it is possible to have separate managers for functions and the rest of the module? That might be a better approach then.

This comment has been minimized.

@nagisa

nagisa Nov 3, 2018

Contributor

Alternative is to have these attributes not work with -Copt-level=0 at all, but that is not what I intended when I wrote the RFC.

This comment has been minimized.

@nikic

nikic Nov 3, 2018

Contributor

Are you saying it is possible to have separate managers for functions and the rest of the module? That might be a better approach then.

As far as I'm aware that's not possible. While LLVM has a separate function pass manager, it is only used for a few early optimizations, the bulk of the work (including most function passes) are performed by the module pass manager.

Alternative is to have these attributes to not work with -Copt-level=0 at all, but that is not what I intended when I wrote the RFC.

This would probably be the most predictable approach. It would make optimize(size) control the optsize attribute and optimize(speed) an opt-out for the optsize attribute (which, having looked at the RFC thread now, appears to be the motivation for having it). Either attribute would have no impact on global codegen, which is still controlled by -C opt-level. -C opt-level=0 would continue to mean "don't touch my code".

@bors

This comment has been minimized.

Contributor

bors commented Nov 4, 2018

☔️ The latest upstream changes (presumably #55349) made this pull request unmergeable. Please resolve the merge conflicts.

@pnkfelix

This comment has been minimized.

Member

pnkfelix commented Nov 5, 2018

(What's here so far seems fine to me. Of course its WIP and it sounds like there may be future changes that will also need review.)

@pnkfelix

This comment has been minimized.

Member

pnkfelix commented Nov 7, 2018

The weakness of compiletest as documented in the description is related (at least tangentially) to #55757

@TimNN

This comment has been minimized.

Contributor

TimNN commented Nov 13, 2018

Ping from triage @nagisa: What is the status of this PR?

@nagisa

This comment has been minimized.

Contributor

nagisa commented Nov 13, 2018

I’ll get back to this as soon as I get the other tasks off my plate and time onto it :)

@nagisa nagisa force-pushed the nagisa:optimize-attr branch from 9201f8a to b45e5ac Nov 18, 2018

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Nov 18, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:025316be:start=1542563866528197442,finish=1542563867660478479,duration=1132281037
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
travis_time:start:tidy
tidy check
[00:04:09] * 569 error codes
[00:04:09] * highest error code: E9999
[00:04:09] tidy error: Found 1 features without a gate test.
[00:04:09] Expected a gate test for the feature 'optimize_attribute'.
[00:04:09] Hint: create a failing test file named 'feature-gate-optimize_attribute.rs'
[00:04:09]       in the 'ui' test suite, with its failures due to
[00:04:09]       missing usage of #![feature(optimize_attribute)].
[00:04:09] Hint: If you already have such a test and don't want to rename it,
[00:04:09]       you can also add a // gate-test-optimize_attribute line to the test file.
[00:04:10] some tidy checks failed
[00:04:10] 
[00:04:10] 
[00:04:10] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:10] 
[00:04:10] 
[00:04:10] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:10] Build completed unsuccessfully in 0:00:43
[00:04:10] Build completed unsuccessfully in 0:00:43
[00:04:10] Makefile:79: recipe for target 'tidy' failed
[00:04:10] make: *** [tidy] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:04e66bd9
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sun Nov 18 18:02:06 UTC 2018
---
travis_time:end:030b2d33:start=1542564127238716706,finish=1542564127243395009,duration=4678303
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:2fe813f3
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:02f277c2
travis_time:start:02f277c2
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:06d9b8cc
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Nov 18, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:03445018:start=1542571687416275752,finish=1542571689995099888,duration=2578824136
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
travis_time:start:tidy
tidy check
[00:04:01] * 569 error codes
[00:04:01] * highest error code: E9999
[00:04:01] Expected a gate test for the feature 'optimize_attribute'.
[00:04:01] tidy error: Found 1 features without a gate test.
[00:04:01] Hint: create a failing test file named 'feature-gate-optimize_attribute.rs'
[00:04:01]       in the 'ui' test suite, with its failures due to
[00:04:01]       missing usage of #![feature(optimize_attribute)].
[00:04:01] Hint: If you already have such a test and don't want to rename it,
[00:04:01]       you can also add a // gate-test-optimize_attribute line to the test file.
[00:04:02] some tidy checks failed
[00:04:02] 
[00:04:02] 
[00:04:02] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:04:02] 
[00:04:02] 
[00:04:02] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:04:02] Build completed unsuccessfully in 0:00:53
[00:04:02] Build completed unsuccessfully in 0:00:53
[00:04:02] make: *** [tidy] Error 1
[00:04:02] Makefile:79: recipe for target 'tidy' failed
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:19464ff0
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sun Nov 18 20:12:22 UTC 2018
---
travis_time:end:009d05e4:start=1542571943258485377,finish=1542571943265865767,duration=7380390
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0386dedc
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0153f7c0
travis_time:start:0153f7c0
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:024659a0
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@nagisa nagisa force-pushed the nagisa:optimize-attr branch from 61526d3 to 7701073 Nov 25, 2018

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Nov 25, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:11e078a8:start=1543165258662792543,finish=1543165260971378223,duration=2308585680
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
travis_time:start:tidy
tidy check
[00:03:01] * 569 error codes
[00:03:01] * highest error code: E9999
[00:03:01] tidy error: Found 1 features without a gate test.
[00:03:01] Expected a gate test for the feature 'optimize_attribute'.
[00:03:01] Hint: create a failing test file named 'feature-gate-optimize_attribute.rs'
[00:03:01]       in the 'ui' test suite, with its failures due to
[00:03:01]       missing usage of #![feature(optimize_attribute)].
[00:03:01] Hint: If you already have such a test and don't want to rename it,
[00:03:01]       you can also add a // gate-test-optimize_attribute line to the test file.
[00:03:02] some tidy checks failed
[00:03:02] 
[00:03:02] 
[00:03:02] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/tidy" "/checkout/src" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "--no-vendor" "--quiet"
[00:03:02] 
[00:03:02] 
[00:03:02] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test src/tools/tidy
[00:03:02] Build completed unsuccessfully in 0:00:56
[00:03:02] Build completed unsuccessfully in 0:00:56
[00:03:02] Makefile:79: recipe for target 'tidy' failed
[00:03:02] make: *** [tidy] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:13bc2fb6
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sun Nov 25 17:04:12 UTC 2018
---
travis_time:end:143006b0:start=1543165452898384025,finish=1543165452903479782,duration=5095757
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:08c2bb24
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:0b2352f1
travis_time:start:0b2352f1
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_fold:start:after_failure.6
travis_time:start:126bd930
$ dmesg | grep -i kill

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@nagisa nagisa force-pushed the nagisa:optimize-attr branch from 7701073 to b38143d Nov 25, 2018

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Nov 25, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:018b87af:start=1543168873127460606,finish=1543168874279320257,duration=1151859651
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
[00:50:32] .................................................................................................... 100/5053
[00:50:35] .................................................................................................... 200/5053
[00:50:38] .............................ii............................................ii...................ii.. 300/5053
[00:50:41] ..............................................................................................iii... 400/5053
[00:50:44] .....iiiiiiii.iii............................iii...........................................i........ 500/5053
[00:50:51] .................................................................................................... 700/5053
[00:50:56] .....................................................................................i...........i.. 800/5053
[00:51:00] .................................................................................................... 900/5053
[00:51:03] ....iiiii..................ii.iiii.................................................................. 1000/5053
---
travis_time:start:test_codegen
Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:06:01] 
[01:06:01] running 120 tests
[01:06:04] i..ii...iii..iiii.....i...i.........i..iii...........i.....i........ii...i..i.ii..............i...ii 100/120
[01:06:05] ..ii.i.....i.iii....
[01:06:05] 
[01:06:05]  finished in 3.534
[01:06:05] travis_fold:end:test_codegen

---
travis_time:start:test_debuginfo
Check compiletest suite=debuginfo mode=debuginfo-both (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:06:19] 
[01:06:19] running 118 tests
[01:06:44] .iiiii...i.....i..i...i..i.i..i.i..i.....i..i....i..........iiii.........i.i....i...i.......ii.i.i.i 100/118
[01:06:48] ......iii.i.....ii
[01:06:48] 
[01:06:48]  finished in 28.524
[01:06:48] travis_fold:end:test_debuginfo

---
travis_time:start:test_run-make-fulldeps
Check compiletest suite=run-make-fulldeps mode=run-make (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[01:39:23] 
[01:39:23] running 192 tests
[01:39:50] .....................................................F.............................................. 100/192
[01:40:46] ...........................................................................................test [run-make] run-make-fulldeps/long-linker-command-lines has been running for over 60 seconds
[01:41:34] failures:
[01:41:34] 
[01:41:34] ---- [run-make] run-make-fulldeps/inline-always-many-cgu stdout ----
[01:41:34] 
[01:41:34] 
[01:41:34] error: make failed
[01:41:34] status: exit code: 2
[01:41:34] command: "make"
[01:41:34] stdout:
[01:41:34] ------------------------------------------
[01:41:34] make[1]: Entering directory '/checkout/src/test/run-make-fulldeps/inline-always-many-cgu'
[01:41:34] LD_LIBRARY_PATH="/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/inline-always-many-cgu/inline-always-many-cgu:/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-bootstrap-tools/x86_64-unknown-linux-gnu/release/deps:/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/lib:" '/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc' --out-dir /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/inline-always-many-cgu/inline-always-many-cgu -L /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/inline-always-many-cgu/inline-always-many-cgu  foo.rs --emit llvm-ir -C codegen-units=2
[01:41:34] if cat /checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps/inline-always-many-cgu/inline-always-many-cgu/*.ll | "/checkout/src/etc/cat-and-grep.sh" -e '\bcall\b'; then \
[01:41:34]  echo "found call instruction when one wasn't expected"; \
[01:41:34]  exit 1; \
[01:41:34] fi
[01:41:34] [[[ begin stdout ]]]
[01:41:34] ; ModuleID = 'foo.3a1fbbbh-cgu.0'
[01:41:34] source_filename = "foo.3a1fbbbh-cgu.0"
[01:41:34] target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
[01:41:34] target triple = "x86_64-unknown-linux-gnu"
[01:41:34] 
[01:41:34] ; foo::a::bar
[01:41:34] ; Function Attrs: noinline nonlazybind optnone uwtable
[01:41:34] define void @_ZN3foo1a3bar17h93d7ab41e03a35d6E() unnamed_addr #0 {
[01:41:34]   ret void
[01:41:34] }
[01:41:34] 
[01:41:34] 
[01:41:34] attributes #0 = { noinline nonlazybind optnone uwtable "probe-stack"="__rust_probestack" }
[01:41:34] 
[01:41:34] !llvm.module.flags = !{!0}
[01:41:34] 
[01:41:34] !0 = !{i32 2, !"RtLibUseGOT", i32 1}
[01:41:34] ; ModuleID = 'foo.3a1fbbbh-cgu.1'
[01:41:34] source_filename = "foo.3a1fbbbh-cgu.1"
[01:41:34] target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
[01:41:34] target triple = "x86_64-unknown-linux-gnu"
[01:41:34] 
[01:41:34] ; foo::a::foo
[01:41:34] ; Function Attrs: noinline nonlazybind optnone uwtable
[01:41:34] define internal void @_ZN3foo1a3foo17h4934260c56dc6ae5E() unnamed_addr #0 {
[01:41:34]   ret void
[01:41:34] thread 'main' panicked at 'Some tests failed', src/tools/compiletest/src/main.rs:503:22
[01:41:34] }
[01:41:34] 
[01:41:34] 
[01:41:34] ; Function Attrs: noinline nonlazybind optnone uwtable
[01:41:34] define void @bar() unnamed_addr #0 {
[01:41:34] start:
[01:41:34] ; call foo::a::foo
[01:41:34]   call void @_ZN3foo1a3foo17h4934260c56dc6ae5E()
[01:41:34]   br label %bb1
[01:41:34] 
[01:41:34] bb1:                                              ; preds = %start
[01:41:34]   ret void
[01:41:34] }
[01:41:34] 
[01:41:34] attributes #0 = { noinline nonlazybind optnone uwtable "probe-stack"="__rust_probestack" }
[01:41:34] 
[01:41:34] !llvm.module.flags = !{!0}
[01:41:34] 
[01:41:34] !0 = !{i32 2, !"RtLibUseGOT", i32 1}
[01:41:34] 
[01:41:34] [[[ end stdout ]]]
[01:41:34] found call instruction when one wasn't expected
[01:41:34] Makefile:4: recipe for target 'all' failed
[01:41:34] make[1]: Leaving directory '/checkout/src/test/run-make-fulldeps/inline-always-many-cgu'
[01:41:34] ------------------------------------------
[01:41:34] stderr:
[01:41:34] ------------------------------------------
[01:41:34] ------------------------------------------
[01:41:34] warning: ignoring emit path because multiple .ll files were produced
[01:41:34] 
[01:41:34] make[1]: *** [all] Error 1
[01:41:34] ------------------------------------------
[01:41:34] 
[01:41:34] thread '[run-make] run-make-fulldeps/inline-always-many-cgu' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3324:9
[01:41:34] note: Run with `RUST_BACKTRACE=1` for a backtrace.
---
[01:41:34] test result: FAILED. 191 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out
[01:41:34] 
[01:41:34] 
[01:41:34] 
[01:41:34] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--rustdoc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustdoc" "--src-base" "/checkout/src/test/run-make-fulldeps" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/run-make-fulldeps" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "run-make" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck" "/usr/lib/llvm-5.0/bin/FileCheck" "--host-rustcflags" "-Crpath -O -Zunstable-options " "--target-rustcflags" "-Crpath -O -Zunstable-options  -Lnative=/checkout/obj/build/x86_64-unknown-linux-gnu/native/rust-test-helpers" "--docck-python" "/usr/bin/python2.7" "--lldb-python" "/usr/bin/python2.7" "--gdb" "/usr/bin/gdb" "--quiet" "--llvm-version" "5.0.0\n" "--system-llvm" "--cc" "cc" "--cxx" "c++" "--cflags" "-ffunction-sections -fdata-sections -fPIC -m64" "--llvm-components" "aarch64 aarch64asmparser aarch64asmprinter aarch64codegen aarch64desc aarch64disassembler aarch64info aarch64utils all all-targets amdgpu amdgpuasmparser amdgpuasmprinter amdgpucodegen amdgpudesc amdgpudisassembler amdgpuinfo amdgpuutils analysis arm armasmparser armasmprinter armcodegen armdesc armdisassembler arminfo asmparser asmprinter binaryformat bitreader bitwriter bpf bpfasmprinter bpfcodegen bpfdesc bpfdisassembler bpfinfo codegen core coroutines coverage debuginfocodeview debuginfodwarf debuginfomsf debuginfopdb demangle dlltooldriver engine executionengine globalisel hexagon hexagonasmparser hexagoncodegen hexagondesc hexagondisassembler hexagoninfo instcombine instrumentation interpreter ipo irreader lanai lanaiasmparser lanaiasmprinter lanaicodegen lanaidesc lanaidisassembler lanaiinfo libdriver lineeditor linker lto mc mcdisassembler mcjit mcparser mips mipsasmparser mipsasmprinter mipscodegen mipsdesc mipsdisassembler mipsinfo mirparser msp430 msp430asmprinter msp430codegen msp430desc msp430info native nativecodegen nvptx nvptxasmprinter nvptxcodegen nvptxdesc nvptxinfo objcarcopts object objectyaml option orcjit passes powerpc powerpcasmparser powerpcasmprinter powerpccodegen powerpcdesc powerpcdisassembler powerpcinfo profiledata runtimedyld scalaropts selectiondag sparc sparcasmparser sparcasmprinter sparccodegen sparcdesc sparcdisassembler sparcinfo support symbolize systemz systemzasmparser systemzasmprinter systemzcodegen systemzdesc systemzdisassembler systemzinfo tablegen target transformutils vectorize x86 x86asmparser x86asmprinter x86codegen x86desc x86disassembler x86info x86utils xcore xcoreasmprinter xcorecodegen xcoredesc xcoredisassembler xcoreinfo" "--llvm-cxxflags" "-I/usr/lib/llvm-5.0/include -std=c++0x -fuse-ld=gold -Wl,--no-keep-files-mapped -Wl,--no-map-whole-files -fPIC -fvisibility-inlines-hidden -Werror=date-time -std=c++11 -Wall -W -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment -ffunction-sections -fdata-sections -O2 -DNDEBUG -g1  -fno-exceptions -DLLVM_BUILD_GLOBAL_ISEL -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS" "--ar" "ar" "--adb-path" "adb" "--adb-test-dir" "/data/tmp/work" "--android-cross-path" "" "--color" "always"
[01:41:34] 
[01:41:34] 
[01:41:34] failed to run: /checkout/obj/build/bootstrap/debug/bootstrap test
[01:41:34] Build completed unsuccessfully in 0:54:54
[01:41:34] Build completed unsuccessfully in 0:54:54
[01:41:34] Makefile:58: recipe for target 'check' failed
[01:41:34] make: *** [check] Error 1
The command "stamp sh -x -c "$RUN_SCRIPT"" exited with 2.
travis_time:start:01bec35c
$ date && (curl -fs --head https://google.com | grep ^Date: | sed 's/Date: //g' || true)
Sun Nov 25 19:42:57 UTC 2018
---
travis_time:end:03323db1:start=1543174983141873234,finish=1543174983149887054,duration=8013820
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:0f711d4d
$ ln -s . checkout && for CORE in obj/cores/core.*;

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

@nagisa

This comment has been minimized.

Contributor

nagisa commented Nov 25, 2018

The failing test seems to be invalid. Namely, it seems that the test is compiling with optimisations disabled and yet checking for inline(always) which is no-op in that case.

cc @alexcrichton do you know/remember why the test is compiled without optimisations? Will the test be just as valid if I slap a -Copt-level=1 on it’s rustc invocations?

@alexcrichton

This comment has been minimized.

Member

alexcrichton commented Nov 26, 2018

I think that's a test that #[inline(always)] is respected in all modes, including opt-level=0. Did this PR break that though?

@nagisa

This comment has been minimized.

Contributor

nagisa commented Nov 26, 2018

@alexcrichton

This comment has been minimized.

Member

alexcrichton commented Nov 26, 2018

We well the intention of the test is that we do respect the inline always attribute at O0, and we do execute the necessary passes to handle inline always functions. I don't believe this is functionality that we can break, crates rely on this in the wild

@nagisa

This comment has been minimized.

Contributor

nagisa commented Nov 26, 2018

Ah, okay, makes sense. I’m slightly surprised we run any passes at -Copt-level=0, but then it also makes sense that we do. I’ll just have to change approach in this PR with that in mind.

@bors

This comment has been minimized.

Contributor

bors commented Nov 30, 2018

☔️ The latest upstream changes (presumably #49219) made this pull request unmergeable. Please resolve the merge conflicts.

@nagisa nagisa force-pushed the nagisa:optimize-attr branch from b38143d to 71d27ba Dec 1, 2018

@nagisa nagisa changed the title from [WIP] Implement optimize(size) and optimize(speed) attributes to Implement optimize(size) and optimize(speed) attributes Dec 1, 2018

@nagisa

This comment has been minimized.

Contributor

nagisa commented Dec 1, 2018

I think this is ready-to-merge now. Perhaps it would have been a great idea to add support for revisions for codegen tests in a separate PR… but hey, it is now possible to have tests with their own optimisation levels! It might be sensible to open up revisions to other test types as well (which should be just removal of the panic/assertion away).

@alexcrichton I used the new revisions support for codegen tests added in this PR to write a proper test for the inline(always) in -Copt-level=0. You can see it at src/test/codegen/inline-always-works-always.rs.

@nagisa nagisa force-pushed the nagisa:optimize-attr branch from 71d27ba to 913072f Dec 1, 2018

@bors

This comment has been minimized.

Contributor

bors commented Dec 3, 2018

☔️ The latest upstream changes (presumably #56451) made this pull request unmergeable. Please resolve the merge conflicts.

@nagisa nagisa force-pushed the nagisa:optimize-attr branch 2 times, most recently from d1976f2 to 53b611a Dec 6, 2018

@bors

This comment has been minimized.

Contributor

bors commented Dec 8, 2018

☔️ The latest upstream changes (presumably #56578) made this pull request unmergeable. Please resolve the merge conflicts.

@nagisa nagisa force-pushed the nagisa:optimize-attr branch from 53b611a to 04d0a4b Dec 8, 2018

@bors

This comment has been minimized.

Contributor

bors commented Dec 13, 2018

☔️ The latest upstream changes (presumably #55982) made this pull request unmergeable. Please resolve the merge conflicts.

@pnkfelix

This comment has been minimized.

Member

pnkfelix commented Dec 13, 2018

I plan to start a (re-)review today or tomorrow, under the assumption that the merge-conflicts can be trivially resolved.

// are present).
config::OptLevel::Size => config::OptLevel::Default,
config::OptLevel::SizeMin => config::OptLevel::Default,
};

This comment has been minimized.

@nikic

nikic Dec 13, 2018

Contributor

If I got this right, when we're optimizing for Size or SizeMin and there is a optimize(speed) attribute, then this code switches us to create a PM for OptLevel = 2 and SizeLevel = 0, instead of OptLevel = 2 and SizeLevel = 1/2. What's the motivation for that?

It shouldn't make much of a difference either way (PM construction depends on SizeLevel only in a few minor ways -- ideally those should be switched to check for optsize attributes), just wondering why this particular behavior was picked. Without it, we could save the backend_optimization_level concept.

This comment has been minimized.

@nagisa

nagisa Dec 13, 2018

Contributor

The idea is that we it should likely be the default to have -Copt-level=s (for those who care about size) and explicitly annotate #[optimize(speed)] where profiling indicates that it is necessary.

In this scenario we want to make sure that we avoid pessimizing functions annotated with #[optimize(speed)] to the greatest extent feasible. Hence, if a #[optimize(size)] function is found in a module, we instead switch over to -Copt-level=2 and hope that annotating all the functions with optsize/minsize will have mostly the same effect that -Copt-level=s had previously with no #[optimize(size)] attributes in the crate.

This comment has been minimized.

@nagisa

nagisa Dec 13, 2018

Contributor

(FWIW a possible extension to the RFC was mentioned that we could make it possible to specify both the "speed" level and "size" level, in which case this code would be switched to use the specified "speed" and "size" levels where necessary)

@nagisa nagisa force-pushed the nagisa:optimize-attr branch from 04d0a4b to 2ee5472 Dec 13, 2018

@nagisa

This comment has been minimized.

Contributor

nagisa commented Dec 13, 2018

@pnkfelix rebased for your convenience.

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Dec 13, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:06f3541a:start=1544709911813303195,finish=1544709914339528575,duration=2526225380
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
[00:22:11]    Compiling rustc-demangle v0.1.9
[00:22:18]    Compiling memmap v0.6.2
[00:22:18]    Compiling num_cpus v1.8.0
[00:22:19]    Compiling rustc_llvm v0.0.0 (/checkout/src/librustc_llvm)
[00:22:39] error: expected item, found `>>`
[00:22:39]    |
[00:22:39]    |
[00:22:39] 19 | >>>>>>> cd9b37c1721... Implement optimize(size) and optimize(speed)
[00:22:39]    | ^^ expected item
[00:22:39] error: aborting due to previous error
[00:22:39] 
[00:22:39] error: Could not compile `rustc_codegen_llvm`.
[00:22:39] 
[00:22:39] 
[00:22:39] To learn more, run the command again with --verbose.
[00:22:39] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0/bin/cargo" "rustc" "--target" "x86_64-unknown-linux-gnu" "-j" "4" "--release" "--locked" "--color" "always" "--manifest-path" "/checkout/src/librustc_codegen_llvm/Cargo.toml" "--features" "" "--message-format" "json"
[00:22:39] expected success, got: exit code: 101
[00:22:39] travis_fold:start:stage0-rustc_codegen_llvm
travis_time:start:stage0-rustc_codegen_llvm
failed to run: /checkout/obj/build/bootstrap/debug/bootstrap build
[00:22:39] Build completed unsuccessfully in 0:16:31
[00:22:39] make: *** [all] Error 1
[00:22:39] Makefile:28: recipe for target 'all' failed
73052 ./.git/modules
73048 ./.git/modules/src
69912 ./src/llvm-emscripten/lib
68396 ./src/test
---
travis_time:end:316144da:start=1544711284370007834,finish=1544711284377851121,duration=7843287
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:118f7de1
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|'); if [ -f "$EXE" ]; then printf travis_fold":start:crashlog\n\033[31;1m%s\033[0m\n" "$CORE"; gdb --batch -q -c "$CORE" "$EXE" -iex 'set auto-load off' -iex 'dir src/' -iex 'set sysroot .' -ex bt -ex q; echo travis_fold":"end:crashlog; fi; done || true
travis_fold:end:after_failure.4
travis_fold:start:after_failure.5
travis_time:start:019f1c98
travis_time:start:019f1c98
$ cat ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers || true
cat: ./obj/build/x86_64-unknown-linux-gnu/native/asan/build/lib/asan/clang_rt.asan-dynamic-i386.vers: No such file or directory
travis_fold:end:after_failure.5
travis_

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

nagisa added some commits Oct 27, 2018

Add an idealistic test for optimize attribute
Alas it does not currently work, because of limitations in compiletest…
Support revisions for codegen tests
`compile-flags: -Copt-level` will avoid adding -O. Similarly for -g and
-Cdebuglevel.

@nagisa nagisa force-pushed the nagisa:optimize-attr branch from 2ee5472 to 208e817 Dec 13, 2018

@rust-highfive

This comment has been minimized.

Collaborator

rust-highfive commented Dec 13, 2018

The job x86_64-gnu-llvm-5.0 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
travis_time:end:20ca0f50:start=1544711753415792650,finish=1544711755885989429,duration=2470196779
$ git checkout -qf FETCH_HEAD
travis_fold:end:git.checkout

Encrypted environment variables have been removed for security reasons.
See https://docs.travis-ci.com/user/pull-requests/#Pull-Requests-and-Security-Restrictions
$ export SCCACHE_BUCKET=rust-lang-ci-sccache2
$ export SCCACHE_REGION=us-west-1
Setting environment variables from .travis.yml
$ export IMAGE=x86_64-gnu-llvm-5.0
---
travis_time:start:test_codegen
Check compiletest suite=codegen mode=codegen (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu)
[00:58:19] 
[00:58:19] running 127 tests
[00:58:21] i..ii...iii..iiii.....i...i........F....i...iii............i.....i.........ii...i..i.ii............. 100/127
/test/codegen/inline-always-works-always.NO-OPT/inline-always-works-always.ll:44:5: note: previous match ended here
[00:58:22] bb1: ; preds = %cleanup
[00:58:22]     ^
[00:58:22] /checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen/inline-always-works-always.NO-OPT/inline-always-works-always.ll:45:1: note: non-matching line after previous match is here
[00:58:22]  call void @llvm.trap()
[00:58:22] 
[00:58:22] ------------------------------------------
[00:58:22] 
[00:58:22] 
[00:58:22] thread '[codegen] codegen/inline-always-works-always.rs#NO-OPT' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:3294:9
[00:58:22] 
[00:58:22] 
[00:58:22] failures:
[00:58:22] failures:
[00:58:22]     [codegen] codegen/inline-always-works-always.rs#NO-OPT
[00:58:22] test result: FAILED. 92 passed; 1 failed; 34 ignored; 0 measured; 0 filtered out
[00:58:22] 
[00:58:22] 
[00:58:22] 
[00:58:22] 
[00:58:22] command did not execute successfully: "/checkout/obj/build/x86_64-unknown-linux-gnu/stage0-tools-bin/compiletest" "--compile-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib" "--run-lib-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib" "--rustc-path" "/checkout/obj/build/x86_64-unknown-linux-gnu/stage2/bin/rustc" "--src-base" "/checkout/src/test/codegen" "--build-base" "/checkout/obj/build/x86_64-unknown-linux-gnu/test/codegen" "--stage-id" "stage2-x86_64-unknown-linux-gnu" "--mode" "codegen" "--target" "x86_64-unknown-linux-gnu" "--host" "x86_64-unknown-linux-gnu" "--llvm-filecheck"ript:"; df -h; du . | sort -nr | head -n100
---
travis_time:end:06207717:start=1544715268742509360,finish=1544715268747431607,duration=4922247
travis_fold:end:after_failure.3
travis_fold:start:after_failure.4
travis_time:start:089b1a48
$ ln -s . checkout && for CORE in obj/cores/core.*; do EXE=$(echo $CORE | sed 's|obj/cores/core\.[0-9]*\.!checkout!\(.*\)|\1|;y|!|/|');

I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact @TimNN. (Feature Requests)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment