-
Notifications
You must be signed in to change notification settings - Fork 45
Implement callback invoking on the NewPM API #524
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
Open
gbaraldi
wants to merge
3
commits into
JuliaLLVM:master
Choose a base branch
from
gbaraldi:gb/fun
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
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 af429939..3ff8252b 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 |
Would it make sense to open a PR upstream and ask for feedback? |
I think so. But we also need this here anyway. |
Sure, but before we commit to the API. Maybe we get lucky with a quick review ;) |
Bump since this is now on LLVM main? |
vchuravy
approved these changes
Sep 29, 2025
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?)