Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ReTestItems.jl. #360

Merged
merged 6 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
version: ['1.6', '1.7', '1.8', '1.9', 'nightly']
version: ['1.8', '1.9', 'nightly']
os: ['ubuntu-latest', 'macOS-latest', 'windows-latest']
arch: [x64]
llvm_args: ['']
Expand Down Expand Up @@ -85,7 +85,7 @@ jobs:
strategy:
fail-fast: false
matrix:
branch: ['release-1.6', 'release-1.7', 'release-1.8', 'release-1.9', 'master']
branch: ['release-1.8', 'release-1.9', 'master']
os: ['ubuntu-latest', 'macOS-latest', 'windows-latest']
arch: ['x64']
llvm_args: ['']
Expand Down Expand Up @@ -114,9 +114,9 @@ jobs:
- branch: 'master'
os: 'macOS-latest'
arch: 'x64'
# 1.6 requires gfortran, which isn't available on macOS runners
- branch: 'release-1.6'
os: 'macOS-latest'
# compilation failure
- branch: 'release-1.8'
os: 'windows-latest'
arch: 'x64'
steps:
- uses: actions/checkout@v3
Expand All @@ -138,20 +138,21 @@ jobs:
# compile Julia
- name: Compile Julia
run: |
sed -i.bak 's/exit 2/exit 0/g' julia/deps/tools/jlchecksum
make -C julia -j $(nproc) FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1 JULIA_PRECOMPILE=0
echo $PWD/julia/usr/bin >> $GITHUB_PATH
mv julia ../ # move julia checkout out of the way, for ReTestItems.jl
sed -i.bak 's/exit 2/exit 0/g' ../julia/deps/tools/jlchecksum
make -C ../julia -j $(nproc) FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1 JULIA_PRECOMPILE=0
echo $PWD/../julia/usr/bin >> $GITHUB_PATH
if: runner.os != 'Windows'
- name: Compile Julia (in msys2)
shell: msys2 {0}
run: |
echo $PWD
sed -i.bak 's/exit 2/exit 0/g' julia/deps/tools/jlchecksum
mv julia ../ # move julia checkout out of the way, for ReTestItems.jl
sed -i.bak 's/exit 2/exit 0/g' ../julia/deps/tools/jlchecksum
# XXX: workaround for JuliaLang/julia#48081
make -C julia/deps install-csl && \
cp ${MINGW_PREFIX}/lib/libmsvcrt.a ./julia/usr/lib/libmsvcrt.a && \
make -C julia -j $(nproc) FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1 JULIA_PRECOMPILE=0
echo $PWD/julia/usr/bin >> $GITHUB_PATH
make -C ../julia/deps install-csl && \
cp ${MINGW_PREFIX}/lib/libmsvcrt.a ../julia/usr/lib/libmsvcrt.a && \
make -C ../julia -j $(nproc) FORCE_ASSERTIONS=1 LLVM_ASSERTIONS=1 JULIA_PRECOMPILE=0
echo $PWD/../julia/usr/bin >> $GITHUB_PATH
if: runner.os == 'Windows'

# set-up packages
Expand Down Expand Up @@ -191,7 +192,7 @@ jobs:
- uses: actions/checkout@v3
- uses: julia-actions/setup-julia@latest
with:
version: '1.6'
version: '1.8'
- name: Install dependencies
run: julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd())); Pkg.instantiate()'
- name: Build and deploy
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ Unicode = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[compat]
CEnum = "0.2, 0.3, 0.4"
LLVMExtra_jll = "=0.0.23"
julia = "1.6"
julia = "1.8"
16 changes: 10 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ by Julia, to interoperate with the Julia compiler, or to create your own compile
heavily used by the different GPU compilers for the Julia programming language.


## Requirements

LLVM.jl is supported on Juila 1.8+, and thus requires LLVM 13. However, the package is
really only **intended to be used with the LLVM library shipped with Julia**. That means you
can not use it with other LLVM libraries, like the one provided by your operating system. It
is recommended to use the official binaries from
[julialang.org](https://julialang.org/downloads/), but custom builds are supported too (as
long as they provide a dynamically-linked copy of the LLVM library).


## Installation

LLVM.jl can be installed with the Julia package manager.
Expand All @@ -39,9 +49,3 @@ Or, equivalently, via the `Pkg` API:
```julia
julia> import Pkg; Pkg.add("LLVM")
```

Note that the package **is intended to be used with the LLVM library shipped with Julia**.
That means you can not use it with other LLVM libraries, like the one provided by your
operating system. It is recommended to use the official binaries from
[julialang.org](https://julialang.org/downloads/), but custom builds are supported too (as
long as they provide a dynamically-linked copy of the LLVM library).
52 changes: 11 additions & 41 deletions examples/sum_orc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,51 +41,21 @@ function codegen!(mod::LLVM.Module, name, tm)
end

tm = JITTargetMachine()
if LLVM.has_orc_v2()
# XXX: LLJIT calls TargetMachineBuilder which disposes the TargetMachine
jit = LLJIT(; tm=JITTargetMachine())

@dispose ts_ctx=ThreadSafeContext() begin
ts_mod = ThreadSafeModule("jit")
name = "sum_orc.jl"
ts_mod() do mod
codegen!(mod, name, tm)
end

jd = JITDylib(jit)
add!(jit, jd, ts_mod)
addr = lookup(jit, name)

@eval call_sum(x, y) = ccall($(pointer(addr)), Int32, (Int32, Int32), x, y)
end
else
jit = OrcJIT(tm)
register!(jit, GDBRegistrationListener())
# XXX: LLJIT calls TargetMachineBuilder which disposes the TargetMachine
jit = LLJIT(; tm=JITTargetMachine())

@dispose ctx=Context() begin
mod = LLVM.Module("jit")
name = mangle(jit, "sum_orc.jl")
@dispose ts_ctx=ThreadSafeContext() begin
ts_mod = ThreadSafeModule("jit")
name = "sum_orc.jl"
ts_mod() do mod
codegen!(mod, name, tm)

# For debugging:
# asm = String(convert(Vector{UInt8}, emit(tm, mod, LLVM.API.LLVMAssemblyFile)))
# write(stdout, asm)

jitted_mod = compile!(jit, mod)

addr = address(jit, name)
addr2 = addressin(jit, jitted_mod, name)
@test addr == addr2
@test addr.ptr != 0

# For debugging:
# ccall(:jl_breakpoint, Cvoid, (Any,), pointer(addr))
# Then in GDB
# b *(*(uint64_t*)v)
@eval call_sum(x, y) = ccall($(pointer(addr)), Int32, (Int32, Int32), x, y)
end

unregister!(jit, GDBRegistrationListener())
jd = JITDylib(jit)
add!(jit, jd, ts_mod)
addr = lookup(jit, name)

@eval call_sum(x, y) = ccall($(pointer(addr)), Int32, (Int32, Int32), x, y)
end

@test call_sum(x, y) == x + y
Expand Down
17 changes: 4 additions & 13 deletions src/LLVM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ include(joinpath(@__DIR__, "..", "lib", "libLLVM_julia.jl"))

end # module API

has_newpm() = LLVM.version() >= v"15"
has_julia_ojit() = VERSION >= v"1.10.0-DEV.1395"

# LLVM API wrappers
include("support.jl")
include("types.jl")
Expand All @@ -72,19 +75,7 @@ include("debuginfo.jl")
include("dibuilder.jl")
include("jitevents.jl")
include("utils.jl")

has_orc_v1() = v"8" <= LLVM.version() < v"12"
if has_orc_v1()
include("orc.jl")
end

has_orc_v2() = v"12" <= LLVM.version()
has_julia_ojit() = VERSION >= v"1.10.0-DEV.1395"
if has_orc_v2()
include("orcv2.jl")
end

has_newpm() = v"15" <= LLVM.version()
include("orc.jl")
if has_newpm()
include("newpm.jl")
end
Expand Down
7 changes: 2 additions & 5 deletions src/core/attributes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,9 @@ function Attribute(ref::API.LLVMAttributeRef)
return EnumAttribute(ref)
elseif convert(Core.Bool, API.LLVMIsStringAttribute(ref))
return StringAttribute(ref)
elseif convert(Core.Bool, API.LLVMIsTypeAttribute(ref))
return TypeAttribute(ref)
else
@static if LLVM.version() >= v"12"
if convert(Core.Bool, API.LLVMIsTypeAttribute(ref))
return TypeAttribute(ref)
end
end
error("unknown attribute kind")
end
end
Expand Down
13 changes: 3 additions & 10 deletions src/interop/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,9 @@ function call_function(llvmf::LLVM.Function, rettyp::Type=Nothing, argtyp::Type=
ir = string(mod)
fn = LLVM.name(llvmf)
@assert !isempty(fn)
if VERSION >= v"1.8.0-DEV.410"
quote
Base.@inline
Base.llvmcall(($ir,$fn), $rettyp, $argtyp, $(args...))
end
else
quote
Base.@_inline_meta
Base.llvmcall(($ir,$fn), $rettyp, $argtyp, $(args...))
end
quote
Base.@inline
Base.llvmcall(($ir,$fn), $rettyp, $argtyp, $(args...))
end
end

Expand Down
6 changes: 1 addition & 5 deletions src/interop/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,4 @@ remove_ni!(pm::PassManager) = API.LLVMAddRemoveNIPass(pm)

julia_licm!(pm::PassManager) = API.LLVMAddJuliaLICMPass(pm)

if VERSION >= v"1.8.0-DEV.1120"
cpu_features!(pm::PassManager) = API.LLVMAddCPUFeaturesPass(pm)
else
cpu_features!(pm::PassManager) = nothing
end
cpu_features!(pm::PassManager) = API.LLVMAddCPUFeaturesPass(pm)
Loading
Loading