Skip to content

Commit ac01a05

Browse files
committed
add batching middle-end
1 parent e821972 commit ac01a05

File tree

1 file changed

+29
-4
lines changed

1 file changed

+29
-4
lines changed

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+29-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::str::FromStr;
22

33
use rustc_abi::ExternAbi;
44
use rustc_ast::expand::autodiff_attrs::{AutoDiffAttrs, DiffActivity, DiffMode};
5-
use rustc_ast::{MetaItem, MetaItemInner, attr};
5+
use rustc_ast::{LitKind, MetaItem, MetaItemInner, attr};
66
use rustc_attr_parsing::ReprAttr::ReprAlign;
77
use rustc_attr_parsing::{AttributeKind, InlineAttr, InstructionSetAttr, OptimizeAttr};
88
use rustc_data_structures::fx::FxHashMap;
@@ -805,8 +805,8 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
805805
return Some(AutoDiffAttrs::source());
806806
}
807807

808-
let [mode, input_activities @ .., ret_activity] = &list[..] else {
809-
span_bug!(attr.span(), "rustc_autodiff attribute must contain mode and activities");
808+
let [mode, width_meta, input_activities @ .., ret_activity] = &list[..] else {
809+
span_bug!(attr.span(), "rustc_autodiff attribute must contain mode, width and activities");
810810
};
811811
let mode = if let MetaItemInner::MetaItem(MetaItem { path: p1, .. }) = mode {
812812
p1.segments.first().unwrap().ident
@@ -823,6 +823,31 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
823823
}
824824
};
825825

826+
let width: u32;
827+
match width_meta {
828+
MetaItemInner::MetaItem(MetaItem { path: p1, .. }) => {
829+
let w = p1.segments.first().unwrap().ident;
830+
width = match w.as_str().parse() {
831+
Ok(val) => val,
832+
Err(_) => {
833+
span_bug!(w.span, "rustc_autodiff width should fit u32");
834+
}
835+
};
836+
}
837+
MetaItemInner::Lit(lit) => {
838+
if let LitKind::Int(val, _) = lit.kind {
839+
width = match val.get().try_into() {
840+
Ok(val) => val,
841+
Err(_) => {
842+
span_bug!(lit.span, "rustc_autodiff width should fit u32");
843+
}
844+
};
845+
} else {
846+
span_bug!(lit.span, "rustc_autodiff width should be an integer");
847+
}
848+
}
849+
}
850+
826851
// First read the ret symbol from the attribute
827852
let ret_symbol = if let MetaItemInner::MetaItem(MetaItem { path: p1, .. }) = ret_activity {
828853
p1.segments.first().unwrap().ident
@@ -860,7 +885,7 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
860885
}
861886
}
862887

863-
Some(AutoDiffAttrs { mode, width: 1, ret_activity, input_activity: arg_activities })
888+
Some(AutoDiffAttrs { mode, width, ret_activity, input_activity: arg_activities })
864889
}
865890

866891
pub(crate) fn provide(providers: &mut Providers) {

0 commit comments

Comments
 (0)