1
Fork 0

fix non-enzyme builds

This commit is contained in:
Manuel Drehwald 2025-02-07 22:27:46 -05:00
parent a6e55271fb
commit 21d096184e
3 changed files with 14 additions and 8 deletions

View file

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

View file

@ -2346,6 +2346,7 @@ unsafe extern "C" {
LoopVectorize: bool, LoopVectorize: bool,
DisableSimplifyLibCalls: bool, DisableSimplifyLibCalls: bool,
EmitLifetimeMarkers: bool, EmitLifetimeMarkers: bool,
RunEnzyme: bool,
SanitizerOptions: Option<&SanitizerOptions>, SanitizerOptions: Option<&SanitizerOptions>,
PGOGenPath: *const c_char, PGOGenPath: *const c_char,
PGOUsePath: *const c_char, PGOUsePath: *const c_char,

View file

@ -688,7 +688,8 @@ struct LLVMRustSanitizerOptions {
bool SanitizeKernelAddressRecover; bool SanitizeKernelAddressRecover;
}; };
extern "C" void registerEnzyme(llvm::PassBuilder &PB); // This symbol won't be available or used when Enzyme is not enabled
extern "C" void registerEnzyme(llvm::PassBuilder &PB) __attribute__((weak));
extern "C" LLVMRustResult LLVMRustOptimize( extern "C" LLVMRustResult LLVMRustOptimize(
LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef, LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef,
@ -696,7 +697,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
bool IsLinkerPluginLTO, bool NoPrepopulatePasses, bool VerifyIR, bool IsLinkerPluginLTO, bool NoPrepopulatePasses, bool VerifyIR,
bool LintIR, bool UseThinLTOBuffers, bool MergeFunctions, bool UnrollLoops, bool LintIR, bool UseThinLTOBuffers, bool MergeFunctions, bool UnrollLoops,
bool SLPVectorize, bool LoopVectorize, bool DisableSimplifyLibCalls, bool SLPVectorize, bool LoopVectorize, bool DisableSimplifyLibCalls,
bool EmitLifetimeMarkers, LLVMRustSanitizerOptions *SanitizerOptions, bool EmitLifetimeMarkers, bool RunEnzyme, LLVMRustSanitizerOptions *SanitizerOptions,
const char *PGOGenPath, const char *PGOUsePath, bool InstrumentCoverage, const char *PGOGenPath, const char *PGOUsePath, bool InstrumentCoverage,
const char *InstrProfileOutput, const char *PGOSampleUsePath, const char *InstrProfileOutput, const char *PGOSampleUsePath,
bool DebugInfoForProfiling, void *LlvmSelfProfiler, bool DebugInfoForProfiling, void *LlvmSelfProfiler,
@ -1013,12 +1014,14 @@ extern "C" LLVMRustResult LLVMRustOptimize(
} }
// now load "-enzyme" pass: // now load "-enzyme" pass:
if (RunEnzyme) {
registerEnzyme(PB); registerEnzyme(PB);
if (auto Err = PB.parsePassPipeline(MPM, "enzyme")) { if (auto Err = PB.parsePassPipeline(MPM, "enzyme")) {
std::string ErrMsg = toString(std::move(Err)); std::string ErrMsg = toString(std::move(Err));
LLVMRustSetLastError(ErrMsg.c_str()); LLVMRustSetLastError(ErrMsg.c_str());
return LLVMRustResult::Failure; return LLVMRustResult::Failure;
} }
}
// Upgrade all calls to old intrinsics first. // Upgrade all calls to old intrinsics first.
for (Module::iterator I = TheModule->begin(), E = TheModule->end(); I != E;) for (Module::iterator I = TheModule->begin(), E = TheModule->end(); I != E;)