Skip to content

Commit f0ad92d

Browse files
wsmosesDilumAluthge
authored andcommitted
Enable getting non-boxed LLVM type from Julia Type (#56890)
The current method :jl_type_to_llvm takes a pointer-to-bool parameter isboxed, which if non-null, is set to true if the Julia Type requires boxing. However, one may want to know the julia type without boxing and there is no mechanism for doing so. Now there is `julia_struct_to_llvm`. (cherry picked from commit 85f1b8c)
1 parent 992d673 commit f0ad92d

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

src/cgutils.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -622,13 +622,13 @@ static Value *emit_struct_gep(jl_codectx_t &ctx, Type *lty, Value *base, unsigne
622622

623623
static Type *_julia_struct_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed, bool llvmcall=false);
624624

625-
static Type *_julia_type_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed)
625+
static Type *_julia_type_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed, bool no_boxing)
626626
{
627627
// this function converts a Julia Type into the equivalent LLVM type
628628
if (isboxed) *isboxed = false;
629629
if (jt == (jl_value_t*)jl_bottom_type)
630630
return getVoidTy(ctxt);
631-
if (jl_is_concrete_immutable(jt)) {
631+
if (jl_is_concrete_immutable(jt) || no_boxing) {
632632
if (jl_datatype_nbits(jt) == 0)
633633
return getVoidTy(ctxt);
634634
Type *t = _julia_struct_to_llvm(ctx, ctxt, jt, isboxed);
@@ -641,13 +641,20 @@ static Type *_julia_type_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, jl
641641

642642
static Type *julia_type_to_llvm(jl_codectx_t &ctx, jl_value_t *jt, bool *isboxed)
643643
{
644-
return _julia_type_to_llvm(&ctx.emission_context, ctx.builder.getContext(), jt, isboxed);
644+
return _julia_type_to_llvm(&ctx.emission_context, ctx.builder.getContext(), jt, isboxed, false);
645645
}
646646

647647
extern "C" JL_DLLEXPORT_CODEGEN
648648
Type *jl_type_to_llvm_impl(jl_value_t *jt, LLVMContextRef ctxt, bool *isboxed)
649649
{
650-
return _julia_type_to_llvm(NULL, *unwrap(ctxt), jt, isboxed);
650+
return _julia_type_to_llvm(NULL, *unwrap(ctxt), jt, isboxed, false);
651+
}
652+
653+
654+
extern "C" JL_DLLEXPORT_CODEGEN
655+
Type *jl_struct_to_llvm_impl(jl_value_t *jt, LLVMContextRef ctxt, bool *isboxed)
656+
{
657+
return _julia_type_to_llvm(NULL, *unwrap(ctxt), jt, isboxed, true);
651658
}
652659

653660

src/codegen-stubs.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ JL_DLLEXPORT LLVMOrcThreadSafeModuleRef jl_get_llvm_module_fallback(void *native
9797

9898
JL_DLLEXPORT void *jl_type_to_llvm_fallback(jl_value_t *jt, LLVMContextRef llvmctxt, bool_t *isboxed) UNAVAILABLE
9999

100+
JL_DLLEXPORT void *jl_struct_to_llvm_fallback(jl_value_t *jt, LLVMContextRef llvmctxt, bool_t *isboxed) UNAVAILABLE
101+
100102
JL_DLLEXPORT jl_value_t *jl_get_libllvm_fallback(void) JL_NOTSAFEPOINT
101103
{
102104
return jl_nothing;

src/jl_exported_funcs.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,7 @@
550550
YY(jl_dump_llvm_opt) \
551551
YY(jl_dump_fptr_asm) \
552552
YY(jl_get_function_id) \
553+
YY(jl_struct_to_llvm) \
553554
YY(jl_type_to_llvm) \
554555
YY(jl_getUnwindInfo) \
555556
YY(jl_get_libllvm) \

0 commit comments

Comments
 (0)