[llvm-commits] CVS: llvm/lib/Analysis/ProfileInfoLoaderPass.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Feb 11 12:22:01 PST 2004


Changes in directory llvm/lib/Analysis:

ProfileInfoLoaderPass.cpp updated: 1.1 -> 1.2

---
Log message:

Actually load profiling information now!  Block layout can use real, live, 
actual profile info, and works!  :)


---
Diffs of the changes:  (+20 -4)

Index: llvm/lib/Analysis/ProfileInfoLoaderPass.cpp
diff -u llvm/lib/Analysis/ProfileInfoLoaderPass.cpp:1.1 llvm/lib/Analysis/ProfileInfoLoaderPass.cpp:1.2
--- llvm/lib/Analysis/ProfileInfoLoaderPass.cpp:1.1	Wed Feb 11 00:10:05 2004
+++ llvm/lib/Analysis/ProfileInfoLoaderPass.cpp	Wed Feb 11 12:21:05 2004
@@ -15,14 +15,22 @@
 #include "llvm/Pass.h"
 #include "llvm/Analysis/ProfileInfo.h"
 #include "llvm/Analysis/ProfileInfoLoader.h"
+#include "Support/CommandLine.h"
 using namespace llvm;
 
 namespace {
+  cl::opt<std::string>
+  ProfileInfoFilename("profile-info-file", cl::init("llvmprof.out"),
+                      cl::desc(""));
+
   class LoaderPass : public Pass, public ProfileInfo {
     std::string Filename;
+    std::map<BasicBlock*, unsigned> ExecutionCounts;
   public:
-    LoaderPass(const std::string &filename = "llvmprof.out")
-      : Filename(filename) {}
+    LoaderPass(const std::string &filename = "")
+      : Filename(filename) {
+      if (filename.empty()) Filename = ProfileInfoFilename;
+    }
 
     virtual void getAnalysisUsage(AnalysisUsage &AU) const {
       AU.setPreservesAll();
@@ -35,7 +43,10 @@
     /// run - Load the profile information from the specified file.
     virtual bool run(Module &M);
 
-    unsigned getExecutionCount(BasicBlock *BB) { return 0; }
+    virtual unsigned getExecutionCount(BasicBlock *BB) {
+      std::map<BasicBlock*, unsigned>::iterator I = ExecutionCounts.find(BB);
+      return I != ExecutionCounts.end() ? I->second : 0;
+    }
   };
  
   RegisterOpt<LoaderPass>
@@ -53,6 +64,11 @@
 }
 
 bool LoaderPass::run(Module &M) {
-
+  ProfileInfoLoader PIL("opt", Filename, M);
+  if (PIL.hasAccurateBlockCounts()) {
+    std::vector<std::pair<BasicBlock*, unsigned> > Counts;
+    PIL.getBlockCounts(Counts);
+    ExecutionCounts.insert(Counts.begin(), Counts.end());
+  }
   return false;
 }





More information about the llvm-commits mailing list