[llvm-commits] CVS: llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Thu Aug 7 13:12:02 PDT 2003
Changes in directory llvm/lib/Reoptimizer/LightWtProfiling/Trigger:
SecondTrigger.cpp updated: 1.7 -> 1.8
---
Log message:
Include scheduler.h to get its prototype(s).
Give triggerBB and printBinary each a comment.
Remove excess parameters that shadow globals from triggerBB.
Replace uses of various `uint64_t one = 1' variables with constant 1ULL.
Refactor find-first-bit-set in 64-bit int into a separate function.
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp
diff -u llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp:1.7 llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp:1.8
--- llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp:1.7 Wed Aug 6 16:52:05 2003
+++ llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp Thu Aug 7 13:11:44 2003
@@ -10,6 +10,7 @@
#include "GetTimer.h"
#include "RegSaveRestore.h"
+#include "scheduler.h"
#include "Timer.h"
#include "llvm/Reoptimizer/Mapping/LLVMinfo.h"
#include "llvm/Reoptimizer/VirtualMem.h"
@@ -49,8 +50,6 @@
extern "C" void llvm_first_trigger(int *cnt);
-void insert_address_at(uint64_t n, uint64_t m);
-
// Forward declarations
void generateTraces(uint64_t start, uint64_t end,
std::vector<uint64_t> &paths,
@@ -62,8 +61,12 @@
std::map<uint64_t, uint64_t> firstTriggerAddr; //tracestart addr
std::map<uint64_t, pair<long, long> > backOffCounters;
-void triggerBB(vector<BasicBlock *> &vBB, VirtualMem *vm, TraceCache *tr,
- TraceCache *tr2, uint64_t a) {
+/// This method is called when we have finally constructed a
+/// trace. The first parameter is the vector of basic blocks that form
+/// the trace; the second parameter is presumably one of the starting
+/// addresses for the trace.
+///
+void triggerBB(vector<BasicBlock *> &vBB, uint64_t a) {
std::cerr << "We made it to triggerBB\n";
}
@@ -173,17 +176,16 @@
for(int i=0, e = paths.size(); i<e; i++){
int j;
- uint64_t one = 1;
uint64_t temp = paths[i];
for(j=63; j>-1; j--){
- if(temp & (one<<j))
+ if(temp & (1ULL << j))
break;
}
//reverse paths
uint64_t fin = 0;
for(int x = 0; x<j; x++)
- fin |= ((((one<<(j-x-1))&temp)>>(j-x-1))<<(x));
+ fin |= ((((1ULL << (j-x-1))&temp)>>(j-x-1))<<(x));
//std::cerr<<"Fin: "<<(void *)fin<<"\n";
paths[i] = fin;
@@ -392,19 +394,28 @@
std::map<int, uint64_t> &targetMap,
std::map<int, uint64_t> &callMap);
+/// Find first set bit in the 64-bit number n. This should probably be
+/// reworked to use libc's ffs(3), but note that the return values are
+/// off by one and ffs() takes 32-bit ints.
+///
+int firstBitSet (const uint64_t n) {
+ int x = 0;
+ for(x = 0; x<64; x++)
+ if(n & (1ULL << x))
+ break;
+ return x;
+}
+
void getIndexToStart(std::pair<int,int> &prtoret, int pathNumber,
std::vector<uint64_t> &paths ){
-
int toRet = 0;
int pathChosen = 0;
- uint64_t one = 1;
for(int i=0; i<pathNumber; i++){
uint64_t temp = (paths[pathNumber]^paths[i]);
- int x=0;
- for(x=0; x<64; x++)
- if(temp & (one<<x))
- break;
+ // Let x be the number of the first bit set in temp, starting with
+ // 0 on the right.
+ int x = firstBitSet (temp);
if(x>toRet){
toRet = x;
pathChosen = i;
@@ -429,13 +440,9 @@
int getIndexToStart(int pathNumber, std::vector<uint64_t> &paths ){
int toRet = 0;
- uint64_t one = 1;
for(int i=0; i<pathNumber; i++){
uint64_t temp = (paths[pathNumber]^paths[i]);
- int x=0;
- for(x=0; x<64; x++)
- if(temp & (one<<x))
- break;
+ int x = firstBitSet (temp);
if(x>toRet)
toRet = x;
}
@@ -443,10 +450,12 @@
return toRet;
}
+/// Print the least-significant 32 bits of the number N, in binary, to
+/// std::cerr, followed by a newline.
+///
void printBinary(uint64_t n){
- uint64_t one = 1;
for(int i=31; i>=0; i--)
- std::cerr<<((n&(one<<i))>>i);
+ std::cerr<<((n&(1ULL <<i))>>i);
std::cerr<<"\n";
}
@@ -498,7 +507,7 @@
}
}
- triggerBB(vBB, vm, tr, tr2, firstLevelTraceStartAddr);
+ triggerBB(vBB, firstLevelTraceStartAddr);
}
#endif
@@ -528,8 +537,6 @@
std::cerr<<"-----------\n";
#endif
- uint64_t one = 1; //the constant 1
-
//branch map and call map
//map of call instructions
std::map<int, uint64_t> callMap;
@@ -784,7 +791,7 @@
nextTrace = (*myIntersections)[pathIndex];
//is it taken?
- if(firstPath & (one<<pathIndex)){
+ if(firstPath & (1ULL << pathIndex)){
#ifdef FOR_DEBUG
std::cerr<<" taken \t";
More information about the llvm-commits
mailing list