Skip to content

Commit cfd7f24

Browse files
authored
Merge pull request #214 from maleadt/vc/jlpasses
Add new Julia passes and the C-binding for dce!
2 parents 827cffa + 5e15809 commit cfd7f24

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

lib/libLLVM_extra.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,24 @@ function LLVMAddRemoveJuliaAddrspacesPass(PM)
168168
end
169169
end
170170

171+
if VERSION >= v"1.6.0-DEV.1215"
172+
function LLVMAddDemoteFloat16Pass(PM)
173+
ccall(:LLVMExtraAddDemoteFloat16Pass,Cvoid,(LLVMPassManagerRef,), PM)
174+
end
175+
end
176+
177+
if VERSION >= v"1.6.0-DEV.1476"
178+
function LLVMAddRemoveNIPass(PM)
179+
ccall(:LLVMExtraAddRemoveNIPass,Cvoid,(LLVMPassManagerRef,), PM)
180+
end
181+
end
182+
183+
if VERSION >= v"1.6.0-DEV.1477"
184+
function LLVMAddJuliaLICMPass(PM)
185+
ccall(:LLVMExtraJuliaLICMPass,Cvoid,(LLVMPassManagerRef,), PM)
186+
end
187+
end
188+
171189
function LLVMGetValueContext(V)
172190
ccall(:LLVMExtraGetValueContext,LLVMContextRef,(LLVMValueRef,),V)
173191
end

lib/libLLVM_h.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4599,6 +4599,11 @@ function LLVMAddAggressiveDCEPass(PM)
45994599
@runtime_ccall((:LLVMAddAggressiveDCEPass,libllvm[]), Cvoid, (LLVMPassManagerRef,), PM)
46004600
end
46014601

4602+
# added in LLVM10
4603+
function LLVMAddDCEPass(PM)
4604+
@runtime_ccall((:LLVMAddDCEPass,libllvm[]), Cvoid, (LLVMPassManagerRef,), PM)
4605+
end
4606+
46024607
function LLVMAddBitTrackingDCEPass(PM)
46034608
@runtime_ccall((:LLVMAddBitTrackingDCEPass,libllvm[]), Cvoid, (LLVMPassManagerRef,), PM)
46044609
end

src/interop/passes.jl

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export alloc_opt!, barrier_noop!, gc_invariant_verifier!, lower_exc_handlers!,
22
combine_mul_add!, multi_versioning!, propagate_julia_addrsp!, lower_ptls!,
3-
lower_simdloop!, late_lower_gc_frame!, final_lower_gc!, remove_julia_addrspaces!
3+
lower_simdloop!, late_lower_gc_frame!, final_lower_gc!, remove_julia_addrspaces!,
4+
demote_float16!, remove_ni!, julia_licm!
45

56
alloc_opt!(pm::PassManager) =
67
API.LLVMAddAllocOptPass(pm)
@@ -44,3 +45,21 @@ if VERSION >= v"1.5.0-DEV.802"
4445
else
4546
remove_julia_addrspaces!(pm::PassManager) = nothing
4647
end
48+
49+
if VERSION >= v"1.6.0-DEV.1215"
50+
demote_float16!(pm::PassManager) = API.LLVMAddDemoteFloat16Pass(pm)
51+
else
52+
demote_float16!(pm::PassManager) = nothing
53+
end
54+
55+
if VERSION >= v"1.6.0-DEV.1476"
56+
remove_ni!(pm::PassManager) = API.LLVMAddRemoveNIPass(pm)
57+
else
58+
remove_ni!(pm::PassManager) = nothing # Could implement this in pure Julia if necessary
59+
end
60+
61+
if VERSION >= v"1.6.0-DEV.1477"
62+
julia_licm!(pm::PassManager) = API.LLVMAddJuliaLICMPass(pm)
63+
else
64+
julia_licm!(pm::PassManager) = nothing
65+
end

src/transform.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,20 @@ define_transforms([
101101
:LowerExpectIntrinsic, :TypeBasedAliasAnalysis, :ScopedNoAliasAA, :BasicAliasAnalysis
102102
])
103103

104-
export scalar_repl_aggregates!, scalar_repl_aggregates_ssa!
104+
export scalar_repl_aggregates!, scalar_repl_aggregates_ssa!, dce!
105105

106106
scalar_repl_aggregates!(pm::PassManager, threshold::Integer) =
107107
API.LLVMAddScalarReplAggregatesPassWithThreshold(pm, Cint(threshold))
108108

109109
scalar_repl_aggregates_ssa!(pm::PassManager) =
110110
API.LLVMAddScalarReplAggregatesPassSSA(pm)
111111

112+
if version() >= v"10.0"
113+
dce!(pm::PassManager) =
114+
API.LLVMAddDCEPass(pm)
115+
else
116+
dce!(pm::PassManager) = nothing
117+
end
112118

113119
## vectorization transformations
114120

test/interop.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,8 @@ Context() do ctx
116116
LLVM.Module("SomeModule", ctx) do mod
117117
ModulePassManager() do pm
118118

119+
demote_float16!(pm)
120+
julia_licm!(pm)
119121
alloc_opt!(pm)
120122
barrier_noop!(pm)
121123
gc_invariant_verifier!(pm)
@@ -127,6 +129,7 @@ propagate_julia_addrsp!(pm)
127129
lower_ptls!(pm)
128130
lower_ptls!(pm, true)
129131
lower_simdloop!(pm)
132+
remove_ni!(pm)
130133
late_lower_gc_frame!(pm)
131134
final_lower_gc!(pm)
132135

test/transform.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Context() do ctx
3030
LLVM.Module("SomeModule", ctx) do mod
3131
ModulePassManager() do pm
3232
aggressive_dce!(pm)
33+
dce!(pm)
3334
bit_tracking_dce!(pm)
3435
alignment_from_assumptions!(pm)
3536
cfgsimplification!(pm)

0 commit comments

Comments
 (0)