def gen_executor_loop_stmts(mapir): from iegen.codegen import Statement,Comment from iegen.util import trans_equals stmts=[] stmts.append(Comment('Define the executor main loop body statments')) statement_names=mapir.statements.keys() statement_names.sort() for i,statement_name in enumerate(statement_names): statement=mapir.statements[statement_name] for comment_line in statement.text.split('\n'): stmts.append(Comment(comment_line)) ar_dict={} for access_relation in statement.get_access_relations(): iegen.print_detail('Generating code for access relation %s'%(access_relation.name)) stmts.append(Comment('%s: %s'%(access_relation.name,access_relation.iter_to_data))) ar_string_list=[] for out_var_name in access_relation.iter_to_data.tuple_out: ar_string_list.append(calc_equality_value(out_var_name,access_relation.iter_to_data,mapir)) ar_dict[access_relation.name]=']['.join(ar_string_list) #Gather the loop iterators if statement.sparse_sched is None: iterators=','.join(statement.iter_space.tuple_set) else: iterators=','.join(statement.iter_space.tuple_set[:-1]) #If there are any UFS constraints, wrap the statement text in a guard statement_text=statement.text ufs_constraints=statement.iter_space.ufs_constraints() #Make sure there is only a single conjunction in the iteration space if len(ufs_constraints)!=1: raise ValueError('Iteration space has multiple conjunctions') #Check if we need to generate a sparse loop if statement.sparse_sched is not None: sparse_sched_name=statement.sparse_sched sparse_sched_er=mapir.er_specs[sparse_sched_name] iter_name=statement.iter_space.tuple_set[-1] outer_iter_name=statement.iter_space.tuple_set[-2] sparse_loop='''for(%s=%s(*%s,%s);\ %s!=%s(*%s,%s);\ %s=%s(*%s,%s))'''%(iter_name,sparse_sched_er.get_begin_iter(),sparse_sched_name,outer_iter_name,iter_name,sparse_sched_er.get_end_iter(),sparse_sched_name,outer_iter_name,iter_name,sparse_sched_er.get_next_iter(),sparse_sched_name,outer_iter_name) statement_text='''%s{\ %s\ }'''%(sparse_loop,statement_text) #Check if there are any UFS constraints that we need to generate guards for elif len(ufs_constraints[0])>0: ufs_constraints_strs=[trans_equals(str(constraint.value_string(function_name_map=mapir.ufs_name_map()))) for constraint in ufs_constraints[0]] statement_text='if(%s){%s}'%(' && '.join(ufs_constraints_strs),statement_text) stmt_string='#define S%d(%s) %s'%(i,iterators,statement_text) stmt_string=stmt_string.replace('\n','\\\n') stmts.append(Statement(stmt_string%ar_dict)) stmts.append(Statement()) return stmts
def TestComplex(self): from iegen.util import trans_equals self.failUnless('a==b and a<=b and 6==1 and c>=d'==trans_equals('a=b and a<=b and 6=1 and c>=d'),'%s'%(trans_equals('a=b and a<=b and 6=1 and c>=d'),))
def TestMultiple(self): from iegen.util import trans_equals self.failUnless('a==b and c==d'==trans_equals('a=b and c=d'),'%s'%(trans_equals('a=b and c=d'),))
def TestIgnoreLE(self): from iegen.util import trans_equals self.failUnless('a<=b'==trans_equals('a<=b'),'%s'%(trans_equals('a<=b'),))
def TestVars(self): from iegen.util import trans_equals self.failUnless('a==b'==trans_equals('a=b'),'%s'%(trans_equals('a=b'),))
def TestConstants(self): from iegen.util import trans_equals self.failUnless('6==1'==trans_equals('6=1'),'%s'%(trans_equals('6=1'),))