o_prefetch.sa


Generated by gen_html_sa_files from ICSI. Contact gomes@icsi.berkeley.edu for details
 
---------------------------> Sather 1.1 source file <--------------------------

class OPT_PREFETCH

class OPT_PREFETCH is include OPT_HELPER; prefetch(func:AM_ROUT_DEF) is prefetch_done::=false; if void(func.code) or ~cs_options.side_effects then return; end;-- AM_ROUT_DEF::code OPT_PREFETCH::cs_options CS_OPTIONS::side_effects BOOL::not if prog.opt_debug then-- OPT_PREFETCH::prog PROG::opt_debug #OUT+"STARTING PREFETCH FUNCTION on\n";-- OUT::create OUT::plus AM_OUT::AM_out(func.code);-- AM_OUT::AM_out AM_ROUT_DEF::code #OUT+"-----\n";-- OUT::create OUT::plus end; c::=#AM_CURSOR(prog,func.code);-- AM_CURSOR::create OPT_PREFETCH::prog AM_ROUT_DEF::code c.ignore_pre:=true;-- AM_CURSOR::ignore_pre c.ignore_post:=true;-- AM_CURSOR::ignore_post c.ignore_assert:=true;-- AM_CURSOR::ignore_assert c.assign_in_order:=true;-- AM_CURSOR::assign_in_order specul::=cs_options.specul_prefetch;-- OPT_PREFETCH::cs_options CS_OPTIONS::specul_prefetch loopp::=cs_options.loop_prefetch;-- OPT_PREFETCH::cs_options CS_OPTIONS::loop_prefetch if func.sig.is_iter or func.sig.get_se_context(prog).has_raise then-- AM_ROUT_DEF::sig SIG::is_iter AM_ROUT_DEF::sig SIG::get_se_context OPT_PREFETCH::prog SE_CONTEXT::has_raise loopp:=false; specul:=false; end; loop am::=c.next!;-- AM_CURSOR::next! typecase am when AM_ROUT_CALL_EXPR then if am.fun.get_se_context(prog).has_import then -- AM_ROUT_CALL_EXPR::fun SIG::get_se_context OPT_PREFETCH::prog SE_CONTEXT::has_import if prog.opt_debug then #OUT+"found import for routine "+am.fun.str+"\n"; end;-- OPT_PREFETCH::prog PROG::opt_debug OUT::create OUT::plus OUT::plus AM_ROUT_CALL_EXPR::fun SIG::str OUT::plus c.mark_stack; end;-- AM_CURSOR::mark_stack when AM_ITER_CALL_EXPR then if am.fun.get_se_context(prog).has_import or ~loopp or func.sig.is_iter then c.mark_stack; end;-- AM_ITER_CALL_EXPR::fun SIG::get_se_context OPT_PREFETCH::prog SE_CONTEXT::has_import BOOL::not AM_ROUT_DEF::sig SIG::is_iter AM_CURSOR::mark_stack when AM_BREAK_STMT then if ~loopp then c.mark_stack; end;-- BOOL::not AM_CURSOR::mark_stack when AM_RAISE_STMT then if ~specul then c.mark_stack; end;-- BOOL::not AM_CURSOR::mark_stack when AM_IF_STMT then if ~specul then c.mark_stack; end;-- BOOL::not AM_CURSOR::mark_stack when AM_IF_EXPR then if ~specul then c.mark_stack; end;-- BOOL::not AM_CURSOR::mark_stack when AM_TYPECASE_STMT then if ~specul then c.mark_stack; end;-- BOOL::not AM_CURSOR::mark_stack when AM_CASE_STMT then if ~specul then c.mark_stack; end;-- BOOL::not AM_CURSOR::mark_stack when AM_LOCK_STMT then if ~specul then c.mark_stack; end;-- BOOL::not AM_CURSOR::mark_stack when AM_WITH_NEAR_STMT then if ~specul then c.mark_stack; end;-- BOOL::not AM_CURSOR::mark_stack when AM_RETURN_STMT then if ~specul then c.mark_stack; end;-- BOOL::not AM_CURSOR::mark_stack when AM_YIELD_STMT then c.mark_stack;-- AM_CURSOR::mark_stack when AM_BND_ROUT_CALL_EXPR then c.mark_stack;-- AM_CURSOR::mark_stack when AM_BND_ITER_CALL_EXPR then c.mark_stack;-- AM_CURSOR::mark_stack else end; typecase am when AM_ATTR_EXPR then if ~c.is_current_lhs and void(c.prefetch_stmt) and void(c.waitfor_stmt) then-- AM_CURSOR::is_current_lhs BOOL::not AM_CURSOR::prefetch_stmt AM_CURSOR::waitfor_stmt p::=#AM_PREFETCH_STMT(am.source);-- AM_PREFETCH_STMT::create AM_ATTR_EXPR::source p.src:=am;-- AM_PREFETCH_STMT::src p.dest:=#AM_LOCAL_EXPR(am.source,void,am.tp);-- AM_PREFETCH_STMT::dest AM_LOCAL_EXPR::create AM_ATTR_EXPR::source AM_ATTR_EXPR::tp p.prefetch:=#AM_LOCAL_EXPR(am.source,void,TP_BUILTIN::prefetch);-- AM_PREFETCH_STMT::prefetch AM_LOCAL_EXPR::create AM_ATTR_EXPR::source TP_BUILTIN::prefetch p.prefetch.is_volatile:=true;-- AM_PREFETCH_STMT::prefetch AM_LOCAL_EXPR::is_volatile p.comment:="prefetch of expression from "+am.source.str;-- AM_PREFETCH_STMT::comment STR::plus AM_ATTR_EXPR::source SFILE_ID::str cc::=#AM_CURSOR(c);-- AM_CURSOR::create if cc.insert_after_mark_after_prefetch(p,cs_options.prefetch_weight) then -- AM_CURSOR::insert_after_mark_after_prefetch OPT_PREFETCH::cs_options CS_OPTIONS::prefetch_weight prog.stat.incr("O: # of prefetch statements");-- OPT_PREFETCH::prog PROG::stat if prog.opt_debug then -- OPT_PREFETCH::prog PROG::opt_debug #OUT+"Inserting a prefetch statement for ";-- OUT::create OUT::plus AM_OUT::AM_out(am);-- AM_OUT::AM_out #OUT+"\n";-- OUT::create OUT::plus end; func.locals:=func.locals.push(p.prefetch);-- AM_ROUT_DEF::locals AM_ROUT_DEF::locals FLIST{1}::push AM_PREFETCH_STMT::prefetch t::=p.dest;-- AM_PREFETCH_STMT::dest typecase t when AM_LOCAL_EXPR then func.locals:=func.locals.push(t);-- AM_ROUT_DEF::locals AM_ROUT_DEF::locals FLIST{1}::push end; if void(func.specul_prefetch) and (specul or loopp) then-- AM_ROUT_DEF::specul_prefetch func.specul_prefetch:=#AM_LOCAL_EXPR(am.source,void,TP_BUILTIN::prefetch);-- AM_ROUT_DEF::specul_prefetch AM_LOCAL_EXPR::create AM_ATTR_EXPR::source TP_BUILTIN::prefetch if prog.opt_debug then #OUT+"specul_prefetch=";AM_OUT::AM_out(func.specul_prefetch);#OUT+"\n";end;-- OPT_PREFETCH::prog PROG::opt_debug OUT::create OUT::plus AM_OUT::AM_out AM_ROUT_DEF::specul_prefetch OUT::create OUT::plus func.specul_prefetch.is_volatile:=true;-- AM_ROUT_DEF::specul_prefetch AM_LOCAL_EXPR::is_volatile func.locals:=func.locals.push(func.specul_prefetch);-- AM_ROUT_DEF::locals AM_ROUT_DEF::locals FLIST{1}::push AM_ROUT_DEF::specul_prefetch end; w::=#AM_WAITFOR_STMT(am.source);-- AM_WAITFOR_STMT::create AM_ATTR_EXPR::source w.prefetch:=p.prefetch;-- AM_WAITFOR_STMT::prefetch AM_PREFETCH_STMT::prefetch w.src:=p.src;-- AM_WAITFOR_STMT::src AM_PREFETCH_STMT::src w.dest:=p.dest;-- AM_WAITFOR_STMT::dest AM_PREFETCH_STMT::dest e::=#AM_STMT_EXPR(am.source);-- AM_STMT_EXPR::create AM_ATTR_EXPR::source e.expr:=w.dest;-- AM_STMT_EXPR::expr AM_WAITFOR_STMT::dest e.stmts:=w;-- AM_STMT_EXPR::stmts c.replace_expr(e);-- AM_CURSOR::replace_expr tam::=c.top;-- AM_CURSOR::top typecase tam when $AM_STMT then func.code:=tam; end;-- AM_ROUT_DEF::code if prog.opt_debug then-- OPT_PREFETCH::prog PROG::opt_debug #OUT+"function code after prefetching:\n";-- OUT::create OUT::plus AM_OUT::AM_out(func.code);-- AM_OUT::AM_out AM_ROUT_DEF::code #OUT+"---\n";-- OUT::create OUT::plus end; end; end; else end; end; tmp::=c.top;-- AM_CURSOR::top typecase tmp when $AM_STMT then func.code:=tmp;-- AM_ROUT_DEF::code end; if prog.opt_debug then -- OPT_PREFETCH::prog PROG::opt_debug #OUT+"PREFETCHING DONE\n";-- OUT::create OUT::plus #OUT+"********************************************************\n";-- OUT::create OUT::plus end; end; end; -- vim:sw=3:nosmartindent