LoopManager.cpp

Go to the documentation of this file.
00001 
00012     #include "LoopManager.hpp"
00013 using namespace std;
00014 
00015 namespace OA {
00016   namespace Loop {
00017 
00018 using namespace AffineExpr;
00019 
00020 
00021 class Statistics {
00022   public:
00023     enum LoopType {
00024         LOOP_LEGAL,
00025         LOOP_ILLEGAL,
00026         LOOP_NONE
00027     };
00028 
00029     enum Linearity {
00030         LINEARITY_FULL,
00031         LINEARITY_PARTIAL,
00032         LINEARITY_NONE
00033     };
00034 
00035 
00036     Statistics() :
00037         mnLinear(0),
00038         mnPartial(0),
00039         mnNonLinear(0),
00040         mnNotInLoop(0),
00041         mnInInvalidLoop(0),
00042         mnInValidLoop(0)
00043     { }
00044 
00045     int getNumLinear()    { return mnLinear; }
00046     int getNumPartial()   { return mnPartial; }
00047     int getNumNonLinear() { return mnNonLinear; }
00048 
00049     int getNumNotInLoop()   { return mnNotInLoop; }
00050     int getNumInvalidLoop() { return mnInValidLoop; }
00051     int getNumValidLoop()   { return mnInValidLoop; }
00052 
00053     void incrementAccessCounter(Linearity linearity, LoopType type);
00054     void output();
00055 
00056   private:
00057     int mnLinear;
00058     int mnPartial;
00059     int mnNonLinear;
00060 
00061     int mnNotInLoop;
00062     int mnInInvalidLoop;
00063     int mnInValidLoop;
00064 };
00065 
00066 void Statistics::incrementAccessCounter(Linearity linearity, LoopType type) {
00067     switch(linearity) {
00068         case LINEARITY_FULL:
00069             mnLinear++;
00070             break;
00071 
00072         case LINEARITY_PARTIAL:
00073             mnPartial++;
00074             break;
00075 
00076         case LINEARITY_NONE:
00077             mnNonLinear++;
00078             break;
00079     }
00080 
00081     switch(type) {
00082         case LOOP_LEGAL:
00083             mnInValidLoop++;
00084             break;
00085 
00086         case LOOP_ILLEGAL:
00087             mnInInvalidLoop++;
00088             break;
00089 
00090         case LOOP_NONE:
00091             mnNotInLoop++;
00092             break;
00093     }
00094 }
00095 
00096 void Statistics::output() {
00097     cout << "Array Access Statistics: " << endl;
00098     cout << " Linearity" << endl;
00099     cout << "   Linear:           " << getNumLinear() << endl;
00100     cout << "   Partially Linear: " << getNumPartial() << endl;
00101     cout << "   Nonlinear:        " << getNumNonLinear() << endl;
00102     cout << " Loops" << endl;
00103     cout << "   Not In Loop:      " << getNumNonLinear() << endl;
00104     cout << "   In Invalid Loop nest:  " << getNumInvalidLoop() << endl;
00105     cout << "   In Valid Loop nest:    " << getNumValidLoop() << endl;
00106     cout << "   In partial Loop nest:  "  /* !!! */ << "!!!" << endl;
00107 }
00108 
00109 
00110 
00111 OA_ptr<LoopResults> LoopManager::performLoopDetection(
00112         ProcHandle proc)
00113 {
00114     OA_ptr<LoopResults> results;
00115     results = new LoopResults(*mIR);
00116 
00117     // For now call a method in the interface which performs a loop
00118     // detection analysis for us.  This is a temporary strategy.
00119     OA_ptr<list<OA_ptr<LoopAbstraction> > > loops;
00120     loops = mIR->gatherLoops(proc);
00121 
00122     // Encode results
00123     for(list<OA_ptr<LoopAbstraction> >::iterator i = loops->begin();
00124         i != loops->end(); i++)
00125     {
00126         results->addLoop(*i);
00127     }
00128 
00129     return results;
00130 }
00131 
00132 } } // end namespaces
00133