llvm-project/llvm/lib/Transforms/IPO
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
..
AlwaysInliner.cpp [clang][NewPM] Fix broken -O0 test from missing assumptions 2019-06-13 18:18:40 +00:00
ArgumentPromotion.cpp OpaquePtr: add Type parameter to Loads analysis API. 2019-07-09 11:35:35 +00:00
Attributor.cpp [Attributor] Implement "noalias" callsite argument deduction 2019-09-11 07:00:33 +00:00
BarrierNoopPass.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
BlockExtractor.cpp [BlockExtractor] Avoid assert with wrong line format 2019-08-20 14:46:02 +00:00
CMakeLists.txt [Attributor] Pass infrastructure and fixpoint framework 2019-06-05 03:02:24 +00:00
CalledValuePropagation.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ConstantMerge.cpp IR. Change strip* family of functions to not look through aliases. 2019-08-22 19:56:14 +00:00
CrossDSOCFI.cpp cfi-icall: Allow the jump table to be optionally made non-canonical. 2019-08-09 22:31:59 +00:00
DeadArgumentElimination.cpp [opaque pointer types] Pass function types to CallInst creation. 2019-02-01 20:43:25 +00:00
ElimAvailExtern.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ExtractGV.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ForceFunctionAttrs.cpp ARM MTE stack sanitizer. 2019-07-15 20:02:23 +00:00
FunctionAttrs.cpp LLVM: Optimization Pass: Remove conflicting attribute, if any, before 2019-09-11 14:26:22 +00:00
FunctionImport.cpp [ThinLTO] Fix handling of weak interposable symbols 2019-08-23 15:18:58 +00:00
GlobalDCE.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
GlobalOpt.cpp Change TargetLibraryInfo analysis passes to always require Function 2019-09-07 03:09:36 +00:00
GlobalSplit.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
HotColdSplitting.cpp [llvm] Migrate llvm::make_unique to std::make_unique 2019-08-15 15:54:37 +00:00
IPConstantPropagation.cpp [IPCP] Don't crash due to arg count/type mismatch between caller/callee 2019-01-29 10:19:44 +00:00
IPO.cpp [LLVM-C] Improve Bindings to The Internalize Pass 2019-07-23 04:56:44 +00:00
InferFunctionAttrs.cpp Change TargetLibraryInfo analysis passes to always require Function 2019-09-07 03:09:36 +00:00
InlineSimple.cpp [CallSite removal] move InlineCost to CallBase usage 2019-04-23 12:43:27 +00:00
Inliner.cpp Change TargetLibraryInfo analysis passes to always require Function 2019-09-07 03:09:36 +00:00
Internalize.cpp [Internalize] Replace uses of std::set with DenseSet 2019-04-02 09:25:31 +00:00
LLVMBuild.txt Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
LoopExtractor.cpp [CodeExtractor] Update function's assumption cache after extracting blocks from it 2019-02-08 06:55:18 +00:00
LowerTypeTests.cpp cfi-icall: Allow the jump table to be optionally made non-canonical. 2019-08-09 22:31:59 +00:00
MergeFunctions.cpp Use llvm::stable_sort 2019-04-23 14:51:27 +00:00
PartialInlining.cpp [llvm] Migrate llvm::make_unique to std::make_unique 2019-08-15 15:54:37 +00:00
PassManagerBuilder.cpp Revert "Reland "r364412 [ExpandMemCmp][MergeICmps] Move passes out of CodeGen into opt pipeline."" 2019-09-10 10:39:09 +00:00
PruneEH.cpp [CallSite removal] Move the legacy PM, call graph, and some inliner 2019-04-19 05:59:42 +00:00
SCCP.cpp Change TargetLibraryInfo analysis passes to always require Function 2019-09-07 03:09:36 +00:00
SampleProfile.cpp Reland "clang-misexpect: Profile Guided Validation of Performance Annotations in LLVM" 2019-09-11 16:19:50 +00:00
StripDeadPrototypes.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
StripSymbols.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
SyntheticCountsPropagation.cpp Update the file headers across all of the LLVM projects in the monorepo 2019-01-19 08:50:56 +00:00
ThinLTOBitcodeWriter.cpp [llvm] Migrate llvm::make_unique to std::make_unique 2019-08-15 15:54:37 +00:00
WholeProgramDevirt.cpp [llvm] Migrate llvm::make_unique to std::make_unique 2019-08-15 15:54:37 +00:00