about summary refs log tree commit diff
path: root/compiler/rustc_codegen_ssa/src
AgeCommit message (Collapse)AuthorLines
2020-10-10Move finalize_session_directory call out of cg_llvmbjorn3-7/+0
This causes it to be called even when passing `-Zno-link`, when linking fails or when neither `--emit link` nor `--emit metadata` is used.
2020-10-10Move save_work_product_index call out of cg_llvmbjorn3-3/+3
2020-10-09Move supported_target_features query provider to cg_ssabjorn3-0/+16
2020-10-06Let backends access span informationkhyperia-0/+3
Sometimes, a backend may need to emit warnings, errors, or otherwise need to know the span of the current item in a basic block. So, add a set_span method to give the backend that information.
2020-10-05Auto merge of #77080 - richkadel:llvm-coverage-counters-2, r=tmandrybors-3/+10
Working branch-level code coverage Add a generalized implementation for computing branch-level coverage spans. This iteration resolves some of the challenges I had identified a few weeks ago. I've tried to implement a solution that is general enough to work for a lot of different graphs/patterns. It's encouraging to see the results on fairly large and complex crates seem to meet my expectations. This may be a "functionally complete" implementation. Except for bug fixes or edge cases I haven't run into yet, the next and essentially final step, I think, is to replace some Counters with CounterExpressions (where their counter values can be computed by adding or subtracting other counters/expressions). Examples of branch-level coverage support enabled in this PR: * https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-cov-reports-base/expected_show_coverage.coverage_of_drop_trait.txt * https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-cov-reports-base/expected_show_coverage.coverage_of_if.txt * https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-cov-reports-base/expected_show_coverage.coverage_of_if_else.txt * https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-cov-reports-base/expected_show_coverage.coverage_of_simple_loop.txt * https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-cov-reports-base/expected_show_coverage.coverage_of_simple_match.txt * ... _and others in the same directory_ Examples of coverage analysis results (MIR spanview files) used to inject counters in the right `BasicBlocks`: * https://htmlpreview.github.io/?https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-mir-cov-html-base/expected_mir_dump.coverage_of_drop_trait/coverage_of_drop_trait.main.-------.InstrumentCoverage.0.html * https://htmlpreview.github.io/?https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-mir-cov-html-base/expected_mir_dump.coverage_of_if/coverage_of_if.main.-------.InstrumentCoverage.0.html * https://htmlpreview.github.io/?https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-mir-cov-html-base/expected_mir_dump.coverage_of_if_else/coverage_of_if_else.main.-------.InstrumentCoverage.0.html * https://htmlpreview.github.io/?https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-mir-cov-html-base/expected_mir_dump.coverage_of_simple_loop/coverage_of_simple_loop.main.-------.InstrumentCoverage.0.html * https://htmlpreview.github.io/?https://github.com/richkadel/rust/blob/llvm-coverage-counters-2/src/test/run-make-fulldeps/instrument-coverage-mir-cov-html-base/expected_mir_dump.coverage_of_simple_match/coverage_of_simple_match.main.-------.InstrumentCoverage.0.html * ... _and others in the same directory_ Here is some sample coverage output after compiling a few real-world crates with the new branch-level coverage features: <img width="801" alt="Screen Shot 2020-09-25 at 1 03 11 PM" src="https://user-images.githubusercontent.com/3827298/94316848-fd882c00-ff39-11ea-9cff-0402d3abd1e7.png"> <img width="721" alt="Screen Shot 2020-09-25 at 1 00 36 PM" src="https://user-images.githubusercontent.com/3827298/94316886-11cc2900-ff3a-11ea-9d03-80b26c8a5173.png"> <img width="889" alt="Screen Shot 2020-09-25 at 12 54 57 PM" src="https://user-images.githubusercontent.com/3827298/94316900-18f33700-ff3a-11ea-8a80-58f67d84b8de.png"> r? `@tmandry` FYI: `@wesleywiser`
2020-10-05Updates to experimental coverage counter injectionRich Kadel-3/+10
This is a combination of 18 commits. Commit #2: Additional examples and some small improvements. Commit #3: fixed mir-opt non-mir extensions and spanview title elements Corrected a fairly recent assumption in runtest.rs that all MIR dump files end in .mir. (It was appending .mir to the graphviz .dot and spanview .html file names when generating blessed output files. That also left outdated files in the baseline alongside the files with the incorrect names, which I've now removed.) Updated spanview HTML title elements to match their content, replacing a hardcoded and incorrect name that was left in accidentally when originally submitted. Commit #4: added more test examples also improved Makefiles with support for non-zero exit status and to force validation of tests unless a specific test overrides it with a specific comment. Commit #5: Fixed rare issues after testing on real-world crate Commit #6: Addressed PR feedback, and removed temporary -Zexperimental-coverage -Zinstrument-coverage once again supports the latest capabilities of LLVM instrprof coverage instrumentation. Also fixed a bug in spanview. Commit #7: Fix closure handling, add tests for closures and inner items And cleaned up other tests for consistency, and to make it more clear where spans start/end by breaking up lines. Commit #8: renamed "typical" test results "expected" Now that the `llvm-cov show` tests are improved to normally expect matching actuals, and to allow individual tests to override that expectation. Commit #9: test coverage of inline generic struct function Commit #10: Addressed review feedback * Removed unnecessary Unreachable filter. * Replaced a match wildcard with remining variants. * Added more comments to help clarify the role of successors() in the CFG traversal Commit #11: refactoring based on feedback * refactored `fn coverage_spans()`. * changed the way I expand an empty coverage span to improve performance * fixed a typo that I had accidently left in, in visit.rs Commit #12: Optimized use of SourceMap and SourceFile Commit #13: Fixed a regression, and synched with upstream Some generated test file names changed due to some new change upstream. Commit #14: Stripping out crate disambiguators from demangled names These can vary depending on the test platform. Commit #15: Ignore llvm-cov show diff on test with generics, expand IO error message Tests with generics produce llvm-cov show results with demangled names that can include an unstable "crate disambiguator" (hex value). The value changes when run in the Rust CI Windows environment. I added a sed filter to strip them out (in a prior commit), but sed also appears to fail in the same environment. Until I can figure out a workaround, I'm just going to ignore this specific test result. I added a FIXME to follow up later, but it's not that critical. I also saw an error with Windows GNU, but the IO error did not specify a path for the directory or file that triggered the error. I updated the error messages to provide more info for next, time but also noticed some other tests with similar steps did not fail. Looks spurious. Commit #16: Modify rust-demangler to strip disambiguators by default Commit #17: Remove std::process::exit from coverage tests Due to Issue #77553, programs that call std::process::exit() do not generate coverage results on Windows MSVC. Commit #18: fix: test file paths exceeding Windows max path len
2020-10-05Instruct lld that our @ files are posix-style, not WindowsMark Rousskov-0/+6
An upstream LLVM change changed behavior here to respect the host system quoting rules; previously the posix-style format was always used for @files.
2020-10-05Pass tune-cpu to LLVMMingye Wang-0/+1
I think this is how it should work...
2020-10-04Rollup merge of #77521 - bjorn3:target_feature_whitelist, r=lcnrJonas Schievink-0/+151
Move target feature whitelist from cg_llvm to cg_ssa These target features have to be supported or at least emulated by alternative codegen backends anyway as they are used by common crates. By moving this list to cg_ssa, other codegen backends don't have to copy this code.
2020-10-04Move target feature whitelist from cg_llvm to cg_ssabjorn3-0/+151
These target features have to be supported or at least emulated by alternative codegen backends anyway as they are used by common crates. By moving this list to cg_ssa, other codegen backends don't have to copy this code.
2020-10-02Implement Make `handle_alloc_error` default to panic (for no_std + liballoc)Harald Hoyer-2/+4
Related: https://github.com/rust-lang/rust/issues/66741 Guarded with `#![feature(default_alloc_error_handler)]` a default `alloc_error_handler` is called, if a custom allocator is used and no other custom `#[alloc_error_handler]` is defined. The panic message does not contain the size anymore, because it would pull in the fmt machinery, which would blow up the code size significantly.
2020-10-01Rollup merge of #77202 - ehuss:defer-apple-sdkroot, r=petrochenkovDylan DPC-0/+86
Defer Apple SDKROOT detection to link time. This defers the detection of the SDKROOT for Apple iOS/tvOS targets to link time, instead of when the `Target` is defined. This allows commands that don't need to link to work (like `rustdoc` or `rustc --print=target-list`). This also makes `--print=target-list` a bit faster. This also removes the note in the platform support documentation about these targets being missing. When I wrote it, I misunderstood how the SDKROOT stuff worked. Notes: * This means that JSON spec targets can't explicitly override these flags. I think that is probably fine, as I believe the value is generally required, and can be set with the SDKROOT environment variable. * This changes `x86_64-apple-tvos` to use `appletvsimulator`. I think the original code was wrong (it was using `iphonesimulator`). Also, `x86_64-apple-tvos` seems broken in general, and I cannot build it locally. The `data_layout` does not appear to be correct (it is a copy of the arm64 layout instead of the x86_64 layout). I have not tried building Apple's LLVM to see if that helps, but I suspect it is just wrong (I'm uncertain since I don't know how the tvOS simulator works with its bitcode-only requirements). * I'm tempted to remove the use of `Result` for built-in target definitions, since I don't think they should be fallible. This was added in https://github.com/rust-lang/rust/pull/34980, but that only relates to JSON definitions. I think the built-in targets shouldn't fail. I can do this now, or not. Fixes #36156 Fixes #76584
2020-09-26Move add_apple_sdk out of add_pre_link_args.Eric Huss-1/+3
2020-09-27Rollup merge of #77208 - mati865:late-link-args-order, r=petrochenkovJonas Schievink-3/+3
Late link args order MSYS2 changed how winpthreads is built and as the result it now depends on more mingw-w64 libraries. This PR affects only MinGW targets since nobody else is using `late_link_args_{dynamic,static}`. Now the order is similar to how it used to be before https://github.com/rust-lang/rust/pull/67502.
2020-09-26Rollup merge of #77211 - est31:remove_unused_allow, r=oli-obkRalf Jung-3/+1
Remove unused #[allow(...)] statements from compiler/
2020-09-26Rollup merge of #77161 - est31:swich_len_already_trusted, r=petrochenkovRalf Jung-3/+1
Remove TrustedLen requirement from BuilderMethods::switch The main use case of TrustedLen is allowing APIs to specialize on it, but no use of it uses that specialization. Instead, only the .len() function provided by ExactSizeIterator is used, which is already required to be accurate. Thus, the TrustedLen requirement on BuilderMethods::switch is redundant.
2020-09-26Remove unused #[allow(...)] statements from compiler/est31-3/+1
2020-09-25Simplify some match statements on `DefPathDataName'marmeladema-8/+1
2020-09-25Rename `DefPathData::get_name()` to `DefPathData::name()`marmeladema-1/+1
2020-09-25Move from {{closure}}#0 syntax to {closure#0} for (def) path componentsmarmeladema-1/+9
2020-09-25Defer Apple SDKROOT detection to link time.Eric Huss-0/+84
2020-09-25Rollup merge of #76973 - lzutao:unstably-const-assume, r=oli-obkJonas Schievink-3/+3
Unstably allow assume intrinsic in const contexts Not sure much about this usage because there are concerns about [blocking optimization][1] and [slowing down LLVM][2] when using `assme` intrinsic in inline functions. But since Oli suggested in https://github.com/rust-lang/rust/issues/76960#issuecomment-695772221, here we are. [1]: https://github.com/rust-lang/rust/pull/54995#issuecomment-429302709 [2]: https://github.com/rust-lang/rust/issues/49572#issuecomment-589615423
2020-09-25Auto merge of #73453 - erikdesjardins:tuplayout, r=eddybbors-9/+27
Ignore ZST offsets when deciding whether to use Scalar/ScalarPair layout This is important because Scalar/ScalarPair layout previously would not be used if any ZST had nonzero offset. For example, before this change, only `((), u128)` would be laid out like `u128`, not `(u128, ())`. Fixes #63244
2020-09-25Link dynamic and static late_link_args before generic onesMateusz Mikuła-3/+3
2020-09-24Remove TrustedLen requirement from BuilderMethods::switchest31-3/+1
The main use case of TrustedLen is allowing APIs to specialize on it, but no use of it uses that specialization. Instead, only the .len() function provided by ExactSizeIterator is used, which is already required to be accurate. Thus, the TrustedLen requirement on BuilderMethods::switch is redundant.
2020-09-23/nightly/nightly-rustcErik Hofmayer-1/+1
2020-09-23Updated html_root_url for compiler cratesErik Hofmayer-1/+1
2020-09-21Rollup merge of #76872 - khyperia:remove_declare_methods, r=eddybRalf Jung-58/+16
Remove DeclareMethods Most of the `DeclareMethods` API was only used internally by rustc_codegen_llvm. As such, it makes no sense to require other backends to implement them. (`get_declared_value` and `declare_cfn` were used, in one place, specific to the `main` symbol, which I've replaced with a more specialized function to allow more flexibility in implementation - the intent is that `declare_c_main` can go away once we do something more clever, e.g. @eddyb has ideas around having a MIR shim or somesuch we can explore in a follow-up PR)
2020-09-20Rollup merge of #76832 - khyperia:backend_target_override, r=eddybRalf Jung-0/+7
Let backends define custom targets Add a target_override hook that takes priority over builtin targets.
2020-09-20Correct file path after some restructures in compilerLzu Tao-3/+3
2020-09-20Auto merge of #76964 - RalfJung:rollup-ybn06fs, r=RalfJungbors-3/+599
Rollup of 15 pull requests Successful merges: - #76722 (Test and fix Send and Sync traits of BTreeMap artefacts) - #76766 (Extract some intrinsics out of rustc_codegen_llvm) - #76800 (Don't generate bootstrap usage unless it's needed) - #76809 (simplfy condition in ItemLowerer::with_trait_impl_ref()) - #76815 (Fix wording in mir doc) - #76818 (Don't compile regex at every function call.) - #76821 (Remove redundant nightly features) - #76823 (black_box: silence unused_mut warning when building with cfg(miri)) - #76825 (use `array_windows` instead of `windows` in the compiler) - #76827 (fix array_windows docs) - #76828 (use strip_prefix over starts_with and manual slicing based on pattern length (clippy::manual_strip)) - #76840 (Move to intra doc links in core/src/future) - #76845 (Use intra docs links in core::{ascii, option, str, pattern, hash::map}) - #76853 (Use intra-doc links in library/core/src/task/wake.rs) - #76871 (support panic=abort in Miri) Failed merges: r? `@ghost`
2020-09-20Rollup merge of #76821 - est31:remove_redundant_nightly_features, ↵Ralf Jung-2/+0
r=oli-obk,Mark-Simulacrum Remove redundant nightly features Removes a bunch of redundant/outdated nightly features. The first commit removes a `core_intrinsics` use for which a stable wrapper has been provided since. The second commit replaces the `const_generics` feature with `min_const_generics` which might get stabilized this year. The third commit is the result of a trial/error run of removing every single feature and then adding it back if compile failed. A bunch of unused features are the result that the third commit removes.
2020-09-19Stop using the `const_eval` query for initializers of staticsOliver Scherer-19/+7
As a side effect, we now represent most promoteds as `ConstValue::Scalar` again. This is useful because all implict promoteds are just references anyway and most explicit promoteds are numeric arguments to `asm!` or SIMD instructions.
2020-09-18Remove DeclareMethodskhyperia-58/+16
2020-09-17PR feedbackkhyperia-2/+4
2020-09-17Let backends define custom targetskhyperia-0/+5
Add a target_override hook that takes priority over builtin targets.
2020-09-17Remove redundant #![feature(...)] 's from compiler/est31-2/+0
2020-09-15Extract some intrinsics out of rustc_codegen_llvmkhyperia-1/+599
A significant amount of intrinsics do not actually need backend-specific behaviors to be implemented, instead relying on methods already in rustc_codegen_ssa. So, extract those methods out to rustc_codegen_ssa, so that each backend doesn't need to reimplement the same code.
2020-09-10use push(char) instead of push_str(&str) to add single chars to stringsMatthias Krüger-2/+2
clippy::single-char-push-str
2020-09-09Add `-Z combine_cgu` flagVictor Ding-12/+53
Introduce a compiler option to let rustc combines all regular CGUs into a single one at the end of compilation. Part of Issue #64191
2020-09-04Change ty.kind to a methodLeSeulArtichaut-19/+19
2020-09-03Auto merge of #73996 - da-x:short-unique-paths, r=petrochenkovbors-8/+11
diagnostics: shorten paths of unique symbols This is a step towards implementing a fix for #50310, and continuation of the discussion in [Pre-RFC: Nicer Types In Diagnostics - compiler - Rust Internals](https://internals.rust-lang.org/t/pre-rfc-nicer-types-in-diagnostics/11139). Impressed upon me from previous discussion in #21934 that an RFC for this is not needed, and I should just come up with code. The recent improvements to `use` suggestions that I've contributed have given rise to this implementation. Contrary to previous suggestions, it's rather simple logic, and I believe it only reduces the amount of cognitive load that a developer would need when reading type errors. ----- If a symbol name can only be imported from one place, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path to the last component. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable from anywhere.
2020-09-03Rollup merge of #76167 - mati865:mingw-self-contained-heuristic, r=petrochenkovDylan DPC-92/+25
Replace MinGW library hack with heuristic controlling link mode Depends on https://github.com/rust-lang/rust/pull/76158 Closes https://github.com/rust-lang/rust/issues/68887
2020-09-02pretty: trim paths of unique symbolsDan Aloni-8/+11
If a symbol name can only be imported from one place for a type, and as long as it was not glob-imported anywhere in the current crate, we can trim its printed path and print only the name. This has wide implications on error messages with types, for example, shortening `std::vec::Vec` to just `Vec`, as long as there is no other `Vec` importable anywhere. This adds a new '-Z trim-diagnostic-paths=false' option to control this feature. On the good path, with no diagnosis printed, we should try to avoid issuing this query, so we need to prevent trimmed_def_paths query on several cases. This change also relies on a previous commit that differentiates between `Debug` and `Display` on various rustc types, where the latter is trimmed and presented to the user and the former is not.
2020-09-01Rollup merge of #76158 - mati865:self-contained-option, r=petrochenkovTyler Mandry-3/+3
Stabilise link-self-contained option MCP has been accepted: https://github.com/rust-lang/compiler-team/issues/343 I'll add improved heuristic in next PR.
2020-09-01Replace MinGW library hack with heuristic controlling link modeMateusz Mikuła-92/+25
2020-09-01Auto merge of #75529 - bugadani:bounds-check, r=nagisabors-5/+21
Eliminate some other bound checks when index comes from an enum #36962 introduced an assumption for the upper limit of the enum's value. This PR adds an assumption to the lower value as well. I've modified the original codegen test to show that derived (in that case, adding 1) values also don't generate bounds checks. However, this test is actually carefully crafted to not hit a bug: if the enum's variants are modified to 1 and 2 instead of 2 and 3, the test fails by adding a bounds check. I suppose this is an LLVM issue and #75525, while not exactly in this context should be tracking it. I'm not at all confident if this patch can be accepted, or even if it _should_ be accepted in this state. But I'm curious about what others think :) ~Improves~ Should improve #13926 but does not close it because it's not exactly predictable, where bounds checks may pop up against the assumptions.
2020-09-01Auto merge of #76071 - khyperia:configurable_to_immediate, r=eddybbors-63/+38
Make to_immediate/from_immediate configurable by backends `librustc_codegen_ssa` has the concept of an immediate vs. memory type, and `librustc_codegen_llvm` uses this distinction to implement `bool`s being `i8` in memory, and `i1` in immediate contexts. However, some of that implementation leaked into `codegen_ssa` when converting to/from immediate values. So, move those methods into builder traits, so that behavior can be configured by backends. This is useful if a backend is able to keep bools as bools, or, needs to do more trickery than just bools to bytes. (Note that there's already a large amount of things abstracted with "immediate types" - this is just bringing this particular thing in line to be abstracted as well) --- Pinging @eddyb since that's who I was talking about this change with when they suggested I submit a PR.
2020-08-31Rollup merge of #76002 - richkadel:llvm-coverage-map-gen-6b.3, r=tmandryTyler Mandry-1/+1
Fix `-Z instrument-coverage` on MSVC Found that `-C link-dead-code` (which was enabled automatically under `-Z instrument-coverage`) was causing the linking error that resulted in segmentation faults in coverage instrumented binaries. Link dead code is now disabled under MSVC, allowing `-Z instrument-coverage` to be enabled under MSVC for the first time. More details are included in Issue #76038 . Note this PR makes it possible to support `Z instrument-coverage` but does not enable instrument coverage for MSVC in existing tests. It will be enabled in another PR to follow this one (both PRs coming from original PR #75828). r? @tmandry FYI: @wesleywiser
2020-08-31Fix `-Z instrument-coverage` on MSVCRich Kadel-1/+1
Found that -C link-dead-code (which was enabled automatically under -Z instrument-coverage) was causing the linking error that resulted in segmentation faults in coverage instrumented binaries. Link dead code is now disabled under MSVC, allowing `-Z instrument-coverage` to be enabled under MSVC for the first time. More details are included in Issue #76038. (This PR was broken out from PR #75828)