Skip to content

Commit

Permalink
Add IR dumping (#638)
Browse files Browse the repository at this point in the history
* Add IR dumping

* fix

* fix

* fix

* jll bump

* Update Project.toml
  • Loading branch information
wsmoses authored Jan 30, 2025
1 parent 0feae66 commit 0d3c8df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions ext/ReactantCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,9 @@ function compile(job)
end
entryname = LLVM.name(meta.entry)

if Reactant.Compiler.DUMP_LLVMIR[]
println("cuda.jl immediate IR\n", string(mod))
end
opt_level = 2
tm = GPUCompiler.llvm_machine(job.config.target)
LLVM.@dispose pb = LLVM.NewPMPassBuilder() begin
Expand Down Expand Up @@ -401,6 +404,9 @@ function compile(job)
end
return true
end
if Reactant.Compiler.DUMP_LLVMIR[]
println("cuda.jl postopt IR\n", string(mod))
end
if !isempty(errors)
throw(GPUCompiler.InvalidIRError(job, errors))
end
Expand Down
7 changes: 6 additions & 1 deletion src/Compiler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,11 @@ function optimization_passes(; no_nan::Bool=false, sroa::Bool=false)
passes = ["inline{default-pipeline=canonicalize max-iterations=4}"]
if sroa
push!(passes, "propagate-constant-bounds")
push!(passes, "sroa-wrappers")
if DUMP_LLVMIR[]
push!(passes, "sroa-wrappers{dump_prellvm=true dump_postllvm=true}")
else
push!(passes, "sroa-wrappers")
end
push!(passes, "libdevice-funcs-raise")
push!(passes, "canonicalize")
push!(passes, "remove-duplicate-func-def")
Expand Down Expand Up @@ -428,6 +432,7 @@ function cubinFeatures()
end

const DEBUG_KERNEL = Ref{Bool}(false)
const DUMP_LLVMIR = Ref{Bool}(false)

function compile_mlir!(
mod, f, args; optimize::Union{Bool,Symbol}=true, no_nan::Bool=false, backend="gpu"
Expand Down

0 comments on commit 0d3c8df

Please sign in to comment.