Hack a structure profiling option together
authorChris Lattner <sabre@nondot.org>
Mon, 12 Nov 2001 16:19:45 +0000 (16:19 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 12 Nov 2001 16:19:45 +0000 (16:19 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@1267 91177308-0d34-0410-b5e6-96231b3b80d8

lib/ExecutionEngine/Interpreter/Execution.cpp
lib/ExecutionEngine/Interpreter/Interpreter.h

index 41948c5806611107522e9ff72eb1f97773dfcf90..c19d15cff42584ddff569f560f19186f74b12164 100644 (file)
@@ -26,6 +26,14 @@ static TargetData TD("lli Interpreter");
 CachedWriter CW;     // Object to accelerate printing of LLVM
 
 
+#ifdef PROFILE_STRUCTURE_FIELDS
+#include "llvm/Support/CommandLine.h"
+static cl::Flag ProfileStructureFields("profilestructfields", 
+                                       "Profile Structure Field Accesses");
+#include <map>
+static map<const StructType *, vector<unsigned> > FieldAccessCounts;
+#endif
+
 sigjmp_buf SignalRecoverBuffer;
 static bool InInstruction = false;
 
@@ -628,6 +636,33 @@ void Interpreter::executeRetInst(ReturnInst *I, ExecutionContext &SF) {
     } else {
       ExitCode = 0;
     }
+
+#ifdef PROFILE_STRUCTURE_FIELDS
+    // Print out structure field accounting information...
+    if (!FieldAccessCounts.empty()) {
+      CW << "Field Access Profile Information:\n";
+      map<const StructType *, vector<unsigned> >::iterator 
+        I = FieldAccessCounts.begin(), E = FieldAccessCounts.end();
+      for (; I != E; ++I) {
+        vector<unsigned> &OfC = I->second;
+        CW << "  '" << (Value*)I->first << "'\t- Sum=";
+
+        unsigned Sum = 0;
+        for (unsigned i = 0; i < OfC.size(); ++i)
+          Sum += OfC[i];
+        CW << Sum << " - ";
+
+        for (unsigned i = 0; i < OfC.size(); ++i) {
+          if (i) CW << ", ";
+          CW << OfC[i];
+        }
+        CW << endl;
+      }
+      CW << endl;
+      FieldAccessCounts.clear();
+    }
+#endif
+
     return;
   }
 
@@ -723,6 +758,16 @@ static PointerTy getElementOffset(Instruction *I, unsigned ArgOff) {
     const ConstPoolUInt *CPU = cast<ConstPoolUInt>(I->getOperand(ArgOff++));
     assert(CPU->getType() == Type::UByteTy);
     unsigned Index = CPU->getValue();
+
+#ifdef PROFILE_STRUCTURE_FIELDS
+    if (ProfileStructureFields) {
+      // Do accounting for this field...
+      vector<unsigned> &OfC = FieldAccessCounts[STy];
+      if (OfC.size() == 0) OfC.resize(STy->getElementTypes().size());
+      OfC[Index]++;
+    }
+#endif
+
     Total += SLO->MemberOffsets[Index];
     Ty = STy->getElementTypes()[Index];
   }
index eba8ea9c327de575e8b7b64cb879fc5a5ae369df..7e1fde1e8d52768333d6187194e98b35b8b2fbdf 100644 (file)
@@ -7,6 +7,10 @@
 #ifndef LLI_INTERPRETER_H
 #define LLI_INTERPRETER_H
 
+// Uncomment this line to enable profiling of structure field accesses.
+#define PROFILE_STRUCTURE_FIELDS 1
+
+
 #include "llvm/Module.h"
 #include "llvm/Method.h"
 #include "llvm/Support/DataTypes.h"
@@ -54,7 +58,6 @@ struct ExecutionContext {
                                     // NULL if main func or debugger invoked fn
 };
 
-
 // Interpreter - This class represents the entirety of the interpreter.
 //
 class Interpreter {