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

@ -688,7 +688,8 @@ struct LLVMRustSanitizerOptions {
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(
LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef,
@ -696,7 +697,7 @@ extern "C" LLVMRustResult LLVMRustOptimize(
bool IsLinkerPluginLTO, bool NoPrepopulatePasses, bool VerifyIR,
bool LintIR, bool UseThinLTOBuffers, bool MergeFunctions, bool UnrollLoops,
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 *InstrProfileOutput, const char *PGOSampleUsePath,
bool DebugInfoForProfiling, void *LlvmSelfProfiler,
@ -1013,11 +1014,13 @@ extern "C" LLVMRustResult LLVMRustOptimize(
}
// now load "-enzyme" pass:
registerEnzyme(PB);
if (auto Err = PB.parsePassPipeline(MPM, "enzyme")) {
std::string ErrMsg = toString(std::move(Err));
LLVMRustSetLastError(ErrMsg.c_str());
return LLVMRustResult::Failure;
if (RunEnzyme) {
registerEnzyme(PB);
if (auto Err = PB.parsePassPipeline(MPM, "enzyme")) {
std::string ErrMsg = toString(std::move(Err));
LLVMRustSetLastError(ErrMsg.c_str());
return LLVMRustResult::Failure;
}
}
// Upgrade all calls to old intrinsics first.