aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenPGO.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2025-06-02 09:51:54 +0200
committerGitHub <noreply@github.com>2025-06-02 09:51:54 +0200
commite2b536431d85c49cdfad5106d116ced683a0667a (patch)
tree2bdba9709f113c45d9ff4d8f591a72013b81264e /clang/lib/CodeGen/CodeGenPGO.cpp
parent9801fdf669bf6e61e276732a95c2f885cb2a39d9 (diff)
downloadllvm-e2b536431d85c49cdfad5106d116ced683a0667a.zip
llvm-e2b536431d85c49cdfad5106d116ced683a0667a.tar.gz
llvm-e2b536431d85c49cdfad5106d116ced683a0667a.tar.bz2
[CodeGen] Move CodeGenPGO behind unique_ptr (NFC) (#142155)
The InstrProf headers are very expensive. Avoid including them in all of CodeGen/ by moving the CodeGenPGO member behind a unqiue_ptr. This reduces clang build time by 0.8%.
Diffstat (limited to 'clang/lib/CodeGen/CodeGenPGO.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenPGO.cpp60
1 files changed, 56 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 8197c5f..a80bebb 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -1505,9 +1505,9 @@ CodeGenFunction::createProfileWeights(ArrayRef<uint64_t> Weights) const {
llvm::MDNode *
CodeGenFunction::createProfileWeightsForLoop(const Stmt *Cond,
uint64_t LoopCount) const {
- if (!PGO.haveRegionCounts())
+ if (!PGO->haveRegionCounts())
return nullptr;
- std::optional<uint64_t> CondCount = PGO.getStmtCount(Cond);
+ std::optional<uint64_t> CondCount = PGO->getStmtCount(Cond);
if (!CondCount || *CondCount == 0)
return nullptr;
return createProfileWeights(LoopCount,
@@ -1520,7 +1520,59 @@ void CodeGenFunction::incrementProfileCounter(const Stmt *S,
!CurFn->hasFnAttribute(llvm::Attribute::NoProfile) &&
!CurFn->hasFnAttribute(llvm::Attribute::SkipProfile)) {
auto AL = ApplyDebugLocation::CreateArtificial(*this);
- PGO.emitCounterSetOrIncrement(Builder, S, StepV);
+ PGO->emitCounterSetOrIncrement(Builder, S, StepV);
}
- PGO.setCurrentStmt(S);
+ PGO->setCurrentStmt(S);
+}
+
+std::pair<bool, bool> CodeGenFunction::getIsCounterPair(const Stmt *S) const {
+ return PGO->getIsCounterPair(S);
+}
+void CodeGenFunction::markStmtAsUsed(bool Skipped, const Stmt *S) {
+ PGO->markStmtAsUsed(Skipped, S);
+}
+void CodeGenFunction::markStmtMaybeUsed(const Stmt *S) {
+ PGO->markStmtMaybeUsed(S);
+}
+
+void CodeGenFunction::maybeCreateMCDCCondBitmap() {
+ if (isMCDCCoverageEnabled()) {
+ PGO->emitMCDCParameters(Builder);
+ MCDCCondBitmapAddr = CreateIRTemp(getContext().UnsignedIntTy, "mcdc.addr");
+ }
+}
+void CodeGenFunction::maybeResetMCDCCondBitmap(const Expr *E) {
+ if (isMCDCCoverageEnabled() && isBinaryLogicalOp(E)) {
+ PGO->emitMCDCCondBitmapReset(Builder, E, MCDCCondBitmapAddr);
+ PGO->setCurrentStmt(E);
+ }
+}
+void CodeGenFunction::maybeUpdateMCDCTestVectorBitmap(const Expr *E) {
+ if (isMCDCCoverageEnabled() && isBinaryLogicalOp(E)) {
+ PGO->emitMCDCTestVectorBitmapUpdate(Builder, E, MCDCCondBitmapAddr, *this);
+ PGO->setCurrentStmt(E);
+ }
+}
+
+void CodeGenFunction::maybeUpdateMCDCCondBitmap(const Expr *E,
+ llvm::Value *Val) {
+ if (isMCDCCoverageEnabled()) {
+ PGO->emitMCDCCondBitmapUpdate(Builder, E, MCDCCondBitmapAddr, Val, *this);
+ PGO->setCurrentStmt(E);
+ }
+}
+
+uint64_t CodeGenFunction::getProfileCount(const Stmt *S) {
+ return PGO->getStmtCount(S).value_or(0);
+}
+
+/// Set the profiler's current count.
+void CodeGenFunction::setCurrentProfileCount(uint64_t Count) {
+ PGO->setCurrentRegionCount(Count);
+}
+
+/// Get the profiler's current count. This is generally the count for the most
+/// recently incremented counter.
+uint64_t CodeGenFunction::getCurrentProfileCount() {
+ return PGO->getCurrentRegionCount();
}