about summary refs log tree commit diff
path: root/compiler/rustc_codegen_llvm/src/llvm
AgeCommit message (Collapse)AuthorLines
2025-01-22Rollup merge of #135156 - Zalathar:debuginfo-flags, r=cuviperMatthias Krüger-3/+17
Make our `DIFlags` match `LLVMDIFlags` in the LLVM-C API In order to be able to use a mixture of LLVM-C and C++ bindings for debuginfo, our Rust-side `DIFlags` needs to have the same layout as LLVM-C's `LLVMDIFlags`, and we also need to be able to convert it to the `DIFlags` accepted by LLVM's C++ API. Internally, LLVM converts between the two types with a simple cast. We can't necessarily rely on that always being true, and LLVM doesn't expose a conversion function, so we have two potential options: - Convert each bit/subvalue individually - Statically assert that doing a cast is actually fine As long as both types do remain the same under the hood (which seems likely), the static-assert-and-cast approach is easier and faster. If the static assertions ever start failing against some future version of LLVM, we'll have to switch over to the convert-each-subvalue approach, which is a bit more error-prone. --- Extracted from #134009, though this PR ended up choosing the static-assert-and-cast approach over the convert-each-subvalue approach.
2025-01-21Treat undef bytes as equal to any other byteOli Scherer-0/+1
2025-01-21Make our `DIFlags` match `LLVMDIFlags` in the LLVM-C APIZalathar-3/+17
2025-01-17Auto merge of #135047 - Flakebi:amdgpu-kernel-cc, r=workingjubileebors-0/+1
Add gpu-kernel calling convention The amdgpu-kernel calling convention was reverted in commit f6b21e90d1ec01081bc2619efb68af6788a63d65 (#120495 and https://github.com/rust-lang/rust-analyzer/pull/16463) due to inactivity in the amdgpu target. Introduce a `gpu-kernel` calling convention that translates to `ptx_kernel` or `amdgpu_kernel`, depending on the target that rust compiles for. Tracking issue: #135467 amdgpu target tracking issue: #135024
2025-01-16Add gpu-kernel calling conventionFlakebi-0/+1
The amdgpu-kernel calling convention was reverted in commit f6b21e90d1ec01081bc2619efb68af6788a63d65 due to inactivity in the amdgpu target. Introduce a `gpu-kernel` calling convention that translates to `ptx_kernel` or `amdgpu_kernel`, depending on the target that rust compiles for.
2025-01-07llvm: Ignore error value that is always falseMatthew Maurer-1/+1
See llvm/llvm-project#121851 For LLVM 20+, this function (`renameModuleForThinLTO`) has no return value. For prior versions of LLVM, this never failed, but had a signature which allowed an error value people were handling.
2025-01-05Use constants for DWARF opcodes, instead of FFI callsZalathar-3/+0
2025-01-04Auto merge of #133990 - Walnut356:static_const, r=workingjubileebors-0/+6
[Debuginfo] Force enum `DISCR_*` to `static const u64` to allow for inspection via LLDB see [here](https://rust-lang.zulipchat.com/#narrow/channel/317568-t-compiler.2Fwg-debugging/topic/Revamping.20Debuginfo/near/486614878) for more info. This change mainly helps `*-msvc` debugged with LLDB. Currently, LLDB cannot inspect `static` struct fields, so the intended visualization for enums is only borderline functional, and niche enums with ranges of discriminant cannot be determined at all . LLDB *can* inspect `static const` values (though for whatever reason, non-enum/non-u64 consts don't work). This change adds the `LLVMRustDIBuilderCreateQualifiedType` to the rust FFI layer to wrap the discr type with a `const` modifier, as well as forcing all generated integer enum `DISCR_*` values to be u64's. Those values will only ever be used by debugger visualizers anyway, so it shouldn't be a huge deal, but I left a fixme comment for it just in case.. The `tag` also still properly reflects the discriminant type, so no information is lost.
2025-01-01upstream rustc_codegen_llvm changes for enzyme/autodiffManuel Drehwald-1/+33
2024-12-30rustc_llvm: expose FloatABIType target machine parameterRalf Jung-2/+11
2024-12-23add LLVMRustDIBuilderCreateQualifiedType to ffiWalnut-0/+6
2024-12-20Remove some dead code around import library generationbjorn3-28/+0
This was missed when replacing the usage of LLVM for generating import libraries.
2024-12-12Fix our `llvm::Bool` typedef to be signed, to match `LLVMBool`Zalathar-1/+3
In the LLVM-C API, boolean values are passed as `typedef int LLVMBool`, but our Rust-side typedef was using `c_uint` instead. Signed and unsigned integers have the same ABI on most platforms, but that isn't universally true, so we should prefer to be consistent with LLVM.
2024-12-12Auto merge of #129181 - beetrees:asm-spans, r=pnkfelix,compiler-errorsbors-2/+2
Pass end position of span through inline ASM cookie Before this PR, only the start position of the span was passed though the inline ASM cookie to diagnostics. LLVM 19 has full support for 64-bit inline ASM cookies; this PR uses that to pass the end position of the span in the upper 32 bits, meaning inline ASM diagnostics now point at the entire line the error occurred on, not just the first character of it.
2024-11-26Respect verify-llvm-ir option in the backendNikita Popov-0/+1
We are currently unconditionally verifying the LLVM IR in the backend (twice), ignoring the value of the verify-llvm-ir option.
2024-11-26Pass end position of span through inline ASM cookiebeetrees-2/+2
2024-11-23Rollup merge of #127483 - BertalanD:no_sanitize-global-var, r=rcvalle许杰友 Jieyou Xu (Joe)-0/+3
Allow disabling ASan instrumentation for globals AddressSanitizer adds instrumentation to global variables unless the [`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes) attribute is set on them. This commit extends the existing `#[no_sanitize(address)]` attribute to set this; previously it only had the desired effect on functions. (cc https://github.com/rust-lang/rust/issues/39699)
2024-11-12Rollup merge of #132702 - 1c3t3a:issue-132615, r=rcvalleMatthias Krüger-0/+1
CFI: Append debug location to CFI blocks Currently we're not appending debug locations to the inserted CFI blocks. This shows up in #132615 and #100783. This change fixes that by passing down the debug location to the CFI type-test generation and appending it to the blocks. Credits also belong to `@jakos-sec` who worked with me on this.
2024-11-11CFI: Append debug location to CFI blocksBastian Kersting-0/+1
2024-11-09Add discriminators to DILocations when multiple functions are inlined into a ↵Kyle Huey-0/+4
single point. LLVM does not expect to ever see multiple dbg_declares for the same variable at the same location with different values. proc-macros make it possible for arbitrary code, including multiple calls that get inlined, to happen at any given location in the source code. Add discriminators when that happens so these locations are different to LLVM. This may interfere with the AddDiscriminators pass in LLVM, which is added by the unstable flag -Zdebug-info-for-profiling. Fixes #131944
2024-11-09Auto merge of #132584 - Zalathar:includes, r=cuviperbors-1/+1
Trim and tidy includes in `rustc_llvm` These includes tend to accumulate over time, and are usually only removed when something breaks in a new LLVM version, so it's nice to clean them up manually once in a while. General strategy used for this PR: - Remove all includes from `LLVMWrapper.h` that aren't needed by the header itself, transplanting them to individual source files as necessary. - For each source file, temporarily remove each include if doing so doesn't cause a compile error. - If a “required” include looks like it shouldn't be needed, try replacing it with its sub-includes, then trim that list. - After doing all of the above, go back and re-add any removed include if the file does actually use things defined in that header, even if the header happens to also be included by something else.
2024-11-09Make `RustString` an extern type to avoid `improper_ctypes` warningsZalathar-24/+2
2024-11-08Rollup merge of #132590 - Zalathar:z-timings-stats, r=jieyouxuStuart Cook-4/+6
Simplify FFI calls for `-Ztime-llvm-passes` and `-Zprint-codegen-stats` The existing code for these unstable LLVM-infodump flags was jumping through hoops to pass an allocated C string across the FFI boundary, when it's much simpler to just write to a `&RustString` instead.
2024-11-05coverage: Tidy up coverage-specific FFI functionsZalathar-12/+12
2024-11-04Simplify FFI calls for `-Ztime-llvm-passes` and `-Zprint-codegen-stats`Zalathar-4/+6
2024-11-04Move `LLVMRustAttribute[Kind]` out of `LLVMWrapper.h`Zalathar-1/+1
2024-11-03compiler: Directly use rustc_abi in codegenJubilee Young-1/+1
2024-11-02Allow disabling ASan instrumentation for globalsDaniel Bertalan-0/+3
AddressSanitizer adds instrumentation to global variables unless the [`no_sanitize_address`](https://llvm.org/docs/LangRef.html#global-attributes) attribute is set on them. This commit extends the existing `#[no_sanitize(address)]` attribute to set this; previously it only had the desired effect on functions.
2024-11-02Port most of `LLVMRustPrintTargetCPUs` to RustZalathar-6/+2
2024-11-02Use a dedicated safe wrapper for `LLVMRustGetHostCPUName`Zalathar-1/+1
2024-10-31Remove support for `-Zprofile` (gcov-style coverage instrumentation)Zalathar-1/+0
2024-10-30Rollup merge of #132342 - Zalathar:operand-bundle, r=workingjubileeMatthias Krüger-55/+74
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-55/+74
2024-10-30Consistently use safe wrapper function `set_section`Zalathar-0/+1
2024-10-29Rollup merge of #132319 - Zalathar:add-module-flag, r=jieyouxuMatthias Krüger-11/+44
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-9/+44
- 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-2/+0
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-2/+2
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-29correct LLVMRustCreateThinLTOData arg typesklensy-2/+2
2024-10-28Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`Zalathar-6/+6
2024-10-27Use LLVM-C APIs for getting/setting visibilityZalathar-6/+6
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-0/+4
2024-10-26Use safe wrappers `get_linkage` and `set_linkage`Zalathar-0/+4
2024-10-25coverage: Emit MC/DC intrinsics using the normal helper methodZalathar-3/+0
2024-10-25coverage: Emit `llvm.instrprof.increment` using the normal helper methodZalathar-1/+0
2024-10-24Rollup merge of #131956 - Zalathar:llvm-counters, r=compiler-errors,SwatinemStuart Cook-10/+16
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-20Make `llvm::set_section` take a `&CStr`Zalathar-3/+2
2024-10-20Pass coverage mappings to LLVM as separate structsZalathar-2/+8