1. clang-misexpect: Profile Guided Validation of Performance Annotations in (details)
  2. gn build: Merge r371484 (details)
Commit a10802fd73f937cab8cfd448d9e9ff283f75b191 by phosek
clang-misexpect: Profile Guided Validation of Performance Annotations in
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
( 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:
llvm-svn: 371484
The file was modifiedclang/lib/Frontend/CompilerInvocation.cpp
The file was addedclang/test/Profile/Inputs/misexpect-switch-default-only.proftext
The file was addedclang/test/Profile/misexpect-branch.c
The file was modifiedclang/lib/CodeGen/CodeGenAction.cpp
The file was addedclang/test/Profile/misexpect-switch-only-default-case.c
The file was addedclang/test/Profile/misexpect-switch-nonconst.c
The file was addedclang/test/Profile/Inputs/misexpect-branch-nonconst-expect-arg.proftext
The file was addedllvm/test/Transforms/PGOProfile/misexpect-branch-unpredictable.ll
The file was modifiedllvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
The file was modifiedclang/include/clang/Basic/
The file was addedllvm/test/Transforms/PGOProfile/Inputs/misexpect-branch.proftext
The file was addedllvm/test/Transforms/PGOProfile/Inputs/misexpect-switch.proftext
The file was addedclang/test/Profile/misexpect-branch-unpredictable.c
The file was addedllvm/test/Transforms/PGOProfile/misexpect-branch-correct.ll
The file was addedclang/test/Profile/misexpect-branch-nonconst-expected-val.c
The file was modifiedllvm/test/Transforms/LowerExpectIntrinsic/basic.ll
The file was addedllvm/lib/Transforms/Utils/MisExpect.cpp
The file was addedclang/test/Profile/Inputs/misexpect-switch.proftext
The file was addedclang/test/Profile/misexpect-switch-default.c
The file was modifiedllvm/lib/Transforms/IPO/SampleProfile.cpp
The file was addedllvm/test/Transforms/PGOProfile/misexpect-switch-default.ll
The file was modifiedllvm/include/llvm/IR/MDBuilder.h
The file was addedclang/test/Profile/misexpect-branch-cold.c
The file was modifiedllvm/test/ThinLTO/X86/lazyload_metadata.ll
The file was addedllvm/test/Transforms/PGOProfile/misexpect-branch-stripped.ll
The file was addedllvm/test/Transforms/PGOProfile/misexpect-branch.ll
The file was addedclang/test/Profile/misexpect-switch.c
The file was addedllvm/test/Transforms/PGOProfile/Inputs/misexpect-branch-correct.proftext
The file was addedclang/test/Profile/Inputs/misexpect-switch-default.proftext
The file was addedllvm/test/Transforms/PGOProfile/Inputs/misexpect-switch-correct.proftext
The file was addedclang/test/Profile/Inputs/misexpect-branch.proftext
The file was addedllvm/test/Transforms/PGOProfile/misexpect-switch.ll
The file was modifiedllvm/include/llvm/IR/DiagnosticInfo.h
The file was addedllvm/include/llvm/Transforms/Utils/MisExpect.h
The file was modifiedllvm/lib/IR/DiagnosticInfo.cpp
The file was modifiedllvm/lib/Transforms/Scalar/LowerExpectIntrinsic.cpp
The file was modifiedllvm/lib/Transforms/Utils/CMakeLists.txt
The file was modifiedllvm/lib/IR/MDBuilder.cpp
The file was modifiedclang/include/clang/Basic/
The file was modifiedllvm/include/llvm/IR/FixedMetadataKinds.def
Commit a6e5a7b63747e27a30eaaed728c9e7859c1fd79a by nicolasweber
gn build: Merge r371484
llvm-svn: 371485
The file was modifiedllvm/utils/gn/secondary/llvm/lib/Transforms/Utils/