summaryrefslogtreecommitdiff
path: root/unsorted/OptimizerHelpers.c
diff options
context:
space:
mode:
authorAsh Wolf <ninji@wuffs.org>2023-01-15 12:14:05 +0000
committerAsh Wolf <ninji@wuffs.org>2023-01-15 12:14:05 +0000
commit35d488e972a9dd75ce3867c000405f128b79c615 (patch)
treee3319a23d9aa0d4725f88a99fdd5131488a334a9 /unsorted/OptimizerHelpers.c
parent8078e7f897aaae9b492b22475060052d68b9c547 (diff)
downloadMWCC-35d488e972a9dd75ce3867c000405f128b79c615.tar.gz
MWCC-35d488e972a9dd75ce3867c000405f128b79c615.zip
reorganise things a bit to align further with the actual names/structure
Diffstat (limited to 'unsorted/OptimizerHelpers.c')
-rw-r--r--unsorted/OptimizerHelpers.c166
1 files changed, 0 insertions, 166 deletions
diff --git a/unsorted/OptimizerHelpers.c b/unsorted/OptimizerHelpers.c
deleted file mode 100644
index 4085363..0000000
--- a/unsorted/OptimizerHelpers.c
+++ /dev/null
@@ -1,166 +0,0 @@
-#include "parser.h"
-
-Boolean setOldOptimizerOptions;
-
-typedef struct {
- Boolean commonsubs;
- Boolean loopinvariants;
- Boolean propagation;
- Boolean deadstore;
- Boolean strengthreduction;
- Boolean deadcode;
- Boolean lifetimes;
-} PIROptimizer; // assumed name
-
-static PIROptimizer pIrOptimizer = {0};
-
-Pragma irPragmas[] = {
- &pIrOptimizer.commonsubs, "opt_common_subs", 0,
- &pIrOptimizer.loopinvariants, "opt_loop_invariants", 0,
- &pIrOptimizer.propagation, "opt_propagation", 0,
- &pIrOptimizer.deadstore, "opt_dead_assignments", 0,
- &pIrOptimizer.deadcode, "opt_dead_code", 0,
- &pIrOptimizer.strengthreduction, "opt_strength_reduction", 0,
- &pIrOptimizer.lifetimes, "opt_lifetimes", 0,
- 0, 0, 0
-};
-
-int SetPragmaOptimizationsToUnspecified(const char *opt, void *, const char *, int) {
- if (setOldOptimizerOptions)
- Option_Warning(CLPStr62);
-
- memset(&pIrOptimizer, 0, sizeof(pIrOptimizer));
- TargetSetPragmaOptimizationsToUnspecified();
- return 1;
-}
-
-int SetOptFlags(const char *opt, void *str, const char *, int flags) {
- // this is very similar to ToolHelper
- // might also fail to match
- unsigned char *ptr;
- Boolean set;
- Boolean no;
- UInt16 flag;
-
- ptr = (unsigned char *) str;
- no = (Boolean) ((flags & PARAMPARSEFLAGS_8) >> 3);
- set = (Boolean) (no ^ 1);
-
- while (*ptr) {
- if (*ptr == '+') {
- set = !no;
- } else if (*ptr == '-') {
- set = no;
- } else if (*ptr == '|') {
- set = (Boolean) (no ^ 1);
- } else {
- flag = (ptr[0] << 8) | ptr[1];
-
- if ((flag >= 'G0' && flag <= 'G4') || (flag == 'Gs') || (flag == 'Gp'))
- SetPragmaOptimizationsToUnspecified(opt, NULL, NULL, 0);
-
- switch (flag) {
- case 'Cs':
- pIrOptimizer.commonsubs = set ? 1 : 2;
- setOldOptimizerOptions = 1;
- break;
- case 'Li':
- pIrOptimizer.loopinvariants = set ? 1 : 2;
- setOldOptimizerOptions = 1;
- break;
- case 'Pr':
- pIrOptimizer.propagation = set ? 1 : 2;
- setOldOptimizerOptions = 1;
- break;
- case 'Ds':
- pIrOptimizer.deadstore = set ? 1 : 2;
- setOldOptimizerOptions = 1;
- break;
- case 'Sr':
- pIrOptimizer.strengthreduction = set ? 1 : 2;
- setOldOptimizerOptions = 1;
- break;
- case 'Dc':
- pIrOptimizer.deadcode = set ? 1 : 2;
- setOldOptimizerOptions = 1;
- break;
- case 'Lt':
- pIrOptimizer.lifetimes = set ? 1 : 2;
- setOldOptimizerOptions = 1;
- break;
- case 'G0':
- pGlobalOptimizer.optimizationlevel = set ? 0 : 0;
- break;
- case 'G1':
- pGlobalOptimizer.optimizationlevel = set ? 1 : 0;
- break;
- case 'G2':
- pGlobalOptimizer.optimizationlevel = set ? 2 : 0;
- break;
- case 'G3':
- pGlobalOptimizer.optimizationlevel = set ? 3 : 0;
- break;
- case 'G4':
- pGlobalOptimizer.optimizationlevel = set ? 4 : 0;
- break;
- case 'Gs':
- pGlobalOptimizer.optfor = set ? 1 : 0;
- break;
- case 'Gp':
- pGlobalOptimizer.optfor = set ? 0 : 1;
- break;
- default:
- if (!TargetSetOptFlags(flag, set))
- CLPFatalError("Bad optimizer settings in %s (%c%c)\n", str, ptr[0], ptr[1]);
- }
-
- ++ptr;
- }
-
- ++ptr;
- }
-
- return 1;
-}
-
-int DisplayOptimizationOptions(const char *, void *, const char *, int) {
- SInt32 oldsize;
- Handle h;
-
- h = NewHandle(0);
- if (!h)
- exit(-23);
-
- HPrintF(h, "\t- global optimizer level %d\n", pGlobalOptimizer.optimizationlevel);
- HPrintF(h, "\t- global optimize for %s\n", (pGlobalOptimizer.optfor == 0) ? "speed" : "size");
-
- oldsize = GetHandleSize(h);
- if (pIrOptimizer.commonsubs)
- HPrintF(h, "\t- common subexpression elimination %s\n", (pIrOptimizer.commonsubs == 1) ? "on" : "off");
- if (pIrOptimizer.loopinvariants)
- HPrintF(h, "\t- loop invariants %s\n", (pIrOptimizer.loopinvariants == 1) ? "on" : "off");
- if (pIrOptimizer.commonsubs)
- HPrintF(h, "\t- constant propagation %s\n", (pIrOptimizer.propagation == 1) ? "on" : "off");
- if (pIrOptimizer.deadstore)
- HPrintF(h, "\t- dead store elimination %s\n", (pIrOptimizer.deadstore == 1) ? "on" : "off");
- if (pIrOptimizer.deadcode)
- HPrintF(h, "\t- dead code elimination %s\n", (pIrOptimizer.deadcode == 1) ? "on" : "off");
- if (pIrOptimizer.strengthreduction)
- HPrintF(h, "\t- strength reduction %s\n", (pIrOptimizer.strengthreduction == 1) ? "on" : "off");
- if (pIrOptimizer.lifetimes)
- HPrintF(h, "\t- variable lifetimes %s\n", (pIrOptimizer.lifetimes == 1) ? "on" : "off");
-
- if (oldsize == GetHandleSize(h))
- HPrintF(h, "\t- no extra global optimizations\n");
-
- HPrintF(h, "Backend-specific optimizer options:\n");
-
- oldsize = GetHandleSize(h);
- TargetDisplayOptimizationOptions(h);
- if (oldsize == GetHandleSize(h))
- HPrintF(h, "\t- no extra backend-specific optimizations\n");
-
- ShowTextHandle(NULL, h);
- DisposeHandle(h);
- return 1;
-}