Implement callback invoking on the NewPM API#524
Open
gbaraldi wants to merge 2 commits intoJuliaLLVM:masterfrom
Open
Implement callback invoking on the NewPM API#524gbaraldi wants to merge 2 commits intoJuliaLLVM:masterfrom
gbaraldi wants to merge 2 commits intoJuliaLLVM:masterfrom
Conversation
Contributor
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/deps/build_local.jl b/deps/build_local.jl
index 1f15f8be..09d378f4 100644
--- a/deps/build_local.jl
+++ b/deps/build_local.jl
@@ -47,7 +47,7 @@ LLVM_DIR = joinpath(LLVM.artifact_dir, "lib", "cmake", "llvm")
# build and install
@info "Building" source_dir scratch_dir build_dir LLVM_DIR
-cmake(adjust_LIBPATH=!Sys.iswindows()) do cmake_path
+cmake(adjust_LIBPATH = !Sys.iswindows()) do cmake_path
config_opts = `-DLLVM_ROOT=$(LLVM_DIR) -DCMAKE_INSTALL_PREFIX=$(scratch_dir)`
if Sys.iswindows()
# prevent picking up MSVC
diff --git a/src/newpm.jl b/src/newpm.jl
index 56279d51..0609693f 100644
--- a/src/newpm.jl
+++ b/src/newpm.jl
@@ -516,26 +516,26 @@ function InternalizePass(; preserved_gvs::Vector=String[], kwargs...)
end
# Module callbacks (not part of general pass sweep)
export PipelineStartCallbacks, PipelineEarlySimplificationCallbacks,
- OptimizerEarlyCallbacks, OptimizerLastCallbacks
-function PipelineStartCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+ OptimizerEarlyCallbacks, OptimizerLastCallbacks
+function PipelineStartCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
- "pipeline-start-callbacks" * kwargs_to_params(opts)
+ return "pipeline-start-callbacks" * kwargs_to_params(opts)
end
-function PipelineEarlySimplificationCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+function PipelineEarlySimplificationCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
- "pipeline-early-simplification-callbacks" * kwargs_to_params(opts)
+ return "pipeline-early-simplification-callbacks" * kwargs_to_params(opts)
end
-function OptimizerEarlyCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+function OptimizerEarlyCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
- "optimizer-early-callbacks" * kwargs_to_params(opts)
+ return "optimizer-early-callbacks" * kwargs_to_params(opts)
end
-function OptimizerLastCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+function OptimizerLastCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
- "optimizer-last-callbacks" * kwargs_to_params(opts)
+ return "optimizer-last-callbacks" * kwargs_to_params(opts)
end
# CGSCC passes
@@ -551,10 +551,10 @@ end
#CGSCC callbacks (not part of general pass sweep)
export CGSCCOptimizerLateCallbacks
-function CGSCCOptimizerLateCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+function CGSCCOptimizerLateCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
- "cgscc-optimizer-late-callbacks" * kwargs_to_params(opts)
+ return "cgscc-optimizer-late-callbacks" * kwargs_to_params(opts)
end
# function passes
@@ -742,25 +742,25 @@ end
# Function pass callbacks (not part of general pass sweep)
export PeepholeCallbacks, ScalarOptimizerLateCallbacks, VectorizerStartCallbacks
-function PeepholeCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+function PeepholeCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
- "peephole-callbacks" * kwargs_to_params(opts)
+ return "peephole-callbacks" * kwargs_to_params(opts)
end
-function ScalarOptimizerLateCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+function ScalarOptimizerLateCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
- "scalar-optimizer-late-callbacks" * kwargs_to_params(opts)
+ return "scalar-optimizer-late-callbacks" * kwargs_to_params(opts)
end
-function VectorizerStartCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+function VectorizerStartCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
- "vectorizer-start-callbacks" * kwargs_to_params(opts)
+ return "vectorizer-start-callbacks" * kwargs_to_params(opts)
end
@static if version() >= v"21"
export VectorizerEndCallbacks
- function VectorizerEndCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+ function VectorizerEndCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
"vectorizer-end-callbacks" * kwargs_to_params(opts)
end
@@ -804,15 +804,15 @@ end
# Loop Callbacks (not part of general pass sweep)
export LateLoopOptimizationsCallbacks, LoopOptimizerEndCallbacks
-function LateLoopOptimizationsCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+function LateLoopOptimizationsCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
- "late-loop-optimizations-callbacks" * kwargs_to_params(opts)
+ return "late-loop-optimizations-callbacks" * kwargs_to_params(opts)
end
-function LoopOptimizerEndCallbacks(; opt_level=0)
- opts = Dict{Symbol,Any}()
+function LoopOptimizerEndCallbacks(; opt_level = 0)
+ opts = Dict{Symbol, Any}()
opts[Symbol("O$opt_level")] = true
- "loop-optimizer-end-callbacks" * kwargs_to_params(opts)
+ return "loop-optimizer-end-callbacks" * kwargs_to_params(opts)
end
diff --git a/test/newpm.jl b/test/newpm.jl
index ae5d6469..c76f0adf 100644
--- a/test/newpm.jl
+++ b/test/newpm.jl
@@ -195,12 +195,12 @@ end
end
@testset "loop" begin
- # skip opt-level callback pseudo-passes, they require parameters and are provided as functions
- skip_loop = [
- "late-loop-optimizations-callbacks",
- "loop-optimizer-end-callbacks",
- ]
- test_passes("loop", LLVM.loop_passes, skip_loop)
+ # skip opt-level callback pseudo-passes, they require parameters and are provided as functions
+ skip_loop = [
+ "late-loop-optimizations-callbacks",
+ "loop-optimizer-end-callbacks",
+ ]
+ test_passes("loop", LLVM.loop_passes, skip_loop)
end
end
@@ -414,31 +414,31 @@ end
end
end
-@testset "callbacks" begin
- # just check that the callbacks can be registered and run without errors
- @dispose ctx=Context() begin
- # module callbacks
- @dispose pb=NewPMPassBuilder() mod=test_module() begin
- @test run!("pipeline-start-callbacks<O0>", mod) === nothing
- end
- @dispose pb=NewPMPassBuilder() mod=test_module() begin
- @test run!(PipelineStartCallbacks(opt_level=0), mod) === nothing
- end
- # CGSCC callback
- @dispose pb=NewPMPassBuilder() mod=test_module() begin
- @test run!("cgscc-optimizer-late-callbacks<O0>", mod) === nothing
- end
- @dispose pb=NewPMPassBuilder() mod=test_module() begin
- @test run!(CGSCCOptimizerLateCallbacks(opt_level=0), mod) === nothing
- end
- # function callbacks
- @dispose pb=NewPMPassBuilder() mod=test_module() begin
- @test run!("peephole-callbacks<O0>", mod) === nothing
- end
- @dispose pb=NewPMPassBuilder() mod=test_module() begin
- @test run!(PeepholeCallbacks(opt_level=0), mod) === nothing
+ @testset "callbacks" begin
+ # just check that the callbacks can be registered and run without errors
+ @dispose ctx = Context() begin
+ # module callbacks
+ @dispose pb = NewPMPassBuilder() mod = test_module() begin
+ @test run!("pipeline-start-callbacks<O0>", mod) === nothing
+ end
+ @dispose pb = NewPMPassBuilder() mod = test_module() begin
+ @test run!(PipelineStartCallbacks(opt_level = 0), mod) === nothing
+ end
+ # CGSCC callback
+ @dispose pb = NewPMPassBuilder() mod = test_module() begin
+ @test run!("cgscc-optimizer-late-callbacks<O0>", mod) === nothing
+ end
+ @dispose pb = NewPMPassBuilder() mod = test_module() begin
+ @test run!(CGSCCOptimizerLateCallbacks(opt_level = 0), mod) === nothing
+ end
+ # function callbacks
+ @dispose pb = NewPMPassBuilder() mod = test_module() begin
+ @test run!("peephole-callbacks<O0>", mod) === nothing
+ end
+ @dispose pb = NewPMPassBuilder() mod = test_module() begin
+ @test run!(PeepholeCallbacks(opt_level = 0), mod) === nothing
+ end
end
end
-end
end |
Collaborator
|
Would it make sense to open a PR upstream and ask for feedback? |
Contributor
Author
|
I think so. But we also need this here anyway. |
Collaborator
|
Sure, but before we commit to the API. Maybe we get lucky with a quick review ;) |
Collaborator
|
Bump since this is now on LLVM main? |
vchuravy
approved these changes
Sep 29, 2025
maleadt
reviewed
Oct 9, 2025
| end | ||
|
|
||
| @testset "callbacks" begin | ||
| # just check that the callbacks can be registered and run without errors |
Member
There was a problem hiding this comment.
What about testing that the callbacks actually fire?
Member
There was a problem hiding this comment.
I'm not sure the callbacks run?
@dispose pb=NewPMPassBuilder(debug_logging=true) mod=test_module() begin
add!(pb, "pipeline-start-callbacks<O3>")
add!(pb, "pipeline-early-simplification-callbacks<O3>")
run!(pb, mod)
endThis results in empty output...
maleadt
reviewed
Oct 14, 2025
| # just check that the callbacks can be registered and run without errors | ||
| @dispose ctx=Context() begin | ||
| # module callbacks | ||
| @dispose pb=NewPMPassBuilder() mod=test_module() begin |
Member
There was a problem hiding this comment.
The pass builders are unused here.
Member
|
Should any of this be gated against LLVM < 22? |
Contributor
Author
|
Yeah, I think that's when the upstream version will land |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We can change the names here but I've tested that this works (maybe we could register a callback and see if it gets invoked?)