From 62173406c840677b4abb05b26e99fb457712bd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20S=C3=A1nchez=20Ram=C3=ADrez?= Date: Tue, 23 Apr 2024 20:23:26 +0200 Subject: [PATCH 1/3] Replace `Base.libllvm_version` with `libmlir_version` preference --- src/Dialects.jl | 2 +- src/IR/Attribute.jl | 4 ++-- src/IR/IR.jl | 2 +- src/IR/Operation.jl | 2 +- src/IR/Pass.jl | 2 +- src/MLIR.jl | 6 +++++- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/Dialects.jl b/src/Dialects.jl index 8bd9c513..88494c2a 100644 --- a/src/Dialects.jl +++ b/src/Dialects.jl @@ -13,7 +13,7 @@ end operandsegmentsizes(segments) = namedattribute("operand_segment_sizes", Attribute(Int32.(segments))) let - ver = string(Base.libllvm_version.major) + ver = string(libmlir_version.major) dir = joinpath(@__DIR__, "Dialects", ver) if !isdir(dir) error("""The MLIR dialect bindings for v$ver do not exist. diff --git a/src/IR/Attribute.jl b/src/IR/Attribute.jl index c49f43ae..7bfb5830 100644 --- a/src/IR/Attribute.jl +++ b/src/IR/Attribute.jl @@ -621,7 +621,7 @@ function Base.length(attr::Attribute) API.mlirDictionaryAttrGetNumElements(attr) elseif iselements(attr) API.mlirElementsAttrGetNumElements(attr) - elseif Base.libllvm_version >= v"16" + elseif libmlir_version >= v"16" _isdensearray = any(T -> isdensearray(attr, T), [Bool, Int8, Int16, Int32, Int64, Float32, Float64]) if _isdensearray API.mlirDenseBoolArrayGetNumElements(attr) @@ -667,7 +667,7 @@ function Base.getindex(attr::Attribute, i) else throw("unsupported element type $(elem_type)") end - elseif Base.libllvm_version >= v"16" + elseif libmlir_version >= v"16" if isdensearray(attr, Bool) API.mlirDenseBoolArrayGetElement(attr, i) elseif isdensearray(attr, Int8) diff --git a/src/IR/IR.jl b/src/IR/IR.jl index 91d765eb..f1fdf84a 100644 --- a/src/IR/IR.jl +++ b/src/IR/IR.jl @@ -30,7 +30,7 @@ macro llvmversioned(pred, expr) @assert Meta.isexpr(version, :macrocall) && version.args[1] == Symbol("@v_str") "Expected a VersionNumber" version = eval(version) - if predname == :min && Base.libllvm_version >= version || predname == :max && VersionNumber(Base.libllvm_version.major) <= version + if predname == :min && libmlir_version >= version || predname == :max && VersionNumber(libmlir_version.major) <= version esc(expr) else esc(:(nothing)) diff --git a/src/IR/Operation.jl b/src/IR/Operation.jl index d7743977..e81d4591 100644 --- a/src/IR/Operation.jl +++ b/src/IR/Operation.jl @@ -220,7 +220,7 @@ function Base.show(io::IO, operation::Operation) flags = API.mlirOpPrintingFlagsCreate() - if Base.libllvm_version >= v"16" + if libmlir_version >= v"16" API.mlirOpPrintingFlagsEnableDebugInfo(flags, get(io, :debug, false), true) else get(io, :debug, false) && API.mlirOpPrintingFlagsEnableDebugInfo(flags, true) diff --git a/src/IR/Pass.jl b/src/IR/Pass.jl index 84ba060a..0043be0a 100644 --- a/src/IR/Pass.jl +++ b/src/IR/Pass.jl @@ -145,7 +145,7 @@ end Parse a textual MLIR pass pipeline and add it to the provided `OpPassManager`. """ function Base.parse(opm::OpPassManager, pipeline::String) - result = if Base.libllvm_version >= v"16" + result = if libmlir_version >= v"16" io = IOBuffer() c_print_callback = @cfunction(print_callback, Cvoid, (API.MlirStringRef, Any)) API.mlirParsePassPipeline(opm, pipeline, c_print_callback, Ref(io)) diff --git a/src/MLIR.jl b/src/MLIR.jl index 5d28953f..189a3ffb 100644 --- a/src/MLIR.jl +++ b/src/MLIR.jl @@ -1,12 +1,16 @@ module MLIR +using Preferences + +libmlir_version = VersionNumber(@load_preference(:libmlir_version, Base.libllvm_version_string)) + module API using CEnum # MLIR C API using MLIR_jll let - ver = string(Base.libllvm_version.major) + ver = string(libmlir_version.major) dir = joinpath(@__DIR__, "API", ver) if !isdir(dir) error("""The MLIR API bindings for v$ver do not exist. From d98f33e8aef7a1b3653e6e11a82255fd91652d49 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20S=C3=A1nchez=20Ram=C3=ADrez?= Date: Tue, 23 Apr 2024 20:45:08 +0200 Subject: [PATCH 2/3] Add `Preferences` dependency --- Project.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Project.toml b/Project.toml index eae50c2c..dbde823a 100644 --- a/Project.toml +++ b/Project.toml @@ -6,8 +6,10 @@ version = "0.1.0" CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" MLIR_jll = "a70bccb4-a5c0-5e2e-a329-e731972457e8" +Preferences = "21216c6a-2e73-6563-6e65-726566657250" [compat] CEnum = "0.4" MLIR_jll = "14,15,16" +Preferences = "1" julia = "1.9" From 47ef25612e0981b96b32fbba5d5677ae2e8c6c89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20S=C3=A1nchez=20Ram=C3=ADrez?= Date: Wed, 24 Apr 2024 12:38:41 +0200 Subject: [PATCH 3/3] Fix preference type from `Symbol` to `String` --- src/MLIR.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MLIR.jl b/src/MLIR.jl index 189a3ffb..43cf6d80 100644 --- a/src/MLIR.jl +++ b/src/MLIR.jl @@ -2,7 +2,7 @@ module MLIR using Preferences -libmlir_version = VersionNumber(@load_preference(:libmlir_version, Base.libllvm_version_string)) +libmlir_version = VersionNumber(@load_preference("libmlir_version", Base.libllvm_version_string)) module API using CEnum