[llvm-commits] CVS: llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp

Brian Gaeke gaeke at cs.uiuc.edu
Fri Aug 8 14:35:01 PDT 2003


Changes in directory llvm/lib/Reoptimizer/LightWtProfiling/Trigger:

SecondTrigger.cpp updated: 1.10 -> 1.11

---
Log message:

Remove garbage from end of lines.
Re-indent and organize the huge if...else if...else statement into paragraphs
 with 1 paragraph per case.
Write many new comments, including comments for each case, and for some
 of the asserts.


---
Diffs of the changes:

Index: llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp
diff -u llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp:1.10 llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp:1.11
--- llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp:1.10	Thu Aug  7 23:05:43 2003
+++ llvm/lib/Reoptimizer/LightWtProfiling/Trigger/SecondTrigger.cpp	Fri Aug  8 14:33:50 2003
@@ -624,8 +624,8 @@
     uint64_t lastPC = pc;
     bool sawUnconditional = false;
 
-    while(!(seenStartPC && pc==start)){///while   
-      lastPC = pc; 
+    while(!(seenStartPC && pc==start)) {
+      lastPC = pc;
      
       //so in the end, if we end the loop through second
       //while condition, we'd know which PC was branch.
@@ -644,45 +644,46 @@
         }
       }
      
-
-      unsigned int instr = vm->readInstrFrmVm(pc, tr, tr2);//, tr2);//, tr2);
+      unsigned int instr = vm->readInstrFrmVm(pc, tr, tr2);
       
-      //case: unconditional jump
-      //neglect the branch, copy the delay slot
-      assert(! isBranchNever(instr));
-      if(isBranchInstr(instr)  && (isBranchAlways(instr) ) ){
-        //push in the delay slot
-        if(insertCode){
+      // case: unconditional jump
+      // Don't copy the branch, but copy the instruction in the delay
+      // slot following it. Then start copying from the branch's
+      // target.
+      assert((! isBranchNever (instr))
+	     && "Unsupported branch never instruction found!");
+      if (isBranchInstr (instr) && isBranchAlways (instr)) {
+	if(insertCode){
+	  // Copy the instruction in the branch's delay slot, unless
+	  // it's a NOP.
 	  unsigned dslot = vm->readInstrFrmVm(pc+4, tr, tr2);
 	  if(dslot != NOP){
-	    traces.push_back(dslot);//, tr2));
+	    traces.push_back(dslot);
 	    index++;
 	  }
-        }
-        pc = getBranchTarget(instr, pc);
-        sawUnconditional = true;
-        continue;
+	}
+	// Start copying from the branch's target.
+	pc = getBranchTarget(instr, pc);
+	sawUnconditional = true;
       }
 
-      //case: call instruction
-      //just rewrite the target later. Right now, just store the index
-      if(isReturn(instr)){
-	//assert(callStack.size() && "Stack empty and a return is found!");
+      // case: return instruction
+      // Don't copy the return, but copy the instruction in the delay
+      // slot following it. Then pop the call stack and start copying
+      // from where we left off in the caller.
+      else if (isReturn(instr)) {
+	// If we find a return we must have previously found the
+	// corresponding call.
 	if(!callStack.size()){
 	  tr->patchTrace(firstLevelTraceStartAddr);
-	  assert(0 && "Found return");
-#ifdef GET_ALL_INFO
-	  std::cerr<<"Found-return\n";
-#endif
+	  assert(0 && "Call stack empty and return instruction found!");
 	  return;
 	}
-
 #ifdef GET_ALL_INFO
 	numberOfFunctions++;
 #endif
-
 	if(insertCode){
-	  //insert DS
+	  // Copy the instruction in the return's delay slot.
 	  traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));
 	  index++;
 	}
@@ -690,6 +691,10 @@
 	callStack.pop_back();
 	calledStack.pop_back();
       }
+
+      // case: indirect call instruction
+      // Copy the call instruction and the instruction in the delay
+      // slot following it.
       else if(isIndirectCall(instr)){
 	if(insertCode){
 #ifdef GET_COVERAGE
@@ -703,7 +708,6 @@
 	  traces.push_back(instr);
 	  traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));
 	  index += 2;
-
 #ifdef GET_COVERAGE
 	  traces.push_back(0xde77a7ef);//save o7
 	  traces.push_back(CALL);
@@ -716,19 +720,21 @@
 	pc += 8;
       }
 
+      // case: ordinary call instruction
+      // If the function being called is simple enough to inline, then
+      // inline it; i.e. we continue copying instructions from the
+      // beginning of the called function. Otherwise, we proceed as
+      // with an indirect call, unless the target of the call is a
+      // reoptimizer entry point.
       else if(isCallInstr(instr)){
         uint64_t callTarget = getCallTarget(instr, pc);
-
 	Function *callFunc = getRevFunction(M, callTarget);
-
 	//inline the function if its just one basic block
 	//avoid recursion
-
 	if(callFunc && isInlinable(callFunc) && 
 	   (callFunc->size() == 1 || tr->hasTraceAddr(callTarget)) && 
 	   std::find(calledStack.begin(), calledStack.end(), callTarget) 
 	   == calledStack.end()){
-	  
 	  //push DS, and set PC to new target
 	  if(insertCode){
 	    //std::cerr<<"Inlining function\n";
@@ -738,18 +744,19 @@
 	    //if(callFunc->size() > 1)
 	    getReturnCode(traces, index, pc);
 	  }
-	  
 	  callStack.push_back(pc+8); //return address
 	  calledStack.push_back(callTarget);
 	  pc = callTarget;
-	  
 	}
 	else{
-
+	  // Can't inline the called function
 	  if(callTarget != (uint64_t)llvm_first_trigger && callTarget != 
 	     (uint64_t)countPath){
+	    // Ordinary function being called; copy the call
+	    // instruction and the instruction in the delay slot
+	    // following it. Record the call target function in the
+	    // call map.
 	    if(insertCode){
-
 #ifdef GET_COVERAGE
 	      traces.push_back(0xde77a7ef);//save o7
 	      traces.push_back(CALL);
@@ -774,39 +781,41 @@
 	    }
 	  }
 	  else{
+	    // Reoptimizer entry point being called; skip the call,
+	    // but copy its delay slot instruction.
 	    if(insertCode){
 	      traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));
 	      index += 1;
 	    }
 	  }
-
 	  pc += 8;
 	}
       }
 
-      //case: conditional branch
+      // case: conditional branch
+      // If the branch was taken, then insert an opposite branch to
+      // the fall-through. Then follow the taken branch, continuing to
+      // copy instructions starting from the branch's target.  If the
+      // branch was not taken, then copy the branch and its delay
+      // slot instruction. 
       else if(isBranchInstr(instr)){
-
         int nextTrace = -1;
         if(myIntersections && myIntersections->find(pathIndex) != 
-           myIntersections->end())// && pathNumber==0)
+           myIntersections->end())
           nextTrace = (*myIntersections)[pathIndex];
-
-        //is it taken?
+        // Check bit number pathIndex of firstPath to see whether the
+        // branch was taken.
         if(firstPath & (1ULL << pathIndex)){
-
 #ifdef GET_ALL_INFO
           std::cerr<<" taken \t";
 #endif
-
           if(insertCode){
-            //invert the branch, and use the fall through as the target
+            // Invert the branch, and use the fall-through as the target.
 	    assert(!(instr & 0x20000000));
 	    unsigned brInstr = vm->getInvertedBranch(instr);
 	    if(isNonDepJump(brInstr))
 	      brInstr = (brInstr & 0xfff7ffff);
             traces.push_back(brInstr);
-
             if(nextTrace < 0){
               targetMap[index] = pc+8;
             }
@@ -815,44 +824,45 @@
                      && "a given trace can have only one entry");
               targetTraceMap[nextTrace] = index;
             }
-            
-            traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));;//, tr2));
+            traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));
             index +=2;
           }
-          //continue pc from the target of the branch
+          // Continue copying instructions from the target of the branch.
           pc = getBranchTarget(instr, pc);
         }
         else{
+	  // Not-taken branch: just copy the branch and the
+	  // instruction in the delay slot following it.
           if(insertCode){
-            //just copy the branch
 	    if(isNonDepJump(instr))
 	      instr = instr & 0xfff7ffff;
- 
             traces.push_back(instr);
-
             if(nextTrace < 0){
               targetMap[index] = getBranchTarget(instr, pc);
             }
             else{
               targetTraceMap[nextTrace] = index;
             }
-            
-            
-            traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));//, tr2));
+            traces.push_back(vm->readInstrFrmVm(pc+4, tr, tr2));
             index +=2;
           }
-                  
           pc += 8;
         }
-      
-        //increment pathIndex
-
+        // Increment pathIndex here to make sure that the next time we
+        // process a conditional branch, we get the next branch's
+        // profile data.
         pathIndex++;
       }
+
+      // case: unsupported control flow transfer instructions (???)
+      // FIXME: This matches a lot of different instructions; what
+      // kind of instruction is really unsupported here?
       else if((instr & 0x81c70000) == 0x81c70000){
-	assert(0);
+	assert(0 && "Unsupported JMP/JMPL/RETT/TN/SAVE/ADDXCC instr. found!");
       }
-      //just copy the instruction
+
+      // case: default
+      // All other instructions are just copied into the traces vector.
       else{
         if(insertCode){
 	  if(instr!=NOP){
@@ -862,10 +872,10 @@
         }
         pc += 4;
       }
-    }
+    } // End of while loop.
 
     if(sawUnconditional){
-       //insert branch back to top!
+      //insert branch back to top!
       unsigned int br = vm->readInstrFrmVm(lastPC, tr, tr2);//, tr2);
       assert(isBranchInstr(br));
       unsigned int ds = vm->readInstrFrmVm(lastPC+4, tr, tr2);//, tr2);





More information about the llvm-commits mailing list