From f2a202ce7a2594e07fd6735c2f6cf25b3a749916 Mon Sep 17 00:00:00 2001 From: Jessica Paquette Date: Fri, 31 Aug 2018 20:19:41 +0000 Subject: [PATCH] [NFC] Pre-calculate function IR counts in size remarks. Size remarks are slow due to lots of recalculation of the module. Pre-calculate the module size and initial function size for a remark. Use deltas calculated using the less-expensive function IR count to update the module counts for Function passes. 1/6 llvm-svn: 341245 --- llvm/lib/IR/LegacyPassManager.cpp | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/llvm/lib/IR/LegacyPassManager.cpp b/llvm/lib/IR/LegacyPassManager.cpp index dbef00a..8ce8d7d 100644 --- a/llvm/lib/IR/LegacyPassManager.cpp +++ b/llvm/lib/IR/LegacyPassManager.cpp @@ -1510,8 +1510,14 @@ bool FPPassManager::runOnFunction(Function &F) { // Collect inherited analysis from Module level pass manager. populateInheritedAnalysis(TPM->activeStack); - unsigned InstrCount = 0; + unsigned InstrCount, FunctionSize = 0; bool EmitICRemark = M.shouldEmitInstrCountChangedRemark(); + // Collect the initial size of the module. + if (EmitICRemark) { + InstrCount = initSizeRemarkInfo(M); + FunctionSize = F.getInstructionCount(); + } + for (unsigned Index = 0; Index < getNumContainedPasses(); ++Index) { FunctionPass *FP = getContainedPass(Index); bool LocalChanged = false; @@ -1524,11 +1530,20 @@ bool FPPassManager::runOnFunction(Function &F) { { PassManagerPrettyStackEntry X(FP, F); TimeRegion PassTimer(getPassTimer(FP)); - if (EmitICRemark) - InstrCount = initSizeRemarkInfo(M); LocalChanged |= FP->runOnFunction(F); - if (EmitICRemark) - emitInstrCountChangedRemark(FP, M, InstrCount); + if (EmitICRemark) { + unsigned NewSize = F.getInstructionCount(); + + // Update the size of the function, emit a remark, and update the size + // of the module. + if (NewSize != FunctionSize) { + emitInstrCountChangedRemark(FP, M, InstrCount); + int64_t Delta = static_cast(NewSize) - + static_cast(FunctionSize); + InstrCount = static_cast(InstrCount) + Delta; + FunctionSize = NewSize; + } + } } Changed |= LocalChanged; -- 2.7.4