llvm-project/clang/lib
Petr Hosek 7bdad08429 Reland "clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM"
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: 371635
2019-09-11 16:19:50 +00:00
..
ARCMigrate [Clang] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:04:18 +00:00
AST When evaluating a __builtin_constant_p conditional, always enter 2019-09-10 21:24:09 +00:00
ASTMatchers [Clang] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:04:18 +00:00
Analysis [analyzer] NFC: Introduce sub-classes for path-sensitive and basic reports. 2019-09-09 20:34:40 +00:00
Basic Reland "Change the X86 datalayout to add three address spaces 2019-09-10 23:15:38 +00:00
CodeGen Reland "clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM" 2019-09-11 16:19:50 +00:00
CrossTU [CrossTU] Fix problem with CrossTU AST load limit and progress messages. 2019-08-12 07:15:29 +00:00
DirectoryWatcher [Clang] Migrate llvm::make_unique to std::make_unique 2019-08-14 23:04:18 +00:00
Driver [ARM] Take into account -mcpu and -mfpu options while handling 'crypto' feature 2019-09-11 09:06:17 +00:00
Edit [C++2a] Add __builtin_bit_cast, used to implement std::bit_cast 2019-07-02 18:28:13 +00:00
Format [clang-format] Apply BAS_AlwaysBreak to C++11 braced lists 2019-09-10 23:26:45 +00:00
Frontend Reland "clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM" 2019-09-11 16:19:50 +00:00
FrontendTool [Driver] Use shared singleton instance of DriverOptTable 2019-09-04 14:26:28 +00:00
Headers [PowerPC][Altivec] Fix constant argument for vec_dss 2019-09-04 14:01:47 +00:00
Index [clang][Index] Replace CodegenNameGenerator with ASTNameGenerator 2019-09-05 20:33:52 +00:00
Lex Introduce a DirectoryEntryRef that stores both a reference and an 2019-08-31 01:26:04 +00:00
Parse Diagnose _Atomic as a C11 extension. 2019-09-04 21:01:57 +00:00
Rewrite [Rewrite][NFC] Add FIXMEs and tests for RemoveLineIfEmpty bug 2019-08-15 21:17:48 +00:00
Sema [OPENMP] Update the diagnosis message for canonical loop form, by Chi 2019-09-11 15:44:06 +00:00
Serialization [Sema] Diagnose default-initialization, destruction, and copying of 2019-09-07 00:34:43 +00:00
StaticAnalyzer [analyzer] NFC: Simplify bug report equivalence classes to not be ilists. 2019-09-09 20:34:44 +00:00
Tooling [Driver] Use shared singleton instance of DriverOptTable 2019-09-04 14:26:28 +00:00
CMakeLists.txt Reland [clang] DirectoryWatcher 2019-07-12 20:34:10 +00:00