[llvm-commits] CVS: llvm/lib/Reoptimizer/Trigger/RuntimeOptimizations.cpp
Anand Shukla
ashukla at cs.uiuc.edu
Sat May 31 21:36:00 PDT 2003
Changes in directory llvm/lib/Reoptimizer/Trigger:
RuntimeOptimizations.cpp added (r1.1)
---
Log message:
Runtime optimization passes
---
Diffs of the changes:
Index: llvm/lib/Reoptimizer/Trigger/RuntimeOptimizations.cpp
diff -c /dev/null llvm/lib/Reoptimizer/Trigger/RuntimeOptimizations.cpp:1.1
*** /dev/null Sat May 31 21:34:14 2003
--- llvm/lib/Reoptimizer/Trigger/RuntimeOptimizations.cpp Sat May 31 21:34:04 2003
***************
*** 0 ****
--- 1,116 ----
+ //===-------------llvm/Reoptimizer/Trigger/RuntimeOptimizations---*- C++ -*--=//
+ //
+ // It performs optimizations at run time on a trace
+ //
+ // This file contains several passes to be performed over the
+ // trace of LLVM basic blocks
+ //
+ //===----------------------------------------------------------------------===//
+
+ #include "llvm/Reoptimizer/BinInterface/LLVMTrace.h"
+ #include "llvm/Reoptimizer/BinInterface/sparcbin.h"
+ #include "llvm/Reoptimizer/BinInterface/analyze.h"
+ #include "llvm/Reoptimizer/BinInterface/bitmath.h"
+ #include "llvm/Reoptimizer/BinInterface/sparc9.h"
+ #include "llvm/Function.h"
+ #include "TriggerAuxillary.h"
+
+ //remove all Trigger instrumentation code
+ void removeInstrumentation(Function *F, LLVMTrace <race, BinInterface &bin,
+ unsigned int secId, unsigned int cidOffset){
+ //Move instrumentation instructions out into epilogs
+ //First sort the instructions by first CID
+ vector<Instruction *> instToRemv;
+ findAllRegs(F, instToRemv);
+ map<unsigned int, Instruction *> tempMapSort;
+ for(vector<Instruction *>::iterator VRI = instToRemv.begin(),
+ VRE = instToRemv.end(); VRI != VRE; ++VRI){
+ vector<unsigned int> cidsForInstr;
+ ltrace.getCids(*VRI, cidsForInstr);
+ if(cidsForInstr.size())
+ tempMapSort[cidsForInstr[0]] = *VRI;
+ }
+
+ vector<Instruction *> sortedVecToRem;
+ for(map<unsigned int, Instruction *>::iterator MI = tempMapSort.begin(),
+ ME = tempMapSort.end(); MI != ME; ++MI)
+ sortedVecToRem.push_back(MI->second);
+
+ //get CID for 1st instruction in each section
+ map<unsigned int, unsigned int> cidFirstInstr;
+ for(unsigned int i = SECTION_TRACE+1; i < UNROLL_FACTOR*(secId - 2) + 2; i++){
+ cidFirstInstr[i] = bin.begin(i);
+ }
+
+ map<unsigned int, unsigned int> ssaIn;
+ for(vector<Instruction *>::iterator VRI = sortedVecToRem.begin(),
+ VRE = sortedVecToRem.end(); VRI != VRE; ++VRI){
+ if(ltrace.getSec(*VRI) == 0){
+ vector<unsigned int> cidsForInstr;
+ ltrace.getCids(*VRI, cidsForInstr);
+ for(vector<unsigned int>::iterator CRI = cidsForInstr.begin(),
+ CRE = cidsForInstr.end(); CRI != CRE; ++CRI){
+ bin.moveToEnd(*CRI, SECTION_PROLOG);
+ }
+
+ //remove rest of the instructions
+ vector<unsigned int> allCidsForInstr;
+ ltrace.getAllCids(*VRI, allCidsForInstr);
+ unsigned int origSize = cidsForInstr.size();
+ for(unsigned int i = origSize, e = allCidsForInstr.size();
+ i < e; i++){
+ bin.remove(allCidsForInstr[i]);
+ ssaIn[allCidsForInstr[i]] = cidsForInstr[i%origSize];
+ }
+ }
+ else{
+ vector<unsigned int> cidsForInstr;
+ ltrace.getCids(*VRI, cidsForInstr);
+ for(unsigned int i = 0; i < UNROLL_FACTOR; i++){
+ for(vector<unsigned int>::iterator CRI = cidsForInstr.begin(),
+ CRE = cidsForInstr.end(); CRI != CRE; ++CRI){
+ unsigned int myCid = *CRI + cidOffset*i;
+ bin.move_instr_before(myCid, cidFirstInstr[ltrace.getSec(*VRI) +
+ (secId - 2)*i]);
+ if(i > 0 && bin.hasrs1(myCid)){
+ unsigned int rs1Cid = bin.getrs1(myCid);
+ if(ssaIn.find(rs1Cid) != ssaIn.end())
+ bin.setrs1(myCid, ssaIn[rs1Cid]);
+ }
+
+ if(i > 0 && bin.hasrs2(myCid)){
+ unsigned int rs2Cid = bin.getrs2(myCid);
+ if(ssaIn.find(rs2Cid) != ssaIn.end())
+ bin.setrs2(myCid, ssaIn[rs2Cid]);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ //Optimization passes
+ //vBB is trace of basic blocks: THE hot path we are optimizing
+ //It is safe to assume that vBB has a loop (last basic block
+ //has a jump to first one
+ //
+ //F is function
+ //
+ //ltrace is LLVM trace
+ //it contains mapping of Instruction* to a set of integers (machine instrs)
+ //this integer can be used to manipulate the correspondingmachine instruction
+ //
+ //totalSections is the total number of sections in the machine code
+ //totalSections = number of epilogs + 2 (TRACE_SECTION+ PROLOG)
+ //
+ //totalInstructions is the number of machine instructions inside
+ //TRACE_SECTION excluding branches
+ //This number could be useful when a loop has been unrolled
+ void optimizationPasses(Function *F, vector<BasicBlock *> &vBB,
+ LLVMTrace <race, BinInterface &bin,
+ unsigned int totalSections,
+ unsigned int totalInstructions){
+
+ //removeInstrumentation(F, ltrace, bin, totalSections, totalInstructions);
+
+ }
More information about the llvm-commits
mailing list