Skip to content
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

Add function signature to code_native and code_llvm #50630

Merged
merged 1 commit into from
Jul 23, 2023
Merged

Conversation

pchintalapudi
Copy link
Member

When getting LLVM IR from @code_llvm, it's sometimes necessary to know exactly which f is being compiled. This prints the type signature of a function in front of code_llvm and code_native to assist in that process.

Example
julia> @code_llvm zeros(64)
; Function Signature: zeros(Int64)
;  @ array.jl:629 within `zeros`
define nonnull {}* @julia_zeros_121(i64 signext %"dims[1]::Int64") #0 {
top:
;  @ array.jl:629 within `zeros` @ array.jl:631 @ array.jl:634
; ┌ @ boot.jl:484 within `Array` @ boot.jl:475
   %0 = call nonnull {}* inttoptr (i64 140604991500960 to {}* ({}*, i64)*)({}* inttoptr (i64 140604630439728 to {}*), i64 %"dims[1]::Int64")
; └
;  @ array.jl:629 within `zeros` @ array.jl:631 @ array.jl:635
; ┌ @ array.jl:392 within `fill!`
; │┌ @ abstractarray.jl:318 within `eachindex`
; ││┌ @ abstractarray.jl:134 within `axes1`
; │││┌ @ abstractarray.jl:98 within `axes`
; ││││┌ @ array.jl:191 within `size`
       %1 = bitcast {}* %0 to { i8*, i64, i16, i16, i32 }*
       %.length_ptr = getelementptr inbounds { i8*, i64, i16, i16, i32 }, { i8*, i64, i16, i16, i32 }* %1, i64 0, i32 1
       %.length = load i64, i64* %.length_ptr, align 8
; │└└└└
; │┌ @ range.jl:897 within `iterate`
; ││┌ @ range.jl:674 within `isempty`
; │││┌ @ operators.jl:378 within `>`
; ││││┌ @ int.jl:83 within `<`
       %.not.not = icmp eq i64 %.length, 0
; │└└└└
   br i1 %.not.not, label %L30, label %L13.preheader

L13.preheader:                                    ; preds = %top
   %2 = bitcast {}* %0 to i8**
   %.data1013 = load i8*, i8** %2, align 8
; │ @ array.jl:394 within `fill!`
   %3 = shl nuw i64 %.length, 3
; │ @ array.jl:393 within `fill!`
; │┌ @ array.jl:1019 within `setindex!`
    call void @llvm.memset.p0i8.i64(i8* nonnull align 8 %.data1013, i8 0, i64 %3, i1 false)
; └└
;  @ array.jl:629 within `zeros`
  br label %L30

L30:                                              ; preds = %L13.preheader, %top
  ret {}* %0
}

@pchintalapudi pchintalapudi added compiler:codegen Generation of LLVM IR and native code compiler:llvm For issues that relate to LLVM labels Jul 22, 2023
@staticfloat staticfloat merged commit 3d944dd into master Jul 23, 2023
8 checks passed
@staticfloat staticfloat deleted the pc/llvm-fname branch July 23, 2023 14:37
@gbaraldi
Copy link
Member

gbaraldi commented Aug 8, 2023

I was looking at this and was thinking, should we also print the called functions as well?

@pchintalapudi
Copy link
Member Author

There's probably some things we can do to improve the called function printing, including:

  1. Print full signature for when we can deduce the specsig (special cased for already compiled and operating in workqueue)
  2. Print the type information for when we can't deduce the specsig, so we fall back to jl_apply_generic

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code compiler:llvm For issues that relate to LLVM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants