Convert StringMap to using StringRef for its APIs.
[oota-llvm.git] / lib / Analysis / ProfileInfoLoader.cpp
index b1ed235c10c1307c6a3ed229650e15077805a4d5..adb2bdc425491fae4fc5411233e635d64282cda3 100644 (file)
@@ -2,8 +2,8 @@
 //
 //                      The LLVM Compiler Infrastructure
 //
-// This file was developed by the LLVM research group and is distributed under
-// the University of Illinois Open Source License. See LICENSE.TXT for details.
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 //
@@ -18,6 +18,7 @@
 #include "llvm/InstrTypes.h"
 #include "llvm/Support/Streams.h"
 #include <cstdio>
+#include <cstdlib>
 #include <map>
 using namespace llvm;
 
@@ -72,7 +73,8 @@ static void ReadProfilingBlock(const char *ToolName, FILE *F,
 //
 ProfileInfoLoader::ProfileInfoLoader(const char *ToolName,
                                      const std::string &Filename,
-                                     Module &TheModule) : M(TheModule) {
+                                     Module &TheModule) : 
+                              M(TheModule), Warned(false) {
   FILE *F = fopen(Filename.c_str(), "r");
   if (F == 0) {
     cerr << ToolName << ": Error opening '" << Filename << "': ";
@@ -152,7 +154,8 @@ void ProfileInfoLoader::getFunctionCounts(std::vector<std::pair<Function*,
       getBlockCounts(BlockCounts);
 
       for (unsigned i = 0, e = BlockCounts.size(); i != e; ++i)
-        if (&BlockCounts[i].first->getParent()->front() == BlockCounts[i].first)
+        if (&BlockCounts[i].first->getParent()->getEntryBlock() ==
+            BlockCounts[i].first)
           Counts.push_back(std::make_pair(BlockCounts[i].first->getParent(),
                                           BlockCounts[i].second));
     } else {
@@ -164,7 +167,7 @@ void ProfileInfoLoader::getFunctionCounts(std::vector<std::pair<Function*,
   unsigned Counter = 0;
   for (Module::iterator I = M.begin(), E = M.end();
        I != E && Counter != FunctionCounts.size(); ++I)
-    if (!I->isExternal())
+    if (!I->isDeclaration())
       Counts.push_back(std::make_pair(I, FunctionCounts[Counter++]));
 }
 
@@ -198,7 +201,6 @@ void ProfileInfoLoader::getBlockCounts(std::vector<std::pair<BasicBlock*,
         Counts.back().second += EdgeCounts[i].second;
         unsigned SuccNum = EdgeCounts[i].first.second;
         if (SuccNum >= TI->getNumSuccessors()) {
-          static bool Warned = false;
           if (!Warned) {
             cerr << "WARNING: profile info doesn't seem to match"
                  << " the program!\n";