Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,12 +812,12 @@ extern "C" LLVMRustResult LLVMRustOptimize(
auto ThinLTOBuffer = std::make_unique<LLVMRustThinLTOBuffer>();
raw_string_ostream ThinLTODataOS(ThinLTOBuffer->data);
raw_string_ostream ThinLinkDataOS(ThinLTOBuffer->thin_link_data);
bool IsLTO = OptStage == LLVMRustOptStage::ThinLTO ||
OptStage == LLVMRustOptStage::FatLTO;
if (!NoPrepopulatePasses) {
// The pre-link pipelines don't support O0 and require using
// buildO0DefaultPipeline() instead. At the same time, the LTO pipelines do
// support O0 and using them is required.
bool IsLTO = OptStage == LLVMRustOptStage::ThinLTO ||
OptStage == LLVMRustOptStage::FatLTO;
if (OptLevel == OptimizationLevel::O0 && !IsLTO) {
for (const auto &C : PipelineStartEPCallbacks)
PB.registerPipelineStartEPCallback(C);
Expand Down Expand Up @@ -908,7 +908,10 @@ extern "C" LLVMRustResult LLVMRustOptimize(

// now load "-enzyme" pass:
// With dlopen, ENZYME macro may not be defined, so check EnzymePtr directly
if (EnzymePtr) {
// In the case of debug builds with multiple codegen units, we might not
// have all function definitions available during the early compiler
// invocations. We therefore wait for the final lto step to run Enzyme.
if (EnzymePtr && IsLTO) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could have checked for fat-lto only, since that's what we require atm. But it seems to work atm. and every once in a while I experiment with lowering our requirements from fat to thin lto, so I think it's fine.


if (PrintBeforeEnzyme) {
// Handle the Rust flag `-Zautodiff=PrintModBefore`.
Expand All @@ -929,6 +932,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
MPM.addPass(PrintModulePass(outs(), Banner, true, false));
}
}

if (PrintPasses) {
// Print all passes from the PM:
std::string Pipeline;
Expand Down
8 changes: 6 additions & 2 deletions tests/ui/autodiff/incremental.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//@ revisions: DEBUG RELEASE
//@[RELEASE] compile-flags: -Zautodiff=Enable,NoTT -C opt-level=3 -Clto=fat
//@[DEBUG] compile-flags: -Zautodiff=Enable,NoTT -C opt-level=0 -Clto=fat -C debuginfo=2
//@[DEBUG] compile-flags: -Zautodiff=Enable,NoTT -Copt-level=0 -Clto=fat -Cdebuginfo=2 -Ccodegen-units=8
//@ needs-enzyme
//@ incremental
//@ no-prefer-dynamic
Expand All @@ -13,14 +13,18 @@
// dropped. We now use globals instead and add this test to verify that incremental
// keeps working. Also testing debug mode while at it.

// We extended this test to use 8 codegen-units in debug mode and call an intrinsic like powi,
// rather than just simple arithmetic. This caused a compilation failure, since the definition of
// the intrinsic was not available in the same cgu as the function being differentiated.

use std::autodiff::autodiff_reverse;

#[autodiff_reverse(bar, Duplicated, Duplicated)]
pub fn foo(r: &[f64; 10], res: &mut f64) {
let mut output = [0.0; 10];
output[0] = r[0];
output[1] = r[1] * r[2];
output[2] = r[4] * r[5];
output[2] = r[4] * r[5].powi(2);
output[3] = r[2] * r[6];
output[4] = r[1] * r[7];
output[5] = r[2] * r[8];
Expand Down
Loading