コード例 #1
0
ファイル: eval_ext_rose.cpp プロジェクト: faizurahman/rose
/*QY: This is used to support traversal of AST by the POET interpreter*/
bool POETAstInterface::MatchAstTypeName(const Ast& n, const std::string& tname)
{ 
 if (tname == "EXP") {
     return AstInterface::IsExpression((SgNode*)n) != AST_NULL;
 }
 else if (tname == "ExpStmt") {
    SgExprStatement* s = isSgExprStatement((SgNode*)n);
    return (s != 0);
 }
 else if (tname == "FunctionDecl") {
     return AstInterface :: IsFunctionDefinition((SgNode*)n);
 }
 else if (tname == "For") {
     return isSgForStatement((SgNode*)n) != 0;
 }
 else if (tname == "Assign") {
     return AstInterface::IsAssignment((SgNode*)n);
 }
 else if (tname == "Pragma") {
   return isSgPragmaDeclaration((SgNode*)n) != 0;
 }
 else if (tname == "VarDecl") {
     return isSgVariableDeclaration((SgNode*)n) != 0;
 }
 else if (tname == "Variable") {
    return isSgInitializedName((SgNode*)n);
 }
 else if (tname == "Loop") {}
 else std::cerr << "does not recognize type name:" << tname << "\n";
 return false;
}
コード例 #2
0
ファイル: code-generation.cpp プロジェクト: 8l/rose
int main ( int argc, char* argv[] ) {
	SgProject * project = frontend ( argc , argv ) ;
	
	Rose_STL_Container<SgNode*> pragma_decls = NodeQuery::querySubTree(project, V_SgPragmaDeclaration);
	Rose_STL_Container<SgNode*>::iterator it;
	for (it = pragma_decls.begin(); it != pragma_decls.end(); it++) {
		SgPragmaDeclaration * pragma_decl = isSgPragmaDeclaration(*it);
		
		try {
			PolyhedricAnnotation::parse(pragma_decl);
		}
		catch (Exception::ExceptionBase & e) {
			e.print(std::cerr);
			continue;
		}
		
		PolyhedricAnnotation::PragmaPolyhedralProgram & polyhedral_program =
				PolyhedricAnnotation::getPolyhedralProgram<SgPragmaDeclaration, SgExprStatement, RoseVariable>(pragma_decl);
		
		Scheduling::PragmaSchedule schedule(polyhedral_program, 0);
		CodeGeneration::generateAndReplace(schedule);
	}
	
	project->unparse();
	
	return 0;
}
コード例 #3
0
ファイル: main.cpp プロジェクト: ssrg-vt/aira
int main(int argc, char** argv)
{
	//Parse command-line args
	ProgramOptions po(argc, argv);

	//Initialize the AST
	SgProject* project = new SgProject(argc, argv);
	ROSE_ASSERT(project);
	AstTests::runAllTests(project); //TODO switch on/off with command-line args

	//Set the folder containing the features
	string featureFolder = "";
	bool defaultFeatures = po.getFeaturesFolder(featureFolder);
	if(!defaultFeatures)
		CallScheduler::setFeaturesFolder(featureFolder);

	//Loop through all partitioned kernels and add scheduling calls
	Rose_STL_Container<SgNode*> pragmas = querySubTree(project, V_SgPragmaDeclaration);
	Rose_STL_Container<SgNode*>::const_iterator pragmaIt = pragmas.begin();
	SgPragmaDeclaration* pragma = NULL;
	SgFunctionDeclaration* funcDecl = NULL;
	SgStatement* stmt = NULL;
	for(pragmaIt = pragmas.begin(); pragmaIt != pragmas.end(); pragmaIt++)
	{
		pragma = isSgPragmaDeclaration(*pragmaIt);
		ROSE_ASSERT(pragma);

		PragmaParser pp(pragma);
		if(pp.isPopcornPragma() && pp.getPragmaType() == PARTITIONED)
		{
			stmt = getNextStatement(pragma);
			while(!isSgFunctionDeclaration(stmt))
				stmt = getNextStatement(pragma);
			funcDecl = isSgFunctionDeclaration(stmt);
			ROSE_ASSERT(funcDecl);
			Pragmas pragmas(funcDecl);

			//Add scheduling calls
			CallScheduler cs(funcDecl, pragmas);
			cs.addSchedulerCalls();

			//Insert the header
			//TODO this won't insert the header into files
			insertHeader(po.getSchedulerHeaderLocation(), PreprocessingInfo::after, false,
					getGlobalScope(funcDecl));
		}
	}

	return backend(project);
}
コード例 #4
0
int main(int argc, char* argv[]) {
	std::vector<std::string> pragma_values;
	SgProject* proj = frontend(argc,argv);
	ROSE_ASSERT(proj != NULL);
	SgFunctionDeclaration* mainDefDecl = SageInterface::findMain(proj);
	SgFunctionDefinition* mainDef = mainDefDecl->get_definition();
	
	Rose_STL_Container<SgNode*> pragmaList = NodeQuery::querySubTree(proj,V_SgPragmaDeclaration);
	for (Rose_STL_Container<SgNode*>::iterator i = pragmaList.begin(); i != pragmaList.end(); i++) {
		SgPragmaDeclaration* prg = isSgPragmaDeclaration(*i);
		std::string prag_string = get_pragma_string(prg);
		if (isSMTGeneral(prag_string)) {
			std::string parsed = parseSMTGeneral(prag_string);
			std::cout << ";;SMTGeneral command found: " << parsed << std::endl;
			//continue;
		}
		else {
		//std::cout << "SMTGeneral command not found" << std::endl;
		std::string pos;
		pos = get_position(prag_string);
		if (pos == "define") {
			std::cout << "define:\n";
			std::vector<std::pair<std::string, std::string> > pragma_values = get_vars(prag_string);
			for (std::vector<std::pair<std::string,std::string> >::iterator j = pragma_values.begin(); j != pragma_values.end(); j++) {
				std::cout << (*j).first << " " << (*j).second << std::endl;
			}
			
		}
		else if (pos == "assume") {
			std::cout << "assume:\n";
			std::vector<std::string> assumptions = get_assumptions(prag_string);
			for (std::vector<std::string>::iterator i = assumptions.begin(); i != assumptions.end(); i++) {
				std::cout << (*i) << std::endl;
			}	
		}
		else if (pos == "begin" || pos == "end") {
			std::cout << "position: " << pos << std::endl;
		}
		else {
			ROSE_ASSERT(false);
		}
		}
	}
	return 0;
}	
コード例 #5
0
ファイル: eval_ext_rose.cpp プロジェクト: faizurahman/rose
POETCode* ROSE_2_POET_list(PtrList& l, POETCode* res, 
                           SgTemplateInstantiationFunctionDecl* tmp)
{
static POETCode* tmpPars=0;
    if (l.size() == 1) { /* return the only element inside the list */
      return POETAstInterface::Ast2POET(*l.begin()); 
    }
    typename PtrList::const_reverse_iterator p = l.rbegin(); 
    if (p == l.rend()) return (res==0)? EMPTY : res;

    SgNode* prev2 = (SgNode*)*p;
    POETCode* prev = POETAstInterface::Ast2POET(prev2);
    for (++p; p != l.rend(); ++p) {
       SgNode* cur = (SgNode*)*p;
       SgPragmaDeclaration* info = isSgPragmaDeclaration(cur);
       if (info!=0) { /* replace template parameters in pragma */
           POETAstInterface::set_Ast2POET(prev2, EMPTY);
           std::string pragma_str = info->get_pragma()->get_pragma();
           POETCode *content=STRING(pragma_str);
           POETCode* tokens = split_string("",content);
           if (tmp == 0) tmpPars = 0;
           else { 
             const SgTemplateArgumentPtrList& args= tmp->get_templateArguments();
             if (tmpPars == 0) 
               tmpPars=get_template_parameters(tmp->get_templateDeclaration ()->get_string());
             POETCode* pars = tmpPars;
             for (SgTemplateArgumentPtrList::const_iterator p2 = args.begin();
                   p2 != args.end(); p2++) {
                 POETCode* from = get_head(pars); pars=get_tail(pars);
                 POETCode* to = STRING((*p2)->unparseToString());
                 tokens = eval_replace(from, to, tokens); 
              } 
           }
           prev = new POETCode_ext(info, PAIR(tokens, prev));
           POETAstInterface::set_Ast2POET(info,prev);
       }
       else { 
         res = LIST(prev, res);
         prev = POETAstInterface::Ast2POET((SgNode*)cur); }
    } 
    res = LIST(prev,res); 
    return res;
}
コード例 #6
0
ファイル: mpiCodeGenerator.C プロジェクト: 8l/rose
  void parsePragmas(SgSourceFile* sfile, std::vector <MPI_PragmaAttribute*>& MPI_Pragma_Attribute_List)
  {
    Rose_STL_Container<SgNode*> nodeList = NodeQuery::querySubTree(sfile,V_SgPragmaDeclaration);
    for (Rose_STL_Container<SgNode *>::iterator i = nodeList.begin(); i != nodeList.end(); i++)
    {
      //      cout << "Found a pragma!" << endl;
      SgPragmaDeclaration * pdecl = isSgPragmaDeclaration(*i); 
      ROSE_ASSERT (pdecl != NULL);
      AstAttribute* result = NULL;
      result = parse_MPI_Pragma (pdecl);
      MPI_PragmaAttribute* hc_att = dynamic_cast <MPI_PragmaAttribute*> (result);
      if (hc_att != NULL)
      {
        MPI_Pragma_Attribute_List.push_back (hc_att);  
        // debugging here
        cout<<hc_att->toString()<<endl;
      }
    } //end for

  } //end parsePragmas()
コード例 #7
0
ファイル: function_interface.cpp プロジェクト: ssrg-vt/aira
/*
 * Initialized the function interface object.
 */
FunctionInterface::FunctionInterface(SgFunctionDeclaration* p_function, SgGraphNode* p_node) :
	function(p_function),
	node(p_node),
	status(NOT_ANALYZED),
	shouldAnnotate(false)
{
	//See if this function contains OpenMP pragmas - if so, annotate
	Rose_STL_Container<SgNode*> pragmas = querySubTree(p_function, V_SgPragmaDeclaration);
	Rose_STL_Container<SgNode*>::const_iterator pragmaIt = pragmas.begin();
	SgPragmaDeclaration* pragma;
	for(pragmaIt = pragmas.begin(); pragmaIt != pragmas.end(); pragmaIt++)
	{
		pragma = isSgPragmaDeclaration(*pragmaIt);
		ROSE_ASSERT(pragma != NULL);

		if(extractPragmaKeyword(pragma) == "omp")
		{
			shouldAnnotate = true;
			break;
		}
	}
}
コード例 #8
0
ファイル: main.cpp プロジェクト: ssrg-vt/aira
int main(int argc, char** argv)
{
	//Parse command-line options
	ProgramOptions po(argc, argv);

	//Initialize the AST
	SgProject* project = new SgProject(argc, argv);
	ROSE_ASSERT(project);
	AstTests::runAllTests(project); //TODO switch on/off with command-line args

	//Insert MM-wrapper header file
	string mmHeader = po.getMMWrapperHeaderLocation();
	insertHeader(mmHeader, PreprocessingInfo::after, false, getGlobalScope(findMain(project)));

	//Initialize set of system headers & compiler generated vars
	RegisterPointers::initialize();

	//Add calls to registers sizes of static variables
	RegisterVars rv(project, mmHeader);
	rv.registerStaticVars();

	//Used to accumulate all global variables
	set<SgInitializedName*> globalVars;

	//Add wrapper calls to each function/sub-function so that all pointers are registered
	Rose_STL_Container<SgNode*> pragmas = querySubTree(project, V_SgPragmaDeclaration);
	Rose_STL_Container<SgNode*>::const_iterator pragmaIt;
	Rose_STL_Container<SgNode*> funcCalls = querySubTree(project, V_SgFunctionCallExp);
	SgPragmaDeclaration* pragma;
	SgStatement* stmt;
	SgFunctionDeclaration* funcDecl;
	for(pragmaIt = pragmas.begin(); pragmaIt != pragmas.end(); pragmaIt++)
	{
		pragma = isSgPragmaDeclaration(*pragmaIt);
		ROSE_ASSERT(pragma);

		PragmaParser pp(pragma);
		if(pp.isPopcornPragma() && pp.getPragmaType() == PARTITIONED)
		{
			//Get function declaration
			stmt = getNextStatement(pragma);
			while(!isSgFunctionDeclaration(stmt))
				stmt = getNextStatement(stmt);
			funcDecl = isSgFunctionDeclaration(stmt);
			ROSE_ASSERT(funcDecl);
			Pragmas pragmas(funcDecl);

			//Save global variables
			saveGlobalVariables(pragmas.getGlobalInputs(), globalVars,
					pragmas.getFunction()->get_scope());
			saveGlobalVariables(pragmas.getGlobalOutputs(), globalVars,
					pragmas.getFunction()->get_scope());

			//Update call sites
			//TODO I don't think we need this anymore, since all sizes are
			//handled through the mm_wrapper interface
			//FunctionCallUpdater fcu(funcDecl, funcCalls);
			//fcu.updateDeclaration();
			//fcu.updateSites();
		}
	}

	//Register/unregister global variables
	RegisterVars::registerGlobalVars(globalVars);

	//Add call to initialize wrapper
	SgFunctionDeclaration* main = findMain(project);
	ROSE_ASSERT(main);
	FunctionCallUpdater::insertInitWrapperCall(main);

	return backend(project);
}
コード例 #9
0
ファイル: mpiCodeGenerator.C プロジェクト: 8l/rose
  //! Parsing all relevant pragmas, generate MPI_Pragma_Attribute_List.
  AstAttribute* parse_MPI_Pragma (SgPragmaDeclaration* pragmaDecl)
  {
    AstAttribute*  result = NULL;
    assert (pragmaDecl != NULL);
    assert (pragmaDecl->get_pragma() != NULL);
    string pragmaString = pragmaDecl->get_pragma()->get_pragma();

    // make sure it is side effect free
    const char* old_char = c_char;
    SgNode* old_node = c_sgnode;

    //c_sgnode = getNextStatement(pragmaDecl);
    c_sgnode = pragmaDecl;
    assert (c_sgnode != NULL);

    SgPragmaDeclaration* pdecl = isSgPragmaDeclaration (c_sgnode);
    assert (pdecl != NULL);

    c_char = pragmaString.c_str();

    if (afs_match_substr("omp"))
    {
      if (afs_match_substr("mpi_device_default"))
      {
        result = new MPI_PragmaAttribute (pdecl, pragma_mpi_device_default);
        assert (result != NULL);
      }
      else if (afs_match_substr("parallel for"))
      {
        result = new MPI_PragmaAttribute (pdecl, pragma_parallel_for);
        assert (result != NULL);
      } 
      else if (afs_match_substr("target"))
      {
        mpi_pragma_enum device_value; 
        //TODO : more fine grain parsing of device() clause
        if (afs_match_substr("device(mpi:all)"))
          device_value = e_mpi_all;
        else if (afs_match_substr("device(mpi:master)"))  
          device_value = e_mpi_master;
        else 
        {
          cerr<<"Error in parse_MPI_Pragma(), expecting mpi:all or mpi:master after target device("<<endl;
          assert (false); 
        }

        if (afs_match_substr("begin"))
        {
          if (device_value ==e_mpi_all )
          {
            result = new MPI_PragmaAttribute (pdecl, pragma_mpi_device_all_begin);
            assert (result != NULL);
          }
          else if (device_value ==e_mpi_master)
          {
            result = new MPI_PragmaAttribute (pdecl, pragma_mpi_device_master_begin);
            assert (result != NULL);
          }
        }  
        else if (afs_match_substr("end"))
        {
          if (device_value ==e_mpi_all )
          {
            result = new MPI_PragmaAttribute (pdecl, pragma_mpi_device_all_end);
            assert (result != NULL);
          }
          else if (device_value ==e_mpi_master)
          {
            result = new MPI_PragmaAttribute (pdecl, pragma_mpi_device_master_end);
            assert (result != NULL);
          }
        }
        else 
        { //TODO match map clauses

        } 
      }
    }
    // undo side effects
    c_char = old_char;
    c_sgnode = old_node;
    return result;

  } // end parse_MPI_Pragma()
コード例 #10
0
ファイル: generate-all-schedules.cpp プロジェクト: 8l/rose
int main ( int argc, char* argv[] ) {

	if (argc != 3) {
		std::cerr << "Usage: generate-all-schedule file.c directory" << std::endl;
		ROSE_ASSERT(false);
	}

	SgSourceFile * source_file = isSgSourceFile(SageBuilder::buildFile(argv[1], argv[1]));
	
	Rose_STL_Container<SgNode*> pragma_decls = NodeQuery::querySubTree(source_file, V_SgPragmaDeclaration);
	
	if (pragma_decls.size() == 1) {
		SgPragmaDeclaration * pragma_decl = isSgPragmaDeclaration(pragma_decls[0]);

		try {
		
		 // Generate polyhedric modelisation 
			PolyhedricAnnotation::parse(pragma_decl);

			PolyhedricAnnotation::PragmaPolyhedralProgram & polyhedral_program =
					PolyhedricAnnotation::getPolyhedralProgram<SgPragmaDeclaration, SgExprStatement, RoseVariable>(pragma_decl);

		 // Compute dependency from the generated modelisation
			std::vector<PolyhedricDependency::PragmaDependency *> * deps =
				PolyhedricDependency::ComputeRaW<SgPragmaDeclaration, SgExprStatement, RoseVariable>(polyhedral_program);

		 // Generate the space containing all valid schedules for the previously compute dependencies	
			Scheduling::PragmaScheduleSpace schedule_space(polyhedral_program, *deps, Scheduling::PBCC);

		 // Traverse the schedule's space to list the schedules
			std::vector<Scheduling::PragmaSchedule> * schedules = schedule_space.generateScheduleList(-1, 1, -1, 1, -1, 1);

		 // **********

			SgStatement * next_statement = SageInterface::getNextStatement(pragma_decl);
			SageInterface::removeStatement(next_statement);
			
			SgStatement * statement_to_replace = pragma_decl;
			size_t cnt = 0;
			std::vector<Scheduling::PragmaSchedule>::iterator it;
			for (it = schedules->begin(); it != schedules->end(); it++) {
			
				std::ostringstream oss;
				oss << cnt;
				
				std::string file_name(argv[1]);
			
				size_t point = file_name.find_last_of(".");
			
				file_name.insert(point, oss.str());
				
				size_t slash = file_name.find_last_of("/");
				
				source_file->set_unparse_output_filename(std::string(argv[2]) + std::string("/") + file_name.substr(slash+1));
				
				SgBasicBlock * generated_block = CodeGeneration::generateBasicBlockFor(*it);
				SageInterface::replaceStatement(statement_to_replace, generated_block);
				statement_to_replace = generated_block;
				
				source_file->unparse();
				
				cnt++;
			}

		}
		catch (Exception::ExceptionBase & e) {
			e.print(std::cerr);
		}
	}
	else {
		std::cerr << "Need to have one and only one pragma in the program for this." << std::endl;
	}

	return 0;
}
コード例 #11
0
ファイル: analyzePath.cpp プロジェクト: 8l/rose
int main(int argc,char** argv) {
	SgProject* proj = frontend(argc,argv);
	fixAllPrefixPostfix(proj);
	initializeScopeInformation(proj);	
	SgFunctionDeclaration* mainDecl = SageInterface::findMain(proj);

	SgFunctionDefinition* mainDef = mainDecl->get_definition();
	
	//SageInterface::rebuildSymbolTable(mainDef);
	StaticCFG::CFG cfg(mainDef);
	SgIncidenceDirectedGraph *g = cfg.getGraph();
	PathCollector* pathCollector = new PathCollector(g,&cfg);	

	std::vector<SgNode*> scopeNodes = NodeQuery::querySubTree(mainDef,V_SgScopeStatement);
	
	std::vector<SgGraphNode*> visited;
	std::vector<SgNode*> nodes = NodeQuery::querySubTree(mainDef,V_SgWhileStmt);
	std::vector<SgNode*>::iterator node = nodes.begin();
	for (; node != nodes.end(); node++) {
	SgScopeStatement* scopeOfWhile = SageInterface::getEnclosingScope(*node);
	SgStatementPtrList statementsInScope = scopeOfWhile->getStatementList();
	SgStatementPtrList::iterator statPtr = statementsInScope.begin();
	std::set<SgPragmaDeclaration*> prdecls;

	for (; statPtr!=statementsInScope.end();statPtr++) {
		if (isSgPragmaDeclaration(*statPtr)) {
			prdecls.insert(isSgPragmaDeclaration(*statPtr));
		}
	}
	//SgExprStatement* boundingConditionStatement = isSgExprStatement(isSgWhileStmt(*node)->get_condition()); 	
	//SgExpression* boundingCondition = boundingConditionStatement->get_expression();
	SgStatement* body = (isSgWhileStmt(*node)->get_body());
	std::vector<std::vector<SgGraphNode*> > paths = pathCollector->getPaths();

	
	std::cout << getPrelude() << std::endl;

		

	SgGraphNode* whileStart = cfg.cfgForBeginning(isSgWhileStmt(*node));		
	SgGraphNode* whileEnd = cfg.cfgForEnd(isSgWhileStmt(*node));
	collectPaths(whileStart,whileEnd, pathCollector);
	SgGraphNode* whileOut = getWhileEndNode(isSgWhileStmt(*node),pathCollector);
	SgGraphNode* bodyStart = cfg.cfgForBeginning(isSgWhileStmt(*node)->get_body());
	SgGraphNode* bodyEnd = cfg.cfgForEnd(isSgWhileStmt(*node)->get_body());

        pathCollector->clearPaths();
	
	collectPaths(bodyStart,whileOut,pathCollector);	
	paths.clear();
	paths = pathCollector->getPaths();
	std::vector<std::vector<SgGraphNode*> >::iterator i  = paths.begin();
	std::set<SgVariableSymbol*> vars = getVars(pathCollector);
	std::string vardecls;
	std::string initrule;
	std::vector<std::string> rules= getRules(*node,pathCollector, vars, vardecls,initrule);
	std::cout << vardecls << std::endl;
	for (int i = 0; i < rules.size(); i++) {
		std::cout << rules[i] << std::endl;
	}
	std::set<SgPragmaDeclaration*>::iterator pr = prdecls.begin();
	for (; pr != prdecls.end(); pr++) {
		std::set<std::string> variables;
		std::vector<std::string> s_expressions;
		std::string prag_str = get_pragma_string(*pr);
		bool initPrag;
		/*std::string rhs =*/ translateToS_Expr(prag_str,variables,s_expressions,initPrag);
		if (s_expressions.size() > 0) {
		std::string queryResult;
		if (initPrag) {
			queryResult = assumptionPragma(s_expressions,initrule);
		}
		else {
			queryResult = queryPragma(s_expressions,initrule);
		}	
		std::cout << queryResult << std::endl;
		}
	}
	}
	backend(proj);
	return 0;
	}