From 50122adb2cfca5f9f8b3a60967fbc5f5c56f6b98 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 18:08:06 +0800 Subject: [PATCH 01/20] vbroadcast: vbroadcast: use opaque pointer --- src/llvm_intrin/vbroadcast.jl | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/llvm_intrin/vbroadcast.jl b/src/llvm_intrin/vbroadcast.jl index 29cae45..ad8a01a 100644 --- a/src/llvm_intrin/vbroadcast.jl +++ b/src/llvm_intrin/vbroadcast.jl @@ -164,12 +164,10 @@ end ) where {W,T} isone(W) && return Expr(:block, Expr(:meta, :inline), :(vload(ptr))) typ = LLVM_TYPES[T] - ptyp = JULIAPOINTERTYPE vtyp = "<$W x $typ>" alignment = Base.datatype_alignment(T) instrs = """ - %ptr = inttoptr $ptyp %0 to $typ* - %res = load $typ, $typ* %ptr, align $alignment + %res = load $typ, ptr %0, align $alignment %ie = insertelement $vtyp undef, $typ %res, i32 0 %v = shufflevector $vtyp %ie, $vtyp undef, <$W x i32> zeroinitializer ret $vtyp %v From 7499ff3c9cd081f3a6276764119be71cabbc428d Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 18:40:55 +0800 Subject: [PATCH 02/20] memory_addr.expandload: use opaque pointer --- src/llvm_intrin/memory_addr.jl | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index 8ad9cf4..f58ac8f 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -2310,21 +2310,20 @@ end ) where {W,T<:NativeTypes,U<:Unsigned} typ = LLVM_TYPES[T] vtyp = "<$W x $typ>" - vptrtyp = "<$W x $typ*>" mtyp_input = LLVM_TYPES[U] mtyp_trunc = "i$W" instrs = String[] - push!(instrs, "%ptr = inttoptr $JULIAPOINTERTYPE %0 to $typ*") + # push!(instrs, "%ptr = inttoptr $JULIAPOINTERTYPE %0 to $typ*") if mtyp_input == mtyp_trunc push!(instrs, "%mask = bitcast $mtyp_input %1 to <$W x i1>") else push!(instrs, "%masktrunc = trunc $mtyp_input %1 to $mtyp_trunc") push!(instrs, "%mask = bitcast $mtyp_trunc %masktrunc to <$W x i1>") end - decl = "declare $vtyp @llvm.masked.expandload.$(suffix(W,T))($typ*, <$W x i1>, $vtyp)" + decl = "declare $vtyp @llvm.masked.expandload.$(suffix(W,T))(ptr, <$W x i1>, $vtyp)" push!( instrs, - "%res = call $vtyp @llvm.masked.expandload.$(suffix(W,T))($typ* %ptr, <$W x i1> %mask, $vtyp zeroinitializer)\nret $vtyp %res" + "%res = call $vtyp @llvm.masked.expandload.$(suffix(W,T))(ptr %0, <$W x i1> %mask, $vtyp zeroinitializer)\nret $vtyp %res" ) llvmcall_expr( decl, From 4c5756d468f63d090067e2bbccc422a0a9fc98d3 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 18:41:13 +0800 Subject: [PATCH 03/20] memory_addr.compressstore: use opaque pointer --- src/llvm_intrin/memory_addr.jl | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index f58ac8f..fc4f71e 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -2284,12 +2284,13 @@ end vtyp = "<$W x $typ>" mtyp_input = LLVM_TYPES[U] mtyp_trunc = "i$W" - instrs = String["%ptr = inttoptr $JULIAPOINTERTYPE %1 to $typ*"] + instrs = String[] + # push!(instrs, "%ptr = inttoptr $JULIAPOINTERTYPE %1 to $typ*") truncate_mask!(instrs, '2', W, 0) - decl = "declare void @llvm.masked.compressstore.$(suffix(W,T))($vtyp, $typ*, <$W x i1>)" + decl = "declare void @llvm.masked.compressstore.$(suffix(W,T))($vtyp, ptr, <$W x i1>)" push!( instrs, - "call void @llvm.masked.compressstore.$(suffix(W,T))($vtyp %0, $typ* %ptr, <$W x i1> %mask.0)\nret void" + "call void @llvm.masked.compressstore.$(suffix(W,T))($vtyp %0, ptr %1, <$W x i1> %mask.0)\nret void" ) llvmcall_expr( decl, From e8f725369417a736e1baa8585a5ca9f08f01fdbc Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 18:43:56 +0800 Subject: [PATCH 04/20] memory_addr.lifetime.start: use opaque pointer --- src/llvm_intrin/memory_addr.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index fc4f71e..f59ce8f 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -2228,8 +2228,8 @@ end @generated function lifetime_start!(ptr::Ptr{T}, ::Val{L}) where {L,T} ptyp = LLVM_TYPES[T] - decl = "declare void @llvm.lifetime.start(i64, $ptyp* nocapture)" - instrs = "%ptr = inttoptr $JULIAPOINTERTYPE %0 to $ptyp*\ncall void @llvm.lifetime.start(i64 $L, $ptyp* %ptr)\nret void" + decl = "declare void @llvm.lifetime.start(i64, ptr nocapture)" + instrs = "call void @llvm.lifetime.start(i64 $L, ptr %0)\nret void" llvmcall_expr( decl, instrs, From 87fd6827639a5a022003cc1950da7bcdb12922e9 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 18:44:11 +0800 Subject: [PATCH 05/20] memory_addr.lifetime.end: use opaque pointer --- src/llvm_intrin/memory_addr.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index f59ce8f..eb025cb 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -2244,8 +2244,8 @@ end end @generated function lifetime_end!(ptr::Ptr{T}, ::Val{L}) where {L,T} ptyp = LLVM_TYPES[T] - decl = "declare void @llvm.lifetime.end(i64, $ptyp* nocapture)" - instrs = "%ptr = inttoptr $JULIAPOINTERTYPE %0 to $ptyp*\ncall void @llvm.lifetime.end(i64 $L, $ptyp* %ptr)\nret void" + decl = "declare void @llvm.lifetime.end(i64, ptr nocapture)" + instrs = "call void @llvm.lifetime.end(i64 $L, ptr %0)\nret void" llvmcall_expr( decl, instrs, From 12959244f80505cafa6ec2cc83804760cbdded18 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 21:22:31 +0800 Subject: [PATCH 06/20] memory_addr.prefetch: use opaque pointer --- src/llvm_intrin/memory_addr.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index eb025cb..7fb820e 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -2170,10 +2170,9 @@ end "Prefetch intrinsic requires a read/write argument of 0, 1, but received $R." ) ) - decl = "declare void @llvm.prefetch(i8*, i32, i32, i32)" + decl = "declare void @llvm.prefetch(ptr, i32, i32, i32)" instrs = """ - %addr = inttoptr $JULIAPOINTERTYPE %0 to i8* - call void @llvm.prefetch(i8* %addr, i32 $R, i32 $L, i32 1) + call void @llvm.prefetch(ptr %0, i32 $R, i32 $L, i32 1) ret void """ llvmcall_expr( From 9f161a5e1d739897fb6bdba10b9a4e2568590bf7 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Mon, 9 Jun 2025 00:27:01 +0800 Subject: [PATCH 07/20] memory_addr.offset_ptr: remove `inttoptr` --- src/llvm_intrin/memory_addr.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index 7fb820e..a3063dc 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -168,7 +168,7 @@ function offset_ptr( if iszero(O) push!( instrs, - "%ptr.$(i) = inttoptr $(JULIAPOINTERTYPE) %0 to $(index_gep_typ)*" + "%ptr.$(i) = bitcast ptr %0 to ptr" # do-nothing ) i += 1 else # !iszero(O) @@ -181,7 +181,7 @@ function offset_ptr( end push!( instrs, - "%ptr.$(i) = inttoptr $(JULIAPOINTERTYPE) %0 to $(offset_gep_typ)*" + "%ptr.$(i) = bitcast ptr %0 to ptr" # do-nothing ) i += 1 push!( From 8bae6f53b4b6575b88d0c7424629beaca3f09934 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Mon, 9 Jun 2025 00:28:36 +0800 Subject: [PATCH 08/20] memory_addr.offset_ptr: remove `ptrtoint` --- src/llvm_intrin/memory_addr.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index a3063dc..d4fb09c 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -192,7 +192,7 @@ function offset_ptr( if forgep && iszero(M) && (iszero(X) || isone(X)) push!( instrs, - "%ptr.$(i) = ptrtoint $(offset_gep_typ)* %ptr.$(i-1) to $(JULIAPOINTERTYPE)" + "%ptr.$(i) = bitcast ptr %ptr.$(i-1) to ptr" # do-nothiong ) i += 1 return instrs, i @@ -224,7 +224,7 @@ function offset_ptr( if forgep push!( instrs, - "%ptr.$(i) = ptrtoint <$W x $index_gep_typ*> %ptr.$(i-1) to <$W x $JULIAPOINTERTYPE>" + "%ptr.$(i) = bitcast <$W x ptr> %ptr.$(i-1) to <$W x ptr>" # do-nothing ) i += 1 elseif index_gep_typ != vtyp @@ -305,7 +305,7 @@ function offset_ptr( if forgep push!( instrs, - "%ptr.$(i) = ptrtoint <$W x $typ*> %ptr.$(i-1) to <$W x $JULIAPOINTERTYPE>" + "%ptr.$(i) = bitcast <$W x ptr> %ptr.$(i-1) to <$W x ptr>" # do-nothing ) i += 1 end @@ -314,7 +314,7 @@ function offset_ptr( if forgep # if forgep, just return now push!( instrs, - "%ptr.$(i) = ptrtoint $(index_gep_typ)* %ptr.$(i-1) to $JULIAPOINTERTYPE" + "%ptr.$(i) = bitcast ptr %ptr.$(i-1) to ptr" # do-nothing ) i += 1 elseif index_gep_typ != vtyp From 1b45d447cbcecf80afcb96c320d0b9a88cae67c1 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Mon, 9 Jun 2025 00:30:11 +0800 Subject: [PATCH 09/20] memory_addr.offset_ptr: remove `ptrtoint` --- src/llvm_intrin/memory_addr.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index d4fb09c..2174fc4 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -199,7 +199,7 @@ function offset_ptr( elseif offset_gep_typ != index_gep_typ push!( instrs, - "%ptr.$(i) = bitcast $(offset_gep_typ)* %ptr.$(i-1) to $(index_gep_typ)*" + "%ptr.$(i) = bitcast ptr %ptr.$(i-1) to ptr" # do-nothing ) i += 1 end @@ -230,7 +230,7 @@ function offset_ptr( elseif index_gep_typ != vtyp push!( instrs, - "%ptr.$(i) = bitcast <$W x $index_gep_typ*> %ptr.$(i-1) to <$W x $typ*>" + "%ptr.$(i) = bitcast <$W x ptr> %ptr.$(i-1) to <$W x ptr>" # do-nothing ) i += 1 end @@ -293,7 +293,7 @@ function offset_ptr( if typ !== index_gep_typ push!( instrs, - "%ptr.$(i) = bitcast $(index_gep_typ)* %ptr.$(i-1) to $(typ)*" + "%ptr.$(i) = bitcast ptr %ptr.$(i-1) to ptr" # do-nothing ) i += 1 end @@ -320,7 +320,7 @@ function offset_ptr( elseif index_gep_typ != vtyp push!( instrs, - "%ptr.$(i) = bitcast $(index_gep_typ)* %ptr.$(i-1) to $(vtyp)*" + "%ptr.$(i) = bitcast ptr %ptr.$(i-1) to ptr" # do-nothing ) i += 1 end From 69d4855c21a06720c97e07a32a50fd011e9e6757 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Mon, 9 Jun 2025 00:31:55 +0800 Subject: [PATCH 10/20] memory_addr.offset_ptr: fix `getelementptr` --- src/llvm_intrin/memory_addr.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index 2174fc4..bffd505 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -186,7 +186,7 @@ function offset_ptr( i += 1 push!( instrs, - "%ptr.$(i) = getelementptr inbounds $(offset_gep_typ), $(offset_gep_typ)* %ptr.$(i-1), i32 $(offset)" + "%ptr.$(i) = getelementptr inbounds $(offset_gep_typ), ptr %ptr.$(i-1), i32 $(offset)" ) i += 1 if forgep && iszero(M) && (iszero(X) || isone(X)) @@ -218,7 +218,7 @@ function offset_ptr( end push!( instrs, - "%ptr.$(i) = getelementptr inbounds $(index_gep_typ), $(index_gep_typ)* %ptr.$(i-1), <$W x i$(ibits)> %$(indname)" + "%ptr.$(i) = getelementptr inbounds $(index_gep_typ), ptr %ptr.$(i-1), <$W x i$(ibits)> %$(indname)" ) i += 1 if forgep @@ -278,7 +278,7 @@ function offset_ptr( end push!( instrs, - "%ptr.$(i) = getelementptr inbounds $(index_gep_typ), $(index_gep_typ)* %ptr.$(i-1), i$(ibits) %$(indname)" + "%ptr.$(i) = getelementptr inbounds $(index_gep_typ), ptr %ptr.$(i-1), i$(ibits) %$(indname)" ) i += 1 end @@ -299,7 +299,7 @@ function offset_ptr( end push!( instrs, - "%ptr.$(i) = getelementptr inbounds $(typ), $(typ)* %ptr.$(i-1), <$W x $(vityp)> <$vityp $vi>" + "%ptr.$(i) = getelementptr inbounds $(typ), ptr %ptr.$(i-1), <$W x $(vityp)> <$vityp $vi>" ) i += 1 if forgep From a8b99642394487ca56f2f3cdb8a38134c47a3b26 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Sun, 8 Jun 2025 23:58:26 +0800 Subject: [PATCH 11/20] memory_addr: fix vstore_quote --- src/llvm_intrin/memory_addr.jl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index bffd505..5860c4c 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -1254,33 +1254,33 @@ function vstore_quote( suffix(W, T_sym) * '.' * ptr_suffix(W, T_sym) - decl *= "declare $storeinstr($vtyp, <$W x $typ*>, i32, <$W x i1>)" + decl *= "declare $storeinstr($vtyp, <$W x ptr>, i32, <$W x i1>)" m = mask ? m = "%mask.0" : llvmconst(W, "i1 1") push!( instrs, - "call $storeinstr($vtyp $(argtostore), <$W x $typ*> %ptr.$(i-1), i32 $alignment, <$W x i1> $m)" * + "call $storeinstr($vtyp $(argtostore), <$W x ptr> %ptr.$(i-1), i32 $alignment, <$W x i1> $m)" * metadata ) - # push!(instrs, "call $storeinstr($vtyp $(argtostore), <$W x $typ*> %ptr.$(i-1), i32 $alignment, <$W x i1> $m)") + # push!(instrs, "call $storeinstr($vtyp $(argtostore), <$W x ptr> %ptr.$(i-1), i32 $alignment, <$W x i1> $m)") elseif mask suff = suffix(W, T_sym) storeinstr = "void @llvm.masked.store." * suff * ".p0" * suff - decl *= "declare $storeinstr($vtyp, $vtyp*, i32, <$W x i1>)" + decl *= "declare $storeinstr($vtyp, ptr, i32, <$W x i1>)" push!( instrs, - "call $storeinstr($vtyp $(argtostore), $vtyp* %ptr.$(i-1), i32 $alignment, <$W x i1> %mask.0)" * + "call $storeinstr($vtyp $(argtostore), ptr %ptr.$(i-1), i32 $alignment, <$W x i1> %mask.0)" * metadata ) elseif nontemporal push!( instrs, - "store $vtyp $(argtostore), $vtyp* %ptr.$(i-1), align $alignment, !nontemporal !{i32 1}" * + "store $vtyp $(argtostore), ptr %ptr.$(i-1), align $alignment, !nontemporal !{i32 1}" * metadata ) else push!( instrs, - "store $vtyp $(argtostore), $vtyp* %ptr.$(i-1), align $alignment" * + "store $vtyp $(argtostore), ptr %ptr.$(i-1), align $alignment" * metadata ) end @@ -1298,7 +1298,7 @@ function vstore_quote( else Expr(:curly, :Tuple, ptrtyp, T_sym) end - largs = String[JULIAPOINTERTYPE, vtyp] + largs = String["ptr", vtyp] arg_syms = Union{Symbol,Expr}[:ptr, Expr(:call, :data, :v)] if dynamic_index push!(arg_syms, :(data(i))) From 66451ef956950f44830211870e316bd784707550 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Mon, 9 Jun 2025 00:00:10 +0800 Subject: [PATCH 12/20] memory_addr: fix vload_quote_llvmcall_core --- src/llvm_intrin/memory_addr.jl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index 5860c4c..9a17f34 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -822,27 +822,27 @@ function vload_quote_llvmcall_core( suffix(W, T_sym) * '.' * ptr_suffix(W, T_sym) - decl *= "declare $loadinstr(<$W x $typ*>, i32, <$W x i1>, $vtyp)" + decl *= "declare $loadinstr(<$W x ptr>, i32, <$W x i1>, $vtyp)" m = mask ? m = "%mask.0" : llvmconst(W, "i1 1") passthrough = mask ? "zeroinitializer" : "undef" push!( instrs, - "%res = call $loadinstr(<$W x $typ*> %ptr.$(i-1), i32 $alignment, <$W x i1> $m, $vtyp $passthrough)" * + "%res = call $loadinstr(<$W x ptr> %ptr.$(i-1), i32 $alignment, <$W x i1> $m, $vtyp $passthrough)" * LOAD_SCOPE_TBAA_FLAGS ) elseif mask suff = suffix(W, T_sym) loadinstr = "$vtyp @llvm.masked.load." * suff * ".p0" * suff - decl *= "declare $loadinstr($vtyp*, i32, <$W x i1>, $vtyp)" + decl *= "declare $loadinstr(ptr, i32, <$W x i1>, $vtyp)" push!( instrs, - "%res = call $loadinstr($vtyp* %ptr.$(i-1), i32 $alignment, <$W x i1> %mask.0, $vtyp zeroinitializer)" * + "%res = call $loadinstr(ptr %ptr.$(i-1), i32 $alignment, <$W x i1> %mask.0, $vtyp zeroinitializer)" * LOAD_SCOPE_TBAA_FLAGS ) else push!( instrs, - "%res = load $vtyp, $vtyp* %ptr.$(i-1), align $alignment" * + "%res = load $vtyp, ptr %ptr.$(i-1), align $alignment" * LOAD_SCOPE_TBAA_FLAGS ) end @@ -886,7 +886,7 @@ function vload_quote_llvmcall_core( end end args = Expr(:curly, :Tuple, Expr(:curly, :Ptr, T_sym)) - largs = String[JULIAPOINTERTYPE] + largs = String["ptr"] arg_syms = Union{Symbol,Expr}[:ptr] if dynamic_index push!(arg_syms, :(data(i))) From 8b1a943f00d39326fc73c741e80ffd38287d0329 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Mon, 9 Jun 2025 00:34:20 +0800 Subject: [PATCH 13/20] memory_addr.gep_quote: fix `lret` and `largs` --- src/llvm_intrin/memory_addr.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index 9a17f34..ef07792 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -373,14 +373,14 @@ function gep_quote( # ::Type{T}, ind_type::Symbol, indargname = '1', ibytes::Int, W::Int = 1, X::Int = 1, M::Int = 1, O::Int = 0, forgep::Bool = false instrs, i = offset_ptr(T_sym, ind_type, '1', ibits, W, X, M, O, true, rs) ret = Expr(:curly, :Ptr, T_sym) - lret = JULIAPOINTERTYPE + lret = "ptr" if gep_returns_vector(W, X, M, ind_type) ret = Expr(:curly, :_Vec, W, ret) lret = "<$W x $lret>" end args = Expr(:curly, :Tuple, Expr(:curly, :Ptr, T_sym)) - largs = String[JULIAPOINTERTYPE] + largs = String["ptr"] arg_syms = Union{Symbol,Expr}[:ptr] if !(iszero(M) || ind_type === :StaticInt) From 34be75acd5c1c11fd8b41472cf316c3cfed08c1d Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Mon, 9 Jun 2025 01:01:30 +0800 Subject: [PATCH 14/20] ci: Update nightly --- .github/workflows/ci-julia-nightly.yml | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ci-julia-nightly.yml b/.github/workflows/ci-julia-nightly.yml index 266ad2b..ae43ddc 100644 --- a/.github/workflows/ci-julia-nightly.yml +++ b/.github/workflows/ci-julia-nightly.yml @@ -9,7 +9,7 @@ on: tags: '*' jobs: test-julia-nightly: - name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }} + name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ github.event_name }} runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -18,29 +18,18 @@ jobs: - 'nightly' os: - ubuntu-latest - - macOS-latest + - macOS-latest # Arm - windows-latest - arch: - - x64 + # Use default arch steps: - uses: actions/checkout@v4 - uses: julia-actions/setup-julia@v2 with: version: ${{ matrix.version }} - arch: ${{ matrix.arch }} - - uses: actions/cache@v4 - env: - cache-name: cache-artifacts - with: - path: ~/.julia/artifacts - key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }} - restore-keys: | - ${{ runner.os }}-test-${{ env.cache-name }}- - ${{ runner.os }}-test- - ${{ runner.os }}- + - uses: julia-actions/cache@v2 - uses: julia-actions/julia-buildpkg@v1 - uses: julia-actions/julia-runtest@v1 - uses: julia-actions/julia-processcoverage@v1 - - uses: codecov/codecov-action@v3 + - uses: codecov/codecov-action@v5 with: - file: lcov.info + files: lcov.info From 5162645cea0e9592db3ed3b4a7cba2fec213ac4f Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Mon, 9 Jun 2025 01:30:30 +0800 Subject: [PATCH 15/20] ci.Aqua: turn off piracy tests --- test/runtests.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index 7afe72e..1f8363d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -9,7 +9,10 @@ include("testsetup.jl") println("Aqua.test_all") t0 = time_ns() deps_compat = VERSION <= v"1.8" || isempty(VERSION.prerelease) - Aqua.test_all(VectorizationBase; deps_compat = deps_compat) + Aqua.test_all(VectorizationBase; + deps_compat = deps_compat, + piracies=false + ) println("Aqua took $((time_ns() - t0)*1e-9) seconds") # @test isempty(detect_unbound_args(VectorizationBase)) # @test isempty(detect_ambiguities(VectorizationBase)) From 54beef3de01ad213accf23e90594a9bf64f84fc2 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Mon, 9 Jun 2025 01:47:16 +0800 Subject: [PATCH 16/20] doc: update jldoctest --- src/VectorizationBase.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/VectorizationBase.jl b/src/VectorizationBase.jl index 16b594e..cd6cb62 100644 --- a/src/VectorizationBase.jl +++ b/src/VectorizationBase.jl @@ -167,7 +167,7 @@ julia> rgbs = [ B = Float32(i + 200) / 255 ) for i = 0:7:49 ] -8-element Vector{NamedTuple{(:R, :G, :B), Tuple{Float32, Float32, Float32}}}: +8-element Vector{@NamedTuple{R::Float32, G::Float32, B::Float32}}: (R = 0.0, G = 0.39215687, B = 0.78431374) (R = 0.02745098, G = 0.41960785, B = 0.8117647) (R = 0.05490196, G = 0.44705883, B = 0.8392157) From f26e2088f419b8b961103944bed03faa7e4ccd0e Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Mon, 9 Jun 2025 01:47:28 +0800 Subject: [PATCH 17/20] ci: Move doc CI to `doc.yml` --- .github/workflows/ci.yml | 43 ------------------------------- .github/workflows/doc.yml | 53 +++++++++++++++++++++++++++++++++++++++ docs/make.jl | 3 ++- 3 files changed, 55 insertions(+), 44 deletions(-) create mode 100644 .github/workflows/doc.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6d860d0..eac35b5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -44,46 +44,3 @@ jobs: - uses: codecov/codecov-action@v3 with: file: lcov.info - docs: - name: Documentation - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 - with: - version: 'nightly' - - run: julia --color=yes -e 'using Pkg; VERSION >= v"1.5-" && !isdir(joinpath(DEPOT_PATH[1], "registries", "General")) && Pkg.Registry.add("General")' - shell: bash - env: - JULIA_PKG_SERVER: "" - - run: | - julia --project=docs -e ' - using Pkg - Pkg.develop(PackageSpec(path=pwd())) - Pkg.instantiate()' - - run: julia --project=docs docs/make.jl - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} - doctests: - name: Doctests - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: julia-actions/setup-julia@v2 - with: - version: 'nightly' - - run: julia --color=yes -e 'using Pkg; VERSION >= v"1.5-" && !isdir(joinpath(DEPOT_PATH[1], "registries", "General")) && Pkg.Registry.add("General")' - shell: bash - env: - JULIA_PKG_SERVER: "" - - run: | - julia --project=docs -e ' - using Pkg - Pkg.develop(PackageSpec(path=pwd())) - Pkg.instantiate()' - - run: | - julia --project=docs -e ' - using Documenter: doctest - using VectorizationBase - doctest(VectorizationBase)' diff --git a/.github/workflows/doc.yml b/.github/workflows/doc.yml new file mode 100644 index 0000000..2605c05 --- /dev/null +++ b/.github/workflows/doc.yml @@ -0,0 +1,53 @@ +name: Docs +on: + pull_request: + branches: + - master + push: + branches: + - master + tags: '*' +jobs: + doctests: + name: Doctests + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: 'nightly' + - uses: julia-actions/cache@v2 + - uses: julia-actions/julia-buildpkg@v1 + - name: Configure doc environment + shell: julia --project=docs --color=yes {0} + run: | + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate() + - name: Run doctest + shell: julia --color=yes --project=docs {0} + run: | + using Documenter: doctest + using VectorizationBase + doctest(VectorizationBase) + deploydocs: + name: Deploy Documentation + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: julia-actions/setup-julia@v2 + with: + version: 'nightly' + - uses: julia-actions/cache@v2 + - uses: julia-actions/julia-buildpkg@v1 + - name: Configure doc environment + shell: julia --project=docs --color=yes {0} + run: | + using Pkg + Pkg.develop(PackageSpec(path=pwd())) + Pkg.instantiate() + - uses: julia-actions/julia-buildpkg@v1 + - uses: julia-actions/julia-docdeploy@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }} diff --git a/docs/make.jl b/docs/make.jl index 0383bc0..005be85 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -1,6 +1,8 @@ using VectorizationBase using Documenter +DocMeta.setdocmeta!(VectorizationBase, :DocTestSetup, :(using VectorizationBase); recursive=true) + makedocs(; modules = [VectorizationBase], authors = "Chris Elrod", @@ -11,7 +13,6 @@ makedocs(; canonical = "https://JuliaSIMD.github.io/VectorizationBase.jl" ), pages = ["Home" => "index.md"], - strict = false ) deploydocs(; repo = "github.com/JuliaSIMD/VectorizationBase.jl") From c679829909b6f77d9b53f06d4926411417f223a3 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Fri, 20 Jun 2025 00:57:34 +0800 Subject: [PATCH 18/20] llvmcall: fix compatibility with Julia1.6 --- src/llvm_intrin/memory_addr.jl | 234 +++++++++++++++++++++++---------- src/llvm_intrin/vbroadcast.jl | 12 +- src/llvm_types.jl | 8 ++ 3 files changed, 180 insertions(+), 74 deletions(-) diff --git a/src/llvm_intrin/memory_addr.jl b/src/llvm_intrin/memory_addr.jl index ef07792..8b08ffb 100644 --- a/src/llvm_intrin/memory_addr.jl +++ b/src/llvm_intrin/memory_addr.jl @@ -166,10 +166,12 @@ function offset_ptr( end # after this block, we will have a index_gep_typ pointer if iszero(O) - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = bitcast ptr %0 to ptr" # do-nothing - ) + else + "%ptr.$(i) = inttoptr $(JULIAPOINTERTYPE) %0 to $(index_gep_typ)*" + end + push!(instrs, instr) i += 1 else # !iszero(O) if !iszero(O & (tzf - 1)) # then index_gep_typ works for the constant offset @@ -179,28 +181,36 @@ function offset_ptr( offset_gep_typ = index_gep_typ offset = O >> tz end - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = bitcast ptr %0 to ptr" # do-nothing - ) + else + "%ptr.$(i) = inttoptr $(JULIAPOINTERTYPE) %0 to $(offset_gep_typ)*" + end + push!(instrs, instr) i += 1 - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = getelementptr inbounds $(offset_gep_typ), ptr %ptr.$(i-1), i32 $(offset)" - ) + else + "%ptr.$(i) = getelementptr inbounds $(offset_gep_typ), $(offset_gep_typ)* %ptr.$(i-1), i32 $(offset)" + end + push!(instrs, instr) i += 1 if forgep && iszero(M) && (iszero(X) || isone(X)) - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = bitcast ptr %ptr.$(i-1) to ptr" # do-nothiong - ) + else + "%ptr.$(i) = ptrtoint $(offset_gep_typ)* %ptr.$(i-1) to $(JULIAPOINTERTYPE)" + end + push!(instrs, instr) i += 1 return instrs, i elseif offset_gep_typ != index_gep_typ - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = bitcast ptr %ptr.$(i-1) to ptr" # do-nothing - ) + else + "%ptr.$(i) = bitcast $(offset_gep_typ)* %ptr.$(i-1) to $(index_gep_typ)*" + end + push!(instrs, instr) i += 1 end end @@ -216,22 +226,28 @@ function offset_ptr( "%$(indname) = mul nsw <$W x i$(ibits)> %$(indargname), $(constmul)" ) end - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = getelementptr inbounds $(index_gep_typ), ptr %ptr.$(i-1), <$W x i$(ibits)> %$(indname)" - ) + else + "%ptr.$(i) = getelementptr inbounds $(index_gep_typ), $(index_gep_typ)* %ptr.$(i-1), <$W x i$(ibits)> %$(indname)" + end + push!(instrs, instr) i += 1 if forgep - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = bitcast <$W x ptr> %ptr.$(i-1) to <$W x ptr>" # do-nothing - ) + else + "%ptr.$(i) = ptrtoint <$W x $index_gep_typ*> %ptr.$(i-1) to <$W x $JULIAPOINTERTYPE>" + end + push!(instrs, instr) i += 1 elseif index_gep_typ != vtyp - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = bitcast <$W x ptr> %ptr.$(i-1) to <$W x ptr>" # do-nothing - ) + else + "%ptr.$(i) = bitcast <$W x $index_gep_typ*> %ptr.$(i-1) to <$W x $typ*>" + end + push!(instrs, instr) i += 1 end return instrs, i @@ -276,10 +292,12 @@ function offset_ptr( end # TODO: if X != 1 and X != 0, check if it is better to gep -> gep, or broadcast -> add -> gep end - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = getelementptr inbounds $(index_gep_typ), ptr %ptr.$(i-1), i$(ibits) %$(indname)" - ) + else + "%ptr.$(i) = getelementptr inbounds $(index_gep_typ), $(index_gep_typ)* %ptr.$(i-1), i$(ibits) %$(indname)" + end + push!(instrs, instr) i += 1 end # ind_type === :Integer || ind_type === :StaticInt @@ -291,37 +309,47 @@ function offset_ptr( vityp = "i$(8vibytes)" vi = join((X * w for w ∈ 0:W-1), ", $vityp ") if typ !== index_gep_typ - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = bitcast ptr %ptr.$(i-1) to ptr" # do-nothing - ) + else + "%ptr.$(i) = bitcast $(index_gep_typ)* %ptr.$(i-1) to $(typ)*" + end + push!(instrs, instr) i += 1 end - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = getelementptr inbounds $(typ), ptr %ptr.$(i-1), <$W x $(vityp)> <$vityp $vi>" - ) + else + "%ptr.$(i) = getelementptr inbounds $(typ), $(typ)* %ptr.$(i-1), <$W x $(vityp)> <$vityp $vi>" + end + push!(instrs, instr) i += 1 if forgep - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = bitcast <$W x ptr> %ptr.$(i-1) to <$W x ptr>" # do-nothing - ) + else + "%ptr.$(i) = ptrtoint <$W x $typ*> %ptr.$(i-1) to <$W x $JULIAPOINTERTYPE>" + end + push!(instrs, instr) i += 1 end return instrs, i end if forgep # if forgep, just return now - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = bitcast ptr %ptr.$(i-1) to ptr" # do-nothing - ) + else + "%ptr.$(i) = ptrtoint $(index_gep_typ)* %ptr.$(i-1) to $JULIAPOINTERTYPE" + end + push!(instrs, instr) i += 1 elseif index_gep_typ != vtyp - push!( - instrs, + instr = @static if USE_OPAQUE_PTR "%ptr.$(i) = bitcast ptr %ptr.$(i-1) to ptr" # do-nothing - ) + else + "%ptr.$(i) = bitcast $(index_gep_typ)* %ptr.$(i-1) to $(vtyp)*" + end + push!(instrs, instr) i += 1 end instrs, i @@ -373,14 +401,22 @@ function gep_quote( # ::Type{T}, ind_type::Symbol, indargname = '1', ibytes::Int, W::Int = 1, X::Int = 1, M::Int = 1, O::Int = 0, forgep::Bool = false instrs, i = offset_ptr(T_sym, ind_type, '1', ibits, W, X, M, O, true, rs) ret = Expr(:curly, :Ptr, T_sym) - lret = "ptr" + lret = @static if USE_OPAQUE_PTR + "ptr" + else + JULIAPOINTERTYPE + end if gep_returns_vector(W, X, M, ind_type) ret = Expr(:curly, :_Vec, W, ret) lret = "<$W x $lret>" end args = Expr(:curly, :Tuple, Expr(:curly, :Ptr, T_sym)) - largs = String["ptr"] + largs = @static if USE_OPAQUE_PTR + String["ptr"] + else + String[JULIAPOINTERTYPE] + end arg_syms = Union{Symbol,Expr}[:ptr] if !(iszero(M) || ind_type === :StaticInt) @@ -816,33 +852,40 @@ function vload_quote_llvmcall_core( truncate_mask!(instrs, '1' + dynamic_index, W, 0, false) end end + @static if USE_OPAQUE_PTR + ptr_type = "ptr" + vptr_type = "ptr" + else + ptr_type = "$typ*" + vptr_type = "$vtyp*" + end if grv loadinstr = "$vtyp @llvm.masked.gather." * suffix(W, T_sym) * '.' * ptr_suffix(W, T_sym) - decl *= "declare $loadinstr(<$W x ptr>, i32, <$W x i1>, $vtyp)" + decl *= "declare $loadinstr(<$W x $ptr_type>, i32, <$W x i1>, $vtyp)" m = mask ? m = "%mask.0" : llvmconst(W, "i1 1") passthrough = mask ? "zeroinitializer" : "undef" push!( instrs, - "%res = call $loadinstr(<$W x ptr> %ptr.$(i-1), i32 $alignment, <$W x i1> $m, $vtyp $passthrough)" * + "%res = call $loadinstr(<$W x $ptr_type> %ptr.$(i-1), i32 $alignment, <$W x i1> $m, $vtyp $passthrough)" * LOAD_SCOPE_TBAA_FLAGS ) elseif mask suff = suffix(W, T_sym) loadinstr = "$vtyp @llvm.masked.load." * suff * ".p0" * suff - decl *= "declare $loadinstr(ptr, i32, <$W x i1>, $vtyp)" + decl *= "declare $loadinstr($vptr_type, i32, <$W x i1>, $vtyp)" push!( instrs, - "%res = call $loadinstr(ptr %ptr.$(i-1), i32 $alignment, <$W x i1> %mask.0, $vtyp zeroinitializer)" * + "%res = call $loadinstr($vptr_type %ptr.$(i-1), i32 $alignment, <$W x i1> %mask.0, $vtyp zeroinitializer)" * LOAD_SCOPE_TBAA_FLAGS ) else push!( instrs, - "%res = load $vtyp, ptr %ptr.$(i-1), align $alignment" * + "%res = load $vtyp, $vptr_type %ptr.$(i-1), align $alignment" * LOAD_SCOPE_TBAA_FLAGS ) end @@ -886,7 +929,11 @@ function vload_quote_llvmcall_core( end end args = Expr(:curly, :Tuple, Expr(:curly, :Ptr, T_sym)) - largs = String["ptr"] + largs = @static if USE_OPAQUE_PTR + String["ptr"] + else + String[JULIAPOINTERTYPE] + end arg_syms = Union{Symbol,Expr}[:ptr] if dynamic_index push!(arg_syms, :(data(i))) @@ -1248,39 +1295,46 @@ function vstore_quote( else argtostore = "%1" end + @static if USE_OPAQUE_PTR + ptr_type = "ptr" + vptr_type = "ptr" + else + ptr_type = "$typ*" + vptr_type = "$vtyp*" + end if grv storeinstr = "void @llvm.masked.scatter." * suffix(W, T_sym) * '.' * ptr_suffix(W, T_sym) - decl *= "declare $storeinstr($vtyp, <$W x ptr>, i32, <$W x i1>)" + decl *= "declare $storeinstr($vtyp, <$W x $ptr_type>, i32, <$W x i1>)" m = mask ? m = "%mask.0" : llvmconst(W, "i1 1") push!( instrs, - "call $storeinstr($vtyp $(argtostore), <$W x ptr> %ptr.$(i-1), i32 $alignment, <$W x i1> $m)" * + "call $storeinstr($vtyp $(argtostore), <$W x $ptr_type> %ptr.$(i-1), i32 $alignment, <$W x i1> $m)" * metadata ) - # push!(instrs, "call $storeinstr($vtyp $(argtostore), <$W x ptr> %ptr.$(i-1), i32 $alignment, <$W x i1> $m)") + # push!(instrs, "call $storeinstr($vtyp $(argtostore), <$W x $ptr_type> %ptr.$(i-1), i32 $alignment, <$W x i1> $m)") elseif mask suff = suffix(W, T_sym) storeinstr = "void @llvm.masked.store." * suff * ".p0" * suff - decl *= "declare $storeinstr($vtyp, ptr, i32, <$W x i1>)" + decl *= "declare $storeinstr($vtyp, $vptr_type, i32, <$W x i1>)" push!( instrs, - "call $storeinstr($vtyp $(argtostore), ptr %ptr.$(i-1), i32 $alignment, <$W x i1> %mask.0)" * + "call $storeinstr($vtyp $(argtostore), $vptr_type %ptr.$(i-1), i32 $alignment, <$W x i1> %mask.0)" * metadata ) elseif nontemporal push!( instrs, - "store $vtyp $(argtostore), ptr %ptr.$(i-1), align $alignment, !nontemporal !{i32 1}" * + "store $vtyp $(argtostore), $vptr_type %ptr.$(i-1), align $alignment, !nontemporal !{i32 1}" * metadata ) else push!( instrs, - "store $vtyp $(argtostore), ptr %ptr.$(i-1), align $alignment" * + "store $vtyp $(argtostore), $vptr_type %ptr.$(i-1), align $alignment" * metadata ) end @@ -1298,7 +1352,12 @@ function vstore_quote( else Expr(:curly, :Tuple, ptrtyp, T_sym) end - largs = String["ptr", vtyp] + largs = @static if USE_OPAQUE_PTR + String["ptr"] + else + String[JULIAPOINTERTYPE] + end + push!(largs, vtyp) arg_syms = Union{Symbol,Expr}[:ptr, Expr(:call, :data, :v)] if dynamic_index push!(arg_syms, :(data(i))) @@ -2170,11 +2229,20 @@ end "Prefetch intrinsic requires a read/write argument of 0, 1, but received $R." ) ) - decl = "declare void @llvm.prefetch(ptr, i32, i32, i32)" - instrs = """ + @static if USE_OPAQUE_PTR + decl = "declare void @llvm.prefetch(ptr, i32, i32, i32)" + instrs = """ call void @llvm.prefetch(ptr %0, i32 $R, i32 $L, i32 1) ret void - """ + """ + else + decl = "declare void @llvm.prefetch(i8*, i32, i32, i32)" + instrs = """ + %addr = inttoptr $JULIAPOINTERTYPE %0 to i8* + call void @llvm.prefetch(i8* %addr, i32 $R, i32 $L, i32 1) + ret void + """ + end llvmcall_expr( decl, instrs, @@ -2227,8 +2295,13 @@ end @generated function lifetime_start!(ptr::Ptr{T}, ::Val{L}) where {L,T} ptyp = LLVM_TYPES[T] - decl = "declare void @llvm.lifetime.start(i64, ptr nocapture)" - instrs = "call void @llvm.lifetime.start(i64 $L, ptr %0)\nret void" + @static if USE_OPAQUE_PTR + decl = "declare void @llvm.lifetime.start(i64, ptr nocapture)" + instrs = "call void @llvm.lifetime.start(i64 $L, ptr %0)\nret void" + else + decl = "declare void @llvm.lifetime.start(i64, $ptyp* nocapture)" + instrs = "%ptr = inttoptr $JULIAPOINTERTYPE %0 to $ptyp*\ncall void @llvm.lifetime.start(i64 $L, $ptyp* %ptr)\nret void" + end llvmcall_expr( decl, instrs, @@ -2243,8 +2316,13 @@ end end @generated function lifetime_end!(ptr::Ptr{T}, ::Val{L}) where {L,T} ptyp = LLVM_TYPES[T] - decl = "declare void @llvm.lifetime.end(i64, ptr nocapture)" - instrs = "call void @llvm.lifetime.end(i64 $L, ptr %0)\nret void" + @static if USE_OPAQUE_PTR + decl = "declare void @llvm.lifetime.end(i64, ptr nocapture)" + instrs = "call void @llvm.lifetime.end(i64 $L, ptr %0)\nret void" + else + decl = "declare void @llvm.lifetime.end(i64, $ptyp* nocapture)" + instrs = "%ptr = inttoptr $JULIAPOINTERTYPE %0 to $ptyp*\ncall void @llvm.lifetime.end(i64 $L, $ptyp* %ptr)\nret void" + end llvmcall_expr( decl, instrs, @@ -2283,13 +2361,18 @@ end vtyp = "<$W x $typ>" mtyp_input = LLVM_TYPES[U] mtyp_trunc = "i$W" - instrs = String[] - # push!(instrs, "%ptr = inttoptr $JULIAPOINTERTYPE %1 to $typ*") + @static if USE_OPAQUE_PTR + ptr_type = "ptr" + instrs = String["%ptr = bitcast ptr %1 to ptr"] + else + ptr_type = "$typ*" + instrs = String["%ptr = inttoptr $JULIAPOINTERTYPE %1 to $ptr_type"] + end truncate_mask!(instrs, '2', W, 0) - decl = "declare void @llvm.masked.compressstore.$(suffix(W,T))($vtyp, ptr, <$W x i1>)" + decl = "declare void @llvm.masked.compressstore.$(suffix(W,T))($vtyp, $ptr_type, <$W x i1>)" push!( instrs, - "call void @llvm.masked.compressstore.$(suffix(W,T))($vtyp %0, ptr %1, <$W x i1> %mask.0)\nret void" + "call void @llvm.masked.compressstore.$(suffix(W,T))($vtyp %0, $ptr_type %ptr, <$W x i1> %mask.0)\nret void" ) llvmcall_expr( decl, @@ -2310,20 +2393,27 @@ end ) where {W,T<:NativeTypes,U<:Unsigned} typ = LLVM_TYPES[T] vtyp = "<$W x $typ>" + vptrtyp = "<$W x $typ*>" mtyp_input = LLVM_TYPES[U] mtyp_trunc = "i$W" instrs = String[] - # push!(instrs, "%ptr = inttoptr $JULIAPOINTERTYPE %0 to $typ*") + @static if USE_OPAQUE_PTR + ptr_type = "ptr" + push!(instrs, "%ptr = bitcast ptr %1 to ptr") + else + ptr_type = "$typ*" + push!(instrs, "%ptr = inttoptr $JULIAPOINTERTYPE %0 to $ptr_type") + end if mtyp_input == mtyp_trunc push!(instrs, "%mask = bitcast $mtyp_input %1 to <$W x i1>") else push!(instrs, "%masktrunc = trunc $mtyp_input %1 to $mtyp_trunc") push!(instrs, "%mask = bitcast $mtyp_trunc %masktrunc to <$W x i1>") end - decl = "declare $vtyp @llvm.masked.expandload.$(suffix(W,T))(ptr, <$W x i1>, $vtyp)" + decl = "declare $vtyp @llvm.masked.expandload.$(suffix(W,T))($ptr_type, <$W x i1>, $vtyp)" push!( instrs, - "%res = call $vtyp @llvm.masked.expandload.$(suffix(W,T))(ptr %0, <$W x i1> %mask, $vtyp zeroinitializer)\nret $vtyp %res" + "%res = call $vtyp @llvm.masked.expandload.$(suffix(W,T))($ptr_type %ptr, <$W x i1> %mask, $vtyp zeroinitializer)\nret $vtyp %res" ) llvmcall_expr( decl, diff --git a/src/llvm_intrin/vbroadcast.jl b/src/llvm_intrin/vbroadcast.jl index ad8a01a..ef4aac4 100644 --- a/src/llvm_intrin/vbroadcast.jl +++ b/src/llvm_intrin/vbroadcast.jl @@ -164,10 +164,18 @@ end ) where {W,T} isone(W) && return Expr(:block, Expr(:meta, :inline), :(vload(ptr))) typ = LLVM_TYPES[T] + ptyp = JULIAPOINTERTYPE vtyp = "<$W x $typ>" alignment = Base.datatype_alignment(T) - instrs = """ - %res = load $typ, ptr %0, align $alignment + instrs = @static if USE_OPAQUE_PTR + "%res = load $typ, ptr %0, align $alignment" + else + """ + %ptr = inttoptr $ptyp %0 to $typ* + %res = load $typ, $typ* %ptr, align $alignment + """ + end + instrs *= """ %ie = insertelement $vtyp undef, $typ %res, i32 0 %v = shufflevector $vtyp %ie, $vtyp undef, <$W x i32> zeroinitializer ret $vtyp %v diff --git a/src/llvm_types.jl b/src/llvm_types.jl index 266ceb2..0456428 100644 --- a/src/llvm_types.jl +++ b/src/llvm_types.jl @@ -114,6 +114,14 @@ function _get_alignment(W::Int, sym::Symbol)::Int end end +""" +use opaque pointer + +Ref: +- Switch LLVM codegen of Ptr{T} to an actual pointer type. + https://github.com/JuliaLang/julia/pull/53687 +""" +const USE_OPAQUE_PTR = VERSION >= v"1.12-DEV" const JULIAPOINTERTYPE = 'i' * string(8sizeof(Int)) vtype(W, typ::String) = (isone(abs(W)) ? typ : "<$W x $typ>")::String From 6c9dad56d62442fbf5d2bcb1a72fe978e8829581 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Fri, 20 Jun 2025 01:13:42 +0800 Subject: [PATCH 19/20] test: fix Auqa compat warn --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 4673363..819539e 100644 --- a/Project.toml +++ b/Project.toml @@ -26,6 +26,7 @@ LinearAlgebra = "1" SIMDTypes = "0.1" Static = "0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 1" StaticArrayInterface = "1" +Test = "<0.0.1, 1" julia = "1.6" [extras] From e90e946a5bf450a7ad8a8eef60fbf8fc9ed85de5 Mon Sep 17 00:00:00 2001 From: Chengyu HAN Date: Fri, 20 Jun 2025 01:14:38 +0800 Subject: [PATCH 20/20] ci: test with macOS-13 --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eac35b5..10c1326 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - '^1.6.0-0' os: - ubuntu-latest - - macOS-latest + - macos-13 # Intel - windows-latest arch: - x64