00001
00002
00003 #include "ip_ssa/code_domains.h"
00004 #include "ip_ssa/trans_util.h"
00005
00006 void IntraPCodeDomain::_build_map(){
00007 if (_empty) return;
00008 for (Statement* ps=_begin; ps!=_end->next_ref(); ps=ps->next_ref()){
00009 _map.ins(ps, new IntElem(0));
00010 }
00011 }
00012
00013 void IntraPCodeDomain::expand_context_before(Statement& begin, Statement& end){
00014 if (_empty){
00015 _empty=false;
00016 } else {
00017 if (_begin!=end.next_ref()) {
00018 p_abort("Wrong arguments to expand_context.");
00019 }
00020 }
00021 _begin=&begin;
00022 if (_begin==_pgm.stmts().first_ref() &&
00023 _end==_pgm.stmts().last_ref()){
00024 _map.clear();
00025 _whole_pgm=true;
00026 _empty=false;
00027 _begin=_end=0;
00028 } else {
00029 for (Statement* ps=&begin; ps!=end.next_ref(); ps=ps->next_ref()){
00030 p_assert(ps, "Wrong arguments to expand_context.");
00031 _map.ins(ps, new IntElem(0));
00032 }
00033 }
00034 }
00035
00036 void IntraPCodeDomain::expand_context_after(Statement& begin, Statement& end){
00037 if (_empty){
00038 _empty=false;
00039 } else {
00040 if (&begin!=_end->next_ref()) {
00041 cerr<<begin<<*_end<<*_end->next_ref();
00042 p_abort("Wrong arguments to expand_context.");
00043 }
00044 }
00045 _end=&end;
00046 if (_begin==_pgm.stmts().first_ref() &&
00047 _end==_pgm.stmts().last_ref()){
00048 _map.clear();
00049 _whole_pgm=true;
00050 _empty=false;
00051 _begin=_end=0;
00052 } else {
00053 for (Statement* ps=&begin; ps!=end.next_ref(); ps=ps->next_ref()){
00054 p_assert(ps, "Wrong arguments to expand_context.");
00055 _map.ins(ps, new IntElem(0));
00056 }
00057 }
00058 }
00059
00060 IntraPCodeDomain::IntraPCodeDomain(ProgramUnit& pgm, bool whole_pgm)
00061 :_pgm(pgm){
00062 if (whole_pgm){
00063 _whole_pgm=true;
00064 _empty=false;
00065 _begin=pgm.stmts().first_ref()->next_ref()->next_ref();
00066 _end=pgm.stmts().last_ref()->prev_ref();
00067 } else {
00068 _empty=true;
00069 _begin=_end=0;
00070 _whole_pgm=false;
00071 }
00072 }
00073
00074 IntraPCodeDomain::IntraPCodeDomain(ProgramUnit& pgm,
00075 Statement& begin, Statement& end)
00076 :_pgm(pgm) {
00077 _whole_pgm=false;
00078 _empty=false;
00079 _begin=&begin;
00080 _end=&end;
00081 Statement* ps=_begin;
00082
00083 while (ps!=_end && ps!=0) ps=ps->next_ref();
00084 if (ps==0){
00085 cerr<<begin<<end;
00086 p_abort("Wrong arguments to IntraPCodeDomain().");
00087 }
00088 _build_map();
00089 }
00090
00091 IntraPCodeDomain::IntraPCodeDomain(const IntraPCodeDomain& other)
00092 :_pgm(other._pgm) {
00093 _whole_pgm=other._whole_pgm;
00094 _empty=other._empty;
00095 _begin=other._begin;
00096 _end=other._end;
00097 if (_begin && _end){
00098 _build_map();
00099 }
00100 }
00101
00102 bool IntraPCodeDomain::contains(Statement& stmt){
00103 if (_whole_pgm) return true;
00104 if (_map.find_ref(&stmt)) return true;
00105 return false;
00106 }
00107
00108 IntraPCodeDomain::~IntraPCodeDomain(){}
00109
00110 void IntraPCodeDomain::print(ostream& o) const{
00111 if (_whole_pgm){
00112 o<<" Whole pgm: "<<_pgm.routine_name_ref();
00113 } else {
00114 o<<" Partial pgm: "<<_pgm.routine_name_ref();
00115 if (!_empty){
00116 o<<"\n\tStmt list :\n";
00117 int dummy=8;
00118
00119 Statement* ps=_begin;
00120 o<<ps->line()<<"\t";
00121 ps->write(o, dummy);
00122 ps=_end;
00123 o<<ps->line()<<"\t";
00124 ps->write(o, dummy);
00125
00126 } else {
00127 o<<" : EMPTY";
00128 }
00129 }
00130 }
00131
00132
00133 Listable* IntraPCodeDomain::listable_clone() const {
00134 return new IntraPCodeDomain(*this);
00135 }
00136
00137
00138 InterPCodeDomain::InterPCodeDomain(){
00139 }
00140
00141
00142 void InterPCodeDomain::_add_whole_pgms_interproc(Program& prog,
00143 ProgramUnit& pgm){
00144 _body.ins(&pgm, new IntraPCodeDomain(pgm));
00145 for (Iterator<Statement> ps=pgm.stmts().iterator(); ps.valid(); ++ps){
00146 ProgramUnit* callee=called_pgm(ps.current());
00147 if (callee) {
00148 _add_whole_pgms_interproc(prog, *callee);
00149 }
00150 }
00151 }
00152
00153 InterPCodeDomain::InterPCodeDomain(Program& prog, ProgramUnit& pgm,
00154 Statement& begin, Statement& end){
00155 _body.ins(&pgm, new IntraPCodeDomain(pgm, begin, end));
00156 for (Statement* ps=&begin; ps!=&end && ps!=0; ps=ps->next_ref()){
00157 ProgramUnit* callee=called_pgm(*ps);
00158 if (callee) {
00159 _add_whole_pgms_interproc(prog, *callee);
00160 }
00161 }
00162 }
00163
00164 bool InterPCodeDomain::contains(ProgramUnit& pgm, Statement& stmt){
00165 IntraPCodeDomain* found_pgm=_body.find_ref(&pgm);
00166 if (!found_pgm) return false;
00167 if (found_pgm->contains(stmt)) return true;
00168 return false;
00169 }
00170
00171 InterPCodeDomain::~InterPCodeDomain(){
00172 }
00173
00174
00175 void InterPCodeDomain::expand_context_after(ProgramUnit& pgm,
00176 Statement& begin, Statement& end){
00177 IntraPCodeDomain* found_pgm=_body.find_ref(&pgm);
00178 if (!found_pgm) {
00179 _body.ins(&pgm, new IntraPCodeDomain(pgm,begin,end));
00180 } else {
00181 found_pgm->expand_context_after(begin, end);
00182 }
00183 }
00184
00185 void InterPCodeDomain::expand_context_before(ProgramUnit& pgm,
00186 Statement& begin, Statement& end){
00187 IntraPCodeDomain* found_pgm=_body.find_ref(&pgm);
00188 if (!found_pgm) {
00189 _body.ins(&pgm, new IntraPCodeDomain(pgm,begin,end));
00190 } else {
00191 found_pgm->expand_context_before(begin, end);
00192 }
00193 }
00194
00195 void InterPCodeDomain::expand_context_after(const InterPCodeDomain& another){
00196 for (KeyIterator<ProgramUnit*, IntraPCodeDomain> kit=another._body;
00197 kit.valid(); ++kit){
00198 IntraPCodeDomain* found_pgm=_body.find_ref(kit.current_key());
00199 if (found_pgm){
00200 found_pgm->expand_context_after(*found_pgm->end()->next_ref(),
00201 *kit.current_data().end());
00202 } else {
00203 _body.ins(kit.current_key(), new IntraPCodeDomain(kit.current_data()));
00204 }
00205 }
00206 }
00207
00208 void InterPCodeDomain::expand_context_add_pgm(Program& prog, ProgramUnit& pgm){
00209 _add_whole_pgms_interproc(prog, pgm);
00210 }
00211
00212 void InterPCodeDomain::print(ostream& o) const{
00213 for(KeyIterator<ProgramUnit*, IntraPCodeDomain> kit=_body;
00214 kit.valid(); ++kit){
00215 kit.current_data().print(o);
00216 }
00217 }
00218
00219 Listable* InterPCodeDomain::listable_clone() const{
00220 InterPCodeDomain * toret=new InterPCodeDomain;
00221 toret->_body=_body;
00222 return toret;
00223 }