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
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084 #include <stdio.h>
00085 #include <vector>
00086 #include "defs.h"
00087 #include "cg_swp_allocator.h"
00088
00089
00090 static const char *
00091 Read_Line()
00092 {
00093 static char line[512];
00094 if (gets(line) == NULL)
00095 line[0] = '\0';
00096 return line;
00097 }
00098
00099 static INT32
00100 Get_A_Number()
00101 {
00102 INT32 num, status = 0;
00103
00104 while (status != 1)
00105 {
00106 status = sscanf(Read_Line(), "%d", &num);
00107 if (status != 1)
00108 printf("\n<Try again! Enter a single integer> ");
00109 }
00110 return num;
00111 }
00112
00113
00114 static INT32
00115 Get_Bounded_Number(INT32 min, INT32 max)
00116 {
00117 INT32 num = Get_A_Number();
00118 while (num > max || num < min)
00119 {
00120 printf("\nInvalid option! Enter a digit between %d and %d>", min, max);
00121 num = Get_A_Number();
00122 }
00123 return num;
00124 }
00125
00126
00127 static void
00128 Get_A_Lifetime(SWP_LIFETIME <)
00129 {
00130 INT32 from_tunit, to_tunit, omega, alpha, status = 0;
00131
00132 printf("\n<Enter lifetime (start_cycle end_cycle omega alpha)> ");
00133 while (status != 4)
00134 {
00135 status = sscanf(Read_Line(), "%d %d %d %d",
00136 &from_tunit, &to_tunit, &omega, &alpha);
00137 if (status != 4)
00138 printf("\n<Try again! Enter 4 space separated integers> ");
00139 }
00140 lt = SWP_LIFETIME(from_tunit, to_tunit, omega, alpha);
00141 }
00142
00143
00144 static void
00145 Get_Lifetimes(std::vector<SWP_LIFETIME> <v)
00146 {
00147 INT32 number_of_values = -1;
00148 SWP_LIFETIME lt;
00149
00150 printf("\n<How many lifetimes do you wish to enter> ");
00151 number_of_values = Get_Bounded_Number(0, 100);
00152
00153 for (INT32 i = 0; i < number_of_values; i++)
00154 {
00155 Get_A_Lifetime(lt);
00156 ltv.push_back(lt);
00157 }
00158 }
00159
00160
00161 void main()
00162 {
00163 BOOL more = TRUE;
00164 INT32 option;
00165 std::vector<SWP_LIFETIME> ltv;
00166 INT32 ii = 2, sc = 10, num_regs = 64, num_its = 15, num_cols = 70;
00167
00168 while (more)
00169 {
00170 printf("\n----------- Testing swp allocator -----------");
00171 printf("\n");
00172 printf("\n 0) Exit");
00173 printf("\n 1) Set ii (default %d)", ii);
00174 printf("\n 2) Set sc (default %d)", sc);
00175 printf("\n 3) Set max registers (default %d)", num_regs);
00176 printf("\n 4) Set number of iterations to plot (default %d)", num_its);
00177 printf("\n 5) Set column-width of plot (default %d)", num_cols);
00178 printf("\n 6) Enter new set of lifetimes");
00179 printf("\n 7) Append to existing set of lifetimes");
00180 printf("\n 8) Allocate and trace with adjacency ordering");
00181 printf("\n 9) Allocate and trace without adjacency ordering");
00182 printf("\n 10) Example from Rau's paper (page 287)");
00183 printf("\n");
00184 printf("\nNOTES on plot:\n");
00185 printf("\n \">\" indicates live value carried in/out of loop");
00186 printf("\n \"*\" indicates overlapped lifetimes (i.e. an error)");
00187 printf("\n");
00188 printf("\n<Enter an option (0-10)> ");
00189
00190 option = Get_Bounded_Number(0, 10);
00191
00192 switch (option)
00193 {
00194 case 0:
00195 more = FALSE;
00196 break;
00197
00198 case 1:
00199 printf("\nEnter ii (1..1000)> ");
00200 ii = Get_Bounded_Number(1, 1000);
00201 break;
00202 case 2:
00203 printf("\nEnter sc (1..1000)> ");
00204 sc = Get_Bounded_Number(1, 1000);
00205 break;
00206 case 3:
00207 printf("\nEnter number of registers (1..256)> ");
00208 num_regs = Get_Bounded_Number(1, 256);
00209 break;
00210 case 4:
00211 printf("\nEnter number of iteration (1..256)> ");
00212 num_its = Get_Bounded_Number(1, 256);
00213 break;
00214 case 5:
00215 printf("\nEnter number of columns (1..256)> ");
00216 num_cols = Get_Bounded_Number(1, 256);
00217 break;
00218 case 6:
00219 ltv.clear();
00220 Get_Lifetimes(ltv);
00221 break;
00222 case 7:
00223 Get_Lifetimes(ltv);
00224 break;
00225 case 8:
00226 {
00227 SWP_ALLOCATOR reg_alloc(ii, sc, num_regs, ltv.begin(), ltv.end(),
00228 Malloc_Mem_Pool, TRUE);
00229 reg_alloc.print(stdout, num_its, num_cols);
00230 break;
00231 }
00232 case 9:
00233 {
00234 SWP_ALLOCATOR reg_alloc(ii, sc, num_regs, ltv.begin(), ltv.end(),
00235 Malloc_Mem_Pool, FALSE);
00236 reg_alloc.print(stdout, num_its, num_cols);
00237 break;
00238 }
00239 case 10:
00240 {
00241 ii = 2;
00242 sc = 10;
00243 num_regs = 64;
00244 ltv.clear();
00245 ltv.push_back(SWP_LIFETIME(13,17,1,1));
00246 ltv.push_back(SWP_LIFETIME(18,21,0,0));
00247 ltv.push_back(SWP_LIFETIME(15,20,0,0));
00248 ltv.push_back(SWP_LIFETIME(0,20,0,0));
00249 ltv.push_back(SWP_LIFETIME(0,23,1,0));
00250 SWP_ALLOCATOR reg_alloc(ii, sc, num_regs, ltv.begin(), ltv.end());
00251 reg_alloc.print(stdout, num_its, num_cols);
00252 break;
00253 }
00254 }
00255 }
00256 }