mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 20:51:52 +01:00
392b87e7b6
This patch contains the basic functionality for reporting potentially incorrect usage of __builtin_expect() by comparing the developer's annotation against a collected PGO profile. A more detailed proposal and discussion appears on the CFE-dev mailing list (http://lists.llvm.org/pipermail/cfe-dev/2019-July/062971.html) and a prototype of the initial frontend changes appear here in D65300 We revised the work in D65300 by moving the misexpect check into the LLVM backend, and adding support for IR and sampling based profiles, in addition to frontend instrumentation. We add new misexpect metadata tags to those instructions directly influenced by the llvm.expect intrinsic (branch, switch, and select) when lowering the intrinsics. The misexpect metadata contains information about the expected target of the intrinsic so that we can check against the correct PGO counter when emitting diagnostics, and the compiler's values for the LikelyBranchWeight and UnlikelyBranchWeight. We use these branch weight values to determine when to emit the diagnostic to the user. A future patch should address the comment at the top of LowerExpectIntrisic.cpp to hoist the LikelyBranchWeight and UnlikelyBranchWeight values into a shared space that can be accessed outside of the LowerExpectIntrinsic pass. Once that is done, the misexpect metadata can be updated to be smaller. In the long term, it is possible to reconstruct portions of the misexpect metadata from the existing profile data. However, we have avoided this to keep the code simple, and because some kind of metadata tag will be required to identify which branch/switch/select instructions are influenced by the use of llvm.expect Patch By: paulkirth Differential Revision: https://reviews.llvm.org/D66324 llvm-svn: 371484
59 lines
2.0 KiB
LLVM
59 lines
2.0 KiB
LLVM
; Do setup work for all below tests: generate bitcode and combined index
|
|
; RUN: opt -module-summary %s -o %t.bc -bitcode-mdindex-threshold=0
|
|
; RUN: opt -module-summary %p/Inputs/lazyload_metadata.ll -o %t2.bc -bitcode-mdindex-threshold=0
|
|
; RUN: llvm-lto -thinlto-action=thinlink -o %t3.bc %t.bc %t2.bc
|
|
; REQUIRES: asserts
|
|
|
|
; Check that importing @globalfunc1 does not trigger loading all the global
|
|
; metadata for @globalfunc2 and @globalfunc3
|
|
|
|
; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t3.bc \
|
|
; RUN: -o /dev/null -stats \
|
|
; RUN: 2>&1 | FileCheck %s -check-prefix=LAZY
|
|
; LAZY: 63 bitcode-reader - Number of Metadata records loaded
|
|
; LAZY: 2 bitcode-reader - Number of MDStrings loaded
|
|
|
|
; RUN: llvm-lto -thinlto-action=import %t2.bc -thinlto-index=%t3.bc \
|
|
; RUN: -o /dev/null -disable-ondemand-mds-loading -stats \
|
|
; RUN: 2>&1 | FileCheck %s -check-prefix=NOTLAZY
|
|
; NOTLAZY: 72 bitcode-reader - Number of Metadata records loaded
|
|
; NOTLAZY: 7 bitcode-reader - Number of MDStrings loaded
|
|
|
|
|
|
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
|
|
target triple = "x86_64-apple-macosx10.11.0"
|
|
|
|
define void @globalfunc1(i32 %arg) {
|
|
%x = call i1 @llvm.type.test(i8* undef, metadata !"typeid1")
|
|
%tmp = add i32 %arg, 0, !metadata !2
|
|
ret void
|
|
}
|
|
|
|
; We need two functions here that will both reference the same metadata.
|
|
; This is to force the metadata to be emitted in the global metadata block and
|
|
; not in the function specific metadata.
|
|
; These function are not imported and so we don't want to load their metadata.
|
|
|
|
define void @globalfunc2(i32 %arg) {
|
|
%x = call i1 @llvm.type.test(i8* undef, metadata !"typeid1")
|
|
%tmp = add i32 %arg, 0, !metadata !1
|
|
ret void
|
|
}
|
|
|
|
define void @globalfunc3(i32 %arg) {
|
|
%tmp = add i32 %arg, 0, !metadata !1
|
|
ret void
|
|
}
|
|
|
|
declare i1 @llvm.type.test(i8* %ptr, metadata %bitset) nounwind readnone
|
|
|
|
!1 = !{!2, !3, !4, !5, !6, !7, !8, !9}
|
|
!2 = !{!"Hello World"}
|
|
!3 = !{!"3"}
|
|
!4 = !{!"4"}
|
|
!5 = !{!"5"}
|
|
!6 = !{!9}
|
|
!7 = !{!"7"}
|
|
!8 = !{!"8"}
|
|
!9 = !{!6}
|