Commit Graph

2209 Commits

Author SHA1 Message Date
Guillaume Gomez
526c67f37b
Rollup merge of #131829 - Zalathar:goodbye-zprofile, r=chenyukang
Remove support for `-Zprofile` (gcov-style coverage instrumentation)

Tracking issue: #42524

MCP: https://github.com/rust-lang/compiler-team/issues/798

---

This PR removes the unstable `-Zprofile` flag, which enables ”gcov-style” coverage instrumentation, along with its associated `-Zprofile-emit` configuration flag.

(The profile flag predates and is almost entirely separate from the stable `-Cinstrument-coverage` flag.)

Notably, the `-Zprofile` flag:
- Is largely untested in-tree, having only one run-make test that does not check whether its output is correct or useful.
- Has no known maintainer.
- Has seen no push towards stabilization.
- Has at least one severe regression reported in 2022 that apparently remains unaddressed.
  - #100125
- Is confusingly named, since it appears to be more about coverage than performance profiling, and has nothing to do with PGO.
- Is fundamentally limited by relying on counters auto-inserted by LLVM, with no knowledge of Rust beyond debuginfo.
2024-11-02 03:08:49 +08:00
Matthew Maurer
9caced7bad llvm: Match new LLVM 128-bit integer alignment on sparc
LLVM continues to align more 128-bit integers to 128-bits in the data
layout rather than relying on the high level language to do it. Update
SPARC target files to match and add a backcompat replacement for current
LLVMs.

See llvm/llvm-project#106951 for details
2024-10-31 20:37:54 +00:00
Zalathar
8dddd1ae60 coverage: Avoid ICE when coverage_cx is unexpectedly unavailable 2024-10-31 21:25:43 +11:00
Zalathar
ce3e14a448 Remove support for -Zprofile (gcov-style coverage instrumentation) 2024-10-31 09:09:25 +11:00
Jubilee
847b6fe6b0
Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errors
Rename `rustc_abi::Abi` to `BackendRepr`

Remove the confabulation of `rustc_abi::Abi` with what "ABI" actually means by renaming it to `BackendRepr`, and rename `Abi::Aggregate` to `BackendRepr::Memory`. The type never actually represented how things are passed, as that has to have `PassMode` considered, at minimum, but rather it just is how we represented some things to the backend. This conflation arose because LLVM, the primary backend at the time, would lower certain IR forms using certain ABIs. Even that only somewhat was true, as it broke down when one ventured significantly afield of what is described by the System V AMD64 ABI either by using different architectures, ABI-modifying IR annotations, the same architecture **with different ISA extensions enabled**, or other... unexpected delights.

Unfortunately both names are still somewhat of a misnomer right now, as people have written code for years based on this misunderstanding. Still, their original names are even moreso, and for better or worse, this backend code hasn't received as much maintenance as the rest of the compiler, lately. Actually arriving at a correct end-state will simply require us to disentangle a lot of code in order to fix, much of it pointlessly repeated in several places. Thus this is not an "actual fix", just a way to deflect further misunderstandings.
2024-10-30 14:01:37 -07:00
Matthias Krüger
879c4d5ccc
Rollup merge of #132342 - Zalathar:operand-bundle, r=workingjubilee
cg_llvm: Clean up FFI calls for operand bundles

All of these FFI functions have equivalents in the stable LLVM-C API, though `LLVMBuildCallBr` requires a temporary polyfill on LLVM 18.

This PR also creates a clear split between `OperandBundleOwned` and `OperandBundle`, and updates the internals of the owner to be a little less terrifying.
2024-10-30 06:40:38 +01:00
Zalathar
c3071590ab Clean up FFI calls for operand bundles 2024-10-30 13:26:24 +11:00
Zalathar
65ff2a6ad7 Consistently use safe wrapper function set_section 2024-10-30 11:38:20 +11:00
Jubilee Young
7086dd83cc compiler: rustc_abi::Abi => BackendRepr
The initial naming of "Abi" was an awful mistake, conveying wrong ideas
about how psABIs worked and even more about what the enum meant.
It was only meant to represent the way the value would be described to
a codegen backend as it was lowered to that intermediate representation.
It was never meant to mean anything about the actual psABI handling!
The conflation is because LLVM typically will associate a certain form
with a certain ABI, but even that does not hold when the special cases
that actually exist arise, plus the IR annotations that modify the ABI.

Reframe `rustc_abi::Abi` as the `BackendRepr` of the type, and rename
`BackendRepr::Aggregate` as `BackendRepr::Memory`. Unfortunately, due to
the persistent misunderstandings, this too is now incorrect:
- Scattered ABI-relevant code is entangled with BackendRepr
- We do not always pre-compute a correct BackendRepr that reflects how
  we "actually" want this value to be handled, so we leave the backend
  interface to also inject various special-cases here
- In some cases `BackendRepr::Memory` is a "real" aggregate, but in
  others it is in fact using memory, and in some cases it is a scalar!

Our rustc-to-backend lowering code handles this sort of thing right now.
That will eventually be addressed by lifting duplicated lowering code
to either rustc_codegen_ssa or rustc_target as appropriate.
2024-10-29 14:56:00 -07:00
Matthias Krüger
2707cd670c
Rollup merge of #132319 - Zalathar:add-module-flag, r=jieyouxu
cg_llvm: Clean up FFI calls for setting module flags

This is a combination of several inter-related changes to how module flags are set:

- Remove some unnecessary code for setting an `"LTOPostLink"` flag, which has been obsolete since LLVM 17.
- Define our own enum instead of relying on enum values defined by LLVM's unstable C++ API.
- Use safe wrapper functions to set module flags, instead of direct `unsafe` calls.
- Consistently pass pointer/length strings instead of C strings.
- Remove or shrink some `unsafe` blocks.
2024-10-29 18:38:59 +01:00
Zalathar
8d2ed4f0f3 Clean up FFI calls for setting module flags
- Don't rely on enum values defined by LLVM's C++ API
- Use safe wrapper functions instead of direct `unsafe` calls
- Consistently pass pointer/length strings instead of C strings
2024-10-29 21:40:34 +11:00
Zalathar
ba81dbf3c6 Don't set unnecessary module flag "LTOPostLink"
This module flag was an internal detail of LLVM's optimization passes, and all
code involving it was removed in LLVM 17.

<200cc952a2>
2024-10-29 21:17:13 +11:00
Jubilee
a70b90b822
Rollup merge of #132216 - klensy:c_uint, r=cuviper
correct LLVMRustCreateThinLTOData arg types

`LLVMRustCreateThinLTOData` defined in rust as
```rust
    pub fn LLVMRustCreateThinLTOData(
        Modules: *const ThinLTOModule,
        NumModules: c_uint,
        PreservedSymbols: *const *const c_char,
        PreservedSymbolsLen: c_uint,
    ) -> Option<&'static mut ThinLTOData>;
```
but in cpp as
```cpp
extern "C" LLVMRustThinLTOData *
LLVMRustCreateThinLTOData(LLVMRustThinLTOModule *modules, int num_modules,
                          const char **preserved_symbols, int num_symbols) {
```

(note `c_unit` vs `int` types). Let it be actually `size_t`.

Also fixes return type of `LLVMRustDIBuilderCreateOpLLVMFragment` to uint64_t as other similar functions around, which should be correct, i assume.
2024-10-29 03:11:42 -07:00
Jubilee
5d0f52efa4
Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillot
compiler: apply clippy::clone_on_ref_ptr for CI

Apply lint https://rust-lang.github.io/rust-clippy/master/index.html#/clone_on_ref_ptr for compiler, also see https://github.com/rust-lang/rust/pull/131225#discussion_r1790109443.

Some Arc's can be misplaced with Lrc's, sorry.

https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/enable.20more.20clippy.20lints.20for.20compiler.20.28and.5Cor.20std.29
2024-10-29 03:11:39 -07:00
klensy
17636374de correct LLVMRustCreateThinLTOData arg types 2024-10-29 00:47:20 +03:00
Jubilee
6fd4a76d3b
Rollup merge of #132261 - ChrisCho-H:refactor/cleaner-check-none, r=compiler-errors
refactor: cleaner check to return None

It's very nit change. Refactor to shorten verbose check when returning None for `backend_feature_name`.
2024-10-28 10:18:52 -07:00
Jubilee
bd43f8e9fd
Rollup merge of #132260 - Zalathar:type-safe-cast, r=compiler-errors
cg_llvm: Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`

In `rustc_codegen_llvm` there are many uses of `.as_ptr().cast()` to convert a string or byte-slice to `*const c_char`, which then gets passed through FFI.

This works, but is fragile, because there's nothing constraining the pointer cast to actually be from `u8` to `c_char`. If the original value changes to something else that has an `as_ptr` method, or the context changes to expect something other than `c_char`, the cast will silently do the wrong thing.

By making the cast more explicit via a helper method, we can be sure that it will either perform the intended cast, or fail at compile time.
2024-10-28 10:18:52 -07:00
Jubilee Young
88a9edc091 compiler: Add is_uninhabited and use LayoutS accessors
This reduces the need of the compiler to peek on the fields of LayoutS.
2024-10-28 09:58:30 -07:00
klensy
746b675c5a fix clippy::clone_on_ref_ptr for compiler 2024-10-28 18:05:08 +03:00
ChrisCho-H
82bfe05309 refactor: cleaner check to return None 2024-10-28 20:16:35 +09:00
Zalathar
4bd84b23a8 Use a type-safe helper to cast &str and &[u8] to *const c_char 2024-10-28 21:31:32 +11:00
bors
be33e4f3d6 Auto merge of #132167 - Zalathar:llvm-wrappers, r=jieyouxu
Replace some LLVMRust wrappers with calls to the LLVM C API

This PR removes the LLVMRust wrapper functions for getting/setting linkage and visibility, and replaces them with direct calls to the corresponding functions in LLVM's C API.

To make this convenient and sound, two pieces of supporting code have also been added:
- A simple proc-macro that derives `TryFrom<u32>` for fieldless enums
- A wrapper type for C enum values returned by LLVM functions, to ensure soundness if LLVM returns an enum value we don't know about

In a few places, the use of safe wrapper functions means that an `unsafe` block is no longer needed, so the affected code has changed its indentation level.
2024-10-27 03:24:54 +00:00
bors
f7cf41c973 Auto merge of #131900 - mrkajetanp:target-feature-pauth-lr, r=Amanieu
rustc_target: Add pauth-lr aarch64 target feature

Add the pauth-lr target feature, corresponding to aarch64 FEAT_PAuth_LR. This feature has been added in LLVM 19.
It is currently not supported by the Linux hwcap and so we cannot add runtime feature detection for it at this time.

r? `@Amanieu`
2024-10-27 00:09:49 +00:00
Zalathar
d976ca8701 Use LLVM-C APIs for getting/setting visibility 2024-10-27 11:05:33 +11:00
许杰友 Jieyou Xu (Joe)
c26280a8ba
Rollup merge of #132124 - Zalathar:consolidate-covstar, r=jieyouxu
coverage: Consolidate creation of covmap/covfun records

This code for creating covmap/covfun records during codegen was split across multiple functions and files for dubious historical reasons. Having it all in one place makes it easier to follow.

This PR also includes two semi-related cleanups:
- Getting the codegen context's `coverage_cx` state is made infallible, since it should always exist when running the code paths that need it.
- The value of `covfun_section_name` is saved in the codegen context, since it never changes at runtime, and the code that needs it has access to the context anyway.

---

Background: Coverage instrumentation generates two kinds of metadata that are embedded in the final binary. There is per-CGU information that goes in the `__llvm_covmap` linker section, and per-function information that goes in the `__llvm_covfun` section (except on Windows, where slightly different section names are used).
2024-10-26 22:01:12 +08:00
Zalathar
96993a9b5e Use LLVM-C APIs for getting/setting linkage 2024-10-26 20:20:20 +11:00
Zalathar
ec41e6d1b0 Add a wrapper type for raw enum values returned by LLVM 2024-10-26 20:20:20 +11:00
Zalathar
b114040afb Use safe wrappers get_visibility and set_visibility 2024-10-26 20:20:20 +11:00
Zalathar
983d258be3 Use safe wrappers get_linkage and set_linkage 2024-10-26 20:20:18 +11:00
Zalathar
0d653a5866 coverage: Add links to LLVM docs for the coverage mapping format 2024-10-26 17:37:04 +11:00
Deadbeef
f6fea83342 Effects cleanup
- removed extra bits from predicates queries that are no longer needed in the new system
- removed the need for `non_erasable_generics` to take in tcx and DefId, removed unused arguments in callers
2024-10-26 10:19:07 +08:00
Zalathar
8f07514520 coverage: SSA doesn't need to know about instrprof_increment 2024-10-25 14:24:05 +11:00
Zalathar
b3d65852c3 coverage: Emit MC/DC intrinsics using the normal helper method 2024-10-25 14:01:36 +11:00
Zalathar
4923e856be coverage: Emit llvm.instrprof.increment using the normal helper method 2024-10-25 13:55:44 +11:00
Zalathar
0356908cf5 coverage: Store covfun_section_name in the codegen context
Adding an extra `OnceCell` to `CrateCoverageContext` is much nicer than trying
to thread this string through multiple layers of function calls that already
have access to the context.
2024-10-25 12:42:42 +11:00
Zalathar
0a96176533 coverage: Make obtaining the codegen coverage context infallible
In all the situations where this context is needed, it should always be
available.
2024-10-25 12:42:42 +11:00
Zalathar
9f8a6be221 coverage: Consolidate creation of covmap/covfun records
There is no need for this code to be split across multiple functions in
multiple files.
2024-10-25 12:42:23 +11:00
Stuart Cook
8f354fc94a
Rollup merge of #131956 - Zalathar:llvm-counters, r=compiler-errors,Swatinem
coverage: Pass coverage mappings to LLVM as separate structs

Instead of trying to cram *N* different kinds of coverage mapping data into a single list for FFI, pass *N* different lists of simpler structs.

This avoids the need to fill unused fields with dummy values, and avoids the need to tag structs with their underlying kind. It also lets us call the dedicated LLVM constructors for each different mapping type, instead of having to go through the complex general-purpose constructor.

Even though this adds multiple new structs to the FFI surface area, the resulting C++ code is simpler and shorter.

---

I've structured this mostly as a single atomic patch, rather than a series of incremental changes, because that avoids the need to make fiddly fixes to code that is about to be deleted anyway.
2024-10-24 14:19:57 +11:00
Josh Triplett
ecdc2441b6 "innermost", "outermost", "leftmost", and "rightmost" don't need hyphens
These are all standard dictionary words and don't require hyphenation.
2024-10-23 02:45:24 -07:00
bors
f2ba41113d Auto merge of #130950 - compiler-errors:yeet-eval, r=BoxyUwU
Continue to get rid of `ty::Const::{try_}eval*`

This PR mostly does:

* Removes all of the `try_eval_*` and `eval_*` helpers from `ty::Const`, and replace their usages with `try_to_*`.
* Remove `ty::Const::eval`.
* Rename `ty::Const::normalize` to `ty::Const::normalize_internal`. This function is still used in the normalization code itself.
* Fix some weirdness around the `TransmuteFrom` goal.

I'm happy to split it out further; for example, I could probably land the first part which removes the helpers, or the changes to codegen which are more obvious than the changes to tools.

r? BoxyUwU

Part of https://github.com/rust-lang/rust/issues/130704
2024-10-21 03:46:28 +00:00
Zalathar
3310419d35 Make llvm::set_section take a &CStr 2024-10-20 17:08:05 +11:00
Zalathar
d1bf77eb34 Pass coverage mappings to LLVM as separate structs 2024-10-20 13:29:34 +11:00
Zalathar
98c4d96957 Reduce visibility of coverage FFI functions/types 2024-10-20 10:55:47 +11:00
Michael Goulet
e83e4e8112 Get rid of const eval_* and try_eval_* helpers 2024-10-19 18:07:35 +00:00
Jubilee Young
45d61b0d26 cg_llvm: Reuse LLVM-C Comdat support
Migrate `llvm::set_comdat` and `llvm::SetUniqueComdat` to LLVM-C FFI.

Note, now we can call `llvm::set_comdat` only when the target actually
supports adding comdat. As this has no convenient LLVM-C API, we
implement this as `TargetOptions::supports_comdat`.

Co-authored-by: Stuart Cook <Zalathar@users.noreply.github.com>
2024-10-19 10:46:10 -07:00
Jubilee Young
888efe74a3 cg_llvm: Switch llvm::add_global to &CStr 2024-10-18 17:46:33 -07:00
Kajetan Puchalski
f641c32aad rustc_target: Add pauth-lr aarch64 target feature
Add the pauth-lr target feature, corresponding to aarch64 FEAT_PAuth_LR.
This feature has been added in LLVM 19.
It is currently not supported by the Linux hwcap and so we cannot add
runtime feature detection for it at this time.
2024-10-16 18:00:51 +01:00
Matthew Maurer
e985396145 llvm: Match aarch64 data layout to new LLVM layout
LLVM has added 3 new address spaces to support special Windows use
cases. These shouldn't trouble us for now, but LLVM requires matching
data layouts.

See llvm/llvm-project#111879 for details
2024-10-16 01:16:44 +00:00
Taiki Endo
67ebb6c20b Fix AArch64InlineAsmReg::emit 2024-10-14 06:04:07 +09:00
Trevor Gross
39071fdc58
Rollup merge of #131626 - matthiaskrgr:dont_string, r=lqd
remove a couple of redundant String to String conversion
2024-10-12 21:38:38 -05:00