diff options
author | Mark de Wever <koraq@xs4all.nl> | 2020-10-31 13:07:06 +0100 |
---|---|---|
committer | Mark de Wever <koraq@xs4all.nl> | 2020-10-31 17:51:29 +0100 |
commit | b46fddf75fc27ee1545f00ab853d50b10c1d7ee6 (patch) | |
tree | c2376509855c7b939060b18c6d2df99840453f6a /clang/lib/CodeGen/CodeGenFunction.cpp | |
parent | ef6f6d1c1a2819407c8c218119b97e1e656e5ef3 (diff) | |
download | llvm-b46fddf75fc27ee1545f00ab853d50b10c1d7ee6.zip llvm-b46fddf75fc27ee1545f00ab853d50b10c1d7ee6.tar.gz llvm-b46fddf75fc27ee1545f00ab853d50b10c1d7ee6.tar.bz2 |
[CodeGen] Implement [[likely]] and [[unlikely]] for while and for loop.
The attribute has no effect on a do statement since the path of execution
will always include its substatement.
It adds a diagnostic when the attribute is used on an infinite while loop
since the codegen omits the branch here. Since the likelihood attributes
have no effect on a do statement no diagnostic will be issued for
do [[unlikely]] {...} while(0);
Differential Revision: https://reviews.llvm.org/D89899
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r-- | clang/lib/CodeGen/CodeGenFunction.cpp | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp index 77b2c97..f1fe8f9 100644 --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -2555,3 +2555,12 @@ llvm::MDNode *CodeGenFunction::createBranchWeights(Stmt::Likelihood LH) const { llvm::MDBuilder MDHelper(CGM.getLLVMContext()); return MDHelper.createBranchWeights(LHW->first, LHW->second); } + +llvm::MDNode *CodeGenFunction::createProfileOrBranchWeightsForLoop( + const Stmt *Cond, uint64_t LoopCount, const Stmt *Body) const { + llvm::MDNode *Weights = createProfileWeightsForLoop(Cond, LoopCount); + if (!Weights && CGM.getCodeGenOpts().OptimizationLevel) + Weights = createBranchWeights(Stmt::getLikelihood(Body)); + + return Weights; +} |