Skip to content

Commit b4d09a6

Browse files
committed
Single commit with all changes
1 parent c1db4dc commit b4d09a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2878
-61
lines changed

Cargo.lock

+2
Original file line numberDiff line numberDiff line change
@@ -4121,6 +4121,7 @@ dependencies = [
41214121
name = "rustc_monomorphize"
41224122
version = "0.0.0"
41234123
dependencies = [
4124+
"rustc_ast",
41244125
"rustc_data_structures",
41254126
"rustc_errors",
41264127
"rustc_fluent_macro",
@@ -4129,6 +4130,7 @@ dependencies = [
41294130
"rustc_middle",
41304131
"rustc_session",
41314132
"rustc_span",
4133+
"rustc_symbol_mangling",
41324134
"rustc_target",
41334135
"serde",
41344136
"serde_json",

compiler/rustc_builtin_macros/src/errors.rs

+54
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,60 @@ mod ad_fallback {
217217
}
218218
}
219219

220+
#[derive(Diagnostic)]
221+
#[diag(builtin_macros_autodiff_unknown_activity)]
222+
pub(crate) struct AutoDiffUnknownActivity {
223+
#[primary_span]
224+
pub(crate) span: Span,
225+
pub(crate) act: String,
226+
}
227+
#[derive(Diagnostic)]
228+
#[diag(builtin_macros_autodiff_ty_activity)]
229+
pub(crate) struct AutoDiffInvalidTypeForActivity {
230+
#[primary_span]
231+
pub(crate) span: Span,
232+
pub(crate) act: String,
233+
}
234+
#[derive(Diagnostic)]
235+
#[diag(builtin_macros_autodiff_number_activities)]
236+
pub(crate) struct AutoDiffInvalidNumberActivities {
237+
#[primary_span]
238+
pub(crate) span: Span,
239+
pub(crate) expected: usize,
240+
pub(crate) found: usize,
241+
}
242+
#[derive(Diagnostic)]
243+
#[diag(builtin_macros_autodiff_mode_activity)]
244+
pub(crate) struct AutoDiffInvalidApplicationModeAct {
245+
#[primary_span]
246+
pub(crate) span: Span,
247+
pub(crate) mode: String,
248+
pub(crate) act: String,
249+
}
250+
251+
#[derive(Diagnostic)]
252+
#[diag(builtin_macros_autodiff_mode)]
253+
pub(crate) struct AutoDiffInvalidMode {
254+
#[primary_span]
255+
pub(crate) span: Span,
256+
pub(crate) mode: String,
257+
}
258+
259+
#[derive(Diagnostic)]
260+
#[diag(builtin_macros_autodiff)]
261+
pub(crate) struct AutoDiffInvalidApplication {
262+
#[primary_span]
263+
pub(crate) span: Span,
264+
}
265+
266+
#[cfg(not(llvm_enzyme))]
267+
#[derive(Diagnostic)]
268+
#[diag(builtin_macros_autodiff_not_build)]
269+
pub(crate) struct AutoDiffSupportNotBuild {
270+
#[primary_span]
271+
pub(crate) span: Span,
272+
}
273+
220274
#[derive(Diagnostic)]
221275
#[diag(builtin_macros_concat_bytes_invalid)]
222276
pub(crate) struct ConcatBytesInvalid {

compiler/rustc_builtin_macros/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#![feature(proc_macro_internals)]
1717
#![feature(proc_macro_quote)]
1818
#![feature(rustdoc_internals)]
19+
#![cfg_attr(not(bootstrap), feature(autodiff))]
1920
#![feature(try_blocks)]
2021
#![warn(unreachable_pub)]
2122
// tidy-alphabetical-end

compiler/rustc_codegen_llvm/messages.ftl

+4
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ codegen_llvm_prepare_thin_lto_module_with_llvm_err = failed to prepare thin LTO
5151
codegen_llvm_run_passes = failed to run LLVM passes
5252
codegen_llvm_run_passes_with_llvm_err = failed to run LLVM passes: {$llvm_err}
5353
54+
codegen_llvm_prepare_autodiff = failed to prepare AutoDiff: src: {$src}, target: {$target}, {$error}
55+
codegen_llvm_prepare_autodiff_with_llvm_err = failed to prepare AutoDiff: {$llvm_err}, src: {$src}, target: {$target}, {$error}
56+
codegen_llvm_autodiff_without_lto = using the autodiff feature requires using fat-lto
57+
5458
codegen_llvm_sanitizer_memtag_requires_mte =
5559
`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`
5660

compiler/rustc_codegen_llvm/src/abi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
244244
scratch_align,
245245
bx.const_usize(copy_bytes),
246246
MemFlags::empty(),
247+
None,
247248
);
248249
bx.lifetime_end(llscratch, scratch_size);
249250
}

compiler/rustc_codegen_llvm/src/attributes.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! Set and unset common attributes on LLVM values.
22
3+
use rustc_ast::expand::autodiff_attrs::AutoDiffAttrs;
34
use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr};
45
use rustc_codegen_ssa::traits::*;
56
use rustc_hir::def_id::DefId;
@@ -332,6 +333,7 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
332333
instance: ty::Instance<'tcx>,
333334
) {
334335
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
336+
let autodiff_attrs: &AutoDiffAttrs = cx.tcx.autodiff_attrs(instance.def_id());
335337

336338
let mut to_add = SmallVec::<[_; 16]>::new();
337339

@@ -349,6 +351,8 @@ pub(crate) fn llfn_attrs_from_instance<'ll, 'tcx>(
349351
let inline =
350352
if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
351353
InlineAttr::Hint
354+
} else if autodiff_attrs.is_active() {
355+
InlineAttr::Never
352356
} else {
353357
codegen_fn_attrs.inline
354358
};

compiler/rustc_codegen_llvm/src/back/lto.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,12 @@ pub(crate) fn run_pass_manager(
616616
}
617617
let opt_stage = if thin { llvm::OptStage::ThinLTO } else { llvm::OptStage::FatLTO };
618618
let opt_level = config.opt_level.unwrap_or(config::OptLevel::No);
619-
write::llvm_optimize(cgcx, dcx, module, config, opt_level, opt_stage)?;
619+
620+
// We will run this again with different values in the context of automatic differentiation.
621+
let first_run = true;
622+
let noop = false;
623+
debug!("running llvm pm opt pipeline");
624+
write::llvm_optimize(cgcx, dcx, module, config, opt_level, opt_stage, first_run, noop)?;
620625
}
621626
debug!("lto done");
622627
Ok(())
@@ -723,7 +728,12 @@ pub(crate) unsafe fn optimize_thin_module(
723728
let llcx = unsafe { llvm::LLVMRustContextCreate(cgcx.fewer_names) };
724729
let llmod_raw = parse_module(llcx, module_name, thin_module.data(), dcx)? as *const _;
725730
let mut module = ModuleCodegen {
726-
module_llvm: ModuleLlvm { llmod_raw, llcx, tm: ManuallyDrop::new(tm) },
731+
module_llvm: ModuleLlvm {
732+
llmod_raw,
733+
llcx,
734+
tm: ManuallyDrop::new(tm),
735+
typetrees: Default::default(),
736+
},
727737
name: thin_module.name().to_string(),
728738
kind: ModuleKind::Regular,
729739
};

0 commit comments

Comments
 (0)