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

Debug build complains about missing DICompileUnit #1

Closed
vchuravy opened this issue Sep 10, 2019 · 4 comments · Fixed by #2
Closed

Debug build complains about missing DICompileUnit #1

vchuravy opened this issue Sep 10, 2019 · 4 comments · Fixed by #2

Comments

@vchuravy
Copy link
Member

julia> using Enzyme

julia> f(x) = 1.0 + x
f (generic function with 1 method)

julia> g(x) = Enzyme.autodiff(f, x)
g (generic function with 1 method)

julia> @code_llvm g(1.0)
saw metadata for diffe_out
DICompileUnit not listed in llvm.dbg.cu
!33 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !32, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
ERROR: LLVM error: Broken module found, compilation aborted!
Stacktrace:
 [1] handle_error(::Cstring) at /home/vchuravy/src/LLVM/src/core/context.jl:103
 [2] _dump_function_linfo(::Core.MethodInstance, ::UInt64, ::Bool, ::Bool, ::Bool, ::Bool, ::Symbol, ::Bool, ::Symbol, ::Base.CodegenParams) at /home/vchuravy/builds/julia-debug/usr/share/julia/stdlib/v1.4/InteractiveUtils/src/codeview.jl:102
 [3] _dump_function(::Any, ::Any, ::Bool, ::Bool, ::Bool, ::Bool, ::Symbol, ::Bool, ::Symbol, ::Base.CodegenParams) at /home/vchuravy/builds/julia-debug/usr/share/julia/stdlib/v1.4/InteractiveUtils/src/codeview.jl:84
 [4] _dump_function at /home/vchuravy/builds/julia-debug/usr/share/julia/stdlib/v1.4/InteractiveUtils/src/codeview.jl:71 [inlined]
 [5] code_llvm at /home/vchuravy/builds/julia-debug/usr/share/julia/stdlib/v1.4/InteractiveUtils/src/codeview.jl:132 [inlined]
 [6] #code_llvm#7 at /home/vchuravy/builds/julia-debug/usr/share/julia/stdlib/v1.4/InteractiveUtils/src/codeview.jl:134 [inlined]
 [7] (::InteractiveUtils.var"#kw##code_llvm")(::NamedTuple{(:raw, :dump_module, :optimize, :debuginfo),Tuple{Bool,Bool,Bool,Symbol}}, ::typeof(code_llvm), ::Base.TTY, ::Function, ::Type) at /home/vchuravy/builds/julia-debug/usr/share/julia/stdlib/v1.4/InteractiveUtils/src/codeview.jl:134
 [8] #code_llvm#8(::Bool, ::Bool, ::Bool, ::Symbol, ::typeof(code_llvm), ::Any, ::Any) at /home/vchuravy/builds/julia-debug/usr/share/julia/stdlib/v1.4/InteractiveUtils/src/codeview.jl:136
 [9] code_llvm(::Any, ::Any) at /home/vchuravy/builds/julia-debug/usr/share/julia/stdlib/v1.4/InteractiveUtils/src/codeview.jl:136
 [10] top-level scope at REPL[4]:1

julia>

Pre-optimization:

julia> llvmf, mod = Enzyme.emit(typeof(f), (Float64,)); mod
; ModuleID = 'f'
source_filename = "f"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:10:11:12:13"
target triple = "x86_64-pc-linux-gnu"

%jl_value_t = type opaque

; Function Attrs: sspstrong
define double @julia_f_2(double) #0 !dbg !5 {
top:
  %1 = call %jl_value_t*** @julia.ptls_states()
  %2 = bitcast %jl_value_t*** %1 to %jl_value_t addrspace(10)**
  %3 = getelementptr inbounds %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)** %2, i64 4
  %4 = bitcast %jl_value_t addrspace(10)** %3 to i64**
  %5 = load i64*, i64** %4, !tbaa !13, !invariant.load !4
  %x = alloca double
  store double %0, double* %x
  call void @llvm.dbg.declare(metadata double* %x, metadata !12, metadata !DIExpression()), !dbg !16
  %6 = fadd double 1.000000e+00, %0, !dbg !17
  ret double %6, !dbg !16
}

declare %jl_value_t*** @julia.ptls_states()

; Function Attrs: allocsize(1)
declare noalias nonnull %jl_value_t addrspace(10)* @julia.gc_alloc_obj(i8*, i64, %jl_value_t addrspace(10)*) #1

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.declare(metadata, metadata, metadata) #2

; Function Attrs: alwaysinline
define double @enzyme_entry(double) #3 {
entry:
  %1 = call double (i8*, ...) @__enzyme_autodiff(i8* bitcast (double (double)* @julia_f_2 to i8*), metadata !"diffe_out", double %0)
  ret double %1
}

declare double @__enzyme_autodiff(i8*, ...)

attributes #0 = { sspstrong }
attributes #1 = { allocsize(1) }
attributes #2 = { nounwind readnone speculatable }
attributes #3 = { alwaysinline }

!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}

!0 = !{i32 2, !"Dwarf Version", i32 4}
!1 = !{i32 1, !"Debug Info Version", i32 3}
!2 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !3, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
!3 = !DIFile(filename: "REPL[2]", directory: ".")
!4 = !{}
!5 = distinct !DISubprogram(name: "f", linkageName: "julia_f_17137", scope: null, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !2, variables: !9)
!6 = !DISubroutineType(types: !7)
!7 = !{!8, !8}
!8 = !DIBasicType(name: "Float64", size: 64, encoding: DW_ATE_unsigned)
!9 = !{!10, !12}
!10 = !DILocalVariable(name: "#self#", arg: 1, scope: !5, file: !3, line: 1, type: !11)
!11 = !DICompositeType(tag: DW_TAG_structure_type, name: "#f", align: 8, elements: !4, runtimeLang: DW_LANG_Julia, identifier: "49701")
!12 = !DILocalVariable(name: "x", arg: 2, scope: !5, file: !3, line: 1, type: !8)
!13 = !{!14, !14, i64 0, i64 1}
!14 = !{!"jtbaa_const", !15, i64 0}
!15 = !{!"jtbaa"}
!16 = !DILocation(line: 1, scope: !5)
!17 = !DILocation(line: 401, scope: !18, inlinedAt: !16)
!18 = distinct !DISubprogram(name: "+;", linkageName: "+", scope: !19, file: !19, type: !20, isLocal: false, isDefinition: true, isOptimized: true, unit: !2, variables: !4)
!19 = !DIFile(filename: "float.jl", directory: ".")
!20 = !DISubroutineType(types: !4)

Post-optimization:

julia> Enzyme.optimize!(mod)
saw metadata for diffe_out
true

julia> mod
; ModuleID = 'f'
source_filename = "f"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:10:11:12:13"
target triple = "x86_64-pc-linux-gnu"

%jl_value_t = type opaque

; Function Attrs: sspstrong
define double @julia_f_2(double) #0 !dbg !5 {
top:
  call void @llvm.dbg.value(metadata double %0, metadata !12, metadata !DIExpression()), !dbg !13
  %1 = fadd double %0, 1.000000e+00, !dbg !14
  ret double %1, !dbg !13
}

; Function Attrs: allocsize(1)
declare noalias nonnull %jl_value_t addrspace(10)* @julia.gc_alloc_obj(i8*, i64, %jl_value_t addrspace(10)*) #1

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.declare(metadata, metadata, metadata) #2

; Function Attrs: alwaysinline
define double @enzyme_entry(double) #3 {
entry:
  %1 = call { double } @diffejulia_f_2(double %0, double 1.000000e+00)
  %2 = extractvalue { double } %1, 0
  ret double %2
}

declare double @__enzyme_autodiff(i8*, ...)

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #4

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #4

; Function Attrs: inaccessiblemem_or_argmemonly
declare void @jl_gc_queue_root(%jl_value_t addrspace(10)*) #5

; Function Attrs: allocsize(1)
declare noalias nonnull %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8*, i32, i32) #1

; Function Attrs: allocsize(1)
declare noalias nonnull %jl_value_t addrspace(10)* @jl_gc_big_alloc(i8*, i64) #1

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value(metadata, metadata, metadata) #2

; Function Attrs: sspstrong
define double @preprocess_julia_f_2(double) #0 !dbg !18 {
top:
  call void @llvm.dbg.value(metadata double %0, metadata !21, metadata !DIExpression()), !dbg !22
  %1 = fadd double %0, 1.000000e+00, !dbg !23
  ret double %1, !dbg !22
}

; Function Attrs: sspstrong
define internal { double } @diffejulia_f_2(double, double %differeturn) #0 !dbg !24 {
top:
  call void @llvm.dbg.value(metadata double %0, metadata !27, metadata !DIExpression()), !dbg !28
  %"'de" = alloca double
  store double 0.000000e+00, double* %"'de"
  %"'de1" = alloca double
  store double 0.000000e+00, double* %"'de1"
  %1 = fadd double %0, 1.000000e+00, !dbg !29
  br label %inverttop, !dbg !28

inverttop:                                        ; preds = %top
  store double %differeturn, double* %"'de"
  %2 = load double, double* %"'de"
  store double 0.000000e+00, double* %"'de"
  %3 = load double, double* %"'de1"
  %4 = fadd fast double %3, %2
  store double %4, double* %"'de1"
  %5 = load double, double* %"'de1"
  %6 = insertvalue { double } undef, double %5, 0
  ret { double } %6
}

attributes #0 = { sspstrong }
attributes #1 = { allocsize(1) }
attributes #2 = { nounwind readnone speculatable }
attributes #3 = { alwaysinline }
attributes #4 = { argmemonly nounwind }
attributes #5 = { inaccessiblemem_or_argmemonly }

!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}

!0 = !{i32 2, !"Dwarf Version", i32 4}
!1 = !{i32 1, !"Debug Info Version", i32 3}
!2 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !3, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
!3 = !DIFile(filename: "REPL[2]", directory: ".")
!4 = !{}
!5 = distinct !DISubprogram(name: "f", linkageName: "julia_f_17137", scope: null, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !2, variables: !9)
!6 = !DISubroutineType(types: !7)
!7 = !{!8, !8}
!8 = !DIBasicType(name: "Float64", size: 64, encoding: DW_ATE_unsigned)
!9 = !{!10, !12}
!10 = !DILocalVariable(name: "#self#", arg: 1, scope: !5, file: !3, line: 1, type: !11)
!11 = !DICompositeType(tag: DW_TAG_structure_type, name: "#f", align: 8, elements: !4, runtimeLang: DW_LANG_Julia, identifier: "49701")
!12 = !DILocalVariable(name: "x", arg: 2, scope: !5, file: !3, line: 1, type: !8)
!13 = !DILocation(line: 1, scope: !5)
!14 = !DILocation(line: 401, scope: !15, inlinedAt: !13)
!15 = distinct !DISubprogram(name: "+;", linkageName: "+", scope: !16, file: !16, type: !17, isLocal: false, isDefinition: true, isOptimized: true, unit: !2, variables: !4)
!16 = !DIFile(filename: "float.jl", directory: ".")
!17 = !DISubroutineType(types: !4)
!18 = distinct !DISubprogram(name: "f", linkageName: "julia_f_17137", scope: null, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !2, variables: !19)
!19 = !{!20, !21}
!20 = !DILocalVariable(name: "#self#", arg: 1, scope: !18, file: !3, line: 1, type: !11)
!21 = !DILocalVariable(name: "x", arg: 2, scope: !18, file: !3, line: 1, type: !8)
!22 = !DILocation(line: 1, scope: !18)
!23 = !DILocation(line: 401, scope: !15, inlinedAt: !22)
!24 = distinct !DISubprogram(name: "f", linkageName: "julia_f_17137", scope: null, file: !3, line: 1, type: !6, isLocal: false, isDefinition: true, scopeLine: 1, isOptimized: true, unit: !2, variables: !25)
!25 = !{!26, !27}
!26 = !DILocalVariable(name: "#self#", arg: 1, scope: !24, file: !3, line: 1, type: !11)
!27 = !DILocalVariable(name: "x", arg: 2, scope: !24, file: !3, line: 1, type: !8)
!28 = !DILocation(line: 1, scope: !24)
!29 = !DILocation(line: 401, scope: !15, inlinedAt: !28)
@wsmoses
Copy link
Member

wsmoses commented Sep 10, 2019

Is this all the output from post optimization (I'm not seeing the !33 being complained about). In any case I'll try reproducing

@vchuravy
Copy link
Member Author

Got the IR:

(rr) call M.dump()
; ModuleID = 'g'
source_filename = "g"
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128-ni:10:11:12:13"
target triple = "x86_64-pc-linux-gnu"

%jl_value_t = type opaque

; Function Attrs: sspstrong
define double @julia_g_16998(double) #0 !dbg !5 {
top:
  call void @llvm.dbg.value(metadata double %0, metadata !12, metadata !DIExpression()), !dbg !13
  %1 = call { double } @diffejulia_f_1(double %0, double 1.000000e+00), !dbg !14
  %2 = extractvalue { double } %1, 0, !dbg !14
  ret double %2, !dbg !13
}

define nonnull %jl_value_t addrspace(10)* @jfptr_g_16999(%jl_value_t addrspace(10)*, %jl_value_t addrspace(10)**, i32) #1 {
top:
  %thread_ptr = call i8* asm "movq %fs:0, $0", "=r"()
  %ptls_i8 = getelementptr i8, i8* %thread_ptr, i64 -15712
  %ptls = bitcast i8* %ptls_i8 to %jl_value_t***
  %3 = bitcast %jl_value_t addrspace(10)** %1 to double addrspace(10)**
  %4 = load double addrspace(10)*, double addrspace(10)** %3, align 8, !nonnull !4, !dereferenceable !23, !align !23
  %5 = addrspacecast double addrspace(10)* %4 to double addrspace(11)*
  %6 = load double, double addrspace(11)* %5, align 8
  %7 = call double @julia_g_16998(double %6)
  %8 = bitcast %jl_value_t*** %ptls to i8*
  %9 = call noalias nonnull %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8* %8, i32 1400, i32 16) #2
  %10 = bitcast %jl_value_t addrspace(10)* %9 to %jl_value_t addrspace(10)* addrspace(10)*
  %11 = getelementptr %jl_value_t addrspace(10)*, %jl_value_t addrspace(10)* addrspace(10)* %10, i64 -1
  store %jl_value_t addrspace(10)* addrspacecast (%jl_value_t* inttoptr (i64 139811181807920 to %jl_value_t*) to %jl_value_t addrspace(10)*), %jl_value_t addrspace(10)* addrspace(10)* %11, !tbaa !24
  %12 = bitcast %jl_value_t addrspace(10)* %9 to double addrspace(10)*
  store double %7, double addrspace(10)* %12, align 8, !tbaa !28
  ret %jl_value_t addrspace(10)* %9
}

; Function Attrs: allocsize(1)
declare noalias nonnull %jl_value_t addrspace(10)* @julia.gc_alloc_obj(i8*, i64, %jl_value_t addrspace(10)*) #2

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.declare(metadata, metadata, metadata) #3

; Function Attrs: alwaysinline
define double @jl_llvmcall0(double) #4 {
entry:
  %1 = call { double } @diffejulia_f_1(double %0, double 1.000000e+00)
  %2 = extractvalue { double } %1, 0
  ret double %2
}

; Function Attrs: sspstrong
define { double } @diffejulia_f_1(double, double %differeturn) #0 !dbg !31 {
top:
  %1 = insertvalue { double } undef, double %differeturn, 0
  ret { double } %1
}

; Function Attrs: nounwind readnone speculatable
declare void @llvm.dbg.value(metadata, metadata, metadata) #3

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #5

; Function Attrs: argmemonly nounwind
declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #5

; Function Attrs: inaccessiblemem_or_argmemonly
declare void @jl_gc_queue_root(%jl_value_t addrspace(10)*) #6

; Function Attrs: allocsize(1)
declare noalias nonnull %jl_value_t addrspace(10)* @jl_gc_pool_alloc(i8*, i32, i32) #2

; Function Attrs: allocsize(1)
declare noalias nonnull %jl_value_t addrspace(10)* @jl_gc_big_alloc(i8*, i64) #2

; Function Attrs: allocsize(1)
declare noalias nonnull %jl_value_t addrspace(10)* @julia.gc_alloc_bytes(i8*, i64) #2

; Function Attrs: nounwind
declare void @llvm.stackprotector(i8*, i8**) #7

attributes #0 = { sspstrong }
attributes #1 = { "thunk" }
attributes #2 = { allocsize(1) }
attributes #3 = { nounwind readnone speculatable }
attributes #4 = { alwaysinline }
attributes #5 = { argmemonly nounwind }
attributes #6 = { inaccessiblemem_or_argmemonly }
attributes #7 = { nounwind }

!llvm.module.flags = !{!0, !1}
!llvm.dbg.cu = !{!2}

!0 = !{i32 2, !"Dwarf Version", i32 4}
!1 = !{i32 1, !"Debug Info Version", i32 3}
!2 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !3, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
!3 = !DIFile(filename: "/home/vchuravy/src/Enzyme.jl/script.jl", directory: ".")
!4 = !{}
!5 = distinct !DISubprogram(name: "g", linkageName: "julia_g_16998", scope: null, file: !3, line: 3, type: !6, isLocal: false, isDefinition: true, scopeLine: 3, isOptimized: true, unit: !2, variables: !9)
!6 = !DISubroutineType(types: !7)
!7 = !{!8, !8}
!8 = !DIBasicType(name: "Float64", size: 64, encoding: DW_ATE_unsigned)
!9 = !{!10, !12}
!10 = !DILocalVariable(name: "#self#", arg: 1, scope: !5, file: !3, line: 3, type: !11)
!11 = !DICompositeType(tag: DW_TAG_structure_type, name: "#g", align: 8, elements: !4, runtimeLang: DW_LANG_Julia, identifier: "49612")
!12 = !DILocalVariable(name: "x", arg: 2, scope: !5, file: !3, line: 3, type: !8)
!13 = !DILocation(line: 3, scope: !5)
!14 = !DILocation(line: 52, scope: !15, inlinedAt: !18)
!15 = distinct !DISubprogram(name: "macro expansion;", linkageName: "macro expansion", scope: !16, file: !16, type: !17, isLocal: false, isDefinition: true, isOptimized: true, unit: !2, variables: !4)
!16 = !DIFile(filename: "/home/vchuravy/src/LLVM/src/interop/base.jl", directory: ".")
!17 = !DISubroutineType(types: !4)
!18 = !DILocation(line: 98, scope: !19, inlinedAt: !21)
!19 = distinct !DISubprogram(name: "macro expansion;", linkageName: "macro expansion", scope: !20, file: !20, type: !17, isLocal: false, isDefinition: true, isOptimized: true, unit: !2, variables: !4)
!20 = !DIFile(filename: "/home/vchuravy/src/Enzyme.jl/src/Enzyme.jl", directory: ".")
!21 = !DILocation(line: 98, scope: !22, inlinedAt: !13)
!22 = distinct !DISubprogram(name: "autodiff;", linkageName: "autodiff", scope: !20, file: !20, type: !17, isLocal: false, isDefinition: true, isOptimized: true, unit: !2, variables: !4)
!23 = !{i64 8}
!24 = !{!25, !25, i64 0}
!25 = !{!"jtbaa_tag", !26, i64 0}
!26 = !{!"jtbaa_data", !27, i64 0}
!27 = !{!"jtbaa"}
!28 = !{!29, !29, i64 0}
!29 = !{!"jtbaa_immut", !30, i64 0}
!30 = !{!"jtbaa_value", !26, i64 0}
!31 = distinct !DISubprogram(name: "f", linkageName: "julia_f_16929", scope: null, file: !3, line: 2, type: !6, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: true, unit: !32, variables: !33)
!32 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !3, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)
!33 = !{!34, !36}
!34 = !DILocalVariable(name: "#self#", arg: 1, scope: !31, file: !3, line: 2, type: !35)
!35 = !DICompositeType(tag: DW_TAG_structure_type, name: "#f", align: 8, elements: !4, runtimeLang: DW_LANG_Julia, identifier: "49611")
!36 = !DILocalVariable(name: "x", arg: 2, scope: !31, file: !3, line: 2, type: !8)
(rr) n
DICompileUnit not listed in llvm.dbg.cu
!32 = distinct !DICompileUnit(language: DW_LANG_Julia, file: !3, producer: "julia", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4)

@vchuravy
Copy link
Member Author

I am hypothesising that the reingestion doesn't like having two DICompileUnits one for f and the other for g. We should probably just strip it.

@wsmoses
Copy link
Member

wsmoses commented Nov 25, 2020

It may be worthwhile looking at this again since now debug info is better handled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants