-
Notifications
You must be signed in to change notification settings - Fork 30
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
Migrate to opaque pointers #112
base: master
Are you sure you want to change the base?
Changes from 10 commits
ad70b42
23b80fa
5eb62ea
24c5868
7eeea13
0e8a192
03683dc
e6fd5e4
e019f1f
ac7d9a8
856f371
cc2473c
8d805a3
c4cab11
2017591
358e3c4
8b19ddb
d0340fd
84f77f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,7 @@ function offset_ptr( | |
if iszero(O) | ||
push!( | ||
instrs, | ||
"%ptr.$(i) = inttoptr $(JULIAPOINTERTYPE) %0 to $(index_gep_typ)*" | ||
"%ptr.$(i) = load $(index_gep_typ)*, ptr %0" | ||
) | ||
i += 1 | ||
else # !iszero(O) | ||
|
@@ -181,25 +181,25 @@ function offset_ptr( | |
end | ||
push!( | ||
instrs, | ||
"%ptr.$(i) = inttoptr $(JULIAPOINTERTYPE) %0 to $(offset_gep_typ)*" | ||
"%ptr.$(i) = load $(offset_gep_typ)*, ptr %0" | ||
) | ||
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)) | ||
push!( | ||
instrs, | ||
"%ptr.$(i) = ptrtoint $(offset_gep_typ)* %ptr.$(i-1) to $(JULIAPOINTERTYPE)" | ||
"%ptr.$(i) = load $(index_gep_typ)*, ptr %ptr.$(i-1)" | ||
) | ||
i += 1 | ||
return instrs, i | ||
elseif offset_gep_typ != index_gep_typ | ||
push!( | ||
instrs, | ||
"%ptr.$(i) = bitcast $(offset_gep_typ)* %ptr.$(i-1) to $(index_gep_typ)*" | ||
"%ptr.$(i) = load $(index_gep_typ)*, ptr %ptr.$(i-1)" | ||
) | ||
i += 1 | ||
end | ||
|
@@ -218,19 +218,19 @@ 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 | ||
push!( | ||
instrs, | ||
"%ptr.$(i) = ptrtoint <$W x $index_gep_typ*> %ptr.$(i-1) to <$W x $JULIAPOINTERTYPE>" | ||
"%ptr.$(i) = load <$W x ptr>, ptr %ptr.$(i-1)" | ||
) | ||
i += 1 | ||
elseif index_gep_typ != vtyp | ||
push!( | ||
instrs, | ||
"%ptr.$(i) = bitcast <$W x $index_gep_typ*> %ptr.$(i-1) to <$W x $typ*>" | ||
"%ptr.$(i) = load <$W x ptr>, ptr %ptr.$(i-1)" | ||
) | ||
i += 1 | ||
end | ||
|
@@ -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 | ||
|
@@ -293,19 +293,19 @@ function offset_ptr( | |
if typ !== index_gep_typ | ||
push!( | ||
instrs, | ||
"%ptr.$(i) = bitcast $(index_gep_typ)* %ptr.$(i-1) to $(typ)*" | ||
"%ptr.$(i) = load $(typ)*, ptr %ptr.$(i-1)" | ||
) | ||
i += 1 | ||
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 | ||
push!( | ||
instrs, | ||
"%ptr.$(i) = ptrtoint <$W x $typ*> %ptr.$(i-1) to <$W x $JULIAPOINTERTYPE>" | ||
"%ptr.$(i) = load <$W x ptr>, ptr, %ptr.$(i-1)" | ||
) | ||
i += 1 | ||
end | ||
|
@@ -314,13 +314,13 @@ 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) = load $(vtyp)*, %ptr.$(i-1)" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one I'm not sure how to bring back the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Every Minor fixes will be needed: %y = bitcast sometype* %x to someothertype*
call foo(%y) needs to become call foo(%x) but that should be relatively trivial when But that's why I'd also simplify things by having the initial definition (as an argument to the function) be named |
||
) | ||
i += 1 | ||
elseif index_gep_typ != vtyp | ||
push!( | ||
instrs, | ||
"%ptr.$(i) = bitcast $(index_gep_typ)* %ptr.$(i-1) to $(vtyp)*" | ||
"%ptr.$(i) = load $vtyp*, ptr %ptr.$(i-1)" | ||
) | ||
i += 1 | ||
end | ||
|
@@ -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 = "ptr" | ||
arg_syms = Union{Symbol,Expr}[:ptr] | ||
|
||
if !(iszero(M) || ind_type === :StaticInt) | ||
|
@@ -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 = "ptr" | ||
arg_syms = Union{Symbol,Expr}[:ptr] | ||
if dynamic_index | ||
push!(arg_syms, :(data(i))) | ||
|
@@ -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)") | ||
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" * | ||
miguelraz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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))) | ||
|
@@ -2170,10 +2170,10 @@ 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) | ||
%addr = load i8*, ptr %0 | ||
call void @llvm.prefetch(ptr %addr, i32 $R, i32 $L, i32 1) | ||
ret void | ||
""" | ||
llvmcall_expr( | ||
|
@@ -2182,7 +2182,7 @@ end | |
:Cvoid, | ||
:(Tuple{Ptr{Cvoid}}), | ||
"void", | ||
[JULIAPOINTERTYPE], | ||
["ptr"], | ||
[:ptr], | ||
false, | ||
true | ||
|
@@ -2228,31 +2228,31 @@ 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 = "%ptr = load $ptyp*, ptr %0\ncall void @llvm.lifetime.start(i64 $L, ptr %ptr)\nret void" | ||
llvmcall_expr( | ||
decl, | ||
instrs, | ||
:Cvoid, | ||
:(Tuple{Ptr{$T}}), | ||
"void", | ||
[JULIAPOINTERTYPE], | ||
["ptr"], | ||
[:ptr], | ||
false, | ||
true | ||
) | ||
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 = "%ptr = load $ptyp*, ptr %0\ncall void @llvm.lifetime.end(i64 $L, ptr %ptr)\nret void" | ||
llvmcall_expr( | ||
decl, | ||
instrs, | ||
:Cvoid, | ||
:(Tuple{Ptr{$T}}), | ||
"void", | ||
[JULIAPOINTERTYPE], | ||
["ptr"], | ||
[:ptr], | ||
false, | ||
true | ||
|
@@ -2284,20 +2284,21 @@ end | |
vtyp = "<$W x $typ>" | ||
mtyp_input = LLVM_TYPES[U] | ||
mtyp_trunc = "i$W" | ||
instrs = String["%ptr = inttoptr $JULIAPOINTERTYPE %1 to $typ*"] | ||
instrs = String["%ptr = load $typ*, ptr %1"] | ||
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 %ptr, <$W x i1> %mask.0)\nret void" | ||
) | ||
|
||
llvmcall_expr( | ||
decl, | ||
join(instrs, "\n"), | ||
:Cvoid, | ||
:(Tuple{_Vec{$W,$T},Ptr{$T},$U}), | ||
"void", | ||
[vtyp, JULIAPOINTERTYPE, "i$(8sizeof(U))"], | ||
[vtyp, "ptr", "i$(8sizeof(U))"], | ||
[:(data(v)), :ptr, :(data(mask))], | ||
false, | ||
true | ||
|
@@ -2310,29 +2311,29 @@ end | |
) where {W,T<:NativeTypes,U<:Unsigned} | ||
typ = LLVM_TYPES[T] | ||
vtyp = "<$W x $typ>" | ||
vptrtyp = "<$W x $typ*>" | ||
vptrtyp = "<$W x ptr>" | ||
mtyp_input = LLVM_TYPES[U] | ||
mtyp_trunc = "i$W" | ||
instrs = String[] | ||
push!(instrs, "%ptr = inttoptr $JULIAPOINTERTYPE %0 to $typ*") | ||
push!(instrs, "%ptr = load $typ*, ptr %0") | ||
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 %ptr, <$W x i1> %mask, $vtyp zeroinitializer)\nret $vtyp %res" | ||
) | ||
llvmcall_expr( | ||
decl, | ||
join(instrs, "\n"), | ||
:(_Vec{$W,$T}), | ||
:(Tuple{Ptr{$T},$U}), | ||
vtyp, | ||
[JULIAPOINTERTYPE, "i$(8sizeof(U))"], | ||
["ptr"], | ||
miguelraz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
[:ptr, :(data(mask))], | ||
false, | ||
true | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They shouldn't be loads at all. There shouldn't be statements here at all; they should simply be deleted.
I'd suggest renaming the argument from
@foo(ptr %0)
to@foo(ptr %ptr.0)
so that you don't need special handling here for the initial definition.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this maneuver to get a
%ptr.0
is a bit trickier than I though. I reannotated the call sites of@foo(ptr %ptr.0)
but am still not finding all the ccases.