about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src
AgeCommit message (Collapse)AuthorLines
2024-11-03Auto merge of #132514 - Zalathar:print-target-cpus, r=jieyouxubors-49/+83
Port most of `--print=target-cpus` to Rust The logic and formatting needed by `--print=target-cpus` has historically been carried out in C++ code. Originally it used `printf` to write directly to the console, but later it switched over to writing to a `std::ostringstream` and then passing its buffer to a callback function pointer. This PR replaces that C++ code with a very simple function that writes a list of CPU names to a `&RustString`, with the rest of the logic and formatting being handled by ordinary safe Rust code.
2024-11-02Rename target triple to target tuple in many places in the compilerNoratrieb-3/+3
This changes the naming to the new naming, used by `--print target-tuple`. It does not change all locations, but many.
2024-11-02Port most of `LLVMRustPrintTargetCPUs` to RustZalathar-37/+63
2024-11-02Use a dedicated safe wrapper for `LLVMRustGetHostCPUName`Zalathar-13/+21
2024-11-02Rollup merge of #131037 - madsmtm:move-llvm-target-versioning, r=petrochenkovMatthias Krüger-2/+4
Move versioned Apple LLVM targets from `rustc_target` to `rustc_codegen_ssa` Fully specified LLVM targets contain the OS version on macOS/iOS/tvOS/watchOS/visionOS, and this version depends on the deployment target environment variables like `MACOSX_DEPLOYMENT_TARGET`, `IPHONEOS_DEPLOYMENT_TARGET` etc. We would like to move this to later in the compilation pipeline, both because it feels impure to access environment variables when fetching target information, but mostly because we need access to more information from https://github.com/rust-lang/rust/pull/130883 to do https://github.com/rust-lang/rust/issues/118204. See also https://github.com/rust-lang/rust/pull/129342#issuecomment-2335156119 for some discussion. The first and second commit does the actual refactor, it should be a non-functional change, the third commit adds diagnostics for invalid deployment targets, which are now possible to do because we have access to the session. Tested with the same commands as in https://github.com/rust-lang/rust/pull/130435. r? ``````@petrochenkov``````
2024-11-02Rollup merge of #131829 - Zalathar:goodbye-zprofile, r=chenyukangGuillaume Gomez-36/+0
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-01Move versioned LLVM target creation to rustc_codegen_ssaMads Marquart-2/+4
The OS version depends on the deployment target environment variables, the access of which we want to move to later in the compilation pipeline that has access to more information, for example `env_depinfo`.
2024-10-31llvm: Match new LLVM 128-bit integer alignment on sparcMatthew Maurer-0/+5
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-31coverage: Avoid ICE when `coverage_cx` is unexpectedly unavailableZalathar-2/+12
2024-10-31Remove support for `-Zprofile` (gcov-style coverage instrumentation)Zalathar-36/+0
2024-10-30Rollup merge of #132246 - workingjubilee:campaign-on-irform, r=compiler-errorsJubilee-70/+87
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-30Rollup merge of #132342 - Zalathar:operand-bundle, r=workingjubileeMatthias Krüger-74/+89
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-30Clean up FFI calls for operand bundlesZalathar-74/+89
2024-10-30Consistently use safe wrapper function `set_section`Zalathar-16/+14
2024-10-29compiler: `rustc_abi::Abi` => `BackendRepr`Jubilee Young-70/+87
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-29Rollup merge of #132319 - Zalathar:add-module-flag, r=jieyouxuMatthias Krüger-225/+195
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-29Clean up FFI calls for setting module flagsZalathar-205/+192
- 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-29Don't set unnecessary module flag "LTOPostLink"Zalathar-20/+3
This module flag was an internal detail of LLVM's optimization passes, and all code involving it was removed in LLVM 17. <https://github.com/llvm/llvm-project/commit/200cc952a28a73687ba24d5334415df6332f2d5b>
2024-10-29Rollup merge of #132216 - klensy:c_uint, r=cuviperJubilee-4/+4
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-29Rollup merge of #131375 - klensy:clone_on_ref_ptr, r=cjgillotJubilee-1/+1
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-29correct LLVMRustCreateThinLTOData arg typesklensy-4/+4
2024-10-28Rollup merge of #132261 - ChrisCho-H:refactor/cleaner-check-none, ↵Jubilee-4/+1
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-28Rollup merge of #132260 - Zalathar:type-safe-cast, r=compiler-errorsJubilee-87/+110
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-28compiler: Add `is_uninhabited` and use LayoutS accessorsJubilee Young-3/+3
This reduces the need of the compiler to peek on the fields of LayoutS.
2024-10-28fix clippy::clone_on_ref_ptr for compilerklensy-1/+1
2024-10-28refactor: cleaner check to return NoneChrisCho-H-4/+1
2024-10-28Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`Zalathar-87/+110
2024-10-27Auto merge of #132167 - Zalathar:llvm-wrappers, r=jieyouxubors-111/+133
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-27Auto merge of #131900 - mrkajetanp:target-feature-pauth-lr, r=Amanieubors-0/+1
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-27Use LLVM-C APIs for getting/setting visibilityZalathar-6/+6
2024-10-26Rollup merge of #132124 - Zalathar:consolidate-covstar, r=jieyouxu许杰友 Jieyou Xu (Joe)-144/+102
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-26Use LLVM-C APIs for getting/setting linkageZalathar-13/+24
2024-10-26Add a wrapper type for raw enum values returned by LLVMZalathar-0/+25
2024-10-26Use safe wrappers `get_visibility` and `set_visibility`Zalathar-33/+20
2024-10-26Use safe wrappers `get_linkage` and `set_linkage`Zalathar-61/+60
2024-10-26coverage: Add links to LLVM docs for the coverage mapping formatZalathar-0/+2
2024-10-26Effects cleanupDeadbeef-3/+1
- 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-25coverage: SSA doesn't need to know about `instrprof_increment`Zalathar-11/+12
2024-10-25coverage: Emit MC/DC intrinsics using the normal helper methodZalathar-49/+14
2024-10-25coverage: Emit `llvm.instrprof.increment` using the normal helper methodZalathar-25/+2
2024-10-25coverage: Store `covfun_section_name` in the codegen contextZalathar-27/+24
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-25coverage: Make obtaining the codegen coverage context infallibleZalathar-33/+16
In all the situations where this context is needed, it should always be available.
2024-10-25coverage: Consolidate creation of covmap/covfun recordsZalathar-88/+64
There is no need for this code to be split across multiple functions in multiple files.
2024-10-24Rollup merge of #131956 - Zalathar:llvm-counters, r=compiler-errors,SwatinemStuart Cook-353/+129
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-23"innermost", "outermost", "leftmost", and "rightmost" don't need hyphensJosh Triplett-1/+1
These are all standard dictionary words and don't require hyphenation.
2024-10-21Auto merge of #130950 - compiler-errors:yeet-eval, r=BoxyUwUbors-10/+9
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-20Make `llvm::set_section` take a `&CStr`Zalathar-13/+14
2024-10-20Pass coverage mappings to LLVM as separate structsZalathar-336/+112
2024-10-20Reduce visibility of coverage FFI functions/typesZalathar-18/+18
2024-10-19Get rid of const eval_* and try_eval_* helpersMichael Goulet-10/+9