[llvm-commits] [llvm] r81335 - in /llvm/trunk: include/llvm/Analysis/ProfileInfoLoader.h lib/Analysis/ProfileInfoLoader.cpp lib/Analysis/ProfileInfoLoaderPass.cpp lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp

Andreas Neustifter astifter-llvm at gmx.at
Wed Sep 9 05:48:27 PDT 2009


Author: astifter
Date: Wed Sep  9 07:48:26 2009
New Revision: 81335

URL: http://llvm.org/viewvc/llvm-project?rev=81335&view=rev
Log:
Updated ProfileInfo to have clean seperation between different sentinels.

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

Modified: llvm/trunk/include/llvm/Analysis/ProfileInfoLoader.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Analysis/ProfileInfoLoader.h?rev=81335&r1=81334&r2=81335&view=diff

==============================================================================
--- llvm/trunk/include/llvm/Analysis/ProfileInfoLoader.h (original)
+++ llvm/trunk/include/llvm/Analysis/ProfileInfoLoader.h Wed Sep  9 07:48:26 2009
@@ -42,6 +42,8 @@
   ProfileInfoLoader(const char *ToolName, const std::string &Filename,
                     Module &M);
 
+  static const unsigned Uncounted = ~0U;
+
   unsigned getNumExecutions() const { return CommandLines.size(); }
   const std::string &getExecution(unsigned i) const { return CommandLines[i]; }
 

Modified: llvm/trunk/lib/Analysis/ProfileInfoLoader.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileInfoLoader.cpp?rev=81335&r1=81334&r2=81335&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ProfileInfoLoader.cpp (original)
+++ llvm/trunk/lib/Analysis/ProfileInfoLoader.cpp Wed Sep  9 07:48:26 2009
@@ -34,8 +34,8 @@
 
 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 @@
   // 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) {

Modified: llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp?rev=81335&r1=81334&r2=81335&view=diff

==============================================================================
--- llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp (original)
+++ llvm/trunk/lib/Analysis/ProfileInfoLoaderPass.cpp Wed Sep  9 07:48:26 2009
@@ -159,8 +159,12 @@
 void LoaderPass::readOrRememberEdge(ProfileInfo::Edge e,
                                     unsigned weight, unsigned ei,
                                     Function *F) {
-  if (weight != ~0U) {
-    EdgeInformation[F][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[F][e] += (double)weight;
     DEBUG(errs()<<"--Read Edge Counter for " << e 
                 <<" (# "<<ei<<"): "<<(unsigned)getEdgeWeight(e)<<"\n");
   } else {
@@ -178,8 +182,12 @@
     for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
       if (F->isDeclaration()) continue;
       if (ei < ECs.size())
+        // 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[F][ProfileInfo::getEdge(0, &F->getEntryBlock())] +=
-          ECs[ei++];
+          (double)ECs[ei++];
       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
@@ -187,8 +195,10 @@
         TerminatorInst *TI = BB->getTerminator();
         for (unsigned s = 0, e = TI->getNumSuccessors(); s != e; ++s) {
           if (ei < ECs.size())
+            // Here the data realm changes from the unsigned of the file to
+            // the double of the ProfileInfo.
             EdgeInformation[F][ProfileInfo::getEdge(BB, TI->getSuccessor(s))] +=
-              ECs[ei++];
+              (double)ECs[ei++];
         }
       }
     }
@@ -264,7 +274,11 @@
       if (F->isDeclaration()) continue;
       for (Function::iterator BB = F->begin(), E = F->end(); BB != E; ++BB)
         if (bi < BCs.size())
-          BlockInformation[F][BB] = BCs[bi++];
+          // 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)BCs[bi++];
     }
     if (bi != BCs.size()) {
       errs() << "WARNING: profile information is inconsistent with "
@@ -279,7 +293,11 @@
     for (Module::iterator F = M.begin(), E = M.end(); F != E; ++F) {
       if (F->isDeclaration()) continue;
       if (fi < FCs.size())
-        FunctionInformation[F] = FCs[fi++];
+        // 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)FCs[fi++];
     }
     if (fi != FCs.size()) {
       errs() << "WARNING: profile information is inconsistent with "

Modified: llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp?rev=81335&r1=81334&r2=81335&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/OptimalEdgeProfiling.cpp Wed Sep  9 07:48:26 2009
@@ -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 @@
   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 @@
     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 @@
         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 @@
             printEdgeCounter(edge,Succ,i);
             IncrementCounterInBlock(Succ, i, Counters); NumEdgesInserted++;
           }
-          Initializer[i++] = (zeroc);
+          Initializer[i++] = (Zero);
         } else {
-          Initializer[i++] = (minusonec);
+          Initializer[i++] = (Uncounted);
         }
       }
     }





More information about the llvm-commits mailing list