Skip to content

Commit

Permalink
Version-gate usage of LLVM.PassBuilder
Browse files Browse the repository at this point in the history
The newPM is not available until Julia 1.10. Unfortunately, this does
mean that we use a slightly different pipeline for Julia 1.9, but at
least it gets things working for now.
  • Loading branch information
topolarity committed Oct 4, 2023
1 parent 039c9cc commit 164074d
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions src/AllocCheck.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,21 +105,25 @@ function backtrace_(inst::LLVM.Instruction, bt=StackTraces.StackFrame[]; compile
return bt
end

function build_newpm_pipeline!(pb::PassBuilder, mpm::NewPMModulePassManager, speedup=2, size=0, lower_intrinsic=true,
dump_native=false, external_use=false, llvm_only=false,)
ccall(:jl_build_newpm_pipeline, Cvoid, (LLVM.API.LLVMModulePassManagerRef, LLVM.API.LLVMPassBuilderRef, Cint, Cint, Cint, Cint, Cint, Cint),
mpm, pb, speedup, size, lower_intrinsic, dump_native, external_use, llvm_only)
end
if LLVM.has_newpm() && VERSION >= v"1.10.0-DEV.1622"
function build_newpm_pipeline!(pb::PassBuilder, mpm::NewPMModulePassManager, speedup=2, size=0, lower_intrinsic=true,
dump_native=false, external_use=false, llvm_only=false,)
ccall(:jl_build_newpm_pipeline, Cvoid, (LLVM.API.LLVMModulePassManagerRef, LLVM.API.LLVMPassBuilderRef, Cint, Cint, Cint, Cint, Cint, Cint),
mpm, pb, speedup, size, lower_intrinsic, dump_native, external_use, llvm_only)
end

function optimize!(@nospecialize(job::CompilerJob), mod::LLVM.Module)
triple = GPUCompiler.llvm_triple(job.config.target)
tm = GPUCompiler.llvm_machine(job.config.target)
@dispose pb = LLVM.PassBuilder(tm) begin
@dispose mpm = LLVM.NewPMModulePassManager(pb) begin
build_newpm_pipeline!(pb, mpm)
run!(mpm, mod, tm)
function optimize!(@nospecialize(job::CompilerJob), mod::LLVM.Module)
triple = GPUCompiler.llvm_triple(job.config.target)
tm = GPUCompiler.llvm_machine(job.config.target)
@dispose pb = LLVM.PassBuilder(tm) begin
@dispose mpm = LLVM.NewPMModulePassManager(pb) begin
build_newpm_pipeline!(pb, mpm)
run!(mpm, mod, tm)
end
end
end
else
optimize!(@nospecialize(job::CompilerJob), mod::LLVM.Module) = GPUCompiler.compile(:llvm, job, validate=false)
end

struct AllocInstance
Expand Down

0 comments on commit 164074d

Please sign in to comment.