[llvm-commits] CVS: llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp
Anand Shukla
ashukla at cs.uiuc.edu
Fri Jul 18 11:10:02 PDT 2003
Changes in directory llvm/lib/Reoptimizer/Mapping:
getLLVMinfo.cpp updated: 1.10 -> 1.11
---
Log message:
Major changes to Mapping framework: added reverse mapping for Function and BasicBlocks, and made BasicBlock forward mapping more efficient
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp
diff -u llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp:1.10 llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp:1.11
--- llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp:1.10 Sat May 31 21:38:11 2003
+++ llvm/lib/Reoptimizer/Mapping/getLLVMinfo.cpp Fri Jul 18 11:09:50 2003
@@ -17,14 +17,21 @@
using std::vector;
extern void** llvmFunctionTable[];
+extern char llvmSimpleFunction[];
+extern int llvmFunctionCount;
extern unsigned char* FunctionBB[];
extern unsigned char* FunctionLI[];
-static map<unsigned, pair<unsigned, unsigned> > BBmapF;
+static map<unsigned, 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<Function*, unsigned> FunctionKey;
static map<BasicBlock*, unsigned> BasicBlockKey;
static map<Instruction*, unsigned> llvmInstructionKey;
+static map<uint64_t, Function *> revFunction;
+static map<BasicBlock *, std::pair<uint64_t, uint64_t> > BBMapFwd;
+static map<Function *, char> FunctionInlinelable;
static void createBBmapF(unsigned char *BBinfo, unsigned length);
static void createMImapF(unsigned char *LMIinfo, unsigned length);
@@ -34,6 +41,9 @@
static void createFunctionKey(Module *M);
static void createBasicBlockKey(Module *M);
static void createllvmInstructionKey(Module *M);
+static void createBBmapRevF(Module *M);
+static void createBBmapFwdF(Module *M);
+
static pair<unsigned, unsigned> &getBasicBlockInfo(unsigned FunctionNo,
unsigned BasicBlockNo);
static vector<unsigned> &getLLVMInstrInfo(unsigned FunctionNo,
@@ -141,7 +151,7 @@
return MIaddVec;
}
-
+#if 0
pair<uint64_t, uint64_t> getBasicBlockInfo(BasicBlock *BB){
//std::cerr<<"BBMimaplength: "<<BBMIMap_length<<"\n";
@@ -179,7 +189,37 @@
//std::cerr<<"added BBendAdd: "<<BBendAdd<<"\n";
return std::make_pair(BBstartAdd, BBendAdd);
}
+#endif
+pair<uint64_t, uint64_t> getBasicBlockInfo(BasicBlock *BB){
+ Module *M = BB->getParent()->getParent();
+
+ static bool initialized_fwdbbmap = false;
+ if(!initialized_fwdbbmap){
+ createBBmapFwdF(M);
+ initialized_fwdbbmap = true;
+ }
+
+ if(BBMapFwd.find(BB) == BBMapFwd.end())
+ assert(0 && "Map not found for BB!");
+
+ return BBMapFwd[BB];
+}
+
+bool getReverseBBMap(uint64_t addr, Module *M, BasicBlock* &bb){
+ static bool initialized_rev = false;
+ if(!initialized_rev){
+
+ createBBmapRevF(M);
+ initialized_rev = true;
+ }
+
+ if(BBmapReverse.find(addr) != BBmapReverse.end()){
+ bb = BBmapReverse[addr];
+ return true;
+ }
+ return false;
+}
// getBasicBlockInfo -
// Returns first and last MI no of F no, BB no
@@ -191,22 +231,16 @@
//std::cerr<<"in getBasicBlockInfo\n";
if(initialized_BBMI!=FunctionNo){
- //std::cerr<<"create map for function: " << FunctionNo << "\n";
-
+
unsigned char *BBMap = FunctionBB[FunctionNo];
unsigned length = *(unsigned *)BBMap - 4;
- //std::cerr<<"FunctionNo: "<<(void *)BBMap<<"\n";
- //std::cerr<<"map: " << (void *)&BBMap[4]<<"\n";
- //std::cerr<<"mapLength: "<<length<<"\n";
-
+
createBBmapF(&BBMap[4], length);
initialized_BBMI = FunctionNo;
-
- //std::cerr<<"insitialized\n";
+
}
pair<unsigned, unsigned> &firstLast = BBmapF[BasicBlockNo];
- //std::cerr<<"done\n";
return firstLast;
}
@@ -257,6 +291,54 @@
}
}
+static void createBBmapRevF(Module *M){
+ unsigned funNo = 0;
+ for(Module::iterator FI=M->begin(), FE=M->end();
+ FE!=FI; ++FI){
+ if(FI->isExternal()) continue;
+
+ unsigned char *BBMap = FunctionBB[funNo];
+ unsigned length = *(unsigned *)BBMap - 4;
+
+ createBBmapF(&BBMap[4], length);
+
+ unsigned bbNo = 0;
+ for(Function::iterator BB = FI->begin(), BE = FI->end(); BB != BE; ++BB){
+ uint64_t Faddr = (uint64_t)(intptr_t)llvmFunctionTable[funNo];
+
+ BBmapReverse[Faddr + BBmapF[bbNo].first*4] = BB;
+ bbNo++;
+ }
+
+ funNo++;
+ }
+}
+
+static void createBBmapFwdF(Module *M){
+ unsigned funNo = 0;
+ for(Module::iterator FI=M->begin(), FE=M->end();
+ FE!=FI; ++FI){
+ if(FI->isExternal()) continue;
+
+ unsigned char *BBMap = FunctionBB[funNo];
+ unsigned length = *(unsigned *)BBMap - 4;
+
+ createBBmapF(&BBMap[4], length);
+
+ unsigned bbNo = 0;
+ for(Function::iterator BB = FI->begin(), BE = FI->end(); BB != BE; ++BB){
+ uint64_t Faddr = (uint64_t)(intptr_t)llvmFunctionTable[funNo];
+
+ pair<unsigned, unsigned> bpr= BBmapF[bbNo];
+ BBMapFwd[BB] = std::make_pair(Faddr + bpr.first*4,
+ Faddr + (bpr.first + bpr.second -1)*4);
+ bbNo++;
+ }
+
+ funNo++;
+ }
+}
+
// createMImap -
// create the MI map from the info on the .s file
// It contains the F no, BB no, and MI [for all corresponding
@@ -311,7 +393,6 @@
}
static void createFunctionKey(Module *M){
-
unsigned i = 0;
for(Module::iterator FI=M->begin(), FE=M->end();
FE!=FI; ++FI){
@@ -320,6 +401,63 @@
++i;
}
}
+
+bool isInlinable(Function *F){
+ static bool initialize_inline = false;
+
+ if(!F)
+ return false;
+
+ if(F->isExternal())
+ return false;
+
+ if(!initialize_inline){
+ int i = 0;
+
+ for(Module::iterator FI=F->getParent()->begin(), FE=F->getParent()->end();
+ FE!=FI; ++FI){
+ if(FI->isExternal()) continue;
+ //std::cerr<<llvmFunctionCount<<"\t"<<i<<"\n";
+
+ //std::cerr<<"--------------------------------------\n";
+ //std::cerr<<FI;
+
+ assert(i < llvmFunctionCount && "No such function in function table");
+ FunctionInlinelable[FI] = llvmSimpleFunction[i];
+ ++i;
+ }
+ initialize_inline = true;
+ }
+
+ if(FunctionInlinelable[F])
+ return true;
+
+ return false;
+}
+
+//given an address, get the Function that maps to the address
+//return NULL when its an external function
+Function *getRevFunction(Module *M, uint64_t addr){
+ static bool initialized_RevFun = false;
+
+ if(!initialized_RevFun){
+ unsigned i = 0;
+ for(Module::iterator FI=M->begin(), FE=M->end();
+ FE!=FI; ++FI){
+ if(FI->isExternal()) continue;
+ revFunction[(uint64_t)(intptr_t)llvmFunctionTable[i]] = (Function *)FI;
+ ++i;
+ }
+
+ initialized_RevFun = true;
+ }
+
+ if(revFunction.find(addr) != revFunction.end())
+ return revFunction[addr];
+
+ return NULL;
+}
+
static void createBasicBlockKey(Module *M){
More information about the llvm-commits
mailing list