1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-23 19:23:23 +01:00
llvm-mirror/test/Transforms/SampleProfile/offset.ll
Shiva Chen a2029fa58e [DebugInfo] Add DILabel metadata and intrinsic llvm.dbg.label.
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.

llvm-svn: 331841
2018-05-09 02:40:45 +00:00

83 lines
3.6 KiB
LLVM

; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/offset.prof | opt -analyze -branch-prob | FileCheck %s
; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/offset.prof | opt -analyze -branch-prob | FileCheck %s
; Original C++ code for this test case:
;
; a.cc:
; #1
; #2
; #3
; #4
; #5 int foo(int a) {
; #6 #include "a.b"
; #7}
;
; a.b:
; #1 if (a > 0) {
; #2 return 10;
; #3 } else {
; #4 return 20;
; #5 }
; Function Attrs: nounwind uwtable
define i32 @_Z3fooi(i32 %a) #0 !dbg !4 {
entry:
%retval = alloca i32, align 4
%a.addr = alloca i32, align 4
store i32 %a, i32* %a.addr, align 4
call void @llvm.dbg.declare(metadata i32* %a.addr, metadata !11, metadata !12), !dbg !13
%0 = load i32, i32* %a.addr, align 4, !dbg !14
%cmp = icmp sgt i32 %0, 0, !dbg !18
br i1 %cmp, label %if.then, label %if.else, !dbg !19
; CHECK: edge entry -> if.then probability is 0x0167ba82 / 0x80000000 = 1.10%
; CHECK: edge entry -> if.else probability is 0x7e98457e / 0x80000000 = 98.90% [HOT edge]
if.then: ; preds = %entry
store i32 10, i32* %retval, align 4, !dbg !20
br label %return, !dbg !20
if.else: ; preds = %entry
store i32 20, i32* %retval, align 4, !dbg !22
br label %return, !dbg !22
return: ; preds = %if.else, %if.then
%1 = load i32, i32* %retval, align 4, !dbg !24
ret i32 %1, !dbg !24
}
; Function Attrs: nounwind readnone
declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
attributes #1 = { nounwind readnone }
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!8, !9}
!llvm.ident = !{!10}
!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 250750)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !2)
!1 = !DIFile(filename: "a.cc", directory: "/tmp")
!2 = !{}
!4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fooi", scope: !1, file: !1, line: 5, type: !5, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2)
!5 = !DISubroutineType(types: !6)
!6 = !{!7, !7}
!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
!8 = !{i32 2, !"Dwarf Version", i32 4}
!9 = !{i32 2, !"Debug Info Version", i32 3}
!10 = !{!"clang version 3.8.0 (trunk 250750)"}
!11 = !DILocalVariable(name: "a", arg: 1, scope: !4, file: !1, line: 5, type: !7)
!12 = !DIExpression()
!13 = !DILocation(line: 5, column: 13, scope: !4)
!14 = !DILocation(line: 1, column: 5, scope: !15)
!15 = distinct !DILexicalBlock(scope: !17, file: !16, line: 1, column: 5)
!16 = !DIFile(filename: "./a.b", directory: "/tmp")
!17 = !DILexicalBlockFile(scope: !4, file: !16, discriminator: 0)
!18 = !DILocation(line: 1, column: 7, scope: !15)
!19 = !DILocation(line: 1, column: 5, scope: !17)
!20 = !DILocation(line: 2, column: 3, scope: !21)
!21 = distinct !DILexicalBlock(scope: !15, file: !16, line: 1, column: 12)
!22 = !DILocation(line: 4, column: 3, scope: !23)
!23 = distinct !DILexicalBlock(scope: !15, file: !16, line: 3, column: 8)
!24 = !DILocation(line: 7, column: 1, scope: !25)
!25 = !DILexicalBlockFile(scope: !4, file: !1, discriminator: 0)