New testcase that is not actually handled yet, but should be in the future.
[oota-llvm.git] / tools / llvm-prof / llvm-prof.cpp
index e9f6d991462c05b5345ac506b494be52363454d6..438fecf07a4a7ca5c5212f82b729a58be4f24f58 100644 (file)
@@ -23,6 +23,8 @@
 #include <map>
 #include <set>
 
+using namespace llvm;
+
 namespace {
   cl::opt<std::string> 
   BytecodeFile(cl::Positional, cl::desc("<program bytecode file>"),
@@ -37,6 +39,9 @@ namespace {
                      cl::desc("Print LLVM code with frequency annotations"));
   cl::alias PrintAnnotated2("A", cl::desc("Alias for --annotated-llvm"),
                             cl::aliasopt(PrintAnnotatedLLVM));
+  cl::opt<bool>
+  PrintAllCode("print-all-code",
+               cl::desc("Print annotated code for the entire program"));
 }
 
 // PairSecondSort - A sorting predicate to sort by the second element of a pair.
@@ -159,6 +164,7 @@ int main(int argc, char **argv) {
     unsigned BlocksToPrint = Counts.size();
     if (BlocksToPrint > 20) BlocksToPrint = 20;
     for (unsigned i = 0; i != BlocksToPrint; ++i) {
+      if (Counts[i].second == 0) break;
       Function *F = Counts[i].first->getParent();
       printf("%3d. %5.2f%% %5u/%llu\t%s() - %s\n", i+1,
              Counts[i].second/(double)TotalExecutions*100,
@@ -170,19 +176,19 @@ int main(int argc, char **argv) {
     BlockFreqs.insert(Counts.begin(), Counts.end());
   }
   
-  if (PrintAnnotatedLLVM) {
+  if (PrintAnnotatedLLVM || PrintAllCode) {
     std::cout << "\n===" << std::string(73, '-') << "===\n";
     std::cout << "Annotated LLVM code for the module:\n\n";
     
-    if (FunctionsToPrint.empty())
-      for (Module::iterator I = M->begin(), E = M->end(); I != E; ++I)
-        FunctionsToPrint.insert(I);
-    
     ProfileAnnotator PA(FuncFreqs, BlockFreqs);
 
-    for (std::set<Function*>::iterator I = FunctionsToPrint.begin(),
-           E = FunctionsToPrint.end(); I != E; ++I)
-      (*I)->print(std::cout, &PA);
+    if (FunctionsToPrint.empty() || PrintAllCode)
+      M->print(std::cout, &PA);
+    else
+      // Print just a subset of the functions...
+      for (std::set<Function*>::iterator I = FunctionsToPrint.begin(),
+             E = FunctionsToPrint.end(); I != E; ++I)
+        (*I)->print(std::cout, &PA);
   }
 
   return 0;