//! Estimate the size of some types, workaround of sizeof //Assuming 64-bit Linux machine // http://docs.oracle.com/cd/E19957-01/805-4939/z40007365fe9/index.html int getSizeOf(SgType* t) { int rt =0; assert (t!=NULL); // Fortran allow type_kind for types, read this first if (SgExpression* kind_exp =t->get_type_kind() ) { SgIntVal* int_val = isSgIntVal (kind_exp); if (int_val != NULL) rt = int_val->get_value(); else { cerr<<"Error in getSizeOf(), only SgIntVal type_kind is handled. Unhandled type_kind "<< kind_exp->class_name()<<endl; assert(false); } } else { switch (t->variantT()) { case V_SgTypeDouble: rt = 8; break; case V_SgTypeInt: { rt = 4; break; } case V_SgTypeFloat: rt = 4; break; default: { cerr<<"Error in getSizeOf() of ai_measurement.cpp . Unhandled type: "<<t->class_name()<<endl; assert (false); } } } return rt; }
std::string getSgValueExp(SgValueExp* valExp) { VariantT var = valExp->variantT(); std::stringstream val; switch (var) { case V_SgDoubleVal: val << isSgDoubleVal(valExp)->get_value(); break; case V_SgFloatVal: val << isSgFloatVal(valExp)->get_value(); break; case V_SgShortVal: val << isSgShortVal(valExp)->get_value(); break; case V_SgLongIntVal: val << isSgLongIntVal(valExp)->get_value(); break; case V_SgLongLongIntVal: val << isSgLongLongIntVal(valExp)->get_value(); break; case V_SgIntVal: val << isSgIntVal(valExp)->get_value(); break; case V_SgLongDoubleVal: val << isSgLongDoubleVal(valExp)->get_value(); break; case V_SgEnumVal: { SgEnumVal* enumValExp = isSgEnumVal(valExp); val << enumValExp->get_name().getString(); break; } default: std::cout << "SgValueExp : " << valExp->class_name() << std::endl; ROSE_ASSERT(false); } return val.str(); }
POETCode* POETAstInterface::Ast2POET(const Ast& n) { static SgTemplateInstantiationFunctionDecl* tmp=0; SgNode* input = (SgNode*) n; if (input == 0) return EMPTY; POETCode* res = POETAstInterface::find_Ast2POET(input); if (res != 0) return res; { SgProject* sageProject=isSgProject(input); if (sageProject != 0) { int filenum = sageProject->numberOfFiles(); for (int i = 0; i < filenum; ++i) { SgSourceFile* sageFile = isSgSourceFile(sageProject->get_fileList()[i]); SgGlobal *root = sageFile->get_globalScope(); SgDeclarationStatementPtrList declList = root->get_declarations (); POETCode* curfile = ROSE_2_POET_list(declList, 0, tmp); curfile = new POETCode_ext(sageFile, curfile); POETAstInterface::set_Ast2POET(sageFile, curfile); res=LIST(curfile, res); } POETAstInterface::set_Ast2POET(sageProject,res); return res; } } { SgBasicBlock* block = isSgBasicBlock(input); if (block != 0) { res=ROSE_2_POET_list(block->get_statements(), res, tmp); POETAstInterface::set_Ast2POET(block, res); return res; } } { SgExprListExp* block = isSgExprListExp(input); if (block != 0) { res=ROSE_2_POET_list(block->get_expressions(), 0, tmp); POETAstInterface::set_Ast2POET(block, res); return res; } } { SgForStatement *f = isSgForStatement(input); if (f != 0) { POETCode* init = ROSE_2_POET_list(f->get_for_init_stmt()->get_init_stmt(),0, tmp); POETCode* ctrl = new POETCode_ext(f, TUPLE3(init,Ast2POET(f->get_test_expr()), Ast2POET(f->get_increment()))); res = CODE_ACC("Nest", PAIR(ctrl,Ast2POET(f->get_loop_body()))); POETAstInterface::set_Ast2POET(input, res); return res; } } { SgVarRefExp * v = isSgVarRefExp(input); if (v != 0) { res = STRING(v->get_symbol()->get_name().str()); POETAstInterface::set_Ast2POET(input, res); return res; } } { SgMemberFunctionRefExp * v = isSgMemberFunctionRefExp(input); if (v != 0) { res = STRING(v->get_symbol()->get_name().str()); POETAstInterface::set_Ast2POET(input, res); return res; } } { SgIntVal * v = isSgIntVal(input); if (v != 0) { res = ICONST(v->get_value()); POETAstInterface::set_Ast2POET(input, res); return res; } } { SgInitializedName* var = isSgInitializedName(input); if (var != 0) { POETCode* name = STRING(var->get_name().str()); POETCode* init = Ast2POET(var->get_initializer()); res = new POETCode_ext(var, PAIR(name,init)); POETAstInterface::set_Ast2POET(input, res); return res; } } /* { std::string fname; AstInterface::AstList params; AstNodeType returnType; AstNodePtr body; if (AstInterface :: IsFunctionDefinition( input, &fname, ¶ms, (AstInterface::AstList*)0, &body, (AstInterface::AstTypeList*)0, &returnType)) { if (body != AST_NULL) std::cerr << "body not empty:" << fname << "\n"; POETCode* c = TUPLE4(STRING(fname), ROSE_2_POET_list(0,params,0), STRING(AstInterface::GetTypeName(returnType)), Ast2POET(body.get_ptr())); res = new POETCode_ext(input, c); POETAstInterface::set_Ast2POET(input,res); return res; } } */ AstInterface::AstList c = AstInterface::GetChildrenList(input); switch (input->variantT()) { case V_SgCastExp: case V_SgAssignInitializer: res = Ast2POET(c[0]); POETAstInterface::set_Ast2POET(input, res); return res; case V_SgDotExp: { POETCode* v1 = Ast2POET(c[1]); if (dynamic_cast<POETString*>(v1)->get_content() == "operator()") return Ast2POET(c[0]); res = CODE_ACC("Bop",TUPLE3(STRING("."), Ast2POET(c[0]), v1)); return res; } case V_SgLessThanOp: res = CODE_ACC("Bop",TUPLE3(STRING("<"),Ast2POET(c[0]), Ast2POET(c[1]))); POETAstInterface::set_Ast2POET(input, res); return res; case V_SgSubtractOp: res = CODE_ACC("Bop",TUPLE3(STRING("-"),Ast2POET(c[0]), Ast2POET(c[1]))); POETAstInterface::set_Ast2POET(input, res); return res; case V_SgAddOp: res = CODE_ACC("Bop",TUPLE3(STRING("+"),Ast2POET(c[0]), Ast2POET(c[1]))); POETAstInterface::set_Ast2POET(input, res); return res; case V_SgMultiplyOp: res = CODE_ACC("Bop",TUPLE3(STRING("*"),Ast2POET(c[0]), Ast2POET(c[1]))); POETAstInterface::set_Ast2POET(input, res); return res; case V_SgDivideOp: res = CODE_ACC("Bop",TUPLE3(STRING("/"),Ast2POET(c[0]), Ast2POET(c[1]))); POETAstInterface::set_Ast2POET(input, res); return res; case V_SgAssignOp: res = CODE_ACC("Assign",PAIR(Ast2POET(c[0]), Ast2POET(c[1]))); POETAstInterface::set_Ast2POET(input, res); return res; case V_SgFunctionCallExp: res = CODE_ACC("FunctionCall",PAIR(Ast2POET(c[0]), Ast2POET(c[1]))); POETAstInterface::set_Ast2POET(input, res); return res; } POETCode * c2 = 0; if (tmp == 0) tmp=isSgTemplateInstantiationFunctionDecl(input); switch (c.size()) { case 0: break; case 1: c2 = Ast2POET(c[0]); break; case 2: c2 = PAIR(Ast2POET(c[0]),Ast2POET(c[1])); break; case 3: c2 = TUPLE3(Ast2POET(c[0]),Ast2POET(c[1]),Ast2POET(c[2])); break; case 4: c2 = TUPLE4(Ast2POET(c[0]),Ast2POET(c[1]),Ast2POET(c[2]),Ast2POET(c[3])); break; default: //std::cerr << "too many children: " << c.size() << ":" << input->unparseToString() << "\n"; c2 = EMPTY; } if (tmp == input) tmp = 0; res = new POETCode_ext(input, c2); POETAstInterface::set_Ast2POET(input,res); return res; }
void DataFlow< DLX::KLT_Annotation<DLX::OpenACC::language_t>, Language::OpenCL, Runtime::OpenACC >::markSplittedData( const context_t & context ) const { std::map< ::KLT::Data<Annotation> *, std::vector<splitted_access_desc_t> > accesses_map; std::map< ::KLT::Data<Annotation> *, std::vector<splitted_access_desc_t> >::iterator it_accesses; std::map< ::KLT::LoopTrees<DLX::KLT_Annotation<DLX::OpenACC::language_t> >::node_t *, accesses_list_t>::const_iterator it; for (it = context.accesses_map.begin(); it != context.accesses_map.end(); it++) { ::KLT::LoopTrees<DLX::KLT_Annotation<DLX::OpenACC::language_t> >::node_t * node = it->first; ::KLT::LoopTrees<DLX::KLT_Annotation<DLX::OpenACC::language_t> >::node_t * parent = node->parent; ::KLT::LoopTrees<DLX::KLT_Annotation<DLX::OpenACC::language_t> >::loop_t * splitted_loop = NULL; ::DLX::Directives::clause_t< ::DLX::OpenACC::language_t, ::DLX::OpenACC::language_t::e_acc_clause_split> * split_clause = NULL; // search for a splitted loop in the parents while (parent != NULL) { ::KLT::LoopTrees<DLX::KLT_Annotation<DLX::OpenACC::language_t> >::loop_t * loop = dynamic_cast< ::KLT::LoopTrees<DLX::KLT_Annotation<DLX::OpenACC::language_t> >::loop_t *>(parent); if (loop != NULL && loop->isSplitted()) { assert(splitted_loop == NULL); // cannot have nested splitted loops splitted_loop = loop; std::vector<DLX::KLT_Annotation<DLX::OpenACC::language_t> >::const_iterator it; for (it = loop->annotations.begin(); it != loop->annotations.end(); it++) { if (it->clause->kind == DLX::OpenACC::language_t::e_acc_clause_split) { assert(split_clause == NULL); // only one split clause per loop split_clause = (::DLX::Directives::clause_t< ::DLX::OpenACC::language_t, ::DLX::OpenACC::language_t::e_acc_clause_split> *)it->clause; } } assert(split_clause != NULL); } parent = parent->parent; } assert(splitted_loop == NULL || split_clause != NULL); // (loop != NULL) => (split_clause != NULL) std::vector<data_access_t>::const_iterator it_data_access; for (it_data_access = it->second.reads.begin(); it_data_access != it->second.reads.end(); it_data_access++) { it_accesses = accesses_map.find(it_data_access->data); if (it_accesses == accesses_map.end()) it_accesses = accesses_map.insert(std::pair< ::KLT::Data<Annotation> *, std::vector<splitted_access_desc_t> >(it_data_access->data, std::vector<splitted_access_desc_t>())).first; assert(it_accesses != accesses_map.end()); it_accesses->second.push_back(splitted_access_desc_t(splitted_access_desc_t::read, splitted_loop, split_clause, &(it_data_access->subscripts))); } for (it_data_access = it->second.writes.begin(); it_data_access != it->second.writes.end(); it_data_access++) { it_accesses = accesses_map.find(it_data_access->data); if (it_accesses == accesses_map.end()) it_accesses = accesses_map.insert(std::pair< ::KLT::Data<Annotation> *, std::vector<splitted_access_desc_t> >(it_data_access->data, std::vector<splitted_access_desc_t>())).first; assert(it_accesses != accesses_map.end()); it_accesses->second.push_back(splitted_access_desc_t(splitted_access_desc_t::write, splitted_loop, split_clause, &(it_data_access->subscripts))); } } for (it_accesses = accesses_map.begin(); it_accesses != accesses_map.end(); it_accesses++) { ::KLT::Data<Annotation> * data = it_accesses->first; assert(it_accesses->second.size() > 0); if (it_accesses->second.size() > 1) { std::vector<splitted_access_desc_t>::iterator it_splitted_access = it_accesses->second.begin(); ::KLT::LoopTrees<DLX::KLT_Annotation<DLX::OpenACC::language_t> >::loop_t * splitted_loop = it_splitted_access->splitted_loop; for (; it_splitted_access != it_accesses->second.end(); it_splitted_access++) assert(splitted_loop == it_splitted_access->splitted_loop); } if (it_accesses->second[0].splitted_loop == NULL) continue; assert(it_accesses->second[0].split_clause != NULL); assert(it_accesses->second[0].subscripts != NULL); assert(it_accesses->second[0].subscripts->size() > 0); SgVarRefExp * var_ref = isSgVarRefExp(it_accesses->second[0].subscripts->at(0)); assert(var_ref != NULL); if (var_ref->get_symbol() != it_accesses->second[0].splitted_loop->iterator) { std::vector<splitted_access_desc_t>::iterator it_splitted_access; for (it_splitted_access = it_accesses->second.begin(); it_splitted_access != it_accesses->second.end(); it_splitted_access++) assert(it_splitted_access->rw == splitted_access_desc_t::read); continue; } ::KLT::Data<Annotation>::data_distribution_t * data_distribution = new ::KLT::Data<Annotation>::data_distribution_t(); data_distribution->distributed_dimension = 0; switch (it_accesses->second[0].split_clause->parameters.kind) { case ::DLX::Directives::generic_clause_t< ::DLX::OpenACC::language_t>::parameters_t< ::DLX::OpenACC::language_t::e_acc_clause_split>::e_acc_split_contiguous: { data_distribution->kind = ::KLT::Data<Annotation>::data_distribution_t::e_split_contiguous; std::vector<SgExpression *>::const_iterator it_portion; for (it_portion = it_accesses->second[0].split_clause->parameters.portions.begin(); it_portion != it_accesses->second[0].split_clause->parameters.portions.end(); it_portion++) { SgIntVal * portion = isSgIntVal(*it_portion); if (portion == NULL) { std::cerr << "(*it_portion)->class_name() = " << (*it_portion)->class_name() << std::endl; assert(false); } data_distribution->portions.push_back(portion->get_value()); } break; } case ::DLX::Directives::generic_clause_t< ::DLX::OpenACC::language_t>::parameters_t< ::DLX::OpenACC::language_t::e_acc_clause_split>::e_acc_split_chunk: { break; } default: assert(false); } data->setDistribution(data_distribution); } }