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

Brian Gaeke gaeke at cs.uiuc.edu
Sat Nov 8 12:25:01 PST 2003


Changes in directory reopt/lib/Mapping:

getLLVMinfo.cpp updated: 1.21 -> 1.22

---
Log message:

C-ify the way some extern declarations are spelled.

Use 'std::map' instead of just saying 'map'.

Make FunctionKey, BasicBlockKey, and llvmInstructionKey file-private (again?).

Refactor getLLVMInstrPositionInfo() so that it shares code with
getLLVMFunctionPositionInfo() (formerly getSavedStateIndexOfFunction());
their shared code is now called maybeFillInMapsForModule().

Move forward decls of create*() methods farther down in the file, closer
to their first uses.


---
Diffs of the changes:  (+47 -28)

Index: reopt/lib/Mapping/getLLVMinfo.cpp
diff -u reopt/lib/Mapping/getLLVMinfo.cpp:1.21 reopt/lib/Mapping/getLLVMinfo.cpp:1.22
--- reopt/lib/Mapping/getLLVMinfo.cpp:1.21	Thu Oct 30 14:42:42 2003
+++ reopt/lib/Mapping/getLLVMinfo.cpp	Sat Nov  8 12:24:47 2003
@@ -16,24 +16,26 @@
 using std::vector;
 
 // Global symbols added to the program by the opt -emitfuncs pass:
-extern void** llvmFunctionTable[];
+extern void **llvmFunctionTable[];
 extern char llvmSimpleFunction[];
 extern int llvmFunctionCount;
 // Global symbols added to the program by FunctionInfo pass:
-extern unsigned char* FunctionBB[];
-extern unsigned char* FunctionLI[];
+extern unsigned char *FunctionBB[];
+extern unsigned char *FunctionLI[];
 
-static map<unsigned, std::pair<unsigned, unsigned> > BBmapF;
+static std::map<unsigned, std::pair<unsigned, unsigned> > BBmapF;
 //reverse of BBMAP
-static map<unsigned, BasicBlock *> BBmapReverse;
-static map<unsigned/*BB*/,map<unsigned/*LI*/,vector<unsigned>/*MI*/ > > MImapF; 
-static map<uint64_t, Function *> revFunction;
-static map<BasicBlock *, std::pair<uint64_t, uint64_t> > BBMapFwd;
-static map<Function *, char> FunctionInlinable;
-
-static void createBBmapF(unsigned char *BBinfo, unsigned length);
-static void createMImapF(unsigned char *LMIinfo, unsigned length);
-static void createBBmapRevFwdF(Module *M);
+static std::map<unsigned, BasicBlock *> BBmapReverse;
+static std::map<unsigned/*BB*/,map<unsigned/*LI*/,vector<unsigned>/*MI*/ > > MImapF; 
+static std::map<uint64_t, Function *> revFunction;
+static std::map<BasicBlock *, std::pair<uint64_t, uint64_t> > BBMapFwd;
+static std::map<Function *, char> FunctionInlinable;
+
+// Tables we use to look up Instructions and Functions in the mapping
+// info for the current Module:
+static std::map<Function *, unsigned> FunctionKey;
+static std::map<BasicBlock *, unsigned> BasicBlockKey;
+static std::map<Instruction *, unsigned> llvmInstructionKey;
 
 /// readNumber - Read in a 32-bit number from the beginning of BBinfo,
 /// decoding it from the compressed encoding in which the mapping
@@ -50,21 +52,7 @@
   return Val + (*BBinfo++ << Shift);
 }
 
-/// getLLVMInstrPositionInfo - Look up the given Instruction in the
-/// LLVM-to-MI map for the Function that contains it, and return the
-/// vector of integers (?) that represents it.
-///
-vector<unsigned int> getLLVMInstrPositionInfo(Instruction *LI){
-  // Get pointers to the BasicBlock, Function, and Module which contain LI.
-  BasicBlock *BB = LI->getParent();
-  Function *F = BB->getParent();
-  Module *M = F->getParent();
-
-  // Tables we use to look up Instructions for the current Module:
-  static map<Function*, unsigned> FunctionKey;
-  static map<BasicBlock*, unsigned> BasicBlockKey;
-  static map<Instruction*, unsigned> llvmInstructionKey;
-
+static void maybeFillInMapsForModule (Module *M) {
   // First time we see a given Module, we have to fill in the above tables.
   static Module *lastUsedModule = NULL;
   if (lastUsedModule != M) {
@@ -86,6 +74,37 @@
     }
     lastUsedModule = M;
   }
+}
+
+/// Returns the index in _llvm_regAllocState.functions[] where F's register
+/// allocation data may be found. It is a runtime error to call this on a
+/// function which was recently added to the module.
+///
+unsigned getLLVMFunctionPositionInfo (Function *F) {
+  // Get pointer to the Module which contains F
+  Module *M = F->getParent ();
+
+  maybeFillInMapsForModule (M);
+  
+  assert (FunctionKey.find (F) != FunctionKey.end ());
+  return FunctionKey[F];
+}
+
+static void createBBmapF(unsigned char *BBinfo, unsigned length);
+static void createMImapF(unsigned char *LMIinfo, unsigned length);
+static void createBBmapRevFwdF(Module *M);
+
+/// getLLVMInstrPositionInfo - Look up the given Instruction in the
+/// LLVM-to-MI map for the Function that contains it, and return the
+/// vector of integers (?) that represents it.
+///
+std::vector<unsigned> getLLVMInstrPositionInfo (Instruction *LI) {
+  // Get pointers to the BasicBlock, Function, and Module which contain LI.
+  BasicBlock *BB = LI->getParent();
+  Function *F = BB->getParent();
+  Module *M = F->getParent();
+
+  maybeFillInMapsForModule (M);
 
   unsigned FunctionNo = FunctionKey[F];
   static unsigned lastUsedFunctionNo = ~0;





More information about the llvm-commits mailing list