Skip to content

Commit 21d0961

Browse files
committed
fix non-enzyme builds
1 parent a6e5527 commit 21d0961

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

Diff for: compiler/rustc_codegen_llvm/src/back/write.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,12 @@ pub(crate) unsafe fn llvm_optimize(
551551
let vectorize_slp;
552552
let vectorize_loop;
553553

554+
let run_enzyme = cfg!(llvm_enzyme);
554555
// When we build rustc with enzyme/autodiff support, we want to postpone size-increasing
555556
// optimizations until after differentiation. FIXME(ZuseZ4): Before shipping on nightly,
556557
// we should make this more granular, or at least check that the user has at least one autodiff
557558
// call in their code, to justify altering the compilation pipeline.
558-
if skip_size_increasing_opts && cfg!(llvm_enzyme) {
559+
if skip_size_increasing_opts && run_enzyme {
559560
unroll_loops = false;
560561
vectorize_slp = false;
561562
vectorize_loop = false;
@@ -633,6 +634,7 @@ pub(crate) unsafe fn llvm_optimize(
633634
vectorize_loop,
634635
config.no_builtins,
635636
config.emit_lifetime_markers,
637+
run_enzyme,
636638
sanitizer_options.as_ref(),
637639
pgo_gen_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),
638640
pgo_use_path.as_ref().map_or(std::ptr::null(), |s| s.as_ptr()),

Diff for: compiler/rustc_codegen_llvm/src/llvm/ffi.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2346,6 +2346,7 @@ unsafe extern "C" {
23462346
LoopVectorize: bool,
23472347
DisableSimplifyLibCalls: bool,
23482348
EmitLifetimeMarkers: bool,
2349+
RunEnzyme: bool,
23492350
SanitizerOptions: Option<&SanitizerOptions>,
23502351
PGOGenPath: *const c_char,
23512352
PGOUsePath: *const c_char,

Diff for: compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp

+10-7
Original file line numberDiff line numberDiff line change
@@ -688,15 +688,16 @@ struct LLVMRustSanitizerOptions {
688688
bool SanitizeKernelAddressRecover;
689689
};
690690

691-
extern "C" void registerEnzyme(llvm::PassBuilder &PB);
691+
// This symbol won't be available or used when Enzyme is not enabled
692+
extern "C" void registerEnzyme(llvm::PassBuilder &PB) __attribute__((weak));
692693

693694
extern "C" LLVMRustResult LLVMRustOptimize(
694695
LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef,
695696
LLVMRustPassBuilderOptLevel OptLevelRust, LLVMRustOptStage OptStage,
696697
bool IsLinkerPluginLTO, bool NoPrepopulatePasses, bool VerifyIR,
697698
bool LintIR, bool UseThinLTOBuffers, bool MergeFunctions, bool UnrollLoops,
698699
bool SLPVectorize, bool LoopVectorize, bool DisableSimplifyLibCalls,
699-
bool EmitLifetimeMarkers, LLVMRustSanitizerOptions *SanitizerOptions,
700+
bool EmitLifetimeMarkers, bool RunEnzyme, LLVMRustSanitizerOptions *SanitizerOptions,
700701
const char *PGOGenPath, const char *PGOUsePath, bool InstrumentCoverage,
701702
const char *InstrProfileOutput, const char *PGOSampleUsePath,
702703
bool DebugInfoForProfiling, void *LlvmSelfProfiler,
@@ -1013,11 +1014,13 @@ extern "C" LLVMRustResult LLVMRustOptimize(
10131014
}
10141015

10151016
// now load "-enzyme" pass:
1016-
registerEnzyme(PB);
1017-
if (auto Err = PB.parsePassPipeline(MPM, "enzyme")) {
1018-
std::string ErrMsg = toString(std::move(Err));
1019-
LLVMRustSetLastError(ErrMsg.c_str());
1020-
return LLVMRustResult::Failure;
1017+
if (RunEnzyme) {
1018+
registerEnzyme(PB);
1019+
if (auto Err = PB.parsePassPipeline(MPM, "enzyme")) {
1020+
std::string ErrMsg = toString(std::move(Err));
1021+
LLVMRustSetLastError(ErrMsg.c_str());
1022+
return LLVMRustResult::Failure;
1023+
}
10211024
}
10221025

10231026
// Upgrade all calls to old intrinsics first.

0 commit comments

Comments
 (0)