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
00029
00034 #include "DDG.h"
00035
00036 #include "LEDA/graph/graph_misc.h"
00037 #include <iostream>
00038 #include <cstdlib>
00039
00040
00041 using namespace std;
00042 using namespace DDG;
00043
00044
00045
00046 int main(int argc, char *argv[])
00047 {
00048
00049 int i,j,cpt ;
00050 int c;
00051
00052 char *ddg_filename=NULL, *arch_filename=NULL;
00053 char str[MAX_STRING];
00054 REGISTER_TYPES rt;
00055 LEDA::list<REGISTER_TYPES> T;
00056
00057
00058
00059 DDG::LOOP loop;
00060 ARCHITECTURE ISA_example;
00061 DDG::DAG dag, dag_copy;
00062
00063 LEDA::node n,u;
00064 LEDA::edge e;
00065 LEDA::set<node> VR;
00066 LEDA::set<node> MA;
00067 LEDA::node_map<int> map;
00068
00069 LEDA::node_array<node> killer;
00070 array< list<node> > ALN ;
00071
00072 DDG::INSTRUCTIONS_TYPES it;
00073
00074 LEDA::list<edge> el;
00075 LEDA::list<node> nl;
00076 LEDA::set<node> parents, children;
00077
00078 while ((c = getopt (argc, argv, "i:a:")) != -1){
00079 switch(c){
00080 case 'a': arch_filename=optarg;
00081 break;
00082 case 'i': ddg_filename =optarg;
00083 break;
00084 case '?':
00085 cout<<"usage:"<< argv[0] <<" -i ddg_filename.xml [-a isa_desc.xml] "<<endl;
00086 return EXIT_FAILURE;
00087 }
00088
00089 }
00090
00091
00092 if (arch_filename!=NULL) {
00093 ISA_example.read_from_xml(arch_filename);
00094 if(ISA_example.check()){
00095 loop=LOOP(ISA_example);
00096 dag=DAG(ISA_example);
00097 } else return EXIT_FAILURE;
00098 }
00099
00100
00101
00102 if (ddg_filename != NULL){
00103
00104 i=loop.read_from_xml(ddg_filename);
00105
00106 if(i==-1){
00107 return EXIT_FAILURE;
00108 }
00109
00110 i=dag.read_from_xml(ddg_filename);
00111
00112 if(i==-1){
00113 return EXIT_FAILURE;
00114 }
00115
00116 }
00117 else{
00118 cout<<"usage:"<< argv[0] <<" -i ddg_filename.xml [-a isa_desc.xml] "<<endl;
00119 return EXIT_FAILURE;
00120 }
00121
00122 if(! Is_Acyclic(dag, el)) {
00123 cerr<<"Input Error: Non acyclic graph.\n";
00124 cerr<<"There are "<< el.size() <<" illegal arcs:\n";
00125 forall(e, el){
00126 cerr<<dag.id(dag.source(e))<<" -> "<< dag.id(dag.target(e))<<endl;
00127 }
00128 return EXIT_FAILURE;
00129 }
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140 cout<< "DAG example program: " <<ddg_filename<<endl;
00141 cout<< "-----------------------------" <<endl;
00142 T=dag.T();
00143
00144 forall(rt,T){
00145
00146 cout<<"Register Saturation of the DAG (loop body) for register type "<< rt.get_register_typename() <<" is " <<REGISTER_SATURATION (dag, rt.get_register_type_id(), nl)<<endl;
00147 cout<<"Saturating values of type "<<rt.get_register_typename()<<endl;
00148 forall(n, nl){
00149 it= dag.instruction_type(n);
00150 cout<< dag.id(n)<< " with opcode " << it.opcode()<< " ("<<dag.latency(n)<<","<<dag.delta_r(n)<<","<<dag.delta_w(n, rt.get_register_type_id())<<")"<<endl;
00151 }
00152 }
00153
00154 cout<<endl<<"Critical Path ="<<dag.CriticalPath(el)<<endl;
00155
00156 cout<<"Edges belonging to the critical path"<<endl;
00157 forall(e, el){
00158 n=dag.source(e);
00159 u=dag.target(e);
00160 it= dag.instruction_type(n);
00161 cout<< dag.id(n)<< " -> " << dag.id(u) <<endl;
00162 }
00163
00164
00165 forall_nodes(u, dag){
00166 parents=dag.get_parents(u);
00167 cout<<"The parents of the node number "<<dag.id(u)<<" are : ";
00168 forall (n, parents){
00169 cout<<dag.id(n)<<" ";
00170 }
00171 cout<<endl;
00172 }
00173 forall_nodes(u, dag){
00174 children=dag.get_children(u);
00175 cout<<"The children of the node number "<<dag.id(u)<<" are : ";
00176 forall (n, children){
00177 cout<<dag.id(n)<<" ";
00178 }
00179 cout<<endl;
00180 }
00181 forall_nodes(u, dag){
00182 parents=dag.get_up(u);
00183 cout<<"The ascendants of the node number "<<dag.id(u)<<" are : ";
00184 forall (n, parents){
00185 cout<<dag.id(n)<<" ";
00186 }
00187 cout<<endl;
00188 }
00189 forall_nodes(u, dag){
00190 children=dag.get_down(u);
00191 cout<<"The descendants of the node number "<<dag.id(u)<<" are : ";
00192 forall (n, children){
00193 cout<<dag.id(n)<<" ";
00194 }
00195 cout<<endl;
00196 }
00197
00198
00199 snprintf(str, MAX_STRING, "%s_dag.vcg",ddg_filename);
00200 dag.write_to_vcg(str);
00201 dag_copy.copy(dag);
00202 snprintf(str, MAX_STRING, "%s_dag_copy.vcg",ddg_filename);
00203 dag_copy.write_to_vcg(str);
00204
00205 cout<<endl<<str<< " can be visualized using xvcg."<<endl;
00206
00207
00208
00209 map.init(loop);
00210
00211 dag.clear();
00212 forall_nodes(u,loop){
00213 map[u]=dag.new_node((loop.instruction_type(u)).opcode_id());
00214 }
00215 forall_edges(e,loop){
00216 if(loop.lambda(e)==0) {
00217 dag.new_edge(map[loop.source(e)], map[loop.target(e)],loop[e]);
00218 }
00219 }
00220
00221
00222 i=MAXIMAL_ANTI_CHAIN(dag, MA);
00223 cout<<"Maximal antichain in the DAG : "<<i<<endl;
00224 cout<<"Nodes belonging to a maximal antichain "<<endl;
00225 forall(n, MA){
00226 cout<< dag.id(n)<< " with opcode " << it.opcode()<<endl;
00227 }
00228
00229
00230
00231
00232 cout<<"Unrolling the loop "<<ddg_filename<<" four times and extract its body"<<endl;
00233 unroll (loop, dag, 4);
00234 snprintf(str, MAX_STRING,"%s_dag_unroll_4.vcg",ddg_filename);
00235 dag.write_to_vcg(str);
00236
00237 forall(rt,T){
00238 cout <<"The set of values of type "<< rt.get_register_typename() <<" of the body is :"<<endl;
00239 VR=dag.get_V_R(rt.get_register_type_id());
00240 forall(u, VR){
00241 it=dag.instruction_type(u);
00242 cout<< dag.id(u)<< " with opcode " << it.opcode()<<endl;
00243
00244 }
00245 }
00246 cout<<endl<< "The set of sources of the body are :"<<endl;
00247 VR=dag.get_Sources();
00248 forall(u, VR){
00249 it=dag.instruction_type(u);
00250 cout<< dag.id(u)<< " with opcode " << it.opcode()<<endl;
00251 }
00252 cout<<endl<< "The set of sinks of the body are :"<<endl;
00253 VR=dag.get_Targets();
00254 forall(u, VR){
00255 it=dag.instruction_type(u);
00256 cout<< dag.id(u)<< " with opcode " << it.opcode()<<endl;
00257 }
00258
00259
00260 cout<<endl<<"Critical Path of the unrolled body ="<<dag.CriticalPath(nl)<<endl;
00261 cout<<"Nodes belonging the critical path of the unrolled body "<<endl;
00262 forall(n, nl){
00263 it= dag.instruction_type(n);
00264 cout<< dag.id(n)<< " with opcode " << it.opcode()<<endl;
00265 }
00266
00267
00268
00269 forall(rt, T){
00270 if (dag.get_V_R(rt.get_register_type_id()).size()>=2){
00271 dag.hide_node(dag.get_V_R(rt.get_register_type_id()).choose());
00272
00273 dag.hide_node(dag.get_V_R(rt.get_register_type_id()).choose());
00274 break;
00275 }
00276 }
00277 rt=T.front();
00278 cout<<"Register Saturation of the DAG (after hiding two values of type "<< rt.get_register_typename() <<") is : "<<(j=REGISTER_SATURATION (dag, rt.get_register_type_id(), nl, killer))<<endl;
00279 cout<<"Saturating values of type "<< rt.get_register_typename() <<endl;
00280 forall(n, nl){
00281 it= dag.instruction_type(n);
00282 cout<< dag.id(n)<< " with opcode " << it.opcode()<<endl;
00283 }
00284
00285 dag.restore_all_nodes();
00286 dag.restore_all_edges();
00287 dag.build_internal_structures();
00288
00289 cout<<"Register Saturation of the DAG (after restoring the two values of type"<< rt.get_register_typename()<<") is : "<<REGISTER_SATURATION (dag, rt.get_register_type_id(), nl, killer)<<endl;
00290 cout<<"Saturating values of type "<< rt.get_register_typename()<<endl;
00291 forall(n, nl){
00292 it= dag.instruction_type(n);
00293 cout<< dag.id(n)<< " with opcode " << it.opcode()<<endl;
00294 }
00295
00296
00297 cout<<"Lattices and Order Notations:\n";
00298 forall_nodes(u, dag){
00299 forall_nodes(n, dag){
00300 if(lt(u,n)){
00301 cout<<dag.id(u)<< " < " << dag.id(n) << endl;
00302 }
00303 if(le(u,n)){
00304 cout<<dag.id(u)<< " <= " << dag.id(n)<< endl;
00305 }
00306 if(gt(u,n)){
00307 cout<<dag.id(u)<< " > " << dag.id(n)<< endl;
00308 }
00309 if(ge(u,n)){
00310 cout<<dag.id(u)<< " >= " << dag.id(n)<< endl;
00311 }
00312 if(parallel(u,n)){
00313 cout<<dag.id(u)<< " || " << dag.id(n)<< endl;
00314 }
00315 if(comparable(u,n)){
00316 cout<<dag.id(u)<< " ~ " << dag.id(n)<< endl;
00317 }
00318 }
00319 }
00320
00321
00322 cout<<"Minimal Chain Decomposition (Dilworth)"<<endl;
00323 cout<<"--------------------------------------"<<endl;
00324 j=MINIMAL_CHAIN(dag, ALN);
00325
00326 cout<<"There are "<< j <<" chains"<<endl;
00327 cpt=0;
00328 for(i=0;i< j ;i++){
00329 cout<<"Chain["<<i<<"]: ";
00330 forall(u,ALN[i]){
00331 cout<<dag.id(u);
00332 cout<<" ";
00333 cpt++;
00334 }
00335 cout<<endl;
00336 }
00337 cout<<"Total "<< cpt <<" nodes"<<" in this distribution."<<endl;
00338
00339
00340 return EXIT_SUCCESS;
00341 }