00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00032 #include "DDG.h"
00033
00034 #include <iostream>
00035 #include <cstdlib>
00036
00037
00038 using namespace std;
00039 using namespace DDG;
00040
00041
00042
00043 int main(int argc, char *argv[])
00044 {
00045
00046 int i,j ;
00047 int c;
00048
00049 ARCHITECTURE isa_arch;
00050
00051 char str[MAX_STRING];
00052 char *ddg_filename=NULL, *arch_filename=NULL;
00053 LEDA::list<REGISTER_TYPES> T;
00054 REGISTER_TYPES rt;
00055
00056
00057 DDG::LOOP loop, unrolled, loop_copy;
00058 ARCHITECTURE isa_example;
00059
00060 LEDA::node n,u;
00061 LEDA::edge e;
00062 set<node> VR;
00063 set<edge> ER;
00064 DDG::INFO_EDGE ie;
00065
00066 INSTRUCTIONS_TYPES it;
00067 LEDA::list<edge> el;
00068
00069 while ((c = getopt (argc, argv, "i:a:")) != -1){
00070 switch(c){
00071 case 'a': arch_filename=optarg;
00072 break;
00073 case 'i': ddg_filename =optarg;
00074 break;
00075 case '?':
00076 cout<<"usage:"<< argv[0] <<" -i ddg_filename.xml [-a isa_desc.xml] "<<endl;
00077 return EXIT_FAILURE;
00078 }
00079
00080 }
00081
00082 if (arch_filename!=NULL) {
00083 isa_example.read_from_xml(arch_filename);
00084 if(isa_example.check()){
00085 loop=LOOP(isa_example);
00086 } else return EXIT_FAILURE;
00087
00088 }
00089
00090 if (ddg_filename != NULL){
00091 i=loop.read_from_xml(ddg_filename);
00092 if(i==-1) return EXIT_FAILURE;
00093
00094 }
00095 else{
00096 cout<<"usage:"<< argv[0] <<" -i ddg_filename.xml [-a isa_desc.xml] "<<endl;
00097 return EXIT_FAILURE;
00098 }
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 cout<< "DDG example program: " <<ddg_filename<<endl;
00111 cout<< "------------------------------" <<endl;
00112
00113
00114 cout<<"Critical Cycle of "<< ddg_filename<<" = "<<loop.CRITICAL_CYCLE(el)<<endl;
00115 cout<<"Edges belonging the the critical cycle"<<endl;
00116 forall(e, el){
00117 ie=loop[e];
00118 cout<< loop.source_id(e)<< " -> "<< loop.target_id(e);
00119 cout<<" : "<< ie<<endl;
00120 }
00121
00122
00123
00124 snprintf(str, MAX_STRING, "%s_temp.xml", ddg_filename);;
00125 loop.write_to_xml(str);
00126
00127 i=loop.read_from_xml(str);
00128 if(i==-1) return EXIT_FAILURE;
00129
00130
00131 snprintf(str, MAX_STRING, "%s.vcg",ddg_filename);
00132 loop.write_to_vcg(str);
00133 cout<<endl<<str<< " can be visualized using xvcg."<<endl;
00134
00135 loop_copy.copy(loop);
00136 snprintf(str, MAX_STRING, "%s_copy.vcg",ddg_filename);
00137
00138 loop_copy.write_to_vcg(str);
00139
00140
00141 T=loop.T();
00142 forall(rt, T){
00143 cout <<"The set of values of type "<< rt.get_register_typename() <<" is :"<<endl;
00144 VR=loop.get_V_R(rt.get_register_type_id());
00145 forall(u, VR){
00146 it=loop.instruction_type(u);
00147 cout<< loop.id(u)<< " with opcode " << it.opcode()<< " ("<<loop.latency(u)<<","<<loop.delta_r(u)<<","<<loop.delta_w(u, rt.get_register_type_id())<<")"<<endl;
00148 }
00149 }
00150
00151 unroll(loop, unrolled, 3);
00152 snprintf(str, MAX_STRING, "%s_unrolled_3.vcg",ddg_filename);
00153 unrolled.write_to_vcg(str);
00154 cout<<endl<<str<< " can be visualized using xvcg."<<endl;
00155 forall (rt, T){
00156 cout <<"The set of flow edges of the loop of type "<< rt.get_register_typename()<<" is :"<<endl;
00157 ER=unrolled.get_E_R(rt.get_register_type_id());
00158 forall(e, ER){
00159 ie=unrolled[e];
00160 cout<< unrolled.source_id(e)<<" -> "<< unrolled.target_id(e)<<" : "<< ie<<endl;
00161 }
00162 }
00163
00164
00165
00166 forall (rt, T){
00167
00168 if (loop.get_V_R(rt.get_register_type_id()).size()>=2) {
00169 loop.hide_node(loop.get_V_R(rt.get_register_type_id()).choose());
00170 loop.hide_node(loop.get_V_R(rt.get_register_type_id()).choose());
00171 break;
00172 }
00173 }
00174 cout<<"Critical Cycle of "<< ddg_filename<<" (after hiding two arbitrary values of type "<< rt.get_register_typename()<<" ) = "<<loop.CRITICAL_CYCLE(el)<<endl;
00175 cout<<"Edges belonging the the critical cycle"<<endl;
00176 forall(e, el){
00177 ie=loop[e];
00178 cout<< loop.source_id(e)<< " -> "<< loop.target_id(e);
00179 cout<<" : "<< ie<<endl;
00180 }
00181
00182
00183 loop.restore_all_nodes();
00184 loop.restore_all_edges();
00185
00186 cout<<"Critical Cycle of "<< ddg_filename<<" (after restoring all values and edges) = "<<loop.CRITICAL_CYCLE(el)<<endl;
00187 cout<<"Edges belonging the the critical cycle"<<endl;
00188 forall(e, el){
00189 ie=loop[e];
00190 cout<< loop.source_id(e)<< " -> "<< loop.target_id(e);
00191 cout<<" : "<< ie<<endl;
00192 }
00193
00194
00195
00196
00197 return EXIT_SUCCESS;
00198 }
00199