Commit Graph

692 Commits

Author SHA1 Message Date
bors
4b57d8154a Auto merge of #147519 - Zalathar:rollup-o5f16uo, r=Zalathar
Rollup of 3 pull requests

Successful merges:

 - rust-lang/rust#147446 (PassWrapper: use non-deprecated lookupTarget method)
 - rust-lang/rust#147473 (Do `x check` on various bootstrap tools in CI)
 - rust-lang/rust#147509 (remove intrinsic wrapper functions from LLVM bindings)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-10-09 10:54:43 +00:00
Stuart Cook
828dd0cdd4 Rollup merge of #147509 - AMS21:remove_llvm_rust_intrinsics, r=Zalathar
remove intrinsic wrapper functions from LLVM bindings

As discussed on https://github.com/llvm/llvm-project/pull/162500 there is no good reason to implement these intrinsic function via the LLVM wrapper instead we now just implement them via `call_intrinsic` like all the other intrinsic functions.

Work towards https://github.com/rust-lang/rust/issues/46437
2025-10-09 21:29:05 +11:00
Stuart Cook
c33f0b373b Rollup merge of #147446 - durin42:llvm-22-lookupTarget-deprecation, r=Zalathar
PassWrapper: use non-deprecated lookupTarget method

This avoids an extra trip through a triple string by directly passing the Triple, and has been available since LLVM 21. The string overload was deprecated today and throws an error on our CI for HEAD due to -Werror paranoia, so we may as well clean this up now and also skip the conversion on LLVM 21 since we can.

`@rustbot` label llvm-main
2025-10-09 21:29:04 +11:00
Stuart Cook
4dfd977c8b Rollup merge of #147488 - AMS21:remove_llvm_rust_insert_private_global, r=nikic
refactor: Remove `LLVMRustInsertPrivateGlobal` and `define_private_global`

Since it can easily be implemented using the existing LLVM C API in
terms of `LLVMAddGlobal` and `LLVMSetLinkage` and `define_private_global`
was only used in one place.

Work towards https://github.com/rust-lang/rust/issues/46437
2025-10-09 18:43:26 +11:00
AMS21
064e3b8212 remove intrinsic wrapper functions from LLVM bindings 2025-10-09 09:26:44 +02:00
AMS21
036ab3a925 refactor: Remove LLVMRustInsertPrivateGlobal and define_private_global
Since it can easily be implemented using the existing LLVM C API in
terms of `LLVMAddGlobal` and `LLVMSetLinkage` and `define_private_global`
was only used in one place.
2025-10-08 21:59:48 +02:00
AMS21
1aed495ed7 refactor: replace LLVMRustAtomicLoad/Store with LLVM built-in functions 2025-10-08 13:53:09 +02:00
Augie Fackler
eb20c6abd6 PassWrapper: use non-deprecated lookupTarget method
This avoids an extra trip through a triple string by directly passing
the Triple, and has been available since LLVM 21. The string overload
was deprecated today and throws an error on our CI for HEAD due to
-Werror paranoia, so we may as well clean this up now and also skip the
conversion on LLVM 21 since we can.

@rustbot label llvm-main
2025-10-07 11:02:13 -04:00
dianqk
1bd89bd42e codegen: Generate dbg_value for the ref statement 2025-10-02 14:55:51 +08:00
Zalathar
906bf49ade Declare all "fixed" metadata kinds as MetadataKindId 2025-09-30 20:10:10 +10:00
Matthias Krüger
c29fb2e57e Rollup merge of #144197 - KMJ-007:type-tree, r=ZuseZ4
TypeTree support in autodiff

# TypeTrees for Autodiff

## What are TypeTrees?
Memory layout descriptors for Enzyme. Tell Enzyme exactly how types are structured in memory so it can compute derivatives efficiently.

## Structure
```rust
TypeTree(Vec<Type>)

Type {
    offset: isize,  // byte offset (-1 = everywhere)
    size: usize,    // size in bytes
    kind: Kind,     // Float, Integer, Pointer, etc.
    child: TypeTree // nested structure
}
```

## Example: `fn compute(x: &f32, data: &[f32]) -> f32`

**Input 0: `x: &f32`**
```rust
TypeTree(vec![Type {
    offset: -1, size: 8, kind: Pointer,
    child: TypeTree(vec![Type {
        offset: -1, size: 4, kind: Float,
        child: TypeTree::new()
    }])
}])
```

**Input 1: `data: &[f32]`**
```rust
TypeTree(vec![Type {
    offset: -1, size: 8, kind: Pointer,
    child: TypeTree(vec![Type {
        offset: -1, size: 4, kind: Float,  // -1 = all elements
        child: TypeTree::new()
    }])
}])
```

**Output: `f32`**
```rust
TypeTree(vec![Type {
    offset: -1, size: 4, kind: Float,
    child: TypeTree::new()
}])
```

## Why Needed?
- Enzyme can't deduce complex type layouts from LLVM IR
- Prevents slow memory pattern analysis
- Enables correct derivative computation for nested structures
- Tells Enzyme which bytes are differentiable vs metadata

## What Enzyme Does With This Information:

Without TypeTrees (current state):
```llvm
; Enzyme sees generic LLVM IR:
define float ``@distance(ptr*`` %p1, ptr* %p2) {
; Has to guess what these pointers point to
; Slow analysis of all memory operations
; May miss optimization opportunities
}
```

With TypeTrees (our implementation):
```llvm
define "enzyme_type"="{[]:Float@float}" float ``@distance(``
    ptr "enzyme_type"="{[]:Pointer}" %p1,
    ptr "enzyme_type"="{[]:Pointer}" %p2
) {
; Enzyme knows exact type layout
; Can generate efficient derivative code directly
}
```

# TypeTrees - Offset and -1 Explained

## Type Structure

```rust
Type {
    offset: isize, // WHERE this type starts
    size: usize,   // HOW BIG this type is
    kind: Kind,    // WHAT KIND of data (Float, Int, Pointer)
    child: TypeTree // WHAT'S INSIDE (for pointers/containers)
}
```

## Offset Values

### Regular Offset (0, 4, 8, etc.)
**Specific byte position within a structure**

```rust
struct Point {
    x: f32, // offset 0, size 4
    y: f32, // offset 4, size 4
    id: i32, // offset 8, size 4
}
```

TypeTree for `&Point` (internal representation):
```rust
TypeTree(vec![
    Type { offset: 0, size: 4, kind: Float },   // x at byte 0
    Type { offset: 4, size: 4, kind: Float },   // y at byte 4
    Type { offset: 8, size: 4, kind: Integer }  // id at byte 8
])
```

Generates LLVM:
```llvm
"enzyme_type"="{[]:Float@float}"
```

### Offset -1 (Special: "Everywhere")
**Means "this pattern repeats for ALL elements"**

#### Example 1: Array `[f32; 100]`
```rust
TypeTree(vec![Type {
    offset: -1, // ALL positions
    size: 4,    // each f32 is 4 bytes
    kind: Float, // every element is float
}])
```

Instead of listing 100 separate Types with offsets `0,4,8,12...396`

#### Example 2: Slice `&[i32]`
```rust
// Pointer to slice data
TypeTree(vec![Type {
    offset: -1, size: 8, kind: Pointer,
    child: TypeTree(vec![Type {
        offset: -1, // ALL slice elements
        size: 4,    // each i32 is 4 bytes
        kind: Integer
    }])
}])
```

#### Example 3: Mixed Structure
```rust
struct Container {
    header: i64,        // offset 0
    data: [f32; 1000],  // offset 8, but elements use -1
}
```

```rust
TypeTree(vec![
    Type { offset: 0, size: 8, kind: Integer }, // header
    Type { offset: 8, size: 4000, kind: Pointer,
        child: TypeTree(vec![Type {
            offset: -1, size: 4, kind: Float // ALL array elements
        }])
    }
])
```
2025-09-28 18:13:11 +02:00
Matthias Krüger
e8578c8808 Rollup merge of #146763 - Zalathar:di-builder, r=jdonszelmann
cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 5)

- Part of rust-lang/rust#134001
- Follow-up to rust-lang/rust#146673

---

This is another batch of LLVMDIBuilder binding migrations, replacing some our own LLVMRust bindings with bindings to upstream LLVM-C APIs.

Some of these are a little more complex than most of the previous migrations, because they split one LLVMRust binding into multiple LLVM bindings, but nothing too fancy.

This appears to be the last of the low-hanging fruit. As noted in https://github.com/rust-lang/rust/issues/134001#issuecomment-2524979268, the remaining bindings are difficult or impossible to migrate at present.
2025-09-28 09:15:23 +02:00
Augie Fackler
bd860bdf26 Fix typo in LLVM_VERSION_ macro use
Co-authored-by: Nikita Popov <github@npopov.com>
2025-09-26 15:38:30 -04:00
Augie Fackler
4c7292aba3 PassWrapper: drop unused variable for LLVM 22+ 2025-09-26 13:27:34 -04:00
Augie Fackler
7a9b6d94d4 PassWrapper: update for new PGOOptions args in LLVM 22
This changed in upstream change a5569b4bd7f8.

@rustbot label llvm-main
2025-09-25 18:24:16 -04:00
Stuart Cook
59866ef305 Rollup merge of #147015 - Zalathar:dispose-tm, r=lqd
Use `LLVMDisposeTargetMachine`

After bumping the minimum LLVM version to 20 (rust-lang/rust#145071), we no longer need to run any custom code when disposing of a TargetMachine, so we can just use the upstream LLVM-C function.
2025-09-25 20:32:00 +10:00
Stuart Cook
2565b27cc0 Rollup merge of #146905 - durin42:llvm-22-bitstream-remarks, r=nikic
llvm: update remarks support on LLVM 22

LLVM change dfbd76bda01e removed separate remark support entirely, but
it turns out we can just drop the parameter and everything appears to
work fine.

Fixes rust-lang/rust#146912 as far as I can tell (the test passes.)
2025-09-25 20:31:56 +10:00
Zalathar
85018f09f6 Use LLVMDisposeTargetMachine 2025-09-25 18:10:55 +10:00
Josh Stone
fe440ec934 llvm: add a destructor to call releaseSerializer 2025-09-24 16:53:17 -07:00
Augie Fackler
42cf78f762 llvm: update remarks support on LLVM 22
LLVM change dfbd76bda01e removed separate remark support entirely, but
it turns out we can just drop the parameter and everything appears to
work fine.

Fixes 146912 as far as I can tell (the test passes.)

@rustbot label llvm-main
2025-09-23 13:25:04 -04:00
Matthias Krüger
8f11c4dadb Rollup merge of #146784 - dpaoliello:findmsvc, r=wesleywiser
[win] Use find-msvc-tools instead of cc to find the linker and rc on Windows

`find-msvc-tools` was factored out from `cc` to allow updating the use in `rustc_codegen_ssa` (finding the linker when running the Rust compiler) and `rustc_windows_rc` (finding the Windows Resource Compiler when running the Rust compiler) to be separate from the use in `rustc_llvm` (building LLVM as part of building the Rust compiler).
2025-09-23 18:13:53 +02:00
Folkert de Vries
3565b0699d emit attribute for readonly non-pure inline assembly 2025-09-21 21:16:06 +02:00
Zalathar
741e1e2ec7 Remove unused LLVMRustDIBuilder(Create|Dispose)
These should have been removed earlier, when we switched to the corresponding
LLVM-C bindings.
2025-09-20 12:48:48 +10:00
Daniel Paoliello
4da59355fd [win] Use find-msvc-tools instead of cc to find the linker and rc on Windows 2025-09-19 12:00:30 -07:00
bors
0be8e16088 Auto merge of #146700 - Zalathar:quoted-args, r=nikic
cg_llvm: Move target machine command-line quoting from C++ to Rust

When this code was introduced in rust-lang/rust#130446 and rust-lang/rust#131805, it was complicated by the need to maintain compatibility with earlier versions of LLVM.

Now that LLVM 20 is the baseline (rust-lang/rust#145071), we can do all of the quoting in pure Rust code, and pass two flat strings to LLVM to be used as-is.

---

In this PR, my priority has been to preserve the existing behaviour as much as possible, without worrying too much about what the behaviour *should* be. (Though I did avoid a leading space before the first argument.)
2025-09-19 18:32:17 +00:00
Zalathar
e39e5a0d15 Use LLVMDIBuilderCreate(Auto|Parameter)Variable 2025-09-19 20:56:58 +10:00
Zalathar
9daa026cad Use LLVMDIBuilder(CreateExpression|InsertDeclareRecordAtEnd) 2025-09-19 17:15:32 +10:00
Karan Janthe
3ba5f19182 autodiff: typetree recursive depth query from enzyme with fallback
Signed-off-by: Karan Janthe <karanjanthe@gmail.com>
2025-09-19 05:42:27 +00:00
Zalathar
a6d261712e Use LLVMDIBuilderGetOrCreateArray 2025-09-19 14:44:54 +10:00
Zalathar
b1a9f231fe Use LLVMDIBuilderGetOrCreateSubrange 2025-09-19 14:41:18 +10:00
Zalathar
8b0a254860 Move target machine command-line quoting from C++ to Rust 2025-09-18 15:25:25 +10:00
Zalathar
6b51f7c076 Use LLVMDIBuilderCreateTypedef 2025-09-17 22:32:22 +10:00
Zalathar
002771ab5c Use LLVMDIBuilderCreateQualifiedType 2025-09-17 22:32:22 +10:00
Zalathar
bb21dbeac7 Use LLVMDIBuilderCreateStaticMemberType 2025-09-17 22:32:22 +10:00
Zalathar
923d1be6b6 Use LLVMDIBuilderCreateMemberType 2025-09-17 22:32:21 +10:00
Stuart Cook
4e6640be66 Rollup merge of #146631 - Zalathar:di-builder, r=nnethercote
cg_llvm: Replace some DIBuilder wrappers with LLVM-C API bindings (part 3)

- Part of rust-lang/rust#134001
- Follow-up to rust-lang/rust#136375
- Follow-up to rust-lang/rust#136632

---

This is another batch of LLVMDIBuilder binding migrations, replacing some our own LLVMRust bindings with bindings to upstream LLVM-C APIs.

This PR migrates all of the bindings that were touched by rust-lang/rust#136632, plus `LLVMDIBuilderCreateStructType`.
2025-09-17 14:56:49 +10:00
Zalathar
af88d14cac Use LLVMDIBuilderCreateStructType 2025-09-17 12:28:08 +10:00
Zalathar
bae6fde270 Use LLVMDIBuilderCreatePointerType 2025-09-17 12:28:08 +10:00
Zalathar
3e9048d9a4 Use LLVMDIBuilderCreateBasicType 2025-09-17 12:28:08 +10:00
Zalathar
bef8f646a6 Use LLVMDIBuilderCreateArrayType 2025-09-17 12:28:08 +10:00
Zalathar
2552deb9cd Use LLVMDIBuilderCreateUnionType 2025-09-17 12:28:08 +10:00
Zalathar
5419896111 Use LLVMDIBuilderCreateSubroutineType 2025-09-17 12:28:08 +10:00
Josh Stone
580b4891aa Update the minimum external LLVM to 20 2025-09-16 11:49:20 -07:00
klensy
dbfa01b6a1 remove outdated jsbackend leftovers 2025-09-12 12:03:09 +03:00
klensy
acb35038ff remove unused getLongestEntryLength 2025-09-11 21:43:18 +03:00
klensy
0e5281cea8 remove unused macro 2025-09-11 21:40:25 +03:00
bors
be8de5d6a0 Auto merge of #146360 - Zalathar:rollup-qc2hhrd, r=Zalathar
Rollup of 11 pull requests

Successful merges:

 - rust-lang/rust#139593 (add sitemap to rust docs)
 - rust-lang/rust#145819 (Port limit attributes to the new attribute parsing infrastructure)
 - rust-lang/rust#146025 (compiler: Include span of too huge array with `-Cdebuginfo=2`)
 - rust-lang/rust#146184 (In the rustc_llvm build script, don't consider arm64* to be 32-bit)
 - rust-lang/rust#146195 (fix partial urlencoded link support)
 - rust-lang/rust#146300 (Implement `Sum` and `Product` for `f16` and `f128`.)
 - rust-lang/rust#146314 (mark `format_args_nl!` as `#[doc(hidden)]`)
 - rust-lang/rust#146324 (const-eval: disable pointer fragment support)
 - rust-lang/rust#146326 (simplify the declaration of the legacy integer modules (`std::u32` etc.))
 - rust-lang/rust#146339 (Update books)
 - rust-lang/rust#146343 (Weakly export `platform_version` symbols)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-09-09 11:54:44 +00:00
Stuart Cook
c5a62b8058 Rollup merge of #146184 - dpaoliello:llvmbuildarm64, r=cuviper
In the rustc_llvm build script, don't consider arm64* to be 32-bit

The build script for `rustc_llvm` needs to detect 32-bit targets so that it links against `libatomics`. To do this, it matches the target architecture against `arm`, unfortunately incorrectly matches Arm64EC, Arm64E, etc.

This change adds a check that the target arch doesn't match `arm64`.
2025-09-09 14:35:03 +10:00
bors
fefce3cecd Auto merge of #146018 - lambdageek:add-winres-version, r=wesleywiser
compiler: Add Windows resources to rustc-main and rustc_driver

Adds Windows resources with the rust version information to rustc-main.exe and rustc_driver.dll

Invokes `rc.exe` directly, rather than using one of the crates from the ecosystem to avoid adding dependencies.

A new internal `rustc_windows_rc` crate has the common build script machinery for locating `rc.exe` and constructing the resource script
2025-09-09 03:56:41 +00:00
Matthias Krüger
92bad93f06 Rollup merge of #146209 - bjorn3:lto_refactors5, r=dianqk
Misc LTO cleanups

Follow up to https://github.com/rust-lang/rust/pull/145955.

* Remove want_summary argument from `prepare_thin`.
   Since https://github.com/rust-lang/rust/pull/133250 ThinLTO summary writing is instead done by `llvm_optimize`.
* Two minor cleanups
2025-09-07 20:02:27 +02:00