<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/compiler/rustc_codegen_llvm/src/back, branch master</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=master</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=master'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2025-09-28T16:13:11+00:00</updated>
<entry>
<title>Rollup merge of #144197 - KMJ-007:type-tree, r=ZuseZ4</title>
<updated>2025-09-28T16:13:11+00:00</updated>
<author>
<name>Matthias Krüger</name>
<email>476013+matthiaskrgr@users.noreply.github.com</email>
</author>
<published>2025-09-28T16:13:11+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=c29fb2e57ed0578c9051cc9314b0225f847de710'/>
<id>urn:sha1:c29fb2e57ed0578c9051cc9314b0225f847de710</id>
<content type='text'>
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&lt;Type&gt;)

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: &amp;f32, data: &amp;[f32]) -&gt; f32`

**Input 0: `x: &amp;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: &amp;[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 `&amp;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 `&amp;[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
        }])
    }
])
```
</content>
</entry>
<entry>
<title>Use `LLVMDisposeTargetMachine`</title>
<updated>2025-09-25T08:10:55+00:00</updated>
<author>
<name>Zalathar</name>
<email>Zalathar@users.noreply.github.com</email>
</author>
<published>2025-09-25T08:10:55+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=85018f09f67bd54868fe12a4632bbd637a474853'/>
<id>urn:sha1:85018f09f67bd54868fe12a4632bbd637a474853</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Add self-profile events for target-machine creation</title>
<updated>2025-09-21T11:37:15+00:00</updated>
<author>
<name>Zalathar</name>
<email>Zalathar@users.noreply.github.com</email>
</author>
<published>2025-09-21T10:50:44+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=b17fb70d0437b90fc9ada0ac2d924cce06eb8828'/>
<id>urn:sha1:b17fb70d0437b90fc9ada0ac2d924cce06eb8828</id>
<content type='text'>
These code paths are surprisingly hot in the `large-workspace` benchmark; it
would be handy to see some detailed timings and execution counts.
</content>
</entry>
<entry>
<title>autodiff: Add basic TypeTree with NoTT flag</title>
<updated>2025-09-19T04:02:19+00:00</updated>
<author>
<name>Karan Janthe</name>
<email>karanjanthe@gmail.com</email>
</author>
<published>2025-08-23T20:17:32+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e1258e79d6cb709b26ded97d32de6c55f355e2aa'/>
<id>urn:sha1:e1258e79d6cb709b26ded97d32de6c55f355e2aa</id>
<content type='text'>
Signed-off-by: Karan Janthe &lt;karanjanthe@gmail.com&gt;
</content>
</entry>
<entry>
<title>Move target machine command-line quoting from C++ to Rust</title>
<updated>2025-09-18T05:25:25+00:00</updated>
<author>
<name>Zalathar</name>
<email>Zalathar@users.noreply.github.com</email>
</author>
<published>2025-09-17T03:46:46+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=8b0a25486040b91ede0120ff5a797517e0973895'/>
<id>urn:sha1:8b0a25486040b91ede0120ff5a797517e0973895</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Make llvm_enzyme a regular cargo feature</title>
<updated>2025-09-15T15:31:56+00:00</updated>
<author>
<name>bjorn3</name>
<email>17426603+bjorn3@users.noreply.github.com</email>
</author>
<published>2025-09-15T15:31:56+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=1991779bd4a0a8d8905b6644b06aa317dde353ac'/>
<id>urn:sha1:1991779bd4a0a8d8905b6644b06aa317dde353ac</id>
<content type='text'>
This makes it clearer that it is set by the build system rather than by
the rustc that compiles the current rustc. It also avoids bootstrap
needing to pass --check-cfg llvm_enzyme to rustc.
</content>
</entry>
<entry>
<title>Remove want_summary argument from prepare_thin</title>
<updated>2025-09-06T18:37:23+00:00</updated>
<author>
<name>bjorn3</name>
<email>17426603+bjorn3@users.noreply.github.com</email>
</author>
<published>2025-09-04T15:16:55+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=f2933b34a8331204270fa2bdbdcfd79fcffbb302'/>
<id>urn:sha1:f2933b34a8331204270fa2bdbdcfd79fcffbb302</id>
<content type='text'>
It is always false nowadays. ThinLTO summary writing is instead done by
llvm_optimize.
</content>
</entry>
<entry>
<title>Remove thin_link_data method from ThinBufferMethods</title>
<updated>2025-09-06T18:37:23+00:00</updated>
<author>
<name>bjorn3</name>
<email>17426603+bjorn3@users.noreply.github.com</email>
</author>
<published>2025-08-15T13:12:19+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e3d0b7d6480d7e4dbbbea24635f56e28dfe735b3'/>
<id>urn:sha1:e3d0b7d6480d7e4dbbbea24635f56e28dfe735b3</id>
<content type='text'>
It is only used within cg_llvm.
</content>
</entry>
<entry>
<title>Ensure fat LTO doesn't merge everything into the allocator module</title>
<updated>2025-09-06T13:31:41+00:00</updated>
<author>
<name>bjorn3</name>
<email>17426603+bjorn3@users.noreply.github.com</email>
</author>
<published>2025-09-05T19:09:39+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=2cf94b92ca852924ad90943a0c469f01742216a6'/>
<id>urn:sha1:2cf94b92ca852924ad90943a0c469f01742216a6</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Special case allocator module submission to avoid special casing it elsewhere</title>
<updated>2025-09-04T08:21:10+00:00</updated>
<author>
<name>bjorn3</name>
<email>17426603+bjorn3@users.noreply.github.com</email>
</author>
<published>2025-08-28T10:26:29+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=319fe230f0d960b343be31a1182dc0f10753156c'/>
<id>urn:sha1:319fe230f0d960b343be31a1182dc0f10753156c</id>
<content type='text'>
A lot of places had special handling just in case they would get an
allocator module even though most of these places could never get one or
would have a trivial implementation for the allocator module. Moving all
handling of the allocator module to a single place simplifies things a
fair bit.
</content>
</entry>
</feed>
