[llvm-commits] CVS: reopt/lib/LightWtProfiling/SLI.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Sun Dec 5 23:56:25 PST 2004



Changes in directory reopt/lib/LightWtProfiling:

SLI.cpp updated: 1.23 -> 1.24
---
Log message:

Add more comments, and a couple of very slight refactorings...
no functional changes.


---
Diffs of the changes:  (+59 -30)

Index: reopt/lib/LightWtProfiling/SLI.cpp
diff -u reopt/lib/LightWtProfiling/SLI.cpp:1.23 reopt/lib/LightWtProfiling/SLI.cpp:1.24
--- reopt/lib/LightWtProfiling/SLI.cpp:1.23	Thu Sep 23 14:48:34 2004
+++ reopt/lib/LightWtProfiling/SLI.cpp	Mon Dec  6 01:56:14 2004
@@ -282,31 +282,43 @@
   std::map<int, BasicBlock *> branchStub; 
   std::map<uint64_t, int> toInline;
 
+  // index should always be equal to the size of the trace.
   int index = 0;
   std::vector<unsigned int> trace; 
-  //generate a vector of instructions
-  trace.push_back(initial_code[0]);
+
+  // Start generating a vector of binary instruction words.
+  trace.push_back(initial_code[0]); // Start with %g1 = 1.
   index += 1; 
 
   //assume: succ[0] is 0, succ[1] is 1
   for(std::vector<BasicBlock *>::iterator VBI = vBB.begin(), VBE = vBB.end();
-      VBI != VBE; ++VBI){//loop on vBB
+      VBI != VBE; ++VBI){
+    // We're looping over the basic blocks in the trace, copying their
+    // machine code into the trace vector. First get the start and end 
+    // addresses of the basic block's machine code:
     std::pair<uint64_t, uint64_t> bbInst = getBasicBlockInfo(*VBI);
     uint64_t bbStart = bbInst.first;
     uint64_t bbEnd = bbInst.second;
-    if(exitBBs.find(*VBI) != exitBBs.end()){ //is an exit BB
-      bbPlacement[*VBI] = index;
-      trace.push_back(call_code[2]);
-      trace.push_back(exit_code[0]);
-      trace.push_back(exit_code[1]);
-      trace.push_back(call_code[3]);
-      trace.push_back(BRANCH_ALWAYS);
-      trace.push_back(NOP);
-      branchMap[index + 4] = bbStart;
+
+    // Keep track of where we're going to emit this block's machine code
+    // into the SLI trace:
+    bbPlacement[*VBI] = index;
+
+    if(exitBBs.find(*VBI) != exitBBs.end()){
+      // This basic block is a trace-exiting BB. We don't trace it; rather, we
+      // emit a call to llvm_time_end() to account for the trace exit, and then
+      // we emit a branch to the original version of this BB (at bbStart).
+      trace.push_back(call_code[2]);  // save %o7 to stack
+      trace.push_back(exit_code[0]);  // call llvm_time_end
       callMap[index+1] = (uint64_t)(intptr_t)(&llvm_time_end);
+      trace.push_back(exit_code[1]);  // nop
+      trace.push_back(call_code[3]);  // restore %o7 from stack
+      trace.push_back(BRANCH_ALWAYS); // ba bbStart
+      branchMap[index + 4] = bbStart;
+      trace.push_back(NOP);           // nop
       index += 6;
-    } else{ //This is not an exit BB
-      bbPlacement[*VBI] = index;
+    } else{
+      // This is a regular, non-trace-exiting BB.
       bool isCondBranch = false;
       int fillLater = 0;
       bool isSucc0 = false;
@@ -326,53 +338,69 @@
       
       for(uint64_t addr = bbStart; addr <= bbEnd; addr+=4){//loop on BB
         unsigned instr = vm->readInstrFrmVm(addr, tr, tr2);
+        // We're looping over the instructions in the BB, possibly modifying 
+        // them as we go along, and copying them into the trace. instr is
+        // the current instruction.
         if(isIndirectCall(instr)){
-          trace.push_back(call_code[0]);
-          trace.push_back(instr);
+          trace.push_back(call_code[0]);  // save %g1 to stack
+          trace.push_back(instr);         // do the indirect call
           trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
-          trace.push_back(call_code[1]);
+                                          // copy delay-slot instr.
+          trace.push_back(call_code[1]);  // restore %g1 from stack
           index += 4;
           addr += 4;
         } else if(isCallInstr(instr)){
           uint64_t callTarget = getCallTarget(instr, addr);
           if(callTarget != (uint64_t)(intptr_t)&llvm_first_trigger){
+            // This is a real call, not FLI instrumentation...
             if(isInlinable(getRevFunction(M, callTarget))){
-              trace.push_back(instr);
-              trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+              trace.push_back(instr);        // do the call
               callMap[index] = getCallTarget(instr, addr);
+              trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+                                             // copy delay-slot instr.
+              // Remember that we're going to inline this call.
               toInline[callTarget] = 1;
               index += 2;
             } 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]);
+              trace.push_back(call_code[0]); // save %g1 to stack
+              trace.push_back(instr);        // do the call
               callMap[index+1] = getCallTarget(instr, addr);
+              trace.push_back(vm->readInstrFrmVm(addr+4, tr, tr2));
+                                             // copy delay-slot instr.
+              trace.push_back(call_code[1]); // restore %g1 from stack
               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
+          } else {
+            // Calls to llvm_first_trigger are replaced with
+            // calls to countPath.
+            trace.push_back(call_code[2]);     // save %o7 on stack
+            trace.push_back(loop_top_code[0]); // call countPath
             callMap[index+1] = (uint64_t)(intptr_t)&countPath;
+            trace.push_back(loop_top_code[1]); // nop
+            trace.push_back(call_code[3]);     // restore %o7 from stack
             index += 4;
           }
-        } else if(isBranchInstr(instr)){//is branch
+        } else if(isBranchInstr(instr)){
+          // Handle branch always and conditional branches.
           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));
             if(target == brTarget){
+              // Branch to beginning of the loop - replace it with a branch to
+              // the beginning of the SLI trace.
               trace[index] = getBranchInst(instr, 
                                            (uint64_t)(intptr_t)&trace[0], 
                                            (uint64_t)(intptr_t)&trace[index]);
 
             } else{
+              // Branch to somewhere else - put it in our "stub" list for
+              // a fixup, below.
               BasicBlock *targetBB=NULL;
-              bool found = getReverseBBMap(getBranchTarget(instr, addr), M, targetBB);
+              bool found = getReverseBBMap(getBranchTarget(instr, addr), M,
+                                           targetBB);
               assert(found);
               branchStub[index] = targetBB;
             }
@@ -396,6 +424,7 @@
             addr += 4;
           }
         } else{
+          // All other instructions are simply copied.
           trace.push_back(instr);
           index++;
         }






More information about the llvm-commits mailing list