mirror of
https://github.com/RPCS3/llvm.git
synced 2025-05-17 19:06:09 +00:00

In order to set breakpoints on labels and list source code around labels, we need collect debug information for labels, i.e., label name, the function label belong, line number in the file, and the address label located. In order to keep these information in LLVM IR and to allow backend to generate debug information correctly. We create a new kind of metadata for labels, DILabel. The format of DILabel is !DILabel(scope: !1, name: "foo", file: !2, line: 3) We hope to keep debug information as much as possible even the code is optimized. So, we create a new kind of intrinsic for label metadata to avoid the metadata is eliminated with basic block. The intrinsic will keep existing if we keep it from optimized out. The format of the intrinsic is llvm.dbg.label(metadata !1) It has only one argument, that is the DILabel metadata. The intrinsic will follow the label immediately. Backend could get the label metadata through the intrinsic's parameter. We also create DIBuilder API for labels to be used by Frontend. Frontend could use createLabel() to allocate DILabel objects, and use insertLabel() to insert llvm.dbg.label intrinsic in LLVM IR. Differential Revision: https://reviews.llvm.org/D45024 Patch by Hsiangkai Wang. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@331841 91177308-0d34-0410-b5e6-96231b3b80d8
53 lines
2.4 KiB
LLVM
53 lines
2.4 KiB
LLVM
; RUN: opt -run-twice -verify -S -o - %s | FileCheck %s
|
|
|
|
; If a module contains a DISubprogram referenced only indirectly from
|
|
; instruction-level debug info metadata, but not attached to any Function
|
|
; defined within the module, cloning such a module with CloneModule was
|
|
; causing a DICompileUnit duplication: it would be moved in indirecty via a
|
|
; DISubprogram by DebugInfoFinder (making sure DISubprogram's don't get
|
|
; duplicated) first without being explicitly self-mapped within the ValueMap
|
|
; shared among CloneFunctionInto calls, and then it would get copied during
|
|
; named metadata cloning.
|
|
;
|
|
; This is to make sure we don't regress on that.
|
|
|
|
; Derived from the following C-snippet
|
|
;
|
|
; static int eliminated(int j);
|
|
; __attribute__((nodebug)) int nodebug(int k) { return eliminated(k); }
|
|
; __attribute__((always_inline)) static int eliminated(int j) { return j * 2; }
|
|
;
|
|
; compiled with `clang -O1 -g1 -emit-llvm -S`
|
|
|
|
; CHECK: DICompileUnit
|
|
; CHECK-NOT: DICompileUnit
|
|
|
|
source_filename = "clone-module.c"
|
|
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
|
target triple = "x86_64-apple-macosx"
|
|
|
|
; Function Attrs: norecurse nounwind readnone ssp uwtable
|
|
define i32 @nodebug(i32 %k) local_unnamed_addr #0 {
|
|
entry:
|
|
%mul.i = shl nsw i32 %k, 1, !dbg !8
|
|
ret i32 %mul.i
|
|
}
|
|
|
|
attributes #0 = { norecurse nounwind readnone ssp uwtable }
|
|
|
|
!llvm.dbg.cu = !{!0}
|
|
!llvm.module.flags = !{!3, !4, !5, !6}
|
|
!llvm.ident = !{!7}
|
|
|
|
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 7.0.0 (https://git.llvm.org/git/clang.git/ 195459d046e795f5952f7d2121e505eeb59c5574) (https://git.llvm.org/git/llvm.git/ e9dc5b5ade57869d1a443c568c6cf556ccf3b7af)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2)
|
|
!1 = !DIFile(filename: "test.c", directory: "/Volumes/Data/llvm/build/obj")
|
|
!2 = !{}
|
|
!3 = !{i32 2, !"Dwarf Version", i32 4}
|
|
!4 = !{i32 2, !"Debug Info Version", i32 3}
|
|
!5 = !{i32 1, !"wchar_size", i32 4}
|
|
!6 = !{i32 7, !"PIC Level", i32 2}
|
|
!7 = !{!"clang version 7.0.0 (https://git.llvm.org/git/clang.git/ 195459d046e795f5952f7d2121e505eeb59c5574) (https://git.llvm.org/git/llvm.git/ e9dc5b5ade57869d1a443c568c6cf556ccf3b7af)"}
|
|
!8 = !DILocation(line: 3, column: 72, scope: !9)
|
|
!9 = distinct !DISubprogram(name: "eliminated", scope: !1, file: !1, line: 3, type: !10, isLocal: true, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2)
|
|
!10 = !DISubroutineType(types: !2)
|