diff options
author | Paul Kirth <paulkirth@google.com> | 2024-06-10 11:27:21 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-10 11:27:21 -0700 |
commit | c5978f1eb5eeca8610b9dfce1fcbf1f473911cd8 (patch) | |
tree | ada1826c5eeb65060dedef86d4473b55bb7dc389 /llvm/lib/CodeGen/CodeGenPrepare.cpp | |
parent | 3254f31a66263ea9647c9547f1531c3123444fcd (diff) | |
download | llvm-c5978f1eb5eeca8610b9dfce1fcbf1f473911cd8.zip llvm-c5978f1eb5eeca8610b9dfce1fcbf1f473911cd8.tar.gz llvm-c5978f1eb5eeca8610b9dfce1fcbf1f473911cd8.tar.bz2 |
[llvm][IR] Extend BranchWeightMetadata to track provenance of weights (#86609)
This patch implements the changes to LLVM IR discussed in
https://discourse.llvm.org/t/rfc-update-branch-weights-metadata-to-allow-tracking-branch-weight-origins/75032
In this patch, we add an optional field to MD_prof metadata nodes for
branch weights, which can be used to distinguish weights added from
`llvm.expect*` intrinsics from those added via other methods, e.g.
from profiles or inserted by the compiler.
One of the major motivations, is for use with MisExpect diagnostics,
which need to know if branch_weight metadata originates from an
llvm.expect intrinsic. Without that information, we end up checking
branch weights multiple times in the case if ThinLTO + SampleProfiling,
leading to some inaccuracy in how we report MisExpect related
diagnostics to users.
Since we change the format of MD_prof metadata in a fundamental way, we
need to update code handling branch weights in a number of places.
We also update the lang ref for branch weights to reflect the change.
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index 339a1f1..0e01080 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -8866,7 +8866,8 @@ bool CodeGenPrepare::splitBranchCondition(Function &F, ModifyDT &ModifiedDT) { scaleWeights(NewTrueWeight, NewFalseWeight); Br1->setMetadata(LLVMContext::MD_prof, MDBuilder(Br1->getContext()) - .createBranchWeights(TrueWeight, FalseWeight)); + .createBranchWeights(TrueWeight, FalseWeight, + hasBranchWeightOrigin(*Br1))); NewTrueWeight = TrueWeight; NewFalseWeight = 2 * FalseWeight; |