Skip to content

Commit

Permalink
Fix top of LLVM. (#8454)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcourteaux authored Nov 4, 2024
1 parent 4052dda commit 6ef825c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
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

0 comments on commit 6ef825c

Please sign in to comment.