[llvm-commits] CVS: reopt/lib/LightWtProfiling/SLI.cpp
Brian Gaeke
gaeke at cs.uiuc.edu
Mon Oct 6 15:51:01 PDT 2003
Changes in directory reopt/lib/LightWtProfiling:
SLI.cpp updated: 1.7 -> 1.8
---
Log message:
Move #defines of BRANCH_ALWAYS and CALL to reopt/InstrUtils.h.
Stdify more names. No more `using namespace std'.
Untabify.
Erase more commented-out code.
Fix more asserts.
Shorten.
---
Diffs of the changes:
Index: reopt/lib/LightWtProfiling/SLI.cpp
diff -u reopt/lib/LightWtProfiling/SLI.cpp:1.7 reopt/lib/LightWtProfiling/SLI.cpp:1.8
--- reopt/lib/LightWtProfiling/SLI.cpp:1.7 Mon Oct 6 12:56:52 2003
+++ reopt/lib/LightWtProfiling/SLI.cpp Mon Oct 6 15:50:01 2003
@@ -12,23 +12,19 @@
#include <algorithm>
#include <cassert>
-using namespace std;
-
extern "C" void llvm_time_end();
extern void countPath();
extern "C" void llvm_first_trigger();
extern void initModules ();
-enum Color{
+enum Color {
WHITE,
GREY,
BLACK
};
-#define BRANCH_ALWAYS 0x10800000
-#define CALL 0x40000000
-
-void doInlining(uint64_t addr1, vector<Function *> &stack, VirtualMem *vm);
+void doInlining(uint64_t addr1, std::vector<Function *> &stack,
+ VirtualMem *vm);
void doBackEdgeDFS(BasicBlock *node,
std::map<BasicBlock*, BasicBlock *> &backedges,
@@ -38,7 +34,7 @@
if (color[*si] == GREY) {
//backedge node->*si
assert(backedges.find(node) == backedges.end() &&
- "Multiple backedges starting at same basic block");
+ "Multiple backedges starting at same basic block");
backedges[node] = *si;
} else if (color[*si] != BLACK) {
assert(color[*si] == WHITE);
@@ -48,65 +44,59 @@
color[node] = BLACK;
}
-void getBackEdges(map<BasicBlock*, BasicBlock *> &backedges, Function *F){
+void getBackEdges (std::map<BasicBlock*, BasicBlock *> &backedges, Function *F){
BasicBlock &root = F->front();
- map<BasicBlock *, Color> color;
+ std::map<BasicBlock *, Color> color;
doBackEdgeDFS(&root, backedges, color);
}
void doForwardDFS(BasicBlock *node,BasicBlock *end,
- std::map<BasicBlock *, BasicBlock *> &backEdges,
- std::map<BasicBlock *, unsigned long> &forward,
- std::map<BasicBlock *, Color> &color){
+ std::map<BasicBlock *, BasicBlock *> &backEdges,
+ std::map<BasicBlock *, unsigned long> &forward,
+ std::map<BasicBlock *, Color> &color){
color[node] = GREY;
forward[node] = 1;
- if(node != end){
- for(succ_iterator s=succ_begin(node), se=succ_end(node); s!=se; ++s){
- //if node -> *s is a backedge, neglect
- if(backEdges[node] == *s)
- continue;
- if(color[*s] == WHITE) {
- doForwardDFS(*s, end, backEdges, forward, color);
- }
- }
- }
+ if (node != end)
+ for (succ_iterator s=succ_begin(node), se=succ_end(node); s!=se; ++s) {
+ //if node -> *s is a backedge, neglect
+ if(backEdges[node] == *s)
+ continue;
+ if(color[*s] == WHITE)
+ doForwardDFS(*s, end, backEdges, forward, color);
+ }
color[node] = BLACK;
}
void getForward(BasicBlock *root, BasicBlock *end,
- std::map<BasicBlock*, BasicBlock *> &backEdges,
- std::map<BasicBlock *, unsigned long> &forward){
+ std::map<BasicBlock*, BasicBlock *> &backEdges,
+ std::map<BasicBlock *, unsigned long> &forward){
//do DFS, avoid backedges, don't go beyond end
std::map<BasicBlock *, Color> color;
doForwardDFS(root, end, backEdges, forward, color);
}
void doBackwardDFS(BasicBlock *node, BasicBlock *start,
- std::map<BasicBlock *, BasicBlock *> &backEdges,
- std::map<BasicBlock *, unsigned long> &forward,
- std::map<BasicBlock *, unsigned long> &backward,
- std::map<BasicBlock *, Color> &color){
+ std::map<BasicBlock *, BasicBlock *> &backEdges,
+ std::map<BasicBlock *, unsigned long> &forward,
+ std::map<BasicBlock *, unsigned long> &backward,
+ std::map<BasicBlock *, Color> &color){
color[node] = GREY;
backward[node] = 1;
- if(node != start){
- for(pred_iterator p=pred_begin(node), pe=pred_end(node); p!=pe; ++p){
- if(forward[*p]){
- if(backEdges[*p] == node){
- continue;
- }
- if(color[*p] == WHITE) {
- doBackwardDFS(*p, start, backEdges, forward, backward, color);
- }
+ if(node != start)
+ for(pred_iterator p=pred_begin(node), pe=pred_end(node); p!=pe; ++p)
+ if(forward[*p]) {
+ if(backEdges[*p] == node)
+ continue;
+ if(color[*p] == WHITE)
+ doBackwardDFS(*p, start, backEdges, forward, backward, color);
}
- }
- }
color[node] = BLACK;
}
void getBackward(BasicBlock *node, BasicBlock *start,
- std::map<BasicBlock*, BasicBlock *> &backEdges,
- std::map<BasicBlock *, unsigned long> &forward,
- std::map<BasicBlock *, unsigned long> &backward){
+ std::map<BasicBlock*, BasicBlock *> &backEdges,
+ std::map<BasicBlock *, unsigned long> &forward,
+ std::map<BasicBlock *, unsigned long> &backward){
//do DFS, avoid backedges, consider only forward edges
std::map<BasicBlock *, Color> color;
doBackwardDFS(node, start, backEdges, forward, backward, color);
@@ -114,27 +104,24 @@
}
void getExit(std::map<BasicBlock *, unsigned long> &backward,
- std::map<BasicBlock *, unsigned long> &exitBBs){
+ std::map<BasicBlock *, unsigned long> &exitBBs){
std::vector<BasicBlock *> toPush;
for(std::map<BasicBlock *, unsigned long>::iterator MI = backward.begin(),
- ME = backward.end(); MI != ME; ++MI){
- for(succ_iterator s=succ_begin(MI->first),
- se=succ_end(MI->first); s != se; ++s){
- if(backward.find(*s) == backward.end()){
- exitBBs[*s] = 1;
- toPush.push_back(*s);
+ ME = backward.end(); MI != ME; ++MI)
+ for (succ_iterator s=succ_begin(MI->first),
+ se=succ_end(MI->first); s != se; ++s)
+ if(backward.find(*s) == backward.end()) {
+ exitBBs[*s] = 1;
+ toPush.push_back(*s);
}
- }
- }
for(std::vector<BasicBlock *>::iterator VI = toPush.begin(),
- VE = toPush.end(); VI != VE; ++VI){
+ VE = toPush.end(); VI != VE; ++VI)
backward[*VI] = 1;
- }
}
void doTraceDFS(BasicBlock *node, std::vector<BasicBlock *> &trace,
- std::map<BasicBlock *, unsigned long> &backward,
- std::map<BasicBlock *, Color> &color){
+ std::map<BasicBlock *, unsigned long> &backward,
+ std::map<BasicBlock *, Color> &color){
color[node] = GREY;
trace.push_back(node);
for(succ_iterator s=succ_begin(node), se=succ_end(node); s != se; ++s)
@@ -145,14 +132,14 @@
}
void getTrace(BasicBlock *root, std::vector<BasicBlock *> &trace,
- std::map<BasicBlock *, unsigned long> &backward){
+ std::map<BasicBlock *, unsigned long> &backward){
//do a DFS from root ONLY on nodes in backward
std::map<BasicBlock *, Color> color;
doTraceDFS(root, trace, backward, color);
}
-void doTraceDFSForFunction(BasicBlock *node, vector<BasicBlock *> &trace,
- map<BasicBlock *, Color> &color){
+void doTraceDFSForFunction(BasicBlock *node, std::vector<BasicBlock *> &trace,
+ std::map<BasicBlock *, Color> &color){
color[node] = GREY;
trace.push_back(node);
for(succ_iterator s=succ_begin(node), se=succ_end(node); s != se; ++s)
@@ -214,7 +201,7 @@
//end node
assert(backEdges.find(end) != backEdges.end() &&
- "No backedge with end found");
+ "No backedge with end found");
//get forward edges
std::map<BasicBlock *, unsigned long> forward;
@@ -266,7 +253,6 @@
trace.push_back(exit_code[0]);
trace.push_back(exit_code[1]);
trace.push_back(call_code[3]);
- //trace.push_back(exit_code[2]);
trace.push_back(BRANCH_ALWAYS);
trace.push_back(NOP);
branchMap[index + 4] = bbStart;
@@ -281,123 +267,123 @@
BasicBlock *taken=NULL, *ntaken=NULL;
TerminatorInst *TI = (*VBI)->getTerminator();
if(isa<BranchInst>(TI)){
- BranchInst *BI = cast<BranchInst>(TI);
- if(BI->isConditional()){
- isCondBranch = true;
- taken = BI->getSuccessor(0);
- ntaken = BI->getSuccessor(1);
- succ0 = getBasicBlockInfo(taken).first;
- succ1 = getBasicBlockInfo(ntaken).first;
- }
+ BranchInst *BI = cast<BranchInst>(TI);
+ if(BI->isConditional()){
+ isCondBranch = true;
+ taken = BI->getSuccessor(0);
+ ntaken = BI->getSuccessor(1);
+ succ0 = getBasicBlockInfo(taken).first;
+ succ1 = getBasicBlockInfo(ntaken).first;
+ }
}
for(uint64_t addr = bbStart; addr <= bbEnd; addr+=4){//loop on BB
- unsigned instr = vm->readInstrFrmVm(addr, tr, tr2);
- if(isIndirectCall(instr)){
- trace.push_back(call_code[0]);
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- trace.push_back(call_code[1]);
- index += 4;
- addr += 4;
- } else if(isCallInstr(instr)){
- uint64_t callTarget = getCallTarget(instr, addr);
- if(callTarget != (uint64_t)(intptr_t)&llvm_first_trigger){
- if(isInlinable(getRevFunction(M, callTarget))){
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- callMap[index] = getCallTarget(instr, addr);
- toInline[callTarget] = 1;
- index += 2;
- addr += 4;
- } else{
- trace.push_back(call_code[0]);
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- trace.push_back(call_code[1]);
- callMap[index+1] = getCallTarget(instr, addr);
- index += 4;
- addr += 4;
- }
- } else{
- trace.push_back(call_code[2]); //save o7
- trace.push_back(loop_top_code[0]);
- trace.push_back(loop_top_code[1]);
- trace.push_back(call_code[3]); //restore o7
- callMap[index+1] = (uint64_t)(intptr_t)&countPath;
- index += 4;
- }
- } else if(isBranchInstr(instr)){//is branch
- assert(!isBranchNever(instr) && "Branch never not handled!");
- if(isBranchAlways(instr)){
- uint64_t target = getBranchTarget(instr, addr);
- if(target == addr1){
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- trace[index] = getBranchInst(instr,
- (uint64_t)(intptr_t)&trace[0],
- (uint64_t)(intptr_t)&trace[index]);
- index += 2;
- } else{
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- BasicBlock *targetBB=NULL;
- assert(getReverseBBMap(getBranchTarget(instr, addr), M, targetBB));
- branchStub[index] = targetBB;
- index += 2;
- }
- addr += 4;
- } else{
+ unsigned instr = vm->readInstrFrmVm(addr, tr, tr2);
+ if(isIndirectCall(instr)){
+ trace.push_back(call_code[0]);
+ trace.push_back(instr);
+ trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+ trace.push_back(call_code[1]);
+ index += 4;
+ addr += 4;
+ } else if(isCallInstr(instr)){
+ uint64_t callTarget = getCallTarget(instr, addr);
+ if(callTarget != (uint64_t)(intptr_t)&llvm_first_trigger){
+ if(isInlinable(getRevFunction(M, callTarget))){
+ trace.push_back(instr);
+ trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+ callMap[index] = getCallTarget(instr, addr);
+ toInline[callTarget] = 1;
+ index += 2;
+ addr += 4;
+ } else{
+ trace.push_back(call_code[0]);
+ trace.push_back(instr);
+ trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+ trace.push_back(call_code[1]);
+ callMap[index+1] = getCallTarget(instr, addr);
+ index += 4;
+ addr += 4;
+ }
+ } else{
+ trace.push_back(call_code[2]); //save o7
+ trace.push_back(loop_top_code[0]);
+ trace.push_back(loop_top_code[1]);
+ trace.push_back(call_code[3]); //restore o7
+ callMap[index+1] = (uint64_t)(intptr_t)&countPath;
+ index += 4;
+ }
+ } else if(isBranchInstr(instr)){//is branch
+ assert(!isBranchNever(instr) && "Branch never not handled!");
+ if(isBranchAlways(instr)){
+ uint64_t target = getBranchTarget(instr, addr);
+ if(target == addr1){
+ trace.push_back(instr);
+ trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+ trace[index] = getBranchInst(instr,
+ (uint64_t)(intptr_t)&trace[0],
+ (uint64_t)(intptr_t)&trace[index]);
+ index += 2;
+ } else{
+ trace.push_back(instr);
+ trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+ BasicBlock *targetBB=NULL;
+ assert(getReverseBBMap(getBranchTarget(instr, addr), M, targetBB));
+ branchStub[index] = targetBB;
+ index += 2;
+ }
+ addr += 4;
+ } else{
assert (isCondBranch);
- uint64_t target = getBranchTarget(instr, addr);
- if (target == succ0) {
- isSucc0 = true;
- fillLater = index;
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- trace.push_back(succ1_code[0]);
- trace.push_back(succ1_code[1]);
- index += 4;
- addr += 4;
- } else {
- fillLater = index;
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- trace.push_back(succ0_code[0]);
- trace.push_back(succ0_code[1]);
- index += 4;
- addr += 4;
- }
- }
- } else{
- trace.push_back(instr);
- index++;
- }
+ uint64_t target = getBranchTarget(instr, addr);
+ if (target == succ0) {
+ isSucc0 = true;
+ fillLater = index;
+ trace.push_back(instr);
+ trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+ trace.push_back(succ1_code[0]);
+ trace.push_back(succ1_code[1]);
+ index += 4;
+ addr += 4;
+ } else {
+ fillLater = index;
+ trace.push_back(instr);
+ trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+ trace.push_back(succ0_code[0]);
+ trace.push_back(succ0_code[1]);
+ index += 4;
+ addr += 4;
+ }
+ }
+ } else{
+ trace.push_back(instr);
+ index++;
+ }
}
if(isCondBranch){
- trace.push_back(0);//dummy
- unsigned int newBranch =
+ trace.push_back(0);//dummy
+ unsigned int newBranch =
getBranchInst(trace[fillLater], (uint64_t)(intptr_t)&trace[index],
(uint64_t)(intptr_t)&trace[fillLater]);
- trace[fillLater] = newBranch;
- if(isSucc0){
- assert((taken != vBB[0]) && "Conditional branch to top!");
- trace[index] = succ0_code[0];
- trace.push_back(succ0_code[1]);
- trace.push_back(BRANCH_ALWAYS);
- trace.push_back(NOP);
- branchStub[index+2] = taken;
- index += 4;
- } else{
- assert((ntaken != vBB[0]) && "Conditional branch to top!");
- trace[index] = succ1_code[0];
- trace.push_back(succ1_code[1]);
- trace.push_back(BRANCH_ALWAYS);
- trace.push_back(NOP);
- branchStub[index+2] = ntaken;
- index += 4;
- }
+ trace[fillLater] = newBranch;
+ if(isSucc0){
+ assert((taken != vBB[0]) && "Conditional branch to top!");
+ trace[index] = succ0_code[0];
+ trace.push_back(succ0_code[1]);
+ trace.push_back(BRANCH_ALWAYS);
+ trace.push_back(NOP);
+ branchStub[index+2] = taken;
+ index += 4;
+ } else{
+ assert((ntaken != vBB[0]) && "Conditional branch to top!");
+ trace[index] = succ1_code[0];
+ trace.push_back(succ1_code[1]);
+ trace.push_back(BRANCH_ALWAYS);
+ trace.push_back(NOP);
+ branchStub[index+2] = ntaken;
+ index += 4;
+ }
}
}
}
@@ -411,24 +397,22 @@
}
- if(!tr->addTrace(addr1, endAddr, trace, 0, callMap, branchMap, tr2)){
- std::cerr<<"Could not add!\n";
- }
+ if(!tr->addTrace(addr1, endAddr, trace, 0, callMap, branchMap, tr2))
+ std::cerr << "Could not add!\n";
DEBUG(std::cerr << "Added-SLI-trace\t" << (void *)addr1 << "\t"
- << (void *)endAddr << "\t" << trace.size() << "\n");
+ << (void *)endAddr << "\t" << trace.size() << "\n");
- for(std::map<uint64_t, int>::iterator MI = toInline.begin(),
- ME = toInline.end(); MI != ME; ++MI) {
- if(!tr->hasTraceAddr(MI->first)){
- vector<Function *> stack;
+ for (std::map<uint64_t, int>::iterator MI = toInline.begin(),
+ ME = toInline.end(); MI != ME; ++MI)
+ if (!tr->hasTraceAddr(MI->first)) {
+ std::vector<Function *> stack;
stack.push_back(root->getParent());
doInlining(MI->first, stack, vm);
}
- }
}
-void doInlining(uint64_t addr1, vector<Function *> &stack, VirtualMem *vm){
+void doInlining(uint64_t addr1, std::vector<Function *> &stack, VirtualMem *vm){
// Make sure we have already parsed the LLVM bytecode and have the
// resulting LLVM Module handy.
if (!M)
@@ -440,16 +424,10 @@
//get BB address
BasicBlock *root = &F->front();
- //BasicBlock *end = &F->back();
- //std::cerr<<F;
-
- //check that end has ret
- //assert(isa<ReturnInst>(end->getTerminator()) && "Not the terminal BB");
-
//get a vector of trace
- vector<BasicBlock *> vBB;
- map<BasicBlock *, Color> color;
+ std::vector<BasicBlock *> vBB;
+ std::map<BasicBlock *, Color> color;
doTraceDFSForFunction(root, vBB, color);
unsigned int initial_code[] = {0x83663001};//0x82102001//move 1 to g1
@@ -462,18 +440,18 @@
//spill o0, g7->o0, call, unspill o0 0x90104000
unsigned int exit_code[] = {CALL, NOP};//call llvm_time_end
- map<int, uint64_t> callMap;
- map<int, uint64_t> branchMap;
- map<BasicBlock *, int> bbPlacement;
- map<int, BasicBlock *> branchStub;
- map<uint64_t, int> toInline;
+ std::map<int, uint64_t> callMap;
+ std::map<int, uint64_t> branchMap;
+ std::map<BasicBlock *, int> bbPlacement;
+ std::map<int, BasicBlock *> branchStub;
+ std::map<uint64_t, int> toInline;
int index = 0;
- vector<unsigned int> trace;
+ std::vector<unsigned int> trace;
//generate a vector of instructions
//assume: succ[0] is 0, succ[1] is 1
- for(vector<BasicBlock *>::iterator VBI = vBB.begin(), VBE = vBB.end();
+ for(std::vector<BasicBlock *>::iterator VBI = vBB.begin(), VBE = vBB.end();
VBI != VBE; ++VBI){//loop on vBB
std::pair<uint64_t, uint64_t> bbInst = getBasicBlockInfo(*VBI);
@@ -492,165 +470,126 @@
if(isa<BranchInst>(TI)){
BranchInst *BI = cast<BranchInst>(TI);
if(BI->isConditional()){
- isCondBranch = true;
- taken = BI->getSuccessor(0);
- ntaken = BI->getSuccessor(1);
- succ0 = getBasicBlockInfo(taken).first;
- succ1 = getBasicBlockInfo(ntaken).first;
+ isCondBranch = true;
+ taken = BI->getSuccessor(0);
+ ntaken = BI->getSuccessor(1);
+ succ0 = getBasicBlockInfo(taken).first;
+ succ1 = getBasicBlockInfo(ntaken).first;
}
}
-
for(uint64_t addr = bbStart; addr <= bbEnd; addr+=4){//loop on BB
unsigned instr = vm->readInstrFrmVm(addr, tr, tr2);
-
- if(isIndirectCall(instr)){
- trace.push_back(call_code[0]);
+ if (isIndirectCall(instr)) {
+ trace.push_back(call_code[0]);
+ trace.push_back(instr);
+ trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+ trace.push_back(call_code[1]);
+ index += 4;
+ addr += 4;
+ } else if (isCallInstr(instr)) {
+ uint64_t callTarget = getCallTarget(instr, addr);
+ if(callTarget != (uint64_t)(intptr_t)&llvm_first_trigger){
+ if(isInlinable(getRevFunction(M, callTarget)) &&
+ find(stack.begin(), stack.end(),
+ getRevFunction(M, callTarget)) == stack.end()){
+ trace.push_back(instr);
+ trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+ callMap[index] = getCallTarget(instr, addr);
+ toInline[callTarget] = 1;
+ index += 2;
+ addr += 4;
+ } else {
+ trace.push_back(call_code[0]);
+ trace.push_back(instr);
+ trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+ trace.push_back(call_code[1]);
+ callMap[index+1] = getCallTarget(instr, addr);
+ index += 4;
+ addr += 4;
+ }
+ } else {
+ trace.push_back(call_code[2]); //save o7
+ trace.push_back(loop_top_code[0]);
+ trace.push_back(loop_top_code[1]);
+ trace.push_back(call_code[3]); //restore o7
+ callMap[index+1] = (uint64_t)(intptr_t)&countPath;
+ index += 4;
+ }
+ } else if(isBranchInstr(instr)){//is branch
+ assert ((isBranchAlways (instr) || isCondBranch)
+ && "Unhandled type of branch instruction");
+ uint64_t target = getBranchTarget(instr, addr);
trace.push_back(instr);
- //trace.push_back(NOP);
trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- trace.push_back(call_code[1]);
- index += 4;
+ if (isBranchAlways(instr)) {
+ BasicBlock *targetBB = NULL;
+ assert(getReverseBBMap(getBranchTarget(instr, addr), M, targetBB));
+ branchStub[index] = targetBB;
+ index += 2;
+ } else if (isCondBranch) {
+ fillLater = index;
+ if (target == succ0) {
+ isSucc0 = true;
+ trace.push_back(succ1_code[0]);
+ trace.push_back(succ1_code[1]);
+ } else{
+ trace.push_back(succ0_code[0]);
+ trace.push_back(succ0_code[1]);
+ }
+ index += 4;
+ }
addr += 4;
- }
- else if(isCallInstr(instr)){
- uint64_t callTarget = getCallTarget(instr, addr);
- if(callTarget != (uint64_t)(intptr_t)&llvm_first_trigger){
- if(isInlinable(getRevFunction(M, callTarget)) &&
- find(stack.begin(), stack.end(),
- getRevFunction(M, callTarget)) == stack.end()){
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- callMap[index] = getCallTarget(instr, addr);
- toInline[callTarget] = 1;
- index += 2;
- addr += 4;
- }
- else{
- trace.push_back(call_code[0]);
- trace.push_back(instr);
- //trace.push_back(NOP);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- trace.push_back(call_code[1]);
- callMap[index+1] = getCallTarget(instr, addr);
- index += 4;
- addr += 4;
- }
- }
- else{
- trace.push_back(call_code[2]); //save o7
- trace.push_back(loop_top_code[0]);
- trace.push_back(loop_top_code[1]);
- trace.push_back(call_code[3]); //restore o7
- callMap[index+1] = (uint64_t)(intptr_t)&countPath;
- index += 4;
- }
- }
- else if(isBranchInstr(instr)){//is branch
- assert(!isBranchNever(instr) && "Branch never not handled!");
- if(isBranchAlways(instr)){
- uint64_t target = getBranchTarget(instr, addr);
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
-
- BasicBlock *targetBB=NULL;
- assert(getReverseBBMap(getBranchTarget(instr, addr), M, targetBB));
- branchStub[index] = targetBB;
- index += 2;
- addr += 4;
- }
- else{
- if(isCondBranch){
- uint64_t target = getBranchTarget(instr, addr);
- if(target == succ0){
- isSucc0 = true;
- fillLater = index;
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- trace.push_back(succ1_code[0]);
- trace.push_back(succ1_code[1]);
- index += 4;
- addr += 4;
- }
- else{
- fillLater = index;
- trace.push_back(instr);
- trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
- trace.push_back(succ0_code[0]);
- trace.push_back(succ0_code[1]);
- index += 4;
- addr += 4;
- }
- }
- else{
- assert(false && "Should not be here!");
- }
- }
- }
- else{
- trace.push_back(instr);
- index++;
+ } else {
+ trace.push_back(instr);
+ index++;
}
}
- if(isCondBranch){
+ if (isCondBranch) {
trace.push_back(0);//dummy
-
- unsigned int newBranch = getBranchInst(trace[fillLater],
- (uint64_t)(intptr_t)&trace[index],
- (uint64_t)(intptr_t)&trace[fillLater]);
-
+ unsigned int newBranch =
+ getBranchInst(trace[fillLater],
+ (uint64_t)(intptr_t)&trace[index],
+ (uint64_t)(intptr_t)&trace[fillLater]);
trace[fillLater] = newBranch;
-
- if(isSucc0){
- trace[index] = succ0_code[0];
- trace.push_back(succ0_code[1]);
- trace.push_back(BRANCH_ALWAYS);
- trace.push_back(NOP);
-
- if(taken == vBB[0]){
- assert(false && "Conditional branch to top!");
- }
- branchStub[index+2] = taken;
- index += 4;
- }
- else{
- trace[index] = succ1_code[0];
- trace.push_back(succ1_code[1]);
- trace.push_back(BRANCH_ALWAYS);
- if(ntaken == vBB[0]){
- assert(false && "Conditional branch to top!");
- }
- branchStub[index+2] = ntaken;
- trace.push_back(NOP);
- index += 4;
+ if (isSucc0) {
+ assert ((taken != vBB[0]) && "Conditional branch to top!");
+ trace[index] = succ0_code[0];
+ trace.push_back(succ0_code[1]);
+ branchStub[index+2] = taken;
+ } else {
+ assert ((ntaken != vBB[0]) && "Conditional branch to top!");
+ trace[index] = succ1_code[0];
+ trace.push_back(succ1_code[1]);
+ branchStub[index+2] = ntaken;
}
+ trace.push_back(BRANCH_ALWAYS);
+ trace.push_back(NOP);
+ index += 4;
}
-
}
- for(map<int, BasicBlock *>::iterator MI = branchStub.begin(),
- ME = branchStub.end(); MI != ME; ++MI){
- trace[MI->first] = getBranchInst(trace[MI->first],
- (uint64_t)(intptr_t)&trace[bbPlacement[MI->second]],
- (uint64_t)(intptr_t)&trace[MI->first]);
+ for (std::map<int, BasicBlock *>::iterator MI = branchStub.begin(),
+ ME = branchStub.end(); MI != ME; ++MI) {
+ trace[MI->first] =
+ getBranchInst(trace[MI->first],
+ (uint64_t)(intptr_t)&trace[bbPlacement[MI->second]],
+ (uint64_t)(intptr_t)&trace[MI->first]);
}
uint64_t fakeEnd = 0;
- if(F->size() > 1){
- if(!tr->addTrace(addr1, fakeEnd, trace, 0, callMap, branchMap, tr2)){
- std::cerr<<"Could not add!\n";
- }
- }
+ if (F->size() > 1)
+ if (!tr->addTrace(addr1, fakeEnd, trace, 0, callMap, branchMap, tr2))
+ std::cerr << "Could not add!\n";
DEBUG(std::cerr << "Added-SLI-inline\t" << (void *)addr1 << "\t" <<
- trace.size() << "\n");
+ trace.size() << "\n");
- for(map<uint64_t, int>::iterator MI = toInline.begin(), ME = toInline.end();
- MI != ME; ++MI){
- if(!tr->hasTraceAddr(MI->first)){
+ for (std::map<uint64_t, int>::iterator MI = toInline.begin(),
+ ME = toInline.end(); MI != ME; ++MI)
+ if (!tr->hasTraceAddr(MI->first)) {
stack.push_back(root->getParent());
doInlining(MI->first, stack, vm);
}
- }
}
More information about the llvm-commits
mailing list