Thread: [Compbench-devel] CompBenchmarks++/libcompbenchmarks/Plan Plan.cpp, 1.8, 1.9 Plan.h, 1.5, 1.6
Brought to you by:
xfred
From: Frederic T. <xf...@us...> - 2007-05-17 14:33:08
|
Update of /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Plan In directory sc8-pr-cvs4.sourceforge.net:/tmp/cvs-serv9288 Modified Files: Plan.cpp Plan.h Log Message: Many improvements (uses PlanBatch). Index: Plan.h =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Plan/Plan.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Plan.h 15 Feb 2007 18:59:19 -0000 1.5 --- Plan.h 17 May 2007 14:33:04 -0000 1.6 *************** *** 18,27 **** %{ #include <Benchmark/Benchmark.h> %} #include <Benchmark/Benchmark.h> #define CBM_BM CBM::Benchmark ! #else # define CBM_BM class Benchmark #endif --- 18,35 ---- %{ #include <Benchmark/Benchmark.h> + #include <Compiler/Compiler-OptionSet.h> + #include <Plan/Plan-Batch.h> %} #include <Benchmark/Benchmark.h> + #include <Compiler/Compiler-OptionSet.h> #define CBM_BM CBM::Benchmark ! #define CBM_OS CBM::CompilerOptionSet ! #define CBM_OP CBM::CompilerOptions ! #define CBM_PB CBM::PlanBatch #else # define CBM_BM class Benchmark + # define CBM_OS class CompilerOptionSet + # define CBM_OP class CompilerOptions + # define CBM_PB class PlanBatch #endif *************** *** 32,38 **** class Plan { protected: ! std::vector<class Compiler *> compilers; /*!< Compilers */ ! std::vector<std::string> compilerOptions; /*!< Compilers' optimisations */ ! std::vector<class Benchmark *> benchmarks; /*!< Benchmarks */ /** Current iteration. --- 40,44 ---- class Plan { protected: ! std::vector<CBM_PB*> planBatch; /** Current iteration. *************** *** 42,71 **** int iteration; ! virtual int isUnique(class Compiler *_compiler); ! virtual int isUnique(std::string _options); ! virtual int isUnique(class Benchmark *_benchmark); ! ! virtual void restoreBenchmarks(class XMLNode *_benchmarksNode); ! virtual void restoreCompilers(class XMLNode *_compilersNode); ! virtual void restoreOptions(class XMLNode *_optionsNode); public: Plan(); ! virtual int add(class Compiler *_compiler); ! virtual int add(std::string _options); ! virtual int add(class Benchmark *_benchmark); ! ! virtual int remove(class Compiler *_compiler); ! virtual int remove(std::string _options); ! virtual int remove(class Benchmark *_benchmark); ! virtual int compilerNumber(void); ! virtual int compilerOptionNumber(void); ! virtual int benchmarkNumber(void); - virtual class Compiler* getCompiler(int _index); - virtual std::string getCompilerOptions(int _index); - virtual CBM_BM *getBenchmark(int _index); virtual int totalIterations(void); --- 48,64 ---- int iteration; ! virtual CBM_PB *batchForIteration(int *it_in_plan); public: Plan(); ! virtual CBM_PB *addBatch(std::string _id); ! virtual void removeBatch(CBM_PB *_ps); ! virtual void removeBatch(std::string _id); ! virtual int batchNumber(void); ! virtual CBM_PB *getBatch(std::string _id); ! virtual CBM_PB *getBatch(int i); virtual int totalIterations(void); *************** *** 73,77 **** virtual int currentIteration(void); virtual class Compiler* currentCompiler(void); ! virtual std::string currentCompilerOptions(void); virtual class Benchmark *currentBenchmark(void); --- 66,70 ---- virtual int currentIteration(void); virtual class Compiler* currentCompiler(void); ! virtual CBM_OP *currentCompilerOptions(void); virtual class Benchmark *currentBenchmark(void); Index: Plan.cpp =================================================================== RCS file: /cvsroot/compbench/CompBenchmarks++/libcompbenchmarks/Plan/Plan.cpp,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Plan.cpp 19 Feb 2007 18:42:51 -0000 1.8 --- Plan.cpp 17 May 2007 14:33:04 -0000 1.9 *************** *** 7,12 **** --- 7,14 ---- ------------------------------------------------------------------------- */ #include <Plan/Plan.h> + #include <Plan/Plan-Batch.h> #include <Compiler/Compiler.h> #include <Compiler/Compiler-Options.h> + #include <Compiler/Compiler-OptionSet.h> #include <Benchmark/Benchmark.h> #include <System/System.h> *************** *** 23,266 **** } ! int Plan::isUnique(CBM::Compiler *_compiler) ! { ! int i; ! int n = compilerNumber(); ! CBM::Compiler *C; ! ! for(i=0; i<n; i++) { ! C=getCompiler(i); ! if (C->Name() == _compiler->Name()) { ! return(0); ! } ! } ! return(1); ! } ! ! int Plan::isUnique(std::string _options) ! { ! int i; ! int n = compilerOptionNumber(); ! std::string O; ! ! for(i=0; i<n; i++) { ! O=getCompilerOptions(i); ! if (O == _options) ! return(0); ! } ! return(1); ! } ! ! int Plan::isUnique(CBM::Benchmark *_benchmark) ! { ! int i; ! int n = benchmarkNumber(); ! CBM::Benchmark *B; ! ! for(i=0; i<n; i++) { ! B=getBenchmark(i); ! if (B->Name() == _benchmark->Name()) ! return(0); ! } ! ! return(1); ! } ! ! void Plan::restoreBenchmarks(CBM::XMLNode *_benchmarksNode) ! { ! int i; ! int n = _benchmarksNode->nodeNumber(); ! CBM::XMLNode *N; ! CBM::XMLAttribute *A; ! CBM::Benchmark *B; ! ! for(i=0; i<n; i++) { ! N=_benchmarksNode->getNode(i); ! if (N->Name() != "benchmark") ! continue; ! A=N->getAttribute("id"); ! if (!A) ! continue; ! B=cbmSystem->Benchmark(A->Value()); ! add(B); ! } ! } ! ! void Plan::restoreCompilers(CBM::XMLNode *_compilersNode) { ! int i; ! int n = _compilersNode->nodeNumber(); ! CBM::XMLNode *N; ! CBM::XMLAttribute *A; ! CBM::CompilerSelector *SC; ! CBM::Compiler *C; ! ! SC=new CBM::CompilerSelector(cbmSystem); ! ! for(i=0; i<n; i++) { ! N=_compilersNode->getNode(i); ! if (N->Name() != "compiler") ! continue; ! A=N->getAttribute("id"); ! if (!A) ! continue; ! C=SC->select((char*) A->Value().c_str()); ! add(C); ! } ! delete(SC); ! } ! void Plan::restoreOptions(CBM::XMLNode *_optionsNode) ! { ! int i; ! int n = _optionsNode->nodeNumber(); ! CBM::XMLNode *N; ! CBM::XMLAttribute *A; ! for(i=0; i<n; i++) { ! N=_optionsNode->getNode(i); ! if (N->Name() != "option") ! continue; ! A=N->getAttribute("value"); ! if (!A) ! continue; ! add(A->Value()); } } ! ! int Plan::add(CBM::Compiler *_compiler) { ! if ((!_compiler) || (!isUnique(_compiler))) { ! return(0); ! } ! ! compilers.push_back(_compiler); ! _compiler->setPlan(this, 0); ! stop(); ! return(1); ! } ! int Plan::add(std::string _compilerOptions) ! { ! if (!isUnique(_compilerOptions)) { ! return(0); } ! compilerOptions.push_back(_compilerOptions); ! stop(); ! return(1); } ! int Plan::add(CBM::Benchmark *_benchmark) { ! if ((!_benchmark) || (!isUnique(_benchmark))) { return(0); - } - - _benchmark->setPlan(this, 0); - benchmarks.push_back(_benchmark); - stop(); - return(1); } ! int Plan::remove(CBM::Compiler *_compiler) { ! int i; ! int n = compilerNumber(); ! CBM::Compiler *C = 0; ! std::vector<CBM::Compiler*> ncompilers; ! ! for(i=0; i<n; i++) { ! C=getCompiler(i); ! if (C!=_compiler) ! ncompilers.push_back(C); ! else ! C->setPlan(0,0); ! } ! compilers=ncompilers; ! stop(); ! return(1); ! } ! int Plan::remove(std::string _options) ! { ! int i; ! int n = compilerOptionNumber(); ! std::string O; ! std::vector<std::string> noptions; ! ! for(i=0; i<n; i++) { ! O=getCompilerOptions(i); ! if (O!=_options) ! noptions.push_back(O); ! } ! compilerOptions=noptions; stop(); ! return(1); } ! int Plan::remove(CBM::Benchmark *_benchmark) { int i; ! int n = benchmarkNumber(); ! CBM::Benchmark *B = 0; ! std::vector<CBM::Benchmark*> nbenchmarks; for(i=0; i<n; i++) { ! B=getBenchmark(i); ! if (B!=_benchmark) ! nbenchmarks.push_back(B); ! else ! B->setPlan(0,0); } stop(); - benchmarks=nbenchmarks; - return(1); } ! ! int Plan::compilerNumber(void) ! { ! return(compilers.size()); ! } ! ! int Plan::compilerOptionNumber(void) ! { ! return(compilerOptions.size()); ! } ! ! int Plan::benchmarkNumber(void) ! { ! return(benchmarks.size()); ! } ! ! CBM::Compiler *Plan::getCompiler(int _index) { ! if (_index<compilerNumber()) ! return(compilers[_index]); ! else ! return(0); ! } ! std::string Plan::getCompilerOptions(int _index) ! { ! if (_index<compilerOptionNumber()) ! return(compilerOptions[_index]); ! else ! return(""); } ! CBM::Benchmark *Plan::getBenchmark(int _index) { ! if (_index<benchmarkNumber()) ! return(benchmarks[_index]); ! else ! return(0); } int Plan::totalIterations(void) { ! return(compilerNumber()*compilerOptionNumber()*benchmarkNumber()); } --- 25,118 ---- } ! CBM::PlanBatch *Plan::batchForIteration(int *it_in_plan) { ! CBM::PlanBatch *c; ! int i, n = batchNumber(); ! int c_it; ! int I = currentIteration(); ! for(i=0;i<n;i++) { ! c=planBatch[i]; ! c_it=c->totalIterations(); ! if (I>c_it) ! I-=c_it; ! else { ! (*it_in_plan)=I; ! return(c); ! } } + return(0); } ! CBM::PlanBatch *Plan::getBatch(std::string _id) { ! PlanBatch *c; ! int i, n = batchNumber(); ! for(i=0;i<n;i++) { ! c=planBatch[i]; ! if (c->Id()==_id) ! return(c); } ! return(0); } ! CBM::PlanBatch *Plan::getBatch(int i) { ! if (i<batchNumber()) ! return(planBatch[i]); ! else return(0); } ! CBM::PlanBatch *Plan::addBatch(std::string _id) { ! PlanBatch *result = new PlanBatch(_id); ! planBatch.push_back(result); stop(); ! return(result); } ! void Plan::removeBatch(PlanBatch *_ps) { int i; ! int n = batchNumber(); ! CBM::PlanBatch *B = 0; ! std::vector<CBM::PlanBatch*> nplanBatch; for(i=0; i<n; i++) { ! B=getBatch(i); ! if (B!=_ps) ! nplanBatch.push_back(B); } + planBatch=nplanBatch; stop(); } ! void Plan::removeBatch(std::string _id) { ! PlanBatch *c = getBatch(_id); ! if (c) ! removeBatch(c); } ! int Plan::batchNumber(void) { ! return(planBatch.size()); } int Plan::totalIterations(void) { ! int i, n = batchNumber(); ! int r = 0; ! ! for(i=0;i<n;i++) { ! r+=getBatch(i)->totalIterations(); ! } ! return(r); } *************** *** 272,296 **** CBM::Compiler *Plan::currentCompiler(void) { ! int compilerIndex = (iteration/(compilerOptionNumber()*benchmarkNumber()))%compilerNumber(); ! CBM::Compiler *C = getCompiler(compilerIndex); ! ! return(C); } ! std::string Plan::currentCompilerOptions(void) { ! int optionIndex = (iteration/benchmarkNumber())%compilerOptionNumber(); ! ! std::string O = getCompilerOptions(optionIndex); ! ! return(O); } CBM::Benchmark *Plan::currentBenchmark(void) { ! int benchmarkIndex = iteration%benchmarkNumber(); ! CBM::Benchmark *B = getBenchmark(benchmarkIndex); ! ! return(B); } --- 124,144 ---- CBM::Compiler *Plan::currentCompiler(void) { ! int loc; ! CBM::PlanBatch *pb = batchForIteration(&loc); ! return(pb->currentCompiler()); } ! CBM::CompilerOptions *Plan::currentCompilerOptions(void) { ! int loc; ! CBM::PlanBatch *pb = batchForIteration(&loc); ! return(pb->currentCompilerOptions()); } CBM::Benchmark *Plan::currentBenchmark(void) { ! int loc; ! CBM::PlanBatch *pb = batchForIteration(&loc); ! return(pb->currentBenchmark()); } *************** *** 313,317 **** } C=currentCompiler(); - o=currentCompilerOptions(); B=currentBenchmark(); P=B->Package(); --- 161,164 ---- *************** *** 324,328 **** testOk="0"; ! O=new CBM::CompilerOptions(o); P->Configure(C, O); if (P->Make()) { --- 171,176 ---- testOk="0"; ! O=currentCompilerOptions(); ! P->Configure(C, O); if (P->Make()) { *************** *** 353,405 **** CBM::XMLNode *Plan::XML(void) { ! XMLNode *root = new CBM::XMLNode("plan"); ! XMLNode *S = new CBM::XMLNode("selection"); ! ! XMLNode *SB = new CBM::XMLNode("benchmarks"); ! XMLNode *SC = new CBM::XMLNode("compilers"); ! XMLNode *SO = new CBM::XMLNode("options"); ! ! XMLNode *R = new CBM::XMLNode("run"); ! XMLNode *I = new CBM::XMLNode("current-iteration"); ! ! XMLNode *tmp; ! std::string str; char c[32]; ! int i; ! int n; ! ! root->add(S); ! root->add(R); ! ! S->add(SB); ! S->add(SC); ! S->add(SO); ! ! n=benchmarkNumber(); ! for(i=0; i<n; i++) { ! tmp=new CBM::XMLNode("benchmark"); ! tmp->addAttribute("id", getBenchmark(i)->Name()); ! SB->add(tmp); ! } ! ! n=compilerNumber(); ! for(i=0; i<n; i++) { ! tmp=new CBM::XMLNode("compiler"); ! tmp->addAttribute("id", getCompiler(i)->Binary()); ! SC->add(tmp); ! } ! n=compilerOptionNumber(); ! for(i=0; i<n; i++) { ! tmp=new CBM::XMLNode("option"); ! tmp->addAttribute("value", getCompilerOptions(i)); ! SO->add(tmp); ! } ! R->add(I); sprintf(c, "%d", currentIteration()); str=c; I->addAttribute("index", str); return(root); } --- 201,224 ---- CBM::XMLNode *Plan::XML(void) { ! XMLNode *root = new CBM::XMLNode("plan"); ! XMLNode *batchs = new CBM::XMLNode("plan-batchs"); ! XMLNode *run = new CBM::XMLNode("run"); ! XMLNode *I = new CBM::XMLNode("iteration"); char c[32]; + std::string str; ! int i, n = batchNumber(); ! root->add(batchs); ! ! for(i=0;i<n;i++) ! batchs->add(getBatch(i)->XML()); ! root->add(run); ! run->add(I); sprintf(c, "%d", currentIteration()); str=c; I->addAttribute("index", str); + return(root); } *************** *** 407,410 **** --- 226,235 ---- void Plan::stop(void) { + int i, n = batchNumber(); + + for(i=0;i<n;i++) { + getBatch(i)->stop(); + } + iteration=0; } *************** *** 412,430 **** void Plan::reset(void) { ! CBM::Compiler *C; ! CBM::Benchmark *B; ! std::string O; ! ! while ( (C=getCompiler(0)) != 0 ) { ! delete(C); ! } ! while ( (B=getBenchmark(0)) != 0 ) { delete(B); } - - while ( (O=getCompilerOptions(0)) != "") { - remove(O); - } } --- 237,245 ---- void Plan::reset(void) { ! CBM::PlanBatch *B; ! while ( (B=getBatch(0)) != 0 ) { delete(B); } } *************** *** 439,449 **** int Plan::restore(XMLNode *_planRootNode) { ! XMLNode *S; XMLNode *R; - XMLNode *BM; - XMLNode *CO; - XMLNode *OP; XMLNode *CI; XMLAttribute *A; if (!_planRootNode) --- 254,265 ---- int Plan::restore(XMLNode *_planRootNode) { ! XMLNode *PBs; XMLNode *R; XMLNode *CI; + XMLNode *tmp; XMLAttribute *A; + int i, n; + + PlanBatch *pb; if (!_planRootNode) *************** *** 451,480 **** reset(); ! S=_planRootNode->getNode("selection"); ! if (!S) return(0); R=_planRootNode->getNode("run"); if (!R) return(0); - BM=S->getNode("benchmarks"); - if (!BM) - return(0); - - restoreBenchmarks(BM); - - CO=S->getNode("compilers"); - if (!CO) - return(0); - - restoreCompilers(CO); - - OP=S->getNode("options"); - if (!OP) - return(0); - - restoreOptions(OP); - CI=R->getNode("current-iteration"); if (!CI) --- 267,289 ---- reset(); ! PBs=_planRootNode->getNode("plan-batchs"); ! if (!PBs) return(0); + n=PBs->nodeNumber(); + for(i=0; i<n;i++) { + tmp=PBs->getNode(i); + if (tmp->Name()=="plan-batch") { + pb=new PlanBatch(""); + pb->restore(tmp); + planBatch.push_back(pb); + } + + } + R=_planRootNode->getNode("run"); if (!R) return(0); CI=R->getNode("current-iteration"); if (!CI) |