From 4b54c8ff1bd77019baa270b1cd9f6a379e3741ab Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Mon, 12 Nov 2012 21:42:53 +0000 Subject: [PATCH] Cache size of PassVector to speed up getNumContainedPasses(). getNumContainedPasses() used to compute the size of the vector on demand. It is called repeated in loops (such as runOnFunction()) and it can be updated while inside the loop. llvm-svn: 167759 --- llvm/include/llvm/PassManagers.h | 14 ++++++++------ llvm/lib/VMCore/PassManager.cpp | 6 ++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/llvm/include/llvm/PassManagers.h b/llvm/include/llvm/PassManagers.h index 0af58533805e..3acbf0e2c074 100644 --- a/llvm/include/llvm/PassManagers.h +++ b/llvm/include/llvm/PassManagers.h @@ -263,7 +263,7 @@ private: class PMDataManager { public: - explicit PMDataManager() : TPM(NULL), Depth(0) { + explicit PMDataManager() : TPM(NULL), PassVectorSize(0), Depth(0) { initializeAnalysisInfo(); } @@ -344,7 +344,7 @@ public: void dumpPreservedSet(const Pass *P) const; virtual unsigned getNumContainedPasses() const { - return (unsigned)PassVector.size(); + return PassVectorSize; } virtual PassManagerType getPassManagerType() const { @@ -369,14 +369,16 @@ protected: // Top level manager. PMTopLevelManager *TPM; - // Collection of pass that are managed by this manager - SmallVector PassVector; - // Collection of Analysis provided by Parent pass manager and // used by current pass manager. At at time there can not be more // then PMT_Last active pass mangers. std::map *InheritedAnalysis[PMT_Last]; + // Collection of pass that are managed by this manager + SmallVector PassVector; + + // Cache the size of PassVector + unsigned PassVectorSize; /// isPassDebuggingExecutionsOrMore - Return true if -debug-pass=Executions /// or higher is specified. @@ -444,7 +446,7 @@ public: } FunctionPass *getContainedPass(unsigned N) { - assert ( N < PassVector.size() && "Pass number out of range!"); + assert ( N < PassVectorSize && "Pass number out of range!"); FunctionPass *FP = static_cast(PassVector[N]); return FP; } diff --git a/llvm/lib/VMCore/PassManager.cpp b/llvm/lib/VMCore/PassManager.cpp index 53f11499e4b9..5c209e24d819 100644 --- a/llvm/lib/VMCore/PassManager.cpp +++ b/llvm/lib/VMCore/PassManager.cpp @@ -195,7 +195,7 @@ public: } BasicBlockPass *getContainedPass(unsigned N) { - assert(N < PassVector.size() && "Pass number out of range!"); + assert(N < PassVectorSize && "Pass number out of range!"); BasicBlockPass *BP = static_cast(PassVector[N]); return BP; } @@ -346,7 +346,7 @@ public: } ModulePass *getContainedPass(unsigned N) { - assert(N < PassVector.size() && "Pass number out of range!"); + assert(N < PassVectorSize && "Pass number out of range!"); return static_cast(PassVector[N]); } @@ -963,6 +963,7 @@ void PMDataManager::add(Pass *P, bool ProcessAnalysis) { if (!ProcessAnalysis) { // Add pass PassVector.push_back(P); + ++PassVectorSize; return; } @@ -1024,6 +1025,7 @@ void PMDataManager::add(Pass *P, bool ProcessAnalysis) { // Add pass PassVector.push_back(P); + ++PassVectorSize; }