Skip to content

Commit 1e283c1

Browse files
committed
wip, all missing changes
1 parent 02d8763 commit 1e283c1

File tree

53 files changed

+2903
-92
lines changed

Some content is hidden

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

53 files changed

+2903
-92
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4148,6 +4148,7 @@ dependencies = [
41484148
name = "rustc_monomorphize"
41494149
version = "0.0.0"
41504150
dependencies = [
4151+
"rustc_ast",
41514152
"rustc_data_structures",
41524153
"rustc_errors",
41534154
"rustc_fluent_macro",
@@ -4156,6 +4157,7 @@ dependencies = [
41564157
"rustc_middle",
41574158
"rustc_session",
41584159
"rustc_span",
4160+
"rustc_symbol_mangling",
41594161
"rustc_target",
41604162
"serde",
41614163
"serde_json",

compiler/rustc_ast/src/ast.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,6 +2729,13 @@ impl FnRetTy {
27292729
FnRetTy::Ty(ty) => ty.span,
27302730
}
27312731
}
2732+
2733+
pub fn has_ret(&self) -> bool {
2734+
match self {
2735+
FnRetTy::Default(_) => false,
2736+
FnRetTy::Ty(_) => true,
2737+
}
2738+
}
27322739
}
27332740

27342741
#[derive(Clone, Copy, PartialEq, Encodable, Decodable, Debug)]

compiler/rustc_ast/src/expand/autodiff_attrs.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::expand::HashStable_Generic;
88
use crate::expand::Encodable;
99
use crate::expand::Decodable;
1010

11-
#[allow(dead_code)]
1211
#[derive(Clone, Copy, Eq, PartialEq, Encodable, Decodable, Debug, HashStable_Generic)]
1312
pub enum DiffMode {
1413
Inactive,

compiler/rustc_builtin_macros/src/errors.rs

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -145,51 +145,51 @@ pub(crate) struct AllocMustStatics {
145145
pub(crate) span: Span,
146146
}
147147

148-
//#[derive(Diagnostic)]
149-
//#[diag(builtin_macros_autodiff_unknown_activity)]
150-
//pub(crate) struct AutoDiffUnknownActivity {
151-
// #[primary_span]
152-
// pub(crate) span: Span,
153-
// pub(crate) act: String,
154-
//}
155-
//#[derive(Diagnostic)]
156-
//#[diag(builtin_macros_autodiff_ty_activity)]
157-
//pub(crate) struct AutoDiffInvalidTypeForActivity {
158-
// #[primary_span]
159-
// pub(crate) span: Span,
160-
// pub(crate) act: String,
161-
//}
162-
//#[derive(Diagnostic)]
163-
//#[diag(builtin_macros_autodiff_number_activities)]
164-
//pub(crate) struct AutoDiffInvalidNumberActivities {
165-
// #[primary_span]
166-
// pub(crate) span: Span,
167-
// pub(crate) expected: usize,
168-
// pub(crate) found: usize,
169-
//}
170-
//#[derive(Diagnostic)]
171-
//#[diag(builtin_macros_autodiff_mode_activity)]
172-
//pub(crate) struct AutoDiffInvalidApplicationModeAct {
173-
// #[primary_span]
174-
// pub(crate) span: Span,
175-
// pub(crate) mode: String,
176-
// pub(crate) act: String,
177-
//}
178-
//
179-
//#[derive(Diagnostic)]
180-
//#[diag(builtin_macros_autodiff_mode)]
181-
//pub(crate) struct AutoDiffInvalidMode {
182-
// #[primary_span]
183-
// pub(crate) span: Span,
184-
// pub(crate) mode: String,
185-
//}
186-
//
187-
//#[derive(Diagnostic)]
188-
//#[diag(builtin_macros_autodiff)]
189-
//pub(crate) struct AutoDiffInvalidApplication {
190-
// #[primary_span]
191-
// pub(crate) span: Span,
192-
//}
148+
#[derive(Diagnostic)]
149+
#[diag(builtin_macros_autodiff_unknown_activity)]
150+
pub(crate) struct AutoDiffUnknownActivity {
151+
#[primary_span]
152+
pub(crate) span: Span,
153+
pub(crate) act: String,
154+
}
155+
#[derive(Diagnostic)]
156+
#[diag(builtin_macros_autodiff_ty_activity)]
157+
pub(crate) struct AutoDiffInvalidTypeForActivity {
158+
#[primary_span]
159+
pub(crate) span: Span,
160+
pub(crate) act: String,
161+
}
162+
#[derive(Diagnostic)]
163+
#[diag(builtin_macros_autodiff_number_activities)]
164+
pub(crate) struct AutoDiffInvalidNumberActivities {
165+
#[primary_span]
166+
pub(crate) span: Span,
167+
pub(crate) expected: usize,
168+
pub(crate) found: usize,
169+
}
170+
#[derive(Diagnostic)]
171+
#[diag(builtin_macros_autodiff_mode_activity)]
172+
pub(crate) struct AutoDiffInvalidApplicationModeAct {
173+
#[primary_span]
174+
pub(crate) span: Span,
175+
pub(crate) mode: String,
176+
pub(crate) act: String,
177+
}
178+
179+
#[derive(Diagnostic)]
180+
#[diag(builtin_macros_autodiff_mode)]
181+
pub(crate) struct AutoDiffInvalidMode {
182+
#[primary_span]
183+
pub(crate) span: Span,
184+
pub(crate) mode: String,
185+
}
186+
187+
#[derive(Diagnostic)]
188+
#[diag(builtin_macros_autodiff)]
189+
pub(crate) struct AutoDiffInvalidApplication {
190+
#[primary_span]
191+
pub(crate) span: Span,
192+
}
193193

194194
#[derive(Diagnostic)]
195195
#[diag(builtin_macros_autodiff_not_build)]

compiler/rustc_codegen_llvm/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ codegen_llvm_prepare_thin_lto_module_with_llvm_err = failed to prepare thin LTO
5757
codegen_llvm_run_passes = failed to run LLVM passes
5858
codegen_llvm_run_passes_with_llvm_err = failed to run LLVM passes: {$llvm_err}
5959
60+
codegen_llvm_prepare_autodiff = failed to prepare AutoDiff: src: {$src}, target: {$target}, {$error}
61+
codegen_llvm_prepare_autodiff_with_llvm_err = failed to prepare AutoDiff: {$llvm_err}, src: {$src}, target: {$target}, {$error}
62+
codegen_llvm_autodiff_without_lto = using the autodiff feature requires using fat-lto
63+
6064
codegen_llvm_sanitizer_memtag_requires_mte =
6165
`-Zsanitizer=memtag` requires `-Ctarget-feature=+mte`
6266

compiler/rustc_codegen_llvm/src/abi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ impl<'ll, 'tcx> ArgAbiExt<'ll, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
242242
scratch_align,
243243
bx.const_usize(copy_bytes),
244244
MemFlags::empty(),
245+
None,
245246
);
246247
bx.lifetime_end(llscratch, scratch_size);
247248
}

compiler/rustc_codegen_llvm/src/attributes.rs

Lines changed: 4 additions & 0 deletions
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
pub use rustc_attr::{InlineAttr, InstructionSetAttr, OptimizeAttr};
45
use rustc_codegen_ssa::traits::*;
56
use rustc_hir::def_id::DefId;
@@ -333,6 +334,7 @@ pub fn llfn_attrs_from_instance<'ll, 'tcx>(
333334
instance: ty::Instance<'tcx>,
334335
) {
335336
let codegen_fn_attrs = cx.tcx.codegen_fn_attrs(instance.def_id());
337+
let autodiff_attrs: &AutoDiffAttrs = cx.tcx.autodiff_attrs(instance.def_id());
336338

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

@@ -350,6 +352,8 @@ pub fn llfn_attrs_from_instance<'ll, 'tcx>(
350352
let inline =
351353
if codegen_fn_attrs.inline == InlineAttr::None && instance.def.requires_inline(cx.tcx) {
352354
InlineAttr::Hint
355+
} else if autodiff_attrs.is_active() {
356+
InlineAttr::Never
353357
} else {
354358
codegen_fn_attrs.inline
355359
};

compiler/rustc_codegen_llvm/src/back/lto.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,12 @@ pub(crate) fn run_pass_manager(
622622
}
623623
let opt_stage = if thin { llvm::OptStage::ThinLTO } else { llvm::OptStage::FatLTO };
624624
let opt_level = config.opt_level.unwrap_or(config::OptLevel::No);
625-
write::llvm_optimize(cgcx, dcx, module, config, opt_level, opt_stage)?;
625+
626+
// We will run this again with different values in the context of automatic differentiation.
627+
let first_run = true;
628+
let noop = false;
629+
debug!("running llvm pm opt pipeline");
630+
write::llvm_optimize(cgcx, dcx, module, config, opt_level, opt_stage, first_run, noop)?;
626631
}
627632
debug!("lto done");
628633
Ok(())
@@ -729,7 +734,12 @@ pub unsafe fn optimize_thin_module(
729734
let llcx = unsafe { llvm::LLVMRustContextCreate(cgcx.fewer_names) };
730735
let llmod_raw = parse_module(llcx, module_name, thin_module.data(), dcx)? as *const _;
731736
let mut module = ModuleCodegen {
732-
module_llvm: ModuleLlvm { llmod_raw, llcx, tm: ManuallyDrop::new(tm) },
737+
module_llvm: ModuleLlvm {
738+
llmod_raw,
739+
llcx,
740+
tm: ManuallyDrop::new(tm),
741+
typetrees: Default::default(),
742+
},
733743
name: thin_module.name().to_string(),
734744
kind: ModuleKind::Regular,
735745
};

0 commit comments

Comments
 (0)