| File: | src/optfoam.c |
| Warning: | line 369, column 4 Value stored to 'newConsts' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /***************************************************************************** |
| 2 | * |
| 3 | * optfoam.c: Foam-to-foam optimizaion. |
| 4 | * |
| 5 | * Copyright (c) 1990-2007 Aldor Software Organization Ltd (Aldor.org). |
| 6 | * |
| 7 | ****************************************************************************/ |
| 8 | |
| 9 | #include "axlobs.h" |
| 10 | #include "debug.h" |
| 11 | #include "flatten.h" |
| 12 | #include "flog.h" |
| 13 | #include "format.h" |
| 14 | #include "inlutil.h" |
| 15 | #include "loops.h" |
| 16 | #include "of_argsub.h" |
| 17 | #include "of_cfold.h" |
| 18 | #include "of_comex.h" |
| 19 | #include "of_cprop.h" |
| 20 | #include "of_crinlin.h" |
| 21 | #include "of_deada.h" |
| 22 | #include "of_deadv.h" |
| 23 | #include "of_emerg.h" |
| 24 | #include "of_env.h" |
| 25 | #include "of_hfold.h" |
| 26 | #include "of_inlin.h" |
| 27 | #include "of_jflow.h" |
| 28 | #include "of_killp.h" |
| 29 | #include "of_peep.h" |
| 30 | #include "of_retyp.h" |
| 31 | #include "of_rrfmt.h" |
| 32 | #include "optfoam.h" |
| 33 | #include "store.h" |
| 34 | #include "strops.h" |
| 35 | |
| 36 | Bool optfDebug = false((int) 0); |
| 37 | Bool optfShowDebug = false((int) 0); |
| 38 | |
| 39 | #define optfDEBUGif (!optfDebug) { } else afprintf DEBUG_IF(optf)if (!optfDebug) { } else afprintf |
| 40 | #define optfShowDEBUGif (!optfShowDebug) { } else afprintf DEBUG_IF(optfShow)if (!optfShowDebug) { } else afprintf |
| 41 | |
| 42 | static int optInline; |
| 43 | static int optInlineAll; |
| 44 | static int optJFlowLimit; |
| 45 | static int optInlineLimit; |
| 46 | int optInlineRoof; |
| 47 | static int optConstFold; |
| 48 | static int optFloatFold; |
| 49 | static int optHashFold; |
| 50 | static int optDeadVar; |
| 51 | static int optDeadAssign; |
| 52 | static int optPeepHole; |
| 53 | static int optCommExp; |
| 54 | static int optEnvMerge; |
| 55 | static int optEnvOpts; |
| 56 | static int optCopyProp; |
| 57 | static int optJumpFlow; |
| 58 | static int optCast; |
| 59 | static int optCC; |
| 60 | static int optArgSub; |
| 61 | static int optArgCrinlin; |
| 62 | static int optCcFnonstd; |
| 63 | static int optIgnoreAsserts; |
| 64 | static int optKillPointers; |
| 65 | static int optEmergeRRFmt; |
| 66 | |
| 67 | #define OPT_Negate"no-" "no-" |
| 68 | #define OPT_All"all" "all" |
| 69 | #define OPT_InlineAll"inline-all" "inline-all" |
| 70 | |
| 71 | #define OPT_MaxQLevel9 9 |
| 72 | #define OPT_MaxLevel4 4 |
| 73 | #define OPT_DefaultLevel1 1 |
| 74 | |
| 75 | static int optLevel = OPT_DefaultLevel1; |
| 76 | |
| 77 | enum optNature { |
| 78 | OPT_FLAG, |
| 79 | OPT_FLOAT |
| 80 | }; |
| 81 | |
| 82 | struct optControl { |
| 83 | String name; |
| 84 | enum optNature nature; |
| 85 | int *pvar; |
| 86 | int value[OPT_MaxLevel4+1]; |
| 87 | }; |
| 88 | |
| 89 | /****************************************************************************** |
| 90 | * |
| 91 | * :: Local operations |
| 92 | * |
| 93 | *****************************************************************************/ |
| 94 | |
| 95 | localstatic void optInitFormatters(); |
| 96 | |
| 97 | localstatic void optSetAllTo (Bool); |
| 98 | localstatic void optSetLevel (int); |
| 99 | localstatic void optPrintOpts (FILE *fout); |
| 100 | localstatic void optSetJFlowLimit (void); |
| 101 | localstatic void optOptimizationsInit (void); |
| 102 | |
| 103 | |
| 104 | /* |
| 105 | * Control Option processing: note that -Qinline-limit and -Qinline-size |
| 106 | * arguments supplied by the user are multiplied by 100. |
| 107 | */ |
| 108 | struct optControl optControl[] = { |
| 109 | /* name nature pvar Q0 Q1 Q2 Q3 Q4. */ |
| 110 | {"inline", OPT_FLAG, &optInline, { 0, 0, 1, 1, 1}}, |
| 111 | {OPT_InlineAll"inline-all", OPT_FLAG, &optInlineAll, { 0, 0, 0, 1, 1}}, |
| 112 | {"inline-limit",OPT_FLOAT, &optInlineLimit, { 0, 0, 500, 600, 800}}, |
| 113 | {"inline-size", OPT_FLOAT, &optInlineRoof, { 0, 0, 1000, 2000, 4000}}, |
| 114 | {"cfold", OPT_FLAG, &optConstFold, { 0, 1, 1, 1, 1}}, |
| 115 | {"ffold", OPT_FLAG, &optFloatFold, { 0, 0, 1, 1, 1}}, |
| 116 | {"hfold", OPT_FLAG, &optHashFold, { 0, 1, 1, 1, 1}}, |
| 117 | {"deadvar", OPT_FLAG, &optDeadVar, { 0, 1, 1, 1, 1}}, |
| 118 | {"dassign", OPT_FLAG, &optDeadAssign, { 0, 0, 1, 1, 1}}, |
| 119 | {"peep", OPT_FLAG, &optPeepHole, { 0, 1, 1, 1, 1}}, |
| 120 | {"cprop", OPT_FLAG, &optCopyProp, { 0, 0, 1, 1, 1}}, |
| 121 | {"cse", OPT_FLAG, &optCommExp, { 0, 0, 1, 1, 1}}, |
| 122 | {"env", OPT_FLAG, &optEnvOpts, { 0, 0, 1, 1, 1}}, |
| 123 | {"emerge", OPT_FLAG, &optEnvMerge, { 0, 0, 1, 1, 1}}, |
| 124 | {"emerge-rr", OPT_FLAG, &optEmergeRRFmt, { 0, 0, 1, 1, 1}}, |
| 125 | {"flow", OPT_FLAG, &optJumpFlow, { 0, 0, 1, 1, 1}}, |
| 126 | {"cast", OPT_FLAG, &optCast, { 0, 0, 1, 1, 1}}, |
| 127 | {"cc", OPT_FLAG, &optCC, { 0, 0, 1, 1, 1}}, |
| 128 | {"del-assert", OPT_FLAG, &optIgnoreAsserts, { 0, 0, 1, 1, 1}}, |
| 129 | {"cc-fnonstd", OPT_FLAG, &optCcFnonstd, { 0, 0, 0, 0, 0}}, |
| 130 | /* The next three are experimental or future-work */ |
| 131 | {"killp", OPT_FLAG, &optKillPointers, { 0, 0, 0, 0, 0}}, |
| 132 | {"argsub", OPT_FLAG, &optArgSub, { 0, 0, 0, 0, 0}}, |
| 133 | {"crinlin", OPT_FLAG, &optArgCrinlin, { 0, 0, 1, 1, 1}}, |
| 134 | { 0 } |
| 135 | }; |
| 136 | |
| 137 | /* optInlineLimit for Q5 Q6 Q7 Q8 Q9 */ |
| 138 | static int optQInlineLimit[] = {1000, 1400, 1800, 3000, -1}; |
| 139 | |
| 140 | /* |
| 141 | * Set all flags to the given value. |
| 142 | */ |
| 143 | localstatic void |
| 144 | optSetAllTo(Bool flag) |
| 145 | { |
| 146 | int i; |
| 147 | |
| 148 | for (i = 0; optControl[i].name; i++) |
| 149 | if (optControl[i].nature == OPT_FLAG) |
| 150 | *optControl[i].pvar = flag; |
| 151 | } |
| 152 | |
| 153 | /* |
| 154 | * Set all flags and control variables to the values suitable for the |
| 155 | * given optimization level. |
| 156 | */ |
| 157 | localstatic void |
| 158 | optSetLevel(int lev) |
| 159 | { |
| 160 | int i, index; |
| 161 | |
| 162 | optLevel = lev; |
| 163 | #if OLD_SET_LEVEL |
| 164 | optInlineLimit = optQInlineLimit[lev - OPT_MaxLevel4 -1]; |
| 165 | index = (lev > OPT_MaxLevel4 ? OPT_MaxLevel4 : lev); |
| 166 | |
| 167 | for (i = 0; optControl[i].name; i++) |
| 168 | *optControl[i].pvar = optControl[i].value[index]; |
| 169 | #else |
| 170 | index = (lev > OPT_MaxLevel4 ? OPT_MaxLevel4 : lev); |
| 171 | |
| 172 | for (i = 0; optControl[i].name; i++) |
| 173 | *optControl[i].pvar = optControl[i].value[index]; |
| 174 | |
| 175 | if (lev > OPT_MaxLevel4) |
| 176 | optInlineLimit = optQInlineLimit[lev - OPT_MaxLevel4 - 1]; |
| 177 | #endif |
| 178 | } |
| 179 | |
| 180 | localstatic void |
| 181 | optPrintOpts(FILE *fout) |
| 182 | { |
| 183 | int i; |
| 184 | fprintf(fout, "Optimizations selected:\n"); |
| 185 | for (i = 0; optControl[i].name; i++) |
| 186 | fprintf(fout, "%15s %d\n", optControl[i].name, *optControl[i].pvar); |
| 187 | } |
| 188 | |
| 189 | void |
| 190 | optInit(void) |
| 191 | { |
| 192 | optSetLevel(OPT_DefaultLevel1); |
| 193 | optInitFormatters(); |
| 194 | } |
| 195 | |
| 196 | int |
| 197 | optSetStdOptimization(void) |
| 198 | { |
| 199 | return optSetOptimization("2"); |
| 200 | } |
| 201 | |
| 202 | void |
| 203 | optSetLoopOption(void) |
| 204 | { |
| 205 | inlSetGenerators(); |
| 206 | } |
| 207 | |
| 208 | int |
| 209 | optSetOptimization(String opt) |
| 210 | { |
| 211 | int i; |
| 212 | String s; |
| 213 | Bool isOn; |
| 214 | |
| 215 | /* LEVELS: -Qn for n in 0..OPT_MaxLevel */ |
| 216 | i = opt[0] - '0'; |
| 217 | if (!opt[1] && 0 <= i && i <= OPT_MaxQLevel9) { |
| 218 | optSetLevel(i); |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | /* INTEGERS: -Qxxx=nnn or -Qxxx:nnn */ |
| 223 | for (i = 0; optControl[i].name; i++) { |
| 224 | if (optControl[i].nature != OPT_FLOAT) continue; |
| 225 | if ((s = strAIsPrefix(optControl[i].name, opt)) == 0) continue; |
| 226 | if (*s != '=' && *s != ':') continue; |
| 227 | |
| 228 | s += 1; |
| 229 | *optControl[i].pvar = (int) (100 * atof(s)); |
| 230 | return 0; |
| 231 | } |
| 232 | |
| 233 | /* FLAGS: -Qxxx -Qno-xxx ... */ |
| 234 | isOn = true1; |
| 235 | while (s = strAIsPrefix(OPT_Negate"no-", opt), s) { |
| 236 | isOn = !isOn; |
| 237 | opt = s; |
| 238 | } |
| 239 | |
| 240 | if (strAEqual(opt, OPT_All"all")) { |
| 241 | optSetAllTo(isOn); |
| 242 | return 0; |
| 243 | } |
| 244 | if (strEqual(opt, OPT_InlineAll"inline-all")) { |
| 245 | optInlineAll = isOn; |
| 246 | if (isOn) optInline = isOn; |
| 247 | return 0; |
| 248 | } |
| 249 | |
| 250 | for (i = 0; optControl[i].name; i++) { |
| 251 | if (!strEqual(opt, optControl[i].name)) continue; |
| 252 | if (optControl[i].nature != OPT_FLAG) continue; |
| 253 | *optControl[i].pvar = isOn; |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | /* FAILED */ |
| 258 | return -1; |
| 259 | } |
| 260 | |
| 261 | Foam |
| 262 | optimizeFoam(Foam foam) |
| 263 | { |
| 264 | Bool newConsts = false((int) 0); |
| 265 | int i, iters; |
| 266 | if (DEBUG(optf)optfDebug){optPrintOpts(dbOut);} |
| 267 | if (DEBUG(optfShow)optfShowDebug) { |
| 268 | afprintf(dbOut, "optfoam - in:\n%pFoam\n", foam); |
| 269 | } |
| 270 | optOptimizationsInit(); |
| 271 | |
| 272 | if (optDeadVar) { |
| 273 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting deadvar...\n"); |
| 274 | dvElim(foam); |
| 275 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 276 | } |
| 277 | if (optInline) { |
| 278 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting inline...\n"); |
| 279 | inlineUnit(foam, optInlineAll, optInlineLimit, true1); |
| 280 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 281 | } |
| 282 | if (optInline) { |
| 283 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting coroutine inline...\n"); |
| 284 | crinUnit(foam); |
| 285 | inlineUnit(foam, optInlineAll, optInlineLimit, true1); |
| 286 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 287 | } |
| 288 | /* Maybe we ought to cprop before cfold? */ |
| 289 | if (optConstFold || optFloatFold) { |
| 290 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting cfold...\n"); |
| 291 | newConsts = cfoldUnit(foam, optConstFold, optFloatFold); |
| 292 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 293 | } |
| 294 | while (newConsts && optInline) { |
| 295 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting expr inline...\n"); |
| 296 | /* If const folding made new constants, inline them. */ |
| 297 | inlineUnit(foam, optInlineAll, optInlineLimit, false((int) 0)); |
| 298 | newConsts = cfoldUnit(foam, optConstFold, optFloatFold); |
| 299 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 300 | } |
| 301 | if (newConsts && optInline) { |
| 302 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting coroutine inline...\n"); |
| 303 | crinUnit(foam); |
| 304 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 305 | } |
| 306 | if (optHashFold) { |
| 307 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting hfold...\n"); |
| 308 | hfoldUnit(foam); |
| 309 | cpropUnit(foam, false((int) 0)); |
| 310 | cfoldUnit(foam, optConstFold, optFloatFold); |
| 311 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 312 | } |
| 313 | if (optEmergeRRFmt) { |
| 314 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting emerge-rr...\n"); |
| 315 | rrUnitEmerge(foam); |
| 316 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 317 | } |
| 318 | if (optEnvMerge) { |
| 319 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting emerge...\n"); |
| 320 | emMergeUnit(foam); |
| 321 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 322 | } |
| 323 | if (optDeadVar) { |
| 324 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting deadvar...\n"); |
| 325 | dvElim(foam); |
| 326 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 327 | } |
| 328 | if (optEnvOpts) { |
| 329 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting env. opts...\n"); |
| 330 | oeUnit(foam); |
| 331 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 332 | } |
| 333 | if (optCast) { |
| 334 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting retype...\n"); |
| 335 | retypeUnit(foam); |
| 336 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 337 | } |
| 338 | |
| 339 | if (optLevel > 5) |
| 340 | iters = 5; |
| 341 | else if (optLevel == 0) |
| 342 | iters = 1; |
| 343 | else |
| 344 | iters = optLevel; |
| 345 | |
| 346 | for (i=0; i<iters; i++) { |
| 347 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "STARTING LOOP (%d)\n", i); |
| 348 | |
| 349 | if (DEBUG(optf)optfDebug){foamWrSExpr(dbOut, foam, int0((int) 0));} |
| 350 | #if 0 |
| 351 | if (optInline) { |
| 352 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting inline...\n"); |
| 353 | inlineUnit(foam, optInlineAll, optInlineLimit, true1); |
| 354 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 355 | } |
| 356 | #endif |
| 357 | if (optCopyProp) { |
| 358 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting cprop...\n"); |
| 359 | cpropUnit(foam, i == 0); |
| 360 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 361 | } |
| 362 | if (optPeepHole) { |
| 363 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting peep...\n"); |
| 364 | peepUnit(foam,optFloatFold); |
| 365 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 366 | } |
| 367 | if (optConstFold || optFloatFold) { |
| 368 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting cfold...\n"); |
| 369 | newConsts = cfoldUnit(foam, optConstFold,optFloatFold); |
Value stored to 'newConsts' is never read | |
| 370 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 371 | } |
| 372 | if (optCommExp) { |
| 373 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting cse...\n"); |
| 374 | cseUnit(foam); |
| 375 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 376 | } |
| 377 | #if 0 |
| 378 | while (newConsts && optInline) { |
| 379 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting expr inline...\n"); |
| 380 | /* If const folding made new constants, inline them. */ |
| 381 | inlineUnit(foam, optInlineAll, optInlineLimit, false((int) 0)); |
| 382 | newConsts = cfoldUnit(foam, optConstFold, optFloatFold); |
| 383 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 384 | } |
| 385 | #endif |
| 386 | #if 0 |
| 387 | if (optArgSub) { |
| 388 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting argsub...\n"); |
| 389 | argsubUnit(foam); |
| 390 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 391 | } |
| 392 | #endif |
| 393 | if (optJumpFlow) { |
| 394 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting jflow...\n"); |
| 395 | jflowUnit(foam, optJFlowLimit); |
| 396 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 397 | } |
| 398 | if (optDeadAssign) { |
| 399 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting dead assign...\n"); |
| 400 | deadAssign(foam); |
| 401 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 402 | } |
| 403 | |
| 404 | if (optDeadVar) { |
| 405 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting deadvar...\n"); |
| 406 | dvElim(foam); |
| 407 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 408 | } |
| 409 | #if 0 |
| 410 | if (optEnvMerge) { |
| 411 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting emerge...\n"); |
| 412 | emMergeUnit(foam); |
| 413 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 414 | } |
| 415 | #endif |
| 416 | } |
| 417 | |
| 418 | if (optEnvOpts) { |
| 419 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting env. opts...\n"); |
| 420 | oeUnit(foam); |
| 421 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 422 | } |
| 423 | |
| 424 | if (optPeepHole) { |
| 425 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Starting peep...\n"); |
| 426 | peepUnit(foam,optFloatFold); |
| 427 | if (DEBUG(phase)phaseDebug){stoAudit();} |
| 428 | } |
| 429 | |
| 430 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "(Starting patchUnit...)\n"); |
| 431 | |
| 432 | fpPatchUnit(foam); |
| 433 | |
| 434 | /* |
| 435 | * inlSetAfterInline turns on checking for domainGetExport |
| 436 | * when using -W runtime. |
| 437 | */ |
| 438 | inlSetAfterInline()(inl0AfterInline=1); |
| 439 | |
| 440 | if (optInline) { |
| 441 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "(Starting unitInfoRefresh...)\n"); |
| 442 | inuUnitInfoRefresh(foam); |
| 443 | } |
| 444 | |
| 445 | /* Remove any nested CCalls, etc */ |
| 446 | /*flattenUnit(foam);*/ |
| 447 | |
| 448 | optfDEBUGif (!optfDebug) { } else afprintf(dbOut, "Optimizations finished.\n"); |
| 449 | |
| 450 | if (DEBUG(optfShow)optfShowDebug) { |
| 451 | afprintf(dbOut, "optfoam - out:\n%pFoam\n", foam); |
| 452 | } |
| 453 | |
| 454 | foamAuditAll(foam, 0xffff); |
| 455 | |
| 456 | assert(foamAudit(foam))do { if (!(foamAudit(foam))) _do_assert(("foamAudit(foam)"),"optfoam.c" ,456); } while (0); |
| 457 | |
| 458 | return foam; |
| 459 | } |
| 460 | |
| 461 | /* This seems reasonable. Note: assumes that with -Q3 limit=600 */ |
| 462 | localstatic void |
| 463 | optSetJFlowLimit(void) |
| 464 | { |
| 465 | if (optInlineLimit > -1) |
| 466 | optJFlowLimit = optInlineLimit / 20; |
| 467 | else |
| 468 | optJFlowLimit = 30000; |
| 469 | } |
| 470 | |
| 471 | Bool |
| 472 | optIsCcOptimizeWanted(void) |
| 473 | { |
| 474 | return optCC; |
| 475 | } |
| 476 | |
| 477 | Bool |
| 478 | optIsCcFNonStdWanted(void) |
| 479 | { |
| 480 | return optCcFnonstd; |
| 481 | } |
| 482 | |
| 483 | Bool |
| 484 | optIsFloatFoldWanted(void) |
| 485 | { |
| 486 | return optFloatFold; |
| 487 | } |
| 488 | |
| 489 | Bool |
| 490 | optIsIgnoreAssertsWanted(void) |
| 491 | { |
| 492 | return optIgnoreAsserts; |
| 493 | } |
| 494 | |
| 495 | Bool |
| 496 | optIsDeadVarWanted(void) |
| 497 | { |
| 498 | return optDeadVar; |
| 499 | } |
| 500 | |
| 501 | Bool |
| 502 | optIsKillPointersWanted(void) |
| 503 | { |
| 504 | return optKillPointers; |
| 505 | } |
| 506 | |
| 507 | Bool |
| 508 | optIsMaxLevel(void) |
| 509 | { |
| 510 | return optLevel == OPT_MaxQLevel9; |
| 511 | } |
| 512 | |
| 513 | /* Put here a every call needed to initialize an optimization. */ |
| 514 | localstatic void |
| 515 | optOptimizationsInit() |
| 516 | { |
| 517 | dvInit(); |
| 518 | optSetJFlowLimit(); |
| 519 | } |
| 520 | |
| 521 | /* |
| 522 | * :: Formatters |
| 523 | */ |
| 524 | localstatic int flogFormatter(OStream stream, Pointer p); |
| 525 | localstatic int loopFormatter(OStream stream, Pointer p); |
| 526 | localstatic int bbFormatter(OStream stream, Pointer p); |
| 527 | localstatic int bbufFormatter(OStream stream, Pointer p); |
| 528 | localstatic int bbListFormatter(OStream stream, Pointer p); |
| 529 | localstatic int loopListFormatter(OStream stream, Pointer p); |
| 530 | |
| 531 | localstatic void |
| 532 | optInitFormatters() |
| 533 | { |
| 534 | fmtRegisterFull("FlowGraph", flogFormatter, false((int) 0)); |
| 535 | |
| 536 | fmtRegisterFull("Loop", loopFormatter, false((int) 0)); |
| 537 | fmtRegisterFull("LoopList", loopListFormatter, true1); |
| 538 | |
| 539 | fmtRegisterFull("BBlock", bbFormatter, false((int) 0)); |
| 540 | fmtRegisterFull("BBlockList", bbListFormatter, true1); |
| 541 | |
| 542 | fmtRegisterFull("BlockBuf", bbufFormatter, false((int) 0)); |
| 543 | |
| 544 | } |
| 545 | |
| 546 | localstatic int |
| 547 | flogFormatter(OStream stream, Pointer p) |
| 548 | { |
| 549 | FlowGraph flog = (FlowGraph) p; |
| 550 | int c=0; |
| 551 | int i; |
| 552 | |
| 553 | c += ostreamPrintf(stream, "(Flog:"); |
| 554 | for (i=0; i < flogBlockC(flog)((flog)->blocks->pos); i++) { |
| 555 | c += ostreamPrintf(stream, " %pBBlock", flogBlock(flog, i)bbufBlockFn((flog)->blocks,i)); |
| 556 | } |
| 557 | c += ostreamPrintf(stream, ")"); |
| 558 | |
| 559 | return c; |
| 560 | } |
| 561 | |
| 562 | localstatic int |
| 563 | loopFormatter(OStream stream, Pointer p) |
| 564 | { |
| 565 | Loop loop = (Loop) p; |
| 566 | int c; |
| 567 | |
| 568 | c = ostreamPrintf(stream, "[L: %d %pBBlockList]", loop->header->label, loop->blockList); |
| 569 | |
| 570 | return c; |
| 571 | } |
| 572 | |
| 573 | localstatic int |
| 574 | bbFormatter(OStream stream, Pointer p) |
| 575 | { |
| 576 | BBlock bb = (BBlock) p; |
| 577 | int c; |
| 578 | c = ostreamPrintf(stream, "[B %s %d In: %pBlockBuf Out: %pBlockBuf]", |
| 579 | bb->kind < FOAM_LIMIT ? foamStr(bb->kind)((foamInfoTable [(int)(bb->kind)-(int)FOAM_START]).str) : "???", |
| 580 | bb->label, bb->entries, bb->exits); |
| 581 | return c; |
| 582 | } |
| 583 | |
| 584 | localstatic int |
| 585 | bbufFormatter(OStream stream, Pointer p) |
| 586 | { |
| 587 | BlockBuf bf = (BlockBuf) p; |
| 588 | int c = 0; |
| 589 | int i; |
| 590 | char *sep = ""; |
| 591 | |
| 592 | ostreamWriteChar(stream, '('); |
| 593 | c++; |
| 594 | for (i=0; i < bbufCount(bf)((bf)->pos); i++) { |
| 595 | BBlock bb = bbufBlock(bf, i)bbufBlockFn(bf,i); |
| 596 | c += ostreamPrintf(stream, "%s%d", sep, bb->label); |
| 597 | sep = " "; |
| 598 | } |
| 599 | ostreamWriteChar(stream, ')'); |
| 600 | c++; |
| 601 | |
| 602 | return c; |
| 603 | } |
| 604 | |
| 605 | localstatic int |
| 606 | loopListFormatter(OStream ostream, Pointer p) |
| 607 | { |
| 608 | LoopList list = (LoopList) p; |
| 609 | return listFormat(Loop)(Loop_listPointer->Format)(ostream, "Loop", list); |
| 610 | } |
| 611 | localstatic int |
| 612 | bbListFormatter(OStream ostream, Pointer p) |
| 613 | { |
| 614 | BBlockList list = (BBlockList) p; |
| 615 | return listFormat(BBlock)(BBlock_listPointer->Format)(ostream, "BBlock", list); |
| 616 | } |