@@ -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
693694extern " 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