Skip to content

Commit 10ad22a

Browse files
authored
Merge pull request #215 from maleadt/vc/passes
Add passes exported from Julia
2 parents cfd7f24 + b574954 commit 10ad22a

File tree

3 files changed

+61
-11
lines changed

3 files changed

+61
-11
lines changed

lib/libLLVM_extra.jl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,42 @@ function LLVMAddJuliaLICMPass(PM)
186186
end
187187
end
188188

189+
if VERSION >= v"1.6.0-DEV.1503"
190+
function LLVMAddDivRemPairsPass(PM)
191+
ccall(:LLVMExtraAddDivRemPairsPass,Cvoid,(LLVMPassManagerRef,), PM)
192+
end
193+
end
194+
195+
if VERSION >= v"1.6.0-DEV.1503"
196+
function LLVMAddLoopDistributePass(PM)
197+
ccall(:LLVMExtraAddLoopDistributePass,Cvoid,(LLVMPassManagerRef,), PM)
198+
end
199+
end
200+
201+
if VERSION >= v"1.6.0-DEV.1503"
202+
function LLVMAddLoopFusePass(PM)
203+
ccall(:LLVMExtraAddLoopFusePass,Cvoid,(LLVMPassManagerRef,), PM)
204+
end
205+
end
206+
207+
if VERSION >= v"1.6.0-DEV.1503"
208+
function LLVMAddLoopLoadEliminationPass(PM)
209+
ccall(:LLVMExtraLoopLoadEliminationPass,Cvoid,(LLVMPassManagerRef,), PM)
210+
end
211+
end
212+
213+
if VERSION >= v"1.6.0-DEV.1503"
214+
function LLVMAddLoadStoreVectorizerPass(PM)
215+
ccall(:LLVMExtraAddLoadStoreVectorizerPass,Cvoid,(LLVMPassManagerRef,), PM)
216+
end
217+
end
218+
219+
if VERSION >= v"1.6.0-DEV.1503"
220+
function LLVMAddInstSimplifyPass(PM)
221+
ccall(:LLVMExtraAddInstructionSimplifyPass,Cvoid,(LLVMPassManagerRef,), PM)
222+
end
223+
end
224+
189225
function LLVMGetValueContext(V)
190226
ccall(:LLVMExtraGetValueContext,LLVMContextRef,(LLVMValueRef,),V)
191227
end

src/transform.jl

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ populate!(mpm::ModulePassManager, pmb::PassManagerBuilder) =
5353

5454
## auxiliary
5555

56-
function define_transforms(transforms)
56+
function define_transforms(transforms, available=true)
5757
for transform in transforms
5858
api_fname = Symbol(:LLVM, :Add, transform, :Pass)
5959

@@ -78,9 +78,16 @@ function define_transforms(transforms)
7878
end
7979
jl_fname = Symbol(join(lowercase.(groups), '_'), '!')
8080

81-
@eval begin
82-
export $jl_fname
83-
$jl_fname(pm::PassManager) = API.$api_fname(pm)
81+
if available
82+
@eval begin
83+
export $jl_fname
84+
$jl_fname(pm::PassManager) = API.$api_fname(pm)
85+
end
86+
else
87+
@eval begin
88+
export $jl_fname
89+
$jl_fname(pm::PassManager) = nothing
90+
end
8491
end
8592
end
8693

@@ -101,27 +108,27 @@ define_transforms([
101108
:LowerExpectIntrinsic, :TypeBasedAliasAnalysis, :ScopedNoAliasAA, :BasicAliasAnalysis
102109
])
103110

104-
export scalar_repl_aggregates!, scalar_repl_aggregates_ssa!, dce!
111+
export scalar_repl_aggregates!, scalar_repl_aggregates_ssa!
105112

106113
scalar_repl_aggregates!(pm::PassManager, threshold::Integer) =
107114
API.LLVMAddScalarReplAggregatesPassWithThreshold(pm, Cint(threshold))
108115

109116
scalar_repl_aggregates_ssa!(pm::PassManager) =
110117
API.LLVMAddScalarReplAggregatesPassSSA(pm)
111118

112-
if version() >= v"10.0"
113-
dce!(pm::PassManager) =
114-
API.LLVMAddDCEPass(pm)
115-
else
116-
dce!(pm::PassManager) = nothing
117-
end
119+
define_transforms([:DCE], version() >= v"10.0")
120+
121+
define_transforms([
122+
:DivRemPairs, :LoopDistribute, :LoopFuse, :LoopLoadElimination, :InstSimplify
123+
], VERSION >= v"1.6.0-DEV.1503")
118124

119125
## vectorization transformations
120126

121127
define_transforms([
122128
:LoopVectorize, :SLPVectorize
123129
])
124130

131+
define_transforms([:LoadStoreVectorizer], VERSION >= v"1.6.0-DEV.1503")
125132

126133
## interprocedural transformations
127134

test/transform.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@ ModulePassManager() do pm
3838
scalarizer!(pm)
3939
merged_load_store_motion!(pm)
4040
gvn!(pm)
41+
div_rem_pairs!(pm)
4142
ind_var_simplify!(pm)
4243
instruction_combining!(pm)
44+
inst_simplify!(pm)
4345
jump_threading!(pm)
4446
licm!(pm)
4547
loop_deletion!(pm)
@@ -48,7 +50,11 @@ ModulePassManager() do pm
4850
loop_reroll!(pm)
4951
loop_unroll!(pm)
5052
loop_unswitch!(pm)
53+
loop_distribute!(pm)
54+
loop_fuse!(pm)
55+
loop_load_elimination!(pm)
5156
mem_cpy_opt!(pm)
57+
5258
partially_inline_lib_calls!(pm)
5359
lower_switch!(pm)
5460
promote_memory_to_register!(pm)
@@ -71,6 +77,7 @@ ModulePassManager() do pm
7177

7278
loop_vectorize!(pm)
7379
slpvectorize!(pm)
80+
load_store_vectorizer!(pm)
7481

7582
argument_promotion!(pm)
7683
constant_merge!(pm)

0 commit comments

Comments
 (0)