Skip to content

Commit 12cddf0

Browse files
committed
reduce warnings, re-add partial enzyme flags support
1 parent 17ac428 commit 12cddf0

File tree

6 files changed

+40
-64
lines changed

6 files changed

+40
-64
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

Lines changed: 38 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::{fs, slice, str};
66

77
use libc::{c_char, c_int, c_uint, c_void, size_t};
88
use llvm::{
9-
IntPredicate, LLVMRustLLVMHasZlibCompressionForDebugSymbols,
9+
LLVMRustLLVMHasZlibCompressionForDebugSymbols,
1010
LLVMRustLLVMHasZstdCompressionForDebugSymbols,
1111
};
1212
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
@@ -44,19 +44,14 @@ use crate::errors::{
4444
use crate::llvm::diagnostic::OptimizationDiagnosticKind::*;
4545
use crate::llvm::{
4646
self, AttributeKind, DiagnosticInfo,
47-
LLVMAppendBasicBlockInContext, LLVMBuildCall2,
48-
LLVMBuildCondBr, LLVMBuildExtractValue, LLVMBuildICmp, LLVMBuildRet, LLVMBuildRetVoid,
49-
LLVMCountParams, LLVMCountStructElementTypes, LLVMCreateBuilderInContext,
50-
LLVMCreateStringAttribute, LLVMDisposeBuilder, LLVMDumpModule, LLVMGetFirstBasicBlock,
51-
LLVMGetFirstFunction, LLVMGetNextFunction, LLVMGetParams, LLVMGetReturnType,
52-
LLVMGetStringAttributeAtIndex, LLVMGlobalGetValueType, LLVMIsEnumAttribute,
53-
LLVMIsStringAttribute, LLVMMetadataAsValue, LLVMPositionBuilderAtEnd,
47+
LLVMCreateStringAttribute, LLVMDumpModule,
48+
LLVMGetFirstFunction, LLVMGetNextFunction,
49+
LLVMGetStringAttributeAtIndex, LLVMIsEnumAttribute,
50+
LLVMIsStringAttribute,
5451
LLVMRemoveStringAttributeAtIndex, LLVMRustAddEnumAttributeAtIndex,
55-
LLVMRustAddFunctionAttributes, LLVMRustDIGetInstMetadata, LLVMRustEraseInstBefore,
56-
LLVMRustEraseInstFromParent, LLVMRustGetEnumAttributeAtIndex, LLVMRustGetFunctionType,
57-
LLVMRustGetLastInstruction, LLVMRustGetTerminator, LLVMRustHasMetadata,
58-
LLVMRustRemoveEnumAttributeAtIndex, LLVMVerifyFunction, LLVMVoidTypeInContext, PassManager,
59-
Value,
52+
LLVMRustAddFunctionAttributes,
53+
LLVMRustGetEnumAttributeAtIndex,
54+
LLVMRustRemoveEnumAttributeAtIndex, PassManager,
6055
};
6156
use crate::type_::Type;
6257
use crate::{LlvmCodegenBackend, ModuleLlvm, base, common, llvm_util};
@@ -652,6 +647,14 @@ pub(crate) unsafe fn llvm_optimize(
652647
result.into_result().map_err(|()| llvm_err(dcx, LlvmError::RunLlvmPasses))
653648
}
654649

650+
#[allow(non_snake_case)]
651+
unsafe fn EnzymeSetCLBool(ptr: *mut c_int, val: u8) {
652+
unsafe {
653+
//let ptr = ptr as *mut c_int;
654+
*ptr = val as c_int;
655+
}
656+
}
657+
655658
pub(crate) fn differentiate(
656659
module: &ModuleCodegen<ModuleLlvm>,
657660
cgcx: &CodegenContext<LlvmCodegenBackend>,
@@ -672,8 +675,13 @@ pub(crate) fn differentiate(
672675

673676
if ad.contains(&AutoDiff::LooseTypes) {
674677
dbg!("Setting loose types to true");
675-
//llvm::set_loose_types(true);
676-
todo!();
678+
//extern "C" {
679+
#[allow(non_upper_case_globals)]
680+
static mut looseTypeAnalysis: c_int = 0;
681+
//}
682+
unsafe {
683+
EnzymeSetCLBool(std::ptr::addr_of_mut!(looseTypeAnalysis), true as u8);
684+
}
677685
}
678686

679687
// Before dumping the module, we want all the tt to become part of the module.
@@ -702,20 +710,13 @@ pub(crate) fn differentiate(
702710
})),
703711
};
704712

705-
// Before dumping the module, we also might want to add dummy functions, which will
706-
// trigger the LLVMEnzyme pass to run on them, if we invoke the opt binary.
707-
// This is super helpfull if we want to create a MWE bug reproducer, e.g. to run in
708-
// Enzyme's compiler explorer.
709-
if ad.contains(&AutoDiff::OPT2) {
710-
dbg!("Enable extra debug helper to debug Enzyme through the opt plugin");
711-
crate::builder::add_opt_dbg_helper2(
712-
llmod,
713-
llcx,
714-
fn_def,
715-
fn_target,
716-
item.attrs.clone(),
717-
);
718-
}
713+
crate::builder::add_opt_dbg_helper2(
714+
llmod,
715+
llcx,
716+
fn_def,
717+
fn_target,
718+
item.attrs.clone(),
719+
);
719720
}
720721

721722
if ad.contains(&AutoDiff::PrintModBefore) || ad.contains(&AutoDiff::OPT) {
@@ -725,36 +726,17 @@ pub(crate) fn differentiate(
725726
}
726727

727728
if ad.contains(&AutoDiff::Inline) {
728-
dbg!("Setting inline to true");
729-
//llvm::set_inline(true);
730-
todo!();
731-
}
732-
733-
if ad.contains(&AutoDiff::RuntimeActivity) {
734-
dbg!("Setting runtime activity check to true");
735-
//llvm::set_runtime_activity_check(true);
736-
todo!();
737-
}
738-
739-
for val in ad {
740-
match &val {
741-
AutoDiff::TTDepth(depth) => {
742-
assert!(*depth >= 1);
743-
//llvm::set_max_int_offset(*depth);
744-
todo!();
745-
}
746-
AutoDiff::TTWidth(width) => {
747-
assert!(*width >= 1);
748-
todo!();
749-
//llvm::set_max_type_offset(*width);
750-
}
751-
_ => {}
729+
trace!("Setting Enzyme inline to true");
730+
//extern "C" {
731+
// static mut EnzymeInline: c_void;
732+
//}
733+
#[allow(non_upper_case_globals)]
734+
static mut EnzymeInline: c_int = 0;
735+
unsafe {
736+
EnzymeSetCLBool(std::ptr::addr_of_mut!(EnzymeInline), true as u8);
752737
}
753738
}
754739

755-
let differentiate = !diff_items.is_empty();
756-
let _fnc_opt = ad.contains(&AutoDiff::EnableFncOpt);
757-
758740
unsafe {
759741
let mut f = LLVMGetFirstFunction(llmod);
760742
loop {
@@ -787,9 +769,6 @@ pub(crate) fn differentiate(
787769
}
788770
}
789771

790-
//if ad.contains(&AutoDiff::NoModOptAfter) || !differentiate {
791-
// trace!("Skipping module optimization after automatic differentiation");
792-
//} else {
793772
if let Some(opt_level) = config.opt_level {
794773
let opt_stage = match cgcx.lto {
795774
Lto::Fat => llvm::OptStage::PreLinkFatLTO,

compiler/rustc_codegen_llvm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ use rustc_codegen_ssa::back::write::{
3737
};
3838
use rustc_codegen_ssa::traits::*;
3939
use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen};
40-
use rustc_data_structures::fx::{FxHashMap, FxIndexMap};
40+
use rustc_data_structures::fx::FxIndexMap;
4141
use rustc_errors::{DiagCtxtHandle, ErrorGuaranteed, FatalError};
4242
use rustc_metadata::EncodedMetadata;
4343
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};

compiler/rustc_codegen_ssa/src/back/lto.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use std::ffi::CString;
22
use std::sync::Arc;
33

44
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
5-
use rustc_data_structures::fx::FxHashMap;
65
use rustc_data_structures::memmap::Mmap;
76
use rustc_errors::FatalError;
87

compiler/rustc_codegen_ssa/src/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1613,7 +1613,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
16131613
}
16141614
}
16151615

1616-
Message::CodegenDone { mut llvm_work_item, cost } => {
1616+
Message::CodegenDone { llvm_work_item, cost } => {
16171617
// We keep the queue sorted by estimated processing cost,
16181618
// so that more expensive items are processed earlier. This
16191619
// is good for throughput as it gives the main thread more

compiler/rustc_codegen_ssa/src/traits/builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use std::assert_matches::assert_matches;
22
use std::ops::Deref;
33

4-
use rustc_ast::expand::typetree::FncTree;
54
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrs;
65
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
76
use rustc_middle::ty::{Instance, Ty};

compiler/rustc_codegen_ssa/src/traits/write.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_ast::expand::autodiff_attrs::AutoDiffItem;
2-
use rustc_data_structures::fx::FxHashMap;
32
use rustc_errors::{DiagCtxtHandle, FatalError};
43
use rustc_middle::dep_graph::WorkProduct;
54

0 commit comments

Comments
 (0)