3
3
function optimize! (@nospecialize (job:: CompilerJob ), mod:: LLVM.Module ; opt_level= 1 )
4
4
tm = llvm_machine (job. config. target)
5
5
6
- global current_job
6
+ global current_job # ScopedValue?
7
7
current_job = job
8
8
9
9
@dispose pb= NewPMPassBuilder () begin
@@ -24,6 +24,15 @@ function optimize!(@nospecialize(job::CompilerJob), mod::LLVM.Module; opt_level=
24
24
return
25
25
end
26
26
27
+ # TODO : Priority heap to provide order between different plugins
28
+ const PIPELINE_CALLBACKS = Dict {String, Any} ()
29
+ function register_plugin! (name:: String , plugin)
30
+ if haskey (PIPELINE_CALLBACKS, name)
31
+ error (" GPUCompiler plugin with name $name is already registered" )
32
+ end
33
+ PIPELINE_CALLBACKS[name] = plugin
34
+ end
35
+
27
36
function buildNewPMPipeline! (mpm, @nospecialize (job:: CompilerJob ), opt_level)
28
37
buildEarlySimplificationPipeline (mpm, job, opt_level)
29
38
add! (mpm, AlwaysInlinerPass ())
@@ -41,6 +50,9 @@ function buildNewPMPipeline!(mpm, @nospecialize(job::CompilerJob), opt_level)
41
50
add! (fpm, WarnMissedTransformationsPass ())
42
51
end
43
52
end
53
+ for (name, callback) in PIPELINE_CALLBACKS
54
+ add! (mpm, CallbackPass (name, callback))
55
+ end
44
56
buildIntrinsicLoweringPipeline (mpm, job, opt_level)
45
57
buildCleanupPipeline (mpm, job, opt_level)
46
58
end
@@ -423,3 +435,17 @@ function lower_ptls!(mod::LLVM.Module)
423
435
return changed
424
436
end
425
437
LowerPTLSPass () = NewPMModulePass (" GPULowerPTLS" , lower_ptls!)
438
+
439
+
440
+ function callback_pass! (name, callback:: F , mod:: LLVM.Module ) where F
441
+ job = current_job:: CompilerJob
442
+ changed = false
443
+
444
+ if haskey (functions (mod), name)
445
+ marker = functions (mod)[name]
446
+ changed = callback (job, marker, mod)
447
+ end
448
+ return changed
449
+ end
450
+
451
+ CallbackPass (name, callback) = NewPMModulePass (" CallbackPass<$name >" , (mod)-> callback_pass! (name, callback, mod))
0 commit comments