Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix top of LLVM. #8454

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 29 additions & 14 deletions src/CodeGen_LLVM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,6 @@ void CodeGen_LLVM::optimize_module() {

llvm::PassBuilder pb(tm.get(), pto);

bool debug_pass_manager = false;
// These analysis managers have to be declared in this order.
llvm::LoopAnalysisManager lam;
llvm::FunctionAnalysisManager fam;
Expand All @@ -1154,15 +1153,25 @@ void CodeGen_LLVM::optimize_module() {
// Add a pass that converts lookup tables to relative lookup tables to make them PIC-friendly.
// See https://bugs.llvm.org/show_bug.cgi?id=45244
pb.registerOptimizerLastEPCallback(
[&](ModulePassManager &mpm, OptimizationLevel level) {
#if LLVM_VERSION >= 200
[&](ModulePassManager &mpm, OptimizationLevel, ThinOrFullLTOPhase)
#else
[&](ModulePassManager &mpm, OptimizationLevel)
#endif
{
mpm.addPass(RelLookupTableConverterPass());
});
}
#endif

if (get_target().has_feature(Target::SanitizerCoverage)) {
pb.registerOptimizerLastEPCallback(
[&](ModulePassManager &mpm, OptimizationLevel level) {
#if LLVM_VERSION >= 200
[&](ModulePassManager &mpm, OptimizationLevel, ThinOrFullLTOPhase)
#else
[&](ModulePassManager &mpm, OptimizationLevel)
#endif
{
SanitizerCoverageOptions sanitizercoverage_options;
// Mirror what -fsanitize=fuzzer-no-link would enable.
// See https://github.com/halide/Halide/issues/6528
Expand All @@ -1180,23 +1189,29 @@ void CodeGen_LLVM::optimize_module() {
}

if (get_target().has_feature(Target::ASAN)) {
pb.registerPipelineStartEPCallback([](ModulePassManager &mpm, OptimizationLevel) {
AddressSanitizerOptions asan_options; // default values are good...
asan_options.UseAfterScope = true; // ...except this one
constexpr bool use_global_gc = false;
constexpr bool use_odr_indicator = true;
constexpr auto destructor_kind = AsanDtorKind::Global;
mpm.addPass(AddressSanitizerPass(
asan_options, use_global_gc, use_odr_indicator, destructor_kind));
});
pb.registerPipelineStartEPCallback(
[](ModulePassManager &mpm, OptimizationLevel) {
AddressSanitizerOptions asan_options; // default values are good...
asan_options.UseAfterScope = true; // ...except this one
constexpr bool use_global_gc = false;
constexpr bool use_odr_indicator = true;
constexpr auto destructor_kind = AsanDtorKind::Global;
mpm.addPass(AddressSanitizerPass(
asan_options, use_global_gc, use_odr_indicator, destructor_kind));
});
}

// Target::MSAN handling is sprinkled throughout the codebase,
// there is no need to run MemorySanitizerPass here.

if (get_target().has_feature(Target::TSAN)) {
pb.registerOptimizerLastEPCallback(
[](ModulePassManager &mpm, OptimizationLevel level) {
#if LLVM_VERSION >= 200
[](ModulePassManager &mpm, OptimizationLevel, ThinOrFullLTOPhase)
#else
[](ModulePassManager &mpm, OptimizationLevel)
#endif
{
mpm.addPass(
createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
});
Expand Down Expand Up @@ -1233,7 +1248,7 @@ void CodeGen_LLVM::optimize_module() {
#endif
}

mpm = pb.buildPerModuleDefaultPipeline(level, debug_pass_manager);
mpm = pb.buildPerModuleDefaultPipeline(level);
mpm.run(*module, mam);

if (llvm::verifyModule(*module, &errs())) {
Expand Down
3 changes: 1 addition & 2 deletions src/CodeGen_PTX_Dev.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,6 @@ vector<char> CodeGen_PTX_Dev::compile_to_src() {

llvm::PassBuilder pb(target_machine.get(), pto);

bool debug_pass_manager = false;
// These analysis managers have to be declared in this order.
llvm::LoopAnalysisManager lam;
llvm::FunctionAnalysisManager fam;
Expand All @@ -695,7 +694,7 @@ vector<char> CodeGen_PTX_Dev::compile_to_src() {
target_machine->registerPassBuilderCallbacks(pb);
#endif

mpm = pb.buildPerModuleDefaultPipeline(level, debug_pass_manager);
mpm = pb.buildPerModuleDefaultPipeline(level);
mpm.run(*module, mam);

if (llvm::verifyModule(*module, &errs())) {
Expand Down
Loading