[llvm] InstrProfiling.cpp: Let lowerIntrinsics() able to insert BBs. (PR #95585)
NAKAMURA Takumi via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 14 12:06:18 PDT 2024
https://github.com/chapuni created https://github.com/llvm/llvm-project/pull/95585
IsBBChanged should be set when lowering inserted BBs. Make lowerMCDCTestVectorBitmapUpdate() return IsBBChanged unconditionally at the moment.
>From 84449a3a083fa5d47481fccff3e25da1579e66a8 Mon Sep 17 00:00:00 2001
From: NAKAMURA Takumi <geek4civic at gmail.com>
Date: Sat, 15 Jun 2024 02:47:33 +0900
Subject: [PATCH] InstrProfiling.cpp: Let lowerIntrinsics() able to insert BBs.
IsBBChanged should be set when lowering inserted BBs.
Make lowerMCDCTestVectorBitmapUpdate() return IsBBChanged unconditionally
at the moment.
---
.../Instrumentation/InstrProfiling.cpp | 69 +++++++++++--------
1 file changed, 40 insertions(+), 29 deletions(-)
diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
index 0c79eaa812b5f..e9bccae1546c1 100644
--- a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
+++ b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp
@@ -276,7 +276,7 @@ class InstrLowerer final {
/// Replace instrprof.mcdc.tvbitmask.update with a shift and or instruction
/// using the index represented by the a temp value into a bitmap.
- void lowerMCDCTestVectorBitmapUpdate(InstrProfMCDCTVBitmapUpdate *Ins);
+ bool lowerMCDCTestVectorBitmapUpdate(InstrProfMCDCTVBitmapUpdate *Ins);
/// Replace instrprof.mcdc.temp.update with a shift and or instruction using
/// the corresponding condition ID.
@@ -625,35 +625,45 @@ PreservedAnalyses InstrProfilingLoweringPass::run(Module &M,
bool InstrLowerer::lowerIntrinsics(Function *F) {
bool MadeChange = false;
PromotionCandidates.clear();
- for (BasicBlock &BB : *F) {
- for (Instruction &Instr : llvm::make_early_inc_range(BB)) {
- if (auto *IPIS = dyn_cast<InstrProfIncrementInstStep>(&Instr)) {
- lowerIncrement(IPIS);
- MadeChange = true;
- } else if (auto *IPI = dyn_cast<InstrProfIncrementInst>(&Instr)) {
- lowerIncrement(IPI);
- MadeChange = true;
- } else if (auto *IPC = dyn_cast<InstrProfTimestampInst>(&Instr)) {
- lowerTimestamp(IPC);
- MadeChange = true;
- } else if (auto *IPC = dyn_cast<InstrProfCoverInst>(&Instr)) {
- lowerCover(IPC);
- MadeChange = true;
- } else if (auto *IPVP = dyn_cast<InstrProfValueProfileInst>(&Instr)) {
- lowerValueProfileInst(IPVP);
- MadeChange = true;
- } else if (auto *IPMP = dyn_cast<InstrProfMCDCBitmapParameters>(&Instr)) {
- IPMP->eraseFromParent();
- MadeChange = true;
- } else if (auto *IPBU = dyn_cast<InstrProfMCDCTVBitmapUpdate>(&Instr)) {
- lowerMCDCTestVectorBitmapUpdate(IPBU);
- MadeChange = true;
- } else if (auto *IPTU = dyn_cast<InstrProfMCDCCondBitmapUpdate>(&Instr)) {
- lowerMCDCCondBitmapUpdate(IPTU);
- MadeChange = true;
+ bool IsBBChanged;
+ do {
+ IsBBChanged = false;
+ for (BasicBlock &BB : *F) {
+ for (Instruction &Instr : llvm::make_early_inc_range(BB)) {
+ if (auto *IPIS = dyn_cast<InstrProfIncrementInstStep>(&Instr)) {
+ lowerIncrement(IPIS);
+ MadeChange = true;
+ } else if (auto *IPI = dyn_cast<InstrProfIncrementInst>(&Instr)) {
+ lowerIncrement(IPI);
+ MadeChange = true;
+ } else if (auto *IPC = dyn_cast<InstrProfTimestampInst>(&Instr)) {
+ lowerTimestamp(IPC);
+ MadeChange = true;
+ } else if (auto *IPC = dyn_cast<InstrProfCoverInst>(&Instr)) {
+ lowerCover(IPC);
+ MadeChange = true;
+ } else if (auto *IPVP = dyn_cast<InstrProfValueProfileInst>(&Instr)) {
+ lowerValueProfileInst(IPVP);
+ MadeChange = true;
+ } else if (auto *IPMP =
+ dyn_cast<InstrProfMCDCBitmapParameters>(&Instr)) {
+ IPMP->eraseFromParent();
+ MadeChange = true;
+ } else if (auto *IPBU = dyn_cast<InstrProfMCDCTVBitmapUpdate>(&Instr)) {
+ IsBBChanged = lowerMCDCTestVectorBitmapUpdate(IPBU);
+ MadeChange = true;
+ } else if (auto *IPTU =
+ dyn_cast<InstrProfMCDCCondBitmapUpdate>(&Instr)) {
+ lowerMCDCCondBitmapUpdate(IPTU);
+ MadeChange = true;
+ }
+ if (IsBBChanged)
+ break;
}
+ if (IsBBChanged)
+ break;
}
- }
+ } while (IsBBChanged);
if (!MadeChange)
return false;
@@ -1007,7 +1017,7 @@ void InstrLowerer::lowerCoverageData(GlobalVariable *CoverageNamesVar) {
CoverageNamesVar->eraseFromParent();
}
-void InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
+bool InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
InstrProfMCDCTVBitmapUpdate *Update) {
IRBuilder<> Builder(Update);
auto *Int8Ty = Type::getInt8Ty(M.getContext());
@@ -1051,6 +1061,7 @@ void InstrLowerer::lowerMCDCTestVectorBitmapUpdate(
// store i8 %8, ptr %3, align 1
Builder.CreateStore(Result, BitmapByteAddr);
Update->eraseFromParent();
+ return false;
}
void InstrLowerer::lowerMCDCCondBitmapUpdate(
More information about the llvm-commits
mailing list