[llvm-commits] CVS: llvm/lib/Reoptimizer/BinInterface/LLVMTrace.cpp
Anand Shukla
ashukla at cs.uiuc.edu
Sat May 31 17:07:01 PDT 2003
Changes in directory llvm/lib/Reoptimizer/BinInterface:
LLVMTrace.cpp added (r1.1)
---
Log message:
API for adding/removing LLVM instruction from binintrface trace
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/BinInterface/LLVMTrace.cpp
diff -c /dev/null llvm/lib/Reoptimizer/BinInterface/LLVMTrace.cpp:1.1
*** /dev/null Sat May 31 17:06:53 2003
--- llvm/lib/Reoptimizer/BinInterface/LLVMTrace.cpp Sat May 31 17:06:43 2003
***************
*** 0 ****
--- 1,147 ----
+ //===-- ------------Reoptimizer/BinInterface/LLVMTrace.cpp--------*- C++ -*--=//
+ // Implements trace manipulation using bin interface
+ //
+ //===----------------------------------------------------------------------===//
+
+ #include "llvm/Reoptimizer/BinInterface/sparcbin.h"
+ #include "llvm/Reoptimizer/BinInterface/LLVMTrace.h"
+ #include "llvm/Reoptimizer/Mapping/LLVMinfo.h"
+ #include "llvm/Reoptimizer/TraceCache.h"
+ #include "llvm/Reoptimizer/VirtualMem.h"
+ #include "llvm/Reoptimizer/InstrUtils.h"
+ #include "llvm/iTerminators.h"
+ #include "llvm/BasicBlock.h"
+ #include "llvm/iPHINode.h"
+ #include <iostream>
+
+ using std::map;
+ using std::cerr;
+ using std::vector;
+
+ 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){
+ cerr<<"Adding---------------------------\n";
+ for(map<BasicBlock *, unsigned int>::iterator MI = bbToCid.begin(),
+ ME = bbToCid.end(); MI != ME; ++MI){
+
+ if(!MI->second)
+ continue;
+
+ for(BasicBlock::iterator II = MI->first->begin(), IE = MI->first->end();
+ II != IE; ++II){
+
+ //no map for PHIs
+ if(PHINode *phi = dyn_cast<PHINode>(&*II))
+ continue;
+
+ if(BranchInst *br = dyn_cast<BranchInst>(&*II))
+ continue;
+
+ vector<unsigned int> positions = getLLVMInstrPositionInfo(II);
+
+ if(positions.size() == 0)
+ continue;
+
+ cerr<<II;
+ std::cerr<<"\t\tPushing back\n";
+ for(vector<unsigned int>::iterator PI = positions.begin(),
+ PE = positions.end(); PI != PE; ++PI){
+ uint64_t addr = getBasicBlockInfo(MI->first).first;
+ addr += (*PI)*4;
+
+ 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]){
+ InstrToCid[II].push_back(MI->second+ *PI - 1);
+ std::cerr<<(MI->second+ *PI - 1)<<"\n";
+ }
+ else{
+ InstrToCid[II].push_back(MI->second+ *PI);
+ std::cerr<<(MI->second+ *PI)<<"\n";
+ }
+ }
+ }
+ }
+ cerr<<"-------------------------------\n";
+
+ traceInstructions = cidOffset;
+ unrollFactor = unroll;
+ numberOfEpilogs = (lastSecId - 1);
+ }
+
+ void LLVMTrace::getCids(Instruction *I, vector<unsigned int> &vec){
+ vec.clear();
+ vec.insert(vec.begin(), InstrToCid[I].begin(), InstrToCid[I].end());
+ }
+
+ 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(),
+ VE = InstrToCid[I].end(); VI != VE; ++VI)
+ vec.push_back(*VI+traceInstructions*i);
+ }
+ }
+
+ unsigned int LLVMTrace::getSec(Instruction *I){
+ return InstrToSec[I];
+ }
+
+ void LLVMTrace::getAllSec(Instruction *I, vector<unsigned int> &vec){
+ vec.clear();
+ 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()){
+ std::cerr<<"Moving\n";
+ std::cerr<<I;
+ for(vector<unsigned int>::iterator VI = InstrToCid[I].begin(),
+ VE = InstrToCid[I].end(); VI != VE; ++VI){
+ std::cerr<<"ID: "<<*VI<<"\n";
+ bb->moveToEnd(*VI, sec);
+ }
+ }
+ }
+
+ 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(),
+ VE = InstrToCid[I].end(); VI != VE; ++VI){
+ bb->move_instr(*VI, after);
+ after = *VI;
+ }
+ }
+ }
+
+ 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(),
+ VE = InstrToCid[I].end(); VI != VE; ++VI){
+ bb->move_instr_before(*VI, before);
+ }
+ }
+ }
More information about the llvm-commits
mailing list