From 217819a363935f24d3104c77a037d355fe82cde5 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Tue, 24 Oct 2023 06:05:06 -0400 Subject: [PATCH] Updates for LLVM 16 (#369) Co-authored-by: Tim Besard --- .gitignore | 1 - LocalPreferences.toml | 5 ++ Project.toml | 1 + deps/LLVMExtra/CMakeLists.txt | 7 ++- deps/LLVMExtra/include/NewPM.h | 2 +- deps/LLVMExtra/lib/llvm-api.cpp | 18 ++++--- deps/LLVMExtra/lib/newpm.cpp | 12 ++++- deps/build_local.jl | 8 +-- lib/libLLVM_extra.jl | 4 +- src/LLVM.jl | 18 ++++++- src/core/value/constant.jl | 5 +- src/init.jl | 8 ++- src/newpm/analyses.jl | 6 ++- src/newpm/instrumentation.jl | 3 +- src/newpm/passes.jl | 87 +++++++++++++++++++-------------- src/transform.jl | 8 ++- test/Project.toml | 1 - test/core_tests.jl | 3 -- test/essential_tests.jl | 6 ++- test/interop_tests.jl | 12 ++++- test/newpm_tests.jl | 34 ++++++------- test/transform_tests.jl | 4 +- 22 files changed, 158 insertions(+), 95 deletions(-) create mode 100644 LocalPreferences.toml diff --git a/.gitignore b/.gitignore index b838016e..ee7261ba 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,4 @@ *.jl.mem deps/Manifest.toml test/Manifest.toml -LocalPreferences.toml Manifest.toml diff --git a/LocalPreferences.toml b/LocalPreferences.toml new file mode 100644 index 00000000..ea77953f --- /dev/null +++ b/LocalPreferences.toml @@ -0,0 +1,5 @@ +[LLVM] +# which extensions library to use. normally, this is provided by an artifact, +# but if you are using a custom version of LLVM you will need to provide your own, +# e.g., by running `deps/build_local.jl`. +#libLLVMExtra = "/path/to/libLLVMExtra.so" diff --git a/Project.toml b/Project.toml index 81455646..5b17987d 100644 --- a/Project.toml +++ b/Project.toml @@ -6,6 +6,7 @@ version = "6.4.0" CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" LLVMExtra_jll = "dad2f222-ce93-54a1-a47d-0025e8a3acab" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" +Preferences = "21216c6a-2e73-6563-6e65-726566657250" Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7" Requires = "ae029012-a4dd-5104-9daa-d747884805df" Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/deps/LLVMExtra/CMakeLists.txt b/deps/LLVMExtra/CMakeLists.txt index 9005c3a0..9abcd992 100644 --- a/deps/LLVMExtra/CMakeLists.txt +++ b/deps/LLVMExtra/CMakeLists.txt @@ -2,6 +2,8 @@ cmake_minimum_required(VERSION 3.3) SET(CMAKE_CXX_FLAGS "-Wall -fPIC -fno-rtti") +cmake_policy(SET CMP0074 NEW) +cmake_policy(SET CMP0077 NEW) project(LLVMExtra VERSION @@ -11,10 +13,11 @@ LANGUAGES C ) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(LLVM REQUIRED) + +find_package(LLVM REQUIRED CONFIG) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${LLVM_CMAKE_DIR} diff --git a/deps/LLVMExtra/include/NewPM.h b/deps/LLVMExtra/include/NewPM.h index 5c09c8e4..3b46fb62 100644 --- a/deps/LLVMExtra/include/NewPM.h +++ b/deps/LLVMExtra/include/NewPM.h @@ -58,7 +58,7 @@ LLVMPreservedAnalysesRef LLVMRunNewPMFunctionPassManager(LLVMFunctionPassManager typedef struct LLVMOpaqueStandardInstrumentations *LLVMStandardInstrumentationsRef; typedef struct LLVMOpaquePassInstrumentationCallbacks *LLVMPassInstrumentationCallbacksRef; -LLVMStandardInstrumentationsRef LLVMCreateStandardInstrumentations(void); +LLVMStandardInstrumentationsRef LLVMCreateStandardInstrumentations(LLVMContextRef C, LLVMBool DebugLogging, LLVMBool VerifyEach); LLVMPassInstrumentationCallbacksRef LLVMCreatePassInstrumentationCallbacks(void); void LLVMDisposeStandardInstrumentations(LLVMStandardInstrumentationsRef SI); diff --git a/deps/LLVMExtra/lib/llvm-api.cpp b/deps/LLVMExtra/lib/llvm-api.cpp index ae284a39..e08a6c70 100644 --- a/deps/LLVMExtra/lib/llvm-api.cpp +++ b/deps/LLVMExtra/lib/llvm-api.cpp @@ -236,7 +236,7 @@ void LLVMExtraAppendToUsed(LLVMModuleRef Mod, size_t Count) { SmallVector GlobalValues; - for (auto *Value : makeArrayRef(Values, Count)) + for (auto *Value : ArrayRef(Values, Count)) GlobalValues.push_back(cast(unwrap(Value))); appendToUsed(*unwrap(Mod), GlobalValues); } @@ -246,7 +246,7 @@ void LLVMExtraAppendToCompilerUsed(LLVMModuleRef Mod, size_t Count) { SmallVector GlobalValues; - for (auto *Value : makeArrayRef(Values, Count)) + for (auto *Value : ArrayRef(Values, Count)) GlobalValues.push_back(cast(unwrap(Value))); appendToCompilerUsed(*unwrap(Mod), GlobalValues); } @@ -531,7 +531,7 @@ DEFINE_STDCXX_CONVERSION_FUNCTIONS(OperandBundleDef, LLVMOperandBundleDefRef) LLVMOperandBundleDefRef LLVMCreateOperandBundleDef(const char *Tag, LLVMValueRef *Inputs, unsigned NumInputs) { SmallVector InputArray; - for (auto *Input : makeArrayRef(Inputs, NumInputs)) + for (auto *Input : ArrayRef(Inputs, NumInputs)) InputArray.push_back(unwrap(Input)); return wrap(new OperandBundleDef(std::string(Tag), InputArray)); } @@ -566,14 +566,18 @@ LLVMValueRef LLVMBuildCallWithOpBundle(LLVMBuilderRef B, LLVMValueRef Fn, LLVMOperandBundleDefRef *Bundles, unsigned NumBundles, const char *Name) { SmallVector BundleArray; - for (auto *Bundle : makeArrayRef(Bundles, NumBundles)) + for (auto *Bundle : ArrayRef(Bundles, NumBundles)) BundleArray.push_back(*unwrap(Bundle)); llvm::IRBuilder<> *Builder = unwrap(B); - llvm::ArrayRef args = makeArrayRef(unwrap(Args), NumArgs); + llvm::ArrayRef args = ArrayRef(unwrap(Args), NumArgs); Value *V = unwrap(Fn); +#if LLVM_VERSION_MAJOR >= 15 + FunctionType *FnT = cast(V)->getFunctionType(); +#else FunctionType *FnT = cast(V->getType()->getPointerElementType()); +#endif llvm::CallInst *CI = Builder->CreateCall(FnT, unwrap(Fn), args ,BundleArray, Name); return wrap(CI); } @@ -583,11 +587,11 @@ LLVMValueRef LLVMBuildCallWithOpBundle2(LLVMBuilderRef B, LLVMTypeRef Ty, LLVMVa LLVMOperandBundleDefRef *Bundles, unsigned NumBundles, const char *Name) { SmallVector BundleArray; - for (auto *Bundle : makeArrayRef(Bundles, NumBundles)) + for (auto *Bundle : ArrayRef(Bundles, NumBundles)) BundleArray.push_back(*unwrap(Bundle)); llvm::IRBuilder<> *Builder = unwrap(B); - llvm::ArrayRef args = makeArrayRef(unwrap(Args), NumArgs); + llvm::ArrayRef args = ArrayRef(unwrap(Args), NumArgs); FunctionType *FTy = unwrap(Ty); llvm::CallInst *CI = Builder->CreateCall(FTy, unwrap(Fn), args ,BundleArray, Name); diff --git a/deps/LLVMExtra/lib/newpm.cpp b/deps/LLVMExtra/lib/newpm.cpp index 8219561f..2c9ab094 100644 --- a/deps/LLVMExtra/lib/newpm.cpp +++ b/deps/LLVMExtra/lib/newpm.cpp @@ -113,8 +113,12 @@ LLVMPreservedAnalysesRef LLVMRunNewPMFunctionPassManager(LLVMFunctionPassManager DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::StandardInstrumentations, LLVMStandardInstrumentationsRef) DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::PassInstrumentationCallbacks, LLVMPassInstrumentationCallbacksRef) -LLVMStandardInstrumentationsRef LLVMCreateStandardInstrumentations(void) { - return wrap(new llvm::StandardInstrumentations(false)); +LLVMStandardInstrumentationsRef LLVMCreateStandardInstrumentations(LLVMContextRef C, LLVMBool DebugLogging, LLVMBool VerifyEach) { +#if LLVM_VERSION_MAJOR >= 16 + return wrap(new llvm::StandardInstrumentations(*unwrap(C), DebugLogging, VerifyEach)); +#else + return wrap(new llvm::StandardInstrumentations(DebugLogging, VerifyEach)); +#endif } LLVMPassInstrumentationCallbacksRef LLVMCreatePassInstrumentationCallbacks(void) { return wrap(new llvm::PassInstrumentationCallbacks()); @@ -134,7 +138,11 @@ void LLVMAddStandardInstrumentations(LLVMPassInstrumentationCallbacksRef PIC, LL DEFINE_SIMPLE_CONVERSION_FUNCTIONS(llvm::PassBuilder, LLVMPassBuilderRef) LLVMPassBuilderRef LLVMCreatePassBuilder(LLVMTargetMachineRef TM, LLVMPassInstrumentationCallbacksRef PIC) { +#if LLVM_VERSION_MAJOR >= 16 + return wrap(new llvm::PassBuilder(unwrap(TM), llvm::PipelineTuningOptions(), std::nullopt, unwrap(PIC))); +#else return wrap(new llvm::PassBuilder(unwrap(TM), llvm::PipelineTuningOptions(), llvm::None, unwrap(PIC))); +#endif } void LLVMDisposePassBuilder(LLVMPassBuilderRef PB) { diff --git a/deps/build_local.jl b/deps/build_local.jl index 4bce4330..032d3619 100644 --- a/deps/build_local.jl +++ b/deps/build_local.jl @@ -48,7 +48,7 @@ LLVM_DIR = joinpath(LLVM.artifact_dir, "lib", "cmake", "llvm") # build and install @info "Building" source_dir scratch_dir build_dir LLVM_DIR cmake() do cmake_path - config_opts = `-DLLVM_DIR=$(LLVM_DIR) -DCMAKE_INSTALL_PREFIX=$(scratch_dir)` + config_opts = `-DLLVM_ROOT=$(LLVM_DIR) -DCMAKE_INSTALL_PREFIX=$(scratch_dir)` if Sys.iswindows() # prevent picking up MSVC config_opts = `$config_opts -G "MSYS Makefiles"` @@ -64,10 +64,10 @@ end lib_path = joinpath(scratch_dir, "lib", only(built_libs)) isfile(lib_path) || error("Could not find library $lib_path in build directory") -# tell LLVMExtra_jll to load our library instead of the default artifact one +# tell LLVM.jl to load our library instead of the default artifact one set_preferences!( joinpath(dirname(@__DIR__), "LocalPreferences.toml"), - "LLVMExtra_jll", - "libLLVMExtra_path" => lib_path; + "LLVM", + "libLLVMExtra" => lib_path; force=true, ) diff --git a/lib/libLLVM_extra.jl b/lib/libLLVM_extra.jl index e3cd2c63..faf1d25e 100644 --- a/lib/libLLVM_extra.jl +++ b/lib/libLLVM_extra.jl @@ -638,8 +638,8 @@ mutable struct LLVMOpaquePassInstrumentationCallbacks end const LLVMPassInstrumentationCallbacksRef = Ptr{LLVMOpaquePassInstrumentationCallbacks} -function LLVMCreateStandardInstrumentations() - ccall((:LLVMCreateStandardInstrumentations, libLLVMExtra), LLVMStandardInstrumentationsRef, ()) +function LLVMCreateStandardInstrumentations(C, DebugLogging, VerifyEach) + ccall((:LLVMCreateStandardInstrumentations, libLLVMExtra), LLVMStandardInstrumentationsRef, (LLVMContextRef, LLVMBool, LLVMBool), C, DebugLogging, VerifyEach) end function LLVMCreatePassInstrumentationCallbacks() diff --git a/src/LLVM.jl b/src/LLVM.jl index eb8dad42..a3e56d62 100644 --- a/src/LLVM.jl +++ b/src/LLVM.jl @@ -20,6 +20,7 @@ const libllvm_version = Base.libllvm_version module API using CEnum +using Preferences # LLVM C API using ..LLVM @@ -44,7 +45,14 @@ let end # LLVMExtra -import LLVMExtra_jll: libLLVMExtra +using LLVMExtra_jll +if has_preference(LLVM, "libLLVMExtra") + const libLLVMExtra = load_preference(LLVM, "libLLVMExtra") +else + if isdefined(LLVMExtra_jll, :libLLVMExtra) + import LLVMExtra_jll: libLLVMExtra + end +end include(joinpath(@__DIR__, "..", "lib", "libLLVM_extra.jl")) # Julia LLVM functionality @@ -97,6 +105,14 @@ function __init__() @debug "Using LLVM $libllvm_version at $(Base.libllvm_path())" # sanity checks + if !isdefined(API, :libLLVMExtra) + @error """LLVM extensions library unavailable for your platform: + $(Base.BinaryPlatforms.triplet(API.LLVMExtra_jll.host_platform)) + LLVM.jl will not be functional. + + If you are using a custom version of LLVM, try building a + custom version of LLVMExtra_jll using `deps/build_local.jl`""" + end if libllvm_version != Base.libllvm_version # this checks that the precompilation image isn't being used # after having upgraded Julia and the contained LLVM library. diff --git a/src/core/value/constant.jl b/src/core/value/constant.jl index b7212655..1d113f73 100644 --- a/src/core/value/constant.jl +++ b/src/core/value/constant.jl @@ -348,7 +348,7 @@ register(ConstantVector, API.LLVMConstantVectorValueKind) export ConstantExpr, - const_neg, const_nswneg, const_nuwneg, const_fneg, const_not, const_add, + const_neg, const_nswneg, const_nuwneg, const_not, const_add, const_nswadd, const_nuwadd, const_sub, const_nswsub, const_nuwsub, const_mul, const_nswmul, const_nuwmul, const_and, const_or, const_xor, const_icmp, const_fcmp, const_shl, const_lshr, const_ashr, const_gep, const_inbounds_gep, const_trunc, @@ -373,9 +373,6 @@ const_nswneg(val::Constant) = const_nuwneg(val::Constant) = Value(API.LLVMConstNUWNeg(val)) -const_fneg(val::Constant) = - Value(API.LLVMConstFNeg(val)) - const_not(val::Constant) = Value(API.LLVMConstNot(val)) diff --git a/src/init.jl b/src/init.jl index e60e3a9d..4252ab1e 100644 --- a/src/init.jl +++ b/src/init.jl @@ -4,8 +4,12 @@ export ismultithreaded ismultithreaded() = convert(Core.Bool, API.LLVMIsMultithreaded()) -for subsystem in [:Core, :TransformUtils, :ScalarOpts, :ObjCARCOpts, :Vectorization, - :InstCombine, :IPO, :Instrumentation, :Analysis, :IPA, :CodeGen, :Target] +const subsystems = [:Core, :TransformUtils, :ScalarOpts, :Vectorization, :InstCombine, + :IPO, :Analysis, :IPA, :CodeGen, :Target] +if LLVM.version() < v"16" + append!(subsystems, [:ObjCARCOpts, :Instrumentation]) +end +for subsystem in subsystems jl_fname = Symbol(:Initialize, subsystem) api_fname = Symbol(:LLVM, jl_fname) @eval begin diff --git a/src/newpm/analyses.jl b/src/newpm/analyses.jl index c0d7f01e..776e3607 100644 --- a/src/newpm/analyses.jl +++ b/src/newpm/analyses.jl @@ -23,12 +23,14 @@ Base.show(io::IO, aa::AAManager) = print(io, analysis_string(aa)) # 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 +if LLVM.version() < v"16" + @alias_analysis "cfl-anders-aa" CFLAndersAA + @alias_analysis "cfl-steens-aa" CFLSteensAA +end add!(am::AAManager, aa::NewPMAliasAnalysis) = push!(am.aas, analysis_string(aa)) add!(am::AAManager, aas::AbstractVector{<:NewPMAliasAnalysis}) = diff --git a/src/newpm/instrumentation.jl b/src/newpm/instrumentation.jl index 973dabdb..dd43dfd9 100644 --- a/src/newpm/instrumentation.jl +++ b/src/newpm/instrumentation.jl @@ -13,7 +13,8 @@ Base.unsafe_convert(::Type{API.LLVMPassInstrumentationCallbacksRef}, pic::PassIn PassInstrumentationCallbacks(si) = PassInstrumentationCallbacks(API.LLVMCreatePassInstrumentationCallbacks(), si, []) PassInstrumentationCallbacks() = PassInstrumentationCallbacks(API.LLVMStandardInstrumentationsRef(C_NULL)) -StandardInstrumentationCallbacks() = PassInstrumentationCallbacks(API.LLVMCreateStandardInstrumentations()) +StandardInstrumentationCallbacks(; debug_logging::Base.Bool=false, verify_each::Base.Bool=false) = + PassInstrumentationCallbacks(API.LLVMCreateStandardInstrumentations(context(), debug_logging, verify_each)) function PassInstrumentationCallbacks(f::Core.Function, args...; kwargs...) pic = PassInstrumentationCallbacks(args...; kwargs...) diff --git a/src/newpm/passes.jl b/src/newpm/passes.jl index 44826411..741ebf99 100644 --- a/src/newpm/passes.jl +++ b/src/newpm/passes.jl @@ -124,7 +124,11 @@ Base.show(io::IO, pass::NewPMLLVMPass) = print(io, pass_string(pass)) @module_pass "extract-blocks" BlockExtractorPass @module_pass "forceattrs" ForceFunctionAttrsPass @module_pass "function-import" FunctionImportPass -@module_pass "function-specialization" FunctionSpecializationPass +if LLVM.version() < v"16" + @module_pass "function-specialization" FunctionSpecializationPass +else + @module_pass "ipsccp" FunctionSpecializationPass +end @module_pass "globaldce" GlobalDCEPass @module_pass "globalopt" GlobalOptPass @module_pass "globalsplit" GlobalSplitPass @@ -180,10 +184,9 @@ Base.show(io::IO, pass::NewPMLLVMPass) = print(io, pass_string(pass)) @module_pass "view-callgraph" CallGraphViewerPass @module_pass "wholeprogramdevirt" WholeProgramDevirtPass @module_pass "dfsan" DataFlowSanitizerPass -@module_pass "msan-module" ModuleMemorySanitizerPass @module_pass "module-inline" ModuleInlinerPass @module_pass "tsan-module" ModuleThreadSanitizerPass -@module_pass "sancov-module" ModuleSanitizerCoveragePass +@module_pass "sancov-module" SanitizerCoveragePass @module_pass "memprof-module" ModuleMemProfilerPass @module_pass "poison-checking" PoisonCheckingPass @module_pass "pseudo-probe-update" PseudoProbeUpdatePass @@ -216,14 +219,49 @@ function options_string(options::HWAddressSanitizerPassOptions) end @module_pass "hwasan" HWAddressSanitizerPass HWAddressSanitizerPassOptions -struct ModuleAddressSanitizerPassOptions +struct AddressSanitizerPassOptions kernel::Core.Bool end -ModuleAddressSanitizerPassOptions(; kernel::Core.Bool = false) = - ModuleAddressSanitizerPassOptions(kernel) -options_string(options::ModuleAddressSanitizerPassOptions) = +AddressSanitizerPassOptions(; kernel::Core.Bool = false) = + AddressSanitizerPassOptions(kernel) +options_string(options::AddressSanitizerPassOptions) = options.kernel ? "" : "" -@module_pass "asan-module" ModuleAddressSanitizerPass ModuleAddressSanitizerPassOptions +if LLVM.version() < v"16" + @module_pass "asan-module" AddressSanitizerPass AddressSanitizerPassOptions +else + @module_pass "asan" AddressSanitizerPass AddressSanitizerPassOptions +end + +struct MemorySanitizerPassOptions + recover::Core.Bool + kernel::Core.Bool + eagerchecks::Core.Bool + trackorigins::Int +end +MemorySanitizerPassOptions(; recover::Core.Bool = false, + kernel::Core.Bool = false, + eagerchecks::Core.Bool = false, + trackorigins::Int = 0) = + MemorySanitizerPassOptions(recover, kernel, eagerchecks, trackorigins) +function options_string(options::MemorySanitizerPassOptions) + final_options = String[] + if options.recover + push!(final_options, "recover") + end + if options.kernel + push!(final_options, "kernel") + end + if options.eagerchecks + push!(final_options, "eager-checks") + end + push!(final_options, "track-origins=$(options.trackorigins)") + "<" * join(final_options, ";") * ">" +end +if LLVM.version() < v"16" + @function_pass "msan" MemorySanitizerPass MemorySanitizerPassOptions +else + @module_pass "msan" MemorySanitizerPass MemorySanitizerPassOptions +end # CGSCC passes @@ -360,6 +398,11 @@ is_function_pass(::Type{InvalidateAllAnalysesPass}) = true @function_pass "print-predicateinfo" PredicateInfoPrinterPass @function_pass "print-mustexecute" MustExecutePrinterPass @function_pass "print-memderefs" MemDerefPrinterPass +if LLVM.version() < v"16" + @loop_pass "print-access-info" LoopAccessInfoPrinterPass +else + @function_pass "print" LoopAccessInfoPrinterPass +end @function_pass "reassociate" ReassociatePass @function_pass "redundant-dbg-inst-elim" RedundantDbgInstEliminationPass @function_pass "reg2mem" RegToMemPass @@ -460,33 +503,6 @@ function options_string(options::LoopUnrollOptions) end @function_pass "loop-unroll" LoopUnrollPass LoopUnrollOptions -struct MemorySanitizerPassOptions - recover::Core.Bool - kernel::Core.Bool - eagerchecks::Core.Bool - trackorigins::Int -end -MemorySanitizerPassOptions(; recover::Core.Bool = false, - kernel::Core.Bool = false, - eagerchecks::Core.Bool = false, - trackorigins::Int = 0) = - MemorySanitizerPassOptions(recover, kernel, eagerchecks, trackorigins) -function options_string(options::MemorySanitizerPassOptions) - final_options = String[] - if options.recover - push!(final_options, "recover") - end - if options.kernel - push!(final_options, "kernel") - end - if options.eagerchecks - push!(final_options, "eager-checks") - end - push!(final_options, "track-origins=$(options.trackorigins)") - "<" * join(final_options, ";") * ">" -end -@function_pass "msan" MemorySanitizerPass MemorySanitizerPassOptions - struct SimplifyCFGPassOptions forward_switch_cond_to_phi::Core.Bool convert_switch_range_to_icmp::Core.Bool @@ -622,7 +638,6 @@ is_loop_pass(::Type{InvalidateAllAnalysesPass}) = true @loop_pass "loop-reduce" LoopStrengthReducePass @loop_pass "indvars" IndVarSimplifyPass @loop_pass "loop-unroll-full" LoopFullUnrollPass -@loop_pass "print-access-info" LoopAccessInfoPrinterPass @loop_pass "print" DDGAnalysisPrinterPass @loop_pass "print" IVUsersPrinterPass @loop_pass "print" LoopNestPrinterPass diff --git a/src/transform.jl b/src/transform.jl index 8a29208d..9b64bed6 100644 --- a/src/transform.jl +++ b/src/transform.jl @@ -155,11 +155,15 @@ define_transforms([:LoadStoreVectorizer]) define_transforms([ :ConstantMerge, :DeadArgElimination, :FunctionAttrs, :FunctionInlining, :AlwaysInliner, :GlobalDCE, :GlobalOptimizer, :IPConstantPropagation, - :PruneEH, :IPSCCP, :StripDeadPrototypes, :StripSymbols + :IPSCCP, :StripDeadPrototypes, :StripSymbols ]) if version() < v"15" - define_transforms([:ArgumentPromotion]) # only avaliable on new PM + define_transforms([:ArgumentPromotion]) +end + +if version() < v"16" + define_transforms([:PruneEH]) end export internalize! diff --git a/test/Project.toml b/test/Project.toml index 943a00d0..f2b88ef1 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,7 +1,6 @@ [deps] BFloat16s = "ab4f0b2a-ad5b-11e8-123f-65d77653426b" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" -LLVMExtra_jll = "dad2f222-ce93-54a1-a47d-0025e8a3acab" ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" diff --git a/test/core_tests.jl b/test/core_tests.jl index 8d997edd..98e91438 100644 --- a/test/core_tests.jl +++ b/test/core_tests.jl @@ -669,9 +669,6 @@ end let val = LLVM.ConstantFP(Float32(42.); ) - ce = const_fneg(val)::LLVM.Constant - @check_ir ce "float -4.200000e+01" - other_val = LLVM.ConstantFP(Float32(2.)) ce = const_fcmp(LLVM.API.LLVMRealUGT, val, other_val)::LLVM.Constant @check_ir ce "i1 true" diff --git a/test/essential_tests.jl b/test/essential_tests.jl index b7ab8702..7f2b073e 100644 --- a/test/essential_tests.jl +++ b/test/essential_tests.jl @@ -19,11 +19,13 @@ end InitializeCore(passreg) InitializeTransformUtils(passreg) InitializeScalarOpts(passreg) - InitializeObjCARCOpts(passreg) + if LLVM.version() < v"16" + InitializeObjCARCOpts(passreg) + InitializeInstrumentation(passreg) + end InitializeVectorization(passreg) InitializeInstCombine(passreg) InitializeIPO(passreg) - InitializeInstrumentation(passreg) InitializeAnalysis(passreg) InitializeIPA(passreg) InitializeCodeGen(passreg) diff --git a/test/interop_tests.jl b/test/interop_tests.jl index 3459fdc2..670c0a61 100644 --- a/test/interop_tests.jl +++ b/test/interop_tests.jl @@ -351,12 +351,20 @@ else annotated(ptr::Ptr{T}) where {T} = @typed_ccall("llvm.ptr.annotation.p0", llvmcall, Ptr{T}, (Ptr{T}, Ptr{Int8}, Ptr{Int8}, Int32), ptr, C_NULL, C_NULL, 0) ir = sprint(io->code_llvm(io, annotated, Tuple{Ptr{Float64}})) - @test occursin("ptr @llvm.ptr.annotation.p0(ptr", ir) + if LLVM.version() >= v"16" + @test occursin("ptr @llvm.ptr.annotation.p0.p0(ptr", ir) + else + @test occursin("ptr @llvm.ptr.annotation.p0(ptr", ir) + end annotated(ptr::LLVMPtr{T}) where {T} = @typed_ccall("llvm.ptr.annotation.p0", llvmcall, LLVMPtr{T,1}, (LLVMPtr{T,1}, Ptr{Int8}, Ptr{Int8}, Int32), ptr, C_NULL, C_NULL, 0) ir = sprint(io->code_llvm(io, annotated, Tuple{LLVMPtr{Float64,1}})) - @test occursin("ptr addrspace(1) @llvm.ptr.annotation.p1(ptr addrspace(1)", ir) + if LLVM.version() >= v"16" + @test occursin("ptr addrspace(1) @llvm.ptr.annotation.p1.p0(ptr addrspace(1)", ir) + else + @test occursin("ptr addrspace(1) @llvm.ptr.annotation.p1(ptr addrspace(1)", ir) + end # test return nothing LLVM.Interop.@typed_ccall("llvm.donothing", llvmcall, Cvoid, ()) diff --git a/test/newpm_tests.jl b/test/newpm_tests.jl index d3ddb375..6d7b7040 100644 --- a/test/newpm_tests.jl +++ b/test/newpm_tests.jl @@ -40,6 +40,7 @@ NewPMLoopPassManager() do lpm end end # testset "newpm pass managers" @testset "newpm pass builder" begin +@dispose ctx=Context() begin let pic = PassInstrumentationCallbacks() dispose(pic) @@ -72,6 +73,7 @@ end @test "PassBuilder didn't crash!" != "" +end end # testset "newpm pass builder" @testset "newpm analysis managers" begin @@ -130,7 +132,7 @@ end # testset "newpm analysis registration" host_triple = triple() host_t = Target(triple=host_triple) -@dispose tm=TargetMachine(host_t, host_triple) pb=PassBuilder(tm) begin +@dispose ctx=Context() tm=TargetMachine(host_t, host_triple) pb=PassBuilder(tm) begin analysis_managers() do lam, fam, cam, mam register!(pb, lam, fam, cam, mam) @@ -219,13 +221,6 @@ host_t = Target(triple=host_triple) end @test "Successfully added nested pass managers!" != "" - - # As of LLVM 15 this count is 279, may change with each version based on LLVM's whims - if VERSION >= v"1.10.0-DEV.1622" - @test length(subtypes(NewPMLLVMPass)) == 279 - else - @test length(subtypes(NewPMLLVMPass)) == 262 - end end end @@ -236,7 +231,7 @@ end # testset "newpm passes" host_triple = triple() host_t = Target(triple=host_triple) -@dispose tm=TargetMachine(host_t, host_triple) pb=PassBuilder(tm) begin +@dispose ctx=Context() tm=TargetMachine(host_t, host_triple) pb=PassBuilder(tm) begin analysis_managers() do lam, fam, cam, mam register!(pb, lam, fam, cam, mam) @@ -257,7 +252,7 @@ host_t = Target(triple=host_triple) @test "Successfully added custom module and function passes!" != "" - @dispose ctx=Context() builder=IRBuilder() mod=LLVM.Module("test") begin + @dispose builder=IRBuilder() mod=LLVM.Module("test") begin @dispose pa=run!(mpm, mod, mam) begin @test observed_modules == 1 @test observed_functions == 0 @@ -289,8 +284,7 @@ function fake_custom_legacy_pass(counter::Ref{Int}) end end -@dispose tm=TargetMachine(host_t, host_triple) pb=PassBuilder(tm) begin - +@dispose ctx=Context() tm=TargetMachine(host_t, host_triple) pb=PassBuilder(tm) begin observed_modules = Ref{Int}(0) observed_functions = Ref{Int}(0) @dispose mpm=NewPMModulePassManager(pb) begin @@ -299,7 +293,7 @@ end add!(legacy2newpm(fake_custom_legacy_pass(observed_functions)), fpm) end - @dispose ctx=Context() builder=IRBuilder() mod=LLVM.Module("test") begin + @dispose builder=IRBuilder() mod=LLVM.Module("test") begin run!(mpm, mod) @test observed_modules[] == 1 @@ -327,7 +321,7 @@ end # testset "newpm custom passes" host_triple = triple() host_t = Target(triple=host_triple) -@dispose tm=TargetMachine(host_t, host_triple) pb=PassBuilder(tm) begin +@dispose ctx=Context() tm=TargetMachine(host_t, host_triple) pb=PassBuilder(tm) begin analysis_managers() do lam, fam, cam, mam @test add!(fam, AAManager) do aam # Do nothing @@ -351,12 +345,14 @@ host_t = Target(triple=host_triple) analysis_managers() do lam, fam, cam, mam add!(fam, AAManager) do aam add!(aam, BasicAA()) - add!(aam, CFLAndersAA()) - add!(aam, CFLSteensAA()) add!(aam, ObjCARCAA()) add!(aam, ScopedNoAliasAA()) add!(aam, TypeBasedAA()) add!(aam, GlobalsAA()) + if LLVM.version() < v"16" + add!(aam, CFLAndersAA()) + add!(aam, CFLSteensAA()) + end end register!(pb, lam, fam, cam, mam) end @@ -442,7 +438,7 @@ end @test_throws ArgumentError add!(lpm, LICMPass()) end -@dispose pb=PassBuilder() begin +@dispose ctx=Context() pb=PassBuilder() begin @dispose mpm=NewPMModulePassManager(pb) begin @test_throws ArgumentError add!(mpm, SimplifyCFGPass()) end @@ -488,7 +484,7 @@ using LLVM.Interop @testset "newpm julia pipeline" begin host_triple = triple() host_t = Target(triple=host_triple) -@dispose tm=TargetMachine(host_t, host_triple) pb=PassBuilder(tm) begin +@dispose ctx=Context() tm=TargetMachine(host_t, host_triple) pb=PassBuilder(tm) begin basicSimplifyCFGOptions = SimplifyCFGPassOptions(; forward_switch_cond_to_phi=true, convert_switch_range_to_icmp=true, @@ -619,7 +615,7 @@ host_t = Target(triple=host_triple) @test "Successfully created julia pipeline!" != "" - @dispose ctx=Context() builder=IRBuilder() mod=LLVM.Module("test") begin + @dispose builder=IRBuilder() mod=LLVM.Module("test") begin ft = LLVM.FunctionType(LLVM.VoidType()) fn = LLVM.Function(mod, "SomeFunction", ft) diff --git a/test/transform_tests.jl b/test/transform_tests.jl index ca1fdda1..7d027679 100644 --- a/test/transform_tests.jl +++ b/test/transform_tests.jl @@ -91,7 +91,9 @@ end always_inliner!(pm) global_dce!(pm) global_optimizer!(pm) - prune_eh!(pm) + if LLVM.version() < v"16" + prune_eh!(pm) + end ipsccp!(pm) strip_dead_prototypes!(pm) strip_symbols!(pm)