[llvm-commits] CVS: llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Wed Aug 20 12:44:01 PDT 2003


Changes in directory llvm/lib/Reoptimizer/Mapping:

getLLVMinfo.cpp updated: 1.12 -> 1.13

---
Log message:

Add comments to several of the functions.
Erase some dead code, whitespace, and commented-out code.
Erase some functions that don't do anything other than look up an argument in a
 std::map.
Shorten some fragments that do "T &t = something; return t" to
 "return something".


---
Diffs of the changes:

Index: llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp
diff -u llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp:1.12 llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp:1.13
--- llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp:1.12	Wed Aug 20 11:41:49 2003
+++ llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp	Wed Aug 20 12:43:30 2003
@@ -51,6 +51,11 @@
 					 unsigned LLVMInstrNo);
 
 
+/// readNumber - Read in a 32-bit number from the beginning of BBinfo,
+/// decoding it from the compressed encoding in which the mapping
+/// information is stored. Updates BBinfo to point to the next number
+/// in the map and returns the number it read.
+///
 static unsigned readNumber(unsigned char *&BBinfo) {
   unsigned Val = 0;
   unsigned Shift = 0;
@@ -61,104 +66,54 @@
   return Val + (*BBinfo++ << Shift);
 }
 
+/// getLLVMInstrPositionInfo - Look up the given Instruction using
+/// getLLVMInstrInfo (I'll figure this out later.)
+///
 vector<unsigned int> getLLVMInstrPositionInfo(Instruction *LI){
-
-  //std::cerr<<"BBMimaplength: "<<BBMIMap_length<<"\n";
-  //std::cerr<<"in getLLVMinstrInfo(Instruction *LI)\n";
-  static bool initialized_tables_LI = false;
-  
+  // Get pointers to the BasicBlock and Function which contain LI.
   BasicBlock *BB = LI->getParent();
   Function *F = BB->getParent();
-  Module *M = F->getParent();
-  //std::cerr<<"got BB, F, M\n";
-  if(!initialized_tables_LI){
-    createllvmInstructionKey(M);
-    //std::cerr<<"created InstructionKey\n";
-    initialized_tables_LI = true;
-  }
-  
-  pair<uint64_t, uint64_t> BBnoVec = getBasicBlockInfo(BB);
-  //std::cerr<<"got BBnoVec\n";
-  
-  unsigned Fno = getFunctionNo(F);
-  //std::cerr<<"got Fno: "<<Fno<<"\n";
-  unsigned BBno = getBasicBlockNo(BB);
-  //std::cerr<<"got BBno: "<<BBno<<"\n";
-  unsigned LIno = getLLVMInstrNo(LI);
-  //std::cerr<<"got LIno: "<<LIno<<"\n";
-  
-  vector<unsigned> &MInoVec = getLLVMInstrInfo(Fno, BBno, LIno);
-  //std::cerr<<"got MInoVec\n";
-  uint64_t BBadd = BBnoVec.first;
-  //std::cerr<<"added BBadd: "<<BBadd<<"\n";
-  vector<unsigned int> MIaddVec;
-  for(unsigned i = 0; i < MInoVec.size(); ++i)
-    {
-      MIaddVec.push_back(MInoVec[i]);
-    }
-  //std::cerr<"done\n";
-  return MIaddVec;
-}
-
-
-vector<uint64_t> getLLVMInstrInfo(Instruction *LI){
 
-  //std::cerr<<"BBMimaplength: "<<BBMIMap_length<<"\n";
-  //std::cerr<<"in getLLVMinstrInfo(Instruction *LI)\n";
   static bool initialized_tables_LI = false;
-  
-  BasicBlock *BB = LI->getParent();
-  Function *F = BB->getParent();
-  Module *M = F->getParent();
-  //std::cerr<<"got BB, F, M\n";
   if(!initialized_tables_LI){
-    createllvmInstructionKey(M);
-    //std::cerr<<"created InstructionKey\n";
+    // First time through, create the table we use to look up Instructions
+    // for this Function's Module.
+    createllvmInstructionKey(F->getParent());
     initialized_tables_LI = true;
   }
-  
-  pair<uint64_t, uint64_t> BBnoVec = getBasicBlockInfo(BB);
-  //std::cerr<<"got BBnoVec\n";
-  
-  unsigned Fno = getFunctionNo(F);
-  //std::cerr<<"got Fno: "<<Fno<<"\n";
-  unsigned BBno = getBasicBlockNo(BB);
-  //std::cerr<<"got BBno: "<<BBno<<"\n";
-  unsigned LIno = getLLVMInstrNo(LI);
-  //std::cerr<<"got LIno: "<<LIno<<"\n";
-  
-  vector<unsigned> &MInoVec = getLLVMInstrInfo(Fno, BBno, LIno);
-  //std::cerr<<"got MInoVec\n";
-  uint64_t BBadd = BBnoVec.first;
-  //std::cerr<<"added BBadd: "<<BBadd<<"\n";
-  vector<uint64_t> MIaddVec;
-  for(unsigned i = 0; i < MInoVec.size(); ++i)
-    {
-      MIaddVec.push_back(BBadd+MInoVec[i]*4);
-    }
-  //std::cerr<"done\n";
-  return MIaddVec;  
+
+  return getLLVMInstrInfo(FunctionKey[F], BasicBlockKey[BB], llvmInstructionKey[LI]);
 }
 
+/// getBasicBlockInfo(BasicBlock *) - Find the given BasicBlock in the
+/// forward basic block map, and return the pair of 64-bit addresses
+/// that corresponds to it. It is a runtime error to call this
+/// function on a basic block which is not in the map.
+///
 pair<uint64_t, uint64_t> getBasicBlockInfo(BasicBlock *BB){
+  // Get pointer to the Module that contains BB.
   Module *M = BB->getParent()->getParent();
 
   static bool initialized_fwdbbmap = false;
   if(!initialized_fwdbbmap){
+    // First time through, create the table we use to look up BasicBlocks.
     createBBmapFwdF(M);
     initialized_fwdbbmap = true;
   }
 
   if(BBMapFwd.find(BB) == BBMapFwd.end())
     assert(0 && "Map not found for BB!");
-
   return BBMapFwd[BB];
 }
 
+/// getReverseBBMap - Look up the given 64-bit address ADDR in the
+/// reverse BB map for the Module. If it is found, return true, and
+/// set BB to the BasicBlock that corresponds to it. Otherwise, return
+/// false.
+///
 bool getReverseBBMap(uint64_t addr, Module *M, BasicBlock* &bb){
   static bool initialized_rev = false;
   if(!initialized_rev){
-  
     createBBmapRevF(M);
     initialized_rev = true;
   }
@@ -174,25 +129,16 @@
 //           Returns first and last MI no of F no, BB no
 static pair<unsigned, unsigned> &getBasicBlockInfo(unsigned FunctionNo, 
 						   unsigned BasicBlockNo){
-  
   static unsigned initialized_BBMI = ~0;
-  
-  //std::cerr<<"in getBasicBlockInfo\n";
-  
   if(initialized_BBMI!=FunctionNo){
-     
     unsigned char *BBMap = FunctionBB[FunctionNo];
     unsigned length = *(unsigned *)BBMap - 4;
-     
     createBBmapF(&BBMap[4], length);
     initialized_BBMI = FunctionNo;
- 
   }
-  
-  pair<unsigned, unsigned> &firstLast = BBmapF[BasicBlockNo];
-  return firstLast;
-}
 
+  return BBmapF[BasicBlockNo];
+}
 
 // getLLVMInstrInfo -
 //           Return MI no for the F no, BB no, LI No
@@ -200,24 +146,15 @@
 					 unsigned BasicBlockNo, 
 					 unsigned LLVMInstrNo){
   static unsigned initialized_LMI = ~0;
-  ////anand
-  //std::cerr<<"Function no:"<<FunctionNo<<"\n";
   if(initialized_LMI!=FunctionNo){
     unsigned char *LIMap = FunctionLI[FunctionNo];
     unsigned length = *(unsigned *)LIMap - 4;
     createMImapF(&LIMap[4], length);
     initialized_LMI = FunctionNo;
   }
-
-  vector<unsigned> &MIList = MImapF[BasicBlockNo][LLVMInstrNo];//MImapF[FunctionNo][BasicBlockNo];
-  //std::cerr<<"************* BB#"<<BasicBlockNo<<" Inst#"<<LLVMInstrNo<<"\n";
-  //for(vector<unsigned>::iterator MI = MIList.begin(), ME = MIList.end();
-  //  MI!=ME; ++MI)
-  //std::cerr<<*MI<<"\n";
-  
-  return MIList;
+  return MImapF[BasicBlockNo][LLVMInstrNo];
 } 
- 
+
 // createBBmap -
 //          create the BB map from the info in the .s file
 // It contains the F no, BB no, 1st MI no, no of MI in BB
@@ -325,20 +262,6 @@
     
     MImapF[BasicBlockNumber]=LImap;
   }
-}
-
-
-
-static unsigned getFunctionNo(Function *F){
-  return FunctionKey[F];
-}
-
-static unsigned getBasicBlockNo(BasicBlock *BB){
-  return BasicBlockKey[BB];
-}
-
-static unsigned getLLVMInstrNo(Instruction *LI){
-  return llvmInstructionKey[LI];
 }
 
 static void createFunctionKey(Module *M){





More information about the llvm-commits mailing list