Reapplied r81355 with the problems fixed.
authorAndreas Neustifter <astifter-llvm@gmx.at>
Wed, 16 Sep 2009 11:35:50 +0000 (11:35 +0000)
committerAndreas Neustifter <astifter-llvm@gmx.at>
Wed, 16 Sep 2009 11:35:50 +0000 (11:35 +0000)
(See http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090907/086737.html and
http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20090907/086746.html)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82039 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Analysis/ProfileInfoLoader.h
lib/Analysis/ProfileInfoLoader.cpp
lib/Analysis/ProfileInfoLoaderPass.cpp
lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp

index e74ea3c7d3a4fc86759da75cb8d754acf7b78c5f..9e0c393c428fbc873bc2e8991557bb9881abe172 100644 (file)
@@ -42,6 +42,8 @@ public:
   ProfileInfoLoader(const char *ToolName, const std::string &Filename,
                     Module &M);
 
+  static const unsigned Uncounted;
+
   unsigned getNumExecutions() const { return CommandLines.size(); }
   const std::string &getExecution(unsigned i) const { return CommandLines[i]; }
 
index a6c55dfd5f7a6e45f17e322627ef8f32acc52236..25481b2ee671ea30064b1af2c214bf55e559605d 100644 (file)
@@ -34,8 +34,8 @@ static inline unsigned ByteSwap(unsigned Var, bool Really) {
 
 static unsigned AddCounts(unsigned A, unsigned B) {
   // If either value is undefined, use the other.
-  if (A == ~0U) return B;
-  if (B == ~0U) return A;
+  if (A == ProfileInfoLoader::Uncounted) return B;
+  if (B == ProfileInfoLoader::Uncounted) return A;
   return A + B;
 }
 
@@ -64,7 +64,7 @@ static void ReadProfilingBlock(const char *ToolName, FILE *F,
   // Make sure we have enough space... The space is initialised to -1 to
   // facitiltate the loading of missing values for OptimalEdgeProfiling.
   if (Data.size() < NumEntries)
-    Data.resize(NumEntries, ~0U);
+    Data.resize(NumEntries, ProfileInfoLoader::Uncounted);
 
   // Accumulate the data we just read into the data.
   if (!ShouldByteSwap) {
@@ -78,6 +78,8 @@ static void ReadProfilingBlock(const char *ToolName, FILE *F,
   }
 }
 
+const unsigned ProfileInfoLoader::Uncounted = ~0U;
+
 // ProfileInfoLoader ctor - Read the specified profiling data file, exiting the
 // program if the file is invalid or broken.
 //
index 5f08612e6bbaec87eb4697cb15ff3d765e682800..89d90bca2166d57a7b79be8342b5868e94bd029a 100644 (file)
@@ -160,8 +160,13 @@ void LoaderPass::readEdge(ProfileInfo::Edge e,
                           std::vector<unsigned> &ECs) {
   if (ReadCount < ECs.size()) {
     double weight = ECs[ReadCount++];
-    if (weight != ~0U) {
-      EdgeInformation[getFunction(e)][e] += weight;
+    if (weight != ProfileInfoLoader::Uncounted) {
+      // Here the data realm changes from the unsigned of the file to the
+      // double of the ProfileInfo. This conversion is save because we know
+      // that everything thats representable in unsinged is also representable
+      // in double.
+      EdgeInformation[getFunction(e)][e] += (double)weight;
+
       DEBUG(errs() << "--Read Edge Counter for " << e
                    << " (# "<< (ReadCount-1) << "): "
                    << (unsigned)getEdgeWeight(e) << "\n");
@@ -185,9 +190,6 @@ bool LoaderPass::runOnModule(Module &M) {
       DEBUG(errs()<<"Working on "<<F->getNameStr()<<"\n");
       readEdge(getEdge(0,&F->getEntryBlock()), Counters);
       for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB) {
-        // Okay, we have to add a counter of each outgoing edge.  If the
-        // outgoing edge is not critical don't split it, just insert the counter
-        // in the source or destination of the edge.
         TerminatorInst *TI = BB->getTerminator();
         for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
           readEdge(getEdge(BB,TI->getSuccessor(s)), Counters);
@@ -258,7 +260,11 @@ bool LoaderPass::runOnModule(Module &M) {
       if (F->isDeclaration()) continue;
       for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
         if (ReadCount < Counters.size())
-          BlockInformation[F][BB] = Counters[ReadCount++];
+          // Here the data realm changes from the unsigned of the file to the
+          // double of the ProfileInfo. This conversion is save because we know
+          // that everything thats representable in unsinged is also
+          // representable in double.
+          BlockInformation[F][BB] = (double)Counters[ReadCount++];
     }
     if (ReadCount != Counters.size()) {
       errs() << "WARNING: profile information is inconsistent with "
@@ -273,7 +279,11 @@ bool LoaderPass::runOnModule(Module &M) {
     for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
       if (F->isDeclaration()) continue;
       if (ReadCount < Counters.size())
-        FunctionInformation[F] = Counters[ReadCount++];
+        // Here the data realm changes from the unsigned of the file to the
+        // double of the ProfileInfo. This conversion is save because we know
+        // that everything thats representable in unsinged is also
+        // representable in double.
+        FunctionInformation[F] = (double)Counters[ReadCount++];
     }
     if (ReadCount != Counters.size()) {
       errs() << "WARNING: profile information is inconsistent with "
index cdaf5f1b0dfe4d42cef7f59ff2d1f54b243e68d4..b2e6747ca0e9ef834febb9fa705cf6773a412885 100644 (file)
@@ -18,6 +18,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Analysis/Passes.h"
 #include "llvm/Analysis/ProfileInfo.h"
+#include "llvm/Analysis/ProfileInfoLoader.h"
 #include "llvm/Support/Compiler.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/Debug.h"
@@ -113,8 +114,8 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
   NumEdgesInserted = 0;
 
   std::vector<Constant*> Initializer(NumEdges);
-  Constant* zeroc = ConstantInt::get(Int32, 0);
-  Constant* minusonec = ConstantInt::get(Int32, ProfileInfo::MissingValue);
+  Constant* Zero = ConstantInt::get(Int32, 0);
+  Constant* Uncounted = ConstantInt::get(Int32, ProfileInfoLoader::Uncounted);
 
   // Instrument all of the edges not in MST...
   unsigned i = 0;
@@ -144,9 +145,9 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
     if (!std::binary_search(MST.begin(), MST.end(), edge)) {
       printEdgeCounter(edge,entry,i);
       IncrementCounterInBlock(entry, i, Counters); NumEdgesInserted++;
-      Initializer[i++] = (zeroc);
+      Initializer[i++] = (Zero);
     } else{
-      Initializer[i++] = (minusonec);
+      Initializer[i++] = (Uncounted);
     }
 
     // InsertedBlocks contains all blocks that were inserted for splitting an
@@ -167,9 +168,9 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
         if (!std::binary_search(MST.begin(), MST.end(), edge)) {
           printEdgeCounter(edge,BB,i);
           IncrementCounterInBlock(BB, i, Counters); NumEdgesInserted++;
-          Initializer[i++] = (zeroc);
+          Initializer[i++] = (Zero);
         } else{
-          Initializer[i++] = (minusonec);
+          Initializer[i++] = (Uncounted);
         }
       }
       for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
@@ -195,9 +196,9 @@ bool OptimalEdgeProfiler::runOnModule(Module &M) {
             printEdgeCounter(edge,Succ,i);
             IncrementCounterInBlock(Succ, i, Counters); NumEdgesInserted++;
           }
-          Initializer[i++] = (zeroc);
+          Initializer[i++] = (Zero);
         } else {
-          Initializer[i++] = (minusonec);
+          Initializer[i++] = (Uncounted);
         }
       }
     }