Commit graph

104 commits

Author SHA1 Message Date
Rich Kadel 1973f84ebb Addressed all feedback to date 2020-11-05 18:24:17 -08:00
Rich Kadel 198ba3bd1c Injecting expressions in place of counters where helpful
Implementing the Graph traits for the BasicCoverageBlock
graph.

optimized replacement of counters with expressions plus new BCB graphviz

* Avoid adding coverage to unreachable blocks.
* Special case for Goto at the end of the body. Make it non-reportable.

Improved debugging and formatting options (from env)

Don't automatically add counters to BCBs without CoverageSpans. They may
still get counters but only if there are dependencies from
other BCBs that have spans, I think.

Make CodeRegions optional for Counters too. It is
possible to inject counters (`llvm.instrprof.increment` intrinsic calls
without corresponding code regions in the coverage map. An expression
can still uses these counter values.

Refactored instrument_coverage.rs -> instrument_coverage/mod.rs, and
then broke up the mod into multiple files.

Compiling with coverage, with the expression optimization, works on
the json5format crate and its dependencies.

Refactored debug features from mod.rs to debug.rs
2020-11-05 18:24:15 -08:00
Rich Kadel c7747cc772 Rust coverage before splitting instrument_coverage.rs 2020-11-05 18:24:12 -08:00
bors 89631663b7 Auto merge of #78280 - bugadani:span, r=lcnr
Codegen: Query span as late as possible
2020-11-04 17:17:01 +00:00
oli abacaf2aef u128 truncation and sign extension are not just interpreter related 2020-11-04 13:41:58 +00:00
oli df4d717d0b s/Scalar::Raw/Scalar::Int 2020-11-04 10:11:31 +00:00
Oliver Scherer 362123dd75 Split the "raw integer bytes" part out of Scalar 2020-11-04 09:58:59 +00:00
Mara Bos 52405f7c0c
Rollup merge of #77950 - arlosi:sha256, r=eddyb
Add support for SHA256 source file hashing

Adds support for `-Z src-hash-algorithm sha256`, which became available in LLVM 11.

Using an older version of LLVM will cause an error `invalid checksum kind` if the hash algorithm is set to sha256.

r? `@eddyb`
cc #70401 `@est31`
2020-11-03 19:32:26 +01:00
bors 7b5a9e9cd2 Auto merge of #78448 - rylev:cache-foreign_modules, r=wesleywiser
foreign_modules query hash table lookups

When compiling a large monolithic crate we're seeing huge times in the `foreign_modules` query due to repeated iteration over foreign modules (in order to find a module by its id). This implements hash table lookups so that which massively reduces time spent in that query in this particular case. We'll need to see if the overhead of creating the hash table has a negative impact on performance in more normal compilation scenarios.

I'm working with `@wesleywiser` on this.
2020-11-03 04:27:27 +00:00
Anthony Ramine 6febaf2419 Implement -Z relax-elf-relocations=yes|no
This lets rustc users tweak whether the linker should relax ELF relocations,
namely whether it should emit R_X86_64_GOTPCRELX relocations instead of
R_X86_64_GOTPCREL, as the former is allowed by the ABI to be further
optimised. The default value is whatever the target defines.
2020-10-31 17:16:56 +01:00
Joshua Nelson 57c6ed0c07 Fix even more clippy warnings 2020-10-30 10:13:39 -04:00
bors 3dddf6ac1e Auto merge of #78414 - nox:function-sections, r=nagisa,bjorn3
Implement -Z function-sections=yes|no

This lets rustc users tweak whether all functions should be put in their own TEXT section, using whatever default value the target defines if the flag is missing.

I'm having fun experimenting with musl libc and trying to implement the start symbol in Rust, that means avoiding code that requires relocations, and AFAIK putting everything in its own section makes the toolchain generate `GOTPCREL` relocations for symbols that could use plain old PC-relative addressing (at least on `x86_64`) if they were all in the same section.
2020-10-28 17:47:36 +00:00
Ryan Levick 69dc98161a Cache foreign_modules query 2020-10-27 16:21:55 +01:00
Dániel Buga caf9131e65 Query span as late as possible 2020-10-27 10:17:01 +01:00
Anthony Ramine 056942215c Implement -Z function-sections=yes|no
This lets rustc users tweak whether all functions should be put in their own
TEXT section, using whatever default value the target defines if the flag
is missing.
2020-10-26 23:26:43 +01:00
bors 0da6d42f29 Auto merge of #68965 - eddyb:mir-inline-scope, r=nagisa,oli-obk
rustc_mir: track inlined callees in SourceScopeData.

We now record which MIR scopes are the roots of *other* (inlined) functions's scope trees, which allows us to generate the correct debuginfo in codegen, similar to what LLVM inlining generates.
This PR makes the `ui` test `backtrace-debuginfo` pass, if the MIR inliner is turned on by default.

Also, `#[track_caller]` is now correct in the face of MIR inlining (cc `@anp).`

Fixes #76997.

r? `@rust-lang/wg-mir-opt`
2020-10-26 18:50:22 +00:00
Dylan DPC 147a001fd3
Rollup merge of #78126 - shepmaster:aarch64-apple-darwin-valist, r=nagisa
Properly define va_arg and va_list for aarch64-apple-darwin

From [Apple][]:

> Because of these changes, the type `va_list` is an alias for `char*`,
> and not for the struct type in the generic procedure call standard.

With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi`
passes.

Fixes #78092

[Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-26 03:09:00 +01:00
Jake Goulding 0a91755ff4 Properly define va_arg and va_list for aarch64-apple-darwin
From [Apple][]:

> Because of these changes, the type `va_list` is an alias for `char*`,
> and not for the struct type in the generic procedure call standard.

With this change `/x.py test --stage 1 src/test/ui/abi/variadic-ffi`
passes.

Fixes #78092

[Apple]: https://developer.apple.com/documentation/xcode/writing_arm64_code_for_apple_platforms
2020-10-25 21:37:01 -04:00
Wesley Wiser 5ac5556d63 Upgrade to measureme 9.0.0 2020-10-24 22:39:42 -04:00
Jake Goulding c6ab758e54 Switch from tuple matching to match guards 2020-10-24 12:58:38 -04:00
Jonas Schievink 1ac137be93
Rollup merge of #78307 - rust-lang:revert-77961-embed-bitcode, r=tmandry
Revert "Set .llvmbc and .llvmcmd sections as allocatable"

Reverts rust-lang/rust#77961, see discussion starting from https://github.com/rust-lang/rust/pull/77961#issuecomment-712313902
2020-10-24 14:12:20 +02:00
Rich Kadel f75a236fe0
Update compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs
Co-authored-by: Wesley Wiser <wwiser@gmail.com>
2020-10-23 14:58:08 -07:00
Tyler Mandry 6640a62e0e
Revert "Set .llvmbc and .llvmcmd sections as allocatable" 2020-10-23 12:54:00 -07:00
Rich Kadel a7bc1a2edf Make codegen coverage_context optional, and check
Addresses Issue #78286

Libraries compiled with coverage and linked with out enabling coverage
would fail when attempting to add the library's coverage statements to
the codegen coverage context (None).

Now, if coverage statements are encountered while compiling / linking
with `-Z instrument-coverage` disabled, codegen will *not* attempt to
add code regions to a coverage map, and it will not inject the LLVM
instrprof_increment intrinsic calls.
2020-10-23 12:00:30 -07:00
varkor 878c97e70c Update to rustc-demangle 0.1.18 2020-10-21 21:11:11 +01:00
varkor 2b9d22d3a9 Update rustc-demangle 2020-10-21 21:05:38 +01:00
Eduard-Mihai Burtescu 0ce4452fce rustc_codegen_llvm: add support for inlined function debuginfo. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu 737499593d rustc_codegen_llvm: expose DILocation to rustc_codegen_ssa. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu 88d874de63 rustc_codegen_llvm: avoid converting between DILocation and Value. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu fa2b381ec8 rustc_codegen_llvm: move DISubprogram creation to a dbg_scope_fn method. 2020-10-21 04:43:57 +03:00
Eduard-Mihai Burtescu 9d57c417fc rustc_codegen_llvm: create DIFiles from just SourceFiles. 2020-10-21 04:43:56 +03:00
bors 94332bbe10 Auto merge of #78047 - khyperia:set_span_mut, r=bjorn3
Make set_span take mut self

This was a mistake in https://github.com/rust-lang/rust/pull/77614

It's not a _huge_ deal, because backends can always implement this with interior mutability, but it's nice to avoid interior mutability when possible. For context, the `set_source_location` method, called alongside `set_span`, also takes `&mut self`.

r? `@eddyb`
2020-10-18 05:36:23 +00:00
khyperia 3d484481c7 Make set_span take mut self 2020-10-17 13:28:58 +02:00
bors 6f0ea299cf Auto merge of #77685 - jackh726:binder-map, r=lcnr
Use rebind instead of Binder::bind when possible

These are really only the easy places. I just searched for `Binder::bind` and replaced where it straightforward.

r? `@lcnr`
cc. `@nikomatsakis`
2020-10-17 10:28:52 +00:00
Dylan DPC 55f9676c47
Rollup merge of #77961 - glandium:embed-bitcode, r=nagisa
Set .llvmbc and .llvmcmd sections as allocatable

This marks both sections as allocatable rather than excluded, which matches what
clang does with the equivalent `-fembed-bitcode` flag.
2020-10-17 03:27:20 +02:00
Jack Huey 11d62aa284 Review comments 2020-10-16 12:58:50 -04:00
Jack Huey dd5c9bf139 Use map_bound(_ref) instead of Binder::bind when possible 2020-10-16 12:58:50 -04:00
bors a78a62fc99 Auto merge of #77972 - Mark-Simulacrum:side-effect-loop, r=nagisa
Prevent miscompilation in trivial loop {}

Ideally, we would want to handle a broader set of cases to fully fix the
underlying bug here. That is currently relatively expensive at compile and
runtime, so we don't do that for now.

Performance results indicate this is not a major regression, if at all, so it should be safe to land.

cc #28728
2020-10-16 14:06:37 +00:00
Mark Rousskov e2efec8976 Prevent miscompilation in trivial loop {}
Ideally, we would want to handle a broader set of cases to fully fix the
underlying bug here. That is currently relatively expensive at compile and
runtime, so we don't do that for now.
2020-10-15 09:42:06 -04:00
est31 d683e3ac23 Remove rustc_session::config::Config
The wrapper type led to tons of target.target
across the compiler. Its ptr_width field isn't
required any more, as target_pointer_width
is already present in parsed form.
2020-10-15 12:02:24 +02:00
est31 4fa5578774 Replace target.target with target and target.ptr_width with target.pointer_width
Preparation for a subsequent change that replaces
rustc_target::config::Config with its wrapped Target.

On its own, this commit breaks the build. I don't like making
build-breaking commits, but in this instance I believe that it
makes review easier, as the "real" changes of this PR can be
seen much more easily.

Result of running:

find compiler/ -type f -exec sed -i -e 's/target\.target\([)\.,; ]\)/target\1/g' {} \;
find compiler/ -type f -exec sed -i -e 's/target\.target$/target/g' {} \;
find compiler/ -type f -exec sed -i -e 's/target.ptr_width/target.pointer_width/g' {} \;
./x.py fmt
2020-10-15 12:02:24 +02:00
est31 0d1aa1e034 Rename target_pointer_width to pointer_width and turn it into an u32
Rename target_pointer_width to pointer_width because it is already
member of the Target struct.

The compiler supports only three valid values for target_pointer_width:
16, 32, 64. Thus it can safely be turned into an int.
This means less allocations and clones as well as easier handling of the type.
2020-10-15 12:02:23 +02:00
Mike Hommey 684d142e70 Set .llvmbc and .llvmcmd sections as allocatable 2020-10-15 14:04:57 +09:00
Yuki Okushi 022d20759b
Rollup merge of #77739 - est31:remove_unused_code, r=petrochenkov,varkor
Remove unused code

Rustc has a builtin lint for detecting unused code inside a crate, but when an item is marked `pub`, the code, even if unused inside the entire workspace, is never marked as such. Therefore, I've built [warnalyzer](https://github.com/est31/warnalyzer) to detect unused items in a cross-crate setting.

Closes https://github.com/est31/warnalyzer/issues/2
2020-10-15 07:32:29 +09:00
Arlo Siemsen 3296d5ca7b Add support for SHA256 source file hashing for LLVM 11+. 2020-10-14 15:09:51 -07:00
est31 feaac592a3 Remove unused code from rustc_codegen_* 2020-10-14 04:14:32 +02:00
Dylan DPC 17ee28b71f
Rollup merge of #77795 - bjorn3:codegen_backend_interface_refactor, r=oli-obk
Codegen backend interface refactor

This moves several things away from the codegen backend to rustc_interface. There are a few behavioral changes where previously the incremental cache (incorrectly) wouldn't get finalized, but now it does. See the individual commit messages.
2020-10-14 02:30:38 +02:00
Dylan DPC 596235281c
Rollup merge of #77765 - amshafer:master, r=petrochenkov
Add LLVM flags to limit DWARF version to 2 on BSD

This has been a thorn in my side for a while, I can finally generate flamegraphs of rust programs on bsd again. This fixes dtrace profiling on freebsd, I think it might help with lldb as well but I can't test that because my current rust-lldb setup is messed up.

I'm limiting the dwarf version to 2 on all bsd's (netbsd/openbsd/freebsd) since it looks like this applies to all of them, but I have only tested on freebsd.

Let me know if there's anything I can improve!

---
Currently on FreeBSD dtrace profiling does not work and shows jumbled/incorrect
symbols in the backtraces. FreeBSD does not support the latest versions of DWARF
in dtrace (and lldb?) yet, and needs to be limited to DWARF2 in the same way as macos.

This adds an is_like_bsd flag since it was missing. NetBSD/OpenBSD/FreeBSD all
match this.

This effectively copies #11864 but targets FreeBSD instead of macos.
2020-10-14 02:30:34 +02:00
Austin Shafer 4511f8b9f3 Add a target option for selecting a DWARF version
Certain platforms need to limit the DWARF version emitted (oxs, *bsd). This
change adds a dwarf_version entry to the options that allows a platform to
specify the dwarf version to use. By default this option is none and the default
DWARF version is selected.

Also adds an option for printing Option<u32> json keys
2020-10-13 15:56:30 -04:00
est31 a0fc455d30 Replace absolute paths with relative ones
Modern compilers allow reaching external crates
like std or core via relative paths in modules
outside of lib.rs and main.rs.
2020-10-13 14:16:45 +02:00