[llvm-commits] CVS: reopt/lib/LightWtProfiling/SecondTrigger.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Mon Oct 4 13:15:37 PDT 2004



Changes in directory reopt/lib/LightWtProfiling:

SecondTrigger.cpp updated: 1.35 -> 1.36
---
Log message:

Make sure we always express paths as type uint64_t.
Add new function constructFullVBB that collapses multiple paths together into
a hyperblock.  Use it to make a trace consisting of *all* the paths for which
we have counter data, instead of just the first path. This is a hack to reduce
the number of trace entrances/exits. 


---
Diffs of the changes:  (+33 -3)

Index: reopt/lib/LightWtProfiling/SecondTrigger.cpp
diff -u reopt/lib/LightWtProfiling/SecondTrigger.cpp:1.35 reopt/lib/LightWtProfiling/SecondTrigger.cpp:1.36
--- reopt/lib/LightWtProfiling/SecondTrigger.cpp:1.35	Thu Sep 23 14:48:34 2004
+++ reopt/lib/LightWtProfiling/SecondTrigger.cpp	Mon Oct  4 15:15:27 2004
@@ -18,6 +18,7 @@
 
 #include "ReoptimizerInternal.h"
 #include "RegSaveRestore.h"
+#include "llvm/ADT/SetVector.h"
 #include "llvm/Support/Debug.h"
 #include "llvm/Function.h"
 #include "llvm/Instructions.h"
@@ -410,7 +411,7 @@
 /// BRANCH which is on the trace. As a side effect, modifies PATH
 /// so that it starts at the returned basic block.
 ///
-BasicBlock *getSuccessorByPath (BranchInst &branch, unsigned &path)
+BasicBlock *getSuccessorByPath (BranchInst &branch, uint64_t &path)
 {
   BasicBlock *bb;
   
@@ -433,7 +434,7 @@
 /// address is START, construct in VBB a vector of LLVM BasicBlocks
 /// that represents the trace.
 ///
-void constructVBB (unsigned int path, uint64_t start,
+void constructVBB (uint64_t path, uint64_t start,
                    std::vector<BasicBlock *> &vBB) {
   BasicBlock *bb;
   BasicBlock *startBB = 0;
@@ -464,6 +465,35 @@
   } while (bb != vBB[0]);
 }
 
+/// Given a vector of paths PATHS starting in the basic block whose machine
+/// address is START, construct in VBB a vector of LLVM BasicBlocks
+/// that represents the trace.
+///
+void constructFullVBB (std::vector<uint64_t> &paths, uint64_t start,
+                       std::vector<BasicBlock *> &vBB) {
+  BasicBlock *bb;
+  BasicBlock *startBB = 0;
+  SetVector<BasicBlock *> svBB;
+  // Get the first basic block by querying the mapping information.
+  bool foundBB = getReverseBBMap (start, M, startBB);
+  assert (foundBB && "Couldn't find starting BasicBlock for trace start addr");
+  bb = startBB;
+  for (unsigned i = 0; i < paths.size (); ++i) {
+    uint64_t path = paths[i];
+    do {
+      // Add basic block to trace, eliminating duplicates.
+      svBB.insert (bb);
+      // Try to find the next basic block.
+      // Silently fail if we have a basic block in the trace that
+      // ends in something other than a branch.
+      BranchInst *BI = dyn_cast<BranchInst> (bb->getTerminator ());
+      if (!BI) return;
+      bb = getSuccessorByPath (*BI, path);
+    } while (bb != startBB);
+  }
+  vBB.assign (svBB.begin (), svBB.end ());
+}
+
 void addCall(std::vector<unsigned int> &traces,
 	     std::map<int, uint64_t> &callMap, int &index,
 	     uint64_t addressOfCall)
@@ -525,7 +555,7 @@
   if (enable_trace_optimizer) {
     //use path 0 to form vBB
     std::vector<BasicBlock *> vBB;
-    constructVBB (paths[0], start, vBB);
+    constructFullVBB (paths, start, vBB);
     if (vBB.empty()) return;
     if (!optimizeTrace (vBB, firstLevelTraceStartAddr)) {
       // give up.






More information about the llvm-commits mailing list