Skip to content

Commit 2c50ebd

Browse files
ZuseZ4davidtwco
andauthored
Update compiler/rustc_codegen_llvm/src/builder.rs
Co-authored-by: David Wood <agile.lion3441@fuligin.ink>
1 parent 6981115 commit 2c50ebd

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,15 @@ fn get_params(fnc: &Value) -> Vec<&Value> {
4848
}
4949
}
5050

51-
// The lowering of one `#[autodiff]` macro happens in multiple steps.
52-
// First we transalte generate a new dummy function, who's llvm-ir we now have as outer_fn.
53-
// We kept track of the original function to which the `#[autodiff]` macro was applied to, which we
54-
// now have as fn_to_diff. In our current implementation, we use the enzyme pass to carry out the
55-
// differentiation, following naming and calling conventions documented here: <https://enzyme.mit.edu/getting_started/CallingConvention/>
56-
//
57-
// Our `outer_fn` had some dummy code inserted at higher levels, so we first remove most of the
58-
// existing body. We then insert an `__enzyme_<autodiff/fwddiff>_<unique_id>` call, which the pass
59-
// will then pick up. FIXME(ZuseZ4): We will later want to upstream safety checks to the `outer_fn`,
60-
// in order to cover some assumptions of enzyme/autodiff, which could lead to UB otherwise.
51+
/// When differentiating `fn_to_diff`, take a `outer_fn` and generate another
52+
/// function with expected naming and calling conventions[^1] which will be
53+
/// discovered by the enzyme LLVM pass and its body populated with the differentiated
54+
/// `fn_to_diff`. `outer_fn` is then modified to have a call to the generated
55+
/// function and handle the differences between the Rust calling convention and
56+
/// Enzyme.
57+
/// [^1]: <https://enzyme.mit.edu/getting_started/CallingConvention/>
58+
// FIXME(ZuseZ4): `outer_fn` should include upstream safety checks to
59+
// cover some assumptions of enzyme/autodiff, which could lead to UB otherwise.
6160
pub(crate) fn generate_enzyme_call<'ll>(
6261
llmod: &'ll llvm::Module,
6362
llcx: &'ll llvm::Context,

0 commit comments

Comments
 (0)