From 8e00273b91ee563a2773f15faa66c2cf0b4af4f9 Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Fri, 31 Aug 2018 20:20:53 +0000 Subject: [PATCH] [NFC] Pre-calculate basic block IR counts in size remarks. Size remarks are slow due to lots of recalculation of the module. This is similar to the previous commit. Cache the size of the module and update counts in basic block passes based off a less-expensive delta. 2/6 llvm-svn: 341246 --- lib/IR/LegacyPassManager.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/lib/IR/LegacyPassManager.cpp b/lib/IR/LegacyPassManager.cpp index 8ce8d7df4d5..efaa66f25ff 100644 --- a/lib/IR/LegacyPassManager.cpp +++ b/lib/IR/LegacyPassManager.cpp @@ -1287,9 +1287,15 @@ bool BBPassManager::runOnFunction(Function &F) { bool Changed = doInitialization(F); Module &M = *F.getParent(); - unsigned InstrCount = 0; + unsigned InstrCount, BBSize = 0; bool EmitICRemark = M.shouldEmitInstrCountChangedRemark(); - for (BasicBlock &BB : F) + if (EmitICRemark) + InstrCount = initSizeRemarkInfo(M); + + for (BasicBlock &BB : F) { + // Collect the initial size of the basic block. + if (EmitICRemark) + BBSize = BB.size(); for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { BasicBlockPass *BP = getContainedPass(Index); bool LocalChanged = false; @@ -1303,11 +1309,19 @@ bool BBPassManager::runOnFunction(Function &F) { // If the pass crashes, remember this. PassManagerPrettyStackEntry X(BP, BB); TimeRegion PassTimer(getPassTimer(BP)); - if (EmitICRemark) - InstrCount = initSizeRemarkInfo(M); LocalChanged |= BP->runOnBasicBlock(BB); - if (EmitICRemark) - emitInstrCountChangedRemark(BP, M, InstrCount); + if (EmitICRemark) { + unsigned NewSize = BB.size(); + // Update the size of the basic block, emit a remark, and update the + // size of the module. + if (NewSize != BBSize) { + emitInstrCountChangedRemark(BP, M, InstrCount); + int64_t Delta = + static_cast(NewSize) - static_cast(BBSize); + InstrCount = static_cast(InstrCount) + Delta; + BBSize = NewSize; + } + } } Changed |= LocalChanged; @@ -1322,6 +1336,7 @@ bool BBPassManager::runOnFunction(Function &F) { recordAvailableAnalysis(BP); removeDeadPasses(BP, BB.getName(), ON_BASICBLOCK_MSG); } + } return doFinalization(F) || Changed; }