/
function_pass_manager.cr
50 lines (40 loc) · 1.01 KB
/
function_pass_manager.cr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
{% unless LibLLVM::IS_LT_170 %}
@[Deprecated("The legacy pass manager was removed in LLVM 17. Use `LLVM::PassBuilderOptions` instead")]
{% end %}
class LLVM::FunctionPassManager
def initialize(@unwrap : LibLLVM::PassManagerRef)
end
def run(mod : Module)
changed = false
run do |runner|
mod.functions.each do |func|
changed ||= runner.run(func)
end
end
changed
end
def run(&)
LibLLVM.initialize_function_pass_manager(self)
runner = Runner.new(self)
yield runner
LibLLVM.finalize_function_pass_manager(self)
self
end
def to_unsafe
@unwrap
end
def finalize
LibLLVM.dispose_pass_manager(@unwrap)
end
{% unless LibLLVM::IS_LT_170 %}
@[Deprecated("The legacy pass manager was removed in LLVM 17. Use `LLVM::PassBuilderOptions` instead")]
{% end %}
struct Runner
@fpm : FunctionPassManager
def initialize(@fpm)
end
def run(f : LLVM::Function)
LibLLVM.run_function_pass_manager(@fpm, f) != 0
end
end
end