Skip to content

Commit

Permalink
Emit structs as LLVM structures (#34996)
Browse files Browse the repository at this point in the history
  • Loading branch information
thomasfaingnaert committed Mar 11, 2020
1 parent d5d71d7 commit 55cd761
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,10 @@ static Type *_julia_struct_to_llvm(jl_codegen_params_t *ctx, jl_value_t *jt, jl_
else if (isarray && !type_is_ghost(lasttype)) {
if (isTuple && isvector && jl_special_vector_alignment(ntypes, jlasttype) != 0)
struct_decl = VectorType::get(lasttype, ntypes);
else
else if (isTuple || !llvmcall)
struct_decl = ArrayType::get(lasttype, ntypes);
else
struct_decl = StructType::get(jl_LLVMContext, latypes);
}
else {
#if 0 // stress-test code that tries to assume julia-index == llvm-index
Expand Down
8 changes: 8 additions & 0 deletions test/llvmpasses/llvmcall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

include(joinpath("..", "testhelpers", "llvmpasses.jl"))

struct Foo
x::Int32
y::Int32
end

@generated foo(x)=:(ccall("extern foo", llvmcall, $x, ($x,), x))
bar(x) = ntuple(i -> VecElement{Float16}(x[i]), 2)

Expand All @@ -20,5 +25,8 @@ emit(foo, NTuple{2, VecElement{Float16}})
# CHECK: call i8 addrspace(3)* @foo(i8 addrspace(3)* %{{[0-9]+}})
emit(foo, Core.AddrSpacePtr{Float32, 3})

# CHECK: call { i32, i32 } @foo({ i32, i32 } %{{[0-9]+}})
emit(foo, Foo)

# CHECK: define <2 x i16> @julia_bar_{{[0-9]+}}([2 x i16]
emit(bar, NTuple{2, Float16})

0 comments on commit 55cd761

Please sign in to comment.