void findCandidateFunctionDefinitions (SgProject* project, std::vector<SgFunctionDefinition* >& candidateFuncDefs) { ROSE_ASSERT (project != NULL); // For each source file in the project SgFilePtrList & ptr_list = project->get_fileList(); for (SgFilePtrList::iterator iter = ptr_list.begin(); iter!=ptr_list.end(); iter++) { SgFile* sageFile = (*iter); SgSourceFile * sfile = isSgSourceFile(sageFile); ROSE_ASSERT(sfile); // SgGlobal *root = sfile->get_globalScope(); if (enable_debug) cout<<"Processing each function within the files "<< sfile->get_file_info()->get_filename() <<endl; // cout<<"\t loop at:"<< cur_loop->get_file_info()->get_line() <<endl; // This is wrong, many functions in question are not top level declarations!! //SgDeclarationStatementPtrList& declList = root->get_declarations (); //VariantVector vv; Rose_STL_Container<SgNode*> defList = NodeQuery::querySubTree(sfile, V_SgFunctionDefinition); // bool hasOpenMP= false; // flag to indicate if omp.h is needed in this file //For each function body in the scope //for (SgDeclarationStatementPtrList::iterator p = declList.begin(); p != declList.end(); ++p) for (Rose_STL_Container<SgNode*>::iterator p = defList.begin(); p != defList.end(); ++p) { SgFunctionDefinition *defn = isSgFunctionDefinition(*p); ROSE_ASSERT (defn != NULL); SgFunctionDeclaration *func = defn->get_declaration(); ROSE_ASSERT (func != NULL); if (enable_debug) cout<<"\t considering function "<< func->get_name() << " at "<< func->get_file_info()->get_line()<<endl; //ignore functions in system headers, Can keep them to test robustness if (defn->get_file_info()->get_filename()!=sageFile->get_file_info()->get_filename()) { if (enable_debug) cout<<"\t Skipped since the function's associated file name does not match current file being considered. Mostly from a header. "<<endl; continue; } candidateFuncDefs.push_back(defn); } // end for def list } // end for file list }
int main ( int argc, char * argv[] ) { //init_poet(); // initialize poet if (argc <= 1) { PrintUsage(argv[0]); return -1; } #ifdef USE_OMEGA std::stringstream buffer; buffer << argv[argc-1] << std::endl; DepStats.SetFileName(buffer.str()); #endif vector<string> argvList(argv, argv + argc); CmdOptions::GetInstance()->SetOptions(argvList); ArrayAnnotation* array_annot = ArrayAnnotation::get_inst(); array_annot->register_annot(); //OperatorSideEffectAnnotation* funcAnnot=OperatorSideEffectAnnotation::get_inst(); //funcAnnot->register_annot(); LoopTransformInterface::set_sideEffectInfo(array_annot); ArrayInterface anal(*array_annot); LoopTransformInterface::set_arrayInfo(&anal); ReadAnnotation::get_inst()->read(); if (DebugAnnot()) { // funcAnnot->Dump(); array_annot->Dump(); } AssumeNoAlias aliasInfo; LoopTransformInterface::set_aliasInfo(&aliasInfo); LoopTransformInterface::cmdline_configure(argvList); SgProject *sageProject = new SgProject ( argvList); FixFileInfo(sageProject); // DQ (11/19/2013): Added AST consistency tests. AstTests::runAllTests(sageProject); int filenum = sageProject->numberOfFiles(); for (int i = 0; i < filenum; ++i) { // DQ (11/19/2013): Added AST consistency tests. AstTests::runAllTests(sageProject); SgSourceFile* sageFile = isSgSourceFile(sageProject->get_fileList()[i]); ROSE_ASSERT(sageFile != NULL); std::string fname = sageFile->get_file_info()->get_raw_filename(); fname=fname.substr(fname.find_last_of('/')+1); AutoTuningInterface tuning(fname); LoopTransformInterface::set_tuningInterface(&tuning); SgGlobal *root = sageFile->get_globalScope(); ROSE_ASSERT(root != NULL); SgDeclarationStatementPtrList declList = root->get_declarations (); // DQ (11/19/2013): Added AST consistency tests. AstTests::runAllTests(sageProject); for (SgDeclarationStatementPtrList::iterator p = declList.begin(); p != declList.end(); ++p) { SgFunctionDeclaration *func = isSgFunctionDeclaration(*p); if (func == 0) continue; SgFunctionDefinition *defn = func->get_definition(); if (defn == 0) continue; SgBasicBlock *stmts = defn->get_body(); AstInterfaceImpl scope(stmts); // DQ (11/19/2013): Added AST consistency tests. AstTests::runAllTests(sageProject); // DQ (11/19/2013): Added AST consistency tests. AstTests::runAllTests(sageProject); LoopTransformInterface::TransformTraverse(scope,AstNodePtrImpl(stmts)); #if 0 // DQ (11/19/2013): Added AST consistency tests (this fails). AstTests::runAllTests(sageProject); #endif } tuning.GenOutput(); #if 0 // DQ (11/19/2013): Added AST consistency tests (this fails). AstTests::runAllTests(sageProject); #endif } // if (CmdOptions::GetInstance()->HasOption("-fd")) { // simpleIndexFiniteDifferencing(sageProject); // } // if (CmdOptions::GetInstance()->HasOption("-pre")) { // partialRedundancyElimination(sageProject); // } #if 0 // DQ (11/19/2013): Added AST consistency tests (this fails). AstTests::runAllTests(sageProject); #endif unparseProject(sageProject); //backend(sageProject); #ifdef USE_OMEGA DepStats.SetDepChoice(0x1 | 0x2 | 0x4); DepStats.PrintResults(); #endif return 0; }