diff --git a/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp b/llvm/lib/Transforms/Instrumentation/InstrProfiling.cpp index 9c34374f0ece1..5a35928d13b21 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); /// Compute the address of the counter value that this profiling instruction /// acts on. @@ -621,32 +621,41 @@ 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(&Instr)) { - lowerIncrement(IPIS); - MadeChange = true; - } else if (auto *IPI = dyn_cast(&Instr)) { - lowerIncrement(IPI); - MadeChange = true; - } else if (auto *IPC = dyn_cast(&Instr)) { - lowerTimestamp(IPC); - MadeChange = true; - } else if (auto *IPC = dyn_cast(&Instr)) { - lowerCover(IPC); - MadeChange = true; - } else if (auto *IPVP = dyn_cast(&Instr)) { - lowerValueProfileInst(IPVP); - MadeChange = true; - } else if (auto *IPMP = dyn_cast(&Instr)) { - IPMP->eraseFromParent(); - MadeChange = true; - } else if (auto *IPBU = dyn_cast(&Instr)) { - lowerMCDCTestVectorBitmapUpdate(IPBU); - 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(&Instr)) { + lowerIncrement(IPIS); + MadeChange = true; + } else if (auto *IPI = dyn_cast(&Instr)) { + lowerIncrement(IPI); + MadeChange = true; + } else if (auto *IPC = dyn_cast(&Instr)) { + lowerTimestamp(IPC); + MadeChange = true; + } else if (auto *IPC = dyn_cast(&Instr)) { + lowerCover(IPC); + MadeChange = true; + } else if (auto *IPVP = dyn_cast(&Instr)) { + lowerValueProfileInst(IPVP); + MadeChange = true; + } else if (auto *IPMP = + dyn_cast(&Instr)) { + IPMP->eraseFromParent(); + MadeChange = true; + } else if (auto *IPBU = dyn_cast(&Instr)) { + IsBBChanged = lowerMCDCTestVectorBitmapUpdate(IPBU); + MadeChange = true; + } + if (IsBBChanged) + break; } + if (IsBBChanged) + break; } - } + } while (IsBBChanged); if (!MadeChange) return false; @@ -1000,7 +1009,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()); @@ -1044,6 +1053,7 @@ void InstrLowerer::lowerMCDCTestVectorBitmapUpdate( // store i8 %8, ptr %3, align 1 Builder.CreateStore(Result, BitmapByteAddr); Update->eraseFromParent(); + return false; } /// Get the name of a profiling variable for a particular function.