Skip to content

Commit 6108a2d

Browse files
committed
Lower autodiff functions using instrinsics
1 parent 2801f9a commit 6108a2d

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,9 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
187187
&[ptr, args[1].immediate()],
188188
)
189189
}
190+
_ if tcx.has_attr(def_id, sym::rustc_autodiff) => {
191+
return Err(ty::Instance::new_raw(def_id, instance.args));
192+
}
190193
sym::is_val_statically_known => {
191194
if let OperandValue::Immediate(imm) = args[0].val {
192195
self.call_intrinsic(

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,8 @@ pub(crate) fn check_intrinsic_type(
170170
}
171171
};
172172

173+
let has_autodiff = tcx.has_attr(intrinsic_id, sym::rustc_autodiff);
174+
173175
let bound_vars = tcx.mk_bound_variable_kinds(&[
174176
ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon),
175177
ty::BoundVariableKind::Region(ty::BoundRegionKind::Anon),
@@ -197,6 +199,17 @@ pub(crate) fn check_intrinsic_type(
197199
let safety = intrinsic_operation_unsafety(tcx, intrinsic_id);
198200
let n_lts = 0;
199201
let (n_tps, n_cts, inputs, output) = match intrinsic_name {
202+
_ if has_autodiff => {
203+
let sig = tcx.fn_sig(intrinsic_id.to_def_id());
204+
let sig = sig.skip_binder();
205+
let n_tps = generics.own_counts().types;
206+
let n_cts = generics.own_counts().consts;
207+
208+
let inputs = sig.skip_binder().inputs().to_vec();
209+
let output = sig.skip_binder().output();
210+
211+
(n_tps, n_cts, inputs, output)
212+
}
200213
sym::abort => (0, 0, vec![], tcx.types.never),
201214
sym::unreachable => (0, 0, vec![], tcx.types.never),
202215
sym::breakpoint => (0, 0, vec![], tcx.types.unit),

0 commit comments

Comments
 (0)