Skip to content

Commit

Permalink
get tests to work without -Z/-C flags
Browse files Browse the repository at this point in the history
  • Loading branch information
ZuseZ4 committed Feb 7, 2025
1 parent 70b9ba3 commit 8f87e80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,8 @@ struct LLVMRustSanitizerOptions {
bool SanitizeKernelAddressRecover;
};

extern "C" void registerEnzyme(llvm::PassBuilder &PB);

extern "C" LLVMRustResult LLVMRustOptimize(
LLVMModuleRef ModuleRef, LLVMTargetMachineRef TMRef,
LLVMRustPassBuilderOptLevel OptLevelRust, LLVMRustOptStage OptStage,
Expand Down Expand Up @@ -1010,6 +1012,14 @@ extern "C" LLVMRustResult LLVMRustOptimize(
MPM.addPass(NameAnonGlobalPass());
}

// 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;
}

// Upgrade all calls to old intrinsics first.
for (Module::iterator I = TheModule->begin(), E = TheModule->end(); I != E;)
UpgradeCallsToIntrinsic(&*I++); // must be post-increment, as we remove
Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/src/core/build_steps/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,9 +1052,9 @@ pub fn rustc_cargo(
// We temporarily disable linking here as part of some refactoring.
// This way, people can manually use -Z llvm-plugins and -C passes=enzyme for now.
// In a follow-up PR, we will re-enable linking here and load the pass for them.
//if builder.config.llvm_enzyme {
// cargo.rustflag("-l").rustflag("Enzyme-19");
//}
if builder.config.llvm_enzyme {
cargo.rustflag("-l").rustflag("Enzyme-19");
}

// Building with protected visibility reduces the number of dynamic relocations needed, giving
// us a faster startup time. However GNU ld < 2.40 will error if we try to link a shared object
Expand Down

0 comments on commit 8f87e80

Please sign in to comment.