[llvm-commits] CVS: llvm/lib/Reoptimizer/Trigger/Trigger.cpp
Anand Shukla
ashukla at cs.uiuc.edu
Sat Sep 21 00:05:06 PDT 2002
Changes in directory llvm/lib/Reoptimizer/Trigger:
Trigger.cpp updated: 1.10 -> 1.11
---
Log message:
added exit stubs for outgoing branches!
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/Trigger/Trigger.cpp
diff -u llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.10 llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.11
--- llvm/lib/Reoptimizer/Trigger/Trigger.cpp:1.10 Fri Sep 20 11:46:46 2002
+++ llvm/lib/Reoptimizer/Trigger/Trigger.cpp Sat Sep 21 00:04:26 2002
@@ -18,6 +18,7 @@
#include <map>
using std::vector;
+using std::map;
extern int llvm_length;
extern const unsigned char LLVMBytecode[];
@@ -25,6 +26,10 @@
void getBBtrace(vector<BasicBlock *> &vBB, int pathNo, Function *M);
+void getBranchExitCode(vector<unsigned int> &instVec,
+ map<int, int> &branchMap,
+ map<int, uint64_t> &targetMap);
+
extern "C" void llvmInitializeCounter(int *cnt, int k){
for(int i=0; i<k; i++)
cnt[i]=0;
@@ -82,21 +87,9 @@
assert(funcList[mn] && "Function not parsed!");
- // ******* SET THE count THRESHOLD HERE ***********
- //if(cnt < 39 || cnt%39!=0) return;
- //for(int ppn = 0; ppn<8; ppn++){
- //getBBtrace(vBB, pn, funcList[mn]);
std::vector<BasicBlock *> vBB;
- //for(int ppn =0; ppn<8; ppn++){
- //std::vector<BasicBlock *> vBB;
- //getBBtrace(vBB, ppn, funcList[mn]);
- //printTrace(vBB, ppn);
- //}
-
- //exit(0);
-
getBBtrace(vBB, pn, funcList[mn]);
//return;//just measure time to retrace!
@@ -149,12 +142,16 @@
//map of call instructions
std::map<int, uint64_t> callMap;
+ //branch target map!
+ std::map<int, uint64_t> targetMap;
+
//map of branches
- std::map<int, uint64_t> branchMap; //branch at index, was located at PC
+ std::map<int, int> branchMap; //branch at index, was located at PC
int instIndex = 0;
//Now iterate ove trace of BBs, and insert them into the cache
+
for(vector<BasicBlock *>::iterator VBI = vBB.begin(), VBE = vBB.end();
VBI!=VBE; ++VBI){
@@ -201,7 +198,7 @@
//then read until last 4
int skipIndex = (isCondBranch ? 4:2);
- //std::cerr<<"From->to"<<(void *)bbInst.first<<"->"<<(void *)(bbInst.second-4*skipIndex)<<"\n";
+ std::cerr<<"From->to\t"<<(void *)bbInst.first<<"->"<<(void *)(bbInst.second-4*skipIndex)<<"\n";
for(uint64_t addr = bbInst.first, endAddr = bbInst.second;
addr<=endAddr-4*skipIndex; addr+=4, instIndex++){
@@ -239,8 +236,6 @@
if(isCallInstr(instrCheck)){
callMap[instIndex] = bbInst.second - 12;
- //std::cerr<<(void *)instrCheck;
- //std::cerr<<"\t\tcall is index:"<<instIndex<<"\t address: "<<bbInst.second-12<<"\n";
}
instIndex++;
@@ -261,23 +256,9 @@
std::pair<uint64_t, uint64_t> bbDest = getBasicBlockInfo(*VBNext);
//get branch br1 and br2 targets to check if any matches bbDest
uint64_t tar1, tar2;
- if(isNonDepJump(br1))
- tar1 = getNonDepJmpTarget(br1, addrbr1);
- else if(isDepJump(br1))
- tar1 = getDepJmpTarget(br1, addrbr1);
- else if(isBPR(br1))
- tar1 = getBPRTarget(br1, addrbr1);
- else{
- //std::cerr<<(void *)br1<<"\n";
- assert(false && "Branch not handled 1!");
- }
- if(isNonDepJump(br2))
- tar2 = getNonDepJmpTarget(br2, addrbr2);
- else if(isDepJump(br2))
- tar2 = getDepJmpTarget(br2, addrbr2);
- else
- assert(false && "Branch not handled!");
+ tar1 = getBranchTarget(br1, addrbr1);
+ tar2 = getBranchTarget(br2, addrbr2);
assert( (tar1 == bbDest.first || tar2 == bbDest.first) &&
"No destination matched for consecutive BBs");
@@ -291,29 +272,19 @@
//and eliminate first branch!
//take the target of br2 and inverted condition of br1
- std::pair<unsigned int, unsigned int> invertedBranch =
- vm->getInvertedBranch(br1, br2);
+ unsigned int invertedBranch = vm->getInvertedBranch(br1);
- //insert (del cmp) ds1, cmp, br2, ds2 in the trace (in that order)
+ //insert ds1, br2, ds2 in the trace (in that order)
//store branches and PCs for later correction in branchMap
- unsigned int last_inst = trace[instIndex-1];
- if(invertedBranch.first == 0){
- trace[instIndex-1] = ds1;
- trace.push_back(last_inst);
- }
- else
- trace.push_back(ds1);
-
+ trace.push_back(ds1);
instIndex++;
- if(invertedBranch.first != 0){
- trace.push_back(invertedBranch.first);
- instIndex++;
- }
- trace.push_back(invertedBranch.second);
- branchMap[instIndex] = addrbr2;
+
+ trace.push_back(invertedBranch);
+ //branchMap[instIndex] = addrbr2;
+ targetMap[instIndex] = getBranchTarget(br2, addrbr2);
+
trace.push_back(ds2);
- //trace.push_back(ds1);
instIndex += 2;
}
else{
@@ -321,12 +292,9 @@
//insert into trace br1, ds1, ds2
trace.push_back(br1);
- //store branch index and PC for later correction in branchMap
- branchMap[instIndex] = addrbr1;
- if(isBPR(br1)){
- trace.push_back(0);
- instIndex++;
- }
+ //branchMap[instIndex] = addrbr1;
+ targetMap[instIndex] = getBranchTarget(br1, addrbr1);
+
trace.push_back(ds1);
trace.push_back(ds2);
@@ -337,46 +305,26 @@
//check that it points to first BB
std::pair<uint64_t, uint64_t> bbDest = getBasicBlockInfo(*(vBB.begin()));
+
//get branch br1 and br2 targets to check if any matches bbDest
uint64_t tar1, tar2;
- if(isNonDepJump(br1))
- tar1 = getNonDepJmpTarget(br1, addrbr1);
- else if(isDepJump(br1))
- tar1 = getDepJmpTarget(br1, addrbr1);
- else
- assert(false && "Branch not handled!");
-
- if(isNonDepJump(br2))
- tar2 = getNonDepJmpTarget(br2, addrbr2);
- else if(isDepJump(br2))
- tar2 = getDepJmpTarget(br2, addrbr2);
- else
- assert(false && "Branch not handled!");
-
- //assert( (tar1 == bbDest.first || tar2 == bbDest.first) &&
- // "Last BB must point to first BB");
+
+ tar1 = getBranchTarget(br1, addrbr1);
+ tar2 = getBranchTarget(br2, addrbr2);
assert(tar2 == bbDest.first && "Last BB must point to first BB");
-
- //insert code
- //trace.push_back(br1);
- //branchMap[instIndex] = addrbr1;
- //if(isBPR(br1)){
- //trace.push_back(0);
- //instIndex++;
- //}
+ //remove br1: it ALWAYS goes to target!
trace.push_back(ds1);
+ instIndex++;
- trace.push_back(br2);
- branchMap[instIndex+1] = addrbr2;
- if(isBPR(br2)){
- trace.push_back(0);
- instIndex++;
- }
-
+ //point new branch to the tracehead!
+ trace.push_back(br2);
+ unsigned int newBr = getBranchInst(br2, (uint64_t)(&trace[0]), (uint64_t)(&trace[instIndex]));
+ trace[instIndex] = newBr;
+
trace.push_back(ds2);
- instIndex += 3;
+ instIndex += 2;
}
}
//is unconditional branch
@@ -394,8 +342,6 @@
if(isCallInstr(instrCheck)){
callMap[instIndex] = bbInst.second - 4;
- //std::cerr<<(void *)instrCheck;
- //std::cerr<<"\t\tcall is index:"<<instIndex<<"\t address: "<<bbInst.second-4<<"\n";
}
instIndex++;
@@ -415,18 +361,9 @@
std::pair<uint64_t, uint64_t> bbDest = getBasicBlockInfo(*(VBI+1));
//get branch br1 target to check if it matches bbDest
- uint64_t tar1, tar2;
-
- if(isNonDepJump(br1))
- tar1 = getNonDepJmpTarget(br1, addrbr1);
- else if(isDepJump(br1))
- tar1 = getDepJmpTarget(br1, addrbr1);
- else if(isBPR(br1))
- tar1 = getBPRTarget(br1, addrbr1);
- else{
- //std::cerr<<(void *)br1<<"\n";
- assert(false && "Branch not handled!");
- }
+ uint64_t tar1 = getBranchTarget(br1, addrbr1);
+
+ assert(tar1 == bbDest.first && "The trace is not continuous!");
//copy ds1, and tht's all
trace.push_back(ds1);
@@ -437,21 +374,12 @@
std::pair<uint64_t, uint64_t> bbDest =
getBasicBlockInfo(*(vBB.begin()));
- uint64_t tar1;
- if(isNonDepJump(br1))
- tar1 = getNonDepJmpTarget(br1, addrbr1);
- else if(isDepJump(br1))
- tar1 = getDepJmpTarget(br1, addrbr1);
- else if(isBPR(br1))
- tar1 = getBPRTarget(br1, addrbr1);
- else{
- //std::cerr<<(void *)br1<<"\n";
- assert(false && "Branch not handled!");
- }
+ uint64_t tar1 = getBranchTarget(br1, addrbr1);
assert(tar1 == bbDest.first && "Last BB must point to first BB");
trace.push_back(br1);
- branchMap[instIndex] = addrbr1;
+ //branchMap[instIndex] = addrbr1;
+ targetMap[instIndex] = getBranchTarget(br1, addrbr1);
trace.push_back(ds1);
instIndex += 2;
@@ -459,7 +387,82 @@
}
}
+ //insert exit code!
+ getBranchExitCode(trace, branchMap, targetMap);
//Now add trace to cache, and we are all set!
if(!tr->addTrace(startAddr, trace, pn, callMap, branchMap))
std::cerr<<"^^^^^^^^^^************** Trace could not be added!!!\n";
+}
+
+
+void getBranchExitCode(vector<unsigned int> &instVec,
+ map<int, int> &branchMap,
+ map<int, uint64_t> &targetMap){
+
+ //for each branch, insert code!
+ int instIndex = instVec.size();
+
+ for(map<int, uint64_t>::iterator MI = targetMap.begin(), ME = targetMap.end();
+ MI != ME; ++MI){
+ unsigned int instr = instVec[MI->first];
+ uint64_t pc = MI->second;
+
+ //save %io, ad1
+ unsigned int stx1 = 0xf077a000|0x7f7; //stx %i0, %fp+offset-8
+ unsigned int stx2 = 0xf277a000|0x7ef; //stx %i1, offset-16
+
+ //sethi
+ uint64_t target = targetMap[MI->first];
+
+ unsigned int r1 = ((target>>32)&(0xfffff000))>>10;
+ unsigned int r2 = (target>>32)&(0xfff);
+ unsigned int sethi1 = 0x31000000 | r1;
+
+ //or %i0, r2, %i0
+ unsigned int or1 = 0xb0162000|r2;
+
+ //sllx %i0, 32, %i1
+ unsigned int sllx = 0xb32e3020;
+
+ //sethi2
+ unsigned int r11 = ((target)&(0xfffff000))>>10;
+ unsigned int r22 = (target)&(0xfff);
+ unsigned int sethi2 = 0x31000000 | r11;
+
+ //or %i0, r22, %i0
+ unsigned int or2 = 0xb0162000|r22;
+
+ //add %i0, %i1, %i0
+ unsigned int add = 0xb0064018;
+
+ //load ad1, %i0
+ unsigned load1 = 0xf05fa000|0x7f7;
+ //load ad2, %i1
+ unsigned load2 = 0xf25fa000|0x7ef;
+
+ //jumpl %i0
+ unsigned int jmpl = 0x81c62000;
+
+ //insert instructions into instVec
+ instVec.push_back(stx1);
+ instVec.push_back(stx2);
+ instVec.push_back(sethi1);
+ instVec.push_back(or1);
+ instVec.push_back(sllx);
+ instVec.push_back(sethi2);
+ instVec.push_back(or2);
+ instVec.push_back(add);
+ instVec.push_back(load2);
+ instVec.push_back(jmpl);
+ instVec.push_back(load1); //delay slot!
+
+ uint64_t newInst = getBranchInst(instr, (uint64_t)(&instVec[instIndex]), (uint64_t)(&instVec[MI->first]));
+ instVec[MI->first] = newInst;
+
+ //change original call map to point to new PC
+ branchMap.erase(MI->first);
+ branchMap[MI->first] = instIndex;
+
+ instIndex += 11;
+ }
}
More information about the llvm-commits
mailing list