Skip to content

Commit 2911775

Browse files
committed
Lower autodiff functions using instrinsics
1 parent a955f1c commit 2911775

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
@@ -189,6 +189,9 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
189189
&[ptr, args[1].immediate()],
190190
)
191191
}
192+
_ if tcx.has_attr(def_id, sym::rustc_autodiff) => {
193+
return Err(ty::Instance::new_raw(def_id, instance.args));
194+
}
192195
sym::is_val_statically_known => {
193196
if let OperandValue::Immediate(imm) = args[0].val {
194197
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
@@ -171,6 +171,8 @@ pub(crate) fn check_intrinsic_type(
171171
}
172172
};
173173

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

0 commit comments

Comments
 (0)