Skip to content

Commit 85f1b8c

Browse files
authored
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`.
1 parent 2a3b722 commit 85f1b8c

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
@@ -628,13 +628,13 @@ static unsigned convert_struct_offset(jl_codectx_t &ctx, Type *lty, unsigned byt
628628

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

631-
static Type *_julia_type_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed)
631+
static Type *_julia_type_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, jl_value_t *jt, bool *isboxed, bool no_boxing)
632632
{
633633
// this function converts a Julia Type into the equivalent LLVM type
634634
if (isboxed) *isboxed = false;
635635
if (jt == (jl_value_t*)jl_bottom_type || jt == (jl_value_t*)jl_typeofbottom_type || jt == (jl_value_t*)jl_typeofbottom_type->super)
636636
return getVoidTy(ctxt);
637-
if (jl_is_concrete_immutable(jt)) {
637+
if (jl_is_concrete_immutable(jt) || no_boxing) {
638638
if (jl_datatype_nbits(jt) == 0)
639639
return getVoidTy(ctxt);
640640
Type *t = _julia_struct_to_llvm(ctx, ctxt, jt, isboxed);
@@ -647,13 +647,20 @@ static Type *_julia_type_to_llvm(jl_codegen_params_t *ctx, LLVMContext &ctxt, jl
647647

648648
static Type *julia_type_to_llvm(jl_codectx_t &ctx, jl_value_t *jt, bool *isboxed)
649649
{
650-
return _julia_type_to_llvm(&ctx.emission_context, ctx.builder.getContext(), jt, isboxed);
650+
return _julia_type_to_llvm(&ctx.emission_context, ctx.builder.getContext(), jt, isboxed, false);
651651
}
652652

653653
extern "C" JL_DLLEXPORT_CODEGEN
654654
Type *jl_type_to_llvm_impl(jl_value_t *jt, LLVMContextRef ctxt, bool *isboxed)
655655
{
656-
return _julia_type_to_llvm(NULL, *unwrap(ctxt), jt, isboxed);
656+
return _julia_type_to_llvm(NULL, *unwrap(ctxt), jt, isboxed, false);
657+
}
658+
659+
660+
extern "C" JL_DLLEXPORT_CODEGEN
661+
Type *jl_struct_to_llvm_impl(jl_value_t *jt, LLVMContextRef ctxt, bool *isboxed)
662+
{
663+
return _julia_type_to_llvm(NULL, *unwrap(ctxt), jt, isboxed, true);
657664
}
658665

659666

src/codegen-stubs.c

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

118118
JL_DLLEXPORT void *jl_type_to_llvm_fallback(jl_value_t *jt, LLVMContextRef llvmctxt, bool_t *isboxed) UNAVAILABLE
119119

120+
JL_DLLEXPORT void *jl_struct_to_llvm_fallback(jl_value_t *jt, LLVMContextRef llvmctxt, bool_t *isboxed) UNAVAILABLE
121+
120122
JL_DLLEXPORT jl_value_t *jl_get_libllvm_fallback(void) JL_NOTSAFEPOINT
121123
{
122124
return jl_nothing;

src/jl_exported_funcs.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@
535535
YY(jl_dump_fptr_asm) \
536536
YY(jl_emit_native) \
537537
YY(jl_get_function_id) \
538+
YY(jl_struct_to_llvm) \
538539
YY(jl_type_to_llvm) \
539540
YY(jl_getUnwindInfo) \
540541
YY(jl_get_libllvm) \

0 commit comments

Comments
 (0)