Commit Graph

59 Commits

Author SHA1 Message Date
Jana Dönszelmann 006588a3ae codegen-llvm shim function for function aliases for macos 2026-02-17 14:22:52 +01:00
Jana Dönszelmann 9bd6b7ff72 EII: generate aliases for implementations 2025-12-12 11:32:29 +01:00
Marcelo Domínguez 5128ce10a0 Implement offload intrinsic 2025-11-25 20:04:27 +01:00
Zalathar f955c76a5b Remove inherent methods from several LLVM FFI types
Using a helper trait allows the conversions to remain in `rustc_codegen_llvm`,
even if the FFI types are moved to a different crate.
2025-10-04 18:16:13 +10:00
Zalathar cc6329a9bc Replace MetadataType with the MetadataKindId constants 2025-09-30 20:10:30 +10:00
Zalathar cd40bbfe29 Move MetadataKindId into its own submodule 2025-09-30 20:07:54 +10:00
Jo Bates 1ebf69d1b1 initial implementation of the darwin_objc unstable feature 2025-09-13 16:06:22 -07:00
Zalathar fcff8f7f5a Assert that LLVM range-attribute values don't exceed 128 bits
The underlying implementation of `LLVMCreateConstantRangeAttribute` assumes
that each of `LowerWords` and `UpperWords` points to enough u64 values to
define an integer of the specified bit-length, and will encounter UB if that is
not the case.

Our safe wrapper function always passes pointers to `[u64; 2]` arrays,
regardless of the bit-length specified. That's fine in practice, because scalar
primitives never exceed 128 bits, but it is technically a soundness hole in a
safe function.

We can close the soundness hole by explicitly asserting `size_bits <= 128`.
This is effectively just a stricter version of the existing check that the
value must be small enough to fit in `c_uint`.
2025-08-26 13:07:19 +10:00
Zalathar 455a67bd4f Replace the llvm::Bool typedef with a proper newtype 2025-08-24 23:09:54 +10:00
Zalathar cf8ec6798f Remove LlvmArchiveBuilder and supporting code/bindings 2025-08-16 16:38:12 +10:00
Marcelo Domínguez e1d79b9aad Remove lto inline logic 2025-08-14 16:30:16 +00:00
Oli Scherer d3d51b4fdb Avoid a bunch of unnecessary unsafe blocks in cg_llvm 2025-07-14 08:27:08 +00:00
Oli Scherer 84eeca2e2f Make some "safe" llvm ops actually sound 2025-07-10 07:27:41 +00:00
sayantn 9415f3d8a6 Use LLVMIntrinsicGetDeclaration to completely remove the hardcoded intrinsics list 2025-06-15 22:15:16 +05:30
sayantn d56fcd968d Simplify implementation of Rust intrinsics by using type parameters in the cache 2025-06-12 00:32:42 +05:30
bors 1a7f290a9a Auto merge of #140914 - Zalathar:asm-bindings, r=compiler-errors
cg_llvm: Clean up some inline assembly bindings

This PR combines a few loosely-related cleanups to LLVM bindings related to inline assembly. These include:
- Replacing `LLVMRustInlineAsm` with LLVM-C's `LLVMGetInlineAsm`
- Adjusting FFI declarations to avoid the need for explicit `as_c_char_ptr` conversions
- Flattening control flow in `inline_asm_call`

There should be no functional changes.
2025-05-12 17:39:21 +00:00
Zalathar dbdbde2a72 Rename OperandBundleOwned to OperandBundleBox
As with `DIBuilderBox`, the "Box" suffix does a better job of communicating
that this is an owning pointer to some borrowable resource.

This also renames the `raw` method to `as_ref`, which is what it would have
been named originally if the `Deref` problem had been known at the time.
2025-05-11 21:21:38 +10:00
Zalathar b1094f6a0a Add a safe wrapper for LLVMAppendModuleInlineAsm
This patch also changes the Rust-side declaration to take `*const c_uchar`
instead of `*const c_char`, to avoid the need for `AsCCharPtr`.
2025-05-11 14:38:42 +10:00
bit-aloo 7018392337 remove noinline attribute and add alwaysinline after AD pass 2025-04-28 21:10:32 +05:30
Daniel Paoliello 79b9664091 Reduce visibility of most items in rustc_codegen_llvm 2025-03-25 16:36:47 +11:00
David Wood a5615d3c62 codegen_llvm: avoid Deref impls w/ extern type
`rustc_codegen_llvm` relied on `Deref` impls where `Deref::Target` was
or contained an extern type - in my experimental implementation of
rust-lang/rfcs#3729, this isn't possible as the `Target` associated
type's `?Sized` bound cannot be relaxed backwards compatibly (unless we
come up with some way of doing this).

In later pull requests with the rust-lang/rfcs#3729 implementation,
breakage like this could only occur for nightly users relying on the
`extern_types` feature.

Upstreaming this to avoid needing to keep carrying this patch locally,
and I think it'll necessarily need to change eventually.
2025-02-24 08:08:55 +00:00
Oli Scherer ce7f58bd91 Merge two operations that were always performed together 2025-02-20 11:24:00 +00:00
Oli Scherer ea7180813b Create safe helper for LLVMSetDLLStorageClass 2025-02-20 11:15:00 +00:00
Daniel Paoliello e7cef26a3d cg_llvm: Reduce visibility of all functions in the llvm module 2025-02-13 12:36:25 +11:00
Oli Scherer dcf1e4d72b Document some safety constraints and use more safe wrappers 2025-02-11 09:47:13 +00:00
Zalathar 042fd8c24a Remove some unused glob re-exports
These were detected by temporarily making `mod llvm` non-public.
2025-02-06 12:10:45 +11:00
Manuel Drehwald d753cbf779 upstream rustc_codegen_llvm changes for enzyme/autodiff 2025-01-01 21:42:45 +01:00
Zalathar 89d7efaf8f Make RustString an extern type to avoid improper_ctypes warnings 2024-11-09 11:07:44 +11:00
Jubilee Young b895bf4fdc compiler: Directly use rustc_abi in codegen 2024-11-03 12:30:32 -08:00
Zalathar c3071590ab Clean up FFI calls for operand bundles 2024-10-30 13:26:24 +11: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 4bd84b23a8 Use a type-safe helper to cast &str and &[u8] to *const c_char 2024-10-28 21:31:32 +11:00
Zalathar d976ca8701 Use LLVM-C APIs for getting/setting visibility 2024-10-27 11:05:33 +11:00
Zalathar 96993a9b5e Use LLVM-C APIs for getting/setting linkage 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 3310419d35 Make llvm::set_section take a &CStr 2024-10-20 17:08:05 +11: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
Andreas Jonson cfadfabfcd Add range attribute to scalar function results and arguments 2024-08-11 19:40:44 +02:00
Nicholas Nethercote 84ac80f192 Reformat use declarations.
The previous commit updated `rustfmt.toml` appropriately. This commit is
the outcome of running `x fmt --all` with the new formatting options.
2024-07-29 08:26:52 +10:00
beetrees 6e5f1dacf3 Use the Align type when parsing alignment attributes 2024-04-01 03:05:55 +01:00
Qiu Chaofan 7037ff99af Recognize AIX style archive kind 2023-04-19 11:10:47 +08:00
Tim Neumann c15cfc91c4 LLVM 16: Switch to using MemoryEffects 2022-11-04 17:58:16 +00:00
Yuki Okushi 7f608e99dc Rollup merge of #99759 - bjorn3:remove_llvm_dead_code, r=nikic
Remove dead code from cg_llvm

Found while working on https://github.com/rust-lang/rust/pull/97485
2022-07-27 11:52:56 +09:00
Augie Fackler 130a1df71e codegen: use new {re,de,}allocator annotations in llvm
This obviates the patch that teaches LLVM internals about
_rust_{re,de}alloc functions by putting annotations directly in the IR
for the optimizer.

The sole test change is required to anchor FileCheck to the body of the
`box_uninitialized` method, so it doesn't see the `allocalign` on
`__rust_alloc` and get mad about the string `alloca` showing up. Since I
was there anyway, I added some checks on the attributes to prove the
right attributes got set.

While we're here, we also emit allocator attributes on
__rust_alloc_zeroed. This should allow LLVM to perform more
optimizations for zeroed blocks, and probably fixes #90032. [This
comment](https://github.com/rust-lang/rust/issues/24194#issuecomment-308791157)
mentions "weird UB-like behaviour with bitvec iterators in
rustc_data_structures" so we may need to back this change out if things
go wrong.

The new test cases require LLVM 15, so we copy them into LLVM
14-supporting versions, which we can delete when we drop LLVM 14.
2022-07-26 09:43:28 -04:00
bjorn3 017e1726ff Remove dead code from cg_llvm 2022-07-26 11:29:18 +00:00
Tomasz Miąsko 926bf1a371 Pass LLVM string attributes as string slices 2022-03-03 00:28:50 +01:00
Erik Desjardins dce14cfacc Remove LLVM attribute removal
This was necessary before, because `declare_raw_fn` would always apply
the default optimization attributes to every declared function,
and then `attributes::from_fn_attrs` would have to remove the default
attributes in the case of, e.g. `#[optimize(speed)]` in a `-Os` build.

However, every relevant callsite of `declare_raw_fn` (i.e. where we
actually generate code for the function, and not e.g. a call to an
intrinsic, where optimization attributes don't [?] matter)
calls `from_fn_attrs`, so we can simply remove the attribute setting
from `declare_raw_fn`, and rely on `from_fn_attrs` to apply the correct
attributes all at once.
2022-02-28 00:02:11 -05:00
Erik Desjardins 30d3ce0674 Add LLVM attributes in batches instead of individually
This should improve performance.
2022-02-26 13:14:55 -05:00