-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Julia newpm passes and pipeline.
- Loading branch information
1 parent
987a230
commit 2a623f6
Showing
14 changed files
with
823 additions
and
119 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import ..LLVM: @module_pass, @function_pass, @loop_pass | ||
import ..LLVM: is_module_pass, is_cgscc_pass, is_function_pass, is_loop_pass | ||
import ..LLVM: pass_string, options_string, add! | ||
|
||
@module_pass "CPUFeatures" CPUFeaturesPass | ||
@module_pass "RemoveNI" RemoveNIPass | ||
@module_pass "LowerSIMDLoop" LowerSIMDLoopPass | ||
@module_pass "FinalLowerGC" FinalLowerGCPass | ||
@module_pass "RemoveJuliaAddrspaces" RemoveJuliaAddrspacesPass | ||
@module_pass "RemoveAddrspaces" RemoveAddrspacesPass | ||
|
||
struct MultiVersioningPassOptions | ||
external::Core.Bool | ||
end | ||
MultiVersioningPassOptions(; external::Core.Bool=false) = MultiVersioningPassOptions(external) | ||
options_string(options::MultiVersioningPassOptions) = ifelse(options.external, "<external>", "") | ||
@module_pass "JuliaMultiVersioning" MultiVersioningPass MultiVersioningPassOptions | ||
|
||
struct LowerPTLSPassOptions | ||
imaging::Core.Bool | ||
end | ||
LowerPTLSPassOptions(; imaging::Core.Bool=false) = LowerPTLSPassOptions(imaging) | ||
options_string(options::LowerPTLSPassOptions) = ifelse(options.imaging, "<imaging>", "") | ||
@module_pass "LowerPTLSPass" LowerPTLSPass LowerPTLSPassOptions | ||
|
||
@function_pass "DemoteFloat16" DemoteFloat16Pass | ||
@function_pass "CombineMulAdd" CombineMulAddPass | ||
@function_pass "LateLowerGCFrame" LateLowerGCPass | ||
@function_pass "AllocOpt" AllocOptPass | ||
@function_pass "PropagateJuliaAddrspaces" PropagateJuliaAddrspacesPass | ||
@function_pass "LowerExcHandlers" LowerExcHandlersPass | ||
|
||
struct GCInvariantVerifierPassOptions | ||
strong::Core.Bool | ||
end | ||
GCInvariantVerifierPassOptions(; strong::Core.Bool=false) = GCInvariantVerifierPassOptions(strong) | ||
options_string(options::GCInvariantVerifierPassOptions) = ifelse(options.strong, "<strong>", "") | ||
@function_pass "GCInvariantVerifier" GCInvariantVerifierPass GCInvariantVerifierPassOptions | ||
|
||
@loop_pass "JuliaLICM" JuliaLICMPass | ||
|
||
# The entire Julia pipeline | ||
struct JuliaPipelinePassOptions | ||
speedup::Int | ||
lower_intrinsics::Core.Bool | ||
dump_native::Core.Bool | ||
external_use::Core.Bool | ||
llvm_only::Core.Bool | ||
end | ||
JuliaPipelinePassOptions(; speedup=Base.JLOptions().opt_level, lower_intrinsics::Core.Bool=true, | ||
dump_native::Core.Bool=false, external_use::Core.Bool=false, | ||
llvm_only::Core.Bool=false) = JuliaPipelinePassOptions(convert(Int, speedup), lower_intrinsics, dump_native, external_use, llvm_only) | ||
function options_string(options::JuliaPipelinePassOptions) | ||
optlevel = "O$(options.speedup)" | ||
lower_intrinsics = ifelse(options.lower_intrinsics, "lower_intrinsics", "no_lower_intrinsics") | ||
dump_native = ifelse(options.dump_native, "dump_native", "no_dump_native") | ||
external_use = ifelse(options.external_use, "external_use", "no_external_use") | ||
llvm_only = ifelse(options.llvm_only, "llvm_only", "no_llvm_only") | ||
"<$optlevel;$lower_intrinsics;$dump_native;$external_use;$llvm_only>" | ||
end | ||
@module_pass "julia" JuliaPipelinePass JuliaPipelinePassOptions | ||
|
||
# We specialize the add! here because if we go through the PassBuilder parser, | ||
# Julia won't insert the PassBuilder's callbacks in the right spots. | ||
# Using the specific method call here allows insertion of those callbacks. | ||
function add!(pm::NewPMModulePassManager, pb::PassBuilder, pass::JuliaPipelinePass) | ||
API.LLVMAddJuliaPipelinePass(pm, pb, pass.options.speedup, 0, pass.options.lower_intrinsics, | ||
pass.options.dump_native, pass.options.external_use, | ||
pass.options.llvm_only) | ||
end |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
export NewPMAnalysis, NewPMAliasAnalysis | ||
|
||
export add!, analysis_string, analysis_managers | ||
|
||
abstract type NewPMAnalysis end | ||
abstract type NewPMAliasAnalysis end | ||
|
||
macro alias_analysis(analysis_name, class_name) | ||
quote | ||
export $class_name | ||
struct $class_name <: NewPMAliasAnalysis end | ||
@eval analysis_string(::$class_name) = $analysis_name | ||
end | ||
end | ||
|
||
analysis_string(aa::AAManager) = join(aa.aas, ",") | ||
|
||
Base.show(io::IO, analysis::NewPMAnalysis) = print(io, analysis_string(analysis)) | ||
Base.show(io::IO, aa::AAManager) = print(io, analysis_string(aa)) | ||
|
||
# Module Alias Analysis | ||
@alias_analysis "globals-aa" GlobalsAA | ||
|
||
# Function Alias Analysis | ||
@alias_analysis "basic-aa" BasicAA | ||
@alias_analysis "cfl-anders-aa" CFLAndersAA | ||
@alias_analysis "cfl-steens-aa" CFLSteensAA | ||
@alias_analysis "objc-arc-aa" ObjCARCAA | ||
@alias_analysis "scev-aa" SCEVAA | ||
@alias_analysis "scoped-noalias-aa" ScopedNoAliasAA | ||
@alias_analysis "tbaa" TypeBasedAA | ||
|
||
add!(am::AAManager, aa::NewPMAliasAnalysis) = push!(am.aas, analysis_string(aa)) | ||
add!(am::AAManager, aas::AbstractVector{<:NewPMAliasAnalysis}) = append!(am.aas, analysis_string.(aas)) | ||
add!(am::AAManager, tm::TargetMachine) = am.tm = tm | ||
|
||
export TargetIRAnalysis, TargetLibraryAnalysis | ||
|
||
struct TargetIRAnalysis | ||
tm::TargetMachine | ||
end | ||
analysis_string(::TargetIRAnalysis) = "target-ir-analysis" | ||
|
||
struct TargetLibraryAnalysis | ||
triple::String | ||
end | ||
analysis_string(::TargetLibraryAnalysis) = "target-library-analysis" | ||
|
||
add!(fam::FunctionAnalysisManager, analysis::TargetIRAnalysis) = convert(Core.Bool, API.LLVMRegisterTargetIRAnalysis(fam, analysis.tm)) | ||
add!(fam::FunctionAnalysisManager, analysis::TargetLibraryAnalysis) = convert(Core.Bool, API.LLVMRegisterTargetLibraryAnalysis(fam, analysis.triple, length(analysis.triple))) | ||
|
||
function analysis_managers(f::Core.Function, pb::Union{Nothing,PassBuilder}=nothing, tm::Union{Nothing,TargetMachine}=nothing, aa_stack::AbstractVector{<:NewPMAliasAnalysis}=NewPMAliasAnalysis[]) | ||
@dispose lam=LoopAnalysisManager() fam=FunctionAnalysisManager() cam=CGSCCAnalysisManager() mam=ModuleAnalysisManager() begin | ||
if !isempty(aa_stack) | ||
add!(fam, AAManager) do aam | ||
add!(aam, aa_stack) | ||
if !isnothing(tm) | ||
add!(aam, tm) | ||
end | ||
end | ||
end | ||
if !isnothing(tm) | ||
add!(fam, TargetIRAnalysis(tm)) | ||
add!(fam, TargetLibraryAnalysis(triple(tm))) | ||
end | ||
if !isnothing(pb) | ||
register!(pb, lam, fam, cam, mam) | ||
end | ||
f(lam, fam, cam, mam) | ||
end | ||
end |
Oops, something went wrong.