[llvm-commits] CVS: reopt/lib/BinInterface/LLVMTrace.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Sat May 15 23:59:01 PDT 2004


Changes in directory reopt/lib/BinInterface:

LLVMTrace.cpp updated: 1.5 -> 1.6

---
Log message:

Use DEBUG() for debug messages.
Get rid of some of the using std:: directives and some commented-out code.
Inline LLVMTrace constructor.
Other very minor cleanups.


---
Diffs of the changes:  (+26 -58)

Index: reopt/lib/BinInterface/LLVMTrace.cpp
diff -u reopt/lib/BinInterface/LLVMTrace.cpp:1.5 reopt/lib/BinInterface/LLVMTrace.cpp:1.6
--- reopt/lib/BinInterface/LLVMTrace.cpp:1.5	Wed Nov 19 16:51:46 2003
+++ reopt/lib/BinInterface/LLVMTrace.cpp	Sat May 15 23:58:06 2004
@@ -13,28 +13,18 @@
 #include "llvm/iTerminators.h"
 #include "llvm/BasicBlock.h"
 #include "llvm/iPHINode.h"
+#include "Support/Debug.h"
 #include <iostream>
 
-using std::map;
-using std::cerr;
-using std::vector;
 using namespace llvm;
 
-LLVMTrace::LLVMTrace(BinInterface *b,VirtualMem *v, TraceCache *t){
-  bb = b;
-  tr = t;
-  vm = v;
-}
-
-void LLVMTrace::addTrace(map<BasicBlock *, unsigned int> &bbToCid, 
-			 map<BasicBlock *, unsigned int> &bbToSec,
-			 map<BasicBlock *, unsigned char> &removedBranch,
-			 unsigned int lastSecId, unsigned int cidOffset, 
-			 unsigned int unroll){
-#ifdef FOR_DEBUG
-  cerr<<"Adding---------------------------\n";
-#endif
-  for(map<BasicBlock *, unsigned int>::iterator MI = bbToCid.begin(),
+void LLVMTrace::addTrace(std::map<BasicBlock *, unsigned int> &bbToCid, 
+			             std::map<BasicBlock *, unsigned int> &bbToSec,
+			             std::map<BasicBlock *, unsigned char> &removedBranch,
+			             unsigned int lastSecId, unsigned int cidOffset, 
+			             unsigned int unroll) {
+  DEBUG(std::cerr<<"Adding trace.\n");
+  for(std::map<BasicBlock *, unsigned int>::iterator MI = bbToCid.begin(),
 	ME = bbToCid.end(); MI != ME; ++MI){
 
     if(!MI->second)
@@ -50,48 +40,32 @@
       if(BranchInst *br = dyn_cast<BranchInst>(&*II))
 	continue;
 
-      vector<unsigned int> positions = getLLVMInstrPositionInfo(II);
+      std::vector<unsigned int> positions = getLLVMInstrPositionInfo(II);
       
       if(positions.size() == 0)
 	continue;
-#ifdef FOR_DEBUG
-      cerr<<II;
-      std::cerr<<"\t\tPushing back\n";
-#endif
-      for(vector<unsigned int>::iterator PI = positions.begin(), 
+      DEBUG (std::cerr << II << "\t\tPushing back\n");
+      for(std::vector<unsigned int>::iterator PI = positions.begin(), 
 	    PE = positions.end(); PI != PE; ++PI){
 	uint64_t addr = getBasicBlockInfo(MI->first).first;
 	addr += (*PI)*4;
-#ifdef FOR_DEBUG
-	std::cerr<<"Section: "<< bbToSec[MI->first]<<" Last: "<<lastSecId<<"\n";
-#endif
-	if( bbToSec[MI->first] <= lastSecId)
+	DEBUG (std::cerr << "Section: " << bbToSec[MI->first] << " Last: " << lastSecId << "\n");
+	if (bbToSec[MI->first] <= lastSecId)
 	  InstrToSec[II] = bbToSec[MI->first];
 	else
 	  InstrToSec[II] = 0;
 
 	//see if previous instruction was a branch
 	unsigned instr = vm->readInstrFrmVm(addr-4, tr);
-	//if((isBranchAlways(instr) || isBranchNever(instr)) && 
-	// removedBranch[MI->first]){
-	if(isBranchInstr(instr) && removedBranch[MI->first]){
+	if(isBranchInstr(instr) && removedBranch[MI->first])
 	  InstrToCid[II].push_back(MI->second+ *PI - 1);
-#ifdef FOR_DEBUG
-	  std::cerr<<(MI->second+ *PI - 1)<<"\n";
-#endif
-	}
-	else{
+	else
 	  InstrToCid[II].push_back(MI->second+ *PI);
-#ifdef FOR_DEBUG
-	  std::cerr<<(MI->second+ *PI)<<"\n";
-#endif
-	}
+	DEBUG (std::cerr << InstrToCid[II].back () << "\n");
       }
     }
   }
-#ifdef FOR_DEBUG
-  cerr<<"-------------------------------\n";
-#endif
+  DEBUG (std::cerr << "Finished adding trace.\n");
   traceInstructions = cidOffset;
   unrollFactor = unroll;
   numberOfEpilogs = (lastSecId - 1);
@@ -105,35 +79,29 @@
 void LLVMTrace::getAllCids(Instruction *I, vector<unsigned int> &vec){
   vec.clear();
   for(unsigned int i = 0; i < unrollFactor; i++){
-    for(vector<unsigned int>::iterator VI = InstrToCid[I].begin(), 
+    for(std::vector<unsigned int>::iterator VI = InstrToCid[I].begin(), 
 	  VE = InstrToCid[I].end(); VI != VE; ++VI)
       vec.push_back(*VI+traceInstructions*i);
   }
 }
 
-unsigned int LLVMTrace::getSec(Instruction *I){
+unsigned int LLVMTrace::getSec(Instruction *I) {
   return InstrToSec[I];
 }
 
-void LLVMTrace::getAllSec(Instruction *I, vector<unsigned int> &vec){
+void LLVMTrace::getAllSec(Instruction *I, vector<unsigned int> &vec) {
   vec.clear();
-  for(unsigned int i = 0; i < unrollFactor; i++){
+  for(unsigned int i = 0; i < unrollFactor; i++)
     vec.push_back(InstrToSec[I] + numberOfEpilogs*i);
-  }
 }
 
 //Should be invoked BEFORE reduce()
 void LLVMTrace::moveInstrToSec(Instruction *I, unsigned int sec){
   if(InstrToCid.find(I) != InstrToCid.end()){
-#ifdef FOR_DEBUG
-    std::cerr<<"Moving\n";
-    std::cerr<<I;
-#endif
-    for(vector<unsigned int>::iterator VI = InstrToCid[I].begin(),
+    DEBUG (std::cerr << "Moving: " << I);
+    for(std::vector<unsigned int>::iterator VI = InstrToCid[I].begin(),
 	  VE = InstrToCid[I].end(); VI != VE; ++VI){
-#ifdef FOR_DEBUG
-      std::cerr<<"ID: "<<*VI<<"\n";
-#endif
+      DEBUG (std::cerr << "ID: " << *VI << "\n");
       bb->moveToEnd(*VI, sec);
     }
   }
@@ -142,7 +110,7 @@
 void LLVMTrace::moveInstrAfter(Instruction *I, unsigned int cid){
   if(InstrToCid.find(I) != InstrToCid.end()){
     unsigned int after = cid;
-    for(vector<unsigned int>::iterator VI = InstrToCid[I].begin(),
+    for(std::vector<unsigned int>::iterator VI = InstrToCid[I].begin(),
 	  VE = InstrToCid[I].end(); VI != VE; ++VI){
       bb->move_instr(*VI, after);
       after = *VI; 
@@ -153,7 +121,7 @@
 void LLVMTrace::moveInstrBefore(Instruction *I, unsigned int cid){
   if(InstrToCid.find(I) != InstrToCid.end()){
     unsigned int before = cid;
-    for(vector<unsigned int>::iterator VI = InstrToCid[I].begin(),
+    for(std::vector<unsigned int>::iterator VI = InstrToCid[I].begin(),
 	  VE = InstrToCid[I].end(); VI != VE; ++VI){
       bb->move_instr_before(*VI, before);
     }





More information about the llvm-commits mailing list